import type * as LlmsProviders from "@cline/llms"; import type { AgentMode, AgentResult, RuntimeConfigExtensionKind } from "@cline/shared"; import type { HookEventPayload } from "../../hooks"; import type { CheckpointEntry } from "../../hooks/checkpoint-hooks"; import type { ProviderSettings } from "../../services/llms/provider-settings"; import type { SessionCompactionState } from "../../session/models/session-compaction"; import type { SessionManifest } from "../../session/models/session-manifest"; import type { SessionSource } from "../../types/common"; import type { ClineCoreStartConfig, CoreSessionConfig } from "../../types/config"; import type { CoreSessionEvent, SessionPendingPrompt } from "../../types/events"; import type { SessionRecord } from "../../types/sessions"; import type { RuntimeCapabilities } from "../capabilities"; import type { ConnectionUpdate } from "../config/connection-update"; export declare const SESSION_NOT_FOUND_ERROR_CODE = "session_not_found"; export declare class SessionNotFoundError extends Error { readonly sessionId?: string | undefined; readonly code = "session_not_found"; constructor(sessionId?: string | undefined, message?: string); } export declare function isSessionNotFoundError(error: unknown): error is SessionNotFoundError; /** * A session that cannot serve another turn, whatever the caller does with it. * * Two distinct causes, one remedy: the session is gone (`session_not_found`, * after a hub restart, a deletion, or retention cleanup), or its runtime is stuck * with a run that never drained (`session_run_in_progress`). A caller holding a * long-lived mapping to that session — a connector thread, for instance — has to * replace the session rather than keep retrying against it. * * Errors reaching a connector have crossed the hub's JSON boundary, so the code * may be gone and only the message survives; both are checked, which also keeps * this working when the hub and the CLI are different versions. */ export declare function isUnusableSessionError(error: unknown): boolean; type LocalOnlyCoreSessionConfigKeys = "hooks" | "logger" | "telemetry" | "extensionContext" | "extraTools" | "extensions" | "onTeamEvent" | "onConsecutiveMistakeLimitReached"; export type RuntimeSessionConfig = Omit & { checkpoint?: Omit, "createCheckpoint">; compaction?: Omit, "compact">; }; /** Workspace paths may be omitted only at the session-start boundary. */ export type StartSessionConfig = Omit & { cwd?: string; }; export type LocalRuntimeBootstrapConfig = Pick & { checkpoint?: Pick, "createCheckpoint"> & Partial>; compaction?: Pick, "compact"> & Partial>; }; export interface LocalRuntimeStartOptions { hooks?: LocalRuntimeBootstrapConfig["hooks"]; logger?: LocalRuntimeBootstrapConfig["logger"]; telemetry?: LocalRuntimeBootstrapConfig["telemetry"]; extensionContext?: LocalRuntimeBootstrapConfig["extensionContext"]; extraTools?: LocalRuntimeBootstrapConfig["extraTools"]; extensions?: LocalRuntimeBootstrapConfig["extensions"]; onTeamEvent?: LocalRuntimeBootstrapConfig["onTeamEvent"]; onConsecutiveMistakeLimitReached?: LocalRuntimeBootstrapConfig["onConsecutiveMistakeLimitReached"]; checkpoint?: LocalRuntimeBootstrapConfig["checkpoint"]; compaction?: LocalRuntimeBootstrapConfig["compaction"]; modelCatalogDefaults?: Partial>; userInstructionService?: import("../../extensions/config").UserInstructionConfigService; configExtensions?: RuntimeConfigExtensionKind[]; onTeamRestored?: () => void; } export interface StartSessionInput { config: StartSessionConfig; /** The process/client that starts the session. E.g., "vscode", "cli". */ source?: SessionSource; /** How the session was initiated, such as user, automation, or subagent. */ mode?: string; prompt?: string; interactive?: boolean; sessionMetadata?: Record; initialMessages?: LlmsProviders.Message[]; initialCompactionState?: SessionCompactionState; userImages?: string[]; userFiles?: string[]; /** * Host-local bootstrap options. These are intentionally isolated from the * transport-neutral runtime session config so all runtime hosts share the * same execution contract while still allowing host-specific preparation. */ localRuntime?: LocalRuntimeStartOptions; capabilities?: RuntimeCapabilities; toolPolicies?: import("@cline/shared").AgentConfig["toolPolicies"]; } /** Session input after the execution host has resolved a concrete workspace. */ export interface ResolvedStartSessionInput extends Omit { config: RuntimeSessionConfig; } export declare function splitCoreSessionConfig(config: ClineCoreStartConfig): { config: StartSessionConfig; localRuntime?: LocalRuntimeStartOptions; }; export interface StartSessionResult { sessionId: string; manifest: SessionManifest; manifestPath: string; messagesPath: string; result?: AgentResult; } export interface SendSessionInput { sessionId: string; prompt: string; mode?: AgentMode; userImages?: string[]; userFiles?: string[]; delivery?: "queue" | "steer"; timeoutMs?: number; } export interface SessionAccumulatedUsage { inputTokens: number; outputTokens: number; cacheReadTokens: number; cacheWriteTokens: number; totalCost: number; } export interface SessionUsageSummary { usage?: SessionAccumulatedUsage; aggregateUsage?: SessionAccumulatedUsage; } export interface PendingPromptMutationResult { sessionId: string; prompts: SessionPendingPrompt[]; prompt?: SessionPendingPrompt; updated?: boolean; removed?: boolean; } export interface PendingPromptsListInput { sessionId: string; } export interface PendingPromptsUpdateInput { sessionId: string; promptId: string; prompt?: string; mode?: AgentMode; delivery?: "queue" | "steer"; } export interface PendingPromptsDeleteInput { sessionId: string; promptId: string; } export interface PendingPromptsServiceApi { list(input: PendingPromptsListInput): Promise; update(input: PendingPromptsUpdateInput): Promise; delete(input: PendingPromptsDeleteInput): Promise; } export interface PendingPromptsRuntimeService { readonly pendingPrompts: PendingPromptsServiceApi; } export interface SessionUsageRuntimeService { getAccumulatedUsage(sessionId: string): Promise; } export type SessionConnectionUpdate = ConnectionUpdate; export interface SessionModelRuntimeService { updateSessionModel(sessionId: string, modelId: string): Promise; } export interface SessionConnectionRuntimeService { updateSessionConnection(sessionId: string, updates: SessionConnectionUpdate): Promise; } export interface RuntimeHostSubscribeOptions { sessionId?: string; } export interface RestoreSessionInput { sessionId: string; checkpointRunCount: number; cwd?: string; restore?: { messages?: boolean; workspace?: boolean; omitCheckpointMessageFromSession?: boolean; }; start?: StartSessionInput; } export interface RestoreSessionResult { sessionId?: string; startResult?: StartSessionResult; messages?: LlmsProviders.Message[]; checkpoint: CheckpointEntry; } /** * RuntimeHost is the transport/runtime boundary for core session execution. * Callers must normalize broad local config into `RuntimeSessionConfig` * plus optional named `localRuntime` bootstrap fields before invoking a host. */ export interface RuntimeHost { readonly runtimeAddress?: string; startSession(input: StartSessionInput): Promise; runTurn(input: SendSessionInput): Promise; restoreSession(input: RestoreSessionInput): Promise; abort(sessionId: string, reason?: unknown): Promise; stopSession(sessionId: string): Promise; dispose(reason?: string): Promise; getSession(sessionId: string): Promise; listSessions(limit?: number): Promise; deleteSession(sessionId: string): Promise; updateSession(sessionId: string, updates: { prompt?: string | null; metadata?: Record | null; title?: string | null; }): Promise<{ updated: boolean; }>; updateSessionCompactionState(sessionId: string, state: SessionCompactionState): Promise<{ updated: boolean; }>; readSessionCompactionState(sessionId: string): Promise; readSessionMessages(sessionId: string): Promise; /** * Like {@link readSessionMessages}, but prefers the resident session's * in-memory conversation over the persisted transcript. Disk persistence * happens at assistant-message/turn boundaries (and abort() does not * flush), so this is the accurate read for callers that need the * conversation of an in-flight or just-aborted turn — e.g. rebuilding a * session for a mode switch. Optional: hosts without live-session access * (e.g. hub clients) fall back to the persisted transcript. */ readLiveSessionMessages?(sessionId: string): Promise; dispatchHookEvent(payload: HookEventPayload): Promise; subscribe(listener: (event: CoreSessionEvent) => void, options?: RuntimeHostSubscribeOptions): () => void; } export type RuntimeHostMode = "auto" | "local" | "hub" | "remote"; export {};