agent-neckbeard 1.1.11 → 1.1.13
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 +20 -0
- package/dist/index.cjs +540 -6
- package/dist/index.d.cts +68 -1
- package/dist/index.d.ts +68 -1
- package/dist/index.js +539 -7
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -61,6 +61,26 @@ new Agent({
|
|
|
61
61
|
});
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
For Next.js/Vercel-style deployments, keep `agent-neckbeard` external to the server bundle and make sure the referenced source file is included in the production artifact:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
// next.config.ts
|
|
68
|
+
import { withNeckbeardNextConfig } from 'agent-neckbeard';
|
|
69
|
+
|
|
70
|
+
const nextConfig = withNeckbeardNextConfig({
|
|
71
|
+
// your existing Next config
|
|
72
|
+
}, {
|
|
73
|
+
routeGlob: '/api/my-agent',
|
|
74
|
+
sourceFiles: ['./packages/my-agent/src/agent.ts'],
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export default nextConfig;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The helper traces files imported by those source entries by default, including package entry metadata that `deploy()` needs when it rebundles the agent at runtime. For Next 13 configs that still use `experimental.serverComponentsExternalPackages`, the helper automatically uses the matching experimental tracing fields when it sees that shape. Set `outputFileTracingRoot` when the agent source is outside the app root.
|
|
81
|
+
|
|
82
|
+
This repo tests that shape locally with `npm run test:compat:next`, which builds and runs a Dockerized Next App Router fixture without pushing to Vercel. The fixture also checks the runtime env contract, Node major, and traced standalone files so source-level tests do not mask deployment artifact problems.
|
|
83
|
+
|
|
64
84
|
## Setup
|
|
65
85
|
|
|
66
86
|
```bash
|
package/dist/index.cjs
CHANGED
|
@@ -230,7 +230,9 @@ __export(index_exports, {
|
|
|
230
230
|
ExecutionError: () => ExecutionError,
|
|
231
231
|
NeckbeardError: () => NeckbeardError,
|
|
232
232
|
ValidationError: () => ValidationError,
|
|
233
|
-
normalizeStackFramePath: () => normalizeStackFramePath
|
|
233
|
+
normalizeStackFramePath: () => normalizeStackFramePath,
|
|
234
|
+
resolveAgentSourceFile: () => resolveAgentSourceFile,
|
|
235
|
+
withNeckbeardNextConfig: () => withNeckbeardNextConfig
|
|
234
236
|
});
|
|
235
237
|
module.exports = __toCommonJS(index_exports);
|
|
236
238
|
var import_node_url = require("url");
|
|
@@ -255,6 +257,8 @@ var QUICK_COMMAND_TIMEOUT_MS = 3e4;
|
|
|
255
257
|
var DAYTONA_CREATE_TIMEOUT_SEC = 120;
|
|
256
258
|
var NODE_TARGET = "node20";
|
|
257
259
|
var DEFAULT_EXTERNALS = ["@anthropic-ai/claude-agent-sdk"];
|
|
260
|
+
var NECKBEARD_PACKAGE_NAME = "agent-neckbeard";
|
|
261
|
+
var NECKBEARD_SANDBOX_RUNTIME_ENV = "AGENT_NECKBEARD_SANDBOX_RUNTIME";
|
|
258
262
|
var SANDBOX_PLATFORM = process.env.NECKBEARD_SANDBOX_PLATFORM ?? "linux";
|
|
259
263
|
var SANDBOX_ARCH = process.env.NECKBEARD_SANDBOX_ARCH ?? "x64";
|
|
260
264
|
var DEFAULT_SERVER_PORT = 3e3;
|
|
@@ -262,6 +266,7 @@ var SERVER_HEALTH_TIMEOUT_MS = 12e4;
|
|
|
262
266
|
var SERVER_RECONNECT_HEALTH_TIMEOUT_MS = 3e3;
|
|
263
267
|
var SERVER_HEALTH_POLL_INTERVAL_MS = 1e3;
|
|
264
268
|
var NATIVE_EXT_RE = /\.(node|wasm|gyp|c|cc|cpp|cxx|h|hpp|hxx)$/i;
|
|
269
|
+
var TRACEABLE_SOURCE_EXT_RE = /\.(cjs|cts|js|jsx|mjs|mts|ts|tsx)$/i;
|
|
265
270
|
var E2B_SANDBOX_HOME = "/home/user";
|
|
266
271
|
var NeckbeardError = class extends Error {
|
|
267
272
|
constructor(message) {
|
|
@@ -296,6 +301,462 @@ var ConfigurationError = class extends NeckbeardError {
|
|
|
296
301
|
this.name = "ConfigurationError";
|
|
297
302
|
}
|
|
298
303
|
};
|
|
304
|
+
function resolveAgentSourceFile(candidates, options = {}) {
|
|
305
|
+
const normalizedCandidates = normalizeNonEmptyStrings("candidates", candidates);
|
|
306
|
+
const sourceFile = normalizedCandidates.find((candidate) => (0, import_node_fs.existsSync)(candidate));
|
|
307
|
+
if (sourceFile) {
|
|
308
|
+
return sourceFile;
|
|
309
|
+
}
|
|
310
|
+
if (process.env[NECKBEARD_SANDBOX_RUNTIME_ENV] === "1") {
|
|
311
|
+
const sandboxSourceFile = options.sandboxSourceFile ?? (0, import_node_path.resolve)(process.cwd(), "agent.mjs");
|
|
312
|
+
if ((0, import_node_fs.existsSync)(sandboxSourceFile)) {
|
|
313
|
+
return sandboxSourceFile;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
throw new ConfigurationError(
|
|
317
|
+
options.errorMessage ?? `Could not resolve agent source file. Checked: ${candidates.join(", ")}`
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
function withNeckbeardNextConfig(nextConfig, options) {
|
|
321
|
+
const sourceFiles = normalizeNonEmptyStrings("sourceFiles", options.sourceFiles);
|
|
322
|
+
const routeGlobs = normalizeNonEmptyStrings("routeGlob", options.routeGlob ?? "/*");
|
|
323
|
+
const traceSourceDependencies = options.traceSourceDependencies ?? true;
|
|
324
|
+
const traceIncludeFiles = traceIncludeFilesForConfig(
|
|
325
|
+
process.cwd(),
|
|
326
|
+
sourceFiles,
|
|
327
|
+
traceSourceDependencies
|
|
328
|
+
);
|
|
329
|
+
const experimental = asRecord(nextConfig.experimental);
|
|
330
|
+
const useLegacyExperimental = options.legacyExperimental ?? ("serverComponentsExternalPackages" in experimental || "outputFileTracingIncludes" in experimental || "outputFileTracingRoot" in experimental);
|
|
331
|
+
if (useLegacyExperimental) {
|
|
332
|
+
const nextExperimental = {
|
|
333
|
+
...experimental,
|
|
334
|
+
serverComponentsExternalPackages: mergeStringArray(
|
|
335
|
+
experimental.serverComponentsExternalPackages,
|
|
336
|
+
[NECKBEARD_PACKAGE_NAME]
|
|
337
|
+
),
|
|
338
|
+
outputFileTracingIncludes: mergeTracingIncludes(
|
|
339
|
+
experimental.outputFileTracingIncludes,
|
|
340
|
+
routeGlobs,
|
|
341
|
+
traceIncludeFiles
|
|
342
|
+
)
|
|
343
|
+
};
|
|
344
|
+
if (options.outputFileTracingRoot !== void 0) {
|
|
345
|
+
nextExperimental.outputFileTracingRoot = options.outputFileTracingRoot;
|
|
346
|
+
}
|
|
347
|
+
return {
|
|
348
|
+
...nextConfig,
|
|
349
|
+
experimental: nextExperimental,
|
|
350
|
+
webpack: withNextTraceIncludeWebpack(
|
|
351
|
+
nextConfig.webpack,
|
|
352
|
+
sourceFiles,
|
|
353
|
+
routeGlobs,
|
|
354
|
+
traceSourceDependencies
|
|
355
|
+
)
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
const result = {
|
|
359
|
+
...nextConfig,
|
|
360
|
+
serverExternalPackages: mergeStringArray(nextConfig.serverExternalPackages, [
|
|
361
|
+
NECKBEARD_PACKAGE_NAME
|
|
362
|
+
]),
|
|
363
|
+
outputFileTracingIncludes: mergeTracingIncludes(
|
|
364
|
+
nextConfig.outputFileTracingIncludes,
|
|
365
|
+
routeGlobs,
|
|
366
|
+
traceIncludeFiles
|
|
367
|
+
)
|
|
368
|
+
};
|
|
369
|
+
if (nextConfig.webpack) {
|
|
370
|
+
result.webpack = withNextTraceIncludeWebpack(
|
|
371
|
+
nextConfig.webpack,
|
|
372
|
+
sourceFiles,
|
|
373
|
+
routeGlobs,
|
|
374
|
+
traceSourceDependencies
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
if (options.outputFileTracingRoot !== void 0) {
|
|
378
|
+
result.outputFileTracingRoot = options.outputFileTracingRoot;
|
|
379
|
+
}
|
|
380
|
+
return result;
|
|
381
|
+
}
|
|
382
|
+
var NextTraceIncludePlugin = class {
|
|
383
|
+
constructor(appDir, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
384
|
+
this.appDir = appDir;
|
|
385
|
+
this.sourceFiles = sourceFiles;
|
|
386
|
+
this.routeGlobs = routeGlobs;
|
|
387
|
+
this.traceSourceDependencies = traceSourceDependencies;
|
|
388
|
+
}
|
|
389
|
+
apply(compiler) {
|
|
390
|
+
const compilationHook = compiler.hooks?.compilation;
|
|
391
|
+
if (typeof compilationHook?.tap === "function") {
|
|
392
|
+
compilationHook.tap("NeckbeardNextTraceIncludePlugin", (compilation) => {
|
|
393
|
+
const processAssets = compilation.hooks?.processAssets;
|
|
394
|
+
if (typeof processAssets?.tap !== "function") {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
processAssets.tap({
|
|
398
|
+
name: "NeckbeardNextTraceIncludePlugin",
|
|
399
|
+
stage: compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_REPORT ?? 5e3
|
|
400
|
+
}, (assets) => {
|
|
401
|
+
appendIncludesToTraceAssets({
|
|
402
|
+
appDir: this.appDir,
|
|
403
|
+
assets,
|
|
404
|
+
outputPath: compilation.outputOptions?.path ?? compiler.outputPath ?? "",
|
|
405
|
+
rawSource: compiler.webpack?.sources?.RawSource,
|
|
406
|
+
routeGlobs: this.routeGlobs,
|
|
407
|
+
sourceFiles: this.sourceFiles,
|
|
408
|
+
traceSourceDependencies: this.traceSourceDependencies,
|
|
409
|
+
updateAsset: compilation.updateAsset?.bind(compilation)
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
const afterEmit = compiler.hooks?.afterEmit;
|
|
415
|
+
const done = compiler.hooks?.done;
|
|
416
|
+
if (typeof afterEmit?.tap !== "function" && typeof done?.tap !== "function") {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
if (!compiler.outputPath) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
const appendIncludes = () => {
|
|
423
|
+
appendIncludesToTraceFiles(
|
|
424
|
+
compiler.outputPath ?? "",
|
|
425
|
+
this.appDir,
|
|
426
|
+
this.sourceFiles,
|
|
427
|
+
this.routeGlobs,
|
|
428
|
+
this.traceSourceDependencies
|
|
429
|
+
);
|
|
430
|
+
};
|
|
431
|
+
if (typeof afterEmit?.tap === "function") {
|
|
432
|
+
afterEmit.tap("NeckbeardNextTraceIncludePlugin", appendIncludes);
|
|
433
|
+
}
|
|
434
|
+
if (typeof done?.tap === "function") {
|
|
435
|
+
done.tap("NeckbeardNextTraceIncludePlugin", appendIncludes);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
function appendIncludesToTraceAssets({
|
|
440
|
+
appDir,
|
|
441
|
+
assets,
|
|
442
|
+
outputPath,
|
|
443
|
+
rawSource,
|
|
444
|
+
routeGlobs,
|
|
445
|
+
sourceFiles,
|
|
446
|
+
traceSourceDependencies,
|
|
447
|
+
updateAsset
|
|
448
|
+
}) {
|
|
449
|
+
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies);
|
|
450
|
+
if (includedFiles.length === 0) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
for (const [assetName, asset] of Object.entries(assets)) {
|
|
454
|
+
if (!assetName.endsWith(".nft.json")) {
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
const routePath = routePathFromTraceAsset(outputPath, assetName);
|
|
458
|
+
if (!routePath || !routeGlobs.some((routeGlob) => routeGlobMatches(routeGlob, routePath))) {
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
const traceDir = (0, import_node_path.dirname)((0, import_node_path.join)(outputPath, assetName));
|
|
462
|
+
const nextSource = traceWithIncludedFiles(String(asset.source()), traceDir, includedFiles);
|
|
463
|
+
if (rawSource && updateAsset) {
|
|
464
|
+
updateAsset(assetName, new rawSource(nextSource));
|
|
465
|
+
} else {
|
|
466
|
+
assets[assetName] = {
|
|
467
|
+
source: () => nextSource,
|
|
468
|
+
size: () => Buffer.byteLength(nextSource)
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
474
|
+
return (config, context) => {
|
|
475
|
+
const nextConfig = originalWebpack ? originalWebpack(config, context) : config;
|
|
476
|
+
if (!context.isServer || context.dev) {
|
|
477
|
+
return nextConfig;
|
|
478
|
+
}
|
|
479
|
+
nextConfig.externals = withNeckbeardExternal(nextConfig.externals);
|
|
480
|
+
nextConfig.plugins = [
|
|
481
|
+
...Array.isArray(nextConfig.plugins) ? nextConfig.plugins : [],
|
|
482
|
+
new NextTraceIncludePlugin(
|
|
483
|
+
context.dir ?? process.cwd(),
|
|
484
|
+
sourceFiles,
|
|
485
|
+
routeGlobs,
|
|
486
|
+
traceSourceDependencies
|
|
487
|
+
)
|
|
488
|
+
];
|
|
489
|
+
return nextConfig;
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function withNeckbeardExternal(externals) {
|
|
493
|
+
return [
|
|
494
|
+
neckbeardExternal,
|
|
495
|
+
...Array.isArray(externals) ? externals : externals ? [externals] : []
|
|
496
|
+
];
|
|
497
|
+
}
|
|
498
|
+
function neckbeardExternal(contextOrRequest, requestOrCallback) {
|
|
499
|
+
const legacyCallback = arguments[2];
|
|
500
|
+
const request = typeof requestOrCallback === "string" ? requestOrCallback : typeof contextOrRequest === "string" ? contextOrRequest : contextOrRequest.request;
|
|
501
|
+
const callback = typeof requestOrCallback === "function" ? requestOrCallback : legacyCallback;
|
|
502
|
+
if (request === NECKBEARD_PACKAGE_NAME) {
|
|
503
|
+
const result = `commonjs ${NECKBEARD_PACKAGE_NAME}`;
|
|
504
|
+
if (callback) {
|
|
505
|
+
callback(null, result);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
return result;
|
|
509
|
+
}
|
|
510
|
+
if (callback) {
|
|
511
|
+
callback();
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
function appendIncludesToTraceFiles(outputPath, appDir, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
515
|
+
if (!outputPath || !(0, import_node_fs.existsSync)(outputPath)) {
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies);
|
|
519
|
+
if (includedFiles.length === 0) {
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
for (const traceFile of findTraceFiles(outputPath)) {
|
|
523
|
+
const routePath = routePathFromTraceFile(outputPath, traceFile);
|
|
524
|
+
if (!routePath || !routeGlobs.some((routeGlob) => routeGlobMatches(routeGlob, routePath))) {
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
appendFilesToTrace(traceFile, includedFiles);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
function appendFilesToTrace(traceFile, includedFiles) {
|
|
531
|
+
const nextSource = traceWithIncludedFiles(
|
|
532
|
+
(0, import_node_fs.readFileSync)(traceFile, "utf8"),
|
|
533
|
+
(0, import_node_path.dirname)(traceFile),
|
|
534
|
+
includedFiles
|
|
535
|
+
);
|
|
536
|
+
(0, import_node_fs.writeFileSync)(traceFile, nextSource);
|
|
537
|
+
}
|
|
538
|
+
function traceWithIncludedFiles(traceSource, traceDir, includedFiles) {
|
|
539
|
+
const trace = JSON.parse(traceSource);
|
|
540
|
+
const files = Array.isArray(trace.files) ? trace.files.filter((file) => typeof file === "string") : [];
|
|
541
|
+
const nextFiles = new Set(files);
|
|
542
|
+
for (const includedFile of includedFiles) {
|
|
543
|
+
nextFiles.add((0, import_node_path.relative)(traceDir, includedFile).replace(/\\/g, "/"));
|
|
544
|
+
}
|
|
545
|
+
return JSON.stringify({
|
|
546
|
+
version: trace.version ?? 1,
|
|
547
|
+
files: [...nextFiles]
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
function expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies = true) {
|
|
551
|
+
const files = /* @__PURE__ */ new Set();
|
|
552
|
+
for (const sourceFile of sourceFiles) {
|
|
553
|
+
for (const file of expandTraceIncludePattern(appDir, sourceFile)) {
|
|
554
|
+
files.add(file);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
if (traceSourceDependencies) {
|
|
558
|
+
for (const file of traceSourceDependencyFiles(appDir, [...files])) {
|
|
559
|
+
files.add(file);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
return [...files];
|
|
563
|
+
}
|
|
564
|
+
function traceIncludeFilesForConfig(appDir, sourceFiles, traceSourceDependencies) {
|
|
565
|
+
const tracedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies).map((file) => toNextTraceIncludePath(appDir, file));
|
|
566
|
+
return mergeStringArray(sourceFiles, tracedFiles);
|
|
567
|
+
}
|
|
568
|
+
function toNextTraceIncludePath(appDir, file) {
|
|
569
|
+
const relativePath = (0, import_node_path.relative)(appDir, file).replace(/\\/g, "/");
|
|
570
|
+
if (relativePath.startsWith("..")) {
|
|
571
|
+
return relativePath;
|
|
572
|
+
}
|
|
573
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
574
|
+
}
|
|
575
|
+
function expandTraceIncludePattern(appDir, sourceFile) {
|
|
576
|
+
const normalized = sourceFile.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
577
|
+
if (normalized.endsWith("/**/*")) {
|
|
578
|
+
const dir = (0, import_node_path.resolve)(appDir, normalized.slice(0, -5));
|
|
579
|
+
return findFiles(dir);
|
|
580
|
+
}
|
|
581
|
+
if (normalized.endsWith("/*")) {
|
|
582
|
+
const dir = (0, import_node_path.resolve)(appDir, normalized.slice(0, -2));
|
|
583
|
+
return directFiles(dir);
|
|
584
|
+
}
|
|
585
|
+
const file = (0, import_node_path.resolve)(appDir, normalized);
|
|
586
|
+
return (0, import_node_fs.existsSync)(file) && (0, import_node_fs.statSync)(file).isFile() ? [file] : [];
|
|
587
|
+
}
|
|
588
|
+
function traceSourceDependencyFiles(appDir, sourceFiles) {
|
|
589
|
+
const entryPoints = sourceFiles.filter((file) => TRACEABLE_SOURCE_EXT_RE.test(file));
|
|
590
|
+
if (entryPoints.length === 0) {
|
|
591
|
+
return [];
|
|
592
|
+
}
|
|
593
|
+
try {
|
|
594
|
+
const esbuild = getEsbuildSync();
|
|
595
|
+
const result = esbuild.buildSync({
|
|
596
|
+
absWorkingDir: appDir,
|
|
597
|
+
bundle: true,
|
|
598
|
+
entryPoints,
|
|
599
|
+
external: [...DEFAULT_EXTERNALS, NECKBEARD_PACKAGE_NAME],
|
|
600
|
+
format: "esm",
|
|
601
|
+
logLevel: "silent",
|
|
602
|
+
metafile: true,
|
|
603
|
+
platform: "node",
|
|
604
|
+
preserveSymlinks: true,
|
|
605
|
+
target: NODE_TARGET,
|
|
606
|
+
treeShaking: false,
|
|
607
|
+
write: false
|
|
608
|
+
});
|
|
609
|
+
const metafile = result.metafile;
|
|
610
|
+
if (!metafile) {
|
|
611
|
+
return [];
|
|
612
|
+
}
|
|
613
|
+
const files = /* @__PURE__ */ new Set();
|
|
614
|
+
const addFile = (file) => {
|
|
615
|
+
if (file && (0, import_node_fs.existsSync)(file) && (0, import_node_fs.statSync)(file).isFile()) {
|
|
616
|
+
files.add(file);
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
for (const [inputPath, input] of Object.entries(metafile.inputs)) {
|
|
620
|
+
const absoluteInput = resolveMetafileInput(appDir, inputPath);
|
|
621
|
+
addFile(absoluteInput);
|
|
622
|
+
for (const importRecord of input.imports ?? []) {
|
|
623
|
+
const importPath = importRecord.original ?? importRecord.path;
|
|
624
|
+
if (!isBareModuleImport(importPath) || isBuiltinModule(importPath)) {
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
627
|
+
if (importPath === NECKBEARD_PACKAGE_NAME) {
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
630
|
+
const resolvedImportPath = importRecord.external ? void 0 : resolveMetafileInput(appDir, importRecord.path);
|
|
631
|
+
const packageInfo = resolvedImportPath ? resolvePackageInfoFromResolvedPath(importPath, resolvedImportPath) : resolvePackageInfoSync(importPath, (0, import_node_path.dirname)(absoluteInput));
|
|
632
|
+
if (!packageInfo) {
|
|
633
|
+
continue;
|
|
634
|
+
}
|
|
635
|
+
addFile(packageInfo.resolvedPath);
|
|
636
|
+
addFile((0, import_node_path.join)(packageInfo.root, "package.json"));
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
return [...files];
|
|
640
|
+
} catch (error) {
|
|
641
|
+
throw new ConfigurationError(
|
|
642
|
+
`Failed to trace Neckbeard source dependencies for Next.js output tracing: ${errorMessage(error)}`
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
function getEsbuildSync() {
|
|
647
|
+
return packageRequire("esbuild");
|
|
648
|
+
}
|
|
649
|
+
function resolveMetafileInput(absWorkingDir, inputPath) {
|
|
650
|
+
return (0, import_node_path.resolve)(absWorkingDir, inputPath);
|
|
651
|
+
}
|
|
652
|
+
function findTraceFiles(root) {
|
|
653
|
+
return findFiles(root).filter((file) => file.endsWith(".nft.json"));
|
|
654
|
+
}
|
|
655
|
+
function findFiles(root) {
|
|
656
|
+
if (!(0, import_node_fs.existsSync)(root)) {
|
|
657
|
+
return [];
|
|
658
|
+
}
|
|
659
|
+
const stat = (0, import_node_fs.statSync)(root);
|
|
660
|
+
if (stat.isFile()) {
|
|
661
|
+
return [root];
|
|
662
|
+
}
|
|
663
|
+
if (!stat.isDirectory()) {
|
|
664
|
+
return [];
|
|
665
|
+
}
|
|
666
|
+
const files = [];
|
|
667
|
+
for (const entry of (0, import_node_fs.readdirSync)(root)) {
|
|
668
|
+
files.push(...findFiles((0, import_node_path.join)(root, entry)));
|
|
669
|
+
}
|
|
670
|
+
return files;
|
|
671
|
+
}
|
|
672
|
+
function directFiles(root) {
|
|
673
|
+
if (!(0, import_node_fs.existsSync)(root) || !(0, import_node_fs.statSync)(root).isDirectory()) {
|
|
674
|
+
return [];
|
|
675
|
+
}
|
|
676
|
+
return (0, import_node_fs.readdirSync)(root).map((entry) => (0, import_node_path.join)(root, entry)).filter((file) => (0, import_node_fs.statSync)(file).isFile());
|
|
677
|
+
}
|
|
678
|
+
function routePathFromTraceFile(outputPath, traceFile) {
|
|
679
|
+
const relativeTrace = (0, import_node_path.relative)(outputPath, traceFile).replace(/\\/g, "/");
|
|
680
|
+
return routePathFromRelativeTrace(outputPath, relativeTrace);
|
|
681
|
+
}
|
|
682
|
+
function routePathFromTraceAsset(outputPath, assetName) {
|
|
683
|
+
return routePathFromRelativeTrace(outputPath, assetName.replace(/\\/g, "/"));
|
|
684
|
+
}
|
|
685
|
+
function routePathFromRelativeTrace(outputPath, relativeTrace) {
|
|
686
|
+
const normalizedTrace = relativeTrace.replace(/^(\.\.\/)+/, "");
|
|
687
|
+
if (relativeTrace.startsWith("app/")) {
|
|
688
|
+
return normalizeTraceRoute(relativeTrace.slice("app/".length));
|
|
689
|
+
}
|
|
690
|
+
if (relativeTrace.startsWith("pages/")) {
|
|
691
|
+
return normalizeTraceRoute(relativeTrace.slice("pages/".length));
|
|
692
|
+
}
|
|
693
|
+
if (normalizedTrace.startsWith("app/")) {
|
|
694
|
+
return normalizeTraceRoute(normalizedTrace.slice("app/".length));
|
|
695
|
+
}
|
|
696
|
+
if (normalizedTrace.startsWith("pages/")) {
|
|
697
|
+
return normalizeTraceRoute(normalizedTrace.slice("pages/".length));
|
|
698
|
+
}
|
|
699
|
+
if ((0, import_node_path.basename)(outputPath) === "app" || (0, import_node_path.basename)(outputPath) === "pages") {
|
|
700
|
+
return normalizeTraceRoute(relativeTrace);
|
|
701
|
+
}
|
|
702
|
+
return void 0;
|
|
703
|
+
}
|
|
704
|
+
function normalizeTraceRoute(relativeTrace) {
|
|
705
|
+
const withoutTraceSuffix = relativeTrace.replace(/\.js\.nft\.json$/, "");
|
|
706
|
+
const route = withoutTraceSuffix.replace(/\/route$/, "").replace(/\/page$/, "").replace(/\/index$/, "");
|
|
707
|
+
return `/${route}`;
|
|
708
|
+
}
|
|
709
|
+
function routeGlobMatches(routeGlob, routePath) {
|
|
710
|
+
if (routeGlob === "/*") {
|
|
711
|
+
return true;
|
|
712
|
+
}
|
|
713
|
+
return routeGlobToRegExp(routeGlob).test(routePath);
|
|
714
|
+
}
|
|
715
|
+
function routeGlobToRegExp(glob) {
|
|
716
|
+
let pattern = "";
|
|
717
|
+
for (let index = 0; index < glob.length; index += 1) {
|
|
718
|
+
const char = glob[index];
|
|
719
|
+
const nextChar = glob[index + 1];
|
|
720
|
+
if (char === "*" && nextChar === "*") {
|
|
721
|
+
pattern += ".*";
|
|
722
|
+
index += 1;
|
|
723
|
+
} else if (char === "*") {
|
|
724
|
+
pattern += "[^/]*";
|
|
725
|
+
} else {
|
|
726
|
+
pattern += escapeRegExp(char);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
return new RegExp(`^${pattern}$`);
|
|
730
|
+
}
|
|
731
|
+
function escapeRegExp(value) {
|
|
732
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
733
|
+
}
|
|
734
|
+
function asRecord(value) {
|
|
735
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
736
|
+
}
|
|
737
|
+
function normalizeNonEmptyStrings(name, value) {
|
|
738
|
+
const values = Array.isArray(value) ? value : [value];
|
|
739
|
+
if (values.length === 0) {
|
|
740
|
+
throw new ConfigurationError(`${name} must contain at least one entry.`);
|
|
741
|
+
}
|
|
742
|
+
for (const entry of values) {
|
|
743
|
+
if (typeof entry !== "string" || entry.trim() === "") {
|
|
744
|
+
throw new ConfigurationError(`${name} entries must be non-empty strings.`);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
return values;
|
|
748
|
+
}
|
|
749
|
+
function mergeStringArray(existing, values) {
|
|
750
|
+
const current = Array.isArray(existing) ? existing.filter((value) => typeof value === "string") : [];
|
|
751
|
+
return [.../* @__PURE__ */ new Set([...current, ...values])];
|
|
752
|
+
}
|
|
753
|
+
function mergeTracingIncludes(existing, routeGlobs, sourceFiles) {
|
|
754
|
+
const includes = { ...asRecord(existing) };
|
|
755
|
+
for (const routeGlob of routeGlobs) {
|
|
756
|
+
includes[routeGlob] = mergeStringArray(includes[routeGlob], sourceFiles);
|
|
757
|
+
}
|
|
758
|
+
return includes;
|
|
759
|
+
}
|
|
299
760
|
var DEFAULT_DEPENDENCIES = {};
|
|
300
761
|
function isServerAgentConfig(config) {
|
|
301
762
|
return "server" in config && config.server !== void 0;
|
|
@@ -407,10 +868,28 @@ function shellEscape(str) {
|
|
|
407
868
|
return `'${str.replace(/'/g, "'\\''")}'`;
|
|
408
869
|
}
|
|
409
870
|
var require2 = (0, import_node_module.createRequire)((0, import_node_path.join)(process.cwd(), "__agent_neckbeard__.cjs"));
|
|
871
|
+
var packageRequire = createPackageRequire();
|
|
872
|
+
function createPackageRequire() {
|
|
873
|
+
const cwdPackageJsonPath = (0, import_node_path.join)(process.cwd(), "package.json");
|
|
874
|
+
try {
|
|
875
|
+
if ((0, import_node_fs.existsSync)(cwdPackageJsonPath) && readPackageJson(cwdPackageJsonPath).name === NECKBEARD_PACKAGE_NAME) {
|
|
876
|
+
return (0, import_node_module.createRequire)(cwdPackageJsonPath);
|
|
877
|
+
}
|
|
878
|
+
} catch {
|
|
879
|
+
}
|
|
880
|
+
try {
|
|
881
|
+
return (0, import_node_module.createRequire)(require2.resolve(NECKBEARD_PACKAGE_NAME));
|
|
882
|
+
} catch {
|
|
883
|
+
return require2;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
410
886
|
function isBareModuleImport(path) {
|
|
411
887
|
const excludes = [".", "/", "~", "file:", "data:"];
|
|
412
888
|
return !excludes.some((exclude) => path.startsWith(exclude));
|
|
413
889
|
}
|
|
890
|
+
function isBuiltinModule(path) {
|
|
891
|
+
return import_node_module.builtinModules.includes(path.replace("node:", ""));
|
|
892
|
+
}
|
|
414
893
|
function packageNameForImportPath(importPath) {
|
|
415
894
|
if (importPath.startsWith("@")) {
|
|
416
895
|
return importPath.split("/").slice(0, 2).join("/");
|
|
@@ -425,6 +904,9 @@ function matchesExternal(matchers, pkgName) {
|
|
|
425
904
|
return matchers.some((re) => re.test(pkgName));
|
|
426
905
|
}
|
|
427
906
|
async function resolvePackageInfo(importPath, resolveDir) {
|
|
907
|
+
return resolvePackageInfoSync(importPath, resolveDir);
|
|
908
|
+
}
|
|
909
|
+
function resolvePackageInfoSync(importPath, resolveDir) {
|
|
428
910
|
try {
|
|
429
911
|
const resolvedPath = require2.resolve(importPath, { paths: [resolveDir] });
|
|
430
912
|
const packageName = packageNameForImportPath(importPath);
|
|
@@ -458,6 +940,29 @@ async function resolvePackageInfo(importPath, resolveDir) {
|
|
|
458
940
|
return null;
|
|
459
941
|
}
|
|
460
942
|
}
|
|
943
|
+
function resolvePackageInfoFromResolvedPath(importPath, resolvedPath) {
|
|
944
|
+
const packageName = packageNameForImportPath(importPath);
|
|
945
|
+
let root = (0, import_node_path.dirname)(resolvedPath);
|
|
946
|
+
while (true) {
|
|
947
|
+
const packageJsonPath = (0, import_node_path.join)(root, "package.json");
|
|
948
|
+
if ((0, import_node_fs.existsSync)(packageJsonPath)) {
|
|
949
|
+
const packageJson = readPackageJson(packageJsonPath);
|
|
950
|
+
if (packageJson.name === packageName) {
|
|
951
|
+
if (!packageJson.version) return null;
|
|
952
|
+
return {
|
|
953
|
+
name: packageJson.name,
|
|
954
|
+
version: packageJson.version,
|
|
955
|
+
root,
|
|
956
|
+
resolvedPath,
|
|
957
|
+
packageJson
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
const parent = (0, import_node_path.dirname)(root);
|
|
962
|
+
if (parent === root) return null;
|
|
963
|
+
root = parent;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
461
966
|
function hasNativeHints(info) {
|
|
462
967
|
const files = Array.isArray(info.packageJson.files) ? info.packageJson.files : [];
|
|
463
968
|
const fields = [info.packageJson.main, info.packageJson.module, info.packageJson.browser].filter(
|
|
@@ -532,6 +1037,9 @@ function timeoutMsToSeconds(timeoutMs) {
|
|
|
532
1037
|
function asError(error) {
|
|
533
1038
|
return error instanceof Error ? error : new Error(String(error));
|
|
534
1039
|
}
|
|
1040
|
+
function errorMessage(error) {
|
|
1041
|
+
return error instanceof Error ? error.message : String(error);
|
|
1042
|
+
}
|
|
535
1043
|
async function resolveDaytonaPaths(sandbox) {
|
|
536
1044
|
const workDir = await sandbox.getWorkDir() ?? await sandbox.getUserHomeDir();
|
|
537
1045
|
const homeDir = await sandbox.getUserHomeDir() ?? workDir;
|
|
@@ -563,11 +1071,11 @@ async function runE2bCommand(sandbox, cmd, options) {
|
|
|
563
1071
|
};
|
|
564
1072
|
} catch (error) {
|
|
565
1073
|
const exitCode = error.exitCode ?? 1;
|
|
566
|
-
const
|
|
1074
|
+
const errorMessage2 = error instanceof Error ? error.message : String(error);
|
|
567
1075
|
return {
|
|
568
1076
|
exitCode,
|
|
569
1077
|
stdout,
|
|
570
|
-
stderr: stderr ||
|
|
1078
|
+
stderr: stderr || errorMessage2
|
|
571
1079
|
};
|
|
572
1080
|
}
|
|
573
1081
|
}
|
|
@@ -701,13 +1209,31 @@ function getCallerFile() {
|
|
|
701
1209
|
}
|
|
702
1210
|
throw new Error("Could not determine source file");
|
|
703
1211
|
}
|
|
1212
|
+
function isFrameworkBuildOutputPath(file) {
|
|
1213
|
+
const normalized = file.replace(/\\/g, "/");
|
|
1214
|
+
return normalized.includes("/.next/server/chunks/") || normalized.includes("/.next/server/app/") || normalized.includes("/.next/server/pages/");
|
|
1215
|
+
}
|
|
1216
|
+
function frameworkBuildOutputError(file) {
|
|
1217
|
+
return new ConfigurationError(
|
|
1218
|
+
`Agent source resolved to framework build output (${file}). Set sourceFile to the original agent module so deploy() bundles your agent source instead of a framework chunk.`
|
|
1219
|
+
);
|
|
1220
|
+
}
|
|
704
1221
|
function resolveSourceFile(sourceFile) {
|
|
705
|
-
if (!sourceFile)
|
|
1222
|
+
if (!sourceFile) {
|
|
1223
|
+
const inferred = getCallerFile();
|
|
1224
|
+
if (isFrameworkBuildOutputPath(inferred)) {
|
|
1225
|
+
throw frameworkBuildOutputError(inferred);
|
|
1226
|
+
}
|
|
1227
|
+
return inferred;
|
|
1228
|
+
}
|
|
706
1229
|
const normalized = normalizeStackFramePath(sourceFile);
|
|
707
1230
|
if (!normalized) {
|
|
708
1231
|
throw new ConfigurationError(`sourceFile could not be resolved: ${sourceFile}`);
|
|
709
1232
|
}
|
|
710
1233
|
const resolved = (0, import_node_path.resolve)(normalized);
|
|
1234
|
+
if (isFrameworkBuildOutputPath(resolved)) {
|
|
1235
|
+
throw frameworkBuildOutputError(resolved);
|
|
1236
|
+
}
|
|
711
1237
|
if (!(0, import_node_fs.existsSync)(resolved)) {
|
|
712
1238
|
throw new ConfigurationError(`sourceFile does not exist: ${resolved}`);
|
|
713
1239
|
}
|
|
@@ -789,7 +1315,10 @@ var Agent = class {
|
|
|
789
1315
|
return this._serverRuntime?.connection.sandboxId ?? this._sandboxId;
|
|
790
1316
|
}
|
|
791
1317
|
get sandboxEnv() {
|
|
792
|
-
return
|
|
1318
|
+
return {
|
|
1319
|
+
...filterDefinedEnvs(this.envs),
|
|
1320
|
+
[NECKBEARD_SANDBOX_RUNTIME_ENV]: "1"
|
|
1321
|
+
};
|
|
793
1322
|
}
|
|
794
1323
|
async createSandboxHandle() {
|
|
795
1324
|
if (this.provider === "daytona") {
|
|
@@ -1032,6 +1561,9 @@ var require = __neckbeard_createRequire(import.meta.url);
|
|
|
1032
1561
|
}
|
|
1033
1562
|
}
|
|
1034
1563
|
}
|
|
1564
|
+
export function resolveAgentSourceFile(_candidates, options = {}) {
|
|
1565
|
+
return options.sandboxSourceFile ?? process.cwd() + '/agent.mjs';
|
|
1566
|
+
}
|
|
1035
1567
|
`,
|
|
1036
1568
|
loader: "js"
|
|
1037
1569
|
}));
|
|
@@ -1329,5 +1861,7 @@ ${parts.join("\n\n")}`;
|
|
|
1329
1861
|
ExecutionError,
|
|
1330
1862
|
NeckbeardError,
|
|
1331
1863
|
ValidationError,
|
|
1332
|
-
normalizeStackFramePath
|
|
1864
|
+
normalizeStackFramePath,
|
|
1865
|
+
resolveAgentSourceFile,
|
|
1866
|
+
withNeckbeardNextConfig
|
|
1333
1867
|
});
|