@moonmath-ai/zro 0.4.3 → 0.5.0-beta.1
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 +55 -2
- package/dist/args.js +87 -0
- package/dist/args.js.map +1 -1
- package/dist/e2ee-proxy.d.ts +18 -0
- package/dist/e2ee-proxy.js +585 -0
- package/dist/e2ee-proxy.js.map +1 -0
- package/dist/e2ee.d.ts +187 -0
- package/dist/e2ee.js +907 -0
- package/dist/e2ee.js.map +1 -0
- package/dist/engine/tools/claude.js +6 -1
- package/dist/engine/tools/claude.js.map +1 -1
- package/dist/engine/tools/codex.js +6 -1
- package/dist/engine/tools/codex.js.map +1 -1
- package/dist/engine/types.d.ts +2 -0
- package/dist/install.js +19 -0
- package/dist/install.js.map +1 -1
- package/dist/run.js +206 -52
- package/dist/run.js.map +1 -1
- package/dist/selfupdate.d.ts +7 -0
- package/dist/selfupdate.js +136 -0
- package/dist/selfupdate.js.map +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/ui.js +6 -1
- package/dist/ui.js.map +1 -1
- package/dist/version.d.ts +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +4 -1
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
import http from "node:http";
|
|
2
|
+
import { encryptRequest, fetchAndVerifyManifest, mergeUsage, selectActiveKey, supportedE2eeModels, } from "./e2ee.js";
|
|
3
|
+
const MAX_BODY_BYTES = 32 * 1024 * 1024;
|
|
4
|
+
const MANIFEST_TTL_MS = 300_000;
|
|
5
|
+
const STALE_RETRY_MS = 30_000;
|
|
6
|
+
const POST_ENDPOINTS = {
|
|
7
|
+
"/v1/chat/completions": "chat_completions",
|
|
8
|
+
"/v1/messages": "messages",
|
|
9
|
+
"/v1/responses": "responses",
|
|
10
|
+
};
|
|
11
|
+
class ManifestCache {
|
|
12
|
+
upstream;
|
|
13
|
+
rootPubkey;
|
|
14
|
+
fetcher;
|
|
15
|
+
ttlMs;
|
|
16
|
+
cached = null;
|
|
17
|
+
inflight = null;
|
|
18
|
+
constructor(upstream, rootPubkey, fetcher, ttlMs) {
|
|
19
|
+
this.upstream = upstream.replace(/\/+$/, "");
|
|
20
|
+
this.rootPubkey = rootPubkey;
|
|
21
|
+
this.fetcher = fetcher;
|
|
22
|
+
this.ttlMs = ttlMs;
|
|
23
|
+
}
|
|
24
|
+
invalidate() {
|
|
25
|
+
this.cached = null;
|
|
26
|
+
}
|
|
27
|
+
async getActive() {
|
|
28
|
+
if (this.cached && Date.now() < this.cached.expiresAt) {
|
|
29
|
+
return this.cached;
|
|
30
|
+
}
|
|
31
|
+
if (!this.inflight) {
|
|
32
|
+
this.inflight = (async () => {
|
|
33
|
+
let manifest;
|
|
34
|
+
try {
|
|
35
|
+
manifest = await fetchAndVerifyManifest(this.upstream, this.rootPubkey, this.fetcher);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
// A failed refresh keeps the last verified key while it is still in its validity window,
|
|
39
|
+
// so a gateway blip doesn't fail live requests. invalidate() clears it for a hard refetch.
|
|
40
|
+
const stale = this.cached;
|
|
41
|
+
if (!stale)
|
|
42
|
+
throw error;
|
|
43
|
+
try {
|
|
44
|
+
selectActiveKey(stale.manifest);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
stale.expiresAt = Date.now() + STALE_RETRY_MS;
|
|
50
|
+
return stale;
|
|
51
|
+
}
|
|
52
|
+
const { kid, publicKey } = selectActiveKey(manifest);
|
|
53
|
+
const supportedModels = supportedE2eeModels(manifest);
|
|
54
|
+
const entry = {
|
|
55
|
+
kid,
|
|
56
|
+
publicKey,
|
|
57
|
+
manifest,
|
|
58
|
+
supportedModels,
|
|
59
|
+
expiresAt: Date.now() + this.ttlMs,
|
|
60
|
+
};
|
|
61
|
+
this.cached = entry;
|
|
62
|
+
return entry;
|
|
63
|
+
})().finally(() => {
|
|
64
|
+
this.inflight = null;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return this.inflight;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export async function startE2eeProxy(options) {
|
|
71
|
+
const upstream = options.upstream.replace(/\/+$/, "");
|
|
72
|
+
const host = options.host ?? "127.0.0.1";
|
|
73
|
+
const requestedPort = options.port ?? 0;
|
|
74
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
75
|
+
const cache = new ManifestCache(upstream, options.rootPubkey, fetcher, options.manifestTtlMs ?? MANIFEST_TTL_MS);
|
|
76
|
+
// Verify manifest eagerly so an invalid root key or unreachable manifest fails before launch.
|
|
77
|
+
const initial = await cache.getActive();
|
|
78
|
+
const server = http.createServer((req, res) => {
|
|
79
|
+
void handleRequest(req, res, upstream, cache, fetcher).catch(() => {
|
|
80
|
+
if (!res.headersSent) {
|
|
81
|
+
sendJson(res, 502, { error: { message: "Local E2EE proxy error", type: "e2ee_error" } });
|
|
82
|
+
}
|
|
83
|
+
else if (!res.writableEnded) {
|
|
84
|
+
res.end();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
server.requestTimeout = 0;
|
|
89
|
+
await new Promise((resolve, reject) => {
|
|
90
|
+
const onError = (err) => {
|
|
91
|
+
server.off("listening", onListening);
|
|
92
|
+
reject(err);
|
|
93
|
+
};
|
|
94
|
+
const onListening = () => {
|
|
95
|
+
server.off("error", onError);
|
|
96
|
+
resolve();
|
|
97
|
+
};
|
|
98
|
+
server.once("error", onError);
|
|
99
|
+
server.once("listening", onListening);
|
|
100
|
+
server.listen(requestedPort, host);
|
|
101
|
+
});
|
|
102
|
+
const addr = server.address();
|
|
103
|
+
const root = `http://${host}:${addr.port}`;
|
|
104
|
+
return {
|
|
105
|
+
root,
|
|
106
|
+
baseUrl: `${root}/v1`,
|
|
107
|
+
port: addr.port,
|
|
108
|
+
kid: initial.kid,
|
|
109
|
+
supportedModels: initial.supportedModels,
|
|
110
|
+
close: () => new Promise((resolve) => {
|
|
111
|
+
server.close(() => resolve());
|
|
112
|
+
server.closeAllConnections?.();
|
|
113
|
+
}),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
async function handleRequest(req, res, upstream, cache, fetcher) {
|
|
117
|
+
const method = (req.method ?? "GET").toUpperCase();
|
|
118
|
+
const rawUrl = req.url ?? "/";
|
|
119
|
+
const pathOnly = new URL(rawUrl, "http://127.0.0.1").pathname;
|
|
120
|
+
if (method === "GET" && (pathOnly === "/health" || pathOnly === "/v1/models")) {
|
|
121
|
+
await handleGetPassthrough(req, res, upstream, rawUrl, fetcher);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const endpoint = method === "POST" ? POST_ENDPOINTS[pathOnly] : undefined;
|
|
125
|
+
if (!endpoint) {
|
|
126
|
+
sendJson(res, 404, {
|
|
127
|
+
error: { message: "Not found", type: "invalid_request_error", code: "not_found" },
|
|
128
|
+
});
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
let rawBody;
|
|
132
|
+
try {
|
|
133
|
+
rawBody = await readBody(req, MAX_BODY_BYTES);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
const msg = error instanceof Error ? error.message : "Invalid request body";
|
|
137
|
+
const status = msg.includes("too large") ? 413 : 400;
|
|
138
|
+
sendJson(res, status, { error: { message: msg, type: "invalid_request_error" } });
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
let innerRequest;
|
|
142
|
+
try {
|
|
143
|
+
innerRequest = JSON.parse(rawBody.toString("utf8"));
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
sendJson(res, 400, {
|
|
147
|
+
error: { message: "Request body must be valid JSON", type: "invalid_request_error" },
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (!innerRequest || typeof innerRequest !== "object" || Array.isArray(innerRequest)) {
|
|
152
|
+
sendJson(res, 400, {
|
|
153
|
+
error: { message: "Request body must be a JSON object", type: "invalid_request_error" },
|
|
154
|
+
});
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const innerObj = innerRequest;
|
|
158
|
+
if (typeof innerObj.model !== "string" || !innerObj.model) {
|
|
159
|
+
sendJson(res, 400, {
|
|
160
|
+
error: { message: "Request body must contain a non-empty string 'model'", type: "invalid_request_error" },
|
|
161
|
+
});
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const stream = Boolean(innerObj.stream);
|
|
165
|
+
let activeKey;
|
|
166
|
+
let outerRequest;
|
|
167
|
+
let session;
|
|
168
|
+
try {
|
|
169
|
+
activeKey = await cache.getActive();
|
|
170
|
+
const sealed = encryptRequest(endpoint, innerObj, {
|
|
171
|
+
kid: activeKey.kid,
|
|
172
|
+
publicKey: activeKey.publicKey,
|
|
173
|
+
});
|
|
174
|
+
outerRequest = sealed.outerRequest;
|
|
175
|
+
session = sealed.session;
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
sendJson(res, 502, {
|
|
179
|
+
error: {
|
|
180
|
+
message: `E2EE encryption error: ${error instanceof Error ? error.name : "Error"}`,
|
|
181
|
+
type: "e2ee_error",
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const headers = forwardAuthHeaders(req.headers);
|
|
187
|
+
headers["Content-Type"] = "application/json";
|
|
188
|
+
headers.Accept = stream ? "text/event-stream" : "application/json";
|
|
189
|
+
if (endpoint === "messages" && !headers["anthropic-version"]) {
|
|
190
|
+
headers["anthropic-version"] = "2023-06-01";
|
|
191
|
+
}
|
|
192
|
+
// A client that disconnects (Esc in the agent, Ctrl-C) cancels the upstream generation too.
|
|
193
|
+
const abort = new AbortController();
|
|
194
|
+
res.on("close", () => {
|
|
195
|
+
if (!res.writableFinished)
|
|
196
|
+
abort.abort();
|
|
197
|
+
});
|
|
198
|
+
let upstreamResp;
|
|
199
|
+
try {
|
|
200
|
+
upstreamResp = await fetcher(`${upstream}${rawUrl}`, {
|
|
201
|
+
method: "POST",
|
|
202
|
+
headers,
|
|
203
|
+
body: JSON.stringify(outerRequest),
|
|
204
|
+
signal: abort.signal,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
sendJson(res, 502, {
|
|
209
|
+
error: {
|
|
210
|
+
message: `Upstream error: ${error instanceof Error ? error.name : "FetchError"}`,
|
|
211
|
+
type: "e2ee_error",
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (!upstreamResp.ok) {
|
|
217
|
+
const errBuf = Buffer.from(await upstreamResp.arrayBuffer());
|
|
218
|
+
const ctype = upstreamResp.headers.get("content-type") ?? "application/json";
|
|
219
|
+
if (extractErrorCode(errBuf) === "unknown_encryption_key_id") {
|
|
220
|
+
cache.invalidate();
|
|
221
|
+
}
|
|
222
|
+
const retryAfter = upstreamResp.headers.get("retry-after");
|
|
223
|
+
res.writeHead(upstreamResp.status, {
|
|
224
|
+
"Content-Type": ctype,
|
|
225
|
+
"Content-Length": String(errBuf.length),
|
|
226
|
+
...(retryAfter ? { "Retry-After": retryAfter } : {}),
|
|
227
|
+
});
|
|
228
|
+
res.end(errBuf);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (!stream) {
|
|
232
|
+
try {
|
|
233
|
+
const respJson = (await upstreamResp.json());
|
|
234
|
+
const decrypted = session.decryptResponse(respJson);
|
|
235
|
+
sendJson(res, 200, decrypted);
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
sendJson(res, 502, {
|
|
239
|
+
error: {
|
|
240
|
+
message: `Response decryption failed: ${error instanceof Error ? error.name : "Error"}`,
|
|
241
|
+
type: "e2ee_error",
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
await handleStreamingResponse(res, upstreamResp, endpoint, String(innerObj.model), session);
|
|
248
|
+
}
|
|
249
|
+
async function handleGetPassthrough(req, res, upstream, rawUrl, fetcher) {
|
|
250
|
+
const headers = forwardAuthHeaders(req.headers);
|
|
251
|
+
headers.Accept = headerString(req.headers.accept) ?? "application/json";
|
|
252
|
+
try {
|
|
253
|
+
const upstreamResp = await fetcher(`${upstream}${rawUrl}`, { method: "GET", headers });
|
|
254
|
+
const body = Buffer.from(await upstreamResp.arrayBuffer());
|
|
255
|
+
const ctype = upstreamResp.headers.get("content-type") ?? "application/json";
|
|
256
|
+
res.writeHead(upstreamResp.status, {
|
|
257
|
+
"Content-Type": ctype,
|
|
258
|
+
"Content-Length": String(body.length),
|
|
259
|
+
});
|
|
260
|
+
res.end(body);
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
sendJson(res, 502, {
|
|
264
|
+
error: {
|
|
265
|
+
message: `Upstream error: ${error instanceof Error ? error.name : "FetchError"}`,
|
|
266
|
+
type: "proxy_error",
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
async function handleStreamingResponse(res, upstreamResp, endpoint, requestModel, session) {
|
|
272
|
+
res.writeHead(200, {
|
|
273
|
+
"Content-Type": "text/event-stream; charset=utf-8",
|
|
274
|
+
"Cache-Control": "no-cache",
|
|
275
|
+
Connection: "keep-alive",
|
|
276
|
+
});
|
|
277
|
+
const dec = session.createStreamDecryptor();
|
|
278
|
+
let outerId = null;
|
|
279
|
+
let outerCreated = null;
|
|
280
|
+
let outerModel = requestModel;
|
|
281
|
+
let outerUsage = null;
|
|
282
|
+
let deferredResponsesCompleted = null;
|
|
283
|
+
const processEvent = (eventName, dataStr) => {
|
|
284
|
+
if (dataStr.trim() === "[DONE]")
|
|
285
|
+
return;
|
|
286
|
+
let data;
|
|
287
|
+
try {
|
|
288
|
+
data = JSON.parse(dataStr);
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (!data || typeof data !== "object" || Array.isArray(data))
|
|
294
|
+
return;
|
|
295
|
+
if (endpoint === "chat_completions") {
|
|
296
|
+
if (typeof data.id === "string")
|
|
297
|
+
outerId = data.id;
|
|
298
|
+
if (typeof data.created === "number")
|
|
299
|
+
outerCreated = data.created;
|
|
300
|
+
if (typeof data.model === "string")
|
|
301
|
+
outerModel = data.model;
|
|
302
|
+
if (data.usage && typeof data.usage === "object" && !Array.isArray(data.usage)) {
|
|
303
|
+
outerUsage = data.usage;
|
|
304
|
+
}
|
|
305
|
+
const choices = data.choices;
|
|
306
|
+
const delta = choices?.[0]?.delta;
|
|
307
|
+
if (delta && typeof delta.content === "string") {
|
|
308
|
+
for (const choiceDelta of dec.feedText(delta.content)) {
|
|
309
|
+
const chunkObj = {
|
|
310
|
+
id: outerId ?? "chatcmpl-e2ee",
|
|
311
|
+
object: "chat.completion.chunk",
|
|
312
|
+
created: outerCreated ?? Math.floor(Date.now() / 1000),
|
|
313
|
+
model: outerModel,
|
|
314
|
+
choices: [choiceDelta],
|
|
315
|
+
};
|
|
316
|
+
res.write(`data: ${JSON.stringify(chunkObj)}\n\n`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
else if (endpoint === "messages") {
|
|
321
|
+
const evType = eventName ?? (typeof data.type === "string" ? data.type : null);
|
|
322
|
+
if (evType === "message_start" && data.message && typeof data.message === "object") {
|
|
323
|
+
const msg = data.message;
|
|
324
|
+
if (typeof msg.model === "string")
|
|
325
|
+
outerModel = msg.model;
|
|
326
|
+
if (msg.usage && typeof msg.usage === "object") {
|
|
327
|
+
outerUsage = mergeUsage(outerUsage, msg.usage);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
else if (evType === "message_delta") {
|
|
331
|
+
if (data.usage && typeof data.usage === "object") {
|
|
332
|
+
outerUsage = mergeUsage(outerUsage, data.usage);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
else if (evType === "content_block_delta") {
|
|
336
|
+
const delta = data.delta;
|
|
337
|
+
if (delta?.type === "text_delta" && typeof delta.text === "string") {
|
|
338
|
+
for (const item of dec.feedText(delta.text)) {
|
|
339
|
+
emitNamedSse(res, item);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
else if (Array.isArray(data.choices) && data.choices.length > 0) {
|
|
344
|
+
if (typeof data.model === "string")
|
|
345
|
+
outerModel = data.model;
|
|
346
|
+
if (data.usage && typeof data.usage === "object") {
|
|
347
|
+
outerUsage = data.usage;
|
|
348
|
+
}
|
|
349
|
+
const delta = data.choices[0]?.delta;
|
|
350
|
+
if (delta && typeof delta.content === "string") {
|
|
351
|
+
for (const item of dec.feedText(delta.content)) {
|
|
352
|
+
emitNamedSse(res, item);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
else if (endpoint === "responses") {
|
|
358
|
+
const evType = eventName ?? (typeof data.type === "string" ? data.type : null);
|
|
359
|
+
if (evType === "response.output_text.delta" && typeof data.delta === "string") {
|
|
360
|
+
for (const item of dec.feedText(data.delta)) {
|
|
361
|
+
if (isResponsesCompleted(item)) {
|
|
362
|
+
deferredResponsesCompleted = item;
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
emitNamedSse(res, item);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
else if (evType === "response.created" ||
|
|
370
|
+
evType === "response.completed" ||
|
|
371
|
+
evType === "response.incomplete") {
|
|
372
|
+
const respObj = data.response;
|
|
373
|
+
if (respObj && typeof respObj === "object") {
|
|
374
|
+
if (typeof respObj.model === "string")
|
|
375
|
+
outerModel = respObj.model;
|
|
376
|
+
if (respObj.usage && typeof respObj.usage === "object") {
|
|
377
|
+
outerUsage = respObj.usage;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
else if (Array.isArray(data.choices) && data.choices.length > 0) {
|
|
382
|
+
if (typeof data.model === "string")
|
|
383
|
+
outerModel = data.model;
|
|
384
|
+
if (data.usage && typeof data.usage === "object") {
|
|
385
|
+
outerUsage = data.usage;
|
|
386
|
+
}
|
|
387
|
+
const delta = data.choices[0]?.delta;
|
|
388
|
+
if (delta && typeof delta.content === "string") {
|
|
389
|
+
for (const item of dec.feedText(delta.content)) {
|
|
390
|
+
if (isResponsesCompleted(item)) {
|
|
391
|
+
deferredResponsesCompleted = item;
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
emitNamedSse(res, item);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
try {
|
|
402
|
+
const reader = upstreamResp.body?.getReader();
|
|
403
|
+
if (!reader)
|
|
404
|
+
throw new Error("Missing upstream stream body");
|
|
405
|
+
const decoder = new TextDecoder();
|
|
406
|
+
let buffer = "";
|
|
407
|
+
let eventName = null;
|
|
408
|
+
let dataLines = [];
|
|
409
|
+
const flushLine = (line) => {
|
|
410
|
+
if (line === "") {
|
|
411
|
+
if (dataLines.length > 0) {
|
|
412
|
+
processEvent(eventName, dataLines.join("\n"));
|
|
413
|
+
dataLines = [];
|
|
414
|
+
}
|
|
415
|
+
eventName = null;
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (line.startsWith(":"))
|
|
419
|
+
return;
|
|
420
|
+
const colon = line.indexOf(":");
|
|
421
|
+
const field = colon === -1 ? line : line.slice(0, colon);
|
|
422
|
+
let value = colon === -1 ? "" : line.slice(colon + 1);
|
|
423
|
+
if (value.startsWith(" "))
|
|
424
|
+
value = value.slice(1);
|
|
425
|
+
if (field === "event")
|
|
426
|
+
eventName = value;
|
|
427
|
+
else if (field === "data")
|
|
428
|
+
dataLines.push(value);
|
|
429
|
+
};
|
|
430
|
+
while (true) {
|
|
431
|
+
const { value, done } = await reader.read();
|
|
432
|
+
if (done)
|
|
433
|
+
break;
|
|
434
|
+
buffer += decoder.decode(value, { stream: true });
|
|
435
|
+
let nl = buffer.indexOf("\n");
|
|
436
|
+
while (nl !== -1) {
|
|
437
|
+
const line = buffer.slice(0, nl).replace(/\r$/, "");
|
|
438
|
+
buffer = buffer.slice(nl + 1);
|
|
439
|
+
flushLine(line);
|
|
440
|
+
nl = buffer.indexOf("\n");
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
buffer += decoder.decode();
|
|
444
|
+
if (buffer.length > 0) {
|
|
445
|
+
flushLine(buffer.replace(/\r$/, ""));
|
|
446
|
+
}
|
|
447
|
+
flushLine("");
|
|
448
|
+
dec.finish();
|
|
449
|
+
if (endpoint === "chat_completions") {
|
|
450
|
+
if (outerUsage !== null) {
|
|
451
|
+
const usageChunk = {
|
|
452
|
+
id: outerId ?? "chatcmpl-e2ee",
|
|
453
|
+
object: "chat.completion.chunk",
|
|
454
|
+
created: outerCreated ?? Math.floor(Date.now() / 1000),
|
|
455
|
+
model: outerModel,
|
|
456
|
+
choices: [],
|
|
457
|
+
usage: outerUsage,
|
|
458
|
+
};
|
|
459
|
+
res.write(`data: ${JSON.stringify(usageChunk)}\n\n`);
|
|
460
|
+
}
|
|
461
|
+
res.write("data: [DONE]\n\n");
|
|
462
|
+
}
|
|
463
|
+
else if (endpoint === "responses") {
|
|
464
|
+
const completed = deferredResponsesCompleted;
|
|
465
|
+
if (completed) {
|
|
466
|
+
const compData = { ...completed.data };
|
|
467
|
+
if (compData.response && typeof compData.response === "object") {
|
|
468
|
+
const respCopy = { ...compData.response };
|
|
469
|
+
if (outerModel)
|
|
470
|
+
respCopy.model = outerModel;
|
|
471
|
+
if (outerUsage !== null && respCopy.usage == null)
|
|
472
|
+
respCopy.usage = outerUsage;
|
|
473
|
+
compData.response = respCopy;
|
|
474
|
+
}
|
|
475
|
+
emitNamedSse(res, { ...completed, data: compData });
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
res.end();
|
|
479
|
+
}
|
|
480
|
+
catch (error) {
|
|
481
|
+
const errName = error instanceof Error ? error.name : "Error";
|
|
482
|
+
const payload = endpoint === "chat_completions"
|
|
483
|
+
? `data: ${JSON.stringify({
|
|
484
|
+
error: {
|
|
485
|
+
message: `E2EE stream verification failed: ${errName}`,
|
|
486
|
+
type: "e2ee_error",
|
|
487
|
+
code: "stream_verification_failed",
|
|
488
|
+
},
|
|
489
|
+
})}\n\n`
|
|
490
|
+
: `event: error\ndata: ${JSON.stringify({
|
|
491
|
+
type: "error",
|
|
492
|
+
error: {
|
|
493
|
+
type: "e2ee_error",
|
|
494
|
+
message: `E2EE stream verification failed: ${errName}`,
|
|
495
|
+
},
|
|
496
|
+
})}\n\n`;
|
|
497
|
+
if (!res.writableEnded) {
|
|
498
|
+
res.write(payload);
|
|
499
|
+
res.end();
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function isResponsesCompleted(item) {
|
|
504
|
+
return Boolean(item &&
|
|
505
|
+
typeof item === "object" &&
|
|
506
|
+
!Array.isArray(item) &&
|
|
507
|
+
item.event === "response.completed");
|
|
508
|
+
}
|
|
509
|
+
function emitNamedSse(res, item) {
|
|
510
|
+
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
511
|
+
return;
|
|
512
|
+
const obj = item;
|
|
513
|
+
const dataJson = JSON.stringify(obj.data);
|
|
514
|
+
if (typeof obj.event === "string" && obj.event) {
|
|
515
|
+
res.write(`event: ${obj.event}\ndata: ${dataJson}\n\n`);
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
res.write(`data: ${dataJson}\n\n`);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
function forwardAuthHeaders(src) {
|
|
522
|
+
const out = {};
|
|
523
|
+
for (const name of ["authorization", "x-api-key", "anthropic-version", "anthropic-beta"]) {
|
|
524
|
+
const val = headerString(src[name]);
|
|
525
|
+
if (val)
|
|
526
|
+
out[name] = val;
|
|
527
|
+
}
|
|
528
|
+
return out;
|
|
529
|
+
}
|
|
530
|
+
function headerString(value) {
|
|
531
|
+
if (typeof value === "string")
|
|
532
|
+
return value;
|
|
533
|
+
if (Array.isArray(value))
|
|
534
|
+
return value[0];
|
|
535
|
+
return undefined;
|
|
536
|
+
}
|
|
537
|
+
function sendJson(res, status, payload) {
|
|
538
|
+
const body = Buffer.from(JSON.stringify(payload), "utf8");
|
|
539
|
+
res.writeHead(status, {
|
|
540
|
+
"Content-Type": "application/json",
|
|
541
|
+
"Content-Length": String(body.length),
|
|
542
|
+
});
|
|
543
|
+
res.end(body);
|
|
544
|
+
}
|
|
545
|
+
function extractErrorCode(buf) {
|
|
546
|
+
try {
|
|
547
|
+
const parsed = JSON.parse(buf.toString("utf8"));
|
|
548
|
+
return typeof parsed?.error?.code === "string" ? parsed.error.code : null;
|
|
549
|
+
}
|
|
550
|
+
catch {
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
function readBody(req, maxBytes) {
|
|
555
|
+
return new Promise((resolve, reject) => {
|
|
556
|
+
const chunks = [];
|
|
557
|
+
let total = 0;
|
|
558
|
+
let settled = false;
|
|
559
|
+
req.on("data", (chunk) => {
|
|
560
|
+
if (settled)
|
|
561
|
+
return;
|
|
562
|
+
total += chunk.length;
|
|
563
|
+
if (total > maxBytes) {
|
|
564
|
+
settled = true;
|
|
565
|
+
reject(new Error("Request body too large"));
|
|
566
|
+
req.destroy();
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
chunks.push(chunk);
|
|
570
|
+
});
|
|
571
|
+
req.on("end", () => {
|
|
572
|
+
if (settled)
|
|
573
|
+
return;
|
|
574
|
+
settled = true;
|
|
575
|
+
resolve(Buffer.concat(chunks, total));
|
|
576
|
+
});
|
|
577
|
+
req.on("error", (err) => {
|
|
578
|
+
if (settled)
|
|
579
|
+
return;
|
|
580
|
+
settled = true;
|
|
581
|
+
reject(err);
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
//# sourceMappingURL=e2ee-proxy.js.map
|
|
@@ -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