/** * AgentSession — stateful wrapper over any IAgentRuntime-compatible object. * * Provides: * - AgentEvent → OutputLine conversion with streaming text accumulation * - State machine: starting → idle ↔ active ↔ waiting → stopped * - Circular output buffer (500 lines, see {@link MAX_OUTPUT_LINES}) * - send() routes to prompt() or reply() based on current state * - stop() disposes the runtime and fires optional cleanup * - onChange callback for reactive UIs (React forceUpdate, EventEmitter, etc.) * * Works with LocalRuntime (in-process) and AgentClient (remote/WebSocket). * Extend to add identity fields (id, name, profileName…): * * class MySession extends AgentSession { * constructor(readonly id: string, runtime: LocalRuntime | AgentClient) { * super(runtime); * } * } * * @docLink packages/sdk/concepts#agent-session */ import type { AgentEvent } from "@skaile/workspaces/types"; import type { OutputLine, SessionState } from "./types.js"; /** * Maximum number of {@link OutputLine} entries retained in {@link AgentSession.output}. * * When the buffer exceeds this limit the oldest lines are dropped from the front, * keeping memory use bounded for long-running sessions. * * @docLink packages/sdk/concepts#agent-session */ export declare const MAX_OUTPUT_LINES = 500; interface MinimalRuntime { prompt(message: string): Promise; reply(answer: string): Promise; abort(): Promise; dispose(): Promise; onEvent(handler: (e: AgentEvent) => void): void; offEvent(handler: (e: AgentEvent) => void): void; } export declare class AgentSession { protected readonly runtime: MinimalRuntime; state: SessionState; readonly output: OutputLine[]; onChange?: () => void; /** Pointer to the streaming text line being accumulated in-place. */ private currentTextLine; /** Registered in constructor so we can offEvent on stop. */ private readonly eventHandler; /** Optional cleanup hook registered by the factory (temp dir removal, etc.). */ private cleanupFn?; constructor(runtime: MinimalRuntime); /** Send a user message. Routes to reply() or prompt() based on state. */ send(text: string): void; /** Stop the session and dispose the runtime. */ stop(): void; /** Register a cleanup function called when the session stops. Used by the factory. */ _registerCleanup(fn: () => void): void; protected handleEvent(event: AgentEvent): void; private handleTextEvent; private handleToolCallEvent; private handleQuestionEvent; private handleErrorEvent; private handleStatusEvent; private handleSubagentEvent; private handleFinishedEvent; private handleStateChangedEvent; protected appendLine(line: OutputLine): void; protected notify(): void; private sealText; private trimOutput; } export {}; //# sourceMappingURL=agent-session.d.ts.map