import type { PromptResponse, SessionNotification } from '@agentclientprotocol/sdk'; import { type RuntimeEvent, type RuntimeUsage, type SessionConfigUpdatedEvent, type SessionModesUpdatedEvent, type SessionModelsUpdatedEvent, type TranscriptState } from './session-data.js'; import { type RuntimeEventHandlers } from './runtime-event.js'; import type { RuntimeHost } from './host.js'; import type { AgentProfile } from './agents.js'; export interface AcpConnectionLike { prompt(params: { sessionId: string; prompt: Array<{ type: 'text'; text: string; }>; }): Promise; cancel(params: { sessionId: string; }): Promise; setSessionMode?(params: { sessionId: string; modeId: string; }): Promise; unstable_setSessionModel?(params: { sessionId: string; modelId: string; }): Promise; unstable_closeSession?(params: { sessionId: string; }): Promise; dispose?(): Promise; } export type SessionStatus = 'idle' | 'running' | 'cancelling' | 'disposed'; export interface TurnStartedEvent { type: 'turn.started'; sessionId: string; at: number; turnId: string; } export interface TurnCompletedEvent { type: 'turn.completed'; sessionId: string; at: number; turnId: string; stopReason: string | null; } export interface TurnFailedEvent { type: 'turn.failed'; sessionId: string; at: number; turnId: string; error: string; } export interface TurnCancelledEvent { type: 'turn.cancelled'; sessionId: string; at: number; turnId: string; reason: string; } export interface StatusChangedEvent { type: 'status.changed'; sessionId: string; at: number; status: SessionStatus; previousStatus: SessionStatus | null; } export type RuntimeSessionEvent = RuntimeEvent | TurnStartedEvent | TurnCompletedEvent | TurnFailedEvent | TurnCancelledEvent | StatusChangedEvent; export interface PromptResult { stopReason: string | null; usage?: RuntimeUsage | null; } interface RuntimeSessionOptions { sessionId: string; agent: AgentProfile; host: RuntimeHost; connection: AcpConnectionLike; initialEvents?: RuntimeEvent[]; onEvent?: (event: RuntimeSessionEvent) => void; } export declare class RuntimeSession { readonly sessionId: string; readonly agent: AgentProfile; private readonly host; private readonly connection; private readonly onEvent; private readonly listeners; private readonly transcriptState; private status; private currentTurnId; private currentMessageId; private currentReasoningId; private cancelling; private currentTurnRuntimeEventCount; private currentTurnToolEventSeen; constructor(options: RuntimeSessionOptions); /** * Read-only snapshot of the session's reducer state (messages, reasoning, * tool calls, mode/model state, open stream ids, usage). Updates in place as * events arrive — do not mutate. Useful for reading the initial * mode / model state populated by `newSession` / `loadSession` before the * first handler has a chance to attach, or for rendering a fresh UI from a * mid-stream snapshot. */ get transcript(): TranscriptState; /** * Subscribe to events using a per-variant handler map. Handlers are keyed by * the camelCase form of the event type (`message.delta` → `messageDelta`, * `tool.start` → `toolStart`, `turn.completed` → `turnCompleted`, ...). * Each handler receives the matching event variant with full type narrowing. * * ```ts * session.on({ * messageDelta: (e) => process.stdout.write(e.delta), * toolStart: (e) => process.stdout.write(`[${e.toolCallId}] ${e.title}\n`), * turnCompleted: (e) => process.stdout.write(`done: ${e.stopReason}\n`), * }); * ``` */ on(handlers: RuntimeEventHandlers): () => void; /** * Subscribe to a specific event type. The listener parameter is narrowed to * the matching event variant (e.g. `'tool.start'` → `ToolStartEvent`), so * fields like `e.toolCallId` / `e.delta` are typed. */ on(type: K, listener: (event: Extract) => void): () => void; /** * Subscribe to every event with the full `RuntimeSessionEvent` union. */ on(type: 'event', listener: (event: RuntimeSessionEvent) => void): () => void; private subscribe; getSnapshot(): TranscriptState; prompt(text: string): Promise; cancel(): Promise; /** * Switch the active mode for this session via ACP `session/set_mode`. Throws * if the connected agent does not implement the request. */ setMode(modeId: string): Promise; /** * Switch the active model for this session via ACP `session/set_model` * (currently exposed by the SDK as `unstable_setSessionModel`). Throws if * the connected agent does not implement the request. */ setModel(modelId: string): Promise; /** * Close this session via ACP `session/close` (currently exposed by the SDK as * `unstable_closeSession`). The agent must cancel any in-flight work and * release server-side state. * * Requires the agent to advertise the `sessionCapabilities.close` capability. * After this resolves, the session is also disposed locally. * * If the agent does not advertise the capability, this falls back to * {@link RuntimeSession.dispose} so callers can use it unconditionally. */ close(): Promise; dispose(): Promise; /** ES Explicit Resource Management: enables `await using session = await acp.newSession(...)`. */ [Symbol.asyncDispose](): Promise; /** @internal Called by the runtime to deliver an incoming ACP `session/update`. */ handleSessionUpdate(notification: SessionNotification): void; hydrateInitialState(initialEvents: RuntimeEvent[]): void; private ensureMessageId; private ensureReasoningId; private flushPendingStreams; private emitRuntimeEvent; private waitForPromptTailQuiescence; private hasOpenCurrentTurnTools; private emitEvent; private dispatch; private resetTurnState; private setStatus; } export declare function createInitialSessionEvents(params: { sessionId: string; at?: number; configOptions?: SessionConfigUpdatedEvent['configOptions']; modes?: SessionModesUpdatedEvent['state']; models?: SessionModelsUpdatedEvent['state']; }): RuntimeEvent[]; export {};