190proof 1.0.111 → 1.0.113

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
@@ -1227,9 +1227,13 @@ function prepareOpenAICompatMessages(messages) {
1227
1227
  }
1228
1228
  continue;
1229
1229
  }
1230
+ const fileRefs = (message.files || []).filter((file) => file.url).map(
1231
+ (file) => ALLOWED_IMAGE_MIME_TYPES.includes(file.mimeType) ? `Image (${file.url})` : `File (${file.url})`
1232
+ );
1233
+ const content = [normalizeMessageContent(message.content), ...fileRefs].filter(Boolean).join("\n");
1230
1234
  const outMessage = {
1231
1235
  role: message.role,
1232
- content: normalizeMessageContent(message.content)
1236
+ content
1233
1237
  };
1234
1238
  if ((_a = message.functionCalls) == null ? void 0 : _a.length) {
1235
1239
  outMessage.tool_calls = message.functionCalls.map((fc, i) => {
@@ -1243,7 +1247,7 @@ function prepareOpenAICompatMessages(messages) {
1243
1247
  }
1244
1248
  };
1245
1249
  });
1246
- if (!message.content)
1250
+ if (!content)
1247
1251
  outMessage.content = null;
1248
1252
  }
1249
1253
  if (message.reasoning)
@@ -1459,7 +1463,9 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1459
1463
  var _a, _b, _c, _d, _e, _f, _g;
1460
1464
  const controller = new AbortController();
1461
1465
  let abortReason = null;
1462
- const abortWith = (reason) => {
1466
+ let abortKind = null;
1467
+ const abortWith = (kind, reason) => {
1468
+ abortKind = kind;
1463
1469
  abortReason = reason;
1464
1470
  controller.abort();
1465
1471
  };
@@ -1471,6 +1477,7 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1471
1477
  const totalTimer = unref(
1472
1478
  setTimeout(
1473
1479
  () => abortWith(
1480
+ "deadline",
1474
1481
  `OpenRouter stream exceeded total deadline of ${streamTimeoutMs}ms`
1475
1482
  ),
1476
1483
  streamTimeoutMs
@@ -1482,6 +1489,7 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1482
1489
  stallTimer = unref(
1483
1490
  setTimeout(
1484
1491
  () => abortWith(
1492
+ "stall",
1485
1493
  `OpenRouter stream stalled: no useful chunk for ${chunkTimeoutMs}ms`
1486
1494
  ),
1487
1495
  chunkTimeoutMs
@@ -1648,7 +1656,31 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1648
1656
  });
1649
1657
  } catch (error2) {
1650
1658
  if (abortReason && !(signal == null ? void 0 : signal.aborted)) {
1651
- logger_default.error(id, abortReason);
1659
+ const kept = paragraph.trim();
1660
+ if (abortKind === "deadline" && kept && !toolCalls.length) {
1661
+ try {
1662
+ const message = finalizeOpenRouterMessage(id, {
1663
+ content: kept,
1664
+ toolCalls: [],
1665
+ reasoning,
1666
+ reasoningDetails: reasoningDetails.length ? reasoningDetails : void 0,
1667
+ provider,
1668
+ usage,
1669
+ forLog: () => JSON.stringify({ provider, kept: kept.slice(0, 500) })
1670
+ });
1671
+ message.truncated = true;
1672
+ logger_default.log(
1673
+ id,
1674
+ `${abortReason} \u2014 returning truncated answer (${kept.length} chars, ~${estimateTokens(kept)} tokens kept)`
1675
+ );
1676
+ return message;
1677
+ } catch (e) {
1678
+ }
1679
+ }
1680
+ logger_default.error(
1681
+ id,
1682
+ `${abortReason} \u2014 discarding ~${estimateTokens(paragraph + reasoning)} generated tokens (content ${paragraph.length} chars, reasoning ${reasoning.length} chars, ${dataChunks} chunks)`
1683
+ );
1652
1684
  throw new Error(abortReason);
1653
1685
  }
1654
1686
  throw error2;
@@ -1721,6 +1753,7 @@ function moderationEvictionSlug(error2, payload) {
1721
1753
  return fromOrder ? fromOrder.split("/")[0] : display.toLowerCase();
1722
1754
  }
1723
1755
  var MIN_STREAM_ATTEMPT_MS = 1e4;
1756
+ var estimateTokens = (text) => Math.round(text.length / 4);
1724
1757
  function streamAttemptBudgetMs(options) {
1725
1758
  if (options.streamDeadlineAt === void 0)
1726
1759
  return options.streamTimeoutMs;