UNPKG

@adonis-agora/agent

Version:

Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.

55 lines • 2.57 kB
/** * 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')], * }, * }) * ``` * * With options, register a lazy import whose default is the factory's result: * `init: [async () => ({ default: toolsHook({ source: 'app/ai/tools', importAlias: '#ai_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; // A FUNCTION, not an object with a `run` method. The assembler adds a lazily imported hook's // default export to `@poppinss/hooks`, which invokes a handler as // `typeof handler === 'function' ? handler(...data) : handler.handle(action, ...data)` // so the previous `{ run }` default export failed every build that registered // `() => import('@adonis-agora/agent/hooks/tools')` (what `node ace configure` writes) with // `handler.handle is not a function`, and mismatched the assembler's `LazyImport` hook type. return function generateToolsBarrel(_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 function itself, so `() => import('@adonis-agora/agent/hooks/tools')` * in `adonisrc.ts` resolves to a handler the assembler can call directly. */ export default toolsHook(); //# sourceMappingURL=tools.js.map