190proof 1.0.112 → 1.0.114
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 +4 -0
- package/dist/index.d.mts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +119 -152
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -151
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
2
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
3
|
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
5
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
6
|
});
|
|
8
7
|
|
|
@@ -138,8 +137,7 @@ async function withRetries(identifier, apiName, fn, options = {}) {
|
|
|
138
137
|
return await fn();
|
|
139
138
|
} catch (error3) {
|
|
140
139
|
lastError = error3;
|
|
141
|
-
if ((_a = options.signal) == null ? void 0 : _a.aborted)
|
|
142
|
-
throw error3;
|
|
140
|
+
if ((_a = options.signal) == null ? void 0 : _a.aborted) throw error3;
|
|
143
141
|
if (onError) {
|
|
144
142
|
onError(error3, attempt);
|
|
145
143
|
} else {
|
|
@@ -163,8 +161,7 @@ function parseStreamedResponse(identifier, paragraph, toolCallAccumulators, allo
|
|
|
163
161
|
const functionCalls = [];
|
|
164
162
|
for (let i = 0; i < toolCallAccumulators.length; i++) {
|
|
165
163
|
const acc = toolCallAccumulators[i];
|
|
166
|
-
if (!acc.name || !acc.arguments)
|
|
167
|
-
continue;
|
|
164
|
+
if (!acc.name || !acc.arguments) continue;
|
|
168
165
|
if (allowedFunctionNames && !allowedFunctionNames.has(acc.name)) {
|
|
169
166
|
throw new Error(
|
|
170
167
|
`Stream error: received function call with unknown name: ${acc.name}`
|
|
@@ -303,8 +300,7 @@ function buildOpenAIRequestConfig(identifier, model, config) {
|
|
|
303
300
|
};
|
|
304
301
|
}
|
|
305
302
|
function filterOpenAICompatReasoningDetails(details) {
|
|
306
|
-
if (!Array.isArray(details))
|
|
307
|
-
return details || void 0;
|
|
303
|
+
if (!Array.isArray(details)) return details || void 0;
|
|
308
304
|
const blocks = details.filter(
|
|
309
305
|
(block) => typeof (block == null ? void 0 : block.type) === "string" && block.type.startsWith("reasoning.")
|
|
310
306
|
);
|
|
@@ -375,13 +371,11 @@ async function prepareOpenAIPayload(identifier, payload) {
|
|
|
375
371
|
};
|
|
376
372
|
});
|
|
377
373
|
}
|
|
378
|
-
if (message.reasoning)
|
|
379
|
-
outMessage.reasoning = message.reasoning;
|
|
374
|
+
if (message.reasoning) outMessage.reasoning = message.reasoning;
|
|
380
375
|
const reasoningDetails = filterOpenAICompatReasoningDetails(
|
|
381
376
|
message.reasoningDetails
|
|
382
377
|
);
|
|
383
|
-
if (reasoningDetails)
|
|
384
|
-
outMessage.reasoning_details = reasoningDetails;
|
|
378
|
+
if (reasoningDetails) outMessage.reasoning_details = reasoningDetails;
|
|
385
379
|
preparedPayload.messages.push(outMessage);
|
|
386
380
|
}
|
|
387
381
|
return preparedPayload;
|
|
@@ -443,8 +437,7 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
|
|
|
443
437
|
}
|
|
444
438
|
const jsonStrings = chunk.split(/^data: /gm);
|
|
445
439
|
for (const jsonString of jsonStrings) {
|
|
446
|
-
if (!jsonString)
|
|
447
|
-
continue;
|
|
440
|
+
if (!jsonString) continue;
|
|
448
441
|
if (jsonString.includes("[DONE]")) {
|
|
449
442
|
clearTimeout(overallTimeout);
|
|
450
443
|
return parseStreamedResponse(
|
|
@@ -482,8 +475,7 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
|
|
|
482
475
|
while (toolCallAccumulators.length <= idx) {
|
|
483
476
|
toolCallAccumulators.push({ name: "", arguments: "" });
|
|
484
477
|
}
|
|
485
|
-
if (toolCall.id)
|
|
486
|
-
toolCallAccumulators[idx].id = toolCall.id;
|
|
478
|
+
if (toolCall.id) toolCallAccumulators[idx].id = toolCall.id;
|
|
487
479
|
if ((_e = toolCall.function) == null ? void 0 : _e.name)
|
|
488
480
|
toolCallAccumulators[idx].name += toolCall.function.name;
|
|
489
481
|
if ((_f = toolCall.function) == null ? void 0 : _f.arguments)
|
|
@@ -491,11 +483,9 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
|
|
|
491
483
|
}
|
|
492
484
|
}
|
|
493
485
|
const text = (_h = (_g = json.choices[0]) == null ? void 0 : _g.delta) == null ? void 0 : _h.content;
|
|
494
|
-
if (text)
|
|
495
|
-
paragraph += text;
|
|
486
|
+
if (text) paragraph += text;
|
|
496
487
|
const reasoningDelta = (_j = (_i = json.choices[0]) == null ? void 0 : _i.delta) == null ? void 0 : _j.reasoning;
|
|
497
|
-
if (reasoningDelta)
|
|
498
|
-
reasoning += reasoningDelta;
|
|
488
|
+
if (reasoningDelta) reasoning += reasoningDelta;
|
|
499
489
|
}
|
|
500
490
|
}
|
|
501
491
|
}
|
|
@@ -640,8 +630,7 @@ function jigAnthropicMessages(messages) {
|
|
|
640
630
|
];
|
|
641
631
|
}
|
|
642
632
|
jiggedMessages = jiggedMessages.reduce((acc, message) => {
|
|
643
|
-
if (acc.length === 0)
|
|
644
|
-
return [message];
|
|
633
|
+
if (acc.length === 0) return [message];
|
|
645
634
|
const lastMessage = acc[acc.length - 1];
|
|
646
635
|
if (lastMessage.role === message.role) {
|
|
647
636
|
const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [{ type: "text", text: lastMessage.content }];
|
|
@@ -895,8 +884,7 @@ function jigGoogleMessages(messages) {
|
|
|
895
884
|
];
|
|
896
885
|
}
|
|
897
886
|
jiggedMessages = jiggedMessages.reduce((acc, message) => {
|
|
898
|
-
if (acc.length === 0)
|
|
899
|
-
return [message];
|
|
887
|
+
if (acc.length === 0) return [message];
|
|
900
888
|
const lastMessage = acc[acc.length - 1];
|
|
901
889
|
if (lastMessage.role === message.role) {
|
|
902
890
|
lastMessage.parts = [...lastMessage.parts, ...message.parts];
|
|
@@ -914,6 +902,7 @@ async function prepareGoogleAIPayload(_identifier, payload) {
|
|
|
914
902
|
const preparedPayload = {
|
|
915
903
|
model: payload.model,
|
|
916
904
|
messages: [],
|
|
905
|
+
thinkingConfig: payload.thinkingConfig,
|
|
917
906
|
tools: payload.functions ? {
|
|
918
907
|
functionDeclarations: payload.functions.map((fn) => ({
|
|
919
908
|
name: fn.name,
|
|
@@ -934,8 +923,7 @@ async function prepareGoogleAIPayload(_identifier, payload) {
|
|
|
934
923
|
const toolNameById = /* @__PURE__ */ new Map();
|
|
935
924
|
for (const m of payload.messages) {
|
|
936
925
|
for (const fc of m.functionCalls || []) {
|
|
937
|
-
if (fc.id)
|
|
938
|
-
toolNameById.set(fc.id, fc.name);
|
|
926
|
+
if (fc.id) toolNameById.set(fc.id, fc.name);
|
|
939
927
|
}
|
|
940
928
|
}
|
|
941
929
|
for (const message of payload.messages) {
|
|
@@ -1010,10 +998,12 @@ async function callGoogleAI(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
|
1010
998
|
const contents = jigGoogleMessages(payload.messages);
|
|
1011
999
|
const requestBody = {
|
|
1012
1000
|
contents,
|
|
1013
|
-
generationConfig: {
|
|
1001
|
+
generationConfig: {
|
|
1002
|
+
responseModalities: ["TEXT"],
|
|
1003
|
+
...payload.thinkingConfig ? { thinkingConfig: payload.thinkingConfig } : {}
|
|
1004
|
+
}
|
|
1014
1005
|
};
|
|
1015
|
-
if (payload.tools)
|
|
1016
|
-
requestBody.tools = [payload.tools];
|
|
1006
|
+
if (payload.tools) requestBody.tools = [payload.tools];
|
|
1017
1007
|
if (payload.tools && payload.toolConfig) {
|
|
1018
1008
|
requestBody.toolConfig = payload.toolConfig;
|
|
1019
1009
|
}
|
|
@@ -1071,8 +1061,7 @@ async function callGoogleAI(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
|
1071
1061
|
});
|
|
1072
1062
|
continue;
|
|
1073
1063
|
}
|
|
1074
|
-
if (part.text)
|
|
1075
|
-
text += part.text;
|
|
1064
|
+
if (part.text) text += part.text;
|
|
1076
1065
|
if ((_m = part.inlineData) == null ? void 0 : _m.data) {
|
|
1077
1066
|
files.push({ mimeType: "image/png", data: part.inlineData.data });
|
|
1078
1067
|
}
|
|
@@ -1116,7 +1105,8 @@ async function callGoogleAI(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
|
1116
1105
|
prompt_tokens: (_o = response.usageMetadata.promptTokenCount) != null ? _o : 0,
|
|
1117
1106
|
completion_tokens: (_p = response.usageMetadata.candidatesTokenCount) != null ? _p : 0,
|
|
1118
1107
|
total_tokens: (_q = response.usageMetadata.totalTokenCount) != null ? _q : 0,
|
|
1119
|
-
cached_tokens: (_r = response.usageMetadata.cachedContentTokenCount) != null ? _r : 0
|
|
1108
|
+
cached_tokens: (_r = response.usageMetadata.cachedContentTokenCount) != null ? _r : 0,
|
|
1109
|
+
thoughts_tokens: response.usageMetadata.thoughtsTokenCount
|
|
1120
1110
|
} : null
|
|
1121
1111
|
};
|
|
1122
1112
|
}
|
|
@@ -1149,21 +1139,15 @@ async function callGoogleAIWithRetries(id, payload, retries = 5, requestTimeoutM
|
|
|
1149
1139
|
finishReason: error2.finishReason,
|
|
1150
1140
|
modelVersion: error2.modelVersion
|
|
1151
1141
|
};
|
|
1152
|
-
if (error2.safetyRatings)
|
|
1153
|
-
|
|
1154
|
-
if (error2.usageMetadata)
|
|
1155
|
-
errorDetails.usageMetadata = error2.usageMetadata;
|
|
1142
|
+
if (error2.safetyRatings) errorDetails.safetyRatings = error2.safetyRatings;
|
|
1143
|
+
if (error2.usageMetadata) errorDetails.usageMetadata = error2.usageMetadata;
|
|
1156
1144
|
if (error2.promptFeedback)
|
|
1157
1145
|
errorDetails.promptFeedback = error2.promptFeedback;
|
|
1158
|
-
if (error2.status)
|
|
1159
|
-
|
|
1160
|
-
if (error2.
|
|
1161
|
-
errorDetails.errorCode = error2.code;
|
|
1162
|
-
if (error2.details)
|
|
1163
|
-
errorDetails.errorDetails = error2.details;
|
|
1146
|
+
if (error2.status) errorDetails.httpStatus = error2.status;
|
|
1147
|
+
if (error2.code) errorDetails.errorCode = error2.code;
|
|
1148
|
+
if (error2.details) errorDetails.errorDetails = error2.details;
|
|
1164
1149
|
const fileUris = payload.messages.flatMap((m) => m.parts).filter((p) => "fileData" in p).map((p) => p.fileData.fileUri);
|
|
1165
|
-
if (fileUris.length)
|
|
1166
|
-
errorDetails.fileUris = fileUris;
|
|
1150
|
+
if (fileUris.length) errorDetails.fileUris = fileUris;
|
|
1167
1151
|
logger_default.error(
|
|
1168
1152
|
id,
|
|
1169
1153
|
`Retry #${attempt} error: ${error2.message}`,
|
|
@@ -1227,9 +1211,13 @@ function prepareOpenAICompatMessages(messages) {
|
|
|
1227
1211
|
}
|
|
1228
1212
|
continue;
|
|
1229
1213
|
}
|
|
1214
|
+
const fileRefs = (message.files || []).filter((file) => file.url).map(
|
|
1215
|
+
(file) => ALLOWED_IMAGE_MIME_TYPES.includes(file.mimeType) ? `Image (${file.url})` : `File (${file.url})`
|
|
1216
|
+
);
|
|
1217
|
+
const content = [normalizeMessageContent(message.content), ...fileRefs].filter(Boolean).join("\n");
|
|
1230
1218
|
const outMessage = {
|
|
1231
1219
|
role: message.role,
|
|
1232
|
-
content
|
|
1220
|
+
content
|
|
1233
1221
|
};
|
|
1234
1222
|
if ((_a = message.functionCalls) == null ? void 0 : _a.length) {
|
|
1235
1223
|
outMessage.tool_calls = message.functionCalls.map((fc, i) => {
|
|
@@ -1243,16 +1231,13 @@ function prepareOpenAICompatMessages(messages) {
|
|
|
1243
1231
|
}
|
|
1244
1232
|
};
|
|
1245
1233
|
});
|
|
1246
|
-
if (!
|
|
1247
|
-
outMessage.content = null;
|
|
1234
|
+
if (!content) outMessage.content = null;
|
|
1248
1235
|
}
|
|
1249
|
-
if (message.reasoning)
|
|
1250
|
-
outMessage.reasoning = message.reasoning;
|
|
1236
|
+
if (message.reasoning) outMessage.reasoning = message.reasoning;
|
|
1251
1237
|
const reasoningDetails = filterOpenAICompatReasoningDetails(
|
|
1252
1238
|
message.reasoningDetails
|
|
1253
1239
|
);
|
|
1254
|
-
if (reasoningDetails)
|
|
1255
|
-
outMessage.reasoning_details = reasoningDetails;
|
|
1240
|
+
if (reasoningDetails) outMessage.reasoning_details = reasoningDetails;
|
|
1256
1241
|
out.push(outMessage);
|
|
1257
1242
|
}
|
|
1258
1243
|
return out;
|
|
@@ -1395,8 +1380,7 @@ function parseDsmlToolCalls(content) {
|
|
|
1395
1380
|
let last = -1;
|
|
1396
1381
|
let tag;
|
|
1397
1382
|
while ((tag = DSML_ANY_TAG_RE.exec(content)) !== null) {
|
|
1398
|
-
if (first === -1)
|
|
1399
|
-
first = tag.index;
|
|
1383
|
+
if (first === -1) first = tag.index;
|
|
1400
1384
|
last = tag.index + tag[0].length;
|
|
1401
1385
|
}
|
|
1402
1386
|
const remaining = first === -1 ? content : (content.slice(0, first) + content.slice(last)).trim();
|
|
@@ -1412,8 +1396,7 @@ function finalizeOpenRouterMessage(id, raw) {
|
|
|
1412
1396
|
const functionCalls = [];
|
|
1413
1397
|
for (let i = 0; i < raw.toolCalls.length; i++) {
|
|
1414
1398
|
const tc = raw.toolCalls[i];
|
|
1415
|
-
if (!tc.name)
|
|
1416
|
-
continue;
|
|
1399
|
+
if (!tc.name) continue;
|
|
1417
1400
|
functionCalls.push({
|
|
1418
1401
|
id: (_a = tc.id) != null ? _a : `call_${i}`,
|
|
1419
1402
|
name: tc.name,
|
|
@@ -1466,8 +1449,7 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
|
|
|
1466
1449
|
controller.abort();
|
|
1467
1450
|
};
|
|
1468
1451
|
const unref = (t) => {
|
|
1469
|
-
if (typeof t === "object" && "unref" in t)
|
|
1470
|
-
t.unref();
|
|
1452
|
+
if (typeof t === "object" && "unref" in t) t.unref();
|
|
1471
1453
|
return t;
|
|
1472
1454
|
};
|
|
1473
1455
|
const totalTimer = unref(
|
|
@@ -1535,98 +1517,88 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
|
|
|
1535
1517
|
const reader = response.body.getReader();
|
|
1536
1518
|
const decoder = new TextDecoder();
|
|
1537
1519
|
let lineBuffer = "";
|
|
1538
|
-
outer:
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
let newlineIdx;
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1520
|
+
outer: while (true) {
|
|
1521
|
+
const { done, value } = await reader.read();
|
|
1522
|
+
if (done) break;
|
|
1523
|
+
lineBuffer += decoder.decode(value, { stream: true });
|
|
1524
|
+
let newlineIdx;
|
|
1525
|
+
while ((newlineIdx = lineBuffer.indexOf("\n")) !== -1) {
|
|
1526
|
+
let line = lineBuffer.slice(0, newlineIdx);
|
|
1527
|
+
lineBuffer = lineBuffer.slice(newlineIdx + 1);
|
|
1528
|
+
if (line.endsWith("\r")) line = line.slice(0, -1);
|
|
1529
|
+
if (!line) continue;
|
|
1530
|
+
if (line.startsWith(":")) continue;
|
|
1531
|
+
if (!line.startsWith("data:")) continue;
|
|
1532
|
+
const dataStr = line.slice(5).trimStart();
|
|
1533
|
+
if (dataStr === "[DONE]") {
|
|
1534
|
+
sawDone = true;
|
|
1535
|
+
break outer;
|
|
1536
|
+
}
|
|
1537
|
+
let json;
|
|
1538
|
+
try {
|
|
1539
|
+
json = JSON.parse(dataStr);
|
|
1540
|
+
} catch (e) {
|
|
1541
|
+
logger_default.error(
|
|
1542
|
+
id,
|
|
1543
|
+
"OpenRouter stream: unparseable data line:",
|
|
1544
|
+
dataStr.slice(0, 200)
|
|
1545
|
+
);
|
|
1546
|
+
continue;
|
|
1547
|
+
}
|
|
1548
|
+
dataChunks++;
|
|
1549
|
+
if (json.error) {
|
|
1550
|
+
logger_default.error(id, "OpenRouter stream error event:", json.error);
|
|
1551
|
+
const error2 = new Error(
|
|
1552
|
+
`OpenRouter error: ${json.error.message}`
|
|
1553
|
+
);
|
|
1554
|
+
error2.data = json.error;
|
|
1555
|
+
throw error2;
|
|
1556
|
+
}
|
|
1557
|
+
if (json.provider) provider = json.provider;
|
|
1558
|
+
let useful = false;
|
|
1559
|
+
if (json.usage) {
|
|
1560
|
+
usage = json.usage;
|
|
1561
|
+
useful = true;
|
|
1562
|
+
}
|
|
1563
|
+
const choice = (_c = json.choices) == null ? void 0 : _c[0];
|
|
1564
|
+
if (choice) {
|
|
1565
|
+
const delta = (_d = choice.delta) != null ? _d : {};
|
|
1566
|
+
if (delta.content) {
|
|
1567
|
+
paragraph += delta.content;
|
|
1568
|
+
useful = true;
|
|
1571
1569
|
}
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
const error2 = new Error(
|
|
1576
|
-
`OpenRouter error: ${json.error.message}`
|
|
1577
|
-
);
|
|
1578
|
-
error2.data = json.error;
|
|
1579
|
-
throw error2;
|
|
1570
|
+
if (delta.reasoning) {
|
|
1571
|
+
reasoning += delta.reasoning;
|
|
1572
|
+
useful = true;
|
|
1580
1573
|
}
|
|
1581
|
-
if (
|
|
1582
|
-
|
|
1583
|
-
let useful = false;
|
|
1584
|
-
if (json.usage) {
|
|
1585
|
-
usage = json.usage;
|
|
1574
|
+
if (Array.isArray(delta.reasoning_details) && delta.reasoning_details.length) {
|
|
1575
|
+
reasoningDetails.push(...delta.reasoning_details);
|
|
1586
1576
|
useful = true;
|
|
1587
1577
|
}
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
useful = true;
|
|
1594
|
-
}
|
|
1595
|
-
if (delta.reasoning) {
|
|
1596
|
-
reasoning += delta.reasoning;
|
|
1597
|
-
useful = true;
|
|
1598
|
-
}
|
|
1599
|
-
if (Array.isArray(delta.reasoning_details) && delta.reasoning_details.length) {
|
|
1600
|
-
reasoningDetails.push(...delta.reasoning_details);
|
|
1601
|
-
useful = true;
|
|
1602
|
-
}
|
|
1603
|
-
if (Array.isArray(delta.tool_calls)) {
|
|
1604
|
-
for (const toolCall of delta.tool_calls) {
|
|
1605
|
-
const idx = (_e = toolCall.index) != null ? _e : 0;
|
|
1606
|
-
while (toolCalls.length <= idx) {
|
|
1607
|
-
toolCalls.push({ name: "", argumentsJson: "" });
|
|
1608
|
-
}
|
|
1609
|
-
if (toolCall.id)
|
|
1610
|
-
toolCalls[idx].id = toolCall.id;
|
|
1611
|
-
if ((_f = toolCall.function) == null ? void 0 : _f.name)
|
|
1612
|
-
toolCalls[idx].name += toolCall.function.name;
|
|
1613
|
-
if ((_g = toolCall.function) == null ? void 0 : _g.arguments)
|
|
1614
|
-
toolCalls[idx].argumentsJson += toolCall.function.arguments;
|
|
1615
|
-
useful = true;
|
|
1578
|
+
if (Array.isArray(delta.tool_calls)) {
|
|
1579
|
+
for (const toolCall of delta.tool_calls) {
|
|
1580
|
+
const idx = (_e = toolCall.index) != null ? _e : 0;
|
|
1581
|
+
while (toolCalls.length <= idx) {
|
|
1582
|
+
toolCalls.push({ name: "", argumentsJson: "" });
|
|
1616
1583
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1584
|
+
if (toolCall.id) toolCalls[idx].id = toolCall.id;
|
|
1585
|
+
if ((_f = toolCall.function) == null ? void 0 : _f.name)
|
|
1586
|
+
toolCalls[idx].name += toolCall.function.name;
|
|
1587
|
+
if ((_g = toolCall.function) == null ? void 0 : _g.arguments)
|
|
1588
|
+
toolCalls[idx].argumentsJson += toolCall.function.arguments;
|
|
1620
1589
|
useful = true;
|
|
1621
1590
|
}
|
|
1622
1591
|
}
|
|
1623
|
-
if (
|
|
1624
|
-
|
|
1592
|
+
if (choice.finish_reason) {
|
|
1593
|
+
finishReason = choice.finish_reason;
|
|
1594
|
+
useful = true;
|
|
1595
|
+
}
|
|
1625
1596
|
}
|
|
1597
|
+
if (useful) armStallTimer();
|
|
1626
1598
|
}
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1599
|
+
}
|
|
1600
|
+
if (sawDone) reader.cancel().catch(() => {
|
|
1601
|
+
});
|
|
1630
1602
|
if (!sawDone && !finishReason) {
|
|
1631
1603
|
logger_default.error(
|
|
1632
1604
|
id,
|
|
@@ -1733,15 +1705,12 @@ var MODERATION_RE = /moderat|inappropriate content|content polic|content managem
|
|
|
1733
1705
|
function moderationEvictionSlug(error2, payload) {
|
|
1734
1706
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1735
1707
|
const body = (_c = error2 == null ? void 0 : error2.data) != null ? _c : (_b = (_a = error2 == null ? void 0 : error2.response) == null ? void 0 : _a.data) == null ? void 0 : _b.error;
|
|
1736
|
-
if (!body)
|
|
1737
|
-
return null;
|
|
1708
|
+
if (!body) return null;
|
|
1738
1709
|
const message = String((_d = body.message) != null ? _d : "");
|
|
1739
1710
|
const isModeration = body.code === 403 || Array.isArray((_e = body.metadata) == null ? void 0 : _e.reasons) || MODERATION_RE.test(message);
|
|
1740
|
-
if (!isModeration)
|
|
1741
|
-
return null;
|
|
1711
|
+
if (!isModeration) return null;
|
|
1742
1712
|
const display = (_h = (_f = body.metadata) == null ? void 0 : _f.provider_name) != null ? _h : (_g = /Upstream error from ([^:]+):/.exec(message)) == null ? void 0 : _g[1];
|
|
1743
|
-
if (!display)
|
|
1744
|
-
return null;
|
|
1713
|
+
if (!display) return null;
|
|
1745
1714
|
const key = normalizeProviderKey(display);
|
|
1746
1715
|
const fromOrder = (_j = (_i = payload.provider) == null ? void 0 : _i.order) == null ? void 0 : _j.find(
|
|
1747
1716
|
(entry) => normalizeProviderKey(entry) === key
|
|
@@ -1751,11 +1720,9 @@ function moderationEvictionSlug(error2, payload) {
|
|
|
1751
1720
|
var MIN_STREAM_ATTEMPT_MS = 1e4;
|
|
1752
1721
|
var estimateTokens = (text) => Math.round(text.length / 4);
|
|
1753
1722
|
function streamAttemptBudgetMs(options) {
|
|
1754
|
-
if (options.streamDeadlineAt === void 0)
|
|
1755
|
-
return options.streamTimeoutMs;
|
|
1723
|
+
if (options.streamDeadlineAt === void 0) return options.streamTimeoutMs;
|
|
1756
1724
|
const remaining = options.streamDeadlineAt - Date.now();
|
|
1757
|
-
if (remaining < MIN_STREAM_ATTEMPT_MS)
|
|
1758
|
-
return null;
|
|
1725
|
+
if (remaining < MIN_STREAM_ATTEMPT_MS) return null;
|
|
1759
1726
|
return Math.min(options.streamTimeoutMs, remaining);
|
|
1760
1727
|
}
|
|
1761
1728
|
async function callOpenRouterWithRetries(id, payload, retries = 5, options, signal) {
|
|
@@ -1911,8 +1878,7 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
1911
1878
|
(_e = result.provider) != null ? _e : result.provider = provider;
|
|
1912
1879
|
return result;
|
|
1913
1880
|
} catch (error2) {
|
|
1914
|
-
if ((_f = aiPayload.signal) == null ? void 0 : _f.aborted)
|
|
1915
|
-
throw error2;
|
|
1881
|
+
if ((_f = aiPayload.signal) == null ? void 0 : _f.aborted) throw error2;
|
|
1916
1882
|
if (aiPayload.fallbackModel) {
|
|
1917
1883
|
logger_default.error(
|
|
1918
1884
|
id,
|