import type { Api, AssistantMessage, AssistantMessageEventStream, Context, Model, SimpleStreamOptions, } from "@earendil-works/pi-ai"; import type { AgentModeOption, ModelSelection, SDKAgent, SDKImage } from "@cursor/sdk"; import type { CursorLiveRun } from "./live-run-coordinator.js"; import type { SessionCursorAgentLease } from "./session-agent.js"; import type { planCursorSessionSend } from "./session-agent.js"; import type { CursorSdkEventDebugSink } from "./sdk-event-debug.js"; import type { CursorSdkTurnCoordinator } from "./provider-turn-coordinator.js"; import type { CursorPrompt } from "./context.js"; import type { CursorResolvedSetting } from "./config.js"; import type { CursorSdkTurnUsage } from "./usage-accounting.js"; import type { CursorProviderRuntimeContext } from "./provider-runtime-context.js"; export interface CursorProviderTurnRunnerParams { model: Model; context: Context; stream: AssistantMessageEventStream; partial: AssistantMessage; options?: SimpleStreamOptions; runtimeContext?: CursorProviderRuntimeContext; sdkEventDebugRef: { current?: CursorSdkEventDebugSink }; } export interface CursorProviderTurnSendPayload { text: string; images?: SDKImage[]; } export interface CursorProviderTurnSendMeta { sendPlan: ReturnType; prompt: CursorPrompt; bootstrap: boolean; promptInputTokens: number; useNativeToolReplay: boolean; bridgeEnabled: boolean; nativeReplayId: string; agentMode: AgentModeOption; modelSelection: ModelSelection; } interface CursorProviderTurnRuntimeBase { turnCoordinator: CursorSdkTurnCoordinator; billedTurnUsage?: CursorSdkTurnUsage; } /** Lifecycle operations for a prepared local turn, delegated to the session agent lease. */ export interface CursorProviderTurnLifecycle { trackRunCompletion(completion: Promise): void; commitSend(context: Context, bootstrapped: boolean): void; abandon(): Promise; dispose(): Promise; } export interface DirectCursorProviderTurnRuntime extends CursorProviderTurnRuntimeBase { kind: "direct"; liveRun?: undefined; } export interface LiveCursorProviderTurnRuntime extends CursorProviderTurnRuntimeBase { kind: "live"; liveRun: CursorLiveRun; } export type CursorProviderTurnRuntime = DirectCursorProviderTurnRuntime | LiveCursorProviderTurnRuntime; /** * Single owned model for a prepared local provider turn. * * Send, finalize, and cleanup phases receive this immutable object instead of * keeping parallel liveRun/turnCoordinator/resource bags in sync by convention. */ export interface CursorProviderTurnPrepareResult { cwd: string; payload: CursorProviderTurnSendPayload; meta: CursorProviderTurnSendMeta; restoreCursorSdkOutputFilter: () => void; lifecycle: CursorProviderTurnLifecycle; sessionAgentLease: SessionCursorAgentLease; localForce: CursorResolvedSetting; runtime: CursorProviderTurnRuntime; } export interface CursorProviderTurnSend { run: Awaited>; cursorAgentMessageOffset: number | undefined; } export interface CursorProviderTurnSendResult { send: CursorProviderTurnSend; abortRegistration: { signal: AbortSignal; listener: () => void } | undefined; }