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/README.md CHANGED
@@ -280,6 +280,8 @@ Optional per-request knobs live on `payload` (`GenericPayload`):
280
280
  - `payload.streamTimeoutMs`: `number` - OpenRouter-only: total wall-clock budget per streaming attempt (default: 600000).
281
281
  - `payload.streamDeadlineAt`: `number` - OpenRouter-only: absolute deadline (epoch ms) for the whole call **including retries** — the caller's turn budget. Each attempt gets `min(streamTimeoutMs, deadline - now)`, and once under 10s remain the call fails fast instead of starting a generation that cannot be delivered. Use it whenever the caller has its own timeout: a per-attempt budget alone is re-granted on every retry and can outlive that timeout.
282
282
 
283
+ When a streaming attempt is cut at its **total deadline** and prose has already arrived, the partial answer is returned with `truncated: true` on the response rather than discarded — those tokens were generated and billed, so throwing them away costs money and gives the user nothing. Surface such a reply as incomplete. Salvage never applies to tool-call turns (half-streamed arguments are unparseable JSON), to stalls (the provider died mid-thought), or to caller aborts. When nothing is salvageable, the discard is logged with an approximate token count — aborted attempts never receive OpenRouter's `usage` chunk, so that log line is the only record of the wasted spend.
284
+
283
285
  OpenRouter retries also perform **moderation eviction**: a provider content-moderation rejection (e.g. "Upstream error from Alibaba: Output data may contain inappropriate content.") is deterministic for a given payload, so on the first one the refusing provider is removed from the request's provider preferences (`ignore` += slug, `order` -= slug) and every remaining attempt reroutes to the next provider. Non-moderation errors retry with unchanged preferences, and `fallbackModel` still applies if the whole pool refuses.
284
286
  - `payload.signal`: `AbortSignal` - Caller-supplied cancellation. When it aborts, the in-flight provider request is cancelled and `callWithRetries` **rejects immediately — it does not retry or fall back** (both the retry loop and the fallback branch bail on `signal.aborted`). Threaded to the underlying fetch/axios/SDK call of each provider.
285
287
 
package/dist/index.d.mts CHANGED
@@ -184,6 +184,15 @@ interface ParsedResponseMessage {
184
184
  * mismatch with the requested model's provider reveals the fallback.
185
185
  */
186
186
  provider?: string;
187
+ /**
188
+ * True when the answer is INCOMPLETE: the streamed generation was cut at the
189
+ * caller's deadline and the partial prose is returned instead of discarded.
190
+ * Content is mid-sentence (or mid-file) by definition — surface it to the
191
+ * end user as truncated rather than presenting it as a finished answer.
192
+ * Never set on tool-call turns (a half-streamed arguments fragment can't be
193
+ * salvaged) and never on a normal completion.
194
+ */
195
+ truncated?: boolean;
187
196
  usage: {
188
197
  prompt_tokens: number;
189
198
  completion_tokens: number;
package/dist/index.d.ts CHANGED
@@ -184,6 +184,15 @@ interface ParsedResponseMessage {
184
184
  * mismatch with the requested model's provider reveals the fallback.
185
185
  */
186
186
  provider?: string;
187
+ /**
188
+ * True when the answer is INCOMPLETE: the streamed generation was cut at the
189
+ * caller's deadline and the partial prose is returned instead of discarded.
190
+ * Content is mid-sentence (or mid-file) by definition — surface it to the
191
+ * end user as truncated rather than presenting it as a finished answer.
192
+ * Never set on tool-call turns (a half-streamed arguments fragment can't be
193
+ * salvaged) and never on a normal completion.
194
+ */
195
+ truncated?: boolean;
187
196
  usage: {
188
197
  prompt_tokens: number;
189
198
  completion_tokens: number;
package/dist/index.js CHANGED
@@ -1493,7 +1493,9 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1493
1493
  var _a, _b, _c, _d, _e, _f, _g;
1494
1494
  const controller = new AbortController();
1495
1495
  let abortReason = null;
1496
- const abortWith = (reason) => {
1496
+ let abortKind = null;
1497
+ const abortWith = (kind, reason) => {
1498
+ abortKind = kind;
1497
1499
  abortReason = reason;
1498
1500
  controller.abort();
1499
1501
  };
@@ -1505,6 +1507,7 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1505
1507
  const totalTimer = unref(
1506
1508
  setTimeout(
1507
1509
  () => abortWith(
1510
+ "deadline",
1508
1511
  `OpenRouter stream exceeded total deadline of ${streamTimeoutMs}ms`
1509
1512
  ),
1510
1513
  streamTimeoutMs
@@ -1516,6 +1519,7 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1516
1519
  stallTimer = unref(
1517
1520
  setTimeout(
1518
1521
  () => abortWith(
1522
+ "stall",
1519
1523
  `OpenRouter stream stalled: no useful chunk for ${chunkTimeoutMs}ms`
1520
1524
  ),
1521
1525
  chunkTimeoutMs
@@ -1682,7 +1686,31 @@ async function callOpenRouterStream(id, payload, streamTimeoutMs = OPENROUTER_ST
1682
1686
  });
1683
1687
  } catch (error2) {
1684
1688
  if (abortReason && !(signal == null ? void 0 : signal.aborted)) {
1685
- logger_default.error(id, abortReason);
1689
+ const kept = paragraph.trim();
1690
+ if (abortKind === "deadline" && kept && !toolCalls.length) {
1691
+ try {
1692
+ const message = finalizeOpenRouterMessage(id, {
1693
+ content: kept,
1694
+ toolCalls: [],
1695
+ reasoning,
1696
+ reasoningDetails: reasoningDetails.length ? reasoningDetails : void 0,
1697
+ provider,
1698
+ usage,
1699
+ forLog: () => JSON.stringify({ provider, kept: kept.slice(0, 500) })
1700
+ });
1701
+ message.truncated = true;
1702
+ logger_default.log(
1703
+ id,
1704
+ `${abortReason} \u2014 returning truncated answer (${kept.length} chars, ~${estimateTokens(kept)} tokens kept)`
1705
+ );
1706
+ return message;
1707
+ } catch (e) {
1708
+ }
1709
+ }
1710
+ logger_default.error(
1711
+ id,
1712
+ `${abortReason} \u2014 discarding ~${estimateTokens(paragraph + reasoning)} generated tokens (content ${paragraph.length} chars, reasoning ${reasoning.length} chars, ${dataChunks} chunks)`
1713
+ );
1686
1714
  throw new Error(abortReason);
1687
1715
  }
1688
1716
  throw error2;
@@ -1755,6 +1783,7 @@ function moderationEvictionSlug(error2, payload) {
1755
1783
  return fromOrder ? fromOrder.split("/")[0] : display.toLowerCase();
1756
1784
  }
1757
1785
  var MIN_STREAM_ATTEMPT_MS = 1e4;
1786
+ var estimateTokens = (text) => Math.round(text.length / 4);
1758
1787
  function streamAttemptBudgetMs(options) {
1759
1788
  if (options.streamDeadlineAt === void 0)
1760
1789
  return options.streamTimeoutMs;