@librechat/agents 3.1.89 → 3.1.91
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/cjs/agents/AgentContext.cjs +9 -5
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +53 -14
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/hooks/executeHooks.cjs +14 -7
- package/dist/cjs/hooks/executeHooks.cjs.map +1 -1
- package/dist/cjs/langfuse.cjs +234 -0
- package/dist/cjs/langfuse.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/index.cjs +8 -2
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +34 -0
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/main.cjs +34 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/run.cjs +44 -27
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +10 -3
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +10 -9
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +12 -8
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +35 -11
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/CodeSessionFileSummary.cjs +63 -0
- package/dist/cjs/tools/CodeSessionFileSummary.cjs.map +1 -0
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +16 -12
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +8 -5
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs +380 -0
- package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs.map +1 -0
- package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs +997 -0
- package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs.map +1 -0
- package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs +575 -0
- package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs.map +1 -0
- package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs +165 -0
- package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs.map +1 -0
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs +17 -5
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs.map +1 -1
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs +110 -6
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +319 -29
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +9 -5
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +53 -14
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/hooks/executeHooks.mjs +14 -7
- package/dist/esm/hooks/executeHooks.mjs.map +1 -1
- package/dist/esm/langfuse.mjs +226 -0
- package/dist/esm/langfuse.mjs.map +1 -0
- package/dist/esm/llm/anthropic/index.mjs +9 -3
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +33 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/main.mjs +7 -2
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/run.mjs +44 -27
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +10 -3
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +11 -10
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +13 -9
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +29 -12
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/CodeSessionFileSummary.mjs +60 -0
- package/dist/esm/tools/CodeSessionFileSummary.mjs.map +1 -0
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +17 -13
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +8 -5
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs +378 -0
- package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs.map +1 -0
- package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs +994 -0
- package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs.map +1 -0
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs +566 -0
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs.map +1 -0
- package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs +155 -0
- package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs.map +1 -0
- package/dist/esm/tools/local/LocalExecutionEngine.mjs +17 -6
- package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs +111 -7
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +320 -31
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +4 -1
- package/dist/types/graphs/Graph.d.ts +6 -5
- package/dist/types/index.d.ts +1 -0
- package/dist/types/langfuse.d.ts +48 -0
- package/dist/types/llm/anthropic/index.d.ts +3 -1
- package/dist/types/llm/anthropic/utils/message_inputs.d.ts +4 -0
- package/dist/types/tools/BashExecutor.d.ts +3 -3
- package/dist/types/tools/CodeExecutor.d.ts +10 -3
- package/dist/types/tools/CodeSessionFileSummary.d.ts +3 -0
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +4 -4
- package/dist/types/tools/cloudflare/CloudflareBridgeRuntime.d.ts +23 -0
- package/dist/types/tools/cloudflare/CloudflareProgrammaticToolCalling.d.ts +4 -0
- package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +21 -0
- package/dist/types/tools/cloudflare/CloudflareSandboxTools.d.ts +22 -0
- package/dist/types/tools/cloudflare/index.d.ts +4 -0
- package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -0
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +8 -5
- package/dist/types/types/graph.d.ts +8 -0
- package/dist/types/types/tools.d.ts +120 -5
- package/package.json +4 -4
- package/src/__tests__/stream.eagerEventExecution.test.ts +66 -0
- package/src/agents/AgentContext.ts +13 -3
- package/src/graphs/Graph.ts +60 -16
- package/src/hooks/__tests__/executeHooks.test.ts +38 -0
- package/src/hooks/executeHooks.ts +27 -7
- package/src/index.ts +1 -0
- package/src/langfuse.ts +358 -0
- package/src/llm/anthropic/index.ts +27 -3
- package/src/llm/anthropic/llm.spec.ts +60 -1
- package/src/llm/anthropic/utils/message_inputs.ts +46 -0
- package/src/run.ts +60 -38
- package/src/specs/langfuse-config.test.ts +57 -0
- package/src/specs/langfuse-metadata.test.ts +19 -1
- package/src/stream.ts +13 -3
- package/src/tools/BashExecutor.ts +21 -10
- package/src/tools/BashProgrammaticToolCalling.ts +21 -9
- package/src/tools/CodeExecutor.ts +55 -12
- package/src/tools/CodeSessionFileSummary.ts +80 -0
- package/src/tools/ProgrammaticToolCalling.ts +25 -12
- package/src/tools/ToolNode.ts +8 -5
- package/src/tools/__tests__/BashExecutor.test.ts +9 -0
- package/src/tools/__tests__/CloudflareSandboxExecution.test.ts +537 -0
- package/src/tools/__tests__/CodeApiAuthHeaders.test.ts +43 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +100 -16
- package/src/tools/__tests__/SubagentExecutor.test.ts +540 -6
- package/src/tools/__tests__/ToolNode.outputReferences.test.ts +52 -0
- package/src/tools/__tests__/subagentHooks.test.ts +237 -0
- package/src/tools/cloudflare/CloudflareBridgeRuntime.ts +480 -0
- package/src/tools/cloudflare/CloudflareProgrammaticToolCalling.ts +1162 -0
- package/src/tools/cloudflare/CloudflareSandboxExecutionEngine.ts +744 -0
- package/src/tools/cloudflare/CloudflareSandboxTools.ts +225 -0
- package/src/tools/cloudflare/index.ts +4 -0
- package/src/tools/local/LocalExecutionEngine.ts +20 -4
- package/src/tools/local/resolveLocalExecutionTools.ts +169 -7
- package/src/tools/subagent/SubagentExecutor.ts +514 -36
- package/src/types/graph.ts +9 -0
- package/src/types/tools.ts +143 -5
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var events = require('events');
|
|
4
|
+
var stream = require('stream');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var LocalExecutionEngine = require('../local/LocalExecutionEngine.cjs');
|
|
7
|
+
|
|
8
|
+
const DEFAULT_WORKSPACE_ROOT = '/workspace';
|
|
9
|
+
const DEFAULT_TIMEOUT_MS = 60000;
|
|
10
|
+
const DEFAULT_MAX_OUTPUT_CHARS = 200000;
|
|
11
|
+
const PROTECTED_TARGET_ARG_RE = /^(?:\/|~|\$\{?HOME\}?|\.)(?:\/?\.?\*|\/)?$/;
|
|
12
|
+
const DESTRUCTIVE_OP_IN_COMMAND_RE = /\b(?:rm\s+-[^\s]*[rf]|chmod\s+-R|chown\s+-R)\b/;
|
|
13
|
+
const sandboxFactoryCache = new WeakMap();
|
|
14
|
+
function normalizeWorkspaceRoot(workspaceRoot) {
|
|
15
|
+
const normalized = path.posix.normalize(workspaceRoot);
|
|
16
|
+
return normalized === '/' ? normalized : normalized.replace(/\/+$/, '');
|
|
17
|
+
}
|
|
18
|
+
function getCloudflareWorkspaceRoot(config) {
|
|
19
|
+
return normalizeWorkspaceRoot(config?.workspaceRoot ?? DEFAULT_WORKSPACE_ROOT);
|
|
20
|
+
}
|
|
21
|
+
async function resolveCloudflareSandbox(config) {
|
|
22
|
+
const sandbox = config.sandbox;
|
|
23
|
+
if (typeof sandbox !== 'function') {
|
|
24
|
+
return sandbox;
|
|
25
|
+
}
|
|
26
|
+
let cached = sandboxFactoryCache.get(config);
|
|
27
|
+
if (cached == null) {
|
|
28
|
+
cached = Promise.resolve()
|
|
29
|
+
.then(() => sandbox())
|
|
30
|
+
.catch((error) => {
|
|
31
|
+
sandboxFactoryCache.delete(config);
|
|
32
|
+
throw error;
|
|
33
|
+
});
|
|
34
|
+
sandboxFactoryCache.set(config, cached);
|
|
35
|
+
}
|
|
36
|
+
return cached;
|
|
37
|
+
}
|
|
38
|
+
async function getRuntimeContext(config) {
|
|
39
|
+
return {
|
|
40
|
+
sandbox: await resolveCloudflareSandbox(config),
|
|
41
|
+
workspaceRoot: getCloudflareWorkspaceRoot(config),
|
|
42
|
+
env: config.env,
|
|
43
|
+
timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
44
|
+
maxOutputChars: config.maxOutputChars ?? DEFAULT_MAX_OUTPUT_CHARS,
|
|
45
|
+
shell: config.shell ?? 'bash',
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function toSandboxPath(filePath, workspaceRoot) {
|
|
49
|
+
const raw = filePath === '' ? '.' : filePath;
|
|
50
|
+
const root = normalizeWorkspaceRoot(workspaceRoot);
|
|
51
|
+
const resolved = raw.startsWith('/')
|
|
52
|
+
? path.posix.normalize(raw)
|
|
53
|
+
: path.posix.resolve(root, raw);
|
|
54
|
+
if (root === '/') {
|
|
55
|
+
return resolved;
|
|
56
|
+
}
|
|
57
|
+
if (resolved === root || resolved.startsWith(`${root}/`)) {
|
|
58
|
+
return resolved;
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`Path is outside the Cloudflare sandbox workspace: ${filePath}`);
|
|
61
|
+
}
|
|
62
|
+
function quote(value) {
|
|
63
|
+
if (value === '') {
|
|
64
|
+
return '\'\'';
|
|
65
|
+
}
|
|
66
|
+
if (/^[A-Za-z0-9_/:=.,@%+-]+$/.test(value)) {
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
return `'${value.replace(/'/g, '\'\\\'\'')}'`;
|
|
70
|
+
}
|
|
71
|
+
function withInSandboxTimeout(command, timeoutMs) {
|
|
72
|
+
const timeoutSeconds = Math.max(1, Math.ceil(timeoutMs / 1000));
|
|
73
|
+
return `timeout -k 2s ${timeoutSeconds}s ${command}`;
|
|
74
|
+
}
|
|
75
|
+
function outerTimeoutMs(timeoutMs) {
|
|
76
|
+
return timeoutMs + 5000;
|
|
77
|
+
}
|
|
78
|
+
function isInSandboxTimeoutExit(exitCode) {
|
|
79
|
+
return exitCode === 124 || exitCode === 137;
|
|
80
|
+
}
|
|
81
|
+
function truncateOutput(value, maxChars) {
|
|
82
|
+
if (maxChars <= 0 || value.length <= maxChars) {
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
const head = Math.max(Math.floor(maxChars / 2), 0);
|
|
86
|
+
const tail = Math.max(maxChars - head, 0);
|
|
87
|
+
return `${value.slice(0, head)}\n...[truncated ${value.length - maxChars} chars]...\n${value.slice(value.length - tail)}`;
|
|
88
|
+
}
|
|
89
|
+
async function readStream(stream) {
|
|
90
|
+
const reader = stream.getReader();
|
|
91
|
+
const chunks = [];
|
|
92
|
+
try {
|
|
93
|
+
for (;;) {
|
|
94
|
+
const { done, value } = await reader.read();
|
|
95
|
+
if (done)
|
|
96
|
+
break;
|
|
97
|
+
chunks.push(value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
reader.releaseLock();
|
|
102
|
+
}
|
|
103
|
+
return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk)));
|
|
104
|
+
}
|
|
105
|
+
async function normalizeReadFileContent(result) {
|
|
106
|
+
if (typeof result === 'string') {
|
|
107
|
+
return Buffer.from(result, 'utf8');
|
|
108
|
+
}
|
|
109
|
+
if (Buffer.isBuffer(result)) {
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
if (result instanceof Uint8Array) {
|
|
113
|
+
return Buffer.from(result);
|
|
114
|
+
}
|
|
115
|
+
const content = result.content;
|
|
116
|
+
if (typeof content === 'string') {
|
|
117
|
+
if (result.encoding === 'base64') {
|
|
118
|
+
return Buffer.from(content, 'base64');
|
|
119
|
+
}
|
|
120
|
+
return Buffer.from(content, 'utf8');
|
|
121
|
+
}
|
|
122
|
+
if (Buffer.isBuffer(content)) {
|
|
123
|
+
return content;
|
|
124
|
+
}
|
|
125
|
+
if (content instanceof Uint8Array) {
|
|
126
|
+
return Buffer.from(content);
|
|
127
|
+
}
|
|
128
|
+
return readStream(content);
|
|
129
|
+
}
|
|
130
|
+
function bytesToStream(bytes) {
|
|
131
|
+
return new ReadableStream({
|
|
132
|
+
start(controller) {
|
|
133
|
+
controller.enqueue(bytes);
|
|
134
|
+
controller.close();
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function normalizeWriteFileContent(content) {
|
|
139
|
+
if (typeof content === 'string') {
|
|
140
|
+
return { content, options: { encoding: 'utf8' } };
|
|
141
|
+
}
|
|
142
|
+
return { content: bytesToStream(content) };
|
|
143
|
+
}
|
|
144
|
+
function createStats(info) {
|
|
145
|
+
const type = info.type ?? 'file';
|
|
146
|
+
const now = new Date();
|
|
147
|
+
return {
|
|
148
|
+
size: info.size ?? 0,
|
|
149
|
+
isFile: () => type === 'file',
|
|
150
|
+
isDirectory: () => type === 'directory',
|
|
151
|
+
isSymbolicLink: () => type === 'symlink',
|
|
152
|
+
isBlockDevice: () => false,
|
|
153
|
+
isCharacterDevice: () => false,
|
|
154
|
+
isFIFO: () => false,
|
|
155
|
+
isSocket: () => false,
|
|
156
|
+
dev: 0,
|
|
157
|
+
ino: 0,
|
|
158
|
+
mode: 0,
|
|
159
|
+
nlink: 1,
|
|
160
|
+
uid: 0,
|
|
161
|
+
gid: 0,
|
|
162
|
+
rdev: 0,
|
|
163
|
+
blksize: 0,
|
|
164
|
+
blocks: 0,
|
|
165
|
+
atimeMs: now.getTime(),
|
|
166
|
+
mtimeMs: now.getTime(),
|
|
167
|
+
ctimeMs: now.getTime(),
|
|
168
|
+
birthtimeMs: now.getTime(),
|
|
169
|
+
atime: now,
|
|
170
|
+
mtime: now,
|
|
171
|
+
ctime: now,
|
|
172
|
+
birthtime: now,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function normalizeFileList(result) {
|
|
176
|
+
return Array.isArray(result) ? result : result.files;
|
|
177
|
+
}
|
|
178
|
+
function entryNameFor(info, parentPath) {
|
|
179
|
+
if (info.name !== '') {
|
|
180
|
+
return info.name.includes('/') ? path.posix.basename(info.name) : info.name;
|
|
181
|
+
}
|
|
182
|
+
if (info.absolutePath != null && info.absolutePath !== '') {
|
|
183
|
+
return path.posix.basename(info.absolutePath);
|
|
184
|
+
}
|
|
185
|
+
if (info.relativePath != null && info.relativePath !== '') {
|
|
186
|
+
return path.posix.basename(info.relativePath);
|
|
187
|
+
}
|
|
188
|
+
return path.posix.basename(parentPath);
|
|
189
|
+
}
|
|
190
|
+
function entryAbsolutePath(info, parentPath) {
|
|
191
|
+
if (info.absolutePath != null && info.absolutePath !== '') {
|
|
192
|
+
return path.posix.normalize(info.absolutePath);
|
|
193
|
+
}
|
|
194
|
+
if (info.relativePath != null && info.relativePath !== '') {
|
|
195
|
+
return path.posix.resolve(parentPath, info.relativePath);
|
|
196
|
+
}
|
|
197
|
+
return path.posix.resolve(parentPath, info.name);
|
|
198
|
+
}
|
|
199
|
+
function createDirent(info) {
|
|
200
|
+
return {
|
|
201
|
+
name: entryNameFor(info, ''),
|
|
202
|
+
isFile: () => (info.type ?? 'file') === 'file',
|
|
203
|
+
isDirectory: () => info.type === 'directory',
|
|
204
|
+
isSymbolicLink: () => info.type === 'symlink',
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
async function findChildInfo(sandbox, filePath) {
|
|
208
|
+
const parent = path.posix.dirname(filePath);
|
|
209
|
+
const basename = path.posix.basename(filePath);
|
|
210
|
+
const entries = normalizeFileList(await sandbox.listFiles(parent, { includeHidden: true }));
|
|
211
|
+
return entries.find((entry) => {
|
|
212
|
+
const absolute = entryAbsolutePath(entry, parent);
|
|
213
|
+
return absolute === filePath || entryNameFor(entry, parent) === basename;
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
function createCloudflareWorkspaceFS(config) {
|
|
217
|
+
const workspaceRoot = getCloudflareWorkspaceRoot(config);
|
|
218
|
+
const fs = {
|
|
219
|
+
readFile: (async (filePath, encoding) => {
|
|
220
|
+
const sandbox = await resolveCloudflareSandbox(config);
|
|
221
|
+
const resolved = toSandboxPath(filePath, workspaceRoot);
|
|
222
|
+
const buffer = await normalizeReadFileContent(await sandbox.readFile(resolved, encoding ? { encoding } : undefined));
|
|
223
|
+
return encoding != null ? buffer.toString(encoding) : buffer;
|
|
224
|
+
}),
|
|
225
|
+
writeFile: async (filePath, content, _options) => {
|
|
226
|
+
const sandbox = await resolveCloudflareSandbox(config);
|
|
227
|
+
const resolved = toSandboxPath(filePath, workspaceRoot);
|
|
228
|
+
const normalized = normalizeWriteFileContent(content);
|
|
229
|
+
await sandbox.writeFile(resolved, normalized.content, normalized.options);
|
|
230
|
+
},
|
|
231
|
+
stat: async (filePath) => {
|
|
232
|
+
const sandbox = await resolveCloudflareSandbox(config);
|
|
233
|
+
const resolved = toSandboxPath(filePath, workspaceRoot);
|
|
234
|
+
if (resolved === workspaceRoot) {
|
|
235
|
+
const entries = normalizeFileList(await sandbox.listFiles(resolved, { includeHidden: true }));
|
|
236
|
+
return createStats({ size: entries.length, type: 'directory' });
|
|
237
|
+
}
|
|
238
|
+
const info = await findChildInfo(sandbox, resolved);
|
|
239
|
+
if (info != null) {
|
|
240
|
+
return createStats({ size: info.size, type: info.type });
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
const entries = normalizeFileList(await sandbox.listFiles(resolved, { includeHidden: true }));
|
|
244
|
+
return createStats({ size: entries.length, type: 'directory' });
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
const buffer = await normalizeReadFileContent(await sandbox.readFile(resolved));
|
|
248
|
+
return createStats({ size: buffer.length, type: 'file' });
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
readdir: (async (filePath, options) => {
|
|
252
|
+
const sandbox = await resolveCloudflareSandbox(config);
|
|
253
|
+
const resolved = toSandboxPath(filePath, workspaceRoot);
|
|
254
|
+
const entries = normalizeFileList(await sandbox.listFiles(resolved, { includeHidden: true }));
|
|
255
|
+
if (options?.withFileTypes === true) {
|
|
256
|
+
return entries.map(createDirent);
|
|
257
|
+
}
|
|
258
|
+
return entries.map((entry) => entryNameFor(entry, resolved));
|
|
259
|
+
}),
|
|
260
|
+
mkdir: async (filePath, options) => {
|
|
261
|
+
const sandbox = await resolveCloudflareSandbox(config);
|
|
262
|
+
await sandbox.mkdir(toSandboxPath(filePath, workspaceRoot), {
|
|
263
|
+
recursive: options?.recursive,
|
|
264
|
+
});
|
|
265
|
+
},
|
|
266
|
+
realpath: async (filePath) => toSandboxPath(filePath, workspaceRoot),
|
|
267
|
+
unlink: async (filePath) => {
|
|
268
|
+
const sandbox = await resolveCloudflareSandbox(config);
|
|
269
|
+
await sandbox.deleteFile(toSandboxPath(filePath, workspaceRoot));
|
|
270
|
+
},
|
|
271
|
+
open: async (filePath, _flags) => {
|
|
272
|
+
const sandbox = await resolveCloudflareSandbox(config);
|
|
273
|
+
const resolved = toSandboxPath(filePath, workspaceRoot);
|
|
274
|
+
const buffer = await normalizeReadFileContent(await sandbox.readFile(resolved));
|
|
275
|
+
return {
|
|
276
|
+
read: async (target, offset, length, position) => {
|
|
277
|
+
const start = Math.max(position, 0);
|
|
278
|
+
const slice = buffer.subarray(start, start + length);
|
|
279
|
+
slice.copy(target, offset);
|
|
280
|
+
return { bytesRead: slice.length, buffer: target };
|
|
281
|
+
},
|
|
282
|
+
close: async () => undefined,
|
|
283
|
+
};
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
return fs;
|
|
287
|
+
}
|
|
288
|
+
function createCloudflareSpawn(config) {
|
|
289
|
+
return (command, args, options) => {
|
|
290
|
+
const stdout = new stream.PassThrough();
|
|
291
|
+
const stderr = new stream.PassThrough();
|
|
292
|
+
const abortController = new AbortController();
|
|
293
|
+
const child = new events.EventEmitter();
|
|
294
|
+
const state = { closed: false };
|
|
295
|
+
const closeOnce = (exitCode, signal) => {
|
|
296
|
+
if (state.closed) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
state.closed = true;
|
|
300
|
+
stdout.end();
|
|
301
|
+
stderr.end();
|
|
302
|
+
Object.assign(child, {
|
|
303
|
+
exitCode,
|
|
304
|
+
signalCode: signal,
|
|
305
|
+
});
|
|
306
|
+
child.emit('close', exitCode, signal);
|
|
307
|
+
};
|
|
308
|
+
Object.assign(child, {
|
|
309
|
+
stdout,
|
|
310
|
+
stderr,
|
|
311
|
+
stdin: new stream.PassThrough(),
|
|
312
|
+
stdio: [null, stdout, stderr],
|
|
313
|
+
killed: false,
|
|
314
|
+
exitCode: null,
|
|
315
|
+
signalCode: null,
|
|
316
|
+
pid: undefined,
|
|
317
|
+
kill: (signal = 'SIGTERM') => {
|
|
318
|
+
Object.assign(child, { killed: true, signalCode: signal });
|
|
319
|
+
abortController.abort();
|
|
320
|
+
closeOnce(null, signal);
|
|
321
|
+
return true;
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
void (async () => {
|
|
325
|
+
const ctx = await getRuntimeContext(config);
|
|
326
|
+
const rendered = [command, ...args].map(quote).join(' ');
|
|
327
|
+
const spawnTimeoutMs = options[LocalExecutionEngine.LOCAL_SPAWN_TIMEOUT_MS];
|
|
328
|
+
const timeoutMs = typeof spawnTimeoutMs === 'number' && Number.isFinite(spawnTimeoutMs)
|
|
329
|
+
? spawnTimeoutMs
|
|
330
|
+
: ctx.timeoutMs;
|
|
331
|
+
const timedCommand = withInSandboxTimeout(rendered, timeoutMs);
|
|
332
|
+
const cwd = options.cwd == null ? ctx.workspaceRoot : options.cwd.toString();
|
|
333
|
+
try {
|
|
334
|
+
const result = await ctx.sandbox.exec(timedCommand, {
|
|
335
|
+
cwd,
|
|
336
|
+
env: ctx.env,
|
|
337
|
+
timeout: outerTimeoutMs(timeoutMs),
|
|
338
|
+
signal: abortController.signal,
|
|
339
|
+
});
|
|
340
|
+
if (state.closed) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (result.stdout)
|
|
344
|
+
stdout.write(result.stdout);
|
|
345
|
+
if (result.stderr)
|
|
346
|
+
stderr.write(result.stderr);
|
|
347
|
+
closeOnce(result.exitCode, null);
|
|
348
|
+
}
|
|
349
|
+
catch (error) {
|
|
350
|
+
if (state.closed) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
stderr.write(error.message);
|
|
354
|
+
closeOnce(1, null);
|
|
355
|
+
}
|
|
356
|
+
})();
|
|
357
|
+
return child;
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function createCloudflareLocalExecutionConfig(config) {
|
|
361
|
+
const workspaceRoot = getCloudflareWorkspaceRoot(config);
|
|
362
|
+
return {
|
|
363
|
+
cwd: workspaceRoot,
|
|
364
|
+
workspace: { root: workspaceRoot },
|
|
365
|
+
exec: {
|
|
366
|
+
spawn: createCloudflareSpawn(config),
|
|
367
|
+
fs: createCloudflareWorkspaceFS(config),
|
|
368
|
+
sandboxed: true,
|
|
369
|
+
},
|
|
370
|
+
shell: config.shell ?? 'bash',
|
|
371
|
+
timeoutMs: config.timeoutMs,
|
|
372
|
+
maxOutputChars: config.maxOutputChars,
|
|
373
|
+
env: config.env,
|
|
374
|
+
includeCodingTools: config.includeCodingTools,
|
|
375
|
+
compileCheck: config.compileCheck,
|
|
376
|
+
readOnly: config.readOnly,
|
|
377
|
+
allowDangerousCommands: config.allowDangerousCommands,
|
|
378
|
+
bashAst: config.bashAst,
|
|
379
|
+
fileCheckpointing: config.fileCheckpointing,
|
|
380
|
+
maxReadBytes: config.maxReadBytes,
|
|
381
|
+
attachReadAttachments: config.attachReadAttachments,
|
|
382
|
+
maxAttachmentBytes: config.maxAttachmentBytes,
|
|
383
|
+
postEditSyntaxCheck: config.postEditSyntaxCheck,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
async function validateCloudflareBashCommand(command, args, config) {
|
|
387
|
+
const localConfig = createCloudflareLocalExecutionConfig(config);
|
|
388
|
+
const validation = await LocalExecutionEngine.validateBashCommand(command, localConfig);
|
|
389
|
+
if (!validation.valid) {
|
|
390
|
+
throw new Error(validation.errors.join('\n'));
|
|
391
|
+
}
|
|
392
|
+
if (args.length > 0 &&
|
|
393
|
+
config.allowDangerousCommands !== true &&
|
|
394
|
+
DESTRUCTIVE_OP_IN_COMMAND_RE.test(command)) {
|
|
395
|
+
const offending = args.find((arg) => PROTECTED_TARGET_ARG_RE.test(arg));
|
|
396
|
+
if (offending !== undefined) {
|
|
397
|
+
throw new Error(`Command matches a destructive command pattern (protected target "${offending}" passed via positional arg).`);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
async function executeCloudflareBash(command, config, args = []) {
|
|
402
|
+
await validateCloudflareBashCommand(command, args, config);
|
|
403
|
+
const ctx = await getRuntimeContext(config);
|
|
404
|
+
const shellCommand = args.length > 0
|
|
405
|
+
? `${ctx.shell} -lc ${quote(command)} -- ${args.map(quote).join(' ')}`
|
|
406
|
+
: `${ctx.shell} -lc ${quote(command)}`;
|
|
407
|
+
const result = await ctx.sandbox.exec(withInSandboxTimeout(shellCommand, ctx.timeoutMs), {
|
|
408
|
+
cwd: ctx.workspaceRoot,
|
|
409
|
+
env: ctx.env,
|
|
410
|
+
timeout: outerTimeoutMs(ctx.timeoutMs),
|
|
411
|
+
});
|
|
412
|
+
return {
|
|
413
|
+
stdout: truncateOutput(result.stdout, ctx.maxOutputChars),
|
|
414
|
+
stderr: truncateOutput(result.stderr, ctx.maxOutputChars),
|
|
415
|
+
exitCode: result.exitCode,
|
|
416
|
+
timedOut: isInSandboxTimeoutExit(result.exitCode),
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
function runtimeForCode(lang, tempDir, code, args = [], shell = 'bash') {
|
|
420
|
+
const fileFor = (name) => path.posix.join(tempDir, name);
|
|
421
|
+
const argText = args.map(quote).join(' ');
|
|
422
|
+
switch (lang) {
|
|
423
|
+
case 'py':
|
|
424
|
+
case 'python':
|
|
425
|
+
return {
|
|
426
|
+
fileName: 'main.py',
|
|
427
|
+
source: code,
|
|
428
|
+
command: `python3 ${quote(fileFor('main.py'))} ${argText}`,
|
|
429
|
+
};
|
|
430
|
+
case 'js':
|
|
431
|
+
case 'javascript':
|
|
432
|
+
return {
|
|
433
|
+
fileName: 'main.js',
|
|
434
|
+
source: code,
|
|
435
|
+
command: `node ${quote(fileFor('main.js'))} ${argText}`,
|
|
436
|
+
};
|
|
437
|
+
case 'ts':
|
|
438
|
+
case 'typescript':
|
|
439
|
+
return {
|
|
440
|
+
fileName: 'main.ts',
|
|
441
|
+
source: code,
|
|
442
|
+
command: `npx --no-install tsx ${quote(fileFor('main.ts'))} ${argText}`,
|
|
443
|
+
};
|
|
444
|
+
case 'php':
|
|
445
|
+
return {
|
|
446
|
+
fileName: 'main.php',
|
|
447
|
+
source: code,
|
|
448
|
+
command: `php ${quote(fileFor('main.php'))} ${argText}`,
|
|
449
|
+
};
|
|
450
|
+
case 'go':
|
|
451
|
+
return {
|
|
452
|
+
fileName: 'main.go',
|
|
453
|
+
source: code,
|
|
454
|
+
command: `go run ${quote(fileFor('main.go'))} ${argText}`,
|
|
455
|
+
};
|
|
456
|
+
case 'rs':
|
|
457
|
+
return {
|
|
458
|
+
fileName: 'main.rs',
|
|
459
|
+
source: code,
|
|
460
|
+
command: `${shell} -lc ${quote(`rustc ${quote(fileFor('main.rs'))} -o ${quote(fileFor('main-rs'))} && ${quote(fileFor('main-rs'))} ${argText}`)}`,
|
|
461
|
+
};
|
|
462
|
+
case 'c':
|
|
463
|
+
return {
|
|
464
|
+
fileName: 'main.c',
|
|
465
|
+
source: code,
|
|
466
|
+
command: `${shell} -lc ${quote(`cc ${quote(fileFor('main.c'))} -o ${quote(fileFor('main-c'))} && ${quote(fileFor('main-c'))} ${argText}`)}`,
|
|
467
|
+
};
|
|
468
|
+
case 'cpp':
|
|
469
|
+
return {
|
|
470
|
+
fileName: 'main.cpp',
|
|
471
|
+
source: code,
|
|
472
|
+
command: `${shell} -lc ${quote(`c++ ${quote(fileFor('main.cpp'))} -o ${quote(fileFor('main-cpp'))} && ${quote(fileFor('main-cpp'))} ${argText}`)}`,
|
|
473
|
+
};
|
|
474
|
+
case 'java':
|
|
475
|
+
return {
|
|
476
|
+
fileName: 'Main.java',
|
|
477
|
+
source: code,
|
|
478
|
+
command: `${shell} -lc ${quote(`javac ${quote(fileFor('Main.java'))} && java -cp ${quote(tempDir)} Main ${argText}`)}`,
|
|
479
|
+
};
|
|
480
|
+
case 'r':
|
|
481
|
+
return {
|
|
482
|
+
fileName: 'main.R',
|
|
483
|
+
source: code,
|
|
484
|
+
command: `Rscript ${quote(fileFor('main.R'))} ${argText}`,
|
|
485
|
+
};
|
|
486
|
+
case 'd':
|
|
487
|
+
return {
|
|
488
|
+
fileName: 'main.d',
|
|
489
|
+
source: code,
|
|
490
|
+
command: `${shell} -lc ${quote(`dmd ${quote(fileFor('main.d'))} -of=${quote(fileFor('main-d'))} && ${quote(fileFor('main-d'))} ${argText}`)}`,
|
|
491
|
+
};
|
|
492
|
+
case 'f90':
|
|
493
|
+
return {
|
|
494
|
+
fileName: 'main.f90',
|
|
495
|
+
source: code,
|
|
496
|
+
command: `${shell} -lc ${quote(`gfortran ${quote(fileFor('main.f90'))} -o ${quote(fileFor('main-f90'))} && ${quote(fileFor('main-f90'))} ${argText}`)}`,
|
|
497
|
+
};
|
|
498
|
+
case 'bash':
|
|
499
|
+
case 'sh':
|
|
500
|
+
return {
|
|
501
|
+
fileName: 'main.sh',
|
|
502
|
+
source: code,
|
|
503
|
+
command: `${shell} -lc ${quote(code)} -- ${argText}`,
|
|
504
|
+
};
|
|
505
|
+
default:
|
|
506
|
+
throw new Error(`Unsupported Cloudflare sandbox runtime: ${lang}`);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
async function executeCloudflareCode(input, config) {
|
|
510
|
+
if (input.lang === 'bash' || input.lang === 'sh') {
|
|
511
|
+
return executeCloudflareBash(input.code, config, input.args ?? []);
|
|
512
|
+
}
|
|
513
|
+
const ctx = await getRuntimeContext(config);
|
|
514
|
+
const id = globalThis.crypto.randomUUID();
|
|
515
|
+
const tempDir = path.posix.join(ctx.workspaceRoot, '.lc-exec', id);
|
|
516
|
+
const runtime = runtimeForCode(input.lang, tempDir, input.code, input.args, ctx.shell);
|
|
517
|
+
await ctx.sandbox.mkdir(tempDir, { recursive: true });
|
|
518
|
+
if (runtime.source != null) {
|
|
519
|
+
await ctx.sandbox.writeFile(path.posix.join(tempDir, runtime.fileName), runtime.source, {
|
|
520
|
+
encoding: 'utf8',
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
try {
|
|
524
|
+
const result = await ctx.sandbox.exec(withInSandboxTimeout(runtime.command, ctx.timeoutMs), {
|
|
525
|
+
cwd: ctx.workspaceRoot,
|
|
526
|
+
env: ctx.env,
|
|
527
|
+
timeout: outerTimeoutMs(ctx.timeoutMs),
|
|
528
|
+
});
|
|
529
|
+
return {
|
|
530
|
+
stdout: truncateOutput(result.stdout, ctx.maxOutputChars),
|
|
531
|
+
stderr: truncateOutput(result.stderr, ctx.maxOutputChars),
|
|
532
|
+
exitCode: result.exitCode,
|
|
533
|
+
timedOut: isInSandboxTimeoutExit(result.exitCode),
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
finally {
|
|
537
|
+
await ctx.sandbox
|
|
538
|
+
.exec(`rm -rf ${quote(tempDir)}`, {
|
|
539
|
+
cwd: ctx.workspaceRoot,
|
|
540
|
+
env: ctx.env,
|
|
541
|
+
timeout: 10000,
|
|
542
|
+
})
|
|
543
|
+
.catch(() => undefined);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function formatCloudflareOutput(result, cwd) {
|
|
547
|
+
let formatted = '';
|
|
548
|
+
if (result.stdout !== '') {
|
|
549
|
+
formatted += `stdout:\n${result.stdout}\n`;
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
formatted += 'stdout: Empty. Ensure you\'re writing output explicitly.\n';
|
|
553
|
+
}
|
|
554
|
+
if (result.stderr !== '') {
|
|
555
|
+
formatted += `stderr:\n${result.stderr}\n`;
|
|
556
|
+
}
|
|
557
|
+
if (result.exitCode != null && result.exitCode !== 0) {
|
|
558
|
+
formatted += `exit_code: ${result.exitCode}\n`;
|
|
559
|
+
}
|
|
560
|
+
if (result.timedOut) {
|
|
561
|
+
formatted += 'timed_out: true\n';
|
|
562
|
+
}
|
|
563
|
+
formatted += `working_directory: ${cwd}`;
|
|
564
|
+
return formatted.trim();
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
exports.createCloudflareLocalExecutionConfig = createCloudflareLocalExecutionConfig;
|
|
568
|
+
exports.createCloudflareWorkspaceFS = createCloudflareWorkspaceFS;
|
|
569
|
+
exports.executeCloudflareBash = executeCloudflareBash;
|
|
570
|
+
exports.executeCloudflareCode = executeCloudflareCode;
|
|
571
|
+
exports.formatCloudflareOutput = formatCloudflareOutput;
|
|
572
|
+
exports.getCloudflareWorkspaceRoot = getCloudflareWorkspaceRoot;
|
|
573
|
+
exports.resolveCloudflareSandbox = resolveCloudflareSandbox;
|
|
574
|
+
exports.validateCloudflareBashCommand = validateCloudflareBashCommand;
|
|
575
|
+
//# sourceMappingURL=CloudflareSandboxExecutionEngine.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudflareSandboxExecutionEngine.cjs","sources":["../../../../src/tools/cloudflare/CloudflareSandboxExecutionEngine.ts"],"sourcesContent":["import { EventEmitter } from 'events';\nimport { PassThrough } from 'stream';\nimport { posix as path } from 'path';\nimport type { ChildProcessWithoutNullStreams } from 'child_process';\nimport type { WriteFileOptions, MakeDirectoryOptions, Stats } from 'fs';\nimport type { FileHandle } from 'fs/promises';\nimport type * as t from '@/types';\nimport {\n LOCAL_SPAWN_TIMEOUT_MS,\n validateBashCommand,\n} from '@/tools/local/LocalExecutionEngine';\nimport type { WorkspaceFS, ReaddirEntry } from '@/tools/local/workspaceFS';\n\nconst DEFAULT_WORKSPACE_ROOT = '/workspace';\nconst DEFAULT_TIMEOUT_MS = 60000;\nconst DEFAULT_MAX_OUTPUT_CHARS = 200000;\nconst PROTECTED_TARGET_ARG_RE = /^(?:\\/|~|\\$\\{?HOME\\}?|\\.)(?:\\/?\\.?\\*|\\/)?$/;\nconst DESTRUCTIVE_OP_IN_COMMAND_RE =\n /\\b(?:rm\\s+-[^\\s]*[rf]|chmod\\s+-R|chown\\s+-R)\\b/;\n\ntype SpawnResult = {\n stdout: string;\n stderr: string;\n exitCode: number | null;\n timedOut: boolean;\n};\n\ntype RuntimeCommand = {\n fileName: string;\n source?: string;\n command: string;\n};\n\ntype SandboxRuntimeContext = {\n sandbox: t.CloudflareSandboxRuntime;\n workspaceRoot: string;\n env?: Record<string, string | undefined>;\n timeoutMs: number;\n maxOutputChars: number;\n shell: string;\n};\n\nconst sandboxFactoryCache = new WeakMap<\n t.CloudflareSandboxExecutionConfig,\n Promise<t.CloudflareSandboxRuntime>\n>();\n\nfunction normalizeWorkspaceRoot(workspaceRoot: string): string {\n const normalized = path.normalize(workspaceRoot);\n return normalized === '/' ? normalized : normalized.replace(/\\/+$/, '');\n}\n\nexport function getCloudflareWorkspaceRoot(\n config?: t.CloudflareSandboxExecutionConfig\n): string {\n return normalizeWorkspaceRoot(\n config?.workspaceRoot ?? DEFAULT_WORKSPACE_ROOT\n );\n}\n\nexport async function resolveCloudflareSandbox(\n config: t.CloudflareSandboxExecutionConfig\n): Promise<t.CloudflareSandboxRuntime> {\n const sandbox = config.sandbox;\n if (typeof sandbox !== 'function') {\n return sandbox;\n }\n let cached = sandboxFactoryCache.get(config);\n if (cached == null) {\n cached = Promise.resolve()\n .then(() => sandbox())\n .catch((error: unknown) => {\n sandboxFactoryCache.delete(config);\n throw error;\n });\n sandboxFactoryCache.set(config, cached);\n }\n return cached;\n}\n\nasync function getRuntimeContext(\n config: t.CloudflareSandboxExecutionConfig\n): Promise<SandboxRuntimeContext> {\n return {\n sandbox: await resolveCloudflareSandbox(config),\n workspaceRoot: getCloudflareWorkspaceRoot(config),\n env: config.env,\n timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,\n maxOutputChars: config.maxOutputChars ?? DEFAULT_MAX_OUTPUT_CHARS,\n shell: config.shell ?? 'bash',\n };\n}\n\nfunction toSandboxPath(filePath: string, workspaceRoot: string): string {\n const raw = filePath === '' ? '.' : filePath;\n const root = normalizeWorkspaceRoot(workspaceRoot);\n const resolved = raw.startsWith('/')\n ? path.normalize(raw)\n : path.resolve(root, raw);\n if (root === '/') {\n return resolved;\n }\n if (resolved === root || resolved.startsWith(`${root}/`)) {\n return resolved;\n }\n throw new Error(\n `Path is outside the Cloudflare sandbox workspace: ${filePath}`\n );\n}\n\nfunction quote(value: string): string {\n if (value === '') {\n return '\\'\\'';\n }\n if (/^[A-Za-z0-9_/:=.,@%+-]+$/.test(value)) {\n return value;\n }\n return `'${value.replace(/'/g, '\\'\\\\\\'\\'')}'`;\n}\n\nfunction withInSandboxTimeout(command: string, timeoutMs: number): string {\n const timeoutSeconds = Math.max(1, Math.ceil(timeoutMs / 1000));\n return `timeout -k 2s ${timeoutSeconds}s ${command}`;\n}\n\nfunction outerTimeoutMs(timeoutMs: number): number {\n return timeoutMs + 5000;\n}\n\nfunction isInSandboxTimeoutExit(exitCode: number | null): boolean {\n return exitCode === 124 || exitCode === 137;\n}\n\nfunction truncateOutput(value: string, maxChars: number): string {\n if (maxChars <= 0 || value.length <= maxChars) {\n return value;\n }\n const head = Math.max(Math.floor(maxChars / 2), 0);\n const tail = Math.max(maxChars - head, 0);\n return `${value.slice(0, head)}\\n...[truncated ${value.length - maxChars} chars]...\\n${value.slice(value.length - tail)}`;\n}\n\nasync function readStream(stream: ReadableStream<Uint8Array>): Promise<Buffer> {\n const reader = stream.getReader();\n const chunks: Uint8Array[] = [];\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n chunks.push(value);\n }\n } finally {\n reader.releaseLock();\n }\n return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk)));\n}\n\nasync function normalizeReadFileContent(\n result: t.CloudflareSandboxReadFileResult\n): Promise<Buffer> {\n if (typeof result === 'string') {\n return Buffer.from(result, 'utf8');\n }\n if (Buffer.isBuffer(result)) {\n return result;\n }\n if (result instanceof Uint8Array) {\n return Buffer.from(result);\n }\n const content = result.content;\n if (typeof content === 'string') {\n if (result.encoding === 'base64') {\n return Buffer.from(content, 'base64');\n }\n return Buffer.from(content, 'utf8');\n }\n if (Buffer.isBuffer(content)) {\n return content;\n }\n if (content instanceof Uint8Array) {\n return Buffer.from(content);\n }\n return readStream(content);\n}\n\nfunction bytesToStream(bytes: Uint8Array): ReadableStream<Uint8Array> {\n return new ReadableStream<Uint8Array>({\n start(controller): void {\n controller.enqueue(bytes);\n controller.close();\n },\n });\n}\n\nfunction normalizeWriteFileContent(content: string | Buffer | Uint8Array): {\n content: string | ReadableStream<Uint8Array>;\n options?: { encoding?: string };\n} {\n if (typeof content === 'string') {\n return { content, options: { encoding: 'utf8' } };\n }\n return { content: bytesToStream(content) };\n}\n\nfunction createStats(info: {\n size?: number;\n type?: t.CloudflareSandboxFileInfo['type'];\n}): Stats {\n const type = info.type ?? 'file';\n const now = new Date();\n return {\n size: info.size ?? 0,\n isFile: () => type === 'file',\n isDirectory: () => type === 'directory',\n isSymbolicLink: () => type === 'symlink',\n isBlockDevice: () => false,\n isCharacterDevice: () => false,\n isFIFO: () => false,\n isSocket: () => false,\n dev: 0,\n ino: 0,\n mode: 0,\n nlink: 1,\n uid: 0,\n gid: 0,\n rdev: 0,\n blksize: 0,\n blocks: 0,\n atimeMs: now.getTime(),\n mtimeMs: now.getTime(),\n ctimeMs: now.getTime(),\n birthtimeMs: now.getTime(),\n atime: now,\n mtime: now,\n ctime: now,\n birthtime: now,\n } as Stats;\n}\n\nfunction normalizeFileList(\n result: t.CloudflareSandboxListFilesResult\n): t.CloudflareSandboxFileInfo[] {\n return Array.isArray(result) ? result : result.files;\n}\n\nfunction entryNameFor(\n info: t.CloudflareSandboxFileInfo,\n parentPath: string\n): string {\n if (info.name !== '') {\n return info.name.includes('/') ? path.basename(info.name) : info.name;\n }\n if (info.absolutePath != null && info.absolutePath !== '') {\n return path.basename(info.absolutePath);\n }\n if (info.relativePath != null && info.relativePath !== '') {\n return path.basename(info.relativePath);\n }\n return path.basename(parentPath);\n}\n\nfunction entryAbsolutePath(\n info: t.CloudflareSandboxFileInfo,\n parentPath: string\n): string {\n if (info.absolutePath != null && info.absolutePath !== '') {\n return path.normalize(info.absolutePath);\n }\n if (info.relativePath != null && info.relativePath !== '') {\n return path.resolve(parentPath, info.relativePath);\n }\n return path.resolve(parentPath, info.name);\n}\n\nfunction createDirent(info: t.CloudflareSandboxFileInfo): ReaddirEntry {\n return {\n name: entryNameFor(info, ''),\n isFile: () => (info.type ?? 'file') === 'file',\n isDirectory: () => info.type === 'directory',\n isSymbolicLink: () => info.type === 'symlink',\n };\n}\n\nasync function findChildInfo(\n sandbox: t.CloudflareSandboxRuntime,\n filePath: string\n): Promise<t.CloudflareSandboxFileInfo | undefined> {\n const parent = path.dirname(filePath);\n const basename = path.basename(filePath);\n const entries = normalizeFileList(\n await sandbox.listFiles(parent, { includeHidden: true })\n );\n return entries.find((entry) => {\n const absolute = entryAbsolutePath(entry, parent);\n return absolute === filePath || entryNameFor(entry, parent) === basename;\n });\n}\n\nexport function createCloudflareWorkspaceFS(\n config: t.CloudflareSandboxExecutionConfig\n): WorkspaceFS {\n const workspaceRoot = getCloudflareWorkspaceRoot(config);\n\n const fs: WorkspaceFS = {\n readFile: (async (filePath: string, encoding?: 'utf8') => {\n const sandbox = await resolveCloudflareSandbox(config);\n const resolved = toSandboxPath(filePath, workspaceRoot);\n const buffer = await normalizeReadFileContent(\n await sandbox.readFile(resolved, encoding ? { encoding } : undefined)\n );\n return encoding != null ? buffer.toString(encoding) : buffer;\n }) as WorkspaceFS['readFile'],\n writeFile: async (\n filePath: string,\n content: string | Buffer,\n _options?: WriteFileOptions\n ) => {\n const sandbox = await resolveCloudflareSandbox(config);\n const resolved = toSandboxPath(filePath, workspaceRoot);\n const normalized = normalizeWriteFileContent(content);\n await sandbox.writeFile(resolved, normalized.content, normalized.options);\n },\n stat: async (filePath: string) => {\n const sandbox = await resolveCloudflareSandbox(config);\n const resolved = toSandboxPath(filePath, workspaceRoot);\n if (resolved === workspaceRoot) {\n const entries = normalizeFileList(\n await sandbox.listFiles(resolved, { includeHidden: true })\n );\n return createStats({ size: entries.length, type: 'directory' });\n }\n const info = await findChildInfo(sandbox, resolved);\n if (info != null) {\n return createStats({ size: info.size, type: info.type });\n }\n try {\n const entries = normalizeFileList(\n await sandbox.listFiles(resolved, { includeHidden: true })\n );\n return createStats({ size: entries.length, type: 'directory' });\n } catch {\n const buffer = await normalizeReadFileContent(\n await sandbox.readFile(resolved)\n );\n return createStats({ size: buffer.length, type: 'file' });\n }\n },\n readdir: (async (filePath: string, options?: { withFileTypes: true }) => {\n const sandbox = await resolveCloudflareSandbox(config);\n const resolved = toSandboxPath(filePath, workspaceRoot);\n const entries = normalizeFileList(\n await sandbox.listFiles(resolved, { includeHidden: true })\n );\n if (options?.withFileTypes === true) {\n return entries.map(createDirent);\n }\n return entries.map((entry) => entryNameFor(entry, resolved));\n }) as WorkspaceFS['readdir'],\n mkdir: async (filePath: string, options?: MakeDirectoryOptions) => {\n const sandbox = await resolveCloudflareSandbox(config);\n await sandbox.mkdir(toSandboxPath(filePath, workspaceRoot), {\n recursive: options?.recursive,\n });\n },\n realpath: async (filePath: string) =>\n toSandboxPath(filePath, workspaceRoot),\n unlink: async (filePath: string) => {\n const sandbox = await resolveCloudflareSandbox(config);\n await sandbox.deleteFile(toSandboxPath(filePath, workspaceRoot));\n },\n open: async (filePath: string, _flags: 'r') => {\n const sandbox = await resolveCloudflareSandbox(config);\n const resolved = toSandboxPath(filePath, workspaceRoot);\n const buffer = await normalizeReadFileContent(\n await sandbox.readFile(resolved)\n );\n return {\n read: async (\n target: Buffer,\n offset: number,\n length: number,\n position: number\n ) => {\n const start = Math.max(position, 0);\n const slice = buffer.subarray(start, start + length);\n slice.copy(target, offset);\n return { bytesRead: slice.length, buffer: target };\n },\n close: async () => undefined,\n } as unknown as FileHandle;\n },\n };\n\n return fs;\n}\n\nfunction createCloudflareSpawn(\n config: t.CloudflareSandboxExecutionConfig\n): t.LocalSpawn {\n return (command, args, options) => {\n const stdout = new PassThrough();\n const stderr = new PassThrough();\n const abortController = new AbortController();\n const child = new EventEmitter() as ChildProcessWithoutNullStreams;\n const state = { closed: false };\n const closeOnce = (\n exitCode: number | null,\n signal: NodeJS.Signals | null\n ): void => {\n if (state.closed) {\n return;\n }\n state.closed = true;\n stdout.end();\n stderr.end();\n Object.assign(child, {\n exitCode,\n signalCode: signal,\n });\n child.emit('close', exitCode, signal);\n };\n Object.assign(child, {\n stdout,\n stderr,\n stdin: new PassThrough(),\n stdio: [null, stdout, stderr],\n killed: false,\n exitCode: null,\n signalCode: null,\n pid: undefined,\n kill: (signal: NodeJS.Signals = 'SIGTERM') => {\n Object.assign(child, { killed: true, signalCode: signal });\n abortController.abort();\n closeOnce(null, signal);\n return true;\n },\n });\n\n void (async (): Promise<void> => {\n const ctx = await getRuntimeContext(config);\n const rendered = [command, ...args].map(quote).join(' ');\n const spawnTimeoutMs = (\n options as {\n [LOCAL_SPAWN_TIMEOUT_MS]?: number;\n }\n )[LOCAL_SPAWN_TIMEOUT_MS];\n const timeoutMs =\n typeof spawnTimeoutMs === 'number' && Number.isFinite(spawnTimeoutMs)\n ? spawnTimeoutMs\n : ctx.timeoutMs;\n const timedCommand = withInSandboxTimeout(rendered, timeoutMs);\n const cwd =\n options.cwd == null ? ctx.workspaceRoot : options.cwd.toString();\n try {\n const result = await ctx.sandbox.exec(timedCommand, {\n cwd,\n env: ctx.env,\n timeout: outerTimeoutMs(timeoutMs),\n signal: abortController.signal,\n });\n if (state.closed) {\n return;\n }\n if (result.stdout) stdout.write(result.stdout);\n if (result.stderr) stderr.write(result.stderr);\n closeOnce(result.exitCode, null);\n } catch (error) {\n if (state.closed) {\n return;\n }\n stderr.write((error as Error).message);\n closeOnce(1, null);\n }\n })();\n\n return child;\n };\n}\n\nexport function createCloudflareLocalExecutionConfig(\n config: t.CloudflareSandboxExecutionConfig\n): t.LocalExecutionConfig {\n const workspaceRoot = getCloudflareWorkspaceRoot(config);\n return {\n cwd: workspaceRoot,\n workspace: { root: workspaceRoot },\n exec: {\n spawn: createCloudflareSpawn(config),\n fs: createCloudflareWorkspaceFS(config),\n sandboxed: true,\n },\n shell: config.shell ?? 'bash',\n timeoutMs: config.timeoutMs,\n maxOutputChars: config.maxOutputChars,\n env: config.env,\n includeCodingTools: config.includeCodingTools,\n compileCheck: config.compileCheck,\n readOnly: config.readOnly,\n allowDangerousCommands: config.allowDangerousCommands,\n bashAst: config.bashAst,\n fileCheckpointing: config.fileCheckpointing,\n maxReadBytes: config.maxReadBytes,\n attachReadAttachments: config.attachReadAttachments,\n maxAttachmentBytes: config.maxAttachmentBytes,\n postEditSyntaxCheck: config.postEditSyntaxCheck,\n };\n}\n\nexport async function validateCloudflareBashCommand(\n command: string,\n args: readonly string[],\n config: t.CloudflareSandboxExecutionConfig\n): Promise<void> {\n const localConfig = createCloudflareLocalExecutionConfig(config);\n const validation = await validateBashCommand(command, localConfig);\n if (!validation.valid) {\n throw new Error(validation.errors.join('\\n'));\n }\n\n if (\n args.length > 0 &&\n config.allowDangerousCommands !== true &&\n DESTRUCTIVE_OP_IN_COMMAND_RE.test(command)\n ) {\n const offending = args.find((arg) => PROTECTED_TARGET_ARG_RE.test(arg));\n if (offending !== undefined) {\n throw new Error(\n `Command matches a destructive command pattern (protected target \"${offending}\" passed via positional arg).`\n );\n }\n }\n}\n\nexport async function executeCloudflareBash(\n command: string,\n config: t.CloudflareSandboxExecutionConfig,\n args: readonly string[] = []\n): Promise<SpawnResult> {\n await validateCloudflareBashCommand(command, args, config);\n const ctx = await getRuntimeContext(config);\n const shellCommand =\n args.length > 0\n ? `${ctx.shell} -lc ${quote(command)} -- ${args.map(quote).join(' ')}`\n : `${ctx.shell} -lc ${quote(command)}`;\n const result = await ctx.sandbox.exec(\n withInSandboxTimeout(shellCommand, ctx.timeoutMs),\n {\n cwd: ctx.workspaceRoot,\n env: ctx.env,\n timeout: outerTimeoutMs(ctx.timeoutMs),\n }\n );\n return {\n stdout: truncateOutput(result.stdout, ctx.maxOutputChars),\n stderr: truncateOutput(result.stderr, ctx.maxOutputChars),\n exitCode: result.exitCode,\n timedOut: isInSandboxTimeoutExit(result.exitCode),\n };\n}\n\nfunction runtimeForCode(\n lang: string,\n tempDir: string,\n code: string,\n args: string[] = [],\n shell = 'bash'\n): RuntimeCommand {\n const fileFor = (name: string): string => path.join(tempDir, name);\n const argText = args.map(quote).join(' ');\n switch (lang) {\n case 'py':\n case 'python':\n return {\n fileName: 'main.py',\n source: code,\n command: `python3 ${quote(fileFor('main.py'))} ${argText}`,\n };\n case 'js':\n case 'javascript':\n return {\n fileName: 'main.js',\n source: code,\n command: `node ${quote(fileFor('main.js'))} ${argText}`,\n };\n case 'ts':\n case 'typescript':\n return {\n fileName: 'main.ts',\n source: code,\n command: `npx --no-install tsx ${quote(fileFor('main.ts'))} ${argText}`,\n };\n case 'php':\n return {\n fileName: 'main.php',\n source: code,\n command: `php ${quote(fileFor('main.php'))} ${argText}`,\n };\n case 'go':\n return {\n fileName: 'main.go',\n source: code,\n command: `go run ${quote(fileFor('main.go'))} ${argText}`,\n };\n case 'rs':\n return {\n fileName: 'main.rs',\n source: code,\n command: `${shell} -lc ${quote(\n `rustc ${quote(fileFor('main.rs'))} -o ${quote(fileFor('main-rs'))} && ${quote(fileFor('main-rs'))} ${argText}`\n )}`,\n };\n case 'c':\n return {\n fileName: 'main.c',\n source: code,\n command: `${shell} -lc ${quote(\n `cc ${quote(fileFor('main.c'))} -o ${quote(fileFor('main-c'))} && ${quote(fileFor('main-c'))} ${argText}`\n )}`,\n };\n case 'cpp':\n return {\n fileName: 'main.cpp',\n source: code,\n command: `${shell} -lc ${quote(\n `c++ ${quote(fileFor('main.cpp'))} -o ${quote(fileFor('main-cpp'))} && ${quote(fileFor('main-cpp'))} ${argText}`\n )}`,\n };\n case 'java':\n return {\n fileName: 'Main.java',\n source: code,\n command: `${shell} -lc ${quote(\n `javac ${quote(fileFor('Main.java'))} && java -cp ${quote(tempDir)} Main ${argText}`\n )}`,\n };\n case 'r':\n return {\n fileName: 'main.R',\n source: code,\n command: `Rscript ${quote(fileFor('main.R'))} ${argText}`,\n };\n case 'd':\n return {\n fileName: 'main.d',\n source: code,\n command: `${shell} -lc ${quote(\n `dmd ${quote(fileFor('main.d'))} -of=${quote(fileFor('main-d'))} && ${quote(fileFor('main-d'))} ${argText}`\n )}`,\n };\n case 'f90':\n return {\n fileName: 'main.f90',\n source: code,\n command: `${shell} -lc ${quote(\n `gfortran ${quote(fileFor('main.f90'))} -o ${quote(fileFor('main-f90'))} && ${quote(fileFor('main-f90'))} ${argText}`\n )}`,\n };\n case 'bash':\n case 'sh':\n return {\n fileName: 'main.sh',\n source: code,\n command: `${shell} -lc ${quote(code)} -- ${argText}`,\n };\n default:\n throw new Error(`Unsupported Cloudflare sandbox runtime: ${lang}`);\n }\n}\n\nexport async function executeCloudflareCode(\n input: { lang: string; code: string; args?: string[] },\n config: t.CloudflareSandboxExecutionConfig\n): Promise<SpawnResult> {\n if (input.lang === 'bash' || input.lang === 'sh') {\n return executeCloudflareBash(input.code, config, input.args ?? []);\n }\n const ctx = await getRuntimeContext(config);\n const id = globalThis.crypto.randomUUID();\n const tempDir = path.join(ctx.workspaceRoot, '.lc-exec', id);\n const runtime = runtimeForCode(\n input.lang,\n tempDir,\n input.code,\n input.args,\n ctx.shell\n );\n await ctx.sandbox.mkdir(tempDir, { recursive: true });\n if (runtime.source != null) {\n await ctx.sandbox.writeFile(\n path.join(tempDir, runtime.fileName),\n runtime.source,\n {\n encoding: 'utf8',\n }\n );\n }\n try {\n const result = await ctx.sandbox.exec(\n withInSandboxTimeout(runtime.command, ctx.timeoutMs),\n {\n cwd: ctx.workspaceRoot,\n env: ctx.env,\n timeout: outerTimeoutMs(ctx.timeoutMs),\n }\n );\n return {\n stdout: truncateOutput(result.stdout, ctx.maxOutputChars),\n stderr: truncateOutput(result.stderr, ctx.maxOutputChars),\n exitCode: result.exitCode,\n timedOut: isInSandboxTimeoutExit(result.exitCode),\n };\n } finally {\n await ctx.sandbox\n .exec(`rm -rf ${quote(tempDir)}`, {\n cwd: ctx.workspaceRoot,\n env: ctx.env,\n timeout: 10000,\n })\n .catch(() => undefined);\n }\n}\n\nexport function formatCloudflareOutput(\n result: SpawnResult,\n cwd: string\n): string {\n let formatted = '';\n if (result.stdout !== '') {\n formatted += `stdout:\\n${result.stdout}\\n`;\n } else {\n formatted += 'stdout: Empty. Ensure you\\'re writing output explicitly.\\n';\n }\n if (result.stderr !== '') {\n formatted += `stderr:\\n${result.stderr}\\n`;\n }\n if (result.exitCode != null && result.exitCode !== 0) {\n formatted += `exit_code: ${result.exitCode}\\n`;\n }\n if (result.timedOut) {\n formatted += 'timed_out: true\\n';\n }\n formatted += `working_directory: ${cwd}`;\n return formatted.trim();\n}\n"],"names":["path","PassThrough","EventEmitter","LOCAL_SPAWN_TIMEO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