@tangle-network/agent-app 3.0.25 → 3.0.27

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.
@@ -175,5 +175,12 @@ export interface SandboxChatProducerOptions {
175
175
  errorNotice?: boolean;
176
176
  log?: (message: string, meta?: Record<string, unknown>) => void;
177
177
  }
178
+ /** A harness's provider retry wait (OpenCode's raw `retry` status) as one sentence: the provider's words and the next attempt. */
179
+ export declare function providerRetryNotice(event: {
180
+ type: string;
181
+ data?: unknown;
182
+ }): string | undefined;
183
+ /** A terminal provider wait (`…, reset at <ISO>`, agent-container provider-retry-wait.ts) as one sentence. */
184
+ export declare function providerResetSentence(message: string): string | undefined;
178
185
  /** Create a sandbox chat producer that manages chat turn routing with logging and interaction rendering options */
179
186
  export declare function createSandboxChatProducer(options: SandboxChatProducerOptions): ChatTurnRouteProducer;
@@ -1498,6 +1498,19 @@ function applyTerminalUsage(reported, usage) {
1498
1498
  if (reported.cacheWriteTokens !== void 0) usage.cacheWriteTokens = reported.cacheWriteTokens;
1499
1499
  if (reported.harnessCostUsd !== void 0) usage.harnessCostUsd = reported.harnessCostUsd;
1500
1500
  }
1501
+ var utcTime = (at) => `${at.toISOString().slice(11, 19)} UTC`;
1502
+ function providerRetryNotice(event) {
1503
+ const retry = event.type === "raw" ? asRecord(asRecord(event.data)?.event) : void 0;
1504
+ if (retry?.type !== "retry" || !(Number(retry.next) > 0)) return void 0;
1505
+ const cause = asString(retry.message)?.trim() || "no reason given";
1506
+ return `The model provider refused the call (${cause}), so the turn retries at ${utcTime(new Date(Number(retry.next)))}.`;
1507
+ }
1508
+ function providerResetSentence(message) {
1509
+ const at = new Date(message.match(/reset at (\d{4}-\d{2}-\d{2}T[\d:.]+Z)/)?.[1] ?? NaN);
1510
+ if (Number.isNaN(at.getTime())) return void 0;
1511
+ const cause = message.split("; the provider asked")[0]?.trim();
1512
+ return `The model provider refused the call (${cause}); try again after ${utcTime(at)} on ${at.toISOString().slice(0, 10)}.`;
1513
+ }
1501
1514
  function sandboxStreamErrorMessage(data) {
1502
1515
  const record = asRecord(data);
1503
1516
  const message = asString(record?.message) ?? asString(record?.error);
@@ -1526,7 +1539,7 @@ function sandboxStreamFailureDiagnostic(error) {
1526
1539
  diagnosticText = "[unserializable diagnostics]";
1527
1540
  }
1528
1541
  }
1529
- const userMessage = [
1542
+ const userMessage = providerResetSentence(message) ?? [
1530
1543
  "The sandbox model stream stopped before a clean completion.",
1531
1544
  `Error: ${message}`,
1532
1545
  "Please retry. If it repeats, send these support details to the team."
@@ -1639,6 +1652,12 @@ function createSandboxChatProducer(options) {
1639
1652
  yield toProducerWireEvent(record);
1640
1653
  continue;
1641
1654
  }
1655
+ const retry = providerRetryNotice(event);
1656
+ if (retry) {
1657
+ const notice = noticePart("warning", `warning-${++projectionState.warningCount}`, retry);
1658
+ recordPersistedPart(notice, void 0, noticePartKey(notice.id));
1659
+ yield { type: "notice", id: notice.id, noticeKind: "warning", text: retry };
1660
+ }
1642
1661
  if (event.type === "warning") {
1643
1662
  const message = asString(event.data?.message);
1644
1663
  if (message) {
@@ -1691,11 +1710,11 @@ function createSandboxChatProducer(options) {
1691
1710
  }
1692
1711
  if (event.type === "error") {
1693
1712
  const message = sandboxStreamErrorMessage(event.data);
1694
- const errorContent = projectionState.fullText.trim() ? `The sandbox model stream stopped before a clean completion.
1713
+ const errorContent = providerResetSentence(message) ?? (projectionState.fullText.trim() ? `The sandbox model stream stopped before a clean completion.
1695
1714
 
1696
1715
  Error: ${message}` : `The sandbox agent returned an error before producing a visible answer.
1697
1716
 
1698
- Error: ${message}`;
1717
+ Error: ${message}`);
1699
1718
  if (options.errorNotice) {
1700
1719
  yield* emitErrorNotice(errorContent, sandboxStreamErrorCode(event.data));
1701
1720
  } else if (options.includeErrorText !== false) {
@@ -3630,17 +3649,19 @@ function createDefaultChatBackend(projectId, env, config, bindings, modelPolicy)
3630
3649
  sandbox: async (args) => {
3631
3650
  const model = modelFor(args);
3632
3651
  if (modelPolicy) await assertPolicy({ kind: "model", id: model, ...modelPolicy });
3652
+ const own = config.providers?.[model];
3653
+ const provider = typeof own === "function" ? await own(args) : own;
3633
3654
  const box = await acquire(args);
3634
3655
  return {
3635
3656
  model,
3636
3657
  modelPolicy,
3637
3658
  modelFailover: false,
3638
3659
  errorNotice: true,
3639
- openEvents: ({ model: model2, signal }) => streamSandboxPrompt(
3640
- config.providers?.[model2] ? { ...shell, provider: config.providers[model2] } : shell,
3660
+ openEvents: ({ signal }) => streamSandboxPrompt(
3661
+ provider ? { ...shell, provider } : shell,
3641
3662
  box,
3642
3663
  normalizeChatPromptForSandbox(args.prompt),
3643
- { ...promptOptions(args), model: model2, signal }
3664
+ { ...promptOptions(args), model, signal }
3644
3665
  )
3645
3666
  };
3646
3667
  }
@@ -4141,6 +4162,8 @@ export {
4141
4162
  MAX_EMPTY_TURN_RETRIES,
4142
4163
  resolveEmptyTurnRetries,
4143
4164
  streamWithModelFailover,
4165
+ providerRetryNotice,
4166
+ providerResetSentence,
4144
4167
  createSandboxChatProducer,
4145
4168
  withProducerStream,
4146
4169
  cancelChatTurn,
@@ -4154,4 +4177,4 @@ export {
4154
4177
  createChatTurnRoutes,
4155
4178
  streamChatRouteAsSandboxEvents
4156
4179
  };
4157
- //# sourceMappingURL=chunk-FYWWQRLA.js.map
4180
+ //# sourceMappingURL=chunk-5OE6SCHS.js.map