@cursor-harness-provider/native 0.0.0-stage → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +8 -2
- package/THIRD_PARTY_NOTICES.md +16 -0
- package/dist/cursor-protocol/auth/oauth.d.ts +65 -0
- package/dist/cursor-protocol/client/bridge.d.ts +86 -0
- package/dist/cursor-protocol/client/cursor-wire.d.ts +27 -0
- package/dist/cursor-protocol/client/h1-bridge.d.ts +23 -0
- package/dist/cursor-protocol/client/h2-proxy.d.ts +7 -0
- package/dist/cursor-protocol/client/h2-session.d.ts +54 -0
- package/dist/cursor-protocol/client/h2-unary.d.ts +23 -0
- package/dist/cursor-protocol/config/index.d.ts +24 -0
- package/dist/cursor-protocol/models/limits.d.ts +33 -0
- package/dist/cursor-protocol/models/parameterized.d.ts +98 -0
- package/dist/cursor-protocol/models/processing.d.ts +39 -0
- package/dist/cursor-protocol/proto/agent_pb.d.ts +13052 -0
- package/dist/cursor-protocol/stream/bridge-session.d.ts +30 -0
- package/dist/cursor-protocol/stream/client-transcript.d.ts +30 -0
- package/dist/cursor-protocol/stream/clipboard-images.d.ts +23 -0
- package/dist/cursor-protocol/stream/config.d.ts +5 -0
- package/dist/cursor-protocol/stream/context-normalize.d.ts +66 -0
- package/dist/cursor-protocol/stream/debug-log.d.ts +26 -0
- package/dist/cursor-protocol/stream/drift.d.ts +26 -0
- package/dist/cursor-protocol/stream/exec-native.d.ts +13 -0
- package/dist/cursor-protocol/stream/images.d.ts +24 -0
- package/dist/cursor-protocol/stream/interaction-query.d.ts +15 -0
- package/dist/cursor-protocol/stream/local-tool-policy.d.ts +73 -0
- package/dist/cursor-protocol/stream/message-parsing.d.ts +38 -0
- package/dist/cursor-protocol/stream/model-discovery.d.ts +50 -0
- package/dist/cursor-protocol/stream/model-routing.d.ts +30 -0
- package/dist/cursor-protocol/stream/native-core.d.ts +63 -0
- package/dist/cursor-protocol/stream/pi-adapter.d.ts +74 -0
- package/dist/cursor-protocol/stream/protocol.d.ts +23 -0
- package/dist/cursor-protocol/stream/recovery.d.ts +96 -0
- package/dist/cursor-protocol/stream/request-build.d.ts +134 -0
- package/dist/cursor-protocol/stream/root-prompt.d.ts +74 -0
- package/dist/cursor-protocol/stream/run-journal.d.ts +77 -0
- package/dist/cursor-protocol/stream/scope-journal.d.ts +43 -0
- package/dist/cursor-protocol/stream/server-messages.d.ts +49 -0
- package/dist/cursor-protocol/stream/session-state.d.ts +73 -0
- package/dist/cursor-protocol/stream/stream-writer.d.ts +6 -0
- package/dist/cursor-protocol/stream/thinking-filter.d.ts +19 -0
- package/dist/cursor-protocol/stream/tool-schema.d.ts +10 -0
- package/dist/cursor-protocol/stream/transport-errors.d.ts +29 -0
- package/dist/cursor-protocol/stream/tuning.d.ts +104 -0
- package/dist/cursor-protocol/stream/types.d.ts +339 -0
- package/dist/cursor-protocol/types/enums.d.ts +40 -0
- package/dist/cursor-protocol/utils/cache-dir.d.ts +6 -0
- package/dist/cursor-protocol/utils/security.d.ts +4 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +15195 -0
- package/dist/index.js.map +7 -0
- package/dist/js-engine/engine.d.ts +88 -0
- package/dist/lifecycle.d.ts +25 -0
- package/dist/lifecycle.js +112 -0
- package/dist/lifecycle.js.map +7 -0
- package/licenses/distribution.json +12 -0
- package/licenses/pi-cursor/LICENSE +21 -0
- package/package.json +42 -4
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tuning knobs for the stream runtime: timeouts, retry budgets, and the
|
|
3
|
+
* silence watchdog that backs them.
|
|
4
|
+
*
|
|
5
|
+
* Every `resolve*` function takes the raw env string so the parsing rules
|
|
6
|
+
* (blank = default, 0 = disabled, floors on the rest) are unit-testable without
|
|
7
|
+
* mutating `process.env`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const CONVERSATION_TTL_MS: number;
|
|
10
|
+
export declare const DEFAULT_ACTIVE_BRIDGE_TTL_MS: number;
|
|
11
|
+
export declare const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 180000;
|
|
12
|
+
export declare const DEFAULT_STREAM_PARK_TIMEOUT_MS = 45000;
|
|
13
|
+
export declare const DEFAULT_RESUME_IDLE_TIMEOUT_MS = 180000;
|
|
14
|
+
export declare const DEFAULT_STREAM_IDLE_MAX_RETRIES = 5;
|
|
15
|
+
/**
|
|
16
|
+
* Idle recoveries a stream may take in a row, with no model output in between, before a stall
|
|
17
|
+
* is charged to the retry budget. A recovery restarts a silent stream without spending a retry,
|
|
18
|
+
* which is right for a one-off stall and wrong for an upstream that never answers: unbounded,
|
|
19
|
+
* that restarted the request every idle timeout until the user interrupted it. With the default
|
|
20
|
+
* retry budget a permanently silent upstream now fails after 1 + 2 + 5 attempts.
|
|
21
|
+
*/
|
|
22
|
+
export declare const MAX_IDLE_RECOVERIES_WITHOUT_OUTPUT = 2;
|
|
23
|
+
/** Soft cap on retained blob bytes per conversation (images + turn blobs). */
|
|
24
|
+
export declare const MAX_CONVERSATION_BLOB_BYTES: number;
|
|
25
|
+
export declare const MAX_ACTIVE_BLOB_BYTES: number;
|
|
26
|
+
export declare const MAX_ACTIVE_BLOB_ENTRIES = 8192;
|
|
27
|
+
export declare const MAX_INDIVIDUAL_BLOB_BYTES: number;
|
|
28
|
+
/**
|
|
29
|
+
* Headroom the live store's setBlob trim needs inside the entry and byte caps.
|
|
30
|
+
* The server pushes its own blobs (state, summaries) during a turn, and the
|
|
31
|
+
* trim fires once the map exceeds cap-1 entries / cap-minus-incoming bytes. A
|
|
32
|
+
* request whose referenced blobs fit inside cap minus this headroom can never
|
|
33
|
+
* lose one to that trim; request-build sheds the oldest turn state when the
|
|
34
|
+
* transcript outgrows it (see shedTurnStateToFit in request-build.ts).
|
|
35
|
+
*/
|
|
36
|
+
export declare const RESERVED_LIVE_BLOB_ENTRIES = 96;
|
|
37
|
+
export declare const RESERVED_LIVE_BLOB_BYTES: number;
|
|
38
|
+
/**
|
|
39
|
+
* Hard cap on a stored upstream checkpoint's byte size. Unlike blobs and tool
|
|
40
|
+
* results, the checkpoint Cursor hands back is opaque and unbounded — over a
|
|
41
|
+
* long-running conversation it can grow past the transport's 64 MiB Connect
|
|
42
|
+
* frame limit, at which point the checkpoint would fail every future turn
|
|
43
|
+
* (frameConnectMessage throws before anything is sent). Discarding it above
|
|
44
|
+
* this cap forces a rebuild from the (bounded) blob store instead, leaving
|
|
45
|
+
* plenty of headroom under the transport limit for mcpTools/model metadata.
|
|
46
|
+
*/
|
|
47
|
+
export declare const MAX_CHECKPOINT_BYTES: number;
|
|
48
|
+
export declare const DEFAULT_H2_CONNECT_TIMEOUT_MS = 30000;
|
|
49
|
+
/**
|
|
50
|
+
* Activity idle kill after first I/O. Default 0 (disabled): parent heartbeats
|
|
51
|
+
* already keep the bridge alive, and a hard idle kill during long tool pauses
|
|
52
|
+
* was a common source of "Bridge connection lost" mid-session. Set
|
|
53
|
+
* PI_CURSOR_H2_IDLE_TIMEOUT_MS to re-enable a safety net.
|
|
54
|
+
*/
|
|
55
|
+
export declare const DEFAULT_H2_IDLE_TIMEOUT_MS = 0;
|
|
56
|
+
export declare function resolveActiveBridgeTtlMs(envValue?: string): number;
|
|
57
|
+
export declare function resolveStreamIdleTimeoutMs(envValue?: string): number;
|
|
58
|
+
export declare function resolveStreamIdleMaxRetries(envValue?: string): number;
|
|
59
|
+
export declare function resolveResumeIdleTimeoutMs(envValue?: string): number;
|
|
60
|
+
export declare function resolveH2ConnectTimeoutMs(envValue?: string): number;
|
|
61
|
+
export declare function resolveH2IdleTimeoutMs(envValue?: string): number;
|
|
62
|
+
/**
|
|
63
|
+
* What a server message says about the stream.
|
|
64
|
+
*
|
|
65
|
+
* `work` is the run moving: tokens, tool calls, answered execs, checkpoints.
|
|
66
|
+
* `liveness` is the connection breathing while the run itself may be stuck —
|
|
67
|
+
* a heartbeat proves the socket, not the turn. `none` is noise.
|
|
68
|
+
*
|
|
69
|
+
* The distinction exists because a park is not silent: Cursor keeps heartbeating
|
|
70
|
+
* a run that is waiting for an exec reply we never sent, which made a
|
|
71
|
+
* silence-only watchdog unable to ever fire (a Grok session sat parked for 90
|
|
72
|
+
* minutes on an unknown exec case in 2026-08).
|
|
73
|
+
*/
|
|
74
|
+
export type StreamProgress = "none" | "liveness" | "work";
|
|
75
|
+
/**
|
|
76
|
+
* How an interaction-update case should be treated by the stream idle watchdog.
|
|
77
|
+
* tokenDelta is work: long reasoning turns emit it without text for minutes at a
|
|
78
|
+
* time, and it only flows while the model is actually generating.
|
|
79
|
+
*/
|
|
80
|
+
export declare function interactionUpdateProgress(updateCase: string | undefined, hasNonEmptyText?: boolean): StreamProgress;
|
|
81
|
+
/** Whether a blind full-request restart is safe given already-streamed content. */
|
|
82
|
+
export declare function canBlindIdleRestart(emittedUserVisibleContent: boolean): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Whether recovery is allowed after transport loss.
|
|
85
|
+
* Blind restart only when nothing was streamed; checkpoint continuation is safe
|
|
86
|
+
* even after partial text because Cursor resumes server-side state and emits
|
|
87
|
+
* only new tokens (Pi appends them to the existing writer).
|
|
88
|
+
*/
|
|
89
|
+
export declare function canRecoverAfterTransportLoss(input: {
|
|
90
|
+
emittedUserVisibleContent: boolean;
|
|
91
|
+
hasCheckpoint: boolean;
|
|
92
|
+
}): boolean;
|
|
93
|
+
export declare function createStreamIdleWatchdog(options: {
|
|
94
|
+
timeoutMs: number;
|
|
95
|
+
onTimeout: () => void;
|
|
96
|
+
}): {
|
|
97
|
+
start(): void;
|
|
98
|
+
reset(): void;
|
|
99
|
+
pause(): void;
|
|
100
|
+
resume(): void;
|
|
101
|
+
clear(): void;
|
|
102
|
+
setTimeoutMs(timeoutMs: number): void;
|
|
103
|
+
};
|
|
104
|
+
export declare const ACTIVE_BRIDGE_TTL_MS: number;
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type surface for the Cursor stream runtime.
|
|
3
|
+
*
|
|
4
|
+
* These types are pure structure with no runtime behaviour, so every stream
|
|
5
|
+
* module can depend on this file without creating import cycles. Anything that
|
|
6
|
+
* used to be declared twice (native-core + recovery) now lives here once.
|
|
7
|
+
*/
|
|
8
|
+
import type { Api, AssistantMessage, Model, SimpleStreamOptions } from "@earendil-works/pi-ai";
|
|
9
|
+
import type { BridgeHandle } from "../client/bridge.js";
|
|
10
|
+
import type { CursorModelParameter } from "../client/cursor-wire.js";
|
|
11
|
+
import type { McpToolDefinition } from "../proto/agent_pb.js";
|
|
12
|
+
import type { CursorNativeModelRouting } from "./model-routing.js";
|
|
13
|
+
export interface OpenAIToolCall {
|
|
14
|
+
id: string;
|
|
15
|
+
type: "function";
|
|
16
|
+
function: {
|
|
17
|
+
name: string;
|
|
18
|
+
arguments: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface ContentPart {
|
|
22
|
+
type: string;
|
|
23
|
+
text?: string;
|
|
24
|
+
data?: string;
|
|
25
|
+
mimeType?: string;
|
|
26
|
+
image_url?: {
|
|
27
|
+
url?: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface OpenAIMessage {
|
|
31
|
+
role: "system" | "user" | "assistant" | "tool";
|
|
32
|
+
content: string | null | ContentPart[];
|
|
33
|
+
tool_call_id?: string;
|
|
34
|
+
tool_calls?: OpenAIToolCall[];
|
|
35
|
+
/** Propagated from Pi toolResult.isError into Cursor MCP results. */
|
|
36
|
+
is_error?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Set on a historical assistant message whose turn did not run to completion
|
|
39
|
+
* (aborted, errored, truncated). Replayed into the turn as a trailing
|
|
40
|
+
* assistant step — see `interruptedAssistantNotice()` in ./pi-adapter.ts.
|
|
41
|
+
*/
|
|
42
|
+
interrupted_notice?: string;
|
|
43
|
+
/** Replayed thinking from a prior assistant turn; see ./pi-adapter.ts. */
|
|
44
|
+
thinking?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface OpenAIToolDef {
|
|
47
|
+
type: "function";
|
|
48
|
+
function: {
|
|
49
|
+
name: string;
|
|
50
|
+
description?: string;
|
|
51
|
+
parameters?: Record<string, unknown>;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export interface CursorToolResultImagePayload {
|
|
55
|
+
toolCallId: string;
|
|
56
|
+
images: Array<{
|
|
57
|
+
data: string;
|
|
58
|
+
mimeType: string;
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
export interface ChatCompletionRequest {
|
|
62
|
+
model: string;
|
|
63
|
+
messages: OpenAIMessage[];
|
|
64
|
+
stream?: boolean;
|
|
65
|
+
temperature?: number;
|
|
66
|
+
max_tokens?: number;
|
|
67
|
+
max_completion_tokens?: number;
|
|
68
|
+
tools?: OpenAIToolDef[];
|
|
69
|
+
tool_choice?: unknown;
|
|
70
|
+
reasoning_effort?: string;
|
|
71
|
+
user?: string;
|
|
72
|
+
pi_session_id?: string;
|
|
73
|
+
cursor_model_id?: string;
|
|
74
|
+
cursor_model_parameters?: CursorModelParameter[];
|
|
75
|
+
cursor_tool_result_images?: CursorToolResultImagePayload[];
|
|
76
|
+
cursor_requires_max_mode?: boolean;
|
|
77
|
+
cursor_model_max_mode?: boolean;
|
|
78
|
+
}
|
|
79
|
+
export interface ParsedImageContent {
|
|
80
|
+
data: Uint8Array;
|
|
81
|
+
mimeType: string;
|
|
82
|
+
}
|
|
83
|
+
export interface ParsedToolResult {
|
|
84
|
+
content: string;
|
|
85
|
+
isError: boolean;
|
|
86
|
+
images?: ParsedImageContent[];
|
|
87
|
+
}
|
|
88
|
+
export interface ParsedAssistantTextStep {
|
|
89
|
+
kind: "assistantText";
|
|
90
|
+
text: string;
|
|
91
|
+
}
|
|
92
|
+
export interface ParsedThinkingStep {
|
|
93
|
+
kind: "thinking";
|
|
94
|
+
text: string;
|
|
95
|
+
}
|
|
96
|
+
export interface ParsedToolCallStep {
|
|
97
|
+
kind: "toolCall";
|
|
98
|
+
toolCallId: string;
|
|
99
|
+
toolName: string;
|
|
100
|
+
arguments: Record<string, unknown>;
|
|
101
|
+
result?: ParsedToolResult;
|
|
102
|
+
}
|
|
103
|
+
export type ParsedTurnStep = ParsedAssistantTextStep | ParsedThinkingStep | ParsedToolCallStep;
|
|
104
|
+
export interface ParsedTurn {
|
|
105
|
+
userText: string;
|
|
106
|
+
steps: ParsedTurnStep[];
|
|
107
|
+
userImages?: ParsedImageContent[];
|
|
108
|
+
}
|
|
109
|
+
export interface ToolResultInfo {
|
|
110
|
+
toolCallId: string;
|
|
111
|
+
content: string;
|
|
112
|
+
images?: ParsedImageContent[];
|
|
113
|
+
isError?: boolean;
|
|
114
|
+
}
|
|
115
|
+
export interface ParsedMessages {
|
|
116
|
+
systemPrompt: string;
|
|
117
|
+
userText: string;
|
|
118
|
+
userImages: ParsedImageContent[];
|
|
119
|
+
turns: ParsedTurn[];
|
|
120
|
+
toolResults: ToolResultInfo[];
|
|
121
|
+
inFlightTurn?: ParsedTurn;
|
|
122
|
+
}
|
|
123
|
+
export interface CursorRequestPayload {
|
|
124
|
+
requestBytes: Uint8Array;
|
|
125
|
+
requestBody: Uint8Array;
|
|
126
|
+
blobStore: Map<string, Uint8Array>;
|
|
127
|
+
mcpTools: McpToolDefinition[];
|
|
128
|
+
}
|
|
129
|
+
export interface CursorRequestDebugSummary {
|
|
130
|
+
systemPrompt: string;
|
|
131
|
+
selectedImages: Array<{
|
|
132
|
+
byteLength: number;
|
|
133
|
+
mimeType: string;
|
|
134
|
+
}>;
|
|
135
|
+
}
|
|
136
|
+
export interface PendingExec {
|
|
137
|
+
execId: string;
|
|
138
|
+
execMsgId: number;
|
|
139
|
+
toolCallId: string;
|
|
140
|
+
toolName: string;
|
|
141
|
+
decodedArgs: string;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Latest upstream checkpoint for a bridge, held by reference so it survives a tool pause.
|
|
145
|
+
*
|
|
146
|
+
* Each resume re-enters the stream writer with fresh locals, but the bridge — and the frames
|
|
147
|
+
* still arriving on it — outlive that boundary. A checkpoint delivered during a pause would be
|
|
148
|
+
* stranded in the previous round's closure without a shared cell.
|
|
149
|
+
*/
|
|
150
|
+
export interface CheckpointRef {
|
|
151
|
+
current: Uint8Array | null;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Pi's view of the turn in flight, as opposed to the wire history sent upstream.
|
|
155
|
+
* Behaviour lives in ./client-transcript.ts.
|
|
156
|
+
*/
|
|
157
|
+
export type ClientTranscript = {
|
|
158
|
+
kind: "live";
|
|
159
|
+
completedTurns: ParsedTurn[];
|
|
160
|
+
} | {
|
|
161
|
+
kind: "recovered";
|
|
162
|
+
completedTurns: ParsedTurn[];
|
|
163
|
+
inFlightTurn: ParsedTurn;
|
|
164
|
+
};
|
|
165
|
+
export interface ActiveBridge {
|
|
166
|
+
bridge: BridgeHandle;
|
|
167
|
+
heartbeatTimer: ReturnType<typeof setInterval>;
|
|
168
|
+
toolTimeoutTimer?: ReturnType<typeof setTimeout>;
|
|
169
|
+
blobStore: Map<string, Uint8Array>;
|
|
170
|
+
mcpTools: McpToolDefinition[];
|
|
171
|
+
pendingExecs: PendingExec[];
|
|
172
|
+
currentTurn: ParsedTurn;
|
|
173
|
+
checkpointRef: CheckpointRef;
|
|
174
|
+
state: StreamState;
|
|
175
|
+
/** Fingerprint of the completed turns this bridge was parked on; guards against key collisions. */
|
|
176
|
+
historyFingerprint: string;
|
|
177
|
+
/** Pi's completed-turn history when the wire current turn is synthetic after recovery. */
|
|
178
|
+
clientTranscript?: ClientTranscript;
|
|
179
|
+
}
|
|
180
|
+
export interface StoredConversation {
|
|
181
|
+
conversationId: string;
|
|
182
|
+
checkpoint: Uint8Array | null;
|
|
183
|
+
checkpointSource?: "upstream" | "absent";
|
|
184
|
+
checkpointTurnCount?: number;
|
|
185
|
+
checkpointHistoryFingerprint?: string;
|
|
186
|
+
midPausePendingToolCalls?: Array<{
|
|
187
|
+
toolCallId: string;
|
|
188
|
+
toolName: string;
|
|
189
|
+
}>;
|
|
190
|
+
midPauseTurnCount?: number;
|
|
191
|
+
midPauseHistoryFingerprint?: string;
|
|
192
|
+
midPauseRecordedAtMs?: number;
|
|
193
|
+
/** Hash of the system prompt last published to Cursor for this conversation. */
|
|
194
|
+
systemPromptHash?: string;
|
|
195
|
+
/**
|
|
196
|
+
* `contextTokens` reported by the previous turn's checkpoint. Cursor's
|
|
197
|
+
* streaming wire has no per-turn cache-read/write breakdown (only a total
|
|
198
|
+
* `tokenDetails.usedTokens`), so this is the basis for estimating how much
|
|
199
|
+
* of a continuation turn's input was already cached vs newly written.
|
|
200
|
+
*/
|
|
201
|
+
lastContextTokens?: number;
|
|
202
|
+
sessionScoped: boolean;
|
|
203
|
+
sessionId?: string;
|
|
204
|
+
blobStore: Map<string, Uint8Array>;
|
|
205
|
+
lastAccessMs: number;
|
|
206
|
+
}
|
|
207
|
+
export interface StreamState {
|
|
208
|
+
/** Rejected native calls since the last Pi result. Stop is deferred while Pi calls await results. */
|
|
209
|
+
localToolRejections?: number;
|
|
210
|
+
/** Model steps with a rejected native call since the last Pi result; a parallel batch is one. */
|
|
211
|
+
localToolRejectionSteps?: number;
|
|
212
|
+
/** True until the next checkpoint: further rejections belong to the step already counted. */
|
|
213
|
+
localToolRejectionStepOpen?: boolean;
|
|
214
|
+
toolCallIndex: number;
|
|
215
|
+
pendingExecs: PendingExec[];
|
|
216
|
+
outputTokens: number;
|
|
217
|
+
totalTokens: number;
|
|
218
|
+
/** Input/context tokens from the last checkpoint `tokenDetails.usedTokens`. */
|
|
219
|
+
contextTokens?: number;
|
|
220
|
+
/** `contextTokens` from the previous turn on this conversation, if any (see StoredConversation). */
|
|
221
|
+
previousContextTokens?: number;
|
|
222
|
+
/** Set once Cursor reported `turnEnded`; a connection close after it is a completed turn. */
|
|
223
|
+
turnEnded: boolean;
|
|
224
|
+
/** The counters `turnEnded` carried, when it carried any. They cover the whole run. */
|
|
225
|
+
turnEndedUsage?: CursorRunUsage;
|
|
226
|
+
/**
|
|
227
|
+
* What Pi was billed for earlier messages of this Cursor run. One object per run: a stream
|
|
228
|
+
* resumed on the parked bridge shares it, a new run starts a new one.
|
|
229
|
+
*/
|
|
230
|
+
runUsage?: CursorRunUsage;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Token counts in Pi's buckets. `input` is fresh input, net of cache reads and writes.
|
|
234
|
+
*
|
|
235
|
+
* Cursor reports a run's counters once, on `turnEnded`, summed over every model step. A run
|
|
236
|
+
* paused for Pi tools spans several assistant messages, so the message that ends it is billed
|
|
237
|
+
* the counters minus what the earlier ones were billed (see `applyCursorUsage`).
|
|
238
|
+
*/
|
|
239
|
+
export interface CursorRunUsage {
|
|
240
|
+
input: number;
|
|
241
|
+
output: number;
|
|
242
|
+
cacheRead: number;
|
|
243
|
+
cacheWrite: number;
|
|
244
|
+
}
|
|
245
|
+
export interface CursorNativeStreamConfig {
|
|
246
|
+
/**
|
|
247
|
+
* Declared as a property rather than a method: the runtime passes this
|
|
248
|
+
* reference on to the idle-retry path, so it must not depend on `this`.
|
|
249
|
+
*/
|
|
250
|
+
getAccessToken: (options?: {
|
|
251
|
+
forceRefresh?: boolean;
|
|
252
|
+
}) => Promise<string>;
|
|
253
|
+
getNoReasoningEffortByModelId?(): Map<string, string>;
|
|
254
|
+
getRawModelRoutingByModelId?(): Map<string, Record<string, CursorNativeModelRouting>>;
|
|
255
|
+
/**
|
|
256
|
+
* Explicit agent endpoint override for this stream, caller-validated
|
|
257
|
+
* (HTTPS, or loopback HTTP; no credentials). Without it the wire falls back
|
|
258
|
+
* to getCursorAgentUrl()'s chain (host env → Cursor CLI config → default).
|
|
259
|
+
* Must stay stable for one session/bridgeKey: Run bridges are pooled by
|
|
260
|
+
* bridgeKey and idle reuse assumes a single endpoint per key.
|
|
261
|
+
*/
|
|
262
|
+
agentUrl?: string;
|
|
263
|
+
}
|
|
264
|
+
export type CursorNativeStreamOptions = SimpleStreamOptions & {
|
|
265
|
+
toolChoice?: unknown;
|
|
266
|
+
/** Absolute workspace directory for conversationState.previousWorkspaceUris; defaults to process.cwd(). */
|
|
267
|
+
workspacePath?: string;
|
|
268
|
+
};
|
|
269
|
+
export type NativeBlockKind = "text" | "thinking";
|
|
270
|
+
export interface NativeStreamWriter {
|
|
271
|
+
output: AssistantMessage;
|
|
272
|
+
closed: boolean;
|
|
273
|
+
start(): void;
|
|
274
|
+
text(delta: string): void;
|
|
275
|
+
thinking(delta: string): void;
|
|
276
|
+
toolCall(exec: PendingExec): void;
|
|
277
|
+
done(reason: "stop" | "length" | "toolUse", state?: StreamState): void;
|
|
278
|
+
error(message: string, reason: "error" | "aborted", state?: StreamState): void;
|
|
279
|
+
}
|
|
280
|
+
export interface IdleRestartContext {
|
|
281
|
+
/** True when text/thinking was already pushed to the Pi writer. */
|
|
282
|
+
emittedUserVisibleContent: boolean;
|
|
283
|
+
latestCheckpoint: Uint8Array | null;
|
|
284
|
+
blobStore: Map<string, Uint8Array>;
|
|
285
|
+
completedTurns: ParsedTurn[];
|
|
286
|
+
currentTurn: ParsedTurn;
|
|
287
|
+
}
|
|
288
|
+
export interface StreamIdleRetryController {
|
|
289
|
+
/** Preserve the rejection budget across transport retries. */
|
|
290
|
+
localToolRejections?: number;
|
|
291
|
+
localToolRejectionSteps?: number;
|
|
292
|
+
currentAttempt: number;
|
|
293
|
+
maxRetries: number;
|
|
294
|
+
recoverBeforeRetry?: boolean;
|
|
295
|
+
/** Idle recoveries taken in a row since the model last produced output. */
|
|
296
|
+
idleRecoveries?: number;
|
|
297
|
+
restart(nextAttempt: number, context: IdleRestartContext): boolean;
|
|
298
|
+
}
|
|
299
|
+
export interface NativeStreamAttemptInput {
|
|
300
|
+
/** Carry the budget when a tool continuation rebuilds its transport. */
|
|
301
|
+
localToolRejections?: number;
|
|
302
|
+
localToolRejectionSteps?: number;
|
|
303
|
+
accessToken: string;
|
|
304
|
+
requestBytes: Uint8Array;
|
|
305
|
+
blobStore: Map<string, Uint8Array>;
|
|
306
|
+
mcpTools: McpToolDefinition[];
|
|
307
|
+
model: Model<Api>;
|
|
308
|
+
modelId: string;
|
|
309
|
+
bridgeKey: string;
|
|
310
|
+
convKey: string;
|
|
311
|
+
completedTurns: ParsedTurn[];
|
|
312
|
+
/**
|
|
313
|
+
* The turns the request carries before `currentTurn`, when they differ from `completedTurns`.
|
|
314
|
+
* Checkpoint tool recovery adds Pi's in-flight turn here and not to `completedTurns`, which
|
|
315
|
+
* history fingerprints and checkpoint commits compare with Pi's next request. A checkpoint
|
|
316
|
+
* continuation rebuilds its request from these.
|
|
317
|
+
*/
|
|
318
|
+
requestTurns?: ParsedTurn[];
|
|
319
|
+
currentTurn: ParsedTurn;
|
|
320
|
+
/** Pi's transcript when `completedTurns`/`currentTurn` are a recovered wire view. */
|
|
321
|
+
clientTranscript?: ClientTranscript;
|
|
322
|
+
writer: NativeStreamWriter;
|
|
323
|
+
options?: CursorNativeStreamOptions;
|
|
324
|
+
requestId?: string;
|
|
325
|
+
maxIdleRetries?: number;
|
|
326
|
+
streamIdleTimeoutMs?: number;
|
|
327
|
+
getAccessToken?: (options?: {
|
|
328
|
+
forceRefresh?: boolean;
|
|
329
|
+
}) => Promise<string>;
|
|
330
|
+
/** When true, idle timeout tries recovery/rebuild before a blind restart. */
|
|
331
|
+
recoverBeforeRetry?: boolean;
|
|
332
|
+
/** Required for checkpoint-based continuation after transport loss. */
|
|
333
|
+
systemPrompt?: string;
|
|
334
|
+
conversationId?: string;
|
|
335
|
+
maxMode?: boolean;
|
|
336
|
+
cursorModelParameters?: CursorModelParameter[];
|
|
337
|
+
/** Explicit agent endpoint for the Run bridge; see CursorNativeStreamConfig.agentUrl. */
|
|
338
|
+
agentUrl?: string;
|
|
339
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain enums for the cursor-protocol layer.
|
|
3
|
+
*
|
|
4
|
+
* Only constants with live consumers remain here; the legacy pi-extension
|
|
5
|
+
* credential/provider constants were removed with the extension entry they
|
|
6
|
+
* served (2026-11-28 cleanup of the pre-refactor wiring).
|
|
7
|
+
*/
|
|
8
|
+
/** Reasoning effort levels recognized by Pi AI. */
|
|
9
|
+
export type PiThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
10
|
+
/** Wire protocol drift signal categories. */
|
|
11
|
+
export declare enum DriftKind {
|
|
12
|
+
ServerMessage = "server_message",
|
|
13
|
+
InteractionUpdate = "interaction_update",
|
|
14
|
+
KvMessage = "kv_message",
|
|
15
|
+
InteractionQuery = "interaction_query",
|
|
16
|
+
ExecMessage = "exec_message",
|
|
17
|
+
UnknownFields = "unknown_fields"
|
|
18
|
+
}
|
|
19
|
+
export type DriftKindType = `${DriftKind}`;
|
|
20
|
+
/** Classified bridge exit and transport failure types. */
|
|
21
|
+
export declare enum TransportFailureKind {
|
|
22
|
+
ConnectTimeout = "connect_timeout",
|
|
23
|
+
SocketTimeout = "socket_timeout",
|
|
24
|
+
ConnectionReset = "connection_reset",
|
|
25
|
+
Goaway = "goaway",
|
|
26
|
+
BridgeCrash = "bridge_crash",
|
|
27
|
+
UpstreamSilence = "upstream_silence",
|
|
28
|
+
UpstreamInternal = "upstream_internal",
|
|
29
|
+
Authentication = "authentication",
|
|
30
|
+
RateLimit = "rate_limit",
|
|
31
|
+
ProtocolDrift = "protocol_drift",
|
|
32
|
+
InvalidRequest = "invalid_request",
|
|
33
|
+
Unknown = "unknown"
|
|
34
|
+
}
|
|
35
|
+
export type TransportFailureKindType = `${TransportFailureKind}`;
|
|
36
|
+
/** Connect RPC framing flags. */
|
|
37
|
+
export declare enum ConnectFlag {
|
|
38
|
+
None = 0,
|
|
39
|
+
EndStream = 2
|
|
40
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Resolve (and create) the cache directory. Returns undefined if unusable. */
|
|
2
|
+
export declare function getCacheDir(): string | undefined;
|
|
3
|
+
/** Absolute path for a cache file, or undefined when no cache dir is usable. */
|
|
4
|
+
export declare function cacheFilePath(name: string): string | undefined;
|
|
5
|
+
/** Test helper: forget the resolved directory between cases. */
|
|
6
|
+
export declare function resetCacheDirForTests(): void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Prevent token exfiltration via poisoned agent URL. */
|
|
2
|
+
export declare function assertSafeCursorBaseUrl(raw: string): string;
|
|
3
|
+
/** Redact JWTs, bearer tokens, and common secret keys from diagnostics/errors. */
|
|
4
|
+
export declare function redactSecrets(text: string): string;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export { createCursorNativeStream } from "./cursor-protocol/stream/native-core.js";
|
|
2
|
+
export { destroyAllIdleBridges, activeBridges } from "./cursor-protocol/stream/bridge-session.js";
|
|
3
|
+
export type { CursorNativeStreamConfig } from "./cursor-protocol/stream/types.js";
|
|
4
|
+
export { createCursorAuthClient, getTokenExpiry, type CursorCredentials } from "./cursor-protocol/auth/oauth.js";
|
|
5
|
+
export { redactSecrets } from "./cursor-protocol/utils/security.js";
|
|
6
|
+
export { processModels, buildRawModelLookup, type ProcessedModel } from "./cursor-protocol/models/processing.js";
|
|
7
|
+
export type { CursorModel } from "./cursor-protocol/stream/model-discovery.js";
|
|
8
|
+
export type { CursorNativeModelRouting } from "./cursor-protocol/stream/model-routing.js";
|
|
9
|
+
export { FALLBACK_MODELS, FALLBACK_AUTO_MODEL } from "./cursor-protocol/models/parameterized.js";
|
|
10
|
+
export { DEFAULT_CURSOR_AGENT_URL, DEFAULT_CURSOR_API_URL, } from "./cursor-protocol/config/index.js";
|
|
11
|
+
export { DEFAULT_CONTEXT_WINDOW, DEFAULT_MAX_OUTPUT_TOKENS, } from "./cursor-protocol/models/limits.js";
|
|
12
|
+
export { CURSOR_CLI_MAX_IMAGE_BYTES } from "./cursor-protocol/stream/images.js";
|
|
13
|
+
export interface RustStream {
|
|
14
|
+
nextEvent(): Promise<string | null | undefined>;
|
|
15
|
+
cancel(): void;
|
|
16
|
+
setAccessToken(token: string): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export interface RustEngine {
|
|
19
|
+
start(request: string, accessToken: string): Promise<RustStream>;
|
|
20
|
+
listModels(accessToken: string, url?: string): Promise<string>;
|
|
21
|
+
getUsage?(accessToken: string): Promise<string>;
|
|
22
|
+
/** Atomic payload accounting, not a process RSS guarantee. */
|
|
23
|
+
resourceStats?(): string;
|
|
24
|
+
/** Explicit dry-run by default; only a previously registered scope/root. */
|
|
25
|
+
maintainCache?(scope: string, apply?: boolean): Promise<string>;
|
|
26
|
+
remove(scope: string): Promise<void>;
|
|
27
|
+
shutdown(): void;
|
|
28
|
+
}
|
|
29
|
+
export declare function nativeVersion(): string;
|
|
30
|
+
export declare function createRustEngine(): RustEngine;
|
|
31
|
+
/** Explicit test/process teardown; production adapters own their engine. */
|
|
32
|
+
export declare function shutdownRustEngines(): void;
|