@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
126 lines • 6.77 kB
TypeScript
import type { ApplicationService } from '@adonisjs/core/types';
import type { A2aActionPolicy, A2aTurnService } from '../a2a/turn.js';
import type { Actor } from '../types.js';
import type { PoppyAuthenticate, PoppyPrincipal } from './auth.js';
import type { PoppyActionFormatter, PoppyDirectHooks, PoppyHandoffHooks, PoppyOperationsOptions, PoppyReplyAddons, PoppyTexts, PoppyVersionCheck } from './conversations.js';
import type { PoppyStore } from './store.js';
/**
* Shape of `config/poppy.ts`. Exposes an agent as the Company Agent of Personal Agent Protocol
* ("Poppy", 1.0) conversations — https://personalagentprotocol.org, §8:
*
* ```ts
* import { definePoppyConfig } from '@adonis-agora/agent/poppy'
*
* export default definePoppyConfig({
* path: 'poppy/conversations',
* agent: 'support',
* })
* ```
*
* Session headers and access tokens are verified by the resolver `@adonis-agora/authkit-server` installs in
* `Symbol.for('@adonis-agora/poppy:authenticate')`, or by `authenticate`. The endpoint is advertised
* in `poppy.json` as `agent.protocols: [{ type: 'poppy', endpoint, description }]`.
*
* @experimental Implements Personal Agent Protocol 1.0 (https://personalagentprotocol.org/docs/1.0/spec).
* The surface may still change between minor releases of this package while it settles.
*/
export interface PoppyConfig {
/** The endpoint path. Default `'poppy/conversations'`. */
path?: string;
/**
* Public origin of this app — the URL a DPoP proof is checked against. Set it in production
* (behind a proxy); the fallback is the request's own protocol and Host. Also REQUIRED for the
* provider to announce `{baseUrl}/{path}` in `Symbol.for('@adonis-agora/poppy:endpoints')`, where
* authkit reads it for `poppy.json` — without it the endpoint is not announced.
*/
baseUrl?: string;
/** The registered agent that answers. Default: the agent provider's default agent. */
agent?: string;
/**
* What the agent can help with, in plain language — the `description` of the `poppy` entry in
* `poppy.json` (§8.1), which personal agents read to decide whether a conversation can serve a
* task. Announced with the endpoint. Default `'Can help with anything.'`.
*/
description?: string;
/** Verifies Session headers and access tokens; overrides the global resolver. Neither → the endpoint answers 501. */
authenticate?: PoppyAuthenticate;
/**
* The actor of a principal the resolver gave none (`principal.actor`). Gets the default: the
* account (`{ id: accountId }`) when signed in, `poppy:<hash of client and user>` signed out. `personal_agent` and the token's `scope:<id>` roles are
* added whatever this returns.
*/
actorFor?: (principal: PoppyPrincipal, defaults: Actor) => Actor | Promise<Actor>;
/**
* Where conversations and their events live. Default `'lucid'` (tables created on first use);
* `'memory'` for a single process; or your own {@link PoppyStore} (e.g. `redisPoppyStore(…)`).
*/
store?: 'lucid' | 'memory' | PoppyStore;
/** Lucid connection for the `'lucid'` store. Default: the primary. */
connection?: string;
/**
* The database schema (a Postgres schema, a MySQL database) the `'lucid'` store's tables live in —
* every statement names it, never `SET search_path`. Default: the top-level `schema` of
* `config/agent.ts`, else none (the connection's current schema). Refused on SQLite.
*/
schema?: string;
/** Create the `'lucid'` store's tables on first use. Default `true`. */
autoCreateTables?: boolean;
/** What happens to `action` calls that park for approval. Default `'approve-delegated'`. */
actions?: A2aActionPolicy;
/** Bring a person in (§8.9). Without it, a handoff is declined by the Company Agent. */
handoff?: PoppyHandoffHooks;
/** Notified when a Direct Conversation opens or closes (§8.10). */
direct?: PoppyDirectHooks;
/** What the Company Agent says on its own. */
texts?: Partial<PoppyTexts>;
/**
* Whether a request in other versions than the conversation started in continues it (§8.2);
* `false` answers `version_mismatch`. Default: when the protocol versions are compatible.
*/
continueVersion?: (check: PoppyVersionCheck) => boolean | Promise<boolean>;
/**
* Words each action of a reply (executed, failed, refused) — the reply's text always tells them,
* `data.actions` carries them structured. Default: `texts.action*` + the confirmation detail.
*/
formatAction?: PoppyActionFormatter;
/**
* Ask for approval with the Operations extension (version 3): an action that waits for approval
* is not run — the reply carries the operation, and it runs once the personal agent sends its
* approval. Only for a personal agent that declares `"operations";v="3"`. Default: on when an
* operations service is installed (`@adonis-agora/authkit-poppy` with operations); `false` turns
* it off; `true` or options without a service log an error and stay off.
*/
operations?: boolean | PoppyOperationsOptions;
/**
* Links and disclosures for each reply of the Company Agent (Links and Disclosures extensions):
* sent as extension content to a personal agent that declares them, otherwise in the text.
*/
replyAddons?: PoppyReplyAddons;
/** Give up on a turn after this many ms. Default 120 000. */
timeoutMs?: number;
/** Largest accepted request body, in bytes. Default 1 MiB. */
maxBodyBytes?: number;
/** Cap on a read's `wait`, in seconds. Default 30. */
maxWaitSeconds?: number;
/** Close an event stream after this long (the Personal Agent reconnects). Default 5 min. */
streamMaxMs?: number;
/** Prune events older than this (a cursor there is `cursor_expired`). Default: keep them. */
retentionMs?: number;
/**
* Execute, in this process, a durable run its dispatcher left `pending` while a reply is read
* (`AgentService.drive`). Default `true`.
*/
drive?: boolean;
/** What runs a turn. Default: the agent provider's `AgentService` (see `A2aConfig.service`). */
service?: A2aTurnService | ((ctx: {
app: ApplicationService;
}) => A2aTurnService | Promise<A2aTurnService>);
}
/**
* Identity helper giving `config/poppy.ts` full type-checking.
*
* @experimental Implements Personal Agent Protocol 1.0 (https://personalagentprotocol.org/docs/1.0/spec).
* The surface may still change between minor releases of this package while it settles.
*/
export declare function definePoppyConfig(config: PoppyConfig): PoppyConfig;
//# sourceMappingURL=define_config.d.ts.map