agent-neckbeard 1.1.11 → 1.1.12

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 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/**/*'],
75
+ });
76
+
77
+ export default nextConfig;
78
+ ```
79
+
80
+ 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;
@@ -296,6 +300,354 @@ var ConfigurationError = class extends NeckbeardError {
296
300
  this.name = "ConfigurationError";
297
301
  }
298
302
  };
303
+ function resolveAgentSourceFile(candidates, options = {}) {
304
+ const normalizedCandidates = normalizeNonEmptyStrings("candidates", candidates);
305
+ const sourceFile = normalizedCandidates.find((candidate) => (0, import_node_fs.existsSync)(candidate));
306
+ if (sourceFile) {
307
+ return sourceFile;
308
+ }
309
+ if (process.env[NECKBEARD_SANDBOX_RUNTIME_ENV] === "1") {
310
+ const sandboxSourceFile = options.sandboxSourceFile ?? (0, import_node_path.resolve)(process.cwd(), "agent.mjs");
311
+ if ((0, import_node_fs.existsSync)(sandboxSourceFile)) {
312
+ return sandboxSourceFile;
313
+ }
314
+ }
315
+ throw new ConfigurationError(
316
+ options.errorMessage ?? `Could not resolve agent source file. Checked: ${candidates.join(", ")}`
317
+ );
318
+ }
319
+ function withNeckbeardNextConfig(nextConfig, options) {
320
+ const sourceFiles = normalizeNonEmptyStrings("sourceFiles", options.sourceFiles);
321
+ const routeGlobs = normalizeNonEmptyStrings("routeGlob", options.routeGlob ?? "/*");
322
+ const experimental = asRecord(nextConfig.experimental);
323
+ const useLegacyExperimental = options.legacyExperimental ?? ("serverComponentsExternalPackages" in experimental || "outputFileTracingIncludes" in experimental || "outputFileTracingRoot" in experimental);
324
+ if (useLegacyExperimental) {
325
+ const nextExperimental = {
326
+ ...experimental,
327
+ serverComponentsExternalPackages: mergeStringArray(
328
+ experimental.serverComponentsExternalPackages,
329
+ [NECKBEARD_PACKAGE_NAME]
330
+ ),
331
+ outputFileTracingIncludes: mergeTracingIncludes(
332
+ experimental.outputFileTracingIncludes,
333
+ routeGlobs,
334
+ sourceFiles
335
+ )
336
+ };
337
+ if (options.outputFileTracingRoot !== void 0) {
338
+ nextExperimental.outputFileTracingRoot = options.outputFileTracingRoot;
339
+ }
340
+ return {
341
+ ...nextConfig,
342
+ experimental: nextExperimental,
343
+ webpack: withNextTraceIncludeWebpack(nextConfig.webpack, sourceFiles, routeGlobs)
344
+ };
345
+ }
346
+ const result = {
347
+ ...nextConfig,
348
+ serverExternalPackages: mergeStringArray(nextConfig.serverExternalPackages, [
349
+ NECKBEARD_PACKAGE_NAME
350
+ ]),
351
+ outputFileTracingIncludes: mergeTracingIncludes(
352
+ nextConfig.outputFileTracingIncludes,
353
+ routeGlobs,
354
+ sourceFiles
355
+ )
356
+ };
357
+ if (options.outputFileTracingRoot !== void 0) {
358
+ result.outputFileTracingRoot = options.outputFileTracingRoot;
359
+ }
360
+ return result;
361
+ }
362
+ var NextTraceIncludePlugin = class {
363
+ constructor(appDir, sourceFiles, routeGlobs) {
364
+ this.appDir = appDir;
365
+ this.sourceFiles = sourceFiles;
366
+ this.routeGlobs = routeGlobs;
367
+ }
368
+ apply(compiler) {
369
+ const compilationHook = compiler.hooks?.compilation;
370
+ if (typeof compilationHook?.tap === "function") {
371
+ compilationHook.tap("NeckbeardNextTraceIncludePlugin", (compilation) => {
372
+ const processAssets = compilation.hooks?.processAssets;
373
+ if (typeof processAssets?.tap !== "function") {
374
+ return;
375
+ }
376
+ processAssets.tap({
377
+ name: "NeckbeardNextTraceIncludePlugin",
378
+ stage: compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_REPORT ?? 5e3
379
+ }, (assets) => {
380
+ appendIncludesToTraceAssets({
381
+ appDir: this.appDir,
382
+ assets,
383
+ outputPath: compilation.outputOptions?.path ?? compiler.outputPath ?? "",
384
+ rawSource: compiler.webpack?.sources?.RawSource,
385
+ routeGlobs: this.routeGlobs,
386
+ sourceFiles: this.sourceFiles,
387
+ updateAsset: compilation.updateAsset?.bind(compilation)
388
+ });
389
+ });
390
+ });
391
+ }
392
+ const afterEmit = compiler.hooks?.afterEmit;
393
+ const done = compiler.hooks?.done;
394
+ if (typeof afterEmit?.tap !== "function" && typeof done?.tap !== "function") {
395
+ return;
396
+ }
397
+ if (!compiler.outputPath) {
398
+ return;
399
+ }
400
+ const appendIncludes = () => {
401
+ appendIncludesToTraceFiles(
402
+ compiler.outputPath ?? "",
403
+ this.appDir,
404
+ this.sourceFiles,
405
+ this.routeGlobs
406
+ );
407
+ };
408
+ if (typeof afterEmit?.tap === "function") {
409
+ afterEmit.tap("NeckbeardNextTraceIncludePlugin", appendIncludes);
410
+ }
411
+ if (typeof done?.tap === "function") {
412
+ done.tap("NeckbeardNextTraceIncludePlugin", appendIncludes);
413
+ }
414
+ }
415
+ };
416
+ function appendIncludesToTraceAssets({
417
+ appDir,
418
+ assets,
419
+ outputPath,
420
+ rawSource,
421
+ routeGlobs,
422
+ sourceFiles,
423
+ updateAsset
424
+ }) {
425
+ const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles);
426
+ if (includedFiles.length === 0) {
427
+ return;
428
+ }
429
+ for (const [assetName, asset] of Object.entries(assets)) {
430
+ if (!assetName.endsWith(".nft.json")) {
431
+ continue;
432
+ }
433
+ const routePath = routePathFromTraceAsset(outputPath, assetName);
434
+ if (!routePath || !routeGlobs.some((routeGlob) => routeGlobMatches(routeGlob, routePath))) {
435
+ continue;
436
+ }
437
+ const traceDir = (0, import_node_path.dirname)((0, import_node_path.join)(outputPath, assetName));
438
+ const nextSource = traceWithIncludedFiles(String(asset.source()), traceDir, includedFiles);
439
+ if (rawSource && updateAsset) {
440
+ updateAsset(assetName, new rawSource(nextSource));
441
+ } else {
442
+ assets[assetName] = {
443
+ source: () => nextSource,
444
+ size: () => Buffer.byteLength(nextSource)
445
+ };
446
+ }
447
+ }
448
+ }
449
+ function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs) {
450
+ return (config, context) => {
451
+ const nextConfig = originalWebpack ? originalWebpack(config, context) : config;
452
+ if (!context.isServer || context.dev) {
453
+ return nextConfig;
454
+ }
455
+ nextConfig.externals = withNeckbeardExternal(nextConfig.externals);
456
+ nextConfig.plugins = [
457
+ ...Array.isArray(nextConfig.plugins) ? nextConfig.plugins : [],
458
+ new NextTraceIncludePlugin(context.dir ?? process.cwd(), sourceFiles, routeGlobs)
459
+ ];
460
+ return nextConfig;
461
+ };
462
+ }
463
+ function withNeckbeardExternal(externals) {
464
+ return [
465
+ neckbeardExternal,
466
+ ...Array.isArray(externals) ? externals : externals ? [externals] : []
467
+ ];
468
+ }
469
+ function neckbeardExternal(contextOrRequest, requestOrCallback) {
470
+ const legacyCallback = arguments[2];
471
+ const request = typeof requestOrCallback === "string" ? requestOrCallback : typeof contextOrRequest === "string" ? contextOrRequest : contextOrRequest.request;
472
+ const callback = typeof requestOrCallback === "function" ? requestOrCallback : legacyCallback;
473
+ if (request === NECKBEARD_PACKAGE_NAME) {
474
+ const result = `commonjs ${NECKBEARD_PACKAGE_NAME}`;
475
+ if (callback) {
476
+ callback(null, result);
477
+ return;
478
+ }
479
+ return result;
480
+ }
481
+ if (callback) {
482
+ callback();
483
+ }
484
+ }
485
+ function appendIncludesToTraceFiles(outputPath, appDir, sourceFiles, routeGlobs) {
486
+ if (!outputPath || !(0, import_node_fs.existsSync)(outputPath)) {
487
+ return;
488
+ }
489
+ const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles);
490
+ if (includedFiles.length === 0) {
491
+ return;
492
+ }
493
+ for (const traceFile of findTraceFiles(outputPath)) {
494
+ const routePath = routePathFromTraceFile(outputPath, traceFile);
495
+ if (!routePath || !routeGlobs.some((routeGlob) => routeGlobMatches(routeGlob, routePath))) {
496
+ continue;
497
+ }
498
+ appendFilesToTrace(traceFile, includedFiles);
499
+ }
500
+ }
501
+ function appendFilesToTrace(traceFile, includedFiles) {
502
+ const nextSource = traceWithIncludedFiles(
503
+ (0, import_node_fs.readFileSync)(traceFile, "utf8"),
504
+ (0, import_node_path.dirname)(traceFile),
505
+ includedFiles
506
+ );
507
+ (0, import_node_fs.writeFileSync)(traceFile, nextSource);
508
+ }
509
+ function traceWithIncludedFiles(traceSource, traceDir, includedFiles) {
510
+ const trace = JSON.parse(traceSource);
511
+ const files = Array.isArray(trace.files) ? trace.files.filter((file) => typeof file === "string") : [];
512
+ const nextFiles = new Set(files);
513
+ for (const includedFile of includedFiles) {
514
+ nextFiles.add((0, import_node_path.relative)(traceDir, includedFile).replace(/\\/g, "/"));
515
+ }
516
+ return JSON.stringify({
517
+ version: trace.version ?? 1,
518
+ files: [...nextFiles]
519
+ });
520
+ }
521
+ function expandTraceIncludeFiles(appDir, sourceFiles) {
522
+ const files = /* @__PURE__ */ new Set();
523
+ for (const sourceFile of sourceFiles) {
524
+ for (const file of expandTraceIncludePattern(appDir, sourceFile)) {
525
+ files.add(file);
526
+ }
527
+ }
528
+ return [...files];
529
+ }
530
+ function expandTraceIncludePattern(appDir, sourceFile) {
531
+ const normalized = sourceFile.replace(/\\/g, "/").replace(/^\.\//, "");
532
+ if (normalized.endsWith("/**/*")) {
533
+ const dir = (0, import_node_path.resolve)(appDir, normalized.slice(0, -5));
534
+ return findFiles(dir);
535
+ }
536
+ if (normalized.endsWith("/*")) {
537
+ const dir = (0, import_node_path.resolve)(appDir, normalized.slice(0, -2));
538
+ return directFiles(dir);
539
+ }
540
+ const file = (0, import_node_path.resolve)(appDir, normalized);
541
+ return (0, import_node_fs.existsSync)(file) && (0, import_node_fs.statSync)(file).isFile() ? [file] : [];
542
+ }
543
+ function findTraceFiles(root) {
544
+ return findFiles(root).filter((file) => file.endsWith(".nft.json"));
545
+ }
546
+ function findFiles(root) {
547
+ if (!(0, import_node_fs.existsSync)(root)) {
548
+ return [];
549
+ }
550
+ const stat = (0, import_node_fs.statSync)(root);
551
+ if (stat.isFile()) {
552
+ return [root];
553
+ }
554
+ if (!stat.isDirectory()) {
555
+ return [];
556
+ }
557
+ const files = [];
558
+ for (const entry of (0, import_node_fs.readdirSync)(root)) {
559
+ files.push(...findFiles((0, import_node_path.join)(root, entry)));
560
+ }
561
+ return files;
562
+ }
563
+ function directFiles(root) {
564
+ if (!(0, import_node_fs.existsSync)(root) || !(0, import_node_fs.statSync)(root).isDirectory()) {
565
+ return [];
566
+ }
567
+ 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());
568
+ }
569
+ function routePathFromTraceFile(outputPath, traceFile) {
570
+ const relativeTrace = (0, import_node_path.relative)(outputPath, traceFile).replace(/\\/g, "/");
571
+ return routePathFromRelativeTrace(outputPath, relativeTrace);
572
+ }
573
+ function routePathFromTraceAsset(outputPath, assetName) {
574
+ return routePathFromRelativeTrace(outputPath, assetName.replace(/\\/g, "/"));
575
+ }
576
+ function routePathFromRelativeTrace(outputPath, relativeTrace) {
577
+ const normalizedTrace = relativeTrace.replace(/^(\.\.\/)+/, "");
578
+ if (relativeTrace.startsWith("app/")) {
579
+ return normalizeTraceRoute(relativeTrace.slice("app/".length));
580
+ }
581
+ if (relativeTrace.startsWith("pages/")) {
582
+ return normalizeTraceRoute(relativeTrace.slice("pages/".length));
583
+ }
584
+ if (normalizedTrace.startsWith("app/")) {
585
+ return normalizeTraceRoute(normalizedTrace.slice("app/".length));
586
+ }
587
+ if (normalizedTrace.startsWith("pages/")) {
588
+ return normalizeTraceRoute(normalizedTrace.slice("pages/".length));
589
+ }
590
+ if ((0, import_node_path.basename)(outputPath) === "app" || (0, import_node_path.basename)(outputPath) === "pages") {
591
+ return normalizeTraceRoute(relativeTrace);
592
+ }
593
+ return void 0;
594
+ }
595
+ function normalizeTraceRoute(relativeTrace) {
596
+ const withoutTraceSuffix = relativeTrace.replace(/\.js\.nft\.json$/, "");
597
+ const route = withoutTraceSuffix.replace(/\/route$/, "").replace(/\/page$/, "").replace(/\/index$/, "");
598
+ return `/${route}`;
599
+ }
600
+ function routeGlobMatches(routeGlob, routePath) {
601
+ if (routeGlob === "/*") {
602
+ return true;
603
+ }
604
+ return routeGlobToRegExp(routeGlob).test(routePath);
605
+ }
606
+ function routeGlobToRegExp(glob) {
607
+ let pattern = "";
608
+ for (let index = 0; index < glob.length; index += 1) {
609
+ const char = glob[index];
610
+ const nextChar = glob[index + 1];
611
+ if (char === "*" && nextChar === "*") {
612
+ pattern += ".*";
613
+ index += 1;
614
+ } else if (char === "*") {
615
+ pattern += "[^/]*";
616
+ } else {
617
+ pattern += escapeRegExp(char);
618
+ }
619
+ }
620
+ return new RegExp(`^${pattern}$`);
621
+ }
622
+ function escapeRegExp(value) {
623
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
624
+ }
625
+ function asRecord(value) {
626
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
627
+ }
628
+ function normalizeNonEmptyStrings(name, value) {
629
+ const values = Array.isArray(value) ? value : [value];
630
+ if (values.length === 0) {
631
+ throw new ConfigurationError(`${name} must contain at least one entry.`);
632
+ }
633
+ for (const entry of values) {
634
+ if (typeof entry !== "string" || entry.trim() === "") {
635
+ throw new ConfigurationError(`${name} entries must be non-empty strings.`);
636
+ }
637
+ }
638
+ return values;
639
+ }
640
+ function mergeStringArray(existing, values) {
641
+ const current = Array.isArray(existing) ? existing.filter((value) => typeof value === "string") : [];
642
+ return [.../* @__PURE__ */ new Set([...current, ...values])];
643
+ }
644
+ function mergeTracingIncludes(existing, routeGlobs, sourceFiles) {
645
+ const includes = { ...asRecord(existing) };
646
+ for (const routeGlob of routeGlobs) {
647
+ includes[routeGlob] = mergeStringArray(includes[routeGlob], sourceFiles);
648
+ }
649
+ return includes;
650
+ }
299
651
  var DEFAULT_DEPENDENCIES = {};
300
652
  function isServerAgentConfig(config) {
301
653
  return "server" in config && config.server !== void 0;
@@ -701,13 +1053,31 @@ function getCallerFile() {
701
1053
  }
702
1054
  throw new Error("Could not determine source file");
703
1055
  }
1056
+ function isFrameworkBuildOutputPath(file) {
1057
+ const normalized = file.replace(/\\/g, "/");
1058
+ return normalized.includes("/.next/server/chunks/") || normalized.includes("/.next/server/app/") || normalized.includes("/.next/server/pages/");
1059
+ }
1060
+ function frameworkBuildOutputError(file) {
1061
+ return new ConfigurationError(
1062
+ `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.`
1063
+ );
1064
+ }
704
1065
  function resolveSourceFile(sourceFile) {
705
- if (!sourceFile) return getCallerFile();
1066
+ if (!sourceFile) {
1067
+ const inferred = getCallerFile();
1068
+ if (isFrameworkBuildOutputPath(inferred)) {
1069
+ throw frameworkBuildOutputError(inferred);
1070
+ }
1071
+ return inferred;
1072
+ }
706
1073
  const normalized = normalizeStackFramePath(sourceFile);
707
1074
  if (!normalized) {
708
1075
  throw new ConfigurationError(`sourceFile could not be resolved: ${sourceFile}`);
709
1076
  }
710
1077
  const resolved = (0, import_node_path.resolve)(normalized);
1078
+ if (isFrameworkBuildOutputPath(resolved)) {
1079
+ throw frameworkBuildOutputError(resolved);
1080
+ }
711
1081
  if (!(0, import_node_fs.existsSync)(resolved)) {
712
1082
  throw new ConfigurationError(`sourceFile does not exist: ${resolved}`);
713
1083
  }
@@ -789,7 +1159,10 @@ var Agent = class {
789
1159
  return this._serverRuntime?.connection.sandboxId ?? this._sandboxId;
790
1160
  }
791
1161
  get sandboxEnv() {
792
- return filterDefinedEnvs(this.envs);
1162
+ return {
1163
+ ...filterDefinedEnvs(this.envs),
1164
+ [NECKBEARD_SANDBOX_RUNTIME_ENV]: "1"
1165
+ };
793
1166
  }
794
1167
  async createSandboxHandle() {
795
1168
  if (this.provider === "daytona") {
@@ -1032,6 +1405,9 @@ var require = __neckbeard_createRequire(import.meta.url);
1032
1405
  }
1033
1406
  }
1034
1407
  }
1408
+ export function resolveAgentSourceFile(_candidates, options = {}) {
1409
+ return options.sandboxSourceFile ?? process.cwd() + '/agent.mjs';
1410
+ }
1035
1411
  `,
1036
1412
  loader: "js"
1037
1413
  }));
@@ -1329,5 +1705,7 @@ ${parts.join("\n\n")}`;
1329
1705
  ExecutionError,
1330
1706
  NeckbeardError,
1331
1707
  ValidationError,
1332
- normalizeStackFramePath
1708
+ normalizeStackFramePath,
1709
+ resolveAgentSourceFile,
1710
+ withNeckbeardNextConfig
1333
1711
  });
package/dist/index.d.cts CHANGED
@@ -85,6 +85,63 @@ interface BuildOptions {
85
85
  */
86
86
  autoDetectExternal?: boolean;
87
87
  }
88
+ interface NeckbeardNextConfigOptions {
89
+ /**
90
+ * Agent source file globs to include in the deployed Next.js server artifact.
91
+ *
92
+ * Paths follow Next.js `outputFileTracingIncludes` semantics and are resolved
93
+ * relative to the app root unless `outputFileTracingRoot` is also set.
94
+ */
95
+ sourceFiles: string[];
96
+ /**
97
+ * Route glob or globs whose server traces should include `sourceFiles`.
98
+ *
99
+ * @default '/*'
100
+ */
101
+ routeGlob?: string | string[];
102
+ /**
103
+ * Next.js output file tracing root. Set this for monorepos when source files
104
+ * live outside the app directory.
105
+ */
106
+ outputFileTracingRoot?: string;
107
+ /**
108
+ * Force the older Next.js experimental config placement used by Next 13.
109
+ *
110
+ * By default this is inferred when the provided config already uses
111
+ * `experimental.serverComponentsExternalPackages` or experimental tracing.
112
+ */
113
+ legacyExperimental?: boolean;
114
+ }
115
+ interface ResolveAgentSourceFileOptions {
116
+ /** Custom error prefix when no source file candidate exists outside the sandbox runtime. */
117
+ errorMessage?: string;
118
+ /**
119
+ * Existing file to use when the bundled agent is imported by the in-sandbox runtime server.
120
+ *
121
+ * @default `${process.cwd()}/agent.mjs`
122
+ */
123
+ sandboxSourceFile?: string;
124
+ }
125
+ declare function resolveAgentSourceFile(candidates: string[], options?: ResolveAgentSourceFileOptions): string;
126
+ type NextConfigObject = {
127
+ experimental?: Record<string, unknown>;
128
+ outputFileTracingIncludes?: Record<string, unknown>;
129
+ outputFileTracingRoot?: string;
130
+ serverExternalPackages?: string[];
131
+ webpack?: NextWebpackFunction;
132
+ [key: string]: unknown;
133
+ };
134
+ type NextWebpackConfig = Record<string, unknown> & {
135
+ externals?: unknown;
136
+ plugins?: unknown[];
137
+ };
138
+ type NextWebpackContext = Record<string, unknown> & {
139
+ dev?: boolean;
140
+ dir?: string;
141
+ isServer?: boolean;
142
+ };
143
+ type NextWebpackFunction = (config: NextWebpackConfig, context: NextWebpackContext) => NextWebpackConfig;
144
+ declare function withNeckbeardNextConfig<TConfig extends NextConfigObject>(nextConfig: TConfig, options: NeckbeardNextConfigOptions): TConfig & NextConfigObject;
88
145
  /**
89
146
  * Configuration for downloading a file into the sandbox filesystem.
90
147
  * Files are downloaded during deploy() before the agent runs.
@@ -335,4 +392,4 @@ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
335
392
  }): AsyncGenerator<TFrame>;
336
393
  }
337
394
 
338
- export { Agent, type AgentConfig, type AgentMode, type AgentRunContext, type AgentRunResult, type AgentSandboxContext, type BuildOptions, ConfigurationError, DEFAULT_DEPENDENCIES, type DaytonaSandboxConfig, DeploymentError, type E2BSandboxConfig, ExecutionError, type FileDownload, NeckbeardError, type OsDependencies, type RunAgentConfig, type SandboxConfig, type SandboxProvider, type ServerAgentConfig, ValidationError };
395
+ export { Agent, type AgentConfig, type AgentMode, type AgentRunContext, type AgentRunResult, type AgentSandboxContext, type BuildOptions, ConfigurationError, DEFAULT_DEPENDENCIES, type DaytonaSandboxConfig, DeploymentError, type E2BSandboxConfig, ExecutionError, type FileDownload, NeckbeardError, type NeckbeardNextConfigOptions, type OsDependencies, type ResolveAgentSourceFileOptions, type RunAgentConfig, type SandboxConfig, type SandboxProvider, type ServerAgentConfig, ValidationError, resolveAgentSourceFile, withNeckbeardNextConfig };
package/dist/index.d.ts CHANGED
@@ -85,6 +85,63 @@ interface BuildOptions {
85
85
  */
86
86
  autoDetectExternal?: boolean;
87
87
  }
88
+ interface NeckbeardNextConfigOptions {
89
+ /**
90
+ * Agent source file globs to include in the deployed Next.js server artifact.
91
+ *
92
+ * Paths follow Next.js `outputFileTracingIncludes` semantics and are resolved
93
+ * relative to the app root unless `outputFileTracingRoot` is also set.
94
+ */
95
+ sourceFiles: string[];
96
+ /**
97
+ * Route glob or globs whose server traces should include `sourceFiles`.
98
+ *
99
+ * @default '/*'
100
+ */
101
+ routeGlob?: string | string[];
102
+ /**
103
+ * Next.js output file tracing root. Set this for monorepos when source files
104
+ * live outside the app directory.
105
+ */
106
+ outputFileTracingRoot?: string;
107
+ /**
108
+ * Force the older Next.js experimental config placement used by Next 13.
109
+ *
110
+ * By default this is inferred when the provided config already uses
111
+ * `experimental.serverComponentsExternalPackages` or experimental tracing.
112
+ */
113
+ legacyExperimental?: boolean;
114
+ }
115
+ interface ResolveAgentSourceFileOptions {
116
+ /** Custom error prefix when no source file candidate exists outside the sandbox runtime. */
117
+ errorMessage?: string;
118
+ /**
119
+ * Existing file to use when the bundled agent is imported by the in-sandbox runtime server.
120
+ *
121
+ * @default `${process.cwd()}/agent.mjs`
122
+ */
123
+ sandboxSourceFile?: string;
124
+ }
125
+ declare function resolveAgentSourceFile(candidates: string[], options?: ResolveAgentSourceFileOptions): string;
126
+ type NextConfigObject = {
127
+ experimental?: Record<string, unknown>;
128
+ outputFileTracingIncludes?: Record<string, unknown>;
129
+ outputFileTracingRoot?: string;
130
+ serverExternalPackages?: string[];
131
+ webpack?: NextWebpackFunction;
132
+ [key: string]: unknown;
133
+ };
134
+ type NextWebpackConfig = Record<string, unknown> & {
135
+ externals?: unknown;
136
+ plugins?: unknown[];
137
+ };
138
+ type NextWebpackContext = Record<string, unknown> & {
139
+ dev?: boolean;
140
+ dir?: string;
141
+ isServer?: boolean;
142
+ };
143
+ type NextWebpackFunction = (config: NextWebpackConfig, context: NextWebpackContext) => NextWebpackConfig;
144
+ declare function withNeckbeardNextConfig<TConfig extends NextConfigObject>(nextConfig: TConfig, options: NeckbeardNextConfigOptions): TConfig & NextConfigObject;
88
145
  /**
89
146
  * Configuration for downloading a file into the sandbox filesystem.
90
147
  * Files are downloaded during deploy() before the agent runs.
@@ -335,4 +392,4 @@ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
335
392
  }): AsyncGenerator<TFrame>;
336
393
  }
337
394
 
338
- export { Agent, type AgentConfig, type AgentMode, type AgentRunContext, type AgentRunResult, type AgentSandboxContext, type BuildOptions, ConfigurationError, DEFAULT_DEPENDENCIES, type DaytonaSandboxConfig, DeploymentError, type E2BSandboxConfig, ExecutionError, type FileDownload, NeckbeardError, type OsDependencies, type RunAgentConfig, type SandboxConfig, type SandboxProvider, type ServerAgentConfig, ValidationError };
395
+ export { Agent, type AgentConfig, type AgentMode, type AgentRunContext, type AgentRunResult, type AgentSandboxContext, type BuildOptions, ConfigurationError, DEFAULT_DEPENDENCIES, type DaytonaSandboxConfig, DeploymentError, type E2BSandboxConfig, ExecutionError, type FileDownload, NeckbeardError, type NeckbeardNextConfigOptions, type OsDependencies, type ResolveAgentSourceFileOptions, type RunAgentConfig, type SandboxConfig, type SandboxProvider, type ServerAgentConfig, ValidationError, resolveAgentSourceFile, withNeckbeardNextConfig };
package/dist/index.js CHANGED
@@ -4,8 +4,8 @@ import {
4
4
 
5
5
  // src/index.ts
6
6
  import { fileURLToPath } from "url";
7
- import { existsSync, readdirSync, readFileSync, statSync } from "fs";
8
- import { dirname, join, relative, resolve } from "path";
7
+ import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "fs";
8
+ import { basename, dirname, join, relative, resolve } from "path";
9
9
  import { builtinModules, createRequire } from "module";
10
10
 
11
11
  // src/runtime/server-source.generated.ts
@@ -24,6 +24,8 @@ var QUICK_COMMAND_TIMEOUT_MS = 3e4;
24
24
  var DAYTONA_CREATE_TIMEOUT_SEC = 120;
25
25
  var NODE_TARGET = "node20";
26
26
  var DEFAULT_EXTERNALS = ["@anthropic-ai/claude-agent-sdk"];
27
+ var NECKBEARD_PACKAGE_NAME = "agent-neckbeard";
28
+ var NECKBEARD_SANDBOX_RUNTIME_ENV = "AGENT_NECKBEARD_SANDBOX_RUNTIME";
27
29
  var SANDBOX_PLATFORM = process.env.NECKBEARD_SANDBOX_PLATFORM ?? "linux";
28
30
  var SANDBOX_ARCH = process.env.NECKBEARD_SANDBOX_ARCH ?? "x64";
29
31
  var DEFAULT_SERVER_PORT = 3e3;
@@ -65,6 +67,354 @@ var ConfigurationError = class extends NeckbeardError {
65
67
  this.name = "ConfigurationError";
66
68
  }
67
69
  };
70
+ function resolveAgentSourceFile(candidates, options = {}) {
71
+ const normalizedCandidates = normalizeNonEmptyStrings("candidates", candidates);
72
+ const sourceFile = normalizedCandidates.find((candidate) => existsSync(candidate));
73
+ if (sourceFile) {
74
+ return sourceFile;
75
+ }
76
+ if (process.env[NECKBEARD_SANDBOX_RUNTIME_ENV] === "1") {
77
+ const sandboxSourceFile = options.sandboxSourceFile ?? resolve(process.cwd(), "agent.mjs");
78
+ if (existsSync(sandboxSourceFile)) {
79
+ return sandboxSourceFile;
80
+ }
81
+ }
82
+ throw new ConfigurationError(
83
+ options.errorMessage ?? `Could not resolve agent source file. Checked: ${candidates.join(", ")}`
84
+ );
85
+ }
86
+ function withNeckbeardNextConfig(nextConfig, options) {
87
+ const sourceFiles = normalizeNonEmptyStrings("sourceFiles", options.sourceFiles);
88
+ const routeGlobs = normalizeNonEmptyStrings("routeGlob", options.routeGlob ?? "/*");
89
+ const experimental = asRecord(nextConfig.experimental);
90
+ const useLegacyExperimental = options.legacyExperimental ?? ("serverComponentsExternalPackages" in experimental || "outputFileTracingIncludes" in experimental || "outputFileTracingRoot" in experimental);
91
+ if (useLegacyExperimental) {
92
+ const nextExperimental = {
93
+ ...experimental,
94
+ serverComponentsExternalPackages: mergeStringArray(
95
+ experimental.serverComponentsExternalPackages,
96
+ [NECKBEARD_PACKAGE_NAME]
97
+ ),
98
+ outputFileTracingIncludes: mergeTracingIncludes(
99
+ experimental.outputFileTracingIncludes,
100
+ routeGlobs,
101
+ sourceFiles
102
+ )
103
+ };
104
+ if (options.outputFileTracingRoot !== void 0) {
105
+ nextExperimental.outputFileTracingRoot = options.outputFileTracingRoot;
106
+ }
107
+ return {
108
+ ...nextConfig,
109
+ experimental: nextExperimental,
110
+ webpack: withNextTraceIncludeWebpack(nextConfig.webpack, sourceFiles, routeGlobs)
111
+ };
112
+ }
113
+ const result = {
114
+ ...nextConfig,
115
+ serverExternalPackages: mergeStringArray(nextConfig.serverExternalPackages, [
116
+ NECKBEARD_PACKAGE_NAME
117
+ ]),
118
+ outputFileTracingIncludes: mergeTracingIncludes(
119
+ nextConfig.outputFileTracingIncludes,
120
+ routeGlobs,
121
+ sourceFiles
122
+ )
123
+ };
124
+ if (options.outputFileTracingRoot !== void 0) {
125
+ result.outputFileTracingRoot = options.outputFileTracingRoot;
126
+ }
127
+ return result;
128
+ }
129
+ var NextTraceIncludePlugin = class {
130
+ constructor(appDir, sourceFiles, routeGlobs) {
131
+ this.appDir = appDir;
132
+ this.sourceFiles = sourceFiles;
133
+ this.routeGlobs = routeGlobs;
134
+ }
135
+ apply(compiler) {
136
+ const compilationHook = compiler.hooks?.compilation;
137
+ if (typeof compilationHook?.tap === "function") {
138
+ compilationHook.tap("NeckbeardNextTraceIncludePlugin", (compilation) => {
139
+ const processAssets = compilation.hooks?.processAssets;
140
+ if (typeof processAssets?.tap !== "function") {
141
+ return;
142
+ }
143
+ processAssets.tap({
144
+ name: "NeckbeardNextTraceIncludePlugin",
145
+ stage: compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_REPORT ?? 5e3
146
+ }, (assets) => {
147
+ appendIncludesToTraceAssets({
148
+ appDir: this.appDir,
149
+ assets,
150
+ outputPath: compilation.outputOptions?.path ?? compiler.outputPath ?? "",
151
+ rawSource: compiler.webpack?.sources?.RawSource,
152
+ routeGlobs: this.routeGlobs,
153
+ sourceFiles: this.sourceFiles,
154
+ updateAsset: compilation.updateAsset?.bind(compilation)
155
+ });
156
+ });
157
+ });
158
+ }
159
+ const afterEmit = compiler.hooks?.afterEmit;
160
+ const done = compiler.hooks?.done;
161
+ if (typeof afterEmit?.tap !== "function" && typeof done?.tap !== "function") {
162
+ return;
163
+ }
164
+ if (!compiler.outputPath) {
165
+ return;
166
+ }
167
+ const appendIncludes = () => {
168
+ appendIncludesToTraceFiles(
169
+ compiler.outputPath ?? "",
170
+ this.appDir,
171
+ this.sourceFiles,
172
+ this.routeGlobs
173
+ );
174
+ };
175
+ if (typeof afterEmit?.tap === "function") {
176
+ afterEmit.tap("NeckbeardNextTraceIncludePlugin", appendIncludes);
177
+ }
178
+ if (typeof done?.tap === "function") {
179
+ done.tap("NeckbeardNextTraceIncludePlugin", appendIncludes);
180
+ }
181
+ }
182
+ };
183
+ function appendIncludesToTraceAssets({
184
+ appDir,
185
+ assets,
186
+ outputPath,
187
+ rawSource,
188
+ routeGlobs,
189
+ sourceFiles,
190
+ updateAsset
191
+ }) {
192
+ const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles);
193
+ if (includedFiles.length === 0) {
194
+ return;
195
+ }
196
+ for (const [assetName, asset] of Object.entries(assets)) {
197
+ if (!assetName.endsWith(".nft.json")) {
198
+ continue;
199
+ }
200
+ const routePath = routePathFromTraceAsset(outputPath, assetName);
201
+ if (!routePath || !routeGlobs.some((routeGlob) => routeGlobMatches(routeGlob, routePath))) {
202
+ continue;
203
+ }
204
+ const traceDir = dirname(join(outputPath, assetName));
205
+ const nextSource = traceWithIncludedFiles(String(asset.source()), traceDir, includedFiles);
206
+ if (rawSource && updateAsset) {
207
+ updateAsset(assetName, new rawSource(nextSource));
208
+ } else {
209
+ assets[assetName] = {
210
+ source: () => nextSource,
211
+ size: () => Buffer.byteLength(nextSource)
212
+ };
213
+ }
214
+ }
215
+ }
216
+ function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs) {
217
+ return (config, context) => {
218
+ const nextConfig = originalWebpack ? originalWebpack(config, context) : config;
219
+ if (!context.isServer || context.dev) {
220
+ return nextConfig;
221
+ }
222
+ nextConfig.externals = withNeckbeardExternal(nextConfig.externals);
223
+ nextConfig.plugins = [
224
+ ...Array.isArray(nextConfig.plugins) ? nextConfig.plugins : [],
225
+ new NextTraceIncludePlugin(context.dir ?? process.cwd(), sourceFiles, routeGlobs)
226
+ ];
227
+ return nextConfig;
228
+ };
229
+ }
230
+ function withNeckbeardExternal(externals) {
231
+ return [
232
+ neckbeardExternal,
233
+ ...Array.isArray(externals) ? externals : externals ? [externals] : []
234
+ ];
235
+ }
236
+ function neckbeardExternal(contextOrRequest, requestOrCallback) {
237
+ const legacyCallback = arguments[2];
238
+ const request = typeof requestOrCallback === "string" ? requestOrCallback : typeof contextOrRequest === "string" ? contextOrRequest : contextOrRequest.request;
239
+ const callback = typeof requestOrCallback === "function" ? requestOrCallback : legacyCallback;
240
+ if (request === NECKBEARD_PACKAGE_NAME) {
241
+ const result = `commonjs ${NECKBEARD_PACKAGE_NAME}`;
242
+ if (callback) {
243
+ callback(null, result);
244
+ return;
245
+ }
246
+ return result;
247
+ }
248
+ if (callback) {
249
+ callback();
250
+ }
251
+ }
252
+ function appendIncludesToTraceFiles(outputPath, appDir, sourceFiles, routeGlobs) {
253
+ if (!outputPath || !existsSync(outputPath)) {
254
+ return;
255
+ }
256
+ const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles);
257
+ if (includedFiles.length === 0) {
258
+ return;
259
+ }
260
+ for (const traceFile of findTraceFiles(outputPath)) {
261
+ const routePath = routePathFromTraceFile(outputPath, traceFile);
262
+ if (!routePath || !routeGlobs.some((routeGlob) => routeGlobMatches(routeGlob, routePath))) {
263
+ continue;
264
+ }
265
+ appendFilesToTrace(traceFile, includedFiles);
266
+ }
267
+ }
268
+ function appendFilesToTrace(traceFile, includedFiles) {
269
+ const nextSource = traceWithIncludedFiles(
270
+ readFileSync(traceFile, "utf8"),
271
+ dirname(traceFile),
272
+ includedFiles
273
+ );
274
+ writeFileSync(traceFile, nextSource);
275
+ }
276
+ function traceWithIncludedFiles(traceSource, traceDir, includedFiles) {
277
+ const trace = JSON.parse(traceSource);
278
+ const files = Array.isArray(trace.files) ? trace.files.filter((file) => typeof file === "string") : [];
279
+ const nextFiles = new Set(files);
280
+ for (const includedFile of includedFiles) {
281
+ nextFiles.add(relative(traceDir, includedFile).replace(/\\/g, "/"));
282
+ }
283
+ return JSON.stringify({
284
+ version: trace.version ?? 1,
285
+ files: [...nextFiles]
286
+ });
287
+ }
288
+ function expandTraceIncludeFiles(appDir, sourceFiles) {
289
+ const files = /* @__PURE__ */ new Set();
290
+ for (const sourceFile of sourceFiles) {
291
+ for (const file of expandTraceIncludePattern(appDir, sourceFile)) {
292
+ files.add(file);
293
+ }
294
+ }
295
+ return [...files];
296
+ }
297
+ function expandTraceIncludePattern(appDir, sourceFile) {
298
+ const normalized = sourceFile.replace(/\\/g, "/").replace(/^\.\//, "");
299
+ if (normalized.endsWith("/**/*")) {
300
+ const dir = resolve(appDir, normalized.slice(0, -5));
301
+ return findFiles(dir);
302
+ }
303
+ if (normalized.endsWith("/*")) {
304
+ const dir = resolve(appDir, normalized.slice(0, -2));
305
+ return directFiles(dir);
306
+ }
307
+ const file = resolve(appDir, normalized);
308
+ return existsSync(file) && statSync(file).isFile() ? [file] : [];
309
+ }
310
+ function findTraceFiles(root) {
311
+ return findFiles(root).filter((file) => file.endsWith(".nft.json"));
312
+ }
313
+ function findFiles(root) {
314
+ if (!existsSync(root)) {
315
+ return [];
316
+ }
317
+ const stat = statSync(root);
318
+ if (stat.isFile()) {
319
+ return [root];
320
+ }
321
+ if (!stat.isDirectory()) {
322
+ return [];
323
+ }
324
+ const files = [];
325
+ for (const entry of readdirSync(root)) {
326
+ files.push(...findFiles(join(root, entry)));
327
+ }
328
+ return files;
329
+ }
330
+ function directFiles(root) {
331
+ if (!existsSync(root) || !statSync(root).isDirectory()) {
332
+ return [];
333
+ }
334
+ return readdirSync(root).map((entry) => join(root, entry)).filter((file) => statSync(file).isFile());
335
+ }
336
+ function routePathFromTraceFile(outputPath, traceFile) {
337
+ const relativeTrace = relative(outputPath, traceFile).replace(/\\/g, "/");
338
+ return routePathFromRelativeTrace(outputPath, relativeTrace);
339
+ }
340
+ function routePathFromTraceAsset(outputPath, assetName) {
341
+ return routePathFromRelativeTrace(outputPath, assetName.replace(/\\/g, "/"));
342
+ }
343
+ function routePathFromRelativeTrace(outputPath, relativeTrace) {
344
+ const normalizedTrace = relativeTrace.replace(/^(\.\.\/)+/, "");
345
+ if (relativeTrace.startsWith("app/")) {
346
+ return normalizeTraceRoute(relativeTrace.slice("app/".length));
347
+ }
348
+ if (relativeTrace.startsWith("pages/")) {
349
+ return normalizeTraceRoute(relativeTrace.slice("pages/".length));
350
+ }
351
+ if (normalizedTrace.startsWith("app/")) {
352
+ return normalizeTraceRoute(normalizedTrace.slice("app/".length));
353
+ }
354
+ if (normalizedTrace.startsWith("pages/")) {
355
+ return normalizeTraceRoute(normalizedTrace.slice("pages/".length));
356
+ }
357
+ if (basename(outputPath) === "app" || basename(outputPath) === "pages") {
358
+ return normalizeTraceRoute(relativeTrace);
359
+ }
360
+ return void 0;
361
+ }
362
+ function normalizeTraceRoute(relativeTrace) {
363
+ const withoutTraceSuffix = relativeTrace.replace(/\.js\.nft\.json$/, "");
364
+ const route = withoutTraceSuffix.replace(/\/route$/, "").replace(/\/page$/, "").replace(/\/index$/, "");
365
+ return `/${route}`;
366
+ }
367
+ function routeGlobMatches(routeGlob, routePath) {
368
+ if (routeGlob === "/*") {
369
+ return true;
370
+ }
371
+ return routeGlobToRegExp(routeGlob).test(routePath);
372
+ }
373
+ function routeGlobToRegExp(glob) {
374
+ let pattern = "";
375
+ for (let index = 0; index < glob.length; index += 1) {
376
+ const char = glob[index];
377
+ const nextChar = glob[index + 1];
378
+ if (char === "*" && nextChar === "*") {
379
+ pattern += ".*";
380
+ index += 1;
381
+ } else if (char === "*") {
382
+ pattern += "[^/]*";
383
+ } else {
384
+ pattern += escapeRegExp(char);
385
+ }
386
+ }
387
+ return new RegExp(`^${pattern}$`);
388
+ }
389
+ function escapeRegExp(value) {
390
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
391
+ }
392
+ function asRecord(value) {
393
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
394
+ }
395
+ function normalizeNonEmptyStrings(name, value) {
396
+ const values = Array.isArray(value) ? value : [value];
397
+ if (values.length === 0) {
398
+ throw new ConfigurationError(`${name} must contain at least one entry.`);
399
+ }
400
+ for (const entry of values) {
401
+ if (typeof entry !== "string" || entry.trim() === "") {
402
+ throw new ConfigurationError(`${name} entries must be non-empty strings.`);
403
+ }
404
+ }
405
+ return values;
406
+ }
407
+ function mergeStringArray(existing, values) {
408
+ const current = Array.isArray(existing) ? existing.filter((value) => typeof value === "string") : [];
409
+ return [.../* @__PURE__ */ new Set([...current, ...values])];
410
+ }
411
+ function mergeTracingIncludes(existing, routeGlobs, sourceFiles) {
412
+ const includes = { ...asRecord(existing) };
413
+ for (const routeGlob of routeGlobs) {
414
+ includes[routeGlob] = mergeStringArray(includes[routeGlob], sourceFiles);
415
+ }
416
+ return includes;
417
+ }
68
418
  var DEFAULT_DEPENDENCIES = {};
69
419
  function isServerAgentConfig(config) {
70
420
  return "server" in config && config.server !== void 0;
@@ -470,13 +820,31 @@ function getCallerFile() {
470
820
  }
471
821
  throw new Error("Could not determine source file");
472
822
  }
823
+ function isFrameworkBuildOutputPath(file) {
824
+ const normalized = file.replace(/\\/g, "/");
825
+ return normalized.includes("/.next/server/chunks/") || normalized.includes("/.next/server/app/") || normalized.includes("/.next/server/pages/");
826
+ }
827
+ function frameworkBuildOutputError(file) {
828
+ return new ConfigurationError(
829
+ `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.`
830
+ );
831
+ }
473
832
  function resolveSourceFile(sourceFile) {
474
- if (!sourceFile) return getCallerFile();
833
+ if (!sourceFile) {
834
+ const inferred = getCallerFile();
835
+ if (isFrameworkBuildOutputPath(inferred)) {
836
+ throw frameworkBuildOutputError(inferred);
837
+ }
838
+ return inferred;
839
+ }
475
840
  const normalized = normalizeStackFramePath(sourceFile);
476
841
  if (!normalized) {
477
842
  throw new ConfigurationError(`sourceFile could not be resolved: ${sourceFile}`);
478
843
  }
479
844
  const resolved = resolve(normalized);
845
+ if (isFrameworkBuildOutputPath(resolved)) {
846
+ throw frameworkBuildOutputError(resolved);
847
+ }
480
848
  if (!existsSync(resolved)) {
481
849
  throw new ConfigurationError(`sourceFile does not exist: ${resolved}`);
482
850
  }
@@ -558,7 +926,10 @@ var Agent = class {
558
926
  return this._serverRuntime?.connection.sandboxId ?? this._sandboxId;
559
927
  }
560
928
  get sandboxEnv() {
561
- return filterDefinedEnvs(this.envs);
929
+ return {
930
+ ...filterDefinedEnvs(this.envs),
931
+ [NECKBEARD_SANDBOX_RUNTIME_ENV]: "1"
932
+ };
562
933
  }
563
934
  async createSandboxHandle() {
564
935
  if (this.provider === "daytona") {
@@ -801,6 +1172,9 @@ var require = __neckbeard_createRequire(import.meta.url);
801
1172
  }
802
1173
  }
803
1174
  }
1175
+ export function resolveAgentSourceFile(_candidates, options = {}) {
1176
+ return options.sandboxSourceFile ?? process.cwd() + '/agent.mjs';
1177
+ }
804
1178
  `,
805
1179
  loader: "js"
806
1180
  }));
@@ -1097,5 +1471,7 @@ export {
1097
1471
  ExecutionError,
1098
1472
  NeckbeardError,
1099
1473
  ValidationError,
1100
- normalizeStackFramePath
1474
+ normalizeStackFramePath,
1475
+ resolveAgentSourceFile,
1476
+ withNeckbeardNextConfig
1101
1477
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-neckbeard",
3
- "version": "1.1.11",
3
+ "version": "1.1.12",
4
4
  "description": "Deploy AI agents to E2B and Daytona sandboxes",
5
5
  "type": "module",
6
6
  "exports": {
@@ -39,6 +39,7 @@
39
39
  "test:e2e": "npm run build && node --experimental-vm-modules ./node_modules/jest/bin/jest.js --config jest.e2e.config.mjs --runInBand",
40
40
  "test:e2e:e2b": "npm run build && node --experimental-vm-modules ./node_modules/jest/bin/jest.js --config jest.e2e.config.mjs --runInBand --testNamePattern=\"live E2B smoke tests\"",
41
41
  "test:e2e:daytona": "npm run build && node --experimental-vm-modules ./node_modules/jest/bin/jest.js --config jest.e2e.config.mjs --runInBand --testNamePattern=\"live Daytona smoke tests\"",
42
+ "test:compat:next": "npm run build && node scripts/run-next-compat-test.mjs",
42
43
  "test:cjs": "npm run build && node --experimental-vm-modules ./node_modules/jest/bin/jest.js --config jest.build.config.mjs",
43
44
  "typecheck": "tsc --noEmit -p tsconfig.test.json",
44
45
  "prepare": "npm run build"