@tangle-network/sandbox 0.10.5 → 0.11.0

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.
package/dist/runtime.d.ts CHANGED
@@ -1,6 +1,31 @@
1
- import { A as CommitTaskSessionOptions, B as CreateTaskSessionOptions, Dr as SandboxRuntimeHealth, Jr as SentSessionMessage, Kr as SendSessionMessageOptions, Mi as WriteFileOptions, Mr as SandboxTerminalInfo, Nr as SandboxTerminalManager, Pr as SandboxTerminalRequestOptions, Qr as SessionInfo, Sr as SandboxPortBinding, dt as FileTreeResult, ei as SessionMessage, ft as FileWriteResult, gi as TaskSessionInfo, it as FileReadBatchResult, jr as SandboxTerminalCreateOptions, kn as RenameOptions, kr as SandboxRuntimeProfileList, mi as TaskSessionCommitResult, pi as TaskSessionChanges, qr as SendSessionMessageRequest, qt as ListMessagesOptions, rt as FileReadBatchOptions, st as FileRenameResult, ut as FileTreeOptions, z as CreateSessionOptions } from "./types-BGGfKALh.js";
2
- import { a as NotFoundError, c as SandboxError, d as ServerError, f as StateError, i as NetworkError, l as SandboxErrorJson, m as ValidationError, n as CapabilityError, o as PartialFailureError, p as TimeoutError, s as QuotaError, t as AuthError, u as SandboxFailureDetail } from "./errors--P_nbLzM.js";
1
+ import { Ar as SandboxRuntimeHealth, E as ChunkedUploadResult, Fi as WriteFileOptions, Fr as SandboxTerminalInfo, H as CreateTaskSessionOptions, Ir as SandboxTerminalManager, Lr as SandboxTerminalRequestOptions, M as CommitTaskSessionOptions, Mn as RenameOptions, Mr as SandboxRuntimeProfileList, Pr as SandboxTerminalCreateOptions, T as ChunkedUploadOptions, Tr as SandboxPortBinding, V as CreateSessionOptions, Xr as SendSessionMessageRequest, Xt as ListMessagesOptions, Yr as SendSessionMessageOptions, Zr as SentSessionMessage, _i as TaskSessionCommitResult, gi as TaskSessionChanges, ht as FileWriteResult, ji as UploadProgress, mt as FileTreeResult, ot as FileReadBatchOptions, pt as FileTreeOptions, ri as SessionMessage, st as FileReadBatchResult, ti as SessionInfo, ut as FileRenameResult, yi as TaskSessionInfo } from "./types-C4dFf5eL.js";
2
+ import { a as NotFoundError, c as SandboxError, d as ServerError, f as StateError, i as NetworkError, l as SandboxErrorJson, m as ValidationError, n as CapabilityError, o as PartialFailureError, p as TimeoutError, s as QuotaError, t as AuthError, u as SandboxFailureDetail } from "./errors-ntvaf0_F.js";
3
3
 
4
+ //#region src/lib/chunked-upload.d.ts
5
+ /** The transport a caller wires this module to — {@link SandboxInstance.runtimeFetch}
6
+ * in the SDK, or any fetch-shaped adapter in a standalone consumer. */
7
+ interface ChunkedUploadTransport {
8
+ fetch(path: string, init?: RequestInit): Promise<Response>;
9
+ }
10
+ /**
11
+ * Upload arbitrary binary or text data to the sandbox via the chunked
12
+ * upload-session protocol, verifying integrity with a whole-payload
13
+ * SHA-256 at commit. Browser/Worker-safe and works identically over the
14
+ * gateway proxy or a direct sidecar connection — see
15
+ * {@link FileSystem.uploadData}.
16
+ *
17
+ * @param transport - Fetch-shaped adapter scoped to the sandbox runtime
18
+ * (paths are relative to it, e.g. `/fs/upload-session`).
19
+ * @param remotePath - Destination path in the sandbox.
20
+ * @param data - Payload to upload. Strings encode as UTF-8.
21
+ * @param options - See {@link ChunkedUploadOptions}.
22
+ * @throws {SandboxError} `PAYLOAD_TOO_LARGE` immediately (zero requests) if
23
+ * the payload exceeds {@link FILE_UPLOAD_SESSION_MAX_BYTES}; otherwise the
24
+ * typed error from whichever step (init/part/commit) failed after retries
25
+ * are exhausted.
26
+ */
27
+ declare function uploadChunked(transport: ChunkedUploadTransport, remotePath: string, data: Blob | ArrayBuffer | ArrayBufferView | string, options?: ChunkedUploadOptions): Promise<ChunkedUploadResult>;
28
+ //#endregion
4
29
  //#region src/runtime-api.d.ts
5
30
  interface RuntimeTransport {
6
31
  ensureRunning(): Promise<void>;
@@ -16,6 +41,22 @@ declare class SandboxRuntimeApi {
16
41
  profiles(): Promise<SandboxRuntimeProfileList>;
17
42
  readFiles(paths: string[], options?: FileReadBatchOptions): Promise<FileReadBatchResult>;
18
43
  writeFile(path: string, content: string, options?: WriteFileOptions): Promise<FileWriteResult>;
44
+ /**
45
+ * Upload in-memory binary or text data to the sandbox over the chunked
46
+ * upload-session protocol — the browser/Worker-safe sanctioned path for
47
+ * payloads over ~1 MiB, sized to clear the gateway proxy's per-request cap
48
+ * (parts stay under {@link FILE_UPLOAD_PART_MAX_BYTES}). Binary-safe:
49
+ * accepts a `Blob`, `ArrayBuffer`, `ArrayBufferView`, or UTF-8 `string`.
50
+ * Delegates to the shared `uploadChunked` engine in `lib/chunked-upload.js`,
51
+ * wired to this client's `transport.fetch` so requests carry the same
52
+ * scoped-token `Authorization` header and base URL as every other method
53
+ * on this class (e.g. {@link SandboxRuntimeApi.writeFile}) — works
54
+ * identically over the gateway proxy or a direct sidecar connection.
55
+ *
56
+ * @throws {SandboxError} `PAYLOAD_TOO_LARGE` immediately, before any
57
+ * request, if the payload exceeds the chunked-upload session cap.
58
+ */
59
+ uploadData(remotePath: string, data: Blob | ArrayBuffer | ArrayBufferView | string, options?: ChunkedUploadOptions): Promise<ChunkedUploadResult>;
19
60
  deleteFile(path: string, options?: Pick<WriteFileOptions, "sessionId">): Promise<void>;
20
61
  renameFile(sourcePath: string, destinationPath: string, options?: RenameOptions): Promise<FileRenameResult>;
21
62
  fileTree(path: string, options?: FileTreeOptions): Promise<FileTreeResult>;
@@ -37,9 +78,9 @@ declare class SandboxRuntimeApi {
37
78
  //#endregion
38
79
  //#region src/runtime-client.d.ts
39
80
  interface SandboxRuntimeClientConfig {
40
- /** Browser-safe proxy base returned by `box.mintScopedToken()`. */
81
+ /** Browser-safe proxy base returned by a runtime-scoped token mint. */
41
82
  baseUrl: string;
42
- /** Short-lived scoped token returned by `box.mintScopedToken()`. */
83
+ /** Short-lived `session-runtime` or `read-only` token. */
43
84
  token: string;
44
85
  /** Request timeout in milliseconds. Defaults to 30 seconds. */
45
86
  timeoutMs?: number;
@@ -50,7 +91,9 @@ interface SandboxRuntimeClientConfig {
50
91
  * Browser- and Worker-safe client for one sandbox runtime.
51
92
  *
52
93
  * Construct it from the scoped token response returned by
53
- * `box.mintScopedToken()`. The full Sandbox API key remains server-side.
94
+ * `box.mintScopedToken({ scope: "session-runtime", sessionId })` or
95
+ * `box.mintScopedToken({ scope: "read-only" })`. The full Sandbox API key
96
+ * remains server-side.
54
97
  */
55
98
  declare class SandboxRuntimeClient extends SandboxRuntimeApi {
56
99
  private readonly auth;
@@ -60,4 +103,4 @@ declare class SandboxRuntimeClient extends SandboxRuntimeApi {
60
103
  }
61
104
  declare function createSandboxRuntimeClient(config: SandboxRuntimeClientConfig): SandboxRuntimeClient;
62
105
  //#endregion
63
- export { AuthError, CapabilityError, type FileReadBatchOptions, type FileReadBatchResult, type FileRenameResult, type FileTreeOptions, type FileTreeResult, type FileWriteResult, type ListMessagesOptions, NetworkError, NotFoundError, PartialFailureError, QuotaError, type RenameOptions, SandboxError, type SandboxErrorJson, type SandboxFailureDetail, SandboxRuntimeClient, type SandboxRuntimeClientConfig, type SandboxRuntimeHealth, type SandboxTerminalCreateOptions, type SandboxTerminalInfo, type SandboxTerminalManager, type SandboxTerminalRequestOptions, ServerError, type SessionMessage, StateError, TimeoutError, ValidationError, type WriteFileOptions, createSandboxRuntimeClient };
106
+ export { AuthError, CapabilityError, type ChunkedUploadOptions, type ChunkedUploadResult, type ChunkedUploadTransport, type FileReadBatchOptions, type FileReadBatchResult, type FileRenameResult, type FileTreeOptions, type FileTreeResult, type FileWriteResult, type ListMessagesOptions, NetworkError, NotFoundError, PartialFailureError, QuotaError, type RenameOptions, SandboxError, type SandboxErrorJson, type SandboxFailureDetail, SandboxRuntimeClient, type SandboxRuntimeClientConfig, type SandboxRuntimeHealth, type SandboxTerminalCreateOptions, type SandboxTerminalInfo, type SandboxTerminalManager, type SandboxTerminalRequestOptions, ServerError, type SessionMessage, StateError, TimeoutError, type UploadProgress, ValidationError, type WriteFileOptions, createSandboxRuntimeClient, uploadChunked };
package/dist/runtime.js CHANGED
@@ -1,5 +1,5 @@
1
- import { t as SandboxRuntimeApi } from "./runtime-api-CvAUrnHc.js";
2
- import { a as NotFoundError, c as SandboxError, d as TimeoutError, f as ValidationError, i as NetworkError, l as ServerError, n as CapabilityError, o as PartialFailureError, s as QuotaError, t as AuthError, u as StateError } from "./errors-DSz87Rkk.js";
1
+ import { o as combineAbortSignals, r as uploadChunked, t as SandboxRuntimeApi } from "./runtime-api-kukaWPtF.js";
2
+ import { a as NotFoundError, c as SandboxError, d as TimeoutError, f as ValidationError, i as NetworkError, l as ServerError, n as CapabilityError, o as PartialFailureError, s as QuotaError, t as AuthError, u as StateError } from "./errors-Cbs78OlF.js";
3
3
  //#region src/runtime-client.ts
4
4
  const DEFAULT_RUNTIME_TIMEOUT_MS = 3e4;
5
5
  function requireToken(token) {
@@ -28,7 +28,9 @@ function requireTimeout(timeoutMs) {
28
28
  * Browser- and Worker-safe client for one sandbox runtime.
29
29
  *
30
30
  * Construct it from the scoped token response returned by
31
- * `box.mintScopedToken()`. The full Sandbox API key remains server-side.
31
+ * `box.mintScopedToken({ scope: "session-runtime", sessionId })` or
32
+ * `box.mintScopedToken({ scope: "read-only" })`. The full Sandbox API key
33
+ * remains server-side.
32
34
  */
33
35
  var SandboxRuntimeClient = class extends SandboxRuntimeApi {
34
36
  auth;
@@ -47,7 +49,7 @@ var SandboxRuntimeClient = class extends SandboxRuntimeApi {
47
49
  const isFormData = typeof FormData !== "undefined" && init.body instanceof FormData;
48
50
  if (init.body !== void 0 && !isFormData && !headers.has("Content-Type")) headers.set("Content-Type", "application/json");
49
51
  const timeoutSignal = AbortSignal.timeout(timeoutMs);
50
- const signal = init.signal ? AbortSignal.any([init.signal, timeoutSignal]) : timeoutSignal;
52
+ const signal = init.signal ? combineAbortSignals([init.signal, timeoutSignal]) : timeoutSignal;
51
53
  try {
52
54
  return await fetchImpl(`${baseUrl}${path}`, {
53
55
  ...init,
@@ -78,4 +80,4 @@ function createSandboxRuntimeClient(config) {
78
80
  return new SandboxRuntimeClient(config);
79
81
  }
80
82
  //#endregion
81
- export { AuthError, CapabilityError, NetworkError, NotFoundError, PartialFailureError, QuotaError, SandboxError, SandboxRuntimeClient, ServerError, StateError, TimeoutError, ValidationError, createSandboxRuntimeClient };
83
+ export { AuthError, CapabilityError, NetworkError, NotFoundError, PartialFailureError, QuotaError, SandboxError, SandboxRuntimeClient, ServerError, StateError, TimeoutError, ValidationError, createSandboxRuntimeClient, uploadChunked };
@@ -1,4 +1,4 @@
1
- import { $ as EventStreamOptions, $r as SessionListOptions, A as CommitTaskSessionOptions, Ai as WaitForOptions, An as RestoreSnapshotOptions, Ar as SandboxStatus, B as CreateTaskSessionOptions, Bn as SSHCommandDescriptor, Br as ScopedToken, Bt as InstalledTool, D as CodeLanguage, Dr as SandboxRuntimeHealth, Dt as GitDiff, E as CodeExecutionResult, Fr as SandboxTraceBundle, Gn as SandboxEvent, Gt as IntelligenceReportWindow, Hr as SearchMatch, Ht as IntelligenceReportBudget, In as RolloutStartResult, Jr as SentSessionMessage, Kr as SendSessionMessageOptions, Kt as JsonValue, Mi as WriteFileOptions, Mn as Rollout, Ni as WriteManyFile, Nr as SandboxTerminalManager, Ot as GitStatus, Pi as WriteManyOptions, Pn as RolloutOptions, Pt as GpuLeaseManager, Qr as SessionInfo, Qt as MintScopedTokenOptions, Rr as SandboxTraceOptions, Si as TeePublicKeyResponse, Sr as SandboxPortBinding, T as CodeExecutionOptions, Ti as TurnDriveResult, Tr as SandboxResourceUsage, Tt as GitCommit, U as DispatchPromptOptions, Un as SandboxConnection, Ur as SearchOptions, Ut as IntelligenceReportCompareTo, Vn as SSHCredentials, Vt as IntelligenceReport, W as DispatchedSession, Xr as SessionEventStreamOptions, Y as DriverInfo, Z as EgressManager, Zr as SessionForkOptions, _n as ProvisionEvent, ai as SnapshotResult, bi as TeeAttestationResponse, ct as FileSystem, di as TaskOptions, ei as SessionMessage, et as ExecOptions, fi as TaskResult, ft as FileWriteResult, gi as TaskSessionInfo, gn as PromptResult, hn as PromptOptions, ii as SnapshotOptions, in as PermissionsManager, j as CompletedTurnResult, ji as WaitForRolloutOptions, jn as ResumeOptions, kr as SandboxRuntimeProfileList, kt as GpuLease, l as BackendManager, mi as TaskSessionCommitResult, mn as PromptInputPart, on as PreviewLinkManager, pi as TaskSessionChanges, q as DriveTurnOptions, qr as SendSessionMessageRequest, qt as ListMessagesOptions, ri as SnapshotInfo, s as BackendConfig, si as StartupDiagnostics, tn as NetworkManager, tt as ExecResult, un as ProcessManager, ur as SandboxFleetTraceBundle, vi as TeeAttestationOptions, vn as ProvisionResult, w as BranchOptions, wt as GitBranch, yr as SandboxInfo, z as CreateSessionOptions } from "./types-BGGfKALh.js";
1
+ import { $ as DurablePlan, $r as SessionEventStreamOptions, Ar as SandboxRuntimeHealth, At as GitDiff, Ci as TeeAttestationResponse, D as CodeExecutionOptions, Dt as GitBranch, Fi as WriteFileOptions, Fn as Rollout, G as DispatchPromptOptions, Gr as SearchMatch, Gt as IntelligenceReportBudget, H as CreateTaskSessionOptions, Ii as WriteManyFile, Ir as SandboxTerminalManager, Jn as SandboxEvent, Jt as IntelligenceReportWindow, K as DispatchedSession, Kn as SandboxConnection, Kr as SearchOptions, Kt as IntelligenceReportCompareTo, Li as WriteManyOptions, Ln as RolloutOptions, Lt as GpuLeaseManager, M as CommitTaskSessionOptions, Mr as SandboxRuntimeProfileList, Mt as GpuLease, N as CompletedTurnResult, Ni as WaitForOptions, Nn as RestoreSnapshotOptions, Nr as SandboxStatus, O as CodeExecutionResult, Oi as TurnDriveResult, Or as SandboxResourceUsage, Ot as GitCommit, Pi as WaitForRolloutOptions, Pn as ResumeOptions, Rr as SandboxTraceBundle, Sr as SandboxInfo, Ti as TeePublicKeyResponse, Tr as SandboxPortBinding, Un as SSHCommandDescriptor, Ur as ScopedToken, Ut as InstalledTool, V as CreateSessionOptions, Vr as SandboxTraceOptions, Wn as SSHCredentials, Wt as IntelligenceReport, Xr as SendSessionMessageRequest, Xt as ListMessagesOptions, Y as DriveTurnOptions, Yr as SendSessionMessageOptions, Yt as JsonValue, Z as DriverInfo, Zr as SentSessionMessage, _i as TaskSessionCommitResult, _n as PromptInputPart, bn as ProvisionEvent, ci as SnapshotResult, dt as FileSystem, ei as SessionForkOptions, et as EgressManager, gi as TaskSessionChanges, hi as TaskResult, ht as FileWriteResult, in as NetworkManager, it as ExecResult, jt as GitStatus, k as CodeLanguage, l as BackendManager, ln as PreviewLinkManager, mi as TaskOptions, ni as SessionListOptions, nt as EventStreamOptions, oi as SnapshotInfo, pn as ProcessManager, pr as SandboxFleetTraceBundle, ri as SessionMessage, rt as ExecOptions, s as BackendConfig, si as SnapshotOptions, sn as PermissionsManager, ti as SessionInfo, tn as MintScopedTokenOptions, ui as StartupDiagnostics, vn as PromptOptions, w as BranchOptions, xi as TeeAttestationOptions, xn as ProvisionResult, yi as TaskSessionInfo, yn as PromptResult, zn as RolloutStartResult } from "./types-C4dFf5eL.js";
2
2
 
3
3
  //#region src/mcp.d.ts
4
4
  /**
@@ -221,6 +221,13 @@ interface SandboxSessionHost extends InteractiveSessionHost {
221
221
  _respondToPermission(id: string, permissionID: string, options: RespondToPermissionOptions): Promise<void>;
222
222
  _interrupt(id: string): Promise<InterruptResult>;
223
223
  _answerQuestion(id: string, answers: Record<string, string[]>): Promise<void>;
224
+ _currentPlan(id: string): Promise<DurablePlan | null>;
225
+ _decidePlan(id: string, planId: string, decision: {
226
+ outcome: "approved";
227
+ } | {
228
+ outcome: "rejected";
229
+ feedback: string;
230
+ }): Promise<DurablePlan>;
224
231
  }
225
232
  /**
226
233
  * A single agent session inside a sandbox. Created via
@@ -327,6 +334,13 @@ declare class SandboxSession {
327
334
  * enabled. Backends with no question support reject loudly.
328
335
  */
329
336
  answer(answers: Record<string, string[]>): Promise<void>;
337
+ /** Return the newest plan awaiting a decision for this session. */
338
+ plan(): Promise<DurablePlan | null>;
339
+ /** Approve a durable plan and enqueue its separate execution turn. */
340
+ approvePlan(planId?: string): Promise<DurablePlan>;
341
+ /** Reject a durable plan with required feedback and enqueue a revision turn. */
342
+ rejectPlan(feedback: string, planId?: string): Promise<DurablePlan>;
343
+ private requireCurrentPlan;
330
344
  }
331
345
  //#endregion
332
346
  //#region src/task-session.d.ts
@@ -894,6 +908,11 @@ declare class SandboxInstance {
894
908
  private fsReadBatch;
895
909
  private fsTree;
896
910
  private fsUpload;
911
+ /** See {@link FileSystem.uploadData}. Delegates to the shared, browser-safe
912
+ * chunked-upload flow in `lib/chunked-upload.ts`, wired to this sandbox's
913
+ * runtime endpoint (works over the gateway proxy or a direct connection —
914
+ * both are transparent through `runtimeFetch`). */
915
+ private fsUploadData;
897
916
  private fsDownload;
898
917
  private fsUploadDir;
899
918
  private fsDownloadDir;
@@ -1015,7 +1034,6 @@ declare class SandboxInstance {
1015
1034
  * ```
1016
1035
  */
1017
1036
  get process(): ProcessManager;
1018
- private processSpawnExact;
1019
1037
  private processSpawn;
1020
1038
  private processRunCode;
1021
1039
  private processList;
@@ -1500,21 +1518,16 @@ declare class SandboxInstance {
1500
1518
  */
1501
1519
  driveTurn(message: string | PromptInputPart[], opts: DriveTurnOptions): Promise<TurnDriveResult>;
1502
1520
  /**
1503
- * Mint a scoped, time-bounded JWT for direct browser access to this
1504
- * sandbox (Issue #913 Gap 1). Authority is the caller's
1505
- * `TANGLE_API_KEY` (sk-tan-*) the Sandbox API mints the token;
1506
- * signing secrets stay server-side.
1507
- *
1508
- * Use this to give a browser direct read access to the sandbox without
1509
- * leaking the full bearer (`box.connection.authToken`). The returned
1510
- * token verifies against the same sidecar middleware that already
1511
- * gates ProductTokenIssuer-issued JWTs — no new sidecar surface.
1521
+ * Mint a scoped, time-bounded JWT for browser access (Issue #913 Gap 1).
1522
+ * Authority is the caller's `TANGLE_API_KEY` (sk-tan-*); signing secrets
1523
+ * stay server-side. Session/project scopes work with SessionGatewayClient,
1524
+ * while session-runtime/read-only scopes work with SandboxRuntimeClient.
1512
1525
  */
1513
1526
  mintScopedToken(opts: MintScopedTokenOptions): Promise<ScopedToken>;
1514
1527
  /** @internal — invoked by SandboxSession.status(). */
1515
1528
  _sessionStatus(id: string): Promise<SessionInfo | null>;
1516
1529
  /** @internal — invoked by SandboxSession.events(). */
1517
- _sessionEvents(id: string, opts?: SessionEventStreamOptions): AsyncGenerator<SandboxEvent>;
1530
+ _sessionEvents(id: string, opts?: SessionEventStreamOptions, stopOnTurnTerminal?: boolean): AsyncGenerator<SandboxEvent>;
1518
1531
  /** @internal — invoked by SandboxSession.result(). */
1519
1532
  _sessionResult(id: string): Promise<PromptResult>;
1520
1533
  /**
@@ -1542,6 +1555,15 @@ declare class SandboxInstance {
1542
1555
  * question's `answerSpec` fields in order.
1543
1556
  */
1544
1557
  _answerQuestion(id: string, answers: Record<string, string[]>): Promise<void>;
1558
+ /** @internal — invoked by SandboxSession.plan(). */
1559
+ _currentPlan(sessionId: string): Promise<DurablePlan | null>;
1560
+ /** @internal — invoked by SandboxSession.approvePlan()/rejectPlan(). */
1561
+ _decidePlan(sessionId: string, planId: string, decision: {
1562
+ outcome: "approved";
1563
+ } | {
1564
+ outcome: "rejected";
1565
+ feedback: string;
1566
+ }): Promise<DurablePlan>;
1545
1567
  }
1546
1568
  //#endregion
1547
1569
  export { SandboxMcpConfig as C, buildSandboxMcpConfig as D, buildControlPlaneMcpConfig as E, SANDBOX_MCP_SERVER_NAME as S, SandboxMcpServerEntry as T, RespondToPermissionOptions as _, TraceExportSink as a, BuildSandboxMcpConfigOptions as b, otelTraceIdForTangleTrace as c, SandboxSession as d, InteractiveAuthFile as f, InterruptResult as g, InteractiveSessionInfo as h, TraceExportResult as i, toOtelJson as l, InteractiveSessionHost as m, SandboxInstance as n, buildTraceExportPayload as o, InteractiveSessionHandle as p, TraceExportFormat as r, exportTraceBundle as s, HttpClient as t, SandboxTaskSession as u, StartInteractiveOptions as v, SandboxMcpEndpoint as w, CONTROL_PLANE_MCP_SERVER_NAME as x, BuildControlPlaneMcpConfigOptions as y };