@tangle-network/agent-app 3.0.26 → 3.0.28

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);
@@ -1539,7 +1544,8 @@ function sandboxStreamFailureDiagnostic(error) {
1539
1544
  diagnosticText = "[unserializable diagnostics]";
1540
1545
  }
1541
1546
  }
1542
- const userMessage = providerResetSentence(message) ?? [
1547
+ const keyRefused = modelKeyRefusedSentence(message);
1548
+ const userMessage = providerResetSentence(message) ?? keyRefused ?? [
1543
1549
  "The sandbox model stream stopped before a clean completion.",
1544
1550
  `Error: ${message}`,
1545
1551
  "Please retry. If it repeats, send these support details to the team."
@@ -1553,6 +1559,7 @@ function sandboxStreamFailureDiagnostic(error) {
1553
1559
  } else if (error instanceof ModelFailoverExhaustedError) {
1554
1560
  code = error.upstreamCode ?? code;
1555
1561
  }
1562
+ if (keyRefused) code = MODEL_KEY_REFUSED_CODE;
1556
1563
  return { userMessage, failureNote, code };
1557
1564
  }
1558
1565
  function createSandboxChatProducer(options) {
@@ -1710,13 +1717,15 @@ function createSandboxChatProducer(options) {
1710
1717
  }
1711
1718
  if (event.type === "error") {
1712
1719
  const message = sandboxStreamErrorMessage(event.data);
1713
- const errorContent = providerResetSentence(message) ?? (projectionState.fullText.trim() ? `The sandbox model stream stopped before a clean completion.
1720
+ const keyRefused = modelKeyRefusedSentence(message);
1721
+ if (keyRefused) log("[chat-routes] model key refused", { code: MODEL_KEY_REFUSED_CODE, error: message });
1722
+ const errorContent = providerResetSentence(message) ?? keyRefused ?? (projectionState.fullText.trim() ? `The sandbox model stream stopped before a clean completion.
1714
1723
 
1715
1724
  Error: ${message}` : `The sandbox agent returned an error before producing a visible answer.
1716
1725
 
1717
1726
  Error: ${message}`);
1718
1727
  if (options.errorNotice) {
1719
- yield* emitErrorNotice(errorContent, sandboxStreamErrorCode(event.data));
1728
+ yield* emitErrorNotice(errorContent, keyRefused ? MODEL_KEY_REFUSED_CODE : sandboxStreamErrorCode(event.data));
1720
1729
  } else if (options.includeErrorText !== false) {
1721
1730
  const errorDelta = projectionState.fullText ? `
1722
1731
 
@@ -3649,22 +3658,20 @@ function createDefaultChatBackend(projectId, env, config, bindings, modelPolicy)
3649
3658
  sandbox: async (args) => {
3650
3659
  const model = modelFor(args);
3651
3660
  if (modelPolicy) await assertPolicy({ kind: "model", id: model, ...modelPolicy });
3661
+ const own = config.providers?.[model];
3662
+ const provider = typeof own === "function" ? await own(args) : own;
3652
3663
  const box = await acquire(args);
3653
3664
  return {
3654
3665
  model,
3655
3666
  modelPolicy,
3656
3667
  modelFailover: false,
3657
3668
  errorNotice: true,
3658
- openEvents: async function* ({ model: model2, signal }) {
3659
- const own = config.providers?.[model2];
3660
- const provider = typeof own === "function" ? await own(args) : own;
3661
- yield* streamSandboxPrompt(
3662
- provider ? { ...shell, provider } : shell,
3663
- box,
3664
- normalizeChatPromptForSandbox(args.prompt),
3665
- { ...promptOptions(args), model: model2, signal }
3666
- );
3667
- }
3669
+ openEvents: ({ signal }) => streamSandboxPrompt(
3670
+ provider ? { ...shell, provider } : shell,
3671
+ box,
3672
+ normalizeChatPromptForSandbox(args.prompt),
3673
+ { ...promptOptions(args), model, signal }
3674
+ )
3668
3675
  };
3669
3676
  }
3670
3677
  };
@@ -4166,6 +4173,8 @@ export {
4166
4173
  streamWithModelFailover,
4167
4174
  providerRetryNotice,
4168
4175
  providerResetSentence,
4176
+ MODEL_KEY_REFUSED_CODE,
4177
+ modelKeyRefusedSentence,
4169
4178
  createSandboxChatProducer,
4170
4179
  withProducerStream,
4171
4180
  cancelChatTurn,
@@ -4179,4 +4188,4 @@ export {
4179
4188
  createChatTurnRoutes,
4180
4189
  streamChatRouteAsSandboxEvents
4181
4190
  };
4182
- //# sourceMappingURL=chunk-IV2QLOA2.js.map
4191
+ //# sourceMappingURL=chunk-4XFPMDIM.js.map