@assemblyline-agents/runtime 3.2.0 → 4.0.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 +6 -0
- package/dist/background-subagents.d.ts.map +1 -1
- package/dist/background-subagents.js +8 -3
- package/dist/background-subagents.js.map +1 -1
- package/dist/harness-loop.d.ts +5 -5
- package/dist/harness-loop.d.ts.map +1 -1
- package/dist/harness-loop.js +14 -5
- package/dist/harness-loop.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -9
- package/dist/index.js.map +1 -1
- package/dist/model-credential-stores.d.ts +20 -0
- package/dist/model-credential-stores.d.ts.map +1 -0
- package/dist/model-credential-stores.js +142 -0
- package/dist/model-credential-stores.js.map +1 -0
- package/dist/public-api.d.ts +3 -1
- package/dist/public-api.d.ts.map +1 -1
- package/dist/public-api.js +1 -0
- package/dist/public-api.js.map +1 -1
- package/dist/run-recovery.js.map +1 -1
- package/dist/runtime-types.d.ts +11 -3
- package/dist/runtime-types.d.ts.map +1 -1
- package/dist/sandbox-authored-tool-child.d.ts +7 -0
- package/dist/sandbox-authored-tool-child.d.ts.map +1 -0
- package/dist/sandbox-authored-tool-child.js +217 -0
- package/dist/sandbox-authored-tool-child.js.map +1 -0
- package/dist/sandbox-authored-tool-executor.d.ts +23 -0
- package/dist/sandbox-authored-tool-executor.d.ts.map +1 -0
- package/dist/sandbox-authored-tool-executor.js +290 -0
- package/dist/sandbox-authored-tool-executor.js.map +1 -0
- package/dist/sandbox-tool-bridge.d.ts +19 -0
- package/dist/sandbox-tool-bridge.d.ts.map +1 -0
- package/dist/sandbox-tool-bridge.js +227 -0
- package/dist/sandbox-tool-bridge.js.map +1 -0
- package/dist/source-loader.d.ts +10 -0
- package/dist/source-loader.d.ts.map +1 -1
- package/dist/source-loader.js +64 -3
- package/dist/source-loader.js.map +1 -1
- package/dist/state.d.ts +1 -1
- package/dist/state.d.ts.map +1 -1
- package/dist/subagent-execution.d.ts +9 -0
- package/dist/subagent-execution.d.ts.map +1 -1
- package/dist/subagent-execution.js +86 -1
- package/dist/subagent-execution.js.map +1 -1
- package/dist/tool-apis.d.ts +1 -1
- package/dist/tool-apis.d.ts.map +1 -1
- package/dist/tool-apis.js +10 -4
- package/dist/tool-apis.js.map +1 -1
- package/dist/tool-execution.d.ts +12 -3
- package/dist/tool-execution.d.ts.map +1 -1
- package/dist/tool-execution.js +52 -12
- package/dist/tool-execution.js.map +1 -1
- package/dist/usage-accounting.js +0 -2
- package/dist/usage-accounting.js.map +1 -1
- package/dist/usage-reconciliation.js +1 -1
- package/dist/usage-reconciliation.js.map +1 -1
- package/package.json +3 -3
- package/dist/model-harnesses.d.ts +0 -4
- package/dist/model-harnesses.d.ts.map +0 -1
- package/dist/model-harnesses.js +0 -6
- package/dist/model-harnesses.js.map +0 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-contained Node.js runner written into the selected sandbox. Authored
|
|
3
|
+
* modules are imported only by this process; host capabilities are reached
|
|
4
|
+
* through the file-backed RPC protocol in sandbox-authored-tool-executor.ts.
|
|
5
|
+
*/
|
|
6
|
+
export const SANDBOX_AUTHORED_TOOL_CHILD_SOURCE = String.raw `
|
|
7
|
+
import {
|
|
8
|
+
appendFileSync,
|
|
9
|
+
mkdirSync,
|
|
10
|
+
readFileSync,
|
|
11
|
+
readdirSync,
|
|
12
|
+
renameSync,
|
|
13
|
+
rmSync,
|
|
14
|
+
writeFileSync
|
|
15
|
+
} from "node:fs";
|
|
16
|
+
import { pathToFileURL } from "node:url";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
import { randomUUID } from "node:crypto";
|
|
19
|
+
|
|
20
|
+
const BRIDGE_KEY = "__assemblyLineBridge";
|
|
21
|
+
const terminate = process.exit.bind(process);
|
|
22
|
+
const configPath = process.argv[2];
|
|
23
|
+
if (!configPath) throw new Error("Sandbox authored-tool runner requires a config path.");
|
|
24
|
+
const config = JSON.parse(readFileSync(configPath, "utf8"));
|
|
25
|
+
const runDir = config.runDir;
|
|
26
|
+
const requestLog = join(runDir, "requests.jsonl");
|
|
27
|
+
const responsesDir = join(runDir, "responses");
|
|
28
|
+
const callbackRequestsDir = join(runDir, "callback-requests");
|
|
29
|
+
const callbackResponsesDir = join(runDir, "callback-responses");
|
|
30
|
+
const finalPath = join(runDir, "final.json");
|
|
31
|
+
mkdirSync(responsesDir, { recursive: true });
|
|
32
|
+
mkdirSync(callbackRequestsDir, { recursive: true });
|
|
33
|
+
mkdirSync(callbackResponsesDir, { recursive: true });
|
|
34
|
+
const callbacks = new Map();
|
|
35
|
+
const handledCallbacks = new Set();
|
|
36
|
+
|
|
37
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
38
|
+
|
|
39
|
+
function exists(path) {
|
|
40
|
+
try {
|
|
41
|
+
readFileSync(path);
|
|
42
|
+
return true;
|
|
43
|
+
} catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function writeJsonAtomic(path, value) {
|
|
49
|
+
const temporary = path + "." + randomUUID() + ".tmp";
|
|
50
|
+
writeFileSync(temporary, JSON.stringify(value));
|
|
51
|
+
renameSync(temporary, path);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function errorValue(error) {
|
|
55
|
+
const candidate = error && typeof error === "object" ? error : undefined;
|
|
56
|
+
const properties = {};
|
|
57
|
+
if (candidate) {
|
|
58
|
+
for (const key of Object.getOwnPropertyNames(candidate)) {
|
|
59
|
+
if (key === "name" || key === "message" || key === "stack") continue;
|
|
60
|
+
properties[key] = encode(candidate[key]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
name: candidate?.name || "Error",
|
|
65
|
+
message: candidate?.message || String(error),
|
|
66
|
+
stack: candidate?.stack,
|
|
67
|
+
properties
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function encode(value, seen = new WeakSet()) {
|
|
72
|
+
if (value === undefined) return { [BRIDGE_KEY]: "undefined" };
|
|
73
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
74
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : String(value);
|
|
75
|
+
if (typeof value === "bigint") return { [BRIDGE_KEY]: "bigint", value: String(value) };
|
|
76
|
+
if (typeof value === "function") {
|
|
77
|
+
const id = randomUUID();
|
|
78
|
+
callbacks.set(id, value);
|
|
79
|
+
return { [BRIDGE_KEY]: "callback", id };
|
|
80
|
+
}
|
|
81
|
+
if (value instanceof Uint8Array) {
|
|
82
|
+
return { [BRIDGE_KEY]: "bytes", value: Buffer.from(value).toString("base64") };
|
|
83
|
+
}
|
|
84
|
+
if (value instanceof Date) return value.toISOString();
|
|
85
|
+
if (!value || typeof value !== "object") return String(value);
|
|
86
|
+
if (seen.has(value)) return { [BRIDGE_KEY]: "circular" };
|
|
87
|
+
seen.add(value);
|
|
88
|
+
if (Array.isArray(value)) {
|
|
89
|
+
const out = value.map((item) => encode(item, seen));
|
|
90
|
+
seen.delete(value);
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
const out = {};
|
|
94
|
+
for (const [key, item] of Object.entries(value)) out[key] = encode(item, seen);
|
|
95
|
+
seen.delete(value);
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function reviveError(value) {
|
|
100
|
+
const error = new Error(value?.message || "Sandbox tool bridge call failed.");
|
|
101
|
+
error.name = value?.name || "Error";
|
|
102
|
+
if (value?.stack) error.stack = value.stack;
|
|
103
|
+
for (const [key, item] of Object.entries(value?.properties || {})) error[key] = decode(item);
|
|
104
|
+
return error;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function decode(value) {
|
|
108
|
+
if (Array.isArray(value)) return value.map(decode);
|
|
109
|
+
if (!value || typeof value !== "object") return value;
|
|
110
|
+
if (value[BRIDGE_KEY] === "undefined") return undefined;
|
|
111
|
+
if (value[BRIDGE_KEY] === "bigint") return BigInt(value.value);
|
|
112
|
+
if (value[BRIDGE_KEY] === "bytes") return Uint8Array.from(Buffer.from(value.value, "base64"));
|
|
113
|
+
if (value[BRIDGE_KEY] === "function") return (...args) => rpc(value.id, args);
|
|
114
|
+
if (value[BRIDGE_KEY] === "promise") return rpc(value.id, []);
|
|
115
|
+
if (value[BRIDGE_KEY] === "asyncIterable") {
|
|
116
|
+
return {
|
|
117
|
+
[Symbol.asyncIterator]() { return this; },
|
|
118
|
+
next() { return rpc(value.id, []); }
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const out = {};
|
|
122
|
+
for (const [key, item] of Object.entries(value)) out[key] = decode(item);
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function serviceCallbacks() {
|
|
127
|
+
let names = [];
|
|
128
|
+
try {
|
|
129
|
+
names = readdirSync(callbackRequestsDir).filter((name) => name.endsWith(".json"));
|
|
130
|
+
} catch {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
for (const name of names) {
|
|
134
|
+
if (handledCallbacks.has(name)) continue;
|
|
135
|
+
handledCallbacks.add(name);
|
|
136
|
+
const requestPath = join(callbackRequestsDir, name);
|
|
137
|
+
const responsePath = join(callbackResponsesDir, name);
|
|
138
|
+
try {
|
|
139
|
+
const request = JSON.parse(readFileSync(requestPath, "utf8"));
|
|
140
|
+
const callback = callbacks.get(request.callbackId);
|
|
141
|
+
if (!callback) throw new Error("Unknown sandbox callback " + request.callbackId + ".");
|
|
142
|
+
const value = await callback(...decode(request.args));
|
|
143
|
+
writeJsonAtomic(responsePath, { ok: true, value: encode(value) });
|
|
144
|
+
} catch (error) {
|
|
145
|
+
writeJsonAtomic(responsePath, { ok: false, error: errorValue(error) });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function rpc(functionId, args) {
|
|
151
|
+
const id = randomUUID();
|
|
152
|
+
appendFileSync(requestLog, JSON.stringify({ id, functionId, args: encode(args) }) + "\n");
|
|
153
|
+
const responsePath = join(responsesDir, id + ".json");
|
|
154
|
+
while (!exists(responsePath)) {
|
|
155
|
+
await serviceCallbacks();
|
|
156
|
+
await delay(10);
|
|
157
|
+
}
|
|
158
|
+
const response = JSON.parse(readFileSync(responsePath, "utf8"));
|
|
159
|
+
rmSync(responsePath, { force: true });
|
|
160
|
+
if (!response.ok) throw reviveError(response.error);
|
|
161
|
+
return decode(response.value);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function main() {
|
|
165
|
+
const loaded = await import(pathToFileURL(config.modulePath).href + "?invocation=" + config.invocationId);
|
|
166
|
+
const definition = loaded.default;
|
|
167
|
+
if (!definition || typeof definition !== "object") {
|
|
168
|
+
throw new Error("Authored tool module does not export a default tool definition.");
|
|
169
|
+
}
|
|
170
|
+
if (config.operation === "describe") {
|
|
171
|
+
return {
|
|
172
|
+
description: definition.description,
|
|
173
|
+
inputSchema: definition.inputSchema,
|
|
174
|
+
outputSchema: definition.outputSchema,
|
|
175
|
+
timeoutMs: definition.timeoutMs
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
if (config.operation !== "execute") throw new Error("Unknown sandbox tool operation " + config.operation + ".");
|
|
179
|
+
if (typeof definition.execute !== "function") throw new Error("Authored tool does not export execute().");
|
|
180
|
+
const context = decode(config.context);
|
|
181
|
+
context.idempotencyKey = (scope) => context.runId + ":" + scope;
|
|
182
|
+
const setAgentState = context.agentState.set;
|
|
183
|
+
const deleteAgentState = context.agentState.delete;
|
|
184
|
+
context.agentState.set = async (...args) => {
|
|
185
|
+
const revision = await setAgentState(...args);
|
|
186
|
+
context.agentState.revision = revision;
|
|
187
|
+
return revision;
|
|
188
|
+
};
|
|
189
|
+
context.agentState.delete = async (...args) => {
|
|
190
|
+
const revision = await deleteAgentState(...args);
|
|
191
|
+
context.agentState.revision = revision;
|
|
192
|
+
return revision;
|
|
193
|
+
};
|
|
194
|
+
context.agentState.update = async (key, update, options = {}) => {
|
|
195
|
+
const current = await context.agentState.get(key);
|
|
196
|
+
const next = await update(current);
|
|
197
|
+
const expectedRevision = options.expectedRevision ?? context.agentState.revision;
|
|
198
|
+
const revision = await context.agentState.set(key, next, { ...options, expectedRevision });
|
|
199
|
+
context.agentState.revision = revision;
|
|
200
|
+
return revision;
|
|
201
|
+
};
|
|
202
|
+
const result = await definition.execute(decode(config.input), context);
|
|
203
|
+
const hasModelOutput = typeof definition.toModelOutput === "function";
|
|
204
|
+
const modelOutput = hasModelOutput ? await definition.toModelOutput(result) : undefined;
|
|
205
|
+
return { result, hasModelOutput, modelOutput };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
try {
|
|
209
|
+
const value = await main();
|
|
210
|
+
writeJsonAtomic(finalPath, { ok: true, value: encode(value) });
|
|
211
|
+
terminate(0);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
writeJsonAtomic(finalPath, { ok: false, error: errorValue(error) });
|
|
214
|
+
terminate(1);
|
|
215
|
+
}
|
|
216
|
+
`;
|
|
217
|
+
//# sourceMappingURL=sandbox-authored-tool-child.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-authored-tool-child.js","sourceRoot":"","sources":["../src/sandbox-authored-tool-child.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkN3D,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type CompiledTool, type ToolDefinition, type ToolExecutionContext } from "@assemblyline-agents/core";
|
|
2
|
+
import type { AuthoredToolExecutionPolicy, RuntimeSandboxHandle } from "./runtime-types.js";
|
|
3
|
+
import type { AgentSourceModuleLoader } from "./source-loader.js";
|
|
4
|
+
export type { AuthoredToolExecutionPolicy };
|
|
5
|
+
export declare function resolveAuthoredToolExecutionPolicy(value: unknown): AuthoredToolExecutionPolicy;
|
|
6
|
+
export interface SandboxedToolExecutionResult {
|
|
7
|
+
result: unknown;
|
|
8
|
+
hasModelOutput: boolean;
|
|
9
|
+
modelOutput?: unknown;
|
|
10
|
+
}
|
|
11
|
+
/** Host orchestrator for authored modules that must never load in the host VM. */
|
|
12
|
+
export declare class SandboxAuthoredToolExecutor {
|
|
13
|
+
private readonly sourceLoader;
|
|
14
|
+
private readonly bundleCache;
|
|
15
|
+
private readonly descriptionCache;
|
|
16
|
+
constructor(sourceLoader: AgentSourceModuleLoader);
|
|
17
|
+
describe(tool: CompiledTool, sandboxHandle: RuntimeSandboxHandle): Promise<ToolDefinition>;
|
|
18
|
+
execute(tool: CompiledTool, input: unknown, context: ToolExecutionContext, sandboxHandle: RuntimeSandboxHandle, signal?: AbortSignal): Promise<SandboxedToolExecutionResult>;
|
|
19
|
+
private describeInSandbox;
|
|
20
|
+
private bundle;
|
|
21
|
+
private runOperation;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=sandbox-authored-tool-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-authored-tool-executor.d.ts","sourceRoot":"","sources":["../src/sandbox-authored-tool-executor.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,YAAY,EAEjB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAUlE,YAAY,EAAE,2BAA2B,EAAE,CAAC;AAE5C,wBAAgB,kCAAkC,CAAC,KAAK,EAAE,OAAO,GAAG,2BAA2B,CAI9F;AAED,MAAM,WAAW,4BAA4B;IAC3C,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAcD,kFAAkF;AAClF,qBAAa,2BAA2B;IAI1B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAHzC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsC;IAClE,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA8C;gBAElD,YAAY,EAAE,uBAAuB;IAE5D,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC;IAe1F,OAAO,CACX,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,oBAAoB,EAC7B,aAAa,EAAE,oBAAoB,EACnC,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,4BAA4B,CAAC;YAwB1B,iBAAiB;IAkB/B,OAAO,CAAC,MAAM;YAUA,YAAY;CA6F3B"}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { posix } from "node:path";
|
|
3
|
+
import { shellQuote } from "@assemblyline-agents/core";
|
|
4
|
+
import { HumanInputRequired } from "./tool-apis.js";
|
|
5
|
+
import { SANDBOX_AUTHORED_TOOL_CHILD_SOURCE } from "./sandbox-authored-tool-child.js";
|
|
6
|
+
import { SandboxToolBridgeRegistry, bridgeError, reviveBridgeError } from "./sandbox-tool-bridge.js";
|
|
7
|
+
export function resolveAuthoredToolExecutionPolicy(value) {
|
|
8
|
+
if (value === undefined || value === "direct")
|
|
9
|
+
return "direct";
|
|
10
|
+
if (value === "sandbox")
|
|
11
|
+
return "sandbox";
|
|
12
|
+
throw new Error('authoredToolExecution must be "direct" or "sandbox".');
|
|
13
|
+
}
|
|
14
|
+
/** Host orchestrator for authored modules that must never load in the host VM. */
|
|
15
|
+
export class SandboxAuthoredToolExecutor {
|
|
16
|
+
sourceLoader;
|
|
17
|
+
bundleCache = new Map();
|
|
18
|
+
descriptionCache = new Map();
|
|
19
|
+
constructor(sourceLoader) {
|
|
20
|
+
this.sourceLoader = sourceLoader;
|
|
21
|
+
}
|
|
22
|
+
async describe(tool, sandboxHandle) {
|
|
23
|
+
if (!isPlaceholderSchema(tool.inputSchema))
|
|
24
|
+
return compiledDefinition(tool);
|
|
25
|
+
const cacheKey = `${tool.source.path}:${tool.source.sha256}`;
|
|
26
|
+
const cached = this.descriptionCache.get(cacheKey);
|
|
27
|
+
if (cached)
|
|
28
|
+
return cached;
|
|
29
|
+
const pending = this.describeInSandbox(tool, sandboxHandle);
|
|
30
|
+
this.descriptionCache.set(cacheKey, pending);
|
|
31
|
+
try {
|
|
32
|
+
return await pending;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
this.descriptionCache.delete(cacheKey);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async execute(tool, input, context, sandboxHandle, signal) {
|
|
40
|
+
const session = await sandboxHandle.get();
|
|
41
|
+
const bootstrapSession = await sandboxHandle.getWrapped();
|
|
42
|
+
const registry = new SandboxToolBridgeRegistry();
|
|
43
|
+
const value = await this.runOperation({
|
|
44
|
+
session,
|
|
45
|
+
bootstrapSession,
|
|
46
|
+
tool,
|
|
47
|
+
operation: "execute",
|
|
48
|
+
registry,
|
|
49
|
+
input: registry.serialize(input),
|
|
50
|
+
context: registry.serializeContext(context),
|
|
51
|
+
environment: stringEnvironment(context.channel?.env),
|
|
52
|
+
...(signal ? { signal } : {})
|
|
53
|
+
});
|
|
54
|
+
if (!value || typeof value !== "object")
|
|
55
|
+
throw new Error(`Sandbox tool ${tool.name} returned an invalid execution envelope.`);
|
|
56
|
+
const result = value;
|
|
57
|
+
return {
|
|
58
|
+
result: result.result,
|
|
59
|
+
hasModelOutput: result.hasModelOutput === true,
|
|
60
|
+
...(result.hasModelOutput === true ? { modelOutput: result.modelOutput } : {})
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async describeInSandbox(tool, sandboxHandle) {
|
|
64
|
+
const session = await sandboxHandle.get();
|
|
65
|
+
const registry = new SandboxToolBridgeRegistry();
|
|
66
|
+
const controller = new AbortController();
|
|
67
|
+
const timeout = setTimeout(() => controller.abort(), 60_000);
|
|
68
|
+
try {
|
|
69
|
+
const value = await this.runOperation({ session, tool, operation: "describe", registry, signal: controller.signal });
|
|
70
|
+
if (!value || typeof value !== "object")
|
|
71
|
+
throw new Error(`Sandbox tool ${tool.name} returned invalid metadata.`);
|
|
72
|
+
const definition = value;
|
|
73
|
+
if (!definition.description || !definition.inputSchema) {
|
|
74
|
+
throw new Error(`Sandbox tool ${tool.name} must export description and inputSchema.`);
|
|
75
|
+
}
|
|
76
|
+
return definition;
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
clearTimeout(timeout);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
bundle(tool) {
|
|
83
|
+
const cacheKey = `${tool.source.path}:${tool.source.sha256}`;
|
|
84
|
+
const cached = this.bundleCache.get(cacheKey);
|
|
85
|
+
if (cached)
|
|
86
|
+
return cached;
|
|
87
|
+
const pending = this.sourceLoader.bundleForSandbox(tool.source);
|
|
88
|
+
this.bundleCache.set(cacheKey, pending);
|
|
89
|
+
pending.catch(() => this.bundleCache.delete(cacheKey));
|
|
90
|
+
return pending;
|
|
91
|
+
}
|
|
92
|
+
async runOperation(input) {
|
|
93
|
+
const invocationId = randomUUID();
|
|
94
|
+
const virtualRunDir = `/workspace/.assembly-line/tool-runs/${invocationId}`;
|
|
95
|
+
const actualRunDir = posix.join(input.session.root, ".assembly-line", "tool-runs", invocationId);
|
|
96
|
+
const virtual = (name) => posix.join(virtualRunDir, name);
|
|
97
|
+
const actual = (name) => posix.join(actualRunDir, name);
|
|
98
|
+
const bundle = await this.bundle(input.tool);
|
|
99
|
+
const driver = new SandboxBridgeProtocolDriver(input.session, virtualRunDir, input.registry, input.signal);
|
|
100
|
+
let processId;
|
|
101
|
+
let completed = false;
|
|
102
|
+
try {
|
|
103
|
+
// One wrapped write creates the durable sync obligation before arbitrary
|
|
104
|
+
// sandbox code can mutate /workspace directly. Protocol traffic itself
|
|
105
|
+
// uses the raw session and does not create redundant state events.
|
|
106
|
+
await (input.bootstrapSession ?? input.session).writeFile(virtual("tool.mjs"), bundle);
|
|
107
|
+
await input.session.writeFile(virtual("runner.mjs"), SANDBOX_AUTHORED_TOOL_CHILD_SOURCE);
|
|
108
|
+
await input.session.writeFile(virtual("config.json"), JSON.stringify({
|
|
109
|
+
invocationId,
|
|
110
|
+
operation: input.operation,
|
|
111
|
+
runDir: actualRunDir,
|
|
112
|
+
modulePath: actual("tool.mjs"),
|
|
113
|
+
...(input.input !== undefined ? { input: input.input } : {}),
|
|
114
|
+
...(input.context !== undefined ? { context: input.context } : {})
|
|
115
|
+
}));
|
|
116
|
+
throwIfAborted(input.signal, input.tool.name);
|
|
117
|
+
const command = [
|
|
118
|
+
"node",
|
|
119
|
+
shellQuote(actual("runner.mjs")),
|
|
120
|
+
shellQuote(actual("config.json")),
|
|
121
|
+
">",
|
|
122
|
+
shellQuote(actual("process.log")),
|
|
123
|
+
"2>&1 & echo $!"
|
|
124
|
+
].join(" ");
|
|
125
|
+
const launched = await input.session.shell(command, {
|
|
126
|
+
cwd: input.session.root,
|
|
127
|
+
timeoutMs: 30_000,
|
|
128
|
+
...(input.environment && Object.keys(input.environment).length > 0 ? { env: input.environment } : {})
|
|
129
|
+
});
|
|
130
|
+
processId = launched.stdout.trim().split(/\s+/u).at(-1);
|
|
131
|
+
if (launched.exitCode !== 0 || !processId || !/^\d+$/u.test(processId)) {
|
|
132
|
+
throw new Error(launched.stderr || `Could not launch sandbox tool ${input.tool.name}; the selected sandbox must provide Node.js 22.`);
|
|
133
|
+
}
|
|
134
|
+
let lastLivenessCheck = 0;
|
|
135
|
+
const pollMs = sandboxPollIntervalMs(input.session);
|
|
136
|
+
const livenessMs = input.session.provider === "local" ? 500 : 2_000;
|
|
137
|
+
while (true) {
|
|
138
|
+
throwIfAborted(input.signal, input.tool.name);
|
|
139
|
+
await driver.drainRequests();
|
|
140
|
+
const final = await readJsonIfPresent(input.session, virtual("final.json"));
|
|
141
|
+
if (final) {
|
|
142
|
+
completed = true;
|
|
143
|
+
await driver.drainRequests();
|
|
144
|
+
if (!final.ok)
|
|
145
|
+
throw reviveSandboxError(final.error);
|
|
146
|
+
return input.registry.decode(final.value, (callbackId, args) => driver.invokeCallback(callbackId, args));
|
|
147
|
+
}
|
|
148
|
+
if (Date.now() - lastLivenessCheck >= livenessMs) {
|
|
149
|
+
lastLivenessCheck = Date.now();
|
|
150
|
+
const live = await input.session.shell(`kill -0 ${processId} 2>/dev/null`, { cwd: input.session.root, timeoutMs: 5_000 });
|
|
151
|
+
if (live.exitCode !== 0) {
|
|
152
|
+
const retry = await readJsonIfPresent(input.session, virtual("final.json"));
|
|
153
|
+
if (retry) {
|
|
154
|
+
completed = true;
|
|
155
|
+
if (!retry.ok)
|
|
156
|
+
throw reviveSandboxError(retry.error);
|
|
157
|
+
return input.registry.decode(retry.value, (callbackId, args) => driver.invokeCallback(callbackId, args));
|
|
158
|
+
}
|
|
159
|
+
const log = await readTextIfPresent(input.session, virtual("process.log"));
|
|
160
|
+
throw new Error(log.trim() || `Sandbox tool ${input.tool.name} exited without returning a result.`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
await delay(pollMs);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
if (processId && !completed) {
|
|
168
|
+
await Promise.resolve(input.session.shell(`kill ${processId} 2>/dev/null || true`, { cwd: input.session.root, timeoutMs: 5_000 })).catch(() => undefined);
|
|
169
|
+
}
|
|
170
|
+
if (input.session.deletePath) {
|
|
171
|
+
await Promise.resolve(input.session.deletePath(virtualRunDir, { recursive: true })).catch(() => undefined);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
await Promise.resolve(input.session.shell(`rm -rf -- ${shellQuote(actualRunDir)}`, { cwd: input.session.root, timeoutMs: 5_000 })).catch(() => undefined);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
class SandboxBridgeProtocolDriver {
|
|
180
|
+
session;
|
|
181
|
+
virtualRunDir;
|
|
182
|
+
registry;
|
|
183
|
+
signal;
|
|
184
|
+
handledRequests = new Set();
|
|
185
|
+
constructor(session, virtualRunDir, registry, signal) {
|
|
186
|
+
this.session = session;
|
|
187
|
+
this.virtualRunDir = virtualRunDir;
|
|
188
|
+
this.registry = registry;
|
|
189
|
+
this.signal = signal;
|
|
190
|
+
}
|
|
191
|
+
async drainRequests() {
|
|
192
|
+
const text = await readTextIfPresent(this.session, posix.join(this.virtualRunDir, "requests.jsonl"));
|
|
193
|
+
for (const line of text.split("\n")) {
|
|
194
|
+
if (!line.trim())
|
|
195
|
+
continue;
|
|
196
|
+
let request;
|
|
197
|
+
try {
|
|
198
|
+
request = JSON.parse(line);
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (!request.id || this.handledRequests.has(request.id))
|
|
204
|
+
continue;
|
|
205
|
+
this.handledRequests.add(request.id);
|
|
206
|
+
const responsePath = posix.join(this.virtualRunDir, "responses", `${request.id}.json`);
|
|
207
|
+
try {
|
|
208
|
+
const decoded = this.registry.decode(request.args, (callbackId, args) => this.invokeCallback(callbackId, args));
|
|
209
|
+
const args = Array.isArray(decoded) ? decoded : [];
|
|
210
|
+
const value = await this.registry.invoke(request.functionId, args);
|
|
211
|
+
await this.session.writeFile(responsePath, JSON.stringify({ ok: true, value: this.registry.serialize(value) }));
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
await this.session.writeFile(responsePath, JSON.stringify({ ok: false, error: bridgeError(error, this.registry) }));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async invokeCallback(callbackId, args) {
|
|
219
|
+
const id = randomUUID();
|
|
220
|
+
const requestPath = posix.join(this.virtualRunDir, "callback-requests", `${id}.json`);
|
|
221
|
+
const responsePath = posix.join(this.virtualRunDir, "callback-responses", `${id}.json`);
|
|
222
|
+
await this.session.writeFile(requestPath, JSON.stringify({ callbackId, args: this.registry.serialize(args) }));
|
|
223
|
+
while (true) {
|
|
224
|
+
throwIfAborted(this.signal, "callback");
|
|
225
|
+
await this.drainRequests();
|
|
226
|
+
const response = await readJsonIfPresent(this.session, responsePath);
|
|
227
|
+
if (response) {
|
|
228
|
+
if (!response.ok)
|
|
229
|
+
throw reviveBridgeError(response.error);
|
|
230
|
+
return this.registry.decode(response.value, (nestedId, nestedArgs) => this.invokeCallback(nestedId, nestedArgs));
|
|
231
|
+
}
|
|
232
|
+
await delay(sandboxPollIntervalMs(this.session));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function compiledDefinition(tool) {
|
|
237
|
+
return {
|
|
238
|
+
description: tool.description,
|
|
239
|
+
inputSchema: tool.inputSchema,
|
|
240
|
+
...(tool.outputSchema ? { outputSchema: tool.outputSchema } : {}),
|
|
241
|
+
...(tool.timeoutMs !== undefined ? { timeoutMs: tool.timeoutMs } : {})
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function isPlaceholderSchema(schema) {
|
|
245
|
+
return Boolean(schema && typeof schema === "object" && schema.description === "Declared in source.");
|
|
246
|
+
}
|
|
247
|
+
function reviveSandboxError(value) {
|
|
248
|
+
const error = reviveBridgeError(value);
|
|
249
|
+
if (error.name !== "HumanInputRequired")
|
|
250
|
+
return error;
|
|
251
|
+
const candidate = error;
|
|
252
|
+
const question = typeof candidate.question === "string" ? candidate.question : error.message;
|
|
253
|
+
const options = candidate.options && typeof candidate.options === "object" && !Array.isArray(candidate.options)
|
|
254
|
+
? candidate.options
|
|
255
|
+
: undefined;
|
|
256
|
+
return new HumanInputRequired(question, options);
|
|
257
|
+
}
|
|
258
|
+
async function readTextIfPresent(session, path) {
|
|
259
|
+
try {
|
|
260
|
+
return await session.readFile(path);
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
return "";
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async function readJsonIfPresent(session, path) {
|
|
267
|
+
const text = await readTextIfPresent(session, path);
|
|
268
|
+
if (!text)
|
|
269
|
+
return undefined;
|
|
270
|
+
try {
|
|
271
|
+
return JSON.parse(text);
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return undefined;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function throwIfAborted(signal, toolName) {
|
|
278
|
+
if (signal?.aborted)
|
|
279
|
+
throw new Error(`Sandbox tool ${toolName} was cancelled.`);
|
|
280
|
+
}
|
|
281
|
+
function delay(ms) {
|
|
282
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
283
|
+
}
|
|
284
|
+
function sandboxPollIntervalMs(session) {
|
|
285
|
+
return session.provider === "local" ? 10 : 75;
|
|
286
|
+
}
|
|
287
|
+
function stringEnvironment(value) {
|
|
288
|
+
return Object.fromEntries(Object.entries(value ?? {}).flatMap(([name, item]) => item === undefined ? [] : [[name, item]]));
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=sandbox-authored-tool-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-authored-tool-executor.js","sourceRoot":"","sources":["../src/sandbox-authored-tool-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,UAAU,EAKX,M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qB,CAAC,OAAuB;IACpD,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAChD,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAqD;IAC9E,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7H,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ToolExecutionContext } from "@assemblyline-agents/core";
|
|
2
|
+
export interface SerializedBridgeError {
|
|
3
|
+
name: string;
|
|
4
|
+
message: string;
|
|
5
|
+
stack?: string;
|
|
6
|
+
properties?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
type SandboxCallbackInvoker = (callbackId: string, args: unknown[]) => Promise<unknown>;
|
|
9
|
+
export declare class SandboxToolBridgeRegistry {
|
|
10
|
+
private readonly functions;
|
|
11
|
+
serializeContext(context: ToolExecutionContext): unknown;
|
|
12
|
+
serialize(value: unknown, seen?: WeakSet<object>): unknown;
|
|
13
|
+
decode(value: unknown, invokeCallback: SandboxCallbackInvoker): unknown;
|
|
14
|
+
invoke(functionId: string, args: unknown[]): Promise<unknown>;
|
|
15
|
+
}
|
|
16
|
+
export declare function bridgeError(error: unknown, registry: SandboxToolBridgeRegistry): SerializedBridgeError;
|
|
17
|
+
export declare function reviveBridgeError(value: SerializedBridgeError | undefined): Error;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=sandbox-tool-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-tool-bridge.d.ts","sourceRoot":"","sources":["../src/sandbox-tool-bridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAKtE,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAGD,KAAK,sBAAsB,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAExF,qBAAa,yBAAyB;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyC;IAEnE,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO;IAIxD,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,kBAAwB,GAAG,OAAO;IA0ChE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,sBAAsB,GAAG,OAAO;IAgBjE,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CAKpE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,yBAAyB,GAAG,qBAAqB,CAatG;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,qBAAqB,GAAG,SAAS,GAAG,KAAK,CAQjF"}
|