@tangle-network/sandbox 0.63.20 → 0.63.22

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 (65) hide show
  1. package/dist/agent/index.d.ts +4 -4
  2. package/dist/agent/index.js +5 -5
  3. package/dist/agent/preview.d.ts +1 -1
  4. package/dist/agent/preview.js +2 -2
  5. package/dist/{agent-run-outcome-DlYhZnhD.d.ts → agent-run-outcome-C-VR-L0I.d.ts} +1 -1
  6. package/dist/auth/index.d.ts +2 -2
  7. package/dist/auth/index.js +1 -1
  8. package/dist/{backend-types-D6bYbvMB.js → backend-types-zuUBEJO1.js} +35 -1
  9. package/dist/{browser-interactive-control-controller-B6sySQFu.d.ts → browser-interactive-control-controller-CvObO_Kf.d.ts} +1 -1
  10. package/dist/{browser-interactive-control-controller-BJf0P_J4.js → browser-interactive-control-controller-DHx53yre.js} +16 -1
  11. package/dist/{chunked-upload-KJyRCAiC.js → chunked-upload-DN2twsUu.js} +1 -1
  12. package/dist/{chunked-upload-file-DfiGzqaR.js → chunked-upload-file-Dpv1YsoA.js} +2 -2
  13. package/dist/{cli-auth-bundle-CMgB8Ec3.js → cli-auth-bundle-R0Y7rngn.js} +8 -8
  14. package/dist/{client-Dl22CVOz.js → client-CGcWP4FX.js} +3271 -3271
  15. package/dist/client-CqpKC6n3.d.ts +6066 -0
  16. package/dist/collaboration/index.d.ts +1 -1
  17. package/dist/collaboration/index.js +1 -1
  18. package/dist/{collaboration-XHg5BEUI.js → collaboration-g_HzXa6f.js} +1 -1
  19. package/dist/core.d.ts +6 -7
  20. package/dist/core.js +5 -5
  21. package/dist/{direct-http2-Dq7tq6jV.js → direct-http2-CoGVOqVR.js} +1 -1
  22. package/dist/{errors-AB5BD3FM.js → errors-BfbOP_rx.js} +19 -1
  23. package/dist/{sandbox-DDdPhk2j.d.ts → index-D4OBUP5M.d.ts} +2105 -1461
  24. package/dist/index.d.ts +12 -4747
  25. package/dist/index.js +15 -11
  26. package/dist/intelligence/index.js +1 -1
  27. package/dist/interactive-control.d.ts +1 -1
  28. package/dist/interactive-control.js +1 -1
  29. package/dist/{interactive-controller-BSWoA0YE.d.ts → interactive-controller-BBwB_5QQ.d.ts} +3 -2
  30. package/dist/{interactive-controller-zE6hwv3C.js → interactive-controller-D4N4zqmu.js} +578 -610
  31. package/dist/{lines-hsXVdk60.d.ts → lines-5m11CEj-.d.ts} +21 -17
  32. package/dist/lines-C5ER4aN_.js +298 -0
  33. package/dist/lines.d.ts +1 -1
  34. package/dist/lines.js +1 -295
  35. package/dist/{local-cli-auth-C4QcPdZt.js → local-cli-auth-DVUBOY4y.js} +1 -1
  36. package/dist/{mcp-local-BYHcA72Z.js → mcp-local-BjLG7VHY.js} +1 -1
  37. package/dist/{preview-D8UAF7F9.d.ts → preview-CcJBQSjB.d.ts} +3 -3
  38. package/dist/{public-templates-BP3sTaSb.d.ts → public-templates-nv4AFFVc.d.ts} +2 -2
  39. package/dist/public-templates.d.ts +1 -1
  40. package/dist/public-templates.js +1 -1
  41. package/dist/runtime.d.ts +47 -40
  42. package/dist/runtime.js +4 -4
  43. package/dist/{sandbox-BJkpVtLN.js → sandbox-BDgvO9Z3.js} +9256 -9215
  44. package/dist/{secp256k1-DoWlH6ff.js → secp256k1-CmLpsmWl.js} +1 -1
  45. package/dist/session-gateway/index.d.ts +16 -17
  46. package/dist/session-gateway/index.js +20 -23
  47. package/dist/tangle/index.d.ts +1 -1
  48. package/dist/tangle/index.js +1 -1
  49. package/dist/{tangle-BBpguPfj.js → tangle-D-VfQGTu.js} +144 -138
  50. package/dist/terminal-stream-types-ClZCArRg.d.ts +662 -0
  51. package/dist/{types-BxZX2EVj.d.ts → types-BjyQe_CI.d.ts} +393 -315
  52. package/package.json +6 -6
  53. package/dist/client-DraGbXEP.d.ts +0 -1249
  54. package/dist/error-classes-BWS1a9HO.d.ts +0 -321
  55. package/dist/index-xS3mRl69.d.ts +0 -578
  56. package/dist/managed-process-B-pXdMLC.d.ts +0 -15
  57. package/dist/terminal-stream-DgD7GlFi.d.ts +0 -388
  58. /package/dist/{cli-auth-bundle-BKsrsbxy.d.ts → cli-auth-bundle-Dyw3hCGx.d.ts} +0 -0
  59. /package/dist/{index-DfA_usrZ.d.ts → index-C8VSFtWl.d.ts} +0 -0
  60. /package/dist/{index-CWUW8pqr.d.ts → index-CVjTnRWP.d.ts} +0 -0
  61. /package/dist/{keep-alive-fetch-CXvfSczd.js → keep-alive-fetch-CuwGi7gz.js} +0 -0
  62. /package/dist/{line-application-UtPFP0o4.js → line-application-DY9ZTdgF.js} +0 -0
  63. /package/dist/{preview-operations-Bvo5YcIq.js → preview-operations-Ca02vPDJ.js} +0 -0
  64. /package/dist/{raw-evidence-archive-Bxk6fUjS.js → raw-evidence-archive-CDYDqHNv.js} +0 -0
  65. /package/dist/{utils-B6gap92T.js → utils-BGvM02yJ.js} +0 -0
@@ -0,0 +1,662 @@
1
+ import { z } from "zod";
2
+ import { AgentInteractiveSessionControlClaim, AgentInteractiveSessionRef } from "@tangle-network/agent-interface";
3
+
4
+ //#region src/create-receipt-types.d.ts
5
+ /** Create admission evidence shared by SDK errors and public sandbox types.
6
+ * This contract has no SDK implementation imports. */
7
+ /**
8
+ * What one `create()` call did to the sandbox environment.
9
+ *
10
+ * - `created`: the call allocated the environment. The platform states this
11
+ * only when the create identity belonged to the call alone.
12
+ * - `idempotent_replay`: the platform returned the environment that an earlier
13
+ * call with the same idempotency key allocated. The call allocated nothing.
14
+ * - `unknown`: the platform cannot prove either outcome, so another caller can
15
+ * hold the environment.
16
+ */
17
+ type SandboxCreateOutcome = "created" | "idempotent_replay" | "unknown";
18
+ /**
19
+ * The platform verdict for one create call.
20
+ *
21
+ * Delete the environment only on a `created` outcome. `idempotencyKeyApplied`
22
+ * reports whether the idempotency key selected the environment: a false value
23
+ * means a retry of the same request allocates a second sandbox.
24
+ */
25
+ interface SandboxCreateReceipt {
26
+ outcome: SandboxCreateOutcome;
27
+ idempotencyKeyApplied: boolean;
28
+ /** Host-confirmed credential-inheritance policy, not a VM-isolation or
29
+ * privacy-from-operator attestation. Missing on older hosts and on unverified
30
+ * replays; isolated creation requires an explicit isolated verdict. */
31
+ ownerContext?: "inherit" | "isolated";
32
+ /**
33
+ * Names of the stored secrets this call decrypted for the sandbox.
34
+ * Read it to size what the box can read. The set is sorted and
35
+ * de-duplicated, and it also counts the names a startup script or a Hub
36
+ * credential pulled in, so it is a superset of the `secrets` the create
37
+ * asked for rather than the same list. A `secrets` entry that declared a
38
+ * `host` is on the list, but the box reads only a placeholder for it: the
39
+ * egress proxy holds the value. Absent on an idempotent replay, and
40
+ * on a platform old enough not to report the set.
41
+ */
42
+ injectedSecrets?: string[];
43
+ /** Host-confirmed identity of the container whose native rollout is retained. */
44
+ captureProof?: {
45
+ hostId: string;
46
+ containerId: string;
47
+ imageId: string;
48
+ bundleRevision: string;
49
+ bundleChecksum: string;
50
+ };
51
+ }
52
+ //#endregion
53
+ //#region src/error-classes.d.ts
54
+ /**
55
+ * Base error class for all Sandbox SDK errors.
56
+ */
57
+ declare class SandboxError extends Error {
58
+ /** HTTP status code if applicable */
59
+ readonly status?: number;
60
+ /** Error code for programmatic handling */
61
+ readonly code: string;
62
+ /** Best-effort origin of the failing request */
63
+ readonly origin?: SandboxErrorOrigin;
64
+ /** Request path or endpoint when known */
65
+ readonly endpoint?: string;
66
+ /** Retry-after duration in ms when surfaced by the upstream */
67
+ readonly retryAfterMs?: number;
68
+ /** Sidecar version when the runtime emitted it */
69
+ readonly sidecarVersion?: string;
70
+ /** Sidecar image/tag/sha when the runtime emitted it */
71
+ readonly containerImage?: string;
72
+ /**
73
+ * Seconds the control plane expects to need before it can serve this
74
+ * request, when it published one. Today only a capacity refusal on create
75
+ * carries it: the cell sizes it from the host add already in flight plus
76
+ * the measured p95 host-birth time, so it is a real wait, not a backoff
77
+ * hint. `retryAfterMs` paces the SDK's own retry; this is the number to
78
+ * show a human or feed to a scheduler.
79
+ */
80
+ readonly etaSeconds?: number;
81
+ /**
82
+ * On create's top-level error, proves this call's attempts admitted no
83
+ * sandbox. Absence is unknown. Earlier errors in `cause` describe only
84
+ * their attempt prefix, not subsequent attempts or earlier calls using
85
+ * the same idempotency key.
86
+ */
87
+ readonly createFailureDisposition?: "not-admitted";
88
+ constructor(message: string, code: string, status?: number, metadata?: SandboxErrorMetadata);
89
+ }
90
+ type SandboxErrorOrigin = "sidecar" | "sandbox-api" | "control-plane" | "runtime" | "unknown";
91
+ interface SandboxErrorMetadata {
92
+ origin?: SandboxErrorOrigin;
93
+ endpoint?: string;
94
+ retryAfterMs?: number;
95
+ sidecarVersion?: string;
96
+ containerImage?: string;
97
+ etaSeconds?: number;
98
+ /** How long the operation ran, for a TimeoutError that measured it. */
99
+ elapsedMs?: number;
100
+ createFailureDisposition?: "not-admitted";
101
+ }
102
+ type SandboxErrorJson = string | number | boolean | null | {
103
+ [key: string]: SandboxErrorJson;
104
+ } | SandboxErrorJson[];
105
+ type SandboxFailureDetail = {
106
+ [key: string]: SandboxErrorJson;
107
+ };
108
+ /**
109
+ * Authentication failed or API key is invalid.
110
+ */
111
+ declare class AuthError extends SandboxError {
112
+ constructor(message?: string, metadata?: SandboxErrorMetadata);
113
+ }
114
+ /**
115
+ * The requested resource was not found.
116
+ */
117
+ declare class NotFoundError extends SandboxError {
118
+ /** The resource type that was not found */
119
+ readonly resourceType: string;
120
+ /** The resource ID that was not found */
121
+ readonly resourceId: string;
122
+ constructor(resourceType: string, resourceId: string, metadata?: SandboxErrorMetadata, message?: string, code?: string);
123
+ }
124
+ /**
125
+ * Account quota or rate limit exceeded.
126
+ */
127
+ declare class QuotaError extends SandboxError {
128
+ /** The type of quota that was exceeded */
129
+ readonly quotaType: string;
130
+ /** Current usage */
131
+ readonly current?: number;
132
+ /** Maximum allowed */
133
+ readonly limit?: number;
134
+ /** Suggested retry-after duration in ms */
135
+ readonly retryAfterMs?: number;
136
+ constructor(quotaType: string, message?: string, current?: number, limit?: number, metadata?: SandboxErrorMetadata, status?: number);
137
+ }
138
+ /**
139
+ * The requested capability is unavailable for the account, driver, or sandbox.
140
+ */
141
+ declare class CapabilityError extends SandboxError {
142
+ /** Capability or feature that was rejected when known */
143
+ readonly capability?: string;
144
+ constructor(message: string, code?: string, status?: number, metadata?: SandboxErrorMetadata, capability?: string);
145
+ }
146
+ /** What one supported GPU provider needs, as a refusal reports it. */
147
+ interface GpuProviderRequirement {
148
+ provider: string;
149
+ /** `ready`, `credential-invalid`, `unverified`, `not-configured`, `disabled`. */
150
+ state: string;
151
+ /** Orchestrator environment variables it needs (`A|B`: either). */
152
+ envVars: string[];
153
+ }
154
+ /**
155
+ * No configured GPU provider can take the lease: none is configured, the
156
+ * named one is not, or the provider refused its credential. Status 503, code
157
+ * `GPU_PROVIDER_NOT_CONFIGURED`. The message names every supported provider
158
+ * and the orchestrator variables it needs; `providers` carries the same.
159
+ */
160
+ declare class GpuProviderNotConfiguredError extends CapabilityError {
161
+ readonly providers: GpuProviderRequirement[];
162
+ constructor(message: string, providers?: GpuProviderRequirement[], status?: number, metadata?: SandboxErrorMetadata);
163
+ }
164
+ /**
165
+ * A multi-resource operation failed for one or more branches.
166
+ */
167
+ declare class PartialFailureError extends SandboxError {
168
+ /** Per-resource failures returned by the API when available */
169
+ readonly failures?: SandboxFailureDetail[];
170
+ /** The operation that failed after another resource was already created. */
171
+ readonly cause?: unknown;
172
+ /** Allocation returned before create readiness failed. */
173
+ readonly allocationId?: string;
174
+ /** Key used for the create call that returned the allocation. */
175
+ readonly idempotencyKey?: string;
176
+ /** Ownership verdict returned by that create call, if available. */
177
+ readonly createReceipt?: SandboxCreateReceipt | null;
178
+ constructor(message: string, code?: string, status?: number, metadata?: SandboxErrorMetadata, failures?: SandboxFailureDetail[], cause?: unknown, createFailure?: {
179
+ allocationId: string;
180
+ idempotencyKey: string;
181
+ createReceipt: SandboxCreateReceipt | null;
182
+ });
183
+ }
184
+ /**
185
+ * The request was invalid or malformed.
186
+ */
187
+ declare class ValidationError extends SandboxError {
188
+ /** Field-level validation errors */
189
+ readonly fields?: Record<string, string>;
190
+ constructor(message: string, fields?: Record<string, string>, metadata?: SandboxErrorMetadata, code?: string);
191
+ }
192
+ /**
193
+ * A profile file mount names a path that the sidecar file API refuses: an
194
+ * absolute path outside `SANDBOX_FILE_API_ABSOLUTE_ROOTS`. create() throws it
195
+ * before it provisions a sandbox, and a turn throws it before any write. The
196
+ * status is 422 and the code is `PROFILE_FILE_MOUNT_OUTSIDE_ROOTS`: a retry
197
+ * with the same profile gets the same refusal.
198
+ */
199
+ declare class ProfileFileMountPathError extends SandboxError {
200
+ /** The refused mount path, exactly as the profile gave it. */
201
+ readonly path: string;
202
+ constructor(path: string, message: string, code: string, metadata?: SandboxErrorMetadata);
203
+ }
204
+ /**
205
+ * The sandbox is not in a valid state for the requested operation.
206
+ */
207
+ declare class StateError extends SandboxError {
208
+ /** Current state of the sandbox */
209
+ readonly currentState: string;
210
+ /** Required state for the operation */
211
+ readonly requiredState?: string;
212
+ constructor(message: string, currentState: string, requiredState?: string, metadata?: SandboxErrorMetadata, code?: string);
213
+ }
214
+ /**
215
+ * The sandbox lifecycle is running, but its consumer-facing runtime edge is
216
+ * still attaching or has failed to attach.
217
+ */
218
+ declare class EdgeNotReadyError extends SandboxError {
219
+ /** Current public edge state. */
220
+ readonly edgeStatus: "pending" | "failed";
221
+ constructor(message: string, edgeStatus: "pending" | "failed", metadata?: SandboxErrorMetadata);
222
+ }
223
+ declare class FileWriteConflictError extends SandboxError {
224
+ readonly path: string;
225
+ readonly currentHash: string | null;
226
+ readonly currentMtime: number | null;
227
+ readonly expectedHash?: string;
228
+ constructor(message: string, path: string, expectedHash: string | undefined, currentHash: string | null, currentMtime: number | null, metadata?: SandboxErrorMetadata);
229
+ }
230
+ /**
231
+ * The Platform key funding the request has no lifetime budget left.
232
+ *
233
+ * A budgeted key funds any number of sandboxes until its budget is spent;
234
+ * then every create, resume, and model credential it funds is refused with
235
+ * this error. The refusal is decided: retrying cannot succeed until the
236
+ * budget is raised or another key is used, so the SDK never retries it.
237
+ */
238
+ declare class KeyBudgetExhaustedError extends SandboxError {
239
+ /**
240
+ * The key the refusal names: the budgeted key with nothing left when
241
+ * Platform refused a delegation, or the presented key when authentication
242
+ * refused it. Absent when the server named none.
243
+ */
244
+ readonly keyId?: string;
245
+ /** That key's lifetime budget, in USD, when Platform reported it. */
246
+ readonly budgetUsd?: number;
247
+ /** What that key has spent, in USD. */
248
+ readonly spentUsd?: number;
249
+ /** What that key has reserved for budgeted children, in USD. */
250
+ readonly reservedUsd?: number;
251
+ constructor(message: string, details?: {
252
+ keyId?: string;
253
+ budgetUsd?: number;
254
+ spentUsd?: number;
255
+ reservedUsd?: number;
256
+ }, metadata?: SandboxErrorMetadata);
257
+ }
258
+ declare class EgressProxyRecoveryError extends SandboxError {
259
+ readonly phase: "egress_proxy_recovery";
260
+ constructor(message: string, metadata?: SandboxErrorMetadata);
261
+ }
262
+ /**
263
+ * Resume must build a new runtime, and that runtime needs public env values
264
+ * the platform does not store at rest: a per-run coordination or capability
265
+ * token, or a secret passed at create. Resume again with each key in
266
+ * `missingEnvKeys` in `ResumeOptions.env`.
267
+ */
268
+ declare class ResumeEnvRequiredError extends SandboxError {
269
+ /** The env keys the next resume must carry. */
270
+ readonly missingEnvKeys: readonly string[];
271
+ constructor(message: string, missingEnvKeys: readonly string[], metadata?: SandboxErrorMetadata);
272
+ }
273
+ /**
274
+ * A branch asked for more children than the parent's host has memory for.
275
+ * Children can only live on the parent's host (their clone is local to its
276
+ * volume), so no other host can take the rest. `maxChildren` is how many
277
+ * children that host admits now; branch that many or fewer, or wait for the
278
+ * host to free memory. Nothing was created and nothing is held.
279
+ *
280
+ * A retry under the same idempotency key replays this refusal unchanged,
281
+ * `maxChildren` included, so the count is the host's room when the key was
282
+ * first used. To branch fewer children, use a new key.
283
+ */
284
+ declare class BranchFanoutExceedsHostError extends SandboxError {
285
+ /** Children the parent's host admitted when it refused (0 when none). */
286
+ readonly maxChildren?: number;
287
+ /** The fan-out width this request asked for. */
288
+ readonly requestedChildren?: number;
289
+ constructor(message: string, counts: {
290
+ maxChildren?: number;
291
+ requestedChildren?: number;
292
+ }, metadata?: SandboxErrorMetadata);
293
+ }
294
+ /**
295
+ * The request timed out.
296
+ */
297
+ declare class TimeoutError extends SandboxError {
298
+ /** The operation's configured budget, in milliseconds. NOT how long it ran. */
299
+ readonly timeoutMs: number;
300
+ /**
301
+ * How long the operation actually ran before this error, in milliseconds,
302
+ * when the thrower measured it.
303
+ *
304
+ * `create()` can end before its budget: when a server-supplied `Retry-After`
305
+ * outlasts the remaining budget, no further attempt can follow that sleep,
306
+ * so the create ends there rather than idling. Reading `timeoutMs` as the
307
+ * duration would record a two-minute timeout for a three-second refusal.
308
+ * Absent means the thrower did not measure it; it never means `timeoutMs`.
309
+ */
310
+ readonly elapsedMs?: number;
311
+ /**
312
+ * The last typed failure the operation had already received when the
313
+ * deadline fired, when there was one.
314
+ *
315
+ * An operation that spends its budget across several attempts (create's
316
+ * bounded POST retry) usually learns the server's failure class on an
317
+ * earlier attempt — `CONTAINER_START_FAILED`, `PROVISIONING_ERROR`,
318
+ * `RATE_LIMIT_EXCEEDED`. Without this field that class dies at the
319
+ * deadline and the caller is left with a timeout that names no cause,
320
+ * which is the last discard in a chain built specifically to deliver it.
321
+ */
322
+ readonly cause?: SandboxError;
323
+ constructor(timeoutMs: number, message?: string, metadata?: SandboxErrorMetadata, cause?: SandboxError);
324
+ }
325
+ /**
326
+ * A network or connection error occurred.
327
+ */
328
+ declare class NetworkError extends SandboxError {
329
+ /** The underlying error */
330
+ readonly cause?: Error;
331
+ constructor(message: string, causeOrMetadata?: Error | SandboxErrorMetadata, metadata?: SandboxErrorMetadata);
332
+ }
333
+ /** Why the SDK stopped rejoining an execution whose stream dropped. */
334
+ type StreamInterruptionReason = /** The caller's reconnect window elapsed while the execution stayed unreachable. */"reconnect-window-elapsed" /** The sandbox is stopped, failed, expired or deleted; the run cannot resume. */ | "sandbox-not-running" /** The runtime kept answering that it has no such execution. */ | "execution-not-found";
335
+ /**
336
+ * The stream of an admitted execution ended without its terminal event, and
337
+ * the SDK could not rejoin it. The execution's outcome is UNKNOWN: it may
338
+ * still be running, or it may have finished while no reader was attached.
339
+ * This is never a failure verdict. Rejoin later with `streamPrompt(message,
340
+ * { executionId, lastEventId, sessionId })`, or read the session status.
341
+ */
342
+ declare class StreamInterruptedError extends SandboxError {
343
+ readonly executionId: string;
344
+ readonly sessionId?: string;
345
+ /** The last event id delivered to the caller; replay resumes after it. */
346
+ readonly lastEventId?: string;
347
+ readonly reason: StreamInterruptionReason;
348
+ /** Last HTTP status the replay endpoint answered, when it answered. */
349
+ readonly lastReplayStatus?: number;
350
+ /** Last execution status the runtime reported, when it reported one. */
351
+ readonly lastExecutionStatus?: string;
352
+ readonly cause?: unknown;
353
+ constructor(details: {
354
+ message: string;
355
+ executionId: string;
356
+ sessionId?: string;
357
+ lastEventId?: string;
358
+ reason: StreamInterruptionReason;
359
+ lastReplayStatus?: number;
360
+ lastExecutionStatus?: string;
361
+ cause?: unknown;
362
+ });
363
+ }
364
+ /**
365
+ * The server returned an unexpected error.
366
+ */
367
+ declare class ServerError extends SandboxError {
368
+ constructor(message: string, status?: number, metadata?: SandboxErrorMetadata, code?: string);
369
+ }
370
+ //#endregion
371
+ //#region src/errors.d.ts
372
+ /** A protocol `error` control frame or a transport failure. */
373
+ declare class TerminalStreamError extends Error {
374
+ /** Protocol error code (e.g. `INIT_FAILED`) or `TRANSPORT` for socket faults. */
375
+ readonly code: string;
376
+ /**
377
+ * True when the socket never reached OPEN: the upgrade was refused (a
378
+ * WebSocket client cannot read the HTTP status, so a 401 and a network drop
379
+ * look alike) or the runtime rejected the dial's options. No PTY work had
380
+ * started on the client's side of that dial.
381
+ */
382
+ readonly beforeOpen: boolean;
383
+ constructor(message: string, code: string, options?: {
384
+ beforeOpen?: boolean;
385
+ });
386
+ }
387
+ //#endregion
388
+ //#region ../../../packages/runtime-contracts/dist/terminal-websocket.d.ts
389
+ /** Non-credential protocol selected during a successful terminal handshake. */
390
+ declare const TERMINAL_WS_ECHO_SUBPROTOCOL = "tangle.terminal.v1";
391
+ /**
392
+ * Server stamps for one attach, in epoch milliseconds on the sidecar's clock.
393
+ * They are absolute so a caller can lay them against its own marks and read
394
+ * each leg (client clock skew is the only error). `spawn*` and `initPersistAt`
395
+ * are absent when the attach adopted a PTY that already existed.
396
+ */
397
+ declare const terminalReadyTimingsSchema: z.ZodObject<{
398
+ upgradeAt: z.ZodNumber;
399
+ authAt: z.ZodNumber;
400
+ initAt: z.ZodNumber;
401
+ loadAt: z.ZodNumber;
402
+ spawnAt: z.ZodOptional<z.ZodNumber>;
403
+ initPersistAt: z.ZodOptional<z.ZodNumber>;
404
+ loadedAt: z.ZodNumber;
405
+ historyAt: z.ZodNumber;
406
+ historyEvents: z.ZodNumber;
407
+ historyBytes: z.ZodNumber;
408
+ readyAt: z.ZodNumber;
409
+ via: z.ZodEnum<{
410
+ upgrade: "upgrade";
411
+ frame: "frame";
412
+ }>;
413
+ ptid: z.ZodOptional<z.ZodString>;
414
+ }, z.core.$strip>;
415
+ type TerminalReadyTimings = z.infer<typeof terminalReadyTimingsSchema>;
416
+ declare const terminalReadyMessageSchema: z.ZodObject<{
417
+ type: z.ZodLiteral<"ready">;
418
+ connectionId: z.ZodString;
419
+ sessionId: z.ZodString;
420
+ restored: z.ZodBoolean;
421
+ detachTimeoutMs: z.ZodNumber;
422
+ attachCount: z.ZodOptional<z.ZodNumber>;
423
+ cursors: z.ZodOptional<z.ZodObject<{
424
+ earliest: z.ZodNumber;
425
+ latest: z.ZodNumber;
426
+ }, z.core.$strip>>;
427
+ timings: z.ZodOptional<z.ZodObject<{
428
+ upgradeAt: z.ZodNumber;
429
+ authAt: z.ZodNumber;
430
+ initAt: z.ZodNumber;
431
+ loadAt: z.ZodNumber;
432
+ spawnAt: z.ZodOptional<z.ZodNumber>;
433
+ initPersistAt: z.ZodOptional<z.ZodNumber>;
434
+ loadedAt: z.ZodNumber;
435
+ historyAt: z.ZodNumber;
436
+ historyEvents: z.ZodNumber;
437
+ historyBytes: z.ZodNumber;
438
+ readyAt: z.ZodNumber;
439
+ via: z.ZodEnum<{
440
+ upgrade: "upgrade";
441
+ frame: "frame";
442
+ }>;
443
+ ptid: z.ZodOptional<z.ZodString>;
444
+ }, z.core.$strip>>;
445
+ }, z.core.$strip>;
446
+ type TerminalReadyMessage = z.infer<typeof terminalReadyMessageSchema>;
447
+ type TerminalReadyInfo = Omit<TerminalReadyMessage, "type">;
448
+ /** One sequenced output frame for an exact interactive terminal. */
449
+ declare const terminalOutputMessageSchema: z.ZodObject<{
450
+ type: z.ZodLiteral<"output">;
451
+ seq: z.ZodNumber;
452
+ data: z.ZodString;
453
+ }, z.core.$strip>;
454
+ type TerminalOutputMessage = z.infer<typeof terminalOutputMessageSchema>;
455
+ declare const terminalExitMessageSchema: z.ZodObject<{
456
+ type: z.ZodLiteral<"exit">;
457
+ exitCode: z.ZodOptional<z.ZodNumber>;
458
+ exitSignal: z.ZodOptional<z.ZodString>;
459
+ }, z.core.$strip>;
460
+ type TerminalExitMessage = z.infer<typeof terminalExitMessageSchema>;
461
+ type TerminalExitInfo = Omit<TerminalExitMessage, "type">;
462
+ type TerminalStreamAuthFormat = "edge" | "sidecar-direct";
463
+ interface TerminalInteractiveSessionIdentity {
464
+ incarnationId: AgentInteractiveSessionRef["incarnationId"];
465
+ control: AgentInteractiveSessionControlClaim;
466
+ }
467
+ //#endregion
468
+ //#region src/scoped-token-types.d.ts
469
+ /**
470
+ * Public types for scoped consumer-side tokens.
471
+ *
472
+ * This module intentionally has no SDK implementation imports. Terminal
473
+ * streams and token requests share these contracts without depending on the
474
+ * SDK's aggregate types module.
475
+ */
476
+ /**
477
+ * Scope of a `box.mintScopedToken()` request. `session` and `project` mint
478
+ * SessionGateway read tokens. `session-runtime` and `read-only` mint sidecar
479
+ * capability tokens for browser-safe runtime access.
480
+ */
481
+ type ScopedTokenScope = "session" | "session-runtime" | "project" | "read-only";
482
+ interface MintScopedTokenBase {
483
+ /** TTL in minutes. Default 5; clamped to [1, 15]. */
484
+ ttlMinutes?: number;
485
+ /** Cancel the token request before it reaches the terminal dial. */
486
+ signal?: AbortSignal;
487
+ }
488
+ /** Options for `box.mintScopedToken()`, narrowed by consumer scope. */
489
+ type MintScopedTokenOptions = (MintScopedTokenBase & {
490
+ scope: "session"; /** Client-facing browser session ID. */
491
+ sessionId: string; /** Actual runtime session ID used to filter the sandbox event stream. */
492
+ runtimeSessionId: string;
493
+ }) | (MintScopedTokenBase & {
494
+ scope: "session-runtime";
495
+ sessionId: string;
496
+ runtimeSessionId?: never;
497
+ }) | (MintScopedTokenBase & {
498
+ scope: "project" | "read-only";
499
+ sessionId?: never;
500
+ runtimeSessionId?: never;
501
+ });
502
+ /** Options for the server-side exact interactive-session token request. */
503
+ type MintInteractiveSessionTokenOptions = Pick<MintScopedTokenBase, "ttlMinutes" | "signal">;
504
+ /**
505
+ * Returned by `box.mintScopedToken()`. Use session/project tokens with
506
+ * `SessionGatewayClient`; use session-runtime/read-only tokens with
507
+ * `SandboxRuntimeClient`.
508
+ */
509
+ interface ScopedToken {
510
+ /** Bearer token (JWT) for the consumer selected by `scope`. */
511
+ token: string;
512
+ /** When the token expires. */
513
+ expiresAt: Date;
514
+ /** The runtime's direct edge URL. Use with runtime scopes; session/project
515
+ * tokens instead connect to the Sandbox API's `/session` WebSocket. */
516
+ runtimeUrl: string;
517
+ /** Browser-safe Sandbox API proxy base for terminal and runtime requests. */
518
+ sidecarProxyUrl: string;
519
+ /** Echo of the requested scope. */
520
+ scope: ScopedTokenScope;
521
+ }
522
+ //#endregion
523
+ //#region src/terminal-stream-types.d.ts
524
+ /**
525
+ * Event callbacks, passed at construction (the same idiom as
526
+ * `SessionGatewayClient`'s `handlers` config). Registering them up front is
527
+ * load-bearing: the server replays PTY history immediately after `ready`, so
528
+ * a handler attached after connect would miss the replayed screen.
529
+ */
530
+ interface TerminalStreamHandlers {
531
+ /** Raw PTY output bytes (both live output and reattach history replay). */
532
+ onData?: (data: Uint8Array) => void;
533
+ /** Server-sequenced output for exact interactive terminal sessions. */
534
+ onOutput?: (seq: number, data: Uint8Array) => void;
535
+ onReady?: (info: TerminalReadyInfo) => void;
536
+ onExit?: (info: TerminalExitInfo) => void;
537
+ /** Protocol `error` frames and post-connect transport failures. */
538
+ onError?: (error: TerminalStreamError) => void;
539
+ /** Socket closed — by the server, the network, or a local `close()`. */
540
+ onClose?: (code: number, reason: string) => void;
541
+ }
542
+ /**
543
+ * Which WebSocket-subprotocol auth envelope to offer. A WebSocket client
544
+ * cannot set an Authorization header, so the bearer rides the
545
+ * `Sec-WebSocket-Protocol` offer — and the two dialable endpoints expect
546
+ * DIFFERENT envelopes:
547
+ *
548
+ * - `"edge"` (default): the public API proxy
549
+ * (`wss://<api>/v1/sidecar-proxy/{sidecarId}/terminals/{id}/ws`) expects
550
+ * `bearer.<base64url(token)>` — see `parseTerminalWsSubprotocolToken` in
551
+ * `products/sandbox/api/src/lib/terminal-websocket.ts`. The fixed
552
+ * `tangle.terminal.v1` marker is offered alongside the credential (see
553
+ * {@link TERMINAL_WS_ECHO_SUBPROTOCOL}).
554
+ * - `"sidecar-direct"`: the sidecar's own `/terminals/{id}/ws` route expects
555
+ * `tangle.bearer.<token>` plus the same `tangle.terminal.v1` echo marker —
556
+ * see `apps/sidecar/src/routes/ws-subprotocol-auth.ts`. Only
557
+ * platform-internal callers (and the composed integration tests) dial the
558
+ * sidecar directly.
559
+ */
560
+ /**
561
+ * Bearer credential for the dial: a token string, or a provider invoked on
562
+ * EVERY dial (including {@link TerminalStream.reconnect}). The provider
563
+ * receives that dial's AbortSignal so token minting observes cancellation.
564
+ * Scoped terminal tokens are short-lived (the platform clamps them to <= 15
565
+ * minutes), so a provider lets the SDK re-mint a fresh token per dial.
566
+ */
567
+ type TerminalStreamBearerToken = string | ScopedToken | ((signal?: AbortSignal) => Promise<string | ScopedToken> | string | ScopedToken);
568
+ /**
569
+ * The account API key, sent as the `Authorization` header of the upgrade
570
+ * instead of a subprotocol credential. Only a runtime that can set headers on
571
+ * a WebSocket upgrade (Node, Bun) can dial this way — see
572
+ * {@link terminalUpgradeHeadersSupported}; a browser keeps a scoped token. The
573
+ * public API proxy takes its owner path for the key, so no scoped token is
574
+ * minted first. Dial the public API proxy with it, never the sidecar directly.
575
+ */
576
+ interface TerminalStreamApiKey {
577
+ readonly apiKey: string;
578
+ }
579
+ type TerminalStreamToken = TerminalStreamBearerToken | TerminalStreamApiKey;
580
+ /**
581
+ * Wall-clock marks for one attach, in milliseconds on the caller's monotonic
582
+ * clock. `server` holds the sidecar's absolute stamps from the `ready` frame
583
+ * (epoch milliseconds on the sidecar's clock); a caller lays them against its
584
+ * own epoch marks to split each leg.
585
+ */
586
+ interface TerminalAttachTimings {
587
+ /** The caller's wall to mint the scoped token; absent when the dial used the API key. */
588
+ mintMs?: number;
589
+ /** WebSocket construction to `open`: the upgrade round trip. */
590
+ wsOpenMs: number;
591
+ /** `open` to `ready`. One client/sidecar round trip plus the sidecar's work when `init` was a frame; the sidecar's work alone once the PTY starts on the upgrade. */
592
+ initToReadyMs: number;
593
+ /** `ready` to the first output byte (replayed screen or live output); absent until it arrives. */
594
+ firstByteMs?: number;
595
+ /** The first `write()` to the next output byte; absent until it arrives. */
596
+ echoRttMs?: number;
597
+ /** How the init was offered: on the upgrade URL as well as in the frame (a default-shell attach), or in the frame alone. */
598
+ init: "upgrade" | "frame";
599
+ /** The sidecar's stamps; absent from a sidecar that predates them. */
600
+ server?: TerminalReadyTimings;
601
+ }
602
+ /** Authority refreshed before an interactive stream reconnects. */
603
+ interface TerminalStreamReconnectBinding {
604
+ incarnationId: TerminalInteractiveSessionIdentity["incarnationId"];
605
+ control: TerminalInteractiveSessionIdentity["control"];
606
+ /** Release a claim if the new socket cannot be opened. */
607
+ onFailure?: () => Promise<void> | void;
608
+ }
609
+ /** Internal SDK hook that reclaims interactive authority before reconnect. */
610
+ interface TerminalStreamReconnectAuthority {
611
+ acquire(signal?: AbortSignal): Promise<TerminalStreamReconnectBinding>;
612
+ }
613
+ interface TerminalStreamOptions {
614
+ /**
615
+ * Absolute URL of the terminal WebSocket endpoint. `http(s)` URLs are
616
+ * converted to `ws(s)` automatically.
617
+ */
618
+ url: string;
619
+ /**
620
+ * Bearer token carried in the auth subprotocol (see `authFormat`) — a
621
+ * string, or a provider re-invoked on every dial so short-lived scoped
622
+ * tokens stay fresh across reconnects.
623
+ */
624
+ token: TerminalStreamToken;
625
+ /**
626
+ * PTY connection id — also sent in the `init` frame; the server rejects a
627
+ * mismatch with the URL's id. Reusing an id reattaches the existing PTY.
628
+ */
629
+ connectionId: string;
630
+ cols?: number;
631
+ rows?: number;
632
+ /** Command to run when the id has no live PTY (defaults to the shell). */
633
+ command?: string;
634
+ cwd?: string;
635
+ env?: Record<string, string>;
636
+ /**
637
+ * Exact interactive-agent incarnation. Ordinary terminal consumers omit
638
+ * both interactive fields and retain the existing wire contract.
639
+ */
640
+ incarnationId?: TerminalInteractiveSessionIdentity["incarnationId"];
641
+ /** Exact active control claim for the interactive-agent incarnation. */
642
+ control?: TerminalInteractiveSessionIdentity["control"];
643
+ /** Auth subprotocol envelope. Default `"edge"`. */
644
+ authFormat?: TerminalStreamAuthFormat;
645
+ handlers?: TerminalStreamHandlers;
646
+ /** Reject `connect()` if `ready` has not arrived within this window. */
647
+ connectTimeoutMs?: number;
648
+ /** Cancel token resolution or an in-progress WebSocket handshake. */
649
+ signal?: AbortSignal;
650
+ /** Reclaim interactive authority before a reconnecting dial. */
651
+ reconnectAuthority?: TerminalStreamReconnectAuthority;
652
+ /**
653
+ * Correlation id for this attach: sent as `x-tangle-trace-id` where the
654
+ * runtime can set upgrade headers, and on the upgrade URL and the `init`
655
+ * frame everywhere else. A fresh id is minted when omitted.
656
+ */
657
+ traceId?: string;
658
+ /** Wall the caller spent minting this dial's credential, reported in {@link TerminalAttachTimings}. */
659
+ mintMs?: number;
660
+ }
661
+ //#endregion
662
+ export { NotFoundError as A, StreamInterruptedError as B, EdgeNotReadyError as C, GpuProviderRequirement as D, GpuProviderNotConfiguredError as E, SandboxError as F, SandboxCreateReceipt as G, TimeoutError as H, SandboxErrorJson as I, SandboxFailureDetail as L, ProfileFileMountPathError as M, QuotaError as N, KeyBudgetExhaustedError as O, ResumeEnvRequiredError as P, ServerError as R, CapabilityError as S, FileWriteConflictError as T, ValidationError as U, StreamInterruptionReason as V, SandboxCreateOutcome as W, TerminalReadyTimings as _, TerminalStreamOptions as a, AuthError as b, MintInteractiveSessionTokenOptions as c, ScopedTokenScope as d, TERMINAL_WS_ECHO_SUBPROTOCOL as f, TerminalReadyInfo as g, TerminalOutputMessage as h, TerminalStreamHandlers as i, PartialFailureError as j, NetworkError as k, MintScopedTokenOptions as l, TerminalInteractiveSessionIdentity as m, TerminalStreamApiKey as n, TerminalStreamReconnectAuthority as o, TerminalExitInfo as p, TerminalStreamBearerToken as r, TerminalStreamToken as s, TerminalAttachTimings as t, ScopedToken as u, TerminalStreamAuthFormat as v, EgressProxyRecoveryError as w, BranchFanoutExceedsHostError as x, TerminalStreamError as y, StateError as z };