190proof 1.0.110 → 1.0.111

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
@@ -1720,18 +1720,38 @@ function moderationEvictionSlug(error2, payload) {
1720
1720
  );
1721
1721
  return fromOrder ? fromOrder.split("/")[0] : display.toLowerCase();
1722
1722
  }
1723
+ var MIN_STREAM_ATTEMPT_MS = 1e4;
1724
+ function streamAttemptBudgetMs(options) {
1725
+ if (options.streamDeadlineAt === void 0)
1726
+ return options.streamTimeoutMs;
1727
+ const remaining = options.streamDeadlineAt - Date.now();
1728
+ if (remaining < MIN_STREAM_ATTEMPT_MS)
1729
+ return null;
1730
+ return Math.min(options.streamTimeoutMs, remaining);
1731
+ }
1723
1732
  async function callOpenRouterWithRetries(id, payload, retries = 5, options, signal) {
1724
1733
  const evicted = [];
1725
1734
  return withRetries(
1726
1735
  id,
1727
1736
  "OpenRouter",
1728
- () => (options.streaming ? callOpenRouterStream(
1729
- id,
1730
- payload,
1731
- options.streamTimeoutMs,
1732
- options.chunkTimeoutMs,
1733
- signal
1734
- ) : callOpenRouterNonStreaming(
1737
+ () => (options.streaming ? (() => {
1738
+ const budget = streamAttemptBudgetMs(options);
1739
+ if (budget === null) {
1740
+ const error2 = new Error(
1741
+ "OpenRouter stream skipped: caller deadline leaves too little time for another attempt"
1742
+ );
1743
+ error2.deadlineExceeded = true;
1744
+ logger_default.error(id, error2.message);
1745
+ throw error2;
1746
+ }
1747
+ return callOpenRouterStream(
1748
+ id,
1749
+ payload,
1750
+ budget,
1751
+ options.chunkTimeoutMs,
1752
+ signal
1753
+ );
1754
+ })() : callOpenRouterNonStreaming(
1735
1755
  id,
1736
1756
  payload,
1737
1757
  options.requestTimeoutMs,
@@ -1851,6 +1871,7 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
1851
1871
  {
1852
1872
  streaming: (_b = aiPayload.streaming) != null ? _b : true,
1853
1873
  streamTimeoutMs: (_c = aiPayload.streamTimeoutMs) != null ? _c : OPENROUTER_STREAM_TIMEOUT_MS,
1874
+ streamDeadlineAt: aiPayload.streamDeadlineAt,
1854
1875
  requestTimeoutMs: (_d = aiPayload.requestTimeoutMs) != null ? _d : OPENROUTER_NONSTREAM_TIMEOUT_MS,
1855
1876
  chunkTimeoutMs
1856
1877
  },
@@ -1892,6 +1913,7 @@ export {
1892
1913
  GPTModel,
1893
1914
  GeminiModel,
1894
1915
  GroqModel,
1916
+ MIN_STREAM_ATTEMPT_MS,
1895
1917
  OPENROUTER_NONSTREAM_TIMEOUT_MS,
1896
1918
  OPENROUTER_STREAM_TIMEOUT_MS,
1897
1919
  OpenRouterModel,