@tangle-network/agent-app 0.63.13 → 0.63.15

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.
@@ -79,7 +79,7 @@ import {
79
79
  turnCarriesFiles,
80
80
  turnPromptText,
81
81
  withProducerStream
82
- } from "../chunk-IRD2IVX2.js";
82
+ } from "../chunk-UKVLJBP4.js";
83
83
  import "../chunk-KH4QSBNI.js";
84
84
  import {
85
85
  sniffMimeFromName
@@ -87,12 +87,12 @@ import {
87
87
  import "../chunk-RN4WPTBH.js";
88
88
  import "../chunk-WP2GYFZ4.js";
89
89
  import "../chunk-4DBHC63F.js";
90
+ import "../chunk-MM6RLOXF.js";
91
+ import "../chunk-ZXZU32Q4.js";
92
+ import "../chunk-F4TUZYMX.js";
90
93
  import {
91
94
  redactErrorMessage
92
95
  } from "../chunk-MH74DY2I.js";
93
- import "../chunk-MM6RLOXF.js";
94
- import "../chunk-562GGG3L.js";
95
- import "../chunk-F4TUZYMX.js";
96
96
  import {
97
97
  assistantRowIdForTurn,
98
98
  createAssistantDraftWriter,
@@ -8,9 +8,6 @@ import {
8
8
  noteMeasuredTurnFacts,
9
9
  readableTurnFailure
10
10
  } from "./chunk-4DBHC63F.js";
11
- import {
12
- redactErrorMessage
13
- } from "./chunk-MH74DY2I.js";
14
11
  import {
15
12
  currentD1QueryCounter,
16
13
  withD1QueryCount
@@ -31,7 +28,10 @@ import {
31
28
  sandboxPromptRunner,
32
29
  streamSandboxPrompt,
33
30
  turnStorageBindings
34
- } from "./chunk-562GGG3L.js";
31
+ } from "./chunk-ZXZU32Q4.js";
32
+ import {
33
+ redactErrorMessage
34
+ } from "./chunk-MH74DY2I.js";
35
35
  import {
36
36
  addStepFinishUsage,
37
37
  assistantRowIdForTurn,
@@ -3912,4 +3912,4 @@ export {
3912
3912
  createChatTurnRoutes,
3913
3913
  streamChatRouteAsSandboxEvents
3914
3914
  };
3915
- //# sourceMappingURL=chunk-IRD2IVX2.js.map
3915
+ //# sourceMappingURL=chunk-UKVLJBP4.js.map
@@ -1,3 +1,6 @@
1
+ import {
2
+ redactErrorMessage
3
+ } from "./chunk-MH74DY2I.js";
1
4
  import {
2
5
  SANDBOX_BACKING_CONTAINER_MISSING_CODE,
3
6
  SandboxTransientDeadlineError,
@@ -3641,12 +3644,49 @@ function lastNonPromptTextPart(parts, promptTexts) {
3641
3644
  return values.at(-1) ?? "";
3642
3645
  }
3643
3646
  async function collectSandboxPromptText(events, message, history) {
3647
+ const { answer, observation } = await collectSandboxPrompt(events, message, history);
3648
+ if (!answer) throw noAnswerError(observation);
3649
+ return answer;
3650
+ }
3651
+ var OBSERVED_TYPE_LIMIT = 16;
3652
+ function record(value) {
3653
+ return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
3654
+ }
3655
+ function failureText(data) {
3656
+ const error = data?.error;
3657
+ const text = [record(error)?.message, error, data?.message, data?.code].find((value) => typeof value === "string" && value.trim().length > 0);
3658
+ return text === void 0 ? void 0 : redactErrorMessage(text);
3659
+ }
3660
+ function observePromptEvent(observation, type, data) {
3661
+ const key = type === "message.part.updated" ? `${type}(${String(record(data?.part)?.type ?? "unknown")})` : type;
3662
+ if (observation.types.has(key) || observation.types.size < OBSERVED_TYPE_LIMIT) {
3663
+ observation.types.set(key, (observation.types.get(key) ?? 0) + 1);
3664
+ }
3665
+ const status = data?.status;
3666
+ const failed = type === "error" || type === "done" && (status === "failed" || status === "cancelled") || type === "result" && (data?.success === false || status === "failed" || status === "error" || Boolean(data?.error));
3667
+ const text = failed ? failureText(data) : void 0;
3668
+ if (isTerminalPromptEvent({ type, data }) || type === "done" && text) observation.terminal = true;
3669
+ if (failed && !observation.failure && (text || type !== "done")) observation.failure = text ?? `${type} event without a message`;
3670
+ }
3671
+ function noAnswerError(observation) {
3672
+ const types = Array.from(observation.types, ([type, count]) => `${type}\xD7${count}`).join(", ") || "no events";
3673
+ const cause = new Error(`Sandbox prompt stream carried ${types}; ${observation.terminal ? "it reached a terminal event" : "no terminal event"}.`);
3674
+ const failure = observation.failure;
3675
+ if (!observation.terminal) {
3676
+ return new SandboxRunError("sandbox_unconfirmed", `The computer stopped reporting before its completion was confirmed. Its work may still be running.${failure ? ` ${failure}` : ""}`, { cause });
3677
+ }
3678
+ if (failure) return new SandboxRunError("sandbox_failed", `The computer reported a failed execution: ${failure}`, { cause });
3679
+ return new SandboxRunError("sandbox_empty", "The sandbox finished without an answer.", { cause });
3680
+ }
3681
+ async function collectSandboxPrompt(events, message, history) {
3644
3682
  let finalText = "";
3645
3683
  const textParts = /* @__PURE__ */ new Map();
3646
3684
  let anonymousTextPart = 0;
3685
+ const observation = { terminal: false, types: /* @__PURE__ */ new Map() };
3647
3686
  for await (const rawEvent of events) {
3648
3687
  const event = rawEvent;
3649
3688
  if (!event.type) continue;
3689
+ observePromptEvent(observation, event.type, record(event.data));
3650
3690
  if (event.type === "message.part.updated") {
3651
3691
  const part = event.data?.part;
3652
3692
  const delta = typeof event.data?.delta === "string" ? event.data.delta : null;
@@ -3660,22 +3700,12 @@ async function collectSandboxPromptText(events, message, history) {
3660
3700
  if (resultText?.trim()) finalText = resultText;
3661
3701
  }
3662
3702
  }
3663
- return finalText || lastNonPromptTextPart(textParts, dispatchedPromptTexts(message, history));
3703
+ const answer = finalText || lastNonPromptTextPart(textParts, dispatchedPromptTexts(message, history));
3704
+ return { answer, observation };
3664
3705
  }
3665
3706
  async function runSandboxPrompt(shell, box, message, options) {
3666
- let terminal = false;
3667
- let failed = false;
3668
- async function* observed() {
3669
- for await (const event of streamSandboxPrompt(shell, box, message, options)) {
3670
- if (isTerminalPromptEvent(event)) terminal = true;
3671
- const raw = event;
3672
- if (raw.type === "error" || raw.type === "result" && (raw.data?.success === false || raw.data?.status === "failed" || raw.data?.status === "error" || Boolean(raw.data?.error))) failed = true;
3673
- yield event;
3674
- }
3675
- }
3676
- const answer = await collectSandboxPromptText(observed(), message, options?.history);
3677
- if (!terminal) throw new SandboxRunError("sandbox_unconfirmed", "The computer stopped reporting before its completion was confirmed. Its work may still be running.");
3678
- if (failed) throw new SandboxRunError("sandbox_failed", "The computer reported a failed execution.");
3707
+ const { answer, observation } = await collectSandboxPrompt(streamSandboxPrompt(shell, box, message, options), message, options?.history);
3708
+ if (!answer || !observation.terminal || observation.failure) throw noAnswerError(observation);
3679
3709
  return answer;
3680
3710
  }
3681
3711
  async function driveSandboxTurn(shell, box, message, options) {
@@ -3880,4 +3910,4 @@ export {
3880
3910
  sandboxPromptRunner,
3881
3911
  createSandboxRunTool
3882
3912
  };
3883
- //# sourceMappingURL=chunk-562GGG3L.js.map
3913
+ //# sourceMappingURL=chunk-ZXZU32Q4.js.map