190proof 1.0.111 → 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;
@@ -1721,6 +1749,7 @@ function moderationEvictionSlug(error2, payload) {
1721
1749
  return fromOrder ? fromOrder.split("/")[0] : display.toLowerCase();
1722
1750
  }
1723
1751
  var MIN_STREAM_ATTEMPT_MS = 1e4;
1752
+ var estimateTokens = (text) => Math.round(text.length / 4);
1724
1753
  function streamAttemptBudgetMs(options) {
1725
1754
  if (options.streamDeadlineAt === void 0)
1726
1755
  return options.streamTimeoutMs;