@tangle-network/sandbox 0.13.0-develop.20260726140131.65bdb24 → 0.13.0-develop.20260726161607.1f7da8b
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 +254 -1295
- package/dist/agent/index.d.ts +11 -11
- package/dist/auth/index.d.ts +1 -1
- package/dist/{client-BDejoJQR.d.ts → client-CdpU6vjj.d.ts} +23 -28
- package/dist/{client-DS8qSxCp.js → client-Cz6oQM1P.js} +86 -78
- package/dist/collaboration/index.d.ts +1 -1
- package/dist/core.d.ts +5 -5
- package/dist/core.js +3 -3
- package/dist/{index-DwjU-4s_.d.ts → index-Cl5Vyyz7.d.ts} +2 -2
- package/dist/index.d.ts +3323 -516
- package/dist/index.js +271 -328
- package/dist/intelligence/index.d.ts +2 -2
- package/dist/intelligence/index.js +3 -3
- package/dist/local-cli-auth-DHBoF3wi.js +35 -0
- package/dist/openai/index.d.ts +1 -1
- package/dist/{runtime-api-BFtk4_HK.js → runtime-api-fZ4UDwOY.js} +30 -17
- package/dist/runtime.d.ts +2 -3
- package/dist/runtime.js +1 -1
- package/dist/{sandbox-CxflW4z4.d.ts → sandbox-Bz7kCFtN.d.ts} +11 -78
- package/dist/{sandbox-DXuuroty.js → sandbox-kHfb3J4x.js} +36 -217
- package/dist/tangle/index.d.ts +1 -1
- package/dist/tangle/index.js +1 -1
- package/dist/{tangle-46aLycNc.js → tangle-BdbEHJRy.js} +9 -31
- package/dist/{types-DFYV3JSL.d.ts → types-Ch78hv3k.d.ts} +218 -331
- package/package.json +5 -3
- /package/dist/{errors-C8HMx78o.d.ts → errors-BzMmpmqU.d.ts} +0 -0
- /package/dist/{index-DKzapw-9.d.ts → index-Cp1KYanB.d.ts} +0 -0
- /package/dist/{index-CyHojkuA.d.ts → index-DtRFVx5U.d.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { l as
|
|
1
|
+
import { l as assertCurrentBackendType, n as normalizeSessionInfo, o as combineAbortSignals, r as uploadChunked, s as encodePromptForWire, t as SandboxRuntimeApi, u as normalizeRuntimeBackendConfig } from "./runtime-api-fZ4UDwOY.js";
|
|
2
2
|
import { a as NotFoundError, c as SandboxError, d as TimeoutError, f as ValidationError, i as NetworkError, l as ServerError, p as parseErrorResponse, s as QuotaError, t as AuthError, u as StateError } from "./errors-D9fFOWX9.js";
|
|
3
|
-
import {
|
|
3
|
+
import { readTokenCostUsd, readTokenUsage } from "@tangle-network/agent-core";
|
|
4
4
|
//#region src/lib/sse-parser.ts
|
|
5
5
|
/**
|
|
6
6
|
* Parse a streaming SSE response body into an async iterable of
|
|
@@ -270,9 +270,7 @@ function snakeCase(value) {
|
|
|
270
270
|
* Normalize a raw `connection` payload from the Sandbox API into the SDK's
|
|
271
271
|
* canonical `SandboxConnection` shape.
|
|
272
272
|
*
|
|
273
|
-
* The
|
|
274
|
-
* the SDK exposes it as `connection.runtimeUrl`. This helper reads either
|
|
275
|
-
* field name so a future server-side rename needs no client change.
|
|
273
|
+
* The server and SDK expose the runtime URL as `connection.runtimeUrl`.
|
|
276
274
|
*
|
|
277
275
|
* Returns `undefined` when the raw payload has no usable runtime URL, so
|
|
278
276
|
* callers using `normalizeConnection(data.connection) ?? fallback` can
|
|
@@ -284,7 +282,7 @@ function snakeCase(value) {
|
|
|
284
282
|
function normalizeConnection(raw) {
|
|
285
283
|
if (!raw || typeof raw !== "object") return void 0;
|
|
286
284
|
const c = raw;
|
|
287
|
-
const runtimeUrl = c.runtimeUrl
|
|
285
|
+
const runtimeUrl = c.runtimeUrl;
|
|
288
286
|
const edgeStatus = normalizeEdgeStatus(c.edgeStatus);
|
|
289
287
|
const ssh = normalizeSshCredentials(c.ssh);
|
|
290
288
|
const webTerminalUrl = c.webTerminalUrl;
|
|
@@ -493,7 +491,7 @@ var InteractiveSessionHandle = class {
|
|
|
493
491
|
* routes: `status` reads `GET /agents/sessions/{id}`, `events` opens an
|
|
494
492
|
* SSE stream against `/agents/events?sessionId=...` (with `since` for
|
|
495
493
|
* replay), `prompt` continues the session via `/agents/run/stream`,
|
|
496
|
-
* `
|
|
494
|
+
* `interrupt` calls `/agents/sessions/{id}/abort`. No new sidecar surface
|
|
497
495
|
* is required — every endpoint already exists.
|
|
498
496
|
*
|
|
499
497
|
* Construction is private to the SDK: get a Session from
|
|
@@ -577,17 +575,6 @@ var SandboxSession = class SandboxSession {
|
|
|
577
575
|
async sendMessage(request, options) {
|
|
578
576
|
return this.box._sessionSendMessage(this.id, request, options);
|
|
579
577
|
}
|
|
580
|
-
/**
|
|
581
|
-
* Abort the session's in-flight execution; the session and its messages
|
|
582
|
-
* are preserved (this does not delete the session). Void-returning alias
|
|
583
|
-
* of `interrupt()` — use `interrupt()` when you need to know whether an
|
|
584
|
-
* execution was actually running. Best-effort: an in-flight LLM call may
|
|
585
|
-
* still complete one more token before the abort takes effect. Idempotent —
|
|
586
|
-
* aborting a session with nothing in flight is a no-op.
|
|
587
|
-
*/
|
|
588
|
-
async cancel() {
|
|
589
|
-
return this.box._sessionCancel(this.id);
|
|
590
|
-
}
|
|
591
578
|
/** Delete this session and its persisted runtime state. */
|
|
592
579
|
async delete() {
|
|
593
580
|
return this.box._sessionDelete(this.id);
|
|
@@ -1545,7 +1532,6 @@ function readFilesystemIncarnationTuple(value) {
|
|
|
1545
1532
|
const provenance = rawProvenance === "fresh" || rawProvenance === "restored" || rawProvenance === "unknown" ? rawProvenance : void 0;
|
|
1546
1533
|
const readiness = rawReadiness === "transitioning" || rawReadiness === "ready" ? rawReadiness : void 0;
|
|
1547
1534
|
return {
|
|
1548
|
-
hasAny: rawId !== void 0 || rawProvenance !== void 0 || rawReadiness !== void 0,
|
|
1549
1535
|
complete: id !== void 0 && provenance !== void 0 && readiness !== void 0,
|
|
1550
1536
|
id,
|
|
1551
1537
|
provenance,
|
|
@@ -1569,8 +1555,6 @@ function isTransientWriteError(err) {
|
|
|
1569
1555
|
var SandboxInstance = class SandboxInstance {
|
|
1570
1556
|
client;
|
|
1571
1557
|
info;
|
|
1572
|
-
/** Once observed, incarnation metadata is authoritative for this handle. */
|
|
1573
|
-
filesystemIncarnationContract;
|
|
1574
1558
|
refreshInFlight;
|
|
1575
1559
|
defaultRuntimeBackend;
|
|
1576
1560
|
runtime;
|
|
@@ -1579,7 +1563,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
1579
1563
|
* A profile the runtime has cached (create-time priming), letting turns
|
|
1580
1564
|
* send `backend.profileSha256` instead of re-shipping the profile's static
|
|
1581
1565
|
* corpus. Set only when priming succeeded; when unset every turn sends the
|
|
1582
|
-
* full profile
|
|
1566
|
+
* full profile. `snapshot` is the serialized
|
|
1583
1567
|
* content at prime time — a turn substitutes the reference only when the
|
|
1584
1568
|
* outgoing profile serializes identically, so a caller that mutates the
|
|
1585
1569
|
* profile in place (or passes an equivalent object) is compared by CONTENT,
|
|
@@ -1589,14 +1573,13 @@ var SandboxInstance = class SandboxInstance {
|
|
|
1589
1573
|
constructor(client, info, defaultRuntimeBackend) {
|
|
1590
1574
|
this.client = client;
|
|
1591
1575
|
const incarnation = readFilesystemIncarnationTuple(info);
|
|
1592
|
-
this.
|
|
1593
|
-
this.info = incarnation.hasAny ? {
|
|
1576
|
+
this.info = {
|
|
1594
1577
|
...info,
|
|
1595
1578
|
filesystemIncarnationId: incarnation.complete ? incarnation.id : void 0,
|
|
1596
1579
|
filesystemIncarnationProvenance: incarnation.complete ? incarnation.provenance : void 0,
|
|
1597
1580
|
filesystemIncarnationReadiness: incarnation.complete ? incarnation.readiness : void 0,
|
|
1598
1581
|
connection: incarnation.complete && incarnation.readiness === "ready" ? info.connection : void 0
|
|
1599
|
-
}
|
|
1582
|
+
};
|
|
1600
1583
|
this.defaultRuntimeBackend = defaultRuntimeBackend;
|
|
1601
1584
|
this.runtime = new SandboxRuntimeApi({
|
|
1602
1585
|
ensureRunning: () => this.ensureRunning(),
|
|
@@ -1943,7 +1926,8 @@ var SandboxInstance = class SandboxInstance {
|
|
|
1943
1926
|
method: "POST",
|
|
1944
1927
|
headers,
|
|
1945
1928
|
body: JSON.stringify({
|
|
1946
|
-
|
|
1929
|
+
executable: "/bin/sh",
|
|
1930
|
+
args: ["-lc", command],
|
|
1947
1931
|
cwd: options?.cwd,
|
|
1948
1932
|
env: options?.env,
|
|
1949
1933
|
timeoutMs,
|
|
@@ -2258,7 +2242,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
2258
2242
|
* static corpus does not ride every turn. The match is by serialized content,
|
|
2259
2243
|
* not object identity, so a mutated-in-place profile — or an equivalent
|
|
2260
2244
|
* object passed as a per-turn override — is compared correctly: unchanged
|
|
2261
|
-
* content references by hash, changed content sends inline
|
|
2245
|
+
* content references by hash, changed content sends inline.
|
|
2262
2246
|
*/
|
|
2263
2247
|
buildRunBackendBody(overrideBackend, forceFullProfile) {
|
|
2264
2248
|
const normalized = normalizeRuntimeBackendConfig(overrideBackend ?? this.defaultRuntimeBackend);
|
|
@@ -2394,16 +2378,15 @@ var SandboxInstance = class SandboxInstance {
|
|
|
2394
2378
|
...options?.detach ? { "x-agent-detach": "true" } : {}
|
|
2395
2379
|
},
|
|
2396
2380
|
body: JSON.stringify({
|
|
2397
|
-
|
|
2381
|
+
id: "default",
|
|
2382
|
+
...options?.sessionId ? { sessionId: options.sessionId } : {},
|
|
2398
2383
|
parts: encodePromptForWire(message),
|
|
2399
|
-
sessionId: options?.sessionId,
|
|
2400
2384
|
turnId: options?.turnId,
|
|
2401
2385
|
metadata: options?.context,
|
|
2402
2386
|
requireVisibleAssistantOutput: options?.requireVisibleAssistantOutput,
|
|
2403
2387
|
...timeoutMs ? { timeoutMs } : {},
|
|
2404
2388
|
...options?.detach ? { detach: true } : {},
|
|
2405
|
-
backend: this.buildRunBackendBody(options?.backend, internal?.forceFullProfile ?? false)
|
|
2406
|
-
...options?.model ? { model: normalizeRuntimeModelOverride(options.model) } : {}
|
|
2389
|
+
backend: this.buildRunBackendBody(options?.backend, internal?.forceFullProfile ?? false)
|
|
2407
2390
|
})
|
|
2408
2391
|
};
|
|
2409
2392
|
response = await this.runtimeFetch(requestEndpoint, request);
|
|
@@ -2704,129 +2687,6 @@ var SandboxInstance = class SandboxInstance {
|
|
|
2704
2687
|
return result;
|
|
2705
2688
|
}
|
|
2706
2689
|
/**
|
|
2707
|
-
* Run an agentic task until completion.
|
|
2708
|
-
*
|
|
2709
|
-
* Unlike prompt(), task() is designed for autonomous agent work:
|
|
2710
|
-
* - The agent works until it completes the task or hits an error
|
|
2711
|
-
* - Session state is maintained for context continuity
|
|
2712
|
-
* - Token usage is aggregated across the execution
|
|
2713
|
-
*
|
|
2714
|
-
* Note: The agent (OpenCode/Claude) handles multi-turn execution internally.
|
|
2715
|
-
* Most tasks complete in a single call. The maxTurns option is for edge cases
|
|
2716
|
-
* where the agent explicitly signals it needs additional input.
|
|
2717
|
-
*
|
|
2718
|
-
* @param prompt - Task description for the agent
|
|
2719
|
-
* @param options - Task options
|
|
2720
|
-
* @returns Task result with response and execution metadata
|
|
2721
|
-
*/
|
|
2722
|
-
async task(prompt, options) {
|
|
2723
|
-
const startTime = Date.now();
|
|
2724
|
-
const sessionId = options?.sessionId ?? `task-${crypto.randomUUID()}`;
|
|
2725
|
-
let responseText;
|
|
2726
|
-
let runError;
|
|
2727
|
-
let runErrorCode;
|
|
2728
|
-
let traceId;
|
|
2729
|
-
let usage;
|
|
2730
|
-
let costUsd;
|
|
2731
|
-
let toolInvocations;
|
|
2732
|
-
let question;
|
|
2733
|
-
let plan;
|
|
2734
|
-
let terminalReached = false;
|
|
2735
|
-
try {
|
|
2736
|
-
for await (const event of this.streamPrompt(prompt, {
|
|
2737
|
-
...options,
|
|
2738
|
-
sessionId
|
|
2739
|
-
})) {
|
|
2740
|
-
responseText = applySandboxEventText(responseText, event);
|
|
2741
|
-
if (event.type === "result") {
|
|
2742
|
-
const eventUsage = readTokenUsage(event.data);
|
|
2743
|
-
if (eventUsage) usage = addTokenUsage(usage, eventUsage);
|
|
2744
|
-
const eventCostUsd = readTokenCostUsd(event.data);
|
|
2745
|
-
if (eventCostUsd !== void 0) costUsd = (costUsd ?? 0) + eventCostUsd;
|
|
2746
|
-
toolInvocations = readToolInvocations(event.data) ?? toolInvocations;
|
|
2747
|
-
}
|
|
2748
|
-
if (event.type === "done" && costUsd === void 0) costUsd = readTokenCostUsd(event.data);
|
|
2749
|
-
if (event.type === "result" || event.type === "done") terminalReached = true;
|
|
2750
|
-
plan = readPlanFromEvent(event) ?? plan;
|
|
2751
|
-
if (event.type === "interaction") question = readQuestionEvent(event.data) ?? question;
|
|
2752
|
-
if (event.type === "trace.id") traceId = event.data.traceId;
|
|
2753
|
-
if (event.type === "error") {
|
|
2754
|
-
runError = event.data.message;
|
|
2755
|
-
runErrorCode = event.data.code;
|
|
2756
|
-
}
|
|
2757
|
-
}
|
|
2758
|
-
const approval = detectHubApproval(toolInvocations);
|
|
2759
|
-
const outcome = deriveOutcome({
|
|
2760
|
-
terminalReached,
|
|
2761
|
-
runError,
|
|
2762
|
-
runErrorCode,
|
|
2763
|
-
toolInvocations,
|
|
2764
|
-
approval,
|
|
2765
|
-
question,
|
|
2766
|
-
plan
|
|
2767
|
-
});
|
|
2768
|
-
return {
|
|
2769
|
-
success: outcome.success,
|
|
2770
|
-
status: outcome.status,
|
|
2771
|
-
response: responseText,
|
|
2772
|
-
error: outcome.error,
|
|
2773
|
-
errorCode: outcome.errorCode,
|
|
2774
|
-
toolInvocations,
|
|
2775
|
-
approval,
|
|
2776
|
-
question,
|
|
2777
|
-
plan,
|
|
2778
|
-
traceId,
|
|
2779
|
-
durationMs: Date.now() - startTime,
|
|
2780
|
-
usage,
|
|
2781
|
-
costUsd,
|
|
2782
|
-
turnsUsed: 1,
|
|
2783
|
-
sessionId
|
|
2784
|
-
};
|
|
2785
|
-
} catch (err) {
|
|
2786
|
-
return {
|
|
2787
|
-
success: false,
|
|
2788
|
-
status: "failed",
|
|
2789
|
-
error: err instanceof Error ? err.message : String(err),
|
|
2790
|
-
durationMs: Date.now() - startTime,
|
|
2791
|
-
turnsUsed: 1,
|
|
2792
|
-
sessionId
|
|
2793
|
-
};
|
|
2794
|
-
}
|
|
2795
|
-
}
|
|
2796
|
-
/**
|
|
2797
|
-
* Stream events from a task execution.
|
|
2798
|
-
*
|
|
2799
|
-
* Use this for real-time updates as the agent works:
|
|
2800
|
-
* - Tool calls and results
|
|
2801
|
-
* - Thinking/reasoning steps
|
|
2802
|
-
* - File operations
|
|
2803
|
-
* - Final response
|
|
2804
|
-
*
|
|
2805
|
-
* @param prompt - Task description for the agent
|
|
2806
|
-
* @param options - Task options
|
|
2807
|
-
*/
|
|
2808
|
-
async *streamTask(prompt, options) {
|
|
2809
|
-
const sessionId = options?.sessionId ?? `task-${crypto.randomUUID()}`;
|
|
2810
|
-
yield {
|
|
2811
|
-
type: "task.start",
|
|
2812
|
-
data: {
|
|
2813
|
-
sessionId,
|
|
2814
|
-
prompt
|
|
2815
|
-
}
|
|
2816
|
-
};
|
|
2817
|
-
try {
|
|
2818
|
-
for await (const event of this.streamPrompt(prompt, {
|
|
2819
|
-
...options,
|
|
2820
|
-
sessionId
|
|
2821
|
-
})) yield event;
|
|
2822
|
-
} finally {
|
|
2823
|
-
yield {
|
|
2824
|
-
type: "task.complete",
|
|
2825
|
-
data: { sessionId }
|
|
2826
|
-
};
|
|
2827
|
-
}
|
|
2828
|
-
}
|
|
2829
|
-
/**
|
|
2830
2690
|
* Search for text patterns in files using ripgrep.
|
|
2831
2691
|
*
|
|
2832
2692
|
* This is a first-class code search capability, not a shell wrapper.
|
|
@@ -2897,10 +2757,6 @@ var SandboxInstance = class SandboxInstance {
|
|
|
2897
2757
|
attach: (connectionId, options) => this._attachTerminal(connectionId, options)
|
|
2898
2758
|
};
|
|
2899
2759
|
}
|
|
2900
|
-
/** List profiles installed in this sandbox runtime. */
|
|
2901
|
-
async listProfiles() {
|
|
2902
|
-
return this.runtime.profiles();
|
|
2903
|
-
}
|
|
2904
2760
|
/**
|
|
2905
2761
|
* Live whole-sandbox resource usage (memory + CPU) from the container cgroup.
|
|
2906
2762
|
*
|
|
@@ -3634,7 +3490,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
3634
3490
|
await this.ensureRunning();
|
|
3635
3491
|
const response = await this.runtimeFetch("/backend/config", {
|
|
3636
3492
|
method: "PATCH",
|
|
3637
|
-
body: JSON.stringify(config)
|
|
3493
|
+
body: JSON.stringify(normalizeRuntimeBackendConfig(config))
|
|
3638
3494
|
});
|
|
3639
3495
|
if (!response.ok) {
|
|
3640
3496
|
const body = await response.text();
|
|
@@ -3758,21 +3614,12 @@ var SandboxInstance = class SandboxInstance {
|
|
|
3758
3614
|
* await proc.kill();
|
|
3759
3615
|
* ```
|
|
3760
3616
|
*
|
|
3761
|
-
* @example Run Python code directly
|
|
3762
|
-
* ```typescript
|
|
3763
|
-
* const result = await box.process.runCode(`
|
|
3764
|
-
* import numpy as np
|
|
3765
|
-
* print(np.random.rand(10).mean())
|
|
3766
|
-
* `);
|
|
3767
|
-
* console.log(result.stdout);
|
|
3768
|
-
* ```
|
|
3769
3617
|
*/
|
|
3770
3618
|
get process() {
|
|
3771
3619
|
return {
|
|
3772
3620
|
ensureDevServer: (options) => this.processEnsureDevServer(options),
|
|
3773
3621
|
spawn: (command, options) => this.processSpawn(command, options),
|
|
3774
3622
|
spawnExact: (executable, args, options) => this.processSpawnExact(executable, args, options),
|
|
3775
|
-
runCode: (code, options) => this.processRunCode(code, options),
|
|
3776
3623
|
list: (options) => this.processList(options),
|
|
3777
3624
|
get: (pid) => this.processGet(pid)
|
|
3778
3625
|
};
|
|
@@ -3802,7 +3649,8 @@ var SandboxInstance = class SandboxInstance {
|
|
|
3802
3649
|
const response = await this.runtimeFetch("/process/spawn", {
|
|
3803
3650
|
method: "POST",
|
|
3804
3651
|
body: JSON.stringify({
|
|
3805
|
-
|
|
3652
|
+
executable: "/bin/sh",
|
|
3653
|
+
args: ["-lc", command],
|
|
3806
3654
|
cwd: options?.cwd,
|
|
3807
3655
|
env: options?.env,
|
|
3808
3656
|
timeoutMs: options?.timeoutMs,
|
|
@@ -3840,24 +3688,6 @@ var SandboxInstance = class SandboxInstance {
|
|
|
3840
3688
|
const data = await response.json();
|
|
3841
3689
|
return this.createProcessHandle(data.data.pid, JSON.stringify([executable, ...args]));
|
|
3842
3690
|
}
|
|
3843
|
-
async processRunCode(code, options) {
|
|
3844
|
-
await this.ensureRunning();
|
|
3845
|
-
const response = await this.runtimeFetch("/process/run-code", {
|
|
3846
|
-
method: "POST",
|
|
3847
|
-
body: JSON.stringify({
|
|
3848
|
-
code,
|
|
3849
|
-
cwd: options?.cwd,
|
|
3850
|
-
env: options?.env,
|
|
3851
|
-
timeoutMs: options?.timeoutMs,
|
|
3852
|
-
blocking: true
|
|
3853
|
-
})
|
|
3854
|
-
});
|
|
3855
|
-
if (!response.ok) {
|
|
3856
|
-
const body = await response.text();
|
|
3857
|
-
throw parseErrorResponse(response.status, body, void 0, response.headers);
|
|
3858
|
-
}
|
|
3859
|
-
return (await response.json()).data;
|
|
3860
|
-
}
|
|
3861
3691
|
async processList(options) {
|
|
3862
3692
|
await this.ensureRunning();
|
|
3863
3693
|
const query = new URLSearchParams();
|
|
@@ -4736,13 +4566,6 @@ var SandboxInstance = class SandboxInstance {
|
|
|
4736
4566
|
return data ? normalizeStartupDiagnostics(data.startupDiagnostics) : null;
|
|
4737
4567
|
}
|
|
4738
4568
|
/**
|
|
4739
|
-
* keepAlive is intentionally unavailable until the API exposes timeout updates.
|
|
4740
|
-
* @param seconds - Reserved for future support
|
|
4741
|
-
*/
|
|
4742
|
-
async keepAlive(_seconds = 3600) {
|
|
4743
|
-
throw new Error("Sandbox keepAlive() is not supported by the current API. Set idleTimeoutSeconds when creating the sandbox instead.");
|
|
4744
|
-
}
|
|
4745
|
-
/**
|
|
4746
4569
|
* Upload a local directory to the sandbox via tar.
|
|
4747
4570
|
* @param localPath - Local directory path to upload
|
|
4748
4571
|
* @param remotePath - Destination path in the sandbox (default: /home/user)
|
|
@@ -4841,9 +4664,8 @@ var SandboxInstance = class SandboxInstance {
|
|
|
4841
4664
|
/**
|
|
4842
4665
|
* Wait for the sandbox to reach a specific status.
|
|
4843
4666
|
*
|
|
4844
|
-
* A sandbox
|
|
4845
|
-
*
|
|
4846
|
-
* contract retain the status-only behavior.
|
|
4667
|
+
* A sandbox is not considered `running` until its filesystem incarnation is
|
|
4668
|
+
* complete and ready.
|
|
4847
4669
|
*
|
|
4848
4670
|
* When `onProgress` is provided and the sandbox is still provisioning,
|
|
4849
4671
|
* uses SSE events for real-time progress instead of polling. Falls back
|
|
@@ -4929,7 +4751,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
4929
4751
|
await this.refresh();
|
|
4930
4752
|
if (this.hasReachedWaitTarget(statuses)) return true;
|
|
4931
4753
|
if (this.status === "failed") throw new StateError(this.error ?? "Sandbox failed", this.status);
|
|
4932
|
-
if (statuses.includes("running") && this.status === "running"
|
|
4754
|
+
if (statuses.includes("running") && this.status === "running") return false;
|
|
4933
4755
|
throw new TimeoutError(timeoutMs, `SSE stream ended before sandbox reached ${statuses.join(" or ")}`);
|
|
4934
4756
|
} finally {
|
|
4935
4757
|
clearTimeout(timeout);
|
|
@@ -4938,7 +4760,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
4938
4760
|
}
|
|
4939
4761
|
hasReachedWaitTarget(statuses) {
|
|
4940
4762
|
if (!statuses.includes(this.status)) return false;
|
|
4941
|
-
return this.status !== "running" ||
|
|
4763
|
+
return this.status !== "running" || this.filesystemIncarnationReadiness === "ready";
|
|
4942
4764
|
}
|
|
4943
4765
|
async ensureRunning() {
|
|
4944
4766
|
const statusObservedAt = sandboxStatusObservedAt.get(this) ?? 0;
|
|
@@ -4948,7 +4770,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
4948
4770
|
this.assertFilesystemIncarnationReady();
|
|
4949
4771
|
}
|
|
4950
4772
|
assertFilesystemIncarnationReady() {
|
|
4951
|
-
if (this.
|
|
4773
|
+
if (this.filesystemIncarnationReadiness !== "ready") throw new StateError("Sandbox filesystem incarnation is not ready", this.status, "running with a ready filesystem incarnation");
|
|
4952
4774
|
}
|
|
4953
4775
|
async runtimeFetch(path, options, fetchOptions) {
|
|
4954
4776
|
this.assertFilesystemIncarnationReady();
|
|
@@ -5044,9 +4866,9 @@ var SandboxInstance = class SandboxInstance {
|
|
|
5044
4866
|
parseInfo(data) {
|
|
5045
4867
|
const id = data.id ?? this.id;
|
|
5046
4868
|
const incarnation = readFilesystemIncarnationTuple(data);
|
|
5047
|
-
this.filesystemIncarnationContract ||= incarnation.hasAny;
|
|
5048
4869
|
const incarnationComplete = incarnation.complete;
|
|
5049
|
-
const
|
|
4870
|
+
const sameReadyIncarnation = incarnationComplete && incarnation.readiness === "ready" && incarnation.id === this.info.filesystemIncarnationId;
|
|
4871
|
+
const connection = incarnationComplete && incarnation.readiness === "ready" ? normalizeConnection(data.connection) ?? (sameReadyIncarnation ? this.info.connection : void 0) : void 0;
|
|
5050
4872
|
return {
|
|
5051
4873
|
id,
|
|
5052
4874
|
name: data.name,
|
|
@@ -5109,7 +4931,10 @@ var SandboxInstance = class SandboxInstance {
|
|
|
5109
4931
|
async sessions(opts) {
|
|
5110
4932
|
await this.ensureRunning();
|
|
5111
4933
|
const search = new URLSearchParams();
|
|
5112
|
-
if (opts?.backend)
|
|
4934
|
+
if (opts?.backend) {
|
|
4935
|
+
assertCurrentBackendType(opts.backend, "backend");
|
|
4936
|
+
search.set("backend", opts.backend);
|
|
4937
|
+
}
|
|
5113
4938
|
const qs = search.toString();
|
|
5114
4939
|
const response = await this.runtimeFetch(`/agents/sessions${qs ? `?${qs}` : ""}`);
|
|
5115
4940
|
if (!response.ok) {
|
|
@@ -5211,7 +5036,10 @@ var SandboxInstance = class SandboxInstance {
|
|
|
5211
5036
|
await this.ensureRunning();
|
|
5212
5037
|
const body = {};
|
|
5213
5038
|
if (opts.messageId !== void 0) body.messageID = opts.messageId;
|
|
5214
|
-
if (opts.targetBackend !== void 0)
|
|
5039
|
+
if (opts.targetBackend !== void 0) {
|
|
5040
|
+
assertCurrentBackendType(opts.targetBackend, "targetBackend");
|
|
5041
|
+
body.targetBackend = opts.targetBackend;
|
|
5042
|
+
}
|
|
5215
5043
|
if (opts.targetModel !== void 0) body.targetModel = opts.targetModel;
|
|
5216
5044
|
if (opts.files !== void 0) body.files = opts.files;
|
|
5217
5045
|
const response = await this.runtimeFetch(`/agents/sessions/${encodeURIComponent(id)}/forks`, {
|
|
@@ -5284,7 +5112,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
5284
5112
|
const startedAt = info.startedAt ?? info.createdAt;
|
|
5285
5113
|
const elapsedMs = startedAt ? Date.now() - startedAt.getTime() : void 0;
|
|
5286
5114
|
if (opts.wallCapMs !== void 0 && elapsedMs !== void 0 && elapsedMs > opts.wallCapMs) {
|
|
5287
|
-
await this.
|
|
5115
|
+
await this._interrupt(opts.sessionId);
|
|
5288
5116
|
return {
|
|
5289
5117
|
state: "failed",
|
|
5290
5118
|
error: `session ${opts.sessionId} exceeded the ${opts.wallCapMs}ms wall-clock cap and was cancelled`
|
|
@@ -5340,11 +5168,11 @@ var SandboxInstance = class SandboxInstance {
|
|
|
5340
5168
|
throw parseErrorResponse(response.status, body, void 0, response.headers);
|
|
5341
5169
|
}
|
|
5342
5170
|
const data = await response.json();
|
|
5343
|
-
if (typeof data.
|
|
5171
|
+
if (typeof data.runtimeUrl !== "string" || typeof data.sidecarProxyUrl !== "string") throw new Error("Scoped token response missing runtime URLs.");
|
|
5344
5172
|
return {
|
|
5345
5173
|
token: data.token,
|
|
5346
5174
|
expiresAt: /* @__PURE__ */ new Date(data.expiresAt * 1e3),
|
|
5347
|
-
runtimeUrl: data.
|
|
5175
|
+
runtimeUrl: data.runtimeUrl,
|
|
5348
5176
|
sidecarProxyUrl: data.sidecarProxyUrl,
|
|
5349
5177
|
scope: data.scope
|
|
5350
5178
|
};
|
|
@@ -5453,18 +5281,9 @@ var SandboxInstance = class SandboxInstance {
|
|
|
5453
5281
|
costUsd
|
|
5454
5282
|
};
|
|
5455
5283
|
}
|
|
5456
|
-
/**
|
|
5457
|
-
* @internal — invoked by SandboxSession.cancel(). Void-returning alias of
|
|
5458
|
-
* `_interrupt`: both abort the in-flight execution via `POST /{id}/abort`
|
|
5459
|
-
* (the session and its messages are preserved). `cancel()` discards the
|
|
5460
|
-
* `cancelled` flag; callers that need to distinguish a real interruption
|
|
5461
|
-
* from a no-op should use `interrupt()`.
|
|
5462
|
-
*/
|
|
5463
|
-
async _sessionCancel(id) {
|
|
5464
|
-
await this._interrupt(id);
|
|
5465
|
-
}
|
|
5466
5284
|
/** @internal — invoked by InteractiveSessionHandle.start(). */
|
|
5467
5285
|
async _startInteractive(id, options) {
|
|
5286
|
+
assertCurrentBackendType(options.harness, "harness");
|
|
5468
5287
|
await this.ensureRunning();
|
|
5469
5288
|
const response = await this.runtimeFetch(`/agents/sessions/${encodeURIComponent(id)}/interactive`, {
|
|
5470
5289
|
method: "POST",
|
package/dist/tangle/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as TANGLE_JOBS_CONTRACT, c as AgentSandboxBlueprintAbi, d as SandboxCreateParamTypes, f as SandboxCreateResponseParamTypes, i as TANGLE_CHAIN_ID, l as ITangleJobsAbi, n as JOB_SANDBOX_CREATE, o as TANGLE_MAINNET_RPC, p as SandboxIdParamTypes, r as JOB_SANDBOX_DELETE, s as TangleSandboxClientConfig, t as TangleSandboxClient, u as JsonResponseParamTypes } from "../index-
|
|
1
|
+
import { a as TANGLE_JOBS_CONTRACT, c as AgentSandboxBlueprintAbi, d as SandboxCreateParamTypes, f as SandboxCreateResponseParamTypes, i as TANGLE_CHAIN_ID, l as ITangleJobsAbi, n as JOB_SANDBOX_CREATE, o as TANGLE_MAINNET_RPC, p as SandboxIdParamTypes, r as JOB_SANDBOX_DELETE, s as TangleSandboxClientConfig, t as TangleSandboxClient, u as JsonResponseParamTypes } from "../index-Cl5Vyyz7.js";
|
|
2
2
|
export { AgentSandboxBlueprintAbi, ITangleJobsAbi, JOB_SANDBOX_CREATE, JOB_SANDBOX_DELETE, JsonResponseParamTypes, SandboxCreateParamTypes, SandboxCreateResponseParamTypes, SandboxIdParamTypes, TANGLE_CHAIN_ID, TANGLE_JOBS_CONTRACT, TANGLE_MAINNET_RPC, TangleSandboxClient, TangleSandboxClientConfig };
|
package/dist/tangle/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as TANGLE_JOBS_CONTRACT, c as ITangleJobsAbi, d as SandboxCreateResponseParamTypes, f as SandboxIdParamTypes, i as TANGLE_CHAIN_ID, l as JsonResponseParamTypes, n as JOB_SANDBOX_CREATE, o as TANGLE_MAINNET_RPC, r as JOB_SANDBOX_DELETE, s as AgentSandboxBlueprintAbi, t as TangleSandboxClient, u as SandboxCreateParamTypes } from "../tangle-
|
|
1
|
+
import { a as TANGLE_JOBS_CONTRACT, c as ITangleJobsAbi, d as SandboxCreateResponseParamTypes, f as SandboxIdParamTypes, i as TANGLE_CHAIN_ID, l as JsonResponseParamTypes, n as JOB_SANDBOX_CREATE, o as TANGLE_MAINNET_RPC, r as JOB_SANDBOX_DELETE, s as AgentSandboxBlueprintAbi, t as TangleSandboxClient, u as SandboxCreateParamTypes } from "../tangle-BdbEHJRy.js";
|
|
2
2
|
export { AgentSandboxBlueprintAbi, ITangleJobsAbi, JOB_SANDBOX_CREATE, JOB_SANDBOX_DELETE, JsonResponseParamTypes, SandboxCreateParamTypes, SandboxCreateResponseParamTypes, SandboxIdParamTypes, TANGLE_CHAIN_ID, TANGLE_JOBS_CONTRACT, TANGLE_MAINNET_RPC, TangleSandboxClient };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { p as parseErrorResponse } from "./errors-D9fFOWX9.js";
|
|
2
|
-
import { n as createSandboxInstanceFromResponse } from "./sandbox-
|
|
2
|
+
import { n as createSandboxInstanceFromResponse } from "./sandbox-kHfb3J4x.js";
|
|
3
3
|
//#region src/tangle/abi.ts
|
|
4
4
|
/**
|
|
5
5
|
* Tangle Contract ABI Definitions
|
|
@@ -447,6 +447,7 @@ var TangleChainClient = class {
|
|
|
447
447
|
};
|
|
448
448
|
}
|
|
449
449
|
encodeSandboxCreateInputs(options) {
|
|
450
|
+
if ((options.sshPublicKeys?.length ?? 0) > 1) throw new Error("Tangle sandbox creation accepts one SSH public key; pass at most one sshPublicKeys entry");
|
|
450
451
|
return {
|
|
451
452
|
types: SandboxCreateParamTypes,
|
|
452
453
|
values: [
|
|
@@ -457,7 +458,7 @@ var TangleChainClient = class {
|
|
|
457
458
|
options.env ? JSON.stringify(options.env) : "",
|
|
458
459
|
options.metadata ? JSON.stringify(options.metadata) : "",
|
|
459
460
|
options.sshEnabled ?? false,
|
|
460
|
-
options.
|
|
461
|
+
options.sshPublicKeys?.[0] ?? "",
|
|
461
462
|
options.webTerminalEnabled ?? false,
|
|
462
463
|
BigInt(options.maxLifetimeSeconds ?? 0),
|
|
463
464
|
BigInt(options.idleTimeoutSeconds ?? 0),
|
|
@@ -632,11 +633,7 @@ function readString(record, keys) {
|
|
|
632
633
|
if (typeof value === "string" && value.length > 0) return value;
|
|
633
634
|
}
|
|
634
635
|
}
|
|
635
|
-
/**
|
|
636
|
-
* The incarnation fields are one contract, not three independent hints.
|
|
637
|
-
* Keep the legacy (all absent) wire shape distinct from a partial contract so
|
|
638
|
-
* a readiness-only response cannot authorize a stale runtime credential.
|
|
639
|
-
*/
|
|
636
|
+
/** The incarnation fields are one contract, not three independent hints. */
|
|
640
637
|
function classifyFilesystemIncarnation(value) {
|
|
641
638
|
const rawId = value.filesystemIncarnationId;
|
|
642
639
|
const rawProvenance = value.filesystemIncarnationProvenance;
|
|
@@ -645,7 +642,6 @@ function classifyFilesystemIncarnation(value) {
|
|
|
645
642
|
const provenance = rawProvenance === "fresh" || rawProvenance === "restored" || rawProvenance === "unknown" ? rawProvenance : void 0;
|
|
646
643
|
const readiness = rawReadiness === "transitioning" || rawReadiness === "ready" ? rawReadiness : void 0;
|
|
647
644
|
return {
|
|
648
|
-
hasAny: rawId !== void 0 || rawProvenance !== void 0 || rawReadiness !== void 0,
|
|
649
645
|
complete: id !== void 0 && provenance !== void 0 && readiness !== void 0,
|
|
650
646
|
id,
|
|
651
647
|
provenance,
|
|
@@ -653,7 +649,7 @@ function classifyFilesystemIncarnation(value) {
|
|
|
653
649
|
};
|
|
654
650
|
}
|
|
655
651
|
function runtimeCredentialsAllowed(incarnation) {
|
|
656
|
-
return
|
|
652
|
+
return incarnation.complete && incarnation.readiness === "ready";
|
|
657
653
|
}
|
|
658
654
|
function entryMetadata(entry) {
|
|
659
655
|
const metadata = {
|
|
@@ -690,34 +686,16 @@ function sandboxEntryFromWire(fallbackId, raw) {
|
|
|
690
686
|
"sandboxId",
|
|
691
687
|
"sandbox_id"
|
|
692
688
|
]) ?? fallbackId;
|
|
693
|
-
const runtimeUrl = readString(connection, [
|
|
694
|
-
|
|
695
|
-
"sidecarUrl",
|
|
696
|
-
"sidecar_url"
|
|
697
|
-
]) ?? readString(raw, [
|
|
698
|
-
"runtimeUrl",
|
|
699
|
-
"sidecarUrl",
|
|
700
|
-
"sidecar_url"
|
|
701
|
-
]) ?? "";
|
|
702
|
-
const runtimeToken = readString(connection, [
|
|
689
|
+
const runtimeUrl = readString(connection, ["runtimeUrl", "sidecar_url"]) ?? readString(raw, ["runtimeUrl", "sidecar_url"]) ?? "";
|
|
690
|
+
const runtimeToken = readString(connection, ["authToken", "runtimeToken"]) ?? readString(raw, [
|
|
703
691
|
"authToken",
|
|
704
692
|
"runtimeToken",
|
|
705
|
-
"sidecarToken"
|
|
706
|
-
]) ?? readString(raw, [
|
|
707
|
-
"authToken",
|
|
708
|
-
"runtimeToken",
|
|
709
|
-
"sidecarToken",
|
|
710
693
|
"token"
|
|
711
694
|
]) ?? "";
|
|
712
695
|
const tupleField = (key) => Object.hasOwn(raw, key) ? raw[key] : void 0;
|
|
713
696
|
const tupleId = tupleField("filesystemIncarnationId") === void 0 ? void 0 : typeof tupleField("filesystemIncarnationId") === "string" ? tupleField("filesystemIncarnationId") : "";
|
|
714
697
|
const tupleProvenance = tupleField("filesystemIncarnationProvenance") === void 0 ? void 0 : tupleField("filesystemIncarnationProvenance");
|
|
715
698
|
const tupleReadiness = tupleField("filesystemIncarnationReadiness") === void 0 ? void 0 : tupleField("filesystemIncarnationReadiness");
|
|
716
|
-
const allowRuntime = runtimeCredentialsAllowed(classifyFilesystemIncarnation({
|
|
717
|
-
filesystemIncarnationId: tupleId,
|
|
718
|
-
filesystemIncarnationProvenance: tupleProvenance,
|
|
719
|
-
filesystemIncarnationReadiness: tupleReadiness
|
|
720
|
-
}));
|
|
721
699
|
const rawStatus = readString(raw, ["status"]) ?? "running";
|
|
722
700
|
const createdAtRaw = readString(raw, ["createdAt", "created_at"]);
|
|
723
701
|
const createdAt = createdAtRaw ? new Date(createdAtRaw) : /* @__PURE__ */ new Date();
|
|
@@ -727,8 +705,8 @@ function sandboxEntryFromWire(fallbackId, raw) {
|
|
|
727
705
|
filesystemIncarnationId: tupleId,
|
|
728
706
|
filesystemIncarnationProvenance: tupleProvenance,
|
|
729
707
|
filesystemIncarnationReadiness: tupleReadiness,
|
|
730
|
-
runtimeUrl
|
|
731
|
-
runtimeToken
|
|
708
|
+
runtimeUrl,
|
|
709
|
+
runtimeToken,
|
|
732
710
|
status: rawStatus === "stopped" || rawStatus === "deleted" || rawStatus === "running" ? rawStatus : "running",
|
|
733
711
|
createdAt,
|
|
734
712
|
metadata,
|