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/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;
|
|
@@ -31,6 +33,7 @@ var SERVER_HEALTH_TIMEOUT_MS = 12e4;
|
|
|
31
33
|
var SERVER_RECONNECT_HEALTH_TIMEOUT_MS = 3e3;
|
|
32
34
|
var SERVER_HEALTH_POLL_INTERVAL_MS = 1e3;
|
|
33
35
|
var NATIVE_EXT_RE = /\.(node|wasm|gyp|c|cc|cpp|cxx|h|hpp|hxx)$/i;
|
|
36
|
+
var TRACEABLE_SOURCE_EXT_RE = /\.(cjs|cts|js|jsx|mjs|mts|ts|tsx)$/i;
|
|
34
37
|
var E2B_SANDBOX_HOME = "/home/user";
|
|
35
38
|
var NeckbeardError = class extends Error {
|
|
36
39
|
constructor(message) {
|
|
@@ -65,6 +68,462 @@ var ConfigurationError = class extends NeckbeardError {
|
|
|
65
68
|
this.name = "ConfigurationError";
|
|
66
69
|
}
|
|
67
70
|
};
|
|
71
|
+
function resolveAgentSourceFile(candidates, options = {}) {
|
|
72
|
+
const normalizedCandidates = normalizeNonEmptyStrings("candidates", candidates);
|
|
73
|
+
const sourceFile = normalizedCandidates.find((candidate) => existsSync(candidate));
|
|
74
|
+
if (sourceFile) {
|
|
75
|
+
return sourceFile;
|
|
76
|
+
}
|
|
77
|
+
if (process.env[NECKBEARD_SANDBOX_RUNTIME_ENV] === "1") {
|
|
78
|
+
const sandboxSourceFile = options.sandboxSourceFile ?? resolve(process.cwd(), "agent.mjs");
|
|
79
|
+
if (existsSync(sandboxSourceFile)) {
|
|
80
|
+
return sandboxSourceFile;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
throw new ConfigurationError(
|
|
84
|
+
options.errorMessage ?? `Could not resolve agent source file. Checked: ${candidates.join(", ")}`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
function withNeckbeardNextConfig(nextConfig, options) {
|
|
88
|
+
const sourceFiles = normalizeNonEmptyStrings("sourceFiles", options.sourceFiles);
|
|
89
|
+
const routeGlobs = normalizeNonEmptyStrings("routeGlob", options.routeGlob ?? "/*");
|
|
90
|
+
const traceSourceDependencies = options.traceSourceDependencies ?? true;
|
|
91
|
+
const traceIncludeFiles = traceIncludeFilesForConfig(
|
|
92
|
+
process.cwd(),
|
|
93
|
+
sourceFiles,
|
|
94
|
+
traceSourceDependencies
|
|
95
|
+
);
|
|
96
|
+
const experimental = asRecord(nextConfig.experimental);
|
|
97
|
+
const useLegacyExperimental = options.legacyExperimental ?? ("serverComponentsExternalPackages" in experimental || "outputFileTracingIncludes" in experimental || "outputFileTracingRoot" in experimental);
|
|
98
|
+
if (useLegacyExperimental) {
|
|
99
|
+
const nextExperimental = {
|
|
100
|
+
...experimental,
|
|
101
|
+
serverComponentsExternalPackages: mergeStringArray(
|
|
102
|
+
experimental.serverComponentsExternalPackages,
|
|
103
|
+
[NECKBEARD_PACKAGE_NAME]
|
|
104
|
+
),
|
|
105
|
+
outputFileTracingIncludes: mergeTracingIncludes(
|
|
106
|
+
experimental.outputFileTracingIncludes,
|
|
107
|
+
routeGlobs,
|
|
108
|
+
traceIncludeFiles
|
|
109
|
+
)
|
|
110
|
+
};
|
|
111
|
+
if (options.outputFileTracingRoot !== void 0) {
|
|
112
|
+
nextExperimental.outputFileTracingRoot = options.outputFileTracingRoot;
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
...nextConfig,
|
|
116
|
+
experimental: nextExperimental,
|
|
117
|
+
webpack: withNextTraceIncludeWebpack(
|
|
118
|
+
nextConfig.webpack,
|
|
119
|
+
sourceFiles,
|
|
120
|
+
routeGlobs,
|
|
121
|
+
traceSourceDependencies
|
|
122
|
+
)
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const result = {
|
|
126
|
+
...nextConfig,
|
|
127
|
+
serverExternalPackages: mergeStringArray(nextConfig.serverExternalPackages, [
|
|
128
|
+
NECKBEARD_PACKAGE_NAME
|
|
129
|
+
]),
|
|
130
|
+
outputFileTracingIncludes: mergeTracingIncludes(
|
|
131
|
+
nextConfig.outputFileTracingIncludes,
|
|
132
|
+
routeGlobs,
|
|
133
|
+
traceIncludeFiles
|
|
134
|
+
)
|
|
135
|
+
};
|
|
136
|
+
if (nextConfig.webpack) {
|
|
137
|
+
result.webpack = withNextTraceIncludeWebpack(
|
|
138
|
+
nextConfig.webpack,
|
|
139
|
+
sourceFiles,
|
|
140
|
+
routeGlobs,
|
|
141
|
+
traceSourceDependencies
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
if (options.outputFileTracingRoot !== void 0) {
|
|
145
|
+
result.outputFileTracingRoot = options.outputFileTracingRoot;
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
var NextTraceIncludePlugin = class {
|
|
150
|
+
constructor(appDir, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
151
|
+
this.appDir = appDir;
|
|
152
|
+
this.sourceFiles = sourceFiles;
|
|
153
|
+
this.routeGlobs = routeGlobs;
|
|
154
|
+
this.traceSourceDependencies = traceSourceDependencies;
|
|
155
|
+
}
|
|
156
|
+
apply(compiler) {
|
|
157
|
+
const compilationHook = compiler.hooks?.compilation;
|
|
158
|
+
if (typeof compilationHook?.tap === "function") {
|
|
159
|
+
compilationHook.tap("NeckbeardNextTraceIncludePlugin", (compilation) => {
|
|
160
|
+
const processAssets = compilation.hooks?.processAssets;
|
|
161
|
+
if (typeof processAssets?.tap !== "function") {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
processAssets.tap({
|
|
165
|
+
name: "NeckbeardNextTraceIncludePlugin",
|
|
166
|
+
stage: compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_REPORT ?? 5e3
|
|
167
|
+
}, (assets) => {
|
|
168
|
+
appendIncludesToTraceAssets({
|
|
169
|
+
appDir: this.appDir,
|
|
170
|
+
assets,
|
|
171
|
+
outputPath: compilation.outputOptions?.path ?? compiler.outputPath ?? "",
|
|
172
|
+
rawSource: compiler.webpack?.sources?.RawSource,
|
|
173
|
+
routeGlobs: this.routeGlobs,
|
|
174
|
+
sourceFiles: this.sourceFiles,
|
|
175
|
+
traceSourceDependencies: this.traceSourceDependencies,
|
|
176
|
+
updateAsset: compilation.updateAsset?.bind(compilation)
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
const afterEmit = compiler.hooks?.afterEmit;
|
|
182
|
+
const done = compiler.hooks?.done;
|
|
183
|
+
if (typeof afterEmit?.tap !== "function" && typeof done?.tap !== "function") {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (!compiler.outputPath) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const appendIncludes = () => {
|
|
190
|
+
appendIncludesToTraceFiles(
|
|
191
|
+
compiler.outputPath ?? "",
|
|
192
|
+
this.appDir,
|
|
193
|
+
this.sourceFiles,
|
|
194
|
+
this.routeGlobs,
|
|
195
|
+
this.traceSourceDependencies
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
if (typeof afterEmit?.tap === "function") {
|
|
199
|
+
afterEmit.tap("NeckbeardNextTraceIncludePlugin", appendIncludes);
|
|
200
|
+
}
|
|
201
|
+
if (typeof done?.tap === "function") {
|
|
202
|
+
done.tap("NeckbeardNextTraceIncludePlugin", appendIncludes);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
function appendIncludesToTraceAssets({
|
|
207
|
+
appDir,
|
|
208
|
+
assets,
|
|
209
|
+
outputPath,
|
|
210
|
+
rawSource,
|
|
211
|
+
routeGlobs,
|
|
212
|
+
sourceFiles,
|
|
213
|
+
traceSourceDependencies,
|
|
214
|
+
updateAsset
|
|
215
|
+
}) {
|
|
216
|
+
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies);
|
|
217
|
+
if (includedFiles.length === 0) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
for (const [assetName, asset] of Object.entries(assets)) {
|
|
221
|
+
if (!assetName.endsWith(".nft.json")) {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const routePath = routePathFromTraceAsset(outputPath, assetName);
|
|
225
|
+
if (!routePath || !routeGlobs.some((routeGlob) => routeGlobMatches(routeGlob, routePath))) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const traceDir = dirname(join(outputPath, assetName));
|
|
229
|
+
const nextSource = traceWithIncludedFiles(String(asset.source()), traceDir, includedFiles);
|
|
230
|
+
if (rawSource && updateAsset) {
|
|
231
|
+
updateAsset(assetName, new rawSource(nextSource));
|
|
232
|
+
} else {
|
|
233
|
+
assets[assetName] = {
|
|
234
|
+
source: () => nextSource,
|
|
235
|
+
size: () => Buffer.byteLength(nextSource)
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
241
|
+
return (config, context) => {
|
|
242
|
+
const nextConfig = originalWebpack ? originalWebpack(config, context) : config;
|
|
243
|
+
if (!context.isServer || context.dev) {
|
|
244
|
+
return nextConfig;
|
|
245
|
+
}
|
|
246
|
+
nextConfig.externals = withNeckbeardExternal(nextConfig.externals);
|
|
247
|
+
nextConfig.plugins = [
|
|
248
|
+
...Array.isArray(nextConfig.plugins) ? nextConfig.plugins : [],
|
|
249
|
+
new NextTraceIncludePlugin(
|
|
250
|
+
context.dir ?? process.cwd(),
|
|
251
|
+
sourceFiles,
|
|
252
|
+
routeGlobs,
|
|
253
|
+
traceSourceDependencies
|
|
254
|
+
)
|
|
255
|
+
];
|
|
256
|
+
return nextConfig;
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function withNeckbeardExternal(externals) {
|
|
260
|
+
return [
|
|
261
|
+
neckbeardExternal,
|
|
262
|
+
...Array.isArray(externals) ? externals : externals ? [externals] : []
|
|
263
|
+
];
|
|
264
|
+
}
|
|
265
|
+
function neckbeardExternal(contextOrRequest, requestOrCallback) {
|
|
266
|
+
const legacyCallback = arguments[2];
|
|
267
|
+
const request = typeof requestOrCallback === "string" ? requestOrCallback : typeof contextOrRequest === "string" ? contextOrRequest : contextOrRequest.request;
|
|
268
|
+
const callback = typeof requestOrCallback === "function" ? requestOrCallback : legacyCallback;
|
|
269
|
+
if (request === NECKBEARD_PACKAGE_NAME) {
|
|
270
|
+
const result = `commonjs ${NECKBEARD_PACKAGE_NAME}`;
|
|
271
|
+
if (callback) {
|
|
272
|
+
callback(null, result);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
if (callback) {
|
|
278
|
+
callback();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function appendIncludesToTraceFiles(outputPath, appDir, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
282
|
+
if (!outputPath || !existsSync(outputPath)) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies);
|
|
286
|
+
if (includedFiles.length === 0) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
for (const traceFile of findTraceFiles(outputPath)) {
|
|
290
|
+
const routePath = routePathFromTraceFile(outputPath, traceFile);
|
|
291
|
+
if (!routePath || !routeGlobs.some((routeGlob) => routeGlobMatches(routeGlob, routePath))) {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
appendFilesToTrace(traceFile, includedFiles);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function appendFilesToTrace(traceFile, includedFiles) {
|
|
298
|
+
const nextSource = traceWithIncludedFiles(
|
|
299
|
+
readFileSync(traceFile, "utf8"),
|
|
300
|
+
dirname(traceFile),
|
|
301
|
+
includedFiles
|
|
302
|
+
);
|
|
303
|
+
writeFileSync(traceFile, nextSource);
|
|
304
|
+
}
|
|
305
|
+
function traceWithIncludedFiles(traceSource, traceDir, includedFiles) {
|
|
306
|
+
const trace = JSON.parse(traceSource);
|
|
307
|
+
const files = Array.isArray(trace.files) ? trace.files.filter((file) => typeof file === "string") : [];
|
|
308
|
+
const nextFiles = new Set(files);
|
|
309
|
+
for (const includedFile of includedFiles) {
|
|
310
|
+
nextFiles.add(relative(traceDir, includedFile).replace(/\\/g, "/"));
|
|
311
|
+
}
|
|
312
|
+
return JSON.stringify({
|
|
313
|
+
version: trace.version ?? 1,
|
|
314
|
+
files: [...nextFiles]
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
function expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies = true) {
|
|
318
|
+
const files = /* @__PURE__ */ new Set();
|
|
319
|
+
for (const sourceFile of sourceFiles) {
|
|
320
|
+
for (const file of expandTraceIncludePattern(appDir, sourceFile)) {
|
|
321
|
+
files.add(file);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (traceSourceDependencies) {
|
|
325
|
+
for (const file of traceSourceDependencyFiles(appDir, [...files])) {
|
|
326
|
+
files.add(file);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return [...files];
|
|
330
|
+
}
|
|
331
|
+
function traceIncludeFilesForConfig(appDir, sourceFiles, traceSourceDependencies) {
|
|
332
|
+
const tracedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies).map((file) => toNextTraceIncludePath(appDir, file));
|
|
333
|
+
return mergeStringArray(sourceFiles, tracedFiles);
|
|
334
|
+
}
|
|
335
|
+
function toNextTraceIncludePath(appDir, file) {
|
|
336
|
+
const relativePath = relative(appDir, file).replace(/\\/g, "/");
|
|
337
|
+
if (relativePath.startsWith("..")) {
|
|
338
|
+
return relativePath;
|
|
339
|
+
}
|
|
340
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
341
|
+
}
|
|
342
|
+
function expandTraceIncludePattern(appDir, sourceFile) {
|
|
343
|
+
const normalized = sourceFile.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
344
|
+
if (normalized.endsWith("/**/*")) {
|
|
345
|
+
const dir = resolve(appDir, normalized.slice(0, -5));
|
|
346
|
+
return findFiles(dir);
|
|
347
|
+
}
|
|
348
|
+
if (normalized.endsWith("/*")) {
|
|
349
|
+
const dir = resolve(appDir, normalized.slice(0, -2));
|
|
350
|
+
return directFiles(dir);
|
|
351
|
+
}
|
|
352
|
+
const file = resolve(appDir, normalized);
|
|
353
|
+
return existsSync(file) && statSync(file).isFile() ? [file] : [];
|
|
354
|
+
}
|
|
355
|
+
function traceSourceDependencyFiles(appDir, sourceFiles) {
|
|
356
|
+
const entryPoints = sourceFiles.filter((file) => TRACEABLE_SOURCE_EXT_RE.test(file));
|
|
357
|
+
if (entryPoints.length === 0) {
|
|
358
|
+
return [];
|
|
359
|
+
}
|
|
360
|
+
try {
|
|
361
|
+
const esbuild = getEsbuildSync();
|
|
362
|
+
const result = esbuild.buildSync({
|
|
363
|
+
absWorkingDir: appDir,
|
|
364
|
+
bundle: true,
|
|
365
|
+
entryPoints,
|
|
366
|
+
external: [...DEFAULT_EXTERNALS, NECKBEARD_PACKAGE_NAME],
|
|
367
|
+
format: "esm",
|
|
368
|
+
logLevel: "silent",
|
|
369
|
+
metafile: true,
|
|
370
|
+
platform: "node",
|
|
371
|
+
preserveSymlinks: true,
|
|
372
|
+
target: NODE_TARGET,
|
|
373
|
+
treeShaking: false,
|
|
374
|
+
write: false
|
|
375
|
+
});
|
|
376
|
+
const metafile = result.metafile;
|
|
377
|
+
if (!metafile) {
|
|
378
|
+
return [];
|
|
379
|
+
}
|
|
380
|
+
const files = /* @__PURE__ */ new Set();
|
|
381
|
+
const addFile = (file) => {
|
|
382
|
+
if (file && existsSync(file) && statSync(file).isFile()) {
|
|
383
|
+
files.add(file);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
for (const [inputPath, input] of Object.entries(metafile.inputs)) {
|
|
387
|
+
const absoluteInput = resolveMetafileInput(appDir, inputPath);
|
|
388
|
+
addFile(absoluteInput);
|
|
389
|
+
for (const importRecord of input.imports ?? []) {
|
|
390
|
+
const importPath = importRecord.original ?? importRecord.path;
|
|
391
|
+
if (!isBareModuleImport(importPath) || isBuiltinModule(importPath)) {
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (importPath === NECKBEARD_PACKAGE_NAME) {
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
const resolvedImportPath = importRecord.external ? void 0 : resolveMetafileInput(appDir, importRecord.path);
|
|
398
|
+
const packageInfo = resolvedImportPath ? resolvePackageInfoFromResolvedPath(importPath, resolvedImportPath) : resolvePackageInfoSync(importPath, dirname(absoluteInput));
|
|
399
|
+
if (!packageInfo) {
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
addFile(packageInfo.resolvedPath);
|
|
403
|
+
addFile(join(packageInfo.root, "package.json"));
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return [...files];
|
|
407
|
+
} catch (error) {
|
|
408
|
+
throw new ConfigurationError(
|
|
409
|
+
`Failed to trace Neckbeard source dependencies for Next.js output tracing: ${errorMessage(error)}`
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function getEsbuildSync() {
|
|
414
|
+
return packageRequire("esbuild");
|
|
415
|
+
}
|
|
416
|
+
function resolveMetafileInput(absWorkingDir, inputPath) {
|
|
417
|
+
return resolve(absWorkingDir, inputPath);
|
|
418
|
+
}
|
|
419
|
+
function findTraceFiles(root) {
|
|
420
|
+
return findFiles(root).filter((file) => file.endsWith(".nft.json"));
|
|
421
|
+
}
|
|
422
|
+
function findFiles(root) {
|
|
423
|
+
if (!existsSync(root)) {
|
|
424
|
+
return [];
|
|
425
|
+
}
|
|
426
|
+
const stat = statSync(root);
|
|
427
|
+
if (stat.isFile()) {
|
|
428
|
+
return [root];
|
|
429
|
+
}
|
|
430
|
+
if (!stat.isDirectory()) {
|
|
431
|
+
return [];
|
|
432
|
+
}
|
|
433
|
+
const files = [];
|
|
434
|
+
for (const entry of readdirSync(root)) {
|
|
435
|
+
files.push(...findFiles(join(root, entry)));
|
|
436
|
+
}
|
|
437
|
+
return files;
|
|
438
|
+
}
|
|
439
|
+
function directFiles(root) {
|
|
440
|
+
if (!existsSync(root) || !statSync(root).isDirectory()) {
|
|
441
|
+
return [];
|
|
442
|
+
}
|
|
443
|
+
return readdirSync(root).map((entry) => join(root, entry)).filter((file) => statSync(file).isFile());
|
|
444
|
+
}
|
|
445
|
+
function routePathFromTraceFile(outputPath, traceFile) {
|
|
446
|
+
const relativeTrace = relative(outputPath, traceFile).replace(/\\/g, "/");
|
|
447
|
+
return routePathFromRelativeTrace(outputPath, relativeTrace);
|
|
448
|
+
}
|
|
449
|
+
function routePathFromTraceAsset(outputPath, assetName) {
|
|
450
|
+
return routePathFromRelativeTrace(outputPath, assetName.replace(/\\/g, "/"));
|
|
451
|
+
}
|
|
452
|
+
function routePathFromRelativeTrace(outputPath, relativeTrace) {
|
|
453
|
+
const normalizedTrace = relativeTrace.replace(/^(\.\.\/)+/, "");
|
|
454
|
+
if (relativeTrace.startsWith("app/")) {
|
|
455
|
+
return normalizeTraceRoute(relativeTrace.slice("app/".length));
|
|
456
|
+
}
|
|
457
|
+
if (relativeTrace.startsWith("pages/")) {
|
|
458
|
+
return normalizeTraceRoute(relativeTrace.slice("pages/".length));
|
|
459
|
+
}
|
|
460
|
+
if (normalizedTrace.startsWith("app/")) {
|
|
461
|
+
return normalizeTraceRoute(normalizedTrace.slice("app/".length));
|
|
462
|
+
}
|
|
463
|
+
if (normalizedTrace.startsWith("pages/")) {
|
|
464
|
+
return normalizeTraceRoute(normalizedTrace.slice("pages/".length));
|
|
465
|
+
}
|
|
466
|
+
if (basename(outputPath) === "app" || basename(outputPath) === "pages") {
|
|
467
|
+
return normalizeTraceRoute(relativeTrace);
|
|
468
|
+
}
|
|
469
|
+
return void 0;
|
|
470
|
+
}
|
|
471
|
+
function normalizeTraceRoute(relativeTrace) {
|
|
472
|
+
const withoutTraceSuffix = relativeTrace.replace(/\.js\.nft\.json$/, "");
|
|
473
|
+
const route = withoutTraceSuffix.replace(/\/route$/, "").replace(/\/page$/, "").replace(/\/index$/, "");
|
|
474
|
+
return `/${route}`;
|
|
475
|
+
}
|
|
476
|
+
function routeGlobMatches(routeGlob, routePath) {
|
|
477
|
+
if (routeGlob === "/*") {
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
return routeGlobToRegExp(routeGlob).test(routePath);
|
|
481
|
+
}
|
|
482
|
+
function routeGlobToRegExp(glob) {
|
|
483
|
+
let pattern = "";
|
|
484
|
+
for (let index = 0; index < glob.length; index += 1) {
|
|
485
|
+
const char = glob[index];
|
|
486
|
+
const nextChar = glob[index + 1];
|
|
487
|
+
if (char === "*" && nextChar === "*") {
|
|
488
|
+
pattern += ".*";
|
|
489
|
+
index += 1;
|
|
490
|
+
} else if (char === "*") {
|
|
491
|
+
pattern += "[^/]*";
|
|
492
|
+
} else {
|
|
493
|
+
pattern += escapeRegExp(char);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return new RegExp(`^${pattern}$`);
|
|
497
|
+
}
|
|
498
|
+
function escapeRegExp(value) {
|
|
499
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
500
|
+
}
|
|
501
|
+
function asRecord(value) {
|
|
502
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
503
|
+
}
|
|
504
|
+
function normalizeNonEmptyStrings(name, value) {
|
|
505
|
+
const values = Array.isArray(value) ? value : [value];
|
|
506
|
+
if (values.length === 0) {
|
|
507
|
+
throw new ConfigurationError(`${name} must contain at least one entry.`);
|
|
508
|
+
}
|
|
509
|
+
for (const entry of values) {
|
|
510
|
+
if (typeof entry !== "string" || entry.trim() === "") {
|
|
511
|
+
throw new ConfigurationError(`${name} entries must be non-empty strings.`);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return values;
|
|
515
|
+
}
|
|
516
|
+
function mergeStringArray(existing, values) {
|
|
517
|
+
const current = Array.isArray(existing) ? existing.filter((value) => typeof value === "string") : [];
|
|
518
|
+
return [.../* @__PURE__ */ new Set([...current, ...values])];
|
|
519
|
+
}
|
|
520
|
+
function mergeTracingIncludes(existing, routeGlobs, sourceFiles) {
|
|
521
|
+
const includes = { ...asRecord(existing) };
|
|
522
|
+
for (const routeGlob of routeGlobs) {
|
|
523
|
+
includes[routeGlob] = mergeStringArray(includes[routeGlob], sourceFiles);
|
|
524
|
+
}
|
|
525
|
+
return includes;
|
|
526
|
+
}
|
|
68
527
|
var DEFAULT_DEPENDENCIES = {};
|
|
69
528
|
function isServerAgentConfig(config) {
|
|
70
529
|
return "server" in config && config.server !== void 0;
|
|
@@ -176,10 +635,28 @@ function shellEscape(str) {
|
|
|
176
635
|
return `'${str.replace(/'/g, "'\\''")}'`;
|
|
177
636
|
}
|
|
178
637
|
var require2 = createRequire(join(process.cwd(), "__agent_neckbeard__.cjs"));
|
|
638
|
+
var packageRequire = createPackageRequire();
|
|
639
|
+
function createPackageRequire() {
|
|
640
|
+
const cwdPackageJsonPath = join(process.cwd(), "package.json");
|
|
641
|
+
try {
|
|
642
|
+
if (existsSync(cwdPackageJsonPath) && readPackageJson(cwdPackageJsonPath).name === NECKBEARD_PACKAGE_NAME) {
|
|
643
|
+
return createRequire(cwdPackageJsonPath);
|
|
644
|
+
}
|
|
645
|
+
} catch {
|
|
646
|
+
}
|
|
647
|
+
try {
|
|
648
|
+
return createRequire(require2.resolve(NECKBEARD_PACKAGE_NAME));
|
|
649
|
+
} catch {
|
|
650
|
+
return require2;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
179
653
|
function isBareModuleImport(path) {
|
|
180
654
|
const excludes = [".", "/", "~", "file:", "data:"];
|
|
181
655
|
return !excludes.some((exclude) => path.startsWith(exclude));
|
|
182
656
|
}
|
|
657
|
+
function isBuiltinModule(path) {
|
|
658
|
+
return builtinModules.includes(path.replace("node:", ""));
|
|
659
|
+
}
|
|
183
660
|
function packageNameForImportPath(importPath) {
|
|
184
661
|
if (importPath.startsWith("@")) {
|
|
185
662
|
return importPath.split("/").slice(0, 2).join("/");
|
|
@@ -194,6 +671,9 @@ function matchesExternal(matchers, pkgName) {
|
|
|
194
671
|
return matchers.some((re) => re.test(pkgName));
|
|
195
672
|
}
|
|
196
673
|
async function resolvePackageInfo(importPath, resolveDir) {
|
|
674
|
+
return resolvePackageInfoSync(importPath, resolveDir);
|
|
675
|
+
}
|
|
676
|
+
function resolvePackageInfoSync(importPath, resolveDir) {
|
|
197
677
|
try {
|
|
198
678
|
const resolvedPath = require2.resolve(importPath, { paths: [resolveDir] });
|
|
199
679
|
const packageName = packageNameForImportPath(importPath);
|
|
@@ -227,6 +707,29 @@ async function resolvePackageInfo(importPath, resolveDir) {
|
|
|
227
707
|
return null;
|
|
228
708
|
}
|
|
229
709
|
}
|
|
710
|
+
function resolvePackageInfoFromResolvedPath(importPath, resolvedPath) {
|
|
711
|
+
const packageName = packageNameForImportPath(importPath);
|
|
712
|
+
let root = dirname(resolvedPath);
|
|
713
|
+
while (true) {
|
|
714
|
+
const packageJsonPath = join(root, "package.json");
|
|
715
|
+
if (existsSync(packageJsonPath)) {
|
|
716
|
+
const packageJson = readPackageJson(packageJsonPath);
|
|
717
|
+
if (packageJson.name === packageName) {
|
|
718
|
+
if (!packageJson.version) return null;
|
|
719
|
+
return {
|
|
720
|
+
name: packageJson.name,
|
|
721
|
+
version: packageJson.version,
|
|
722
|
+
root,
|
|
723
|
+
resolvedPath,
|
|
724
|
+
packageJson
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
const parent = dirname(root);
|
|
729
|
+
if (parent === root) return null;
|
|
730
|
+
root = parent;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
230
733
|
function hasNativeHints(info) {
|
|
231
734
|
const files = Array.isArray(info.packageJson.files) ? info.packageJson.files : [];
|
|
232
735
|
const fields = [info.packageJson.main, info.packageJson.module, info.packageJson.browser].filter(
|
|
@@ -301,6 +804,9 @@ function timeoutMsToSeconds(timeoutMs) {
|
|
|
301
804
|
function asError(error) {
|
|
302
805
|
return error instanceof Error ? error : new Error(String(error));
|
|
303
806
|
}
|
|
807
|
+
function errorMessage(error) {
|
|
808
|
+
return error instanceof Error ? error.message : String(error);
|
|
809
|
+
}
|
|
304
810
|
async function resolveDaytonaPaths(sandbox) {
|
|
305
811
|
const workDir = await sandbox.getWorkDir() ?? await sandbox.getUserHomeDir();
|
|
306
812
|
const homeDir = await sandbox.getUserHomeDir() ?? workDir;
|
|
@@ -332,11 +838,11 @@ async function runE2bCommand(sandbox, cmd, options) {
|
|
|
332
838
|
};
|
|
333
839
|
} catch (error) {
|
|
334
840
|
const exitCode = error.exitCode ?? 1;
|
|
335
|
-
const
|
|
841
|
+
const errorMessage2 = error instanceof Error ? error.message : String(error);
|
|
336
842
|
return {
|
|
337
843
|
exitCode,
|
|
338
844
|
stdout,
|
|
339
|
-
stderr: stderr ||
|
|
845
|
+
stderr: stderr || errorMessage2
|
|
340
846
|
};
|
|
341
847
|
}
|
|
342
848
|
}
|
|
@@ -470,13 +976,31 @@ function getCallerFile() {
|
|
|
470
976
|
}
|
|
471
977
|
throw new Error("Could not determine source file");
|
|
472
978
|
}
|
|
979
|
+
function isFrameworkBuildOutputPath(file) {
|
|
980
|
+
const normalized = file.replace(/\\/g, "/");
|
|
981
|
+
return normalized.includes("/.next/server/chunks/") || normalized.includes("/.next/server/app/") || normalized.includes("/.next/server/pages/");
|
|
982
|
+
}
|
|
983
|
+
function frameworkBuildOutputError(file) {
|
|
984
|
+
return new ConfigurationError(
|
|
985
|
+
`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.`
|
|
986
|
+
);
|
|
987
|
+
}
|
|
473
988
|
function resolveSourceFile(sourceFile) {
|
|
474
|
-
if (!sourceFile)
|
|
989
|
+
if (!sourceFile) {
|
|
990
|
+
const inferred = getCallerFile();
|
|
991
|
+
if (isFrameworkBuildOutputPath(inferred)) {
|
|
992
|
+
throw frameworkBuildOutputError(inferred);
|
|
993
|
+
}
|
|
994
|
+
return inferred;
|
|
995
|
+
}
|
|
475
996
|
const normalized = normalizeStackFramePath(sourceFile);
|
|
476
997
|
if (!normalized) {
|
|
477
998
|
throw new ConfigurationError(`sourceFile could not be resolved: ${sourceFile}`);
|
|
478
999
|
}
|
|
479
1000
|
const resolved = resolve(normalized);
|
|
1001
|
+
if (isFrameworkBuildOutputPath(resolved)) {
|
|
1002
|
+
throw frameworkBuildOutputError(resolved);
|
|
1003
|
+
}
|
|
480
1004
|
if (!existsSync(resolved)) {
|
|
481
1005
|
throw new ConfigurationError(`sourceFile does not exist: ${resolved}`);
|
|
482
1006
|
}
|
|
@@ -558,7 +1082,10 @@ var Agent = class {
|
|
|
558
1082
|
return this._serverRuntime?.connection.sandboxId ?? this._sandboxId;
|
|
559
1083
|
}
|
|
560
1084
|
get sandboxEnv() {
|
|
561
|
-
return
|
|
1085
|
+
return {
|
|
1086
|
+
...filterDefinedEnvs(this.envs),
|
|
1087
|
+
[NECKBEARD_SANDBOX_RUNTIME_ENV]: "1"
|
|
1088
|
+
};
|
|
562
1089
|
}
|
|
563
1090
|
async createSandboxHandle() {
|
|
564
1091
|
if (this.provider === "daytona") {
|
|
@@ -801,6 +1328,9 @@ var require = __neckbeard_createRequire(import.meta.url);
|
|
|
801
1328
|
}
|
|
802
1329
|
}
|
|
803
1330
|
}
|
|
1331
|
+
export function resolveAgentSourceFile(_candidates, options = {}) {
|
|
1332
|
+
return options.sandboxSourceFile ?? process.cwd() + '/agent.mjs';
|
|
1333
|
+
}
|
|
804
1334
|
`,
|
|
805
1335
|
loader: "js"
|
|
806
1336
|
}));
|
|
@@ -1097,5 +1627,7 @@ export {
|
|
|
1097
1627
|
ExecutionError,
|
|
1098
1628
|
NeckbeardError,
|
|
1099
1629
|
ValidationError,
|
|
1100
|
-
normalizeStackFramePath
|
|
1630
|
+
normalizeStackFramePath,
|
|
1631
|
+
resolveAgentSourceFile,
|
|
1632
|
+
withNeckbeardNextConfig
|
|
1101
1633
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-neckbeard",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.13",
|
|
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"
|