cc-hub-cli 1.0.6 → 1.0.7
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/dist/index.js +38 -14
- package/package.json +9 -3
package/dist/index.js
CHANGED
|
@@ -318,6 +318,42 @@ async function startOpenAIProxy(targetUrl, apiKey, model, models = []) {
|
|
|
318
318
|
}
|
|
319
319
|
const isStream = !!parsed.stream;
|
|
320
320
|
const openaiBody = transformAnthropicToOpenAI({ ...parsed, stream: false });
|
|
321
|
+
if (isStream) {
|
|
322
|
+
res.writeHead(200, {
|
|
323
|
+
"Content-Type": "text/event-stream",
|
|
324
|
+
"Cache-Control": "no-cache",
|
|
325
|
+
"Connection": "keep-alive"
|
|
326
|
+
});
|
|
327
|
+
const keepalive = setInterval(() => res.write(": keepalive\n\n"), 15e3);
|
|
328
|
+
try {
|
|
329
|
+
const upstream2 = await fetch(`${base}/v1/chat/completions`, {
|
|
330
|
+
method: "POST",
|
|
331
|
+
headers: {
|
|
332
|
+
"Content-Type": "application/json",
|
|
333
|
+
"Authorization": `Bearer ${apiKey}`
|
|
334
|
+
},
|
|
335
|
+
body: JSON.stringify(openaiBody)
|
|
336
|
+
});
|
|
337
|
+
if (!upstream2.ok) {
|
|
338
|
+
const errText = await upstream2.text();
|
|
339
|
+
res.write(`event: error
|
|
340
|
+
data: ${errText}
|
|
341
|
+
|
|
342
|
+
`);
|
|
343
|
+
res.end();
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const data2 = await upstream2.json();
|
|
347
|
+
const anthropicResponse2 = transformOpenAIResponseToAnthropic(data2, parsed.model ?? model);
|
|
348
|
+
for (const chunk of synthesizeAnthropicSSE(anthropicResponse2)) {
|
|
349
|
+
res.write(chunk);
|
|
350
|
+
}
|
|
351
|
+
res.end();
|
|
352
|
+
} finally {
|
|
353
|
+
clearInterval(keepalive);
|
|
354
|
+
}
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
321
357
|
const upstream = await fetch(`${base}/v1/chat/completions`, {
|
|
322
358
|
method: "POST",
|
|
323
359
|
headers: {
|
|
@@ -334,20 +370,8 @@ async function startOpenAIProxy(targetUrl, apiKey, model, models = []) {
|
|
|
334
370
|
}
|
|
335
371
|
const data = await upstream.json();
|
|
336
372
|
const anthropicResponse = transformOpenAIResponseToAnthropic(data, parsed.model ?? model);
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
"Content-Type": "text/event-stream",
|
|
340
|
-
"Cache-Control": "no-cache",
|
|
341
|
-
"Connection": "keep-alive"
|
|
342
|
-
});
|
|
343
|
-
for (const chunk of synthesizeAnthropicSSE(anthropicResponse)) {
|
|
344
|
-
res.write(chunk);
|
|
345
|
-
}
|
|
346
|
-
res.end();
|
|
347
|
-
} else {
|
|
348
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
349
|
-
res.end(JSON.stringify(anthropicResponse));
|
|
350
|
-
}
|
|
373
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
374
|
+
res.end(JSON.stringify(anthropicResponse));
|
|
351
375
|
return;
|
|
352
376
|
}
|
|
353
377
|
res.writeHead(404, { "Content-Type": "application/json" });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-hub-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Manage Claude CLI profiles, hooks, and sessions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -10,7 +10,11 @@
|
|
|
10
10
|
"build": "tsup",
|
|
11
11
|
"dev": "tsup --watch",
|
|
12
12
|
"start": "node dist/index.js",
|
|
13
|
-
"prepublishOnly": "npm run build"
|
|
13
|
+
"prepublishOnly": "npm run build",
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test:watch": "vitest",
|
|
16
|
+
"test:coverage": "vitest run --coverage",
|
|
17
|
+
"test:build": "npm test && npm run build"
|
|
14
18
|
},
|
|
15
19
|
"repository": {
|
|
16
20
|
"type": "git",
|
|
@@ -29,7 +33,9 @@
|
|
|
29
33
|
},
|
|
30
34
|
"devDependencies": {
|
|
31
35
|
"tsup": "^8.4.0",
|
|
32
|
-
"typescript": "^5.7.0"
|
|
36
|
+
"typescript": "^5.7.0",
|
|
37
|
+
"vitest": "^3.0.0",
|
|
38
|
+
"@vitest/coverage-v8": "^3.0.0"
|
|
33
39
|
},
|
|
34
40
|
"engines": {
|
|
35
41
|
"node": ">=18"
|