agent-neckbeard 1.1.12 → 1.1.14
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 +31 -2
- package/dist/index.cjs +461 -152
- package/dist/index.d.cts +72 -1
- package/dist/index.d.ts +72 -1
- package/dist/index.js +459 -151
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ var SERVER_HEALTH_TIMEOUT_MS = 12e4;
|
|
|
33
33
|
var SERVER_RECONNECT_HEALTH_TIMEOUT_MS = 3e3;
|
|
34
34
|
var SERVER_HEALTH_POLL_INTERVAL_MS = 1e3;
|
|
35
35
|
var NATIVE_EXT_RE = /\.(node|wasm|gyp|c|cc|cpp|cxx|h|hpp|hxx)$/i;
|
|
36
|
+
var TRACEABLE_SOURCE_EXT_RE = /\.(cjs|cts|js|jsx|mjs|mts|ts|tsx)$/i;
|
|
36
37
|
var E2B_SANDBOX_HOME = "/home/user";
|
|
37
38
|
var NeckbeardError = class extends Error {
|
|
38
39
|
constructor(message) {
|
|
@@ -86,6 +87,12 @@ function resolveAgentSourceFile(candidates, options = {}) {
|
|
|
86
87
|
function withNeckbeardNextConfig(nextConfig, options) {
|
|
87
88
|
const sourceFiles = normalizeNonEmptyStrings("sourceFiles", options.sourceFiles);
|
|
88
89
|
const routeGlobs = normalizeNonEmptyStrings("routeGlob", options.routeGlob ?? "/*");
|
|
90
|
+
const traceSourceDependencies = options.traceSourceDependencies ?? true;
|
|
91
|
+
const traceIncludeFiles = traceIncludeFilesForConfig(
|
|
92
|
+
process.cwd(),
|
|
93
|
+
sourceFiles,
|
|
94
|
+
traceSourceDependencies
|
|
95
|
+
);
|
|
89
96
|
const experimental = asRecord(nextConfig.experimental);
|
|
90
97
|
const useLegacyExperimental = options.legacyExperimental ?? ("serverComponentsExternalPackages" in experimental || "outputFileTracingIncludes" in experimental || "outputFileTracingRoot" in experimental);
|
|
91
98
|
if (useLegacyExperimental) {
|
|
@@ -98,7 +105,7 @@ function withNeckbeardNextConfig(nextConfig, options) {
|
|
|
98
105
|
outputFileTracingIncludes: mergeTracingIncludes(
|
|
99
106
|
experimental.outputFileTracingIncludes,
|
|
100
107
|
routeGlobs,
|
|
101
|
-
|
|
108
|
+
traceIncludeFiles
|
|
102
109
|
)
|
|
103
110
|
};
|
|
104
111
|
if (options.outputFileTracingRoot !== void 0) {
|
|
@@ -107,7 +114,12 @@ function withNeckbeardNextConfig(nextConfig, options) {
|
|
|
107
114
|
return {
|
|
108
115
|
...nextConfig,
|
|
109
116
|
experimental: nextExperimental,
|
|
110
|
-
webpack: withNextTraceIncludeWebpack(
|
|
117
|
+
webpack: withNextTraceIncludeWebpack(
|
|
118
|
+
nextConfig.webpack,
|
|
119
|
+
sourceFiles,
|
|
120
|
+
routeGlobs,
|
|
121
|
+
traceSourceDependencies
|
|
122
|
+
)
|
|
111
123
|
};
|
|
112
124
|
}
|
|
113
125
|
const result = {
|
|
@@ -118,19 +130,28 @@ function withNeckbeardNextConfig(nextConfig, options) {
|
|
|
118
130
|
outputFileTracingIncludes: mergeTracingIncludes(
|
|
119
131
|
nextConfig.outputFileTracingIncludes,
|
|
120
132
|
routeGlobs,
|
|
121
|
-
|
|
133
|
+
traceIncludeFiles
|
|
122
134
|
)
|
|
123
135
|
};
|
|
136
|
+
if (nextConfig.webpack) {
|
|
137
|
+
result.webpack = withNextTraceIncludeWebpack(
|
|
138
|
+
nextConfig.webpack,
|
|
139
|
+
sourceFiles,
|
|
140
|
+
routeGlobs,
|
|
141
|
+
traceSourceDependencies
|
|
142
|
+
);
|
|
143
|
+
}
|
|
124
144
|
if (options.outputFileTracingRoot !== void 0) {
|
|
125
145
|
result.outputFileTracingRoot = options.outputFileTracingRoot;
|
|
126
146
|
}
|
|
127
147
|
return result;
|
|
128
148
|
}
|
|
129
149
|
var NextTraceIncludePlugin = class {
|
|
130
|
-
constructor(appDir, sourceFiles, routeGlobs) {
|
|
150
|
+
constructor(appDir, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
131
151
|
this.appDir = appDir;
|
|
132
152
|
this.sourceFiles = sourceFiles;
|
|
133
153
|
this.routeGlobs = routeGlobs;
|
|
154
|
+
this.traceSourceDependencies = traceSourceDependencies;
|
|
134
155
|
}
|
|
135
156
|
apply(compiler) {
|
|
136
157
|
const compilationHook = compiler.hooks?.compilation;
|
|
@@ -151,6 +172,7 @@ var NextTraceIncludePlugin = class {
|
|
|
151
172
|
rawSource: compiler.webpack?.sources?.RawSource,
|
|
152
173
|
routeGlobs: this.routeGlobs,
|
|
153
174
|
sourceFiles: this.sourceFiles,
|
|
175
|
+
traceSourceDependencies: this.traceSourceDependencies,
|
|
154
176
|
updateAsset: compilation.updateAsset?.bind(compilation)
|
|
155
177
|
});
|
|
156
178
|
});
|
|
@@ -169,7 +191,8 @@ var NextTraceIncludePlugin = class {
|
|
|
169
191
|
compiler.outputPath ?? "",
|
|
170
192
|
this.appDir,
|
|
171
193
|
this.sourceFiles,
|
|
172
|
-
this.routeGlobs
|
|
194
|
+
this.routeGlobs,
|
|
195
|
+
this.traceSourceDependencies
|
|
173
196
|
);
|
|
174
197
|
};
|
|
175
198
|
if (typeof afterEmit?.tap === "function") {
|
|
@@ -187,9 +210,10 @@ function appendIncludesToTraceAssets({
|
|
|
187
210
|
rawSource,
|
|
188
211
|
routeGlobs,
|
|
189
212
|
sourceFiles,
|
|
213
|
+
traceSourceDependencies,
|
|
190
214
|
updateAsset
|
|
191
215
|
}) {
|
|
192
|
-
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles);
|
|
216
|
+
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies);
|
|
193
217
|
if (includedFiles.length === 0) {
|
|
194
218
|
return;
|
|
195
219
|
}
|
|
@@ -213,7 +237,7 @@ function appendIncludesToTraceAssets({
|
|
|
213
237
|
}
|
|
214
238
|
}
|
|
215
239
|
}
|
|
216
|
-
function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs) {
|
|
240
|
+
function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
217
241
|
return (config, context) => {
|
|
218
242
|
const nextConfig = originalWebpack ? originalWebpack(config, context) : config;
|
|
219
243
|
if (!context.isServer || context.dev) {
|
|
@@ -222,7 +246,12 @@ function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs) {
|
|
|
222
246
|
nextConfig.externals = withNeckbeardExternal(nextConfig.externals);
|
|
223
247
|
nextConfig.plugins = [
|
|
224
248
|
...Array.isArray(nextConfig.plugins) ? nextConfig.plugins : [],
|
|
225
|
-
new NextTraceIncludePlugin(
|
|
249
|
+
new NextTraceIncludePlugin(
|
|
250
|
+
context.dir ?? process.cwd(),
|
|
251
|
+
sourceFiles,
|
|
252
|
+
routeGlobs,
|
|
253
|
+
traceSourceDependencies
|
|
254
|
+
)
|
|
226
255
|
];
|
|
227
256
|
return nextConfig;
|
|
228
257
|
};
|
|
@@ -249,11 +278,11 @@ function neckbeardExternal(contextOrRequest, requestOrCallback) {
|
|
|
249
278
|
callback();
|
|
250
279
|
}
|
|
251
280
|
}
|
|
252
|
-
function appendIncludesToTraceFiles(outputPath, appDir, sourceFiles, routeGlobs) {
|
|
281
|
+
function appendIncludesToTraceFiles(outputPath, appDir, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
253
282
|
if (!outputPath || !existsSync(outputPath)) {
|
|
254
283
|
return;
|
|
255
284
|
}
|
|
256
|
-
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles);
|
|
285
|
+
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies);
|
|
257
286
|
if (includedFiles.length === 0) {
|
|
258
287
|
return;
|
|
259
288
|
}
|
|
@@ -285,15 +314,31 @@ function traceWithIncludedFiles(traceSource, traceDir, includedFiles) {
|
|
|
285
314
|
files: [...nextFiles]
|
|
286
315
|
});
|
|
287
316
|
}
|
|
288
|
-
function expandTraceIncludeFiles(appDir, sourceFiles) {
|
|
317
|
+
function expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies = true) {
|
|
289
318
|
const files = /* @__PURE__ */ new Set();
|
|
290
319
|
for (const sourceFile of sourceFiles) {
|
|
291
320
|
for (const file of expandTraceIncludePattern(appDir, sourceFile)) {
|
|
292
321
|
files.add(file);
|
|
293
322
|
}
|
|
294
323
|
}
|
|
324
|
+
if (traceSourceDependencies) {
|
|
325
|
+
for (const file of traceSourceDependencyFiles(appDir, [...files])) {
|
|
326
|
+
files.add(file);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
295
329
|
return [...files];
|
|
296
330
|
}
|
|
331
|
+
function traceIncludeFilesForConfig(appDir, sourceFiles, traceSourceDependencies) {
|
|
332
|
+
const tracedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies).map((file) => toNextTraceIncludePath(appDir, file));
|
|
333
|
+
return mergeStringArray(sourceFiles, tracedFiles);
|
|
334
|
+
}
|
|
335
|
+
function toNextTraceIncludePath(appDir, file) {
|
|
336
|
+
const relativePath = relative(appDir, file).replace(/\\/g, "/");
|
|
337
|
+
if (relativePath.startsWith("..")) {
|
|
338
|
+
return relativePath;
|
|
339
|
+
}
|
|
340
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
341
|
+
}
|
|
297
342
|
function expandTraceIncludePattern(appDir, sourceFile) {
|
|
298
343
|
const normalized = sourceFile.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
299
344
|
if (normalized.endsWith("/**/*")) {
|
|
@@ -307,6 +352,70 @@ function expandTraceIncludePattern(appDir, sourceFile) {
|
|
|
307
352
|
const file = resolve(appDir, normalized);
|
|
308
353
|
return existsSync(file) && statSync(file).isFile() ? [file] : [];
|
|
309
354
|
}
|
|
355
|
+
function traceSourceDependencyFiles(appDir, sourceFiles) {
|
|
356
|
+
const entryPoints = sourceFiles.filter((file) => TRACEABLE_SOURCE_EXT_RE.test(file));
|
|
357
|
+
if (entryPoints.length === 0) {
|
|
358
|
+
return [];
|
|
359
|
+
}
|
|
360
|
+
try {
|
|
361
|
+
const esbuild = getEsbuildSync();
|
|
362
|
+
const result = esbuild.buildSync({
|
|
363
|
+
absWorkingDir: appDir,
|
|
364
|
+
bundle: true,
|
|
365
|
+
entryPoints,
|
|
366
|
+
external: [...DEFAULT_EXTERNALS, NECKBEARD_PACKAGE_NAME],
|
|
367
|
+
format: "esm",
|
|
368
|
+
logLevel: "silent",
|
|
369
|
+
metafile: true,
|
|
370
|
+
platform: "node",
|
|
371
|
+
preserveSymlinks: true,
|
|
372
|
+
target: NODE_TARGET,
|
|
373
|
+
treeShaking: false,
|
|
374
|
+
write: false
|
|
375
|
+
});
|
|
376
|
+
const metafile = result.metafile;
|
|
377
|
+
if (!metafile) {
|
|
378
|
+
return [];
|
|
379
|
+
}
|
|
380
|
+
const files = /* @__PURE__ */ new Set();
|
|
381
|
+
const addFile = (file) => {
|
|
382
|
+
if (file && existsSync(file) && statSync(file).isFile()) {
|
|
383
|
+
files.add(file);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
for (const [inputPath, input] of Object.entries(metafile.inputs)) {
|
|
387
|
+
const absoluteInput = resolveMetafileInput(appDir, inputPath);
|
|
388
|
+
addFile(absoluteInput);
|
|
389
|
+
for (const importRecord of input.imports ?? []) {
|
|
390
|
+
const importPath = importRecord.original ?? importRecord.path;
|
|
391
|
+
if (!isBareModuleImport(importPath) || isBuiltinModule(importPath)) {
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (importPath === NECKBEARD_PACKAGE_NAME) {
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
const resolvedImportPath = importRecord.external ? void 0 : resolveMetafileInput(appDir, importRecord.path);
|
|
398
|
+
const packageInfo = resolvedImportPath ? resolvePackageInfoFromResolvedPath(importPath, resolvedImportPath) : resolvePackageInfoSync(importPath, dirname(absoluteInput));
|
|
399
|
+
if (!packageInfo) {
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
addFile(packageInfo.resolvedPath);
|
|
403
|
+
addFile(join(packageInfo.root, "package.json"));
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return [...files];
|
|
407
|
+
} catch (error) {
|
|
408
|
+
throw new ConfigurationError(
|
|
409
|
+
`Failed to trace Neckbeard source dependencies for Next.js output tracing: ${errorMessage(error)}`
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function getEsbuildSync() {
|
|
414
|
+
return packageRequire("esbuild");
|
|
415
|
+
}
|
|
416
|
+
function resolveMetafileInput(absWorkingDir, inputPath) {
|
|
417
|
+
return resolve(absWorkingDir, inputPath);
|
|
418
|
+
}
|
|
310
419
|
function findTraceFiles(root) {
|
|
311
420
|
return findFiles(root).filter((file) => file.endsWith(".nft.json"));
|
|
312
421
|
}
|
|
@@ -526,10 +635,28 @@ function shellEscape(str) {
|
|
|
526
635
|
return `'${str.replace(/'/g, "'\\''")}'`;
|
|
527
636
|
}
|
|
528
637
|
var require2 = createRequire(join(process.cwd(), "__agent_neckbeard__.cjs"));
|
|
638
|
+
var packageRequire = createPackageRequire();
|
|
639
|
+
function createPackageRequire() {
|
|
640
|
+
const cwdPackageJsonPath = join(process.cwd(), "package.json");
|
|
641
|
+
try {
|
|
642
|
+
if (existsSync(cwdPackageJsonPath) && readPackageJson(cwdPackageJsonPath).name === NECKBEARD_PACKAGE_NAME) {
|
|
643
|
+
return createRequire(cwdPackageJsonPath);
|
|
644
|
+
}
|
|
645
|
+
} catch {
|
|
646
|
+
}
|
|
647
|
+
try {
|
|
648
|
+
return createRequire(require2.resolve(NECKBEARD_PACKAGE_NAME));
|
|
649
|
+
} catch {
|
|
650
|
+
return require2;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
529
653
|
function isBareModuleImport(path) {
|
|
530
654
|
const excludes = [".", "/", "~", "file:", "data:"];
|
|
531
655
|
return !excludes.some((exclude) => path.startsWith(exclude));
|
|
532
656
|
}
|
|
657
|
+
function isBuiltinModule(path) {
|
|
658
|
+
return builtinModules.includes(path.replace("node:", ""));
|
|
659
|
+
}
|
|
533
660
|
function packageNameForImportPath(importPath) {
|
|
534
661
|
if (importPath.startsWith("@")) {
|
|
535
662
|
return importPath.split("/").slice(0, 2).join("/");
|
|
@@ -544,6 +671,9 @@ function matchesExternal(matchers, pkgName) {
|
|
|
544
671
|
return matchers.some((re) => re.test(pkgName));
|
|
545
672
|
}
|
|
546
673
|
async function resolvePackageInfo(importPath, resolveDir) {
|
|
674
|
+
return resolvePackageInfoSync(importPath, resolveDir);
|
|
675
|
+
}
|
|
676
|
+
function resolvePackageInfoSync(importPath, resolveDir) {
|
|
547
677
|
try {
|
|
548
678
|
const resolvedPath = require2.resolve(importPath, { paths: [resolveDir] });
|
|
549
679
|
const packageName = packageNameForImportPath(importPath);
|
|
@@ -577,6 +707,29 @@ async function resolvePackageInfo(importPath, resolveDir) {
|
|
|
577
707
|
return null;
|
|
578
708
|
}
|
|
579
709
|
}
|
|
710
|
+
function resolvePackageInfoFromResolvedPath(importPath, resolvedPath) {
|
|
711
|
+
const packageName = packageNameForImportPath(importPath);
|
|
712
|
+
let root = dirname(resolvedPath);
|
|
713
|
+
while (true) {
|
|
714
|
+
const packageJsonPath = join(root, "package.json");
|
|
715
|
+
if (existsSync(packageJsonPath)) {
|
|
716
|
+
const packageJson = readPackageJson(packageJsonPath);
|
|
717
|
+
if (packageJson.name === packageName) {
|
|
718
|
+
if (!packageJson.version) return null;
|
|
719
|
+
return {
|
|
720
|
+
name: packageJson.name,
|
|
721
|
+
version: packageJson.version,
|
|
722
|
+
root,
|
|
723
|
+
resolvedPath,
|
|
724
|
+
packageJson
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
const parent = dirname(root);
|
|
729
|
+
if (parent === root) return null;
|
|
730
|
+
root = parent;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
580
733
|
function hasNativeHints(info) {
|
|
581
734
|
const files = Array.isArray(info.packageJson.files) ? info.packageJson.files : [];
|
|
582
735
|
const fields = [info.packageJson.main, info.packageJson.module, info.packageJson.browser].filter(
|
|
@@ -609,9 +762,13 @@ function isPackageCompatible(info) {
|
|
|
609
762
|
return listAllowsTarget(osList, SANDBOX_PLATFORM) && listAllowsTarget(cpuList, SANDBOX_ARCH);
|
|
610
763
|
}
|
|
611
764
|
function filterDefinedEnvs(envs) {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
765
|
+
const filtered = {};
|
|
766
|
+
for (const [key, value] of Object.entries(envs)) {
|
|
767
|
+
if (value !== void 0) {
|
|
768
|
+
filtered[key] = value;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
return filtered;
|
|
615
772
|
}
|
|
616
773
|
function arrayBufferToBuffer(value) {
|
|
617
774
|
return Buffer.from(value);
|
|
@@ -651,6 +808,9 @@ function timeoutMsToSeconds(timeoutMs) {
|
|
|
651
808
|
function asError(error) {
|
|
652
809
|
return error instanceof Error ? error : new Error(String(error));
|
|
653
810
|
}
|
|
811
|
+
function errorMessage(error) {
|
|
812
|
+
return error instanceof Error ? error.message : String(error);
|
|
813
|
+
}
|
|
654
814
|
async function resolveDaytonaPaths(sandbox) {
|
|
655
815
|
const workDir = await sandbox.getWorkDir() ?? await sandbox.getUserHomeDir();
|
|
656
816
|
const homeDir = await sandbox.getUserHomeDir() ?? workDir;
|
|
@@ -659,6 +819,16 @@ async function resolveDaytonaPaths(sandbox) {
|
|
|
659
819
|
}
|
|
660
820
|
return createSandboxPaths("daytona", homeDir, workDir);
|
|
661
821
|
}
|
|
822
|
+
function numberProperty(value, property) {
|
|
823
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
824
|
+
const propertyValue = Reflect.get(value, property);
|
|
825
|
+
return typeof propertyValue === "number" ? propertyValue : void 0;
|
|
826
|
+
}
|
|
827
|
+
function stringProperty(value, property) {
|
|
828
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
829
|
+
const propertyValue = Reflect.get(value, property);
|
|
830
|
+
return typeof propertyValue === "string" ? propertyValue : void 0;
|
|
831
|
+
}
|
|
662
832
|
async function runE2bCommand(sandbox, cmd, options) {
|
|
663
833
|
let stdout = "";
|
|
664
834
|
let stderr = "";
|
|
@@ -666,6 +836,7 @@ async function runE2bCommand(sandbox, cmd, options) {
|
|
|
666
836
|
const result = await sandbox.commands.run(cmd, {
|
|
667
837
|
timeoutMs: options.timeoutMs,
|
|
668
838
|
envs: options.envs,
|
|
839
|
+
background: false,
|
|
669
840
|
onStdout: (data) => {
|
|
670
841
|
stdout += data;
|
|
671
842
|
options.onStdout?.(data);
|
|
@@ -681,118 +852,271 @@ async function runE2bCommand(sandbox, cmd, options) {
|
|
|
681
852
|
stderr: stderr || result.stderr
|
|
682
853
|
};
|
|
683
854
|
} catch (error) {
|
|
684
|
-
const exitCode = error
|
|
685
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
855
|
+
const exitCode = numberProperty(error, "exitCode") ?? 1;
|
|
686
856
|
return {
|
|
687
857
|
exitCode,
|
|
688
|
-
stdout,
|
|
689
|
-
stderr: stderr || errorMessage
|
|
858
|
+
stdout: stdout || stringProperty(error, "stdout") || "",
|
|
859
|
+
stderr: stderr || stringProperty(error, "stderr") || errorMessage(error)
|
|
690
860
|
};
|
|
691
861
|
}
|
|
692
862
|
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
863
|
+
var E2bSandboxHandle = class {
|
|
864
|
+
constructor(sandbox) {
|
|
865
|
+
this.sandbox = sandbox;
|
|
866
|
+
}
|
|
867
|
+
provider = "e2b";
|
|
868
|
+
paths = createSandboxPaths("e2b", E2B_SANDBOX_HOME, E2B_SANDBOX_HOME);
|
|
869
|
+
get id() {
|
|
870
|
+
return this.sandbox.sandboxId;
|
|
871
|
+
}
|
|
872
|
+
async makeDir(path) {
|
|
873
|
+
await this.sandbox.files.makeDir(path);
|
|
874
|
+
}
|
|
875
|
+
writeFile(path, content) {
|
|
876
|
+
return this.sandbox.files.write(path, toE2bWriteContent(content)).then(() => void 0);
|
|
877
|
+
}
|
|
878
|
+
readFile(path) {
|
|
879
|
+
return this.sandbox.files.read(path, { format: "text" });
|
|
880
|
+
}
|
|
881
|
+
readFileBytes(path) {
|
|
882
|
+
return this.sandbox.files.read(path, { format: "bytes" });
|
|
883
|
+
}
|
|
884
|
+
runCommand(cmd, options) {
|
|
885
|
+
const command = options.cwd ? `cd ${shellEscape(options.cwd)} && ${cmd}` : cmd;
|
|
886
|
+
return runE2bCommand(this.sandbox, command, options);
|
|
887
|
+
}
|
|
888
|
+
setTimeout(timeoutMs) {
|
|
889
|
+
return this.sandbox.setTimeout(timeoutMs);
|
|
890
|
+
}
|
|
891
|
+
async startDetachedCommand(cmd, options) {
|
|
892
|
+
const command = options.cwd ? `cd ${shellEscape(options.cwd)} && ${cmd}` : cmd;
|
|
893
|
+
const handle = await this.sandbox.commands.run(command, {
|
|
894
|
+
timeoutMs: 0,
|
|
895
|
+
envs: options.envs,
|
|
896
|
+
background: true
|
|
897
|
+
});
|
|
898
|
+
return { sessionId: `e2b:${handle.pid}`, commandId: String(handle.pid) };
|
|
899
|
+
}
|
|
900
|
+
async readSessionLogs(_sessionId, commandId) {
|
|
901
|
+
try {
|
|
902
|
+
const handle = await this.sandbox.commands.connect(Number(commandId));
|
|
903
|
+
return { stdout: handle.stdout ?? "", stderr: handle.stderr ?? "" };
|
|
904
|
+
} catch {
|
|
905
|
+
return { stdout: "", stderr: "" };
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
async stopSession(sessionId) {
|
|
909
|
+
const pid = Number(sessionId.replace(/^e2b:/, ""));
|
|
910
|
+
if (Number.isFinite(pid)) {
|
|
911
|
+
await this.sandbox.commands.kill(pid);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
async getServerEndpoint(port) {
|
|
915
|
+
return {
|
|
916
|
+
url: `https://${this.sandbox.getHost(port)}`,
|
|
917
|
+
trafficToken: this.sandbox.trafficAccessToken
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
destroy() {
|
|
921
|
+
return this.sandbox.kill();
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
var DaytonaSandboxHandle = class _DaytonaSandboxHandle {
|
|
925
|
+
constructor(sandbox, paths) {
|
|
926
|
+
this.sandbox = sandbox;
|
|
927
|
+
this.paths = paths;
|
|
928
|
+
}
|
|
929
|
+
provider = "daytona";
|
|
930
|
+
static async create(sandbox) {
|
|
931
|
+
return new _DaytonaSandboxHandle(sandbox, await resolveDaytonaPaths(sandbox));
|
|
932
|
+
}
|
|
933
|
+
get id() {
|
|
934
|
+
return this.sandbox.id;
|
|
935
|
+
}
|
|
936
|
+
async makeDir(path) {
|
|
937
|
+
const result = await this.sandbox.process.executeCommand(
|
|
938
|
+
`mkdir -p ${shellEscape(path)}`,
|
|
939
|
+
void 0,
|
|
940
|
+
void 0,
|
|
941
|
+
timeoutMsToSeconds(QUICK_COMMAND_TIMEOUT_MS)
|
|
942
|
+
);
|
|
943
|
+
if (result.exitCode !== 0) {
|
|
944
|
+
throw new DeploymentError(result.result || `Failed to create directory ${path}`);
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
writeFile(path, content) {
|
|
948
|
+
return this.sandbox.fs.uploadFile(
|
|
741
949
|
toDaytonaUploadContent(content),
|
|
742
950
|
path,
|
|
743
951
|
timeoutMsToSeconds(SANDBOX_COMMAND_TIMEOUT_MS)
|
|
744
|
-
)
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
952
|
+
);
|
|
953
|
+
}
|
|
954
|
+
async readFile(path) {
|
|
955
|
+
const content = await this.sandbox.fs.downloadFile(path, timeoutMsToSeconds(SANDBOX_COMMAND_TIMEOUT_MS));
|
|
956
|
+
return content.toString("utf-8");
|
|
957
|
+
}
|
|
958
|
+
async readFileBytes(path) {
|
|
959
|
+
const content = await this.sandbox.fs.downloadFile(path, timeoutMsToSeconds(SANDBOX_COMMAND_TIMEOUT_MS));
|
|
960
|
+
return new Uint8Array(content);
|
|
961
|
+
}
|
|
962
|
+
async runCommand(cmd, options) {
|
|
963
|
+
const result = await this.sandbox.process.executeCommand(
|
|
964
|
+
cmd,
|
|
965
|
+
options.cwd,
|
|
966
|
+
options.envs,
|
|
967
|
+
timeoutMsToSeconds(options.timeoutMs)
|
|
968
|
+
);
|
|
969
|
+
const stdout = result.artifacts?.stdout ?? result.result ?? "";
|
|
970
|
+
if (stdout) options.onStdout?.(stdout);
|
|
971
|
+
return {
|
|
972
|
+
exitCode: result.exitCode,
|
|
973
|
+
stdout,
|
|
974
|
+
stderr: ""
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
async startDetachedCommand(cmd, options) {
|
|
978
|
+
const sessionId = `neckbeard-server-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
979
|
+
await this.sandbox.process.createSession(sessionId);
|
|
980
|
+
const envPrefix = options.envs ? Object.entries(options.envs).map(([key, value]) => `${key}=${shellEscape(value)}`).join(" ") + " " : "";
|
|
981
|
+
const cwdPrefix = options.cwd ? `cd ${shellEscape(options.cwd)} && ` : "";
|
|
982
|
+
const result = await this.sandbox.process.executeSessionCommand(sessionId, {
|
|
983
|
+
command: `${cwdPrefix}${envPrefix}${cmd}`,
|
|
984
|
+
runAsync: true
|
|
985
|
+
});
|
|
986
|
+
return { sessionId, commandId: result.cmdId };
|
|
987
|
+
}
|
|
988
|
+
async readSessionLogs(sessionId, commandId) {
|
|
989
|
+
try {
|
|
990
|
+
const logs = await this.sandbox.process.getSessionCommandLogs(sessionId, commandId);
|
|
758
991
|
return {
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
stderr: ""
|
|
992
|
+
stdout: logs.stdout ?? logs.output ?? "",
|
|
993
|
+
stderr: logs.stderr ?? ""
|
|
762
994
|
};
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
995
|
+
} catch {
|
|
996
|
+
return { stdout: "", stderr: "" };
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
stopSession(sessionId) {
|
|
1000
|
+
return this.sandbox.process.deleteSession(sessionId);
|
|
1001
|
+
}
|
|
1002
|
+
async getServerEndpoint(port) {
|
|
1003
|
+
const preview = await this.sandbox.getPreviewLink(port);
|
|
1004
|
+
return { url: preview.url, trafficToken: preview.token };
|
|
1005
|
+
}
|
|
1006
|
+
destroy() {
|
|
1007
|
+
return this.sandbox.delete(timeoutMsToSeconds(SANDBOX_COMMAND_TIMEOUT_MS));
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
function providerApiKey(provider, explicitApiKey) {
|
|
1011
|
+
if (explicitApiKey) return explicitApiKey;
|
|
1012
|
+
return requireEnv(provider === "e2b" ? "E2B_API_KEY" : "DAYTONA_API_KEY");
|
|
1013
|
+
}
|
|
1014
|
+
async function createProviderSandboxHandle(options) {
|
|
1015
|
+
if (options.provider === "daytona") {
|
|
1016
|
+
const apiKey2 = providerApiKey("daytona", options.apiKey);
|
|
1017
|
+
const { Daytona } = await getDaytona();
|
|
1018
|
+
const daytona = new Daytona({ apiKey: apiKey2 });
|
|
1019
|
+
const sandbox2 = await daytona.create(
|
|
1020
|
+
{
|
|
1021
|
+
...options.template ? { snapshot: options.template } : {},
|
|
1022
|
+
envVars: filterDefinedEnvs(options.envs ?? {}),
|
|
1023
|
+
autoDeleteInterval: options.autoDeleteInterval ?? -1
|
|
1024
|
+
},
|
|
1025
|
+
{ timeout: options.createTimeoutSec ?? DAYTONA_CREATE_TIMEOUT_SEC }
|
|
1026
|
+
);
|
|
1027
|
+
return DaytonaSandboxHandle.create(sandbox2);
|
|
1028
|
+
}
|
|
1029
|
+
const apiKey = providerApiKey("e2b", options.apiKey);
|
|
1030
|
+
const { Sandbox } = await getE2b();
|
|
1031
|
+
const sandboxOptions = {
|
|
1032
|
+
apiKey,
|
|
1033
|
+
envs: filterDefinedEnvs(options.envs ?? {}),
|
|
1034
|
+
timeoutMs: options.timeoutMs,
|
|
1035
|
+
requestTimeoutMs: options.requestTimeoutMs,
|
|
1036
|
+
network: options.allowPublicTraffic === void 0 ? void 0 : { allowPublicTraffic: options.allowPublicTraffic }
|
|
794
1037
|
};
|
|
1038
|
+
const sandbox = options.template ? await Sandbox.create(options.template, sandboxOptions) : await Sandbox.create(sandboxOptions);
|
|
1039
|
+
return new E2bSandboxHandle(sandbox);
|
|
795
1040
|
}
|
|
1041
|
+
async function connectProviderSandboxHandle(options) {
|
|
1042
|
+
if (options.provider === "daytona") {
|
|
1043
|
+
const apiKey2 = providerApiKey("daytona", options.apiKey);
|
|
1044
|
+
const { Daytona } = await getDaytona();
|
|
1045
|
+
const daytona = new Daytona({ apiKey: apiKey2 });
|
|
1046
|
+
const sandbox2 = await daytona.get(options.sandboxId);
|
|
1047
|
+
if (sandbox2.state !== "started") {
|
|
1048
|
+
if (sandbox2.state === "starting" || sandbox2.state === "creating" || sandbox2.state === "restoring") {
|
|
1049
|
+
await sandbox2.waitUntilStarted(options.createTimeoutSec ?? DAYTONA_CREATE_TIMEOUT_SEC);
|
|
1050
|
+
} else {
|
|
1051
|
+
await sandbox2.start(options.createTimeoutSec ?? DAYTONA_CREATE_TIMEOUT_SEC);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
return DaytonaSandboxHandle.create(sandbox2);
|
|
1055
|
+
}
|
|
1056
|
+
const apiKey = providerApiKey("e2b", options.apiKey);
|
|
1057
|
+
const { Sandbox } = await getE2b();
|
|
1058
|
+
const sandbox = await Sandbox.connect(options.sandboxId, {
|
|
1059
|
+
apiKey,
|
|
1060
|
+
timeoutMs: options.timeoutMs,
|
|
1061
|
+
requestTimeoutMs: options.requestTimeoutMs
|
|
1062
|
+
});
|
|
1063
|
+
return new E2bSandboxHandle(sandbox);
|
|
1064
|
+
}
|
|
1065
|
+
var SandboxClient = class _SandboxClient {
|
|
1066
|
+
constructor(handle) {
|
|
1067
|
+
this.handle = handle;
|
|
1068
|
+
}
|
|
1069
|
+
static async create(options) {
|
|
1070
|
+
return new _SandboxClient(await createProviderSandboxHandle(options));
|
|
1071
|
+
}
|
|
1072
|
+
static async connect(options) {
|
|
1073
|
+
return new _SandboxClient(await connectProviderSandboxHandle(options));
|
|
1074
|
+
}
|
|
1075
|
+
get id() {
|
|
1076
|
+
return this.handle.id;
|
|
1077
|
+
}
|
|
1078
|
+
get provider() {
|
|
1079
|
+
return this.handle.provider;
|
|
1080
|
+
}
|
|
1081
|
+
get paths() {
|
|
1082
|
+
return {
|
|
1083
|
+
provider: this.handle.paths.provider,
|
|
1084
|
+
homeDir: this.handle.paths.homeDir,
|
|
1085
|
+
workDir: this.handle.paths.workDir,
|
|
1086
|
+
agentDir: this.handle.paths.agentDir,
|
|
1087
|
+
ioDir: this.handle.paths.ioDir,
|
|
1088
|
+
inputJson: this.handle.paths.inputJson,
|
|
1089
|
+
outputJson: this.handle.paths.outputJson
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
async makeDir(path) {
|
|
1093
|
+
await this.handle.makeDir(path);
|
|
1094
|
+
}
|
|
1095
|
+
async writeFile(path, content) {
|
|
1096
|
+
await this.handle.writeFile(path, content);
|
|
1097
|
+
}
|
|
1098
|
+
async readFile(path) {
|
|
1099
|
+
return this.handle.readFile(path);
|
|
1100
|
+
}
|
|
1101
|
+
async readFileBytes(path) {
|
|
1102
|
+
return this.handle.readFileBytes(path);
|
|
1103
|
+
}
|
|
1104
|
+
async runCommand(command, options) {
|
|
1105
|
+
return this.handle.runCommand(command, options);
|
|
1106
|
+
}
|
|
1107
|
+
async setTimeout(timeoutMs) {
|
|
1108
|
+
if (!this.handle.setTimeout) {
|
|
1109
|
+
throw new ConfigurationError(`Sandbox provider "${this.provider}" does not support setTimeout().`);
|
|
1110
|
+
}
|
|
1111
|
+
await this.handle.setTimeout(timeoutMs);
|
|
1112
|
+
}
|
|
1113
|
+
async kill() {
|
|
1114
|
+
await this.handle.destroy();
|
|
1115
|
+
}
|
|
1116
|
+
async destroy() {
|
|
1117
|
+
await this.kill();
|
|
1118
|
+
}
|
|
1119
|
+
};
|
|
796
1120
|
function normalizeStackFramePath(rawPath, cwd = process.cwd()) {
|
|
797
1121
|
if (rawPath.startsWith("file://")) {
|
|
798
1122
|
return fileURLToPath(rawPath);
|
|
@@ -932,48 +1256,31 @@ var Agent = class {
|
|
|
932
1256
|
};
|
|
933
1257
|
}
|
|
934
1258
|
async createSandboxHandle() {
|
|
935
|
-
if (this.provider === "
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
envVars: this.sandboxEnv,
|
|
943
|
-
autoDeleteInterval: -1
|
|
944
|
-
},
|
|
945
|
-
{ timeout: DAYTONA_CREATE_TIMEOUT_SEC }
|
|
946
|
-
);
|
|
947
|
-
return createDaytonaHandle(sandbox2);
|
|
1259
|
+
if (this.provider === "e2b") {
|
|
1260
|
+
return createProviderSandboxHandle({
|
|
1261
|
+
provider: "e2b",
|
|
1262
|
+
template: this.template,
|
|
1263
|
+
envs: this.sandboxEnv,
|
|
1264
|
+
allowPublicTraffic: false
|
|
1265
|
+
});
|
|
948
1266
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
envs: this.sandboxEnv,
|
|
954
|
-
network: { allowPublicTraffic: false }
|
|
1267
|
+
return createProviderSandboxHandle({
|
|
1268
|
+
provider: "daytona",
|
|
1269
|
+
template: this.template,
|
|
1270
|
+
envs: this.sandboxEnv
|
|
955
1271
|
});
|
|
956
|
-
return createE2bHandle(sandbox);
|
|
957
1272
|
}
|
|
958
1273
|
async connectSandboxHandle(sandboxId) {
|
|
959
|
-
if (this.provider === "
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
if (sandbox2.state !== "started") {
|
|
965
|
-
if (sandbox2.state === "starting" || sandbox2.state === "creating" || sandbox2.state === "restoring") {
|
|
966
|
-
await sandbox2.waitUntilStarted?.(DAYTONA_CREATE_TIMEOUT_SEC);
|
|
967
|
-
} else {
|
|
968
|
-
await sandbox2.start?.(DAYTONA_CREATE_TIMEOUT_SEC);
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
return createDaytonaHandle(sandbox2);
|
|
1274
|
+
if (this.provider === "e2b") {
|
|
1275
|
+
return connectProviderSandboxHandle({
|
|
1276
|
+
provider: "e2b",
|
|
1277
|
+
sandboxId
|
|
1278
|
+
});
|
|
972
1279
|
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
1280
|
+
return connectProviderSandboxHandle({
|
|
1281
|
+
provider: "daytona",
|
|
1282
|
+
sandboxId
|
|
1283
|
+
});
|
|
977
1284
|
}
|
|
978
1285
|
async readRuntimeServerConfig(sandbox) {
|
|
979
1286
|
try {
|
|
@@ -1470,6 +1777,7 @@ export {
|
|
|
1470
1777
|
DeploymentError,
|
|
1471
1778
|
ExecutionError,
|
|
1472
1779
|
NeckbeardError,
|
|
1780
|
+
SandboxClient,
|
|
1473
1781
|
ValidationError,
|
|
1474
1782
|
normalizeStackFramePath,
|
|
1475
1783
|
resolveAgentSourceFile,
|