Files
hub/.gral/functions/main.js
T
2026-10-14 02:01:34 -05:00

38 lines
1.3 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
const system = `The user is probably asking for either information, a review, or general suggestions.
You can only read files, you're forbidden from writing any file, only respond to the user after light research.
Only read up to 10 files. If more context is needed, submit your response regardless with all the information available. Your maximum iteration count is 20, you should NEVER reach it, ideally stay under 5 iterations.
`;
function resolvePrompt (input) {
if (input.prompt) return input.prompt;
const candidates = ['prompt.md', 'prompt.txt', 'prompt'];
for (const name of candidates) {
const file = path.resolve(Gral.path, '.gral', name);
if (fs.existsSync(file)) {
return fs.readFileSync(file, 'utf8');
}
}
throw new Error("Prompt required.");
}
export default async function research (input) {
const prompt = resolvePrompt(input);
let res = await Gral.run({
instruction: system,
// input gets bumped to the front of the convo every turn
// pass as message instead
messages: [{role: "user", content: prompt}],
agentId: 7,
read: true,
write: [],
defaultTools: ['list-dir', 'read-file', 'find-files', 'search-files'],
});
console.log(res);
};