UNPKG

@adonis-agora/agent

Version:

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

217 lines • 9.64 kB
/** * The wire format of Personal Agent Protocol ("Poppy", version 1.0, §8) conversations: requests, * messages, events, the conversation state and the error codes of §8.13. Hand-rolled like the A2A * surface — the rules are few and exact, and unknown fields are ignored everywhere (§3.1, §3.3). * * @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. */ /** The `protocol_version` this surface implements (§3.1). */ export declare const POPPY_PROTOCOL_VERSION = "1.0"; /** The `type` of this surface's entry in `poppy.json` `agent.protocols` (§8.1). */ export declare const POPPY_PROTOCOL_TYPE = "poppy"; /** `handoff` of the conversation state (§8.7): `pending` while the Company looks for a person. */ export type PoppyHandoff = 'none' | 'pending'; /** `responder` of the conversation state (§8.7): who handles the Company side. */ export type PoppyResponder = 'agent' | 'human'; export type PoppyAuthorType = 'agent' | 'human'; /** The four state fields every read reports (§8.7), each independent of the others. */ export interface PoppyState { /** The Company is still replying: a request accepted but not acted on, or a reply being written. */ working: boolean; handoff: PoppyHandoff; responder: PoppyResponder; /** The conversation takes no more messages (§8.12). */ closed: boolean; } /** Who wrote a message (§8.4). Only Company messages have `id`, `name` and `image`. */ export interface PoppyAuthor { type: PoppyAuthorType; id?: string; name?: string; image?: string; } /** * Facts about the User's situation (§8.4). Other fields are kept as sent; a field set to `null` * clears it. */ export interface PoppyContext { locale?: string | null; time_zone?: string | null; user_available?: boolean | null; [field: string]: unknown; } /** A message as the Personal Agent sends it (§8.4). Its ID is its request's ID (§8.3). */ export interface PoppyInboundMessage { author: { type: PoppyAuthorType; }; text?: string; data?: Record<string, unknown>; context?: PoppyContext; /** The last cursor the Personal Agent had read when it wrote the message — a hint (§8.4). */ as_of_cursor?: string; /** * Content defined by extensions, keyed by extension name (§8.4). Only the extensions this surface * supports and the request declares are kept (`operations`); the rest is ignored (§3.3). */ extensions?: Record<string, unknown>; } /** A message as it appears in a `message` event (§8.5): `role` says which side it came from. */ export interface PoppyEventMessage { id: string; role: 'user' | 'company'; author: PoppyAuthor; /** On a Company Agent message: the latest request it took into account — a hint (§8.4). */ as_of_request?: string; as_of_cursor?: string; text?: string; data?: Record<string, unknown>; context?: PoppyContext; /** Content defined by extensions, keyed by extension name (§8.4). */ extensions?: Record<string, unknown>; } /** The Links extension (version 1): a page a Company message refers to. */ export interface PoppyLink { /** The page's HTTPS URL. */ url: string; /** The page's name, as the message refers to it. */ title?: string; } /** The Disclosures extension (version 1): a notice that matters whatever else the message says. */ export interface PoppyDisclosure { text: string; } /** * What a Company message can carry besides its text and data — sent as `extensions.links` and * `extensions.disclosures` to a Personal Agent that declares those extensions; otherwise put in the * text, so a disclosure always reaches the User. */ export interface PoppyMessageAddons { links?: PoppyLink[]; disclosures?: PoppyDisclosure[]; } /** The versions of the message extensions this surface speaks. */ export declare const POPPY_LINKS_VERSION = "1"; export declare const POPPY_DISCLOSURES_VERSION = "1"; export type PoppyEventType = 'message' | 'state' | 'authorization' | 'user_requested' | 'direct_opened' | 'direct_closed'; /** One event of a conversation (§8.5): `id`, `type`, `created_at`, and the type's own fields. */ export interface PoppyEvent { id: string; type: PoppyEventType | (string & {}); created_at: string; [field: string]: unknown; } /** The type-specific fields of a new event — what the store appends. */ export type PoppyEventBody = { type: 'message'; message: PoppyEventMessage; } | { type: 'state'; handoff: PoppyHandoff; responder: PoppyResponder; closed: boolean; } | { type: 'authorization'; error: 'insufficient_scope'; scope: string; } | { type: 'user_requested'; reason: string; } | { type: 'direct_opened' | 'direct_closed'; conversation_id: string; }; /** The conversation errors of §8.13, plus the request errors this surface answers. */ declare const ERRORS: { readonly conversation_not_found: 404; readonly conversation_closed: 409; readonly direct_conversation_open: 409; readonly request_id_conflict: 409; readonly invalid_cursor: 400; readonly cursor_expired: 410; readonly invalid_request: 400; /** §3.3 — a request handled only with an extension the Personal Agent does not declare. */ readonly extension_required: 403; /** §3.4 — `Poppy-Version` missing, or not compatible with a version this Company serves. */ readonly version_unsupported: 400; /** §8.2 — the conversation started in other versions and is not continued in these. */ readonly version_mismatch: 409; /** Answered as a challenge without an error code (§7): the request needs the account. */ readonly account_required: 401; readonly not_found: 404; readonly method_not_allowed: 405; readonly request_too_large: 413; readonly not_implemented: 501; readonly server_error: 500; }; export type PoppyErrorCode = keyof typeof ERRORS; /** * A Poppy error, answered as `{ "error": code, … }` like an OAuth error response (§8.13). `extra` * carries what a code adds — `conversation_id` for `direct_conversation_open`, `extension` for * `extension_required`, `protocol_version` for `version_mismatch`. An app hook may throw one to * refuse a request. */ export declare class PoppyError extends Error { readonly code: PoppyErrorCode; readonly extra: Record<string, unknown>; constructor(code: PoppyErrorCode, description?: string, extra?: Record<string, unknown>); get status(): number; toJSON(): Record<string, unknown>; } export declare function isPoppyId(value: unknown): value is string; /** A new id of `kind` — `cnv_…`, `msg_…`. */ export declare function newPoppyId(prefix: 'cnv' | 'msg'): string; /** A stable id derived from `seed` — what lets a re-read turn produce the same company message. */ export declare function derivedPoppyId(prefix: 'msg', seed: string): string; /** * Whether `version` (a `Poppy-Version` value) is compatible with the version this surface serves * (§3.4): from 1.0, the same major version. */ export declare function isCompatiblePoppyVersion(version: string | null | undefined, served?: string): boolean; /** * The extensions a `Poppy-Extensions` header declares (§3.4): an RFC 9651 List of Strings, each * with its version in the `v` parameter — `{ name: version }`. A header that fails to parse * declares none. */ export declare function parsePoppyExtensions(header: string | undefined): Record<string, string>; /** * Links and disclosures checked for a Company message: a link needs an HTTPS `url`, a disclosure * its `text` (Links §3, Disclosures §3). Throws on anything else — it is the app's own input. */ export declare function checkPoppyAddons(addons: PoppyMessageAddons): PoppyMessageAddons; /** A validated `POST {endpoint}` / `POST {endpoint}/{id}/messages` body (§8.3). */ export interface PoppySendBody { /** The request ID, chosen by the Personal Agent — also its message's ID. */ id: string; /** Absent only when accepting a `user_requested` event (§8.10). */ message?: PoppyInboundMessage; /** Only on `POST {endpoint}`: start a Direct Conversation under this one (§8.10). */ parentConversationId?: string; /** Only with `parentConversationId`: the `user_requested` event this accepts (§8.10). */ userRequestedEventId?: string; } /** A validated handoff, handoff-cancel or close body: only its request ID (§8.9, §8.12). */ export interface PoppyRequestBody { id: string; } /** * Parse a message request (§8.3, §8.4, §8.10). Unknown fields — on the body, the message or its * context — are ignored, never refused (§3.3). Only the fields the protocol defines are kept. */ export declare function parseSendBody(raw: string, opts: { allowParent: boolean; }): PoppySendBody; /** * Parse a handoff, handoff-cancel or close request: its request ID (§8.9, §8.12). Other fields * are tolerated — extensions may add them (§3.3). */ export declare function parseRequestBody(raw: string): PoppyRequestBody; /** * The fingerprint a retry is compared by (§8.3): the request's path (`new`, `<id>/messages`, * `<id>/handoff`, …) and its body. Unknown fields were dropped by the parser, so a retry that adds * one is still the same request; query parameters (`cursor`, `wait`) are not part of it. */ export declare function requestFingerprint(path: string, body: object): string; export {}; //# sourceMappingURL=protocol.d.ts.map