/** * backend/api.ts — APIBackend: Claude Agent SDK subprocess bridge. * * Spawns a Claude Code subprocess via the Agent SDK's query() function. * Returns the assistant's response synchronously — no iTerm2 required. * * Supports multiple parallel sessions, each with its own conversation * context, working directory, and Claude session UUID for resume. * * Tracks live session status (thinking, tool_running, compacting, etc.) * so consumers can show meaningful status via /ss. */ import type { Backend, APIBackendConfig, BackendHealth } from "../types/backend.js"; /** Live status of a session's current deliver() call */ export type SessionState = "idle" | "thinking" | "tool_running" | "compacting" | "done" | "error"; /** Live status snapshot for a session */ export interface SessionStatus { state: SessionState; /** Current tool name (when state === "tool_running") */ currentTool?: string; /** How long the current tool has been running (seconds) */ toolElapsed?: number; /** Number of turns completed so far */ turns: number; /** Accumulated cost in USD */ costUsd: number; /** Result subtype from the last completed deliver() */ lastResult?: string; /** Error messages from the last completed deliver() */ lastErrors?: string[]; /** Permission denials encountered */ permissionDenials: number; /** Timestamp when deliver() started */ startedAt?: number; } /** Metadata for a single API session */ export interface APISession { /** External session ID (e.g. "api-1") */ id: string; /** Human-readable name */ name: string; /** Working directory for this session */ cwd: string; /** Claude Agent SDK session UUID for resume (set after first message) */ claudeSessionId?: string; /** Timestamp of last activity */ lastActive: number; } export declare class APIBackend implements Backend { readonly name: string; readonly type: "api"; readonly provider: APIBackendConfig["provider"]; readonly model: string; private readonly config; /** All active API sessions */ private readonly sessions; /** Live status per session */ private readonly statuses; /** Currently active session ID */ private _activeSessionId; /** Auto-increment counter for session IDs */ private nextSessionNum; constructor(config: APIBackendConfig & { name?: string; }); /** Get the active session ID */ get activeSessionId(): string; /** Switch the active session */ set activeSessionId(id: string); /** Create a new session and make it active */ createSession(name: string, cwd?: string): APISession; /** End a session and switch to another if it was active */ endSession(id: string): boolean; /** Clear the active session's conversation (starts fresh on next message) */ clearSession(id?: string): void; /** List all sessions ordered by number */ listSessions(): APISession[]; /** Get session by list index (1-based, matching /s display) */ getSessionByIndex(index: number): APISession | undefined; /** Get live status for a session (or the active session) */ getStatus(sessionId?: string): SessionStatus; /** Get a formatted status string suitable for display */ formatStatus(): string; private formatState; deliver(message: string, sessionId?: string): Promise; health(): Promise; private anthropicDeliver; private ollamaDeliver; private openaiDeliver; } //# sourceMappingURL=api.d.ts.map