commandcode-api-proxy 0.1.4 → 0.3.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/README.md +59 -29
- package/dist/config.d.ts +5 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +30 -1
- package/dist/config.js.map +1 -1
- package/dist/models.json +88 -23
- package/dist/proxy.js +18 -5
- package/dist/proxy.js.map +1 -1
- package/dist/server.d.ts +4 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +162 -46
- package/dist/server.js.map +1 -1
- package/dist/setup/opencode.d.ts.map +1 -1
- package/dist/setup/opencode.js +20 -1
- package/dist/setup/opencode.js.map +1 -1
- package/dist/stream.d.ts +0 -17
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +0 -44
- package/dist/stream.js.map +1 -1
- package/dist/translate/anthropic.d.ts +10 -1
- package/dist/translate/anthropic.d.ts.map +1 -1
- package/dist/translate/anthropic.js +88 -20
- package/dist/translate/anthropic.js.map +1 -1
- package/dist/translate/models.d.ts +15 -0
- package/dist/translate/models.d.ts.map +1 -1
- package/dist/translate/models.js +48 -1
- package/dist/translate/models.js.map +1 -1
- package/dist/translate/openai.d.ts +31 -0
- package/dist/translate/openai.d.ts.map +1 -1
- package/dist/translate/openai.js +128 -38
- package/dist/translate/openai.js.map +1 -1
- package/dist/translate/types.d.ts +16 -2
- package/dist/translate/types.d.ts.map +1 -1
- package/dist/upstream.d.ts +3 -10
- package/dist/upstream.d.ts.map +1 -1
- package/dist/upstream.js +166 -42
- package/dist/upstream.js.map +1 -1
- package/package.json +17 -15
package/dist/upstream.js
CHANGED
|
@@ -9,7 +9,7 @@ import { logger } from "./logger.js";
|
|
|
9
9
|
*/
|
|
10
10
|
export function buildHeaders(apiKey, ccVersion, body) {
|
|
11
11
|
const sessionId = body.threadId;
|
|
12
|
-
logger.debug(`Sending Authorization
|
|
12
|
+
logger.debug(`Sending Authorization header (key length: ${apiKey.length})`);
|
|
13
13
|
return {
|
|
14
14
|
"Content-Type": "application/json",
|
|
15
15
|
Accept: "application/json, */*",
|
|
@@ -47,44 +47,83 @@ function generateTraceparent() {
|
|
|
47
47
|
* regardless of the downstream client's `stream` flag. For non-streaming
|
|
48
48
|
* downstream requests, the caller drains the returned `stream` into events.
|
|
49
49
|
*
|
|
50
|
+
* Retryable failures (HTTP 5xx/429, timeouts, network errors) are retried up
|
|
51
|
+
* to MAX_RETRIES times with linear backoff — but ONLY before the stream starts.
|
|
52
|
+
* A client-initiated abort (caller already disconnected) is never retried.
|
|
53
|
+
*
|
|
50
54
|
* Returns a Readable of parsed CCEvents. Callers MUST consume or destroy it.
|
|
51
55
|
*/
|
|
56
|
+
const MAX_RETRIES = 2;
|
|
57
|
+
const RETRY_BACKOFF_MS = 500;
|
|
58
|
+
function sleep(ms, signal) {
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
const t = setTimeout(resolve, ms);
|
|
61
|
+
signal?.addEventListener("abort", () => {
|
|
62
|
+
clearTimeout(t);
|
|
63
|
+
resolve();
|
|
64
|
+
}, { once: true });
|
|
65
|
+
});
|
|
66
|
+
}
|
|
52
67
|
export async function sendToCC(body, options, signal) {
|
|
53
|
-
const { apiBase, apiKey, ccVersion, timeoutMs =
|
|
68
|
+
const { apiBase, apiKey, ccVersion, timeoutMs = 600_000, idleTimeoutMs = 120_000, } = options;
|
|
54
69
|
const url = `${apiBase}/alpha/generate`;
|
|
55
70
|
// CC's API is always streaming — force it on so the upstream stays a stream.
|
|
56
71
|
body.params.stream = true;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
let lastError = null;
|
|
73
|
+
for (let attempt = 1; attempt <= MAX_RETRIES + 1; attempt++) {
|
|
74
|
+
// Per-attempt timeout so one dead connection can't burn the whole budget.
|
|
75
|
+
const controller = new AbortController();
|
|
76
|
+
const combinedSignal = signal ? combineSignals(signal, controller.signal) : controller.signal;
|
|
77
|
+
const timeout = setTimeout(() => controller.abort(new Error("Upstream timeout")), timeoutMs);
|
|
78
|
+
try {
|
|
79
|
+
const response = await fetch(url, {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: buildHeaders(apiKey, ccVersion, body),
|
|
82
|
+
body: JSON.stringify(body),
|
|
83
|
+
signal: combinedSignal,
|
|
84
|
+
});
|
|
85
|
+
clearTimeout(timeout);
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
const errorText = await response.text().catch(() => "");
|
|
88
|
+
const retryable = response.status >= 500 || response.status === 429;
|
|
89
|
+
lastError = new UpstreamError(`CC API ${response.status}: ${errorText || response.statusText}`, response.status, retryable);
|
|
90
|
+
if (retryable && attempt <= MAX_RETRIES) {
|
|
91
|
+
logger.warn(`CC upstream ${response.status}, retrying ${attempt}/${MAX_RETRIES}...`);
|
|
92
|
+
await sleep(RETRY_BACKOFF_MS * attempt, signal);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
throw lastError;
|
|
96
|
+
}
|
|
97
|
+
if (!response.body) {
|
|
98
|
+
throw new UpstreamError("CC API returned no body", 0, true);
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
stream: nodeReaderToStream(response.body.getReader(), {
|
|
102
|
+
idleTimeoutMs,
|
|
103
|
+
abortSignal: signal,
|
|
104
|
+
}),
|
|
105
|
+
};
|
|
75
106
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
107
|
+
catch (err) {
|
|
108
|
+
clearTimeout(timeout);
|
|
109
|
+
if (err instanceof UpstreamError)
|
|
110
|
+
throw err;
|
|
111
|
+
// Distinguish a client-initiated abort (caller is gone — never retry, it
|
|
112
|
+
// only wastes a request) from a timeout/network blip (retryable).
|
|
113
|
+
const aborted = err.name === "AbortError";
|
|
114
|
+
if (aborted && signal?.aborted) {
|
|
115
|
+
throw new UpstreamError("Request aborted", 0, true);
|
|
116
|
+
}
|
|
117
|
+
lastError = new UpstreamError(aborted ? "Upstream timeout" : `Upstream request failed: ${err.message}`, 0, true);
|
|
118
|
+
if (attempt <= MAX_RETRIES) {
|
|
119
|
+
logger.warn(`CC upstream ${aborted ? "timeout" : "error"}, retrying ${attempt}/${MAX_RETRIES}...`);
|
|
120
|
+
await sleep(RETRY_BACKOFF_MS * attempt, signal);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
throw lastError;
|
|
85
124
|
}
|
|
86
|
-
throw new UpstreamError(`Upstream request failed: ${err.message}`, 0, true);
|
|
87
125
|
}
|
|
126
|
+
throw lastError ?? new UpstreamError("Upstream request failed after retries", 0, true);
|
|
88
127
|
}
|
|
89
128
|
/**
|
|
90
129
|
* Drain a CCEvent stream into an array. Used for non-streaming downstream
|
|
@@ -125,21 +164,96 @@ function combineSignals(...signals) {
|
|
|
125
164
|
}
|
|
126
165
|
return controller.signal;
|
|
127
166
|
}
|
|
128
|
-
function nodeReaderToStream(reader) {
|
|
167
|
+
function nodeReaderToStream(reader, opts = {}) {
|
|
129
168
|
const decoder = new TextDecoder();
|
|
130
169
|
let buffer = "";
|
|
131
|
-
|
|
170
|
+
// Lines parsed from the current upstream chunk that haven't been pushed yet.
|
|
171
|
+
// Kept in closure scope so backpressure mid-chunk doesn't drop them: when
|
|
172
|
+
// push() returns false we return out of read(), and resume here on the next
|
|
173
|
+
// read() call instead of starting a fresh reader.read().
|
|
174
|
+
let pendingLines = [];
|
|
175
|
+
let upstreamDone = false;
|
|
176
|
+
let readerReleased = false;
|
|
177
|
+
// Idle timeout: detect a stalled upstream (TCP open, no chunks arriving).
|
|
178
|
+
// Reset on every successful read(). If it fires we abort the reader so
|
|
179
|
+
// pumpStream's error path synthesizes a clean finish for the client
|
|
180
|
+
// instead of hanging forever waiting on a dead connection.
|
|
181
|
+
const idleMs = opts.idleTimeoutMs ?? 0;
|
|
182
|
+
let idleTimer = null;
|
|
183
|
+
const armIdle = () => {
|
|
184
|
+
if (idleMs <= 0)
|
|
185
|
+
return;
|
|
186
|
+
disarmIdle();
|
|
187
|
+
idleTimer = setTimeout(() => {
|
|
188
|
+
const err = new Error(`CC upstream idle timeout: no data for ${idleMs}ms`);
|
|
189
|
+
err.name = "IdleTimeoutError";
|
|
190
|
+
// Cancel the reader — pending read() will reject with this reason.
|
|
191
|
+
const cancel = reader.cancel;
|
|
192
|
+
if (typeof cancel === "function") {
|
|
193
|
+
cancel.call(reader, err).catch(() => { });
|
|
194
|
+
}
|
|
195
|
+
}, idleMs);
|
|
196
|
+
// Don't keep the event loop alive just for the idle timer.
|
|
197
|
+
idleTimer.unref?.();
|
|
198
|
+
};
|
|
199
|
+
const disarmIdle = () => {
|
|
200
|
+
if (idleTimer) {
|
|
201
|
+
clearTimeout(idleTimer);
|
|
202
|
+
idleTimer = null;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
// Release the underlying reader when the consumer destroys this stream
|
|
206
|
+
// (e.g. client disconnected). Otherwise CC keeps generating tokens nobody
|
|
207
|
+
// will read, burning the user's quota until upstream's own timeout fires.
|
|
208
|
+
const releaseReader = () => {
|
|
209
|
+
disarmIdle();
|
|
210
|
+
if (readerReleased)
|
|
211
|
+
return;
|
|
212
|
+
readerReleased = true;
|
|
213
|
+
const cancel = reader.cancel;
|
|
214
|
+
if (typeof cancel === "function") {
|
|
215
|
+
cancel.call(reader).catch(() => {
|
|
216
|
+
/* already closed */
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
const stream = new Readable({
|
|
132
221
|
objectMode: true,
|
|
222
|
+
emitClose: true,
|
|
223
|
+
destroy(err, cb) {
|
|
224
|
+
releaseReader();
|
|
225
|
+
cb(err);
|
|
226
|
+
},
|
|
133
227
|
async read() {
|
|
134
228
|
try {
|
|
135
229
|
while (true) {
|
|
230
|
+
// Drain anything left over from a previous chunk that was
|
|
231
|
+
// interrupted by backpressure before we read more from upstream.
|
|
232
|
+
while (pendingLines.length > 0) {
|
|
233
|
+
const line = pendingLines.shift();
|
|
234
|
+
const result = parseCCLine(line);
|
|
235
|
+
if (result.type === "event" && result.event) {
|
|
236
|
+
if (!this.push(result.event))
|
|
237
|
+
return; // still backpressured
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (upstreamDone) {
|
|
241
|
+
this.push(null);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
armIdle();
|
|
136
245
|
const { done, value } = await reader.read();
|
|
246
|
+
disarmIdle();
|
|
137
247
|
if (done) {
|
|
138
|
-
|
|
248
|
+
upstreamDone = true;
|
|
249
|
+
releaseReader();
|
|
250
|
+
// Flush trailing partial line (no newline terminator).
|
|
139
251
|
if (buffer.trim()) {
|
|
140
252
|
const result = parseCCLine(buffer);
|
|
253
|
+
buffer = "";
|
|
141
254
|
if (result.type === "event" && result.event) {
|
|
142
|
-
this.push(result.event)
|
|
255
|
+
if (!this.push(result.event))
|
|
256
|
+
return; // backpressured; null next read
|
|
143
257
|
}
|
|
144
258
|
}
|
|
145
259
|
this.push(null);
|
|
@@ -147,21 +261,31 @@ function nodeReaderToStream(reader) {
|
|
|
147
261
|
}
|
|
148
262
|
buffer += decoder.decode(value, { stream: true });
|
|
149
263
|
const lines = buffer.split("\n");
|
|
264
|
+
// Last segment is the partial line awaiting its newline; keep it.
|
|
150
265
|
buffer = lines.pop() ?? "";
|
|
151
|
-
|
|
152
|
-
const result = parseCCLine(line);
|
|
153
|
-
if (result.type === "event" && result.event) {
|
|
154
|
-
const canContinue = this.push(result.event);
|
|
155
|
-
if (!canContinue)
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
266
|
+
pendingLines = lines;
|
|
159
267
|
}
|
|
160
268
|
}
|
|
161
269
|
catch (err) {
|
|
270
|
+
releaseReader();
|
|
162
271
|
this.destroy(err);
|
|
163
272
|
}
|
|
164
273
|
},
|
|
165
274
|
});
|
|
275
|
+
// If the caller aborts (client disconnect), make sure a pending read()
|
|
276
|
+
// wakes up. The reader.cancel() in destroy() handles the converse.
|
|
277
|
+
if (opts.abortSignal) {
|
|
278
|
+
const sig = opts.abortSignal;
|
|
279
|
+
if (sig.aborted) {
|
|
280
|
+
releaseReader();
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
sig.addEventListener("abort", () => {
|
|
284
|
+
disarmIdle();
|
|
285
|
+
stream.destroy(new Error("Client disconnected"));
|
|
286
|
+
}, { once: true });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return stream;
|
|
166
290
|
}
|
|
167
291
|
//# sourceMappingURL=upstream.js.map
|
package/dist/upstream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upstream.js","sourceRoot":"","sources":["../src/upstream.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"upstream.js","sourceRoot":"","sources":["../src/upstream.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAYrC;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAc,EACd,SAAiB,EACjB,IAAmB;IAEnB,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;I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AAC,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAC;YACnD,CAAC,EACD,EAAE,IAAI,EAAE,IAAI,EAAE,CACf,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commandcode-api-proxy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "OpenAI-compatible API proxy for Command Code. Use your Command Code subscription from any OpenAI client.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-proxy",
|
|
@@ -27,6 +27,20 @@
|
|
|
27
27
|
],
|
|
28
28
|
"type": "module",
|
|
29
29
|
"main": "./dist/proxy.js",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc && tsc-alias",
|
|
32
|
+
"start": "node dist/proxy.js",
|
|
33
|
+
"dev": "tsx src/proxy.ts",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"test:watch": "vitest",
|
|
36
|
+
"test:coverage": "vitest run --coverage",
|
|
37
|
+
"lint": "vp lint",
|
|
38
|
+
"fmt": "vp fmt",
|
|
39
|
+
"fmt:check": "vp fmt --check",
|
|
40
|
+
"auth": "tsx src/proxy.ts auth",
|
|
41
|
+
"check": "vp check",
|
|
42
|
+
"prepublishOnly": "pnpm build && pnpm test"
|
|
43
|
+
},
|
|
30
44
|
"devDependencies": {
|
|
31
45
|
"@types/node": "^24.0.0",
|
|
32
46
|
"ai": "^5.0.206",
|
|
@@ -39,17 +53,5 @@
|
|
|
39
53
|
"engines": {
|
|
40
54
|
"node": ">=24.0.0"
|
|
41
55
|
},
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
"start": "node dist/proxy.js",
|
|
45
|
-
"dev": "tsx src/proxy.ts",
|
|
46
|
-
"test": "vitest run",
|
|
47
|
-
"test:watch": "vitest",
|
|
48
|
-
"test:coverage": "vitest run --coverage",
|
|
49
|
-
"lint": "vp lint",
|
|
50
|
-
"fmt": "vp fmt",
|
|
51
|
-
"fmt:check": "vp fmt --check",
|
|
52
|
-
"auth": "tsx src/proxy.ts auth",
|
|
53
|
-
"check": "vp check"
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
+
"packageManager": "pnpm@10.32.1"
|
|
57
|
+
}
|