@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
48 lines • 1.88 kB
JavaScript
/**
* Where the generated tools barrel is written, relative to the app root. The agent provider imports
* THIS path at boot (build-time codegen) instead of scanning `app/agent_tools` with `readdir` at
* runtime. Kept in sync with the module the provider imports.
*/
export const GENERATED_TOOLS_OUTPUT = '.adonisjs/agent/tools.ts';
/**
* An AdonisJS **Assembler `init` hook** that generates a typed barrel of the app's `app/agent_tools/`
* directory at build/dev time — exactly how `@adonisjs/core` generates the controllers/events barrels
* and how `@adonis-agora/durable`'s steps hook does for `app/steps`. The provider imports the generated
* `.adonisjs/agent/tools.ts` at boot and registers every `@AiTool`/`defineTool` export it finds
* (falling back to the runtime scan when the barrel is absent).
*
* Register it in `adonisrc.ts`:
*
* ```ts
* export default defineConfig({
* hooks: {
* init: [() => import('@adonis-agora/agent/hooks/tools')],
* },
* })
* ```
*/
export function toolsHook(options = {}) {
const source = options.source ?? 'app/agent_tools';
const importAlias = options.importAlias ?? '#agent_tools';
const output = options.output ?? GENERATED_TOOLS_OUTPUT;
return {
run(_parent, _hooks, indexGenerator) {
indexGenerator.add('agent_tools', {
source,
as: 'barrelFile',
exportName: 'tools',
importAlias,
removeSuffix: 'tool',
skipSegments: ['agent_tools'],
output,
comment: true,
});
},
};
}
/**
* The default export is the hook object itself, so `() => import('@adonis-agora/agent/hooks/tools')`
* in `adonisrc.ts` resolves to a ready hook (the assembler calls its `run`).
*/
export default toolsHook();
//# sourceMappingURL=tools.js.map