@velum-labs/cursorkit 0.1.3 → 0.2.0
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/DISCLAIMER.md +10 -8
- package/LICENSE +201 -0
- package/README.md +4 -2
- package/dist/src/ckLauncher.d.ts +7 -0
- package/dist/src/ckLauncher.js +11 -2
- package/dist/src/fixtures/modelFusion.d.ts +1 -1
- package/dist/src/fixtures/modelFusion.js +1 -1
- package/dist/src/providers/openai.d.ts +46 -1
- package/dist/src/providers/openai.js +139 -1
- package/dist/src/services/chat.js +63 -3
- package/dist/src/tools/releaseCheck.d.ts +1 -1
- package/dist/src/tools/releaseCheck.js +1 -0
- package/docs/cursor-app.md +5 -0
- package/docs/model-fusion-protocol-origin.json +1 -1
- package/docs/release-gates.md +1 -1
- package/package.json +7 -6
package/DISCLAIMER.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# Disclaimer
|
|
2
2
|
|
|
3
|
-
This is an unofficial and unsupported interoperability research project.
|
|
3
|
+
This is an unofficial and unsupported interoperability research project. It is
|
|
4
|
+
not affiliated with, endorsed by, or supported by Cursor.
|
|
4
5
|
|
|
5
|
-
It
|
|
6
|
-
experimental use with a self-hosted
|
|
7
|
-
to run your own models may conflict
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
It exists for personal interoperability research: emulating enough of Cursor's
|
|
7
|
+
backend protocol for experimental use with a self-hosted, OpenAI-compatible
|
|
8
|
+
model. Reverse-engineering a client protocol to run your own models may conflict
|
|
9
|
+
with Cursor's Terms of Service, so you are responsible for ensuring your own use
|
|
10
|
+
complies with any agreements you have with Cursor.
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
The software is provided under the Apache License 2.0 on an "AS IS" basis,
|
|
13
|
+
without warranties or conditions of any kind. Use it at your own risk, and make
|
|
14
|
+
your own assessment of the legal, security, and compatibility implications.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Velum Labs
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -151,8 +151,10 @@ the experimental local plugin shape. Examples are typechecked by
|
|
|
151
151
|
|
|
152
152
|
## Release Gates
|
|
153
153
|
|
|
154
|
-
This package
|
|
155
|
-
|
|
154
|
+
This package is published to public npm as `@velum-labs/cursorkit` under the
|
|
155
|
+
Apache License 2.0; see `LICENSE` for the license terms and `DISCLAIMER.md` for
|
|
156
|
+
the unofficial-research caveats. See `docs/release-gates.md` for the checks
|
|
157
|
+
required before publishing a release or changing the API stability posture.
|
|
156
158
|
Use `pnpm baseline:check` to verify generated route/config/docs drift and
|
|
157
159
|
`pnpm release:check` for the authoritative deterministic local release gate,
|
|
158
160
|
including package artifact smoke validation.
|
package/dist/src/ckLauncher.d.ts
CHANGED
|
@@ -139,6 +139,13 @@ export declare function buildCkLaunchPlan(options: {
|
|
|
139
139
|
instanceId?: string;
|
|
140
140
|
seedAuthFromDefault?: boolean;
|
|
141
141
|
cwd?: string;
|
|
142
|
+
/**
|
|
143
|
+
* Folder Cursor opens as its workspace. Defaults to {@link cwd}; set it to
|
|
144
|
+
* decouple the opened project from the ck state directory (which stays under
|
|
145
|
+
* {@link cwd}), so an embedding launcher can keep certs/state/logs in a
|
|
146
|
+
* scratch dir while still opening the user's real repo.
|
|
147
|
+
*/
|
|
148
|
+
workspacePath?: string;
|
|
142
149
|
}): CkLaunchPlan;
|
|
143
150
|
export declare function commandForDisplay(spec: CommandSpec): string;
|
|
144
151
|
export declare function buildCkRoutePlan(options?: {
|
package/dist/src/ckLauncher.js
CHANGED
|
@@ -179,6 +179,7 @@ function compactCkArgs(args) {
|
|
|
179
179
|
}
|
|
180
180
|
export function buildCkLaunchPlan(options) {
|
|
181
181
|
const cwd = options.cwd ?? process.cwd();
|
|
182
|
+
const workspacePath = options.workspacePath ?? cwd;
|
|
182
183
|
const profileMode = options.profileMode ?? "isolated";
|
|
183
184
|
const stateDir = options.instanceId === undefined
|
|
184
185
|
? path.join(cwd, CK_STATE_DIR)
|
|
@@ -211,7 +212,7 @@ export function buildCkLaunchPlan(options) {
|
|
|
211
212
|
...bridgeCommandSpec(cwd),
|
|
212
213
|
env: stringEnv(bridgeEnv),
|
|
213
214
|
},
|
|
214
|
-
cursor: cursorCommandSpec(profileMode, userDataDir, extensionsDir, options.debugPort,
|
|
215
|
+
cursor: cursorCommandSpec(profileMode, userDataDir, extensionsDir, options.debugPort, workspacePath, options.bridgePort, profileMode === "isolated", connectProxyPort),
|
|
215
216
|
bridgePort: options.bridgePort,
|
|
216
217
|
...(connectProxyPort !== undefined ? { connectProxyPort } : {}),
|
|
217
218
|
...(agentHttpPort !== undefined ? { agentHttpPort } : {}),
|
|
@@ -221,7 +222,7 @@ export function buildCkLaunchPlan(options) {
|
|
|
221
222
|
...(connectProxyLogPath !== undefined ? { connectProxyLogPath } : {}),
|
|
222
223
|
userDataDir,
|
|
223
224
|
extensionsDir,
|
|
224
|
-
workspacePath
|
|
225
|
+
workspacePath,
|
|
225
226
|
profileMode,
|
|
226
227
|
seedAuthFromDefault: profileMode === "isolated" && options.seedAuthFromDefault !== false,
|
|
227
228
|
authSeedStatus: "not-requested",
|
|
@@ -516,6 +517,13 @@ async function runCkCommand(parsed) {
|
|
|
516
517
|
const bridgePort = await chooseBridgePort();
|
|
517
518
|
const connectProxyPort = parsed.profileMode === "isolated" ? await chooseFreePort() : undefined;
|
|
518
519
|
const agentHttpPort = parsed.profileMode === "isolated" ? await chooseFreePort() : undefined;
|
|
520
|
+
// CK_WORKSPACE_PATH lets an embedding launcher open the user's real repo while
|
|
521
|
+
// keeping ck's state/cert/log directory under cwd (a scratch dir). Unset for
|
|
522
|
+
// normal `pnpm ck`, where the workspace is the current directory.
|
|
523
|
+
const workspacePathEnv = process.env.CK_WORKSPACE_PATH;
|
|
524
|
+
const workspacePath = workspacePathEnv !== undefined && workspacePathEnv.length > 0
|
|
525
|
+
? workspacePathEnv
|
|
526
|
+
: undefined;
|
|
519
527
|
const plan = buildCkLaunchPlan({
|
|
520
528
|
env: process.env,
|
|
521
529
|
bridgePort,
|
|
@@ -525,6 +533,7 @@ async function runCkCommand(parsed) {
|
|
|
525
533
|
debugPort: parsed.debugPort,
|
|
526
534
|
instanceId: parsed.instanceId,
|
|
527
535
|
seedAuthFromDefault: parsed.seedAuthFromDefault,
|
|
536
|
+
...(workspacePath !== undefined ? { workspacePath } : {}),
|
|
528
537
|
});
|
|
529
538
|
if (parsed.dryRun) {
|
|
530
539
|
printPlan(plan);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const MODEL_FUSION_SCHEMA_BUNDLE_HASH = "sha256:
|
|
1
|
+
export declare const MODEL_FUSION_SCHEMA_BUNDLE_HASH = "sha256:3e8388595aefc8e82962d76e822c514db6552f6ee65e62d487534ef825ad87b8";
|
|
2
2
|
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
3
3
|
[key: string]: JsonValue;
|
|
4
4
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
export const MODEL_FUSION_SCHEMA_BUNDLE_HASH = "sha256:
|
|
2
|
+
export const MODEL_FUSION_SCHEMA_BUNDLE_HASH = "sha256:3e8388595aefc8e82962d76e822c514db6552f6ee65e62d487534ef825ad87b8";
|
|
3
3
|
const STATUSES = [
|
|
4
4
|
"pending",
|
|
5
5
|
"running",
|
|
@@ -31,6 +31,29 @@ export type OpenAICompletionEvent = {
|
|
|
31
31
|
toolCalls: OpenAIToolCall[];
|
|
32
32
|
};
|
|
33
33
|
export type OpenAIBackendErrorCode = "http_error" | "malformed_sse" | "request_aborted" | "request_timeout";
|
|
34
|
+
/**
|
|
35
|
+
* Canonical egress error taxonomy, mirrored from the fusionkit WS1 classifier
|
|
36
|
+
* (`fusionkit_core.clients.ProviderErrorCategory`) so the Cursor bridge and the
|
|
37
|
+
* fusion gateway agree on what an upstream failure *means*:
|
|
38
|
+
*
|
|
39
|
+
* - `transient`: retrying may succeed (HTTP 429 rate limits, 5xx, vendor
|
|
40
|
+
* `overloaded_error`, timeouts). Honors `Retry-After`.
|
|
41
|
+
* - `quota_exhausted`: the account is out of money/quota (`insufficient_quota`,
|
|
42
|
+
* billing/credit errors). Re-running the same key will not help — fail over
|
|
43
|
+
* to the fusion ensemble.
|
|
44
|
+
* - `auth_permanent`: the request can never succeed as-is (401/403, invalid
|
|
45
|
+
* key, `model_not_found`). Do not retry, do not blind-failover.
|
|
46
|
+
* - `unknown`: could not be classified; treated as non-retryable.
|
|
47
|
+
*/
|
|
48
|
+
export type OpenAIBackendErrorCategory = "transient" | "quota_exhausted" | "auth_permanent" | "unknown";
|
|
49
|
+
export interface OpenAIBackendErrorOptions extends ErrorOptions {
|
|
50
|
+
/** Egress taxonomy classification. Defaults from {@link OpenAIBackendErrorCode}. */
|
|
51
|
+
category?: OpenAIBackendErrorCategory;
|
|
52
|
+
/** Parsed `Retry-After` (seconds) when the upstream supplied one. */
|
|
53
|
+
retryAfter?: number;
|
|
54
|
+
/** Upstream HTTP status code, when the failure was an HTTP response. */
|
|
55
|
+
status?: number;
|
|
56
|
+
}
|
|
34
57
|
export interface OpenAIStreamOptions {
|
|
35
58
|
signal?: AbortSignal;
|
|
36
59
|
timeoutMs?: number;
|
|
@@ -43,7 +66,12 @@ export interface OpenAIStreamOptions {
|
|
|
43
66
|
}
|
|
44
67
|
export declare class OpenAIBackendError extends Error {
|
|
45
68
|
readonly code: OpenAIBackendErrorCode;
|
|
46
|
-
|
|
69
|
+
readonly category: OpenAIBackendErrorCategory;
|
|
70
|
+
readonly retryAfter: number | undefined;
|
|
71
|
+
readonly status: number | undefined;
|
|
72
|
+
constructor(code: OpenAIBackendErrorCode, message: string, options?: OpenAIBackendErrorOptions);
|
|
73
|
+
/** Only `transient` failures are worth retrying as-is. */
|
|
74
|
+
get retryable(): boolean;
|
|
47
75
|
}
|
|
48
76
|
export declare class OpenAIStreamParseError extends OpenAIBackendError {
|
|
49
77
|
constructor(message: string, options?: ErrorOptions);
|
|
@@ -62,3 +90,20 @@ export declare class OpenAICompatibleProvider implements ModelProvider {
|
|
|
62
90
|
export declare function parseOpenAIStream(stream: AsyncIterable<Uint8Array>): AsyncGenerator<string | Extract<OpenAICompletionEvent, {
|
|
63
91
|
type: "tool_calls";
|
|
64
92
|
}>>;
|
|
93
|
+
export interface BackendErrorClassification {
|
|
94
|
+
category: OpenAIBackendErrorCategory;
|
|
95
|
+
retryAfter: number | undefined;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Classify a non-2xx upstream (vendor/gateway) response into the egress
|
|
99
|
+
* taxonomy. Reads the status code, the `Retry-After` header, and the raw error
|
|
100
|
+
* body so a vendor 429 / `insufficient_quota` / billing signal is no longer
|
|
101
|
+
* collapsed into a generic `http_error`.
|
|
102
|
+
*/
|
|
103
|
+
export declare function classifyUpstreamHttpError(status: number, retryAfterHeader: string | null | undefined, body: string): BackendErrorClassification;
|
|
104
|
+
/**
|
|
105
|
+
* Parse an HTTP `Retry-After` header. Supports both the delta-seconds form
|
|
106
|
+
* (`"7"`) and the HTTP-date form (`"Wed, 21 Oct 2025 07:28:00 GMT"`), returning
|
|
107
|
+
* a non-negative seconds value, or `undefined` when absent/unparseable.
|
|
108
|
+
*/
|
|
109
|
+
export declare function parseRetryAfter(value: string | null | undefined): number | undefined;
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { emitTrace, newSpanId, TRACE_ID_HEADER, TRACE_SPAN_HEADER, } from "../trace.js";
|
|
2
2
|
export class OpenAIBackendError extends Error {
|
|
3
3
|
code;
|
|
4
|
+
category;
|
|
5
|
+
retryAfter;
|
|
6
|
+
status;
|
|
4
7
|
constructor(code, message, options) {
|
|
5
8
|
super(message, options);
|
|
6
9
|
this.code = code;
|
|
7
10
|
this.name = "OpenAIBackendError";
|
|
11
|
+
this.category = options?.category ?? defaultCategoryForCode(code);
|
|
12
|
+
this.retryAfter = options?.retryAfter;
|
|
13
|
+
this.status = options?.status;
|
|
14
|
+
}
|
|
15
|
+
/** Only `transient` failures are worth retrying as-is. */
|
|
16
|
+
get retryable() {
|
|
17
|
+
return this.category === "transient";
|
|
8
18
|
}
|
|
9
19
|
}
|
|
10
20
|
export class OpenAIStreamParseError extends OpenAIBackendError {
|
|
@@ -115,6 +125,9 @@ export class OpenAICompatibleProvider {
|
|
|
115
125
|
code: classified instanceof OpenAIBackendError
|
|
116
126
|
? classified.code
|
|
117
127
|
: undefined,
|
|
128
|
+
category: classified instanceof OpenAIBackendError
|
|
129
|
+
? classified.category
|
|
130
|
+
: undefined,
|
|
118
131
|
cause: error instanceof Error && error.cause instanceof Error
|
|
119
132
|
? error.cause.message
|
|
120
133
|
: undefined,
|
|
@@ -124,7 +137,12 @@ export class OpenAICompatibleProvider {
|
|
|
124
137
|
}
|
|
125
138
|
if (!response.ok || response.body === null) {
|
|
126
139
|
const body = await response.text().catch(() => "");
|
|
127
|
-
const
|
|
140
|
+
const classification = classifyUpstreamHttpError(response.status, response.headers.get("retry-after"), body);
|
|
141
|
+
const error = new OpenAIBackendError("http_error", `Model backend returned ${response.status}: ${body}`, {
|
|
142
|
+
category: classification.category,
|
|
143
|
+
retryAfter: classification.retryAfter,
|
|
144
|
+
status: response.status,
|
|
145
|
+
});
|
|
128
146
|
this.logger?.warn("model backend response failed", {
|
|
129
147
|
modelId: this.config.id,
|
|
130
148
|
providerModel: this.config.providerModel,
|
|
@@ -133,6 +151,8 @@ export class OpenAICompatibleProvider {
|
|
|
133
151
|
durationMs: Date.now() - started,
|
|
134
152
|
bodyPreview: body.slice(0, 500),
|
|
135
153
|
code: error.code,
|
|
154
|
+
category: error.category,
|
|
155
|
+
retryAfter: error.retryAfter,
|
|
136
156
|
});
|
|
137
157
|
abortContext.dispose();
|
|
138
158
|
throw error;
|
|
@@ -188,6 +208,9 @@ export class OpenAICompatibleProvider {
|
|
|
188
208
|
code: classified instanceof OpenAIBackendError
|
|
189
209
|
? classified.code
|
|
190
210
|
: undefined,
|
|
211
|
+
category: classified instanceof OpenAIBackendError
|
|
212
|
+
? classified.category
|
|
213
|
+
: undefined,
|
|
191
214
|
});
|
|
192
215
|
throw classified;
|
|
193
216
|
}
|
|
@@ -339,6 +362,121 @@ function createRequestAbortContext(timeoutMs, upstreamSignal) {
|
|
|
339
362
|
},
|
|
340
363
|
};
|
|
341
364
|
}
|
|
365
|
+
// Lower-cased substrings matched against the upstream error body. Mirrors the
|
|
366
|
+
// fusionkit WS1 marker sets so both egress points classify identically.
|
|
367
|
+
const QUOTA_MARKERS = [
|
|
368
|
+
"insufficient_quota",
|
|
369
|
+
"insufficient quota",
|
|
370
|
+
"exceeded your current quota",
|
|
371
|
+
"billing_hard_limit_reached",
|
|
372
|
+
"billing",
|
|
373
|
+
"credit balance",
|
|
374
|
+
"out of credits",
|
|
375
|
+
"payment required",
|
|
376
|
+
"quota exceeded",
|
|
377
|
+
];
|
|
378
|
+
const AUTH_MARKERS = [
|
|
379
|
+
"invalid api key",
|
|
380
|
+
"invalid_api_key",
|
|
381
|
+
"invalid x-api-key",
|
|
382
|
+
"authentication_error",
|
|
383
|
+
"permission_error",
|
|
384
|
+
"permission denied",
|
|
385
|
+
"permission_denied",
|
|
386
|
+
"model_not_found",
|
|
387
|
+
"model not found",
|
|
388
|
+
"does not exist",
|
|
389
|
+
"no such model",
|
|
390
|
+
"unauthorized",
|
|
391
|
+
];
|
|
392
|
+
const TRANSIENT_MARKERS = [
|
|
393
|
+
"overloaded",
|
|
394
|
+
"rate_limit",
|
|
395
|
+
"rate limit",
|
|
396
|
+
"ratelimit",
|
|
397
|
+
"try again",
|
|
398
|
+
"timeout",
|
|
399
|
+
"timed out",
|
|
400
|
+
"temporarily unavailable",
|
|
401
|
+
"service unavailable",
|
|
402
|
+
"service_unavailable",
|
|
403
|
+
];
|
|
404
|
+
/**
|
|
405
|
+
* Classify a non-2xx upstream (vendor/gateway) response into the egress
|
|
406
|
+
* taxonomy. Reads the status code, the `Retry-After` header, and the raw error
|
|
407
|
+
* body so a vendor 429 / `insufficient_quota` / billing signal is no longer
|
|
408
|
+
* collapsed into a generic `http_error`.
|
|
409
|
+
*/
|
|
410
|
+
export function classifyUpstreamHttpError(status, retryAfterHeader, body) {
|
|
411
|
+
return {
|
|
412
|
+
category: categoryForUpstream(status, body.toLowerCase()),
|
|
413
|
+
retryAfter: parseRetryAfter(retryAfterHeader),
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
function categoryForUpstream(status, blob) {
|
|
417
|
+
// Quota first: an OpenAI `insufficient_quota` is delivered as HTTP 429, so it
|
|
418
|
+
// must win over the generic "429 is transient" rule below.
|
|
419
|
+
if (QUOTA_MARKERS.some((marker) => blob.includes(marker))) {
|
|
420
|
+
return "quota_exhausted";
|
|
421
|
+
}
|
|
422
|
+
if (status === 401 || status === 403) {
|
|
423
|
+
return "auth_permanent";
|
|
424
|
+
}
|
|
425
|
+
if (status === 404 && blob.includes("model")) {
|
|
426
|
+
return "auth_permanent";
|
|
427
|
+
}
|
|
428
|
+
if (AUTH_MARKERS.some((marker) => blob.includes(marker))) {
|
|
429
|
+
return "auth_permanent";
|
|
430
|
+
}
|
|
431
|
+
if (status === 429) {
|
|
432
|
+
return "transient";
|
|
433
|
+
}
|
|
434
|
+
if (status >= 500) {
|
|
435
|
+
return "transient";
|
|
436
|
+
}
|
|
437
|
+
if (TRANSIENT_MARKERS.some((marker) => blob.includes(marker))) {
|
|
438
|
+
return "transient";
|
|
439
|
+
}
|
|
440
|
+
return "unknown";
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Parse an HTTP `Retry-After` header. Supports both the delta-seconds form
|
|
444
|
+
* (`"7"`) and the HTTP-date form (`"Wed, 21 Oct 2025 07:28:00 GMT"`), returning
|
|
445
|
+
* a non-negative seconds value, or `undefined` when absent/unparseable.
|
|
446
|
+
*/
|
|
447
|
+
export function parseRetryAfter(value) {
|
|
448
|
+
if (value === null || value === undefined) {
|
|
449
|
+
return undefined;
|
|
450
|
+
}
|
|
451
|
+
const trimmed = value.trim();
|
|
452
|
+
if (trimmed.length === 0) {
|
|
453
|
+
return undefined;
|
|
454
|
+
}
|
|
455
|
+
const seconds = Number(trimmed);
|
|
456
|
+
if (Number.isFinite(seconds)) {
|
|
457
|
+
return seconds >= 0 ? seconds : undefined;
|
|
458
|
+
}
|
|
459
|
+
const dateMs = Date.parse(trimmed);
|
|
460
|
+
if (!Number.isNaN(dateMs)) {
|
|
461
|
+
const deltaSeconds = (dateMs - Date.now()) / 1000;
|
|
462
|
+
return deltaSeconds > 0 ? deltaSeconds : 0;
|
|
463
|
+
}
|
|
464
|
+
return undefined;
|
|
465
|
+
}
|
|
466
|
+
function defaultCategoryForCode(code) {
|
|
467
|
+
switch (code) {
|
|
468
|
+
case "request_timeout":
|
|
469
|
+
return "transient";
|
|
470
|
+
case "http_error":
|
|
471
|
+
case "malformed_sse":
|
|
472
|
+
case "request_aborted":
|
|
473
|
+
return "unknown";
|
|
474
|
+
default: {
|
|
475
|
+
const exhaustive = code;
|
|
476
|
+
return exhaustive;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
342
480
|
function classifyBackendError(error, abortContext) {
|
|
343
481
|
if (error instanceof OpenAIBackendError) {
|
|
344
482
|
return error;
|
|
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { create, fromBinary, toBinary } from "@bufbuild/protobuf";
|
|
3
3
|
import { encodeEndStream, encodeEnvelope } from "../connectEnvelope.js";
|
|
4
4
|
import { StreamUnifiedChatRequestWithToolsSchema, StreamUnifiedChatResponseSchema, StreamUnifiedChatResponseWithToolsSchema, } from "../gen/aiserver/v1/aiserver_pb.js";
|
|
5
|
+
import { OpenAIBackendError } from "../providers/openai.js";
|
|
5
6
|
import { cursorRequestToOpenAI } from "../translation.js";
|
|
6
7
|
export function getLocalChatDecision(payload, models) {
|
|
7
8
|
const request = fromBinary(StreamUnifiedChatRequestWithToolsSchema, payload);
|
|
@@ -31,17 +32,76 @@ export async function writeLocalChatResponse(response, decision, logger, options
|
|
|
31
32
|
logger.info("served local chat", { model: decision.model.id });
|
|
32
33
|
}
|
|
33
34
|
catch (error) {
|
|
35
|
+
const failure = classifyLocalChatFailure(error);
|
|
34
36
|
logger.error("local chat failed", {
|
|
35
37
|
model: decision.model.id,
|
|
36
38
|
error: error instanceof Error ? error.message : String(error),
|
|
39
|
+
category: failure.category,
|
|
40
|
+
retryAfter: failure.retryAfter,
|
|
37
41
|
});
|
|
38
|
-
endLocalChatFailure(response);
|
|
42
|
+
endLocalChatFailure(response, serverBubbleId, failure);
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
|
-
function
|
|
45
|
+
function classifyLocalChatFailure(error) {
|
|
46
|
+
if (error instanceof OpenAIBackendError) {
|
|
47
|
+
return { category: error.category, retryAfter: error.retryAfter };
|
|
48
|
+
}
|
|
49
|
+
return { category: "unknown", retryAfter: undefined };
|
|
50
|
+
}
|
|
51
|
+
function endLocalChatFailure(response, serverBubbleId, failure) {
|
|
42
52
|
if (!response.headersSent) {
|
|
43
53
|
response.statusCode = 200;
|
|
44
54
|
response.setHeader("content-type", "application/connect+proto");
|
|
45
55
|
}
|
|
46
|
-
|
|
56
|
+
// Surface a clear, user-facing terminal notice (named cause) for rate-limit /
|
|
57
|
+
// credit failures. The product decision is pre-stream failover + one-tap
|
|
58
|
+
// resume on the ensemble, so we do NOT attempt a transparent mid-stream
|
|
59
|
+
// cut-over here — we just tell the user what happened and keep the Connect
|
|
60
|
+
// stream protocol valid for Cursor.
|
|
61
|
+
const notice = failureNotice(failure);
|
|
62
|
+
if (notice !== undefined) {
|
|
63
|
+
response.write(encodeEnvelope(toBinary(StreamUnifiedChatResponseWithToolsSchema, create(StreamUnifiedChatResponseWithToolsSchema, {
|
|
64
|
+
streamUnifiedChatResponse: create(StreamUnifiedChatResponseSchema, {
|
|
65
|
+
text: notice,
|
|
66
|
+
serverBubbleId,
|
|
67
|
+
}),
|
|
68
|
+
eventId: randomUUID(),
|
|
69
|
+
}))));
|
|
70
|
+
}
|
|
71
|
+
response.end(encodeEndStream({ error: failureMetadata(failure.category) }));
|
|
72
|
+
}
|
|
73
|
+
function failureNotice(failure) {
|
|
74
|
+
switch (failure.category) {
|
|
75
|
+
case "quota_exhausted":
|
|
76
|
+
return "\n\n> ⚠️ The model backend is out of credits / quota (vendor billing or hard quota). Re-run this turn on the fusion ensemble — it routes around the exhausted provider.";
|
|
77
|
+
case "transient": {
|
|
78
|
+
const wait = failure.retryAfter !== undefined
|
|
79
|
+
? ` (retry after ~${String(Math.ceil(failure.retryAfter))}s)`
|
|
80
|
+
: "";
|
|
81
|
+
return `\n\n> ⚠️ The model backend is rate-limited or temporarily overloaded${wait}. Re-run this turn on the fusion ensemble, or retry shortly.`;
|
|
82
|
+
}
|
|
83
|
+
case "auth_permanent":
|
|
84
|
+
case "unknown":
|
|
85
|
+
return undefined;
|
|
86
|
+
default: {
|
|
87
|
+
const exhaustive = failure.category;
|
|
88
|
+
return exhaustive;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function failureMetadata(category) {
|
|
93
|
+
switch (category) {
|
|
94
|
+
case "quota_exhausted":
|
|
95
|
+
return "model out of credits / quota";
|
|
96
|
+
case "transient":
|
|
97
|
+
return "model rate-limited or temporarily unavailable";
|
|
98
|
+
case "auth_permanent":
|
|
99
|
+
return "model auth or permission error";
|
|
100
|
+
case "unknown":
|
|
101
|
+
return "local model failed";
|
|
102
|
+
default: {
|
|
103
|
+
const exhaustive = category;
|
|
104
|
+
return exhaustive;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
47
107
|
}
|
|
@@ -20,7 +20,7 @@ export interface ReleaseCategoryStatus {
|
|
|
20
20
|
optionalSuiteIds: string[];
|
|
21
21
|
summary: string;
|
|
22
22
|
}
|
|
23
|
-
export declare const REQUIRED_PACKAGE_ENTRIES: readonly ["package/package.json", "package/README.md", "package/DISCLAIMER.md", "package/dist/src/cli.js", "package/dist/src/cli.d.ts", "package/proto/agent/v1/agent.proto", "package/proto/aiserver/v1/aiserver.proto", "package/docs/protocol.md", "package/docs/release-gates.md", "package/docs/testing-harness.md", "package/docs/test-manifest.json", "package/docs/route-contract-manifest.json", "package/docs/release-summary.json"];
|
|
23
|
+
export declare const REQUIRED_PACKAGE_ENTRIES: readonly ["package/package.json", "package/README.md", "package/DISCLAIMER.md", "package/LICENSE", "package/dist/src/cli.js", "package/dist/src/cli.d.ts", "package/proto/agent/v1/agent.proto", "package/proto/aiserver/v1/aiserver.proto", "package/docs/protocol.md", "package/docs/release-gates.md", "package/docs/testing-harness.md", "package/docs/test-manifest.json", "package/docs/route-contract-manifest.json", "package/docs/release-summary.json"];
|
|
24
24
|
export declare const EXCLUDED_PACKAGE_ENTRY_PREFIXES: readonly ["package/examples/"];
|
|
25
25
|
export declare function runReleaseCheck(repoRoot?: string): number;
|
|
26
26
|
export declare function buildReleaseCategoryStatuses(results: ReleaseGateStatusInput[], optionalSuites?: OptionalLiveSuite[]): ReleaseCategoryStatus[];
|
package/docs/cursor-app.md
CHANGED
|
@@ -55,6 +55,11 @@ settings.
|
|
|
55
55
|
It does not run `sudo`, install certificate trust, edit `/etc/hosts`, modify
|
|
56
56
|
`pf`, bind privileged ports, or kill your normal Cursor instance.
|
|
57
57
|
|
|
58
|
+
Set `CK_WORKSPACE_PATH=<repo>` to make the launched Cursor open a specific
|
|
59
|
+
project while ck keeps its certs/state/logs under the current directory. This is
|
|
60
|
+
how an embedding launcher (for example `fusionkit cursor --ide`) opens the
|
|
61
|
+
user's repo without writing a `.cursor-rpc/` folder into it.
|
|
62
|
+
|
|
58
63
|
Useful commands:
|
|
59
64
|
|
|
60
65
|
```bash
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"status": "reserved-for-future-internal-streaming-connect-grpc",
|
|
50
50
|
"notes": "Do not require protobuf/Buf for v1 package or HTTP/JSON service consumption."
|
|
51
51
|
},
|
|
52
|
-
"schemaBundleHash": "sha256:
|
|
52
|
+
"schemaBundleHash": "sha256:3e8388595aefc8e82962d76e822c514db6552f6ee65e62d487534ef825ad87b8",
|
|
53
53
|
"persistedJsonSchemas": [
|
|
54
54
|
"harness-run-request.v1",
|
|
55
55
|
"harness-run-result.v1",
|
package/docs/release-gates.md
CHANGED
|
@@ -81,7 +81,7 @@ Package smoke validates:
|
|
|
81
81
|
|
|
82
82
|
- `pnpm pack` succeeds after a build.
|
|
83
83
|
- The tarball contains the required `dist/src`, `proto`, `docs`, `README.md`,
|
|
84
|
-
|
|
84
|
+
`DISCLAIMER.md`, and `LICENSE` files.
|
|
85
85
|
- `examples/` is intentionally excluded from the tarball; source examples are
|
|
86
86
|
typechecked by `pnpm examples:check` against the built package exports.
|
|
87
87
|
- A temporary clean project can install the tarball with `pnpm add --offline`.
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velum-labs/cursorkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Unofficial research bridge for experimenting with Cursor's ConnectRPC protocol against a self-hosted OpenAI-compatible model.",
|
|
7
|
-
"license": "
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/velum-labs/cursorkit.git"
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"modelFusionProtocol": {
|
|
20
20
|
"packageName": "@velum-labs/model-fusion-protocol",
|
|
21
|
-
"version": "0.
|
|
22
|
-
"schemaBundleHash": "sha256:
|
|
21
|
+
"version": "0.3.0",
|
|
22
|
+
"schemaBundleHash": "sha256:3e8388595aefc8e82962d76e822c514db6552f6ee65e62d487534ef825ad87b8",
|
|
23
23
|
"contracts": "json-schema+openapi-3.1",
|
|
24
24
|
"origin": "fusionkit"
|
|
25
25
|
},
|
|
@@ -46,7 +46,8 @@
|
|
|
46
46
|
"proto",
|
|
47
47
|
"docs",
|
|
48
48
|
"README.md",
|
|
49
|
-
"DISCLAIMER.md"
|
|
49
|
+
"DISCLAIMER.md",
|
|
50
|
+
"LICENSE"
|
|
50
51
|
],
|
|
51
52
|
"dependencies": {
|
|
52
53
|
"@bufbuild/protobuf": "^2.12.0",
|
|
@@ -61,7 +62,7 @@
|
|
|
61
62
|
"@bufbuild/buf": "^1.70.0",
|
|
62
63
|
"@bufbuild/protoc-gen-es": "^2.12.0",
|
|
63
64
|
"@types/node": "24.10.1",
|
|
64
|
-
"@velum-labs/model-fusion-protocol": "0.
|
|
65
|
+
"@velum-labs/model-fusion-protocol": "0.3.0",
|
|
65
66
|
"@vitest/coverage-v8": "4.1.8",
|
|
66
67
|
"prettier": "3.8.4",
|
|
67
68
|
"tsx": "4.22.4",
|