190proof 1.0.110 → 1.0.112

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
@@ -1459,7 +1459,9 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1459
1459
  var _a, _b, _c, _d, _e, _f, _g;
1460
1460
  const controller = new AbortController();
1461
1461
  let abortReason = null;
1462
- const abortWith = (reason) => {
1462
+ let abortKind = null;
1463
+ const abortWith = (kind, reason) => {
1464
+ abortKind = kind;
1463
1465
  abortReason = reason;
1464
1466
  controller.abort();
1465
1467
  };
@@ -1471,6 +1473,7 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1471
1473
  const totalTimer = unref(
1472
1474
  setTimeout(
1473
1475
  () => abortWith(
1476
+ "deadline",
1474
1477
  `OpenRouter stream exceeded total deadline of ${streamTimeoutMs}ms`
1475
1478
  ),
1476
1479
  streamTimeoutMs
@@ -1482,6 +1485,7 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1482
1485
  stallTimer = unref(
1483
1486
  setTimeout(
1484
1487
  () => abortWith(
1488
+ "stall",
1485
1489
  `OpenRouter stream stalled: no useful chunk for ${chunkTimeoutMs}ms`
1486
1490
  ),
1487
1491
  chunkTimeoutMs
@@ -1648,7 +1652,31 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1648
1652
  });
1649
1653
  } catch (error2) {
1650
1654
  if (abortReason && !(signal == null ? void 0 : signal.aborted)) {
1651
- logger_default.error(id, abortReason);
1655
+ const kept = paragraph.trim();
1656
+ if (abortKind === "deadline" && kept && !toolCalls.length) {
1657
+ try {
1658
+ const message = finalizeOpenRouterMessage(id, {
1659
+ content: kept,
1660
+ toolCalls: [],
1661
+ reasoning,
1662
+ reasoningDetails: reasoningDetails.length ? reasoningDetails : void 0,
1663
+ provider,
1664
+ usage,
1665
+ forLog: () => JSON.stringify({ provider, kept: kept.slice(0, 500) })
1666
+ });
1667
+ message.truncated = true;
1668
+ logger_default.log(
1669
+ id,
1670
+ `${abortReason} \u2014 returning truncated answer (${kept.length} chars, ~${estimateTokens(kept)} tokens kept)`
1671
+ );
1672
+ return message;
1673
+ } catch (e) {
1674
+ }
1675
+ }
1676
+ logger_default.error(
1677
+ id,
1678
+ `${abortReason} \u2014 discarding ~${estimateTokens(paragraph + reasoning)} generated tokens (content ${paragraph.length} chars, reasoning ${reasoning.length} chars, ${dataChunks} chunks)`
1679
+ );
1652
1680
  throw new Error(abortReason);
1653
1681
  }
1654
1682
  throw error2;
@@ -1720,18 +1748,39 @@ function moderationEvictionSlug(error2, payload) {
1720
1748
  );
1721
1749
  return fromOrder ? fromOrder.split("/")[0] : display.toLowerCase();
1722
1750
  }
1751
+ var MIN_STREAM_ATTEMPT_MS = 1e4;
1752
+ var estimateTokens = (text) => Math.round(text.length / 4);
1753
+ function streamAttemptBudgetMs(options) {
1754
+ if (options.streamDeadlineAt === void 0)
1755
+ return options.streamTimeoutMs;
1756
+ const remaining = options.streamDeadlineAt - Date.now();
1757
+ if (remaining < MIN_STREAM_ATTEMPT_MS)
1758
+ return null;
1759
+ return Math.min(options.streamTimeoutMs, remaining);
1760
+ }
1723
1761
  async function callOpenRouterWithRetries(id, payload, retries = 5, options, signal) {
1724
1762
  const evicted = [];
1725
1763
  return withRetries(
1726
1764
  id,
1727
1765
  "OpenRouter",
1728
- () => (options.streaming ? callOpenRouterStream(
1729
- id,
1730
- payload,
1731
- options.streamTimeoutMs,
1732
- options.chunkTimeoutMs,
1733
- signal
1734
- ) : callOpenRouterNonStreaming(
1766
+ () => (options.streaming ? (() => {
1767
+ const budget = streamAttemptBudgetMs(options);
1768
+ if (budget === null) {
1769
+ const error2 = new Error(
1770
+ "OpenRouter stream skipped: caller deadline leaves too little time for another attempt"
1771
+ );
1772
+ error2.deadlineExceeded = true;
1773
+ logger_default.error(id, error2.message);
1774
+ throw error2;
1775
+ }
1776
+ return callOpenRouterStream(
1777
+ id,
1778
+ payload,
1779
+ budget,
1780
+ options.chunkTimeoutMs,
1781
+ signal
1782
+ );
1783
+ })() : callOpenRouterNonStreaming(
1735
1784
  id,
1736
1785
  payload,
1737
1786
  options.requestTimeoutMs,
@@ -1851,6 +1900,7 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
1851
1900
  {
1852
1901
  streaming: (_b = aiPayload.streaming) != null ? _b : true,
1853
1902
  streamTimeoutMs: (_c = aiPayload.streamTimeoutMs) != null ? _c : OPENROUTER_STREAM_TIMEOUT_MS,
1903
+ streamDeadlineAt: aiPayload.streamDeadlineAt,
1854
1904
  requestTimeoutMs: (_d = aiPayload.requestTimeoutMs) != null ? _d : OPENROUTER_NONSTREAM_TIMEOUT_MS,
1855
1905
  chunkTimeoutMs
1856
1906
  },
@@ -1892,6 +1942,7 @@ export {
1892
1942
  GPTModel,
1893
1943
  GeminiModel,
1894
1944
  GroqModel,
1945
+ MIN_STREAM_ATTEMPT_MS,
1895
1946
  OPENROUTER_NONSTREAM_TIMEOUT_MS,
1896
1947
  OPENROUTER_STREAM_TIMEOUT_MS,
1897
1948
  OpenRouterModel,