@tangle-network/agent-app 0.60.131 → 0.60.132

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.
@@ -3,7 +3,7 @@ import {
3
3
  createPlatformBalanceManager,
4
4
  createTcloudKeyProvisioner,
5
5
  createWorkspaceKeyManager
6
- } from "../chunk-LJDMPYGA.js";
6
+ } from "../chunk-YJHE73TF.js";
7
7
  export {
8
8
  createIdentityBoundWorkspaceKeyManager,
9
9
  createPlatformBalanceManager,
@@ -42,7 +42,7 @@ import {
42
42
  flattenHistory,
43
43
  readSandboxBinaryBytes,
44
44
  statSandboxFileSize
45
- } from "../chunk-JGLK5RDK.js";
45
+ } from "../chunk-JIXM57JM.js";
46
46
  import "../chunk-4LBCTFBP.js";
47
47
  import "../chunk-WVESWAJJ.js";
48
48
  import "../chunk-LWSJK546.js";
@@ -425,7 +425,7 @@ var DEFAULT_TIMEOUT_MS = 5 * 6e4;
425
425
  var TASK_LIMIT = 2e4;
426
426
  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 whole task and the result you need; the sandbox agent does it and returns its answer. Takes seconds to minutes, so use it only when the answer needs the computer.";
427
427
  function sandboxPromptRunner(shell, prompt = {}) {
428
- return (box, task, run) => runSandboxPrompt(shell, box, task, { ...prompt, ...run, disallowQuestions: true });
428
+ return (box, task, { signal, timeoutMs }) => runSandboxPrompt(shell, box, task, { ...prompt, signal, timeoutMs, disallowQuestions: true });
429
429
  }
430
430
  function createSandboxRunTool(options) {
431
431
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
@@ -444,7 +444,13 @@ function createSandboxRunTool(options) {
444
444
  required: ["task"],
445
445
  additionalProperties: false
446
446
  },
447
- async run(args) {
447
+ async run(args, context) {
448
+ const emit = (kind, data) => {
449
+ try {
450
+ context?.emit(kind, data);
451
+ } catch {
452
+ }
453
+ };
448
454
  const task = typeof args.task === "string" ? args.task.trim() : "";
449
455
  if (!task || task.length > TASK_LIMIT) {
450
456
  return fail2("invalid_arguments", `task must be 1 to ${TASK_LIMIT} characters`);
@@ -453,22 +459,21 @@ function createSandboxRunTool(options) {
453
459
  const signal = AbortSignal.any([AbortSignal.timeout(timeoutMs), ...options.signal ? [options.signal] : []]);
454
460
  if (options.warm) await options.warm.leases.turn(options.warm.key).catch(() => {
455
461
  });
462
+ const capped = (work) => Promise.race([work, new Promise((_, reject) => {
463
+ if (signal.aborted) reject(signal.reason);
464
+ signal.addEventListener("abort", () => reject(signal.reason), { once: true });
465
+ })]);
456
466
  let box;
457
467
  try {
458
- box = await options.box(signal);
468
+ box = await capped(options.box(signal));
459
469
  } catch (error) {
460
470
  if (error instanceof SandboxRunError) return fail2(error.code, error.message, error.cause);
461
471
  return fail2("sandbox_unavailable", "The sandbox for this workspace could not start, so this work was not done.", error);
462
472
  }
473
+ emit("box_ready", { ms: Date.now() - started });
463
474
  let answer;
464
475
  try {
465
- answer = await Promise.race([
466
- runTask(box, task, { signal, timeoutMs: Math.max(1, timeoutMs - (Date.now() - started)) }),
467
- new Promise((_, reject) => {
468
- if (signal.aborted) reject(signal.reason);
469
- signal.addEventListener("abort", () => reject(signal.reason), { once: true });
470
- })
471
- ]);
476
+ answer = await capped(runTask(box, task, { signal, timeoutMs: Math.max(1, timeoutMs - (Date.now() - started)), emit }));
472
477
  } catch (error) {
473
478
  const timedOut = signal.aborted && !options.signal?.aborted;
474
479
  return fail2("sandbox_failed", timedOut ? `The sandbox did not finish within ${Math.round(timeoutMs / 1e3)} s, so this work was not done.` : "The sandbox run failed, so this work was not done.", error);
@@ -481,7 +486,7 @@ function createSandboxRunTool(options) {
481
486
 
482
487
  // src/sandbox/sandbox-exec-tool.ts
483
488
  var DEFAULT_TIMEOUT_MS2 = 2 * 6e4;
484
- var DEFAULT_OUTPUT_CHARS = 2e4;
489
+ var DEFAULT_OUTPUT_CHARS = 4e3;
485
490
  var COMMAND_LIMIT = 1e4;
486
491
  var SANDBOX_EXEC_DESCRIPTION = "Run one shell command in this workspace's sandbox and get its exit code, stdout and stderr. Use it for the installed toolkits and scripts, file conversion and checks. A non-zero exit code is a result to read and fix, not a reason to stop.";
487
492
  function tail(text, limit) {
@@ -535,7 +540,13 @@ function createSandboxExecTool(options) {
535
540
  required: ["command"],
536
541
  additionalProperties: false
537
542
  },
538
- async run(args) {
543
+ async run(args, context) {
544
+ const emit = (kind, data) => {
545
+ try {
546
+ context?.emit(kind, data);
547
+ } catch {
548
+ }
549
+ };
539
550
  const command = typeof args.command === "string" ? args.command.trim() : "";
540
551
  if (!command || command.length > COMMAND_LIMIT) return fail2("invalid_arguments", `command must be 1 to ${COMMAND_LIMIT} characters`);
541
552
  const refusal = options.allow?.(command);
@@ -546,15 +557,18 @@ function createSandboxExecTool(options) {
546
557
  if (options.warm) await options.warm.leases.turn(options.warm.key).catch(() => {
547
558
  });
548
559
  let box;
560
+ const starting = place(signal);
549
561
  try {
550
- box = await raceAbort(place(signal), signal);
562
+ box = await raceAbort(starting, signal);
551
563
  } catch (error) {
564
+ if (ready === starting) ready = null;
552
565
  if (error instanceof SandboxRunError) {
553
566
  options.onFailure?.(error);
554
567
  throw error;
555
568
  }
556
569
  return fail2("sandbox_unavailable", "The sandbox did not start in time, so the command did not run.", error);
557
570
  }
571
+ emit("box_ready", { ms: Date.now() - started });
558
572
  let result;
559
573
  try {
560
574
  result = await raceAbort(box.exec(command, {
@@ -3305,4 +3319,4 @@ export {
3305
3319
  isTerminalPromptEvent,
3306
3320
  detectInteractiveQuestion
3307
3321
  };
3308
- //# sourceMappingURL=chunk-JGLK5RDK.js.map
3322
+ //# sourceMappingURL=chunk-JIXM57JM.js.map