UNPKG

@adonis-agora/agent

Version:

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

152 lines • 7.15 kB
import type { CompanyClient } from './company.js'; import type { ConversationEvent, ConversationState, EventMessage, EventsPage, OutgoingMessage, PoppyProtocolEntry, StartConversationResponse, TextDelta } from './types.js'; /** * A fresh request ID: URL-safe base64, prefixed, unique for the User across all its requests (8.2, * 8.3). A message's ID is its request's. */ export declare function newRequestId(prefix?: string): string; /** A request ID for a message (8.3). */ export declare function newMessageId(): string; /** * The `poppy` conversation protocol entries (8.1), with their `description` of what the agent there * can help with, so a caller can choose between them. Unknown types are skipped. */ export declare function poppyProtocols(company: CompanyClient): PoppyProtocolEntry[]; /** The first `poppy` conversation protocol entry (8.1). */ export declare function poppyProtocol(company: CompanyClient): PoppyProtocolEntry | undefined; /** `author.type` as 8.4 says to read it: one this client doesn't know is `agent`. */ export declare function authorTypeOf(message: EventMessage | undefined): 'agent' | 'human'; /** Whether a message is the Company's: any `role` other than `user` is content from the Company (8.4). */ export declare function isFromCompany(message: EventMessage | undefined): boolean; /** The state fields as 8.7 says to read them: unknown `handoff` is `pending`, unknown `responder` `human`. */ export declare function readState(raw: { [K in keyof ConversationState]?: ConversationState[K] | undefined; } | undefined): ConversationState; export type StreamItem = { kind: 'event'; event: ConversationEvent; } | { kind: 'delta'; delta: TextDelta; } /** `working` changed (8.6). It isn't an event and has no ID. */ | { kind: 'working'; working: boolean; } /** The reader reconnected; any provisional `text-delta` pieces must be dropped (8.6). */ | { kind: 'reconnected'; } /** `cursor_expired`: the read restarted from the beginning; part of history is missing. */ | { kind: 'history_gap'; }; export interface FollowOptions { signal?: AbortSignal | undefined; /** Stop once `working` is false (the Company's reply is complete) or the conversation is closed. */ untilSettled?: boolean | undefined; /** Prefer SSE (default). When the Company answers with JSON, long-polling is used. */ stream?: boolean | undefined; /** Long-poll `wait` seconds. */ wait?: number | undefined; } type PostOptions = { wait?: number | undefined; cursor?: string | undefined; }; /** * Client for one Company's Poppy conversation endpoint (section 8). Every request carries the * Session header (8.2) and, when signed in, an access token, through `CompanyClient.fetch`. Every * POST carries a request `id`, so a retry is safe (8.3). A successful POST means the Company accepted * the request: what it did comes from the events and the state (8.5, 8.7). */ export declare class ConversationClient { #private; readonly company: CompanyClient; readonly endpoint: string; /** What the agent at this endpoint can help with (8.1). */ readonly description: string | undefined; /** Narrower scope for every request of this client (4.4), when set. */ private readonly scope?; constructor(company: CompanyClient, entry?: PoppyProtocolEntry | undefined, options?: { scope?: string | undefined; }); private url; /** * POST with retries on network errors / 5xx. Safe because the request ID makes it idempotent: the * Company returns the original response for a repeat with the same path and body (8.3). */ private post; private remember; /** * 8.4: `author.type` agent or human, at least one field; and extension content only for an * extension this agent uses with the Company in the chosen version, never content only Company * messages carry (links, disclosures). */ private checkMessage; /** Notes operations and declines in an event (Operations extension), then hands it on. */ private note; /** The cursor this client last handled for a conversation, if any. */ cursorOf(id: string): string | undefined; /** `as_of_cursor` on a message the Personal Agent wrote (8.4): never on the User's own words. */ private withAsOf; /** * Starts a conversation with its first message (8.3), or a Direct Conversation with * `parentConversationId` (8.10). Accepting a `user_requested` event (`userRequestedEventId`) may * leave the message out, so the Company speaks first. */ start(message: OutgoingMessage | undefined, opts?: PostOptions & { /** The request ID; a retry of the same start reuses it. */ requestId?: string | undefined; parentConversationId?: string | undefined; userRequestedEventId?: string | undefined; }): Promise<StartConversationResponse>; /** Sends another message (8.3). HTTP 202 with `conversation_id`, or a read with `wait`. */ send(id: string, message: OutgoingMessage, opts?: PostOptions & { requestId?: string | undefined; }): Promise<StartConversationResponse>; /** One read of events after `cursor` (8.5). */ read(id: string, opts?: { cursor?: string | undefined; wait?: number | undefined; }): Promise<EventsPage>; /** Asks for a person at the Company (8.9). Accepted (202): `handoff` and `responder` tell the outcome. */ handoff(id: string, opts?: PostOptions & { requestId?: string | undefined; }): Promise<StartConversationResponse>; /** * Withdraws a request for a person (8.9). The Company MAY keep looking: read `handoff` and * `responder`, never assume the cancel took effect. */ cancelHandoff(id: string, opts?: PostOptions & { requestId?: string | undefined; }): Promise<StartConversationResponse>; /** * Closes the conversation (8.12): HTTP 202. A close doesn't wait its turn, so the Company may drop * requests it hasn't acted on: read until `working` is false first (`collect`) when that matters. */ close(id: string, opts?: { requestId?: string | undefined; }): Promise<StartConversationResponse>; /** * Reads (long-polling, JSON) until `working` is false and `has_more` is false (8.5, 8.7), returning * the new events and the state. Used by the autonomous `ask` mode. */ collect(id: string, opts?: { timeoutMs?: number | undefined; wait?: number | undefined; }): Promise<{ events: ConversationEvent[]; state: ConversationState; }>; /** * Follows a conversation's events in order, from the saved cursor: SSE when the Company streams * (reconnecting with `Last-Event-ID`), long-polling otherwise. Skips event IDs it already handled, * restarts from the beginning on `cursor_expired`, persists the cursor, and skips SSE event names * and event types it doesn't know (8.5, 8.6). */ follow(id: string, opts?: FollowOptions): AsyncGenerator<StreamItem>; } export {}; //# sourceMappingURL=conversations.d.ts.map