@tangle-network/sandbox 0.63.19 → 0.63.21
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/agent/index.d.ts +4 -4
- package/dist/agent/index.js +5 -5
- package/dist/agent/preview.d.ts +1 -1
- package/dist/agent/preview.js +2 -2
- package/dist/{agent-run-outcome-DlYhZnhD.d.ts → agent-run-outcome-C-VR-L0I.d.ts} +1 -1
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +1 -1
- package/dist/{backend-types-D6bYbvMB.js → backend-types-zuUBEJO1.js} +35 -1
- package/dist/{browser-interactive-control-controller-B6sySQFu.d.ts → browser-interactive-control-controller-CvObO_Kf.d.ts} +1 -1
- package/dist/{browser-interactive-control-controller-BJf0P_J4.js → browser-interactive-control-controller-DHx53yre.js} +16 -1
- package/dist/{chunked-upload-KJyRCAiC.js → chunked-upload-DN2twsUu.js} +1 -1
- package/dist/{chunked-upload-file-DfiGzqaR.js → chunked-upload-file-Dpv1YsoA.js} +2 -2
- package/dist/{cli-auth-bundle-CMgB8Ec3.js → cli-auth-bundle-AvhkWJHX.js} +1 -1
- package/dist/{client-Dl22CVOz.js → client-5yqzAcFJ.js} +3271 -3271
- package/dist/client-CqpKC6n3.d.ts +6066 -0
- package/dist/collaboration/index.d.ts +1 -1
- package/dist/collaboration/index.js +1 -1
- package/dist/{collaboration-XHg5BEUI.js → collaboration-g_HzXa6f.js} +1 -1
- package/dist/core.d.ts +6 -7
- package/dist/core.js +5 -5
- package/dist/{direct-http2-Dq7tq6jV.js → direct-http2-CoGVOqVR.js} +1 -1
- package/dist/{errors-AB5BD3FM.js → errors-BfbOP_rx.js} +19 -1
- package/dist/{sandbox-DDdPhk2j.d.ts → index-D4OBUP5M.d.ts} +2105 -1461
- package/dist/index.d.ts +12 -4747
- package/dist/index.js +15 -11
- package/dist/intelligence/index.js +1 -1
- package/dist/interactive-control.d.ts +1 -1
- package/dist/interactive-control.js +1 -1
- package/dist/{interactive-controller-BSWoA0YE.d.ts → interactive-controller-BBwB_5QQ.d.ts} +3 -2
- package/dist/{interactive-controller-zE6hwv3C.js → interactive-controller-D4N4zqmu.js} +578 -610
- package/dist/{lines-hsXVdk60.d.ts → lines-5m11CEj-.d.ts} +21 -17
- package/dist/lines-C5ER4aN_.js +298 -0
- package/dist/lines.d.ts +1 -1
- package/dist/lines.js +1 -295
- package/dist/{local-cli-auth-C4QcPdZt.js → local-cli-auth-CSnvjLAP.js} +1 -1
- package/dist/{mcp-local-BYHcA72Z.js → mcp-local-BjLG7VHY.js} +1 -1
- package/dist/{preview-D8UAF7F9.d.ts → preview-CcJBQSjB.d.ts} +3 -3
- package/dist/{public-templates-BP3sTaSb.d.ts → public-templates-nv4AFFVc.d.ts} +2 -2
- package/dist/public-templates.d.ts +1 -1
- package/dist/public-templates.js +1 -1
- package/dist/runtime.d.ts +47 -40
- package/dist/runtime.js +4 -4
- package/dist/{sandbox-BJkpVtLN.js → sandbox-BGIam_wK.js} +9256 -9215
- package/dist/{secp256k1-DoWlH6ff.js → secp256k1-CmLpsmWl.js} +1 -1
- package/dist/session-gateway/index.d.ts +16 -17
- package/dist/session-gateway/index.js +20 -23
- package/dist/tangle/index.d.ts +1 -1
- package/dist/tangle/index.js +1 -1
- package/dist/{tangle-BBpguPfj.js → tangle--i0MX6UC.js} +144 -138
- package/dist/terminal-stream-types-ClZCArRg.d.ts +662 -0
- package/dist/{types-BxZX2EVj.d.ts → types-BjyQe_CI.d.ts} +393 -315
- package/package.json +5 -5
- package/dist/client-DraGbXEP.d.ts +0 -1249
- package/dist/error-classes-BWS1a9HO.d.ts +0 -321
- package/dist/index-xS3mRl69.d.ts +0 -578
- package/dist/managed-process-B-pXdMLC.d.ts +0 -15
- package/dist/terminal-stream-DgD7GlFi.d.ts +0 -388
- /package/dist/{cli-auth-bundle-BKsrsbxy.d.ts → cli-auth-bundle-Dyw3hCGx.d.ts} +0 -0
- /package/dist/{index-DfA_usrZ.d.ts → index-C8VSFtWl.d.ts} +0 -0
- /package/dist/{index-CWUW8pqr.d.ts → index-CVjTnRWP.d.ts} +0 -0
- /package/dist/{keep-alive-fetch-CXvfSczd.js → keep-alive-fetch-CuwGi7gz.js} +0 -0
- /package/dist/{line-application-UtPFP0o4.js → line-application-DY9ZTdgF.js} +0 -0
- /package/dist/{preview-operations-Bvo5YcIq.js → preview-operations-Ca02vPDJ.js} +0 -0
- /package/dist/{raw-evidence-archive-Bxk6fUjS.js → raw-evidence-archive-CDYDqHNv.js} +0 -0
- /package/dist/{utils-B6gap92T.js → utils-BGvM02yJ.js} +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $ as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { g as SandboxError } from "./error-classes-BWS1a9HO.js";
|
|
1
|
+
import { F as SandboxError, G as SandboxCreateReceipt, g as TerminalReadyInfo, i as TerminalStreamHandlers, l as MintScopedTokenOptions, o as TerminalStreamReconnectAuthority, u as ScopedToken } from "./terminal-stream-types-ClZCArRg.js";
|
|
2
|
+
import { $i as WaitForRolloutOptions, $n as SandboxTerminalAttachOptions, A as ResumeOptions, At as SessionListOptions, B as ProcessManager, Bt as TurnDriveResult, C as StopOptions, Ci as GpuLease, Cr as SandboxRuntimeCapabilities, Ct as SessionEventStreamOptions, D as ProvisionEvent, Da as SandboxTraceOptions, Dr as NetworkManager, Dt as SessionForkOptions, Fi as CodeExecutionResult, Fn as SandboxFleetTraceBundle, Ft as TaskSessionChanges, Gn as SSHCommandDescriptor, It as TaskSessionCommitResult, J as BackendManager, Ji as ForkIdempotency, Jn as SandboxInfo, Ki as BranchOptions, Kn as SSHCredentials, Kr as FileSystem, Mt as SessionMessageAdmission, O as ProvisionResult, Oi as GpuLeaseManager, Ot as SessionInfo, P as WaitForOptions, Pi as CodeExecutionOptions, Pt as SessionResultOptions, Qi as RolloutStartResult, Qn as SandboxRuntimeHealth, Qr as FileWriteResult, Rt as TaskSessionInfo, S as SnapshotResult, Sa as SandboxEvent, Sr as SandboxResourceUsage, Tr as EgressManager, Ui as HttpClient, W as PreviewLinkManager, Wi as JsonValue, Xa as WorkspaceImagePublishResult, Xi as Rollout, Ya as WorkspaceImagePublishInput, Yi as ForkLookupOptions, Yn as SandboxPortBinding, Z as PermissionsManager, Za as CodeLanguage, Zi as RolloutOptions, _r as SandboxShape, _t as ListMessagesOptions, ai as WriteManyFile, ar as StartupDiagnostics, b as SnapshotProvenance, ba as PromptOptions, br as SandboxStatus, bt as SendSessionMessageRequest, c as SandboxDeleteAcknowledgement, ca as DurablePlan, ci as SearchOptions, co as RawEvidenceBoxDirectoryExport, d as SandboxOperationInfo, do as RawEvidenceExportOptions, dr as TeePublicKeyResponse, dt as ConversationTurnResult, et as GitBranch, f as SandboxOperationKind, fr as TerminalStream, ft as CreateSessionOptions, ga as IntelligenceReportCompareTo, gt as DriveTurnOptions, h as SnapshotDeleteAcknowledgement, ha as IntelligenceReportBudget, ho as InteractionResolutionAcknowledgement, ht as DispatchedSession, ii as WriteFileOptions, ir as SandboxTerminals, ja as BackendConfig, jt as SessionMessage, ka as TurnBackendConfig, kt as SessionInterruptOptions, l as SandboxDeleteOptions, la as DurablePlanDecisionOptions, li as ExecOptions, lo as RawEvidenceBoxExportOptions, lr as TeeAttestationResponse, lt as CompletedTurnResult, ma as IntelligenceReport, mr as CreateSandboxOptions, mt as DispatchPromptOptions, no as SandboxEnvRecovery, nt as GitDiff, oi as WriteManyOptions, p as SandboxOperationState, pa as EventStreamOptions, pt as CreateTaskSessionOptions, qi as ForkCounts, qn as SandboxConnection, ro as SandboxEnvRecoveryView, rt as GitStatus, s as RestoreSnapshotOptions, si as SearchMatch, sr as TeeAttestationOptions, st as CommitTaskSessionOptions, t as InstalledTool, tt as GitCommit, ua as DurablePlanDecisionResult, ui as ExecResult, uo as RawEvidenceDirectoryExport, ut as ConversationTurnOptions, v as SnapshotInfo, va as IntelligenceReportWindow, vt as PublicProfileConflict, w as WorkspaceOperationLookup, wa as SandboxTraceBundle, wt as SessionExecutionInfo, xa as PromptResult, xi as DriverInfo, xt as SentSessionMessage, y as SnapshotOptions, ya as PromptInputPart, yt as SendSessionMessageOptions } from "./types-BjyQe_CI.js";
|
|
3
|
+
import { t as CliAuthReference } from "./cli-auth-bundle-Dyw3hCGx.js";
|
|
4
|
+
import { n as SandboxLines } from "./lines-5m11CEj-.js";
|
|
5
|
+
import { f as InteractiveAttachOptions, g as InteractiveSessionStatus, h as InteractiveRequestOptions, m as InteractiveControlClaimOptions, p as InteractiveControlClaimAcknowledgement } from "./browser-interactive-control-controller-CvObO_Kf.js";
|
|
6
|
+
import { r as InteractiveAttachRequest } from "./interactive-controller-BBwB_5QQ.js";
|
|
8
7
|
import { z } from "zod";
|
|
9
|
-
import
|
|
8
|
+
import * as Agent from "@tangle-network/agent-interface";
|
|
9
|
+
import { AgentInteractiveSessionAttach, AgentInteractiveSessionControlClaim, AgentInteractiveSessionControlClaimRequest, AgentInteractiveSessionPromptAcknowledgement, AgentInteractiveSessionPromptCommand, AgentInteractiveSessionRef, AgentInteractiveSessionStart, AgentInteractiveSessionStopAcknowledgement, AgentInteractiveSessionStopCommand, AgentInteractiveTerminalSession, AgentInteractiveTerminalSession as AgentInteractiveTerminalSession$1, AgentProfile, AgentProfileFileMount, AgentRunCancellationAcknowledgement, AgentRunCancellationRequest, InteractionAcknowledgement, InteractionData, InteractionRequest, InteractionResponseCommand, TerminalOutputEvent, TerminalReplayWindow, agentInteractiveSessionPromptRequestDigest } from "@tangle-network/agent-interface";
|
|
10
10
|
|
|
11
11
|
//#region src/mcp.d.ts
|
|
12
12
|
/**
|
|
@@ -119,40 +119,36 @@ declare function buildControlPlaneMcpConfig(options: BuildControlPlaneMcpConfigO
|
|
|
119
119
|
config: SandboxMcpConfig;
|
|
120
120
|
};
|
|
121
121
|
//#endregion
|
|
122
|
-
//#region src/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
attempts: number;
|
|
128
|
-
/** Direct reads that proved the state had not moved; no API call followed. */
|
|
129
|
-
unchanged: number;
|
|
130
|
-
/** Direct reads that saw a change and sent the caller to the API. */
|
|
131
|
-
changed: number;
|
|
132
|
-
/** Reads that went to the API because the direct route could NOT serve. */
|
|
133
|
-
fallbacks: number;
|
|
134
|
-
/** Why the last fallback happened; null until one does. */
|
|
135
|
-
lastReason: DirectReadFallbackReason | null;
|
|
122
|
+
//#region src/operation.d.ts
|
|
123
|
+
/** An accepted operation ended in failure. `code` names why. */
|
|
124
|
+
declare class SandboxOperationFailedError extends SandboxError {
|
|
125
|
+
readonly operation: SandboxOperationInfo;
|
|
126
|
+
constructor(operation: SandboxOperationInfo);
|
|
136
127
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
128
|
+
declare class SandboxOperation {
|
|
129
|
+
#private;
|
|
130
|
+
/**
|
|
131
|
+
* @param client - null for a verb that already finished synchronously.
|
|
132
|
+
* @param onSettled - runs once when the operation is first seen succeeded.
|
|
133
|
+
*/
|
|
134
|
+
constructor(info: SandboxOperationInfo, client: HttpClient | null, onSettled?: (info: SandboxOperationInfo) => void | Promise<void>);
|
|
135
|
+
/** A verb the API finished synchronously, as a succeeded operation. */
|
|
136
|
+
static completed(kind: SandboxOperationKind, sandboxId: string, result?: SandboxOperationInfo["result"]): SandboxOperation;
|
|
137
|
+
get id(): string;
|
|
138
|
+
get state(): SandboxOperationState;
|
|
139
|
+
/** The last state read. */
|
|
140
|
+
get info(): SandboxOperationInfo;
|
|
141
|
+
/** Read the operation's current state. */
|
|
142
|
+
refresh(): Promise<SandboxOperationInfo>;
|
|
143
|
+
/**
|
|
144
|
+
* Poll until the operation is terminal (250 ms, doubling to 2 s). Resolves
|
|
145
|
+
* with a succeeded operation; throws {@link SandboxOperationFailedError} on
|
|
146
|
+
* a failed one and {@link TimeoutError} past `timeoutMs` (default 10 min).
|
|
147
|
+
*/
|
|
148
|
+
wait(options?: {
|
|
149
|
+
timeoutMs?: number;
|
|
150
|
+
signal?: AbortSignal;
|
|
151
|
+
}): Promise<SandboxOperationInfo>;
|
|
156
152
|
}
|
|
157
153
|
//#endregion
|
|
158
154
|
//#region src/interactive-terminal-session.d.ts
|
|
@@ -333,39 +329,33 @@ declare class InteractiveSessionHandle {
|
|
|
333
329
|
stopLifecycle(options?: InteractiveRequestOptions): Promise<AgentInteractiveSessionStopAcknowledgement>;
|
|
334
330
|
}
|
|
335
331
|
//#endregion
|
|
336
|
-
//#region src/
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
332
|
+
//#region src/interaction-response.d.ts
|
|
333
|
+
declare const REFUSED_INTERACTION_STATUS: z.ZodEnum<{
|
|
334
|
+
already_resolved_different: "already_resolved_different";
|
|
335
|
+
binding_mismatch: "binding_mismatch";
|
|
336
|
+
}>;
|
|
337
|
+
type SandboxInteractionResolution = InteractionResolutionAcknowledgement;
|
|
338
|
+
type SandboxInteractionConflict = {
|
|
339
|
+
status: z.infer<typeof REFUSED_INTERACTION_STATUS>;
|
|
340
|
+
message: string;
|
|
341
|
+
existingResponseDigest?: `sha256:${string}`;
|
|
342
|
+
existingOperationId?: string;
|
|
343
|
+
resolvedAt?: string;
|
|
344
|
+
};
|
|
345
|
+
type SandboxInteractionResult = SandboxInteractionResolution | SandboxInteractionConflict;
|
|
346
|
+
/** Canonical acknowledgement and the exact durable server result, when one exists. */
|
|
347
|
+
interface SandboxInteractionCommandResult {
|
|
348
|
+
acknowledgement: InteractionAcknowledgement;
|
|
349
|
+
serverResult?: SandboxInteractionResult;
|
|
341
350
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
*/
|
|
348
|
-
constructor(info: SandboxOperationInfo, client: HttpClient | null, onSettled?: (info: SandboxOperationInfo) => void | Promise<void>);
|
|
349
|
-
/** A verb the API finished synchronously, as a succeeded operation. */
|
|
350
|
-
static completed(kind: SandboxOperationKind, sandboxId: string, result?: SandboxOperationInfo["result"]): SandboxOperation;
|
|
351
|
-
get id(): string;
|
|
352
|
-
get state(): SandboxOperationState;
|
|
353
|
-
/** The last state read. */
|
|
354
|
-
get info(): SandboxOperationInfo;
|
|
355
|
-
/** Read the operation's current state. */
|
|
356
|
-
refresh(): Promise<SandboxOperationInfo>;
|
|
357
|
-
/**
|
|
358
|
-
* Poll until the operation is terminal (250 ms, doubling to 2 s). Resolves
|
|
359
|
-
* with a succeeded operation; throws {@link SandboxOperationFailedError} on
|
|
360
|
-
* a failed one and {@link TimeoutError} past `timeoutMs` (default 10 min).
|
|
361
|
-
*/
|
|
362
|
-
wait(options?: {
|
|
363
|
-
timeoutMs?: number;
|
|
364
|
-
signal?: AbortSignal;
|
|
365
|
-
}): Promise<SandboxOperationInfo>;
|
|
351
|
+
interface SandboxInteractionTransport {
|
|
352
|
+
/** Public sandbox id used by InteractionBinding.environmentId. */
|
|
353
|
+
environmentId: string;
|
|
354
|
+
ensureRunning(): Promise<void>;
|
|
355
|
+
fetch(endpoint: string, request: RequestInit): Promise<Response>;
|
|
366
356
|
}
|
|
367
357
|
//#endregion
|
|
368
|
-
//#region src/profile-file-
|
|
358
|
+
//#region src/profile-file-preparation.d.ts
|
|
369
359
|
interface SplitInlineProfileFileMountsResult {
|
|
370
360
|
leanProfile: AgentProfile;
|
|
371
361
|
deferredFiles: AgentProfileFileMount[];
|
|
@@ -451,7 +441,6 @@ interface SplitInlineProfileSkillsResult {
|
|
|
451
441
|
*/
|
|
452
442
|
declare function splitInlineProfileSkills(profile: AgentProfile): SplitInlineProfileSkillsResult;
|
|
453
443
|
declare function splitInlineProfileFileMounts(profile: AgentProfile): SplitInlineProfileFileMountsResult;
|
|
454
|
-
declare function materializeProfileFileMounts(box: ProfileFileMountBox, files: readonly AgentProfileFileMount[], options?: MaterializeProfileFileMountsOptions): Promise<MaterializeProfileFileMountsResult>;
|
|
455
444
|
//#endregion
|
|
456
445
|
//#region src/profile-file-delivery.d.ts
|
|
457
446
|
/**
|
|
@@ -470,320 +459,23 @@ interface ProfileFileDeliveryReport {
|
|
|
470
459
|
durationMs: number;
|
|
471
460
|
}
|
|
472
461
|
//#endregion
|
|
473
|
-
//#region src/
|
|
474
|
-
type
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
nativeSessionId: string | null;
|
|
488
|
-
proofStatus: "verified" | "unverified";
|
|
489
|
-
containerId?: string;
|
|
490
|
-
sidecarImageDigest: string;
|
|
491
|
-
sidecarBundleRevision: string;
|
|
492
|
-
sidecarBundleChecksum?: string;
|
|
493
|
-
nativeRoots: Array<{
|
|
494
|
-
sourceId?: string;
|
|
495
|
-
rootScope: "session-home" | "workspace-session";
|
|
496
|
-
path: string;
|
|
497
|
-
}>;
|
|
498
|
-
files: Array<Record<string, unknown>>;
|
|
499
|
-
excluded: Array<Record<string, unknown>>;
|
|
500
|
-
skipped: Array<{
|
|
501
|
-
sourceId?: string;
|
|
502
|
-
rootScope: "session-home" | "workspace-session";
|
|
503
|
-
path: string;
|
|
504
|
-
reason: string;
|
|
505
|
-
}>;
|
|
506
|
-
inventory: Record<string, number>;
|
|
507
|
-
processIo: Array<Record<string, unknown>>;
|
|
508
|
-
processTerminals: Array<Record<string, unknown>>; /** Exact raw spool for every readable provider HOME. */
|
|
509
|
-
processSources: Array<{
|
|
510
|
-
sourceId: string;
|
|
511
|
-
contentBase64: string;
|
|
512
|
-
sizeBytes: number;
|
|
513
|
-
sha256: string;
|
|
514
|
-
}>;
|
|
515
|
-
events: Array<Record<string, unknown>>;
|
|
516
|
-
attempts: RawEvidenceAttempt[];
|
|
517
|
-
evidenceSources: Array<{
|
|
518
|
-
executionId: string;
|
|
519
|
-
sourceId: string;
|
|
520
|
-
backendType: string;
|
|
521
|
-
runtimeHome: string;
|
|
522
|
-
credentialPaths: string[];
|
|
523
|
-
}>;
|
|
524
|
-
completeness: {
|
|
525
|
-
nativeStore: boolean;
|
|
526
|
-
processIo: boolean;
|
|
527
|
-
events: boolean;
|
|
528
|
-
};
|
|
529
|
-
coverageComplete: boolean;
|
|
530
|
-
missingReasons: string[];
|
|
531
|
-
} & ({
|
|
532
|
-
status: "captured";
|
|
533
|
-
nativeSessionId: string | null;
|
|
534
|
-
completeness: {
|
|
535
|
-
nativeStore: true;
|
|
536
|
-
processIo: true;
|
|
537
|
-
events: true;
|
|
538
|
-
};
|
|
539
|
-
coverageComplete: true;
|
|
540
|
-
missingReasons: [];
|
|
541
|
-
} | {
|
|
542
|
-
status: "partial";
|
|
543
|
-
coverageComplete: false;
|
|
544
|
-
})) | {
|
|
545
|
-
status: "unavailable";
|
|
546
|
-
sessionId: string;
|
|
547
|
-
backendType: string;
|
|
548
|
-
reason: string;
|
|
549
|
-
};
|
|
550
|
-
/**
|
|
551
|
-
* The subset of `SandboxInstance` a `SandboxSession` drives. Declared here
|
|
552
|
-
* (rather than importing the concrete class) so `session.ts` stays a leaf
|
|
553
|
-
* of `sandbox.ts` — `sandbox.ts` constructs `SandboxSession`, so the reverse
|
|
554
|
-
* import would form a cycle. `SandboxInstance` satisfies this structurally.
|
|
555
|
-
*/
|
|
556
|
-
interface SandboxSessionHost extends InteractiveSessionHost {
|
|
557
|
-
prompt(message: string | PromptInputPart[], options?: PromptOptions): Promise<PromptResult>;
|
|
558
|
-
_sessionStatus(id: string): Promise<SessionInfo | null>;
|
|
559
|
-
_sessionEvents(id: string, opts?: SessionEventStreamOptions): AsyncGenerator<SandboxEvent>;
|
|
560
|
-
_sessionRuns(id: string): Promise<SessionExecutionInfo[]>;
|
|
561
|
-
_sessionRawEvidence(id: string): Promise<RawEvidenceExport>;
|
|
562
|
-
_sessionExportRawEvidence(id: string, destination: string, options: RawEvidenceExportOptions): Promise<RawEvidenceDirectoryExport>;
|
|
563
|
-
_sessionAdmission(id: string, turnId: string, options?: {
|
|
564
|
-
signal?: AbortSignal;
|
|
565
|
-
}): Promise<SessionMessageAdmission | null>;
|
|
566
|
-
_sessionResult(id: string, options?: SessionResultOptions, session?: SessionInfo): Promise<PromptResult>;
|
|
567
|
-
_sessionDelete(id: string): Promise<void>;
|
|
568
|
-
_sessionSendMessage(id: string, request: SendSessionMessageRequest, options?: SendSessionMessageOptions): Promise<SentSessionMessage>;
|
|
569
|
-
messages(opts: ListMessagesOptions): Promise<SessionMessage[]>;
|
|
570
|
-
_sessionFork(id: string, opts?: SessionForkOptions): Promise<SessionInfo>;
|
|
571
|
-
_respondToPermission(id: string, permissionID: string, options: RespondToPermissionOptions): Promise<SandboxInteractionResult>;
|
|
572
|
-
_listInteractions(id: string, options?: {
|
|
573
|
-
signal?: AbortSignal;
|
|
574
|
-
}): Promise<InteractionRequest[]>;
|
|
575
|
-
_respondToInteraction(id: string, command: InteractionResponseCommand, options?: {
|
|
576
|
-
signal?: AbortSignal;
|
|
577
|
-
}): Promise<SandboxInteractionCommandResult>;
|
|
578
|
-
_interrupt(id: string, options?: SessionInterruptOptions): Promise<InterruptResult>;
|
|
579
|
-
_cancelRun(id: string, request: AgentRunCancellationRequest, options?: {
|
|
580
|
-
signal?: AbortSignal;
|
|
581
|
-
}): Promise<AgentRunCancellationAcknowledgement>;
|
|
582
|
-
_answerQuestion(id: string, interactionId: string, answers: InteractionData, options?: {
|
|
583
|
-
signal?: AbortSignal;
|
|
584
|
-
}): Promise<SandboxInteractionResult>;
|
|
585
|
-
_currentPlan(id: string): Promise<DurablePlan | null>;
|
|
586
|
-
_decidePlan(id: string, planId: string, decision: {
|
|
587
|
-
outcome: "approved";
|
|
588
|
-
} | {
|
|
589
|
-
outcome: "rejected";
|
|
590
|
-
feedback: string;
|
|
591
|
-
}, options?: DurablePlanDecisionOptions): Promise<DurablePlanDecisionResult>;
|
|
462
|
+
//#region src/direct-read-route.d.ts
|
|
463
|
+
type DirectReadFallbackReason = "expired" | "refused" | "unreachable" | "timeout" | "malformed" | "cooldown";
|
|
464
|
+
/** What the route has done, for the caller and for the probe. */
|
|
465
|
+
interface DirectReadStats {
|
|
466
|
+
/** Reads offered to this route. */
|
|
467
|
+
attempts: number;
|
|
468
|
+
/** Direct reads that proved the state had not moved; no API call followed. */
|
|
469
|
+
unchanged: number;
|
|
470
|
+
/** Direct reads that saw a change and sent the caller to the API. */
|
|
471
|
+
changed: number;
|
|
472
|
+
/** Reads that went to the API because the direct route could NOT serve. */
|
|
473
|
+
fallbacks: number;
|
|
474
|
+
/** Why the last fallback happened; null until one does. */
|
|
475
|
+
lastReason: DirectReadFallbackReason | null;
|
|
592
476
|
}
|
|
593
|
-
/**
|
|
594
|
-
* A single agent session inside a sandbox. Created via
|
|
595
|
-
* `box.session(id)` — does not hit the network until a method is called.
|
|
596
|
-
*/
|
|
597
|
-
declare class SandboxSession {
|
|
598
|
-
private readonly box;
|
|
599
|
-
/** Stable session id assigned by the sandbox runtime. */
|
|
600
|
-
readonly id: string;
|
|
601
|
-
/**
|
|
602
|
-
* @internal SDK-internal constructor — apps should call `box.session(id)`.
|
|
603
|
-
*/
|
|
604
|
-
constructor(box: SandboxSessionHost, /** Stable session id assigned by the sandbox runtime. */
|
|
605
|
-
|
|
606
|
-
id: string);
|
|
607
|
-
/**
|
|
608
|
-
* Fetch the current session state from the sandbox. Includes status,
|
|
609
|
-
* model, prompt count, token usage if known, and timing metadata.
|
|
610
|
-
*
|
|
611
|
-
* Throws on transport error; returns `null` if the session id is not
|
|
612
|
-
* known to the sandbox (e.g. it ended and was reaped, or the id is
|
|
613
|
-
* invalid).
|
|
614
|
-
*/
|
|
615
|
-
status(): Promise<SessionInfo | null>;
|
|
616
|
-
/**
|
|
617
|
-
* Stream events from this session as they arrive. With no `since`,
|
|
618
|
-
* starts at the live tail; with `since`, replays strictly after that
|
|
619
|
-
* event id — useful for reconnect-after-disconnect flows.
|
|
620
|
-
*
|
|
621
|
-
* The async iterator terminates when the session reaches a terminal
|
|
622
|
-
* state (`completed`, `failed`, `cancelled`) and the corresponding
|
|
623
|
-
* terminal event has been yielded, OR when the caller's signal aborts.
|
|
624
|
-
*/
|
|
625
|
-
events(opts?: SessionEventStreamOptions): AsyncGenerator<SandboxEvent>;
|
|
626
|
-
/**
|
|
627
|
-
* List the durable executions recorded for this session, newest first.
|
|
628
|
-
*
|
|
629
|
-
* This is the runtime's authoritative execution ledger. It lets callers
|
|
630
|
-
* count provider runs without inferring execution from model-written files.
|
|
631
|
-
*/
|
|
632
|
-
runs(): Promise<SessionExecutionInfo[]>;
|
|
633
|
-
/** Capture the complete attributed native store and process stream before deletion. */
|
|
634
|
-
/** Export verified native evidence into a new local directory with bounded memory. */
|
|
635
|
-
exportRawEvidence(destination: string, options: RawEvidenceExportOptions): Promise<RawEvidenceDirectoryExport>;
|
|
636
|
-
rawEvidence(): Promise<RawEvidenceExport>;
|
|
637
|
-
/** Read the exact execution admitted for a turn, including server-owned plan follow-ups.
|
|
638
|
-
* This never admits work or verifies the input of a proposed retry.
|
|
639
|
-
*/
|
|
640
|
-
admission(turnId: string, options?: {
|
|
641
|
-
signal?: AbortSignal;
|
|
642
|
-
}): Promise<SessionMessageAdmission | null>;
|
|
643
|
-
/**
|
|
644
|
-
* Await a terminal result. With `executionId`, drains only that execution;
|
|
645
|
-
* without it, reads status and selects the latest execution. Event replay
|
|
646
|
-
* makes either form safe after the execution has already finished.
|
|
647
|
-
*
|
|
648
|
-
* Use this to wait for a session that was started by another caller
|
|
649
|
-
* (e.g. `dispatchPrompt`).
|
|
650
|
-
*/
|
|
651
|
-
result(options?: SessionResultOptions): Promise<PromptResult>;
|
|
652
|
-
/**
|
|
653
|
-
* List persisted messages for this session, including in-flight assistant
|
|
654
|
-
* content when the runtime has flushed partial output.
|
|
655
|
-
*/
|
|
656
|
-
messages(opts?: Omit<ListMessagesOptions, "sessionId">): Promise<SessionMessage[]>;
|
|
657
|
-
/**
|
|
658
|
-
* Continue this session with an additional prompt. Equivalent to
|
|
659
|
-
* `box.prompt(message, { ...opts, sessionId: this.id })` but reads
|
|
660
|
-
* naturally on a Session reference.
|
|
661
|
-
*/
|
|
662
|
-
prompt(message: string | PromptInputPart[], opts?: PromptOptions): Promise<PromptResult>;
|
|
663
|
-
/**
|
|
664
|
-
* Submit a structured message through the session message endpoint. The
|
|
665
|
-
* returned receipt confirms admission; follow progress with `events()` or
|
|
666
|
-
* await the terminal response with `result()`. Model and message identifiers
|
|
667
|
-
* are translated to the runtime's wire names by the SDK.
|
|
668
|
-
*/
|
|
669
|
-
sendMessage(request: SendSessionMessageRequest, options?: SendSessionMessageOptions): Promise<SentSessionMessage>;
|
|
670
|
-
/** Delete this session and its persisted runtime state. */
|
|
671
|
-
delete(): Promise<void>;
|
|
672
|
-
/**
|
|
673
|
-
* Fork this session into a new queued session. The fork shares the
|
|
674
|
-
* parent workspace and copies conversation history up to `messageId`
|
|
675
|
-
* when supplied.
|
|
676
|
-
*/
|
|
677
|
-
fork(opts?: SessionForkOptions): Promise<{
|
|
678
|
-
session: SandboxSession;
|
|
679
|
-
info: SessionInfo;
|
|
680
|
-
}>;
|
|
681
|
-
/**
|
|
682
|
-
* Drive this session's harness in INTERACTIVE mode: spawn its native TUI,
|
|
683
|
-
* stream the live framebuffer, and inject prompts as keystrokes. Distinct
|
|
684
|
-
* from the headless `prompt()`/`events()` surface above. Lazy — does not hit
|
|
685
|
-
* the network until a handle method is called.
|
|
686
|
-
*/
|
|
687
|
-
interactive(options?: InteractiveSessionHandleOptions): InteractiveSessionHandle;
|
|
688
|
-
/**
|
|
689
|
-
* Resolve a pending permission interaction the agent raised mid-turn,
|
|
690
|
-
* forwarding `allow`/`deny` to the blocked agent through the unified
|
|
691
|
-
* interaction channel. Throws if no matching permission is outstanding.
|
|
692
|
-
*/
|
|
693
|
-
respondToPermission(permissionID: string, options: RespondToPermissionOptions): Promise<SandboxInteractionResult>;
|
|
694
|
-
/** Return every interaction that still awaits a response on this session. */
|
|
695
|
-
interactions(options?: {
|
|
696
|
-
signal?: AbortSignal;
|
|
697
|
-
}): Promise<InteractionRequest[]>;
|
|
698
|
-
/** Respond to one exact interaction with a retry-safe command. */
|
|
699
|
-
respondToInteraction(command: InteractionResponseCommand, options?: {
|
|
700
|
-
signal?: AbortSignal;
|
|
701
|
-
}): Promise<SandboxInteractionCommandResult>;
|
|
702
|
-
/**
|
|
703
|
-
* Interrupt an execution without deleting the session. Pass `executionId`
|
|
704
|
-
* to make the cancellation exact: a newer run on the same session is never
|
|
705
|
-
* touched. Without it, the current execution is selected. Returns
|
|
706
|
-
* `{ cancelled: false }` when the selected execution is not running.
|
|
707
|
-
*/
|
|
708
|
-
interrupt(options?: SessionInterruptOptions): Promise<InterruptResult>;
|
|
709
|
-
/**
|
|
710
|
-
* Cancel one exact run through the durable operation contract. Reusing the
|
|
711
|
-
* same request after a lost response returns the sidecar's replayed
|
|
712
|
-
* acknowledgement instead of issuing a second cancellation.
|
|
713
|
-
*/
|
|
714
|
-
cancelRun(request: AgentRunCancellationRequest, options?: {
|
|
715
|
-
signal?: AbortSignal;
|
|
716
|
-
}): Promise<AgentRunCancellationAcknowledgement>;
|
|
717
|
-
/** Answer one exact question without selecting another outstanding ask. */
|
|
718
|
-
answer(interactionId: string, answers: InteractionData, options?: {
|
|
719
|
-
signal?: AbortSignal;
|
|
720
|
-
}): Promise<SandboxInteractionResult>;
|
|
721
|
-
/** Return the newest plan awaiting a decision for this session. */
|
|
722
|
-
plan(): Promise<DurablePlan | null>;
|
|
723
|
-
/** Approve a durable plan; caller mode returns admission for fresh preparation. */
|
|
724
|
-
approvePlan(planId?: string, options?: DurablePlanDecisionOptions): Promise<DurablePlanDecisionResult>;
|
|
725
|
-
/** Reject a durable plan with feedback; caller mode prepares the revision turn. */
|
|
726
|
-
rejectPlan(feedback: string, planId?: string, options?: DurablePlanDecisionOptions): Promise<DurablePlanDecisionResult>;
|
|
727
|
-
private requireCurrentPlan;
|
|
728
|
-
}
|
|
729
|
-
//#endregion
|
|
730
|
-
//#region src/task-session.d.ts
|
|
731
|
-
/** @internal Operations implemented by `SandboxInstance`. */
|
|
732
|
-
interface SandboxTaskSessionHost extends SandboxSessionHost {
|
|
733
|
-
_taskSessionChanges(id: string): Promise<TaskSessionChanges>;
|
|
734
|
-
_taskSessionCommit(id: string, options?: CommitTaskSessionOptions): Promise<TaskSessionCommitResult>;
|
|
735
|
-
}
|
|
736
|
-
/** A background task session with isolated changeset operations. */
|
|
737
|
-
declare class SandboxTaskSession extends SandboxSession {
|
|
738
|
-
private readonly taskBox;
|
|
739
|
-
/** @internal Apps should call `box.taskSession(id)`. */
|
|
740
|
-
constructor(taskBox: SandboxTaskSessionHost, id: string);
|
|
741
|
-
/** Read the task's isolated file changes. */
|
|
742
|
-
changes(): Promise<TaskSessionChanges>;
|
|
743
|
-
/** Apply all or a selected subset of the task's isolated file changes. */
|
|
744
|
-
commit(options?: CommitTaskSessionOptions): Promise<TaskSessionCommitResult>;
|
|
745
|
-
}
|
|
746
|
-
//#endregion
|
|
747
|
-
//#region src/trace-exporter.d.ts
|
|
748
|
-
type JsonObject = {
|
|
749
|
-
[key: string]: JsonValue;
|
|
750
|
-
};
|
|
751
|
-
type TraceExportFormat = "tangle" | "otel-json";
|
|
752
|
-
type TraceExportBundle = SandboxTraceBundle | SandboxFleetTraceBundle;
|
|
753
|
-
interface TraceExportSink {
|
|
754
|
-
url: string;
|
|
755
|
-
headers?: Record<string, string>;
|
|
756
|
-
format?: TraceExportFormat;
|
|
757
|
-
serviceName?: string;
|
|
758
|
-
timeoutMs?: number;
|
|
759
|
-
fetch?: typeof fetch;
|
|
760
|
-
}
|
|
761
|
-
interface TraceExportResult {
|
|
762
|
-
status: number;
|
|
763
|
-
ok: boolean;
|
|
764
|
-
body: string;
|
|
765
|
-
}
|
|
766
|
-
declare function buildTraceExportPayload(bundle: TraceExportBundle, format?: TraceExportFormat, serviceName?: string): TraceExportBundle | JsonObject;
|
|
767
|
-
declare function exportTraceBundle(bundle: TraceExportBundle, sink: TraceExportSink): Promise<TraceExportResult>;
|
|
768
|
-
declare function toOtelJson(bundle: TraceExportBundle, serviceName?: string): JsonObject;
|
|
769
|
-
declare function otelTraceIdForTangleTrace(traceId: string): string;
|
|
770
477
|
//#endregion
|
|
771
478
|
//#region src/workspace-images.d.ts
|
|
772
|
-
interface WorkspaceImagePublishInput {
|
|
773
|
-
/** Workspace-relative build context. */
|
|
774
|
-
contextPath?: string;
|
|
775
|
-
/** Dockerfile path relative to the build context. */
|
|
776
|
-
dockerfilePath?: string;
|
|
777
|
-
/** Registry host and repository path, without a scheme, tag, or digest. */
|
|
778
|
-
repository: string;
|
|
779
|
-
/** Registry credential used only by the trusted image publisher. */
|
|
780
|
-
auth: {
|
|
781
|
-
username: string;
|
|
782
|
-
password: string;
|
|
783
|
-
};
|
|
784
|
-
platform?: "linux/amd64" | "linux/arm64";
|
|
785
|
-
}
|
|
786
|
-
type WorkspaceImagePublishResult = WorkspaceImagePublishResult$1;
|
|
787
479
|
interface WorkspaceImageHttpClient {
|
|
788
480
|
fetch(path: string, options?: RequestInit, fetchOptions?: {
|
|
789
481
|
timeoutMs?: number;
|
|
@@ -806,114 +498,8 @@ declare class WorkspaceImages {
|
|
|
806
498
|
publish(input: WorkspaceImagePublishInput, options?: WorkspaceImagePublishRequestOptions): Promise<WorkspaceImagePublishResult>;
|
|
807
499
|
}
|
|
808
500
|
//#endregion
|
|
809
|
-
//#region src/sandbox.d.ts
|
|
810
|
-
|
|
811
|
-
* Result of registering a sidecar session mapping. `reprovisionRequired` is
|
|
812
|
-
* true when the server reports the mapped sidecar is stale (HTTP 410) and the
|
|
813
|
-
* caller must reprovision the sandbox before retrying.
|
|
814
|
-
*/
|
|
815
|
-
interface SessionMappingResult {
|
|
816
|
-
success: boolean;
|
|
817
|
-
sessionId: string;
|
|
818
|
-
sidecarSessionId?: string;
|
|
819
|
-
reprovisionRequired: boolean;
|
|
820
|
-
code?: string;
|
|
821
|
-
}
|
|
822
|
-
/**
|
|
823
|
-
* Git capability for repository operations.
|
|
824
|
-
*/
|
|
825
|
-
interface GitCapability {
|
|
826
|
-
/** Get repository status */
|
|
827
|
-
status(): Promise<GitStatus>;
|
|
828
|
-
/** Get commit log */
|
|
829
|
-
log(limit?: number): Promise<GitCommit[]>;
|
|
830
|
-
/** Get diff (optionally against a ref) */
|
|
831
|
-
diff(ref?: string): Promise<GitDiff>;
|
|
832
|
-
/** Stage files */
|
|
833
|
-
add(paths: string[]): Promise<void>;
|
|
834
|
-
/** Create a commit */
|
|
835
|
-
commit(message: string, options?: {
|
|
836
|
-
amend?: boolean;
|
|
837
|
-
}): Promise<GitCommit>;
|
|
838
|
-
/** Push to remote */
|
|
839
|
-
push(options?: {
|
|
840
|
-
force?: boolean;
|
|
841
|
-
}): Promise<void>;
|
|
842
|
-
/** Pull from remote */
|
|
843
|
-
pull(options?: {
|
|
844
|
-
rebase?: boolean;
|
|
845
|
-
}): Promise<void>;
|
|
846
|
-
/** List branches */
|
|
847
|
-
branches(): Promise<GitBranch[]>;
|
|
848
|
-
/** Checkout a branch or ref */
|
|
849
|
-
checkout(ref: string, options?: {
|
|
850
|
-
create?: boolean;
|
|
851
|
-
}): Promise<void>;
|
|
852
|
-
}
|
|
853
|
-
/**
|
|
854
|
-
* Tools capability for managing language runtimes via mise.
|
|
855
|
-
*/
|
|
856
|
-
interface ToolsCapability {
|
|
857
|
-
/** Install a tool version */
|
|
858
|
-
install(tool: string, version: string): Promise<void>;
|
|
859
|
-
/** Activate a tool version for the session */
|
|
860
|
-
use(tool: string, version: string): Promise<void>;
|
|
861
|
-
/** List installed tools */
|
|
862
|
-
list(): Promise<InstalledTool[]>;
|
|
863
|
-
/** Run a command with a specific tool */
|
|
864
|
-
run(tool: string, args: string[]): Promise<ExecResult>;
|
|
865
|
-
}
|
|
866
|
-
/**
|
|
867
|
-
* One fork of a running sandbox, reported with its fan-out accounting.
|
|
868
|
-
*
|
|
869
|
-
* `children` holds the sandboxes that exist. A partial fan-out is never
|
|
870
|
-
* reported as a whole one: `complete` is false whenever `materializedCount` is
|
|
871
|
-
* below `requestedCount`, and the caller decides what to do about the
|
|
872
|
-
* shortfall.
|
|
873
|
-
*/
|
|
874
|
-
interface ForkAcknowledgement extends ForkCounts {
|
|
875
|
-
children: SandboxInstance[];
|
|
876
|
-
/** Present only for a keyed fork against an API that reports it. */
|
|
877
|
-
idempotency?: ForkIdempotency;
|
|
878
|
-
}
|
|
879
|
-
/**
|
|
880
|
-
* A sandbox instance with methods for interaction.
|
|
881
|
-
*/
|
|
882
|
-
declare class SandboxInstance {
|
|
883
|
-
#private;
|
|
884
|
-
private refreshInFlight?;
|
|
885
|
-
private readonly runtime;
|
|
886
|
-
private readonly workspaceImages;
|
|
887
|
-
private readonly interactiveOperations;
|
|
888
|
-
private readonly interactiveTerminalOperations;
|
|
889
|
-
/** @internal Test seam for terminal attach unit tests. */
|
|
890
|
-
private _terminalStreamConnect;
|
|
891
|
-
/**
|
|
892
|
-
* A profile the runtime has cached (create-time priming), letting turns
|
|
893
|
-
* send `backend.profileSha256` instead of re-shipping the profile's static
|
|
894
|
-
* corpus. Set only when priming succeeded; when unset every turn sends the
|
|
895
|
-
* transport profile. `snapshot` is the canonicalized
|
|
896
|
-
* content at prime time — a turn substitutes the reference only when the
|
|
897
|
-
* outgoing profile has identical canonical content, so a caller that mutates the
|
|
898
|
-
* profile in place (or passes an equivalent object) is compared by CONTENT,
|
|
899
|
-
* never by object identity, and a changed profile is sent inline.
|
|
900
|
-
*/
|
|
901
|
-
private deferredProfileReference?;
|
|
902
|
-
private readonly profileFiles;
|
|
903
|
-
/**
|
|
904
|
-
* The profile provenance receipt carried from create-time. Set when the
|
|
905
|
-
* sandbox was created with a profile (inline or catalog); carried forward
|
|
906
|
-
* to every snapshot so the snapshot answers "what configuration produced
|
|
907
|
-
* this state?" without requiring a live profile read.
|
|
908
|
-
*/
|
|
909
|
-
private profileProvenance?;
|
|
910
|
-
/**
|
|
911
|
-
* Direct regional status reads for THIS sandbox. Inert until the API
|
|
912
|
-
* relays a grant, and it retreats to the API path on any failure — see
|
|
913
|
-
* direct-read-route.ts.
|
|
914
|
-
*/
|
|
915
|
-
private readonly directRead;
|
|
916
|
-
constructor(client: HttpClient, info: SandboxInfo, defaultRuntimeBackend?: BackendConfig);
|
|
501
|
+
//#region src/sandbox-info.d.ts
|
|
502
|
+
declare abstract class SandboxInfoCapabilities {
|
|
917
503
|
/** Unique sandbox identifier */
|
|
918
504
|
get id(): string;
|
|
919
505
|
/** Human-readable name */
|
|
@@ -936,6 +522,10 @@ declare class SandboxInstance {
|
|
|
936
522
|
get startedAt(): Date | undefined;
|
|
937
523
|
/** Last activity timestamp */
|
|
938
524
|
get lastActivityAt(): Date | undefined;
|
|
525
|
+
/** Stop phase under `stopped`; see {@link T.SandboxInfo.lifecycleState}. */
|
|
526
|
+
get lifecycleState(): SandboxInfo["lifecycleState"];
|
|
527
|
+
/** When the sandbox entered its current stop. */
|
|
528
|
+
get suspendedAt(): SandboxInfo["suspendedAt"];
|
|
939
529
|
/** When the sandbox will expire */
|
|
940
530
|
get expiresAt(): Date | undefined;
|
|
941
531
|
/** Error message if status is 'failed' */
|
|
@@ -1010,45 +600,12 @@ declare class SandboxInstance {
|
|
|
1010
600
|
includeSecrets?: boolean;
|
|
1011
601
|
}): SandboxInfo;
|
|
1012
602
|
/**
|
|
1013
|
-
*
|
|
1014
|
-
*
|
|
1015
|
-
* Runtime methods on the returned instance talk to the sandbox runtime
|
|
1016
|
-
* directly using `connection.execHost` when supplied, otherwise
|
|
1017
|
-
* `connection.runtimeUrl`, and the scoped `connection.authToken`.
|
|
1018
|
-
* Lifecycle methods still go through the parent SDK client.
|
|
603
|
+
* Refresh sandbox information from the server.
|
|
1019
604
|
*/
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
* codex, opencode, …) plus a freshly-minted, capability-scoped JWT.
|
|
1025
|
-
*
|
|
1026
|
-
* The token is short-lived and limited to the requested capabilities
|
|
1027
|
-
* — it cannot be used against admin endpoints (`/exec`, `/files`,
|
|
1028
|
-
* etc.) on the sandbox. Call `getMcpEndpoint()` again to rotate.
|
|
1029
|
-
*
|
|
1030
|
-
* Requires the sandbox to have been created with `capabilities`
|
|
1031
|
-
* including the requested capability (default: `computer_use`).
|
|
1032
|
-
*
|
|
1033
|
-
* @example
|
|
1034
|
-
* ```typescript
|
|
1035
|
-
* const ep = await box.getMcpEndpoint();
|
|
1036
|
-
* // Save ep.config to your IDE's mcp.json — that's it.
|
|
1037
|
-
* fs.writeFileSync("mcp.json", JSON.stringify(ep.config, null, 2));
|
|
1038
|
-
* ```
|
|
1039
|
-
*/
|
|
1040
|
-
getMcpEndpoint(options?: {
|
|
1041
|
-
capabilities?: ReadonlyArray<"computer_use">; /** Override server entry name (default: "tangle-sandbox"). */
|
|
1042
|
-
serverName?: string; /** Token TTL in minutes (server clamps to its policy). */
|
|
1043
|
-
ttlMinutes?: number;
|
|
1044
|
-
}): Promise<SandboxMcpEndpoint>;
|
|
1045
|
-
/**
|
|
1046
|
-
* Refresh sandbox information from the server.
|
|
1047
|
-
*/
|
|
1048
|
-
refresh(signal?: AbortSignal): Promise<void>;
|
|
1049
|
-
private refreshFor;
|
|
1050
|
-
private refreshInfo;
|
|
1051
|
-
private readStatus;
|
|
605
|
+
refresh(signal?: AbortSignal): Promise<void>;
|
|
606
|
+
protected refreshFor(reason: RefreshReason, signal?: AbortSignal): Promise<void>;
|
|
607
|
+
protected refreshInfo(reason: RefreshReason): Promise<void>;
|
|
608
|
+
protected readStatus(reason: RefreshReason): Promise<void>;
|
|
1052
609
|
/**
|
|
1053
610
|
* What the direct regional read route has done for this sandbox: attempts,
|
|
1054
611
|
* reads it served, reads that fell back to the API, and the last reason.
|
|
@@ -1061,239 +618,354 @@ declare class SandboxInstance {
|
|
|
1061
618
|
*/
|
|
1062
619
|
adoptDirectRead(payload: Record<string, unknown>): void;
|
|
1063
620
|
/**
|
|
1064
|
-
*
|
|
1065
|
-
*
|
|
1066
|
-
* When `attestationNonce` is supplied, the runtime must return evidence bound
|
|
1067
|
-
* to that challenge or fail closed if the selected TEE backend cannot support
|
|
1068
|
-
* nonce-bound report data. *
|
|
1069
|
-
* Throws `CapabilityError` (`TEE_UNSUPPORTED`) when the deployment does not
|
|
1070
|
-
* serve the TEE intercept — these paths are answered by a Tangle
|
|
1071
|
-
* confidential operator ahead of the sandbox API, which registers no route
|
|
1072
|
-
* for them. That refusal is recognised from the API's own unmatched-route
|
|
1073
|
-
* answer, so an intermediary that rewrites 404 bodies leaves the ordinary
|
|
1074
|
-
* `NotFoundError` in its place rather than the named refusal.
|
|
1075
|
-
*/
|
|
1076
|
-
getTeeAttestation(options?: TeeAttestationOptions): Promise<TeeAttestationResponse>;
|
|
1077
|
-
/**
|
|
1078
|
-
* Fetch the TEE-bound public key used for sealed-secret encryption.
|
|
1079
|
-
*
|
|
1080
|
-
* The returned key includes an attestation report. Verify that report before
|
|
1081
|
-
* encrypting secrets to the key. *
|
|
1082
|
-
* Throws `CapabilityError` (`TEE_UNSUPPORTED`) when the deployment does not
|
|
1083
|
-
* serve the TEE intercept — these paths are answered by a Tangle
|
|
1084
|
-
* confidential operator ahead of the sandbox API, which registers no route
|
|
1085
|
-
* for them. That refusal is recognised from the API's own unmatched-route
|
|
1086
|
-
* answer, so an intermediary that rewrites 404 bodies leaves the ordinary
|
|
1087
|
-
* `NotFoundError` in its place rather than the named refusal.
|
|
1088
|
-
*/
|
|
1089
|
-
getTeePublicKey(): Promise<TeePublicKeyResponse>;
|
|
1090
|
-
/**
|
|
1091
|
-
* Bootstrap a real-time collaboration session for a file.
|
|
1092
|
-
* Returns the WebSocket URL and auth token needed to connect a
|
|
1093
|
-
* Hocuspocus/Yjs provider for live multi-user editing.
|
|
621
|
+
* Read a lifecycle response body once.
|
|
1094
622
|
*
|
|
1095
|
-
*
|
|
1096
|
-
*
|
|
1097
|
-
* const collab = await box.collaborate("src/index.ts")
|
|
1098
|
-
* // Use collab.transport.websocketUrl + collab.transport.token
|
|
1099
|
-
* // with @hocuspocus/provider to connect
|
|
1100
|
-
* ```
|
|
1101
|
-
*/
|
|
1102
|
-
collaborate(path: string, options?: {
|
|
1103
|
-
access?: "read" | "write";
|
|
1104
|
-
}): Promise<{
|
|
1105
|
-
documentId: string;
|
|
1106
|
-
transport: {
|
|
1107
|
-
websocketUrl: string;
|
|
1108
|
-
token: string;
|
|
1109
|
-
expiresAt: number;
|
|
1110
|
-
};
|
|
1111
|
-
permissions: {
|
|
1112
|
-
access: "read" | "write";
|
|
1113
|
-
canSnapshot: boolean;
|
|
1114
|
-
};
|
|
1115
|
-
}>;
|
|
1116
|
-
/**
|
|
1117
|
-
* Refresh a collaboration token for an existing document session.
|
|
623
|
+
* Current APIs return the complete sandbox state. Older APIs return an empty
|
|
624
|
+
* body, so callers refresh when this method cannot recover a state payload.
|
|
1118
625
|
*/
|
|
626
|
+
protected readLifecycleResponse(response: Response): Promise<Record<string, unknown> | null>;
|
|
627
|
+
protected applyLifecycleResponse(data: Record<string, unknown> | null): boolean;
|
|
628
|
+
protected hasFreshStatus(): boolean;
|
|
1119
629
|
/**
|
|
1120
|
-
*
|
|
1121
|
-
*
|
|
630
|
+
* The check before a runtime call. A handle that has seen the sandbox
|
|
631
|
+
* running and ready dispatches at once: the authenticated runtime route
|
|
632
|
+
* checks current sandbox state itself, so a status GET before every call was
|
|
633
|
+
* a whole round trip through the Worker that only moved the same refusal
|
|
634
|
+
* earlier. A stale cache surfaces as the call's own answer, which the
|
|
635
|
+
* direct client and the prompt stream turn into a typed `StateError`. A
|
|
636
|
+
* handle that has not seen the status, or saw one that is not runnable,
|
|
637
|
+
* reads it first.
|
|
1122
638
|
*/
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
639
|
+
protected ensureRunning(signal?: AbortSignal): Promise<void>;
|
|
640
|
+
/** Why the status must be read before a runtime call, or undefined to trust the cache. */
|
|
641
|
+
protected statusReadReason(): RefreshReason | undefined;
|
|
642
|
+
protected assertRunnable(): void;
|
|
643
|
+
protected assertFilesystemIncarnationReady(): void;
|
|
1128
644
|
/**
|
|
1129
|
-
*
|
|
1130
|
-
*
|
|
645
|
+
* One authenticated runtime HTTP call for this sandbox, relative endpoint
|
|
646
|
+
* (`/agents/...`), scoped to the current filesystem incarnation. This is
|
|
647
|
+
* the transport `/agents/profiles` rides and the box surface mount
|
|
648
|
+
* delivery uses for profile-bundle cache claim/publish.
|
|
1131
649
|
*/
|
|
1132
|
-
|
|
1133
|
-
|
|
650
|
+
runtimeFetch(path: string, options?: RequestInit, fetchOptions?: {
|
|
651
|
+
timeoutMs?: number;
|
|
652
|
+
}): Promise<Response>;
|
|
1134
653
|
/**
|
|
1135
|
-
*
|
|
1136
|
-
*
|
|
654
|
+
* Parse a sandbox API payload into `SandboxInfo`.
|
|
655
|
+
*
|
|
656
|
+
* `carryCreateFacts` supplies the create-time facts a refresh must keep:
|
|
657
|
+
* the GPU lease, the startup diagnostics, and the create receipt each arrive
|
|
658
|
+
* once on the create response and are absent from every later payload. They
|
|
659
|
+
* describe ONE environment's creation, so they travel only when the payload
|
|
660
|
+
* describes that same environment. A payload for a different sandbox — a
|
|
661
|
+
* branch child parsed through its parent — passes no carry, or the child
|
|
662
|
+
* would report its parent's create verdict.
|
|
1137
663
|
*/
|
|
1138
|
-
|
|
664
|
+
protected parseInfo(data: Record<string, unknown>, carryCreateFacts?: Pick<SandboxInfo, "gpuLease" | "startupDiagnostics" | "createReceipt">): SandboxInfo;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Why a status read was sent: the `sdk.refresh` span's `desc` and the value of
|
|
668
|
+
* the `x-tangle-refresh-reason` header, so a status GET that costs a round
|
|
669
|
+
* trip is attributable instead of anonymous.
|
|
670
|
+
*
|
|
671
|
+
* - `caller`: the caller asked (`refresh()`).
|
|
672
|
+
* - `poll`, `lifecycle`: a wait loop, or a lifecycle verb that needs the state.
|
|
673
|
+
* - `unobserved`: this handle has never seen the sandbox's status.
|
|
674
|
+
* - `not-running`: the cached status is not a runnable one, so it may have moved.
|
|
675
|
+
* - `bearer-refused`, `runtime-refused`: the runtime refused the call, which is
|
|
676
|
+
* the only evidence that a cached `running` went stale.
|
|
677
|
+
*/
|
|
678
|
+
type RefreshReason = "caller" | "poll" | "lifecycle" | "unobserved" | "not-running" | "bearer-refused" | "runtime-refused";
|
|
679
|
+
//#endregion
|
|
680
|
+
//#region src/sandbox-workspace-git.d.ts
|
|
681
|
+
/**
|
|
682
|
+
* Git capability for repository operations.
|
|
683
|
+
*/
|
|
684
|
+
interface GitCapability {
|
|
685
|
+
/** Get repository status */
|
|
686
|
+
status(): Promise<GitStatus>;
|
|
687
|
+
/** Get commit log */
|
|
688
|
+
log(limit?: number): Promise<GitCommit[]>;
|
|
689
|
+
/** Get diff (optionally against a ref) */
|
|
690
|
+
diff(ref?: string): Promise<GitDiff>;
|
|
691
|
+
/** Stage files */
|
|
692
|
+
add(paths: string[]): Promise<void>;
|
|
693
|
+
/** Create a commit */
|
|
694
|
+
commit(message: string, options?: {
|
|
695
|
+
amend?: boolean;
|
|
696
|
+
}): Promise<GitCommit>;
|
|
697
|
+
/** Push to remote */
|
|
698
|
+
push(options?: {
|
|
699
|
+
force?: boolean;
|
|
700
|
+
}): Promise<void>;
|
|
701
|
+
/** Pull from remote */
|
|
702
|
+
pull(options?: {
|
|
703
|
+
rebase?: boolean;
|
|
704
|
+
}): Promise<void>;
|
|
705
|
+
/** List branches */
|
|
706
|
+
branches(): Promise<GitBranch[]>;
|
|
707
|
+
/** Checkout a branch or ref */
|
|
708
|
+
checkout(ref: string, options?: {
|
|
709
|
+
create?: boolean;
|
|
710
|
+
}): Promise<void>;
|
|
711
|
+
}
|
|
712
|
+
declare abstract class SandboxGitCapabilities extends SandboxInfoCapabilities {
|
|
1139
713
|
/**
|
|
1140
|
-
*
|
|
1141
|
-
*
|
|
1142
|
-
* Each `(sessionId, language)` pair gets its own long-lived kernel that
|
|
1143
|
-
* keeps variable state across calls — like Jupyter cells. Without a
|
|
1144
|
-
* `sessionId`, calls share a process-wide kernel per language.
|
|
1145
|
-
*
|
|
1146
|
-
* Returns typed results: stdout/stderr text plus a `results` array of
|
|
1147
|
-
* structured outputs (matplotlib images as base64 PNG, pandas DataFrames,
|
|
1148
|
-
* explicit `display(value)` calls as JSON/HTML, errors with traceback).
|
|
714
|
+
* Git capability object for repository operations.
|
|
1149
715
|
*
|
|
1150
|
-
*
|
|
1151
|
-
* ```ts
|
|
1152
|
-
* await box.runCode("python", "import pandas as pd; df = pd.DataFrame({'x': range(5)})", { sessionId: "s1" });
|
|
1153
|
-
* const r = await box.runCode("python", "df.describe()", { sessionId: "s1" });
|
|
1154
|
-
* // r.results[0] is a `dataframe` part with columns + rows from the describe()
|
|
1155
|
-
* ```
|
|
716
|
+
* All git operations are executed in the sandbox workspace.
|
|
1156
717
|
*
|
|
1157
|
-
* @example
|
|
1158
|
-
* ```
|
|
1159
|
-
* const
|
|
1160
|
-
*
|
|
1161
|
-
*
|
|
1162
|
-
*
|
|
1163
|
-
*
|
|
718
|
+
* @example Check status and commit
|
|
719
|
+
* ```typescript
|
|
720
|
+
* const status = await box.git.status();
|
|
721
|
+
* if (status.isDirty) {
|
|
722
|
+
* await box.git.add(["."]);
|
|
723
|
+
* await box.git.commit("Update files");
|
|
724
|
+
* await box.git.push();
|
|
725
|
+
* }
|
|
1164
726
|
* ```
|
|
1165
727
|
*/
|
|
1166
|
-
|
|
728
|
+
get git(): GitCapability;
|
|
729
|
+
private gitStatus;
|
|
730
|
+
private gitLog;
|
|
731
|
+
private gitDiff;
|
|
732
|
+
private gitAdd;
|
|
733
|
+
private gitCommit;
|
|
734
|
+
private gitPush;
|
|
735
|
+
private gitPull;
|
|
736
|
+
private gitBranches;
|
|
737
|
+
private gitCheckout;
|
|
738
|
+
}
|
|
739
|
+
//#endregion
|
|
740
|
+
//#region src/sandbox-workspace-permissions.d.ts
|
|
741
|
+
declare abstract class SandboxPermissionsCapabilities extends SandboxGitCapabilities {
|
|
1167
742
|
/**
|
|
1168
|
-
*
|
|
743
|
+
* Permissions manager for multi-user access control.
|
|
1169
744
|
*
|
|
1170
|
-
* @
|
|
1171
|
-
*
|
|
1172
|
-
*
|
|
745
|
+
* @example List users
|
|
746
|
+
* ```typescript
|
|
747
|
+
* const users = await box.permissions.list();
|
|
748
|
+
* for (const user of users) {
|
|
749
|
+
* console.log(`${user.username}: ${user.role}`);
|
|
750
|
+
* }
|
|
751
|
+
* ```
|
|
1173
752
|
*
|
|
1174
|
-
* @example
|
|
753
|
+
* @example Add a developer
|
|
1175
754
|
* ```typescript
|
|
1176
|
-
*
|
|
1177
|
-
*
|
|
755
|
+
* await box.permissions.add({
|
|
756
|
+
* userId: "user_abc",
|
|
757
|
+
* role: "developer",
|
|
758
|
+
* sshKeys: ["ssh-ed25519 AAAA..."],
|
|
759
|
+
* });
|
|
1178
760
|
* ```
|
|
1179
761
|
*/
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
762
|
+
get permissions(): PermissionsManager;
|
|
763
|
+
private permissionsList;
|
|
764
|
+
private permissionsGet;
|
|
765
|
+
private permissionsAdd;
|
|
766
|
+
private permissionsUpdate;
|
|
767
|
+
private permissionsRemove;
|
|
768
|
+
private permissionsSetAccessPolicies;
|
|
769
|
+
private permissionsGetAccessPolicies;
|
|
770
|
+
private permissionsCheckAccess;
|
|
771
|
+
}
|
|
772
|
+
//#endregion
|
|
773
|
+
//#region src/sandbox-workspace-backend.d.ts
|
|
774
|
+
declare abstract class SandboxBackendCapabilities extends SandboxPermissionsCapabilities {
|
|
1184
775
|
/**
|
|
1185
|
-
*
|
|
776
|
+
* Backend manager for runtime agent configuration.
|
|
1186
777
|
*
|
|
1187
|
-
* @
|
|
1188
|
-
*
|
|
1189
|
-
*
|
|
778
|
+
* @example Check backend status
|
|
779
|
+
* ```typescript
|
|
780
|
+
* const status = await box.backend.status();
|
|
781
|
+
* console.log(`Backend: ${status.type}, Status: ${status.status}`);
|
|
782
|
+
* ```
|
|
1190
783
|
*
|
|
1191
|
-
* @example
|
|
784
|
+
* @example Point the backend at a different model
|
|
1192
785
|
* ```typescript
|
|
1193
|
-
* await box.
|
|
1194
|
-
*
|
|
786
|
+
* await box.backend.updateConfig({ model: "openai/gpt-5-mini" });
|
|
787
|
+
* ```
|
|
788
|
+
*
|
|
789
|
+
* @example Read provider-native Cursor metadata
|
|
790
|
+
* ```typescript
|
|
791
|
+
* const models = await box.backend.models();
|
|
792
|
+
* const agents = await box.backend.agents({ limit: 20 });
|
|
793
|
+
* const runs = await box.backend.runs(agents.items[0].agentId);
|
|
1195
794
|
* ```
|
|
1196
795
|
*/
|
|
1197
|
-
|
|
1198
|
-
private
|
|
1199
|
-
private
|
|
1200
|
-
private
|
|
1201
|
-
private
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
private
|
|
796
|
+
get backend(): BackendManager;
|
|
797
|
+
private backendStatus;
|
|
798
|
+
private backendGetMcpStatus;
|
|
799
|
+
private backendUpdateConfig;
|
|
800
|
+
private backendControlData;
|
|
801
|
+
private backendControlAction;
|
|
802
|
+
private backendListSearch;
|
|
803
|
+
private backendAccount;
|
|
804
|
+
private backendModels;
|
|
805
|
+
private backendRepositories;
|
|
806
|
+
private backendAgents;
|
|
807
|
+
private backendAgent;
|
|
808
|
+
private backendArchiveAgent;
|
|
809
|
+
private backendUnarchiveAgent;
|
|
810
|
+
private backendDeleteAgent;
|
|
811
|
+
private backendRuns;
|
|
812
|
+
private backendRun;
|
|
813
|
+
private backendAgentMessages;
|
|
814
|
+
private backendArtifacts;
|
|
815
|
+
private backendDownloadArtifact;
|
|
816
|
+
private backendRestart;
|
|
817
|
+
}
|
|
818
|
+
//#endregion
|
|
819
|
+
//#region src/sandbox-workspace-process.d.ts
|
|
820
|
+
declare abstract class SandboxProcessCapabilities extends SandboxBackendCapabilities {
|
|
1213
821
|
/**
|
|
1214
|
-
*
|
|
1215
|
-
* Use this for real-time updates during agent execution.
|
|
822
|
+
* Process manager for spawning and controlling processes.
|
|
1216
823
|
*
|
|
1217
|
-
*
|
|
1218
|
-
*
|
|
1219
|
-
*
|
|
1220
|
-
*
|
|
824
|
+
* Provides non-blocking process execution with real-time log streaming,
|
|
825
|
+
* ideal for long-running tasks like ML training or dev servers.
|
|
826
|
+
*
|
|
827
|
+
* @example Non-blocking process
|
|
828
|
+
* ```typescript
|
|
829
|
+
* const proc = await box.process.spawn("python train.py", {
|
|
830
|
+
* cwd: "/workspace",
|
|
831
|
+
* env: { "CUDA_VISIBLE_DEVICES": "0" }
|
|
832
|
+
* });
|
|
833
|
+
*
|
|
834
|
+
* // Stream logs
|
|
835
|
+
* for await (const entry of proc.logs()) {
|
|
836
|
+
* console.log(`[${entry.type}] ${entry.data}`);
|
|
837
|
+
* }
|
|
838
|
+
*
|
|
839
|
+
* // Check status
|
|
840
|
+
* const status = await proc.status();
|
|
841
|
+
* console.log(`Running: ${status.running}`);
|
|
842
|
+
*
|
|
843
|
+
* // Kill if needed
|
|
844
|
+
* await proc.kill();
|
|
845
|
+
* ```
|
|
1221
846
|
*
|
|
1222
|
-
* Automatically reconnects via the runtime event replay endpoint if the
|
|
1223
|
-
* SSE stream drops before a terminal event (`done` or `error`) is
|
|
1224
|
-
* received. Reconnection is transparent — replayed events that were
|
|
1225
|
-
* already yielded (based on event ID tracking) are deduplicated.
|
|
1226
847
|
*/
|
|
848
|
+
get process(): ProcessManager;
|
|
849
|
+
private processEnsureDevServer;
|
|
850
|
+
private processSpawn;
|
|
851
|
+
private processSpawnExact;
|
|
852
|
+
private processList;
|
|
853
|
+
private processGet;
|
|
854
|
+
private createProcessHandle;
|
|
855
|
+
private parseProcessLogStream;
|
|
856
|
+
}
|
|
857
|
+
//#endregion
|
|
858
|
+
//#region src/sandbox-workspace-network.d.ts
|
|
859
|
+
declare abstract class SandboxNetworkCapabilities extends SandboxProcessCapabilities {
|
|
1227
860
|
/**
|
|
1228
|
-
*
|
|
1229
|
-
*
|
|
1230
|
-
*
|
|
1231
|
-
*
|
|
1232
|
-
*
|
|
1233
|
-
*
|
|
1234
|
-
*
|
|
861
|
+
* Port exposure and runtime network state.
|
|
862
|
+
*
|
|
863
|
+
* Outbound restrictions are on {@link SandboxInstance.egress}: `update()`
|
|
864
|
+
* here rejects every policy field rather than recording one nothing
|
|
865
|
+
* enforces.
|
|
866
|
+
*
|
|
867
|
+
* @example Expose ports dynamically
|
|
868
|
+
* ```typescript
|
|
869
|
+
* const url = await box.network.exposePort(8000);
|
|
870
|
+
* console.log(`Service available at: ${url}`);
|
|
871
|
+
* ```
|
|
872
|
+
*
|
|
873
|
+
* @example Restrict outbound traffic
|
|
874
|
+
* ```typescript
|
|
875
|
+
* await box.egress.update({ mode: "blocked" });
|
|
876
|
+
* ```
|
|
1235
877
|
*/
|
|
1236
|
-
|
|
878
|
+
get network(): NetworkManager;
|
|
879
|
+
private networkUpdate;
|
|
880
|
+
private networkExposePort;
|
|
881
|
+
private networkListUrls;
|
|
882
|
+
private networkGetConfig;
|
|
1237
883
|
/**
|
|
1238
|
-
*
|
|
1239
|
-
* to the runtime (`POST /agents/profiles`) and record
|
|
1240
|
-
* the returned transport-profile hash via {@link attachProfileReference}, so subsequent turns
|
|
1241
|
-
* reference it by `profileSha256` instead of re-sending the corpus.
|
|
1242
|
-
* `create()` calls this automatically for its inline profile when
|
|
1243
|
-
* `autoDeferProfile` is on; call it directly when the profile only exists
|
|
1244
|
-
* per-turn, or when the instance was fetched rather than created. Persist
|
|
1245
|
-
* the returned sha256 alongside a content hash of the profile to
|
|
1246
|
-
* re-attach on later instances without re-priming. Throws on transport/HTTP
|
|
1247
|
-
* failure — the caller decides whether that is fatal (it is not: turns fall
|
|
1248
|
-
* back to sending the file-free profile inline).
|
|
884
|
+
* Validate CIDR notation (IPv4 and IPv6)
|
|
1249
885
|
*/
|
|
1250
|
-
|
|
886
|
+
private isValidCidr;
|
|
887
|
+
}
|
|
888
|
+
//#endregion
|
|
889
|
+
//#region src/sandbox-workspace-gpu.d.ts
|
|
890
|
+
declare abstract class SandboxGpuCapabilities extends SandboxNetworkCapabilities {
|
|
1251
891
|
/**
|
|
1252
|
-
*
|
|
1253
|
-
*
|
|
1254
|
-
*
|
|
1255
|
-
*
|
|
1256
|
-
* not object identity, so a mutated-in-place profile — or an equivalent
|
|
1257
|
-
* object passed as a per-turn override — is compared correctly: unchanged
|
|
1258
|
-
* content references by hash, changed content sends inline.
|
|
892
|
+
* On-demand GPU leases attached to this sandbox.
|
|
893
|
+
*
|
|
894
|
+
* The base sandbox stays cheap; `attach` starts a temporary external GPU
|
|
895
|
+
* worker with an explicit spend cap, and `detach` destroys it.
|
|
1259
896
|
*/
|
|
897
|
+
get gpu(): GpuLeaseManager;
|
|
898
|
+
private gpuProviders;
|
|
899
|
+
private gpuAttach;
|
|
900
|
+
private gpuList;
|
|
901
|
+
private gpuExec;
|
|
902
|
+
private gpuDetach;
|
|
903
|
+
}
|
|
904
|
+
//#endregion
|
|
905
|
+
//#region src/sandbox-workspace-preview.d.ts
|
|
906
|
+
declare abstract class SandboxPreviewCapabilities extends SandboxGpuCapabilities {
|
|
1260
907
|
/**
|
|
1261
|
-
*
|
|
1262
|
-
*
|
|
1263
|
-
*
|
|
908
|
+
* Preview link management.
|
|
909
|
+
*
|
|
910
|
+
* Create publicly accessible HTTPS URLs for TCP ports inside the sandbox.
|
|
911
|
+
*
|
|
912
|
+
* @example
|
|
913
|
+
* ```typescript
|
|
914
|
+
* const link = await box.previewLinks.create(3000);
|
|
915
|
+
* console.log(link.url);
|
|
916
|
+
*
|
|
917
|
+
* const links = await box.previewLinks.list();
|
|
918
|
+
* await box.previewLinks.remove(link.previewId);
|
|
919
|
+
* ```
|
|
1264
920
|
*/
|
|
1265
|
-
get
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
private
|
|
1269
|
-
|
|
921
|
+
get previewLinks(): PreviewLinkManager;
|
|
922
|
+
private previewLinkCreate;
|
|
923
|
+
private previewLinkList;
|
|
924
|
+
private previewLinkGet;
|
|
925
|
+
private previewLinkWaitUntilReady;
|
|
926
|
+
private previewLinkRemove;
|
|
927
|
+
}
|
|
928
|
+
//#endregion
|
|
929
|
+
//#region src/sandbox-workspace-tools.d.ts
|
|
930
|
+
/**
|
|
931
|
+
* Tools capability for managing language runtimes via mise.
|
|
932
|
+
*/
|
|
933
|
+
interface ToolsCapability {
|
|
934
|
+
/** Install a tool version */
|
|
935
|
+
install(tool: string, version: string): Promise<void>;
|
|
936
|
+
/** Activate a tool version for the session */
|
|
937
|
+
use(tool: string, version: string): Promise<void>;
|
|
938
|
+
/** List installed tools */
|
|
939
|
+
list(): Promise<InstalledTool[]>;
|
|
940
|
+
/** Run a command with a specific tool */
|
|
941
|
+
run(tool: string, args: string[]): Promise<ExecResult>;
|
|
942
|
+
}
|
|
943
|
+
declare abstract class SandboxToolsCapabilities extends SandboxPreviewCapabilities {
|
|
1270
944
|
/**
|
|
1271
|
-
*
|
|
1272
|
-
*
|
|
1273
|
-
*
|
|
1274
|
-
*
|
|
1275
|
-
*
|
|
945
|
+
* Tools capability object for managing language runtimes.
|
|
946
|
+
*
|
|
947
|
+
* Uses mise (polyglot version manager) to install and manage tools.
|
|
948
|
+
*
|
|
949
|
+
* @example Install and use Node.js
|
|
950
|
+
* ```typescript
|
|
951
|
+
* await box.tools.install("node", "22");
|
|
952
|
+
* await box.tools.use("node", "22");
|
|
953
|
+
* const list = await box.tools.list();
|
|
954
|
+
* ```
|
|
1276
955
|
*/
|
|
1277
|
-
|
|
956
|
+
get tools(): ToolsCapability;
|
|
957
|
+
private toolsInstall;
|
|
958
|
+
private toolsUse;
|
|
959
|
+
private toolsList;
|
|
960
|
+
private toolsRun;
|
|
961
|
+
}
|
|
962
|
+
//#endregion
|
|
963
|
+
//#region src/sandbox-lifecycle-events.d.ts
|
|
964
|
+
declare abstract class SandboxLifecycleEventsCapabilities extends SandboxToolsCapabilities {
|
|
1278
965
|
/**
|
|
1279
966
|
* Stream sandbox lifecycle and activity events.
|
|
1280
967
|
*/
|
|
1281
968
|
events(options?: EventStreamOptions): AsyncGenerator<SandboxEvent>;
|
|
1282
|
-
trace(options?: SandboxTraceOptions): Promise<SandboxTraceBundle>;
|
|
1283
|
-
intelligence(): Promise<NonNullable<SandboxTraceBundle["intelligence"]>>;
|
|
1284
|
-
createIntelligenceReport(options?: {
|
|
1285
|
-
mode?: "deterministic" | "agentic";
|
|
1286
|
-
acknowledgeCost?: boolean;
|
|
1287
|
-
budget?: IntelligenceReportBudget;
|
|
1288
|
-
metadata?: Record<string, unknown>; /** Bound the analysis to a time window. */
|
|
1289
|
-
window?: IntelligenceReportWindow; /** Compare this sandbox against a same-type baseline sandbox. */
|
|
1290
|
-
compareTo?: IntelligenceReportCompareTo;
|
|
1291
|
-
}): Promise<IntelligenceReport>;
|
|
1292
|
-
createAgenticIntelligenceReport(options: {
|
|
1293
|
-
maxUsd: number;
|
|
1294
|
-
metadata?: Record<string, unknown>;
|
|
1295
|
-
}): Promise<IntelligenceReport>;
|
|
1296
|
-
exportTrace(sink: TraceExportSink): Promise<TraceExportResult>;
|
|
1297
969
|
/**
|
|
1298
970
|
* Stream real-time provisioning progress events.
|
|
1299
971
|
*
|
|
@@ -1318,35 +990,117 @@ declare class SandboxInstance {
|
|
|
1318
990
|
signal?: AbortSignal;
|
|
1319
991
|
}): AsyncGenerator<ProvisionEvent, ProvisionResult | undefined>;
|
|
1320
992
|
/**
|
|
1321
|
-
*
|
|
993
|
+
* Delegates to the shared `parseSSEStream` in `lib/sse-parser.ts`
|
|
994
|
+
* — one canonical SSE implementation for the whole SDK. The
|
|
995
|
+
* shared parser throws `AbortError` on cancellation, while agent and task
|
|
996
|
+
* streams inspect the signal after iteration to decide whether to reconnect.
|
|
997
|
+
* This adapter converts cancellation to that local control flow and lets one
|
|
998
|
+
* malformed output frame be skipped without losing later valid output.
|
|
999
|
+
*/
|
|
1000
|
+
protected parseSSEStream(response: Response, signal?: AbortSignal): AsyncGenerator<SandboxEvent>;
|
|
1001
|
+
/**
|
|
1002
|
+
* Wait for the sandbox to reach a specific status.
|
|
1322
1003
|
*
|
|
1323
|
-
*
|
|
1324
|
-
*
|
|
1004
|
+
* A sandbox is not considered `running` until its filesystem incarnation is
|
|
1005
|
+
* complete and ready.
|
|
1325
1006
|
*
|
|
1326
|
-
*
|
|
1327
|
-
*
|
|
1328
|
-
*
|
|
1007
|
+
* When `onProgress` is provided and the sandbox is still provisioning,
|
|
1008
|
+
* uses SSE events for real-time progress instead of polling. Falls back
|
|
1009
|
+
* to polling if the SSE connection fails or is unavailable.
|
|
1329
1010
|
*
|
|
1330
|
-
* @example
|
|
1011
|
+
* @example Basic wait
|
|
1331
1012
|
* ```typescript
|
|
1332
|
-
*
|
|
1333
|
-
* console.log(`${match.path}:${match.line}: ${match.text}`);
|
|
1334
|
-
* }
|
|
1013
|
+
* await box.waitFor("running");
|
|
1335
1014
|
* ```
|
|
1336
1015
|
*
|
|
1337
|
-
* @example
|
|
1016
|
+
* @example Wait with progress tracking
|
|
1338
1017
|
* ```typescript
|
|
1339
|
-
*
|
|
1340
|
-
*
|
|
1341
|
-
*
|
|
1342
|
-
*
|
|
1343
|
-
*
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1018
|
+
* await box.waitFor("running", {
|
|
1019
|
+
* onProgress: (event) => {
|
|
1020
|
+
* console.log(`[${event.step}] ${event.status} — ${event.message}`);
|
|
1021
|
+
* if (event.percent !== undefined) {
|
|
1022
|
+
* updateProgressBar(event.percent);
|
|
1023
|
+
* }
|
|
1024
|
+
* },
|
|
1025
|
+
* });
|
|
1026
|
+
* ```
|
|
1027
|
+
*/
|
|
1028
|
+
waitFor(status: SandboxStatus | SandboxStatus[], options?: WaitForOptions): Promise<void>;
|
|
1029
|
+
/**
|
|
1030
|
+
* SSE-based wait implementation. Subscribes to provisioning events and
|
|
1031
|
+
* delivers progress callbacks while waiting for a target status.
|
|
1032
|
+
*/
|
|
1033
|
+
protected waitForWithSSE(statuses: SandboxStatus[], timeoutMs: number, onProgress: (event: ProvisionEvent) => void, signal?: AbortSignal): Promise<boolean>;
|
|
1034
|
+
protected hasReachedWaitTarget(statuses: SandboxStatus[]): boolean;
|
|
1035
|
+
/**
|
|
1036
|
+
* A running filesystem is not enough to serve a consumer. The API can
|
|
1037
|
+
* expose `running` while the public edge is still pending, or after edge
|
|
1038
|
+
* attachment failed. Keep that distinction in the SDK so every caller gets
|
|
1039
|
+
* the same wait and error semantics.
|
|
1040
|
+
*/
|
|
1041
|
+
protected consumerConnectionReady(): boolean;
|
|
1042
|
+
protected sleep(ms: number): Promise<void>;
|
|
1043
|
+
}
|
|
1044
|
+
//#endregion
|
|
1045
|
+
//#region src/sandbox-lifecycle.d.ts
|
|
1046
|
+
declare abstract class SandboxLifecycleCapabilities extends SandboxLifecycleEventsCapabilities {
|
|
1047
|
+
#private;
|
|
1048
|
+
/**
|
|
1049
|
+
* Stop the sandbox (keeps state for resume).
|
|
1050
|
+
*
|
|
1051
|
+
* The stop response carries the orchestrator's per-phase stop breakdown
|
|
1052
|
+
* (`stop_metering` / `container_kill` / `stop_complete` /
|
|
1053
|
+
* `stop_unaccounted`); after this resolves, {@link startupDiagnostics}
|
|
1054
|
+
* returns it (replacing the create breakdown).
|
|
1055
|
+
*/
|
|
1056
|
+
stop(): Promise<void>;
|
|
1057
|
+
/**
|
|
1058
|
+
* With `wait: false`, answers as soon as the stop is durably accepted and
|
|
1059
|
+
* returns the {@link SandboxOperation}; `await op.wait()` resolves once the
|
|
1060
|
+
* sandbox is stopped. A stop the API finished synchronously comes back as an
|
|
1061
|
+
* operation that is already `succeeded`.
|
|
1062
|
+
*/
|
|
1063
|
+
stop(options: StopOptions & {
|
|
1064
|
+
wait: false;
|
|
1065
|
+
}): Promise<SandboxOperation>;
|
|
1066
|
+
stop(options?: StopOptions): Promise<void>;
|
|
1067
|
+
/** Read an operation a `wait: false` stop or snapshot of this sandbox returned. */
|
|
1068
|
+
getOperation(operationId: string): Promise<SandboxOperation>;
|
|
1069
|
+
/** Read credential recovery metadata without changing sandbox lifecycle. */
|
|
1070
|
+
getEnvRecovery(): Promise<SandboxEnvRecoveryView>;
|
|
1071
|
+
/** Replace a stopped sandbox's policy, or inspect a proposed change with dryRun. */
|
|
1072
|
+
setEnvRecovery(envRecovery: SandboxEnvRecovery, options?: {
|
|
1073
|
+
dryRun?: boolean;
|
|
1074
|
+
}): Promise<SandboxEnvRecoveryView>;
|
|
1075
|
+
/** Resume a stopped sandbox; cold recovery may require caller env values. */
|
|
1076
|
+
resume(options?: ResumeOptions): Promise<void>;
|
|
1077
|
+
/** Rebuild a stopped sandbox from its durable snapshot under the same ID. */
|
|
1078
|
+
rebuild(options?: ResumeOptions): Promise<void>;
|
|
1079
|
+
protected resumeRuntime(operation: "resume" | "rebuild", options: ResumeOptions): Promise<void>;
|
|
1080
|
+
/**
|
|
1081
|
+
* Delete the sandbox permanently. This is how a forked child is destroyed.
|
|
1082
|
+
*
|
|
1083
|
+
* `outcome` separates `destroyed` from `already_absent`, so a retry after an
|
|
1084
|
+
* uncertain failure reports what really happened instead of raising.
|
|
1085
|
+
*
|
|
1086
|
+
* The call answers once the runtime is killed and billed; the container,
|
|
1087
|
+
* volume and network are reclaimed behind it and `removal` says
|
|
1088
|
+
* `"pending"`. Pass `until: "removed"` to wait for that reclaim instead.
|
|
1089
|
+
*
|
|
1090
|
+
* The delete response carries the orchestrator's per-phase delete breakdown
|
|
1091
|
+
* (`runtime_kill` / `tombstone_persist` / `delete_complete` /
|
|
1092
|
+
* `delete_unaccounted`); after this resolves, {@link startupDiagnostics}
|
|
1093
|
+
* returns it for post-mortem reads on the now-gone sandbox.
|
|
1094
|
+
*/
|
|
1095
|
+
delete(options?: SandboxDeleteOptions): Promise<SandboxDeleteAcknowledgement>;
|
|
1096
|
+
}
|
|
1097
|
+
//#endregion
|
|
1098
|
+
//#region src/sandbox-runtime.d.ts
|
|
1099
|
+
declare abstract class SandboxRuntimeOperations extends SandboxLifecycleCapabilities {
|
|
1100
|
+
/** Basic health reported by the runtime inside this sandbox. */
|
|
1101
|
+
runtimeHealth(): Promise<SandboxRuntimeHealth>;
|
|
1102
|
+
/**
|
|
1103
|
+
* Merge application variables into the running sandbox before dispatch.
|
|
1350
1104
|
* New child processes and profile secret references use these values.
|
|
1351
1105
|
* Existing processes retain their environment.
|
|
1352
1106
|
*
|
|
@@ -1368,12 +1122,6 @@ declare class SandboxInstance {
|
|
|
1368
1122
|
* rather than reporting an empty snapshot it never collected.
|
|
1369
1123
|
*/
|
|
1370
1124
|
ports(): Promise<SandboxPortBinding[]>;
|
|
1371
|
-
/**
|
|
1372
|
-
* Interactive terminal operations for this runtime: the REST manager
|
|
1373
|
-
* (create/input/list/get) plus `attach()`, which opens the live terminal
|
|
1374
|
-
* WebSocket as a {@link TerminalStream}.
|
|
1375
|
-
*/
|
|
1376
|
-
get terminals(): SandboxTerminals;
|
|
1377
1125
|
/**
|
|
1378
1126
|
* Live whole-sandbox resource usage (memory + CPU) from the container cgroup.
|
|
1379
1127
|
*
|
|
@@ -1425,43 +1173,131 @@ declare class SandboxInstance {
|
|
|
1425
1173
|
}): Promise<void>;
|
|
1426
1174
|
capabilities(): Promise<SandboxRuntimeCapabilities | null>;
|
|
1427
1175
|
/**
|
|
1428
|
-
*
|
|
1176
|
+
* Get information about the infrastructure driver for this sandbox.
|
|
1429
1177
|
*
|
|
1430
|
-
*
|
|
1178
|
+
* @example
|
|
1179
|
+
* ```typescript
|
|
1180
|
+
* const info = await box.getDriverInfo();
|
|
1181
|
+
* console.log(`Driver: ${info.type}, CRIU: ${info.capabilities.criu}`);
|
|
1182
|
+
* ```
|
|
1183
|
+
*/
|
|
1184
|
+
getDriverInfo(): Promise<DriverInfo>;
|
|
1185
|
+
}
|
|
1186
|
+
//#endregion
|
|
1187
|
+
//#region src/sandbox-exec.d.ts
|
|
1188
|
+
declare abstract class SandboxExecCapabilities extends SandboxRuntimeOperations {
|
|
1189
|
+
/**
|
|
1190
|
+
* Execute a command in the sandbox through a non-login POSIX shell.
|
|
1191
|
+
* The command inherits the sandbox runtime environment.
|
|
1192
|
+
*/
|
|
1193
|
+
exec(command: string, options?: ExecOptions): Promise<ExecResult>;
|
|
1194
|
+
/**
|
|
1195
|
+
* Run code in a persistent language kernel.
|
|
1431
1196
|
*
|
|
1432
|
-
*
|
|
1197
|
+
* Each `(sessionId, language)` pair gets its own long-lived kernel that
|
|
1198
|
+
* keeps variable state across calls — like Jupyter cells. Without a
|
|
1199
|
+
* `sessionId`, calls share a process-wide kernel per language.
|
|
1200
|
+
*
|
|
1201
|
+
* Returns typed results: stdout/stderr text plus a `results` array of
|
|
1202
|
+
* structured outputs (matplotlib images as base64 PNG, pandas DataFrames,
|
|
1203
|
+
* explicit `display(value)` calls as JSON/HTML, errors with traceback).
|
|
1204
|
+
*
|
|
1205
|
+
* @example Persistent Python session
|
|
1206
|
+
* ```ts
|
|
1207
|
+
* await box.runCode("python", "import pandas as pd; df = pd.DataFrame({'x': range(5)})", { sessionId: "s1" });
|
|
1208
|
+
* const r = await box.runCode("python", "df.describe()", { sessionId: "s1" });
|
|
1209
|
+
* // r.results[0] is a `dataframe` part with columns + rows from the describe()
|
|
1210
|
+
* ```
|
|
1211
|
+
*
|
|
1212
|
+
* @example Matplotlib chart
|
|
1213
|
+
* ```ts
|
|
1214
|
+
* const r = await box.runCode("python",
|
|
1215
|
+
* "import matplotlib.pyplot as plt; plt.plot([1,2,3,4]); plt.show()",
|
|
1216
|
+
* { sessionId: "s1" });
|
|
1217
|
+
* const png = r.results.find(p => p.type === "image");
|
|
1218
|
+
* // png.data is a base64 PNG ready to render or hand back to an LLM
|
|
1219
|
+
* ```
|
|
1220
|
+
*/
|
|
1221
|
+
runCode(language: CodeLanguage, source: string, options?: CodeExecutionOptions): Promise<CodeExecutionResult>;
|
|
1222
|
+
/**
|
|
1223
|
+
* Search for text patterns in files using ripgrep.
|
|
1224
|
+
*
|
|
1225
|
+
* This is a first-class code search capability, not a shell wrapper.
|
|
1226
|
+
* Ripgrep is pre-installed in all managed sandboxes.
|
|
1227
|
+
*
|
|
1228
|
+
* @param pattern - Regular expression pattern to search for
|
|
1229
|
+
* @param options - Search options
|
|
1230
|
+
* @returns Async iterator of search matches
|
|
1231
|
+
*
|
|
1232
|
+
* @example Search for task-marker comments
|
|
1433
1233
|
* ```typescript
|
|
1434
|
-
* const
|
|
1435
|
-
*
|
|
1436
|
-
*
|
|
1437
|
-
*
|
|
1438
|
-
*
|
|
1234
|
+
* for await (const match of box.search("TASK:", { glob: "**\/*.ts" })) {
|
|
1235
|
+
* console.log(`${match.path}:${match.line}: ${match.text}`);
|
|
1236
|
+
* }
|
|
1237
|
+
* ```
|
|
1238
|
+
*
|
|
1239
|
+
* @example Collect all matches
|
|
1240
|
+
* ```typescript
|
|
1241
|
+
* const matches = [];
|
|
1242
|
+
* for await (const match of box.search("function.*async")) {
|
|
1243
|
+
* matches.push(match);
|
|
1439
1244
|
* }
|
|
1440
1245
|
* ```
|
|
1441
1246
|
*/
|
|
1442
|
-
|
|
1443
|
-
private gitStatus;
|
|
1444
|
-
private gitLog;
|
|
1445
|
-
private gitDiff;
|
|
1446
|
-
private gitAdd;
|
|
1447
|
-
private gitCommit;
|
|
1448
|
-
private gitPush;
|
|
1449
|
-
private gitPull;
|
|
1450
|
-
private gitBranches;
|
|
1451
|
-
private gitCheckout;
|
|
1247
|
+
search(pattern: string, options?: SearchOptions): AsyncGenerator<SearchMatch>;
|
|
1452
1248
|
/**
|
|
1453
|
-
*
|
|
1249
|
+
* Upload a local directory to the sandbox via tar.
|
|
1250
|
+
* @param localPath - Local directory path to upload
|
|
1251
|
+
* @param remotePath - Destination path in the sandbox (default: /home/user)
|
|
1252
|
+
*/
|
|
1253
|
+
uploadDirectory(localPath: string, remotePath?: string): Promise<void>;
|
|
1254
|
+
}
|
|
1255
|
+
//#endregion
|
|
1256
|
+
//#region src/sandbox-file-write.d.ts
|
|
1257
|
+
declare abstract class SandboxFileWriteCapabilities extends SandboxExecCapabilities {
|
|
1258
|
+
/**
|
|
1259
|
+
* Read a file from the sandbox.
|
|
1454
1260
|
*
|
|
1455
|
-
*
|
|
1261
|
+
* @param path - Path to the file. Relative paths resolve from the workspace root.
|
|
1262
|
+
* Absolute paths (e.g., `/tmp/output.json`) access the container filesystem directly.
|
|
1263
|
+
* @returns File content as string
|
|
1456
1264
|
*
|
|
1457
|
-
* @example
|
|
1265
|
+
* @example
|
|
1458
1266
|
* ```typescript
|
|
1459
|
-
* await box.
|
|
1460
|
-
* await box.
|
|
1461
|
-
* const list = await box.tools.list();
|
|
1267
|
+
* const content = await box.read("src/index.ts");
|
|
1268
|
+
* const report = await box.read("/output/report.json");
|
|
1462
1269
|
* ```
|
|
1463
1270
|
*/
|
|
1464
|
-
|
|
1271
|
+
read(path: string, options?: {
|
|
1272
|
+
sessionId?: string;
|
|
1273
|
+
traceId?: string;
|
|
1274
|
+
}): Promise<string>;
|
|
1275
|
+
/**
|
|
1276
|
+
* Write content to a file in the sandbox.
|
|
1277
|
+
*
|
|
1278
|
+
* @param path - Path to the file. Relative paths resolve from the workspace root.
|
|
1279
|
+
* Absolute paths (e.g., `/tmp/cases.json`) write to the container filesystem directly.
|
|
1280
|
+
* @param content - Content to write
|
|
1281
|
+
*
|
|
1282
|
+
* @example
|
|
1283
|
+
* ```typescript
|
|
1284
|
+
* await box.write("src/fix.ts", "export const fix = () => {}");
|
|
1285
|
+
* await box.write("/tmp/config.json", JSON.stringify(config));
|
|
1286
|
+
* ```
|
|
1287
|
+
*/
|
|
1288
|
+
write(path: string, content: string, options?: WriteFileOptions): Promise<FileWriteResult>;
|
|
1289
|
+
protected writeFileRequest(path: string, content: string, options?: WriteFileOptions): Promise<FileWriteResult>;
|
|
1290
|
+
protected assertWritePreconditions(result: FileWriteResult, requested: {
|
|
1291
|
+
expectedHash?: string;
|
|
1292
|
+
ifAbsent?: boolean;
|
|
1293
|
+
}): void;
|
|
1294
|
+
protected writeBatchRequest(files: WriteManyWireFile[], body: string): Promise<boolean>;
|
|
1295
|
+
protected writeManySequential(files: WriteManyFile[], paceMs: number, maxRetries: number): Promise<void>;
|
|
1296
|
+
/**
|
|
1297
|
+
* Write many files through the runtime batch endpoint. Older runtimes that
|
|
1298
|
+
* return 404 use the sequential write path with the same retry policy.
|
|
1299
|
+
*/
|
|
1300
|
+
writeMany(files: WriteManyFile[], options?: WriteManyOptions): Promise<void>;
|
|
1465
1301
|
/**
|
|
1466
1302
|
* File system operations beyond basic read/write:
|
|
1467
1303
|
* - Binary upload/download
|
|
@@ -1492,239 +1328,74 @@ declare class SandboxInstance {
|
|
|
1492
1328
|
* ```
|
|
1493
1329
|
*/
|
|
1494
1330
|
get fs(): FileSystem;
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
private fsOpenArchive;
|
|
1508
|
-
private fsDownloadDir;
|
|
1509
|
-
private fsList;
|
|
1510
|
-
private fsStat;
|
|
1511
|
-
private fsDelete;
|
|
1512
|
-
private fsRename;
|
|
1513
|
-
private fsMkdir;
|
|
1514
|
-
private fsExists;
|
|
1331
|
+
}
|
|
1332
|
+
interface WriteManyWireFile {
|
|
1333
|
+
path: string;
|
|
1334
|
+
content: string;
|
|
1335
|
+
mode?: number;
|
|
1336
|
+
encoding?: "utf8" | "base64";
|
|
1337
|
+
expectedHash?: string;
|
|
1338
|
+
ifAbsent?: boolean;
|
|
1339
|
+
}
|
|
1340
|
+
//#endregion
|
|
1341
|
+
//#region src/sandbox-profile.d.ts
|
|
1342
|
+
declare abstract class SandboxProfileCapabilities extends SandboxFileWriteCapabilities {
|
|
1515
1343
|
/**
|
|
1516
|
-
*
|
|
1344
|
+
* Stream events from an agent prompt.
|
|
1345
|
+
* Use this for real-time updates during agent execution.
|
|
1517
1346
|
*
|
|
1518
|
-
*
|
|
1519
|
-
*
|
|
1520
|
-
*
|
|
1521
|
-
*
|
|
1522
|
-
* console.log(`${user.username}: ${user.role}`);
|
|
1523
|
-
* }
|
|
1524
|
-
* ```
|
|
1347
|
+
* Guarantees terminal completion on every non-cancelled path. A clean run
|
|
1348
|
+
* emits a `result` summary and ends with `done`. A failure is an in-band
|
|
1349
|
+
* `error` followed by `done`, never a thrown generator. Caller cancellation
|
|
1350
|
+
* ends the stream silently with no synthetic terminal.
|
|
1525
1351
|
*
|
|
1526
|
-
*
|
|
1527
|
-
*
|
|
1528
|
-
*
|
|
1529
|
-
*
|
|
1530
|
-
* role: "developer",
|
|
1531
|
-
* sshKeys: ["ssh-ed25519 AAAA..."],
|
|
1532
|
-
* });
|
|
1533
|
-
* ```
|
|
1352
|
+
* Automatically reconnects via the runtime event replay endpoint if the
|
|
1353
|
+
* SSE stream drops before a terminal event (`done` or `error`) is
|
|
1354
|
+
* received. Reconnection is transparent — replayed events that were
|
|
1355
|
+
* already yielded (based on event ID tracking) are deduplicated.
|
|
1534
1356
|
*/
|
|
1535
|
-
get permissions(): PermissionsManager;
|
|
1536
|
-
private permissionsList;
|
|
1537
|
-
private permissionsGet;
|
|
1538
|
-
private permissionsAdd;
|
|
1539
|
-
private permissionsUpdate;
|
|
1540
|
-
private permissionsRemove;
|
|
1541
|
-
private permissionsSetAccessPolicies;
|
|
1542
|
-
private permissionsGetAccessPolicies;
|
|
1543
|
-
private permissionsCheckAccess;
|
|
1544
1357
|
/**
|
|
1545
|
-
*
|
|
1546
|
-
*
|
|
1547
|
-
*
|
|
1548
|
-
*
|
|
1549
|
-
*
|
|
1550
|
-
*
|
|
1551
|
-
*
|
|
1552
|
-
*
|
|
1553
|
-
* @example Point the backend at a different model
|
|
1554
|
-
* ```typescript
|
|
1555
|
-
* await box.backend.updateConfig({ model: "openai/gpt-5-mini" });
|
|
1556
|
-
* ```
|
|
1557
|
-
*
|
|
1558
|
-
* @example Read provider-native Cursor metadata
|
|
1559
|
-
* ```typescript
|
|
1560
|
-
* const models = await box.backend.models();
|
|
1561
|
-
* const agents = await box.backend.agents({ limit: 20 });
|
|
1562
|
-
* const runs = await box.backend.runs(agents.items[0].agentId);
|
|
1563
|
-
* ```
|
|
1564
|
-
*/
|
|
1565
|
-
get backend(): BackendManager;
|
|
1566
|
-
private backendStatus;
|
|
1567
|
-
private backendGetMcpStatus;
|
|
1568
|
-
private backendUpdateConfig;
|
|
1569
|
-
private backendControlData;
|
|
1570
|
-
private backendControlAction;
|
|
1571
|
-
private backendListSearch;
|
|
1572
|
-
private backendAccount;
|
|
1573
|
-
private backendModels;
|
|
1574
|
-
private backendRepositories;
|
|
1575
|
-
private backendAgents;
|
|
1576
|
-
private backendAgent;
|
|
1577
|
-
private backendArchiveAgent;
|
|
1578
|
-
private backendUnarchiveAgent;
|
|
1579
|
-
private backendDeleteAgent;
|
|
1580
|
-
private backendRuns;
|
|
1581
|
-
private backendRun;
|
|
1582
|
-
private backendAgentMessages;
|
|
1583
|
-
private backendArtifacts;
|
|
1584
|
-
private backendDownloadArtifact;
|
|
1585
|
-
private backendRestart;
|
|
1586
|
-
/**
|
|
1587
|
-
* Process manager for spawning and controlling processes.
|
|
1588
|
-
*
|
|
1589
|
-
* Provides non-blocking process execution with real-time log streaming,
|
|
1590
|
-
* ideal for long-running tasks like ML training or dev servers.
|
|
1591
|
-
*
|
|
1592
|
-
* @example Non-blocking process
|
|
1593
|
-
* ```typescript
|
|
1594
|
-
* const proc = await box.process.spawn("python train.py", {
|
|
1595
|
-
* cwd: "/workspace",
|
|
1596
|
-
* env: { "CUDA_VISIBLE_DEVICES": "0" }
|
|
1597
|
-
* });
|
|
1598
|
-
*
|
|
1599
|
-
* // Stream logs
|
|
1600
|
-
* for await (const entry of proc.logs()) {
|
|
1601
|
-
* console.log(`[${entry.type}] ${entry.data}`);
|
|
1602
|
-
* }
|
|
1603
|
-
*
|
|
1604
|
-
* // Check status
|
|
1605
|
-
* const status = await proc.status();
|
|
1606
|
-
* console.log(`Running: ${status.running}`);
|
|
1607
|
-
*
|
|
1608
|
-
* // Kill if needed
|
|
1609
|
-
* await proc.kill();
|
|
1610
|
-
* ```
|
|
1611
|
-
*
|
|
1612
|
-
*/
|
|
1613
|
-
get process(): ProcessManager;
|
|
1614
|
-
private processEnsureDevServer;
|
|
1615
|
-
private processSpawn;
|
|
1616
|
-
private processSpawnExact;
|
|
1617
|
-
private processList;
|
|
1618
|
-
private processGet;
|
|
1619
|
-
private createProcessHandle;
|
|
1620
|
-
private parseProcessLogStream;
|
|
1621
|
-
/**
|
|
1622
|
-
* Port exposure and runtime network state.
|
|
1623
|
-
*
|
|
1624
|
-
* Outbound restrictions are on {@link SandboxInstance.egress}: `update()`
|
|
1625
|
-
* here rejects every policy field rather than recording one nothing
|
|
1626
|
-
* enforces.
|
|
1627
|
-
*
|
|
1628
|
-
* @example Expose ports dynamically
|
|
1629
|
-
* ```typescript
|
|
1630
|
-
* const url = await box.network.exposePort(8000);
|
|
1631
|
-
* console.log(`Service available at: ${url}`);
|
|
1632
|
-
* ```
|
|
1633
|
-
*
|
|
1634
|
-
* @example Restrict outbound traffic
|
|
1635
|
-
* ```typescript
|
|
1636
|
-
* await box.egress.update({ mode: "blocked" });
|
|
1637
|
-
* ```
|
|
1638
|
-
*/
|
|
1639
|
-
get network(): NetworkManager;
|
|
1640
|
-
/**
|
|
1641
|
-
* Egress policy manager for controlling outbound internet access.
|
|
1642
|
-
*
|
|
1643
|
-
* @example Read current egress policy
|
|
1644
|
-
* ```typescript
|
|
1645
|
-
* const { policy, source } = await box.egress.get();
|
|
1646
|
-
* console.log(policy.mode, source);
|
|
1647
|
-
* ```
|
|
1648
|
-
*
|
|
1649
|
-
* @example Update egress policy at runtime
|
|
1650
|
-
* ```typescript
|
|
1651
|
-
* // strict reaches these plus the sandbox's own model endpoint, nothing else.
|
|
1652
|
-
* await box.egress.update({ mode: "strict", allowDomains: ["api.github.com"] });
|
|
1653
|
-
* ```
|
|
1654
|
-
*/
|
|
1655
|
-
get egress(): EgressManager;
|
|
1656
|
-
/**
|
|
1657
|
-
* On-demand GPU leases attached to this sandbox.
|
|
1658
|
-
*
|
|
1659
|
-
* The base sandbox stays cheap; `attach` starts a temporary external GPU
|
|
1660
|
-
* worker with an explicit spend cap, and `detach` destroys it.
|
|
1661
|
-
*/
|
|
1662
|
-
get gpu(): GpuLeaseManager;
|
|
1663
|
-
private networkUpdate;
|
|
1664
|
-
private networkExposePort;
|
|
1665
|
-
private networkListUrls;
|
|
1666
|
-
private networkGetConfig;
|
|
1667
|
-
private egressGet;
|
|
1668
|
-
private egressUpdate;
|
|
1669
|
-
private egressDenials;
|
|
1670
|
-
/**
|
|
1671
|
-
* This sandbox's egress for one calendar month, from the billing meter. A
|
|
1672
|
-
* malformed answer is a typed `ServerError`, never a defaulted zero: a
|
|
1673
|
-
* caller budgeting on it must not read a broken reply as no usage.
|
|
1674
|
-
*/
|
|
1675
|
-
private egressUsage;
|
|
1676
|
-
/**
|
|
1677
|
-
* What the sandbox reached, and whether that is decidable.
|
|
1678
|
-
*
|
|
1679
|
-
* Every malformed answer leaves as a typed `ServerError` rather than a
|
|
1680
|
-
* defaulted record. That matters more here than on `denials()`: a caller uses
|
|
1681
|
-
* this to establish a NEGATIVE claim, so inventing a `complete: true` record
|
|
1682
|
-
* from a broken response would manufacture the very proof it came for.
|
|
1358
|
+
* Record that the runtime already holds `profile` under `sha256`, so
|
|
1359
|
+
* subsequent turns whose profile has the same canonical content send
|
|
1360
|
+
* `backend.profileSha256` instead of the inline corpus. Use this to hydrate
|
|
1361
|
+
* a freshly-fetched instance (`get()`/`list()`) from caller-persisted state
|
|
1362
|
+
* — the reference otherwise lives only on the instance that primed it.
|
|
1363
|
+
* Captures a content snapshot, so mutating the object afterwards is
|
|
1364
|
+
* detected and that turn falls back to sending the profile inline.
|
|
1683
1365
|
*/
|
|
1684
|
-
|
|
1685
|
-
private gpuProviders;
|
|
1686
|
-
private gpuAttach;
|
|
1687
|
-
private gpuList;
|
|
1688
|
-
private gpuExec;
|
|
1689
|
-
private gpuDetach;
|
|
1366
|
+
attachProfileReference(profile: object, sha256: string, name?: string): void;
|
|
1690
1367
|
/**
|
|
1691
|
-
*
|
|
1368
|
+
* Deliver inline file mounts separately, then upload the remaining profile
|
|
1369
|
+
* to the runtime (`POST /agents/profiles`) and record
|
|
1370
|
+
* the returned transport-profile hash via {@link attachProfileReference}, so subsequent turns
|
|
1371
|
+
* reference it by `profileSha256` instead of re-sending the corpus.
|
|
1372
|
+
* `create()` calls this automatically for its inline profile when
|
|
1373
|
+
* `autoDeferProfile` is on; call it directly when the profile only exists
|
|
1374
|
+
* per-turn, or when the instance was fetched rather than created. Persist
|
|
1375
|
+
* the returned sha256 alongside a content hash of the profile to
|
|
1376
|
+
* re-attach on later instances without re-priming. Throws on transport/HTTP
|
|
1377
|
+
* failure — the caller decides whether that is fatal (it is not: turns fall
|
|
1378
|
+
* back to sending the file-free profile inline).
|
|
1692
1379
|
*/
|
|
1693
|
-
|
|
1380
|
+
primeProfile(profile: object): Promise<string>;
|
|
1694
1381
|
/**
|
|
1695
|
-
*
|
|
1696
|
-
*
|
|
1697
|
-
*
|
|
1698
|
-
*
|
|
1699
|
-
*
|
|
1700
|
-
*
|
|
1701
|
-
*
|
|
1702
|
-
* console.log(link.url);
|
|
1703
|
-
*
|
|
1704
|
-
* const links = await box.previewLinks.list();
|
|
1705
|
-
* await box.previewLinks.remove(link.previewId);
|
|
1706
|
-
* ```
|
|
1382
|
+
* Build the run request's `backend` body. When the outgoing profile's CONTENT
|
|
1383
|
+
* matches the one the runtime already holds (and we are not resending after a
|
|
1384
|
+
* cache miss), swap the inline `profile` for its `profileSha256` so a large
|
|
1385
|
+
* static corpus does not ride every turn. The match is by serialized content,
|
|
1386
|
+
* not object identity, so a mutated-in-place profile — or an equivalent
|
|
1387
|
+
* object passed as a per-turn override — is compared correctly: unchanged
|
|
1388
|
+
* content references by hash, changed content sends inline.
|
|
1707
1389
|
*/
|
|
1708
|
-
get previewLinks(): PreviewLinkManager;
|
|
1709
|
-
private previewLinkCreate;
|
|
1710
|
-
private previewLinkList;
|
|
1711
|
-
private previewLinkGet;
|
|
1712
|
-
private previewLinkWaitUntilReady;
|
|
1713
|
-
private previewLinkRemove;
|
|
1714
1390
|
/**
|
|
1715
|
-
*
|
|
1716
|
-
*
|
|
1717
|
-
*
|
|
1718
|
-
* ```typescript
|
|
1719
|
-
* const info = await box.getDriverInfo();
|
|
1720
|
-
* console.log(`Driver: ${info.type}, CRIU: ${info.capabilities.criu}`);
|
|
1721
|
-
* ```
|
|
1391
|
+
* How this handle's most recent profile file preparation was satisfied
|
|
1392
|
+
* (host cache hit, partial, miss, legacy delivery, or a held receipt) and
|
|
1393
|
+
* how long it took. Undefined until a profile with file mounts is prepared.
|
|
1722
1394
|
*/
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
private toolsRun;
|
|
1395
|
+
get lastProfileFileDelivery(): ProfileFileDeliveryReport | undefined;
|
|
1396
|
+
/** @internal Shared create/turn delivery; caller policy decides how to expose failures. */
|
|
1397
|
+
materializeProfileFiles(profile: AgentProfile, signal?: AbortSignal, existingFiles?: "replace" | "allow-identical"): Promise<AgentProfile>;
|
|
1398
|
+
protected buildRunBackendBody(overrideBackend: Partial<BackendConfig> | undefined, forceFullProfile: boolean, requestedModel?: string, signal?: AbortSignal, preserveManagedProfile?: boolean): Promise<Record<string, unknown> | undefined>;
|
|
1728
1399
|
/**
|
|
1729
1400
|
* Create a snapshot of the sandbox state.
|
|
1730
1401
|
* Snapshots can be used to save workspace state for later restoration.
|
|
@@ -1790,40 +1461,663 @@ declare class SandboxInstance {
|
|
|
1790
1461
|
noChanges: boolean;
|
|
1791
1462
|
};
|
|
1792
1463
|
/**
|
|
1793
|
-
*
|
|
1794
|
-
*
|
|
1795
|
-
* Each harness stores conversations in its own files:
|
|
1796
|
-
* Claude Code: ~/.claude/projects/<session-id>/ (JSONL)
|
|
1797
|
-
* Codex: ~/.codex/sessions/ (JSON)
|
|
1798
|
-
* OpenCode: ~/.local/share/opencode/storage/ (SQLite)
|
|
1799
|
-
*
|
|
1800
|
-
* This reads those files and returns them as a map of session-id to
|
|
1801
|
-
* conversation content, so the caller can persist them before deleting
|
|
1802
|
-
* the sandbox. Without this, conversation history dies with the sandbox.
|
|
1464
|
+
* Ask the initialized provider to prepare this turn's public native profile
|
|
1465
|
+
* before admission. Pass both returned expected digests to driveConversationTurn.
|
|
1803
1466
|
*/
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1467
|
+
preparePublicProfileRevision(opts: {
|
|
1468
|
+
sessionId: string;
|
|
1469
|
+
backend: Partial<BackendConfig>;
|
|
1470
|
+
model?: ConversationTurnOptions["model"];
|
|
1471
|
+
}): Promise<{
|
|
1472
|
+
expectedPublicProfileRequestDigest: `sha256:${string}`;
|
|
1473
|
+
expectedPublicProfileRevision: {
|
|
1474
|
+
workspacePlanDigest: `sha256:${string}`;
|
|
1475
|
+
materializedDigest: `sha256:${string}`;
|
|
1476
|
+
launchDigest: string;
|
|
1477
|
+
};
|
|
1478
|
+
conflicts: PublicProfileConflict[];
|
|
1479
|
+
}>;
|
|
1480
|
+
/** Prepare a secret-bearing native revision without starting a model turn. */
|
|
1481
|
+
prepareSecretProfileRevision(opts: {
|
|
1482
|
+
sessionId: string;
|
|
1483
|
+
backend: TurnBackendConfig;
|
|
1484
|
+
model?: ConversationTurnOptions["model"];
|
|
1485
|
+
}): Promise<{
|
|
1486
|
+
expectedPublicProfileRequestDigest: `sha256:${string}`;
|
|
1487
|
+
expectedSecretProfileReceipt: `hmac-sha256:${string}`;
|
|
1488
|
+
workspacePlanDigest: `sha256:${string}`;
|
|
1489
|
+
conflicts: Array<{
|
|
1490
|
+
relPath: string;
|
|
1491
|
+
copyRelPath: string;
|
|
1492
|
+
reason: "existing" | "symlink";
|
|
1493
|
+
}>;
|
|
1494
|
+
}>;
|
|
1495
|
+
}
|
|
1496
|
+
//#endregion
|
|
1497
|
+
//#region src/sandbox-session-admission.d.ts
|
|
1498
|
+
declare abstract class SandboxSessionAdmissionCapabilities extends SandboxProfileCapabilities {
|
|
1812
1499
|
/**
|
|
1813
|
-
* List
|
|
1814
|
-
*
|
|
1815
|
-
*
|
|
1816
|
-
*
|
|
1817
|
-
*
|
|
1818
|
-
* @param storage - Optional customer storage config for BYOS3
|
|
1819
|
-
* @returns Array of snapshot metadata
|
|
1500
|
+
* List messages for a session, including in-flight assistant content
|
|
1501
|
+
* the agent is still streaming. Each entry's `metadata` carries the
|
|
1502
|
+
* durability marker — `status: "streaming" | "completed" | "interrupted"`,
|
|
1503
|
+
* `completed/interrupted` booleans, and the caller-supplied `turnId`
|
|
1504
|
+
* when one was set. See `SessionMessage` for the full contract.
|
|
1820
1505
|
*
|
|
1821
|
-
*
|
|
1822
|
-
*
|
|
1823
|
-
*
|
|
1824
|
-
*
|
|
1825
|
-
|
|
1826
|
-
|
|
1506
|
+
* Polling this is the right way to detect "did the sidecar die mid-
|
|
1507
|
+
* turn?" — a SIGKILL leaves the assistant message with `status:
|
|
1508
|
+
* "streaming"` and no `completed`/`interrupted` marker; a graceful
|
|
1509
|
+
* abort stamps `interrupted: true` explicitly.
|
|
1510
|
+
*/
|
|
1511
|
+
messages(opts: ListMessagesOptions): Promise<SessionMessage[]>;
|
|
1512
|
+
/** @internal — invoked by SandboxSession.sendMessage(). */
|
|
1513
|
+
_sessionSendMessage(id: string, request: SendSessionMessageRequest, options?: SendSessionMessageOptions): Promise<SentSessionMessage>;
|
|
1514
|
+
/** @internal — invoked by SandboxSession.delete(). */
|
|
1515
|
+
_sessionDelete(id: string): Promise<void>;
|
|
1516
|
+
/** @internal — invoked by SandboxTaskSession.changes(). */
|
|
1517
|
+
_taskSessionChanges(id: string): Promise<TaskSessionChanges>;
|
|
1518
|
+
/** @internal — invoked by SandboxTaskSession.commit(). */
|
|
1519
|
+
_taskSessionCommit(id: string, options?: CommitTaskSessionOptions): Promise<TaskSessionCommitResult>;
|
|
1520
|
+
_sessionFork(id: string, opts?: SessionForkOptions): Promise<SessionInfo>;
|
|
1521
|
+
/** @internal — invoked by SandboxSession.status(). */
|
|
1522
|
+
_sessionStatus(id: string): Promise<SessionInfo | null>;
|
|
1523
|
+
/** @internal — invoked by SandboxSession.runs(). */
|
|
1524
|
+
_sessionRuns(id: string): Promise<SessionExecutionInfo[]>;
|
|
1525
|
+
/** @internal — invoked by SandboxSession.admission(). */
|
|
1526
|
+
_sessionAdmission(id: string, turnId: string, options?: {
|
|
1527
|
+
signal?: AbortSignal;
|
|
1528
|
+
}): Promise<SessionMessageAdmission | null>;
|
|
1529
|
+
/** @internal — invoked by SandboxSession.interrupt(). */
|
|
1530
|
+
_interrupt(id: string, options?: SessionInterruptOptions): Promise<InterruptResult>;
|
|
1531
|
+
protected interactionTransport(): SandboxInteractionTransport;
|
|
1532
|
+
/** @internal — invoked by SandboxSession.interactions(). */
|
|
1533
|
+
_listInteractions(id: string, options?: {
|
|
1534
|
+
signal?: AbortSignal;
|
|
1535
|
+
}): Promise<InteractionRequest[]>;
|
|
1536
|
+
/** @internal — invoked by SandboxSession.respondToInteraction(). */
|
|
1537
|
+
_respondToInteraction(id: string, command: InteractionResponseCommand, options?: {
|
|
1538
|
+
signal?: AbortSignal;
|
|
1539
|
+
}): Promise<SandboxInteractionCommandResult>;
|
|
1540
|
+
/** @internal — invoked by SandboxSession.respondToPermission(). */
|
|
1541
|
+
_respondToPermission(id: string, permissionID: string, options: RespondToPermissionOptions): Promise<SandboxInteractionResult>;
|
|
1542
|
+
/** @internal — invoked by SandboxSession.cancelRun(). */
|
|
1543
|
+
_cancelRun(id: string, request: AgentRunCancellationRequest, options?: {
|
|
1544
|
+
signal?: AbortSignal;
|
|
1545
|
+
}): Promise<AgentRunCancellationAcknowledgement>;
|
|
1546
|
+
/** @internal — invoked by SandboxSession.answer(). */
|
|
1547
|
+
_answerQuestion(id: string, interactionId: string, answers: InteractionData, options?: {
|
|
1548
|
+
signal?: AbortSignal;
|
|
1549
|
+
}): Promise<SandboxInteractionResult>;
|
|
1550
|
+
/** @internal — invoked by SandboxSession.plan(). */
|
|
1551
|
+
_currentPlan(sessionId: string): Promise<DurablePlan | null>;
|
|
1552
|
+
/** @internal — invoked by SandboxSession.approvePlan()/rejectPlan(). */
|
|
1553
|
+
_decidePlan(sessionId: string, planId: string, decision: {
|
|
1554
|
+
outcome: "approved";
|
|
1555
|
+
} | {
|
|
1556
|
+
outcome: "rejected";
|
|
1557
|
+
feedback: string;
|
|
1558
|
+
}, options?: DurablePlanDecisionOptions): Promise<DurablePlanDecisionResult>;
|
|
1559
|
+
}
|
|
1560
|
+
//#endregion
|
|
1561
|
+
//#region src/sandbox-prompt-transport.d.ts
|
|
1562
|
+
declare abstract class SandboxPromptTransportCapabilities extends SandboxSessionAdmissionCapabilities {
|
|
1563
|
+
protected logStreamCheckpoint(checkpoint: string, data?: Record<string, unknown>): void;
|
|
1564
|
+
/**
|
|
1565
|
+
* Inner prompt stream: opens the SSE connection and rejoins the execution's
|
|
1566
|
+
* event log on silent drops. May throw (pre-stream HTTP error, timeout, or
|
|
1567
|
+
* `StreamInterruptedError` when it cannot rejoin); the public
|
|
1568
|
+
* `streamPrompt` wrapper converts those throws into in-band events so
|
|
1569
|
+
* callers never see a thrown generator.
|
|
1570
|
+
*/
|
|
1571
|
+
protected streamPromptInner(message: string | PromptInputPart[], options?: PromptOptions, internal?: {
|
|
1572
|
+
forceFullProfile?: boolean;
|
|
1573
|
+
replaySessionId?: string;
|
|
1574
|
+
}): AsyncGenerator<SandboxEvent>;
|
|
1575
|
+
}
|
|
1576
|
+
//#endregion
|
|
1577
|
+
//#region src/sandbox-prompt.d.ts
|
|
1578
|
+
declare abstract class SandboxPromptCapabilities extends SandboxPromptTransportCapabilities {
|
|
1579
|
+
/**
|
|
1580
|
+
* Send a prompt to the agent running in the sandbox.
|
|
1581
|
+
* Returns the complete response after the agent finishes.
|
|
1582
|
+
*/
|
|
1583
|
+
prompt(message: string | PromptInputPart[], options?: PromptOptions): Promise<PromptResult>;
|
|
1584
|
+
streamPrompt(message: string | PromptInputPart[], requestedOptions?: PromptOptions): AsyncGenerator<SandboxEvent>;
|
|
1585
|
+
}
|
|
1586
|
+
//#endregion
|
|
1587
|
+
//#region src/sandbox-interactive-operations.d.ts
|
|
1588
|
+
declare abstract class SandboxInteractiveCapabilities extends SandboxPromptCapabilities {
|
|
1589
|
+
/**
|
|
1590
|
+
* Interactive terminal operations for this runtime: the REST manager
|
|
1591
|
+
* (create/input/list/get) plus `attach()`, which opens the live terminal
|
|
1592
|
+
* WebSocket as a {@link TerminalStream}.
|
|
1593
|
+
*/
|
|
1594
|
+
get terminals(): SandboxTerminals;
|
|
1595
|
+
/**
|
|
1596
|
+
* Mint a scoped, time-bounded JWT for browser access (Issue #913 Gap 1).
|
|
1597
|
+
* Authority is the caller's `TANGLE_API_KEY` (sk-tan-*); signing secrets
|
|
1598
|
+
* stay server-side. Session/project scopes work with SessionGatewayClient,
|
|
1599
|
+
* while session-runtime/read-only scopes work with SandboxRuntimeClient.
|
|
1600
|
+
*/
|
|
1601
|
+
mintScopedToken(opts: MintScopedTokenOptions): Promise<ScopedToken>;
|
|
1602
|
+
/** @internal — delegated to the native interactive operations module. */
|
|
1603
|
+
_startInteractive(id: string, options: InteractiveSessionStartOptions, requestOptions?: InteractiveRequestOptions): Promise<InteractiveSessionStartResult>;
|
|
1604
|
+
/** @internal — delegated to the native interactive operations module. */
|
|
1605
|
+
_sendInteractivePrompt(id: string, command: InteractivePromptCommand, options?: InteractiveRequestOptions): Promise<Agent.AgentInteractiveSessionPromptAcknowledgement>;
|
|
1606
|
+
/** @internal — delegated to the native interactive operations module. */
|
|
1607
|
+
_claimInteractiveControl(id: string, request: Agent.AgentInteractiveSessionControlClaimRequest, options?: InteractiveControlClaimOptions): Promise<Agent.AgentInteractiveSessionControlClaimAcknowledgement>;
|
|
1608
|
+
/** @internal — delegated to the native interactive operations module. */
|
|
1609
|
+
_releaseInteractiveControl(id: string, ref: Agent.AgentInteractiveSessionRef, control: Agent.AgentInteractiveSessionControlClaim, options?: InteractiveRequestOptions): Promise<void>;
|
|
1610
|
+
/** @internal — delegated to the native interactive operations module. */
|
|
1611
|
+
_validateInteractiveControl(id: string, ref: Agent.AgentInteractiveSessionRef, control: Agent.AgentInteractiveSessionControlClaim, options?: InteractiveRequestOptions): Promise<void>;
|
|
1612
|
+
/** @internal — delegated to the native interactive operations module. */
|
|
1613
|
+
_interactiveStatus(id: string, incarnationId: string, options?: InteractiveRequestOptions): Promise<InteractiveSessionStatus | null>;
|
|
1614
|
+
/** @internal — delegated to the native interactive operations module. */
|
|
1615
|
+
_attachInteractive(id: string, ref: Agent.AgentInteractiveSessionRef, request: InteractiveAttachOptions, options?: InteractiveRequestOptions, reconnectAuthority?: TerminalStreamReconnectAuthority): Promise<TerminalStream>;
|
|
1616
|
+
/** @internal — read exact terminal facts from the runtime-owned manager. */
|
|
1617
|
+
_interactiveTerminalInfo(environmentId: string, terminalId: string, options?: InteractiveRequestOptions): Promise<InteractiveTerminalMetadata | null>;
|
|
1618
|
+
/** @internal — delegated to the native interactive operations module. */
|
|
1619
|
+
_attachTerminal(connectionId: string, options?: SandboxTerminalAttachOptions): Promise<TerminalStream>;
|
|
1620
|
+
/** @internal — delegated to the native interactive operations module. */
|
|
1621
|
+
_stopInteractive(id: string, command: InteractiveStopCommand, options?: InteractiveRequestOptions): Promise<Agent.AgentInteractiveSessionStopAcknowledgement>;
|
|
1622
|
+
/** @internal — delegated to the native interactive operations module. */
|
|
1623
|
+
_stopInteractiveLifecycle(id: string, ref: Agent.AgentInteractiveSessionRef, options?: InteractiveRequestOptions): Promise<Agent.AgentInteractiveSessionStopAcknowledgement>;
|
|
1624
|
+
}
|
|
1625
|
+
//#endregion
|
|
1626
|
+
//#region src/session.d.ts
|
|
1627
|
+
type RawEvidenceAttempt = {
|
|
1628
|
+
executionId: string;
|
|
1629
|
+
ordinal: number;
|
|
1630
|
+
providerSessionId: string;
|
|
1631
|
+
nativeSessionIds: string[];
|
|
1632
|
+
processIds: string[];
|
|
1633
|
+
outcome: "succeeded" | "failed" | "cancelled" | "unknown";
|
|
1634
|
+
missingReasons: string[];
|
|
1635
|
+
};
|
|
1636
|
+
type RawEvidenceExport = ({
|
|
1637
|
+
status: "captured" | "partial";
|
|
1638
|
+
sessionId: string;
|
|
1639
|
+
backendType: string;
|
|
1640
|
+
nativeSessionId: string | null;
|
|
1641
|
+
proofStatus: "verified" | "unverified";
|
|
1642
|
+
containerId?: string;
|
|
1643
|
+
sidecarImageDigest: string;
|
|
1644
|
+
sidecarBundleRevision: string;
|
|
1645
|
+
sidecarBundleChecksum?: string;
|
|
1646
|
+
nativeRoots: Array<{
|
|
1647
|
+
sourceId?: string;
|
|
1648
|
+
rootScope: "session-home" | "workspace-session";
|
|
1649
|
+
path: string;
|
|
1650
|
+
}>;
|
|
1651
|
+
files: Array<Record<string, unknown>>;
|
|
1652
|
+
excluded: Array<Record<string, unknown>>;
|
|
1653
|
+
skipped: Array<{
|
|
1654
|
+
sourceId?: string;
|
|
1655
|
+
rootScope: "session-home" | "workspace-session";
|
|
1656
|
+
path: string;
|
|
1657
|
+
reason: string;
|
|
1658
|
+
}>;
|
|
1659
|
+
inventory: Record<string, number>;
|
|
1660
|
+
processIo: Array<Record<string, unknown>>;
|
|
1661
|
+
processTerminals: Array<Record<string, unknown>>; /** Exact raw spool for every readable provider HOME. */
|
|
1662
|
+
processSources: Array<{
|
|
1663
|
+
sourceId: string;
|
|
1664
|
+
contentBase64: string;
|
|
1665
|
+
sizeBytes: number;
|
|
1666
|
+
sha256: string;
|
|
1667
|
+
}>;
|
|
1668
|
+
events: Array<Record<string, unknown>>;
|
|
1669
|
+
attempts: RawEvidenceAttempt[];
|
|
1670
|
+
evidenceSources: Array<{
|
|
1671
|
+
executionId: string;
|
|
1672
|
+
sourceId: string;
|
|
1673
|
+
backendType: string;
|
|
1674
|
+
runtimeHome: string;
|
|
1675
|
+
credentialPaths: string[];
|
|
1676
|
+
}>;
|
|
1677
|
+
completeness: {
|
|
1678
|
+
nativeStore: boolean;
|
|
1679
|
+
processIo: boolean;
|
|
1680
|
+
events: boolean;
|
|
1681
|
+
};
|
|
1682
|
+
coverageComplete: boolean;
|
|
1683
|
+
missingReasons: string[];
|
|
1684
|
+
} & ({
|
|
1685
|
+
status: "captured";
|
|
1686
|
+
nativeSessionId: string | null;
|
|
1687
|
+
completeness: {
|
|
1688
|
+
nativeStore: true;
|
|
1689
|
+
processIo: true;
|
|
1690
|
+
events: true;
|
|
1691
|
+
};
|
|
1692
|
+
coverageComplete: true;
|
|
1693
|
+
missingReasons: [];
|
|
1694
|
+
} | {
|
|
1695
|
+
status: "partial";
|
|
1696
|
+
coverageComplete: false;
|
|
1697
|
+
})) | {
|
|
1698
|
+
status: "unavailable";
|
|
1699
|
+
sessionId: string;
|
|
1700
|
+
backendType: string;
|
|
1701
|
+
reason: string;
|
|
1702
|
+
};
|
|
1703
|
+
/**
|
|
1704
|
+
* The subset of `SandboxInstance` a `SandboxSession` drives. Declared here
|
|
1705
|
+
* (rather than importing the concrete class) so `session.ts` stays a leaf
|
|
1706
|
+
* of `sandbox.ts` — `sandbox.ts` constructs `SandboxSession`, so the reverse
|
|
1707
|
+
* import would form a cycle. `SandboxInstance` satisfies this structurally.
|
|
1708
|
+
*/
|
|
1709
|
+
interface SandboxSessionHost extends InteractiveSessionHost {
|
|
1710
|
+
prompt(message: string | PromptInputPart[], options?: PromptOptions): Promise<PromptResult>;
|
|
1711
|
+
_sessionStatus(id: string): Promise<SessionInfo | null>;
|
|
1712
|
+
_sessionEvents(id: string, opts?: SessionEventStreamOptions): AsyncGenerator<SandboxEvent>;
|
|
1713
|
+
_sessionRuns(id: string): Promise<SessionExecutionInfo[]>;
|
|
1714
|
+
_sessionRawEvidence(id: string): Promise<RawEvidenceExport>;
|
|
1715
|
+
_sessionExportRawEvidence(id: string, destination: string, options: RawEvidenceExportOptions): Promise<RawEvidenceDirectoryExport>;
|
|
1716
|
+
_sessionAdmission(id: string, turnId: string, options?: {
|
|
1717
|
+
signal?: AbortSignal;
|
|
1718
|
+
}): Promise<SessionMessageAdmission | null>;
|
|
1719
|
+
_sessionResult(id: string, options?: SessionResultOptions, session?: SessionInfo): Promise<PromptResult>;
|
|
1720
|
+
_sessionDelete(id: string): Promise<void>;
|
|
1721
|
+
_sessionSendMessage(id: string, request: SendSessionMessageRequest, options?: SendSessionMessageOptions): Promise<SentSessionMessage>;
|
|
1722
|
+
messages(opts: ListMessagesOptions): Promise<SessionMessage[]>;
|
|
1723
|
+
_sessionFork(id: string, opts?: SessionForkOptions): Promise<SessionInfo>;
|
|
1724
|
+
_respondToPermission(id: string, permissionID: string, options: RespondToPermissionOptions): Promise<SandboxInteractionResult>;
|
|
1725
|
+
_listInteractions(id: string, options?: {
|
|
1726
|
+
signal?: AbortSignal;
|
|
1727
|
+
}): Promise<InteractionRequest[]>;
|
|
1728
|
+
_respondToInteraction(id: string, command: InteractionResponseCommand, options?: {
|
|
1729
|
+
signal?: AbortSignal;
|
|
1730
|
+
}): Promise<SandboxInteractionCommandResult>;
|
|
1731
|
+
_interrupt(id: string, options?: SessionInterruptOptions): Promise<InterruptResult>;
|
|
1732
|
+
_cancelRun(id: string, request: AgentRunCancellationRequest, options?: {
|
|
1733
|
+
signal?: AbortSignal;
|
|
1734
|
+
}): Promise<AgentRunCancellationAcknowledgement>;
|
|
1735
|
+
_answerQuestion(id: string, interactionId: string, answers: InteractionData, options?: {
|
|
1736
|
+
signal?: AbortSignal;
|
|
1737
|
+
}): Promise<SandboxInteractionResult>;
|
|
1738
|
+
_currentPlan(id: string): Promise<DurablePlan | null>;
|
|
1739
|
+
_decidePlan(id: string, planId: string, decision: {
|
|
1740
|
+
outcome: "approved";
|
|
1741
|
+
} | {
|
|
1742
|
+
outcome: "rejected";
|
|
1743
|
+
feedback: string;
|
|
1744
|
+
}, options?: DurablePlanDecisionOptions): Promise<DurablePlanDecisionResult>;
|
|
1745
|
+
}
|
|
1746
|
+
/**
|
|
1747
|
+
* A single agent session inside a sandbox. Created via
|
|
1748
|
+
* `box.session(id)` — does not hit the network until a method is called.
|
|
1749
|
+
*/
|
|
1750
|
+
declare class SandboxSession {
|
|
1751
|
+
private readonly box;
|
|
1752
|
+
/** Stable session id assigned by the sandbox runtime. */
|
|
1753
|
+
readonly id: string;
|
|
1754
|
+
/**
|
|
1755
|
+
* @internal SDK-internal constructor — apps should call `box.session(id)`.
|
|
1756
|
+
*/
|
|
1757
|
+
constructor(box: SandboxSessionHost, /** Stable session id assigned by the sandbox runtime. */
|
|
1758
|
+
|
|
1759
|
+
id: string);
|
|
1760
|
+
/**
|
|
1761
|
+
* Fetch the current session state from the sandbox. Includes status,
|
|
1762
|
+
* model, prompt count, token usage if known, and timing metadata.
|
|
1763
|
+
*
|
|
1764
|
+
* Throws on transport error; returns `null` if the session id is not
|
|
1765
|
+
* known to the sandbox (e.g. it ended and was reaped, or the id is
|
|
1766
|
+
* invalid).
|
|
1767
|
+
*/
|
|
1768
|
+
status(): Promise<SessionInfo | null>;
|
|
1769
|
+
/**
|
|
1770
|
+
* Stream events from this session as they arrive. With no `since`,
|
|
1771
|
+
* starts at the live tail; with `since`, replays strictly after that
|
|
1772
|
+
* event id — useful for reconnect-after-disconnect flows.
|
|
1773
|
+
*
|
|
1774
|
+
* The async iterator terminates when the session reaches a terminal
|
|
1775
|
+
* state (`completed`, `failed`, `cancelled`) and the corresponding
|
|
1776
|
+
* terminal event has been yielded, OR when the caller's signal aborts.
|
|
1777
|
+
*/
|
|
1778
|
+
events(opts?: SessionEventStreamOptions): AsyncGenerator<SandboxEvent>;
|
|
1779
|
+
/**
|
|
1780
|
+
* List the durable executions recorded for this session, newest first.
|
|
1781
|
+
*
|
|
1782
|
+
* This is the runtime's authoritative execution ledger. It lets callers
|
|
1783
|
+
* count provider runs without inferring execution from model-written files.
|
|
1784
|
+
*/
|
|
1785
|
+
runs(): Promise<SessionExecutionInfo[]>;
|
|
1786
|
+
/** Capture the complete attributed native store and process stream before deletion. */
|
|
1787
|
+
/** Export verified native evidence into a new local directory with bounded memory. */
|
|
1788
|
+
exportRawEvidence(destination: string, options: RawEvidenceExportOptions): Promise<RawEvidenceDirectoryExport>;
|
|
1789
|
+
rawEvidence(): Promise<RawEvidenceExport>;
|
|
1790
|
+
/** Read the exact execution admitted for a turn, including server-owned plan follow-ups.
|
|
1791
|
+
* This never admits work or verifies the input of a proposed retry.
|
|
1792
|
+
*/
|
|
1793
|
+
admission(turnId: string, options?: {
|
|
1794
|
+
signal?: AbortSignal;
|
|
1795
|
+
}): Promise<SessionMessageAdmission | null>;
|
|
1796
|
+
/**
|
|
1797
|
+
* Await a terminal result. With `executionId`, drains only that execution;
|
|
1798
|
+
* without it, reads status and selects the latest execution. Event replay
|
|
1799
|
+
* makes either form safe after the execution has already finished.
|
|
1800
|
+
*
|
|
1801
|
+
* Use this to wait for a session that was started by another caller
|
|
1802
|
+
* (e.g. `dispatchPrompt`).
|
|
1803
|
+
*/
|
|
1804
|
+
result(options?: SessionResultOptions): Promise<PromptResult>;
|
|
1805
|
+
/**
|
|
1806
|
+
* List persisted messages for this session, including in-flight assistant
|
|
1807
|
+
* content when the runtime has flushed partial output.
|
|
1808
|
+
*/
|
|
1809
|
+
messages(opts?: Omit<ListMessagesOptions, "sessionId">): Promise<SessionMessage[]>;
|
|
1810
|
+
/**
|
|
1811
|
+
* Continue this session with an additional prompt. Equivalent to
|
|
1812
|
+
* `box.prompt(message, { ...opts, sessionId: this.id })` but reads
|
|
1813
|
+
* naturally on a Session reference.
|
|
1814
|
+
*/
|
|
1815
|
+
prompt(message: string | PromptInputPart[], opts?: PromptOptions): Promise<PromptResult>;
|
|
1816
|
+
/**
|
|
1817
|
+
* Submit a structured message through the session message endpoint. The
|
|
1818
|
+
* returned receipt confirms admission; follow progress with `events()` or
|
|
1819
|
+
* await the terminal response with `result()`. Model and message identifiers
|
|
1820
|
+
* are translated to the runtime's wire names by the SDK.
|
|
1821
|
+
*/
|
|
1822
|
+
sendMessage(request: SendSessionMessageRequest, options?: SendSessionMessageOptions): Promise<SentSessionMessage>;
|
|
1823
|
+
/** Delete this session and its persisted runtime state. */
|
|
1824
|
+
delete(): Promise<void>;
|
|
1825
|
+
/**
|
|
1826
|
+
* Fork this session into a new queued session. The fork shares the
|
|
1827
|
+
* parent workspace and copies conversation history up to `messageId`
|
|
1828
|
+
* when supplied.
|
|
1829
|
+
*/
|
|
1830
|
+
fork(opts?: SessionForkOptions): Promise<{
|
|
1831
|
+
session: SandboxSession;
|
|
1832
|
+
info: SessionInfo;
|
|
1833
|
+
}>;
|
|
1834
|
+
/**
|
|
1835
|
+
* Drive this session's harness in INTERACTIVE mode: spawn its native TUI,
|
|
1836
|
+
* stream the live framebuffer, and inject prompts as keystrokes. Distinct
|
|
1837
|
+
* from the headless `prompt()`/`events()` surface above. Lazy — does not hit
|
|
1838
|
+
* the network until a handle method is called.
|
|
1839
|
+
*/
|
|
1840
|
+
interactive(options?: InteractiveSessionHandleOptions): InteractiveSessionHandle;
|
|
1841
|
+
/**
|
|
1842
|
+
* Resolve a pending permission interaction the agent raised mid-turn,
|
|
1843
|
+
* forwarding `allow`/`deny` to the blocked agent through the unified
|
|
1844
|
+
* interaction channel. Throws if no matching permission is outstanding.
|
|
1845
|
+
*/
|
|
1846
|
+
respondToPermission(permissionID: string, options: RespondToPermissionOptions): Promise<SandboxInteractionResult>;
|
|
1847
|
+
/** Return every interaction that still awaits a response on this session. */
|
|
1848
|
+
interactions(options?: {
|
|
1849
|
+
signal?: AbortSignal;
|
|
1850
|
+
}): Promise<InteractionRequest[]>;
|
|
1851
|
+
/** Respond to one exact interaction with a retry-safe command. */
|
|
1852
|
+
respondToInteraction(command: InteractionResponseCommand, options?: {
|
|
1853
|
+
signal?: AbortSignal;
|
|
1854
|
+
}): Promise<SandboxInteractionCommandResult>;
|
|
1855
|
+
/**
|
|
1856
|
+
* Interrupt an execution without deleting the session. Pass `executionId`
|
|
1857
|
+
* to make the cancellation exact: a newer run on the same session is never
|
|
1858
|
+
* touched. Without it, the current execution is selected. Returns
|
|
1859
|
+
* `{ cancelled: false }` when the selected execution is not running.
|
|
1860
|
+
*/
|
|
1861
|
+
interrupt(options?: SessionInterruptOptions): Promise<InterruptResult>;
|
|
1862
|
+
/**
|
|
1863
|
+
* Cancel one exact run through the durable operation contract. Reusing the
|
|
1864
|
+
* same request after a lost response returns the sidecar's replayed
|
|
1865
|
+
* acknowledgement instead of issuing a second cancellation.
|
|
1866
|
+
*/
|
|
1867
|
+
cancelRun(request: AgentRunCancellationRequest, options?: {
|
|
1868
|
+
signal?: AbortSignal;
|
|
1869
|
+
}): Promise<AgentRunCancellationAcknowledgement>;
|
|
1870
|
+
/** Answer one exact question without selecting another outstanding ask. */
|
|
1871
|
+
answer(interactionId: string, answers: InteractionData, options?: {
|
|
1872
|
+
signal?: AbortSignal;
|
|
1873
|
+
}): Promise<SandboxInteractionResult>;
|
|
1874
|
+
/** Return the newest plan awaiting a decision for this session. */
|
|
1875
|
+
plan(): Promise<DurablePlan | null>;
|
|
1876
|
+
/** Approve a durable plan; caller mode returns admission for fresh preparation. */
|
|
1877
|
+
approvePlan(planId?: string, options?: DurablePlanDecisionOptions): Promise<DurablePlanDecisionResult>;
|
|
1878
|
+
/** Reject a durable plan with feedback; caller mode prepares the revision turn. */
|
|
1879
|
+
rejectPlan(feedback: string, planId?: string, options?: DurablePlanDecisionOptions): Promise<DurablePlanDecisionResult>;
|
|
1880
|
+
private requireCurrentPlan;
|
|
1881
|
+
}
|
|
1882
|
+
//#endregion
|
|
1883
|
+
//#region src/sandbox-session-evidence.d.ts
|
|
1884
|
+
declare abstract class SandboxSessionEvidenceCapabilities extends SandboxInteractiveCapabilities {
|
|
1885
|
+
/** @internal — invoked before the sandbox is deleted. */
|
|
1886
|
+
_sessionExportRawEvidence(id: string, destination: string, options: RawEvidenceExportOptions): Promise<RawEvidenceDirectoryExport>;
|
|
1887
|
+
/**
|
|
1888
|
+
* Export every native session store on this box into a new local
|
|
1889
|
+
* directory: each runtime HOME's Claude Code, Codex, OpenCode and other
|
|
1890
|
+
* harness stores (transcripts and SQLite databases), and every settled
|
|
1891
|
+
* copy. The box-level twin of `box.session(id).exportRawEvidence`, for a
|
|
1892
|
+
* box about to be deleted, including one restored from a snapshot whose
|
|
1893
|
+
* session listing is empty. Only files a harness contract declares as its
|
|
1894
|
+
* session store are read; credentials and config never leave the box.
|
|
1895
|
+
*
|
|
1896
|
+
* The destination must not exist. Payload digests, the manifest digest
|
|
1897
|
+
* and the byte and file bounds are verified before the directory appears.
|
|
1898
|
+
*/
|
|
1899
|
+
exportRawEvidence(destination: string, options: RawEvidenceBoxExportOptions): Promise<RawEvidenceBoxDirectoryExport>;
|
|
1900
|
+
_sessionRawEvidence(id: string): Promise<RawEvidenceExport>;
|
|
1901
|
+
/** @internal — invoked by SandboxSession.events(). */
|
|
1902
|
+
_sessionEvents(id: string, opts?: SessionEventStreamOptions, stopOnTurnTerminal?: boolean): AsyncGenerator<SandboxEvent>;
|
|
1903
|
+
/** Replay one execution without subscribing to other runs on its session. */
|
|
1904
|
+
protected _executionEvents(sessionId: string, executionId: string): AsyncGenerator<SandboxEvent>;
|
|
1905
|
+
/** @internal — invoked by SandboxSession.result(). */
|
|
1906
|
+
_sessionResult(id: string, options?: SessionResultOptions, knownSession?: SessionInfo): Promise<PromptResult>;
|
|
1907
|
+
}
|
|
1908
|
+
//#endregion
|
|
1909
|
+
//#region src/task-session.d.ts
|
|
1910
|
+
/** @internal Operations implemented by `SandboxInstance`. */
|
|
1911
|
+
interface SandboxTaskSessionHost extends SandboxSessionHost {
|
|
1912
|
+
_taskSessionChanges(id: string): Promise<TaskSessionChanges>;
|
|
1913
|
+
_taskSessionCommit(id: string, options?: CommitTaskSessionOptions): Promise<TaskSessionCommitResult>;
|
|
1914
|
+
}
|
|
1915
|
+
/** A background task session with isolated changeset operations. */
|
|
1916
|
+
declare class SandboxTaskSession extends SandboxSession {
|
|
1917
|
+
private readonly taskBox;
|
|
1918
|
+
/** @internal Apps should call `box.taskSession(id)`. */
|
|
1919
|
+
constructor(taskBox: SandboxTaskSessionHost, id: string);
|
|
1920
|
+
/** Read the task's isolated file changes. */
|
|
1921
|
+
changes(): Promise<TaskSessionChanges>;
|
|
1922
|
+
/** Apply all or a selected subset of the task's isolated file changes. */
|
|
1923
|
+
commit(options?: CommitTaskSessionOptions): Promise<TaskSessionCommitResult>;
|
|
1924
|
+
}
|
|
1925
|
+
//#endregion
|
|
1926
|
+
//#region src/sandbox-sessions.d.ts
|
|
1927
|
+
/**
|
|
1928
|
+
* Result of registering a sidecar session mapping. `reprovisionRequired` is
|
|
1929
|
+
* true when the server reports the mapped sidecar is stale (HTTP 410) and the
|
|
1930
|
+
* caller must reprovision the sandbox before retrying.
|
|
1931
|
+
*/
|
|
1932
|
+
interface SessionMappingResult {
|
|
1933
|
+
success: boolean;
|
|
1934
|
+
sessionId: string;
|
|
1935
|
+
sidecarSessionId?: string;
|
|
1936
|
+
reprovisionRequired: boolean;
|
|
1937
|
+
code?: string;
|
|
1938
|
+
}
|
|
1939
|
+
declare abstract class SandboxSessionCapabilities extends SandboxSessionEvidenceCapabilities {
|
|
1940
|
+
/**
|
|
1941
|
+
* Associate a session ID with this sandbox so the Sandbox API can route
|
|
1942
|
+
* subsequent WebSocket connections.
|
|
1943
|
+
*
|
|
1944
|
+
* @param opts - Session and sandbox routing identifiers
|
|
1945
|
+
*
|
|
1946
|
+
* @example
|
|
1947
|
+
* ```typescript
|
|
1948
|
+
* await box.registerSessionMapping({
|
|
1949
|
+
* sessionId: "sess_abc",
|
|
1950
|
+
* runtimeSessionId: "runtime_abc",
|
|
1951
|
+
* });
|
|
1952
|
+
* ```
|
|
1953
|
+
*/
|
|
1954
|
+
registerSessionMapping(opts: {
|
|
1955
|
+
sessionId: string; /** The runtime (sidecar) session id this agent session routes to. */
|
|
1956
|
+
runtimeSessionId: string; /** Optional container id for direct routing. */
|
|
1957
|
+
sidecarId?: string; /** Optional projectRef so the server can detect a stale sidecar. */
|
|
1958
|
+
projectRef?: string;
|
|
1959
|
+
}): Promise<SessionMappingResult>;
|
|
1960
|
+
/**
|
|
1961
|
+
* Remove the sidecar session mapping for an agent session. Sandbox deletion
|
|
1962
|
+
* also cleans mappings, so this is only needed to release a mapping while the
|
|
1963
|
+
* sandbox stays alive.
|
|
1964
|
+
*/
|
|
1965
|
+
unregisterSessionMapping(opts: {
|
|
1966
|
+
sessionId: string;
|
|
1967
|
+
}): Promise<{
|
|
1968
|
+
success: boolean;
|
|
1969
|
+
sessionId: string;
|
|
1970
|
+
}>;
|
|
1971
|
+
/**
|
|
1972
|
+
* Get a session reference bound to this sandbox. Lazy: does not hit the
|
|
1973
|
+
* network until you call a method on the returned `SandboxSession`.
|
|
1974
|
+
* Use {@link sessions} to discover existing session ids.
|
|
1975
|
+
*/
|
|
1976
|
+
session(id: string): SandboxSession;
|
|
1977
|
+
/**
|
|
1978
|
+
* Lines attached to this sandbox. `attach()` binds a line so Hub runs each
|
|
1979
|
+
* member's messages here, one session per member.
|
|
1980
|
+
*/
|
|
1981
|
+
get lines(): SandboxLines;
|
|
1982
|
+
/** Create an agent session and return both its handle and initial metadata. */
|
|
1983
|
+
createSession(options: CreateSessionOptions): Promise<{
|
|
1984
|
+
session: SandboxSession;
|
|
1985
|
+
info: SessionInfo;
|
|
1986
|
+
}>;
|
|
1987
|
+
/** Delete an agent session by id. */
|
|
1988
|
+
deleteSession(id: string): Promise<void>;
|
|
1989
|
+
/** Get a lazy background-task session reference. */
|
|
1990
|
+
taskSession(id: string): SandboxTaskSession;
|
|
1991
|
+
/** Create a background task session. Dispatch work with `session.sendMessage()`. */
|
|
1992
|
+
createTaskSession(options: CreateTaskSessionOptions): Promise<{
|
|
1993
|
+
session: SandboxTaskSession;
|
|
1994
|
+
info: TaskSessionInfo;
|
|
1995
|
+
}>;
|
|
1996
|
+
/**
|
|
1997
|
+
* List sessions on this sandbox, optionally filtering by status. Returns
|
|
1998
|
+
* `SandboxSession` instances paired with their last-known
|
|
1999
|
+
* {@link SessionInfo} so callers can avoid an extra round-trip per
|
|
2000
|
+
* session for status.
|
|
2001
|
+
*/
|
|
2002
|
+
sessions(opts?: SessionListOptions): Promise<Array<{
|
|
2003
|
+
session: SandboxSession;
|
|
2004
|
+
info: SessionInfo;
|
|
2005
|
+
}>>;
|
|
2006
|
+
/**
|
|
2007
|
+
* Dispatch a prompt and return immediately with the session id (Issue
|
|
2008
|
+
* #913 Gap 2). The sandbox keeps running the prompt after this call
|
|
2009
|
+
* returns; reconnect via `box.session(id).events()` or wait for
|
|
2010
|
+
* completion with `box.session(id).result()`.
|
|
2011
|
+
*
|
|
2012
|
+
* Skips the dispatch only on positive evidence that this work is
|
|
2013
|
+
* already in flight or already finished — never on the mere existence
|
|
2014
|
+
* of a session with the same id:
|
|
2015
|
+
*
|
|
2016
|
+
* 1. `opts.turnId` is set and the completed-turn cache has it → the
|
|
2017
|
+
* turn already finished; return `dispatched: false`. This is the
|
|
2018
|
+
* only durable idempotency key, and it outlives the session (the
|
|
2019
|
+
* cache survives session eviction, see `findCompletedTurn`).
|
|
2020
|
+
* 2. Otherwise, the session is in flight — `running`, or `queued` with a
|
|
2021
|
+
* `latestExecutionId` — → a second dispatch would run two agents
|
|
2022
|
+
* against one session, so return the live status with
|
|
2023
|
+
* `dispatched: false`.
|
|
2024
|
+
*
|
|
2025
|
+
* Anything else dispatches. Two cases in particular:
|
|
2026
|
+
*
|
|
2027
|
+
* - A `queued` session with no `latestExecutionId` was created or
|
|
2028
|
+
* forked and has never run anything — the runtime writes exactly
|
|
2029
|
+
* that state on `POST /agents/sessions` and on fork, and sets
|
|
2030
|
+
* `latestExecutionId` at execution START. Refusing here would leave
|
|
2031
|
+
* a pre-created session permanently undispatchable.
|
|
2032
|
+
* - A terminal session is a finished conversation, and a new prompt
|
|
2033
|
+
* into it is a new turn, not a retry.
|
|
2034
|
+
*
|
|
2035
|
+
* A caller that needs a completed dispatch to stay a no-op across
|
|
2036
|
+
* retries MUST pass `turnId`; session existence cannot stand in for it,
|
|
2037
|
+
* because an evicted session makes the same retry dispatch anyway.
|
|
2038
|
+
*
|
|
2039
|
+
* Read `dispatched`, not `alreadyExisted`, to tell "the prompt ran"
|
|
2040
|
+
* from "we found prior work and did nothing".
|
|
2041
|
+
*/
|
|
2042
|
+
dispatchPrompt(message: string | PromptInputPart[], opts?: DispatchPromptOptions): Promise<DispatchedSession>;
|
|
2043
|
+
/**
|
|
2044
|
+
* Look up a cached turn result by idempotency key. Returns the cached
|
|
2045
|
+
* payload if a turn with this `turnId` previously completed on the
|
|
2046
|
+
* given session; returns `null` if no such turn has finished yet
|
|
2047
|
+
* (either it never started, or it interrupted before completion).
|
|
2048
|
+
*
|
|
2049
|
+
* Call this before re-issuing a `streamPrompt` / `prompt` / `task`
|
|
2050
|
+
* that you might be retrying — a non-null result means the original
|
|
2051
|
+
* attempt finished and you can return that to your caller instead of
|
|
2052
|
+
* running the agent a second time. Only turns that reach the
|
|
2053
|
+
* `completed` terminal state are cached; interrupted turns are not.
|
|
2054
|
+
*/
|
|
2055
|
+
findCompletedTurn(turnId: string, opts: {
|
|
2056
|
+
sessionId: string;
|
|
2057
|
+
}): Promise<CompletedTurnResult | null>;
|
|
2058
|
+
}
|
|
2059
|
+
//#endregion
|
|
2060
|
+
//#region src/sandbox-turns.d.ts
|
|
2061
|
+
declare abstract class SandboxTurnCapabilities extends SandboxSessionCapabilities {
|
|
2062
|
+
/**
|
|
2063
|
+
* Drive a detached turn forward by exactly one settle → poll → dispatch
|
|
2064
|
+
* pass and report where it stands. Built for tick-based callers —
|
|
2065
|
+
* Cloudflare Workflows steps, queue consumers, crons — that re-invoke
|
|
2066
|
+
* on their own schedule instead of holding a stream open.
|
|
2067
|
+
* The pass does not poll repeatedly or keep a connection alive.
|
|
2068
|
+
* Session admission may retry one classified pre-dispatch credential refusal.
|
|
2069
|
+
*
|
|
2070
|
+
* The pass resolves to the first of:
|
|
2071
|
+
* 1. The completed-turn cache has `turnId` → `completed`, or `failed`
|
|
2072
|
+
* when the cached payload carries no text — that result is final,
|
|
2073
|
+
* so a retry cannot improve it.
|
|
2074
|
+
* 2. The session is queued/running → `running`, after enforcing
|
|
2075
|
+
* `wallCapMs`: a session past the cap is cancelled and reported
|
|
2076
|
+
* `failed`.
|
|
2077
|
+
* 3. The session is terminal without a cached turn → settle from the
|
|
2078
|
+
* session result; an unsuccessful result is `failed`.
|
|
2079
|
+
* 4. No session exists, or one exists that was created/forked but never
|
|
2080
|
+
* ran (`queued` with no `latestExecutionId`) → dispatch
|
|
2081
|
+
* fire-and-detach → `running`.
|
|
2082
|
+
*
|
|
2083
|
+
* `failed` is always deterministic: re-invoking with the same ids
|
|
2084
|
+
* returns the same outcome rather than starting a second agent run, so
|
|
2085
|
+
* callers can treat it as terminal without their own retry bookkeeping.
|
|
2086
|
+
*/
|
|
2087
|
+
driveTurn(message: string | PromptInputPart[], opts: DriveTurnOptions): Promise<TurnDriveResult>;
|
|
2088
|
+
/** Advance exactly the named turn while retaining the native conversation.
|
|
2089
|
+
* Admission receipts are independent of expiring event logs. A previous
|
|
2090
|
+
* turn's terminal session status cannot settle a newly submitted message. */
|
|
2091
|
+
driveConversationTurn(message: string | PromptInputPart[], opts: ConversationTurnOptions): Promise<ConversationTurnResult>;
|
|
2092
|
+
protected driveConversationTurnPass(message: string | PromptInputPart[], opts: ConversationTurnOptions, traceId: string): Promise<ConversationTurnResult>;
|
|
2093
|
+
}
|
|
2094
|
+
//#endregion
|
|
2095
|
+
//#region src/sandbox-snapshots.d.ts
|
|
2096
|
+
interface SnapshotRestoreAcceptedResponse {
|
|
2097
|
+
jobId: string;
|
|
2098
|
+
status: "pending";
|
|
2099
|
+
}
|
|
2100
|
+
declare abstract class SandboxSnapshotCapabilities extends SandboxTurnCapabilities {
|
|
2101
|
+
#private;
|
|
2102
|
+
snapshot(options: SnapshotOptions & {
|
|
2103
|
+
wait: false;
|
|
2104
|
+
}): Promise<SandboxOperation>;
|
|
2105
|
+
snapshot(options?: SnapshotOptions): Promise<SnapshotResult>;
|
|
2106
|
+
/**
|
|
2107
|
+
* List all snapshots for this sandbox.
|
|
2108
|
+
*
|
|
2109
|
+
* If `storage` is provided (BYOS3), lists snapshots from customer-provided
|
|
2110
|
+
* S3 storage.
|
|
2111
|
+
*
|
|
2112
|
+
* @param storage - Optional customer storage config for BYOS3
|
|
2113
|
+
* @returns Array of snapshot metadata
|
|
2114
|
+
*
|
|
2115
|
+
* @example List from our storage
|
|
2116
|
+
* ```typescript
|
|
2117
|
+
* const snapshots = await box.listSnapshots();
|
|
2118
|
+
* for (const snap of snapshots) {
|
|
2119
|
+
* console.log(`${snap.snapshotId}: ${snap.createdAt}`);
|
|
2120
|
+
* }
|
|
1827
2121
|
* ```
|
|
1828
2122
|
*
|
|
1829
2123
|
* @example List from customer S3 (BYOS3)
|
|
@@ -1836,14 +2130,6 @@ declare class SandboxInstance {
|
|
|
1836
2130
|
* ```
|
|
1837
2131
|
*/
|
|
1838
2132
|
listSnapshots(storage?: SnapshotOptions["storage"]): Promise<SnapshotInfo[]>;
|
|
1839
|
-
revertToSnapshot(snapshotId: string): Promise<SnapshotResult>;
|
|
1840
|
-
/**
|
|
1841
|
-
* Replace selected workspace-relative paths from a whole-workspace snapshot.
|
|
1842
|
-
* Files outside the requested paths are left untouched.
|
|
1843
|
-
*/
|
|
1844
|
-
restorePaths(snapshotId: string, paths: string[]): Promise<SnapshotResult>;
|
|
1845
|
-
private waitForSnapshotRestore;
|
|
1846
|
-
private waitForSnapshotVisible;
|
|
1847
2133
|
/**
|
|
1848
2134
|
* Delete a snapshot.
|
|
1849
2135
|
*
|
|
@@ -1869,6 +2155,14 @@ declare class SandboxInstance {
|
|
|
1869
2155
|
* options to read the operation bound to this owner-scoped key.
|
|
1870
2156
|
*/
|
|
1871
2157
|
getSnapshotOperation(idempotencyKey: string, options?: Pick<SnapshotOptions, "tags">): Promise<WorkspaceOperationLookup>;
|
|
2158
|
+
revertToSnapshot(snapshotId: string): Promise<SnapshotResult>;
|
|
2159
|
+
/**
|
|
2160
|
+
* Replace selected workspace-relative paths from a whole-workspace snapshot.
|
|
2161
|
+
* Files outside the requested paths are left untouched.
|
|
2162
|
+
*/
|
|
2163
|
+
restorePaths(snapshotId: string, paths: string[]): Promise<SnapshotResult>;
|
|
2164
|
+
protected waitForSnapshotRestore(snapshotId: string, accepted: SnapshotRestoreAcceptedResponse): Promise<SnapshotResult>;
|
|
2165
|
+
protected waitForSnapshotVisible(snapshotId: string, fallback?: Partial<SnapshotResult>): Promise<SnapshotResult>;
|
|
1872
2166
|
/**
|
|
1873
2167
|
* Restore from the latest snapshot in customer-provided storage.
|
|
1874
2168
|
* Only available when using BYOS3 (calls the runtime directly).
|
|
@@ -1893,45 +2187,10 @@ declare class SandboxInstance {
|
|
|
1893
2187
|
* ```
|
|
1894
2188
|
*/
|
|
1895
2189
|
restoreFromStorage(storage: SnapshotOptions["storage"], options?: RestoreSnapshotOptions): Promise<SnapshotResult | null>;
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
* parent's clean pages instead of each copying full guest memory. The parent
|
|
1901
|
-
* stays running.
|
|
1902
|
-
*
|
|
1903
|
-
* Returns only the children. A fan-out that materialized fewer than `count`
|
|
1904
|
-
* still resolves — the children are real — so compare the array length, or
|
|
1905
|
-
* call {@link fork} for the explicit `complete` flag.
|
|
1906
|
-
*
|
|
1907
|
-
* @param count - Number of children to create (must be >= 1).
|
|
1908
|
-
* @param options - Per-child overrides.
|
|
1909
|
-
* @returns The new sandbox instances that materialized.
|
|
1910
|
-
*
|
|
1911
|
-
* @example
|
|
1912
|
-
* ```typescript
|
|
1913
|
-
* const [a, b, c] = await box.branch(3);
|
|
1914
|
-
* // a, b, c each share box's memory state at branch time
|
|
1915
|
-
* ```
|
|
1916
|
-
*/
|
|
1917
|
-
branch(count: number, options?: BranchOptions): Promise<SandboxInstance[]>;
|
|
1918
|
-
/**
|
|
1919
|
-
* Branch this RUNNING sandbox and report the fan-out, not only the children.
|
|
1920
|
-
*
|
|
1921
|
-
* `complete` is false when fewer children materialized than were requested,
|
|
1922
|
-
* so a partial fan-out is never read as a whole one. With an
|
|
1923
|
-
* `idempotencyKey`, a retry of the same key and options returns exactly the
|
|
1924
|
-
* children the first request materialized and creates none.
|
|
1925
|
-
*
|
|
1926
|
-
* @example
|
|
1927
|
-
* ```typescript
|
|
1928
|
-
* const forked = await box.fork(5, { idempotencyKey: "run-42" });
|
|
1929
|
-
* if (!forked.complete) {
|
|
1930
|
-
* console.warn(`${forked.materializedCount} of ${forked.requestedCount}`);
|
|
1931
|
-
* }
|
|
1932
|
-
* ```
|
|
1933
|
-
*/
|
|
1934
|
-
fork(count: number, options?: BranchOptions): Promise<ForkAcknowledgement>;
|
|
2190
|
+
}
|
|
2191
|
+
//#endregion
|
|
2192
|
+
//#region src/sandbox-branches.d.ts
|
|
2193
|
+
declare abstract class SandboxBranchCapabilities extends SandboxSnapshotCapabilities {
|
|
1935
2194
|
/**
|
|
1936
2195
|
* Ask whether the fork bound to an idempotency key is decided.
|
|
1937
2196
|
*
|
|
@@ -1978,448 +2237,833 @@ declare class SandboxInstance {
|
|
|
1978
2237
|
* exceptions. Throws {@link TimeoutError} on deadline or abort.
|
|
1979
2238
|
*/
|
|
1980
2239
|
waitForRollout(rolloutId: string, options?: WaitForRolloutOptions): Promise<Rollout>;
|
|
2240
|
+
}
|
|
2241
|
+
//#endregion
|
|
2242
|
+
//#region src/sandbox-access.d.ts
|
|
2243
|
+
declare abstract class SandboxAccessCapabilities extends SandboxBranchCapabilities {
|
|
1981
2244
|
/**
|
|
1982
|
-
*
|
|
1983
|
-
*
|
|
1984
|
-
*
|
|
1985
|
-
* (`stop_metering` / `container_kill` / `stop_complete` /
|
|
1986
|
-
* `stop_unaccounted`); after this resolves, {@link startupDiagnostics}
|
|
1987
|
-
* returns it (replacing the create breakdown).
|
|
1988
|
-
*/
|
|
1989
|
-
stop(): Promise<void>;
|
|
1990
|
-
/**
|
|
1991
|
-
* With `wait: false`, answers as soon as the stop is durably accepted and
|
|
1992
|
-
* returns the {@link SandboxOperation}; `await op.wait()` resolves once the
|
|
1993
|
-
* sandbox is stopped. A stop the API finished synchronously comes back as an
|
|
1994
|
-
* operation that is already `succeeded`.
|
|
1995
|
-
*/
|
|
1996
|
-
stop(options: StopOptions & {
|
|
1997
|
-
wait: false;
|
|
1998
|
-
}): Promise<SandboxOperation>;
|
|
1999
|
-
stop(options?: StopOptions): Promise<void>;
|
|
2000
|
-
/** Read an operation a `wait: false` stop or snapshot of this sandbox returned. */
|
|
2001
|
-
getOperation(operationId: string): Promise<SandboxOperation>;
|
|
2002
|
-
/** Read credential recovery metadata without changing sandbox lifecycle. */
|
|
2003
|
-
getEnvRecovery(): Promise<SandboxEnvRecoveryView>;
|
|
2004
|
-
/** Replace a stopped sandbox's policy, or inspect a proposed change with dryRun. */
|
|
2005
|
-
setEnvRecovery(envRecovery: SandboxEnvRecovery, options?: {
|
|
2006
|
-
dryRun?: boolean;
|
|
2007
|
-
}): Promise<SandboxEnvRecoveryView>;
|
|
2008
|
-
/** Resume a stopped sandbox; cold recovery may require caller env values. */
|
|
2009
|
-
resume(options?: ResumeOptions): Promise<void>;
|
|
2010
|
-
/** Rebuild a stopped sandbox from its durable snapshot under the same ID. */
|
|
2011
|
-
rebuild(options?: ResumeOptions): Promise<void>;
|
|
2012
|
-
private resumeRuntime;
|
|
2013
|
-
/**
|
|
2014
|
-
* Delete the sandbox permanently. This is how a forked child is destroyed.
|
|
2015
|
-
*
|
|
2016
|
-
* `outcome` separates `destroyed` from `already_absent`, so a retry after an
|
|
2017
|
-
* uncertain failure reports what really happened instead of raising.
|
|
2018
|
-
*
|
|
2019
|
-
* The call answers once the runtime is killed and billed; the container,
|
|
2020
|
-
* volume and network are reclaimed behind it and `removal` says
|
|
2021
|
-
* `"pending"`. Pass `until: "removed"` to wait for that reclaim instead.
|
|
2022
|
-
*
|
|
2023
|
-
* The delete response carries the orchestrator's per-phase delete breakdown
|
|
2024
|
-
* (`runtime_kill` / `tombstone_persist` / `delete_complete` /
|
|
2025
|
-
* `delete_unaccounted`); after this resolves, {@link startupDiagnostics}
|
|
2026
|
-
* returns it for post-mortem reads on the now-gone sandbox.
|
|
2027
|
-
*/
|
|
2028
|
-
delete(options?: SandboxDeleteOptions): Promise<SandboxDeleteAcknowledgement>;
|
|
2029
|
-
/**
|
|
2030
|
-
* Read a lifecycle response body once.
|
|
2031
|
-
*
|
|
2032
|
-
* Current APIs return the complete sandbox state. Older APIs return an empty
|
|
2033
|
-
* body, so callers refresh when this method cannot recover a state payload.
|
|
2034
|
-
*/
|
|
2035
|
-
private readLifecycleResponse;
|
|
2036
|
-
private applyLifecycleResponse;
|
|
2037
|
-
/**
|
|
2038
|
-
* Upload a local directory to the sandbox via tar.
|
|
2039
|
-
* @param localPath - Local directory path to upload
|
|
2040
|
-
* @param remotePath - Destination path in the sandbox (default: /home/user)
|
|
2041
|
-
*/
|
|
2042
|
-
uploadDirectory(localPath: string, remotePath?: string): Promise<void>;
|
|
2043
|
-
/**
|
|
2044
|
-
* Wait for the sandbox to reach a specific status.
|
|
2045
|
-
*
|
|
2046
|
-
* A sandbox is not considered `running` until its filesystem incarnation is
|
|
2047
|
-
* complete and ready.
|
|
2245
|
+
* Get an MCP endpoint for this sandbox. Returns a paste-able config
|
|
2246
|
+
* for any MCP-capable host (Claude Desktop, Cursor, claude-code,
|
|
2247
|
+
* codex, opencode, …) plus a freshly-minted, capability-scoped JWT.
|
|
2048
2248
|
*
|
|
2049
|
-
*
|
|
2050
|
-
*
|
|
2051
|
-
*
|
|
2249
|
+
* The token is short-lived and limited to the requested capabilities
|
|
2250
|
+
* — it cannot be used against admin endpoints (`/exec`, `/files`,
|
|
2251
|
+
* etc.) on the sandbox. Call `getMcpEndpoint()` again to rotate.
|
|
2052
2252
|
*
|
|
2053
|
-
*
|
|
2054
|
-
*
|
|
2055
|
-
* await box.waitFor("running");
|
|
2056
|
-
* ```
|
|
2253
|
+
* Requires the sandbox to have been created with `capabilities`
|
|
2254
|
+
* including the requested capability (default: `computer_use`).
|
|
2057
2255
|
*
|
|
2058
|
-
* @example
|
|
2256
|
+
* @example
|
|
2059
2257
|
* ```typescript
|
|
2060
|
-
* await box.
|
|
2061
|
-
*
|
|
2062
|
-
*
|
|
2063
|
-
*
|
|
2064
|
-
* updateProgressBar(event.percent);
|
|
2065
|
-
* }
|
|
2066
|
-
* },
|
|
2067
|
-
* });
|
|
2068
|
-
* ```
|
|
2069
|
-
*/
|
|
2070
|
-
waitFor(status: SandboxStatus | SandboxStatus[], options?: WaitForOptions): Promise<void>;
|
|
2071
|
-
/**
|
|
2072
|
-
* SSE-based wait implementation. Subscribes to provisioning events and
|
|
2073
|
-
* delivers progress callbacks while waiting for a target status.
|
|
2074
|
-
*/
|
|
2075
|
-
private waitForWithSSE;
|
|
2076
|
-
private hasReachedWaitTarget;
|
|
2077
|
-
/**
|
|
2078
|
-
* A running filesystem is not enough to serve a consumer. The API can
|
|
2079
|
-
* expose `running` while the public edge is still pending, or after edge
|
|
2080
|
-
* attachment failed. Keep that distinction in the SDK so every caller gets
|
|
2081
|
-
* the same wait and error semantics.
|
|
2082
|
-
*/
|
|
2083
|
-
private consumerConnectionReady;
|
|
2084
|
-
private hasFreshStatus;
|
|
2085
|
-
/**
|
|
2086
|
-
* The check before a runtime call. A handle that has seen the sandbox
|
|
2087
|
-
* running and ready dispatches at once: the authenticated runtime route
|
|
2088
|
-
* checks current sandbox state itself, so a status GET before every call was
|
|
2089
|
-
* a whole round trip through the Worker that only moved the same refusal
|
|
2090
|
-
* earlier. A stale cache surfaces as the call's own answer, which the
|
|
2091
|
-
* direct client and the prompt stream turn into a typed `StateError`. A
|
|
2092
|
-
* handle that has not seen the status, or saw one that is not runnable,
|
|
2093
|
-
* reads it first.
|
|
2258
|
+
* const ep = await box.getMcpEndpoint();
|
|
2259
|
+
* // Save ep.config to your IDE's mcp.json — that's it.
|
|
2260
|
+
* fs.writeFileSync("mcp.json", JSON.stringify(ep.config, null, 2));
|
|
2261
|
+
* ```
|
|
2094
2262
|
*/
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2263
|
+
getMcpEndpoint(options?: {
|
|
2264
|
+
capabilities?: ReadonlyArray<"computer_use">; /** Override server entry name (default: "tangle-sandbox"). */
|
|
2265
|
+
serverName?: string; /** Token TTL in minutes (server clamps to its policy). */
|
|
2266
|
+
ttlMinutes?: number;
|
|
2267
|
+
}): Promise<SandboxMcpEndpoint>;
|
|
2100
2268
|
/**
|
|
2101
|
-
*
|
|
2102
|
-
*
|
|
2103
|
-
*
|
|
2104
|
-
*
|
|
2269
|
+
* Fetch fresh TEE attestation evidence for this sandbox.
|
|
2270
|
+
*
|
|
2271
|
+
* When `attestationNonce` is supplied, the runtime must return evidence bound
|
|
2272
|
+
* to that challenge or fail closed if the selected TEE backend cannot support
|
|
2273
|
+
* nonce-bound report data. *
|
|
2274
|
+
* Throws `CapabilityError` (`TEE_UNSUPPORTED`) when the deployment does not
|
|
2275
|
+
* serve the TEE intercept — these paths are answered by a Tangle
|
|
2276
|
+
* confidential operator ahead of the sandbox API, which registers no route
|
|
2277
|
+
* for them. That refusal is recognised from the API's own unmatched-route
|
|
2278
|
+
* answer, so an intermediary that rewrites 404 bodies leaves the ordinary
|
|
2279
|
+
* `NotFoundError` in its place rather than the named refusal.
|
|
2105
2280
|
*/
|
|
2106
|
-
|
|
2107
|
-
timeoutMs?: number;
|
|
2108
|
-
}): Promise<Response>;
|
|
2281
|
+
getTeeAttestation(options?: TeeAttestationOptions): Promise<TeeAttestationResponse>;
|
|
2109
2282
|
/**
|
|
2110
|
-
*
|
|
2111
|
-
*
|
|
2112
|
-
*
|
|
2113
|
-
*
|
|
2114
|
-
*
|
|
2115
|
-
*
|
|
2283
|
+
* Fetch the TEE-bound public key used for sealed-secret encryption.
|
|
2284
|
+
*
|
|
2285
|
+
* The returned key includes an attestation report. Verify that report before
|
|
2286
|
+
* encrypting secrets to the key. *
|
|
2287
|
+
* Throws `CapabilityError` (`TEE_UNSUPPORTED`) when the deployment does not
|
|
2288
|
+
* serve the TEE intercept — these paths are answered by a Tangle
|
|
2289
|
+
* confidential operator ahead of the sandbox API, which registers no route
|
|
2290
|
+
* for them. That refusal is recognised from the API's own unmatched-route
|
|
2291
|
+
* answer, so an intermediary that rewrites 404 bodies leaves the ordinary
|
|
2292
|
+
* `NotFoundError` in its place rather than the named refusal.
|
|
2116
2293
|
*/
|
|
2117
|
-
|
|
2294
|
+
getTeePublicKey(): Promise<TeePublicKeyResponse>;
|
|
2118
2295
|
/**
|
|
2119
|
-
*
|
|
2120
|
-
*
|
|
2121
|
-
*
|
|
2122
|
-
* @param opts - Session and sandbox routing identifiers
|
|
2296
|
+
* Bootstrap a real-time collaboration session for a file.
|
|
2297
|
+
* Returns the WebSocket URL and auth token needed to connect a
|
|
2298
|
+
* Hocuspocus/Yjs provider for live multi-user editing.
|
|
2123
2299
|
*
|
|
2124
2300
|
* @example
|
|
2125
2301
|
* ```typescript
|
|
2126
|
-
* await box.
|
|
2127
|
-
*
|
|
2128
|
-
*
|
|
2129
|
-
* });
|
|
2302
|
+
* const collab = await box.collaborate("src/index.ts")
|
|
2303
|
+
* // Use collab.transport.websocketUrl + collab.transport.token
|
|
2304
|
+
* // with @hocuspocus/provider to connect
|
|
2130
2305
|
* ```
|
|
2131
2306
|
*/
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
runtimeSessionId: string; /** Optional container id for direct routing. */
|
|
2135
|
-
sidecarId?: string; /** Optional projectRef so the server can detect a stale sidecar. */
|
|
2136
|
-
projectRef?: string;
|
|
2137
|
-
}): Promise<SessionMappingResult>;
|
|
2138
|
-
/**
|
|
2139
|
-
* Remove the sidecar session mapping for an agent session. Sandbox deletion
|
|
2140
|
-
* also cleans mappings, so this is only needed to release a mapping while the
|
|
2141
|
-
* sandbox stays alive.
|
|
2142
|
-
*/
|
|
2143
|
-
unregisterSessionMapping(opts: {
|
|
2144
|
-
sessionId: string;
|
|
2307
|
+
collaborate(path: string, options?: {
|
|
2308
|
+
access?: "read" | "write";
|
|
2145
2309
|
}): Promise<{
|
|
2146
|
-
|
|
2147
|
-
|
|
2310
|
+
documentId: string;
|
|
2311
|
+
transport: {
|
|
2312
|
+
websocketUrl: string;
|
|
2313
|
+
token: string;
|
|
2314
|
+
expiresAt: number;
|
|
2315
|
+
};
|
|
2316
|
+
permissions: {
|
|
2317
|
+
access: "read" | "write";
|
|
2318
|
+
canSnapshot: boolean;
|
|
2319
|
+
};
|
|
2148
2320
|
}>;
|
|
2149
2321
|
/**
|
|
2150
|
-
*
|
|
2151
|
-
*
|
|
2152
|
-
* `carryCreateFacts` supplies the create-time facts a refresh must keep:
|
|
2153
|
-
* the GPU lease, the startup diagnostics, and the create receipt each arrive
|
|
2154
|
-
* once on the create response and are absent from every later payload. They
|
|
2155
|
-
* describe ONE environment's creation, so they travel only when the payload
|
|
2156
|
-
* describes that same environment. A payload for a different sandbox — a
|
|
2157
|
-
* branch child parsed through its parent — passes no carry, or the child
|
|
2158
|
-
* would report its parent's create verdict.
|
|
2322
|
+
* Refresh a collaboration token for an existing document session.
|
|
2159
2323
|
*/
|
|
2160
|
-
private parseInfo;
|
|
2161
|
-
private sleep;
|
|
2162
2324
|
/**
|
|
2163
|
-
*
|
|
2164
|
-
*
|
|
2165
|
-
* Use {@link sessions} to discover existing session ids.
|
|
2325
|
+
* Refresh a collaboration token. Access level is preserved from the original
|
|
2326
|
+
* token — cannot be escalated (read stays read, write stays write).
|
|
2166
2327
|
*/
|
|
2167
|
-
|
|
2328
|
+
refreshCollaborationToken(documentId: string, currentToken: string): Promise<{
|
|
2329
|
+
token: string;
|
|
2330
|
+
expiresAt: number;
|
|
2331
|
+
access: "read" | "write";
|
|
2332
|
+
}>;
|
|
2168
2333
|
/**
|
|
2169
|
-
*
|
|
2170
|
-
*
|
|
2334
|
+
* Get SSH credentials for connecting to the sandbox.
|
|
2335
|
+
* Throws if SSH is not enabled or sandbox is not running.
|
|
2171
2336
|
*/
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2337
|
+
ssh(): Promise<SSHCredentials>;
|
|
2338
|
+
sshCommand(): Promise<SSHCommandDescriptor>;
|
|
2339
|
+
}
|
|
2340
|
+
//#endregion
|
|
2341
|
+
//#region src/trace-exporter.d.ts
|
|
2342
|
+
type JsonObject = {
|
|
2343
|
+
[key: string]: JsonValue;
|
|
2344
|
+
};
|
|
2345
|
+
type TraceExportFormat = "tangle" | "otel-json";
|
|
2346
|
+
type TraceExportBundle = SandboxTraceBundle | SandboxFleetTraceBundle;
|
|
2347
|
+
interface TraceExportSink {
|
|
2348
|
+
url: string;
|
|
2349
|
+
headers?: Record<string, string>;
|
|
2350
|
+
format?: TraceExportFormat;
|
|
2351
|
+
serviceName?: string;
|
|
2352
|
+
timeoutMs?: number;
|
|
2353
|
+
fetch?: typeof fetch;
|
|
2354
|
+
}
|
|
2355
|
+
interface TraceExportResult {
|
|
2356
|
+
status: number;
|
|
2357
|
+
ok: boolean;
|
|
2358
|
+
body: string;
|
|
2359
|
+
}
|
|
2360
|
+
declare function buildTraceExportPayload(bundle: TraceExportBundle, format?: TraceExportFormat, serviceName?: string): TraceExportBundle | JsonObject;
|
|
2361
|
+
declare function exportTraceBundle(bundle: TraceExportBundle, sink: TraceExportSink): Promise<TraceExportResult>;
|
|
2362
|
+
declare function toOtelJson(bundle: TraceExportBundle, serviceName?: string): JsonObject;
|
|
2363
|
+
declare function otelTraceIdForTangleTrace(traceId: string): string;
|
|
2364
|
+
//#endregion
|
|
2365
|
+
//#region src/sandbox-trace.d.ts
|
|
2366
|
+
declare abstract class SandboxTraceCapabilities extends SandboxAccessCapabilities {
|
|
2367
|
+
trace(options?: SandboxTraceOptions): Promise<SandboxTraceBundle>;
|
|
2368
|
+
intelligence(): Promise<NonNullable<SandboxTraceBundle["intelligence"]>>;
|
|
2369
|
+
createIntelligenceReport(options?: {
|
|
2370
|
+
mode?: "deterministic" | "agentic";
|
|
2371
|
+
acknowledgeCost?: boolean;
|
|
2372
|
+
budget?: IntelligenceReportBudget;
|
|
2373
|
+
metadata?: Record<string, unknown>; /** Bound the analysis to a time window. */
|
|
2374
|
+
window?: IntelligenceReportWindow; /** Compare this sandbox against a same-type baseline sandbox. */
|
|
2375
|
+
compareTo?: IntelligenceReportCompareTo;
|
|
2376
|
+
}): Promise<IntelligenceReport>;
|
|
2377
|
+
createAgenticIntelligenceReport(options: {
|
|
2378
|
+
maxUsd: number;
|
|
2379
|
+
metadata?: Record<string, unknown>;
|
|
2380
|
+
}): Promise<IntelligenceReport>;
|
|
2381
|
+
exportTrace(sink: TraceExportSink): Promise<TraceExportResult>;
|
|
2187
2382
|
/**
|
|
2188
|
-
*
|
|
2189
|
-
*
|
|
2190
|
-
*
|
|
2191
|
-
* session
|
|
2383
|
+
* Export the agent's conversation history from the sandbox filesystem.
|
|
2384
|
+
*
|
|
2385
|
+
* Each harness stores conversations in its own files:
|
|
2386
|
+
* Claude Code: ~/.claude/projects/<session-id>/ (JSONL)
|
|
2387
|
+
* Codex: ~/.codex/sessions/ (JSON)
|
|
2388
|
+
* OpenCode: ~/.local/share/opencode/storage/ (SQLite)
|
|
2389
|
+
*
|
|
2390
|
+
* This reads those files and returns them as a map of session-id to
|
|
2391
|
+
* conversation content, so the caller can persist them before deleting
|
|
2392
|
+
* the sandbox. Without this, conversation history dies with the sandbox.
|
|
2192
2393
|
*/
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2394
|
+
exportConversations(): Promise<Map<string, {
|
|
2395
|
+
format: string;
|
|
2396
|
+
content: string;
|
|
2196
2397
|
}>>;
|
|
2398
|
+
}
|
|
2399
|
+
//#endregion
|
|
2400
|
+
//#region src/sandbox-egress.d.ts
|
|
2401
|
+
declare abstract class SandboxEgressCapabilities extends SandboxTraceCapabilities {
|
|
2197
2402
|
/**
|
|
2198
|
-
*
|
|
2199
|
-
* #913 Gap 2). The sandbox keeps running the prompt after this call
|
|
2200
|
-
* returns; reconnect via `box.session(id).events()` or wait for
|
|
2201
|
-
* completion with `box.session(id).result()`.
|
|
2202
|
-
*
|
|
2203
|
-
* Skips the dispatch only on positive evidence that this work is
|
|
2204
|
-
* already in flight or already finished — never on the mere existence
|
|
2205
|
-
* of a session with the same id:
|
|
2403
|
+
* Egress policy manager for controlling outbound internet access.
|
|
2206
2404
|
*
|
|
2207
|
-
*
|
|
2208
|
-
*
|
|
2209
|
-
*
|
|
2210
|
-
*
|
|
2211
|
-
*
|
|
2212
|
-
* `latestExecutionId` — → a second dispatch would run two agents
|
|
2213
|
-
* against one session, so return the live status with
|
|
2214
|
-
* `dispatched: false`.
|
|
2405
|
+
* @example Read current egress policy
|
|
2406
|
+
* ```typescript
|
|
2407
|
+
* const { policy, source } = await box.egress.get();
|
|
2408
|
+
* console.log(policy.mode, source);
|
|
2409
|
+
* ```
|
|
2215
2410
|
*
|
|
2216
|
-
*
|
|
2411
|
+
* @example Update egress policy at runtime
|
|
2412
|
+
* ```typescript
|
|
2413
|
+
* // strict reaches these plus the sandbox's own model endpoint, nothing else.
|
|
2414
|
+
* await box.egress.update({ mode: "strict", allowDomains: ["api.github.com"] });
|
|
2415
|
+
* ```
|
|
2416
|
+
*/
|
|
2417
|
+
get egress(): EgressManager;
|
|
2418
|
+
}
|
|
2419
|
+
//#endregion
|
|
2420
|
+
//#region src/sandbox.d.ts
|
|
2421
|
+
/**
|
|
2422
|
+
* One fork of a running sandbox, reported with its fan-out accounting.
|
|
2423
|
+
*
|
|
2424
|
+
* `children` holds the sandboxes that exist. A partial fan-out is never
|
|
2425
|
+
* reported as a whole one: `complete` is false whenever `materializedCount` is
|
|
2426
|
+
* below `requestedCount`, and the caller decides what to do about the
|
|
2427
|
+
* shortfall.
|
|
2428
|
+
*/
|
|
2429
|
+
interface ForkAcknowledgement extends ForkCounts {
|
|
2430
|
+
children: SandboxInstance[];
|
|
2431
|
+
/** Present only for a keyed fork against an API that reports it. */
|
|
2432
|
+
idempotency?: ForkIdempotency;
|
|
2433
|
+
}
|
|
2434
|
+
/**
|
|
2435
|
+
* A sandbox instance with methods for interaction.
|
|
2436
|
+
*/
|
|
2437
|
+
declare class SandboxInstance extends SandboxEgressCapabilities {
|
|
2438
|
+
constructor(client: HttpClient, info: SandboxInfo, defaultRuntimeBackend?: BackendConfig);
|
|
2439
|
+
/**
|
|
2440
|
+
* Branch this RUNNING sandbox into `count` copy-on-write children
|
|
2441
|
+
* (Morph Infinibranch parity). Branch forks the live VM's memory into many
|
|
2442
|
+
* children at once via Firecracker UFFD copy-on-write: the children share the
|
|
2443
|
+
* parent's clean pages instead of each copying full guest memory. The parent
|
|
2444
|
+
* stays running.
|
|
2217
2445
|
*
|
|
2218
|
-
*
|
|
2219
|
-
*
|
|
2220
|
-
*
|
|
2221
|
-
* `latestExecutionId` at execution START. Refusing here would leave
|
|
2222
|
-
* a pre-created session permanently undispatchable.
|
|
2223
|
-
* - A terminal session is a finished conversation, and a new prompt
|
|
2224
|
-
* into it is a new turn, not a retry.
|
|
2446
|
+
* Returns only the children. A fan-out that materialized fewer than `count`
|
|
2447
|
+
* still resolves — the children are real — so compare the array length, or
|
|
2448
|
+
* call {@link fork} for the explicit `complete` flag.
|
|
2225
2449
|
*
|
|
2226
|
-
*
|
|
2227
|
-
*
|
|
2228
|
-
*
|
|
2450
|
+
* @param count - Number of children to create (must be >= 1).
|
|
2451
|
+
* @param options - Per-child overrides.
|
|
2452
|
+
* @returns The new sandbox instances that materialized.
|
|
2229
2453
|
*
|
|
2230
|
-
*
|
|
2231
|
-
*
|
|
2454
|
+
* @example
|
|
2455
|
+
* ```typescript
|
|
2456
|
+
* const [a, b, c] = await box.branch(3);
|
|
2457
|
+
* // a, b, c each share box's memory state at branch time
|
|
2458
|
+
* ```
|
|
2232
2459
|
*/
|
|
2233
|
-
|
|
2460
|
+
branch(count: number, options?: BranchOptions): Promise<SandboxInstance[]>;
|
|
2234
2461
|
/**
|
|
2235
|
-
*
|
|
2236
|
-
* the agent is still streaming. Each entry's `metadata` carries the
|
|
2237
|
-
* durability marker — `status: "streaming" | "completed" | "interrupted"`,
|
|
2238
|
-
* `completed/interrupted` booleans, and the caller-supplied `turnId`
|
|
2239
|
-
* when one was set. See `SessionMessage` for the full contract.
|
|
2462
|
+
* Branch this RUNNING sandbox and report the fan-out, not only the children.
|
|
2240
2463
|
*
|
|
2241
|
-
*
|
|
2242
|
-
*
|
|
2243
|
-
*
|
|
2244
|
-
*
|
|
2464
|
+
* `complete` is false when fewer children materialized than were requested,
|
|
2465
|
+
* so a partial fan-out is never read as a whole one. With an
|
|
2466
|
+
* `idempotencyKey`, a retry of the same key and options returns exactly the
|
|
2467
|
+
* children the first request materialized and creates none.
|
|
2468
|
+
*
|
|
2469
|
+
* @example
|
|
2470
|
+
* ```typescript
|
|
2471
|
+
* const forked = await box.fork(5, { idempotencyKey: "run-42" });
|
|
2472
|
+
* if (!forked.complete) {
|
|
2473
|
+
* console.warn(`${forked.materializedCount} of ${forked.requestedCount}`);
|
|
2474
|
+
* }
|
|
2475
|
+
* ```
|
|
2245
2476
|
*/
|
|
2246
|
-
|
|
2247
|
-
/** @internal — invoked by SandboxSession.sendMessage(). */
|
|
2248
|
-
_sessionSendMessage(id: string, request: SendSessionMessageRequest, options?: SendSessionMessageOptions): Promise<SentSessionMessage>;
|
|
2249
|
-
/** @internal — invoked by SandboxSession.delete(). */
|
|
2250
|
-
_sessionDelete(id: string): Promise<void>;
|
|
2251
|
-
/** @internal — invoked by SandboxTaskSession.changes(). */
|
|
2252
|
-
_taskSessionChanges(id: string): Promise<TaskSessionChanges>;
|
|
2253
|
-
/** @internal — invoked by SandboxTaskSession.commit(). */
|
|
2254
|
-
_taskSessionCommit(id: string, options?: CommitTaskSessionOptions): Promise<TaskSessionCommitResult>;
|
|
2255
|
-
_sessionFork(id: string, opts?: SessionForkOptions): Promise<SessionInfo>;
|
|
2477
|
+
fork(count: number, options?: BranchOptions): Promise<ForkAcknowledgement>;
|
|
2256
2478
|
/**
|
|
2257
|
-
*
|
|
2258
|
-
* payload if a turn with this `turnId` previously completed on the
|
|
2259
|
-
* given session; returns `null` if no such turn has finished yet
|
|
2260
|
-
* (either it never started, or it interrupted before completion).
|
|
2479
|
+
* Create an advanced direct-runtime view of this sandbox.
|
|
2261
2480
|
*
|
|
2262
|
-
*
|
|
2263
|
-
*
|
|
2264
|
-
*
|
|
2265
|
-
*
|
|
2266
|
-
* `completed` terminal state are cached; interrupted turns are not.
|
|
2481
|
+
* Runtime methods on the returned instance talk to the sandbox runtime
|
|
2482
|
+
* directly using `connection.execHost` when supplied, otherwise
|
|
2483
|
+
* `connection.runtimeUrl`, and the scoped `connection.authToken`.
|
|
2484
|
+
* Lifecycle methods still go through the parent SDK client.
|
|
2267
2485
|
*/
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2486
|
+
direct(): SandboxInstance;
|
|
2487
|
+
}
|
|
2488
|
+
//#endregion
|
|
2489
|
+
//#region ../../../packages/runtime-contracts/dist/tangle-blueprint-abi.d.ts
|
|
2490
|
+
/**
|
|
2491
|
+
* Tangle blueprint wire contract shared by the orchestrator's Tangle driver and
|
|
2492
|
+
* the published sandbox SDK's Tangle client: job indices and the ABI
|
|
2493
|
+
* definitions for encoding/decoding the AgentSandbox blueprint's job inputs
|
|
2494
|
+
* and outputs, plus its contract views/events.
|
|
2495
|
+
*/
|
|
2496
|
+
/** Job indices matching the blueprint's job IDs. */
|
|
2497
|
+
declare const JOB_SANDBOX_CREATE = 0;
|
|
2498
|
+
declare const JOB_SANDBOX_DELETE = 1;
|
|
2499
|
+
declare const SandboxCreateParamTypes: readonly [{
|
|
2500
|
+
readonly name: "request";
|
|
2501
|
+
readonly type: "tuple";
|
|
2502
|
+
readonly components: readonly [{
|
|
2503
|
+
readonly name: "name";
|
|
2504
|
+
readonly type: "string";
|
|
2505
|
+
}, {
|
|
2506
|
+
readonly name: "image";
|
|
2507
|
+
readonly type: "string";
|
|
2508
|
+
}, {
|
|
2509
|
+
readonly name: "stack";
|
|
2510
|
+
readonly type: "string";
|
|
2511
|
+
}, {
|
|
2512
|
+
readonly name: "agent_identifier";
|
|
2513
|
+
readonly type: "string";
|
|
2514
|
+
}, {
|
|
2515
|
+
readonly name: "env_json";
|
|
2516
|
+
readonly type: "string";
|
|
2517
|
+
}, {
|
|
2518
|
+
readonly name: "metadata_json";
|
|
2519
|
+
readonly type: "string";
|
|
2520
|
+
}, {
|
|
2521
|
+
readonly name: "ssh_enabled";
|
|
2522
|
+
readonly type: "bool";
|
|
2523
|
+
}, {
|
|
2524
|
+
readonly name: "ssh_public_key";
|
|
2525
|
+
readonly type: "string";
|
|
2526
|
+
}, {
|
|
2527
|
+
readonly name: "web_terminal_enabled";
|
|
2528
|
+
readonly type: "bool";
|
|
2529
|
+
}, {
|
|
2530
|
+
readonly name: "max_lifetime_seconds";
|
|
2531
|
+
readonly type: "uint64";
|
|
2532
|
+
}, {
|
|
2533
|
+
readonly name: "idle_timeout_seconds";
|
|
2534
|
+
readonly type: "uint64";
|
|
2535
|
+
}, {
|
|
2536
|
+
readonly name: "cpu_cores";
|
|
2537
|
+
readonly type: "uint64";
|
|
2538
|
+
}, {
|
|
2539
|
+
readonly name: "memory_mb";
|
|
2540
|
+
readonly type: "uint64";
|
|
2541
|
+
}, {
|
|
2542
|
+
readonly name: "disk_gb";
|
|
2543
|
+
readonly type: "uint64";
|
|
2544
|
+
}, {
|
|
2545
|
+
readonly name: "tee_required";
|
|
2546
|
+
readonly type: "bool";
|
|
2547
|
+
}, {
|
|
2548
|
+
readonly name: "tee_type";
|
|
2549
|
+
readonly type: "uint8";
|
|
2550
|
+
}, {
|
|
2551
|
+
readonly name: "attestation_nonce";
|
|
2552
|
+
readonly type: "string";
|
|
2553
|
+
}, {
|
|
2554
|
+
readonly name: "capabilities_json";
|
|
2555
|
+
readonly type: "string";
|
|
2556
|
+
}];
|
|
2557
|
+
}];
|
|
2558
|
+
declare const SandboxIdParamTypes: readonly [{
|
|
2559
|
+
readonly name: "request";
|
|
2560
|
+
readonly type: "tuple";
|
|
2561
|
+
readonly components: readonly [{
|
|
2562
|
+
readonly name: "sandbox_id";
|
|
2563
|
+
readonly type: "string";
|
|
2564
|
+
}];
|
|
2565
|
+
}];
|
|
2566
|
+
declare const SandboxCreateResponseParamTypes: readonly [{
|
|
2567
|
+
readonly name: "response";
|
|
2568
|
+
readonly type: "tuple";
|
|
2569
|
+
readonly components: readonly [{
|
|
2570
|
+
readonly name: "sandboxId";
|
|
2571
|
+
readonly type: "string";
|
|
2572
|
+
}, {
|
|
2573
|
+
readonly name: "json";
|
|
2574
|
+
readonly type: "string";
|
|
2575
|
+
}];
|
|
2576
|
+
}];
|
|
2577
|
+
declare const JsonResponseParamTypes: readonly [{
|
|
2578
|
+
readonly name: "response";
|
|
2579
|
+
readonly type: "tuple";
|
|
2580
|
+
readonly components: readonly [{
|
|
2581
|
+
readonly name: "json";
|
|
2582
|
+
readonly type: "string";
|
|
2583
|
+
}];
|
|
2584
|
+
}];
|
|
2585
|
+
declare const AgentSandboxBlueprintAbi: readonly [{
|
|
2586
|
+
readonly type: "function";
|
|
2587
|
+
readonly name: "getAvailableCapacity";
|
|
2588
|
+
readonly inputs: readonly [];
|
|
2589
|
+
readonly outputs: readonly [{
|
|
2590
|
+
readonly name: "available";
|
|
2591
|
+
readonly type: "uint32";
|
|
2592
|
+
}];
|
|
2593
|
+
readonly stateMutability: "view";
|
|
2594
|
+
}, {
|
|
2595
|
+
readonly type: "function";
|
|
2596
|
+
readonly name: "getServiceStats";
|
|
2597
|
+
readonly inputs: readonly [];
|
|
2598
|
+
readonly outputs: readonly [{
|
|
2599
|
+
readonly name: "totalSandboxes";
|
|
2600
|
+
readonly type: "uint32";
|
|
2601
|
+
}, {
|
|
2602
|
+
readonly name: "totalCapacity";
|
|
2603
|
+
readonly type: "uint32";
|
|
2604
|
+
}];
|
|
2605
|
+
readonly stateMutability: "view";
|
|
2606
|
+
}, {
|
|
2607
|
+
readonly type: "function";
|
|
2608
|
+
readonly name: "getOperatorLoad";
|
|
2609
|
+
readonly inputs: readonly [{
|
|
2610
|
+
readonly name: "operator";
|
|
2611
|
+
readonly type: "address";
|
|
2612
|
+
}];
|
|
2613
|
+
readonly outputs: readonly [{
|
|
2614
|
+
readonly name: "active";
|
|
2615
|
+
readonly type: "uint32";
|
|
2616
|
+
}, {
|
|
2617
|
+
readonly name: "max";
|
|
2618
|
+
readonly type: "uint32";
|
|
2619
|
+
}];
|
|
2620
|
+
readonly stateMutability: "view";
|
|
2621
|
+
}, {
|
|
2622
|
+
readonly type: "function";
|
|
2623
|
+
readonly name: "getSandboxOperator";
|
|
2624
|
+
readonly inputs: readonly [{
|
|
2625
|
+
readonly name: "sandboxId";
|
|
2626
|
+
readonly type: "string";
|
|
2627
|
+
}];
|
|
2628
|
+
readonly outputs: readonly [{
|
|
2629
|
+
readonly name: "";
|
|
2630
|
+
readonly type: "address";
|
|
2631
|
+
}];
|
|
2632
|
+
readonly stateMutability: "view";
|
|
2633
|
+
}, {
|
|
2634
|
+
readonly type: "function";
|
|
2635
|
+
readonly name: "isSandboxActive";
|
|
2636
|
+
readonly inputs: readonly [{
|
|
2637
|
+
readonly name: "sandboxId";
|
|
2638
|
+
readonly type: "string";
|
|
2639
|
+
}];
|
|
2640
|
+
readonly outputs: readonly [{
|
|
2641
|
+
readonly name: "";
|
|
2642
|
+
readonly type: "bool";
|
|
2643
|
+
}];
|
|
2644
|
+
readonly stateMutability: "view";
|
|
2645
|
+
}, {
|
|
2646
|
+
readonly type: "event";
|
|
2647
|
+
readonly name: "OperatorAssigned";
|
|
2648
|
+
readonly inputs: readonly [{
|
|
2649
|
+
readonly name: "serviceId";
|
|
2650
|
+
readonly type: "uint64";
|
|
2651
|
+
readonly indexed: true;
|
|
2652
|
+
}, {
|
|
2653
|
+
readonly name: "callId";
|
|
2654
|
+
readonly type: "uint64";
|
|
2655
|
+
readonly indexed: true;
|
|
2656
|
+
}, {
|
|
2657
|
+
readonly name: "operator";
|
|
2658
|
+
readonly type: "address";
|
|
2659
|
+
readonly indexed: true;
|
|
2660
|
+
}];
|
|
2661
|
+
}, {
|
|
2662
|
+
readonly type: "event";
|
|
2663
|
+
readonly name: "OperatorRouted";
|
|
2664
|
+
readonly inputs: readonly [{
|
|
2665
|
+
readonly name: "serviceId";
|
|
2666
|
+
readonly type: "uint64";
|
|
2667
|
+
readonly indexed: true;
|
|
2668
|
+
}, {
|
|
2669
|
+
readonly name: "callId";
|
|
2670
|
+
readonly type: "uint64";
|
|
2671
|
+
readonly indexed: true;
|
|
2672
|
+
}, {
|
|
2673
|
+
readonly name: "operator";
|
|
2674
|
+
readonly type: "address";
|
|
2675
|
+
readonly indexed: true;
|
|
2676
|
+
}];
|
|
2677
|
+
}, {
|
|
2678
|
+
readonly type: "event";
|
|
2679
|
+
readonly name: "SandboxCreated";
|
|
2680
|
+
readonly inputs: readonly [{
|
|
2681
|
+
readonly name: "sandboxHash";
|
|
2682
|
+
readonly type: "bytes32";
|
|
2683
|
+
readonly indexed: true;
|
|
2684
|
+
}, {
|
|
2685
|
+
readonly name: "operator";
|
|
2686
|
+
readonly type: "address";
|
|
2687
|
+
readonly indexed: true;
|
|
2688
|
+
}];
|
|
2689
|
+
}, {
|
|
2690
|
+
readonly type: "event";
|
|
2691
|
+
readonly name: "SandboxDeleted";
|
|
2692
|
+
readonly inputs: readonly [{
|
|
2693
|
+
readonly name: "sandboxHash";
|
|
2694
|
+
readonly type: "bytes32";
|
|
2695
|
+
readonly indexed: true;
|
|
2696
|
+
}, {
|
|
2697
|
+
readonly name: "operator";
|
|
2698
|
+
readonly type: "address";
|
|
2699
|
+
readonly indexed: true;
|
|
2700
|
+
}];
|
|
2701
|
+
}];
|
|
2702
|
+
//#endregion
|
|
2703
|
+
//#region src/tangle/abi.d.ts
|
|
2704
|
+
/**
|
|
2705
|
+
* Tangle Contract ABI Definitions
|
|
2706
|
+
*
|
|
2707
|
+
* Viem-compatible ABI for the ITangleJobs precompile.
|
|
2708
|
+
*/
|
|
2709
|
+
declare const ITangleJobsAbi: readonly [{
|
|
2710
|
+
readonly type: "function";
|
|
2711
|
+
readonly name: "submitJob";
|
|
2712
|
+
readonly inputs: readonly [{
|
|
2713
|
+
readonly name: "serviceId";
|
|
2714
|
+
readonly type: "uint64";
|
|
2715
|
+
}, {
|
|
2716
|
+
readonly name: "jobIndex";
|
|
2717
|
+
readonly type: "uint8";
|
|
2718
|
+
}, {
|
|
2719
|
+
readonly name: "inputs";
|
|
2720
|
+
readonly type: "bytes";
|
|
2721
|
+
}];
|
|
2722
|
+
readonly outputs: readonly [{
|
|
2723
|
+
readonly name: "callId";
|
|
2724
|
+
readonly type: "uint64";
|
|
2725
|
+
}];
|
|
2726
|
+
readonly stateMutability: "payable";
|
|
2727
|
+
}, {
|
|
2728
|
+
readonly type: "function";
|
|
2729
|
+
readonly name: "getJobCall";
|
|
2730
|
+
readonly inputs: readonly [{
|
|
2731
|
+
readonly name: "serviceId";
|
|
2732
|
+
readonly type: "uint64";
|
|
2733
|
+
}, {
|
|
2734
|
+
readonly name: "callId";
|
|
2735
|
+
readonly type: "uint64";
|
|
2736
|
+
}];
|
|
2737
|
+
readonly outputs: readonly [{
|
|
2738
|
+
readonly name: "";
|
|
2739
|
+
readonly type: "tuple";
|
|
2740
|
+
readonly components: readonly [{
|
|
2741
|
+
readonly name: "jobIndex";
|
|
2742
|
+
readonly type: "uint8";
|
|
2743
|
+
}, {
|
|
2744
|
+
readonly name: "caller";
|
|
2745
|
+
readonly type: "address";
|
|
2746
|
+
}, {
|
|
2747
|
+
readonly name: "createdAt";
|
|
2748
|
+
readonly type: "uint64";
|
|
2749
|
+
}, {
|
|
2750
|
+
readonly name: "resultCount";
|
|
2751
|
+
readonly type: "uint32";
|
|
2752
|
+
}, {
|
|
2753
|
+
readonly name: "payment";
|
|
2754
|
+
readonly type: "uint256";
|
|
2755
|
+
}, {
|
|
2756
|
+
readonly name: "completed";
|
|
2757
|
+
readonly type: "bool";
|
|
2758
|
+
}];
|
|
2759
|
+
}];
|
|
2760
|
+
readonly stateMutability: "view";
|
|
2761
|
+
}, {
|
|
2762
|
+
readonly type: "event";
|
|
2763
|
+
readonly name: "JobSubmitted";
|
|
2764
|
+
readonly inputs: readonly [{
|
|
2765
|
+
readonly name: "serviceId";
|
|
2766
|
+
readonly type: "uint64";
|
|
2767
|
+
readonly indexed: true;
|
|
2768
|
+
}, {
|
|
2769
|
+
readonly name: "callId";
|
|
2770
|
+
readonly type: "uint64";
|
|
2771
|
+
readonly indexed: true;
|
|
2772
|
+
}, {
|
|
2773
|
+
readonly name: "jobIndex";
|
|
2774
|
+
readonly type: "uint8";
|
|
2775
|
+
readonly indexed: false;
|
|
2776
|
+
}, {
|
|
2777
|
+
readonly name: "caller";
|
|
2778
|
+
readonly type: "address";
|
|
2779
|
+
readonly indexed: false;
|
|
2780
|
+
}, {
|
|
2781
|
+
readonly name: "inputs";
|
|
2782
|
+
readonly type: "bytes";
|
|
2783
|
+
readonly indexed: false;
|
|
2784
|
+
}];
|
|
2785
|
+
}, {
|
|
2786
|
+
readonly type: "event";
|
|
2787
|
+
readonly name: "JobResultSubmitted";
|
|
2788
|
+
readonly inputs: readonly [{
|
|
2789
|
+
readonly name: "serviceId";
|
|
2790
|
+
readonly type: "uint64";
|
|
2791
|
+
readonly indexed: true;
|
|
2792
|
+
}, {
|
|
2793
|
+
readonly name: "callId";
|
|
2794
|
+
readonly type: "uint64";
|
|
2795
|
+
readonly indexed: true;
|
|
2796
|
+
}, {
|
|
2797
|
+
readonly name: "operator";
|
|
2798
|
+
readonly type: "address";
|
|
2799
|
+
readonly indexed: true;
|
|
2800
|
+
}, {
|
|
2801
|
+
readonly name: "result";
|
|
2802
|
+
readonly type: "bytes";
|
|
2803
|
+
readonly indexed: false;
|
|
2804
|
+
}];
|
|
2805
|
+
}];
|
|
2806
|
+
//#endregion
|
|
2807
|
+
//#region src/tangle/types.d.ts
|
|
2808
|
+
/**
|
|
2809
|
+
* Tangle Sandbox Client types and constants.
|
|
2810
|
+
*/
|
|
2811
|
+
/** Tangle mainnet chain ID. */
|
|
2812
|
+
declare const TANGLE_CHAIN_ID = 5845;
|
|
2813
|
+
/** ITangleJobs precompile contract address. */
|
|
2814
|
+
declare const TANGLE_JOBS_CONTRACT: "0x0000000000000000000000000000000000000808";
|
|
2815
|
+
interface TangleSandboxClientConfig {
|
|
2816
|
+
/** Tangle service instance ID for the sandbox blueprint. */
|
|
2817
|
+
serviceId: bigint;
|
|
2818
|
+
/** viem WalletClient for browser environments. Mutually exclusive with privateKey. */
|
|
2819
|
+
wallet?: unknown;
|
|
2820
|
+
/** Hex-encoded private key for Node.js environments. Mutually exclusive with wallet. */
|
|
2821
|
+
privateKey?: `0x${string}`;
|
|
2822
|
+
/**
|
|
2823
|
+
* HTTP JSON-RPC endpoint for the Tangle chain. Required for both the
|
|
2824
|
+
* privateKey and wallet paths: the SDK ships no default endpoint because the
|
|
2825
|
+
* legacy public host was retired.
|
|
2826
|
+
*/
|
|
2827
|
+
rpcUrl: string;
|
|
2828
|
+
/** Blueprint contract address for view calls (getAvailableCapacity, etc). */
|
|
2829
|
+
blueprintContractAddress?: `0x${string}`;
|
|
2830
|
+
/** ITangleJobs precompile address. Defaults to 0x...0808. */
|
|
2831
|
+
contractAddress?: `0x${string}`;
|
|
2832
|
+
/** Max time to wait for a job to complete. No hard limit — agent jobs can run hours. Default: 14400000 (4h). */
|
|
2833
|
+
jobTimeoutMs?: number;
|
|
2834
|
+
/** Interval between job completion polls. Default: 5000 (5s). */
|
|
2835
|
+
pollIntervalMs?: number;
|
|
2836
|
+
/**
|
|
2837
|
+
* Operator API base URL for routes that must be handled by the Blueprint
|
|
2838
|
+
* operator rather than the sidecar directly, such as nonce-bound TEE
|
|
2839
|
+
* attestation.
|
|
2840
|
+
*/
|
|
2841
|
+
operatorApiUrl?: string;
|
|
2842
|
+
/** Bearer token for the operator API session. */
|
|
2843
|
+
operatorApiToken?: string;
|
|
2844
|
+
}
|
|
2845
|
+
//#endregion
|
|
2846
|
+
//#region src/tangle/client.d.ts
|
|
2847
|
+
declare class TangleSandboxClient implements HttpClient {
|
|
2848
|
+
#private;
|
|
2849
|
+
private readonly chain;
|
|
2850
|
+
private readonly operatorApiUrl?;
|
|
2851
|
+
private operatorSession;
|
|
2852
|
+
constructor(config: TangleSandboxClientConfig);
|
|
2271
2853
|
/**
|
|
2272
|
-
*
|
|
2273
|
-
* pass and report where it stands. Built for tick-based callers —
|
|
2274
|
-
* Cloudflare Workflows steps, queue consumers, crons — that re-invoke
|
|
2275
|
-
* on their own schedule instead of holding a stream open.
|
|
2276
|
-
* The pass does not poll repeatedly or keep a connection alive.
|
|
2277
|
-
* Session admission may retry one classified pre-dispatch credential refusal.
|
|
2854
|
+
* Create a sandbox via on-chain job submission.
|
|
2278
2855
|
*
|
|
2279
|
-
*
|
|
2280
|
-
*
|
|
2281
|
-
*
|
|
2282
|
-
*
|
|
2283
|
-
*
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
*
|
|
2288
|
-
*
|
|
2289
|
-
|
|
2290
|
-
|
|
2856
|
+
* Secrets never ride the chain: `options.tangleSecrets` is delivered to the
|
|
2857
|
+
* operator's 2-phase provisioning endpoint over an EIP-191-authenticated
|
|
2858
|
+
* session after the job completes (requires `operatorApiUrl`). Everything
|
|
2859
|
+
* in `options.env` IS published on-chain in the job calldata — secret-shaped
|
|
2860
|
+
* keys there trigger a warning pointing at `tangleSecrets`.
|
|
2861
|
+
*/
|
|
2862
|
+
create(options?: CreateSandboxOptions): Promise<SandboxInstance>;
|
|
2863
|
+
/**
|
|
2864
|
+
* Get a sandbox by id. Rehydrates from the operator API when configured so
|
|
2865
|
+
* app servers can resolve sandboxes created by earlier requests.
|
|
2866
|
+
*/
|
|
2867
|
+
get(id: string): Promise<SandboxInstance | null>;
|
|
2868
|
+
/**
|
|
2869
|
+
* Route interception for SandboxInstance lifecycle calls.
|
|
2291
2870
|
*
|
|
2292
|
-
*
|
|
2293
|
-
*
|
|
2294
|
-
*
|
|
2871
|
+
* SandboxInstance calls this.client.fetch() for:
|
|
2872
|
+
* - GET /v1/sandboxes/:id → return from local tracking
|
|
2873
|
+
* - POST /v1/sandboxes/:id/stop → unsupported until blueprint exposes stop
|
|
2874
|
+
* - POST /v1/sandboxes/:id/resume → unsupported until blueprint exposes resume
|
|
2875
|
+
* - DELETE /v1/sandboxes/:id → on-chain JOB_SANDBOX_DELETE
|
|
2295
2876
|
*/
|
|
2296
|
-
|
|
2877
|
+
fetch(path: string, options?: RequestInit): Promise<Response>;
|
|
2878
|
+
private fetchRuntime;
|
|
2297
2879
|
/**
|
|
2298
|
-
*
|
|
2299
|
-
*
|
|
2880
|
+
* Get available capacity from the blueprint contract.
|
|
2881
|
+
* Requires blueprintContractAddress in config.
|
|
2300
2882
|
*/
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
materializedDigest: `sha256:${string}`;
|
|
2310
|
-
launchDigest: string;
|
|
2311
|
-
};
|
|
2312
|
-
conflicts: PublicProfileConflict[];
|
|
2883
|
+
getAvailableCapacity(): Promise<number>;
|
|
2884
|
+
/**
|
|
2885
|
+
* Get service stats from the blueprint contract.
|
|
2886
|
+
* Requires blueprintContractAddress in config.
|
|
2887
|
+
*/
|
|
2888
|
+
getServiceStats(): Promise<{
|
|
2889
|
+
totalSandboxes: number;
|
|
2890
|
+
totalCapacity: number;
|
|
2313
2891
|
}>;
|
|
2314
|
-
/**
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2892
|
+
/**
|
|
2893
|
+
* Mint or reuse the EIP-191 session for the operator API.
|
|
2894
|
+
*
|
|
2895
|
+
* The session is signed by the SAME key that submits jobs (`chain.signMessage`),
|
|
2896
|
+
* so the operator binds it to every sandbox this client created.
|
|
2897
|
+
*/
|
|
2898
|
+
private getOperatorSession;
|
|
2899
|
+
/**
|
|
2900
|
+
* Deliver secrets to a sandbox via the operator's 2-phase provisioning
|
|
2901
|
+
* endpoint (`POST /api/sandboxes/:id/secrets`).
|
|
2902
|
+
*
|
|
2903
|
+
* Unlike `env`, these values never appear on-chain: they ride TLS to the
|
|
2904
|
+
* operator, which validates the session's recovered address against the
|
|
2905
|
+
* sandbox's on-chain creator before injecting.
|
|
2906
|
+
*/
|
|
2907
|
+
injectSecrets(sandboxId: string, secrets: Record<string, string>): Promise<void>;
|
|
2908
|
+
/** Read a sandbox's provisioned secret keys and credential availability. */
|
|
2909
|
+
getSecrets(sandboxId: string): Promise<{
|
|
2910
|
+
sandboxId: string;
|
|
2911
|
+
envJson: Record<string, unknown>;
|
|
2912
|
+
credentialsAvailable: boolean;
|
|
2328
2913
|
}>;
|
|
2329
|
-
/** Advance exactly the named turn while retaining the native conversation.
|
|
2330
|
-
* Admission receipts are independent of expiring event logs. A previous
|
|
2331
|
-
* turn's terminal session status cannot settle a newly submitted message. */
|
|
2332
|
-
driveConversationTurn(message: string | PromptInputPart[], opts: ConversationTurnOptions): Promise<ConversationTurnResult>;
|
|
2333
|
-
private driveConversationTurnPass;
|
|
2334
2914
|
/**
|
|
2335
|
-
*
|
|
2336
|
-
*
|
|
2337
|
-
*
|
|
2338
|
-
* while session-runtime/read-only scopes work with SandboxRuntimeClient.
|
|
2915
|
+
* Run an operator-API request with a session, retrying once with a fresh
|
|
2916
|
+
* session on 401 (expired PASETO). Any other failure names the sandbox so
|
|
2917
|
+
* the caller can retry without losing the ID.
|
|
2339
2918
|
*/
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2919
|
+
private withOperatorSession;
|
|
2920
|
+
private fetchOperatorApi;
|
|
2921
|
+
}
|
|
2922
|
+
//#endregion
|
|
2923
|
+
//#region src/tangle/operator-auth.d.ts
|
|
2924
|
+
/**
|
|
2925
|
+
* Operator API session auth — the client half of the operator's EIP-191
|
|
2926
|
+
* challenge-response flow (`sandbox-runtime/src/session_auth`).
|
|
2927
|
+
*
|
|
2928
|
+
* Flow (matches the operator exactly):
|
|
2929
|
+
* 1. `POST /api/auth/challenge` → `{ nonce, message, expires_at }`
|
|
2930
|
+
* 2. Sign `message` with the job submitter's key (EIP-191 personal_sign,
|
|
2931
|
+
* 65-byte `r ‖ s ‖ v`)
|
|
2932
|
+
* 3. `POST /api/auth/session` `{ nonce, signature }` →
|
|
2933
|
+
* `{ token, address, expires_at }` (PASETO bearer, 1h)
|
|
2934
|
+
* 4. `Authorization: Bearer <token>`
|
|
2935
|
+
*
|
|
2936
|
+
* The operator recovers the signer address from the signature and binds every
|
|
2937
|
+
* sandbox operation to it: `require_sandbox_owner` rejects any session whose
|
|
2938
|
+
* address is not the sandbox's on-chain creator. So a session minted from the
|
|
2939
|
+
* same key that submitted the create job can read/inject that sandbox's
|
|
2940
|
+
* secrets — and nothing else.
|
|
2941
|
+
*/
|
|
2942
|
+
/** Challenge payload served by `POST /api/auth/challenge`. */
|
|
2943
|
+
interface OperatorChallenge {
|
|
2944
|
+
nonce: string;
|
|
2945
|
+
message: string;
|
|
2946
|
+
expires_at: number;
|
|
2947
|
+
}
|
|
2948
|
+
/** Session payload served by `POST /api/auth/session`. */
|
|
2949
|
+
interface OperatorSessionToken {
|
|
2950
|
+
token: string;
|
|
2951
|
+
address: string;
|
|
2952
|
+
expires_at: number;
|
|
2953
|
+
}
|
|
2954
|
+
/** Signs an arbitrary message with EIP-191 personal_sign semantics. */
|
|
2955
|
+
type SignMessage = (message: string) => Promise<`0x${string}`>;
|
|
2956
|
+
declare class OperatorSessionError extends Error {
|
|
2957
|
+
readonly status?: number | undefined;
|
|
2958
|
+
constructor(message: string, status?: number | undefined);
|
|
2959
|
+
}
|
|
2960
|
+
/**
|
|
2961
|
+
* A bearer session with the blueprint operator API, minted by proving control
|
|
2962
|
+
* of the job submitter's key. Establish lazily and reuse until near expiry;
|
|
2963
|
+
* the caller retries with a fresh session on 401.
|
|
2964
|
+
*/
|
|
2965
|
+
declare class OperatorSession {
|
|
2966
|
+
#private;
|
|
2967
|
+
private readonly address;
|
|
2968
|
+
private readonly expiresAtMs;
|
|
2969
|
+
private constructor();
|
|
2970
|
+
get signerAddress(): string;
|
|
2971
|
+
/** True when the token is within the refresh margin of expiry. */
|
|
2972
|
+
needsRefresh(nowMs?: number): boolean;
|
|
2973
|
+
authorizationHeader(): string;
|
|
2345
2974
|
/**
|
|
2346
|
-
*
|
|
2347
|
-
* directory: each runtime HOME's Claude Code, Codex, OpenCode and other
|
|
2348
|
-
* harness stores (transcripts and SQLite databases), and every settled
|
|
2349
|
-
* copy. The box-level twin of `box.session(id).exportRawEvidence`, for a
|
|
2350
|
-
* box about to be deleted, including one restored from a snapshot whose
|
|
2351
|
-
* session listing is empty. Only files a harness contract declares as its
|
|
2352
|
-
* session store are read; credentials and config never leave the box.
|
|
2975
|
+
* Run the challenge-response flow against an operator API base URL.
|
|
2353
2976
|
*
|
|
2354
|
-
*
|
|
2355
|
-
*
|
|
2977
|
+
* `signMessage` must implement EIP-191 personal_sign with the SAME key that
|
|
2978
|
+
* submitted the sandbox create job — the operator binds ownership to the
|
|
2979
|
+
* recovered address, so any other key yields a session that owns nothing.
|
|
2356
2980
|
*/
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
/**
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
_stopInteractiveLifecycle(id: string, ref: AgentInteractiveSessionRef, options?: InteractiveRequestOptions): Promise<AgentInteractiveSessionStopAcknowledgement>;
|
|
2393
|
-
private interactionTransport;
|
|
2394
|
-
/** @internal — invoked by SandboxSession.interactions(). */
|
|
2395
|
-
_listInteractions(id: string, options?: {
|
|
2396
|
-
signal?: AbortSignal;
|
|
2397
|
-
}): Promise<InteractionRequest[]>;
|
|
2398
|
-
/** @internal — invoked by SandboxSession.respondToInteraction(). */
|
|
2399
|
-
_respondToInteraction(id: string, command: InteractionResponseCommand, options?: {
|
|
2400
|
-
signal?: AbortSignal;
|
|
2401
|
-
}): Promise<SandboxInteractionCommandResult>;
|
|
2402
|
-
/** @internal — invoked by SandboxSession.respondToPermission(). */
|
|
2403
|
-
_respondToPermission(id: string, permissionID: string, options: RespondToPermissionOptions): Promise<SandboxInteractionResult>;
|
|
2404
|
-
/** @internal — invoked by SandboxSession.interrupt(). */
|
|
2405
|
-
_interrupt(id: string, options?: SessionInterruptOptions): Promise<InterruptResult>;
|
|
2406
|
-
/** @internal — invoked by SandboxSession.cancelRun(). */
|
|
2407
|
-
_cancelRun(id: string, request: AgentRunCancellationRequest, options?: {
|
|
2408
|
-
signal?: AbortSignal;
|
|
2409
|
-
}): Promise<AgentRunCancellationAcknowledgement>;
|
|
2410
|
-
/** @internal — invoked by SandboxSession.answer(). */
|
|
2411
|
-
_answerQuestion(id: string, interactionId: string, answers: InteractionData, options?: {
|
|
2412
|
-
signal?: AbortSignal;
|
|
2413
|
-
}): Promise<SandboxInteractionResult>;
|
|
2414
|
-
/** @internal — invoked by SandboxSession.plan(). */
|
|
2415
|
-
_currentPlan(sessionId: string): Promise<DurablePlan | null>;
|
|
2416
|
-
/** @internal — invoked by SandboxSession.approvePlan()/rejectPlan(). */
|
|
2417
|
-
_decidePlan(sessionId: string, planId: string, decision: {
|
|
2418
|
-
outcome: "approved";
|
|
2419
|
-
} | {
|
|
2420
|
-
outcome: "rejected";
|
|
2421
|
-
feedback: string;
|
|
2422
|
-
}, options?: DurablePlanDecisionOptions): Promise<DurablePlanDecisionResult>;
|
|
2981
|
+
static establish(baseUrl: string, signMessage: SignMessage, fetchImpl?: typeof fetch): Promise<OperatorSession>;
|
|
2982
|
+
}
|
|
2983
|
+
//#endregion
|
|
2984
|
+
//#region src/tangle/rfq.d.ts
|
|
2985
|
+
/**
|
|
2986
|
+
* RFQ quote primitives for tnt-core's `JobsRFQ` marketplace flow.
|
|
2987
|
+
*
|
|
2988
|
+
* These helpers fetch, hash, and validate operator quotes. Callers remain
|
|
2989
|
+
* responsible for preparing and submitting on-chain transactions.
|
|
2990
|
+
*
|
|
2991
|
+
* The EIP-712 hashing here is pinned byte-for-byte against the Rust SDK
|
|
2992
|
+
* (blueprint `tangle-extra::job_quote`, digest fixture in
|
|
2993
|
+
* `tangle-rfq.test.ts`) and against `SignatureLib` in tnt-core. Never change
|
|
2994
|
+
* the typed-data shape without regenerating all three.
|
|
2995
|
+
*/
|
|
2996
|
+
type Address = `0x${string}`;
|
|
2997
|
+
type Hash = `0x${string}`;
|
|
2998
|
+
/** EIP-712 domain — identical to tnt-core `Base.sol`: name "TangleQuote", version "1". */
|
|
2999
|
+
interface QuoteDomain {
|
|
3000
|
+
chainId: number;
|
|
3001
|
+
verifyingContract: Address;
|
|
3002
|
+
}
|
|
3003
|
+
/** Mirrors `JobQuoteDetails` in tnt-core `SignatureLib` (field-for-field). */
|
|
3004
|
+
interface JobQuoteDetails {
|
|
3005
|
+
requester: Address;
|
|
3006
|
+
serviceId: bigint;
|
|
3007
|
+
jobIndex: number;
|
|
3008
|
+
/** Price in the chain native unit's smallest denomination; wire values use
|
|
3009
|
+
* decimal strings to survive JSON transport without precision loss. */
|
|
3010
|
+
price: bigint;
|
|
3011
|
+
timestamp: bigint;
|
|
3012
|
+
expiry: bigint;
|
|
3013
|
+
/** tnt-core `ConfidentialityPolicy`: 0 Any, 1 TEE required, 2 Standard required, 3 TEE preferred. */
|
|
3014
|
+
confidentiality: 0 | 1 | 2 | 3;
|
|
3015
|
+
inputsHash: Hash;
|
|
2423
3016
|
}
|
|
3017
|
+
/** A signed quote as served by the operator's `/api/quote`. */
|
|
3018
|
+
interface SignedQuote {
|
|
3019
|
+
details: JobQuoteDetails;
|
|
3020
|
+
/** 65-byte `r ‖ s ‖ v` hex — exactly what `submitJobFromQuote` expects. */
|
|
3021
|
+
signature: `0x${string}`;
|
|
3022
|
+
operator: Address;
|
|
3023
|
+
/** Operator-reported live capacity at quote time (informational). */
|
|
3024
|
+
capacity?: {
|
|
3025
|
+
active: number;
|
|
3026
|
+
max: number;
|
|
3027
|
+
};
|
|
3028
|
+
}
|
|
3029
|
+
declare class QuoteError extends Error {
|
|
3030
|
+
readonly code: "QUOTE_REJECTED" | "QUOTE_SIGNATURE_INVALID" | "QUOTE_EXPIRED" | "QUOTE_MISMATCH";
|
|
3031
|
+
constructor(message: string, code: "QUOTE_REJECTED" | "QUOTE_SIGNATURE_INVALID" | "QUOTE_EXPIRED" | "QUOTE_MISMATCH");
|
|
3032
|
+
}
|
|
3033
|
+
/**
|
|
3034
|
+
* The EIP-712 digest of a quote — matches
|
|
3035
|
+
* `job_quote_digest_eip712` (Rust SDK) and `computeJobQuoteDigest` (tnt-core).
|
|
3036
|
+
*/
|
|
3037
|
+
declare function jobQuoteDigest(details: JobQuoteDetails, domain: QuoteDomain): Hash;
|
|
3038
|
+
/** Parse the operator's `/api/quote` JSON without fabricating missing values. */
|
|
3039
|
+
declare function parseQuoteResponse(raw: Record<string, unknown>): SignedQuote;
|
|
3040
|
+
/** keccak256 of the exact ABI-encoded job inputs — what quotes bind to. */
|
|
3041
|
+
declare function inputsHashOf(encodedInputs: `0x${string}`): Hash;
|
|
3042
|
+
/**
|
|
3043
|
+
* Validate a quote before paying for it: fresh (not expired), addressed to
|
|
3044
|
+
* the buyer, for the exact inputs about to be submitted, on the expected
|
|
3045
|
+
* service/job, and signed by the operator it names.
|
|
3046
|
+
*
|
|
3047
|
+
* Signature verification uses viem's offline EOA recovery and compares the
|
|
3048
|
+
* signer against the same digest the chain checks.
|
|
3049
|
+
*/
|
|
3050
|
+
declare function validateQuote(args: {
|
|
3051
|
+
quote: SignedQuote;
|
|
3052
|
+
domain: QuoteDomain; /** The buyer's address — must equal `details.requester`. */
|
|
3053
|
+
buyer: Address;
|
|
3054
|
+
serviceId: bigint;
|
|
3055
|
+
jobIndex: number;
|
|
3056
|
+
inputsHash: Hash;
|
|
3057
|
+
now?: number;
|
|
3058
|
+
}): Promise<void>;
|
|
3059
|
+
/** Query one operator for a quote over HTTP. */
|
|
3060
|
+
declare function fetchQuote(operatorApiUrl: string, params: {
|
|
3061
|
+
requester: Address;
|
|
3062
|
+
jobIndex: number; /** 0x-hex ABI-encoded job inputs, or a precomputed keccak256 hash. */
|
|
3063
|
+
inputs?: `0x${string}`;
|
|
3064
|
+
inputsHash?: Hash;
|
|
3065
|
+
confidentiality?: JobQuoteDetails["confidentiality"];
|
|
3066
|
+
fetchImpl?: typeof fetch;
|
|
3067
|
+
}): Promise<SignedQuote>;
|
|
2424
3068
|
//#endregion
|
|
2425
|
-
export {
|
|
3069
|
+
export { SandboxInteractionResult as $, TraceExportResult as A, buildControlPlaneMcpConfig as At, WorkspaceImages as B, JsonResponseParamTypes as C, BuildControlPlaneMcpConfigOptions as Ct, ForkAcknowledgement as D, SandboxMcpConfig as Dt, SandboxIdParamTypes as E, SANDBOX_MCP_SERVER_NAME as Et, toOtelJson as F, SplitInlineProfileFileMountsResult as G, MaterializeProfileFileMountsOptions as H, SandboxTaskSession as I, splitInlineProfileSkills as J, SplitInlineProfileSkillsResult as K, RawEvidenceExport as L, buildTraceExportPayload as M, exportTraceBundle as N, SandboxInstance as O, SandboxMcpEndpoint as Ot, otelTraceIdForTangleTrace as P, SandboxInteractionResolution as Q, SandboxSession as R, JOB_SANDBOX_DELETE as S, SandboxOperationFailedError as St, SandboxCreateResponseParamTypes as T, CONTROL_PLANE_MCP_SERVER_NAME as Tt, MaterializeProfileFileMountsResult as U, ProfileFileDeliveryReport as V, ProfileFileMountBox as W, SandboxInteractionCommandResult as X, validateDeferredProfileFileMounts as Y, SandboxInteractionConflict as Z, TANGLE_JOBS_CONTRACT as _, InteractiveTerminalFrameLog as _t, fetchQuote as a, InteractiveSessionHandleOptions as at, AgentSandboxBlueprintAbi as b, createInteractiveTerminalSession as bt, parseQuoteResponse as c, InteractiveSessionInfo as ct, OperatorSession as d, InteractiveSessionStartResult as dt, AgentInteractiveTerminalSession$1 as et, OperatorSessionError as f, InteractiveStopCommand as ft, TANGLE_CHAIN_ID as g, InteractiveTerminalCapture as gt, TangleSandboxClient as h, agentInteractiveSessionPromptRequestDigest as ht, SignedQuote as i, InteractiveSessionHandle as it, TraceExportSink as j, buildSandboxMcpConfig as jt, TraceExportFormat as k, SandboxMcpServerEntry as kt, validateQuote as l, InteractiveSessionRef as lt, SignMessage as m, RespondToPermissionOptions as mt, QuoteDomain as n, InteractivePromptCommand as nt, inputsHashOf as o, InteractiveSessionHost as ot, OperatorSessionToken as p, InterruptResult as pt, splitInlineProfileFileMounts as q, QuoteError as r, InteractiveSessionControlClaim as rt, jobQuoteDigest as s, InteractiveSessionIncarnationId as st, JobQuoteDetails as t, InteractiveControlClaimRequest as tt, OperatorChallenge as u, InteractiveSessionStartOptions as ut, TangleSandboxClientConfig as v, InteractiveTerminalMetadata as vt, SandboxCreateParamTypes as w, BuildSandboxMcpConfigOptions as wt, JOB_SANDBOX_CREATE as x, SandboxOperation as xt, ITangleJobsAbi as y, createInteractiveTerminalCapture as yt, WorkspaceImagePublishRequestOptions as z };
|