190proof 1.0.102 → 1.0.105
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 +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +58 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -289,6 +289,14 @@ function buildOpenAIRequestConfig(identifier, model, config) {
|
|
|
289
289
|
}
|
|
290
290
|
};
|
|
291
291
|
}
|
|
292
|
+
function filterOpenAICompatReasoningDetails(details) {
|
|
293
|
+
if (!Array.isArray(details))
|
|
294
|
+
return details || void 0;
|
|
295
|
+
const blocks = details.filter(
|
|
296
|
+
(block) => typeof (block == null ? void 0 : block.type) === "string" && block.type.startsWith("reasoning.")
|
|
297
|
+
);
|
|
298
|
+
return blocks.length ? blocks : void 0;
|
|
299
|
+
}
|
|
292
300
|
async function prepareOpenAIPayload(identifier, payload) {
|
|
293
301
|
var _a, _b;
|
|
294
302
|
const preparedPayload = {
|
|
@@ -356,8 +364,11 @@ async function prepareOpenAIPayload(identifier, payload) {
|
|
|
356
364
|
}
|
|
357
365
|
if (message.reasoning)
|
|
358
366
|
outMessage.reasoning = message.reasoning;
|
|
359
|
-
|
|
360
|
-
|
|
367
|
+
const reasoningDetails = filterOpenAICompatReasoningDetails(
|
|
368
|
+
message.reasoningDetails
|
|
369
|
+
);
|
|
370
|
+
if (reasoningDetails)
|
|
371
|
+
outMessage.reasoning_details = reasoningDetails;
|
|
361
372
|
preparedPayload.messages.push(outMessage);
|
|
362
373
|
}
|
|
363
374
|
return preparedPayload;
|
|
@@ -642,7 +653,11 @@ async function prepareAnthropicPayload(_identifier, payload) {
|
|
|
642
653
|
model: payload.model,
|
|
643
654
|
messages: [],
|
|
644
655
|
functions: payload.functions,
|
|
645
|
-
temperature: payload.temperature
|
|
656
|
+
temperature: payload.temperature,
|
|
657
|
+
// Map the generic function_call to Anthropic tool_choice ("none" forces a
|
|
658
|
+
// text-only turn). Only meaningful alongside tools — callAnthropic sends
|
|
659
|
+
// it only when tools are present (tool_choice without tools 400s).
|
|
660
|
+
tool_choice: payload.function_call ? typeof payload.function_call === "string" ? { type: payload.function_call } : { type: "tool", name: payload.function_call.name } : void 0
|
|
646
661
|
};
|
|
647
662
|
for (const message of payload.messages) {
|
|
648
663
|
if (message.role === "system") {
|
|
@@ -697,7 +712,9 @@ async function prepareAnthropicPayload(_identifier, payload) {
|
|
|
697
712
|
});
|
|
698
713
|
}
|
|
699
714
|
}
|
|
700
|
-
const leadingBlocks = message.role === "assistant" && Array.isArray(message.reasoningDetails) ? message.reasoningDetails
|
|
715
|
+
const leadingBlocks = message.role === "assistant" && Array.isArray(message.reasoningDetails) ? message.reasoningDetails.filter(
|
|
716
|
+
(block) => (block == null ? void 0 : block.type) === "thinking" || (block == null ? void 0 : block.type) === "redacted_thinking"
|
|
717
|
+
) : [];
|
|
701
718
|
const toolUseBlocks = (message.functionCalls || []).map((fc, i) => {
|
|
702
719
|
var _a;
|
|
703
720
|
return {
|
|
@@ -754,6 +771,8 @@ async function callAnthropic(id, payload, config, requestTimeoutMs = 12e4, signa
|
|
|
754
771
|
model: payload.model,
|
|
755
772
|
messages: anthropicMessages,
|
|
756
773
|
tools: cachedTools,
|
|
774
|
+
// tool_choice requires tools in the request; drop it otherwise.
|
|
775
|
+
tool_choice: (cachedTools == null ? void 0 : cachedTools.length) ? payload.tool_choice : void 0,
|
|
757
776
|
temperature: payload.temperature,
|
|
758
777
|
system: payload.system,
|
|
759
778
|
max_tokens: 4096
|
|
@@ -885,6 +904,13 @@ async function prepareGoogleAIPayload(_identifier, payload) {
|
|
|
885
904
|
...fn.parameters
|
|
886
905
|
}
|
|
887
906
|
}))
|
|
907
|
+
} : void 0,
|
|
908
|
+
// Map the generic function_call to Gemini's functionCallingConfig ("none"
|
|
909
|
+
// → mode NONE forces a text-only turn). Only meaningful alongside tools.
|
|
910
|
+
toolConfig: payload.functions && payload.function_call ? {
|
|
911
|
+
functionCallingConfig: {
|
|
912
|
+
mode: typeof payload.function_call === "string" ? payload.function_call === "none" ? "NONE" : "AUTO" : "ANY"
|
|
913
|
+
}
|
|
888
914
|
} : void 0
|
|
889
915
|
};
|
|
890
916
|
const toolNameById = /* @__PURE__ */ new Map();
|
|
@@ -970,6 +996,9 @@ async function callGoogleAI(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
|
970
996
|
};
|
|
971
997
|
if (payload.tools)
|
|
972
998
|
requestBody.tools = [payload.tools];
|
|
999
|
+
if (payload.tools && payload.toolConfig) {
|
|
1000
|
+
requestBody.toolConfig = payload.toolConfig;
|
|
1001
|
+
}
|
|
973
1002
|
if (payload.systemInstruction) {
|
|
974
1003
|
requestBody.systemInstruction = {
|
|
975
1004
|
parts: [{ text: payload.systemInstruction }]
|
|
@@ -1196,8 +1225,11 @@ function prepareOpenAICompatMessages(messages) {
|
|
|
1196
1225
|
}
|
|
1197
1226
|
if (message.reasoning)
|
|
1198
1227
|
outMessage.reasoning = message.reasoning;
|
|
1199
|
-
|
|
1200
|
-
|
|
1228
|
+
const reasoningDetails = filterOpenAICompatReasoningDetails(
|
|
1229
|
+
message.reasoningDetails
|
|
1230
|
+
);
|
|
1231
|
+
if (reasoningDetails)
|
|
1232
|
+
outMessage.reasoning_details = reasoningDetails;
|
|
1201
1233
|
out.push(outMessage);
|
|
1202
1234
|
}
|
|
1203
1235
|
return out;
|
|
@@ -1343,7 +1375,7 @@ function parseDsmlToolCalls(content) {
|
|
|
1343
1375
|
return { calls, remainingContent: remaining.length ? remaining : null };
|
|
1344
1376
|
}
|
|
1345
1377
|
async function callOpenRouter(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
1346
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1378
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1347
1379
|
const response = await axios.post(
|
|
1348
1380
|
"https://openrouter.ai/api/v1/chat/completions",
|
|
1349
1381
|
payload,
|
|
@@ -1403,11 +1435,14 @@ async function callOpenRouter(id, payload, requestTimeoutMs = 12e4, signal) {
|
|
|
1403
1435
|
files: [],
|
|
1404
1436
|
reasoning: (_f = answer.reasoning) != null ? _f : void 0,
|
|
1405
1437
|
reasoningDetails: (_g = answer.reasoning_details) != null ? _g : void 0,
|
|
1438
|
+
// The upstream provider OpenRouter routed to (e.g. "Baidu") — finer-grained
|
|
1439
|
+
// than the "openrouter" stamp callWithRetries would apply.
|
|
1440
|
+
provider: (_h = response.data.provider) != null ? _h : void 0,
|
|
1406
1441
|
usage: response.data.usage ? {
|
|
1407
1442
|
prompt_tokens: response.data.usage.prompt_tokens,
|
|
1408
1443
|
completion_tokens: response.data.usage.completion_tokens,
|
|
1409
1444
|
total_tokens: response.data.usage.total_tokens,
|
|
1410
|
-
cached_tokens: (
|
|
1445
|
+
cached_tokens: (_j = (_i = response.data.usage.prompt_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : 0
|
|
1411
1446
|
} : null
|
|
1412
1447
|
};
|
|
1413
1448
|
}
|
|
@@ -1457,15 +1492,16 @@ function parseModelString(model) {
|
|
|
1457
1492
|
);
|
|
1458
1493
|
}
|
|
1459
1494
|
async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeoutMs = 15e3) {
|
|
1460
|
-
var _a, _b;
|
|
1495
|
+
var _a, _b, _c;
|
|
1461
1496
|
try {
|
|
1462
1497
|
const { provider, modelId } = parseModelString(aiPayload.model);
|
|
1463
1498
|
const routingPayload = { ...aiPayload, model: modelId };
|
|
1464
1499
|
const requestTimeoutMs = (_a = aiPayload.requestTimeoutMs) != null ? _a : 12e4;
|
|
1465
1500
|
const signal = aiPayload.signal;
|
|
1501
|
+
let result;
|
|
1466
1502
|
switch (provider) {
|
|
1467
1503
|
case "anthropic":
|
|
1468
|
-
|
|
1504
|
+
result = await callAnthropicWithRetries(
|
|
1469
1505
|
id,
|
|
1470
1506
|
await prepareAnthropicPayload(id, routingPayload),
|
|
1471
1507
|
aiConfig,
|
|
@@ -1473,8 +1509,9 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
1473
1509
|
requestTimeoutMs,
|
|
1474
1510
|
signal
|
|
1475
1511
|
);
|
|
1512
|
+
break;
|
|
1476
1513
|
case "openai":
|
|
1477
|
-
|
|
1514
|
+
result = await callOpenAiWithRetries(
|
|
1478
1515
|
id,
|
|
1479
1516
|
await prepareOpenAIPayload(id, routingPayload),
|
|
1480
1517
|
aiConfig,
|
|
@@ -1483,33 +1520,39 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
|
|
|
1483
1520
|
requestTimeoutMs,
|
|
1484
1521
|
signal
|
|
1485
1522
|
);
|
|
1523
|
+
break;
|
|
1486
1524
|
case "groq":
|
|
1487
|
-
|
|
1525
|
+
result = await callGroqWithRetries(
|
|
1488
1526
|
id,
|
|
1489
1527
|
prepareGroqPayload(routingPayload),
|
|
1490
1528
|
retries,
|
|
1491
1529
|
requestTimeoutMs,
|
|
1492
1530
|
signal
|
|
1493
1531
|
);
|
|
1532
|
+
break;
|
|
1494
1533
|
case "google":
|
|
1495
|
-
|
|
1534
|
+
result = await callGoogleAIWithRetries(
|
|
1496
1535
|
id,
|
|
1497
1536
|
await prepareGoogleAIPayload(id, routingPayload),
|
|
1498
1537
|
retries,
|
|
1499
1538
|
requestTimeoutMs,
|
|
1500
1539
|
signal
|
|
1501
1540
|
);
|
|
1541
|
+
break;
|
|
1502
1542
|
case "openrouter":
|
|
1503
|
-
|
|
1543
|
+
result = await callOpenRouterWithRetries(
|
|
1504
1544
|
id,
|
|
1505
1545
|
prepareOpenRouterPayload(routingPayload),
|
|
1506
1546
|
retries,
|
|
1507
1547
|
requestTimeoutMs,
|
|
1508
1548
|
signal
|
|
1509
1549
|
);
|
|
1550
|
+
break;
|
|
1510
1551
|
}
|
|
1552
|
+
(_b = result.provider) != null ? _b : result.provider = provider;
|
|
1553
|
+
return result;
|
|
1511
1554
|
} catch (error2) {
|
|
1512
|
-
if ((
|
|
1555
|
+
if ((_c = aiPayload.signal) == null ? void 0 : _c.aborted)
|
|
1513
1556
|
throw error2;
|
|
1514
1557
|
if (aiPayload.fallbackModel) {
|
|
1515
1558
|
logger_default.error(
|