import { n as Principal } from "./context-Ewez0LPe.js"; import { n as FileRef, r as FileStore } from "./agent-files-C7oZVYjV.js"; //#region src/agent-runtime.d.ts export declare const RUNTIME_API_VERSION = 7; export type ToolCall = { id: string; name: string; input: unknown; providerState?: string; }; export type Msg = { role: "user"; turnId: string; text: string; } | { role: "trigger"; turnId: string; text: string; by: string; } | { role: "assistant"; turnId: string; text: string; toolCalls: ToolCall[]; } | { role: "tool"; turnId: string; toolCallId: string; name: string; result: unknown; isError?: true; } | { role: "note"; turnId: string; by: string; kind: NoteKind; text: string; at: string; }; export type NoteKind = "operator_reply" | "observed" | (string & {}); export type ModelReply = { text: string; toolCalls: ToolCall[]; }; export type ToolSpec = { name: string; description: string; input: unknown; }; export type InboundEvent = { source: string; kind: "message" | "app_mention" | "reaction_added" | "reaction_removed" | "message_changed" | "rating" | "state_changed"; channelId: string; threadId?: string; teamId?: string; ts: string; user?: { id: string; name?: string; attested?: boolean; }; principal?: Principal; text?: string; reaction?: { name: string; itemTs: string; }; rating?: { stars: number; comment?: string; }; state?: string; raw?: unknown; }; export type ModelFinish = { reason: "stop" | "max_tokens" | "content_filter" | "malformed_tool_call" | "refusal" | "other"; raw?: string; }; export type ModelDelta = { type: "reasoning"; text: string; } | { type: "text"; text: string; } | { type: "done"; reply: ModelReply; finish?: ModelFinish; }; export type Model = (msgs: Msg[], tools: ToolSpec[], opts?: { system?: string; systemMode?: "append" | "replace"; }) => AsyncIterable; export type ChannelPolicy = { overlay?: string; overlayMode?: "append" | "replace"; denyTools?: string[]; }; export declare function replyStream(reply: ModelReply, finish?: ModelFinish): AsyncIterable; export declare function withSystem(model: Model, system: string): Model; export interface ToolContext { store: SessionStore; runtime: Runtime; agent: string; sessionId: string; callId: string; event?: InboundEvent; principal?: Principal; initiator?: Principal; requestInput(req: { id: string; prompt: string; schema?: unknown; answerers?: Answerers; }): Promise; files: FileStore; } export type Tool = { spec: ToolSpec; run: (input: any, ctx: ToolContext) => unknown; subagent?: boolean; requiresPrincipal?: boolean; mode?: ToolMode; }; export type ToolMode = "local" | "remote"; export declare function toolMode(run: Function, mode?: ToolMode): ToolMode; export interface SessionStore { appendMessage(m: Msg): void; messages(): Msg[]; hasOpeningMessage(turnId: string): boolean; getStep(id: string): unknown | undefined; putStep(id: string, output: unknown): void; delStep(id: string): void; getStatus(): string; setStatus(s: string): void; tx(fn: () => T): T; reset?(inTx?: () => void): number; unwrap(): H; } export type Answerers = { user: string; } | { policy: string; scope?: unknown; }; export type InputRequest = { id: string; prompt: string; schema?: unknown; answerers?: Answerers; }; export type AuthorizeAnswer = (a: { policy: string; scope?: unknown; by?: string; principal?: Principal; agent: string; session: string; request: InputRequest; }) => boolean | Promise; export declare class SuspendSignal extends Error { readonly request: InputRequest; readonly callId: string; constructor(request: InputRequest, callId: string); } export declare class FatalToolError extends Error { constructor(message: string, options?: { cause?: unknown; }); } export declare class ResumeAuthorizationError extends Error {} export type CancelReason = "replaced" | "reset" | "requested"; export declare class CancelSignal extends Error { readonly turnId: string; readonly reason: CancelReason; constructor(turnId: string, reason: CancelReason); } export type QueuedTurn = { turnId: string; userText: string; event?: InboundEvent; trigger?: ProactiveTrigger; hostContext?: unknown; queuedAt: string; }; type AnnouncementBody = { kind: "parked"; turnId: string; request: InputRequest; event?: InboundEvent; queued: number; } | { kind: "held"; turnId: string; inputId: string; queued: number; } | { kind: "resolved"; turnId: string; inputId: string; outcome: "answered" | "retired"; by?: string; }; export type InputAnnouncement = { id: string; agent: string; session: string; at: string; } & AnnouncementBody; export type ProactiveTrigger = { kind: "proactive"; by: string; note?: string; }; export type TurnTrigger = { kind: "inbound"; event: InboundEvent; } | ProactiveTrigger | { kind: "resume"; callId: string; }; export type TurnEvent = { type: "turn.started"; turnId: string; trigger: TurnTrigger; } | { type: "action.requested"; turnId: string; call: ToolCall; } | { type: "action.completed"; turnId: string; call: ToolCall; result: unknown; error?: string; } | { type: "file.attached"; turnId: string; callId: string; file: FileRef; } | { type: "message.completed"; turnId: string; text: string; } | { type: "input.requested"; turnId: string; request: InputRequest; } | { type: "input.resolved"; turnId: string; inputId: string; outcome: "answered" | "retired"; by?: string; } | { type: "turn.completed"; turnId: string; text: string; } | { type: "turn.failed"; turnId: string; error: TurnError; phase?: TurnFailurePhase; step?: string; } | { type: "turn.cancelled"; turnId: string; reason: CancelReason; } | { type: "reasoning.delta"; turnId: string; text: string; } | { type: "message.delta"; turnId: string; text: string; }; export type TurnResult = { status: "completed"; text: string; } | { status: "suspended"; request: InputRequest; } | { status: "failed"; error: TurnError; } | { status: "cancelled"; }; export type TurnError = { message: string; stack?: string; causeChain?: string[]; }; export type TurnFailurePhase = "model" | "tool"; export declare function serializeTurnError(err: unknown): TurnError; export interface EventSink { emit(e: TurnEvent): void; subscribe(cb: (e: TurnEvent) => void): () => void; } export type Crash = { at: "before-model-commit" | "after-model-commit" | "before-tool-commit" | "after-tool-commit"; step: string; }; export declare function runTurn(store: SessionStore, sink: EventSink, model: Model, tools: Tool[], opts: { turnId: string; userText: string; crash?: Crash; cancelled?: () => CancelReason | undefined; }, env: { runtime: Runtime; agent: string; sessionId: string; event?: InboundEvent; systemOverlay?: string; systemMode?: "append" | "replace"; deniedTools?: string[]; trigger?: TurnTrigger; announce?: boolean; files?: FileStore; }): Promise; export type Turn = { turnId: string; user: string; by?: string; steps: { name: string; done: boolean; result?: unknown; }[]; text?: string; note?: { by: string; kind: NoteKind; text: string; at: string; }; }; export declare function foldTranscript(msgs: Msg[]): Turn[]; export declare function mintTurnId(): string; export type TurnInput = { turnId?: string; userText: string; crash?: Crash; event?: InboundEvent; trigger?: ProactiveTrigger; replace?: boolean; ifSuspended?: "reject" | "queue"; hostContext?: unknown; }; export declare class AgentSession { private chain; private readonly running; private readonly cancelRequests; private pendingReset; onDequeue?: (turnId: string, queued: QueuedTurn) => void; onAnnounce?: (a: InputAnnouncement) => void | Promise; files?: FileStore; private flushing?; private flushAgain; readonly agent: string; readonly id: string; private readonly store; private readonly sink; private readonly model; private readonly tools; private readonly runtime; private readonly channelInstructions?; constructor(agent: string, id: string, store: SessionStore, sink: EventSink, model: Model, tools: Tool[], runtime: Runtime, channelInstructions?: Record); start(input: TurnInput): { turnId: string; queued?: true; }; private begin; cancel(turnId: string): boolean; cancelPending(reason?: CancelReason): string[]; private withTerminal; private track; result(turnId: string): Promise; resume(turnId: string, inputId: string, input: unknown, opts?: { by?: string; granted?: Answerers; }): { turnId: string; }; note(input: { by: string; kind: NoteKind; text: string; }): Promise<{ noteId: string; }>; pending(): { turnId: string; request: InputRequest; queued: number; } | undefined; heldTurns(): QueuedTurn[]; drain(): { turnId: string; } | undefined; private release; private parkedTurnId; private hold; flushAnnouncements(): Promise; private deliverOutbox; undeliveredAnnouncements(): InputAnnouncement[]; private outbox; reset(): Promise<{ previousSession: string; generation: number; }>; turn(input: Omit): Promise; observe(cb: (e: TurnEvent) => void, opts?: { turnId?: string; replay?: boolean; }): () => void; private foldEvents; transcript(): Turn[]; snapshot(): { transcript: Turn[]; status: string; }; idle(): boolean; } export interface Runtime { session(agent: string, id: string): AgentSession; } export declare function grantAnswer(session: AgentSession, resume: { turnId: string; inputId: string; by?: string; principal?: Principal; }, authorize: AuthorizeAnswer | undefined): Promise; //#endregion