190proof 1.0.104 → 1.0.106
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 +5 -1
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +64 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -61
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -4
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
|
|
|
@@ -125,8 +124,7 @@ async function withRetries(identifier, apiName, fn, options = {}) {
|
|
|
125
124
|
return await fn();
|
|
126
125
|
} catch (error3) {
|
|
127
126
|
lastError = error3;
|
|
128
|
-
if ((_a = options.signal) == null ? void 0 : _a.aborted)
|
|
129
|
-
throw error3;
|
|
127
|
+
if ((_a = options.signal) == null ? void 0 : _a.aborted) throw error3;
|
|
130
128
|
if (onError) {
|
|
131
129
|
onError(error3, attempt);
|
|
132
130
|
} else {
|
|
@@ -150,8 +148,7 @@ function parseStreamedResponse(identifier, paragraph, toolCallAccumulators, allo
|
|
|
150
148
|
const functionCalls = [];
|
|
151
149
|
for (let i = 0; i < toolCallAccumulators.length; i++) {
|
|
152
150
|
const acc = toolCallAccumulators[i];
|
|
153
|
-
if (!acc.name || !acc.arguments)
|
|
154
|
-
continue;
|
|
151
|
+
if (!acc.name || !acc.arguments) continue;
|
|
155
152
|
if (allowedFunctionNames && !allowedFunctionNames.has(acc.name)) {
|
|
156
153
|
throw new Error(
|
|
157
154
|
`Stream error: received function call with unknown name: ${acc.name}`
|
|
@@ -290,8 +287,7 @@ function buildOpenAIRequestConfig(identifier, model, config) {
|
|
|
290
287
|
};
|
|
291
288
|
}
|
|
292
289
|
function filterOpenAICompatReasoningDetails(details) {
|
|
293
|
-
if (!Array.isArray(details))
|
|
294
|
-
return details || void 0;
|
|
290
|
+
if (!Array.isArray(details)) return details || void 0;
|
|
295
291
|
const blocks = details.filter(
|
|
296
292
|
(block) => typeof (block == null ? void 0 : block.type) === "string" && block.type.startsWith("reasoning.")
|
|
297
293
|
);
|
|
@@ -362,13 +358,11 @@ async function prepareOpenAIPayload(identifier, payload) {
|
|
|
362
358
|
};
|
|
363
359
|
});
|
|
364
360
|
}
|
|
365
|
-
if (message.reasoning)
|
|
366
|
-
outMessage.reasoning = message.reasoning;
|
|
361
|
+
if (message.reasoning) outMessage.reasoning = message.reasoning;
|
|
367
362
|
const reasoningDetails = filterOpenAICompatReasoningDetails(
|
|
368
363
|
message.reasoningDetails
|
|
369
364
|
);
|
|
370
|
-
if (reasoningDetails)
|
|
371
|
-
outMessage.reasoning_details = reasoningDetails;
|
|
365
|
+
if (reasoningDetails) outMessage.reasoning_details = reasoningDetails;
|
|
372
366
|
preparedPayload.messages.push(outMessage);
|
|
373
367
|
}
|
|
374
368
|
return preparedPayload;
|
|
@@ -430,8 +424,7 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
|
|
|
430
424
|
}
|
|
431
425
|
const jsonStrings = chunk.split(/^data: /gm);
|
|
432
426
|
for (const jsonString of jsonStrings) {
|
|
433
|
-
if (!jsonString)
|
|
434
|
-
continue;
|
|
427
|
+
if (!jsonString) continue;
|
|
435
428
|
if (jsonString.includes("[DONE]")) {
|
|
436
429
|
clearTimeout(overallTimeout);
|
|
437
430
|
return parseStreamedResponse(
|
|
@@ -469,8 +462,7 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
|
|
|
469
462
|
while (toolCallAccumulators.length <= idx) {
|
|
470
463
|
toolCallAccumulators.push({ name: "", arguments: "" });
|
|
471
464
|
}
|
|
472
|
-
if (toolCall.id)
|
|
473
|
-
toolCallAccumulators[idx].id = toolCall.id;
|
|
465
|
+
if (toolCall.id) toolCallAccumulators[idx].id = toolCall.id;
|
|
474
466
|
if ((_e = toolCall.function) == null ? void 0 : _e.name)
|
|
475
467
|
toolCallAccumulators[idx].name += toolCall.function.name;
|
|
476
468
|
if ((_f = toolCall.function) == null ? void 0 : _f.arguments)
|
|
@@ -478,11 +470,9 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
|
|
|
478
470
|
}
|
|
479
471
|
}
|
|
480
472
|
const text = (_h = (_g = json.choices[0]) == null ? void 0 : _g.delta) == null ? void 0 : _h.content;
|
|
481
|
-
if (text)
|
|
482
|
-
paragraph += text;
|
|
473
|
+
if (text) paragraph += text;
|
|
483
474
|
const reasoningDelta = (_j = (_i = json.choices[0]) == null ? void 0 : _i.delta) == null ? void 0 : _j.reasoning;
|
|
484
|
-
if (reasoningDelta)
|
|
485
|
-
reasoning += reasoningDelta;
|
|
475
|
+
if (reasoningDelta) reasoning += reasoningDelta;
|
|
486
476
|
}
|
|
487
477
|
}
|
|
488
478
|
}
|
|
@@ -627,8 +617,7 @@ function jigAnthropicMessages(messages) {
|
|
|
627
617
|
];
|
|
628
618
|
}
|
|
629
619
|
jiggedMessages = jiggedMessages.reduce((acc, message) => {
|
|
630
|
-
if (acc.length === 0)
|
|
631
|
-
return [message];
|
|
620
|
+
if (acc.length === 0) return [message];
|
|
632
621
|
const lastMessage = acc[acc.length - 1];
|
|
633
622
|
if (lastMessage.role === message.role) {
|
|
634
623
|
const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [{ type: "text", text: lastMessage.content }];
|
|
@@ -653,7 +642,11 @@ async function prepareAnthropicPayload(_identifier, payload) {
|
|
|
653
642
|
model: payload.model,
|
|
654
643
|
messages: [],
|
|
655
644
|
functions: payload.functions,
|
|
656
|
-
temperature: payload.temperature
|
|
645
|
+
temperature: payload.temperature,
|
|
646
|
+
// Map the generic function_call to Anthropic tool_choice ("none" forces a
|
|
647
|
+
// text-only turn). Only meaningful alongside tools — callAnthropic sends
|
|
648
|
+
// it only when tools are present (tool_choice without tools 400s).
|
|
649
|
+
tool_choice: payload.function_call ? typeof payload.function_call === "string" ? { type: payload.function_call } : { type: "tool", name: payload.function_call.name } : void 0
|
|
657
650
|
};
|
|
658
651
|
for (const message of payload.messages) {
|
|
659
652
|
if (message.role === "system") {
|
|
@@ -767,6 +760,8 @@ async function callAnthropic(id, payload, config, requestTimeoutMs = 12e4, signa
|
|
|
767
760
|
model: payload.model,
|
|
768
761
|
messages: anthropicMessages,
|
|
769
762
|
tools: cachedTools,
|
|
763
|
+
// tool_choice requires tools in the request; drop it otherwise.
|
|
764
|
+
tool_choice: (cachedTools == null ? void 0 : cachedTools.length) ? payload.tool_choice : void 0,
|
|
770
765
|
temperature: payload.temperature,
|
|
771
766
|
system: payload.system,
|
|
772
767
|
max_tokens: 4096
|
|
@@ -871,8 +866,7 @@ function jigGoogleMessages(messages) {
|
|
|
871
866
|
];
|
|
872
867
|
}
|
|
873
868
|
jiggedMessages = jiggedMessages.reduce((acc, message) => {
|
|
874
|
-
if (acc.length === 0)
|
|
875
|
-
return [message];
|
|
869
|
+
if (acc.length === 0) return [message];
|
|
876
870
|
const lastMessage = acc[acc.length - 1];
|
|
877
871
|
if (lastMessage.role === message.role) {
|
|
878
872
|
lastMessage.parts = [...lastMessage.parts, ...message.parts];
|
|
@@ -898,13 +892,19 @@ async function prepareGoogleAIPayload(_identifier, payload) {
|
|
|
898
892
|
...fn.parameters
|
|
899
893
|
}
|
|
900
894
|
}))
|
|
895
|
+
} : void 0,
|
|
896
|
+
// Map the generic function_call to Gemini's functionCallingConfig ("none"
|
|
897
|
+
// → mode NONE forces a text-only turn). Only meaningful alongside tools.
|
|
898
|
+
toolConfig: payload.functions && payload.function_call ? {
|
|
899
|
+
functionCallingConfig: {
|
|
900
|
+
mode: typeof payload.function_call === "string" ? payload.function_call === "none" ? "NONE" : "AUTO" : "ANY"
|
|
901
|
+
}
|
|
901
902
|
} : void 0
|
|
902
903
|
};
|
|
903
904
|
const toolNameById = /* @__PURE__ */ new Map();
|
|
904
905
|
for (const m of payload.messages) {
|
|
905
906
|
for (const fc of m.functionCalls || []) {
|
|
906
|
-
if (fc.id)
|
|
907
|
-
toolNameById.set(fc.id, fc.name);
|
|
907
|
+
if (fc.id) toolNameById.set(fc.id, fc.name);
|
|
908
908
|
}
|
|
909
909
|
}
|
|
910
910
|
for (const message of payload.messages) {
|
|
@@ -981,8 +981,10 @@ async function callGoogleAI(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
|
981
981
|
contents,
|
|
982
982
|
generationConfig: { responseModalities: ["TEXT"] }
|
|
983
983
|
};
|
|
984
|
-
if (payload.tools)
|
|
985
|
-
|
|
984
|
+
if (payload.tools) requestBody.tools = [payload.tools];
|
|
985
|
+
if (payload.tools && payload.toolConfig) {
|
|
986
|
+
requestBody.toolConfig = payload.toolConfig;
|
|
987
|
+
}
|
|
986
988
|
if (payload.systemInstruction) {
|
|
987
989
|
requestBody.systemInstruction = {
|
|
988
990
|
parts: [{ text: payload.systemInstruction }]
|
|
@@ -1032,8 +1034,7 @@ async function callGoogleAI(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
|
1032
1034
|
});
|
|
1033
1035
|
continue;
|
|
1034
1036
|
}
|
|
1035
|
-
if (part.text)
|
|
1036
|
-
text += part.text;
|
|
1037
|
+
if (part.text) text += part.text;
|
|
1037
1038
|
if ((_m = part.inlineData) == null ? void 0 : _m.data) {
|
|
1038
1039
|
files.push({ mimeType: "image/png", data: part.inlineData.data });
|
|
1039
1040
|
}
|
|
@@ -1110,21 +1111,15 @@ async function callGoogleAIWithRetries(id, payload, retries = 5, requestTimeoutM
|
|
|
1110
1111
|
finishReason: error2.finishReason,
|
|
1111
1112
|
modelVersion: error2.modelVersion
|
|
1112
1113
|
};
|
|
1113
|
-
if (error2.safetyRatings)
|
|
1114
|
-
|
|
1115
|
-
if (error2.usageMetadata)
|
|
1116
|
-
errorDetails.usageMetadata = error2.usageMetadata;
|
|
1114
|
+
if (error2.safetyRatings) errorDetails.safetyRatings = error2.safetyRatings;
|
|
1115
|
+
if (error2.usageMetadata) errorDetails.usageMetadata = error2.usageMetadata;
|
|
1117
1116
|
if (error2.promptFeedback)
|
|
1118
1117
|
errorDetails.promptFeedback = error2.promptFeedback;
|
|
1119
|
-
if (error2.status)
|
|
1120
|
-
|
|
1121
|
-
if (error2.
|
|
1122
|
-
errorDetails.errorCode = error2.code;
|
|
1123
|
-
if (error2.details)
|
|
1124
|
-
errorDetails.errorDetails = error2.details;
|
|
1118
|
+
if (error2.status) errorDetails.httpStatus = error2.status;
|
|
1119
|
+
if (error2.code) errorDetails.errorCode = error2.code;
|
|
1120
|
+
if (error2.details) errorDetails.errorDetails = error2.details;
|
|
1125
1121
|
const fileUris = payload.messages.flatMap((m) => m.parts).filter((p) => "fileData" in p).map((p) => p.fileData.fileUri);
|
|
1126
|
-
if (fileUris.length)
|
|
1127
|
-
errorDetails.fileUris = fileUris;
|
|
1122
|
+
if (fileUris.length) errorDetails.fileUris = fileUris;
|
|
1128
1123
|
logger_default.error(
|
|
1129
1124
|
id,
|
|
1130
1125
|
`Retry #${attempt} error: ${error2.message}`,
|
|
@@ -1204,16 +1199,13 @@ function prepareOpenAICompatMessages(messages) {
|
|
|
1204
1199
|
}
|
|
1205
1200
|
};
|
|
1206
1201
|
});
|
|
1207
|
-
if (!message.content)
|
|
1208
|
-
outMessage.content = null;
|
|
1202
|
+
if (!message.content) outMessage.content = null;
|
|
1209
1203
|
}
|
|
1210
|
-
if (message.reasoning)
|
|
1211
|
-
outMessage.reasoning = message.reasoning;
|
|
1204
|
+
if (message.reasoning) outMessage.reasoning = message.reasoning;
|
|
1212
1205
|
const reasoningDetails = filterOpenAICompatReasoningDetails(
|
|
1213
1206
|
message.reasoningDetails
|
|
1214
1207
|
);
|
|
1215
|
-
if (reasoningDetails)
|
|
1216
|
-
outMessage.reasoning_details = reasoningDetails;
|
|
1208
|
+
if (reasoningDetails) outMessage.reasoning_details = reasoningDetails;
|
|
1217
1209
|
out.push(outMessage);
|
|
1218
1210
|
}
|
|
1219
1211
|
return out;
|
|
@@ -1351,15 +1343,14 @@ function parseDsmlToolCalls(content) {
|
|
|
1351
1343
|
let last = -1;
|
|
1352
1344
|
let tag;
|
|
1353
1345
|
while ((tag = DSML_ANY_TAG_RE.exec(content)) !== null) {
|
|
1354
|
-
if (first === -1)
|
|
1355
|
-
first = tag.index;
|
|
1346
|
+
if (first === -1) first = tag.index;
|
|
1356
1347
|
last = tag.index + tag[0].length;
|
|
1357
1348
|
}
|
|
1358
1349
|
const remaining = first === -1 ? content : (content.slice(0, first) + content.slice(last)).trim();
|
|
1359
1350
|
return { calls, remainingContent: remaining.length ? remaining : null };
|
|
1360
1351
|
}
|
|
1361
1352
|
async function callOpenRouter(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
1362
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1353
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1363
1354
|
const response = await axios.post(
|
|
1364
1355
|
"https://openrouter.ai/api/v1/chat/completions",
|
|
1365
1356
|
payload,
|
|
@@ -1419,11 +1410,14 @@ async function callOpenRouter(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
|
1419
1410
|
files: [],
|
|
1420
1411
|
reasoning: (_f = answer.reasoning) != null ? _f : void 0,
|
|
1421
1412
|
reasoningDetails: (_g = answer.reasoning_details) != null ? _g : void 0,
|
|
1413
|
+
// The upstream provider OpenRouter routed to (e.g. "Baidu") — finer-grained
|
|
1414
|
+
// than the "openrouter" stamp callWithRetries would apply.
|
|
1415
|
+
provider: (_h = response.data.provider) != null ? _h : void 0,
|
|
1422
1416
|
usage: response.data.usage ? {
|
|
1423
1417
|
prompt_tokens: response.data.usage.prompt_tokens,
|
|
1424
1418
|
completion_tokens: response.data.usage.completion_tokens,
|
|
1425
1419
|
total_tokens: response.data.usage.total_tokens,
|
|
1426
|
-
cached_tokens: (
|
|
1420
|
+
cached_tokens: (_j = (_i = response.data.usage.prompt_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : 0
|
|
1427
1421
|
} : null
|
|
1428
1422
|
};
|
|
1429
1423
|
}
|
|
@@ -1473,15 +1467,16 @@ function parseModelString(model) {
|
|
|
1473
1467
|
);
|
|
1474
1468
|
}
|
|
1475
1469
|
async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeoutMs = 15e3) {
|
|
1476
|
-
var _a, _b;
|
|
1470
|
+
var _a, _b, _c;
|
|
1477
1471
|
try {
|
|
1478
1472
|
const { provider, modelId } = parseModelString(aiPayload.model);
|
|
1479
1473
|
const routingPayload = { ...aiPayload, model: modelId };
|
|
1480
1474
|
const requestTimeoutMs = (_a = aiPayload.requestTimeoutMs) != null ? _a : 12e4;
|
|
1481
1475
|
const signal = aiPayload.signal;
|
|
1476
|
+
let result;
|
|
1482
1477
|
switch (provider) {
|
|
1483
1478
|
case "anthropic":
|
|
1484
|
-
|
|
1479
|
+
result = await callAnthropicWithRetries(
|
|
1485
1480
|
id,
|
|
1486
1481
|
await prepareAnthropicPayload(id, routingPayload),
|
|
1487
1482
|
aiConfig,
|
|
@@ -1489,8 +1484,9 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
1489
1484
|
requestTimeoutMs,
|
|
1490
1485
|
signal
|
|
1491
1486
|
);
|
|
1487
|
+
break;
|
|
1492
1488
|
case "openai":
|
|
1493
|
-
|
|
1489
|
+
result = await callOpenAiWithRetries(
|
|
1494
1490
|
id,
|
|
1495
1491
|
await prepareOpenAIPayload(id, routingPayload),
|
|
1496
1492
|
aiConfig,
|
|
@@ -1499,34 +1495,39 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
1499
1495
|
requestTimeoutMs,
|
|
1500
1496
|
signal
|
|
1501
1497
|
);
|
|
1498
|
+
break;
|
|
1502
1499
|
case "groq":
|
|
1503
|
-
|
|
1500
|
+
result = await callGroqWithRetries(
|
|
1504
1501
|
id,
|
|
1505
1502
|
prepareGroqPayload(routingPayload),
|
|
1506
1503
|
retries,
|
|
1507
1504
|
requestTimeoutMs,
|
|
1508
1505
|
signal
|
|
1509
1506
|
);
|
|
1507
|
+
break;
|
|
1510
1508
|
case "google":
|
|
1511
|
-
|
|
1509
|
+
result = await callGoogleAIWithRetries(
|
|
1512
1510
|
id,
|
|
1513
1511
|
await prepareGoogleAIPayload(id, routingPayload),
|
|
1514
1512
|
retries,
|
|
1515
1513
|
requestTimeoutMs,
|
|
1516
1514
|
signal
|
|
1517
1515
|
);
|
|
1516
|
+
break;
|
|
1518
1517
|
case "openrouter":
|
|
1519
|
-
|
|
1518
|
+
result = await callOpenRouterWithRetries(
|
|
1520
1519
|
id,
|
|
1521
1520
|
prepareOpenRouterPayload(routingPayload),
|
|
1522
1521
|
retries,
|
|
1523
1522
|
requestTimeoutMs,
|
|
1524
1523
|
signal
|
|
1525
1524
|
);
|
|
1525
|
+
break;
|
|
1526
1526
|
}
|
|
1527
|
+
(_b = result.provider) != null ? _b : result.provider = provider;
|
|
1528
|
+
return result;
|
|
1527
1529
|
} catch (error2) {
|
|
1528
|
-
if ((
|
|
1529
|
-
throw error2;
|
|
1530
|
+
if ((_c = aiPayload.signal) == null ? void 0 : _c.aborted) throw error2;
|
|
1530
1531
|
if (aiPayload.fallbackModel) {
|
|
1531
1532
|
logger_default.error(
|
|
1532
1533
|
id,
|