import { type Settings } from "../../config/settings"; import type { ExtensionAPI, ExtensionContext } from "../../extensibility/extensions"; import { SessionSdkHost, type SessionSdkHostOptions } from "./host"; import { type SessionSurface } from "./query"; import { type SdkCapabilities, type SdkSurfacePolicy } from "./surface-policy"; import type { BrokerIndexWriter, SdkFrame } from "./types"; /** Transport-neutral endpoint contract consumed by the SDK session runtime. */ export interface SessionSdkTransport { readonly sessionId: string; readonly stateRoot: string; readonly token: string; sendFrame(connectionId: string, frame: SdkFrame): void | "written" | "dropped" | Promise | Promise<"written" | "dropped">; onFrame(handler: (connectionId: string, frame: SdkFrame) => void): undefined | (() => void); onMalformedFrame?(handler: (connectionId: string, message: string) => void): undefined | (() => void); start(): Promise<{ url: string; }>; stop(): Promise; broadcastFrame?(frame: SdkFrame): void; onConnectionClose?(handler: (connectionId: string) => void): undefined | (() => void); onNegotiatedCapabilities?(handler: (connectionId: string, capabilities: readonly string[]) => void): undefined | (() => void); } export interface SessionSdkRuntimeOptions extends Omit { transport: SessionSdkTransport; /** Session settings; enables `config.patch` application on this runtime. */ settings?: Settings; /** Mutable shadow of patched config values merged into query readback. */ configOverrides?: Map; } export interface SdkOnlyInvocationRecord extends InvocationCorrelation { kind: InvocationKind | "terminal" | "steer"; clientRef?: string; status: InvocationStatus | "dispatching" | "rejected"; acceptedAt: number; startedAt?: number; terminalAt?: number; error?: { code: string; message: string; }; outcome?: unknown; pendingOutcome?: unknown; skillName?: string; /** Steer records (origin/dev) carry their own dispatching lifecycle. */ textDigest?: string; createdAt?: number; settledAt?: number; } export interface SdkOnlyTerminalScopeRecord { selection: "turn" | "owned"; idempotencyKeyHash?: string; idempotencyInputHash?: string; turnDisposition: "pending" | "stopped" | "uncertain" | "no_effect" | "no_effect_reserved" | "no_effect_marker_failure"; terminalPublished?: boolean; ownedWorkDisposition: "not_requested" | "left_running" | "stopped" | "uncertain"; automaticDeliveryDisposition: "enabled" | "none"; resumeOnOwnedCompletion: boolean; turnContinuationFence: { state: "retained" | "released"; abortedAttemptEpoch: number; blockedContinuationIds: string[]; predecessorTombstones: string[]; ownedCompletionPolicy: "enabled" | "disabled"; }; responseState: "pending" | "sent" | "delivered" | "failed"; responsePayloadHash: string; replayPayloadHash?: string; acceptedAt: number; terminalAt?: number; } export interface SdkOnlyEvictedTerminalKeyEntry { keyHash: string; inputHash: string; turnDisposition?: "stopped" | "uncertain" | "no_effect" | "no_effect_reserved" | "no_effect_marker_failure"; ownedWorkDisposition?: "not_requested" | "left_running" | "stopped" | "uncertain"; responseState?: "pending" | "sent" | "delivered" | "failed"; responsePayloadHash?: string; replayPayloadHash?: string; terminalPublished?: boolean; } export interface SdkOnlyReconciliationStore { readonly path: string | null; load(): Promise; transact(mutator: (records: SdkOnlyInvocationRecord[]) => SdkOnlyInvocationRecord[]): Promise; snapshotTerminalScopes(): SdkOnlyTerminalScopeRecord[]; snapshotTerminalKeys(): SdkOnlyEvictedTerminalKeyEntry[]; transactTerminalScopes(mutator: (scopes: SdkOnlyTerminalScopeRecord[]) => SdkOnlyTerminalScopeRecord[]): Promise; transactTerminalState(mutator: (state: { scopes: SdkOnlyTerminalScopeRecord[]; keys: SdkOnlyEvictedTerminalKeyEntry[]; }) => { scopes: SdkOnlyTerminalScopeRecord[]; keys: SdkOnlyEvictedTerminalKeyEntry[]; }): Promise; } export interface SdkOnlyTerminalAbortSeams { getReconciliationStore?: () => SdkOnlyReconciliationStore | undefined; getTerminalTurnEpoch: () => number | undefined; getActivePromptHandle: () => string | undefined; /** Re-read the active prompt's owning SDK connection for the owner-mismatch * recheck; falls back to the runtime-tracked owner when absent (review * thread P1). */ getActivePromptOwnerConnectionId?: () => string | undefined; cancelPendingPreflightForTerminalAbort: () => void; /** Capture the steering admission snapshot at abort ADMISSION (before any * durable transaction), so steers admitted while the abort is in flight * classify as post-snapshot (review thread P1). */ captureTerminalAbortSteeringSnapshot?: () => number | undefined; /** Discard the steering snapshot when a replay-only abort never settles * (review thread P1). */ discardTerminalAbortSteeringSnapshot?: (token: number) => void; /** Rebind the snapshot to the current turn when the requester's turn * wins the race (review thread P1). */ rebindTerminalAbortSteeringSnapshot?: (token: number) => void; abortPromptAndWaitWithTerminal: (handle: string, options: { graceMs: number; terminal?: { scope: "turn" | "owned"; expectedEpoch?: number; steeringSnapshotToken?: number; }; }) => Promise<{ status: string; terminalScope?: unknown; }>; /** Test override for the maximum durable terminal reservation rows. */ maxDurableTerminalReservationsForTests?: number; } /** * The transport-neutral SDK session runtime. * * Concrete transports (including the optional notification/native transport) are * injected by the caller. This module owns host construction, control/query * dispatch, replay/event publication, and reverse-provider lifecycle without * importing any notification adapter or native notification class. */ export declare class SessionSdkSessionRuntime { #private; readonly host: SessionSdkHost; readonly transport: SessionSdkTransport; constructor(options: SessionSdkRuntimeOptions); get started(): boolean; get generation(): number; getProviderDefinitions(capability: string): unknown | undefined; emitEvent(frame: SdkFrame): void; publish(frame: SdkFrame): void; startHost(): Promise<"started" | "already">; startTransport(): Promise<{ url: string; }>; start(): Promise<{ url: string; }>; stop(): Promise; registerWithBroker(writer: BrokerIndexWriter): Promise; } /** Narrow extension-facing factory for the SDK-only session path. */ export interface CreateSdkSessionRuntimeOptions { /** Authoritative broker state root for this session's endpoint lifecycle. */ agentDir: string; /** Lifecycle-owned sessions require broker publication before they become usable. */ brokerRegistrationRequired?: boolean; createTransport(input: { sessionId: string; stateRoot: string; token: string; }): SessionSdkTransport | Promise; /** Session settings; enables `config.patch` application on this runtime. */ settings?: Settings; /** Callback for diagnostics and lifecycle request observation. */ onSdkRequest?: SessionSdkHostOptions["onRequest"]; /** Mutable shadow of patched config values merged into query readback. */ configOverrides?: Map; /** Private session-owned terminal-abort capabilities; never exposed on ExtensionContext. */ terminalAbortSeams?: SdkOnlyTerminalAbortSeams; /** Callback when a frame is admitted to the runtime (test harness). */ onFrameAdmitted?: () => void; } export interface InvocationCorrelation { commandId: string; turnId: string; } export type InvocationKind = "prompt" | "skill" | "steer"; type InvocationStatus = "accepted" | "in_flight" | "terminal_ok" | "failed" | "uncertain"; export interface InvocationReconciliation { /** Shared v2 reconciliation owner; present for durable terminal admission. */ readonly store?: SdkOnlyReconciliationStore; admit(kind: InvocationKind, clientRef?: string): void; release(kind: InvocationKind, clientRef?: string): void; noteAccepted(kind: InvocationKind, correlation: InvocationCorrelation, clientRef?: string): Promise; noteTransition(kind: InvocationKind, correlation: InvocationCorrelation | undefined, frame: { type: "agent_start" | "agent_end"; } | { type: "agent_failed"; error: unknown; }): Promise; lookup(kind: InvocationKind, selector: { commandId?: string; turnId?: string; clientRef?: string; }): unknown; lookupResult(kind: InvocationKind, selector: { commandId?: string; turnId?: string; clientRef?: string; }): unknown; listDeadlineRecoveryPendingPrompts(): Array<{ correlation: InvocationCorrelation; acceptedAt: number; deadlineMaxAt?: number; }>; hydrate(): Promise; claimPendingOutcome(kind: InvocationKind, correlation: InvocationCorrelation, outcome: { kind: string; code: string; message: string; provenance?: string; }): Promise; finalizeOutcome(kind: InvocationKind, correlation: InvocationCorrelation, outcome?: { kind: string; code: string; message: string; provenance?: string; }, arg4?: (() => boolean) | { code: string; message: string; }, arg5?: unknown): Promise; markUncertain(kind: InvocationKind, correlation: InvocationCorrelation, isCurrent?: () => boolean, deadlineMaxAt?: number): Promise; } export declare function createInvocationReconciliation(options?: { stateRoot?: string; sessionId?: string; store?: SdkOnlyReconciliationStore; }): InvocationReconciliation; export interface SdkSurfaceFactoryOptions { ctx: ExtensionContext; id: string; api: ExtensionAPI; policy?: SdkSurfacePolicy; getInstalledDefinitions?: (capability: string) => unknown | undefined; getLiveState?: () => { isStreaming: boolean; steeringQueueDepth: number; followupQueueDepth: number; }; configOverrides?: ReadonlyMap; /** Session settings; used for model-usage preferences in profile-limit resolution. */ settings?: Settings; turnResultLookup?: (selector: { kind: "prompt" | "skill"; commandId?: string; turnId?: string; clientRef?: string; }) => unknown; steerStatusLookup?: (selector: { commandId?: string; turnId?: string; clientRef?: string; }) => unknown; hostTools?: boolean | (() => boolean); } /** Shared policy, capability, and query-surface factory for every SDK transport. */ export interface SdkSurfaceFactory { readonly policy: SdkSurfacePolicy; readonly query: SessionSurface; getCapabilities(): SdkCapabilities; } /** * Build the transport-neutral SDK policy/capability/query bundle. Native and * loopback transports must use this entry point so their advertised surface, * query handlers, and error behavior cannot drift. */ export declare function createSdkSurfaceFactory(options: SdkSurfaceFactoryOptions & { reconciliation?: InvocationReconciliation; }): SdkSurfaceFactory; /** Register the default-session notification command without loading notification adapters. */ export declare function registerSdkOnlyNotificationCommand(api: ExtensionAPI): void; /** Install a complete SDK host for a session when notifications are inactive. */ export declare function createSdkSessionRuntimeExtension(api: ExtensionAPI, options: CreateSdkSessionRuntimeOptions): void; export {};