@tangle-network/sandbox 0.69.11 → 0.69.13

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 (77) 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 +3 -3
  5. package/dist/{agent-run-outcome-B5CzWxw4.d.ts → agent-run-outcome-BuebRCWr.d.ts} +2 -2
  6. package/dist/{api-request-D1UVNo16.js → api-request-EseiF9B1.js} +1 -1
  7. package/dist/auth/index.d.ts +2 -2
  8. package/dist/auth/index.js +1 -1
  9. package/dist/browser-interactive-control-controller-Bt1vcu9c.js +4045 -0
  10. package/dist/{browser-interactive-control-controller-SI9hV6r5.d.ts → browser-interactive-control-controller-CVnME80O.d.ts} +5 -7
  11. package/dist/{chunked-upload-l6b9AWFA.js → chunked-upload-Df_5Q2x8.js} +1 -1
  12. package/dist/{chunked-upload-file-CLwAeLrM.js → chunked-upload-file-Dtm1GBkE.js} +2 -2
  13. package/dist/cli-auth-bundle-3LBcaEqw.js +2593 -0
  14. package/dist/{client-Ds3As2SY.d.ts → client-BWnbrifs.d.ts} +40 -42
  15. package/dist/{client-D6b3wBnI.js → client-D-6z6BJb.js} +11 -11
  16. package/dist/collaboration/index.d.ts +1 -1
  17. package/dist/collaboration/index.js +1 -1
  18. package/dist/{collaboration-BwLNv6sy.js → collaboration-BTGTf3We.js} +1 -1
  19. package/dist/{core-BhSZIdRK.js → core-EqIoRKiQ.js} +5 -4
  20. package/dist/core.d.ts +6 -6
  21. package/dist/core.js +5 -5
  22. package/dist/{direct-http2-Pyj3Rvr1.js → direct-http2-B0ra_xhU.js} +1 -1
  23. package/dist/{errors-Bs5G7JdV.js → errors-ZmDrrk4f.js} +1 -1
  24. package/dist/harness-BD_OISom.js +201 -0
  25. package/dist/harness-DWL2MM4q.js +418 -0
  26. package/dist/{index-nXob5TkM.d.ts → index-DdcCRDq8.d.ts} +14 -16
  27. package/dist/index.d.ts +11 -11
  28. package/dist/index.js +11 -11
  29. package/dist/intelligence/index.js +2 -2
  30. package/dist/interactive-control.d.ts +1 -1
  31. package/dist/interactive-control.js +1 -1
  32. package/dist/{interactive-controller-DSDEfapN.js → interactive-controller-B4bQwRJL.js} +21 -8
  33. package/dist/{interactive-controller-FgmcS8_Y.d.ts → interactive-controller-DlFKGQqu.d.ts} +3 -4
  34. package/dist/lib/prepared-evidence.js +1 -1
  35. package/dist/lib/prepared-process.js +1 -1
  36. package/dist/{lines-D_HDAcVt.js → lines-BqZOl_io.js} +1 -1
  37. package/dist/{lines-BoVYnUCM.d.ts → lines-ptj8SyD4.d.ts} +1 -1
  38. package/dist/lines.d.ts +1 -1
  39. package/dist/lines.js +1 -1
  40. package/dist/{local-cli-auth-DaU64laN.js → local-cli-auth-BBdGF3wf.js} +1 -1
  41. package/dist/{mcp-local-Gz1Uygqk.js → mcp-local-BcRLN_Ic.js} +1 -1
  42. package/dist/{prepared-evidence-DUmJSegi.js → prepared-evidence-CuUh_mz6.js} +1 -1
  43. package/dist/{preview-7EJ_80nL.d.ts → preview-ByTCKjiK.d.ts} +3 -3
  44. package/dist/profile-schema-CT3hB1mG.js +1135 -0
  45. package/dist/{public-templates-B6_uwnRZ.d.ts → public-templates-O2mxBX7J.d.ts} +2 -2
  46. package/dist/public-templates.d.ts +1 -1
  47. package/dist/public-templates.js +1 -1
  48. package/dist/{raw-evidence-archive-D60Yg1-5.js → raw-evidence-archive-CqarcYcp.js} +1 -1
  49. package/dist/runtime.d.ts +5 -5
  50. package/dist/runtime.js +5 -5
  51. package/dist/{sandbox-DVOrtcTK.js → sandbox-eUPdjk1p.js} +384 -46
  52. package/dist/{secp256k1-DxHlUI6v.js → secp256k1-CZWrpqxW.js} +1 -1
  53. package/dist/select-seat-command.d.ts +1 -1
  54. package/dist/select-seat-command.js +1 -1
  55. package/dist/session-gateway/index.js +3 -3
  56. package/dist/sha2-BUPMvGTk.js +694 -0
  57. package/dist/tangle/index.d.ts +1 -1
  58. package/dist/tangle/index.js +1 -1
  59. package/dist/{tangle-Br7yT7X8.js → tangle-BmhK_E7e.js} +4 -4
  60. package/dist/terminal-stream-types-DwXQzUbH.d.ts +3328 -0
  61. package/dist/{types-CkLWX7i5.d.ts → types-B28t5Sq1.d.ts} +10 -12
  62. package/package.json +6 -6
  63. package/dist/browser-interactive-control-controller-CLHNi8rG.js +0 -292
  64. package/dist/cli-auth-bundle-B1Mpf18p.js +0 -1590
  65. package/dist/terminal-stream-types-DuzvL1ge.d.ts +0 -676
  66. /package/dist/{abort-signal-BKVZNJul.js → abort-signal-jU-SEjLT.js} +0 -0
  67. /package/dist/{cli-auth-bundle-CeNOYFje.d.ts → cli-auth-bundle-MskLEgtA.d.ts} +0 -0
  68. /package/dist/{index-C0RkLba5.d.ts → index-Dqcr9p97.d.ts} +0 -0
  69. /package/dist/{index-DaIF4c9p.d.ts → index-Dslyq85a.d.ts} +0 -0
  70. /package/dist/{keep-alive-fetch-Bi-zvHpN.js → keep-alive-fetch-C2DX2_rG.js} +0 -0
  71. /package/dist/{prepared-process-Dlk_9JVJ.js → prepared-process-LjBfQnZ5.js} +0 -0
  72. /package/dist/{preview-operations-eTUlPen5.js → preview-operations-BvgwYaoL.js} +0 -0
  73. /package/dist/{response-rewrap-BKkJ5hnn.js → response-rewrap-MBztoTLx.js} +0 -0
  74. /package/dist/{retry-after-header-U_L5Ml9Q.js → retry-after-header-BZbs5rig.js} +0 -0
  75. /package/dist/{sidecar-proxy-error-B2Hxt41g.js → sidecar-proxy-error-Dty4zmN7.js} +0 -0
  76. /package/dist/{sse-parser-CUfurwcm.js → sse-parser-DmO5gP6u.js} +0 -0
  77. /package/dist/{utils-DB8DnUCU.js → utils-vaFoyyiO.js} +0 -0
@@ -1,676 +0,0 @@
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 create that requires HIPAA placement was refused. `code` says why:
166
- * `COMPLIANCE_NOT_ENTITLED` (403) when the credential carries no HIPAA
167
- * entitlement, `COMPLIANCE_CELL_UNAVAILABLE` (503) when no HIPAA-designated
168
- * cell can take the create now. Either way nothing was created, and the
169
- * create was not placed in any other cell. The SDK does not retry it.
170
- */
171
- declare class CompliancePlacementError extends SandboxError {
172
- constructor(message: string, code: "COMPLIANCE_NOT_ENTITLED" | "COMPLIANCE_CELL_UNAVAILABLE", status: number, metadata?: SandboxErrorMetadata);
173
- }
174
- /**
175
- * A multi-resource operation failed for one or more branches.
176
- */
177
- declare class PartialFailureError extends SandboxError {
178
- /** Per-resource failures returned by the API when available */
179
- readonly failures?: SandboxFailureDetail[];
180
- /** The operation that failed after another resource was already created. */
181
- readonly cause?: unknown;
182
- /** Allocation returned before create readiness failed. */
183
- readonly allocationId?: string;
184
- /** Key used for the create call that returned the allocation. */
185
- readonly idempotencyKey?: string;
186
- /** Ownership verdict returned by that create call, if available. */
187
- readonly createReceipt?: SandboxCreateReceipt | null;
188
- constructor(message: string, code?: string, status?: number, metadata?: SandboxErrorMetadata, failures?: SandboxFailureDetail[], cause?: unknown, createFailure?: {
189
- allocationId: string;
190
- idempotencyKey: string;
191
- createReceipt: SandboxCreateReceipt | null;
192
- });
193
- }
194
- /**
195
- * The request was invalid or malformed.
196
- */
197
- declare class ValidationError extends SandboxError {
198
- /** Field-level validation errors */
199
- readonly fields?: Record<string, string>;
200
- constructor(message: string, fields?: Record<string, string>, metadata?: SandboxErrorMetadata, code?: string);
201
- }
202
- /**
203
- * A profile file mount names a path that the sidecar file API refuses: an
204
- * absolute path outside `SANDBOX_FILE_API_ABSOLUTE_ROOTS`. create() throws it
205
- * before it provisions a sandbox, and a turn throws it before any write. The
206
- * status is 422 and the code is `PROFILE_FILE_MOUNT_OUTSIDE_ROOTS`: a retry
207
- * with the same profile gets the same refusal.
208
- */
209
- declare class ProfileFileMountPathError extends SandboxError {
210
- /** The refused mount path, exactly as the profile gave it. */
211
- readonly path: string;
212
- constructor(path: string, message: string, code: string, metadata?: SandboxErrorMetadata);
213
- }
214
- /**
215
- * The sandbox is not in a valid state for the requested operation.
216
- */
217
- declare class StateError extends SandboxError {
218
- /** Current state of the sandbox */
219
- readonly currentState: string;
220
- /** Required state for the operation */
221
- readonly requiredState?: string;
222
- constructor(message: string, currentState: string, requiredState?: string, metadata?: SandboxErrorMetadata, code?: string);
223
- }
224
- /**
225
- * The sandbox lifecycle is running, but its consumer-facing runtime edge is
226
- * still attaching or has failed to attach.
227
- */
228
- declare class EdgeNotReadyError extends SandboxError {
229
- /** Current public edge state. */
230
- readonly edgeStatus: "pending" | "failed";
231
- constructor(message: string, edgeStatus: "pending" | "failed", metadata?: SandboxErrorMetadata);
232
- }
233
- declare class FileWriteConflictError extends SandboxError {
234
- readonly path: string;
235
- readonly currentHash: string | null;
236
- readonly currentMtime: number | null;
237
- readonly expectedHash?: string;
238
- constructor(message: string, path: string, expectedHash: string | undefined, currentHash: string | null, currentMtime: number | null, metadata?: SandboxErrorMetadata);
239
- }
240
- /**
241
- * The Platform key funding the request has no lifetime budget left.
242
- *
243
- * A budgeted key funds any number of sandboxes until its budget is spent;
244
- * then every create, resume, and model credential it funds is refused with
245
- * this error. The refusal is decided: retrying cannot succeed until the
246
- * budget is raised or another key is used, so the SDK never retries it.
247
- */
248
- declare class KeyBudgetExhaustedError extends SandboxError {
249
- /**
250
- * The key the refusal names: the budgeted key with nothing left when
251
- * Platform refused a delegation, or the presented key when authentication
252
- * refused it. Absent when the server named none.
253
- */
254
- readonly keyId?: string;
255
- /** That key's lifetime budget, in USD, when Platform reported it. */
256
- readonly budgetUsd?: number;
257
- /** What that key has spent, in USD. */
258
- readonly spentUsd?: number;
259
- /** What that key has reserved for budgeted children, in USD. */
260
- readonly reservedUsd?: number;
261
- constructor(message: string, details?: {
262
- keyId?: string;
263
- budgetUsd?: number;
264
- spentUsd?: number;
265
- reservedUsd?: number;
266
- }, metadata?: SandboxErrorMetadata);
267
- }
268
- declare class EgressProxyRecoveryError extends SandboxError {
269
- readonly phase: "egress_proxy_recovery";
270
- constructor(message: string, metadata?: SandboxErrorMetadata);
271
- }
272
- /**
273
- * Resume must build a new runtime, and that runtime needs public env values
274
- * the platform does not store at rest: a per-run coordination or capability
275
- * token, or a secret passed at create. Resume again with each key in
276
- * `missingEnvKeys` in `ResumeOptions.env`.
277
- */
278
- declare class ResumeEnvRequiredError extends SandboxError {
279
- /** The env keys the next resume must carry. */
280
- readonly missingEnvKeys: readonly string[];
281
- constructor(message: string, missingEnvKeys: readonly string[], metadata?: SandboxErrorMetadata);
282
- }
283
- /**
284
- * A branch asked for more children than the parent's host has memory for.
285
- * Children can only live on the parent's host (their clone is local to its
286
- * volume), so no other host can take the rest. `maxChildren` is how many
287
- * children that host admits now; branch that many or fewer, or wait for the
288
- * host to free memory. Nothing was created and nothing is held.
289
- *
290
- * A retry under the same idempotency key replays this refusal unchanged,
291
- * `maxChildren` included, so the count is the host's room when the key was
292
- * first used. To branch fewer children, use a new key.
293
- */
294
- declare class BranchFanoutExceedsHostError extends SandboxError {
295
- /** Children the parent's host admitted when it refused (0 when none). */
296
- readonly maxChildren?: number;
297
- /** The fan-out width this request asked for. */
298
- readonly requestedChildren?: number;
299
- constructor(message: string, counts: {
300
- maxChildren?: number;
301
- requestedChildren?: number;
302
- }, metadata?: SandboxErrorMetadata);
303
- }
304
- /**
305
- * The request timed out.
306
- */
307
- declare class TimeoutError extends SandboxError {
308
- /** The operation's configured budget, in milliseconds. NOT how long it ran. */
309
- readonly timeoutMs: number;
310
- /**
311
- * How long the operation actually ran before this error, in milliseconds,
312
- * when the thrower measured it.
313
- *
314
- * `create()` can end before its budget: when a server-supplied `Retry-After`
315
- * outlasts the remaining budget, no further attempt can follow that sleep,
316
- * so the create ends there rather than idling. Reading `timeoutMs` as the
317
- * duration would record a two-minute timeout for a three-second refusal.
318
- * Absent means the thrower did not measure it; it never means `timeoutMs`.
319
- */
320
- readonly elapsedMs?: number;
321
- /**
322
- * The last typed failure the operation had already received when the
323
- * deadline fired, when there was one.
324
- *
325
- * An operation that spends its budget across several attempts (create's
326
- * bounded POST retry) usually learns the server's failure class on an
327
- * earlier attempt — `CONTAINER_START_FAILED`, `PROVISIONING_ERROR`,
328
- * `RATE_LIMIT_EXCEEDED`. Without this field that class dies at the
329
- * deadline and the caller is left with a timeout that names no cause,
330
- * which is the last discard in a chain built specifically to deliver it.
331
- */
332
- readonly cause?: SandboxError;
333
- constructor(timeoutMs: number, message?: string, metadata?: SandboxErrorMetadata, cause?: SandboxError);
334
- }
335
- /**
336
- * A network or connection error occurred.
337
- */
338
- declare class NetworkError extends SandboxError {
339
- /** The underlying error */
340
- readonly cause?: Error;
341
- constructor(message: string, causeOrMetadata?: Error | SandboxErrorMetadata, metadata?: SandboxErrorMetadata);
342
- }
343
- /** Why the SDK stopped rejoining an execution whose stream dropped. */
344
- 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";
345
- /**
346
- * The stream of an admitted execution ended without its terminal event, and
347
- * the SDK could not rejoin it. The execution's outcome is UNKNOWN: it may
348
- * still be running, or it may have finished while no reader was attached.
349
- * This is never a failure verdict. Rejoin later with `streamPrompt(message,
350
- * { executionId, lastEventId, sessionId })`, or read the session status.
351
- */
352
- declare class StreamInterruptedError extends SandboxError {
353
- readonly executionId: string;
354
- readonly sessionId?: string;
355
- /** The last event id delivered to the caller; replay resumes after it. */
356
- readonly lastEventId?: string;
357
- readonly reason: StreamInterruptionReason;
358
- /** Last HTTP status the replay endpoint answered, when it answered. */
359
- readonly lastReplayStatus?: number;
360
- /** Last execution status the runtime reported, when it reported one. */
361
- readonly lastExecutionStatus?: string;
362
- readonly cause?: unknown;
363
- constructor(details: {
364
- message: string;
365
- executionId: string;
366
- sessionId?: string;
367
- lastEventId?: string;
368
- reason: StreamInterruptionReason;
369
- lastReplayStatus?: number;
370
- lastExecutionStatus?: string;
371
- cause?: unknown;
372
- });
373
- }
374
- /**
375
- * The server returned an unexpected error.
376
- */
377
- declare class ServerError extends SandboxError {
378
- constructor(message: string, status?: number, metadata?: SandboxErrorMetadata, code?: string);
379
- }
380
- //#endregion
381
- //#region src/errors.d.ts
382
- /** A protocol `error` control frame or a transport failure. */
383
- declare class TerminalStreamError extends Error {
384
- /** Protocol error code (e.g. `INIT_FAILED`) or `TRANSPORT` for socket faults. */
385
- readonly code: string;
386
- /**
387
- * True when the socket never reached OPEN: the upgrade was refused (a
388
- * WebSocket client cannot read the HTTP status, so a 401 and a network drop
389
- * look alike) or the runtime rejected the dial's options. No PTY work had
390
- * started on the client's side of that dial.
391
- */
392
- readonly beforeOpen: boolean;
393
- constructor(message: string, code: string, options?: {
394
- beforeOpen?: boolean;
395
- });
396
- }
397
- //#endregion
398
- //#region ../../../packages/runtime-contracts/dist/terminal-websocket.d.ts
399
- /** Non-credential protocol selected during a successful terminal handshake. */
400
- declare const TERMINAL_WS_ECHO_SUBPROTOCOL = "tangle.terminal.v1";
401
- /**
402
- * Server stamps for one attach, in epoch milliseconds on the sidecar's clock.
403
- * They are absolute so a caller can lay them against its own marks and read
404
- * each leg (client clock skew is the only error). `spawn*` and `initPersistAt`
405
- * are absent when the attach adopted a PTY that already existed.
406
- */
407
- declare const terminalReadyTimingsSchema: z.ZodObject<{
408
- upgradeAt: z.ZodNumber;
409
- authAt: z.ZodNumber;
410
- initAt: z.ZodNumber;
411
- loadAt: z.ZodNumber;
412
- spawnAt: z.ZodOptional<z.ZodNumber>;
413
- initPersistAt: z.ZodOptional<z.ZodNumber>;
414
- loadedAt: z.ZodNumber;
415
- historyAt: z.ZodNumber;
416
- historyEvents: z.ZodNumber;
417
- historyBytes: z.ZodNumber;
418
- readyAt: z.ZodNumber;
419
- via: z.ZodEnum<{
420
- upgrade: "upgrade";
421
- frame: "frame";
422
- }>;
423
- ptid: z.ZodOptional<z.ZodString>;
424
- }, z.core.$strip>;
425
- type TerminalReadyTimings = z.infer<typeof terminalReadyTimingsSchema>;
426
- declare const terminalReadyMessageSchema: z.ZodObject<{
427
- type: z.ZodLiteral<"ready">;
428
- connectionId: z.ZodString;
429
- sessionId: z.ZodString;
430
- restored: z.ZodBoolean;
431
- detachTimeoutMs: z.ZodNumber;
432
- attachCount: z.ZodOptional<z.ZodNumber>;
433
- cursors: z.ZodOptional<z.ZodObject<{
434
- earliest: z.ZodNumber;
435
- latest: z.ZodNumber;
436
- }, z.core.$strip>>;
437
- timings: z.ZodOptional<z.ZodObject<{
438
- upgradeAt: z.ZodNumber;
439
- authAt: z.ZodNumber;
440
- initAt: z.ZodNumber;
441
- loadAt: z.ZodNumber;
442
- spawnAt: z.ZodOptional<z.ZodNumber>;
443
- initPersistAt: z.ZodOptional<z.ZodNumber>;
444
- loadedAt: z.ZodNumber;
445
- historyAt: z.ZodNumber;
446
- historyEvents: z.ZodNumber;
447
- historyBytes: z.ZodNumber;
448
- readyAt: z.ZodNumber;
449
- via: z.ZodEnum<{
450
- upgrade: "upgrade";
451
- frame: "frame";
452
- }>;
453
- ptid: z.ZodOptional<z.ZodString>;
454
- }, z.core.$strip>>;
455
- }, z.core.$strip>;
456
- type TerminalReadyMessage = z.infer<typeof terminalReadyMessageSchema>;
457
- type TerminalReadyInfo = Omit<TerminalReadyMessage, "type">;
458
- /** One sequenced output frame for an exact interactive terminal. */
459
- declare const terminalOutputMessageSchema: z.ZodObject<{
460
- type: z.ZodLiteral<"output">;
461
- seq: z.ZodNumber;
462
- data: z.ZodString;
463
- }, z.core.$strip>;
464
- type TerminalOutputMessage = z.infer<typeof terminalOutputMessageSchema>;
465
- declare const terminalExitMessageSchema: z.ZodObject<{
466
- type: z.ZodLiteral<"exit">;
467
- exitCode: z.ZodOptional<z.ZodNumber>;
468
- exitSignal: z.ZodOptional<z.ZodString>;
469
- }, z.core.$strip>;
470
- type TerminalExitMessage = z.infer<typeof terminalExitMessageSchema>;
471
- type TerminalExitInfo = Omit<TerminalExitMessage, "type">;
472
- type TerminalStreamAuthFormat = "edge" | "sidecar-direct";
473
- interface TerminalInteractiveSessionIdentity {
474
- incarnationId: AgentInteractiveSessionRef["incarnationId"];
475
- control: AgentInteractiveSessionControlClaim;
476
- }
477
- //#endregion
478
- //#region src/scoped-token-types.d.ts
479
- /**
480
- * Public types for scoped consumer-side tokens.
481
- *
482
- * This module intentionally has no SDK implementation imports. Terminal
483
- * streams and token requests share these contracts without depending on the
484
- * SDK's aggregate types module.
485
- */
486
- /**
487
- * Scope of a `box.mintScopedToken()` request. `session` and `project` mint
488
- * SessionGateway read tokens. `session-runtime` and `read-only` mint sidecar
489
- * capability tokens for browser-safe runtime access; request access:"read-only"
490
- * on session-runtime for a session event stream without write capabilities.
491
- */
492
- type ScopedTokenScope = "session" | "session-runtime" | "project" | "read-only";
493
- interface MintScopedTokenBase {
494
- /** TTL in minutes. Default 5; clamped to [1, 15]. */
495
- ttlMinutes?: number;
496
- /** Cancel the token request before it reaches the terminal dial. */
497
- signal?: AbortSignal;
498
- }
499
- /** Options for `box.mintScopedToken()`, narrowed by consumer scope. */
500
- type MintScopedTokenOptions = (MintScopedTokenBase & {
501
- scope: "session"; /** Client-facing browser session ID. */
502
- sessionId: string; /** Actual runtime session ID used to filter the sandbox event stream. */
503
- runtimeSessionId: string;
504
- }) | (MintScopedTokenBase & {
505
- scope: "session-runtime";
506
- sessionId: string; /** Restrict this session's bearer to reads; omission also grants workspace/terminal. */
507
- access?: "read-only";
508
- runtimeSessionId?: never;
509
- }) | (MintScopedTokenBase & {
510
- scope: "project" | "read-only";
511
- sessionId?: never;
512
- runtimeSessionId?: never;
513
- });
514
- /** Options for the server-side exact interactive-session token request. */
515
- type MintInteractiveSessionTokenOptions = Pick<MintScopedTokenBase, "ttlMinutes" | "signal">;
516
- /**
517
- * Returned by `box.mintScopedToken()`. Native session streams use a read-only
518
- * session-runtime token. Session/project tokens retain legacy gateway semantics.
519
- */
520
- interface ScopedToken {
521
- /** Bearer token (JWT) for the consumer selected by `scope`. */
522
- token: string;
523
- /** When the token expires. */
524
- expiresAt: Date;
525
- /** The runtime's direct edge URL. Use with runtime scopes; session/project
526
- * tokens instead connect to the Sandbox API's `/session` WebSocket. */
527
- runtimeUrl: string;
528
- /** Browser-safe Sandbox API proxy base for terminal and runtime requests. */
529
- sidecarProxyUrl: string;
530
- /** Echo of the requested scope. */
531
- scope: ScopedTokenScope;
532
- /** Acknowledged session-runtime restriction; absent for unrestricted requests. */
533
- access?: "read-only";
534
- }
535
- //#endregion
536
- //#region src/terminal-stream-types.d.ts
537
- /**
538
- * Event callbacks, passed at construction (the same idiom as
539
- * `SessionGatewayClient`'s `handlers` config). Registering them up front is
540
- * load-bearing: the server replays PTY history immediately after `ready`, so
541
- * a handler attached after connect would miss the replayed screen.
542
- */
543
- interface TerminalStreamHandlers {
544
- /** Raw PTY output bytes (both live output and reattach history replay). */
545
- onData?: (data: Uint8Array) => void;
546
- /** Server-sequenced output for exact interactive terminal sessions. */
547
- onOutput?: (seq: number, data: Uint8Array) => void;
548
- onReady?: (info: TerminalReadyInfo) => void;
549
- onExit?: (info: TerminalExitInfo) => void;
550
- /** Protocol `error` frames and post-connect transport failures. */
551
- onError?: (error: TerminalStreamError) => void;
552
- /** Socket closed — by the server, the network, or a local `close()`. */
553
- onClose?: (code: number, reason: string) => void;
554
- }
555
- /**
556
- * Which WebSocket-subprotocol auth envelope to offer. A WebSocket client
557
- * cannot set an Authorization header, so the bearer rides the
558
- * `Sec-WebSocket-Protocol` offer — and the two dialable endpoints expect
559
- * DIFFERENT envelopes:
560
- *
561
- * - `"edge"` (default): the public API runtime proxy
562
- * (`wss://<api>/v1/sandboxes/{id}/runtime/terminals/{id}/ws`, or its older
563
- * spelling `/v1/sidecar-proxy/{id}/...`) expects
564
- * `bearer.<base64url(token)>` — see `bearerFromSubprotocolOffer` in the
565
- * platform's runtime contracts. The fixed
566
- * `tangle.terminal.v1` marker is offered alongside the credential (see
567
- * {@link TERMINAL_WS_ECHO_SUBPROTOCOL}).
568
- * - `"sidecar-direct"`: the sidecar's own `/terminals/{id}/ws` route expects
569
- * `tangle.bearer.<token>` plus the same `tangle.terminal.v1` echo marker —
570
- * see `apps/sidecar/src/routes/ws-subprotocol-auth.ts`. Only
571
- * platform-internal callers (and the composed integration tests) dial the
572
- * sidecar directly.
573
- */
574
- /**
575
- * Bearer credential for the dial: a token string, or a provider invoked on
576
- * EVERY dial (including {@link TerminalStream.reconnect}). The provider
577
- * receives that dial's AbortSignal so token minting observes cancellation.
578
- * Scoped terminal tokens are short-lived (the platform clamps them to <= 15
579
- * minutes), so a provider lets the SDK re-mint a fresh token per dial.
580
- */
581
- type TerminalStreamBearerToken = string | ScopedToken | ((signal?: AbortSignal) => Promise<string | ScopedToken> | string | ScopedToken);
582
- /**
583
- * The account API key, sent as the `Authorization` header of the upgrade
584
- * instead of a subprotocol credential. Only a runtime that can set headers on
585
- * a WebSocket upgrade (Node, Bun) can dial this way — see
586
- * {@link terminalUpgradeHeadersSupported}; a browser keeps a scoped token. The
587
- * public API proxy takes its owner path for the key, so no scoped token is
588
- * minted first. Dial the public API proxy with it, never the sidecar directly.
589
- */
590
- interface TerminalStreamApiKey {
591
- readonly apiKey: string;
592
- }
593
- type TerminalStreamToken = TerminalStreamBearerToken | TerminalStreamApiKey;
594
- /**
595
- * Wall-clock marks for one attach, in milliseconds on the caller's monotonic
596
- * clock. `server` holds the sidecar's absolute stamps from the `ready` frame
597
- * (epoch milliseconds on the sidecar's clock); a caller lays them against its
598
- * own epoch marks to split each leg.
599
- */
600
- interface TerminalAttachTimings {
601
- /** The caller's wall to mint the scoped token; absent when the dial used the API key. */
602
- mintMs?: number;
603
- /** WebSocket construction to `open`: the upgrade round trip. */
604
- wsOpenMs: number;
605
- /** `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. */
606
- initToReadyMs: number;
607
- /** `ready` to the first output byte (replayed screen or live output); absent until it arrives. */
608
- firstByteMs?: number;
609
- /** The first `write()` to the next output byte; absent until it arrives. */
610
- echoRttMs?: number;
611
- /** How the init was offered: on the upgrade URL as well as in the frame (a default-shell attach), or in the frame alone. */
612
- init: "upgrade" | "frame";
613
- /** The sidecar's stamps; absent from a sidecar that predates them. */
614
- server?: TerminalReadyTimings;
615
- }
616
- /** Authority refreshed before an interactive stream reconnects. */
617
- interface TerminalStreamReconnectBinding {
618
- incarnationId: TerminalInteractiveSessionIdentity["incarnationId"];
619
- control: TerminalInteractiveSessionIdentity["control"];
620
- /** Release a claim if the new socket cannot be opened. */
621
- onFailure?: () => Promise<void> | void;
622
- }
623
- /** Internal SDK hook that reclaims interactive authority before reconnect. */
624
- interface TerminalStreamReconnectAuthority {
625
- acquire(signal?: AbortSignal): Promise<TerminalStreamReconnectBinding>;
626
- }
627
- interface TerminalStreamOptions {
628
- /**
629
- * Absolute URL of the terminal WebSocket endpoint. `http(s)` URLs are
630
- * converted to `ws(s)` automatically.
631
- */
632
- url: string;
633
- /**
634
- * Bearer token carried in the auth subprotocol (see `authFormat`) — a
635
- * string, or a provider re-invoked on every dial so short-lived scoped
636
- * tokens stay fresh across reconnects.
637
- */
638
- token: TerminalStreamToken;
639
- /**
640
- * PTY connection id — also sent in the `init` frame; the server rejects a
641
- * mismatch with the URL's id. Reusing an id reattaches the existing PTY.
642
- */
643
- connectionId: string;
644
- cols?: number;
645
- rows?: number;
646
- /** Command to run when the id has no live PTY (defaults to the shell). */
647
- command?: string;
648
- cwd?: string;
649
- env?: Record<string, string>;
650
- /**
651
- * Exact interactive-agent incarnation. Ordinary terminal consumers omit
652
- * both interactive fields and retain the existing wire contract.
653
- */
654
- incarnationId?: TerminalInteractiveSessionIdentity["incarnationId"];
655
- /** Exact active control claim for the interactive-agent incarnation. */
656
- control?: TerminalInteractiveSessionIdentity["control"];
657
- /** Auth subprotocol envelope. Default `"edge"`. */
658
- authFormat?: TerminalStreamAuthFormat;
659
- handlers?: TerminalStreamHandlers;
660
- /** Reject `connect()` if `ready` has not arrived within this window. */
661
- connectTimeoutMs?: number;
662
- /** Cancel token resolution or an in-progress WebSocket handshake. */
663
- signal?: AbortSignal;
664
- /** Reclaim interactive authority before a reconnecting dial. */
665
- reconnectAuthority?: TerminalStreamReconnectAuthority;
666
- /**
667
- * Correlation id for this attach: sent as `x-tangle-trace-id` where the
668
- * runtime can set upgrade headers, and on the upgrade URL and the `init`
669
- * frame everywhere else. A fresh id is minted when omitted.
670
- */
671
- traceId?: string;
672
- /** Wall the caller spent minting this dial's credential, reported in {@link TerminalAttachTimings}. */
673
- mintMs?: number;
674
- }
675
- //#endregion
676
- export { NetworkError as A, StateError as B, CompliancePlacementError as C, GpuProviderNotConfiguredError as D, FileWriteConflictError as E, ResumeEnvRequiredError as F, SandboxCreateOutcome as G, StreamInterruptionReason as H, SandboxError as I, SandboxCreateReceipt as K, SandboxErrorJson as L, PartialFailureError as M, ProfileFileMountPathError as N, GpuProviderRequirement as O, QuotaError as P, SandboxFailureDetail as R, CapabilityError as S, EgressProxyRecoveryError as T, TimeoutError as U, StreamInterruptedError as V, ValidationError 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, NotFoundError as j, KeyBudgetExhaustedError 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, EdgeNotReadyError as w, BranchFanoutExceedsHostError as x, TerminalStreamError as y, ServerError as z };