190proof 1.0.113 → 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/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: { responseModalities: ["TEXT"] }
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
- errorDetails.safetyRatings = error2.safetyRatings;
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
- errorDetails.httpStatus = error2.status;
1160
- if (error2.code)
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}`,
@@ -1247,16 +1231,13 @@ function prepareOpenAICompatMessages(messages) {
1247
1231
  }
1248
1232
  };
1249
1233
  });
1250
- if (!content)
1251
- outMessage.content = null;
1234
+ if (!content) outMessage.content = null;
1252
1235
  }
1253
- if (message.reasoning)
1254
- outMessage.reasoning = message.reasoning;
1236
+ if (message.reasoning) outMessage.reasoning = message.reasoning;
1255
1237
  const reasoningDetails = filterOpenAICompatReasoningDetails(
1256
1238
  message.reasoningDetails
1257
1239
  );
1258
- if (reasoningDetails)
1259
- outMessage.reasoning_details = reasoningDetails;
1240
+ if (reasoningDetails) outMessage.reasoning_details = reasoningDetails;
1260
1241
  out.push(outMessage);
1261
1242
  }
1262
1243
  return out;
@@ -1399,8 +1380,7 @@ function parseDsmlToolCalls(content) {
1399
1380
  let last = -1;
1400
1381
  let tag;
1401
1382
  while ((tag = DSML_ANY_TAG_RE.exec(content)) !== null) {
1402
- if (first === -1)
1403
- first = tag.index;
1383
+ if (first === -1) first = tag.index;
1404
1384
  last = tag.index + tag[0].length;
1405
1385
  }
1406
1386
  const remaining = first === -1 ? content : (content.slice(0, first) + content.slice(last)).trim();
@@ -1416,8 +1396,7 @@ function finalizeOpenRouterMessage(id, raw) {
1416
1396
  const functionCalls = [];
1417
1397
  for (let i = 0; i < raw.toolCalls.length; i++) {
1418
1398
  const tc = raw.toolCalls[i];
1419
- if (!tc.name)
1420
- continue;
1399
+ if (!tc.name) continue;
1421
1400
  functionCalls.push({
1422
1401
  id: (_a = tc.id) != null ? _a : `call_${i}`,
1423
1402
  name: tc.name,
@@ -1470,8 +1449,7 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1470
1449
  controller.abort();
1471
1450
  };
1472
1451
  const unref = (t) => {
1473
- if (typeof t === "object" && "unref" in t)
1474
- t.unref();
1452
+ if (typeof t === "object" && "unref" in t) t.unref();
1475
1453
  return t;
1476
1454
  };
1477
1455
  const totalTimer = unref(
@@ -1539,98 +1517,88 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1539
1517
  const reader = response.body.getReader();
1540
1518
  const decoder = new TextDecoder();
1541
1519
  let lineBuffer = "";
1542
- outer:
1543
- while (true) {
1544
- const { done, value } = await reader.read();
1545
- if (done)
1546
- break;
1547
- lineBuffer += decoder.decode(value, { stream: true });
1548
- let newlineIdx;
1549
- while ((newlineIdx = lineBuffer.indexOf("\n")) !== -1) {
1550
- let line = lineBuffer.slice(0, newlineIdx);
1551
- lineBuffer = lineBuffer.slice(newlineIdx + 1);
1552
- if (line.endsWith("\r"))
1553
- line = line.slice(0, -1);
1554
- if (!line)
1555
- continue;
1556
- if (line.startsWith(":"))
1557
- continue;
1558
- if (!line.startsWith("data:"))
1559
- continue;
1560
- const dataStr = line.slice(5).trimStart();
1561
- if (dataStr === "[DONE]") {
1562
- sawDone = true;
1563
- break outer;
1564
- }
1565
- let json;
1566
- try {
1567
- json = JSON.parse(dataStr);
1568
- } catch (e) {
1569
- logger_default.error(
1570
- id,
1571
- "OpenRouter stream: unparseable data line:",
1572
- dataStr.slice(0, 200)
1573
- );
1574
- continue;
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;
1575
1569
  }
1576
- dataChunks++;
1577
- if (json.error) {
1578
- logger_default.error(id, "OpenRouter stream error event:", json.error);
1579
- const error2 = new Error(
1580
- `OpenRouter error: ${json.error.message}`
1581
- );
1582
- error2.data = json.error;
1583
- throw error2;
1570
+ if (delta.reasoning) {
1571
+ reasoning += delta.reasoning;
1572
+ useful = true;
1584
1573
  }
1585
- if (json.provider)
1586
- provider = json.provider;
1587
- let useful = false;
1588
- if (json.usage) {
1589
- usage = json.usage;
1574
+ if (Array.isArray(delta.reasoning_details) && delta.reasoning_details.length) {
1575
+ reasoningDetails.push(...delta.reasoning_details);
1590
1576
  useful = true;
1591
1577
  }
1592
- const choice = (_c = json.choices) == null ? void 0 : _c[0];
1593
- if (choice) {
1594
- const delta = (_d = choice.delta) != null ? _d : {};
1595
- if (delta.content) {
1596
- paragraph += delta.content;
1597
- useful = true;
1598
- }
1599
- if (delta.reasoning) {
1600
- reasoning += delta.reasoning;
1601
- useful = true;
1602
- }
1603
- if (Array.isArray(delta.reasoning_details) && delta.reasoning_details.length) {
1604
- reasoningDetails.push(...delta.reasoning_details);
1605
- useful = true;
1606
- }
1607
- if (Array.isArray(delta.tool_calls)) {
1608
- for (const toolCall of delta.tool_calls) {
1609
- const idx = (_e = toolCall.index) != null ? _e : 0;
1610
- while (toolCalls.length <= idx) {
1611
- toolCalls.push({ name: "", argumentsJson: "" });
1612
- }
1613
- if (toolCall.id)
1614
- toolCalls[idx].id = toolCall.id;
1615
- if ((_f = toolCall.function) == null ? void 0 : _f.name)
1616
- toolCalls[idx].name += toolCall.function.name;
1617
- if ((_g = toolCall.function) == null ? void 0 : _g.arguments)
1618
- toolCalls[idx].argumentsJson += toolCall.function.arguments;
1619
- 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: "" });
1620
1583
  }
1621
- }
1622
- if (choice.finish_reason) {
1623
- finishReason = choice.finish_reason;
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;
1624
1589
  useful = true;
1625
1590
  }
1626
1591
  }
1627
- if (useful)
1628
- armStallTimer();
1592
+ if (choice.finish_reason) {
1593
+ finishReason = choice.finish_reason;
1594
+ useful = true;
1595
+ }
1629
1596
  }
1597
+ if (useful) armStallTimer();
1630
1598
  }
1631
- if (sawDone)
1632
- reader.cancel().catch(() => {
1633
- });
1599
+ }
1600
+ if (sawDone) reader.cancel().catch(() => {
1601
+ });
1634
1602
  if (!sawDone && !finishReason) {
1635
1603
  logger_default.error(
1636
1604
  id,
@@ -1737,15 +1705,12 @@ var MODERATION_RE = /moderat|inappropriate content|content polic|content managem
1737
1705
  function moderationEvictionSlug(error2, payload) {
1738
1706
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1739
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;
1740
- if (!body)
1741
- return null;
1708
+ if (!body) return null;
1742
1709
  const message = String((_d = body.message) != null ? _d : "");
1743
1710
  const isModeration = body.code === 403 || Array.isArray((_e = body.metadata) == null ? void 0 : _e.reasons) || MODERATION_RE.test(message);
1744
- if (!isModeration)
1745
- return null;
1711
+ if (!isModeration) return null;
1746
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];
1747
- if (!display)
1748
- return null;
1713
+ if (!display) return null;
1749
1714
  const key = normalizeProviderKey(display);
1750
1715
  const fromOrder = (_j = (_i = payload.provider) == null ? void 0 : _i.order) == null ? void 0 : _j.find(
1751
1716
  (entry) => normalizeProviderKey(entry) === key
@@ -1755,11 +1720,9 @@ function moderationEvictionSlug(error2, payload) {
1755
1720
  var MIN_STREAM_ATTEMPT_MS = 1e4;
1756
1721
  var estimateTokens = (text) => Math.round(text.length / 4);
1757
1722
  function streamAttemptBudgetMs(options) {
1758
- if (options.streamDeadlineAt === void 0)
1759
- return options.streamTimeoutMs;
1723
+ if (options.streamDeadlineAt === void 0) return options.streamTimeoutMs;
1760
1724
  const remaining = options.streamDeadlineAt - Date.now();
1761
- if (remaining < MIN_STREAM_ATTEMPT_MS)
1762
- return null;
1725
+ if (remaining < MIN_STREAM_ATTEMPT_MS) return null;
1763
1726
  return Math.min(options.streamTimeoutMs, remaining);
1764
1727
  }
1765
1728
  async function callOpenRouterWithRetries(id, payload, retries = 5, options, signal) {
@@ -1915,8 +1878,7 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
1915
1878
  (_e = result.provider) != null ? _e : result.provider = provider;
1916
1879
  return result;
1917
1880
  } catch (error2) {
1918
- if ((_f = aiPayload.signal) == null ? void 0 : _f.aborted)
1919
- throw error2;
1881
+ if ((_f = aiPayload.signal) == null ? void 0 : _f.aborted) throw error2;
1920
1882
  if (aiPayload.fallbackModel) {
1921
1883
  logger_default.error(
1922
1884
  id,