190proof 1.0.104 → 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/dist/index.mjs CHANGED
@@ -653,7 +653,11 @@ async function prepareAnthropicPayload(_identifier, payload) {
653
653
  model: payload.model,
654
654
  messages: [],
655
655
  functions: payload.functions,
656
- 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
657
661
  };
658
662
  for (const message of payload.messages) {
659
663
  if (message.role === "system") {
@@ -767,6 +771,8 @@ async function callAnthropic(id, payload, config, requestTimeoutMs = 12e4, signa
767
771
  model: payload.model,
768
772
  messages: anthropicMessages,
769
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,
770
776
  temperature: payload.temperature,
771
777
  system: payload.system,
772
778
  max_tokens: 4096
@@ -898,6 +904,13 @@ async function prepareGoogleAIPayload(_identifier, payload) {
898
904
  ...fn.parameters
899
905
  }
900
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
+ }
901
914
  } : void 0
902
915
  };
903
916
  const toolNameById = /* @__PURE__ */ new Map();
@@ -983,6 +996,9 @@ async function callGoogleAI(id, payload, requestTimeoutMs = 12e4, signal) {
983
996
  };
984
997
  if (payload.tools)
985
998
  requestBody.tools = [payload.tools];
999
+ if (payload.tools && payload.toolConfig) {
1000
+ requestBody.toolConfig = payload.toolConfig;
1001
+ }
986
1002
  if (payload.systemInstruction) {
987
1003
  requestBody.systemInstruction = {
988
1004
  parts: [{ text: payload.systemInstruction }]
@@ -1359,7 +1375,7 @@ function parseDsmlToolCalls(content) {
1359
1375
  return { calls, remainingContent: remaining.length ? remaining : null };
1360
1376
  }
1361
1377
  async function callOpenRouter(id, payload, requestTimeoutMs = 12e4, signal) {
1362
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1378
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1363
1379
  const response = await axios.post(
1364
1380
  "https://openrouter.ai/api/v1/chat/completions",
1365
1381
  payload,
@@ -1419,11 +1435,14 @@ async function callOpenRouter(id, payload, requestTimeoutMs = 12e4, signal) {
1419
1435
  files: [],
1420
1436
  reasoning: (_f = answer.reasoning) != null ? _f : void 0,
1421
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,
1422
1441
  usage: response.data.usage ? {
1423
1442
  prompt_tokens: response.data.usage.prompt_tokens,
1424
1443
  completion_tokens: response.data.usage.completion_tokens,
1425
1444
  total_tokens: response.data.usage.total_tokens,
1426
- cached_tokens: (_i = (_h = response.data.usage.prompt_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : 0
1445
+ cached_tokens: (_j = (_i = response.data.usage.prompt_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : 0
1427
1446
  } : null
1428
1447
  };
1429
1448
  }
@@ -1473,15 +1492,16 @@ function parseModelString(model) {
1473
1492
  );
1474
1493
  }
1475
1494
  async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeoutMs = 15e3) {
1476
- var _a, _b;
1495
+ var _a, _b, _c;
1477
1496
  try {
1478
1497
  const { provider, modelId } = parseModelString(aiPayload.model);
1479
1498
  const routingPayload = { ...aiPayload, model: modelId };
1480
1499
  const requestTimeoutMs = (_a = aiPayload.requestTimeoutMs) != null ? _a : 12e4;
1481
1500
  const signal = aiPayload.signal;
1501
+ let result;
1482
1502
  switch (provider) {
1483
1503
  case "anthropic":
1484
- return await callAnthropicWithRetries(
1504
+ result = await callAnthropicWithRetries(
1485
1505
  id,
1486
1506
  await prepareAnthropicPayload(id, routingPayload),
1487
1507
  aiConfig,
@@ -1489,8 +1509,9 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
1489
1509
  requestTimeoutMs,
1490
1510
  signal
1491
1511
  );
1512
+ break;
1492
1513
  case "openai":
1493
- return await callOpenAiWithRetries(
1514
+ result = await callOpenAiWithRetries(
1494
1515
  id,
1495
1516
  await prepareOpenAIPayload(id, routingPayload),
1496
1517
  aiConfig,
@@ -1499,33 +1520,39 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
1499
1520
  requestTimeoutMs,
1500
1521
  signal
1501
1522
  );
1523
+ break;
1502
1524
  case "groq":
1503
- return await callGroqWithRetries(
1525
+ result = await callGroqWithRetries(
1504
1526
  id,
1505
1527
  prepareGroqPayload(routingPayload),
1506
1528
  retries,
1507
1529
  requestTimeoutMs,
1508
1530
  signal
1509
1531
  );
1532
+ break;
1510
1533
  case "google":
1511
- return await callGoogleAIWithRetries(
1534
+ result = await callGoogleAIWithRetries(
1512
1535
  id,
1513
1536
  await prepareGoogleAIPayload(id, routingPayload),
1514
1537
  retries,
1515
1538
  requestTimeoutMs,
1516
1539
  signal
1517
1540
  );
1541
+ break;
1518
1542
  case "openrouter":
1519
- return await callOpenRouterWithRetries(
1543
+ result = await callOpenRouterWithRetries(
1520
1544
  id,
1521
1545
  prepareOpenRouterPayload(routingPayload),
1522
1546
  retries,
1523
1547
  requestTimeoutMs,
1524
1548
  signal
1525
1549
  );
1550
+ break;
1526
1551
  }
1552
+ (_b = result.provider) != null ? _b : result.provider = provider;
1553
+ return result;
1527
1554
  } catch (error2) {
1528
- if ((_b = aiPayload.signal) == null ? void 0 : _b.aborted)
1555
+ if ((_c = aiPayload.signal) == null ? void 0 : _c.aborted)
1529
1556
  throw error2;
1530
1557
  if (aiPayload.fallbackModel) {
1531
1558
  logger_default.error(