cursor-api-proxy 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 +219 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.js +53 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +95 -0
- package/dist/client.js +316 -0
- package/dist/client.js.map +1 -0
- package/dist/lib/agent-cmd-args.d.ts +5 -0
- package/dist/lib/agent-cmd-args.js +24 -0
- package/dist/lib/agent-cmd-args.js.map +1 -0
- package/dist/lib/agent-runner.d.ts +12 -0
- package/dist/lib/agent-runner.js +38 -0
- package/dist/lib/agent-runner.js.map +1 -0
- package/dist/lib/anthropic.d.ts +26 -0
- package/dist/lib/anthropic.js +59 -0
- package/dist/lib/anthropic.js.map +1 -0
- package/dist/lib/cli-stream-parser.d.ts +8 -0
- package/dist/lib/cli-stream-parser.js +46 -0
- package/dist/lib/cli-stream-parser.js.map +1 -0
- package/dist/lib/config.d.ts +28 -0
- package/dist/lib/config.js +24 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/cursor-cli.d.ts +9 -0
- package/dist/lib/cursor-cli.js +30 -0
- package/dist/lib/cursor-cli.js.map +1 -0
- package/dist/lib/cursorCli.d.ts +9 -0
- package/dist/lib/cursorCli.js +30 -0
- package/dist/lib/cursorCli.js.map +1 -0
- package/dist/lib/env.d.ts +41 -0
- package/dist/lib/env.js +138 -0
- package/dist/lib/env.js.map +1 -0
- package/dist/lib/handlers/anthropic-messages.d.ts +9 -0
- package/dist/lib/handlers/anthropic-messages.js +124 -0
- package/dist/lib/handlers/anthropic-messages.js.map +1 -0
- package/dist/lib/handlers/chat-completions.d.ts +9 -0
- package/dist/lib/handlers/chat-completions.js +98 -0
- package/dist/lib/handlers/chat-completions.js.map +1 -0
- package/dist/lib/handlers/health.d.ts +7 -0
- package/dist/lib/handlers/health.js +15 -0
- package/dist/lib/handlers/health.js.map +1 -0
- package/dist/lib/handlers/models.d.ts +14 -0
- package/dist/lib/handlers/models.js +34 -0
- package/dist/lib/handlers/models.js.map +1 -0
- package/dist/lib/http.d.ts +5 -0
- package/dist/lib/http.js +32 -0
- package/dist/lib/http.js.map +1 -0
- package/dist/lib/max-mode-preflight.d.ts +5 -0
- package/dist/lib/max-mode-preflight.js +56 -0
- package/dist/lib/max-mode-preflight.js.map +1 -0
- package/dist/lib/model-map.d.ts +17 -0
- package/dist/lib/model-map.js +62 -0
- package/dist/lib/model-map.js.map +1 -0
- package/dist/lib/modelMap.d.ts +17 -0
- package/dist/lib/modelMap.js +62 -0
- package/dist/lib/modelMap.js.map +1 -0
- package/dist/lib/openai.d.ts +7 -0
- package/dist/lib/openai.js +59 -0
- package/dist/lib/openai.js.map +1 -0
- package/dist/lib/process.d.ts +19 -0
- package/dist/lib/process.js +92 -0
- package/dist/lib/process.js.map +1 -0
- package/dist/lib/request-listener.d.ts +7 -0
- package/dist/lib/request-listener.js +70 -0
- package/dist/lib/request-listener.js.map +1 -0
- package/dist/lib/request-log.d.ts +13 -0
- package/dist/lib/request-log.js +110 -0
- package/dist/lib/request-log.js.map +1 -0
- package/dist/lib/requestLog.d.ts +2 -0
- package/dist/lib/requestLog.js +19 -0
- package/dist/lib/requestLog.js.map +1 -0
- package/dist/lib/resolve-model.d.ts +8 -0
- package/dist/lib/resolve-model.js +18 -0
- package/dist/lib/resolve-model.js.map +1 -0
- package/dist/lib/server.d.ts +8 -0
- package/dist/lib/server.js +35 -0
- package/dist/lib/server.js.map +1 -0
- package/dist/lib/workspace.d.ts +6 -0
- package/dist/lib/workspace.js +15 -0
- package/dist/lib/workspace.js.map +1 -0
- package/package.json +50 -0
package/dist/lib/http.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function extractBearerToken(req) {
|
|
2
|
+
const h = req.headers["authorization"];
|
|
3
|
+
if (!h)
|
|
4
|
+
return undefined;
|
|
5
|
+
const val = Array.isArray(h) ? h[0] : h;
|
|
6
|
+
const match = val.match(/^Bearer\s+(.+)$/i);
|
|
7
|
+
return match ? match[1] : undefined;
|
|
8
|
+
}
|
|
9
|
+
export function json(res, status, body) {
|
|
10
|
+
res.writeHead(status, { "Content-Type": "application/json" });
|
|
11
|
+
res.end(JSON.stringify(body));
|
|
12
|
+
}
|
|
13
|
+
export function writeSseHeaders(res) {
|
|
14
|
+
res.writeHead(200, {
|
|
15
|
+
"Content-Type": "text/event-stream",
|
|
16
|
+
"Cache-Control": "no-cache",
|
|
17
|
+
Connection: "keep-alive",
|
|
18
|
+
"X-Accel-Buffering": "no",
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export async function readBody(req) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
let data = "";
|
|
24
|
+
req.setEncoding("utf8");
|
|
25
|
+
req.on("data", (chunk) => {
|
|
26
|
+
data += chunk;
|
|
27
|
+
});
|
|
28
|
+
req.on("end", () => resolve(data));
|
|
29
|
+
req.on("error", reject);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/lib/http.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB,CAAC,GAAyB;IAC1D,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IACvC,IAAI,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACzB,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAC5C,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,GAAwB,EAAE,MAAc,EAAE,IAAa;IAC1E,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAC9D,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAwB;IACtD,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,cAAc,EAAE,mBAAmB;QACnC,eAAe,EAAE,UAAU;QAC3B,UAAU,EAAE,YAAY;QACxB,mBAAmB,EAAE,IAAI;KAC1B,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,GAAyB;IACtD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,IAAI,GAAG,EAAE,CAAC;QACd,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACxB,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;YACvB,IAAI,IAAI,KAAK,CAAC;QAChB,CAAC,CAAC,CAAC;QACH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACnC,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets maxMode=true in Cursor CLI's cli-config.json before spawning the agent.
|
|
3
|
+
* Config resolution order (same as Cursor CLI):
|
|
4
|
+
* 1. CURSOR_CONFIG_DIR/cli-config.json
|
|
5
|
+
* 2. <agent-dir>/../data/config/cli-config.json (CursorToolkit layout)
|
|
6
|
+
* 3. Platform default (LOCALAPPDATA / Library / XDG)
|
|
7
|
+
*/
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
|
+
import * as path from "node:path";
|
|
10
|
+
function getCandidates(agentScriptPath) {
|
|
11
|
+
const result = [];
|
|
12
|
+
if (process.env.CURSOR_CONFIG_DIR) {
|
|
13
|
+
result.push(path.join(process.env.CURSOR_CONFIG_DIR, "cli-config.json"));
|
|
14
|
+
}
|
|
15
|
+
if (agentScriptPath) {
|
|
16
|
+
const agentDir = path.dirname(path.resolve(agentScriptPath));
|
|
17
|
+
result.push(path.join(agentDir, "..", "data", "config", "cli-config.json"));
|
|
18
|
+
}
|
|
19
|
+
const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
|
|
20
|
+
if (process.platform === "win32") {
|
|
21
|
+
const local = process.env.LOCALAPPDATA ?? path.join(home, "AppData", "Local");
|
|
22
|
+
result.push(path.join(local, "cursor-agent", "cli-config.json"));
|
|
23
|
+
}
|
|
24
|
+
else if (process.platform === "darwin") {
|
|
25
|
+
result.push(path.join(home, "Library", "Application Support", "cursor-agent", "cli-config.json"));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const xdg = process.env.XDG_CONFIG_HOME ?? path.join(home, ".config");
|
|
29
|
+
result.push(path.join(xdg, "cursor-agent", "cli-config.json"));
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Write maxMode: true to the first writable cli-config.json.
|
|
35
|
+
* Best-effort: ignores errors (e.g. missing or read-only config).
|
|
36
|
+
*/
|
|
37
|
+
export function runMaxModePreflight(agentScriptPath) {
|
|
38
|
+
for (const candidate of getCandidates(agentScriptPath)) {
|
|
39
|
+
try {
|
|
40
|
+
const rawStr = fs.readFileSync(candidate, "utf-8");
|
|
41
|
+
const raw = JSON.parse(rawStr.replace(/^\uFEFF/, ""));
|
|
42
|
+
if (!raw || typeof raw !== "object" || Object.keys(raw).length <= 1)
|
|
43
|
+
continue;
|
|
44
|
+
raw.maxMode = true;
|
|
45
|
+
if (typeof raw.model === "object" && raw.model && raw.model !== null) {
|
|
46
|
+
raw.model.maxMode = true;
|
|
47
|
+
}
|
|
48
|
+
fs.writeFileSync(candidate, JSON.stringify(raw, null, 2), "utf-8");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
/* candidate not found or unreadable — try next */
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=max-mode-preflight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"max-mode-preflight.js","sourceRoot":"","sources":["../../src/lib/max-mode-preflight.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,SAAS,aAAa,CAAC,eAAwB;IAC7C,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC;QAClC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED,IAAI,eAAe,EAAE,CAAC;QACpB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC;QAC7D,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC;IAE/D,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,OAAO,CA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AAQ,IAAI,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;gBACpE,GAAG,CAAC,KAAiC,CAAC,OAAO,GAAG,IAAI,CAAC;YACxD,CAAC;YACD,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YACnE,OAAO;QACT,CAAC;QAAC,MAAM,CAAC;YACP,kDAAkD;QACpD,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps Anthropic/Claude Code model names to Cursor CLI model IDs
|
|
3
|
+
* so clients like Claude Code can send "claude-opus-4-6" and the proxy uses "opus-4.6".
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Resolve a requested model (e.g. from the client) to the Cursor CLI model ID.
|
|
7
|
+
* If the request uses an Anthropic-style name, returns the mapped Cursor ID; otherwise returns the value as-is.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveToCursorModel(requested: string | undefined): string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Return extra model list entries for GET /v1/models so clients like Claude Code
|
|
12
|
+
* see Anthropic-style ids (e.g. claude-opus-4-6) when those Cursor models are available.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getAnthropicModelAliases(availableCursorIds: string[]): Array<{
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps Anthropic/Claude Code model names to Cursor CLI model IDs
|
|
3
|
+
* so clients like Claude Code can send "claude-opus-4-6" and the proxy uses "opus-4.6".
|
|
4
|
+
*/
|
|
5
|
+
/** Anthropic-style model name (any case) -> Cursor CLI model id */
|
|
6
|
+
const ANTHROPIC_TO_CURSOR = {
|
|
7
|
+
// Claude 4.6
|
|
8
|
+
"claude-opus-4-6": "opus-4.6",
|
|
9
|
+
"claude-opus-4.6": "opus-4.6",
|
|
10
|
+
"claude-sonnet-4-6": "sonnet-4.6",
|
|
11
|
+
"claude-sonnet-4.6": "sonnet-4.6",
|
|
12
|
+
// Claude 4.5
|
|
13
|
+
"claude-opus-4-5": "opus-4.5",
|
|
14
|
+
"claude-opus-4.5": "opus-4.5",
|
|
15
|
+
"claude-sonnet-4-5": "sonnet-4.5",
|
|
16
|
+
"claude-sonnet-4.5": "sonnet-4.5",
|
|
17
|
+
// Generic 4.x (prefer 4.6)
|
|
18
|
+
"claude-opus-4": "opus-4.6",
|
|
19
|
+
"claude-sonnet-4": "sonnet-4.6",
|
|
20
|
+
// Haiku (Cursor has no Haiku; map to Sonnet)
|
|
21
|
+
"claude-haiku-4-5-20251001": "sonnet-4.5",
|
|
22
|
+
"claude-haiku-4-5": "sonnet-4.5",
|
|
23
|
+
"claude-haiku-4-6": "sonnet-4.6",
|
|
24
|
+
"claude-haiku-4": "sonnet-4.5",
|
|
25
|
+
// Thinking variants (if client sends them)
|
|
26
|
+
"claude-opus-4-6-thinking": "opus-4.6-thinking",
|
|
27
|
+
"claude-sonnet-4-6-thinking": "sonnet-4.6-thinking",
|
|
28
|
+
"claude-opus-4-5-thinking": "opus-4.5-thinking",
|
|
29
|
+
"claude-sonnet-4-5-thinking": "sonnet-4.5-thinking",
|
|
30
|
+
};
|
|
31
|
+
/** Cursor IDs we want to expose under Anthropic-style names in GET /v1/models */
|
|
32
|
+
const CURSOR_TO_ANTHROPIC_ALIAS = [
|
|
33
|
+
{ cursorId: "opus-4.6", anthropicId: "claude-opus-4-6", name: "Claude 4.6 Opus" },
|
|
34
|
+
{ cursorId: "opus-4.6-thinking", anthropicId: "claude-opus-4-6-thinking", name: "Claude 4.6 Opus (Thinking)" },
|
|
35
|
+
{ cursorId: "sonnet-4.6", anthropicId: "claude-sonnet-4-6", name: "Claude 4.6 Sonnet" },
|
|
36
|
+
{ cursorId: "sonnet-4.6-thinking", anthropicId: "claude-sonnet-4-6-thinking", name: "Claude 4.6 Sonnet (Thinking)" },
|
|
37
|
+
{ cursorId: "opus-4.5", anthropicId: "claude-opus-4-5", name: "Claude 4.5 Opus" },
|
|
38
|
+
{ cursorId: "opus-4.5-thinking", anthropicId: "claude-opus-4-5-thinking", name: "Claude 4.5 Opus (Thinking)" },
|
|
39
|
+
{ cursorId: "sonnet-4.5", anthropicId: "claude-sonnet-4-5", name: "Claude 4.5 Sonnet" },
|
|
40
|
+
{ cursorId: "sonnet-4.5-thinking", anthropicId: "claude-sonnet-4-5-thinking", name: "Claude 4.5 Sonnet (Thinking)" },
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
* Resolve a requested model (e.g. from the client) to the Cursor CLI model ID.
|
|
44
|
+
* If the request uses an Anthropic-style name, returns the mapped Cursor ID; otherwise returns the value as-is.
|
|
45
|
+
*/
|
|
46
|
+
export function resolveToCursorModel(requested) {
|
|
47
|
+
if (!requested || !requested.trim())
|
|
48
|
+
return undefined;
|
|
49
|
+
const key = requested.trim().toLowerCase();
|
|
50
|
+
return ANTHROPIC_TO_CURSOR[key] ?? requested.trim();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Return extra model list entries for GET /v1/models so clients like Claude Code
|
|
54
|
+
* see Anthropic-style ids (e.g. claude-opus-4-6) when those Cursor models are available.
|
|
55
|
+
*/
|
|
56
|
+
export function getAnthropicModelAliases(availableCursorIds) {
|
|
57
|
+
const set = new Set(availableCursorIds);
|
|
58
|
+
return CURSOR_TO_ANTHROPIC_ALIAS
|
|
59
|
+
.filter((a) => set.has(a.cursorId))
|
|
60
|
+
.map((a) => ({ id: a.anthropicId, name: a.name }));
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=model-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-map.js","sourceRoot":"","sources":["../../src/lib/model-map.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA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,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,IAAI,EAAE,mBAAmB,EAAE;IACvF,EAAE,QAAQ,EAAE,qBAAqB,EAAE,WAAW,EAAE,4BAA4B,EAAE,IAAI,EAAE,8BAA8B,EAAE;CACrH,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAA6B;IAChE,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE;QAAE,OAAO,SAAS,CAAC;IACtD,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC3C,OAAO,mBAAmB,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,kBAA4B;IACnE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACxC,OAAO,yBAAyB;SAC7B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;SAClC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps Anthropic/Claude Code model names to Cursor CLI model IDs
|
|
3
|
+
* so clients like Claude Code can send "claude-opus-4-6" and the proxy uses "opus-4.6".
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Resolve a requested model (e.g. from the client) to the Cursor CLI model ID.
|
|
7
|
+
* If the request uses an Anthropic-style name, returns the mapped Cursor ID; otherwise returns the value as-is.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveToCursorModel(requested: string | undefined): string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Return extra model list entries for GET /v1/models so clients like Claude Code
|
|
12
|
+
* see Anthropic-style ids (e.g. claude-opus-4-6) when those Cursor models are available.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getAnthropicModelAliases(availableCursorIds: string[]): Array<{
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps Anthropic/Claude Code model names to Cursor CLI model IDs
|
|
3
|
+
* so clients like Claude Code can send "claude-opus-4-6" and the proxy uses "opus-4.6".
|
|
4
|
+
*/
|
|
5
|
+
/** Anthropic-style model name (any case) -> Cursor CLI model id */
|
|
6
|
+
const ANTHROPIC_TO_CURSOR = {
|
|
7
|
+
// Claude 4.6
|
|
8
|
+
"claude-opus-4-6": "opus-4.6",
|
|
9
|
+
"claude-opus-4.6": "opus-4.6",
|
|
10
|
+
"claude-sonnet-4-6": "sonnet-4.6",
|
|
11
|
+
"claude-sonnet-4.6": "sonnet-4.6",
|
|
12
|
+
// Claude 4.5
|
|
13
|
+
"claude-opus-4-5": "opus-4.5",
|
|
14
|
+
"claude-opus-4.5": "opus-4.5",
|
|
15
|
+
"claude-sonnet-4-5": "sonnet-4.5",
|
|
16
|
+
"claude-sonnet-4.5": "sonnet-4.5",
|
|
17
|
+
// Generic 4.x (prefer 4.6)
|
|
18
|
+
"claude-opus-4": "opus-4.6",
|
|
19
|
+
"claude-sonnet-4": "sonnet-4.6",
|
|
20
|
+
// Haiku (Cursor has no Haiku; map to Sonnet)
|
|
21
|
+
"claude-haiku-4-5-20251001": "sonnet-4.5",
|
|
22
|
+
"claude-haiku-4-5": "sonnet-4.5",
|
|
23
|
+
"claude-haiku-4-6": "sonnet-4.6",
|
|
24
|
+
"claude-haiku-4": "sonnet-4.5",
|
|
25
|
+
// Thinking variants (if client sends them)
|
|
26
|
+
"claude-opus-4-6-thinking": "opus-4.6-thinking",
|
|
27
|
+
"claude-sonnet-4-6-thinking": "sonnet-4.6-thinking",
|
|
28
|
+
"claude-opus-4-5-thinking": "opus-4.5-thinking",
|
|
29
|
+
"claude-sonnet-4-5-thinking": "sonnet-4.5-thinking",
|
|
30
|
+
};
|
|
31
|
+
/** Cursor IDs we want to expose under Anthropic-style names in GET /v1/models */
|
|
32
|
+
const CURSOR_TO_ANTHROPIC_ALIAS = [
|
|
33
|
+
{ cursorId: "opus-4.6", anthropicId: "claude-opus-4-6", name: "Claude 4.6 Opus" },
|
|
34
|
+
{ cursorId: "opus-4.6-thinking", anthropicId: "claude-opus-4-6-thinking", name: "Claude 4.6 Opus (Thinking)" },
|
|
35
|
+
{ cursorId: "sonnet-4.6", anthropicId: "claude-sonnet-4-6", name: "Claude 4.6 Sonnet" },
|
|
36
|
+
{ cursorId: "sonnet-4.6-thinking", anthropicId: "claude-sonnet-4-6-thinking", name: "Claude 4.6 Sonnet (Thinking)" },
|
|
37
|
+
{ cursorId: "opus-4.5", anthropicId: "claude-opus-4-5", name: "Claude 4.5 Opus" },
|
|
38
|
+
{ cursorId: "opus-4.5-thinking", anthropicId: "claude-opus-4-5-thinking", name: "Claude 4.5 Opus (Thinking)" },
|
|
39
|
+
{ cursorId: "sonnet-4.5", anthropicId: "claude-sonnet-4-5", name: "Claude 4.5 Sonnet" },
|
|
40
|
+
{ cursorId: "sonnet-4.5-thinking", anthropicId: "claude-sonnet-4-5-thinking", name: "Claude 4.5 Sonnet (Thinking)" },
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
* Resolve a requested model (e.g. from the client) to the Cursor CLI model ID.
|
|
44
|
+
* If the request uses an Anthropic-style name, returns the mapped Cursor ID; otherwise returns the value as-is.
|
|
45
|
+
*/
|
|
46
|
+
export function resolveToCursorModel(requested) {
|
|
47
|
+
if (!requested || !requested.trim())
|
|
48
|
+
return undefined;
|
|
49
|
+
const key = requested.trim().toLowerCase();
|
|
50
|
+
return ANTHROPIC_TO_CURSOR[key] ?? requested.trim();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Return extra model list entries for GET /v1/models so clients like Claude Code
|
|
54
|
+
* see Anthropic-style ids (e.g. claude-opus-4-6) when those Cursor models are available.
|
|
55
|
+
*/
|
|
56
|
+
export function getAnthropicModelAliases(availableCursorIds) {
|
|
57
|
+
const set = new Set(availableCursorIds);
|
|
58
|
+
return CURSOR_TO_ANTHROPIC_ALIAS
|
|
59
|
+
.filter((a) => set.has(a.cursorId))
|
|
60
|
+
.map((a) => ({ id: a.anthropicId, name: a.name }));
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=modelMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modelMap.js","sourceRoot":"","sources":["../../src/lib/modelMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,mEAAmE;AACnE,MAAM,mBAAmB,GAA2B;IAClD,aAAa;IACb,iBAAiB,EAAE,UAAU;IAC7B,iBAAiB,EAAE,UAAU;IAC7B,mBAAmB,EAAE,YAAY;IACjC,mBAAmB,EAAE,YAAY;IACjC,aAAa;IACb,iBAAiB,EAAE,UAAU;IAC7B,iBAAiB,EAAE,UAAU;IAC7B,mBAAmB,EAAE,YAAY;IACjC,mBAAmB,EAAE,YAAY;IACjC,2BAA2B;IAC3B,eAAe,EAAE,UAAU;IAC3B,iBAAiB,EAAE,YAAY;IAC/B,6CAA6C;IAC7C,2BAA2B,EAAE,YAAY;IACzC,kBAAkB,EAAE,YAAY;IAChC,kBAAkB,EAAE,YAAY;IAChC,gBAAgB,EAAE,YAAY;IAC9B,2CAA2C;IAC3C,0BAA0B,EAAE,mBAAmB;IAC/C,4BAA4B,EAAE,qBAAqB;IACnD,0BAA0B,EAAE,mBAAmB;IAC/C,4BAA4B,EAAE,qBAAqB;CACpD,CAAC;AAEF,iFAAiF;AACjF,MAAM,yBAAyB,GAAmE;IAChG,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,EA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AG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type OpenAiChatCompletionRequest = {
|
|
2
|
+
model?: string;
|
|
3
|
+
messages: any[];
|
|
4
|
+
stream?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function normalizeModelId(raw: string | undefined): string | undefined;
|
|
7
|
+
export declare function buildPromptFromMessages(messages: any[]): string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export function normalizeModelId(raw) {
|
|
2
|
+
if (!raw)
|
|
3
|
+
return undefined;
|
|
4
|
+
const trimmed = raw.trim();
|
|
5
|
+
if (!trimmed)
|
|
6
|
+
return undefined;
|
|
7
|
+
const parts = trimmed.split("/");
|
|
8
|
+
return parts[parts.length - 1] || undefined;
|
|
9
|
+
}
|
|
10
|
+
function messageContentToText(content) {
|
|
11
|
+
if (typeof content === "string")
|
|
12
|
+
return content;
|
|
13
|
+
if (Array.isArray(content)) {
|
|
14
|
+
return content
|
|
15
|
+
.map((p) => {
|
|
16
|
+
if (!p)
|
|
17
|
+
return "";
|
|
18
|
+
if (typeof p === "string")
|
|
19
|
+
return p;
|
|
20
|
+
if (p.type === "text" && typeof p.text === "string")
|
|
21
|
+
return p.text;
|
|
22
|
+
return "";
|
|
23
|
+
})
|
|
24
|
+
.join("");
|
|
25
|
+
}
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
28
|
+
export function buildPromptFromMessages(messages) {
|
|
29
|
+
const systemParts = [];
|
|
30
|
+
const convo = [];
|
|
31
|
+
for (const m of messages || []) {
|
|
32
|
+
const role = m?.role;
|
|
33
|
+
const text = messageContentToText(m?.content);
|
|
34
|
+
if (!text)
|
|
35
|
+
continue;
|
|
36
|
+
if (role === "system" || role === "developer") {
|
|
37
|
+
systemParts.push(text);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (role === "user") {
|
|
41
|
+
convo.push(`User: ${text}`);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (role === "assistant") {
|
|
45
|
+
convo.push(`Assistant: ${text}`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (role === "tool" || role === "function") {
|
|
49
|
+
convo.push(`Tool: ${text}`);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const system = systemParts.length
|
|
54
|
+
? `System:\n${systemParts.join("\n\n")}\n\n`
|
|
55
|
+
: "";
|
|
56
|
+
const transcript = convo.join("\n\n");
|
|
57
|
+
return system + transcript + "\n\nAssistant:";
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/lib/openai.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,gBAAgB,CAAC,GAAuB;IACtD,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC;IAC3B,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAC3B,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,SAAS,CAAC;AAC9C,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAY;IACxC,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC;IAChD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO;aACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,IAAI,CAAC,CAAC;gBAAE,OAAO,EAAE,CAAC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/B,CAAC,CAAC,YAAY,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM;QAC5C,CAAC,CAAC,EAAE,CAAC;IACP,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtC,OAAO,MAAM,GAAG,UAAU,GAAG,gBAAgB,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type RunResult = {
|
|
2
|
+
code: number;
|
|
3
|
+
stdout: string;
|
|
4
|
+
stderr: string;
|
|
5
|
+
};
|
|
6
|
+
export type RunOptions = {
|
|
7
|
+
cwd?: string;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
/** Enable Cursor Max Mode (preflight writes maxMode to cli-config.json). */
|
|
10
|
+
maxMode?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type RunStreamingOptions = RunOptions & {
|
|
13
|
+
onLine: (line: string) => void;
|
|
14
|
+
};
|
|
15
|
+
export declare function runStreaming(cmd: string, args: string[], opts: RunStreamingOptions): Promise<{
|
|
16
|
+
code: number;
|
|
17
|
+
stderr: string;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function run(cmd: string, args: string[], opts?: RunOptions): Promise<RunResult>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { resolveAgentCommand } from "./env.js";
|
|
3
|
+
import { runMaxModePreflight } from "./max-mode-preflight.js";
|
|
4
|
+
function spawnChild(cmd, args, opts) {
|
|
5
|
+
const resolved = resolveAgentCommand(cmd, args);
|
|
6
|
+
if (opts?.maxMode && resolved.agentScriptPath) {
|
|
7
|
+
runMaxModePreflight(resolved.agentScriptPath);
|
|
8
|
+
}
|
|
9
|
+
const env = { ...resolved.env };
|
|
10
|
+
if (resolved.configDir && !env.CURSOR_CONFIG_DIR) {
|
|
11
|
+
env.CURSOR_CONFIG_DIR = resolved.configDir;
|
|
12
|
+
}
|
|
13
|
+
return spawn(resolved.command, resolved.args, {
|
|
14
|
+
cwd: opts?.cwd,
|
|
15
|
+
env,
|
|
16
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
17
|
+
windowsVerbatimArguments: resolved.windowsVerbatimArguments,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export function runStreaming(cmd, args, opts) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
const child = spawnChild(cmd, args, { cwd: opts.cwd, maxMode: opts.maxMode });
|
|
23
|
+
const timeoutMs = opts.timeoutMs;
|
|
24
|
+
const timeout = typeof timeoutMs === "number" && timeoutMs > 0
|
|
25
|
+
? setTimeout(() => {
|
|
26
|
+
child.kill("SIGKILL");
|
|
27
|
+
}, timeoutMs)
|
|
28
|
+
: undefined;
|
|
29
|
+
let stderr = "";
|
|
30
|
+
let lineBuffer = "";
|
|
31
|
+
child.stderr.setEncoding("utf8");
|
|
32
|
+
child.stderr.on("data", (c) => (stderr += c));
|
|
33
|
+
child.stdout.setEncoding("utf8");
|
|
34
|
+
child.stdout.on("data", (chunk) => {
|
|
35
|
+
lineBuffer += chunk;
|
|
36
|
+
const lines = lineBuffer.split("\n");
|
|
37
|
+
lineBuffer = lines.pop() ?? "";
|
|
38
|
+
for (const line of lines) {
|
|
39
|
+
if (line.trim())
|
|
40
|
+
opts.onLine(line);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
child.on("error", (err) => {
|
|
44
|
+
if (timeout)
|
|
45
|
+
clearTimeout(timeout);
|
|
46
|
+
if (err?.code === "ENOENT") {
|
|
47
|
+
reject(new Error(`Command not found: ${cmd}. Install Cursor CLI (agent) or set CURSOR_AGENT_BIN to its path.`));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
reject(err);
|
|
51
|
+
});
|
|
52
|
+
child.on("close", (code) => {
|
|
53
|
+
if (timeout)
|
|
54
|
+
clearTimeout(timeout);
|
|
55
|
+
if (lineBuffer.trim())
|
|
56
|
+
opts.onLine(lineBuffer.trim());
|
|
57
|
+
resolve({ code: code ?? 0, stderr });
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export function run(cmd, args, opts = {}) {
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const child = spawnChild(cmd, args, { cwd: opts.cwd, maxMode: opts.maxMode });
|
|
64
|
+
const timeoutMs = opts.timeoutMs;
|
|
65
|
+
const timeout = typeof timeoutMs === "number" && timeoutMs > 0
|
|
66
|
+
? setTimeout(() => {
|
|
67
|
+
child.kill("SIGKILL");
|
|
68
|
+
}, timeoutMs)
|
|
69
|
+
: undefined;
|
|
70
|
+
let stdout = "";
|
|
71
|
+
let stderr = "";
|
|
72
|
+
child.stdout.setEncoding("utf8");
|
|
73
|
+
child.stderr.setEncoding("utf8");
|
|
74
|
+
child.stdout.on("data", (c) => (stdout += c));
|
|
75
|
+
child.stderr.on("data", (c) => (stderr += c));
|
|
76
|
+
child.on("error", (err) => {
|
|
77
|
+
if (timeout)
|
|
78
|
+
clearTimeout(timeout);
|
|
79
|
+
if (err?.code === "ENOENT") {
|
|
80
|
+
reject(new Error(`Command not found: ${cmd}. Install Cursor CLI (agent) or set CURSOR_AGENT_BIN to its path.`));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
reject(err);
|
|
84
|
+
});
|
|
85
|
+
child.on("close", (code) => {
|
|
86
|
+
if (timeout)
|
|
87
|
+
clearTimeout(timeout);
|
|
88
|
+
resolve({ code: code ?? 0, stdout, stderr });
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/lib/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EA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AC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC;QAE/C,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAA0B,EAAE,EAAE;YAC/C,IAAI,OAAO;gBAAE,YAAY,CAAC,OAAO,CAAC,CAAC;YACnC,IAAI,GAAG,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC3B,MAAM,CACJ,IAAI,KAAK,CACP,sBAAsB,GAAG,mEAAmE,CAC7F,CACF,CAAC;gBACF,OAAO;YACT,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACzB,IAAI,OAAO;gBAAE,YAAY,CAAC,OAAO,CAAC,CAAC;YACnC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as http from "node:http";
|
|
2
|
+
import type { BridgeConfig } from "./config.js";
|
|
3
|
+
export type BridgeServerOptions = {
|
|
4
|
+
version: string;
|
|
5
|
+
config: BridgeConfig;
|
|
6
|
+
};
|
|
7
|
+
export declare function createRequestListener(opts: BridgeServerOptions): (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { handleHealth } from "./handlers/health.js";
|
|
3
|
+
import { handleModels } from "./handlers/models.js";
|
|
4
|
+
import { handleChatCompletions } from "./handlers/chat-completions.js";
|
|
5
|
+
import { handleAnthropicMessages } from "./handlers/anthropic-messages.js";
|
|
6
|
+
import { extractBearerToken, json, readBody } from "./http.js";
|
|
7
|
+
import { appendSessionLine, logIncoming } from "./request-log.js";
|
|
8
|
+
export function createRequestListener(opts) {
|
|
9
|
+
const { config } = opts;
|
|
10
|
+
const modelCacheRef = { current: undefined };
|
|
11
|
+
const lastRequestedModelRef = {};
|
|
12
|
+
return async (req, res) => {
|
|
13
|
+
const protocol = config.tlsCertPath && config.tlsKeyPath ? "https" : "http";
|
|
14
|
+
const url = new URL(req.url || "/", `${protocol}://${req.headers.host || "localhost"}`);
|
|
15
|
+
const remoteAddress = req.socket?.remoteAddress ?? "unknown";
|
|
16
|
+
const method = req.method ?? "?";
|
|
17
|
+
const pathname = url.pathname;
|
|
18
|
+
logIncoming(method, pathname, remoteAddress);
|
|
19
|
+
res.on("finish", () => {
|
|
20
|
+
appendSessionLine(config.sessionsLogPath, method, pathname, remoteAddress, res.statusCode);
|
|
21
|
+
});
|
|
22
|
+
try {
|
|
23
|
+
if (config.requiredKey) {
|
|
24
|
+
const token = extractBearerToken(req);
|
|
25
|
+
if (token !== config.requiredKey) {
|
|
26
|
+
json(res, 401, {
|
|
27
|
+
error: { message: "Invalid API key", code: "unauthorized" },
|
|
28
|
+
});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (req.method === "GET" && pathname === "/health") {
|
|
33
|
+
handleHealth(res, { version: opts.version, config });
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (req.method === "GET" && pathname === "/v1/models") {
|
|
37
|
+
await handleModels(res, { config, modelCacheRef });
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (req.method === "POST" && pathname === "/v1/chat/completions") {
|
|
41
|
+
const raw = await readBody(req);
|
|
42
|
+
await handleChatCompletions(req, res, { config, lastRequestedModelRef }, raw, method, pathname, remoteAddress);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (req.method === "POST" && pathname === "/v1/messages") {
|
|
46
|
+
const raw = await readBody(req);
|
|
47
|
+
await handleAnthropicMessages(req, res, { config, lastRequestedModelRef }, raw, method, pathname, remoteAddress);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
json(res, 404, { error: { message: "Not found", code: "not_found" } });
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
54
|
+
console.error(`[${new Date().toISOString()}] Proxy error: ${msg}`);
|
|
55
|
+
if (err instanceof Error && err.stack) {
|
|
56
|
+
console.error(err.stack);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
fs.appendFileSync(config.sessionsLogPath, `${new Date().toISOString()} ERROR ${method} ${pathname} ${remoteAddress} ${msg.slice(0, 200).replace(/\n/g, " ")}\n`);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
/* ignore */
|
|
63
|
+
}
|
|
64
|
+
json(res, 500, {
|
|
65
|
+
error: { message: msg, code: "internal_error" },
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=request-listener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-listener.js","sourceRoot":"","sources":["../../src/lib/request-listener.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAK9B,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAOlE,MAAM,UAAU,qBAAqB,CAAC,IAAyB;IAC7D,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACxB,MAAM,aAAa,GAA6B,EAAE,OAAO,EAAE,S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,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,kBAAkB,GAAG,EAAE,CAAC,CAAC;YACnE,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;gBACtC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;YACD,IAAI,CAAC;gBACH,EAAE,CAAC,cAAc,CACf,MAAM,CAAC,eAAe,EACtB,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,UAAU,MAAM,IAAI,QAAQ,IAAI,aAAa,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CACtH,CAAC;YACJ,CAAC;YAAC,MAAM,CAAC;gBACP,YAAY;YACd,CAAC;YACD,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE;gBACb,KAAK,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,gBAAgB,EAAE;aAChD,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function logIncoming(method: string, pathname: string, remoteAddress: string): void;
|
|
2
|
+
export type TrafficMessage = {
|
|
3
|
+
role: string;
|
|
4
|
+
content: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function logTrafficRequest(verbose: boolean, model: string, messages: TrafficMessage[], isStream: boolean): void;
|
|
7
|
+
export declare function logTrafficResponse(verbose: boolean, model: string, text: string, isStream: boolean): void;
|
|
8
|
+
export declare function appendSessionLine(logPath: string, method: string, pathname: string, remoteAddress: string, statusCode: number): void;
|
|
9
|
+
/**
|
|
10
|
+
* Log an agent execution error to console and sessions log.
|
|
11
|
+
* Returns the error message for use in API responses.
|
|
12
|
+
*/
|
|
13
|
+
export declare function logAgentError(logPath: string, method: string, pathname: string, remoteAddress: string, exitCode: number, stderr: string): string;
|