import { PiClientEvent, PiHostUiResponse, PiModelInfo, PiSendMessageInput, PiThinkingLevel, PiThreadMetadata, PiThreadSnapshot } from "../types.js"; import { createAgentSession } from "@earendil-works/pi-coding-agent"; //#region src/node/ThreadSupervisor.d.ts /** The `model` shape `createAgentSession` accepts (a Pi `Model`), derived from * the SDK so the supervisor stays the only file that names it. The host resolves * it (e.g. env-seeded via `ModelRuntime.getModel`) and forwards it opaquely. */ type PiSessionModel = NonNullable[0]>["model"]; export interface PiThreadSupervisorOptions { /** Default workspace for `listThreads`/`createThread` when a call omits one. * Defaults to `process.cwd()`. */ workspacePath?: string; /** Global Pi config dir (`~/.pi/agent` by default). Forwarded to the SDK. */ agentDir?: string; /** Explicit model for new sessions. When omitted, Pi resolves from its own * settings, else the first available model. */ model?: PiSessionModel; } export declare class PiThreadSupervisor { private readonly records; /** In-flight cold opens, so concurrent calls for the same thread (e.g. an * SSE subscribe racing a send) share one `AgentSession` instead of creating * two on the same session file. */ private readonly pendingOpens; /** Per-send cancellation tokens for the window between a send starting its * cold open and launching the prompt. `cancelRun` flips every token for the * thread so the open resolves without firing the prompt, since the thread has * no live record yet for `session.abort()` to reach. A set (not one token per * thread) because a second send can start while the first shares the same * in-flight cold open, and cancel must reach both. */ private readonly startingSends; private readonly pendingDeletes; private readonly recordsBySessionFile; private readonly workspacePath; private readonly agentDir; private readonly model; /** Lazily-created Pi model/auth runtime backing the model catalog, picker, and * cold-snapshot context-window lookups. `ModelRuntime.create` is async (it * loads models.json and runs an availability refresh), so the promise is * cached and shared by every caller, keeping the supervisor constructor sync. */ private modelRuntimePromise; private readonly archivedSessionFiles; private readonly catalogCache; private readonly catalogInfoByThreadId; private generation; constructor(options?: PiThreadSupervisorOptions); listThreads(input?: { workspacePath?: string; includeArchived?: boolean; }): Promise; createThread(input?: { workspacePath?: string; title?: string; initialMessage?: PiSendMessageInput; }): Promise; getThread(threadId: string): Promise; sendMessage(threadId: string, input: PiSendMessageInput): Promise; cancelRun(threadId: string): Promise; /** Clear all queued messages, returning the cleared text. The session emits * its own `queue_update`, which the event relay forwards to subscribers. * Cold threads hold no live session and therefore no queue. */ clearQueue(threadId: string): Promise<{ steering: string[]; followUp: string[]; }>; getAvailableModels(): Promise; setModel(threadId: string, input: { provider: string; modelId: string; }): Promise; setThinkingLevel(threadId: string, level: PiThinkingLevel): Promise; renameThread(threadId: string, title: string): Promise; archiveThread(threadId: string): Promise; unarchiveThread(threadId: string): Promise; deleteThread(threadId: string): Promise; private deleteThreadNow; respondToHostUiRequest(threadId: string, response: PiHostUiResponse): Promise; subscribe(threadId: string, listener: (event: PiClientEvent) => void, options?: { includeSnapshot?: boolean; }): () => void; /** Tear down every record and cancel pending cold opens. Active runs are not * aborted implicitly; call `cancelRun` first if a graceful stop is wanted. */ dispose(): Promise; /** The process-wide Pi model/auth runtime, created on first use and shared by * every catalog/picker/snapshot call. Passing `authPath` makes `ModelRuntime` * back the credentials at `agentDir/auth.json`, so auth orchestration lives * inside the runtime rather than an explicit credential store. A creation * failure (e.g. the async availability refresh timing out) clears the cache so * the next call retries instead of rejecting forever. */ private getModelRuntime; private openSession; private ensureOpen; private openCold; private openWasCancelled; private throwIfOpenCancelled; private throwOpenCancelled; private listSessionInfos; private invalidateCatalog; private findSessionInfo; private rememberSessionInfos; private send; private onSessionEvent; private emitContextUsage; /** Stamp the per-thread seq and deliver to listeners. Pi invokes the session * subscription synchronously, so direct delivery is already ordered. */ private emit; private notifyListener; private liveStatusFor; private runStatus; private readinessOf; private queuedMessagesOf; private metadataOf; private snapshotOf; private snapshotFromSessionFile; } //#endregion //# sourceMappingURL=ThreadSupervisor.d.ts.map