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.cjs
CHANGED
|
@@ -229,6 +229,7 @@ __export(index_exports, {
|
|
|
229
229
|
DeploymentError: () => DeploymentError,
|
|
230
230
|
ExecutionError: () => ExecutionError,
|
|
231
231
|
NeckbeardError: () => NeckbeardError,
|
|
232
|
+
SandboxClient: () => SandboxClient,
|
|
232
233
|
ValidationError: () => ValidationError,
|
|
233
234
|
normalizeStackFramePath: () => normalizeStackFramePath,
|
|
234
235
|
resolveAgentSourceFile: () => resolveAgentSourceFile,
|
|
@@ -266,6 +267,7 @@ var SERVER_HEALTH_TIMEOUT_MS = 12e4;
|
|
|
266
267
|
var SERVER_RECONNECT_HEALTH_TIMEOUT_MS = 3e3;
|
|
267
268
|
var SERVER_HEALTH_POLL_INTERVAL_MS = 1e3;
|
|
268
269
|
var NATIVE_EXT_RE = /\.(node|wasm|gyp|c|cc|cpp|cxx|h|hpp|hxx)$/i;
|
|
270
|
+
var TRACEABLE_SOURCE_EXT_RE = /\.(cjs|cts|js|jsx|mjs|mts|ts|tsx)$/i;
|
|
269
271
|
var E2B_SANDBOX_HOME = "/home/user";
|
|
270
272
|
var NeckbeardError = class extends Error {
|
|
271
273
|
constructor(message) {
|
|
@@ -319,6 +321,12 @@ function resolveAgentSourceFile(candidates, options = {}) {
|
|
|
319
321
|
function withNeckbeardNextConfig(nextConfig, options) {
|
|
320
322
|
const sourceFiles = normalizeNonEmptyStrings("sourceFiles", options.sourceFiles);
|
|
321
323
|
const routeGlobs = normalizeNonEmptyStrings("routeGlob", options.routeGlob ?? "/*");
|
|
324
|
+
const traceSourceDependencies = options.traceSourceDependencies ?? true;
|
|
325
|
+
const traceIncludeFiles = traceIncludeFilesForConfig(
|
|
326
|
+
process.cwd(),
|
|
327
|
+
sourceFiles,
|
|
328
|
+
traceSourceDependencies
|
|
329
|
+
);
|
|
322
330
|
const experimental = asRecord(nextConfig.experimental);
|
|
323
331
|
const useLegacyExperimental = options.legacyExperimental ?? ("serverComponentsExternalPackages" in experimental || "outputFileTracingIncludes" in experimental || "outputFileTracingRoot" in experimental);
|
|
324
332
|
if (useLegacyExperimental) {
|
|
@@ -331,7 +339,7 @@ function withNeckbeardNextConfig(nextConfig, options) {
|
|
|
331
339
|
outputFileTracingIncludes: mergeTracingIncludes(
|
|
332
340
|
experimental.outputFileTracingIncludes,
|
|
333
341
|
routeGlobs,
|
|
334
|
-
|
|
342
|
+
traceIncludeFiles
|
|
335
343
|
)
|
|
336
344
|
};
|
|
337
345
|
if (options.outputFileTracingRoot !== void 0) {
|
|
@@ -340,7 +348,12 @@ function withNeckbeardNextConfig(nextConfig, options) {
|
|
|
340
348
|
return {
|
|
341
349
|
...nextConfig,
|
|
342
350
|
experimental: nextExperimental,
|
|
343
|
-
webpack: withNextTraceIncludeWebpack(
|
|
351
|
+
webpack: withNextTraceIncludeWebpack(
|
|
352
|
+
nextConfig.webpack,
|
|
353
|
+
sourceFiles,
|
|
354
|
+
routeGlobs,
|
|
355
|
+
traceSourceDependencies
|
|
356
|
+
)
|
|
344
357
|
};
|
|
345
358
|
}
|
|
346
359
|
const result = {
|
|
@@ -351,19 +364,28 @@ function withNeckbeardNextConfig(nextConfig, options) {
|
|
|
351
364
|
outputFileTracingIncludes: mergeTracingIncludes(
|
|
352
365
|
nextConfig.outputFileTracingIncludes,
|
|
353
366
|
routeGlobs,
|
|
354
|
-
|
|
367
|
+
traceIncludeFiles
|
|
355
368
|
)
|
|
356
369
|
};
|
|
370
|
+
if (nextConfig.webpack) {
|
|
371
|
+
result.webpack = withNextTraceIncludeWebpack(
|
|
372
|
+
nextConfig.webpack,
|
|
373
|
+
sourceFiles,
|
|
374
|
+
routeGlobs,
|
|
375
|
+
traceSourceDependencies
|
|
376
|
+
);
|
|
377
|
+
}
|
|
357
378
|
if (options.outputFileTracingRoot !== void 0) {
|
|
358
379
|
result.outputFileTracingRoot = options.outputFileTracingRoot;
|
|
359
380
|
}
|
|
360
381
|
return result;
|
|
361
382
|
}
|
|
362
383
|
var NextTraceIncludePlugin = class {
|
|
363
|
-
constructor(appDir, sourceFiles, routeGlobs) {
|
|
384
|
+
constructor(appDir, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
364
385
|
this.appDir = appDir;
|
|
365
386
|
this.sourceFiles = sourceFiles;
|
|
366
387
|
this.routeGlobs = routeGlobs;
|
|
388
|
+
this.traceSourceDependencies = traceSourceDependencies;
|
|
367
389
|
}
|
|
368
390
|
apply(compiler) {
|
|
369
391
|
const compilationHook = compiler.hooks?.compilation;
|
|
@@ -384,6 +406,7 @@ var NextTraceIncludePlugin = class {
|
|
|
384
406
|
rawSource: compiler.webpack?.sources?.RawSource,
|
|
385
407
|
routeGlobs: this.routeGlobs,
|
|
386
408
|
sourceFiles: this.sourceFiles,
|
|
409
|
+
traceSourceDependencies: this.traceSourceDependencies,
|
|
387
410
|
updateAsset: compilation.updateAsset?.bind(compilation)
|
|
388
411
|
});
|
|
389
412
|
});
|
|
@@ -402,7 +425,8 @@ var NextTraceIncludePlugin = class {
|
|
|
402
425
|
compiler.outputPath ?? "",
|
|
403
426
|
this.appDir,
|
|
404
427
|
this.sourceFiles,
|
|
405
|
-
this.routeGlobs
|
|
428
|
+
this.routeGlobs,
|
|
429
|
+
this.traceSourceDependencies
|
|
406
430
|
);
|
|
407
431
|
};
|
|
408
432
|
if (typeof afterEmit?.tap === "function") {
|
|
@@ -420,9 +444,10 @@ function appendIncludesToTraceAssets({
|
|
|
420
444
|
rawSource,
|
|
421
445
|
routeGlobs,
|
|
422
446
|
sourceFiles,
|
|
447
|
+
traceSourceDependencies,
|
|
423
448
|
updateAsset
|
|
424
449
|
}) {
|
|
425
|
-
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles);
|
|
450
|
+
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies);
|
|
426
451
|
if (includedFiles.length === 0) {
|
|
427
452
|
return;
|
|
428
453
|
}
|
|
@@ -446,7 +471,7 @@ function appendIncludesToTraceAssets({
|
|
|
446
471
|
}
|
|
447
472
|
}
|
|
448
473
|
}
|
|
449
|
-
function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs) {
|
|
474
|
+
function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
450
475
|
return (config, context) => {
|
|
451
476
|
const nextConfig = originalWebpack ? originalWebpack(config, context) : config;
|
|
452
477
|
if (!context.isServer || context.dev) {
|
|
@@ -455,7 +480,12 @@ function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs) {
|
|
|
455
480
|
nextConfig.externals = withNeckbeardExternal(nextConfig.externals);
|
|
456
481
|
nextConfig.plugins = [
|
|
457
482
|
...Array.isArray(nextConfig.plugins) ? nextConfig.plugins : [],
|
|
458
|
-
new NextTraceIncludePlugin(
|
|
483
|
+
new NextTraceIncludePlugin(
|
|
484
|
+
context.dir ?? process.cwd(),
|
|
485
|
+
sourceFiles,
|
|
486
|
+
routeGlobs,
|
|
487
|
+
traceSourceDependencies
|
|
488
|
+
)
|
|
459
489
|
];
|
|
460
490
|
return nextConfig;
|
|
461
491
|
};
|
|
@@ -482,11 +512,11 @@ function neckbeardExternal(contextOrRequest, requestOrCallback) {
|
|
|
482
512
|
callback();
|
|
483
513
|
}
|
|
484
514
|
}
|
|
485
|
-
function appendIncludesToTraceFiles(outputPath, appDir, sourceFiles, routeGlobs) {
|
|
515
|
+
function appendIncludesToTraceFiles(outputPath, appDir, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
486
516
|
if (!outputPath || !(0, import_node_fs.existsSync)(outputPath)) {
|
|
487
517
|
return;
|
|
488
518
|
}
|
|
489
|
-
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles);
|
|
519
|
+
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies);
|
|
490
520
|
if (includedFiles.length === 0) {
|
|
491
521
|
return;
|
|
492
522
|
}
|
|
@@ -518,15 +548,31 @@ function traceWithIncludedFiles(traceSource, traceDir, includedFiles) {
|
|
|
518
548
|
files: [...nextFiles]
|
|
519
549
|
});
|
|
520
550
|
}
|
|
521
|
-
function expandTraceIncludeFiles(appDir, sourceFiles) {
|
|
551
|
+
function expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies = true) {
|
|
522
552
|
const files = /* @__PURE__ */ new Set();
|
|
523
553
|
for (const sourceFile of sourceFiles) {
|
|
524
554
|
for (const file of expandTraceIncludePattern(appDir, sourceFile)) {
|
|
525
555
|
files.add(file);
|
|
526
556
|
}
|
|
527
557
|
}
|
|
558
|
+
if (traceSourceDependencies) {
|
|
559
|
+
for (const file of traceSourceDependencyFiles(appDir, [...files])) {
|
|
560
|
+
files.add(file);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
528
563
|
return [...files];
|
|
529
564
|
}
|
|
565
|
+
function traceIncludeFilesForConfig(appDir, sourceFiles, traceSourceDependencies) {
|
|
566
|
+
const tracedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies).map((file) => toNextTraceIncludePath(appDir, file));
|
|
567
|
+
return mergeStringArray(sourceFiles, tracedFiles);
|
|
568
|
+
}
|
|
569
|
+
function toNextTraceIncludePath(appDir, file) {
|
|
570
|
+
const relativePath = (0, import_node_path.relative)(appDir, file).replace(/\\/g, "/");
|
|
571
|
+
if (relativePath.startsWith("..")) {
|
|
572
|
+
return relativePath;
|
|
573
|
+
}
|
|
574
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
575
|
+
}
|
|
530
576
|
function expandTraceIncludePattern(appDir, sourceFile) {
|
|
531
577
|
const normalized = sourceFile.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
532
578
|
if (normalized.endsWith("/**/*")) {
|
|
@@ -540,6 +586,70 @@ function expandTraceIncludePattern(appDir, sourceFile) {
|
|
|
540
586
|
const file = (0, import_node_path.resolve)(appDir, normalized);
|
|
541
587
|
return (0, import_node_fs.existsSync)(file) && (0, import_node_fs.statSync)(file).isFile() ? [file] : [];
|
|
542
588
|
}
|
|
589
|
+
function traceSourceDependencyFiles(appDir, sourceFiles) {
|
|
590
|
+
const entryPoints = sourceFiles.filter((file) => TRACEABLE_SOURCE_EXT_RE.test(file));
|
|
591
|
+
if (entryPoints.length === 0) {
|
|
592
|
+
return [];
|
|
593
|
+
}
|
|
594
|
+
try {
|
|
595
|
+
const esbuild = getEsbuildSync();
|
|
596
|
+
const result = esbuild.buildSync({
|
|
597
|
+
absWorkingDir: appDir,
|
|
598
|
+
bundle: true,
|
|
599
|
+
entryPoints,
|
|
600
|
+
external: [...DEFAULT_EXTERNALS, NECKBEARD_PACKAGE_NAME],
|
|
601
|
+
format: "esm",
|
|
602
|
+
logLevel: "silent",
|
|
603
|
+
metafile: true,
|
|
604
|
+
platform: "node",
|
|
605
|
+
preserveSymlinks: true,
|
|
606
|
+
target: NODE_TARGET,
|
|
607
|
+
treeShaking: false,
|
|
608
|
+
write: false
|
|
609
|
+
});
|
|
610
|
+
const metafile = result.metafile;
|
|
611
|
+
if (!metafile) {
|
|
612
|
+
return [];
|
|
613
|
+
}
|
|
614
|
+
const files = /* @__PURE__ */ new Set();
|
|
615
|
+
const addFile = (file) => {
|
|
616
|
+
if (file && (0, import_node_fs.existsSync)(file) && (0, import_node_fs.statSync)(file).isFile()) {
|
|
617
|
+
files.add(file);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
for (const [inputPath, input] of Object.entries(metafile.inputs)) {
|
|
621
|
+
const absoluteInput = resolveMetafileInput(appDir, inputPath);
|
|
622
|
+
addFile(absoluteInput);
|
|
623
|
+
for (const importRecord of input.imports ?? []) {
|
|
624
|
+
const importPath = importRecord.original ?? importRecord.path;
|
|
625
|
+
if (!isBareModuleImport(importPath) || isBuiltinModule(importPath)) {
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
if (importPath === NECKBEARD_PACKAGE_NAME) {
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
const resolvedImportPath = importRecord.external ? void 0 : resolveMetafileInput(appDir, importRecord.path);
|
|
632
|
+
const packageInfo = resolvedImportPath ? resolvePackageInfoFromResolvedPath(importPath, resolvedImportPath) : resolvePackageInfoSync(importPath, (0, import_node_path.dirname)(absoluteInput));
|
|
633
|
+
if (!packageInfo) {
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
addFile(packageInfo.resolvedPath);
|
|
637
|
+
addFile((0, import_node_path.join)(packageInfo.root, "package.json"));
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
return [...files];
|
|
641
|
+
} catch (error) {
|
|
642
|
+
throw new ConfigurationError(
|
|
643
|
+
`Failed to trace Neckbeard source dependencies for Next.js output tracing: ${errorMessage(error)}`
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
function getEsbuildSync() {
|
|
648
|
+
return packageRequire("esbuild");
|
|
649
|
+
}
|
|
650
|
+
function resolveMetafileInput(absWorkingDir, inputPath) {
|
|
651
|
+
return (0, import_node_path.resolve)(absWorkingDir, inputPath);
|
|
652
|
+
}
|
|
543
653
|
function findTraceFiles(root) {
|
|
544
654
|
return findFiles(root).filter((file) => file.endsWith(".nft.json"));
|
|
545
655
|
}
|
|
@@ -759,10 +869,28 @@ function shellEscape(str) {
|
|
|
759
869
|
return `'${str.replace(/'/g, "'\\''")}'`;
|
|
760
870
|
}
|
|
761
871
|
var require2 = (0, import_node_module.createRequire)((0, import_node_path.join)(process.cwd(), "__agent_neckbeard__.cjs"));
|
|
872
|
+
var packageRequire = createPackageRequire();
|
|
873
|
+
function createPackageRequire() {
|
|
874
|
+
const cwdPackageJsonPath = (0, import_node_path.join)(process.cwd(), "package.json");
|
|
875
|
+
try {
|
|
876
|
+
if ((0, import_node_fs.existsSync)(cwdPackageJsonPath) && readPackageJson(cwdPackageJsonPath).name === NECKBEARD_PACKAGE_NAME) {
|
|
877
|
+
return (0, import_node_module.createRequire)(cwdPackageJsonPath);
|
|
878
|
+
}
|
|
879
|
+
} catch {
|
|
880
|
+
}
|
|
881
|
+
try {
|
|
882
|
+
return (0, import_node_module.createRequire)(require2.resolve(NECKBEARD_PACKAGE_NAME));
|
|
883
|
+
} catch {
|
|
884
|
+
return require2;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
762
887
|
function isBareModuleImport(path) {
|
|
763
888
|
const excludes = [".", "/", "~", "file:", "data:"];
|
|
764
889
|
return !excludes.some((exclude) => path.startsWith(exclude));
|
|
765
890
|
}
|
|
891
|
+
function isBuiltinModule(path) {
|
|
892
|
+
return import_node_module.builtinModules.includes(path.replace("node:", ""));
|
|
893
|
+
}
|
|
766
894
|
function packageNameForImportPath(importPath) {
|
|
767
895
|
if (importPath.startsWith("@")) {
|
|
768
896
|
return importPath.split("/").slice(0, 2).join("/");
|
|
@@ -777,6 +905,9 @@ function matchesExternal(matchers, pkgName) {
|
|
|
777
905
|
return matchers.some((re) => re.test(pkgName));
|
|
778
906
|
}
|
|
779
907
|
async function resolvePackageInfo(importPath, resolveDir) {
|
|
908
|
+
return resolvePackageInfoSync(importPath, resolveDir);
|
|
909
|
+
}
|
|
910
|
+
function resolvePackageInfoSync(importPath, resolveDir) {
|
|
780
911
|
try {
|
|
781
912
|
const resolvedPath = require2.resolve(importPath, { paths: [resolveDir] });
|
|
782
913
|
const packageName = packageNameForImportPath(importPath);
|
|
@@ -810,6 +941,29 @@ async function resolvePackageInfo(importPath, resolveDir) {
|
|
|
810
941
|
return null;
|
|
811
942
|
}
|
|
812
943
|
}
|
|
944
|
+
function resolvePackageInfoFromResolvedPath(importPath, resolvedPath) {
|
|
945
|
+
const packageName = packageNameForImportPath(importPath);
|
|
946
|
+
let root = (0, import_node_path.dirname)(resolvedPath);
|
|
947
|
+
while (true) {
|
|
948
|
+
const packageJsonPath = (0, import_node_path.join)(root, "package.json");
|
|
949
|
+
if ((0, import_node_fs.existsSync)(packageJsonPath)) {
|
|
950
|
+
const packageJson = readPackageJson(packageJsonPath);
|
|
951
|
+
if (packageJson.name === packageName) {
|
|
952
|
+
if (!packageJson.version) return null;
|
|
953
|
+
return {
|
|
954
|
+
name: packageJson.name,
|
|
955
|
+
version: packageJson.version,
|
|
956
|
+
root,
|
|
957
|
+
resolvedPath,
|
|
958
|
+
packageJson
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
const parent = (0, import_node_path.dirname)(root);
|
|
963
|
+
if (parent === root) return null;
|
|
964
|
+
root = parent;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
813
967
|
function hasNativeHints(info) {
|
|
814
968
|
const files = Array.isArray(info.packageJson.files) ? info.packageJson.files : [];
|
|
815
969
|
const fields = [info.packageJson.main, info.packageJson.module, info.packageJson.browser].filter(
|
|
@@ -842,9 +996,13 @@ function isPackageCompatible(info) {
|
|
|
842
996
|
return listAllowsTarget(osList, SANDBOX_PLATFORM) && listAllowsTarget(cpuList, SANDBOX_ARCH);
|
|
843
997
|
}
|
|
844
998
|
function filterDefinedEnvs(envs) {
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
999
|
+
const filtered = {};
|
|
1000
|
+
for (const [key, value] of Object.entries(envs)) {
|
|
1001
|
+
if (value !== void 0) {
|
|
1002
|
+
filtered[key] = value;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
return filtered;
|
|
848
1006
|
}
|
|
849
1007
|
function arrayBufferToBuffer(value) {
|
|
850
1008
|
return Buffer.from(value);
|
|
@@ -884,6 +1042,9 @@ function timeoutMsToSeconds(timeoutMs) {
|
|
|
884
1042
|
function asError(error) {
|
|
885
1043
|
return error instanceof Error ? error : new Error(String(error));
|
|
886
1044
|
}
|
|
1045
|
+
function errorMessage(error) {
|
|
1046
|
+
return error instanceof Error ? error.message : String(error);
|
|
1047
|
+
}
|
|
887
1048
|
async function resolveDaytonaPaths(sandbox) {
|
|
888
1049
|
const workDir = await sandbox.getWorkDir() ?? await sandbox.getUserHomeDir();
|
|
889
1050
|
const homeDir = await sandbox.getUserHomeDir() ?? workDir;
|
|
@@ -892,6 +1053,16 @@ async function resolveDaytonaPaths(sandbox) {
|
|
|
892
1053
|
}
|
|
893
1054
|
return createSandboxPaths("daytona", homeDir, workDir);
|
|
894
1055
|
}
|
|
1056
|
+
function numberProperty(value, property) {
|
|
1057
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
1058
|
+
const propertyValue = Reflect.get(value, property);
|
|
1059
|
+
return typeof propertyValue === "number" ? propertyValue : void 0;
|
|
1060
|
+
}
|
|
1061
|
+
function stringProperty(value, property) {
|
|
1062
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
1063
|
+
const propertyValue = Reflect.get(value, property);
|
|
1064
|
+
return typeof propertyValue === "string" ? propertyValue : void 0;
|
|
1065
|
+
}
|
|
895
1066
|
async function runE2bCommand(sandbox, cmd, options) {
|
|
896
1067
|
let stdout = "";
|
|
897
1068
|
let stderr = "";
|
|
@@ -899,6 +1070,7 @@ async function runE2bCommand(sandbox, cmd, options) {
|
|
|
899
1070
|
const result = await sandbox.commands.run(cmd, {
|
|
900
1071
|
timeoutMs: options.timeoutMs,
|
|
901
1072
|
envs: options.envs,
|
|
1073
|
+
background: false,
|
|
902
1074
|
onStdout: (data) => {
|
|
903
1075
|
stdout += data;
|
|
904
1076
|
options.onStdout?.(data);
|
|
@@ -914,118 +1086,271 @@ async function runE2bCommand(sandbox, cmd, options) {
|
|
|
914
1086
|
stderr: stderr || result.stderr
|
|
915
1087
|
};
|
|
916
1088
|
} catch (error) {
|
|
917
|
-
const exitCode = error
|
|
918
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1089
|
+
const exitCode = numberProperty(error, "exitCode") ?? 1;
|
|
919
1090
|
return {
|
|
920
1091
|
exitCode,
|
|
921
|
-
stdout,
|
|
922
|
-
stderr: stderr || errorMessage
|
|
1092
|
+
stdout: stdout || stringProperty(error, "stdout") || "",
|
|
1093
|
+
stderr: stderr || stringProperty(error, "stderr") || errorMessage(error)
|
|
923
1094
|
};
|
|
924
1095
|
}
|
|
925
1096
|
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1097
|
+
var E2bSandboxHandle = class {
|
|
1098
|
+
constructor(sandbox) {
|
|
1099
|
+
this.sandbox = sandbox;
|
|
1100
|
+
}
|
|
1101
|
+
provider = "e2b";
|
|
1102
|
+
paths = createSandboxPaths("e2b", E2B_SANDBOX_HOME, E2B_SANDBOX_HOME);
|
|
1103
|
+
get id() {
|
|
1104
|
+
return this.sandbox.sandboxId;
|
|
1105
|
+
}
|
|
1106
|
+
async makeDir(path) {
|
|
1107
|
+
await this.sandbox.files.makeDir(path);
|
|
1108
|
+
}
|
|
1109
|
+
writeFile(path, content) {
|
|
1110
|
+
return this.sandbox.files.write(path, toE2bWriteContent(content)).then(() => void 0);
|
|
1111
|
+
}
|
|
1112
|
+
readFile(path) {
|
|
1113
|
+
return this.sandbox.files.read(path, { format: "text" });
|
|
1114
|
+
}
|
|
1115
|
+
readFileBytes(path) {
|
|
1116
|
+
return this.sandbox.files.read(path, { format: "bytes" });
|
|
1117
|
+
}
|
|
1118
|
+
runCommand(cmd, options) {
|
|
1119
|
+
const command = options.cwd ? `cd ${shellEscape(options.cwd)} && ${cmd}` : cmd;
|
|
1120
|
+
return runE2bCommand(this.sandbox, command, options);
|
|
1121
|
+
}
|
|
1122
|
+
setTimeout(timeoutMs) {
|
|
1123
|
+
return this.sandbox.setTimeout(timeoutMs);
|
|
1124
|
+
}
|
|
1125
|
+
async startDetachedCommand(cmd, options) {
|
|
1126
|
+
const command = options.cwd ? `cd ${shellEscape(options.cwd)} && ${cmd}` : cmd;
|
|
1127
|
+
const handle = await this.sandbox.commands.run(command, {
|
|
1128
|
+
timeoutMs: 0,
|
|
1129
|
+
envs: options.envs,
|
|
1130
|
+
background: true
|
|
1131
|
+
});
|
|
1132
|
+
return { sessionId: `e2b:${handle.pid}`, commandId: String(handle.pid) };
|
|
1133
|
+
}
|
|
1134
|
+
async readSessionLogs(_sessionId, commandId) {
|
|
1135
|
+
try {
|
|
1136
|
+
const handle = await this.sandbox.commands.connect(Number(commandId));
|
|
1137
|
+
return { stdout: handle.stdout ?? "", stderr: handle.stderr ?? "" };
|
|
1138
|
+
} catch {
|
|
1139
|
+
return { stdout: "", stderr: "" };
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
async stopSession(sessionId) {
|
|
1143
|
+
const pid = Number(sessionId.replace(/^e2b:/, ""));
|
|
1144
|
+
if (Number.isFinite(pid)) {
|
|
1145
|
+
await this.sandbox.commands.kill(pid);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
async getServerEndpoint(port) {
|
|
1149
|
+
return {
|
|
1150
|
+
url: `https://${this.sandbox.getHost(port)}`,
|
|
1151
|
+
trafficToken: this.sandbox.trafficAccessToken
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
destroy() {
|
|
1155
|
+
return this.sandbox.kill();
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
var DaytonaSandboxHandle = class _DaytonaSandboxHandle {
|
|
1159
|
+
constructor(sandbox, paths) {
|
|
1160
|
+
this.sandbox = sandbox;
|
|
1161
|
+
this.paths = paths;
|
|
1162
|
+
}
|
|
1163
|
+
provider = "daytona";
|
|
1164
|
+
static async create(sandbox) {
|
|
1165
|
+
return new _DaytonaSandboxHandle(sandbox, await resolveDaytonaPaths(sandbox));
|
|
1166
|
+
}
|
|
1167
|
+
get id() {
|
|
1168
|
+
return this.sandbox.id;
|
|
1169
|
+
}
|
|
1170
|
+
async makeDir(path) {
|
|
1171
|
+
const result = await this.sandbox.process.executeCommand(
|
|
1172
|
+
`mkdir -p ${shellEscape(path)}`,
|
|
1173
|
+
void 0,
|
|
1174
|
+
void 0,
|
|
1175
|
+
timeoutMsToSeconds(QUICK_COMMAND_TIMEOUT_MS)
|
|
1176
|
+
);
|
|
1177
|
+
if (result.exitCode !== 0) {
|
|
1178
|
+
throw new DeploymentError(result.result || `Failed to create directory ${path}`);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
writeFile(path, content) {
|
|
1182
|
+
return this.sandbox.fs.uploadFile(
|
|
974
1183
|
toDaytonaUploadContent(content),
|
|
975
1184
|
path,
|
|
976
1185
|
timeoutMsToSeconds(SANDBOX_COMMAND_TIMEOUT_MS)
|
|
977
|
-
)
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1186
|
+
);
|
|
1187
|
+
}
|
|
1188
|
+
async readFile(path) {
|
|
1189
|
+
const content = await this.sandbox.fs.downloadFile(path, timeoutMsToSeconds(SANDBOX_COMMAND_TIMEOUT_MS));
|
|
1190
|
+
return content.toString("utf-8");
|
|
1191
|
+
}
|
|
1192
|
+
async readFileBytes(path) {
|
|
1193
|
+
const content = await this.sandbox.fs.downloadFile(path, timeoutMsToSeconds(SANDBOX_COMMAND_TIMEOUT_MS));
|
|
1194
|
+
return new Uint8Array(content);
|
|
1195
|
+
}
|
|
1196
|
+
async runCommand(cmd, options) {
|
|
1197
|
+
const result = await this.sandbox.process.executeCommand(
|
|
1198
|
+
cmd,
|
|
1199
|
+
options.cwd,
|
|
1200
|
+
options.envs,
|
|
1201
|
+
timeoutMsToSeconds(options.timeoutMs)
|
|
1202
|
+
);
|
|
1203
|
+
const stdout = result.artifacts?.stdout ?? result.result ?? "";
|
|
1204
|
+
if (stdout) options.onStdout?.(stdout);
|
|
1205
|
+
return {
|
|
1206
|
+
exitCode: result.exitCode,
|
|
1207
|
+
stdout,
|
|
1208
|
+
stderr: ""
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
async startDetachedCommand(cmd, options) {
|
|
1212
|
+
const sessionId = `neckbeard-server-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
1213
|
+
await this.sandbox.process.createSession(sessionId);
|
|
1214
|
+
const envPrefix = options.envs ? Object.entries(options.envs).map(([key, value]) => `${key}=${shellEscape(value)}`).join(" ") + " " : "";
|
|
1215
|
+
const cwdPrefix = options.cwd ? `cd ${shellEscape(options.cwd)} && ` : "";
|
|
1216
|
+
const result = await this.sandbox.process.executeSessionCommand(sessionId, {
|
|
1217
|
+
command: `${cwdPrefix}${envPrefix}${cmd}`,
|
|
1218
|
+
runAsync: true
|
|
1219
|
+
});
|
|
1220
|
+
return { sessionId, commandId: result.cmdId };
|
|
1221
|
+
}
|
|
1222
|
+
async readSessionLogs(sessionId, commandId) {
|
|
1223
|
+
try {
|
|
1224
|
+
const logs = await this.sandbox.process.getSessionCommandLogs(sessionId, commandId);
|
|
991
1225
|
return {
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
stderr: ""
|
|
1226
|
+
stdout: logs.stdout ?? logs.output ?? "",
|
|
1227
|
+
stderr: logs.stderr ?? ""
|
|
995
1228
|
};
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1229
|
+
} catch {
|
|
1230
|
+
return { stdout: "", stderr: "" };
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
stopSession(sessionId) {
|
|
1234
|
+
return this.sandbox.process.deleteSession(sessionId);
|
|
1235
|
+
}
|
|
1236
|
+
async getServerEndpoint(port) {
|
|
1237
|
+
const preview = await this.sandbox.getPreviewLink(port);
|
|
1238
|
+
return { url: preview.url, trafficToken: preview.token };
|
|
1239
|
+
}
|
|
1240
|
+
destroy() {
|
|
1241
|
+
return this.sandbox.delete(timeoutMsToSeconds(SANDBOX_COMMAND_TIMEOUT_MS));
|
|
1242
|
+
}
|
|
1243
|
+
};
|
|
1244
|
+
function providerApiKey(provider, explicitApiKey) {
|
|
1245
|
+
if (explicitApiKey) return explicitApiKey;
|
|
1246
|
+
return requireEnv(provider === "e2b" ? "E2B_API_KEY" : "DAYTONA_API_KEY");
|
|
1247
|
+
}
|
|
1248
|
+
async function createProviderSandboxHandle(options) {
|
|
1249
|
+
if (options.provider === "daytona") {
|
|
1250
|
+
const apiKey2 = providerApiKey("daytona", options.apiKey);
|
|
1251
|
+
const { Daytona } = await getDaytona();
|
|
1252
|
+
const daytona = new Daytona({ apiKey: apiKey2 });
|
|
1253
|
+
const sandbox2 = await daytona.create(
|
|
1254
|
+
{
|
|
1255
|
+
...options.template ? { snapshot: options.template } : {},
|
|
1256
|
+
envVars: filterDefinedEnvs(options.envs ?? {}),
|
|
1257
|
+
autoDeleteInterval: options.autoDeleteInterval ?? -1
|
|
1258
|
+
},
|
|
1259
|
+
{ timeout: options.createTimeoutSec ?? DAYTONA_CREATE_TIMEOUT_SEC }
|
|
1260
|
+
);
|
|
1261
|
+
return DaytonaSandboxHandle.create(sandbox2);
|
|
1262
|
+
}
|
|
1263
|
+
const apiKey = providerApiKey("e2b", options.apiKey);
|
|
1264
|
+
const { Sandbox } = await getE2b();
|
|
1265
|
+
const sandboxOptions = {
|
|
1266
|
+
apiKey,
|
|
1267
|
+
envs: filterDefinedEnvs(options.envs ?? {}),
|
|
1268
|
+
timeoutMs: options.timeoutMs,
|
|
1269
|
+
requestTimeoutMs: options.requestTimeoutMs,
|
|
1270
|
+
network: options.allowPublicTraffic === void 0 ? void 0 : { allowPublicTraffic: options.allowPublicTraffic }
|
|
1027
1271
|
};
|
|
1272
|
+
const sandbox = options.template ? await Sandbox.create(options.template, sandboxOptions) : await Sandbox.create(sandboxOptions);
|
|
1273
|
+
return new E2bSandboxHandle(sandbox);
|
|
1274
|
+
}
|
|
1275
|
+
async function connectProviderSandboxHandle(options) {
|
|
1276
|
+
if (options.provider === "daytona") {
|
|
1277
|
+
const apiKey2 = providerApiKey("daytona", options.apiKey);
|
|
1278
|
+
const { Daytona } = await getDaytona();
|
|
1279
|
+
const daytona = new Daytona({ apiKey: apiKey2 });
|
|
1280
|
+
const sandbox2 = await daytona.get(options.sandboxId);
|
|
1281
|
+
if (sandbox2.state !== "started") {
|
|
1282
|
+
if (sandbox2.state === "starting" || sandbox2.state === "creating" || sandbox2.state === "restoring") {
|
|
1283
|
+
await sandbox2.waitUntilStarted(options.createTimeoutSec ?? DAYTONA_CREATE_TIMEOUT_SEC);
|
|
1284
|
+
} else {
|
|
1285
|
+
await sandbox2.start(options.createTimeoutSec ?? DAYTONA_CREATE_TIMEOUT_SEC);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
return DaytonaSandboxHandle.create(sandbox2);
|
|
1289
|
+
}
|
|
1290
|
+
const apiKey = providerApiKey("e2b", options.apiKey);
|
|
1291
|
+
const { Sandbox } = await getE2b();
|
|
1292
|
+
const sandbox = await Sandbox.connect(options.sandboxId, {
|
|
1293
|
+
apiKey,
|
|
1294
|
+
timeoutMs: options.timeoutMs,
|
|
1295
|
+
requestTimeoutMs: options.requestTimeoutMs
|
|
1296
|
+
});
|
|
1297
|
+
return new E2bSandboxHandle(sandbox);
|
|
1028
1298
|
}
|
|
1299
|
+
var SandboxClient = class _SandboxClient {
|
|
1300
|
+
constructor(handle) {
|
|
1301
|
+
this.handle = handle;
|
|
1302
|
+
}
|
|
1303
|
+
static async create(options) {
|
|
1304
|
+
return new _SandboxClient(await createProviderSandboxHandle(options));
|
|
1305
|
+
}
|
|
1306
|
+
static async connect(options) {
|
|
1307
|
+
return new _SandboxClient(await connectProviderSandboxHandle(options));
|
|
1308
|
+
}
|
|
1309
|
+
get id() {
|
|
1310
|
+
return this.handle.id;
|
|
1311
|
+
}
|
|
1312
|
+
get provider() {
|
|
1313
|
+
return this.handle.provider;
|
|
1314
|
+
}
|
|
1315
|
+
get paths() {
|
|
1316
|
+
return {
|
|
1317
|
+
provider: this.handle.paths.provider,
|
|
1318
|
+
homeDir: this.handle.paths.homeDir,
|
|
1319
|
+
workDir: this.handle.paths.workDir,
|
|
1320
|
+
agentDir: this.handle.paths.agentDir,
|
|
1321
|
+
ioDir: this.handle.paths.ioDir,
|
|
1322
|
+
inputJson: this.handle.paths.inputJson,
|
|
1323
|
+
outputJson: this.handle.paths.outputJson
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
async makeDir(path) {
|
|
1327
|
+
await this.handle.makeDir(path);
|
|
1328
|
+
}
|
|
1329
|
+
async writeFile(path, content) {
|
|
1330
|
+
await this.handle.writeFile(path, content);
|
|
1331
|
+
}
|
|
1332
|
+
async readFile(path) {
|
|
1333
|
+
return this.handle.readFile(path);
|
|
1334
|
+
}
|
|
1335
|
+
async readFileBytes(path) {
|
|
1336
|
+
return this.handle.readFileBytes(path);
|
|
1337
|
+
}
|
|
1338
|
+
async runCommand(command, options) {
|
|
1339
|
+
return this.handle.runCommand(command, options);
|
|
1340
|
+
}
|
|
1341
|
+
async setTimeout(timeoutMs) {
|
|
1342
|
+
if (!this.handle.setTimeout) {
|
|
1343
|
+
throw new ConfigurationError(`Sandbox provider "${this.provider}" does not support setTimeout().`);
|
|
1344
|
+
}
|
|
1345
|
+
await this.handle.setTimeout(timeoutMs);
|
|
1346
|
+
}
|
|
1347
|
+
async kill() {
|
|
1348
|
+
await this.handle.destroy();
|
|
1349
|
+
}
|
|
1350
|
+
async destroy() {
|
|
1351
|
+
await this.kill();
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1029
1354
|
function normalizeStackFramePath(rawPath, cwd = process.cwd()) {
|
|
1030
1355
|
if (rawPath.startsWith("file://")) {
|
|
1031
1356
|
return (0, import_node_url.fileURLToPath)(rawPath);
|
|
@@ -1165,48 +1490,31 @@ var Agent = class {
|
|
|
1165
1490
|
};
|
|
1166
1491
|
}
|
|
1167
1492
|
async createSandboxHandle() {
|
|
1168
|
-
if (this.provider === "
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
return createDaytonaHandle(sandbox2);
|
|
1181
|
-
}
|
|
1182
|
-
const apiKey = requireEnv("E2B_API_KEY");
|
|
1183
|
-
const { Sandbox } = await getE2b();
|
|
1184
|
-
const sandbox = await Sandbox.create(this.template, {
|
|
1185
|
-
apiKey,
|
|
1186
|
-
envs: this.sandboxEnv,
|
|
1187
|
-
network: { allowPublicTraffic: false }
|
|
1493
|
+
if (this.provider === "e2b") {
|
|
1494
|
+
return createProviderSandboxHandle({
|
|
1495
|
+
provider: "e2b",
|
|
1496
|
+
template: this.template,
|
|
1497
|
+
envs: this.sandboxEnv,
|
|
1498
|
+
allowPublicTraffic: false
|
|
1499
|
+
});
|
|
1500
|
+
}
|
|
1501
|
+
return createProviderSandboxHandle({
|
|
1502
|
+
provider: "daytona",
|
|
1503
|
+
template: this.template,
|
|
1504
|
+
envs: this.sandboxEnv
|
|
1188
1505
|
});
|
|
1189
|
-
return createE2bHandle(sandbox);
|
|
1190
1506
|
}
|
|
1191
1507
|
async connectSandboxHandle(sandboxId) {
|
|
1192
|
-
if (this.provider === "
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
if (sandbox2.state !== "started") {
|
|
1198
|
-
if (sandbox2.state === "starting" || sandbox2.state === "creating" || sandbox2.state === "restoring") {
|
|
1199
|
-
await sandbox2.waitUntilStarted?.(DAYTONA_CREATE_TIMEOUT_SEC);
|
|
1200
|
-
} else {
|
|
1201
|
-
await sandbox2.start?.(DAYTONA_CREATE_TIMEOUT_SEC);
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
return createDaytonaHandle(sandbox2);
|
|
1508
|
+
if (this.provider === "e2b") {
|
|
1509
|
+
return connectProviderSandboxHandle({
|
|
1510
|
+
provider: "e2b",
|
|
1511
|
+
sandboxId
|
|
1512
|
+
});
|
|
1205
1513
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1514
|
+
return connectProviderSandboxHandle({
|
|
1515
|
+
provider: "daytona",
|
|
1516
|
+
sandboxId
|
|
1517
|
+
});
|
|
1210
1518
|
}
|
|
1211
1519
|
async readRuntimeServerConfig(sandbox) {
|
|
1212
1520
|
try {
|
|
@@ -1704,6 +2012,7 @@ ${parts.join("\n\n")}`;
|
|
|
1704
2012
|
DeploymentError,
|
|
1705
2013
|
ExecutionError,
|
|
1706
2014
|
NeckbeardError,
|
|
2015
|
+
SandboxClient,
|
|
1707
2016
|
ValidationError,
|
|
1708
2017
|
normalizeStackFramePath,
|
|
1709
2018
|
resolveAgentSourceFile,
|