@tangle-network/sandbox 0.10.2 → 0.10.3
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/LICENSE +11 -0
- package/dist/agent/index.d.ts +3 -2
- package/dist/auth/index.d.ts +1 -1
- package/dist/{client-8wOu9raV.d.ts → client-Cr39zlgv.d.ts} +2 -1
- package/dist/{client-B3oM6E-L.js → client-Df1K1d_Q.js} +1 -1
- 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-DS4SOkKG.d.ts → index-DzEUjav-.d.ts} +2 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.js +5 -4
- 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-CeimsfC8.js → sandbox-CxBHIBV1.js} +3 -393
- package/dist/tangle/index.d.ts +1 -1
- package/dist/tangle/index.js +1 -1
- package/dist/{tangle-DayyZe-i.js → tangle-BdRRHMpX.js} +1 -1
- package/dist/{sandbox-Bm2C9Phd.d.ts → types-Cmpv-ox_.d.ts} +6 -1491
- package/package.json +44 -80
- /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,159 +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
|
-
...backend?.metadata !== void 0 ? { metadata: backend.metadata } : {}
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Permission keys the sidecar's strict `permission` schema accepts
|
|
42
|
-
* (apps/sidecar/src/schemas/agent-profile-schema.ts → permissionConfigSchema).
|
|
43
|
-
* Any other portable-permission key is a per-tool gate, not a permission, and
|
|
44
|
-
* is routed into `tools` instead of passed through — the sidecar's `.strict()`
|
|
45
|
-
* schema rejects unknown permission keys with `unrecognized_keys`.
|
|
46
|
-
*
|
|
47
|
-
* Name must not carry an UPPERCASE `SIDECAR_`/`ORCHESTRATOR_`-style prefix:
|
|
48
|
-
* obfuscate.sh runs `--rename-globals false`, so a module-global identifier
|
|
49
|
-
* ships verbatim in dist/, and verify-dist.sh bans those prefixes as
|
|
50
|
-
* closed-source leaks.
|
|
51
|
-
*/
|
|
52
|
-
const CANONICAL_PERMISSION_KEYS = new Set([
|
|
53
|
-
"edit",
|
|
54
|
-
"bash",
|
|
55
|
-
"webfetch",
|
|
56
|
-
"mcp",
|
|
57
|
-
"doom_loop",
|
|
58
|
-
"external_directory"
|
|
59
|
-
]);
|
|
60
|
-
function hasAnyProfileResource(resources) {
|
|
61
|
-
return !!(resources.files?.length || resources.tools?.length || resources.skills?.length || resources.agents?.length || resources.commands?.length || resources.instructions);
|
|
62
|
-
}
|
|
63
|
-
function validateProfileResources(profile) {
|
|
64
|
-
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");
|
|
65
|
-
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");
|
|
66
|
-
}
|
|
67
|
-
function toBackendProfile(profile) {
|
|
68
|
-
validateProfileResources(profile);
|
|
69
|
-
const permission = {};
|
|
70
|
-
const derivedTools = {};
|
|
71
|
-
for (const [rawKey, value] of Object.entries(profile.permissions ?? {})) {
|
|
72
|
-
const key = rawKey === "network" ? "webfetch" : rawKey;
|
|
73
|
-
if (CANONICAL_PERMISSION_KEYS.has(key)) permission[key] = value;
|
|
74
|
-
else if (typeof value === "string") derivedTools[key] = value !== "deny";
|
|
75
|
-
else console.warn(`[sandbox-sdk] dropping unsupported permission key "${rawKey}": not a canonical sidecar permission and not a string tool gate`);
|
|
76
|
-
}
|
|
77
|
-
const tools = {
|
|
78
|
-
...derivedTools,
|
|
79
|
-
...profile.tools ?? {}
|
|
80
|
-
};
|
|
81
|
-
const mcp = profile.mcp ? Object.fromEntries(Object.entries(profile.mcp).map(([name, config]) => {
|
|
82
|
-
const c = config;
|
|
83
|
-
const transport = c.transport;
|
|
84
|
-
const command = c.command;
|
|
85
|
-
const hasCommand = Array.isArray(command) ? command.length > 0 : typeof command === "string" && command.trim().length > 0;
|
|
86
|
-
const isRemote = transport === "http" || transport === "sse" || typeof c.url === "string" && !hasCommand;
|
|
87
|
-
const enabled = c.enabled;
|
|
88
|
-
const timeout = c.timeout;
|
|
89
|
-
if (isRemote) return [name, {
|
|
90
|
-
type: "remote",
|
|
91
|
-
url: c.url,
|
|
92
|
-
...c.headers ? { headers: c.headers } : {},
|
|
93
|
-
...enabled !== void 0 ? { enabled } : {},
|
|
94
|
-
...timeout !== void 0 ? { timeout } : {}
|
|
95
|
-
}];
|
|
96
|
-
return [name, {
|
|
97
|
-
type: "local",
|
|
98
|
-
command: [...Array.isArray(command) ? command : typeof command === "string" ? command.trim().split(/\s+/).filter(Boolean) : [], ...c.args ?? []],
|
|
99
|
-
...c.env ? { environment: c.env } : {},
|
|
100
|
-
...enabled !== void 0 ? { enabled } : {},
|
|
101
|
-
...timeout !== void 0 ? { timeout } : {}
|
|
102
|
-
}];
|
|
103
|
-
})) : void 0;
|
|
104
|
-
const openCodeExtension = profile.extensions?.opencode;
|
|
105
|
-
const plugins = openCodeExtension?.plugins;
|
|
106
|
-
if (plugins !== void 0 && (!Array.isArray(plugins) || plugins.some((plugin) => typeof plugin !== "string" || !plugin.trim()))) throw new Error("backend.profile.extensions.opencode.plugins must be an array of non-empty package names");
|
|
107
|
-
const commands = openCodeExtension?.commands;
|
|
108
|
-
if (commands !== void 0 && (commands === null || typeof commands !== "object" || Array.isArray(commands))) throw new Error("backend.profile.extensions.opencode.commands must be an object");
|
|
109
|
-
const profileExtends = openCodeExtension?.extends;
|
|
110
|
-
if (profileExtends !== void 0 && typeof profileExtends !== "string" && (!Array.isArray(profileExtends) || profileExtends.some((entry) => typeof entry !== "string" || !entry.trim()))) throw new Error("backend.profile.extensions.opencode.extends must be a profile name or array of profile names");
|
|
111
|
-
const agents = profile.subagents ? Object.fromEntries(Object.entries(profile.subagents).map(([name, subagent]) => [name, {
|
|
112
|
-
description: subagent.description,
|
|
113
|
-
prompt: subagent.prompt,
|
|
114
|
-
model: subagent.model,
|
|
115
|
-
tools: subagent.tools,
|
|
116
|
-
permission: subagent.permissions,
|
|
117
|
-
maxSteps: subagent.maxSteps,
|
|
118
|
-
...subagent.metadata ?? {}
|
|
119
|
-
}])) : void 0;
|
|
120
|
-
return {
|
|
121
|
-
name: profile.name,
|
|
122
|
-
description: profile.description,
|
|
123
|
-
version: profile.version,
|
|
124
|
-
tags: profile.tags,
|
|
125
|
-
...profileExtends ? { extends: profileExtends } : {},
|
|
126
|
-
model: profile.model?.default,
|
|
127
|
-
small_model: profile.model?.small,
|
|
128
|
-
...profile.prompt?.systemPrompt ? { systemPrompt: profile.prompt.systemPrompt } : {},
|
|
129
|
-
...Object.keys(tools).length > 0 ? { tools } : {},
|
|
130
|
-
...profile.prompt?.instructions?.length ? { instructions: profile.prompt.instructions } : {},
|
|
131
|
-
...Object.keys(permission).length > 0 ? { permission } : {},
|
|
132
|
-
...mcp ? { mcp } : {},
|
|
133
|
-
...profile.connections?.length ? { connections: profile.connections } : {},
|
|
134
|
-
...agents ? { agent: agents } : {},
|
|
135
|
-
...profile.resources && hasAnyProfileResource(profile.resources) ? { resources: profile.resources } : {},
|
|
136
|
-
...profile.hooks ? { hooks: profile.hooks } : {},
|
|
137
|
-
...profile.modes ? { modes: profile.modes } : {},
|
|
138
|
-
...commands ? { command: commands } : {},
|
|
139
|
-
...plugins?.length ? { plugin: plugins } : {},
|
|
140
|
-
...profile.extensions ? { extensions: profile.extensions } : {}
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Serialize a portable AgentProfile into the sidecar's canonical inline-profile
|
|
145
|
-
* wire shape (validated by inlineProfileSchema in
|
|
146
|
-
* apps/sidecar/src/schemas/agent-profile-schema.ts).
|
|
147
|
-
*
|
|
148
|
-
* Single choke point every product shares: streamPrompt →
|
|
149
|
-
* normalizeRuntimeBackendConfig → toBackendProfile. Exported so callers and the
|
|
150
|
-
* drift-guard test target one contract — the test parses this output with the
|
|
151
|
-
* sidecar's own schema, so any future schema tightening fails here first.
|
|
152
|
-
*/
|
|
153
|
-
function serializeForSidecar(profile) {
|
|
154
|
-
return toBackendProfile(profile);
|
|
155
|
-
}
|
|
156
|
-
//#endregion
|
|
157
4
|
//#region src/lib/sse-parser.ts
|
|
158
5
|
/**
|
|
159
6
|
* Parse a streaming SSE response body into an async iterable of
|
|
@@ -599,244 +446,6 @@ function collectAgentResponseText(events) {
|
|
|
599
446
|
return responseText && responseText.trim().length > 0 ? responseText : void 0;
|
|
600
447
|
}
|
|
601
448
|
//#endregion
|
|
602
|
-
//#region src/runtime-api.ts
|
|
603
|
-
/** Internal typed client for routes served by a sandbox runtime. */
|
|
604
|
-
var SandboxRuntimeApi = class {
|
|
605
|
-
terminals;
|
|
606
|
-
constructor(transport) {
|
|
607
|
-
this.transport = transport;
|
|
608
|
-
this.terminals = {
|
|
609
|
-
create: (options, request) => this.createTerminal(options, request),
|
|
610
|
-
input: (terminalId, data, request) => this.writeTerminal(terminalId, data, request),
|
|
611
|
-
list: () => this.listTerminals(),
|
|
612
|
-
get: (terminalId) => this.getTerminal(terminalId)
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
async health() {
|
|
616
|
-
await this.transport.ensureRunning();
|
|
617
|
-
return this.json("/health", { method: "GET" });
|
|
618
|
-
}
|
|
619
|
-
async ports() {
|
|
620
|
-
await this.transport.ensureRunning();
|
|
621
|
-
return (await this.json("/ports", { method: "GET" })).data?.ports ?? [];
|
|
622
|
-
}
|
|
623
|
-
async profiles() {
|
|
624
|
-
await this.transport.ensureRunning();
|
|
625
|
-
return this.json("/profiles", { method: "GET" });
|
|
626
|
-
}
|
|
627
|
-
async readFiles(paths, options = {}) {
|
|
628
|
-
if (paths.length === 0) return {
|
|
629
|
-
files: [],
|
|
630
|
-
errors: [],
|
|
631
|
-
stats: {
|
|
632
|
-
requested: 0,
|
|
633
|
-
succeeded: 0,
|
|
634
|
-
failed: 0
|
|
635
|
-
}
|
|
636
|
-
};
|
|
637
|
-
await this.transport.ensureRunning();
|
|
638
|
-
const files = [];
|
|
639
|
-
const errors = [];
|
|
640
|
-
let requested = 0;
|
|
641
|
-
let succeeded = 0;
|
|
642
|
-
let failed = 0;
|
|
643
|
-
for (let offset = 0; offset < paths.length; offset += 100) {
|
|
644
|
-
const chunk = paths.slice(offset, offset + 100);
|
|
645
|
-
const params = new URLSearchParams();
|
|
646
|
-
if (options.sessionId) params.set("sessionId", options.sessionId);
|
|
647
|
-
const query = params.toString();
|
|
648
|
-
const payload = await this.json(`/files/read-batch${query ? `?${query}` : ""}`, {
|
|
649
|
-
method: "POST",
|
|
650
|
-
body: JSON.stringify({
|
|
651
|
-
paths: chunk,
|
|
652
|
-
...options.encoding ? { encoding: options.encoding } : {}
|
|
653
|
-
})
|
|
654
|
-
});
|
|
655
|
-
for (const [path, result] of Object.entries(payload.data.files)) if (result.success) files.push({
|
|
656
|
-
path,
|
|
657
|
-
content: result.content,
|
|
658
|
-
encoding: result.encoding,
|
|
659
|
-
hash: result.hash,
|
|
660
|
-
size: result.size,
|
|
661
|
-
mtime: result.mtime
|
|
662
|
-
});
|
|
663
|
-
else errors.push({
|
|
664
|
-
path,
|
|
665
|
-
error: result.error,
|
|
666
|
-
code: result.code
|
|
667
|
-
});
|
|
668
|
-
const results = Object.values(payload.data.files);
|
|
669
|
-
requested += payload.data.stats?.requested ?? chunk.length;
|
|
670
|
-
succeeded += payload.data.stats?.succeeded ?? results.filter((entry) => entry.success).length;
|
|
671
|
-
failed += payload.data.stats?.failed ?? results.filter((entry) => !entry.success).length;
|
|
672
|
-
}
|
|
673
|
-
return {
|
|
674
|
-
files,
|
|
675
|
-
errors,
|
|
676
|
-
stats: {
|
|
677
|
-
requested,
|
|
678
|
-
succeeded,
|
|
679
|
-
failed
|
|
680
|
-
}
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
async fileTree(path, options = {}) {
|
|
684
|
-
if (options.maxDepth !== void 0 && (!Number.isInteger(options.maxDepth) || options.maxDepth < 1 || options.maxDepth > 20)) throw new ValidationError("maxDepth must be an integer between 1 and 20");
|
|
685
|
-
await this.transport.ensureRunning();
|
|
686
|
-
const params = new URLSearchParams({ path });
|
|
687
|
-
if (options.maxDepth !== void 0) params.set("maxDepth", String(options.maxDepth));
|
|
688
|
-
if (options.sessionId) params.set("sessionId", options.sessionId);
|
|
689
|
-
return (await this.json(`/files/tree?${params}`, { method: "GET" })).data;
|
|
690
|
-
}
|
|
691
|
-
async createSession(options) {
|
|
692
|
-
await this.transport.ensureRunning();
|
|
693
|
-
const info = normalizeSessionInfo(await this.json("/agents/sessions", {
|
|
694
|
-
method: "POST",
|
|
695
|
-
body: JSON.stringify({
|
|
696
|
-
...options.title !== void 0 ? { title: options.title } : {},
|
|
697
|
-
...options.parentId !== void 0 ? { parentID: options.parentId } : {},
|
|
698
|
-
backend: normalizeRuntimeBackendConfig(options.backend)
|
|
699
|
-
})
|
|
700
|
-
}));
|
|
701
|
-
if (!info) throw new ServerError("Session creation response missing session id", 502, {
|
|
702
|
-
endpoint: "/agents/sessions",
|
|
703
|
-
origin: "runtime"
|
|
704
|
-
});
|
|
705
|
-
return info;
|
|
706
|
-
}
|
|
707
|
-
async createTaskSession(options) {
|
|
708
|
-
await this.transport.ensureRunning();
|
|
709
|
-
const info = await this.json("/tasks", {
|
|
710
|
-
method: "POST",
|
|
711
|
-
body: JSON.stringify({
|
|
712
|
-
sessionId: options.sessionId,
|
|
713
|
-
backend: normalizeRuntimeBackendConfig(options.backend),
|
|
714
|
-
title: options.title,
|
|
715
|
-
...options.parentSessionId !== void 0 ? { parentSessionId: options.parentSessionId } : {},
|
|
716
|
-
...options.profile !== void 0 ? { profile: options.profile } : {},
|
|
717
|
-
...options.isolateFileWrites !== void 0 ? { isolateFileWrites: options.isolateFileWrites } : {}
|
|
718
|
-
})
|
|
719
|
-
});
|
|
720
|
-
if (!info.id) throw new ServerError("Task session creation response missing session id", 502, {
|
|
721
|
-
endpoint: "/tasks",
|
|
722
|
-
origin: "runtime"
|
|
723
|
-
});
|
|
724
|
-
return info;
|
|
725
|
-
}
|
|
726
|
-
async sendSessionMessage(id, request, options = {}) {
|
|
727
|
-
if (options.timeoutMs !== void 0 && options.timeoutMs <= 0) throw new ValidationError("timeoutMs must be greater than zero");
|
|
728
|
-
await this.transport.ensureRunning();
|
|
729
|
-
const headers = new Headers({ "x-no-retry": "true" });
|
|
730
|
-
if (options.credentials?.apiKey) headers.set("X-Backend-Api-Key", options.credentials.apiKey);
|
|
731
|
-
if (options.credentials?.baseUrl) headers.set("X-Backend-Base-Url", options.credentials.baseUrl);
|
|
732
|
-
const timeoutSignal = options.timeoutMs !== void 0 ? AbortSignal.timeout(options.timeoutMs) : void 0;
|
|
733
|
-
const signal = options.signal && timeoutSignal ? AbortSignal.any([options.signal, timeoutSignal]) : options.signal ?? timeoutSignal;
|
|
734
|
-
return this.json(`/agents/sessions/${encodeURIComponent(id)}/messages`, {
|
|
735
|
-
method: "POST",
|
|
736
|
-
headers,
|
|
737
|
-
signal,
|
|
738
|
-
body: JSON.stringify({
|
|
739
|
-
...request.messageId !== void 0 ? { messageID: request.messageId } : {},
|
|
740
|
-
parts: request.parts,
|
|
741
|
-
...request.system !== void 0 ? { system: request.system } : {},
|
|
742
|
-
...request.agent !== void 0 ? { agent: request.agent } : {},
|
|
743
|
-
...request.model !== void 0 ? { model: {
|
|
744
|
-
providerID: request.model.providerId,
|
|
745
|
-
modelID: request.model.modelId
|
|
746
|
-
} } : {},
|
|
747
|
-
...request.reasoningEffort !== void 0 ? { reasoningEffort: request.reasoningEffort } : {},
|
|
748
|
-
...request.turnId !== void 0 ? { turnId: request.turnId } : {},
|
|
749
|
-
...request.interactions !== void 0 ? { interactions: request.interactions } : {}
|
|
750
|
-
})
|
|
751
|
-
});
|
|
752
|
-
}
|
|
753
|
-
async deleteSession(id) {
|
|
754
|
-
await this.transport.ensureRunning();
|
|
755
|
-
await this.request(`/agents/sessions/${encodeURIComponent(id)}`, { method: "DELETE" });
|
|
756
|
-
}
|
|
757
|
-
async taskSessionChanges(id) {
|
|
758
|
-
await this.transport.ensureRunning();
|
|
759
|
-
return this.json(`/tasks/${encodeURIComponent(id)}/changes`, { method: "GET" });
|
|
760
|
-
}
|
|
761
|
-
async commitTaskSession(id, options = {}) {
|
|
762
|
-
await this.transport.ensureRunning();
|
|
763
|
-
return this.json(`/tasks/${encodeURIComponent(id)}/changes`, {
|
|
764
|
-
method: "POST",
|
|
765
|
-
body: JSON.stringify({
|
|
766
|
-
...options.message !== void 0 ? { message: options.message } : {},
|
|
767
|
-
...options.files !== void 0 ? { files: options.files } : {}
|
|
768
|
-
})
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
async createTerminal(options = {}, request = {}) {
|
|
772
|
-
await this.transport.ensureRunning();
|
|
773
|
-
const params = new URLSearchParams();
|
|
774
|
-
if (request.sessionId) params.set("sessionId", request.sessionId);
|
|
775
|
-
const query = params.toString();
|
|
776
|
-
return (await this.json(`/terminals${query ? `?${query}` : ""}`, {
|
|
777
|
-
method: "POST",
|
|
778
|
-
body: JSON.stringify(options)
|
|
779
|
-
})).data;
|
|
780
|
-
}
|
|
781
|
-
async writeTerminal(terminalId, data, request = {}) {
|
|
782
|
-
await this.transport.ensureRunning();
|
|
783
|
-
const params = new URLSearchParams();
|
|
784
|
-
if (request.sessionId) params.set("sessionId", request.sessionId);
|
|
785
|
-
const query = params.toString();
|
|
786
|
-
await this.request(`/terminals/${encodeURIComponent(terminalId)}/input${query ? `?${query}` : ""}`, {
|
|
787
|
-
method: "POST",
|
|
788
|
-
body: JSON.stringify({ data })
|
|
789
|
-
});
|
|
790
|
-
}
|
|
791
|
-
async listTerminals() {
|
|
792
|
-
await this.transport.ensureRunning();
|
|
793
|
-
return (await this.json("/terminals", { method: "GET" })).data ?? [];
|
|
794
|
-
}
|
|
795
|
-
async getTerminal(terminalId) {
|
|
796
|
-
await this.transport.ensureRunning();
|
|
797
|
-
const response = await this.transport.fetch(`/terminals/${encodeURIComponent(terminalId)}`, { method: "GET" });
|
|
798
|
-
if (response.status === 404) return null;
|
|
799
|
-
await this.assertOk(response);
|
|
800
|
-
return (await response.json()).data;
|
|
801
|
-
}
|
|
802
|
-
async json(path, init) {
|
|
803
|
-
return await (await this.request(path, init)).json();
|
|
804
|
-
}
|
|
805
|
-
async request(path, init) {
|
|
806
|
-
const response = await this.transport.fetch(path, init);
|
|
807
|
-
await this.assertOk(response);
|
|
808
|
-
return response;
|
|
809
|
-
}
|
|
810
|
-
async assertOk(response) {
|
|
811
|
-
if (response.ok) return;
|
|
812
|
-
const body = await response.text();
|
|
813
|
-
throw parseErrorResponse(response.status, body, void 0, response.headers);
|
|
814
|
-
}
|
|
815
|
-
};
|
|
816
|
-
function normalizeSessionInfo(raw) {
|
|
817
|
-
const id = raw.id;
|
|
818
|
-
if (typeof id !== "string") return null;
|
|
819
|
-
const status = raw.status || "running";
|
|
820
|
-
return {
|
|
821
|
-
id,
|
|
822
|
-
parentId: typeof raw.parentID === "string" ? raw.parentID : typeof raw.parentId === "string" ? raw.parentId : void 0,
|
|
823
|
-
status: [
|
|
824
|
-
"queued",
|
|
825
|
-
"running",
|
|
826
|
-
"completed",
|
|
827
|
-
"failed",
|
|
828
|
-
"cancelled"
|
|
829
|
-
].includes(status) ? status : "running",
|
|
830
|
-
backend: typeof raw.backendType === "string" ? raw.backendType : typeof raw.backend === "string" ? raw.backend : void 0,
|
|
831
|
-
model: typeof raw.model === "string" ? raw.model : void 0,
|
|
832
|
-
promptCount: typeof raw.promptCount === "number" ? raw.promptCount : void 0,
|
|
833
|
-
createdAt: raw.createdAt ? new Date(raw.createdAt) : void 0,
|
|
834
|
-
startedAt: raw.startedAt ? new Date(raw.startedAt) : void 0,
|
|
835
|
-
endedAt: raw.endedAt ? new Date(raw.endedAt) : void 0,
|
|
836
|
-
raw
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
//#endregion
|
|
840
449
|
//#region src/interactive.ts
|
|
841
450
|
/**
|
|
842
451
|
* Handle for one session's interactive harness. Obtained via
|
|
@@ -4732,6 +4341,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
4732
4341
|
* gates ProductTokenIssuer-issued JWTs — no new sidecar surface.
|
|
4733
4342
|
*/
|
|
4734
4343
|
async mintScopedToken(opts) {
|
|
4344
|
+
if ((opts.scope === "session" || opts.scope === "session-runtime") && !opts.sessionId) throw new ValidationError(`${opts.scope} scope requires a sessionId`);
|
|
4735
4345
|
const response = await this.client.fetch(`/v1/sandboxes/${encodeURIComponent(this.id)}/scoped-token`, {
|
|
4736
4346
|
method: "POST",
|
|
4737
4347
|
headers: { "Content-Type": "application/json" },
|
|
@@ -5047,4 +4657,4 @@ function quoteForShell(value) {
|
|
|
5047
4657
|
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
5048
4658
|
}
|
|
5049
4659
|
//#endregion
|
|
5050
|
-
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 };
|
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 };
|