@tangle-network/sandbox 0.8.3-develop.20260623071657.8f265f2 → 0.8.3-develop.20260623083050.fc79e13

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.
@@ -937,13 +937,77 @@ interface InstalledTool {
937
937
  /**
938
938
  * Result of an agent prompt.
939
939
  */
940
+ /**
941
+ * Granular outcome of an agent run.
942
+ * - `success` — reached a terminal event with no run-level error and no failed
943
+ * tool. A tool-only turn (no text) succeeds.
944
+ * - `failed` — a run-level error event, or any failed (`isError`) tool, or the
945
+ * stream ended with no terminal event.
946
+ * - `blocked_on_approval` — a tool hit a hub approval gate; resolve it, then
947
+ * re-run. See {@link AgentApprovalRequirement}.
948
+ * - `awaiting_question` — the agent asked a question and the turn ended without
949
+ * an answer. See {@link AgentQuestionRequest}.
950
+ */
951
+ type AgentRunStatus = "success" | "failed" | "blocked_on_approval" | "awaiting_question";
952
+ /**
953
+ * A tool the agent invoked during a run. `isError` flags a failed call
954
+ * (errored, timed out, or rejected — e.g. a hub approval gate). Failed tools
955
+ * are recorded, not dropped, so callers can inspect what the agent attempted.
956
+ */
957
+ interface AgentToolInvocation {
958
+ toolName: string;
959
+ input?: unknown;
960
+ result?: unknown;
961
+ isError?: boolean;
962
+ }
963
+ /**
964
+ * A hub approval gate the agent hit mid-run. Present on a result when
965
+ * `status === "blocked_on_approval"`. Approve with the CLI
966
+ * (`tangle hub approvals approve <approvalId>`) or the hub SDK, then re-run.
967
+ */
968
+ interface AgentApprovalRequirement {
969
+ /**
970
+ * Approval id to act on. `undefined` when the in-sandbox hub bridge did not
971
+ * preserve the structured approval object — surfaced honestly rather than
972
+ * invented; inspect `message` in that case.
973
+ */
974
+ approvalId?: string;
975
+ /** Hub connection the gated tool belongs to, when known. */
976
+ connectionId?: string;
977
+ /** The tool error message that surfaced the gate. */
978
+ message?: string;
979
+ }
980
+ /**
981
+ * A question the agent asked mid-run. Present on a result when
982
+ * `status === "awaiting_question"`. Answer via
983
+ * `box.session(id).answer({ [questionId]: [...selected] })`, then re-run.
984
+ */
985
+ interface AgentQuestionRequest {
986
+ /** Question id to pass to `session.answer`. */
987
+ questionId: string;
988
+ /** The questions payload the agent emitted (prompt + options per entry). */
989
+ questions: unknown;
990
+ }
940
991
  interface PromptResult {
941
- /** Whether the prompt completed successfully */
992
+ /**
993
+ * Whether the run succeeded. Shorthand for `status === "success"`: true only
994
+ * when the run reached a terminal event with no run-level error and no failed
995
+ * tool. (Text presence is no longer part of this — a tool-only turn
996
+ * succeeds.)
997
+ */
942
998
  success: boolean;
999
+ /** Granular run outcome. */
1000
+ status: AgentRunStatus;
943
1001
  /** Agent's response text */
944
1002
  response?: string;
945
- /** Error message if failed */
1003
+ /** Error message when the run did not succeed */
946
1004
  error?: string;
1005
+ /** Tool calls the agent made this run, including failures (`isError`). */
1006
+ toolInvocations?: AgentToolInvocation[];
1007
+ /** Set when `status === "blocked_on_approval"`. */
1008
+ approval?: AgentApprovalRequirement;
1009
+ /** Set when `status === "awaiting_question"`. */
1010
+ question?: AgentQuestionRequest;
947
1011
  /** Trace ID for debugging */
948
1012
  traceId?: string;
949
1013
  /** Duration in milliseconds */
@@ -1251,6 +1315,15 @@ interface WaitForOptions {
1251
1315
  */
1252
1316
  onProgress?: (event: ProvisionEvent) => void;
1253
1317
  }
1318
+ /**
1319
+ * Options for resuming a stopped sandbox.
1320
+ */
1321
+ interface ResumeOptions {
1322
+ /** Timeout in milliseconds for the resume request */
1323
+ timeoutMs?: number;
1324
+ /** AbortSignal for cancellation */
1325
+ signal?: AbortSignal;
1326
+ }
1254
1327
  /**
1255
1328
  * Usage information for the account.
1256
1329
  */
@@ -4577,12 +4650,26 @@ declare class SandboxInstance {
4577
4650
  * Stream events from an agent prompt.
4578
4651
  * Use this for real-time updates during agent execution.
4579
4652
  *
4653
+ * Guarantees a terminal event on every non-cancelled path: a clean run
4654
+ * ends with the runtime's `result`/`done`; a failure (pre-stream HTTP
4655
+ * error, mid-stream network drop, timeout, or reconnect exhaustion) is
4656
+ * surfaced as an in-band `error` event followed by a synthetic `done`,
4657
+ * never a thrown generator. Caller-initiated cancellation (aborting
4658
+ * `options.signal`) ends the stream silently with no synthetic terminal.
4659
+ *
4580
4660
  * Automatically reconnects via the runtime event replay endpoint if the
4581
- * SSE stream drops before a terminal event (`result` or `done`) is received.
4582
- * Reconnection is transparent — replayed events that were already yielded
4583
- * (based on event ID tracking) are deduplicated.
4661
+ * SSE stream drops before a terminal event (`result` or `done`) is
4662
+ * received. Reconnection is transparent — replayed events that were
4663
+ * already yielded (based on event ID tracking) are deduplicated.
4584
4664
  */
4585
4665
  streamPrompt(message: string | PromptInputPart[], options?: PromptOptions): AsyncGenerator<SandboxEvent>;
4666
+ /**
4667
+ * Inner prompt stream: opens the SSE connection and reconnects on silent
4668
+ * drops. May throw (pre-stream HTTP error, timeout, reconnect exhausted);
4669
+ * the public `streamPrompt` wrapper converts those throws into a terminal
4670
+ * `error` + `done` so callers never see a thrown generator.
4671
+ */
4672
+ private streamPromptInner;
4586
4673
  /**
4587
4674
  * Stream sandbox lifecycle and activity events.
4588
4675
  */
@@ -5133,7 +5220,7 @@ declare class SandboxInstance {
5133
5220
  /**
5134
5221
  * Resume a stopped sandbox.
5135
5222
  */
5136
- resume(): Promise<void>;
5223
+ resume(options?: ResumeOptions): Promise<void>;
5137
5224
  /**
5138
5225
  * Delete the sandbox permanently.
5139
5226
  */