@caeliq/llms 1.0.66 → 1.0.67
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/README.md +2 -1
- package/dist/cjs/server.cjs +231 -221
- package/dist/cjs/server.cjs.map +4 -4
- package/dist/cursor-sdk/auth-exchange-cache.d.ts +23 -0
- package/dist/cursor-sdk/lifecycle-planner.d.ts +16 -4
- package/dist/cursor-sdk/prompt.d.ts +10 -0
- package/dist/cursor-sdk/session.d.ts +23 -0
- package/dist/cursor-sdk/turn-output.d.ts +3 -0
- package/dist/cursor-sdk/usage.d.ts +17 -0
- package/dist/esm/server.mjs +235 -225
- package/dist/esm/server.mjs.map +4 -4
- package/dist/routing/protocol-endpoints.d.ts +14 -0
- package/dist/tests/anthropic.message-start-usage.test.d.ts +1 -0
- package/dist/tests/cache-outcome.d.ts +1 -0
- package/dist/tests/cross-protocol.matrix.d.ts +1 -0
- package/dist/tests/cursor-sdk.auth-exchange-cache.d.ts +1 -0
- package/dist/tests/responses.encrypted-content-cache.d.ts +1 -0
- package/dist/tests/tool-content.multimodal.d.ts +1 -0
- package/dist/tests/wire-keep.d.ts +1 -0
- package/dist/transformer/codex.transformer.d.ts +20 -34
- package/dist/transformer/openai.responses.transformer.d.ts +1 -1
- package/dist/utils/cache-outcome.d.ts +79 -0
- package/dist/utils/cache-prefix-debug.d.ts +21 -1
- package/dist/utils/cacheControl.d.ts +8 -0
- package/dist/utils/deepseek.util.d.ts +1 -1
- package/dist/utils/message-debug.d.ts +12 -2
- package/dist/utils/nested-agent.d.ts +26 -0
- package/dist/utils/openai.responses.util.d.ts +11 -0
- package/dist/utils/request-latency.d.ts +4 -0
- package/dist/utils/responses.encrypted-content-cache.d.ts +42 -0
- package/dist/utils/sse-debug-tap.d.ts +12 -2
- package/dist/utils/stream-peek.d.ts +20 -0
- package/dist/utils/tool-content.d.ts +54 -0
- package/dist/utils/transformer-plan.d.ts +9 -0
- package/dist/utils/vertex-claude.util.d.ts +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @cursor/sdk POSTs /auth/exchange_user_api_key on every Agent.create and
|
|
3
|
+
* models.list. Subagent turns mint new session keys, so Agent.create runs
|
|
4
|
+
* again and the SDK does not cache the access token across those calls.
|
|
5
|
+
*
|
|
6
|
+
* Wrap global fetch: coalesce in-flight exchanges per crsr_ key, reuse the
|
|
7
|
+
* access token until a Cursor request with that token returns 401.
|
|
8
|
+
*
|
|
9
|
+
* Critical: never forward a caller's AbortSignal onto the shared exchange.
|
|
10
|
+
* Agent.create often cancels while another waiter still needs the token; if
|
|
11
|
+
* the first caller's signal aborts the shared fetch, every waiter rejects
|
|
12
|
+
* with AbortError and Node surfaces unhandledRejection / late-handled
|
|
13
|
+
* PromiseRejectionHandledWarning.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Drop a cached exchanged token for a dashboard API key (crsr_... or Bearer).
|
|
17
|
+
* Call when Cursor reports auth failure via run status / AuthenticationError —
|
|
18
|
+
* those paths often never surface as an HTTP 401 on the wrapped fetch.
|
|
19
|
+
*/
|
|
20
|
+
export declare function invalidateCursorAuthExchange(crsrApiKey: string): void;
|
|
21
|
+
/** Re-wrap if tests or other code replaced globalThis.fetch. */
|
|
22
|
+
export declare function installCursorAuthExchangeCache(): void;
|
|
23
|
+
export declare function __resetCursorAuthExchangeCacheForTests(): void;
|
|
@@ -43,7 +43,9 @@ export type CursorLifecycleInput<TParked extends CursorParkedToolRef = CursorPar
|
|
|
43
43
|
toolResults: readonly TResult[];
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
|
-
|
|
46
|
+
/** Hard remint only — soft alignment cases stay on the same agent. */
|
|
47
|
+
export type CursorLifecycleRetirementReason = "poisoned-session";
|
|
48
|
+
export type CursorLifecycleIncrementalReason = "strictly-aligned-idle-session" | "unknown-context-alignment" | "divergent-context-alignment" | "active-different-turn" | "dead-parked-run" | "parked-turn-has-steering" | "parked-tool-results-mismatch" | "orphaned-tool-results";
|
|
47
49
|
export type CursorLifecycleRetirementPlan = {
|
|
48
50
|
action: "retire-and-replay-full";
|
|
49
51
|
reason: CursorLifecycleRetirementReason;
|
|
@@ -54,13 +56,23 @@ export type CursorLifecyclePlan<TParked extends CursorParkedToolRef = CursorPark
|
|
|
54
56
|
matches: ExactParkedResultMatch<TParked, TResult>;
|
|
55
57
|
} | {
|
|
56
58
|
action: "send-full";
|
|
57
|
-
reason: "unused-session";
|
|
59
|
+
reason: "unused-session" | "inconsistent-unused-session";
|
|
58
60
|
} | {
|
|
59
61
|
action: "send-incremental";
|
|
60
|
-
reason:
|
|
62
|
+
reason: CursorLifecycleIncrementalReason;
|
|
61
63
|
} | CursorLifecycleRetirementPlan;
|
|
62
64
|
/**
|
|
63
|
-
*
|
|
65
|
+
* Soft incremental reasons where the runner must cancel/abandon any prior
|
|
66
|
+
* active or parked run before `agent.send` — without reminting the agent.
|
|
67
|
+
*/
|
|
68
|
+
export declare const CURSOR_SOFT_CANCEL_THEN_INCREMENTAL: Set<CursorLifecycleIncrementalReason>;
|
|
69
|
+
/**
|
|
70
|
+
* Choose the lifecycle action for a new, non-coalesced host turn.
|
|
71
|
+
*
|
|
72
|
+
* Soft transcript-alignment mismatches stay on the same Cursor agent via
|
|
73
|
+
* `send-incremental` (caller cancels parked/active runs when needed). Hard
|
|
74
|
+
* remint (`retire-and-replay-full`) is reserved for poisoned sessions; send/
|
|
75
|
+
* stream failure recovery remints in the runner, not here.
|
|
64
76
|
*
|
|
65
77
|
* This function is intentionally pure. It neither resolves parked tools nor
|
|
66
78
|
* changes session state; the caller executes the returned plan under its
|
|
@@ -3,6 +3,11 @@ import { type UnifiedTurnIntent } from "../types/turn-intent";
|
|
|
3
3
|
import type { SDKUserMessage } from "@cursor/sdk";
|
|
4
4
|
import { type HostEnvironment } from "./host-env";
|
|
5
5
|
export declare function buildBridgeSystemGuidance(request: UnifiedChatRequest, workspaceDir: string, hostEnv?: HostEnvironment): string;
|
|
6
|
+
/**
|
|
7
|
+
* Identity of the bridge preamble actually sent on an agent. Unchanged
|
|
8
|
+
* follow-ups skip re-sending it so Cursor history does not stack copies.
|
|
9
|
+
*/
|
|
10
|
+
export declare function bridgePromptGuidanceFingerprint(request: UnifiedChatRequest, workspaceDir: string, hostEnv: HostEnvironment): string;
|
|
6
11
|
/**
|
|
7
12
|
* Short restatement appended after the transcript. The guidance above is far
|
|
8
13
|
* from the generation point once history is flattened in; this is the last
|
|
@@ -37,6 +42,11 @@ export declare function toSdkPrompt(request: UnifiedChatRequest, options: {
|
|
|
37
42
|
hostEnv?: HostEnvironment;
|
|
38
43
|
/** Protocol semantics recovered before Anthropic content was flattened. */
|
|
39
44
|
turnIntent?: UnifiedTurnIntent;
|
|
45
|
+
/**
|
|
46
|
+
* Bridge preamble + tail reminder. Default true. Set false on follow-ups
|
|
47
|
+
* whose tool catalog and host env already went out on this agent.
|
|
48
|
+
*/
|
|
49
|
+
includeBridgeGuidance?: boolean;
|
|
40
50
|
}): SDKUserMessage;
|
|
41
51
|
export type TrailingCursorToolTurn = {
|
|
42
52
|
toolResults: Array<{
|
|
@@ -63,6 +63,11 @@ export type CursorSdkSession = {
|
|
|
63
63
|
compatibilityStamp?: string;
|
|
64
64
|
/** Fingerprint of the host env baked into the workspace rules/deny hooks. */
|
|
65
65
|
guidanceFingerprint?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Bridge preamble last actually sent on this agent (host env + tool catalog).
|
|
68
|
+
* Unchanged follow-ups omit the preamble so history does not stack copies.
|
|
69
|
+
*/
|
|
70
|
+
lastBridgePromptGuidanceFingerprint?: string;
|
|
66
71
|
/**
|
|
67
72
|
* Set when the local SDK handles are no longer trustworthy. The manager must
|
|
68
73
|
* not hand this agent out for a future request.
|
|
@@ -138,11 +143,29 @@ export declare function shouldEnableCursorSandbox(requested?: boolean): boolean;
|
|
|
138
143
|
* path correction) is updated here regardless.
|
|
139
144
|
*/
|
|
140
145
|
export declare function refreshWorkspaceGuidance(session: CursorSdkSession, hostEnv: HostEnvironment): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Cursor SDK session directory key. Prefer explicit client conversation ids
|
|
148
|
+
* over hashing prompt text — never include system / harness version.
|
|
149
|
+
*
|
|
150
|
+
* Claude Code subagents share the parent session id. Mix first-user text so
|
|
151
|
+
* parallel Task agents each get their own Cursor Agent instead of collapsing
|
|
152
|
+
* onto one turn registry slot.
|
|
153
|
+
*/
|
|
141
154
|
export declare function buildSessionKey(input: {
|
|
142
155
|
headerSession?: string;
|
|
156
|
+
/** Inbound-captured Claude/OpenCode session id (protocolContext / req). */
|
|
157
|
+
clientSessionId?: string;
|
|
143
158
|
metadataUserId?: string;
|
|
144
159
|
model?: string;
|
|
160
|
+
/** Anonymous clients only: first user text (not system). */
|
|
161
|
+
firstUserText?: string;
|
|
162
|
+
/** @deprecated Use firstUserText. Kept for call-site compatibility. */
|
|
145
163
|
systemAndFirstUser?: string;
|
|
164
|
+
/**
|
|
165
|
+
* Claude Code Task / subagent turn. Parent session id alone is not unique
|
|
166
|
+
* across parallel subagents.
|
|
167
|
+
*/
|
|
168
|
+
isSubagent?: boolean;
|
|
146
169
|
}): string;
|
|
147
170
|
/** True while a session has a live run, open stream, or unresolved host tools. */
|
|
148
171
|
export declare function isSessionInFlight(session: CursorSdkSession): boolean;
|
|
@@ -71,6 +71,9 @@ export declare class CursorTurnRegistry {
|
|
|
71
71
|
responseKind: "stream" | "json";
|
|
72
72
|
signal?: AbortSignal;
|
|
73
73
|
}): Promise<CursorTurnLease>;
|
|
74
|
+
peekActive(sessionKey: string): {
|
|
75
|
+
fingerprint: string;
|
|
76
|
+
} | undefined;
|
|
74
77
|
clear(): void;
|
|
75
78
|
}
|
|
76
79
|
export declare const globalCursorTurnRegistry: CursorTurnRegistry;
|
|
@@ -7,6 +7,13 @@ export type OpenAiUsage = {
|
|
|
7
7
|
cached_tokens?: number;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
|
+
export type CursorUsageCounters = {
|
|
11
|
+
inputTokens: number;
|
|
12
|
+
outputTokens: number;
|
|
13
|
+
cacheRead: number;
|
|
14
|
+
cacheWrite: number;
|
|
15
|
+
reasoningTokens: number;
|
|
16
|
+
};
|
|
10
17
|
/**
|
|
11
18
|
* Rough char→token estimate for mid-turn usage before Cursor emits a usage
|
|
12
19
|
* event (and as the host-facing request usage even when it does).
|
|
@@ -18,11 +25,21 @@ export declare function estimateTokens(chars: number): number;
|
|
|
18
25
|
export declare function estimateRequestPromptTokens(request: UnifiedChatRequest): number;
|
|
19
26
|
/** Build OpenAI-style usage for a single CCR request (not Cursor session totals). */
|
|
20
27
|
export declare function requestUsageFromEstimate(promptTokens: number, outputChars: number, cacheReadTokens?: number): OpenAiUsage;
|
|
28
|
+
export declare function cursorUsageCountersFromSdk(raw: OpenAiUsage | undefined): CursorUsageCounters | undefined;
|
|
21
29
|
/**
|
|
22
30
|
* Cursor SDK usage is session-cumulative, while Claude Code needs per-request
|
|
23
31
|
* usage. Use SDK usage only as a cache-read ratio and apply it to CCR's
|
|
24
32
|
* current-request prompt estimate.
|
|
33
|
+
*
|
|
34
|
+
* Kept for tests; prefer buildAccurateUsageFromSdk for turn-end reporting.
|
|
25
35
|
*/
|
|
26
36
|
export declare function cacheReadFromSdkDelta(current: OpenAiUsage | undefined, previous: OpenAiUsage | undefined, promptTokens: number): number;
|
|
37
|
+
/**
|
|
38
|
+
* Build per-request OpenAI usage from SDK TurnEnded counters, normalized to
|
|
39
|
+
* the per-request prompt estimate but preserving Cursor's cache proportions
|
|
40
|
+
* (same math as cursor-opencode-provider buildLanguageModelV3UsageFromCounters).
|
|
41
|
+
* Falls back to chars/4-based completion tokens when SDK output is absent.
|
|
42
|
+
*/
|
|
43
|
+
export declare function buildAccurateUsageFromSdk(sdkRaw: OpenAiUsage | undefined, promptTokens: number, outputChars: number, priorRaw?: OpenAiUsage | undefined): OpenAiUsage;
|
|
27
44
|
/** Map SDK TokenUsage / usage message into OpenAI shape (diagnostics only). */
|
|
28
45
|
export declare function usageFromSdk(message: any): OpenAiUsage | undefined;
|