@tangle-network/sandbox 0.45.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/dist/agent/index.d.ts +6 -6
- package/dist/agent/index.js +37 -10
- package/dist/{agent-run-outcome-BpQhOdXp.d.ts → agent-run-outcome-CDpN0lAh.d.ts} +1 -1
- package/dist/{client-C_mFKZwS.d.ts → client-BVnci7-6.d.ts} +51 -2
- package/dist/{client-C2AGfwGT.js → client-DWX9LVU8.js} +177 -7
- package/dist/core.d.ts +12 -4
- package/dist/core.js +10 -3
- package/dist/{index-DT_pNtbV.d.ts → index-ByUvixzl.d.ts} +2 -2
- package/dist/index.d.ts +40 -31
- package/dist/index.js +45 -30
- package/dist/{runtime-api-C10Hg1OF.js → runtime-api-D7CdKcbu.js} +120 -28
- package/dist/runtime.d.ts +11 -10
- package/dist/runtime.js +1 -1
- package/dist/{sandbox-CQ2YTLtO.d.ts → sandbox-CpCVgm4V.d.ts} +54 -1
- package/dist/{sandbox-9IUdHeyj.js → sandbox-f9NE1NPU.js} +379 -85
- package/dist/tangle/index.d.ts +1 -1
- package/dist/tangle/index.js +1 -1
- package/dist/{tangle-B-w03_fQ.js → tangle-CBTGyeMO.js} +1 -1
- package/dist/{types-B3C-MizG.d.ts → types-CDksqyD4.d.ts} +167 -3
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -33,6 +33,9 @@ export SANDBOX_BASE_URL=https://sandbox.tangle.tools
|
|
|
33
33
|
| Browser-safe trace reads from Tangle Intelligence | `@tangle-network/sandbox/intelligence` |
|
|
34
34
|
|
|
35
35
|
Install an optional peer dependency only when the selected integration requires it.
|
|
36
|
+
The AI SDK tool pack supports the declared AI 6 and AI 7 peer ranges.
|
|
37
|
+
The Mastra tool pack validates arguments before it calls a Sandbox operation.
|
|
38
|
+
Both tool packs pass the selected session to operations that support sessions.
|
|
36
39
|
|
|
37
40
|
## Credential boundary
|
|
38
41
|
|
|
@@ -108,6 +111,28 @@ Keep `delete()` in `finally` unless the sandbox must outlive the process.
|
|
|
108
111
|
The sandbox is already gone for every read at that point.
|
|
109
112
|
Pass `await box.delete({ until: "removed" })` when you need the reclaim itself, for example before reusing the same host capacity in a test; it reports `removal: "complete"`, or `"pending"` if the wait runs out.
|
|
110
113
|
|
|
114
|
+
To remove every sandbox that one job created, tag them with metadata at create time and delete them by prefix:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
const result = await client.deleteMatching({
|
|
118
|
+
metadataPrefix: { retainedIdempotencyKey: `runtime:${runId}:` },
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`deleteMatching()` deletes only your own sandboxes, each through the same delete as `box.delete()`.
|
|
123
|
+
`result.complete` is `true` only when every match is confirmed gone.
|
|
124
|
+
`result.sandboxes` reports each sandbox as `destroyed`, `already_absent` or `failed`, with the refusal's `status` and `code`.
|
|
125
|
+
One call attempts every match once, so a refused delete does not hold back the others.
|
|
126
|
+
The call is safe to repeat; a confirmed sandbox no longer matches.
|
|
127
|
+
|
|
128
|
+
Stop creating the job's sandboxes before you call `deleteMatching()`.
|
|
129
|
+
`result.complete` covers only the sandboxes the call listed.
|
|
130
|
+
A create that registers after the listing, or retries with the same idempotency key, can leave a match behind, so call again once in-flight creates have settled.
|
|
131
|
+
|
|
132
|
+
With `{ until: "removed" }`, a destroyed sandbox counts as confirmed only when its removal is proven.
|
|
133
|
+
If the removal wait runs out, the sandbox reports `removal: "pending"` and `confirmed: false`, and `result.complete` is `false`.
|
|
134
|
+
That sandbox is already gone for every read, so a later call does not list it again.
|
|
135
|
+
|
|
111
136
|
## Create a sandbox
|
|
112
137
|
|
|
113
138
|
`client.create()` accepts a named environment, container image, or published image ID.
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { g as SandboxSession, h as SandboxTaskSession, r as SandboxInstance } from "../sandbox-
|
|
2
|
-
import { D as CodeExecutionResult, E as CodeExecutionOptions,
|
|
3
|
-
import { i as Sandbox } from "../client-
|
|
1
|
+
import { g as SandboxSession, h as SandboxTaskSession, r as SandboxInstance } from "../sandbox-CpCVgm4V.js";
|
|
2
|
+
import { D as CodeExecutionResult, E as CodeExecutionOptions, Mi as SessionInfo, O as CodeLanguage, Pi as SessionListOptions, d as BackendConfig, k as CodeResultPart } from "../types-CDksqyD4.js";
|
|
3
|
+
import { i as Sandbox } from "../client-BVnci7-6.js";
|
|
4
4
|
import * as _$_modelcontextprotocol_sdk_server_index_js0 from "@modelcontextprotocol/sdk/server/index.js";
|
|
5
|
+
import { JSONSchema } from "zod/v4/core";
|
|
5
6
|
|
|
6
7
|
//#region src/agent/instances.d.ts
|
|
7
8
|
/**
|
|
@@ -97,7 +98,7 @@ declare module "../sandbox.js" {
|
|
|
97
98
|
/** JSON-schema-ish object describing tool inputs. Plain object literal — no Zod required. */
|
|
98
99
|
type ToolJSONSchema = {
|
|
99
100
|
type: "object";
|
|
100
|
-
properties: Record<string,
|
|
101
|
+
properties: Record<string, JSONSchema.JSONSchema>;
|
|
101
102
|
required?: string[];
|
|
102
103
|
additionalProperties?: boolean;
|
|
103
104
|
};
|
|
@@ -502,7 +503,6 @@ interface MastraToolPackOptions {
|
|
|
502
503
|
allow?: ToolName[];
|
|
503
504
|
sessionId?: string;
|
|
504
505
|
}
|
|
505
|
-
type AnyTool$1 = unknown;
|
|
506
506
|
/**
|
|
507
507
|
* Build a Mastra tool pack bound to one sandbox.
|
|
508
508
|
*
|
|
@@ -516,7 +516,7 @@ type AnyTool$1 = unknown;
|
|
|
516
516
|
* await agent.generate("Plot sin(x).");
|
|
517
517
|
* ```
|
|
518
518
|
*/
|
|
519
|
-
declare function mastraTools(box: SandboxInstance, options?: MastraToolPackOptions): Promise<Record<string,
|
|
519
|
+
declare function mastraTools(box: SandboxInstance, options?: MastraToolPackOptions): Promise<Record<string, unknown>>;
|
|
520
520
|
//#endregion
|
|
521
521
|
//#region src/agent/tools/openai.d.ts
|
|
522
522
|
interface OpenAITool {
|
package/dist/agent/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as assertCurrentBackendType } from "../runtime-api-D7CdKcbu.js";
|
|
2
2
|
import { c as NotFoundError, h as ValidationError, p as StateError } from "../errors-CdDyExth.js";
|
|
3
|
-
import { n as Sandbox } from "../client-
|
|
4
|
-
import { t as SandboxInstance } from "../sandbox-
|
|
3
|
+
import { n as Sandbox } from "../client-DWX9LVU8.js";
|
|
4
|
+
import { t as SandboxInstance } from "../sandbox-f9NE1NPU.js";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
|
+
import { z } from "zod";
|
|
6
7
|
//#region src/agent/instances.ts
|
|
7
8
|
const managers = /* @__PURE__ */ new WeakMap();
|
|
8
9
|
function generateAgentId() {
|
|
@@ -682,6 +683,23 @@ function selectFleetSpecs(allow) {
|
|
|
682
683
|
}
|
|
683
684
|
//#endregion
|
|
684
685
|
//#region src/agent/tools/fleet/index.ts
|
|
686
|
+
/**
|
|
687
|
+
* Fleet tool packs — one per framework. The shape mirrors the per-box
|
|
688
|
+
* packs (`anthropicTools`, `openaiTools`, etc.), bound to a Sandbox
|
|
689
|
+
* instead of a single SandboxInstance because fleet lifecycle is multi-
|
|
690
|
+
* machine and outlives any one sandbox handle.
|
|
691
|
+
*
|
|
692
|
+
* Fleet tools default-OFF in the agent's allow-list discipline: the
|
|
693
|
+
* operator passes `allow: ["sandbox_fleet_spawn", "sandbox_fleet_dispatch", ...]`
|
|
694
|
+
* to opt in. This is a cost gate — a single `sandbox_fleet_spawn({workers: 16})`
|
|
695
|
+
* provisions 17 sandboxes (16 workers + 1 coordinator) and bills linearly.
|
|
696
|
+
*
|
|
697
|
+
* Operationally: the agent threads `fleetId` through its tool-use history.
|
|
698
|
+
* After a `sandbox_fleet_spawn` returns `{fleetId, machineIds}`, every
|
|
699
|
+
* subsequent fleet call carries that `fleetId`. The agent is also
|
|
700
|
+
* responsible for calling `sandbox_fleet_destroy` when the campaign ends;
|
|
701
|
+
* orphaned fleets keep accruing cost.
|
|
702
|
+
*/
|
|
685
703
|
function anthropicFleetTools(client, options = {}) {
|
|
686
704
|
const specs = selectFleetSpecs(options.allow);
|
|
687
705
|
const handlers = buildFleetHandlers(specs, { client });
|
|
@@ -770,7 +788,7 @@ async function vercelAiFleetTools(client, options = {}) {
|
|
|
770
788
|
const result = {};
|
|
771
789
|
for (const spec of specs) result[spec.name] = ai.tool({
|
|
772
790
|
description: spec.description,
|
|
773
|
-
inputSchema:
|
|
791
|
+
inputSchema: z.fromJSONSchema(spec.inputSchema).pipe(z.record(z.string(), z.unknown())),
|
|
774
792
|
execute: async (args) => {
|
|
775
793
|
const h = handlers.get(spec.name);
|
|
776
794
|
if (!h) throw new Error(`Unknown fleet tool: ${spec.name}`);
|
|
@@ -782,7 +800,7 @@ async function vercelAiFleetTools(client, options = {}) {
|
|
|
782
800
|
async function mastraFleetTools(client, options = {}) {
|
|
783
801
|
let mastra;
|
|
784
802
|
try {
|
|
785
|
-
mastra = await import("@mastra/core");
|
|
803
|
+
mastra = await import("@mastra/core/tools");
|
|
786
804
|
} catch {
|
|
787
805
|
throw new Error("mastraFleetTools(): the `@mastra/core` package is not installed. Install via `pnpm add @mastra/core`.");
|
|
788
806
|
}
|
|
@@ -792,11 +810,11 @@ async function mastraFleetTools(client, options = {}) {
|
|
|
792
810
|
for (const spec of specs) result[spec.name] = mastra.createTool({
|
|
793
811
|
id: spec.name,
|
|
794
812
|
description: spec.description,
|
|
795
|
-
inputSchema:
|
|
813
|
+
inputSchema: z.fromJSONSchema(spec.inputSchema).pipe(z.record(z.string(), z.unknown())),
|
|
796
814
|
execute: async (input) => {
|
|
797
815
|
const h = handlers.get(spec.name);
|
|
798
816
|
if (!h) throw new Error(`Unknown fleet tool: ${spec.name}`);
|
|
799
|
-
return { result: serializeToolResult(await h(input
|
|
817
|
+
return { result: serializeToolResult(await h(input)) };
|
|
800
818
|
}
|
|
801
819
|
});
|
|
802
820
|
return result;
|
|
@@ -994,6 +1012,15 @@ function buildLifecycleHandlers(specs, ctx) {
|
|
|
994
1012
|
//#endregion
|
|
995
1013
|
//#region src/agent/tools/mastra.ts
|
|
996
1014
|
/**
|
|
1015
|
+
* Mastra tool pack.
|
|
1016
|
+
*
|
|
1017
|
+
* Returns a `Record<id, Tool>` ready for `new Agent({ tools })`.
|
|
1018
|
+
* The registry's JSON schemas become validated object inputs.
|
|
1019
|
+
*
|
|
1020
|
+
* `@mastra/core` is dynamically imported. Install it in your app:
|
|
1021
|
+
* pnpm add @mastra/core
|
|
1022
|
+
*/
|
|
1023
|
+
/**
|
|
997
1024
|
* Build a Mastra tool pack bound to one sandbox.
|
|
998
1025
|
*
|
|
999
1026
|
* @example
|
|
@@ -1009,7 +1036,7 @@ function buildLifecycleHandlers(specs, ctx) {
|
|
|
1009
1036
|
async function mastraTools(box, options = {}) {
|
|
1010
1037
|
let mastra;
|
|
1011
1038
|
try {
|
|
1012
|
-
mastra = await import("@mastra/core");
|
|
1039
|
+
mastra = await import("@mastra/core/tools");
|
|
1013
1040
|
} catch {
|
|
1014
1041
|
throw new Error("mastraTools(): the `@mastra/core` package is not installed. Install it via `pnpm add @mastra/core`.");
|
|
1015
1042
|
}
|
|
@@ -1024,9 +1051,9 @@ async function mastraTools(box, options = {}) {
|
|
|
1024
1051
|
result[spec.name] = mastra.createTool({
|
|
1025
1052
|
id: spec.name,
|
|
1026
1053
|
description: spec.description,
|
|
1027
|
-
inputSchema:
|
|
1054
|
+
inputSchema: z.fromJSONSchema(spec.inputSchema).pipe(z.record(z.string(), z.unknown())),
|
|
1028
1055
|
execute: async (input) => {
|
|
1029
|
-
return { result: serializeToolResult(await handler(input
|
|
1056
|
+
return { result: serializeToolResult(await handler(input)) };
|
|
1030
1057
|
}
|
|
1031
1058
|
});
|
|
1032
1059
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as AgentQuestionRequest,
|
|
1
|
+
import { a as AgentQuestionRequest, br as SandboxEvent, i as AgentApprovalRequirement, o as AgentRunStatus, s as AgentToolInvocation, st as DurablePlanSnapshot } from "./types-CDksqyD4.js";
|
|
2
2
|
import { InteractionRequest } from "@tangle-network/agent-interface";
|
|
3
3
|
|
|
4
4
|
//#region src/agent-run-outcome.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { l as TraceExportResult, n as HttpClient, r as SandboxInstance, u as TraceExportSink } from "./sandbox-
|
|
1
|
+
import { l as TraceExportResult, n as HttpClient, r as SandboxInstance, u as TraceExportSink } from "./sandbox-CpCVgm4V.js";
|
|
2
2
|
import { l as ScopedToken, s as MintInteractiveSessionTokenOptions } from "./terminal-stream-CcaBTVg3.js";
|
|
3
|
-
import {
|
|
3
|
+
import { $n as ReconcileSandboxFleetsResult, B as CreateSandboxOptions, Bn as PromptOptions, Bt as FleetMachineId, Cr as SandboxFleetCostEstimate, Er as SandboxFleetDriverCapability, F as CreateIntelligenceReportOptions, Ft as FleetDispatchStreamOptions, G as DeleteMatchingSandboxesFilter, Gr as SandboxFleetWorkspaceReconcileResult, Hr as SandboxFleetTraceOptions, Ht as FleetPromptDispatchResult, I as CreateRequestOptions, Ir as SandboxFleetOperationsSummary, It as FleetDriveTurnOutcome, Jn as PublishPublicTemplateOptions, Jr as SandboxIdentity, K as DeleteMatchingSandboxesOptions, Ki as SshKeysManager, Kn as PublicTemplateInfo, Kr as SandboxFleetWorkspaceRestoreResult, L as CreateSandboxFleetOptions, Lt as FleetDriveTurnRequest, Mr as SandboxFleetMachineRecord, Mt as FleetDispatchCancelResult, Nt as FleetDispatchResultBuffer, Or as SandboxFleetInfo, Pr as SandboxFleetManifest, Pt as FleetDispatchResultBufferOptions, Qn as ReconcileSandboxFleetsOptions, R as CreateSandboxFleetTokenOptions, Rr as SandboxFleetToken, Rt as FleetExecDispatchOptions, Si as SecretsManager, Sr as SandboxFleetArtifactSpec, Tr as SandboxFleetDispatchResponse, Ur as SandboxFleetUsage, Vn as PromptResult, Vt as FleetPromptDispatchOptions, Xi as SubscriptionInfo, Xn as ReapExpiredSandboxFleetsOptions, Yn as PublishPublicTemplateVersionOptions, Yr as SandboxInfo, Zn as ReapExpiredSandboxFleetsResult, _t as ExecOptions, b as BatchRunRequest, dn as IntelligenceReportBudget, fn as IntelligenceReportCompareTo, fr as SandboxConfig, l as AttachSandboxFleetMachineOptions, mn as IntelligenceReportWindow, oi as SandboxShapesInfo, pa as UsageInfo, q as DeleteMatchingSandboxesResult, qn as PublicTemplateVersionInfo, qr as SandboxFleetWorkspaceSnapshotResult, sa as TokenRefreshHandler, un as IntelligenceReport, v as BatchResult, vn as ListSandboxFleetOptions, vt as ExecResult, xa as BatchEvent, xr as SandboxFleetArtifact, y as BatchRunOptions, yn as ListSandboxOptions, yr as SandboxEnvironment, z as CreateSandboxFleetWithCoordinatorOptions, zn as PromptInputPart, zr as SandboxFleetTraceBundle, zt as FleetExecDispatchResult } from "./types-CDksqyD4.js";
|
|
4
4
|
import { AgentInteractiveSessionRef } from "@tangle-network/agent-interface";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
|
|
@@ -492,6 +492,37 @@ declare class Sandbox implements HttpClient, ScopedTokenHttpClient {
|
|
|
492
492
|
* ```
|
|
493
493
|
*/
|
|
494
494
|
get(id: string): Promise<SandboxInstance | null>;
|
|
495
|
+
/**
|
|
496
|
+
* Delete every sandbox this caller owns whose metadata matches, and report
|
|
497
|
+
* which ones are confirmed gone.
|
|
498
|
+
*
|
|
499
|
+
* Each sandbox goes through the same delete as {@link SandboxInstance.delete}.
|
|
500
|
+
* The API deletes a bounded batch per request in ID order; this method
|
|
501
|
+
* follows its cursor, so one call attempts every match once and a refused
|
|
502
|
+
* delete never holds back the matches after it. Calling it again is safe: a
|
|
503
|
+
* sandbox confirmed gone no longer matches.
|
|
504
|
+
*
|
|
505
|
+
* `complete` is the teardown verdict. When it is false, `sandboxes` names
|
|
506
|
+
* each refused delete with its status and code, and `listingComplete` or
|
|
507
|
+
* `remaining` says whether a match may not have been attempted.
|
|
508
|
+
*
|
|
509
|
+
* `complete` covers the sandboxes this call listed. Stop creating
|
|
510
|
+
* sandboxes that match before calling, and call again once in-flight
|
|
511
|
+
* creates have settled; a create that registers after the listing, or that
|
|
512
|
+
* retries with the same idempotency key, can leave a match behind.
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* ```typescript
|
|
516
|
+
* // Remove every sandbox one Agent Runtime run created.
|
|
517
|
+
* const result = await client.deleteMatching({
|
|
518
|
+
* metadataPrefix: { retainedIdempotencyKey: `runtime:${runId}:` },
|
|
519
|
+
* });
|
|
520
|
+
* if (!result.complete) {
|
|
521
|
+
* console.warn(result.sandboxes.filter((s) => !s.confirmed));
|
|
522
|
+
* }
|
|
523
|
+
* ```
|
|
524
|
+
*/
|
|
525
|
+
deleteMatching(filter: DeleteMatchingSandboxesFilter, options?: DeleteMatchingSandboxesOptions): Promise<DeleteMatchingSandboxesResult>;
|
|
495
526
|
/**
|
|
496
527
|
* Mint the terminal-capable token for one exact interactive session.
|
|
497
528
|
*
|
|
@@ -500,6 +531,24 @@ declare class Sandbox implements HttpClient, ScopedTokenHttpClient {
|
|
|
500
531
|
* and makes one scoped-token request without loading the sandbox first.
|
|
501
532
|
*/
|
|
502
533
|
mintInteractiveSessionToken(ref: AgentInteractiveSessionRef, options?: MintInteractiveSessionTokenOptions): Promise<ScopedToken>;
|
|
534
|
+
/**
|
|
535
|
+
* The named sandbox sizes, which one is the platform's default, and the
|
|
536
|
+
* largest shape this account can be granted on the serving deployment.
|
|
537
|
+
*
|
|
538
|
+
* The platform owns these numbers; a client that sizes a request from
|
|
539
|
+
* `ceiling` is never refused with `RESOURCES_EXCEED_LIMIT`, and
|
|
540
|
+
* {@link sandboxResourcesForSize} accepts `presets` so a named tier expands
|
|
541
|
+
* to what this deployment actually sells.
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
* ```typescript
|
|
545
|
+
* const shapes = await client.shapes();
|
|
546
|
+
* const box = await client.create({
|
|
547
|
+
* resources: sandboxResourcesForSize("medium", shapes.presets),
|
|
548
|
+
* });
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
shapes(): Promise<SandboxShapesInfo>;
|
|
503
552
|
/**
|
|
504
553
|
* Return the identity the public Sandbox API observed for this credential.
|
|
505
554
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as backendTypeSchema, _ as normalizeRuntimeBackendConfig, d as encodePromptForWire, f as encodeTextForWire, h as assertCurrentBackendType, l as SANDBOX_PROXY_REQUEST_MAX_BYTES, m as applyRequestedModel, p as parseSSEStream } from "./runtime-api-D7CdKcbu.js";
|
|
2
2
|
import { c as NotFoundError, d as SandboxError, f as ServerError, g as parseErrorResponse, h as ValidationError, l as PartialFailureError, m as TimeoutError, s as NetworkError, t as AuthError } from "./errors-CdDyExth.js";
|
|
3
3
|
import { n as combineAbortSignals } from "./abort-signal-si1WMfJb.js";
|
|
4
|
-
import {
|
|
4
|
+
import { D as normalizeSandboxShape, E as normalizeConnection, b as requestInteractiveSessionToken, i as normalizeStartupDiagnostics, k as exportTraceBundle, n as createSandboxInstanceFromResponse, r as normalizeSandboxCreateReceipt } from "./sandbox-f9NE1NPU.js";
|
|
5
5
|
import { agentProfileSchema } from "@tangle-network/agent-interface";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
//#region src/backend-registry.ts
|
|
@@ -1076,6 +1076,106 @@ const runtimeWorkspaceCwdSchema = z.string().min(1).max(MAX_RUNTIME_WORKSPACE_CW
|
|
|
1076
1076
|
return value.split("/").filter((segment) => segment.length > 0 && segment !== ".").join("/") || ".";
|
|
1077
1077
|
});
|
|
1078
1078
|
//#endregion
|
|
1079
|
+
//#region src/delete-matching.ts
|
|
1080
|
+
/**
|
|
1081
|
+
* Delete every sandbox the caller owns whose metadata matches, and report
|
|
1082
|
+
* which ones are confirmed gone.
|
|
1083
|
+
*
|
|
1084
|
+
* The API deletes a bounded batch per request, in ID order, and answers a
|
|
1085
|
+
* `next` cursor while matches remain past it. This helper follows the cursor
|
|
1086
|
+
* until no match remains past it, so one pass attempts every match once:
|
|
1087
|
+
* matches whose deletes keep failing never hold back the ones after them.
|
|
1088
|
+
*/
|
|
1089
|
+
const DELETE_MATCHING_PATH = "/v1/sandboxes/delete-matching";
|
|
1090
|
+
const DEFAULT_TIMEOUT_MS$1 = 12e4;
|
|
1091
|
+
const DEFAULT_UNTIL_REMOVED_TIMEOUT_MS = 3e5;
|
|
1092
|
+
const OUTCOMES = new Set([
|
|
1093
|
+
"destroyed",
|
|
1094
|
+
"already_absent",
|
|
1095
|
+
"failed"
|
|
1096
|
+
]);
|
|
1097
|
+
function invalidDeleteMatching(message) {
|
|
1098
|
+
throw new ServerError(`Sandbox API answered delete-matching with ${message}`, 502, {
|
|
1099
|
+
origin: "sandbox-api",
|
|
1100
|
+
endpoint: DELETE_MATCHING_PATH
|
|
1101
|
+
}, "INVALID_DELETE_MATCHING_RESPONSE");
|
|
1102
|
+
}
|
|
1103
|
+
function isRecord(value) {
|
|
1104
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1105
|
+
}
|
|
1106
|
+
function readResult(raw) {
|
|
1107
|
+
if (!isRecord(raw) || typeof raw.id !== "string" || typeof raw.confirmed !== "boolean" || !OUTCOMES.has(raw.outcome)) invalidDeleteMatching("a malformed sandbox result");
|
|
1108
|
+
const deletedChildren = Array.isArray(raw.deletedChildren) ? raw.deletedChildren.map(String) : void 0;
|
|
1109
|
+
const children = Array.isArray(raw.children) ? raw.children.map(String) : void 0;
|
|
1110
|
+
return {
|
|
1111
|
+
id: raw.id,
|
|
1112
|
+
confirmed: raw.confirmed,
|
|
1113
|
+
outcome: raw.outcome,
|
|
1114
|
+
...raw.removal === "pending" || raw.removal === "complete" ? { removal: raw.removal } : {},
|
|
1115
|
+
...deletedChildren ? { deletedChildren } : {},
|
|
1116
|
+
...raw.settlementDeferred === true ? { settlementDeferred: true } : {},
|
|
1117
|
+
...typeof raw.status === "number" ? { status: raw.status } : {},
|
|
1118
|
+
...typeof raw.code === "string" ? { code: raw.code } : {},
|
|
1119
|
+
...typeof raw.error === "string" ? { error: raw.error } : {},
|
|
1120
|
+
...children ? { children } : {}
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
function readPage(raw) {
|
|
1124
|
+
if (!isRecord(raw) || typeof raw.remaining !== "number" || typeof raw.listingComplete !== "boolean" || typeof raw.complete !== "boolean" || !Array.isArray(raw.sandboxes) || raw.next !== void 0 && typeof raw.next !== "string") invalidDeleteMatching("a body missing its result fields");
|
|
1125
|
+
return {
|
|
1126
|
+
remaining: raw.remaining,
|
|
1127
|
+
next: raw.next,
|
|
1128
|
+
listingComplete: raw.listingComplete,
|
|
1129
|
+
complete: raw.complete,
|
|
1130
|
+
sandboxes: raw.sandboxes.map(readResult)
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
async function requestPage(client, body, options) {
|
|
1134
|
+
const timeoutMs = options?.timeoutMs ?? (options?.until === "removed" ? DEFAULT_UNTIL_REMOVED_TIMEOUT_MS : DEFAULT_TIMEOUT_MS$1);
|
|
1135
|
+
const response = await client.fetch(DELETE_MATCHING_PATH, {
|
|
1136
|
+
method: "POST",
|
|
1137
|
+
body,
|
|
1138
|
+
...options?.signal ? { signal: options.signal } : {}
|
|
1139
|
+
}, { timeoutMs });
|
|
1140
|
+
if (!response.ok) throw parseErrorResponse(response.status, await response.text(), {
|
|
1141
|
+
method: "POST",
|
|
1142
|
+
path: DELETE_MATCHING_PATH
|
|
1143
|
+
}, response.headers);
|
|
1144
|
+
return readPage(await response.json());
|
|
1145
|
+
}
|
|
1146
|
+
async function deleteMatchingSandboxes(client, filter, options) {
|
|
1147
|
+
const request = {
|
|
1148
|
+
metadataPrefix: filter.metadataPrefix,
|
|
1149
|
+
...options?.cascade ? { cascade: true } : {},
|
|
1150
|
+
...options?.until ? { until: options.until } : {}
|
|
1151
|
+
};
|
|
1152
|
+
const latest = /* @__PURE__ */ new Map();
|
|
1153
|
+
let listingComplete = true;
|
|
1154
|
+
const send = async (after) => {
|
|
1155
|
+
options?.signal?.throwIfAborted();
|
|
1156
|
+
const page = await requestPage(client, JSON.stringify(after === void 0 ? request : {
|
|
1157
|
+
...request,
|
|
1158
|
+
after
|
|
1159
|
+
}), options);
|
|
1160
|
+
for (const result of page.sandboxes) latest.set(result.id, result);
|
|
1161
|
+
listingComplete &&= page.listingComplete;
|
|
1162
|
+
return page;
|
|
1163
|
+
};
|
|
1164
|
+
let last = await send(void 0);
|
|
1165
|
+
for (let sent = 1; sent < 100 && last.remaining > 0 && last.next !== void 0; sent += 1) {
|
|
1166
|
+
const after = last.next;
|
|
1167
|
+
last = await send(after);
|
|
1168
|
+
if (last.next !== void 0 && last.next <= after) invalidDeleteMatching("a cursor that does not advance");
|
|
1169
|
+
}
|
|
1170
|
+
const sandboxes = [...latest.values()];
|
|
1171
|
+
return {
|
|
1172
|
+
complete: last.complete && last.remaining === 0 && listingComplete && sandboxes.every((result) => result.confirmed),
|
|
1173
|
+
listingComplete,
|
|
1174
|
+
remaining: last.remaining,
|
|
1175
|
+
sandboxes
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
//#endregion
|
|
1079
1179
|
//#region src/fleet.ts
|
|
1080
1180
|
const FLEET_ID_META = "tangle.fleet.id";
|
|
1081
1181
|
const MACHINE_ID_META = "tangle.fleet.machine_id";
|
|
@@ -2764,8 +2864,8 @@ var Sandbox = class {
|
|
|
2764
2864
|
return this.create({
|
|
2765
2865
|
...options,
|
|
2766
2866
|
ownerContext: "isolated",
|
|
2767
|
-
secrets: [],
|
|
2768
|
-
sshEnabled: false
|
|
2867
|
+
secrets: options.secrets ?? [],
|
|
2868
|
+
sshEnabled: options.sshEnabled ?? false
|
|
2769
2869
|
}, requestOptions);
|
|
2770
2870
|
}
|
|
2771
2871
|
async create(inputOptions, requestOptions) {
|
|
@@ -2794,7 +2894,7 @@ var Sandbox = class {
|
|
|
2794
2894
|
auth: options.git.auth
|
|
2795
2895
|
} : void 0;
|
|
2796
2896
|
const environment = options?.environment;
|
|
2797
|
-
const backend = await hydrateLocalCliBackendAuth(options?.backend, this.baseUrl, this.trustLocalCliAuth);
|
|
2897
|
+
const backend = options?.ownerContext === "isolated" ? options.backend : await hydrateLocalCliBackendAuth(options?.backend, this.baseUrl, this.trustLocalCliAuth);
|
|
2798
2898
|
const resolvedBackend = backend ? {
|
|
2799
2899
|
...backend,
|
|
2800
2900
|
type: backend.type ?? "opencode"
|
|
@@ -2943,7 +3043,16 @@ var Sandbox = class {
|
|
|
2943
3043
|
}
|
|
2944
3044
|
if (!response) throw createTimeoutError();
|
|
2945
3045
|
const data = await response.json();
|
|
2946
|
-
const
|
|
3046
|
+
const info = this.parseInfo(data);
|
|
3047
|
+
const injectedSecrets = data.createReceipt?.injectedSecrets;
|
|
3048
|
+
if (options?.ownerContext === "isolated" && (info.createReceipt?.ownerContext !== "isolated" || injectedSecrets !== void 0 && (!Array.isArray(injectedSecrets) || injectedSecrets.length !== 0))) throw new PartialFailureError("The host did not confirm isolated owner context. No post-create work was started. Inspect the recorded sandbox and retry identity before allocating a replacement.", "SANDBOX_ISOLATION_UNVERIFIED", 502, {
|
|
3049
|
+
origin: "sandbox-api",
|
|
3050
|
+
endpoint: "/v1/sandboxes"
|
|
3051
|
+
}, [{
|
|
3052
|
+
sandboxId: info.id,
|
|
3053
|
+
idempotencyKey
|
|
3054
|
+
}]);
|
|
3055
|
+
const instance = createSandboxInstanceFromResponse(this, info, handleBackend, data);
|
|
2947
3056
|
if (instance.status === "provisioning" || instance.status === "pending") {
|
|
2948
3057
|
const remainingMs = Math.max(0, deadline - Date.now());
|
|
2949
3058
|
await instance.waitFor("running", {
|
|
@@ -3080,7 +3189,40 @@ var Sandbox = class {
|
|
|
3080
3189
|
throw parseErrorResponse(response.status, body, void 0, response.headers);
|
|
3081
3190
|
}
|
|
3082
3191
|
const data = await response.json();
|
|
3083
|
-
return createSandboxInstanceFromResponse(this, this.parseInfo(data));
|
|
3192
|
+
return createSandboxInstanceFromResponse(this, this.parseInfo(data), void 0, data);
|
|
3193
|
+
}
|
|
3194
|
+
/**
|
|
3195
|
+
* Delete every sandbox this caller owns whose metadata matches, and report
|
|
3196
|
+
* which ones are confirmed gone.
|
|
3197
|
+
*
|
|
3198
|
+
* Each sandbox goes through the same delete as {@link SandboxInstance.delete}.
|
|
3199
|
+
* The API deletes a bounded batch per request in ID order; this method
|
|
3200
|
+
* follows its cursor, so one call attempts every match once and a refused
|
|
3201
|
+
* delete never holds back the matches after it. Calling it again is safe: a
|
|
3202
|
+
* sandbox confirmed gone no longer matches.
|
|
3203
|
+
*
|
|
3204
|
+
* `complete` is the teardown verdict. When it is false, `sandboxes` names
|
|
3205
|
+
* each refused delete with its status and code, and `listingComplete` or
|
|
3206
|
+
* `remaining` says whether a match may not have been attempted.
|
|
3207
|
+
*
|
|
3208
|
+
* `complete` covers the sandboxes this call listed. Stop creating
|
|
3209
|
+
* sandboxes that match before calling, and call again once in-flight
|
|
3210
|
+
* creates have settled; a create that registers after the listing, or that
|
|
3211
|
+
* retries with the same idempotency key, can leave a match behind.
|
|
3212
|
+
*
|
|
3213
|
+
* @example
|
|
3214
|
+
* ```typescript
|
|
3215
|
+
* // Remove every sandbox one Agent Runtime run created.
|
|
3216
|
+
* const result = await client.deleteMatching({
|
|
3217
|
+
* metadataPrefix: { retainedIdempotencyKey: `runtime:${runId}:` },
|
|
3218
|
+
* });
|
|
3219
|
+
* if (!result.complete) {
|
|
3220
|
+
* console.warn(result.sandboxes.filter((s) => !s.confirmed));
|
|
3221
|
+
* }
|
|
3222
|
+
* ```
|
|
3223
|
+
*/
|
|
3224
|
+
async deleteMatching(filter, options) {
|
|
3225
|
+
return deleteMatchingSandboxes(this, filter, options);
|
|
3084
3226
|
}
|
|
3085
3227
|
/**
|
|
3086
3228
|
* Mint the terminal-capable token for one exact interactive session.
|
|
@@ -3093,6 +3235,33 @@ var Sandbox = class {
|
|
|
3093
3235
|
return requestInteractiveSessionToken(this, ref, options);
|
|
3094
3236
|
}
|
|
3095
3237
|
/**
|
|
3238
|
+
* The named sandbox sizes, which one is the platform's default, and the
|
|
3239
|
+
* largest shape this account can be granted on the serving deployment.
|
|
3240
|
+
*
|
|
3241
|
+
* The platform owns these numbers; a client that sizes a request from
|
|
3242
|
+
* `ceiling` is never refused with `RESOURCES_EXCEED_LIMIT`, and
|
|
3243
|
+
* {@link sandboxResourcesForSize} accepts `presets` so a named tier expands
|
|
3244
|
+
* to what this deployment actually sells.
|
|
3245
|
+
*
|
|
3246
|
+
* @example
|
|
3247
|
+
* ```typescript
|
|
3248
|
+
* const shapes = await client.shapes();
|
|
3249
|
+
* const box = await client.create({
|
|
3250
|
+
* resources: sandboxResourcesForSize("medium", shapes.presets),
|
|
3251
|
+
* });
|
|
3252
|
+
* ```
|
|
3253
|
+
*/
|
|
3254
|
+
async shapes() {
|
|
3255
|
+
const response = await this.fetch("/v1/shapes");
|
|
3256
|
+
if (!response.ok) {
|
|
3257
|
+
const body = await response.text();
|
|
3258
|
+
throw parseErrorResponse(response.status, body, void 0, response.headers);
|
|
3259
|
+
}
|
|
3260
|
+
const data = await response.json();
|
|
3261
|
+
if (!Array.isArray(data?.presets) || typeof data.default !== "string" || !data.ceiling || typeof data.ceiling.cpuCores !== "number" || typeof data.ceiling.memoryMB !== "number" || typeof data.ceiling.diskGB !== "number") throw new SandboxError("GET /v1/shapes returned no usable shape catalogue", "INVALID_RESPONSE", 502);
|
|
3262
|
+
return data;
|
|
3263
|
+
}
|
|
3264
|
+
/**
|
|
3096
3265
|
* Return the identity the public Sandbox API observed for this credential.
|
|
3097
3266
|
*
|
|
3098
3267
|
* This is useful for deployment checks that must confirm which account and
|
|
@@ -3367,6 +3536,7 @@ var Sandbox = class {
|
|
|
3367
3536
|
expiresAt: data.expiresAt ? new Date(data.expiresAt) : void 0,
|
|
3368
3537
|
error: data.error,
|
|
3369
3538
|
gpuLease: data.gpuLease,
|
|
3539
|
+
resources: normalizeSandboxShape(data.resources),
|
|
3370
3540
|
startupDiagnostics: normalizeStartupDiagnostics(data.startupDiagnostics) ?? void 0,
|
|
3371
3541
|
createReceipt: normalizeSandboxCreateReceipt(data.createReceipt) ?? void 0
|
|
3372
3542
|
};
|
package/dist/core.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { a as WorkspaceImagePublishRequestOptions, i as WorkspaceImagePublishInput, o as WorkspaceImagePublishResult, r as SandboxInstance, s as WorkspaceImages } from "./sandbox-
|
|
2
|
-
import {
|
|
3
|
-
import { C as isBackendRegistryInteractionKind, S as backendRegistryResponseSchema, T as parseBackendRegistryResponseBody, _ as BackendRegistryInteractionKind, b as backendRegistryEntrySchema, g as BackendRegistryEntry, h as BackendRegistryCapabilities, i as Sandbox, v as BackendRegistryResponse, w as parseBackendRegistryResponse, x as backendRegistryInteractionKindSchema, y as backendRegistryCapabilitiesSchema } from "./client-
|
|
1
|
+
import { a as WorkspaceImagePublishRequestOptions, i as WorkspaceImagePublishInput, o as WorkspaceImagePublishResult, r as SandboxInstance, s as WorkspaceImages } from "./sandbox-CpCVgm4V.js";
|
|
2
|
+
import { An as PreviewLinkWaitOptions, B as CreateSandboxOptions, Cn as NetworkConfig, Ii as SessionMessageAdmission, M as ConversationTurnOptions, N as ConversationTurnResult, On as PreviewLinkInfo, Yr as SandboxInfo, _t as ExecOptions, fr as SandboxConfig, kn as PreviewLinkManager, si as SandboxStatus, vt as ExecResult, zn as PromptInputPart } from "./types-CDksqyD4.js";
|
|
3
|
+
import { C as isBackendRegistryInteractionKind, S as backendRegistryResponseSchema, T as parseBackendRegistryResponseBody, _ as BackendRegistryInteractionKind, b as backendRegistryEntrySchema, g as BackendRegistryEntry, h as BackendRegistryCapabilities, i as Sandbox, v as BackendRegistryResponse, w as parseBackendRegistryResponse, x as backendRegistryInteractionKindSchema, y as backendRegistryCapabilitiesSchema } from "./client-BVnci7-6.js";
|
|
4
4
|
import { _ as ValidationError, a as FileWriteConflictError, c as NotFoundError, d as SandboxError, f as SandboxErrorJson, g as TimeoutError, h as StateError, l as PartialFailureError, m as ServerError, n as CapabilityError, p as SandboxFailureDetail, s as NetworkError, t as AuthError, u as QuotaError } from "./errors-BoD3Ifbd.js";
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
//#region src/core.d.ts
|
|
7
|
+
/** Local SDK protocol support only, not a deployed-host readiness assertion.
|
|
8
|
+
* Version 1 refuses unconfirmed isolated receipts before materializing any
|
|
9
|
+
* profile/files and suppresses ambient CLI credential discovery. Callers must
|
|
10
|
+
* still inspect the host receipt and their own customer/workspace binding. */
|
|
11
|
+
declare const ISOLATED_CREATION_ATTESTATION_VERSION: 1;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { AuthError, type BackendRegistryCapabilities, type BackendRegistryEntry, type BackendRegistryInteractionKind, type BackendRegistryResponse, CapabilityError, type ConversationTurnOptions, type ConversationTurnResult, type CreateSandboxOptions, type ExecOptions, type ExecResult, FileWriteConflictError, ISOLATED_CREATION_ATTESTATION_VERSION, type NetworkConfig, NetworkError, NotFoundError, PartialFailureError, type PreviewLinkInfo, type PreviewLinkManager, type PreviewLinkWaitOptions, type PromptInputPart, QuotaError, Sandbox, type SandboxConfig, SandboxError, type SandboxErrorJson, type SandboxFailureDetail, type SandboxInfo, SandboxInstance, type SandboxStatus, ServerError, type SessionMessageAdmission, StateError, TimeoutError, ValidationError, type WorkspaceImagePublishInput, type WorkspaceImagePublishRequestOptions, type WorkspaceImagePublishResult, WorkspaceImages, backendRegistryCapabilitiesSchema, backendRegistryEntrySchema, backendRegistryInteractionKindSchema, backendRegistryResponseSchema, isBackendRegistryInteractionKind, parseBackendRegistryResponse, parseBackendRegistryResponseBody };
|
package/dist/core.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { a as FileWriteConflictError, c as NotFoundError, d as SandboxError, f as ServerError, h as ValidationError, l as PartialFailureError, m as TimeoutError, n as CapabilityError, p as StateError, s as NetworkError, t as AuthError, u as QuotaError } from "./errors-CdDyExth.js";
|
|
2
|
-
import { _ as parseBackendRegistryResponse, f as backendRegistryCapabilitiesSchema, g as isBackendRegistryInteractionKind, h as backendRegistryResponseSchema, m as backendRegistryInteractionKindSchema, n as Sandbox, p as backendRegistryEntrySchema, v as parseBackendRegistryResponseBody } from "./client-
|
|
3
|
-
import { a as WorkspaceImages, t as SandboxInstance } from "./sandbox-
|
|
4
|
-
|
|
2
|
+
import { _ as parseBackendRegistryResponse, f as backendRegistryCapabilitiesSchema, g as isBackendRegistryInteractionKind, h as backendRegistryResponseSchema, m as backendRegistryInteractionKindSchema, n as Sandbox, p as backendRegistryEntrySchema, v as parseBackendRegistryResponseBody } from "./client-DWX9LVU8.js";
|
|
3
|
+
import { a as WorkspaceImages, t as SandboxInstance } from "./sandbox-f9NE1NPU.js";
|
|
4
|
+
//#region src/core.ts
|
|
5
|
+
/** Local SDK protocol support only, not a deployed-host readiness assertion.
|
|
6
|
+
* Version 1 refuses unconfirmed isolated receipts before materializing any
|
|
7
|
+
* profile/files and suppresses ambient CLI credential discovery. Callers must
|
|
8
|
+
* still inspect the host receipt and their own customer/workspace binding. */
|
|
9
|
+
const ISOLATED_CREATION_ATTESTATION_VERSION = 1;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { AuthError, CapabilityError, FileWriteConflictError, ISOLATED_CREATION_ATTESTATION_VERSION, NetworkError, NotFoundError, PartialFailureError, QuotaError, Sandbox, SandboxError, SandboxInstance, ServerError, StateError, TimeoutError, ValidationError, WorkspaceImages, backendRegistryCapabilitiesSchema, backendRegistryEntrySchema, backendRegistryInteractionKindSchema, backendRegistryResponseSchema, isBackendRegistryInteractionKind, parseBackendRegistryResponse, parseBackendRegistryResponseBody };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as HttpClient, r as SandboxInstance } from "./sandbox-
|
|
2
|
-
import { B as CreateSandboxOptions } from "./types-
|
|
1
|
+
import { n as HttpClient, r as SandboxInstance } from "./sandbox-CpCVgm4V.js";
|
|
2
|
+
import { B as CreateSandboxOptions } from "./types-CDksqyD4.js";
|
|
3
3
|
|
|
4
4
|
//#region src/tangle/abi.d.ts
|
|
5
5
|
/**
|