@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 cursor-native contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cursor-harness-provider/native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared pure-JavaScript Cursor protocol/session runtime for coding harnesses. Normally installed as a dependency of the Pi or OpenCode adapter.
|
|
4
|
+
|
|
5
|
+
Requires Node >=22.19 (or the validated OpenCode Bun host). The runtime is pure JavaScript over `node:http2`; there is no native binary, install script, toolchain download or CLI/JS inference fallback. The public `RustEngine`/`RustStream` entry-point names are retained from the former Rust binding for host-adapter compatibility.
|
|
6
|
+
|
|
7
|
+
Release gates still cover macOS 15+ (arm64/x64) and Linux x64 GNU (Ubuntu 22.04/glibc 2.35+) hosts; the shipped packages themselves are platform-independent. Windows, Linux arm64 and musl are not part of the release gates.
|
|
8
|
+
|
|
9
|
+
See LICENSE, THIRD_PARTY_NOTICES.md and licenses/ for attribution. This is experimental and unofficial, not endorsed by Cursor/Anysphere. Public package availability is determined by the release, not by the existence of this source README.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
The project's MIT license is included in `LICENSE`.
|
|
4
|
+
|
|
5
|
+
## pi-cursor source and schema
|
|
6
|
+
|
|
7
|
+
The protocol/session implementation adapts source/schema from MIT-licensed
|
|
8
|
+
`Rahularya01/pi-cursor` 1.4.39, revision
|
|
9
|
+
`ef3cafb5c38081ce6e06df8e594241aabd9621e3`.
|
|
10
|
+
The original copyright and full license are included in `licenses/pi-cursor/LICENSE`.
|
|
11
|
+
The upstream JavaScript inference engine is not included in this package.
|
|
12
|
+
|
|
13
|
+
The runtime is pure JavaScript with no native binary; there are no
|
|
14
|
+
redistributed native dependency inventories in this package.
|
|
15
|
+
`licenses/distribution.json` records the license file hashes above.
|
|
16
|
+
No blanket legal-compliance certification is claimed.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor OAuth authentication via PKCE.
|
|
3
|
+
*
|
|
4
|
+
* Flow:
|
|
5
|
+
* 1. Generate PKCE verifier + challenge
|
|
6
|
+
* 2. Open browser to cursor.com/loginDeepControl
|
|
7
|
+
* 3. Poll api2.cursor.sh/auth/poll until tokens arrive
|
|
8
|
+
* 4. Refresh via api2.cursor.sh/auth/exchange_user_api_key
|
|
9
|
+
*
|
|
10
|
+
* Based on https://github.com/ephraimduncan/opencode-cursor by Ephraim Duncan.
|
|
11
|
+
*/
|
|
12
|
+
export interface CursorAuthParams {
|
|
13
|
+
verifier: string;
|
|
14
|
+
challenge: string;
|
|
15
|
+
uuid: string;
|
|
16
|
+
loginUrl: string;
|
|
17
|
+
}
|
|
18
|
+
export interface CursorAuthClientDependencies {
|
|
19
|
+
fetch?: typeof fetch;
|
|
20
|
+
generatePkce?: () => Promise<{
|
|
21
|
+
verifier: string;
|
|
22
|
+
challenge: string;
|
|
23
|
+
uuid?: string;
|
|
24
|
+
}>;
|
|
25
|
+
randomUUID?: () => string;
|
|
26
|
+
sleep?: (ms: number) => Promise<void>;
|
|
27
|
+
requestTimeoutMs?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface CursorAuthLoginCallbacks {
|
|
30
|
+
onAuth(payload: {
|
|
31
|
+
url: string;
|
|
32
|
+
}): void | Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
export declare function createCursorAuthClient(deps?: CursorAuthClientDependencies): {
|
|
35
|
+
generateParams: () => Promise<CursorAuthParams>;
|
|
36
|
+
login: (callbacks: CursorAuthLoginCallbacks, options?: {
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
}) => Promise<CursorCredentials>;
|
|
39
|
+
poll: (uuid: string, verifier: string, options?: {
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
}) => Promise<{
|
|
42
|
+
accessToken: string;
|
|
43
|
+
refreshToken: string;
|
|
44
|
+
}>;
|
|
45
|
+
refreshToken: (refreshToken: string, options?: {
|
|
46
|
+
signal?: AbortSignal;
|
|
47
|
+
}) => Promise<CursorCredentials>;
|
|
48
|
+
};
|
|
49
|
+
export declare function generateCursorAuthParams(): Promise<CursorAuthParams>;
|
|
50
|
+
export declare function pollCursorAuth(uuid: string, verifier: string, options?: {
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
accessToken: string;
|
|
54
|
+
refreshToken: string;
|
|
55
|
+
}>;
|
|
56
|
+
export interface CursorCredentials {
|
|
57
|
+
access: string;
|
|
58
|
+
refresh: string;
|
|
59
|
+
expires: number;
|
|
60
|
+
}
|
|
61
|
+
export declare function refreshCursorToken(refreshToken: string, options?: {
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
}): Promise<CursorCredentials>;
|
|
64
|
+
export declare function getCursorAccessTokenFromEnv(): string | undefined;
|
|
65
|
+
export declare function getTokenExpiry(token: string): number;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export declare const MAX_BRIDGE_MESSAGE_BYTES: number;
|
|
2
|
+
export declare const MAX_CONNECT_MESSAGE_BYTES: number;
|
|
3
|
+
export interface SpawnBridgeOptions {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
rpcPath: string;
|
|
6
|
+
url?: string;
|
|
7
|
+
unary?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Keep the HTTP/2 session alive after a stream ends so the next turn can
|
|
10
|
+
* open a new stream without a process spawn + TLS handshake. Streaming
|
|
11
|
+
* chat uses this; unary RPCs do not.
|
|
12
|
+
*/
|
|
13
|
+
persistent?: boolean;
|
|
14
|
+
/** Initial connect idle kill (ms). Default 30s. */
|
|
15
|
+
connectTimeoutMs?: number;
|
|
16
|
+
/** Activity idle kill after first I/O (ms). Default 15m. */
|
|
17
|
+
idleTimeoutMs?: number;
|
|
18
|
+
/** Extra request headers for every stream the bridge opens, persistent reopens included. */
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
/** Minimal shape a `BridgeHandle` needs for forceful teardown — no longer literally a child
|
|
22
|
+
* process now that the transport runs in-process, but kept `.kill()`-shaped since every call
|
|
23
|
+
* site only ever calls it and never inspects anything else. */
|
|
24
|
+
export interface BridgeProcessHandle {
|
|
25
|
+
kill(): boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface BridgeHandle {
|
|
28
|
+
proc: BridgeProcessHandle;
|
|
29
|
+
readonly alive: boolean;
|
|
30
|
+
/** Trailing transport diagnostics (HTTP/2 errors, GOAWAY, non-2xx bodies). */
|
|
31
|
+
lastStderr(): string;
|
|
32
|
+
write(data: Uint8Array): void;
|
|
33
|
+
end(): void;
|
|
34
|
+
onData(cb: (chunk: Buffer) => void): void;
|
|
35
|
+
onClose(cb: (code: number) => void): void;
|
|
36
|
+
/**
|
|
37
|
+
* Open a new Connect stream on a persistent bridge. Absent on one-shot
|
|
38
|
+
* (unary / test) handles.
|
|
39
|
+
*/
|
|
40
|
+
openStream?(accessToken: string): void;
|
|
41
|
+
/** Fires when a persistent bridge reports the current stream ended. */
|
|
42
|
+
onStreamDone?(cb: () => void): void;
|
|
43
|
+
}
|
|
44
|
+
export type BridgeFactory = (options: SpawnBridgeOptions) => BridgeHandle;
|
|
45
|
+
export type BridgeDebugLog = (event: string, data?: Record<string, unknown>) => void;
|
|
46
|
+
export declare function frameConnectMessage(data: Uint8Array, flags?: number): Buffer;
|
|
47
|
+
/**
|
|
48
|
+
* Opens a `BridgeHandle` for one Cursor Connect RPC (streaming or unary), backed directly by an
|
|
49
|
+
* in-process HTTP/2 session — see `h2-session.ts` for the transport implementation and why no
|
|
50
|
+
* subprocess is needed.
|
|
51
|
+
*/
|
|
52
|
+
export declare function spawnBridge(options: SpawnBridgeOptions, debugLog?: BridgeDebugLog): BridgeHandle;
|
|
53
|
+
/** Attached to the error thrown for a declared-length overflow so callers can log forensics
|
|
54
|
+
* (behind PI_CURSOR_PROVIDER_DEBUG) without needing to re-derive parser-internal state. */
|
|
55
|
+
export interface ConnectFrameDesyncDiagnostics {
|
|
56
|
+
/** Bytes successfully parsed into complete frames before the desync, across this parser's life. */
|
|
57
|
+
bytesConsumedBeforeDesync: number;
|
|
58
|
+
/** Number of complete frames successfully parsed before the desync. */
|
|
59
|
+
framesParsedBeforeDesync: number;
|
|
60
|
+
/** Hex of the 5-byte header read as the (bogus) next frame. */
|
|
61
|
+
headerHex: string;
|
|
62
|
+
/** Hex of up to 32 bytes immediately following the header, for context. */
|
|
63
|
+
trailingContextHex: string;
|
|
64
|
+
}
|
|
65
|
+
export declare function createConnectFrameParser(onMessage: (bytes: Uint8Array) => void, onEndStream: (bytes: Uint8Array) => void): (incoming: Buffer) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Cursor's own account of a failed run, from the `aiserver.v1.ErrorDetails` entry of a Connect
|
|
68
|
+
* end-stream error. The top-level `message` is usually just `"Error"`; this is where Cursor
|
|
69
|
+
* says what happened (`Model name is not valid: "..."`, a provider outage, a usage limit).
|
|
70
|
+
*/
|
|
71
|
+
export interface CursorErrorDetail {
|
|
72
|
+
/** Cursor's error enum, e.g. `ERROR_BAD_MODEL_NAME` or `ERROR_PROVIDER_ERROR`. */
|
|
73
|
+
errorCode?: string;
|
|
74
|
+
title?: string;
|
|
75
|
+
detail?: string;
|
|
76
|
+
/** HTTP status the upstream model provider returned to Cursor, when Cursor reports one. */
|
|
77
|
+
providerStatusCode?: string;
|
|
78
|
+
}
|
|
79
|
+
/** The detail `parseConnectEndStream` found on an end-stream error, if Cursor sent one. */
|
|
80
|
+
export declare function cursorErrorDetailOf(error: unknown): CursorErrorDetail | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* The error's `message` stays `Connect error <code>: <message>`: retry classification matches on
|
|
83
|
+
* it, and Cursor's free-form detail text must not change which failures are retried. The detail
|
|
84
|
+
* rides alongside (`cursorErrorDetailOf`) for the message the user finally sees.
|
|
85
|
+
*/
|
|
86
|
+
export declare function parseConnectEndStream(data: Uint8Array): Error | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface CursorModelParameter {
|
|
2
|
+
id: string;
|
|
3
|
+
value: string;
|
|
4
|
+
}
|
|
5
|
+
export interface CursorParameterizedVariant {
|
|
6
|
+
parameters: CursorModelParameter[];
|
|
7
|
+
isMaxMode: boolean;
|
|
8
|
+
isDefaultMaxConfig?: boolean;
|
|
9
|
+
isDefaultNonMaxConfig?: boolean;
|
|
10
|
+
displayName?: string;
|
|
11
|
+
displayNameOutsidePicker?: string;
|
|
12
|
+
variantStringRepresentation?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CursorParameterizedModel {
|
|
15
|
+
name: string;
|
|
16
|
+
clientDisplayName?: string;
|
|
17
|
+
serverModelName?: string;
|
|
18
|
+
supportsMaxMode?: boolean;
|
|
19
|
+
supportsNonMaxMode?: boolean;
|
|
20
|
+
supportsImages?: boolean;
|
|
21
|
+
contextTokenLimit?: number;
|
|
22
|
+
contextTokenLimitForMaxMode?: number;
|
|
23
|
+
variants: CursorParameterizedVariant[];
|
|
24
|
+
}
|
|
25
|
+
export declare function encodeAvailableModelsRequest(): Uint8Array;
|
|
26
|
+
export declare function decodeAvailableModelsResponse(bytes: Uint8Array): CursorParameterizedModel[];
|
|
27
|
+
export declare function buildSelectedContextBlob(rootPromptBlobIds: Uint8Array[], clientName: string): Uint8Array;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type BridgeDebugLog, type BridgeHandle, type SpawnBridgeOptions } from "./bridge.js";
|
|
2
|
+
/** The host that serves RunSSE and BidiAppend over HTTP/1.1. */
|
|
3
|
+
export declare const CURSOR_HTTP1_BASE_URL = "https://api2.cursor.sh";
|
|
4
|
+
export declare const CURSOR_RUN_PATH = "/agent.v1.AgentService/Run";
|
|
5
|
+
/** After HTTP/2 failed to negotiate, how long new runs go straight to HTTP/1.1. */
|
|
6
|
+
export declare const HTTP2_UNAVAILABLE_TTL_MS: number;
|
|
7
|
+
export declare function createHttp1RunBridge(options: SpawnBridgeOptions, debugLog: BridgeDebugLog, baseUrl?: string): BridgeHandle;
|
|
8
|
+
export type RunTransport = "auto" | "http2" | "http1";
|
|
9
|
+
/** `PI_CURSOR_TRANSPORT`: `http1` or `http2` forces one; anything else is `auto`. */
|
|
10
|
+
export declare function resolveRunTransport(envValue?: string | undefined): RunTransport;
|
|
11
|
+
export declare function isHttp2Unavailable(stderr: string): boolean;
|
|
12
|
+
/** Whether a recent run found HTTP/2 unavailable, so new runs go straight to HTTP/1.1. */
|
|
13
|
+
export declare function http2KnownUnavailable(): boolean;
|
|
14
|
+
export declare function resetHttp2AvailabilityForTests(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Starts on HTTP/2 and replays the run on HTTP/1.1 if HTTP/2 could not be negotiated. The
|
|
17
|
+
* replay is safe only while Cursor has sent nothing back: a connection that never negotiated
|
|
18
|
+
* HTTP/2 never delivered the run request either. Once data arrives, this is a plain HTTP/2
|
|
19
|
+
* bridge.
|
|
20
|
+
*/
|
|
21
|
+
export declare function withHttp1Fallback(primary: BridgeHandle, makeFallback: () => BridgeHandle, debugLog: BridgeDebugLog): BridgeHandle;
|
|
22
|
+
/** The bridge for one `AgentService/Run` stream, on the transport `PI_CURSOR_TRANSPORT` asks for. */
|
|
23
|
+
export declare function createRunBridge(options: SpawnBridgeOptions, debugLog: BridgeDebugLog): BridgeHandle;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import tls from "node:tls";
|
|
2
|
+
export declare function resolveCursorProxyUrl(): URL | undefined;
|
|
3
|
+
export declare function connectProxiedSocket(proxyUrl: URL, targetOrigin: string, options?: {
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
timeoutMs?: number;
|
|
6
|
+
alpnProtocols?: string[];
|
|
7
|
+
}): Promise<tls.TLSSocket>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-process HTTP/2 transport for Cursor's Connect RPCs — streaming (bidirectional) and unary.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the old h2-bridge.mjs Node child process. Writes (heartbeats, interaction
|
|
5
|
+
* responses, exec results) are interleaved with reads throughout the stream's life, no
|
|
6
|
+
* subprocess. ALPN negotiation can still fail behind an ALPN-stripping TLS proxy (see
|
|
7
|
+
* `describeH2TransportError`) — an environment issue, not a bidirectional-streaming bug.
|
|
8
|
+
*
|
|
9
|
+
* This module reproduces h2-bridge.mjs's exact externally observable protocol — the same
|
|
10
|
+
* onData frames and onClose exit codes for the same conditions (clean end, non-2xx status,
|
|
11
|
+
* GOAWAY, transport error, idle/connect timeout) — just as direct in-process event wiring
|
|
12
|
+
* instead of a length-prefixed pipe to a child process. Every consumer (bridge-session.ts,
|
|
13
|
+
* native-core.ts, model-discovery.ts) drives the `BridgeHandle` interface and does not care which
|
|
14
|
+
* transport is behind it, so this is a byte-for-byte behavioral port, not a redesign: keeping
|
|
15
|
+
* that behavior identical is what keeps the retry/recovery logic downstream correct unchanged.
|
|
16
|
+
*/
|
|
17
|
+
import http2 from "node:http2";
|
|
18
|
+
import { type BridgeDebugLog, type BridgeHandle, type SpawnBridgeOptions } from "./bridge.js";
|
|
19
|
+
/**
|
|
20
|
+
* Maps an opaque HTTP/2 negotiation failure into an actionable diagnostic message.
|
|
21
|
+
*
|
|
22
|
+
* An ALPN-stripping TLS-intercepting proxy (e.g. Zscaler) makes the TLS handshake negotiate no
|
|
23
|
+
* `h2` protocol. Bun throws `ERR_HTTP2_ERROR: h2 is not supported`; Node connects anyway, so the
|
|
24
|
+
* session checks ALPN itself on connect (see `createBridgeHandleForSession`). The streaming Run
|
|
25
|
+
* RPC then falls back to HTTP/1.1 (h1-bridge.ts); unary RPCs cannot. Non-ALPN errors pass
|
|
26
|
+
* through untouched.
|
|
27
|
+
*/
|
|
28
|
+
export declare function describeH2TransportError(error: unknown, baseUrl: string): string;
|
|
29
|
+
/** The slice of `http2.ClientHttp2Session` this module depends on — narrowed so tests can inject
|
|
30
|
+
* a fake session without standing up a real TLS/H2 connection. */
|
|
31
|
+
export type H2Session = Pick<http2.ClientHttp2Session, "request" | "on" | "close" | "destroy"> & {
|
|
32
|
+
readonly destroyed: boolean;
|
|
33
|
+
readonly closed: boolean;
|
|
34
|
+
/** The connection the session runs on; absent on test doubles. */
|
|
35
|
+
readonly socket?: unknown;
|
|
36
|
+
ping?(callback: (err: Error | null) => void): void;
|
|
37
|
+
};
|
|
38
|
+
/** The slice of `http2.ClientHttp2Stream` this module depends on. */
|
|
39
|
+
export type H2Stream = Pick<http2.ClientHttp2Stream, "write" | "end" | "on" | "destroy" | "close"> & {
|
|
40
|
+
readonly destroyed: boolean;
|
|
41
|
+
readonly closed: boolean;
|
|
42
|
+
readonly writableLength: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Builds a `BridgeHandle` on top of an already-connected `H2Session`. Split out from
|
|
46
|
+
* `createInProcessBridge` so tests can drive the state machine against a fake session/stream pair
|
|
47
|
+
* instead of a real HTTP/2 connection — the same seam `createBridgeHandleForChild` used to provide
|
|
48
|
+
* for the subprocess implementation.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createBridgeHandleForSession(session: H2Session, options: SpawnBridgeOptions, debugLog: BridgeDebugLog): BridgeHandle;
|
|
51
|
+
export declare function createInProcessBridge(options: SpawnBridgeOptions, debugLog: BridgeDebugLog): BridgeHandle;
|
|
52
|
+
export declare const __testInternals: {
|
|
53
|
+
createBridgeHandleForSession: typeof createBridgeHandleForSession;
|
|
54
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const MAX_UNARY_RESPONSE_BYTES: number;
|
|
2
|
+
export interface UnaryH2Options {
|
|
3
|
+
accessToken: string;
|
|
4
|
+
rpcPath: string;
|
|
5
|
+
requestBody: Uint8Array;
|
|
6
|
+
url?: string;
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
}
|
|
10
|
+
export interface UnaryH2Result {
|
|
11
|
+
status: number;
|
|
12
|
+
body: Buffer;
|
|
13
|
+
}
|
|
14
|
+
/** True when node:http2 client sessions are usable in this runtime. */
|
|
15
|
+
export declare function supportsInProcessH2(): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Perform one unary Connect RPC over an in-process HTTP/2 session.
|
|
18
|
+
*
|
|
19
|
+
* Rejects on transport failure so callers can fall back to the general-purpose
|
|
20
|
+
* bridge transport (h2-session.ts); a non-2xx response resolves normally with
|
|
21
|
+
* the status for the caller to interpret.
|
|
22
|
+
*/
|
|
23
|
+
export declare function callUnaryOverH2(options: UnaryH2Options): Promise<UnaryH2Result>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const DEFAULT_CURSOR_AGENT_URL = "https://agentn.us.api5.cursor.sh";
|
|
2
|
+
/**
|
|
3
|
+
* Home of the aiserver.v1 RPCs (AvailableModels). The agent endpoint never
|
|
4
|
+
* substitutes for it: routing AvailableModels at agentn returns an empty list
|
|
5
|
+
* and silently drops every parameterized model family from the catalogs.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_CURSOR_API_URL = "https://api2.cursor.sh";
|
|
8
|
+
/**
|
|
9
|
+
* The Cursor CLI build this client announces. Cursor gates protocol features on it, so it follows
|
|
10
|
+
* the build `proto/agent.proto` was last synced from; raise both together, after a live check.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_CURSOR_CLIENT_VERSION = "cli-2026.10.22-27dcf5f";
|
|
13
|
+
export declare function normalizeCursorUrl(value: unknown): string | undefined;
|
|
14
|
+
export declare function readCursorCliAgentUrl(): string | undefined;
|
|
15
|
+
export declare function getCursorClientVersion(): string;
|
|
16
|
+
/** Resolve the agent base URL, validating host against the allowlist. */
|
|
17
|
+
export declare function getCursorAgentUrl(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Resolve the aiserver.v1 (api2) base URL. The agent endpoint chain does not
|
|
20
|
+
* apply here: AvailableModels lives on api2 regardless of where agent.v1 Run
|
|
21
|
+
* requests go. `PI_CURSOR_API_URL` exists for fixture servers that host both
|
|
22
|
+
* RPC families on one origin; production leaves it unset.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getCursorApiUrl(): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context-window and output-token ceilings for Cursor models.
|
|
3
|
+
*
|
|
4
|
+
* GetUsableModels `ModelDetails` carries neither number, so both are inferred
|
|
5
|
+
* from the model id and display name. AvailableModels parameterized metadata
|
|
6
|
+
* *does* send `contextTokenLimit`; prefer that at catalog-merge time and treat
|
|
7
|
+
* this helper as the GetUsableModels-only fallback. Kept in a dependency-free
|
|
8
|
+
* module because the model catalog needs it at startup and must not drag the
|
|
9
|
+
* transport stack in with it.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEFAULT_CONTEXT_WINDOW = 200000;
|
|
12
|
+
export declare const DEFAULT_MAX_OUTPUT_TOKENS = 64000;
|
|
13
|
+
/** GPT-5.6 default (272k short-context tier). */
|
|
14
|
+
export declare const GPT56_DEFAULT_CONTEXT_WINDOW = 272000;
|
|
15
|
+
/**
|
|
16
|
+
* OpenAI-via-Cursor GPT-5.6 (Luna / Sol / Terra) rejects prompts above this,
|
|
17
|
+
* even when Cursor labels the row "1M" or advertises `context=1m`.
|
|
18
|
+
* Observed: `maximum prompt length is 500000 but the request contains 503167`.
|
|
19
|
+
*/
|
|
20
|
+
export declare const GPT56_MAX_PROMPT_TOKENS = 500000;
|
|
21
|
+
export declare function isGpt56Model(id: string, name?: string): boolean;
|
|
22
|
+
/** Cap GPT-5.6 windows at the real OpenAI prompt limit; leave other families alone. */
|
|
23
|
+
export declare function clampCursorContextWindow(id: string, name: string, window: number): number;
|
|
24
|
+
export declare function inferCursorContextWindow(id: string, name: string): number;
|
|
25
|
+
/**
|
|
26
|
+
* Pi-side budgeting metadata only: the Cursor run request has no max-output
|
|
27
|
+
* field, so a wrong value here cannot fail a request upstream — it only
|
|
28
|
+
* mis-sizes Pi's output allowance.
|
|
29
|
+
*
|
|
30
|
+
* Conservative by design. Only families whose provider documents a ceiling above
|
|
31
|
+
* 64K are raised; everything else keeps the 64K floor Cursor's older models use.
|
|
32
|
+
*/
|
|
33
|
+
export declare function inferCursorMaxOutputTokens(id: string, name: string): number;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parameterized Cursor models metadata conversion and catalog augmentation.
|
|
3
|
+
*/
|
|
4
|
+
import type { CursorModelParameter, CursorParameterizedModel, CursorParameterizedVariant } from "../client/cursor-wire.js";
|
|
5
|
+
import type { CursorModel } from "../stream/model-discovery.js";
|
|
6
|
+
export declare const GPT55_VARIANTS: readonly [{
|
|
7
|
+
readonly idPart: "";
|
|
8
|
+
readonly label: "272K";
|
|
9
|
+
readonly context: "272k";
|
|
10
|
+
readonly contextWindow: 272000;
|
|
11
|
+
readonly requestedMaxMode: false;
|
|
12
|
+
readonly fastOptions: readonly [false, true];
|
|
13
|
+
}, {
|
|
14
|
+
readonly idPart: "-max";
|
|
15
|
+
readonly label: "272K Max";
|
|
16
|
+
readonly context: "272k";
|
|
17
|
+
readonly contextWindow: 272000;
|
|
18
|
+
readonly requestedMaxMode: true;
|
|
19
|
+
readonly fastOptions: readonly [false, true];
|
|
20
|
+
}, {
|
|
21
|
+
readonly idPart: "-1m";
|
|
22
|
+
readonly label: "1M";
|
|
23
|
+
readonly context: "1m";
|
|
24
|
+
readonly contextWindow: 1000000;
|
|
25
|
+
readonly requestedMaxMode: true;
|
|
26
|
+
readonly fastOptions: readonly [false];
|
|
27
|
+
}];
|
|
28
|
+
export declare const GPT55_REASONING_LEVELS: readonly [{
|
|
29
|
+
readonly suffix: "none";
|
|
30
|
+
readonly label: "None";
|
|
31
|
+
readonly value: "none";
|
|
32
|
+
}, {
|
|
33
|
+
readonly suffix: "low";
|
|
34
|
+
readonly label: "Low";
|
|
35
|
+
readonly value: "low";
|
|
36
|
+
}, {
|
|
37
|
+
readonly suffix: "medium";
|
|
38
|
+
readonly label: "";
|
|
39
|
+
readonly value: "medium";
|
|
40
|
+
}, {
|
|
41
|
+
readonly suffix: "high";
|
|
42
|
+
readonly label: "High";
|
|
43
|
+
readonly value: "high";
|
|
44
|
+
}, {
|
|
45
|
+
readonly suffix: "extra-high";
|
|
46
|
+
readonly label: "Extra High";
|
|
47
|
+
readonly value: "extra-high";
|
|
48
|
+
}];
|
|
49
|
+
export declare function gpt55ParameterizedModels(): CursorModel[];
|
|
50
|
+
export declare function parameterValue(parameters: CursorModelParameter[], id: string): string | undefined;
|
|
51
|
+
export declare function contextWindowFromParameter(context: string | undefined, fallback?: number): number;
|
|
52
|
+
export declare function cursorEffortSuffix(value: string): string;
|
|
53
|
+
export declare function cursorEffortLabel(value: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* The parameter ids Cursor uses for a model's selectable effort. `reasoning_effort` is the one
|
|
56
|
+
* on DeepSeek V4.1 Flash and on Grok 4.7 since it gained a `context` parameter. While it went
|
|
57
|
+
* unrecognized, each effort became its own group under one shared row id, so the last variant
|
|
58
|
+
* listed won: those rows had no thinking control and always asked for `max` / `xhigh`.
|
|
59
|
+
*/
|
|
60
|
+
export type EffortParameterId = "reasoning" | "effort" | "reasoning_effort";
|
|
61
|
+
export declare function metadataEffortParameterId(variant: CursorParameterizedVariant): EffortParameterId | undefined;
|
|
62
|
+
export declare function isDefaultContext(context: string | undefined): boolean;
|
|
63
|
+
export declare function contextIdPart(context: string | undefined): string;
|
|
64
|
+
export declare function contextLabel(context: string | undefined): string | undefined;
|
|
65
|
+
export declare function maxModeIdPart(modelName: string, context: string | undefined, requestedMaxMode: boolean, hasEffortParameter: boolean): string;
|
|
66
|
+
export declare function maxModeLabel(modelName: string, context: string | undefined, requestedMaxMode: boolean, hasEffortParameter: boolean): string | undefined;
|
|
67
|
+
export declare function parameterizedBaseId(modelName: string, variant: CursorParameterizedVariant, requestedMaxMode: boolean, hasEffortParameter: boolean): string;
|
|
68
|
+
export declare function parameterizedBaseLabel(model: CursorParameterizedModel, variant: CursorParameterizedVariant, requestedMaxMode: boolean, hasEffortParameter: boolean): string[];
|
|
69
|
+
export declare function hasVariantParameterSet(model: CursorParameterizedModel, parameters: CursorModelParameter[]): boolean;
|
|
70
|
+
export declare function normalizeParameterValues(parameters: CursorModelParameter[]): string;
|
|
71
|
+
export declare function buildParameterizedRowsFromGroup(options: {
|
|
72
|
+
model: CursorParameterizedModel;
|
|
73
|
+
variants: CursorParameterizedVariant[];
|
|
74
|
+
requestedMaxMode: boolean;
|
|
75
|
+
effortParameterId?: EffortParameterId;
|
|
76
|
+
}): CursorModel[];
|
|
77
|
+
export declare function parameterGroupKey(variant: CursorParameterizedVariant, effortParameterId?: string): string;
|
|
78
|
+
export declare function shouldGenerateSyntheticMaxRows(model: CursorParameterizedModel, variant: CursorParameterizedVariant): boolean;
|
|
79
|
+
export declare function modelsFromParameterizedMetadata(parameterizedModels: CursorParameterizedModel[]): CursorModel[];
|
|
80
|
+
export declare function normalizeDisplayModel(model: CursorModel): CursorModel;
|
|
81
|
+
export declare function augmentCursorModels(raw: CursorModel[], parameterizedModels?: CursorParameterizedModel[]): CursorModel[];
|
|
82
|
+
export declare const FALLBACK_MODELS: CursorModel[];
|
|
83
|
+
/**
|
|
84
|
+
* The "auto" (Cursor default) placeholder row both hosts register before the
|
|
85
|
+
* first successful discovery, offline, or after a discovery failure. Hand-written
|
|
86
|
+
* per-adapter copies had drifted (8192 vs 64000 maxTokens, image-capable vs
|
|
87
|
+
* text-only), so the unverified row is defined once here and both adapters map
|
|
88
|
+
* from it. Fail-closed while unverified: no image input and no reasoning until
|
|
89
|
+
* the live catalog replaces it.
|
|
90
|
+
*/
|
|
91
|
+
export declare const FALLBACK_AUTO_MODEL: {
|
|
92
|
+
readonly id: "auto";
|
|
93
|
+
readonly name: "Cursor Auto (unverified catalog)";
|
|
94
|
+
readonly reasoning: false;
|
|
95
|
+
readonly contextWindow: 200000;
|
|
96
|
+
readonly maxTokens: 64000;
|
|
97
|
+
readonly supportsImages: false;
|
|
98
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model parsing, effort mapping, and routing lookups.
|
|
3
|
+
*/
|
|
4
|
+
import type { CursorModel } from "../stream/model-discovery.js";
|
|
5
|
+
import type { CursorNativeModelRouting } from "../stream/model-routing.js";
|
|
6
|
+
import type { PiThinkingLevel } from "../types/enums.js";
|
|
7
|
+
export type CursorModelRouting = CursorNativeModelRouting;
|
|
8
|
+
export declare const CURSOR_EFFORT_SUFFIXES: Array<{
|
|
9
|
+
suffix: string;
|
|
10
|
+
effort: string;
|
|
11
|
+
}>;
|
|
12
|
+
export type CursorEffortMap = Record<PiThinkingLevel, string | null>;
|
|
13
|
+
export interface ParsedModelId {
|
|
14
|
+
base: string;
|
|
15
|
+
effort: string;
|
|
16
|
+
fast: boolean;
|
|
17
|
+
thinking: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function stripEffortSuffix(id: string): {
|
|
20
|
+
remaining: string;
|
|
21
|
+
effort: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function parseModelId(id: string): ParsedModelId;
|
|
24
|
+
export interface ProcessedModel extends CursorModel {
|
|
25
|
+
supportsEffort: boolean;
|
|
26
|
+
effortMap?: CursorEffortMap;
|
|
27
|
+
rawModelByEffort?: Record<string, string>;
|
|
28
|
+
rawRoutingByEffort?: Record<string, CursorModelRouting>;
|
|
29
|
+
}
|
|
30
|
+
export declare function grok47SiblingRouting(base: string, fast: boolean, effort: string, model: CursorModel): CursorModelRouting | undefined;
|
|
31
|
+
export declare function buildRawModelLookup(models: ProcessedModel[]): Map<string, Record<string, CursorModelRouting>>;
|
|
32
|
+
export declare function supportsReasoningModelId(id: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Map only controls Cursor explicitly advertised. Null hides unsupported Pi
|
|
35
|
+
* levels instead of silently routing them to a different Cursor effort.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildEffortMap(efforts: Set<string>): CursorEffortMap;
|
|
38
|
+
/** Dedup raw models: collapse effort variants into one entry with supportsReasoningEffort. */
|
|
39
|
+
export declare function processModels(raw: CursorModel[]): ProcessedModel[];
|