@tangle-network/sandbox 0.9.4-develop.20260710231333.22d131b → 0.9.4-develop.20260711192548.3c9ec78
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 +3 -2
- package/dist/auth/index.d.ts +1 -1
- package/dist/{client-BlHX4Cf0.d.ts → client-Cr39zlgv.d.ts} +25 -2
- package/dist/{client-bSvcFAca.js → client-Df1K1d_Q.js} +90 -73
- package/dist/collaboration/index.d.ts +1 -1
- package/dist/collaboration/index.js +1 -1
- package/dist/core.d.ts +4 -3
- package/dist/core.js +2 -2
- package/dist/{index-CuwpLz65.d.ts → index-DzEUjav-.d.ts} +2 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.js +6 -5
- package/dist/runtime-api-CYA2DUQw.js +434 -0
- package/dist/runtime.d.ts +62 -0
- package/dist/runtime.js +81 -0
- package/dist/sandbox-BhYmj7L3.d.ts +1489 -0
- package/dist/{sandbox-BZ33qVxk.js → sandbox-CxBHIBV1.js} +120 -155
- package/dist/session-gateway/index.js +16 -10
- package/dist/tangle/index.d.ts +1 -1
- package/dist/tangle/index.js +1 -1
- package/dist/{tangle-sPZOYZkz.js → tangle-BdRRHMpX.js} +1 -1
- package/dist/{sandbox-BEkgXuYK.d.ts → types-Cmpv-ox_.d.ts} +516 -1450
- package/package.json +6 -1
- /package/dist/{collaboration-D17lnOJX.js → collaboration-QZXrXdIb.js} +0 -0
- /package/dist/{errors-H9268M_g.d.ts → errors--P_nbLzM.d.ts} +0 -0
- /package/dist/{index-D-2pH_70.d.ts → index-CyHojkuA.d.ts} +0 -0
- /package/dist/{index-D7bwmNs8.d.ts → index-DKzapw-9.d.ts} +0 -0
|
@@ -1,135 +1,6 @@
|
|
|
1
|
+
import { n as normalizeSessionInfo, r as normalizeRuntimeBackendConfig, t as SandboxRuntimeApi } from "./runtime-api-CYA2DUQw.js";
|
|
1
2
|
import { c as SandboxError, d as TimeoutError, f as ValidationError, i as NetworkError, l as ServerError, n as CapabilityError, p as parseErrorResponse, s as QuotaError, t as AuthError, u as StateError } from "./errors-DSz87Rkk.js";
|
|
2
3
|
import { addTokenUsage, readTokenCostUsd, readTokenUsage } from "@tangle-network/agent-core";
|
|
3
|
-
//#region src/backend-config.ts
|
|
4
|
-
const LEGACY_QUESTION_ALIAS_KEY = ["question", "Channel"].join("");
|
|
5
|
-
function parseModelString(model) {
|
|
6
|
-
const parts = model.split("/");
|
|
7
|
-
if (parts.length >= 2) return {
|
|
8
|
-
provider: parts[0],
|
|
9
|
-
model: parts.slice(1).join("/")
|
|
10
|
-
};
|
|
11
|
-
return { model };
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Normalize runtime backend config for the wire format.
|
|
15
|
-
*
|
|
16
|
-
* Callers set `backend.profile` (named string or portable AgentProfile).
|
|
17
|
-
* This function generates the native `inlineProfile` shim automatically.
|
|
18
|
-
*/
|
|
19
|
-
function normalizeRuntimeBackendConfig(backend, options = {}) {
|
|
20
|
-
if (!backend && !options.model) return void 0;
|
|
21
|
-
if (backend && LEGACY_QUESTION_ALIAS_KEY in backend) throw new Error(`[sandbox-sdk] backend.${LEGACY_QUESTION_ALIAS_KEY} was removed. Use backend.interactions.question instead.`);
|
|
22
|
-
const portableProfile = backend?.profile && typeof backend.profile !== "string" ? backend.profile : void 0;
|
|
23
|
-
const inlineProfile = portableProfile ? toBackendProfile(portableProfile) : void 0;
|
|
24
|
-
const callerInlineProfile = backend?.inlineProfile;
|
|
25
|
-
if (callerInlineProfile && !inlineProfile) console.warn("[sandbox-sdk] backend.inlineProfile is deprecated. Use backend.profile (AgentPortableProfile) instead.");
|
|
26
|
-
if (inlineProfile && portableProfile) {
|
|
27
|
-
const reasoningEffort = portableProfile.model?.reasoningEffort ?? portableProfile.extensions?.[backend?.type ?? ""]?.reasoningEffort;
|
|
28
|
-
if (typeof reasoningEffort === "string" && reasoningEffort !== "auto" && reasoningEffort !== "none") inlineProfile.reasoningEffort = reasoningEffort;
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
...backend?.type ? { type: backend.type } : {},
|
|
32
|
-
...typeof backend?.profile === "string" ? { profile: backend.profile } : {},
|
|
33
|
-
...inlineProfile ? { inlineProfile } : callerInlineProfile ? { inlineProfile: callerInlineProfile } : {},
|
|
34
|
-
...backend?.model ? { model: backend.model } : options.model ? { model: parseModelString(options.model) } : {},
|
|
35
|
-
...backend?.server ? { server: backend.server } : {},
|
|
36
|
-
...backend?.interactions !== void 0 ? { interactions: backend.interactions } : {}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Permission keys the sidecar's strict `permission` schema accepts
|
|
41
|
-
* (apps/sidecar/src/schemas/agent-profile-schema.ts → permissionConfigSchema).
|
|
42
|
-
* Any other portable-permission key is a per-tool gate, not a permission, and
|
|
43
|
-
* is routed into `tools` instead of passed through — the sidecar's `.strict()`
|
|
44
|
-
* schema rejects unknown permission keys with `unrecognized_keys`.
|
|
45
|
-
*
|
|
46
|
-
* Name must not carry an UPPERCASE `SIDECAR_`/`ORCHESTRATOR_`-style prefix:
|
|
47
|
-
* obfuscate.sh runs `--rename-globals false`, so a module-global identifier
|
|
48
|
-
* ships verbatim in dist/, and verify-dist.sh bans those prefixes as
|
|
49
|
-
* closed-source leaks.
|
|
50
|
-
*/
|
|
51
|
-
const CANONICAL_PERMISSION_KEYS = new Set([
|
|
52
|
-
"edit",
|
|
53
|
-
"bash",
|
|
54
|
-
"webfetch",
|
|
55
|
-
"mcp",
|
|
56
|
-
"doom_loop",
|
|
57
|
-
"external_directory"
|
|
58
|
-
]);
|
|
59
|
-
function hasAnyProfileResource(resources) {
|
|
60
|
-
return !!(resources.files?.length || resources.tools?.length || resources.skills?.length || resources.agents?.length || resources.commands?.length || resources.instructions);
|
|
61
|
-
}
|
|
62
|
-
function validateProfileResources(profile) {
|
|
63
|
-
if (profile.resources !== void 0 && (profile.resources === null || typeof profile.resources !== "object" || Array.isArray(profile.resources))) throw new Error("backend.profile.resources must be an object when provided");
|
|
64
|
-
if (profile.resources?.plugins?.length) throw new Error("backend.profile.resources.plugins is not supported by the sandbox SDK profile contract; use backend-specific provider profiles for OpenCode plugin resources");
|
|
65
|
-
}
|
|
66
|
-
function toBackendProfile(profile) {
|
|
67
|
-
validateProfileResources(profile);
|
|
68
|
-
const permission = {};
|
|
69
|
-
const derivedTools = {};
|
|
70
|
-
for (const [rawKey, value] of Object.entries(profile.permissions ?? {})) {
|
|
71
|
-
const key = rawKey === "network" ? "webfetch" : rawKey;
|
|
72
|
-
if (CANONICAL_PERMISSION_KEYS.has(key)) permission[key] = value;
|
|
73
|
-
else if (typeof value === "string") derivedTools[key] = value !== "deny";
|
|
74
|
-
else console.warn(`[sandbox-sdk] dropping unsupported permission key "${rawKey}": not a canonical sidecar permission and not a string tool gate`);
|
|
75
|
-
}
|
|
76
|
-
const tools = {
|
|
77
|
-
...derivedTools,
|
|
78
|
-
...profile.tools ?? {}
|
|
79
|
-
};
|
|
80
|
-
const mcp = profile.mcp ? Object.fromEntries(Object.entries(profile.mcp).map(([name, config]) => {
|
|
81
|
-
const c = config;
|
|
82
|
-
const transport = c.transport;
|
|
83
|
-
const command = c.command;
|
|
84
|
-
const hasCommand = Array.isArray(command) ? command.length > 0 : typeof command === "string" && command.trim().length > 0;
|
|
85
|
-
const isRemote = transport === "http" || transport === "sse" || typeof c.url === "string" && !hasCommand;
|
|
86
|
-
const enabled = c.enabled;
|
|
87
|
-
const timeout = c.timeout;
|
|
88
|
-
if (isRemote) return [name, {
|
|
89
|
-
type: "remote",
|
|
90
|
-
url: c.url,
|
|
91
|
-
...c.headers ? { headers: c.headers } : {},
|
|
92
|
-
...enabled !== void 0 ? { enabled } : {},
|
|
93
|
-
...timeout !== void 0 ? { timeout } : {}
|
|
94
|
-
}];
|
|
95
|
-
return [name, {
|
|
96
|
-
type: "local",
|
|
97
|
-
command: [...Array.isArray(command) ? command : typeof command === "string" ? command.trim().split(/\s+/).filter(Boolean) : [], ...c.args ?? []],
|
|
98
|
-
...c.env ? { environment: c.env } : {},
|
|
99
|
-
...enabled !== void 0 ? { enabled } : {},
|
|
100
|
-
...timeout !== void 0 ? { timeout } : {}
|
|
101
|
-
}];
|
|
102
|
-
})) : void 0;
|
|
103
|
-
return {
|
|
104
|
-
name: profile.name,
|
|
105
|
-
model: profile.model?.default,
|
|
106
|
-
...profile.prompt?.systemPrompt ? { systemPrompt: profile.prompt.systemPrompt } : {},
|
|
107
|
-
...Object.keys(tools).length > 0 ? { tools } : {},
|
|
108
|
-
...profile.prompt?.instructions?.length ? { instructions: profile.prompt.instructions } : {},
|
|
109
|
-
...Object.keys(permission).length > 0 ? { permission } : {},
|
|
110
|
-
...mcp ? { mcp } : {},
|
|
111
|
-
...profile.connections?.length ? { connections: profile.connections } : {},
|
|
112
|
-
...profile.subagents ? { subagents: profile.subagents } : {},
|
|
113
|
-
...profile.resources && hasAnyProfileResource(profile.resources) ? { resources: profile.resources } : {},
|
|
114
|
-
...profile.hooks ? { hooks: profile.hooks } : {},
|
|
115
|
-
...profile.modes ? { modes: profile.modes } : {},
|
|
116
|
-
...profile.extensions ? { extensions: profile.extensions } : {}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Serialize a portable AgentProfile into the sidecar's canonical inline-profile
|
|
121
|
-
* wire shape (validated by inlineProfileSchema in
|
|
122
|
-
* apps/sidecar/src/schemas/agent-profile-schema.ts).
|
|
123
|
-
*
|
|
124
|
-
* Single choke point every product shares: streamPrompt →
|
|
125
|
-
* normalizeRuntimeBackendConfig → toBackendProfile. Exported so callers and the
|
|
126
|
-
* drift-guard test target one contract — the test parses this output with the
|
|
127
|
-
* sidecar's own schema, so any future schema tightening fails here first.
|
|
128
|
-
*/
|
|
129
|
-
function serializeForSidecar(profile) {
|
|
130
|
-
return toBackendProfile(profile);
|
|
131
|
-
}
|
|
132
|
-
//#endregion
|
|
133
4
|
//#region src/lib/sse-parser.ts
|
|
134
5
|
/**
|
|
135
6
|
* Parse a streaming SSE response body into an async iterable of
|
|
@@ -696,6 +567,13 @@ var SandboxSession = class SandboxSession {
|
|
|
696
567
|
});
|
|
697
568
|
}
|
|
698
569
|
/**
|
|
570
|
+
* Send a structured message through the session message endpoint. Model and
|
|
571
|
+
* message identifiers are translated to the runtime's wire names by the SDK.
|
|
572
|
+
*/
|
|
573
|
+
async sendMessage(request, options) {
|
|
574
|
+
return this.box._sessionSendMessage(this.id, request, options);
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
699
577
|
* Abort the session's in-flight execution; the session and its messages
|
|
700
578
|
* are preserved (this does not delete the session). Void-returning alias
|
|
701
579
|
* of `interrupt()` — use `interrupt()` when you need to know whether an
|
|
@@ -706,6 +584,10 @@ var SandboxSession = class SandboxSession {
|
|
|
706
584
|
async cancel() {
|
|
707
585
|
return this.box._sessionCancel(this.id);
|
|
708
586
|
}
|
|
587
|
+
/** Delete this session and its persisted runtime state. */
|
|
588
|
+
async delete() {
|
|
589
|
+
return this.box._sessionDelete(this.id);
|
|
590
|
+
}
|
|
709
591
|
/**
|
|
710
592
|
* Fork this session into a new queued session. The fork shares the
|
|
711
593
|
* parent workspace and copies conversation history up to `messageId`
|
|
@@ -755,6 +637,24 @@ var SandboxSession = class SandboxSession {
|
|
|
755
637
|
}
|
|
756
638
|
};
|
|
757
639
|
//#endregion
|
|
640
|
+
//#region src/task-session.ts
|
|
641
|
+
/** A background task session with isolated changeset operations. */
|
|
642
|
+
var SandboxTaskSession = class extends SandboxSession {
|
|
643
|
+
/** @internal Apps should call `box.taskSession(id)`. */
|
|
644
|
+
constructor(taskBox, id) {
|
|
645
|
+
super(taskBox, id);
|
|
646
|
+
this.taskBox = taskBox;
|
|
647
|
+
}
|
|
648
|
+
/** Read the task's isolated file changes. */
|
|
649
|
+
async changes() {
|
|
650
|
+
return this.taskBox._taskSessionChanges(this.id);
|
|
651
|
+
}
|
|
652
|
+
/** Apply all or a selected subset of the task's isolated file changes. */
|
|
653
|
+
async commit(options) {
|
|
654
|
+
return this.taskBox._taskSessionCommit(this.id, options);
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
//#endregion
|
|
758
658
|
//#region src/sandbox.ts
|
|
759
659
|
/**
|
|
760
660
|
* Sandbox Instance
|
|
@@ -1027,10 +927,15 @@ var SandboxInstance = class SandboxInstance {
|
|
|
1027
927
|
client;
|
|
1028
928
|
info;
|
|
1029
929
|
defaultRuntimeBackend;
|
|
930
|
+
runtime;
|
|
1030
931
|
constructor(client, info, defaultRuntimeBackend) {
|
|
1031
932
|
this.client = client;
|
|
1032
933
|
this.info = info;
|
|
1033
934
|
this.defaultRuntimeBackend = defaultRuntimeBackend;
|
|
935
|
+
this.runtime = new SandboxRuntimeApi({
|
|
936
|
+
ensureRunning: () => this.ensureRunning(),
|
|
937
|
+
fetch: (path, init) => this.runtimeFetch(path, init)
|
|
938
|
+
});
|
|
1034
939
|
}
|
|
1035
940
|
/** Unique sandbox identifier */
|
|
1036
941
|
get id() {
|
|
@@ -1447,11 +1352,15 @@ var SandboxInstance = class SandboxInstance {
|
|
|
1447
1352
|
*/
|
|
1448
1353
|
async write(path, content, options) {
|
|
1449
1354
|
await this.ensureRunning();
|
|
1450
|
-
const
|
|
1355
|
+
const params = new URLSearchParams();
|
|
1356
|
+
if (options?.sessionId) params.set("sessionId", options.sessionId);
|
|
1357
|
+
const query = params.toString();
|
|
1358
|
+
const response = await this.runtimeFetch(`/files/write${query ? `?${query}` : ""}`, {
|
|
1451
1359
|
method: "POST",
|
|
1452
1360
|
body: JSON.stringify({
|
|
1453
1361
|
path,
|
|
1454
1362
|
content,
|
|
1363
|
+
encoding: options?.encoding,
|
|
1455
1364
|
mode: options?.mode
|
|
1456
1365
|
})
|
|
1457
1366
|
});
|
|
@@ -1459,6 +1368,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
1459
1368
|
const body = await response.text();
|
|
1460
1369
|
throw parseErrorResponse(response.status, body, void 0, response.headers);
|
|
1461
1370
|
}
|
|
1371
|
+
return (await response.json()).data;
|
|
1462
1372
|
}
|
|
1463
1373
|
/**
|
|
1464
1374
|
* Write many files in one paced, retry-aware batch — see
|
|
@@ -2149,6 +2059,22 @@ var SandboxInstance = class SandboxInstance {
|
|
|
2149
2059
|
after: match.after
|
|
2150
2060
|
};
|
|
2151
2061
|
}
|
|
2062
|
+
/** Basic health reported by the runtime inside this sandbox. */
|
|
2063
|
+
async runtimeHealth() {
|
|
2064
|
+
return this.runtime.health();
|
|
2065
|
+
}
|
|
2066
|
+
/** Return the runtime's current listening-port snapshot. */
|
|
2067
|
+
async ports() {
|
|
2068
|
+
return this.runtime.ports();
|
|
2069
|
+
}
|
|
2070
|
+
/** Interactive terminal operations for this runtime. */
|
|
2071
|
+
get terminals() {
|
|
2072
|
+
return this.runtime.terminals;
|
|
2073
|
+
}
|
|
2074
|
+
/** List profiles installed in this sandbox runtime. */
|
|
2075
|
+
async listProfiles() {
|
|
2076
|
+
return this.runtime.profiles();
|
|
2077
|
+
}
|
|
2152
2078
|
/**
|
|
2153
2079
|
* Live whole-sandbox resource usage (memory + CPU) from the container cgroup.
|
|
2154
2080
|
*
|
|
@@ -2383,6 +2309,8 @@ var SandboxInstance = class SandboxInstance {
|
|
|
2383
2309
|
return {
|
|
2384
2310
|
supportsWriteMode: true,
|
|
2385
2311
|
read: (path) => this.read(path),
|
|
2312
|
+
readBatch: (paths, options) => this.fsReadBatch(paths, options),
|
|
2313
|
+
tree: (path, options) => this.fsTree(path, options),
|
|
2386
2314
|
write: (path, content, options) => this.write(path, content, options),
|
|
2387
2315
|
writeMany: (files, options) => this.writeMany(files, options),
|
|
2388
2316
|
search: (query, options) => this.search(query, options),
|
|
@@ -2397,6 +2325,12 @@ var SandboxInstance = class SandboxInstance {
|
|
|
2397
2325
|
exists: (path) => this.fsExists(path)
|
|
2398
2326
|
};
|
|
2399
2327
|
}
|
|
2328
|
+
async fsReadBatch(paths, options = {}) {
|
|
2329
|
+
return this.runtime.readFiles(paths, options);
|
|
2330
|
+
}
|
|
2331
|
+
async fsTree(path, options = {}) {
|
|
2332
|
+
return this.runtime.fileTree(path, options);
|
|
2333
|
+
}
|
|
2400
2334
|
async fsUpload(localPath, remotePath, options) {
|
|
2401
2335
|
await this.ensureRunning();
|
|
2402
2336
|
const fs = await import("node:fs/promises");
|
|
@@ -2549,8 +2483,21 @@ var SandboxInstance = class SandboxInstance {
|
|
|
2549
2483
|
}
|
|
2550
2484
|
async fsDelete(path, options) {
|
|
2551
2485
|
await this.ensureRunning();
|
|
2486
|
+
if (options?.sessionId && !options.recursive) {
|
|
2487
|
+
const params = new URLSearchParams({ sessionId: options.sessionId });
|
|
2488
|
+
const response = await this.runtimeFetch(`/files/delete?${params}`, {
|
|
2489
|
+
method: "POST",
|
|
2490
|
+
body: JSON.stringify({ path })
|
|
2491
|
+
});
|
|
2492
|
+
if (!response.ok) {
|
|
2493
|
+
const body = await response.text();
|
|
2494
|
+
throw parseErrorResponse(response.status, body, void 0, response.headers);
|
|
2495
|
+
}
|
|
2496
|
+
return;
|
|
2497
|
+
}
|
|
2552
2498
|
const params = new URLSearchParams();
|
|
2553
2499
|
if (options?.recursive) params.set("recursive", "true");
|
|
2500
|
+
if (options?.sessionId) params.set("sessionId", options.sessionId);
|
|
2554
2501
|
const query = params.toString();
|
|
2555
2502
|
const url = query ? `/fs${path}?${query}` : `/fs${path}`;
|
|
2556
2503
|
const response = await this.runtimeFetch(url, { method: "DELETE" });
|
|
@@ -4132,6 +4079,30 @@ var SandboxInstance = class SandboxInstance {
|
|
|
4132
4079
|
session(id) {
|
|
4133
4080
|
return new SandboxSession(this, id);
|
|
4134
4081
|
}
|
|
4082
|
+
/** Create an agent session and return both its handle and initial metadata. */
|
|
4083
|
+
async createSession(options) {
|
|
4084
|
+
const info = await this.runtime.createSession(options);
|
|
4085
|
+
return {
|
|
4086
|
+
session: this.session(info.id),
|
|
4087
|
+
info
|
|
4088
|
+
};
|
|
4089
|
+
}
|
|
4090
|
+
/** Delete an agent session by id. */
|
|
4091
|
+
async deleteSession(id) {
|
|
4092
|
+
return this._sessionDelete(id);
|
|
4093
|
+
}
|
|
4094
|
+
/** Get a lazy background-task session reference. */
|
|
4095
|
+
taskSession(id) {
|
|
4096
|
+
return new SandboxTaskSession(this, id);
|
|
4097
|
+
}
|
|
4098
|
+
/** Create a background task session. Dispatch work with `session.sendMessage()`. */
|
|
4099
|
+
async createTaskSession(options) {
|
|
4100
|
+
const info = await this.runtime.createTaskSession(options);
|
|
4101
|
+
return {
|
|
4102
|
+
session: this.taskSession(info.id),
|
|
4103
|
+
info
|
|
4104
|
+
};
|
|
4105
|
+
}
|
|
4135
4106
|
/**
|
|
4136
4107
|
* List sessions on this sandbox, optionally filtering by status. Returns
|
|
4137
4108
|
* `SandboxSession` instances paired with their last-known
|
|
@@ -4239,6 +4210,22 @@ var SandboxInstance = class SandboxInstance {
|
|
|
4239
4210
|
metadata: m.info.metadata
|
|
4240
4211
|
}));
|
|
4241
4212
|
}
|
|
4213
|
+
/** @internal — invoked by SandboxSession.sendMessage(). */
|
|
4214
|
+
async _sessionSendMessage(id, request, options = {}) {
|
|
4215
|
+
return this.runtime.sendSessionMessage(id, request, options);
|
|
4216
|
+
}
|
|
4217
|
+
/** @internal — invoked by SandboxSession.delete(). */
|
|
4218
|
+
async _sessionDelete(id) {
|
|
4219
|
+
return this.runtime.deleteSession(id);
|
|
4220
|
+
}
|
|
4221
|
+
/** @internal — invoked by SandboxTaskSession.changes(). */
|
|
4222
|
+
async _taskSessionChanges(id) {
|
|
4223
|
+
return this.runtime.taskSessionChanges(id);
|
|
4224
|
+
}
|
|
4225
|
+
/** @internal — invoked by SandboxTaskSession.commit(). */
|
|
4226
|
+
async _taskSessionCommit(id, options = {}) {
|
|
4227
|
+
return this.runtime.commitTaskSession(id, options);
|
|
4228
|
+
}
|
|
4242
4229
|
async _sessionFork(id, opts = {}) {
|
|
4243
4230
|
await this.ensureRunning();
|
|
4244
4231
|
const body = {};
|
|
@@ -4354,6 +4341,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
4354
4341
|
* gates ProductTokenIssuer-issued JWTs — no new sidecar surface.
|
|
4355
4342
|
*/
|
|
4356
4343
|
async mintScopedToken(opts) {
|
|
4344
|
+
if ((opts.scope === "session" || opts.scope === "session-runtime") && !opts.sessionId) throw new ValidationError(`${opts.scope} scope requires a sessionId`);
|
|
4357
4345
|
const response = await this.client.fetch(`/v1/sandboxes/${encodeURIComponent(this.id)}/scoped-token`, {
|
|
4358
4346
|
method: "POST",
|
|
4359
4347
|
headers: { "Content-Type": "application/json" },
|
|
@@ -4603,29 +4591,6 @@ function settleTurnDrive(result) {
|
|
|
4603
4591
|
result
|
|
4604
4592
|
};
|
|
4605
4593
|
}
|
|
4606
|
-
function normalizeSessionInfo(raw) {
|
|
4607
|
-
const id = raw.id;
|
|
4608
|
-
if (typeof id !== "string") return null;
|
|
4609
|
-
const status = raw.status || "running";
|
|
4610
|
-
return {
|
|
4611
|
-
id,
|
|
4612
|
-
parentId: typeof raw.parentID === "string" ? raw.parentID : typeof raw.parentId === "string" ? raw.parentId : void 0,
|
|
4613
|
-
status: [
|
|
4614
|
-
"queued",
|
|
4615
|
-
"running",
|
|
4616
|
-
"completed",
|
|
4617
|
-
"failed",
|
|
4618
|
-
"cancelled"
|
|
4619
|
-
].includes(status) ? status : "running",
|
|
4620
|
-
backend: typeof raw.backendType === "string" ? raw.backendType : typeof raw.backend === "string" ? raw.backend : void 0,
|
|
4621
|
-
model: typeof raw.model === "string" ? raw.model : void 0,
|
|
4622
|
-
promptCount: typeof raw.promptCount === "number" ? raw.promptCount : void 0,
|
|
4623
|
-
createdAt: raw.createdAt ? new Date(raw.createdAt) : void 0,
|
|
4624
|
-
startedAt: raw.startedAt ? new Date(raw.startedAt) : void 0,
|
|
4625
|
-
endedAt: raw.endedAt ? new Date(raw.endedAt) : void 0,
|
|
4626
|
-
raw
|
|
4627
|
-
};
|
|
4628
|
-
}
|
|
4629
4594
|
var DirectRuntimeHttpClient = class {
|
|
4630
4595
|
baseClient;
|
|
4631
4596
|
sandboxId;
|
|
@@ -4692,4 +4657,4 @@ function quoteForShell(value) {
|
|
|
4692
4657
|
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
4693
4658
|
}
|
|
4694
4659
|
//#endregion
|
|
4695
|
-
export {
|
|
4660
|
+
export { InteractiveSessionHandle as a, getSandboxEventText as c, exportTraceBundle as d, otelTraceIdForTangleTrace as f, parseSSEStream as g, encodeTextForWire as h, SandboxSession as i, normalizeConnection as l, encodePromptForWire as m, normalizeStartupDiagnostics as n, applySandboxEventText as o, toOtelJson as p, SandboxTaskSession as r, collectAgentResponseText as s, SandboxInstance as t, buildTraceExportPayload as u };
|
|
@@ -163,21 +163,25 @@ var SessionGatewayClient = class {
|
|
|
163
163
|
connectWebSocket() {
|
|
164
164
|
const url = new URL(this.config.url);
|
|
165
165
|
url.searchParams.set("token", this.currentToken);
|
|
166
|
-
|
|
167
|
-
this.ws
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
166
|
+
const socket = new WebSocket(url.toString());
|
|
167
|
+
this.ws = socket;
|
|
168
|
+
socket.onopen = () => {
|
|
169
|
+
if (this.ws === socket) this.handleOpen();
|
|
170
|
+
};
|
|
171
|
+
socket.onclose = (event) => this.handleClose(socket, event.code, event.reason);
|
|
172
|
+
socket.onerror = (_event) => {};
|
|
173
|
+
socket.onmessage = (event) => {
|
|
174
|
+
if (this.ws === socket) this.handleMessage(event.data);
|
|
175
|
+
};
|
|
171
176
|
}
|
|
172
177
|
/**
|
|
173
178
|
* Disconnect from the session gateway.
|
|
174
179
|
*/
|
|
175
180
|
disconnect() {
|
|
176
181
|
this.cleanup();
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
182
|
+
const socket = this.ws;
|
|
183
|
+
this.ws = null;
|
|
184
|
+
if (socket) socket.close(1e3, "Client disconnect");
|
|
181
185
|
this.setState("disconnected");
|
|
182
186
|
}
|
|
183
187
|
/**
|
|
@@ -338,7 +342,9 @@ var SessionGatewayClient = class {
|
|
|
338
342
|
this.handlers.onReconnect?.();
|
|
339
343
|
}
|
|
340
344
|
}
|
|
341
|
-
handleClose(code, reason) {
|
|
345
|
+
handleClose(socket, code, reason) {
|
|
346
|
+
if (this.ws !== socket) return;
|
|
347
|
+
this.ws = null;
|
|
342
348
|
this.cleanup();
|
|
343
349
|
this.handlers.onDisconnect?.(code, reason);
|
|
344
350
|
if (this.config.autoReconnect && this.reconnectAttempts < this.config.maxReconnectAttempts) {
|
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-DzEUjav-.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-BdRRHMpX.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 };
|