import type * as LlmsProviders from "@cline/llms"; import { type AgentConfig, type AgentResult, type ITelemetryService } from "@cline/shared"; import type { HookEventPayload } from "../../hooks"; import { ProviderSettingsManager } from "../../services/storage/provider-settings-manager"; import { type SessionCompactionState } from "../../session/models/session-compaction"; import type { CoreSessionConfig } from "../../types/config"; import type { CoreSessionEvent } from "../../types/events"; import type { SessionRecord } from "../../types/sessions"; import type { RuntimeCapabilities } from "../capabilities"; import { RuntimeOAuthTokenManager } from "../orchestration/runtime-oauth-token-manager"; import type { RuntimeBuilder } from "../orchestration/session-runtime"; import { SessionRuntime } from "../orchestration/session-runtime-orchestrator"; import { type SessionBackend } from "./local/session-record"; import type { PendingPromptsServiceApi, RestoreSessionInput, RestoreSessionResult, RuntimeHost, RuntimeHostSubscribeOptions, SendSessionInput, SessionConnectionUpdate, SessionUsageSummary, StartSessionInput, StartSessionResult } from "./runtime-host"; export interface LocalRuntimeHostOptions { distinctId?: string; sessionService: SessionBackend; runtimeBuilder?: RuntimeBuilder; createAgent?: (config: AgentConfig) => SessionRuntime; capabilities?: RuntimeCapabilities; toolPolicies?: AgentConfig["toolPolicies"]; providerSettingsManager?: ProviderSettingsManager; oauthTokenManager?: RuntimeOAuthTokenManager; telemetry?: ITelemetryService; /** * Default custom `fetch` implementation threaded into every * `ProviderConfig.fetch` built during local session bootstrap. Used by * the AI gateway providers when issuing HTTP requests. */ fetch?: typeof fetch; } export declare class LocalRuntimeHost implements RuntimeHost { readonly runtimeAddress: undefined; readonly pendingPrompts: PendingPromptsServiceApi; private readonly sessionService; private readonly runtimeBuilder; private readonly createAgentInstance; private readonly toolExecutors?; private readonly defaultCapabilities?; private readonly defaultToolPolicies?; private readonly providerSettingsManager; private readonly oauthTokenManager; private readonly defaultTelemetry?; private readonly defaultFetch?; private readonly events; private readonly sessions; private readonly manifestMutationQueues; private readonly usageBySession; private readonly aggregateUsageBySession; private readonly subAgentStarts; private readonly pendingPromptsController; private readonly eventBridge; private readonly sessionVersioning; constructor(options: LocalRuntimeHostOptions); private applyInitialOAuthCredentials; startSession(input: StartSessionInput): Promise; restoreSession(input: RestoreSessionInput): Promise; runTurn(input: SendSessionInput): Promise; getAccumulatedUsage(sessionId: string): 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; private isCompactionStateForSession; private canPersistCompactionState; private persistActiveSessionCompactionState; private enqueueCompactionStateWrite; readSessionMessages(sessionId: string): Promise; dispatchHookEvent(payload: HookEventPayload): Promise; subscribe(listener: (event: CoreSessionEvent) => void, options?: RuntimeHostSubscribeOptions): () => void; updateSessionModel(sessionId: string, modelId: string): Promise; updateSessionConnection(sessionId: string, rawUpdates: SessionConnectionUpdate): Promise; /** * Serialized read-modify-write for a live session's manifest. Every * manifest write for an active session MUST go through this helper: it * re-reads the disk manifest first so disk-only writers (compaction-path * updates, title/metadata renames) are never reverted by a stale in-memory * copy, applies the field-level mutation, syncs the in-memory copy, and * persists — one mutation at a time per session. */ private mutateSessionManifest; handlePluginEvent(rootSessionId: string, event: { name: string; payload?: unknown; }, fallbackAutomation?: NonNullable["automation"]): Promise; private executeTurn; private completeInteractiveTurn; private resolveInteractiveStopStatus; private resolveInteractiveStopExitCode; private completeAbortedInteractiveTurn; private executeAgentTurn; /** * Anchor `task.completed` telemetry to the assistant's explicit * completion declaration. We emit at most once per session, the moment * a successful `submit_and_exit` tool call is observed in the run * result. This is the SDK analog of original Cline's * `attempt_completion`-driven emission and works for both interactive * and non-interactive sessions. * * `shutdownSession(...)` retains a fallback emission for completed * sessions that finish without an explicit completion-tool observation * (e.g., non-interactive runs not using the yolo preset). This helper * sets `submitAndExitObserved` so the shutdown fallback can suppress a * duplicate emission for the same logical completion. */ private observeTaskCompletionTool; private prepareTurnInput; private ensureSessionPersisted; private markTurnRunning; private refreshActiveSessionGitMetadata; private markTurnPending; private markTurnIdle; private persistSessionMetadata; private finalizeSingleRun; private failSession; private shutdownSession; private releaseSessionRuntime; private updateStatus; private runWithAuthRetry; private syncOAuthCredentials; private getSessionOrThrow; private resolveAbsoluteFilePaths; private getSessionAgentTelemetryIdentity; private seedAggregateUsageFromArtifacts; private summarizePersistedTeammateUsage; private withPersistedAggregateUsageFloor; private emitStatus; private emitSessionSnapshot; private emit; private listRows; private getRow; private readManifest; private invoke; private invokeOptional; private invokeOptionalValue; }