UNPKG

@adonis-agora/agent

Version:

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

50 lines • 3.2 kB
import type { ApplicationService } from '@adonisjs/core/types'; /** * Wires `@adonis-agora/agent` into the AdonisJS application from `config/agent.ts`: * * - `register()` binds the shared `ToolRegistry` + `AgentRegistry` singletons. * - `boot()` discovers tools (the generated `hooks/tools` barrel first, then an `app/agent_tools` * readdir fallback), registers config-level functional tools and synthesizes `agent`-kind delegate * tools for `delegatesTo` edges, builds the runtime graph (store/sink/quota/authorizer/actor-resolver * → deps factory → the inline runner → the `AgentService` facade), and mounts the `/agent` routes * under `config.path` — plus optional routes (`POST /agent/attachments` when `attachments` is * configured; `/agent/approvals/mine` when `governanceQueries` is configured; the cross-actor * `/agent/governance/*` read-model when `governanceQueries` is configured AND a `governanceAuthorize` * gate exists). * * Every route resolves the acting actor (401 if it can't). Run/thread routes (stream re-attach, * cancel, tool-call approve/reject, `threads/:id` read/delete/fork) are additionally owner-scoped: * a caller may act only on runs/threads it owns, unless it is governance-privileged (`governanceAuthorize`). * The cross-actor `/agent/governance/*` read-model fails closed by omission: without a * `governanceAuthorize` gate it is not mounted at all (404). `approvals/mine` is always scoped to the * caller's own pending approvals and mounts regardless of the gate. * * The selected store (`lucid`/`memory`) is built lazily from the config so its peer (`@adonisjs/lucid`) * loads only when chosen. Agent lifecycle events are emitted structurally by core onto the * `agora:agent:*` diagnostics channel when `@adonis-agora/diagnostics` is installed — no bridge needed. */ export default class AgentProvider { #private; protected app: ApplicationService; constructor(app: ApplicationService); register(): void; boot(): Promise<void>; /** * Provision (or repair) the agent tables once, as the app starts — before the HTTP server takes a * request and before a test runner opens its first transaction. Left to first use, the DDL ran * inside whatever the first caller had open: a Japa suite's global transaction held the locks the * DDL needed and the run hung. * * Every store that manages its own schema exposes `ensureSchema()` (the three Lucid stores and the * Lucid token sink do, and it is a no-op under `autoCreateTables: false`); a custom store may too. Skipped for ace commands * (`console`): `migration:run` must not find the tables already made by the app it is booting, and * `list:routes` must not need a database. A command that does use the agent (a durable worker) * falls back to first use, which is the same idempotent call. * * A failure here is reported, not fatal: the app may be starting ahead of its database, and the * first use retries — and surfaces the error to the caller if it is still there. */ start(): Promise<void>; shutdown(): Promise<void>; } //# sourceMappingURL=agent_provider.d.ts.map