190proof 1.0.114 → 1.0.115

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,7 +1,8 @@
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") return require.apply(this, arguments);
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
5
6
  throw Error('Dynamic require of "' + x + '" is not supported');
6
7
  });
7
8
 
@@ -137,7 +138,8 @@ async function withRetries(identifier, apiName, fn, options = {}) {
137
138
  return await fn();
138
139
  } catch (error3) {
139
140
  lastError = error3;
140
- if ((_a = options.signal) == null ? void 0 : _a.aborted) throw error3;
141
+ if ((_a = options.signal) == null ? void 0 : _a.aborted)
142
+ throw error3;
141
143
  if (onError) {
142
144
  onError(error3, attempt);
143
145
  } else {
@@ -161,7 +163,8 @@ function parseStreamedResponse(identifier, paragraph, toolCallAccumulators, allo
161
163
  const functionCalls = [];
162
164
  for (let i = 0; i < toolCallAccumulators.length; i++) {
163
165
  const acc = toolCallAccumulators[i];
164
- if (!acc.name || !acc.arguments) continue;
166
+ if (!acc.name || !acc.arguments)
167
+ continue;
165
168
  if (allowedFunctionNames && !allowedFunctionNames.has(acc.name)) {
166
169
  throw new Error(
167
170
  `Stream error: received function call with unknown name: ${acc.name}`
@@ -300,7 +303,8 @@ function buildOpenAIRequestConfig(identifier, model, config) {
300
303
  };
301
304
  }
302
305
  function filterOpenAICompatReasoningDetails(details) {
303
- if (!Array.isArray(details)) return details || void 0;
306
+ if (!Array.isArray(details))
307
+ return details || void 0;
304
308
  const blocks = details.filter(
305
309
  (block) => typeof (block == null ? void 0 : block.type) === "string" && block.type.startsWith("reasoning.")
306
310
  );
@@ -311,6 +315,7 @@ async function prepareOpenAIPayload(identifier, payload) {
311
315
  const preparedPayload = {
312
316
  model: payload.model,
313
317
  messages: [],
318
+ reasoning_effort: payload.reasoningEffort,
314
319
  tools: (_a = payload.functions) == null ? void 0 : _a.map((fn) => ({
315
320
  type: "function",
316
321
  function: fn
@@ -371,11 +376,13 @@ async function prepareOpenAIPayload(identifier, payload) {
371
376
  };
372
377
  });
373
378
  }
374
- if (message.reasoning) outMessage.reasoning = message.reasoning;
379
+ if (message.reasoning)
380
+ outMessage.reasoning = message.reasoning;
375
381
  const reasoningDetails = filterOpenAICompatReasoningDetails(
376
382
  message.reasoningDetails
377
383
  );
378
- if (reasoningDetails) outMessage.reasoning_details = reasoningDetails;
384
+ if (reasoningDetails)
385
+ outMessage.reasoning_details = reasoningDetails;
379
386
  preparedPayload.messages.push(outMessage);
380
387
  }
381
388
  return preparedPayload;
@@ -437,7 +444,8 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
437
444
  }
438
445
  const jsonStrings = chunk.split(/^data: /gm);
439
446
  for (const jsonString of jsonStrings) {
440
- if (!jsonString) continue;
447
+ if (!jsonString)
448
+ continue;
441
449
  if (jsonString.includes("[DONE]")) {
442
450
  clearTimeout(overallTimeout);
443
451
  return parseStreamedResponse(
@@ -475,7 +483,8 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
475
483
  while (toolCallAccumulators.length <= idx) {
476
484
  toolCallAccumulators.push({ name: "", arguments: "" });
477
485
  }
478
- if (toolCall.id) toolCallAccumulators[idx].id = toolCall.id;
486
+ if (toolCall.id)
487
+ toolCallAccumulators[idx].id = toolCall.id;
479
488
  if ((_e = toolCall.function) == null ? void 0 : _e.name)
480
489
  toolCallAccumulators[idx].name += toolCall.function.name;
481
490
  if ((_f = toolCall.function) == null ? void 0 : _f.arguments)
@@ -483,9 +492,11 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs,
483
492
  }
484
493
  }
485
494
  const text = (_h = (_g = json.choices[0]) == null ? void 0 : _g.delta) == null ? void 0 : _h.content;
486
- if (text) paragraph += text;
495
+ if (text)
496
+ paragraph += text;
487
497
  const reasoningDelta = (_j = (_i = json.choices[0]) == null ? void 0 : _i.delta) == null ? void 0 : _j.reasoning;
488
- if (reasoningDelta) reasoning += reasoningDelta;
498
+ if (reasoningDelta)
499
+ reasoning += reasoningDelta;
489
500
  }
490
501
  }
491
502
  }
@@ -630,7 +641,8 @@ function jigAnthropicMessages(messages) {
630
641
  ];
631
642
  }
632
643
  jiggedMessages = jiggedMessages.reduce((acc, message) => {
633
- if (acc.length === 0) return [message];
644
+ if (acc.length === 0)
645
+ return [message];
634
646
  const lastMessage = acc[acc.length - 1];
635
647
  if (lastMessage.role === message.role) {
636
648
  const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [{ type: "text", text: lastMessage.content }];
@@ -884,7 +896,8 @@ function jigGoogleMessages(messages) {
884
896
  ];
885
897
  }
886
898
  jiggedMessages = jiggedMessages.reduce((acc, message) => {
887
- if (acc.length === 0) return [message];
899
+ if (acc.length === 0)
900
+ return [message];
888
901
  const lastMessage = acc[acc.length - 1];
889
902
  if (lastMessage.role === message.role) {
890
903
  lastMessage.parts = [...lastMessage.parts, ...message.parts];
@@ -923,7 +936,8 @@ async function prepareGoogleAIPayload(_identifier, payload) {
923
936
  const toolNameById = /* @__PURE__ */ new Map();
924
937
  for (const m of payload.messages) {
925
938
  for (const fc of m.functionCalls || []) {
926
- if (fc.id) toolNameById.set(fc.id, fc.name);
939
+ if (fc.id)
940
+ toolNameById.set(fc.id, fc.name);
927
941
  }
928
942
  }
929
943
  for (const message of payload.messages) {
@@ -1003,7 +1017,8 @@ async function callGoogleAI(id, payload, requestTimeoutMs = 12e4, signal) {
1003
1017
  ...payload.thinkingConfig ? { thinkingConfig: payload.thinkingConfig } : {}
1004
1018
  }
1005
1019
  };
1006
- if (payload.tools) requestBody.tools = [payload.tools];
1020
+ if (payload.tools)
1021
+ requestBody.tools = [payload.tools];
1007
1022
  if (payload.tools && payload.toolConfig) {
1008
1023
  requestBody.toolConfig = payload.toolConfig;
1009
1024
  }
@@ -1061,7 +1076,8 @@ async function callGoogleAI(id, payload, requestTimeoutMs = 12e4, signal) {
1061
1076
  });
1062
1077
  continue;
1063
1078
  }
1064
- if (part.text) text += part.text;
1079
+ if (part.text)
1080
+ text += part.text;
1065
1081
  if ((_m = part.inlineData) == null ? void 0 : _m.data) {
1066
1082
  files.push({ mimeType: "image/png", data: part.inlineData.data });
1067
1083
  }
@@ -1139,15 +1155,21 @@ async function callGoogleAIWithRetries(id, payload, retries = 5, requestTimeoutM
1139
1155
  finishReason: error2.finishReason,
1140
1156
  modelVersion: error2.modelVersion
1141
1157
  };
1142
- if (error2.safetyRatings) errorDetails.safetyRatings = error2.safetyRatings;
1143
- if (error2.usageMetadata) errorDetails.usageMetadata = error2.usageMetadata;
1158
+ if (error2.safetyRatings)
1159
+ errorDetails.safetyRatings = error2.safetyRatings;
1160
+ if (error2.usageMetadata)
1161
+ errorDetails.usageMetadata = error2.usageMetadata;
1144
1162
  if (error2.promptFeedback)
1145
1163
  errorDetails.promptFeedback = error2.promptFeedback;
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
+ if (error2.status)
1165
+ errorDetails.httpStatus = error2.status;
1166
+ if (error2.code)
1167
+ errorDetails.errorCode = error2.code;
1168
+ if (error2.details)
1169
+ errorDetails.errorDetails = error2.details;
1149
1170
  const fileUris = payload.messages.flatMap((m) => m.parts).filter((p) => "fileData" in p).map((p) => p.fileData.fileUri);
1150
- if (fileUris.length) errorDetails.fileUris = fileUris;
1171
+ if (fileUris.length)
1172
+ errorDetails.fileUris = fileUris;
1151
1173
  logger_default.error(
1152
1174
  id,
1153
1175
  `Retry #${attempt} error: ${error2.message}`,
@@ -1231,13 +1253,16 @@ function prepareOpenAICompatMessages(messages) {
1231
1253
  }
1232
1254
  };
1233
1255
  });
1234
- if (!content) outMessage.content = null;
1256
+ if (!content)
1257
+ outMessage.content = null;
1235
1258
  }
1236
- if (message.reasoning) outMessage.reasoning = message.reasoning;
1259
+ if (message.reasoning)
1260
+ outMessage.reasoning = message.reasoning;
1237
1261
  const reasoningDetails = filterOpenAICompatReasoningDetails(
1238
1262
  message.reasoningDetails
1239
1263
  );
1240
- if (reasoningDetails) outMessage.reasoning_details = reasoningDetails;
1264
+ if (reasoningDetails)
1265
+ outMessage.reasoning_details = reasoningDetails;
1241
1266
  out.push(outMessage);
1242
1267
  }
1243
1268
  return out;
@@ -1380,7 +1405,8 @@ function parseDsmlToolCalls(content) {
1380
1405
  let last = -1;
1381
1406
  let tag;
1382
1407
  while ((tag = DSML_ANY_TAG_RE.exec(content)) !== null) {
1383
- if (first === -1) first = tag.index;
1408
+ if (first === -1)
1409
+ first = tag.index;
1384
1410
  last = tag.index + tag[0].length;
1385
1411
  }
1386
1412
  const remaining = first === -1 ? content : (content.slice(0, first) + content.slice(last)).trim();
@@ -1396,7 +1422,8 @@ function finalizeOpenRouterMessage(id, raw) {
1396
1422
  const functionCalls = [];
1397
1423
  for (let i = 0; i < raw.toolCalls.length; i++) {
1398
1424
  const tc = raw.toolCalls[i];
1399
- if (!tc.name) continue;
1425
+ if (!tc.name)
1426
+ continue;
1400
1427
  functionCalls.push({
1401
1428
  id: (_a = tc.id) != null ? _a : `call_${i}`,
1402
1429
  name: tc.name,
@@ -1449,7 +1476,8 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1449
1476
  controller.abort();
1450
1477
  };
1451
1478
  const unref = (t) => {
1452
- if (typeof t === "object" && "unref" in t) t.unref();
1479
+ if (typeof t === "object" && "unref" in t)
1480
+ t.unref();
1453
1481
  return t;
1454
1482
  };
1455
1483
  const totalTimer = unref(
@@ -1517,88 +1545,98 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1517
1545
  const reader = response.body.getReader();
1518
1546
  const decoder = new TextDecoder();
1519
1547
  let lineBuffer = "";
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;
1548
+ outer:
1549
+ while (true) {
1550
+ const { done, value } = await reader.read();
1551
+ if (done)
1552
+ break;
1553
+ lineBuffer += decoder.decode(value, { stream: true });
1554
+ let newlineIdx;
1555
+ while ((newlineIdx = lineBuffer.indexOf("\n")) !== -1) {
1556
+ let line = lineBuffer.slice(0, newlineIdx);
1557
+ lineBuffer = lineBuffer.slice(newlineIdx + 1);
1558
+ if (line.endsWith("\r"))
1559
+ line = line.slice(0, -1);
1560
+ if (!line)
1561
+ continue;
1562
+ if (line.startsWith(":"))
1563
+ continue;
1564
+ if (!line.startsWith("data:"))
1565
+ continue;
1566
+ const dataStr = line.slice(5).trimStart();
1567
+ if (dataStr === "[DONE]") {
1568
+ sawDone = true;
1569
+ break outer;
1569
1570
  }
1570
- if (delta.reasoning) {
1571
- reasoning += delta.reasoning;
1572
- useful = true;
1571
+ let json;
1572
+ try {
1573
+ json = JSON.parse(dataStr);
1574
+ } catch (e) {
1575
+ logger_default.error(
1576
+ id,
1577
+ "OpenRouter stream: unparseable data line:",
1578
+ dataStr.slice(0, 200)
1579
+ );
1580
+ continue;
1573
1581
  }
1574
- if (Array.isArray(delta.reasoning_details) && delta.reasoning_details.length) {
1575
- reasoningDetails.push(...delta.reasoning_details);
1582
+ dataChunks++;
1583
+ if (json.error) {
1584
+ logger_default.error(id, "OpenRouter stream error event:", json.error);
1585
+ const error2 = new Error(
1586
+ `OpenRouter error: ${json.error.message}`
1587
+ );
1588
+ error2.data = json.error;
1589
+ throw error2;
1590
+ }
1591
+ if (json.provider)
1592
+ provider = json.provider;
1593
+ let useful = false;
1594
+ if (json.usage) {
1595
+ usage = json.usage;
1576
1596
  useful = true;
1577
1597
  }
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: "" });
1598
+ const choice = (_c = json.choices) == null ? void 0 : _c[0];
1599
+ if (choice) {
1600
+ const delta = (_d = choice.delta) != null ? _d : {};
1601
+ if (delta.content) {
1602
+ paragraph += delta.content;
1603
+ useful = true;
1604
+ }
1605
+ if (delta.reasoning) {
1606
+ reasoning += delta.reasoning;
1607
+ useful = true;
1608
+ }
1609
+ if (Array.isArray(delta.reasoning_details) && delta.reasoning_details.length) {
1610
+ reasoningDetails.push(...delta.reasoning_details);
1611
+ useful = true;
1612
+ }
1613
+ if (Array.isArray(delta.tool_calls)) {
1614
+ for (const toolCall of delta.tool_calls) {
1615
+ const idx = (_e = toolCall.index) != null ? _e : 0;
1616
+ while (toolCalls.length <= idx) {
1617
+ toolCalls.push({ name: "", argumentsJson: "" });
1618
+ }
1619
+ if (toolCall.id)
1620
+ toolCalls[idx].id = toolCall.id;
1621
+ if ((_f = toolCall.function) == null ? void 0 : _f.name)
1622
+ toolCalls[idx].name += toolCall.function.name;
1623
+ if ((_g = toolCall.function) == null ? void 0 : _g.arguments)
1624
+ toolCalls[idx].argumentsJson += toolCall.function.arguments;
1625
+ useful = true;
1583
1626
  }
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;
1627
+ }
1628
+ if (choice.finish_reason) {
1629
+ finishReason = choice.finish_reason;
1589
1630
  useful = true;
1590
1631
  }
1591
1632
  }
1592
- if (choice.finish_reason) {
1593
- finishReason = choice.finish_reason;
1594
- useful = true;
1595
- }
1633
+ if (useful)
1634
+ armStallTimer();
1596
1635
  }
1597
- if (useful) armStallTimer();
1598
1636
  }
1599
- }
1600
- if (sawDone) reader.cancel().catch(() => {
1601
- });
1637
+ if (sawDone)
1638
+ reader.cancel().catch(() => {
1639
+ });
1602
1640
  if (!sawDone && !finishReason) {
1603
1641
  logger_default.error(
1604
1642
  id,
@@ -1705,12 +1743,15 @@ var MODERATION_RE = /moderat|inappropriate content|content polic|content managem
1705
1743
  function moderationEvictionSlug(error2, payload) {
1706
1744
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1707
1745
  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;
1708
- if (!body) return null;
1746
+ if (!body)
1747
+ return null;
1709
1748
  const message = String((_d = body.message) != null ? _d : "");
1710
1749
  const isModeration = body.code === 403 || Array.isArray((_e = body.metadata) == null ? void 0 : _e.reasons) || MODERATION_RE.test(message);
1711
- if (!isModeration) return null;
1750
+ if (!isModeration)
1751
+ return null;
1712
1752
  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];
1713
- if (!display) return null;
1753
+ if (!display)
1754
+ return null;
1714
1755
  const key = normalizeProviderKey(display);
1715
1756
  const fromOrder = (_j = (_i = payload.provider) == null ? void 0 : _i.order) == null ? void 0 : _j.find(
1716
1757
  (entry) => normalizeProviderKey(entry) === key
@@ -1720,9 +1761,11 @@ function moderationEvictionSlug(error2, payload) {
1720
1761
  var MIN_STREAM_ATTEMPT_MS = 1e4;
1721
1762
  var estimateTokens = (text) => Math.round(text.length / 4);
1722
1763
  function streamAttemptBudgetMs(options) {
1723
- if (options.streamDeadlineAt === void 0) return options.streamTimeoutMs;
1764
+ if (options.streamDeadlineAt === void 0)
1765
+ return options.streamTimeoutMs;
1724
1766
  const remaining = options.streamDeadlineAt - Date.now();
1725
- if (remaining < MIN_STREAM_ATTEMPT_MS) return null;
1767
+ if (remaining < MIN_STREAM_ATTEMPT_MS)
1768
+ return null;
1726
1769
  return Math.min(options.streamTimeoutMs, remaining);
1727
1770
  }
1728
1771
  async function callOpenRouterWithRetries(id, payload, retries = 5, options, signal) {
@@ -1878,7 +1921,8 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
1878
1921
  (_e = result.provider) != null ? _e : result.provider = provider;
1879
1922
  return result;
1880
1923
  } catch (error2) {
1881
- if ((_f = aiPayload.signal) == null ? void 0 : _f.aborted) throw error2;
1924
+ if ((_f = aiPayload.signal) == null ? void 0 : _f.aborted)
1925
+ throw error2;
1882
1926
  if (aiPayload.fallbackModel) {
1883
1927
  logger_default.error(
1884
1928
  id,