@tangle-network/agent-app 0.63.5 → 0.63.7

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.
Files changed (41) hide show
  1. package/dist/assistant/index.js +1 -1
  2. package/dist/chat-routes/default-backend.d.ts +46 -0
  3. package/dist/chat-routes/dispatch-first.d.ts +3 -2
  4. package/dist/chat-routes/index.d.ts +1 -0
  5. package/dist/chat-routes/index.js +13 -345
  6. package/dist/chat-routes/index.js.map +1 -1
  7. package/dist/chat-routes/route-prewarm.d.ts +2 -0
  8. package/dist/chat-routes/route-storage.d.ts +13 -4
  9. package/dist/chat-routes/sandbox-model-source.d.ts +1 -0
  10. package/dist/chat-routes/turn-ownership.d.ts +2 -1
  11. package/dist/chat-routes/turn-route-contracts.d.ts +21 -5
  12. package/dist/{chunk-XYSKMHWG.js → chunk-42QCR4CV.js} +548 -15
  13. package/dist/chunk-42QCR4CV.js.map +1 -0
  14. package/dist/{chunk-JRTWTADT.js → chunk-E3AOUTIR.js} +5 -2
  15. package/dist/chunk-E3AOUTIR.js.map +1 -0
  16. package/dist/{chunk-IDG2XR5O.js → chunk-EKXG4JSN.js} +2 -2
  17. package/dist/chunk-EKXG4JSN.js.map +1 -0
  18. package/dist/{chunk-4CALWPN5.js → chunk-L6BS2XTE.js} +20 -16
  19. package/dist/chunk-L6BS2XTE.js.map +1 -0
  20. package/dist/{chunk-YCMVNXAX.js → chunk-NUWSPR5O.js} +2 -2
  21. package/dist/{chunk-OCR36QGZ.js → chunk-UVMKP5IK.js} +65 -28
  22. package/dist/chunk-UVMKP5IK.js.map +1 -0
  23. package/dist/public-consultation/index.js +3 -3
  24. package/dist/runtime/index.js +2 -2
  25. package/dist/runtime/router-turn.d.ts +2 -2
  26. package/dist/runtime/router-turn.js +1 -1
  27. package/dist/sandbox/index.js +1 -1
  28. package/dist/sandbox/prompt-events.d.ts +1 -1
  29. package/dist/sandbox/sandbox-run-error.d.ts +8 -0
  30. package/dist/sandbox/sandbox-run-tool.d.ts +5 -9
  31. package/dist/signoff/cli.js +1 -1
  32. package/dist/signoff/index.js +1 -1
  33. package/dist/web-react/durable-plan-flow.d.ts +10 -0
  34. package/dist/web-react/index.js +1 -1
  35. package/package.json +1 -1
  36. package/dist/chunk-4CALWPN5.js.map +0 -1
  37. package/dist/chunk-IDG2XR5O.js.map +0 -1
  38. package/dist/chunk-JRTWTADT.js.map +0 -1
  39. package/dist/chunk-OCR36QGZ.js.map +0 -1
  40. package/dist/chunk-XYSKMHWG.js.map +0 -1
  41. /package/dist/{chunk-YCMVNXAX.js.map → chunk-NUWSPR5O.js.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  runRouterTurn
3
- } from "./chunk-IDG2XR5O.js";
3
+ } from "./chunk-EKXG4JSN.js";
4
4
 
5
5
  // src/runtime/protected-model.ts
6
6
  import {
@@ -219,4 +219,4 @@ export {
219
219
  createRouterProtectedModelPort,
220
220
  runProtectedRouterTurn
221
221
  };
222
- //# sourceMappingURL=chunk-YCMVNXAX.js.map
222
+ //# sourceMappingURL=chunk-NUWSPR5O.js.map
@@ -543,7 +543,7 @@ function createSandboxPrewarmer(shell, options) {
543
543
  };
544
544
  }
545
545
 
546
- // src/sandbox/sandbox-run-tool.ts
546
+ // src/sandbox/sandbox-run-error.ts
547
547
  var SandboxRunError = class extends Error {
548
548
  constructor(code, message, options) {
549
549
  super(message, options);
@@ -552,18 +552,27 @@ var SandboxRunError = class extends Error {
552
552
  }
553
553
  code;
554
554
  };
555
+
556
+ // src/sandbox/sandbox-run-tool.ts
555
557
  var DEFAULT_TIMEOUT_MS = 5 * 6e4;
556
558
  var TASK_LIMIT = 2e4;
557
559
  var SANDBOX_RUN_DESCRIPTION = "Run work that needs a computer in this workspace's sandbox: executing code or scripts, reading or converting PDFs, spreadsheets and archives, filling forms with the installed toolkits, or editing many files. Describe the member's requirements, file paths and exact field names, not model-written code; the sandbox agent writes and runs the code and returns its answer. Takes seconds to minutes, so use it only when the answer needs the computer.";
558
560
  function sandboxPromptRunner(shell, prompt = {}) {
559
- return (box, task, { signal, timeoutMs, trace, span }) => runSandboxPrompt(shell, box, task, {
560
- ...prompt,
561
- signal,
562
- timeoutMs,
563
- disallowQuestions: true,
564
- ...trace ? { trace } : {},
565
- ...span ? { traceParent: span } : {}
566
- });
561
+ return async (box, task, { callId, signal, timeoutMs, trace, span }) => {
562
+ const parent = prompt.executionId?.trim() || prompt.turnId?.trim();
563
+ const identity = parent ? new TextEncoder().encode(JSON.stringify([parent, prompt.sessionId, callId?.trim() || crypto.randomUUID()])) : void 0;
564
+ const digest = identity ? await crypto.subtle.digest("SHA-256", identity) : void 0;
565
+ const child = digest ? Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("") : void 0;
566
+ return runSandboxPrompt(shell, box, task, {
567
+ ...prompt,
568
+ ...child ? { executionId: child, turnId: child } : {},
569
+ signal,
570
+ timeoutMs,
571
+ disallowQuestions: true,
572
+ ...trace ? { trace } : {},
573
+ ...span ? { traceParent: span } : {}
574
+ });
575
+ };
567
576
  }
568
577
  function createSandboxRunTool(options) {
569
578
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
@@ -634,8 +643,9 @@ Your part of it:
634
643
  ...context?.span ? { span: context.span } : {}
635
644
  }));
636
645
  } catch (error) {
646
+ if (error instanceof SandboxRunError) return fail2(error.code, error.message, error.cause);
637
647
  const timedOut = signal.aborted && !options.signal?.aborted && !context?.signal?.aborted;
638
- return fail2("sandbox_failed", timedOut ? `The computer step did not return an answer within ${Math.round(timeoutMs / 1e3)} s. Its completion could not be confirmed.` : "The computer step failed to return an answer. Its completion could not be confirmed.", error);
648
+ return fail2("sandbox_unconfirmed", timedOut ? `The computer step did not return an answer within ${Math.round(timeoutMs / 1e3)} s. Its completion could not be confirmed.` : "The computer step failed to return an answer. Its completion could not be confirmed.", error);
639
649
  }
640
650
  if (!answer.trim()) return fail2("sandbox_empty", "The sandbox finished without an answer.");
641
651
  return { answer, ms: Date.now() - started };
@@ -886,15 +896,27 @@ ON CONFLICT(id) DO UPDATE SET at = ?2, expires_at = ?3, report = ?4`;
886
896
 
887
897
  // src/chat-routes/route-storage.ts
888
898
  function createDefaultTurnLock(store) {
889
- return createDurableTurnLock({ ...store.lock, locationHint: store.region, scopeOf: () => "thread" });
899
+ return createDurableTurnLock({ ...store.lock, locationHint: store.region, scopeOf: () => "workspace" });
900
+ }
901
+ function turnStorageBindings(options) {
902
+ if (!("append" in options.turnStore)) return options.turnStore;
903
+ const env = options.env;
904
+ const namespace = env?.TURN_STREAM ?? env?.TURN_STREAM_DO;
905
+ if (!env?.DB || !namespace || !env.TURN_STREAM_AUTH_SECRET) return void 0;
906
+ return { db: env.DB, region: env.D1_REGION, lock: { namespace, auth: { secret: env.TURN_STREAM_AUTH_SECRET } } };
890
907
  }
891
908
  function resolveTurnStorage(options) {
892
- const store = options.turnStore;
893
- if ("append" in store) return { ...options, turnStore: store };
909
+ const bindings = turnStorageBindings(options);
910
+ const env = options.env;
911
+ const namespace = env?.TURN_STREAM ?? env?.TURN_STREAM_DO;
912
+ const lockBindings = bindings ?? (namespace && env?.TURN_STREAM_AUTH_SECRET ? {
913
+ region: env.D1_REGION,
914
+ lock: { namespace, auth: { secret: env.TURN_STREAM_AUTH_SECRET } }
915
+ } : void 0);
894
916
  return {
895
- ...options,
896
- turnStore: createD1TurnEventStore(store.db),
897
- turnLock: options.turnLock ?? createDefaultTurnLock(store)
917
+ turnStore: "append" in options.turnStore ? options.turnStore : createD1TurnEventStore(options.turnStore.db),
918
+ turnLock: options.turnLock === false ? void 0 : options.turnLock ?? (lockBindings ? createDefaultTurnLock(lockBindings) : env ? { acquire: () => ({ acquired: false, response: Response.json({ error: "Durable turn locking is not configured", code: "chat.lock_not_configured" }, { status: 503 }) }), release: () => {
919
+ } } : void 0)
898
920
  };
899
921
  }
900
922
 
@@ -3383,8 +3405,8 @@ function classifySeveredStream(event) {
3383
3405
  return { kind: "step-finish", reason, severed: SEVERED_FINISH_REASONS.has(reason) };
3384
3406
  }
3385
3407
  function isTerminalPromptEvent(event) {
3386
- const t = asPlainRecord(event)?.type;
3387
- return t === "result" || t === "done";
3408
+ const root = asPlainRecord(event);
3409
+ return root?.type === "result" || root?.type === "done" && asPlainRecord(root.data)?.status !== "failed";
3388
3410
  }
3389
3411
  function detectInteractiveQuestion(event) {
3390
3412
  const root = asPlainRecord(event);
@@ -3451,9 +3473,14 @@ async function* resendRefusedDispatch(dispatch, signal) {
3451
3473
  }
3452
3474
  }
3453
3475
  async function* streamSandboxPrompt(shell, box, message, options) {
3454
- options?.signal?.throwIfAborted();
3455
- const backend = await resolveSandboxPromptBackend(shell, options ?? {}, "streamSandboxPrompt");
3456
- options?.signal?.throwIfAborted();
3476
+ let backend;
3477
+ try {
3478
+ options?.signal?.throwIfAborted();
3479
+ backend = await resolveSandboxPromptBackend(shell, options ?? {}, "streamSandboxPrompt");
3480
+ options?.signal?.throwIfAborted();
3481
+ } catch (error) {
3482
+ throw new SandboxRunError("sandbox_unavailable", "The sandbox prompt was not dispatched because its configuration or admission was refused.", { cause: error });
3483
+ }
3457
3484
  const prompt = typeof message === "string" ? flattenHistory(message, options?.history) : mergeHistoryIntoParts(message, options?.history);
3458
3485
  const dispatch = () => options?.detach ? detachedSandboxPromptEvents(box, prompt, options, backend) : box.streamPrompt(prompt, {
3459
3486
  sessionId: options?.sessionId,
@@ -3549,11 +3576,20 @@ async function collectSandboxPromptText(events, message, history) {
3549
3576
  return finalText || lastNonPromptTextPart(textParts, dispatchedPromptTexts(message, history));
3550
3577
  }
3551
3578
  async function runSandboxPrompt(shell, box, message, options) {
3552
- return collectSandboxPromptText(
3553
- streamSandboxPrompt(shell, box, message, options),
3554
- message,
3555
- options?.history
3556
- );
3579
+ let terminal = false;
3580
+ let failed = false;
3581
+ async function* observed() {
3582
+ for await (const event of streamSandboxPrompt(shell, box, message, options)) {
3583
+ if (isTerminalPromptEvent(event)) terminal = true;
3584
+ const raw = event;
3585
+ 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;
3586
+ yield event;
3587
+ }
3588
+ }
3589
+ const answer = await collectSandboxPromptText(observed(), message, options?.history);
3590
+ if (!terminal) throw new SandboxRunError("sandbox_unconfirmed", "The computer stopped reporting before its completion was confirmed. Its work may still be running.");
3591
+ if (failed) throw new SandboxRunError("sandbox_failed", "The computer reported a failed execution.");
3592
+ return answer;
3557
3593
  }
3558
3594
  async function driveSandboxTurn(shell, box, message, options) {
3559
3595
  const backend = await resolveSandboxPromptBackend(shell, options, "driveSandboxTurn");
@@ -3677,6 +3713,7 @@ export {
3677
3713
  DEFAULT_WARM_RECEIPT_TABLE,
3678
3714
  WARM_RECEIPT_TABLE_DDL,
3679
3715
  createD1WarmReceiptStore,
3716
+ turnStorageBindings,
3680
3717
  resolveTurnStorage,
3681
3718
  isAutomatedPrewarmRequest,
3682
3719
  createWorkspacePrewarmRoute,
@@ -3739,6 +3776,7 @@ export {
3739
3776
  classifySeveredStream,
3740
3777
  isTerminalPromptEvent,
3741
3778
  detectInteractiveQuestion,
3779
+ SandboxRunError,
3742
3780
  SANDBOX_DISPATCH_TRANSIENT_DEADLINE_MS,
3743
3781
  streamSandboxPrompt,
3744
3782
  collectSandboxPromptText,
@@ -3751,9 +3789,8 @@ export {
3751
3789
  storeSecret,
3752
3790
  deleteSecret,
3753
3791
  mintSandboxScopedToken,
3754
- SandboxRunError,
3755
3792
  SANDBOX_RUN_DESCRIPTION,
3756
3793
  sandboxPromptRunner,
3757
3794
  createSandboxRunTool
3758
3795
  };
3759
- //# sourceMappingURL=chunk-OCR36QGZ.js.map
3796
+ //# sourceMappingURL=chunk-UVMKP5IK.js.map