@agent-native/core 0.75.2 → 0.75.5
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/corpus/README.md +1 -1
- package/corpus/core/CHANGELOG.md +86 -0
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/agent/durable-background.ts +57 -25
- package/corpus/core/src/agent/production-agent.ts +16 -13
- package/corpus/core/src/cli/skills.ts +22 -4
- package/corpus/core/src/cli/sync-builder-starter-manifest.ts +36 -12
- package/corpus/core/src/deploy/build.ts +79 -57
- package/corpus/core/src/deploy/workspace-deploy.ts +62 -30
- package/corpus/core/src/server/self-dispatch.ts +29 -2
- package/corpus/templates/clips/changelog/2026-06-24-chrome-extension-setup-now-shows-a-clear-all-done-confirmati.md +6 -0
- package/corpus/templates/clips/chrome-extension/src/permission.html +60 -0
- package/corpus/templates/clips/chrome-extension/src/permission.ts +28 -15
- package/corpus/templates/content/app/components/editor/DocumentProperties.tsx +6 -20
- package/corpus/templates/plan/.agents/skills/visual-plan/references/wireframe.md +22 -4
- package/corpus/templates/plan/.agents/skills/visual-recap/references/wireframe.md +22 -4
- package/corpus/templates/plan/app/components/plan/DocumentArea.tsx +45 -33
- package/corpus/templates/plan/changelog/2026-06-24-invalid-generated-recap-blocks-now-show-a-clear-warning-with.md +6 -0
- package/corpus/templates/plan/server/plan-content.ts +53 -3
- package/dist/agent/durable-background.d.ts +33 -24
- package/dist/agent/durable-background.d.ts.map +1 -1
- package/dist/agent/durable-background.js +56 -25
- package/dist/agent/durable-background.js.map +1 -1
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +16 -13
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/cli/skills.d.ts +1 -1
- package/dist/cli/skills.d.ts.map +1 -1
- package/dist/cli/skills.js +22 -4
- package/dist/cli/skills.js.map +1 -1
- package/dist/cli/sync-builder-starter-manifest.d.ts.map +1 -1
- package/dist/cli/sync-builder-starter-manifest.js +21 -10
- package/dist/cli/sync-builder-starter-manifest.js.map +1 -1
- package/dist/deploy/build.d.ts +53 -33
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +79 -57
- package/dist/deploy/build.js.map +1 -1
- package/dist/deploy/workspace-deploy.js +62 -30
- package/dist/deploy/workspace-deploy.js.map +1 -1
- package/dist/server/self-dispatch.d.ts +0 -10
- package/dist/server/self-dispatch.d.ts.map +1 -1
- package/dist/server/self-dispatch.js +27 -2
- package/dist/server/self-dispatch.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-builder-starter-manifest.d.ts","sourceRoot":"","sources":["../../src/cli/sync-builder-starter-manifest.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,gBAAgB,iCAAiC,CAAC;AAC/D,eAAO,MAAM,aAAa,SAAS,CAAC;AAEpC,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE3C,wBAAgB,mBAAmB,CAAC,QAAQ,SAAgB,GAAG,MAAM,CAmBpE;AAED,wBAAgB,8BAA8B,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG;IACjE,WAAW,EAAE,WAAW,CAAC;IACzB,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC,CAwBA;
|
|
1
|
+
{"version":3,"file":"sync-builder-starter-manifest.d.ts","sourceRoot":"","sources":["../../src/cli/sync-builder-starter-manifest.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,gBAAgB,iCAAiC,CAAC;AAC/D,eAAO,MAAM,aAAa,SAAS,CAAC;AAEpC,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE3C,wBAAgB,mBAAmB,CAAC,QAAQ,SAAgB,GAAG,MAAM,CAmBpE;AAED,wBAAgB,8BAA8B,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG;IACjE,WAAW,EAAE,WAAW,CAAC;IACzB,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC,CAwBA;AAsBD,wBAAgB,oBAAoB,CAClC,kBAAkB,EAAE,WAAW,EAC/B,oBAAoB,EAAE,WAAW,GAChC,WAAW,CAgCb;AAED,wBAAgB,wBAAwB,CACtC,iBAAiB,EAAE,MAAM,GAAG,IAAI,EAChC,kBAAkB,EAAE,MAAM,GAAG,IAAI,GAChC,OAAO,CAKT;AAED,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,MAAM,EAClB,kBAAkB,EAAE,MAAM,GAAG,IAAI,GAChC,IAAI,CAQN;AAMD,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,WAAW,CAAC;IACzB,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC,CAAC;AAEF,wBAAgB,wBAAwB,CAAC,OAAO,EAAE;IAChD,sBAAsB,EAAE,MAAM,CAAC;IAC/B,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,GAAG,yBAAyB,CA6C5B;AAED,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG;IAC5D,OAAO,EAAE,OAAO,GAAG,UAAU,CAAC;IAC9B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CA0CA;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAmChE"}
|
|
@@ -37,6 +37,21 @@ export function generateStandaloneChatManifest(repoRoot) {
|
|
|
37
37
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
function mergePackageJsonRecords(canonical, starter, starterPinnedKeys = []) {
|
|
41
|
+
const merged = { ...(canonical ?? {}) };
|
|
42
|
+
for (const [key, value] of Object.entries(starter ?? {})) {
|
|
43
|
+
if (!(key in merged)) {
|
|
44
|
+
merged[key] = value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (const key of starterPinnedKeys) {
|
|
48
|
+
const pinned = starter?.[key];
|
|
49
|
+
if (pinned) {
|
|
50
|
+
merged[key] = pinned;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return merged;
|
|
54
|
+
}
|
|
40
55
|
export function mergeStarterManifest(starterPackageJson, canonicalPackageJson) {
|
|
41
56
|
const merged = structuredClone(canonicalPackageJson);
|
|
42
57
|
merged.name = starterPackageJson.name ?? STARTER_APP_NAME;
|
|
@@ -49,16 +64,12 @@ export function mergeStarterManifest(starterPackageJson, canonicalPackageJson) {
|
|
|
49
64
|
if (starterPackageJson.private !== undefined) {
|
|
50
65
|
merged.private = starterPackageJson.private;
|
|
51
66
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
merged.
|
|
57
|
-
|
|
58
|
-
...(starterDeps["@agent-native/core"]
|
|
59
|
-
? { "@agent-native/core": starterDeps["@agent-native/core"] }
|
|
60
|
-
: {}),
|
|
61
|
-
};
|
|
67
|
+
if (typeof starterPackageJson.packageManager === "string") {
|
|
68
|
+
merged.packageManager = starterPackageJson.packageManager;
|
|
69
|
+
}
|
|
70
|
+
merged.dependencies = mergePackageJsonRecords(canonicalPackageJson.dependencies, starterPackageJson.dependencies, ["@agent-native/core"]);
|
|
71
|
+
merged.devDependencies = mergePackageJsonRecords(canonicalPackageJson.devDependencies, starterPackageJson.devDependencies);
|
|
72
|
+
merged.scripts = mergePackageJsonRecords(canonicalPackageJson.scripts, starterPackageJson.scripts);
|
|
62
73
|
return merged;
|
|
63
74
|
}
|
|
64
75
|
export function workspaceFileSyncChanged(existingWorkspace, canonicalWorkspace) {
|
|
@@ -1 +1 @@
|
|
|
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AAC;QAC3B,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEjD,IAAI,WAAW,EAAE,CAAC;IAChB,MAAM,QAAQ,GAAG,yBAAyB,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAClE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { _postProcessStandalone } from \"./create.js\";\n\nexport const STARTER_APP_NAME = \"builder-agent-native-starter\";\nexport const CHAT_TEMPLATE = \"chat\";\n\ntype PackageJson = Record<string, unknown>;\n\nexport function findAgentNativeRoot(startDir = process.cwd()): string {\n let dir = path.resolve(startDir);\n for (let i = 0; i < 12; i++) {\n const chatPackageJson = path.join(\n dir,\n \"templates\",\n CHAT_TEMPLATE,\n \"package.json\",\n );\n if (fs.existsSync(chatPackageJson)) {\n return dir;\n }\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n throw new Error(\n \"Could not find agent-native repo root (expected templates/chat/package.json).\",\n );\n}\n\nexport function generateStandaloneChatManifest(repoRoot?: string): {\n packageJson: PackageJson;\n pnpmWorkspaceYaml: string | null;\n} {\n const root = repoRoot ?? findAgentNativeRoot();\n const chatTemplateDir = path.join(root, \"templates\", CHAT_TEMPLATE);\n const tempDir = fs.mkdtempSync(\n path.join(os.tmpdir(), \"an-builder-starter-sync-\"),\n );\n\n try {\n fs.cpSync(chatTemplateDir, tempDir, { recursive: true });\n _postProcessStandalone(STARTER_APP_NAME, tempDir, CHAT_TEMPLATE);\n\n const packageJson = JSON.parse(\n fs.readFileSync(path.join(tempDir, \"package.json\"), \"utf-8\"),\n ) as PackageJson;\n\n const workspacePath = path.join(tempDir, \"pnpm-workspace.yaml\");\n const pnpmWorkspaceYaml = fs.existsSync(workspacePath)\n ? fs.readFileSync(workspacePath, \"utf-8\")\n : null;\n\n return { packageJson, pnpmWorkspaceYaml };\n } finally {\n fs.rmSync(tempDir, { recursive: true, force: true });\n }\n}\n\nexport function mergeStarterManifest(\n starterPackageJson: PackageJson,\n canonicalPackageJson: PackageJson,\n): PackageJson {\n const merged = structuredClone(canonicalPackageJson) as PackageJson;\n\n merged.name = starterPackageJson.name ?? STARTER_APP_NAME;\n if (typeof starterPackageJson.displayName === \"string\") {\n merged.displayName = starterPackageJson.displayName;\n }\n if (typeof starterPackageJson.description === \"string\") {\n merged.description = starterPackageJson.description;\n }\n if (starterPackageJson.private !== undefined) {\n merged.private = starterPackageJson.private;\n }\n\n const starterDeps =\n (starterPackageJson.dependencies as Record<string, string> | undefined) ??\n {};\n const canonicalDeps =\n (canonicalPackageJson.dependencies as Record<string, string> | undefined) ??\n {};\n merged.dependencies = {\n ...canonicalDeps,\n ...(starterDeps[\"@agent-native/core\"]\n ? { \"@agent-native/core\": starterDeps[\"@agent-native/core\"] }\n : {}),\n };\n\n return merged;\n}\n\nexport function workspaceFileSyncChanged(\n existingWorkspace: string | null,\n canonicalWorkspace: string | null,\n): boolean {\n if (canonicalWorkspace === null) {\n return existingWorkspace !== null;\n }\n return existingWorkspace !== canonicalWorkspace;\n}\n\nexport function applyWorkspaceFileSync(\n targetPath: string,\n canonicalWorkspace: string | null,\n): void {\n if (canonicalWorkspace === null) {\n if (fs.existsSync(targetPath)) {\n fs.unlinkSync(targetPath);\n }\n return;\n }\n fs.writeFileSync(targetPath, canonicalWorkspace);\n}\n\nfunction stableJson(value: unknown): string {\n return `${JSON.stringify(value, null, 2)}\\n`;\n}\n\nexport type SyncStarterManifestResult = {\n changed: boolean;\n packageJson: PackageJson;\n pnpmWorkspaceYaml: string | null;\n};\n\nexport function syncStarterManifestFiles(options: {\n starterPackageJsonPath: string;\n starterPnpmWorkspacePath?: string;\n repoRoot?: string;\n write?: boolean;\n}): SyncStarterManifestResult {\n const { packageJson: canonical, pnpmWorkspaceYaml } =\n generateStandaloneChatManifest(options.repoRoot);\n\n const starterPackageJson = JSON.parse(\n fs.readFileSync(options.starterPackageJsonPath, \"utf-8\"),\n ) as PackageJson;\n const mergedPackageJson = mergeStarterManifest(starterPackageJson, canonical);\n\n let workspaceChanged = false;\n const existingWorkspace =\n options.starterPnpmWorkspacePath &&\n fs.existsSync(options.starterPnpmWorkspacePath)\n ? fs.readFileSync(options.starterPnpmWorkspacePath, \"utf-8\")\n : null;\n\n workspaceChanged = workspaceFileSyncChanged(\n existingWorkspace,\n pnpmWorkspaceYaml,\n );\n\n const packageChanged =\n stableJson(starterPackageJson) !== stableJson(mergedPackageJson);\n const changed = packageChanged || workspaceChanged;\n\n if (options.write && changed) {\n if (packageChanged) {\n fs.writeFileSync(\n options.starterPackageJsonPath,\n stableJson(mergedPackageJson),\n );\n }\n if (workspaceChanged && options.starterPnpmWorkspacePath) {\n applyWorkspaceFileSync(\n options.starterPnpmWorkspacePath,\n pnpmWorkspaceYaml,\n );\n }\n }\n\n return {\n changed,\n packageJson: mergedPackageJson,\n pnpmWorkspaceYaml,\n };\n}\n\nexport function parseSyncStarterManifestArgs(argv: string[]): {\n command: \"merge\" | \"generate\";\n starterPackageJsonPath?: string;\n starterPnpmWorkspacePath?: string;\n write: boolean;\n repoRoot?: string;\n} {\n const [commandRaw, ...rest] = argv;\n const command = commandRaw === \"generate\" ? \"generate\" : \"merge\";\n let starterPackageJsonPath: string | undefined;\n let starterPnpmWorkspacePath: string | undefined;\n let write = false;\n let repoRoot: string | undefined;\n\n for (let i = 0; i < rest.length; i++) {\n const arg = rest[i];\n if (arg === \"--write\") {\n write = true;\n continue;\n }\n if (arg === \"--starter-package-json\") {\n starterPackageJsonPath = rest[++i];\n continue;\n }\n if (arg === \"--starter-pnpm-workspace\") {\n starterPnpmWorkspacePath = rest[++i];\n continue;\n }\n if (arg === \"--repo-root\") {\n repoRoot = rest[++i];\n continue;\n }\n throw new Error(`Unknown argument: ${arg}`);\n }\n\n if (command === \"merge\" && !starterPackageJsonPath) {\n throw new Error(\n \"merge requires --starter-package-json <path> [--starter-pnpm-workspace <path>] [--write] [--repo-root <path>]\",\n );\n }\n\n return {\n command,\n starterPackageJsonPath,\n starterPnpmWorkspacePath,\n write,\n repoRoot,\n };\n}\n\nexport function runSyncStarterManifestCli(argv: string[]): number {\n const args = parseSyncStarterManifestArgs(argv);\n\n if (args.command === \"generate\") {\n const { packageJson, pnpmWorkspaceYaml } = generateStandaloneChatManifest(\n args.repoRoot,\n );\n process.stdout.write(stableJson(packageJson));\n if (pnpmWorkspaceYaml) {\n process.stdout.write(\"\\n--- pnpm-workspace.yaml ---\\n\");\n process.stdout.write(pnpmWorkspaceYaml);\n }\n return 0;\n }\n\n const result = syncStarterManifestFiles({\n starterPackageJsonPath: args.starterPackageJsonPath!,\n starterPnpmWorkspacePath: args.starterPnpmWorkspacePath,\n repoRoot: args.repoRoot,\n write: args.write,\n });\n\n if (result.changed) {\n console.log(\n args.write\n ? \"Updated builder-agent-native-starter manifest from templates/chat.\"\n : \"builder-agent-native-starter manifest is out of date with templates/chat.\",\n );\n return args.write ? 0 : 1;\n }\n\n console.log(\n \"builder-agent-native-starter manifest already matches templates/chat.\",\n );\n return 0;\n}\n\nconst isDirectRun =\n process.argv[1] &&\n path.resolve(process.argv[1]) ===\n path.resolve(fileURLToPath(import.meta.url));\n\nif (isDirectRun) {\n const exitCode = runSyncStarterManifestCli(process.argv.slice(2));\n process.exit(exitCode);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sync-builder-starter-manifest.js","sourceRoot":"","sources":["../../src/cli/sync-builder-starter-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,a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EAAE,IAAI,CAAC,KAAK;KAClB,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,CAAC,GAAG,CACT,IAAI,CAAC,KAAK;YACR,CAAC,CAAC,oEAAoE;YACtE,CAAC,CAAC,2EAA2E,CAChF,CAAC;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,CAAC,GAAG,CACT,uEAAuE,CACxE,CAAC;IACF,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,WAAW,GACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACf,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEjD,IAAI,WAAW,EAAE,CAAC;IAChB,MAAM,QAAQ,GAAG,yBAAyB,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAClE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { _postProcessStandalone } from \"./create.js\";\n\nexport const STARTER_APP_NAME = \"builder-agent-native-starter\";\nexport const CHAT_TEMPLATE = \"chat\";\n\ntype PackageJson = Record<string, unknown>;\n\nexport function findAgentNativeRoot(startDir = process.cwd()): string {\n let dir = path.resolve(startDir);\n for (let i = 0; i < 12; i++) {\n const chatPackageJson = path.join(\n dir,\n \"templates\",\n CHAT_TEMPLATE,\n \"package.json\",\n );\n if (fs.existsSync(chatPackageJson)) {\n return dir;\n }\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n throw new Error(\n \"Could not find agent-native repo root (expected templates/chat/package.json).\",\n );\n}\n\nexport function generateStandaloneChatManifest(repoRoot?: string): {\n packageJson: PackageJson;\n pnpmWorkspaceYaml: string | null;\n} {\n const root = repoRoot ?? findAgentNativeRoot();\n const chatTemplateDir = path.join(root, \"templates\", CHAT_TEMPLATE);\n const tempDir = fs.mkdtempSync(\n path.join(os.tmpdir(), \"an-builder-starter-sync-\"),\n );\n\n try {\n fs.cpSync(chatTemplateDir, tempDir, { recursive: true });\n _postProcessStandalone(STARTER_APP_NAME, tempDir, CHAT_TEMPLATE);\n\n const packageJson = JSON.parse(\n fs.readFileSync(path.join(tempDir, \"package.json\"), \"utf-8\"),\n ) as PackageJson;\n\n const workspacePath = path.join(tempDir, \"pnpm-workspace.yaml\");\n const pnpmWorkspaceYaml = fs.existsSync(workspacePath)\n ? fs.readFileSync(workspacePath, \"utf-8\")\n : null;\n\n return { packageJson, pnpmWorkspaceYaml };\n } finally {\n fs.rmSync(tempDir, { recursive: true, force: true });\n }\n}\n\nfunction mergePackageJsonRecords(\n canonical: Record<string, string> | undefined,\n starter: Record<string, string> | undefined,\n starterPinnedKeys: string[] = [],\n): Record<string, string> {\n const merged = { ...(canonical ?? {}) };\n for (const [key, value] of Object.entries(starter ?? {})) {\n if (!(key in merged)) {\n merged[key] = value;\n }\n }\n for (const key of starterPinnedKeys) {\n const pinned = starter?.[key];\n if (pinned) {\n merged[key] = pinned;\n }\n }\n return merged;\n}\n\nexport function mergeStarterManifest(\n starterPackageJson: PackageJson,\n canonicalPackageJson: PackageJson,\n): PackageJson {\n const merged = structuredClone(canonicalPackageJson) as PackageJson;\n\n merged.name = starterPackageJson.name ?? STARTER_APP_NAME;\n if (typeof starterPackageJson.displayName === \"string\") {\n merged.displayName = starterPackageJson.displayName;\n }\n if (typeof starterPackageJson.description === \"string\") {\n merged.description = starterPackageJson.description;\n }\n if (starterPackageJson.private !== undefined) {\n merged.private = starterPackageJson.private;\n }\n if (typeof starterPackageJson.packageManager === \"string\") {\n merged.packageManager = starterPackageJson.packageManager;\n }\n\n merged.dependencies = mergePackageJsonRecords(\n canonicalPackageJson.dependencies as Record<string, string> | undefined,\n starterPackageJson.dependencies as Record<string, string> | undefined,\n [\"@agent-native/core\"],\n );\n merged.devDependencies = mergePackageJsonRecords(\n canonicalPackageJson.devDependencies as Record<string, string> | undefined,\n starterPackageJson.devDependencies as Record<string, string> | undefined,\n );\n merged.scripts = mergePackageJsonRecords(\n canonicalPackageJson.scripts as Record<string, string> | undefined,\n starterPackageJson.scripts as Record<string, string> | undefined,\n );\n\n return merged;\n}\n\nexport function workspaceFileSyncChanged(\n existingWorkspace: string | null,\n canonicalWorkspace: string | null,\n): boolean {\n if (canonicalWorkspace === null) {\n return existingWorkspace !== null;\n }\n return existingWorkspace !== canonicalWorkspace;\n}\n\nexport function applyWorkspaceFileSync(\n targetPath: string,\n canonicalWorkspace: string | null,\n): void {\n if (canonicalWorkspace === null) {\n if (fs.existsSync(targetPath)) {\n fs.unlinkSync(targetPath);\n }\n return;\n }\n fs.writeFileSync(targetPath, canonicalWorkspace);\n}\n\nfunction stableJson(value: unknown): string {\n return `${JSON.stringify(value, null, 2)}\\n`;\n}\n\nexport type SyncStarterManifestResult = {\n changed: boolean;\n packageJson: PackageJson;\n pnpmWorkspaceYaml: string | null;\n};\n\nexport function syncStarterManifestFiles(options: {\n starterPackageJsonPath: string;\n starterPnpmWorkspacePath?: string;\n repoRoot?: string;\n write?: boolean;\n}): SyncStarterManifestResult {\n const { packageJson: canonical, pnpmWorkspaceYaml } =\n generateStandaloneChatManifest(options.repoRoot);\n\n const starterPackageJson = JSON.parse(\n fs.readFileSync(options.starterPackageJsonPath, \"utf-8\"),\n ) as PackageJson;\n const mergedPackageJson = mergeStarterManifest(starterPackageJson, canonical);\n\n let workspaceChanged = false;\n const existingWorkspace =\n options.starterPnpmWorkspacePath &&\n fs.existsSync(options.starterPnpmWorkspacePath)\n ? fs.readFileSync(options.starterPnpmWorkspacePath, \"utf-8\")\n : null;\n\n workspaceChanged = workspaceFileSyncChanged(\n existingWorkspace,\n pnpmWorkspaceYaml,\n );\n\n const packageChanged =\n stableJson(starterPackageJson) !== stableJson(mergedPackageJson);\n const changed = packageChanged || workspaceChanged;\n\n if (options.write && changed) {\n if (packageChanged) {\n fs.writeFileSync(\n options.starterPackageJsonPath,\n stableJson(mergedPackageJson),\n );\n }\n if (workspaceChanged && options.starterPnpmWorkspacePath) {\n applyWorkspaceFileSync(\n options.starterPnpmWorkspacePath,\n pnpmWorkspaceYaml,\n );\n }\n }\n\n return {\n changed,\n packageJson: mergedPackageJson,\n pnpmWorkspaceYaml,\n };\n}\n\nexport function parseSyncStarterManifestArgs(argv: string[]): {\n command: \"merge\" | \"generate\";\n starterPackageJsonPath?: string;\n starterPnpmWorkspacePath?: string;\n write: boolean;\n repoRoot?: string;\n} {\n const [commandRaw, ...rest] = argv;\n const command = commandRaw === \"generate\" ? \"generate\" : \"merge\";\n let starterPackageJsonPath: string | undefined;\n let starterPnpmWorkspacePath: string | undefined;\n let write = false;\n let repoRoot: string | undefined;\n\n for (let i = 0; i < rest.length; i++) {\n const arg = rest[i];\n if (arg === \"--write\") {\n write = true;\n continue;\n }\n if (arg === \"--starter-package-json\") {\n starterPackageJsonPath = rest[++i];\n continue;\n }\n if (arg === \"--starter-pnpm-workspace\") {\n starterPnpmWorkspacePath = rest[++i];\n continue;\n }\n if (arg === \"--repo-root\") {\n repoRoot = rest[++i];\n continue;\n }\n throw new Error(`Unknown argument: ${arg}`);\n }\n\n if (command === \"merge\" && !starterPackageJsonPath) {\n throw new Error(\n \"merge requires --starter-package-json <path> [--starter-pnpm-workspace <path>] [--write] [--repo-root <path>]\",\n );\n }\n\n return {\n command,\n starterPackageJsonPath,\n starterPnpmWorkspacePath,\n write,\n repoRoot,\n };\n}\n\nexport function runSyncStarterManifestCli(argv: string[]): number {\n const args = parseSyncStarterManifestArgs(argv);\n\n if (args.command === \"generate\") {\n const { packageJson, pnpmWorkspaceYaml } = generateStandaloneChatManifest(\n args.repoRoot,\n );\n process.stdout.write(stableJson(packageJson));\n if (pnpmWorkspaceYaml) {\n process.stdout.write(\"\\n--- pnpm-workspace.yaml ---\\n\");\n process.stdout.write(pnpmWorkspaceYaml);\n }\n return 0;\n }\n\n const result = syncStarterManifestFiles({\n starterPackageJsonPath: args.starterPackageJsonPath!,\n starterPnpmWorkspacePath: args.starterPnpmWorkspacePath,\n repoRoot: args.repoRoot,\n write: args.write,\n });\n\n if (result.changed) {\n console.log(\n args.write\n ? \"Updated builder-agent-native-starter manifest from templates/chat.\"\n : \"builder-agent-native-starter manifest is out of date with templates/chat.\",\n );\n return args.write ? 0 : 1;\n }\n\n console.log(\n \"builder-agent-native-starter manifest already matches templates/chat.\",\n );\n return 0;\n}\n\nconst isDirectRun =\n process.argv[1] &&\n path.resolve(process.argv[1]) ===\n path.resolve(fileURLToPath(import.meta.url));\n\nif (isDirectRun) {\n const exitCode = runSyncStarterManifestCli(process.argv.slice(2));\n process.exit(exitCode);\n}\n"]}
|
package/dist/deploy/build.d.ts
CHANGED
|
@@ -58,46 +58,66 @@ export declare function findInstalledResvgPackages(nodeModulesRoots: string[]):
|
|
|
58
58
|
*/
|
|
59
59
|
export declare function isDurableBackgroundDeployEnabled(): boolean;
|
|
60
60
|
/**
|
|
61
|
-
* Single-template Netlify build: emit
|
|
62
|
-
* the chat `_process-run` worker runs on Netlify's
|
|
63
|
-
*
|
|
61
|
+
* Single-template Netlify build: emit an async (background) function INSIDE the
|
|
62
|
+
* scanned functions dir so the chat `_process-run` worker runs on Netlify's
|
|
63
|
+
* 15-min async function instead of the synchronous `/*` catch-all.
|
|
64
64
|
* Additive + flag-gated (see `isDurableBackgroundDeployEnabled`).
|
|
65
65
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
66
|
+
* GROUNDED IN THE REAL NETLIFY BUILD OUTPUT (verified from a local Nitro build)
|
|
67
|
+
* AND THE NETLIFY DOCS DEFAULT-URL RULE:
|
|
68
|
+
* - Nitro's `netlify` preset emits exactly ONE function source at
|
|
69
|
+
* `.netlify/functions-internal/server/`. `server.mjs` re-exports `main.mjs`
|
|
70
|
+
* and declares `export const config = { path: "/*", excludedPath:
|
|
71
|
+
* ["/.netlify/*"], preferStatic: true, ... }`. The `/*` catch-all is an
|
|
72
|
+
* IN-CODE Functions-API-v2 `config.path` and it ALREADY EXCLUDES
|
|
73
|
+
* `/.netlify/*`.
|
|
74
|
+
* - The generated `.netlify/netlify.toml` sets
|
|
75
|
+
* `functionsDirectory = ".netlify/functions-internal"`. Netlify scans EXACTLY
|
|
76
|
+
* that dir; functions placed anywhere else (e.g. `.netlify/functions/`, which
|
|
77
|
+
* is the BUILD OUTPUT dir where `@netlify/build` later writes the zipped
|
|
78
|
+
* functions + `manifest.json`) are NEVER deployed.
|
|
79
|
+
* - Every scanned function is reachable at its DEFAULT url
|
|
80
|
+
* `/.netlify/functions/<name>` BY DEFAULT. A custom `config.path` REMOVES
|
|
81
|
+
* that default url; declaring NO custom `config.path` KEEPS it.
|
|
82
|
+
*
|
|
83
|
+
* THEREFORE we:
|
|
84
|
+
* 1. Emit the background function INTO the scanned dir
|
|
85
|
+
* (`.netlify/functions-internal/server-agent-background/`), sharing the same
|
|
86
|
+
* built `main.mjs` bundle, so Netlify discovers it and honors its config.
|
|
87
|
+
* 2. Give its `export const config` `background: true` (→ async invoke,
|
|
88
|
+
* immediate 202, 15-min budget) and NO custom `config.path`. With no custom
|
|
89
|
+
* path the function keeps its DEFAULT url
|
|
90
|
+
* `/.netlify/functions/server-agent-background`, and because the Nitro
|
|
91
|
+
* `server` function's `/*` catch-all already excludes `/.netlify/*`, that
|
|
92
|
+
* default-url namespace is NEVER shadowed by the synchronous function — no
|
|
93
|
+
* catch-all patch is needed.
|
|
94
|
+
* 3. The entry NORMALIZES/rewrites the incoming request pathname to
|
|
95
|
+
* `AGENT_CHAT_PROCESS_RUN_PATH` before delegating to `./main.mjs`. The
|
|
96
|
+
* function is reached at its default url
|
|
97
|
+
* (`/.netlify/functions/server-agent-background`), so the Nitro router needs
|
|
98
|
+
* the path rewritten to the framework `_process-run` route, preserving the
|
|
99
|
+
* method, ALL headers (the HMAC `Authorization: Bearer` MUST survive), and
|
|
100
|
+
* the body.
|
|
101
|
+
* 4. Set `globalThis.__AGENT_NATIVE_BACKGROUND_RUNTIME__ = true` at cold start
|
|
71
102
|
* (read back by `isInBackgroundFunctionRuntime()` so the worker takes the
|
|
72
103
|
* ~13-min soft-timeout). A `globalThis` flag — NOT `process.env` — keeps the
|
|
73
104
|
* no-env-mutation guard satisfied and carries no cross-request state.
|
|
74
|
-
* 2. Declares `export const config = { background: true }` with NO `path`. With
|
|
75
|
-
* no custom `path`, Netlify exposes the function at the DEFAULT url
|
|
76
|
-
* `/.netlify/functions/server-agent-background` and `background:true` makes
|
|
77
|
-
* it ASYNC (immediate HTTP 202 ack, 15-min budget). The foreground POST
|
|
78
|
-
* self-dispatches to that direct url
|
|
79
|
-
* (`resolveAgentChatProcessRunDispatchPath`), BYPASSING Nitro's `/*`
|
|
80
|
-
* catch-all entirely.
|
|
81
|
-
* 3. REWRITES the incoming request path to `AGENT_CHAT_PROCESS_RUN_PATH` before
|
|
82
|
-
* delegating to the Nitro handler (`./main.mjs` default export — a Netlify
|
|
83
|
-
* v2 / Web-standard `async (Request) => Response` handler), so the Nitro
|
|
84
|
-
* router dispatches it to the `_process-run` plugin. Method, ALL headers
|
|
85
|
-
* (critically the HMAC `Authorization: Bearer` the plugin verifies) and the
|
|
86
|
-
* body are preserved by cloning the incoming `Request` with only its URL
|
|
87
|
-
* pathname rewritten.
|
|
88
105
|
*
|
|
89
|
-
*
|
|
90
|
-
* `
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
106
|
+
* The foreground dispatches to this DEFAULT url on hosted Netlify
|
|
107
|
+
* (`resolveAgentChatProcessRunDispatchPath` → `AGENT_BACKGROUND_FUNCTION_URL_PATH`).
|
|
108
|
+
*
|
|
109
|
+
* WHY THIS IS THE DOC-CORRECT FIX: a prior attempt gave the function a custom
|
|
110
|
+
* `config.path` (= the framework route) plus a catch-all `excludedPath` patch.
|
|
111
|
+
* The custom `config.path` was NOT honored as a route in prod — a probe of
|
|
112
|
+
* `POST /_agent-native/agent-chat/_process-run` returned 404. The doc-correct
|
|
113
|
+
* approach (confirmed against the Netlify docs) is to use the DEFAULT function
|
|
114
|
+
* url with no custom path: the function stays reachable at
|
|
115
|
+
* `/.netlify/functions/<name>` and is never shadowed because `/.netlify/*` is
|
|
116
|
+
* already excluded from the `server` catch-all.
|
|
97
117
|
*
|
|
98
|
-
* Safety net regardless of Netlify routing nuance: if the
|
|
99
|
-
*
|
|
100
|
-
*
|
|
118
|
+
* Safety net regardless of Netlify routing nuance: if the dispatch fast-fails
|
|
119
|
+
* (e.g. the function was not emitted), the foreground handler degrades to an
|
|
120
|
+
* inline 40s synchronous run (see production-agent.ts).
|
|
101
121
|
*/
|
|
102
122
|
export declare function emitSingleTemplateNetlifyBackgroundFunction(projectCwd: string): void;
|
|
103
123
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/deploy/build.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;GAYG;AAOH,OAAO,EAML,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,qBAAqB,CAAC;AA+B7B,eAAO,MAAM,6BAA6B,UAiBzC,CAAC;AAuBF,wBAAgB,wCAAwC,CACtD,WAAW,EAAE,MAAM,EAAE,GACpB,MAAM,CAaR;AAgBD,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAC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;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAqCpD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gCAAgC,IAAI,OAAO,CAK1D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,wBAAgB,2CAA2C,CACzD,UAAU,EAAE,MAAM,GACjB,IAAI,CAyFN;AAkND;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,gBAAgB,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,UAAU,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,GAAG,CAAC;IACX,KAAK,EAAE,eAAe,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,yBAAyB,GAC9B,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
|
package/dist/deploy/build.js
CHANGED
|
@@ -1252,46 +1252,66 @@ export function isDurableBackgroundDeployEnabled() {
|
|
|
1252
1252
|
return !(v === "0" || v === "false" || v === "no" || v === "off");
|
|
1253
1253
|
}
|
|
1254
1254
|
/**
|
|
1255
|
-
* Single-template Netlify build: emit
|
|
1256
|
-
* the chat `_process-run` worker runs on Netlify's
|
|
1257
|
-
*
|
|
1255
|
+
* Single-template Netlify build: emit an async (background) function INSIDE the
|
|
1256
|
+
* scanned functions dir so the chat `_process-run` worker runs on Netlify's
|
|
1257
|
+
* 15-min async function instead of the synchronous `/*` catch-all.
|
|
1258
1258
|
* Additive + flag-gated (see `isDurableBackgroundDeployEnabled`).
|
|
1259
1259
|
*
|
|
1260
|
-
*
|
|
1261
|
-
*
|
|
1262
|
-
*
|
|
1263
|
-
*
|
|
1264
|
-
*
|
|
1260
|
+
* GROUNDED IN THE REAL NETLIFY BUILD OUTPUT (verified from a local Nitro build)
|
|
1261
|
+
* AND THE NETLIFY DOCS DEFAULT-URL RULE:
|
|
1262
|
+
* - Nitro's `netlify` preset emits exactly ONE function source at
|
|
1263
|
+
* `.netlify/functions-internal/server/`. `server.mjs` re-exports `main.mjs`
|
|
1264
|
+
* and declares `export const config = { path: "/*", excludedPath:
|
|
1265
|
+
* ["/.netlify/*"], preferStatic: true, ... }`. The `/*` catch-all is an
|
|
1266
|
+
* IN-CODE Functions-API-v2 `config.path` and it ALREADY EXCLUDES
|
|
1267
|
+
* `/.netlify/*`.
|
|
1268
|
+
* - The generated `.netlify/netlify.toml` sets
|
|
1269
|
+
* `functionsDirectory = ".netlify/functions-internal"`. Netlify scans EXACTLY
|
|
1270
|
+
* that dir; functions placed anywhere else (e.g. `.netlify/functions/`, which
|
|
1271
|
+
* is the BUILD OUTPUT dir where `@netlify/build` later writes the zipped
|
|
1272
|
+
* functions + `manifest.json`) are NEVER deployed.
|
|
1273
|
+
* - Every scanned function is reachable at its DEFAULT url
|
|
1274
|
+
* `/.netlify/functions/<name>` BY DEFAULT. A custom `config.path` REMOVES
|
|
1275
|
+
* that default url; declaring NO custom `config.path` KEEPS it.
|
|
1276
|
+
*
|
|
1277
|
+
* THEREFORE we:
|
|
1278
|
+
* 1. Emit the background function INTO the scanned dir
|
|
1279
|
+
* (`.netlify/functions-internal/server-agent-background/`), sharing the same
|
|
1280
|
+
* built `main.mjs` bundle, so Netlify discovers it and honors its config.
|
|
1281
|
+
* 2. Give its `export const config` `background: true` (→ async invoke,
|
|
1282
|
+
* immediate 202, 15-min budget) and NO custom `config.path`. With no custom
|
|
1283
|
+
* path the function keeps its DEFAULT url
|
|
1284
|
+
* `/.netlify/functions/server-agent-background`, and because the Nitro
|
|
1285
|
+
* `server` function's `/*` catch-all already excludes `/.netlify/*`, that
|
|
1286
|
+
* default-url namespace is NEVER shadowed by the synchronous function — no
|
|
1287
|
+
* catch-all patch is needed.
|
|
1288
|
+
* 3. The entry NORMALIZES/rewrites the incoming request pathname to
|
|
1289
|
+
* `AGENT_CHAT_PROCESS_RUN_PATH` before delegating to `./main.mjs`. The
|
|
1290
|
+
* function is reached at its default url
|
|
1291
|
+
* (`/.netlify/functions/server-agent-background`), so the Nitro router needs
|
|
1292
|
+
* the path rewritten to the framework `_process-run` route, preserving the
|
|
1293
|
+
* method, ALL headers (the HMAC `Authorization: Bearer` MUST survive), and
|
|
1294
|
+
* the body.
|
|
1295
|
+
* 4. Set `globalThis.__AGENT_NATIVE_BACKGROUND_RUNTIME__ = true` at cold start
|
|
1265
1296
|
* (read back by `isInBackgroundFunctionRuntime()` so the worker takes the
|
|
1266
1297
|
* ~13-min soft-timeout). A `globalThis` flag — NOT `process.env` — keeps the
|
|
1267
1298
|
* no-env-mutation guard satisfied and carries no cross-request state.
|
|
1268
|
-
* 2. Declares `export const config = { background: true }` with NO `path`. With
|
|
1269
|
-
* no custom `path`, Netlify exposes the function at the DEFAULT url
|
|
1270
|
-
* `/.netlify/functions/server-agent-background` and `background:true` makes
|
|
1271
|
-
* it ASYNC (immediate HTTP 202 ack, 15-min budget). The foreground POST
|
|
1272
|
-
* self-dispatches to that direct url
|
|
1273
|
-
* (`resolveAgentChatProcessRunDispatchPath`), BYPASSING Nitro's `/*`
|
|
1274
|
-
* catch-all entirely.
|
|
1275
|
-
* 3. REWRITES the incoming request path to `AGENT_CHAT_PROCESS_RUN_PATH` before
|
|
1276
|
-
* delegating to the Nitro handler (`./main.mjs` default export — a Netlify
|
|
1277
|
-
* v2 / Web-standard `async (Request) => Response` handler), so the Nitro
|
|
1278
|
-
* router dispatches it to the `_process-run` plugin. Method, ALL headers
|
|
1279
|
-
* (critically the HMAC `Authorization: Bearer` the plugin verifies) and the
|
|
1280
|
-
* body are preserved by cloning the incoming `Request` with only its URL
|
|
1281
|
-
* pathname rewritten.
|
|
1282
1299
|
*
|
|
1283
|
-
*
|
|
1284
|
-
* `
|
|
1285
|
-
*
|
|
1286
|
-
*
|
|
1287
|
-
*
|
|
1288
|
-
*
|
|
1289
|
-
*
|
|
1290
|
-
*
|
|
1300
|
+
* The foreground dispatches to this DEFAULT url on hosted Netlify
|
|
1301
|
+
* (`resolveAgentChatProcessRunDispatchPath` → `AGENT_BACKGROUND_FUNCTION_URL_PATH`).
|
|
1302
|
+
*
|
|
1303
|
+
* WHY THIS IS THE DOC-CORRECT FIX: a prior attempt gave the function a custom
|
|
1304
|
+
* `config.path` (= the framework route) plus a catch-all `excludedPath` patch.
|
|
1305
|
+
* The custom `config.path` was NOT honored as a route in prod — a probe of
|
|
1306
|
+
* `POST /_agent-native/agent-chat/_process-run` returned 404. The doc-correct
|
|
1307
|
+
* approach (confirmed against the Netlify docs) is to use the DEFAULT function
|
|
1308
|
+
* url with no custom path: the function stays reachable at
|
|
1309
|
+
* `/.netlify/functions/<name>` and is never shadowed because `/.netlify/*` is
|
|
1310
|
+
* already excluded from the `server` catch-all.
|
|
1291
1311
|
*
|
|
1292
|
-
* Safety net regardless of Netlify routing nuance: if the
|
|
1293
|
-
*
|
|
1294
|
-
*
|
|
1312
|
+
* Safety net regardless of Netlify routing nuance: if the dispatch fast-fails
|
|
1313
|
+
* (e.g. the function was not emitted), the foreground handler degrades to an
|
|
1314
|
+
* inline 40s synchronous run (see production-agent.ts).
|
|
1295
1315
|
*/
|
|
1296
1316
|
export function emitSingleTemplateNetlifyBackgroundFunction(projectCwd) {
|
|
1297
1317
|
const internalDir = path.join(projectCwd, ".netlify", "functions-internal");
|
|
@@ -1304,15 +1324,15 @@ export function emitSingleTemplateNetlifyBackgroundFunction(projectCwd) {
|
|
|
1304
1324
|
return;
|
|
1305
1325
|
}
|
|
1306
1326
|
const backgroundName = AGENT_BACKGROUND_FUNCTION_NAME;
|
|
1307
|
-
// Emit
|
|
1308
|
-
//
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1327
|
+
// Emit INTO the SCANNED functions dir (functions-internal) so Netlify discovers
|
|
1328
|
+
// the function and honors its `export const config`. `.netlify/functions/` is
|
|
1329
|
+
// the build OUTPUT dir (where @netlify/build writes the zip + manifest) and is
|
|
1330
|
+
// NOT scanned — emitting there is why the standalone attempt 404'd.
|
|
1331
|
+
const dest = path.join(internalDir, backgroundName);
|
|
1312
1332
|
fs.rmSync(dest, { recursive: true, force: true });
|
|
1313
1333
|
copyDir(serverDir, dest);
|
|
1314
|
-
// Drop the original Nitro `/*` entry so our
|
|
1315
|
-
//
|
|
1334
|
+
// Drop the original Nitro `/*` entry so our entry is the entrypoint and the
|
|
1335
|
+
// copied bundle does NOT re-register the catch-all `config.path`.
|
|
1316
1336
|
fs.rmSync(path.join(dest, "server.mjs"), { force: true });
|
|
1317
1337
|
const processRunPath = JSON.stringify(AGENT_CHAT_PROCESS_RUN_PATH);
|
|
1318
1338
|
const entry = `// Mark this isolate as the durable background runtime BEFORE the handler
|
|
@@ -1331,12 +1351,12 @@ let cachedHandler;
|
|
|
1331
1351
|
|
|
1332
1352
|
// Netlify v2 invokes this as (request, context). The Nitro netlify handler is a
|
|
1333
1353
|
// Web-standard \`async (Request) => Response\` (see nitro/presets/netlify/runtime).
|
|
1334
|
-
//
|
|
1335
|
-
// (/.netlify/functions/${backgroundName})
|
|
1336
|
-
//
|
|
1337
|
-
//
|
|
1338
|
-
//
|
|
1339
|
-
//
|
|
1354
|
+
// This function declares NO custom \`config.path\`, so it is reached at its
|
|
1355
|
+
// DEFAULT url (/.netlify/functions/${backgroundName}). The Nitro router only
|
|
1356
|
+
// knows the framework route, so we REWRITE the incoming pathname to
|
|
1357
|
+
// PROCESS_RUN_PATH before delegating. Method, ALL headers (the HMAC
|
|
1358
|
+
// Authorization: Bearer MUST survive — the plugin verifies it) and the body are
|
|
1359
|
+
// preserved by cloning the incoming Request with only its URL pathname set.
|
|
1340
1360
|
export default async function handler(request) {
|
|
1341
1361
|
cachedHandler ??= (await import("./main.mjs")).default;
|
|
1342
1362
|
const url = new URL(request.url);
|
|
@@ -1357,13 +1377,12 @@ export const config = {
|
|
|
1357
1377
|
name: "agent background handler",
|
|
1358
1378
|
generator: "agent-native build",
|
|
1359
1379
|
// background: true makes Netlify invoke this ASYNCHRONOUSLY (immediate HTTP
|
|
1360
|
-
// 202 ack) with the 15-minute budget
|
|
1361
|
-
//
|
|
1362
|
-
//
|
|
1363
|
-
//
|
|
1364
|
-
//
|
|
1365
|
-
//
|
|
1366
|
-
// build/functions/configuration.
|
|
1380
|
+
// 202 ack) with the 15-minute budget (Netlify docs:
|
|
1381
|
+
// build/functions/background-functions + build/functions/api). We declare NO
|
|
1382
|
+
// custom path, so the function keeps its DEFAULT url
|
|
1383
|
+
// /.netlify/functions/${backgroundName}; the Nitro \`server\` /* catch-all
|
|
1384
|
+
// already excludes /.netlify/* so that default url is never shadowed by the
|
|
1385
|
+
// synchronous function. The foreground dispatches to that default url.
|
|
1367
1386
|
background: true,
|
|
1368
1387
|
nodeBundler: "none",
|
|
1369
1388
|
includedFiles: ["**"],
|
|
@@ -1371,10 +1390,13 @@ export const config = {
|
|
|
1371
1390
|
};
|
|
1372
1391
|
`;
|
|
1373
1392
|
fs.writeFileSync(path.join(dest, `${backgroundName}.mjs`), entry);
|
|
1374
|
-
console.log(`[build] Emitted
|
|
1375
|
-
`
|
|
1376
|
-
|
|
1377
|
-
|
|
1393
|
+
console.log(`[build] Emitted durable-background function "${backgroundName}" into the ` +
|
|
1394
|
+
`scanned dir .netlify/functions-internal with config { background:true } ` +
|
|
1395
|
+
`and NO custom path — reachable at its default url ` +
|
|
1396
|
+
`/.netlify/functions/${backgroundName} (never shadowed; the server /* ` +
|
|
1397
|
+
`catch-all already excludes /.netlify/*). REQUIRES real-deploy ` +
|
|
1398
|
+
`verification of Netlify async (202) invocation — see ` +
|
|
1399
|
+
`docs/design/durable-agent-runs.md.`);
|
|
1378
1400
|
}
|
|
1379
1401
|
function copyInstalledLibsqlNativePackages(serverDir) {
|
|
1380
1402
|
if (!serverDir || !fs.existsSync(serverDir))
|