@tangle-network/agent-app 3.0.27 → 3.0.29

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.
@@ -182,5 +182,11 @@ export declare function providerRetryNotice(event: {
182
182
  }): string | undefined;
183
183
  /** A terminal provider wait (`…, reset at <ISO>`, agent-container provider-retry-wait.ts) as one sentence. */
184
184
  export declare function providerResetSentence(message: string): string | undefined;
185
+ /** The typed code for a harness whose model refused its key, so a product can tell it from other stream failures. */
186
+ export declare const MODEL_KEY_REFUSED_CODE = "model.key_refused";
187
+ /** A harness whose model provider refused its key ("Invalid API key", OpenCode's `OPENCODE_ERROR`) as plain words, true
188
+ * both for a newly started box whose harness called the model before its minted key was in place (it recovers within
189
+ * minutes) and for a key that is wrong. The raw error goes to the log and the failure note, never to the person. */
190
+ export declare function modelKeyRefusedSentence(message: string): string | undefined;
185
191
  /** Create a sandbox chat producer that manages chat turn routing with logging and interaction rendering options */
186
192
  export declare function createSandboxChatProducer(options: SandboxChatProducerOptions): ChatTurnRouteProducer;
@@ -1511,6 +1511,11 @@ function providerResetSentence(message) {
1511
1511
  const cause = message.split("; the provider asked")[0]?.trim();
1512
1512
  return `The model provider refused the call (${cause}); try again after ${utcTime(at)} on ${at.toISOString().slice(0, 10)}.`;
1513
1513
  }
1514
+ var MODEL_KEY_REFUSED_CODE = "model.key_refused";
1515
+ function modelKeyRefusedSentence(message) {
1516
+ if (!/\binvalid api key\b|\b401\b[^\n]*\b(?:unauthori[sz]ed|api key)\b/i.test(message)) return void 0;
1517
+ return "The assistant's model refused its access key, so this message was not answered. If the assistant has just started, send it again in a minute; if this repeats, tell the team.";
1518
+ }
1514
1519
  function sandboxStreamErrorMessage(data) {
1515
1520
  const record = asRecord(data);
1516
1521
  const message = asString(record?.message) ?? asString(record?.error);
@@ -1527,6 +1532,15 @@ function sandboxStreamErrorCode(data) {
1527
1532
  function toProducerWireEvent(event) {
1528
1533
  return event;
1529
1534
  }
1535
+ function plainFailureEvent(event) {
1536
+ const data = asRecord(event.data);
1537
+ if (!data || !["error", "warning", "done", "session.run.failed"].includes(String(event.type))) return event;
1538
+ const reasons = ["message", "error", "reason"].filter((key) => typeof data[key] === "string" && data[key]);
1539
+ const raw = reasons.map((key) => data[key]).join(" | ");
1540
+ const plain = raw ? providerResetSentence(raw) ?? modelKeyRefusedSentence(raw) : void 0;
1541
+ if (!plain) return event;
1542
+ return { ...event, data: { ...data, ...Object.fromEntries(reasons.map((key) => [key, plain])), details: { ...asRecord(data.details), raw } } };
1543
+ }
1530
1544
  function sandboxStreamFailureDiagnostic(error) {
1531
1545
  const streamMessage = error?.streamMessage;
1532
1546
  const message = typeof streamMessage === "string" ? streamMessage : error instanceof Error ? error.message : "Sandbox stream failed";
@@ -1539,7 +1553,8 @@ function sandboxStreamFailureDiagnostic(error) {
1539
1553
  diagnosticText = "[unserializable diagnostics]";
1540
1554
  }
1541
1555
  }
1542
- const userMessage = providerResetSentence(message) ?? [
1556
+ const keyRefused = modelKeyRefusedSentence(message);
1557
+ const userMessage = providerResetSentence(message) ?? keyRefused ?? [
1543
1558
  "The sandbox model stream stopped before a clean completion.",
1544
1559
  `Error: ${message}`,
1545
1560
  "Please retry. If it repeats, send these support details to the team."
@@ -1553,6 +1568,7 @@ function sandboxStreamFailureDiagnostic(error) {
1553
1568
  } else if (error instanceof ModelFailoverExhaustedError) {
1554
1569
  code = error.upstreamCode ?? code;
1555
1570
  }
1571
+ if (keyRefused) code = MODEL_KEY_REFUSED_CODE;
1556
1572
  return { userMessage, failureNote, code };
1557
1573
  }
1558
1574
  function createSandboxChatProducer(options) {
@@ -1660,7 +1676,9 @@ function createSandboxChatProducer(options) {
1660
1676
  }
1661
1677
  if (event.type === "warning") {
1662
1678
  const message = asString(event.data?.message);
1663
- if (message) {
1679
+ const plainFailure = message && (providerResetSentence(message) ?? modelKeyRefusedSentence(message));
1680
+ if (plainFailure) log("[chat-routes] failure warning folded into its error notice", { code: asString(event.data?.code), error: message });
1681
+ if (message && !plainFailure) {
1664
1682
  projectionState.warningCount += 1;
1665
1683
  const code = asString(event.data?.code);
1666
1684
  const text = code ? `${code}: ${message}` : message;
@@ -1668,7 +1686,7 @@ function createSandboxChatProducer(options) {
1668
1686
  recordPersistedPart(notice, void 0, noticePartKey(notice.id));
1669
1687
  yield { type: "notice", id: notice.id, noticeKind: "warning", text };
1670
1688
  }
1671
- yield toProducerWireEvent(record);
1689
+ yield toProducerWireEvent(plainFailureEvent(record));
1672
1690
  continue;
1673
1691
  }
1674
1692
  if (event.type === "usage") {
@@ -1705,18 +1723,20 @@ function createSandboxChatProducer(options) {
1705
1723
  yield* emitFinalUsage();
1706
1724
  }
1707
1725
  yield* emitTerminalizedTools();
1708
- yield toProducerWireEvent(record);
1726
+ yield toProducerWireEvent(plainFailureEvent(record));
1709
1727
  continue;
1710
1728
  }
1711
1729
  if (event.type === "error") {
1712
1730
  const message = sandboxStreamErrorMessage(event.data);
1713
- const errorContent = providerResetSentence(message) ?? (projectionState.fullText.trim() ? `The sandbox model stream stopped before a clean completion.
1731
+ const keyRefused = modelKeyRefusedSentence(message);
1732
+ if (keyRefused) log("[chat-routes] model key refused", { code: MODEL_KEY_REFUSED_CODE, error: message });
1733
+ const errorContent = providerResetSentence(message) ?? keyRefused ?? (projectionState.fullText.trim() ? `The sandbox model stream stopped before a clean completion.
1714
1734
 
1715
1735
  Error: ${message}` : `The sandbox agent returned an error before producing a visible answer.
1716
1736
 
1717
1737
  Error: ${message}`);
1718
1738
  if (options.errorNotice) {
1719
- yield* emitErrorNotice(errorContent, sandboxStreamErrorCode(event.data));
1739
+ yield* emitErrorNotice(errorContent, keyRefused ? MODEL_KEY_REFUSED_CODE : sandboxStreamErrorCode(event.data));
1720
1740
  } else if (options.includeErrorText !== false) {
1721
1741
  const errorDelta = projectionState.fullText ? `
1722
1742
 
@@ -1727,10 +1747,10 @@ ${errorContent}` : errorContent;
1727
1747
  }
1728
1748
  projectionState.interactionOutcome = "expired";
1729
1749
  yield* emitTerminalizedTools();
1730
- yield toProducerWireEvent(record);
1750
+ yield toProducerWireEvent(plainFailureEvent(record));
1731
1751
  continue;
1732
1752
  }
1733
- yield toProducerWireEvent(record);
1753
+ yield toProducerWireEvent(plainFailureEvent(record));
1734
1754
  }
1735
1755
  yield* drainModelNotices();
1736
1756
  } catch (streamErr) {
@@ -4164,6 +4184,8 @@ export {
4164
4184
  streamWithModelFailover,
4165
4185
  providerRetryNotice,
4166
4186
  providerResetSentence,
4187
+ MODEL_KEY_REFUSED_CODE,
4188
+ modelKeyRefusedSentence,
4167
4189
  createSandboxChatProducer,
4168
4190
  withProducerStream,
4169
4191
  cancelChatTurn,
@@ -4177,4 +4199,4 @@ export {
4177
4199
  createChatTurnRoutes,
4178
4200
  streamChatRouteAsSandboxEvents
4179
4201
  };
4180
- //# sourceMappingURL=chunk-5OE6SCHS.js.map
4202
+ //# sourceMappingURL=chunk-LRUH36LD.js.map