code-mode-core 2.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/dist/bridges.d.ts +28 -0
- package/dist/bridges.d.ts.map +1 -0
- package/dist/bridges.js +130 -0
- package/dist/bridges.js.map +1 -0
- package/dist/cache.d.ts +26 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +43 -0
- package/dist/cache.js.map +1 -0
- package/dist/engine.d.ts +32 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +163 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/sandbox.d.ts +36 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +101 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/schema-to-ts.d.ts +32 -0
- package/dist/schema-to-ts.d.ts.map +1 -0
- package/dist/schema-to-ts.js +223 -0
- package/dist/schema-to-ts.js.map +1 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +52 -0
- package/src/bridges.ts +160 -0
- package/src/cache.ts +48 -0
- package/src/engine.ts +211 -0
- package/src/index.ts +20 -0
- package/src/sandbox.ts +85 -0
- package/src/schema-to-ts.ts +262 -0
- package/src/types.ts +77 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @code-mode/core — Console and tool bridges for isolated-vm sandbox
|
|
3
|
+
*
|
|
4
|
+
* Adapted from @utcp/code-mode (CodeModeUtcpClient) by UTCP Contributors.
|
|
5
|
+
* Original: https://github.com/universal-tool-calling-protocol/code-mode
|
|
6
|
+
*
|
|
7
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
8
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
9
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
10
|
+
*/
|
|
11
|
+
import type ivm from 'isolated-vm';
|
|
12
|
+
import type { ToolLike } from './schema-to-ts';
|
|
13
|
+
export type CallToolFn = (toolName: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* Set up console.log/error/warn/info bridges in the isolate.
|
|
16
|
+
* Console calls are forwarded to the logs array in the main process.
|
|
17
|
+
*/
|
|
18
|
+
export declare function setupConsoleBridge(isolate: ivm.Isolate, context: ivm.Context, jail: ivm.Reference<Record<string | number | symbol, unknown>>, logs: string[], ivm_module: typeof ivm): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Set up tool bridge functions in the isolate.
|
|
21
|
+
* Tool calls are forwarded to the main process via callToolFn.
|
|
22
|
+
*/
|
|
23
|
+
export declare function setupToolBridges(isolate: ivm.Isolate, context: ivm.Context, jail: ivm.Reference<Record<string | number | symbol, unknown>>, tools: ToolLike[], callToolFn: CallToolFn, ivm_module: typeof ivm): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Set up utility functions (__interfaces, __getToolInterface) in the isolate.
|
|
26
|
+
*/
|
|
27
|
+
export declare function setupUtilities(isolate: ivm.Isolate, context: ivm.Context, jail: ivm.Reference<Record<string | number | symbol, unknown>>, tools: ToolLike[], interfacesString: string, interfaceMap: Record<string, string>): Promise<void>;
|
|
28
|
+
//# sourceMappingURL=bridges.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridges.d.ts","sourceRoot":"","sources":["../src/bridges.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAEnC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE/F;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,GAAG,CAAC,OAAO,EACpB,OAAO,EAAE,GAAG,CAAC,OAAO,EACpB,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC,EAC9D,IAAI,EAAE,MAAM,EAAE,EACd,UAAU,EAAE,OAAO,GAAG,GACrB,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,GAAG,CAAC,OAAO,EACpB,OAAO,EAAE,GAAG,CAAC,OAAO,EACpB,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC,EAC9D,KAAK,EAAE,QAAQ,EAAE,EACjB,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,OAAO,GAAG,GACrB,OAAO,CAAC,IAAI,CAAC,CAyEf;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,GAAG,CAAC,OAAO,EACpB,OAAO,EAAE,GAAG,CAAC,OAAO,EACpB,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC,EAC9D,KAAK,EAAE,QAAQ,EAAE,EACjB,gBAAgB,EAAE,MAAM,EACxB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACnC,OAAO,CAAC,IAAI,CAAC,CAWf"}
|
package/dist/bridges.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @code-mode/core — Console and tool bridges for isolated-vm sandbox
|
|
4
|
+
*
|
|
5
|
+
* Adapted from @utcp/code-mode (CodeModeUtcpClient) by UTCP Contributors.
|
|
6
|
+
* Original: https://github.com/universal-tool-calling-protocol/code-mode
|
|
7
|
+
*
|
|
8
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
9
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
10
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.setupConsoleBridge = setupConsoleBridge;
|
|
14
|
+
exports.setupToolBridges = setupToolBridges;
|
|
15
|
+
exports.setupUtilities = setupUtilities;
|
|
16
|
+
const schema_to_ts_1 = require("./schema-to-ts");
|
|
17
|
+
/**
|
|
18
|
+
* Set up console.log/error/warn/info bridges in the isolate.
|
|
19
|
+
* Console calls are forwarded to the logs array in the main process.
|
|
20
|
+
*/
|
|
21
|
+
async function setupConsoleBridge(isolate, context, jail, logs, ivm_module) {
|
|
22
|
+
const createLogHandler = (prefix) => {
|
|
23
|
+
return new ivm_module.Reference((...args) => {
|
|
24
|
+
const message = args.join(' ');
|
|
25
|
+
logs.push(prefix ? `${prefix} ${message}` : message);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
await jail.set('__logRef', createLogHandler(''));
|
|
29
|
+
await jail.set('__errorRef', createLogHandler('[ERROR]'));
|
|
30
|
+
await jail.set('__warnRef', createLogHandler('[WARN]'));
|
|
31
|
+
await jail.set('__infoRef', createLogHandler('[INFO]'));
|
|
32
|
+
const consoleSetupScript = await isolate.compileScript(`
|
|
33
|
+
const __stringify = (a) => typeof a === 'object' && a !== null ? JSON.stringify(a, null, 2) : String(a);
|
|
34
|
+
global.console = {
|
|
35
|
+
log: (...args) => __logRef.applySync(undefined, args.map(__stringify)),
|
|
36
|
+
error: (...args) => __errorRef.applySync(undefined, args.map(__stringify)),
|
|
37
|
+
warn: (...args) => __warnRef.applySync(undefined, args.map(__stringify)),
|
|
38
|
+
info: (...args) => __infoRef.applySync(undefined, args.map(__stringify))
|
|
39
|
+
};
|
|
40
|
+
`);
|
|
41
|
+
await consoleSetupScript.run(context);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Set up tool bridge functions in the isolate.
|
|
45
|
+
* Tool calls are forwarded to the main process via callToolFn.
|
|
46
|
+
*/
|
|
47
|
+
async function setupToolBridges(isolate, context, jail, tools, callToolFn, ivm_module) {
|
|
48
|
+
const toolCallerRef = new ivm_module.Reference(async (toolName, argsJson) => {
|
|
49
|
+
try {
|
|
50
|
+
const args = JSON.parse(argsJson);
|
|
51
|
+
const result = await callToolFn(toolName, args);
|
|
52
|
+
return JSON.stringify({ success: true, result });
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
let errorMsg = error instanceof Error ? error.message : String(error);
|
|
56
|
+
if (error.response?.data) {
|
|
57
|
+
errorMsg += ` Error data: ${JSON.stringify(error.response.data)}`;
|
|
58
|
+
}
|
|
59
|
+
return JSON.stringify({
|
|
60
|
+
success: false,
|
|
61
|
+
error: errorMsg,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
await jail.set('__callToolRef', toolCallerRef);
|
|
66
|
+
const toolSetupParts = [];
|
|
67
|
+
const seenPaths = new Set();
|
|
68
|
+
const namespaces = new Set();
|
|
69
|
+
// Resolve collisions when two tool names sanitize to the same identifier
|
|
70
|
+
const getUniquePath = (fullPath) => {
|
|
71
|
+
let uniquePath = fullPath;
|
|
72
|
+
let counter = 1;
|
|
73
|
+
while (seenPaths.has(uniquePath)) {
|
|
74
|
+
uniquePath = `${fullPath}_${counter}`;
|
|
75
|
+
counter += 1;
|
|
76
|
+
}
|
|
77
|
+
seenPaths.add(uniquePath);
|
|
78
|
+
return uniquePath;
|
|
79
|
+
};
|
|
80
|
+
for (const tool of tools) {
|
|
81
|
+
if (tool.name.includes('.')) {
|
|
82
|
+
const [manualName, ...toolParts] = tool.name.split('.');
|
|
83
|
+
const sanitizedManualName = (0, schema_to_ts_1.sanitizeIdentifier)(manualName);
|
|
84
|
+
const baseFnName = toolParts.map(part => (0, schema_to_ts_1.sanitizeIdentifier)(part)).join('_');
|
|
85
|
+
const fullPath = getUniquePath(`${sanitizedManualName}.${baseFnName}`);
|
|
86
|
+
const toolFnName = fullPath.slice(sanitizedManualName.length + 1);
|
|
87
|
+
if (!namespaces.has(sanitizedManualName)) {
|
|
88
|
+
namespaces.add(sanitizedManualName);
|
|
89
|
+
toolSetupParts.push(`global.${sanitizedManualName} = global.${sanitizedManualName} || {};`);
|
|
90
|
+
}
|
|
91
|
+
toolSetupParts.push(`
|
|
92
|
+
global.${sanitizedManualName}.${toolFnName} = function(args) {
|
|
93
|
+
var resultJson = __callToolRef.applySyncPromise(undefined, [${JSON.stringify(tool.name)}, JSON.stringify(args || {})]);
|
|
94
|
+
var parsed = JSON.parse(resultJson);
|
|
95
|
+
if (!parsed.success) throw new Error(parsed.error);
|
|
96
|
+
return parsed.result;
|
|
97
|
+
};
|
|
98
|
+
`);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
const baseName = (0, schema_to_ts_1.sanitizeIdentifier)(tool.name);
|
|
102
|
+
const sanitizedToolName = getUniquePath(baseName);
|
|
103
|
+
toolSetupParts.push(`
|
|
104
|
+
global.${sanitizedToolName} = function(args) {
|
|
105
|
+
var resultJson = __callToolRef.applySyncPromise(undefined, [${JSON.stringify(tool.name)}, JSON.stringify(args || {})]);
|
|
106
|
+
var parsed = JSON.parse(resultJson);
|
|
107
|
+
if (!parsed.success) throw new Error(parsed.error);
|
|
108
|
+
return parsed.result;
|
|
109
|
+
};
|
|
110
|
+
`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const toolSetupScript = await isolate.compileScript(toolSetupParts.join('\n'));
|
|
114
|
+
await toolSetupScript.run(context);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Set up utility functions (__interfaces, __getToolInterface) in the isolate.
|
|
118
|
+
*/
|
|
119
|
+
async function setupUtilities(isolate, context, jail, tools, interfacesString, interfaceMap) {
|
|
120
|
+
await jail.set('__interfaces', interfacesString);
|
|
121
|
+
await jail.set('__interfaceMapJson', JSON.stringify(interfaceMap));
|
|
122
|
+
const utilSetupScript = await isolate.compileScript(`
|
|
123
|
+
global.__getToolInterface = (toolName) => {
|
|
124
|
+
const map = JSON.parse(__interfaceMapJson);
|
|
125
|
+
return map[toolName] || null;
|
|
126
|
+
};
|
|
127
|
+
`);
|
|
128
|
+
await utilSetupScript.run(context);
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=bridges.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridges.js","sourceRoot":"","sources":["../src/bridges.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAYH,gDA6BC;AAMD,4CAgFC;AAKD,wCAkBC;AAnJD,iDAAoD;AAKpD;;;GAGG;AACI,KAAK,UAAU,kBAAkB,CACtC,OAAoB,EACpB,OAAoB,EACpB,IAA8D,EAC9D,IAAc,EACd,UAAsB;IAEtB,MAAM,gBAAgB,GAAG,CAAC,MAAc,EAAE,EAAE;QAC1C,OAAO,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE;YACjD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC/B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC;IACjD,MAAM,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;IAC1D,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,gBAA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ED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @code-mode/core — Internal setup caching
|
|
3
|
+
*
|
|
4
|
+
* Always-on caching for tool bridge setup strings, TypeScript interfaces,
|
|
5
|
+
* and tool description prompts. Keyed on a hash of tool configuration.
|
|
6
|
+
* No user-facing configuration.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
9
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
10
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
11
|
+
*/
|
|
12
|
+
import type { ToolLike } from './schema-to-ts';
|
|
13
|
+
export interface CachedSetup {
|
|
14
|
+
interfacesString: string;
|
|
15
|
+
interfaceMap: Record<string, string>;
|
|
16
|
+
toolDescription: string;
|
|
17
|
+
}
|
|
18
|
+
/** Compute a hash key from the current set of tools (name, schema, description). */
|
|
19
|
+
export declare function computeToolsHash(tools: ToolLike[]): string;
|
|
20
|
+
/** Get cached setup data for the given tools hash, or null. */
|
|
21
|
+
export declare function getCachedSetup(hash: string): CachedSetup | null;
|
|
22
|
+
/** Store setup data in the cache (FIFO eviction at MAX_CACHE_SIZE). */
|
|
23
|
+
export declare function setCachedSetup(hash: string, setup: CachedSetup): void;
|
|
24
|
+
/** Clear the entire setup cache. */
|
|
25
|
+
export declare function clearSetupCache(): void;
|
|
26
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,WAAW,WAAW;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,eAAe,EAAE,MAAM,CAAC;CACzB;AAKD,oFAAoF;AACpF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CAG1D;AAED,+DAA+D;AAC/D,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAE/D;AAED,uEAAuE;AACvE,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CAMrE;AAED,oCAAoC;AACpC,wBAAgB,eAAe,IAAI,IAAI,CAEtC"}
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @code-mode/core — Internal setup caching
|
|
4
|
+
*
|
|
5
|
+
* Always-on caching for tool bridge setup strings, TypeScript interfaces,
|
|
6
|
+
* and tool description prompts. Keyed on a hash of tool configuration.
|
|
7
|
+
* No user-facing configuration.
|
|
8
|
+
*
|
|
9
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
10
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
11
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.computeToolsHash = computeToolsHash;
|
|
15
|
+
exports.getCachedSetup = getCachedSetup;
|
|
16
|
+
exports.setCachedSetup = setCachedSetup;
|
|
17
|
+
exports.clearSetupCache = clearSetupCache;
|
|
18
|
+
const crypto_1 = require("crypto");
|
|
19
|
+
const MAX_CACHE_SIZE = 16;
|
|
20
|
+
const setupCache = new Map();
|
|
21
|
+
/** Compute a hash key from the current set of tools (name, schema, description). */
|
|
22
|
+
function computeToolsHash(tools) {
|
|
23
|
+
const data = tools.map(t => `${t.name}:${t.description}:${JSON.stringify(t.inputs)}:${JSON.stringify(t.outputs)}`).join('|');
|
|
24
|
+
return (0, crypto_1.createHash)('sha256').update(data).digest('hex').slice(0, 16);
|
|
25
|
+
}
|
|
26
|
+
/** Get cached setup data for the given tools hash, or null. */
|
|
27
|
+
function getCachedSetup(hash) {
|
|
28
|
+
return setupCache.get(hash) ?? null;
|
|
29
|
+
}
|
|
30
|
+
/** Store setup data in the cache (FIFO eviction at MAX_CACHE_SIZE). */
|
|
31
|
+
function setCachedSetup(hash, setup) {
|
|
32
|
+
if (!setupCache.has(hash) && setupCache.size >= MAX_CACHE_SIZE) {
|
|
33
|
+
const oldestKey = setupCache.keys().next().value;
|
|
34
|
+
if (oldestKey !== undefined)
|
|
35
|
+
setupCache.delete(oldestKey);
|
|
36
|
+
}
|
|
37
|
+
setupCache.set(hash, setup);
|
|
38
|
+
}
|
|
39
|
+
/** Clear the entire setup cache. */
|
|
40
|
+
function clearSetupCache() {
|
|
41
|
+
setupCache.clear();
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AAeH,4CAGC;AAGD,wCAEC;AAGD,wCAMC;AAGD,0CAEC;AAnCD,mCAAoC;AASpC,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,UAAU,GAAG,IAAI,GAAG,EAAuB,CAAC;AAElD,oFAAoF;AACpF,SAAgB,gBAAgB,CAAC,KAAiB;IAChD,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,WAAW,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7H,OAAO,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACtE,CAAC;AAED,+DAA+D;AAC/D,SAAgB,cAAc,CAAC,IAAY;IACzC,OAAO,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AACtC,CAAC;AAED,uEAAuE;AACvE,SAAgB,cAAc,CAAC,IAAY,EAAE,KAAkB;IAC7D,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,IAAI,cAAc,EAAE,CAAC;QAC/D,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;QACjD,IAAI,SAAS,KAAK,SAAS;YAAE,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;IACD,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,oCAAoC;AACpC,SAAgB,eAAe;IAC7B,UAAU,CAAC,KAAK,EAAE,CAAC;AACrB,CAAC"}
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @code-mode/core — CodeModeEngine
|
|
3
|
+
*
|
|
4
|
+
* Platform-agnostic engine for executing TypeScript code with tool access
|
|
5
|
+
* in a secure isolated-vm sandbox.
|
|
6
|
+
*
|
|
7
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
8
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
9
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
10
|
+
*/
|
|
11
|
+
import type { ExecutionOptions, ExecutionResult, ToolSourceConfig, RegisterResult } from './types';
|
|
12
|
+
export declare class CodeModeEngine {
|
|
13
|
+
private client;
|
|
14
|
+
private toolsHash;
|
|
15
|
+
private constructor();
|
|
16
|
+
/** Create a new CodeModeEngine instance. */
|
|
17
|
+
static create(): Promise<CodeModeEngine>;
|
|
18
|
+
/** Register a tool source (MCP server, HTTP API, etc.). */
|
|
19
|
+
registerToolSource(config: ToolSourceConfig): Promise<RegisterResult>;
|
|
20
|
+
/** Execute code in the sandbox with registered tools. */
|
|
21
|
+
execute(code: string, options?: Partial<ExecutionOptions>): Promise<ExecutionResult>;
|
|
22
|
+
/** Get tool descriptions for LLM prompt generation. */
|
|
23
|
+
getToolDescription(): Promise<string>;
|
|
24
|
+
/** Clean up resources including the underlying UTCP client and MCP transports. */
|
|
25
|
+
close(): Promise<void>;
|
|
26
|
+
private getToolsAsToolLike;
|
|
27
|
+
private getOrComputeSetup;
|
|
28
|
+
private createCallTool;
|
|
29
|
+
private createTracedCallTool;
|
|
30
|
+
private computeStats;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,cAAc,EAGf,MAAM,SAAS,CAAC;AAqBjB,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,SAAS,CAAc;IAE/B,OAAO;IAIP,4CAA4C;WAC/B,MAAM,IAAI,OAAO,CAAC,cAAc,CAAC;IAK9C,2DAA2D;IACrD,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC;IAuB3E,yDAAyD;IACnD,OAAO,CACX,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAClC,OAAO,CAAC,eAAe,CAAC;IAoC3B,uDAAuD;IACjD,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAM3C,kFAAkF;IAC5E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAOd,kBAAkB;YAWlB,iBAAiB;IAgC/B,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,oBAAoB;IAqB5B,OAAO,CAAC,YAAY;CAOrB"}
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @code-mode/core — CodeModeEngine
|
|
4
|
+
*
|
|
5
|
+
* Platform-agnostic engine for executing TypeScript code with tool access
|
|
6
|
+
* in a secure isolated-vm sandbox.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
9
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
10
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.CodeModeEngine = void 0;
|
|
14
|
+
const sdk_1 = require("@utcp/sdk");
|
|
15
|
+
const schema_to_ts_1 = require("./schema-to-ts");
|
|
16
|
+
const sandbox_1 = require("./sandbox");
|
|
17
|
+
const cache_1 = require("./cache");
|
|
18
|
+
const DEFAULT_OPTIONS = {
|
|
19
|
+
timeout: 30000,
|
|
20
|
+
memoryLimit: 128,
|
|
21
|
+
enableTrace: false,
|
|
22
|
+
};
|
|
23
|
+
class CodeModeEngine {
|
|
24
|
+
constructor(client) {
|
|
25
|
+
this.toolsHash = '';
|
|
26
|
+
this.client = client;
|
|
27
|
+
}
|
|
28
|
+
/** Create a new CodeModeEngine instance. */
|
|
29
|
+
static async create() {
|
|
30
|
+
const client = await sdk_1.UtcpClient.create();
|
|
31
|
+
return new CodeModeEngine(client);
|
|
32
|
+
}
|
|
33
|
+
/** Register a tool source (MCP server, HTTP API, etc.). */
|
|
34
|
+
async registerToolSource(config) {
|
|
35
|
+
// Always invalidate cache — tool state may have changed regardless of outcome
|
|
36
|
+
this.toolsHash = '';
|
|
37
|
+
try {
|
|
38
|
+
const result = await this.client.registerManual(config);
|
|
39
|
+
if (result.success) {
|
|
40
|
+
const toolNames = (result.manual?.tools ?? []).map((t) => t.name ?? 'unknown');
|
|
41
|
+
return { success: true, toolNames };
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
success: false,
|
|
45
|
+
toolNames: [],
|
|
46
|
+
errors: result.errors ?? ['Registration failed'],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
return {
|
|
51
|
+
success: false,
|
|
52
|
+
toolNames: [],
|
|
53
|
+
errors: [err instanceof Error ? err.message : String(err)],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Execute code in the sandbox with registered tools. */
|
|
58
|
+
async execute(code, options) {
|
|
59
|
+
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
60
|
+
const tools = await this.getToolsAsToolLike();
|
|
61
|
+
// Get or compute cached setup
|
|
62
|
+
const setup = await this.getOrComputeSetup(tools);
|
|
63
|
+
// Build callToolFn — optionally with tracing
|
|
64
|
+
const trace = [];
|
|
65
|
+
const callToolFn = opts.enableTrace
|
|
66
|
+
? this.createTracedCallTool(trace)
|
|
67
|
+
: this.createCallTool();
|
|
68
|
+
const sandboxResult = await (0, sandbox_1.executeInSandbox)(code, tools, callToolFn, setup.interfacesString, setup.interfaceMap, { timeout: opts.timeout, memoryLimit: opts.memoryLimit });
|
|
69
|
+
const executionResult = {
|
|
70
|
+
result: sandboxResult.result,
|
|
71
|
+
logs: sandboxResult.logs,
|
|
72
|
+
...(sandboxResult.error ? { error: sandboxResult.error } : {}),
|
|
73
|
+
};
|
|
74
|
+
if (opts.enableTrace) {
|
|
75
|
+
executionResult.trace = trace;
|
|
76
|
+
executionResult.stats = this.computeStats(trace);
|
|
77
|
+
}
|
|
78
|
+
return executionResult;
|
|
79
|
+
}
|
|
80
|
+
/** Get tool descriptions for LLM prompt generation. */
|
|
81
|
+
async getToolDescription() {
|
|
82
|
+
const tools = await this.getToolsAsToolLike();
|
|
83
|
+
const setup = await this.getOrComputeSetup(tools);
|
|
84
|
+
return setup.toolDescription;
|
|
85
|
+
}
|
|
86
|
+
/** Clean up resources including the underlying UTCP client and MCP transports. */
|
|
87
|
+
async close() {
|
|
88
|
+
this.toolsHash = '';
|
|
89
|
+
(0, schema_to_ts_1.clearInterfaceCache)();
|
|
90
|
+
(0, cache_1.clearSetupCache)();
|
|
91
|
+
await this.client.close();
|
|
92
|
+
}
|
|
93
|
+
async getToolsAsToolLike() {
|
|
94
|
+
const tools = await this.client.getTools();
|
|
95
|
+
return tools.map((t) => ({
|
|
96
|
+
name: t.name,
|
|
97
|
+
description: t.description,
|
|
98
|
+
inputs: t.inputs,
|
|
99
|
+
outputs: t.outputs,
|
|
100
|
+
tags: t.tags ?? [],
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
async getOrComputeSetup(tools) {
|
|
104
|
+
const hash = (0, cache_1.computeToolsHash)(tools);
|
|
105
|
+
if (hash === this.toolsHash) {
|
|
106
|
+
const cached = (0, cache_1.getCachedSetup)(hash);
|
|
107
|
+
if (cached)
|
|
108
|
+
return cached;
|
|
109
|
+
}
|
|
110
|
+
// Compute fresh — build interfaceMap in one pass, then join for interfacesString
|
|
111
|
+
(0, schema_to_ts_1.clearInterfaceCache)();
|
|
112
|
+
const interfaceMap = {};
|
|
113
|
+
for (const tool of tools) {
|
|
114
|
+
interfaceMap[tool.name] = (0, schema_to_ts_1.toolToTypeScriptInterface)(tool);
|
|
115
|
+
}
|
|
116
|
+
const interfacesString = `// Auto-generated TypeScript interfaces for UTCP tools\n${Object.values(interfaceMap).join('\n\n')}`;
|
|
117
|
+
const toolDescription = [
|
|
118
|
+
'Execute a TypeScript code block with access to registered UTCP tools.',
|
|
119
|
+
'The code runs in an isolated sandbox. Tools are called as synchronous functions: manual.tool({ param: value }).',
|
|
120
|
+
'Use `return` to return the final result.',
|
|
121
|
+
'',
|
|
122
|
+
'Available tool interfaces:',
|
|
123
|
+
interfacesString || '(no tools registered — configure tool sources on the node)',
|
|
124
|
+
].join('\n');
|
|
125
|
+
const setup = { interfacesString, interfaceMap, toolDescription };
|
|
126
|
+
(0, cache_1.setCachedSetup)(hash, setup);
|
|
127
|
+
this.toolsHash = hash;
|
|
128
|
+
return setup;
|
|
129
|
+
}
|
|
130
|
+
createCallTool() {
|
|
131
|
+
return async (toolName, args) => {
|
|
132
|
+
return this.client.callTool(toolName, args);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
createTracedCallTool(trace) {
|
|
136
|
+
return async (toolName, args) => {
|
|
137
|
+
const start = performance.now();
|
|
138
|
+
try {
|
|
139
|
+
const result = await this.client.callTool(toolName, args);
|
|
140
|
+
trace.push({ toolName, args, result, durationMs: performance.now() - start });
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
trace.push({
|
|
145
|
+
toolName,
|
|
146
|
+
args,
|
|
147
|
+
error: err instanceof Error ? err.message : String(err),
|
|
148
|
+
durationMs: performance.now() - start,
|
|
149
|
+
});
|
|
150
|
+
throw err;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
computeStats(trace) {
|
|
155
|
+
return {
|
|
156
|
+
totalCalls: trace.length,
|
|
157
|
+
totalDurationMs: trace.reduce((sum, r) => sum + r.durationMs, 0),
|
|
158
|
+
failures: trace.filter(r => r.error !== undefined).length,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.CodeModeEngine = CodeModeEngine;
|
|
163
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,mCAAuC;AASvC,iDAGwB;AAExB,uCAA6C;AAC7C,mCAKiB;AAGjB,MAAM,eAAe,GAAqB;IACxC,OAAO,EAAE,KAAK;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CAAC;oBACT,QAAQ;oBACR,IAAI;oBACJ,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;oBACvD,UAAU,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK;iBACtC,CAAC,CAAC;gBACH,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;IAEO,YAAY,CAAC,KAAuB;QAC1C,OAAO;YACL,UAAU,EAAE,KAAK,CAAC,MAAM;YACxB,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC;YAChE,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,MAAM;SAC1D,CAAC;IACJ,CAAC;CACF;AA1KD,wCA0KC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @code-mode/core — Public API
|
|
3
|
+
*
|
|
4
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
+
*/
|
|
8
|
+
export { CodeModeEngine } from './engine';
|
|
9
|
+
export type { ExecutionOptions, ExecutionResult, ToolDefinition, ToolCallRecord, ExecutionStats, ToolSourceConfig, RegisterResult, JsonSchemaLike, } from './types';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,cAAc,GACf,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @code-mode/core — Public API
|
|
4
|
+
*
|
|
5
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
6
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
7
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.CodeModeEngine = void 0;
|
|
11
|
+
var engine_1 = require("./engine");
|
|
12
|
+
Object.defineProperty(exports, "CodeModeEngine", { enumerable: true, get: function () { return engine_1.CodeModeEngine; } });
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,mCAA0C;AAAjC,wGAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @code-mode/core — SandboxManager
|
|
3
|
+
*
|
|
4
|
+
* Only file that imports isolated-vm. Contains isolate creation and
|
|
5
|
+
* code execution within the sandbox.
|
|
6
|
+
*
|
|
7
|
+
* Adapted from @utcp/code-mode (CodeModeUtcpClient) by UTCP Contributors.
|
|
8
|
+
* Original: https://github.com/universal-tool-calling-protocol/code-mode
|
|
9
|
+
*
|
|
10
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
11
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
12
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
13
|
+
*/
|
|
14
|
+
import type { ToolLike } from './schema-to-ts';
|
|
15
|
+
import type { CallToolFn } from './bridges';
|
|
16
|
+
/** Create an isolated-vm isolate with the given memory limit. */
|
|
17
|
+
export declare function createIsolate(memoryLimit: number): Promise<{
|
|
18
|
+
isolate: import("isolated-vm").Isolate;
|
|
19
|
+
ivm: typeof import("isolated-vm");
|
|
20
|
+
}>;
|
|
21
|
+
export interface SandboxExecuteOptions {
|
|
22
|
+
timeout: number;
|
|
23
|
+
memoryLimit: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Execute code in an isolated sandbox with tool access.
|
|
27
|
+
*
|
|
28
|
+
* Sets up console bridges, tool bridges, and utilities, then runs the
|
|
29
|
+
* user code. Returns the result and captured logs.
|
|
30
|
+
*/
|
|
31
|
+
export declare function executeInSandbox(code: string, tools: ToolLike[], callToolFn: CallToolFn, interfacesString: string, interfaceMap: Record<string, string>, options: SandboxExecuteOptions): Promise<{
|
|
32
|
+
result: unknown;
|
|
33
|
+
logs: string[];
|
|
34
|
+
error?: string;
|
|
35
|
+
}>;
|
|
36
|
+
//# sourceMappingURL=sandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,iEAAiE;AACjE,wBAAsB,aAAa,CAAC,WAAW,EAAE,MAAM;;;GAItD;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,QAAQ,EAAE,EACjB,UAAU,EAAE,UAAU,EACtB,gBAAgB,EAAE,MAAM,EACxB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAyC9D"}
|
package/dist/sandbox.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @code-mode/core — SandboxManager
|
|
4
|
+
*
|
|
5
|
+
* Only file that imports isolated-vm. Contains isolate creation and
|
|
6
|
+
* code execution within the sandbox.
|
|
7
|
+
*
|
|
8
|
+
* Adapted from @utcp/code-mode (CodeModeUtcpClient) by UTCP Contributors.
|
|
9
|
+
* Original: https://github.com/universal-tool-calling-protocol/code-mode
|
|
10
|
+
*
|
|
11
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
12
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
13
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
14
|
+
*/
|
|
15
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
18
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
19
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(o, k2, desc);
|
|
22
|
+
}) : (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
o[k2] = m[k];
|
|
25
|
+
}));
|
|
26
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
27
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
28
|
+
}) : function(o, v) {
|
|
29
|
+
o["default"] = v;
|
|
30
|
+
});
|
|
31
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
32
|
+
var ownKeys = function(o) {
|
|
33
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
34
|
+
var ar = [];
|
|
35
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
36
|
+
return ar;
|
|
37
|
+
};
|
|
38
|
+
return ownKeys(o);
|
|
39
|
+
};
|
|
40
|
+
return function (mod) {
|
|
41
|
+
if (mod && mod.__esModule) return mod;
|
|
42
|
+
var result = {};
|
|
43
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
44
|
+
__setModuleDefault(result, mod);
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
})();
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.createIsolate = createIsolate;
|
|
50
|
+
exports.executeInSandbox = executeInSandbox;
|
|
51
|
+
const bridges_1 = require("./bridges");
|
|
52
|
+
/** Create an isolated-vm isolate with the given memory limit. */
|
|
53
|
+
async function createIsolate(memoryLimit) {
|
|
54
|
+
const ivm = await Promise.resolve().then(() => __importStar(require('isolated-vm')));
|
|
55
|
+
const isolate = new ivm.default.Isolate({ memoryLimit });
|
|
56
|
+
return { isolate, ivm: ivm.default };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Execute code in an isolated sandbox with tool access.
|
|
60
|
+
*
|
|
61
|
+
* Sets up console bridges, tool bridges, and utilities, then runs the
|
|
62
|
+
* user code. Returns the result and captured logs.
|
|
63
|
+
*/
|
|
64
|
+
async function executeInSandbox(code, tools, callToolFn, interfacesString, interfaceMap, options) {
|
|
65
|
+
const { isolate, ivm: ivm_module } = await createIsolate(options.memoryLimit);
|
|
66
|
+
const logs = [];
|
|
67
|
+
try {
|
|
68
|
+
const context = await isolate.createContext();
|
|
69
|
+
const jail = context.global;
|
|
70
|
+
await jail.set('global', jail.derefInto());
|
|
71
|
+
await (0, bridges_1.setupConsoleBridge)(isolate, context, jail, logs, ivm_module);
|
|
72
|
+
await (0, bridges_1.setupToolBridges)(isolate, context, jail, tools, callToolFn, ivm_module);
|
|
73
|
+
await (0, bridges_1.setupUtilities)(isolate, context, jail, tools, interfacesString, interfaceMap);
|
|
74
|
+
const wrappedCode = `
|
|
75
|
+
(function() {
|
|
76
|
+
var __result = (function() {
|
|
77
|
+
${code}
|
|
78
|
+
})();
|
|
79
|
+
return JSON.stringify({ __result: __result });
|
|
80
|
+
})()
|
|
81
|
+
`;
|
|
82
|
+
const script = await isolate.compileScript(wrappedCode);
|
|
83
|
+
const resultJson = await script.run(context, { timeout: options.timeout });
|
|
84
|
+
const result = typeof resultJson === 'string'
|
|
85
|
+
? JSON.parse(resultJson).__result
|
|
86
|
+
: resultJson;
|
|
87
|
+
return { result, logs };
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
91
|
+
return {
|
|
92
|
+
result: null,
|
|
93
|
+
logs: [...logs, `[ERROR] Code execution failed: ${errorMessage}`],
|
|
94
|
+
error: errorMessage,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
isolate.dispose();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOH,sCAIC;AAaD,4CAgDC;AArED,uCAAiF;AAGjF,iEAAiE;AAC1D,KAAK,UAAU,aAAa,CAAC,WAAmB;IACrD,MAAM,GAAG,GAAG,wDAAa,aAAa,GAAC,CAAC;IACxC,MAA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