UNPKG

agents

Version:

A home for your AI agents

204 lines (202 loc) • 5.92 kB
import { _ as TranscriptMessage, l as Json, m as ResponseChunk } from "./protocol-CukuI73M.js"; //#region src/experimental/channels/harness.d.ts type SessionId = string; /** One agent harness hosted in a Durable Object. */ interface AgentHarness { readonly sessions: HarnessSessions; /** A handle on one session. Without an id, the harness's default session. */ session(id?: SessionId): HarnessSession; } interface HarnessSessions { create(): Promise<HarnessSession>; /** A new session that sees `from`'s history so far. */ fork(from: SessionId): Promise<HarnessSession>; list(): Promise<SessionInfo[]>; } type SessionInfo = { readonly id: SessionId; readonly parent?: SessionId; readonly busy: boolean; }; interface HarnessSession { readonly id: SessionId; /** A harness that takes no tool answers rejects them. */ submit( input: (HarnessInput | ToolAnswer) & HarnessInputFrom, options?: SubmitOptions ): Promise<Receipt>; /** Stop one operation, or, without an id, everything in the session. */ abort(operationId?: string): Promise<boolean>; wait(operationId: string, signal?: AbortSignal): Promise<OperationResult>; /** Start a new context, optionally from a handoff note. */ reset(handoff?: string): Promise<void>; /** The current state, then every change, in order. */ watch(): Promise<SessionWatch>; } type InputPart = | { readonly type: "text"; readonly text: string; } | { readonly type: "file"; readonly mediaType: string; readonly url: string; readonly filename?: string; }; type HarnessInput = { readonly parts: readonly InputPart[]; /** * The caller's id for the user message this places. Default: the * operation id. */ readonly messageId?: string; }; /** * Who sent an input, once a conversation has several participants. (From the * "later" draft, adopted early: a client tool's result is taken only from * the participant whose client runs it.) */ type HarnessInputFrom = { readonly from?: { readonly participantId: string; }; }; /** * A reply to something the agent asked for. Like a message, it makes the * agent act, so it is submitted, queued, deduplicated and settled as an * operation. (From the "later" draft, adopted early.) */ type ToolAnswer = | { readonly type: "approval"; readonly approvalId: string; readonly approved: boolean; readonly reason?: string; } | { readonly type: "tool-result"; readonly toolCallId: string; readonly result: | { readonly ok: true; readonly output: Json; } | { readonly ok: false; readonly errorText?: string; }; }; type SubmitOptions = { /** Idempotency key. Submitting the same id twice returns the same receipt. */ readonly operationId?: string; readonly whenBusy?: "followUp" | "steer"; }; type Receipt = { readonly operationId: string; readonly session: SessionId /** False when this operation id was already submitted. */; readonly accepted: boolean; }; type OperationStatus = | { readonly operationId: string; readonly status: "queued"; } | { readonly operationId: string; readonly status: "placed"; } | { readonly operationId: string; readonly status: "done"; readonly text?: string; } | { readonly operationId: string; readonly status: "unanswered"; readonly reason?: string; }; type OperationResult = Extract< OperationStatus, | { status: "done"; } | { status: "unanswered"; } > & { readonly session: SessionId; }; type SessionWatch = { readonly state: SessionState; start(listener: (events: readonly SessionEvent[]) => Promise<void>): void; stop(): Promise<void> /** Settles when the watch ends, stopped or not. */; readonly closed: Promise<void>; }; /** Resume is from state: no event log, no cursors. */ type SessionState = { /** The active transcript, since the newest reset. */ readonly messages: readonly TranscriptMessage[] /** Operations not settled yet, oldest first. */; readonly pending: readonly OperationStatus[] /** The run in progress, with its in-flight message. */; readonly run?: { readonly operations: readonly string[]; /** * The in-flight message so far, as chunks, with parts still streaming * left open. The watch's `chunk` events continue these parts. (The first * draft had a `TranscriptMessage` here, which later chunks could not * continue without showing the message twice.) */ readonly partial?: readonly ResponseChunk[]; }; }; type SessionEvent = | { readonly type: "operation"; readonly status: OperationStatus; } | { readonly type: "run-start"; readonly operations: readonly string[]; } | { readonly type: "run-end"; readonly operations: readonly string[]; } /** A streamed delta of the in-flight message. Part ids are unique per run. */ | { readonly type: "chunk"; readonly chunk: ResponseChunk; } /** A message saved to the transcript; replaces any message with its id. */ | { readonly type: "message"; readonly message: TranscriptMessage; } /** * The context was reset. Not in the first draft: without it a watcher * could not tell the active transcript restarted. Messages that follow * belong to the new context. */ | { readonly type: "reset"; }; //#endregion export { HarnessSessions as a, OperationStatus as c, SessionId as d, SessionInfo as f, ToolAnswer as g, SubmitOptions as h, HarnessSession as i, Receipt as l, SessionWatch as m, HarnessInput as n, InputPart as o, SessionState as p, HarnessInputFrom as r, OperationResult as s, AgentHarness as t, SessionEvent as u }; //# sourceMappingURL=harness-B6B9S3rb.d.ts.map