@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
57 lines • 3.24 kB
TypeScript
import type { ActorResolver } from './spi/actor-resolver.js';
import type { Actor, AgentDefinition } from './types.js';
/**
* Pick the effective {@link ActorResolver} for a turn: an agent's own `actorResolver` (from its
* {@link AgentDefinition}) wins over the module-global resolver, letting different agents read the
* caller from different places (e.g. one that reads the actor from the HTTP body). Falls back to
* `globalResolver` when the agent is unknown (`undefined` definition) or declares none — identical to
* the single-resolver behavior before per-agent overrides existed.
*/
export declare function resolveActorResolver(globalResolver: ActorResolver, definition: Pick<AgentDefinition, 'actorResolver'> | undefined): ActorResolver;
/**
* The default {@link ActorResolver} the provider installs when `config/agent.ts` sets no
* `actorResolver`. It throws on every request rather than inventing an identity — security by
* default. Wire a real resolver (e.g. {@link AuthActorResolver}) or the opt-in
* {@link HeaderActorResolver} via `defineConfig({ actorResolver })`.
*/
export declare class UnconfiguredActorResolver implements ActorResolver {
resolve(): Actor;
}
/**
* A development / gateway {@link ActorResolver} that trusts request headers:
* `x-actor-id` (required), `x-actor-role` (comma-separated → `roles`), `x-tenant-ref`.
*
* **Security:** it throws when `x-actor-id` is absent — it never fabricates an identity and never
* grants a default role (an actor with no `x-actor-role` gets `roles: []`, i.e. no tools). Trusting
* client headers is only safe behind a gateway that strips and re-sets them from an authenticated
* principal. Real deployments should provide their own resolver (or {@link AuthActorResolver}) that
* reads a verified session/JWT instead.
*/
export declare class HeaderActorResolver implements ActorResolver {
resolve(ctx: unknown): Actor;
}
/** Options for {@link AuthActorResolver}. */
export interface AuthActorResolverOptions {
/** Map the authenticated user to an {@link Actor}. Defaults to reading `id`/`roles`/`tenantRef`. */
toActor?: (user: unknown) => Actor;
/**
* The `@adonisjs/auth` guards to check the request with, in order (`['web', 'api']`). Default:
* the default guard.
*/
guards?: string[];
}
/**
* Reads Adonis's authenticated principal (`ctx.auth.user`, from `@adonisjs/auth`) into an
* {@link Actor}. The agent routes run no auth middleware, so when no guard has tried the request
* yet the resolver checks it itself — `ctx.auth.check()` (or `checkUsing(guards)`), which reads a
* session cookie or a bearer token and never throws for an anonymous request. Fail-closed: throws
* (the routes answer `401`) when no user is authenticated rather than fabricating one. Pass a
* `toActor` mapper when your user model doesn't expose `id`/`roles`/`tenantRef` directly (e.g. to
* pull roles from a relation). This is the resolver most apps wire in `config/agent.ts`.
*/
export declare class AuthActorResolver implements ActorResolver {
private readonly options;
constructor(options?: AuthActorResolverOptions);
resolve(ctx: unknown): Promise<Actor>;
}
//# sourceMappingURL=actor-resolver.d.ts.map