@agent-native/core 0.7.29 → 0.7.31

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.
Files changed (34) hide show
  1. package/dist/a2a/artifact-response.d.ts +9 -0
  2. package/dist/a2a/artifact-response.d.ts.map +1 -0
  3. package/dist/a2a/artifact-response.js +154 -0
  4. package/dist/a2a/artifact-response.js.map +1 -0
  5. package/dist/cli/create.d.ts.map +1 -1
  6. package/dist/cli/create.js +3 -0
  7. package/dist/cli/create.js.map +1 -1
  8. package/dist/cli/index.js +3 -0
  9. package/dist/cli/index.js.map +1 -1
  10. package/dist/cli/workspacify.d.ts.map +1 -1
  11. package/dist/cli/workspacify.js +5 -0
  12. package/dist/cli/workspacify.js.map +1 -1
  13. package/dist/deploy/workspace-deploy.d.ts +21 -1
  14. package/dist/deploy/workspace-deploy.d.ts.map +1 -1
  15. package/dist/deploy/workspace-deploy.js +187 -13
  16. package/dist/deploy/workspace-deploy.js.map +1 -1
  17. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  18. package/dist/server/agent-chat-plugin.js +27 -1
  19. package/dist/server/agent-chat-plugin.js.map +1 -1
  20. package/dist/server/builder-browser.d.ts +0 -1
  21. package/dist/server/builder-browser.d.ts.map +1 -1
  22. package/dist/server/builder-browser.js +14 -15
  23. package/dist/server/builder-browser.js.map +1 -1
  24. package/dist/templates/default/package.json +2 -1
  25. package/dist/templates/workspace-root/_gitignore +1 -0
  26. package/dist/templates/workspace-root/netlify.toml +8 -0
  27. package/dist/templates/workspace-root/package.json +2 -1
  28. package/docs/content/deployment.md +16 -2
  29. package/docs/content/multi-app-workspace.md +7 -1
  30. package/package.json +1 -1
  31. package/src/templates/default/package.json +2 -1
  32. package/src/templates/workspace-root/_gitignore +1 -0
  33. package/src/templates/workspace-root/netlify.toml +8 -0
  34. package/src/templates/workspace-root/package.json +2 -1
@@ -1 +1 @@
1
- {"version":3,"file":"workspacify.js","sourceRoot":"","sources":["../../src/cli/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EACvC,WAAW,IAAI,CAAC,OAAO,iBAAiB,CACzC,CAAC;YACJ,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxC,CAAC;QAAC,MAAM,CAAC;YACP,wCAAwC;QAC1C,CAAC;IACH,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,SAAS,EAAE,CAAC;QACtD,KAAK,MAAM,MAAM,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,EAAE,CAAC;YAClD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;YAClE,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;gBAAE,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,iBAAyB;IAC3D,MAAM,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACjD,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACvB,CAAC","sourcesContent":["/**\n * Transform a standalone template directory into a workspace app in place.\n *\n * Called after copying any template under `apps/<name>/` inside an enterprise\n * workspace. The transform:\n *\n * 1. Rewrites package.json:\n * - @agent-native/core stays as a regular npm dep\n * - Adds @<workspace-scope>/shared as a workspace:* dep so the app\n * inherits shared plugins/skills/AGENTS.md via the three-layer model.\n * 2. Removes files that only make sense in standalone apps\n * (`learnings.defaults.md`, etc.).\n * 3. Removes starter's stock auth/chat wrappers so the workspace core can\n * own those inherited plugin slots.\n * 4. Leaves app source code untouched. The three-layer framework\n * auto-discovers workspace-core via `agent-native.workspaceCore` in the\n * workspace root package.json — no per-app wiring needed.\n *\n * This means any first-party template under templates/* is usable as a\n * workspace app without maintaining a parallel copy.\n */\nimport fs from \"fs\";\nimport path from \"path\";\n\nexport interface WorkspacifyOptions {\n /** Target app directory (already populated with the copied template) */\n appDir: string;\n /** App name (e.g. \"mail\") */\n appName: string;\n /** Source template name (e.g. \"starter\" when appName is \"crm\") */\n templateName?: string;\n /** Workspace root directory */\n workspaceRoot: string;\n /** Shared workspace package name (e.g. \"@my-company/shared\") */\n workspaceCoreName: string;\n /** Version range to use for the published @agent-native/core package */\n coreDependencyVersion?: string;\n}\n\nexport function workspacifyApp(opts: WorkspacifyOptions): void {\n const { appDir, workspaceCoreName } = opts;\n const coreDependencyVersion = opts.coreDependencyVersion ?? \"latest\";\n\n // 1) Rewrite package.json to add the workspace core dep and resolve\n // @agent-native/core workspace:* refs to the CLI package's published\n // range (it's an npm package, not a workspace member). Other workspace:* deps (e.g.\n // @agent-native/scheduling) stay as-is — they resolve within the workspace\n // because the required package is scaffolded alongside the app.\n const pkgPath = path.join(appDir, \"package.json\");\n if (fs.existsSync(pkgPath)) {\n try {\n const pkg = JSON.parse(fs.readFileSync(pkgPath, \"utf-8\"));\n for (const depType of [\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n ] as const) {\n const deps = pkg[depType];\n if (!deps) continue;\n for (const [key, val] of Object.entries(deps)) {\n if (\n typeof val === \"string\" &&\n val.startsWith(\"workspace:\") &&\n key === \"@agent-native/core\"\n ) {\n deps[key] = coreDependencyVersion;\n }\n }\n }\n // Ensure the dependency on the workspace shared package is present.\n pkg.dependencies = pkg.dependencies ?? {};\n pkg.dependencies[workspaceCoreName] = \"workspace:*\";\n // pnpm build-script approvals belong at the workspace root. Leaving the\n // template's per-app setting in place makes pnpm warn on every install.\n if (pkg.pnpm && typeof pkg.pnpm === \"object\") {\n delete pkg.pnpm.onlyBuiltDependencies;\n if (Object.keys(pkg.pnpm).length === 0) {\n delete pkg.pnpm;\n }\n }\n fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + \"\\n\");\n } catch {\n // Non-fatal: leave package.json unchanged.\n }\n }\n\n // 2) Remove standalone-only files that would confuse the workspace layout.\n for (const f of [\n \"learnings.defaults.md\",\n // If the template shipped its own workspace marker / stray monorepo\n // files, strip them here too.\n ]) {\n const p = path.join(appDir, f);\n if (fs.existsSync(p)) fs.unlinkSync(p);\n }\n\n // 3) Templates document action commands from the framework repo layout.\n // Workspace apps live under apps/<name>, so point every agent at the\n // generated app directory instead.\n const agentsPath = path.join(appDir, \"AGENTS.md\");\n if (fs.existsSync(agentsPath)) {\n try {\n let content = fs.readFileSync(agentsPath, \"utf-8\");\n content = content\n .replace(\n \"The terminal cwd is the framework root. Always `cd` to this template's root before running any action:\",\n `The terminal cwd is the workspace root. Always \\`cd\\` to this app's root before running any action:`,\n )\n .replace(\n /cd templates\\/[^ \\n]+ && pnpm action/g,\n `cd apps/${opts.appName} && pnpm action`,\n );\n fs.writeFileSync(agentsPath, content);\n } catch {\n // Non-fatal: leave AGENTS.md unchanged.\n }\n }\n\n if ((opts.templateName ?? opts.appName) === \"starter\") {\n for (const plugin of [\"auth.ts\", \"agent-chat.ts\"]) {\n const pluginPath = path.join(appDir, \"server\", \"plugins\", plugin);\n if (fs.existsSync(pluginPath)) fs.unlinkSync(pluginPath);\n }\n }\n}\n\n/**\n * Parse a workspace core package name into its npm scope.\n * \"@my-company/shared\" → \"my-company\"\n * \"shared\" → \"\" (no scope — shouldn't happen)\n */\nexport function parseWorkspaceScope(workspaceCoreName: string): string {\n const m = workspaceCoreName.match(/^@([^/]+)\\//);\n return m ? m[1] : \"\";\n}\n"]}
1
+ {"version":3,"file":"workspacify.js","sourceRoot":"","sources":["../../src/cli/workspacify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,2BAA2B,GAAG,QAAQ,CAAC;AAiB7C,MAAM,UAAU,cAAc,CAAC,IAAwB;I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AAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxC,CAAC;QAAC,MAAM,CAAC;YACP,wCAAwC;QAC1C,CAAC;IACH,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,SAAS,EAAE,CAAC;QACtD,KAAK,MAAM,MAAM,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,EAAE,CAAC;YAClD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;YAClE,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;gBAAE,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,iBAAyB;IAC3D,MAAM,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACjD,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACvB,CAAC","sourcesContent":["/**\n * Transform a standalone template directory into a workspace app in place.\n *\n * Called after copying any template under `apps/<name>/` inside an enterprise\n * workspace. The transform:\n *\n * 1. Rewrites package.json:\n * - @agent-native/core stays as a regular npm dep\n * - Adds @<workspace-scope>/shared as a workspace:* dep so the app\n * inherits shared plugins/skills/AGENTS.md via the three-layer model.\n * 2. Removes files that only make sense in standalone apps\n * (`learnings.defaults.md`, etc.).\n * 3. Removes starter's stock auth/chat wrappers so the workspace core can\n * own those inherited plugin slots.\n * 4. Leaves app source code untouched. The three-layer framework\n * auto-discovers workspace-core via `agent-native.workspaceCore` in the\n * workspace root package.json — no per-app wiring needed.\n *\n * This means any first-party template under templates/* is usable as a\n * workspace app without maintaining a parallel copy.\n */\nimport fs from \"fs\";\nimport path from \"path\";\n\nconst POSTGRES_DEPENDENCY_VERSION = \"^3.4.9\";\n\nexport interface WorkspacifyOptions {\n /** Target app directory (already populated with the copied template) */\n appDir: string;\n /** App name (e.g. \"mail\") */\n appName: string;\n /** Source template name (e.g. \"starter\" when appName is \"crm\") */\n templateName?: string;\n /** Workspace root directory */\n workspaceRoot: string;\n /** Shared workspace package name (e.g. \"@my-company/shared\") */\n workspaceCoreName: string;\n /** Version range to use for the published @agent-native/core package */\n coreDependencyVersion?: string;\n}\n\nexport function workspacifyApp(opts: WorkspacifyOptions): void {\n const { appDir, workspaceCoreName } = opts;\n const coreDependencyVersion = opts.coreDependencyVersion ?? \"latest\";\n\n // 1) Rewrite package.json to add the workspace core dep and resolve\n // @agent-native/core workspace:* refs to the CLI package's published\n // range (it's an npm package, not a workspace member). Other workspace:* deps (e.g.\n // @agent-native/scheduling) stay as-is — they resolve within the workspace\n // because the required package is scaffolded alongside the app.\n const pkgPath = path.join(appDir, \"package.json\");\n if (fs.existsSync(pkgPath)) {\n try {\n const pkg = JSON.parse(fs.readFileSync(pkgPath, \"utf-8\"));\n for (const depType of [\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n ] as const) {\n const deps = pkg[depType];\n if (!deps) continue;\n for (const [key, val] of Object.entries(deps)) {\n if (\n typeof val === \"string\" &&\n val.startsWith(\"workspace:\") &&\n key === \"@agent-native/core\"\n ) {\n deps[key] = coreDependencyVersion;\n }\n }\n }\n // Ensure the dependency on the workspace shared package is present.\n pkg.dependencies = pkg.dependencies ?? {};\n pkg.dependencies[workspaceCoreName] = \"workspace:*\";\n // Core loads postgres-js lazily when DATABASE_URL points at Postgres.\n // Add the runtime package to workspace apps so production bundles do\n // not fail only after a hosted Postgres database is configured.\n pkg.dependencies.postgres ??= POSTGRES_DEPENDENCY_VERSION;\n // pnpm build-script approvals belong at the workspace root. Leaving the\n // template's per-app setting in place makes pnpm warn on every install.\n if (pkg.pnpm && typeof pkg.pnpm === \"object\") {\n delete pkg.pnpm.onlyBuiltDependencies;\n if (Object.keys(pkg.pnpm).length === 0) {\n delete pkg.pnpm;\n }\n }\n fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + \"\\n\");\n } catch {\n // Non-fatal: leave package.json unchanged.\n }\n }\n\n // 2) Remove standalone-only files that would confuse the workspace layout.\n for (const f of [\n \"learnings.defaults.md\",\n // If the template shipped its own workspace marker / stray monorepo\n // files, strip them here too.\n ]) {\n const p = path.join(appDir, f);\n if (fs.existsSync(p)) fs.unlinkSync(p);\n }\n\n // 3) Templates document action commands from the framework repo layout.\n // Workspace apps live under apps/<name>, so point every agent at the\n // generated app directory instead.\n const agentsPath = path.join(appDir, \"AGENTS.md\");\n if (fs.existsSync(agentsPath)) {\n try {\n let content = fs.readFileSync(agentsPath, \"utf-8\");\n content = content\n .replace(\n \"The terminal cwd is the framework root. Always `cd` to this template's root before running any action:\",\n `The terminal cwd is the workspace root. Always \\`cd\\` to this app's root before running any action:`,\n )\n .replace(\n /cd templates\\/[^ \\n]+ && pnpm action/g,\n `cd apps/${opts.appName} && pnpm action`,\n );\n fs.writeFileSync(agentsPath, content);\n } catch {\n // Non-fatal: leave AGENTS.md unchanged.\n }\n }\n\n if ((opts.templateName ?? opts.appName) === \"starter\") {\n for (const plugin of [\"auth.ts\", \"agent-chat.ts\"]) {\n const pluginPath = path.join(appDir, \"server\", \"plugins\", plugin);\n if (fs.existsSync(pluginPath)) fs.unlinkSync(pluginPath);\n }\n }\n}\n\n/**\n * Parse a workspace core package name into its npm scope.\n * \"@my-company/shared\" → \"my-company\"\n * \"shared\" → \"\" (no scope — shouldn't happen)\n */\nexport function parseWorkspaceScope(workspaceCoreName: string): string {\n const m = workspaceCoreName.match(/^@([^/]+)\\//);\n return m ? m[1] : \"\";\n}\n"]}
@@ -1,3 +1,21 @@
1
+ /**
2
+ * `agent-native deploy` — build and deploy every app in a workspace to a
3
+ * single origin. Each app is served from `/<app-name>/*`, so:
4
+ *
5
+ * https://your-agents.com/mail/* → apps/mail
6
+ * https://your-agents.com/calendar/* → apps/calendar
7
+ *
8
+ * Benefits of same-origin deploy:
9
+ * - Shared auth cookie → log in once, every app is signed in
10
+ * - Cross-app A2A is a same-origin fetch (no CORS, no JWT for siblings)
11
+ * - One DNS record, one TLS cert, one CDN cache
12
+ *
13
+ * Per-app independent deploy is still supported — just cd into the app and
14
+ * run `agent-native build` as before. This orchestrator is for teams that
15
+ * want the whole workspace behind one domain.
16
+ */
17
+ import { execFileSync } from "child_process";
18
+ export type WorkspaceDeployPreset = "cloudflare_pages" | "netlify";
1
19
  export interface WorkspaceDeployOptions {
2
20
  args?: string[];
3
21
  /** Override the workspace root (defaults to walking up from cwd). */
@@ -5,7 +23,9 @@ export interface WorkspaceDeployOptions {
5
23
  /** Only build — don't invoke the deploy platform CLI. */
6
24
  buildOnly?: boolean;
7
25
  /** Target preset. Defaults to `cloudflare_pages`. */
8
- preset?: "cloudflare_pages";
26
+ preset?: WorkspaceDeployPreset;
27
+ /** @internal Override process execution in tests. */
28
+ execFile?: typeof execFileSync;
9
29
  }
10
30
  export declare function runWorkspaceDeploy(opts?: WorkspaceDeployOptions): Promise<void>;
11
31
  //# sourceMappingURL=workspace-deploy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-deploy.d.ts","sourceRoot":"","sources":["../../src/deploy/workspace-deploy.ts"],"names":[],"mappings":"AAqBA,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,yDAAyD;IACzD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,qDAAqD;IACrD,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC7B;AAED,wBAAsB,kBAAkB,CACtC,IAAI,GAAE,sBAA2B,GAChC,OAAO,CAAC,IAAI,CAAC,CAsDf"}
1
+ {"version":3,"file":"workspace-deploy.d.ts","sourceRoot":"","sources":["../../src/deploy/workspace-deploy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAK7C,MAAM,MAAM,qBAAqB,GAAG,kBAAkB,GAAG,SAAS,CAAC;AAEnE,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,yDAAyD;IACzD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,qDAAqD;IACrD,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,qDAAqD;IACrD,QAAQ,CAAC,EAAE,OAAO,YAAY,CAAC;CAChC;AAED,wBAAsB,kBAAkB,CACtC,IAAI,GAAE,sBAA2B,GAChC,OAAO,CAAC,IAAI,CAAC,CAwEf"}
@@ -24,7 +24,8 @@ export async function runWorkspaceDeploy(opts = {}) {
24
24
  if (!fs.existsSync(appsDir)) {
25
25
  throw new Error(`No apps/ directory found at ${workspaceRoot}. Run this inside an agent-native workspace.`);
26
26
  }
27
- const args = new Set(opts.args ?? []);
27
+ const rawArgs = opts.args ?? [];
28
+ const args = new Set(rawArgs);
28
29
  const buildOnly = opts.buildOnly ?? args.has("--build-only");
29
30
  const apps = fs
30
31
  .readdirSync(appsDir, { withFileTypes: true })
@@ -34,40 +35,64 @@ export async function runWorkspaceDeploy(opts = {}) {
34
35
  if (apps.length === 0) {
35
36
  throw new Error(`Workspace has no apps. Run \`agent-native add-app\` to add one.`);
36
37
  }
37
- const preset = opts.preset ?? "cloudflare_pages";
38
+ const preset = resolvePreset(opts.preset, rawArgs);
38
39
  const distDir = path.join(workspaceRoot, "dist");
39
40
  fs.rmSync(distDir, { recursive: true, force: true });
40
41
  fs.mkdirSync(distDir, { recursive: true });
42
+ if (preset === "netlify") {
43
+ const functionsDir = netlifyFunctionsDir(workspaceRoot);
44
+ fs.rmSync(functionsDir, { recursive: true, force: true });
45
+ fs.mkdirSync(functionsDir, { recursive: true });
46
+ }
41
47
  console.log(`[workspace-deploy] Building ${apps.length} app(s) for preset=${preset}`);
48
+ const execFile = opts.execFile ?? execFileSync;
42
49
  for (const app of apps) {
43
- buildOneApp(workspaceRoot, app, preset);
44
- moveAppBuildIntoDist(workspaceRoot, app, distDir);
50
+ buildOneApp(workspaceRoot, app, preset, execFile);
51
+ moveAppBuildIntoDist(workspaceRoot, app, distDir, preset);
52
+ }
53
+ if (preset === "netlify") {
54
+ writeNetlifyRedirects(distDir, apps);
55
+ }
56
+ else {
57
+ writeCloudflareRoutingManifest(distDir, apps);
45
58
  }
46
- writeWorkspaceRoutingManifest(distDir, apps);
47
59
  if (buildOnly) {
48
60
  console.log(`\n[workspace-deploy] Build complete at ${distDir}. Skipping publish (--build-only).`);
49
61
  return;
50
62
  }
51
63
  console.log(`\n[workspace-deploy] Build complete. Publish with:\n`);
52
64
  console.log(` cd ${path.relative(process.cwd(), workspaceRoot) || "."}`);
53
- console.log(` wrangler pages deploy dist\n`);
65
+ if (preset === "netlify") {
66
+ console.log(` netlify deploy --prod --dir=dist --functions=.netlify/functions-internal\n`);
67
+ }
68
+ else {
69
+ console.log(` wrangler pages deploy dist\n`);
70
+ }
54
71
  console.log(`All apps live at https://<origin>/<app-name>/*. Log in once on any app\nand the session is shared across the workspace.`);
55
72
  }
56
- function buildOneApp(workspaceRoot, app, preset) {
73
+ function buildOneApp(workspaceRoot, app, preset, execFile) {
74
+ const appDir = path.join(workspaceRoot, "apps", app);
57
75
  const env = {
58
76
  ...process.env,
59
77
  NITRO_PRESET: preset,
60
78
  APP_BASE_PATH: `/${app}`,
61
79
  VITE_APP_BASE_PATH: `/${app}`,
62
80
  };
81
+ if (preset === "netlify" && appUsesNetlifyUnpooledDatabaseUrl(appDir)) {
82
+ env.DATABASE_URL =
83
+ process.env.NETLIFY_DATABASE_URL_UNPOOLED ??
84
+ process.env.DATABASE_URL ??
85
+ env.DATABASE_URL;
86
+ }
63
87
  console.log(`[workspace-deploy] Building ${app} (base=/${app}, preset=${preset})`);
64
- execFileSync("pnpm", ["--filter", app, "build"], {
88
+ cleanAppBuildOutputs(appDir);
89
+ execFile("pnpm", ["--filter", app, "build"], {
65
90
  cwd: workspaceRoot,
66
91
  env,
67
92
  stdio: "inherit",
68
93
  });
69
94
  }
70
- function moveAppBuildIntoDist(workspaceRoot, app, distDir) {
95
+ function moveAppBuildIntoDist(workspaceRoot, app, distDir, preset) {
71
96
  const appDir = path.join(workspaceRoot, "apps", app);
72
97
  // Resolve the per-app build output: prefer dist/ (standard), fall back to
73
98
  // .output/ (Nitro's default). The Cloudflare preset emits into dist/
@@ -79,15 +104,29 @@ function moveAppBuildIntoDist(workspaceRoot, app, distDir) {
79
104
  if (!src) {
80
105
  throw new Error(`Expected ${candidates.join(" or ")} under ${appDir} but none existed. Check the app's build script.`);
81
106
  }
82
- const target = path.join(distDir, app);
83
- fs.mkdirSync(target, { recursive: true });
84
- copyDir(src, target);
107
+ if (preset === "netlify") {
108
+ const mountedSrc = path.join(src, app);
109
+ const staticSrc = fs.existsSync(mountedSrc) ? mountedSrc : src;
110
+ const target = path.join(distDir, app);
111
+ fs.mkdirSync(target, { recursive: true });
112
+ copyDir(staticSrc, target);
113
+ // Nitro/Vite mounted builds can contain a nested copy of public assets at
114
+ // dist/<app>/<app>/...; the workspace root already supplies the outer
115
+ // mount path, so keeping it would publish duplicate /<app>/<app> URLs.
116
+ fs.rmSync(path.join(target, app), { recursive: true, force: true });
117
+ copyNetlifyFunctionIntoWorkspace(workspaceRoot, app);
118
+ }
119
+ else {
120
+ const target = path.join(distDir, app);
121
+ fs.mkdirSync(target, { recursive: true });
122
+ copyDir(src, target);
123
+ }
85
124
  }
86
125
  /**
87
126
  * Write the Cloudflare Pages `_routes.json` and a dispatcher `_worker.js` at
88
127
  * the workspace dist root so each app is reachable under /<app>/*.
89
128
  */
90
- function writeWorkspaceRoutingManifest(distDir, apps) {
129
+ function writeCloudflareRoutingManifest(distDir, apps) {
91
130
  // _routes.json tells Cloudflare which paths are dynamic (Functions) vs
92
131
  // static. Mark /<app>/* as include so every app's worker handles its
93
132
  // subtree.
@@ -120,6 +159,141 @@ ${dispatch}
120
159
  `;
121
160
  fs.writeFileSync(path.join(distDir, "_worker.js"), worker);
122
161
  }
162
+ function writeNetlifyRedirects(distDir, apps) {
163
+ const lines = [
164
+ "# Generated by agent-native deploy --preset netlify",
165
+ "# No forced rewrites: Netlify should serve static files from dist/ first.",
166
+ ];
167
+ if (apps.includes("dispatch")) {
168
+ lines.push("/ /dispatch/overview 302");
169
+ lines.push("/dispatch /dispatch/overview 302");
170
+ for (const [from, to] of DISPATCH_WORKSPACE_ROOT_REDIRECTS) {
171
+ lines.push(`/${from} /dispatch/${to} 302`);
172
+ }
173
+ }
174
+ else {
175
+ lines.push(`/ /${apps[0]}/ 302`);
176
+ }
177
+ fs.writeFileSync(path.join(distDir, "_redirects"), lines.join("\n") + "\n");
178
+ }
179
+ const DISPATCH_WORKSPACE_ROOT_REDIRECTS = [
180
+ ["overview", "overview"],
181
+ ["apps", "apps"],
182
+ ["new-app", "new-app"],
183
+ ["vault", "vault"],
184
+ ["integrations", "integrations"],
185
+ ["agents", "agents"],
186
+ ["workspace", "workspace"],
187
+ ["messaging", "messaging"],
188
+ ["destinations", "destinations"],
189
+ ["identities", "identities"],
190
+ ["approvals", "approvals"],
191
+ ["audit", "audit"],
192
+ ["team", "team"],
193
+ ];
194
+ function copyNetlifyFunctionIntoWorkspace(workspaceRoot, app) {
195
+ const appDir = path.join(workspaceRoot, "apps", app);
196
+ const src = path.join(appDir, ".netlify", "functions-internal", "server");
197
+ if (!fs.existsSync(src)) {
198
+ throw new Error(`Expected Netlify function at ${src} after building ${app}. Check the app's build script and NITRO_PRESET.`);
199
+ }
200
+ const dest = path.join(netlifyFunctionsDir(workspaceRoot), `${app}-server`);
201
+ fs.rmSync(dest, { recursive: true, force: true });
202
+ copyDir(src, dest);
203
+ patchNetlifyFunctionEntry(dest, app);
204
+ }
205
+ function patchNetlifyFunctionEntry(functionDir, app) {
206
+ const serverPath = path.join(functionDir, "server.mjs");
207
+ if (!fs.existsSync(serverPath))
208
+ return;
209
+ const basePath = `/${app}`;
210
+ const server = `const basePath = ${JSON.stringify(basePath)};
211
+
212
+ function setBasePathEnv() {
213
+ const processRef = globalThis.process ??= { env: {} };
214
+ processRef.env ??= {};
215
+ Object.assign(processRef.env, {
216
+ APP_BASE_PATH: basePath,
217
+ VITE_APP_BASE_PATH: basePath,
218
+ });
219
+ }
220
+
221
+ setBasePathEnv();
222
+
223
+ let cachedHandler;
224
+
225
+ export default async function handler(...args) {
226
+ setBasePathEnv();
227
+ cachedHandler ??= (await import("./main.mjs")).default;
228
+ return cachedHandler(...args);
229
+ }
230
+
231
+ export const config = {
232
+ name: ${JSON.stringify(`${app} server handler`)},
233
+ generator: "agent-native workspace deploy",
234
+ path: ${JSON.stringify(`${basePath}/*`)},
235
+ nodeBundler: "none",
236
+ includedFiles: ["**"],
237
+ excludedPath: ["/.netlify/*"],
238
+ preferStatic: true,
239
+ };
240
+ `;
241
+ fs.rmSync(serverPath, { force: true });
242
+ fs.writeFileSync(path.join(functionDir, `${app}-server.mjs`), server);
243
+ }
244
+ function netlifyFunctionsDir(workspaceRoot) {
245
+ return path.join(workspaceRoot, ".netlify", "functions-internal");
246
+ }
247
+ function cleanAppBuildOutputs(appDir) {
248
+ for (const name of ["dist", ".output", "build"]) {
249
+ fs.rmSync(path.join(appDir, name), { recursive: true, force: true });
250
+ }
251
+ fs.rmSync(path.join(appDir, ".netlify", "functions-internal"), {
252
+ recursive: true,
253
+ force: true,
254
+ });
255
+ }
256
+ function appUsesNetlifyUnpooledDatabaseUrl(appDir) {
257
+ const netlifyPath = path.join(appDir, "netlify.toml");
258
+ if (!fs.existsSync(netlifyPath))
259
+ return false;
260
+ try {
261
+ return fs
262
+ .readFileSync(netlifyPath, "utf-8")
263
+ .includes("NETLIFY_DATABASE_URL_UNPOOLED");
264
+ }
265
+ catch {
266
+ return false;
267
+ }
268
+ }
269
+ function parsePresetArg(args) {
270
+ for (let i = 0; i < args.length; i++) {
271
+ const arg = args[i];
272
+ if (arg === "--preset" && args[i + 1]) {
273
+ return normalizePreset(args[i + 1]);
274
+ }
275
+ if (arg.startsWith("--preset=")) {
276
+ return normalizePreset(arg.slice("--preset=".length));
277
+ }
278
+ }
279
+ return null;
280
+ }
281
+ function resolvePreset(optionPreset, args) {
282
+ return (optionPreset ??
283
+ parsePresetArg(args) ??
284
+ normalizePreset(process.env.NITRO_PRESET) ??
285
+ "cloudflare_pages");
286
+ }
287
+ function normalizePreset(value) {
288
+ if (!value)
289
+ return null;
290
+ if (value === "cloudflare_pages" || value === "cloudflare-pages") {
291
+ return "cloudflare_pages";
292
+ }
293
+ if (value === "netlify")
294
+ return "netlify";
295
+ throw new Error(`Unsupported workspace deploy preset "${value}". Supported presets: cloudflare_pages, netlify.`);
296
+ }
123
297
  function moduleIdent(app) {
124
298
  return "app_" + app.replace(/[^a-zA-Z0-9_]/g, "_");
125
299
  }
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-deploy.js","sourceRoot":"","sources":["../../src/deploy/workspace-deploy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAYxD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAA+B,EAAE;IAEjC,MAAM,aAAa,GACjB,IAAI,CAAC,aAAa,IAAI,iBAAiB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1E,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IACjD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,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,CAAC;gBAClC,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YAC5B,CAAC;YAAC,MAAM,CAAC;gBACP,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;aAAM,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YAC/B,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAChB,CAAC;aAAM,CAAC;YACN,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/**\n * `agent-native deploy` — build and deploy every app in a workspace to a\n * single origin. Each app is served from `/<app-name>/*`, so:\n *\n * https://your-agents.com/mail/* → apps/mail\n * https://your-agents.com/calendar/* → apps/calendar\n *\n * Benefits of same-origin deploy:\n * - Shared auth cookie → log in once, every app is signed in\n * - Cross-app A2A is a same-origin fetch (no CORS, no JWT for siblings)\n * - One DNS record, one TLS cert, one CDN cache\n *\n * Per-app independent deploy is still supported — just cd into the app and\n * run `agent-native build` as before. This orchestrator is for teams that\n * want the whole workspace behind one domain.\n */\nimport { execFileSync } from \"child_process\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { findWorkspaceRoot } from \"../scripts/utils.js\";\n\nexport interface WorkspaceDeployOptions {\n args?: string[];\n /** Override the workspace root (defaults to walking up from cwd). */\n workspaceRoot?: string;\n /** Only build — don't invoke the deploy platform CLI. */\n buildOnly?: boolean;\n /** Target preset. Defaults to `cloudflare_pages`. */\n preset?: \"cloudflare_pages\";\n}\n\nexport async function runWorkspaceDeploy(\n opts: WorkspaceDeployOptions = {},\n): Promise<void> {\n const workspaceRoot =\n opts.workspaceRoot ?? findWorkspaceRoot(process.cwd()) ?? process.cwd();\n const appsDir = path.join(workspaceRoot, \"apps\");\n if (!fs.existsSync(appsDir)) {\n throw new Error(\n `No apps/ directory found at ${workspaceRoot}. Run this inside an agent-native workspace.`,\n );\n }\n\n const args = new Set(opts.args ?? []);\n const buildOnly = opts.buildOnly ?? args.has(\"--build-only\");\n\n const apps = fs\n .readdirSync(appsDir, { withFileTypes: true })\n .filter((e) => e.isDirectory())\n .map((e) => e.name)\n .filter((n) => fs.existsSync(path.join(appsDir, n, \"package.json\")));\n\n if (apps.length === 0) {\n throw new Error(\n `Workspace has no apps. Run \\`agent-native add-app\\` to add one.`,\n );\n }\n\n const preset = opts.preset ?? \"cloudflare_pages\";\n const distDir = path.join(workspaceRoot, \"dist\");\n fs.rmSync(distDir, { recursive: true, force: true });\n fs.mkdirSync(distDir, { recursive: true });\n\n console.log(\n `[workspace-deploy] Building ${apps.length} app(s) for preset=${preset}`,\n );\n\n for (const app of apps) {\n buildOneApp(workspaceRoot, app, preset);\n moveAppBuildIntoDist(workspaceRoot, app, distDir);\n }\n\n writeWorkspaceRoutingManifest(distDir, apps);\n\n if (buildOnly) {\n console.log(\n `\\n[workspace-deploy] Build complete at ${distDir}. Skipping publish (--build-only).`,\n );\n return;\n }\n\n console.log(`\\n[workspace-deploy] Build complete. Publish with:\\n`);\n console.log(` cd ${path.relative(process.cwd(), workspaceRoot) || \".\"}`);\n console.log(` wrangler pages deploy dist\\n`);\n console.log(\n `All apps live at https://<origin>/<app-name>/*. Log in once on any app\\nand the session is shared across the workspace.`,\n );\n}\n\nfunction buildOneApp(workspaceRoot: string, app: string, preset: string): void {\n const env = {\n ...process.env,\n NITRO_PRESET: preset,\n APP_BASE_PATH: `/${app}`,\n VITE_APP_BASE_PATH: `/${app}`,\n };\n\n console.log(\n `[workspace-deploy] Building ${app} (base=/${app}, preset=${preset})`,\n );\n\n execFileSync(\"pnpm\", [\"--filter\", app, \"build\"], {\n cwd: workspaceRoot,\n env,\n stdio: \"inherit\",\n });\n}\n\nfunction moveAppBuildIntoDist(\n workspaceRoot: string,\n app: string,\n distDir: string,\n): void {\n const appDir = path.join(workspaceRoot, \"apps\", app);\n // Resolve the per-app build output: prefer dist/ (standard), fall back to\n // .output/ (Nitro's default). The Cloudflare preset emits into dist/\n // containing the worker + assets.\n const candidates = [\"dist\", \".output\"];\n const src = candidates\n .map((c) => path.join(appDir, c))\n .find((p) => fs.existsSync(p));\n if (!src) {\n throw new Error(\n `Expected ${candidates.join(\" or \")} under ${appDir} but none existed. Check the app's build script.`,\n );\n }\n const target = path.join(distDir, app);\n fs.mkdirSync(target, { recursive: true });\n copyDir(src, target);\n}\n\n/**\n * Write the Cloudflare Pages `_routes.json` and a dispatcher `_worker.js` at\n * the workspace dist root so each app is reachable under /<app>/*.\n */\nfunction writeWorkspaceRoutingManifest(distDir: string, apps: string[]): void {\n // _routes.json tells Cloudflare which paths are dynamic (Functions) vs\n // static. Mark /<app>/* as include so every app's worker handles its\n // subtree.\n const routes = {\n version: 1,\n include: apps.map((a) => `/${a}/*`).concat([\"/\"]),\n exclude: [],\n };\n fs.writeFileSync(\n path.join(distDir, \"_routes.json\"),\n JSON.stringify(routes, null, 2) + \"\\n\",\n );\n\n // Dispatcher worker: inspects the path and forwards to the matching\n // per-app worker.\n const imports = apps\n .map((a) => `import ${moduleIdent(a)} from \"./${a}/_worker.js\";`)\n .join(\"\\n\");\n const dispatch = apps\n .map(\n (a) =>\n ` if (pathname === \"/${a}\" || pathname.startsWith(\"/${a}/\")) return ${moduleIdent(a)}.fetch(request, env, ctx);`,\n )\n .join(\"\\n\");\n\n const worker = `${imports}\n\nexport default {\n async fetch(request, env, ctx) {\n const { pathname } = new URL(request.url);\n${dispatch}\n if (pathname === \"/\") {\n return Response.redirect(new URL(\"/${apps[0]}/\", request.url).toString(), 302);\n }\n return new Response(\"Not found\", { status: 404 });\n },\n};\n`;\n fs.writeFileSync(path.join(distDir, \"_worker.js\"), worker);\n}\n\nfunction moduleIdent(app: string): string {\n return \"app_\" + app.replace(/[^a-zA-Z0-9_]/g, \"_\");\n}\n\nfunction copyDir(src: string, dest: string): void {\n fs.mkdirSync(dest, { recursive: true });\n for (const entry of fs.readdirSync(src, { withFileTypes: true })) {\n const s = path.join(src, entry.name);\n const d = path.join(dest, entry.name);\n if (entry.isSymbolicLink()) {\n try {\n const target = fs.readlinkSync(s);\n fs.symlinkSync(target, d);\n } catch {\n fs.copyFileSync(s, d);\n }\n } else if (entry.isDirectory()) {\n copyDir(s, d);\n } else {\n fs.copyFileSync(s, d);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"workspace-deploy.js","sourceRoot":"","sources":["../../src/deploy/workspace-deploy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAgBxD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAA+B,EAAE;IAEjC,MAAM,aAAa,GACjB,IAAI,CAAC,aAAa,IAAI,iBAAiB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1E,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IACjD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACb,+BAA+B,aAAa,8CAA8C,CAC3F,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;IAChC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9B,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAE7D,MAAM,IAAI,GAAG,EAAE;SACZ,WAAW,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;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P,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;aAAM,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YAC/B,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAChB,CAAC;aAAM,CAAC;YACN,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/**\n * `agent-native deploy` — build and deploy every app in a workspace to a\n * single origin. Each app is served from `/<app-name>/*`, so:\n *\n * https://your-agents.com/mail/* → apps/mail\n * https://your-agents.com/calendar/* → apps/calendar\n *\n * Benefits of same-origin deploy:\n * - Shared auth cookie → log in once, every app is signed in\n * - Cross-app A2A is a same-origin fetch (no CORS, no JWT for siblings)\n * - One DNS record, one TLS cert, one CDN cache\n *\n * Per-app independent deploy is still supported — just cd into the app and\n * run `agent-native build` as before. This orchestrator is for teams that\n * want the whole workspace behind one domain.\n */\nimport { execFileSync } from \"child_process\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { findWorkspaceRoot } from \"../scripts/utils.js\";\n\nexport type WorkspaceDeployPreset = \"cloudflare_pages\" | \"netlify\";\n\nexport interface WorkspaceDeployOptions {\n args?: string[];\n /** Override the workspace root (defaults to walking up from cwd). */\n workspaceRoot?: string;\n /** Only build — don't invoke the deploy platform CLI. */\n buildOnly?: boolean;\n /** Target preset. Defaults to `cloudflare_pages`. */\n preset?: WorkspaceDeployPreset;\n /** @internal Override process execution in tests. */\n execFile?: typeof execFileSync;\n}\n\nexport async function runWorkspaceDeploy(\n opts: WorkspaceDeployOptions = {},\n): Promise<void> {\n const workspaceRoot =\n opts.workspaceRoot ?? findWorkspaceRoot(process.cwd()) ?? process.cwd();\n const appsDir = path.join(workspaceRoot, \"apps\");\n if (!fs.existsSync(appsDir)) {\n throw new Error(\n `No apps/ directory found at ${workspaceRoot}. Run this inside an agent-native workspace.`,\n );\n }\n\n const rawArgs = opts.args ?? [];\n const args = new Set(rawArgs);\n const buildOnly = opts.buildOnly ?? args.has(\"--build-only\");\n\n const apps = fs\n .readdirSync(appsDir, { withFileTypes: true })\n .filter((e) => e.isDirectory())\n .map((e) => e.name)\n .filter((n) => fs.existsSync(path.join(appsDir, n, \"package.json\")));\n\n if (apps.length === 0) {\n throw new Error(\n `Workspace has no apps. Run \\`agent-native add-app\\` to add one.`,\n );\n }\n\n const preset = resolvePreset(opts.preset, rawArgs);\n const distDir = path.join(workspaceRoot, \"dist\");\n fs.rmSync(distDir, { recursive: true, force: true });\n fs.mkdirSync(distDir, { recursive: true });\n\n if (preset === \"netlify\") {\n const functionsDir = netlifyFunctionsDir(workspaceRoot);\n fs.rmSync(functionsDir, { recursive: true, force: true });\n fs.mkdirSync(functionsDir, { recursive: true });\n }\n\n console.log(\n `[workspace-deploy] Building ${apps.length} app(s) for preset=${preset}`,\n );\n\n const execFile = opts.execFile ?? execFileSync;\n for (const app of apps) {\n buildOneApp(workspaceRoot, app, preset, execFile);\n moveAppBuildIntoDist(workspaceRoot, app, distDir, preset);\n }\n\n if (preset === \"netlify\") {\n writeNetlifyRedirects(distDir, apps);\n } else {\n writeCloudflareRoutingManifest(distDir, apps);\n }\n\n if (buildOnly) {\n console.log(\n `\\n[workspace-deploy] Build complete at ${distDir}. Skipping publish (--build-only).`,\n );\n return;\n }\n\n console.log(`\\n[workspace-deploy] Build complete. Publish with:\\n`);\n console.log(` cd ${path.relative(process.cwd(), workspaceRoot) || \".\"}`);\n if (preset === \"netlify\") {\n console.log(\n ` netlify deploy --prod --dir=dist --functions=.netlify/functions-internal\\n`,\n );\n } else {\n console.log(` wrangler pages deploy dist\\n`);\n }\n console.log(\n `All apps live at https://<origin>/<app-name>/*. Log in once on any app\\nand the session is shared across the workspace.`,\n );\n}\n\nfunction buildOneApp(\n workspaceRoot: string,\n app: string,\n preset: WorkspaceDeployPreset,\n execFile: typeof execFileSync,\n): void {\n const appDir = path.join(workspaceRoot, \"apps\", app);\n const env: NodeJS.ProcessEnv = {\n ...process.env,\n NITRO_PRESET: preset,\n APP_BASE_PATH: `/${app}`,\n VITE_APP_BASE_PATH: `/${app}`,\n };\n\n if (preset === \"netlify\" && appUsesNetlifyUnpooledDatabaseUrl(appDir)) {\n env.DATABASE_URL =\n process.env.NETLIFY_DATABASE_URL_UNPOOLED ??\n process.env.DATABASE_URL ??\n env.DATABASE_URL;\n }\n\n console.log(\n `[workspace-deploy] Building ${app} (base=/${app}, preset=${preset})`,\n );\n\n cleanAppBuildOutputs(appDir);\n\n execFile(\"pnpm\", [\"--filter\", app, \"build\"], {\n cwd: workspaceRoot,\n env,\n stdio: \"inherit\",\n });\n}\n\nfunction moveAppBuildIntoDist(\n workspaceRoot: string,\n app: string,\n distDir: string,\n preset: WorkspaceDeployPreset,\n): void {\n const appDir = path.join(workspaceRoot, \"apps\", app);\n // Resolve the per-app build output: prefer dist/ (standard), fall back to\n // .output/ (Nitro's default). The Cloudflare preset emits into dist/\n // containing the worker + assets.\n const candidates = [\"dist\", \".output\"];\n const src = candidates\n .map((c) => path.join(appDir, c))\n .find((p) => fs.existsSync(p));\n if (!src) {\n throw new Error(\n `Expected ${candidates.join(\" or \")} under ${appDir} but none existed. Check the app's build script.`,\n );\n }\n if (preset === \"netlify\") {\n const mountedSrc = path.join(src, app);\n const staticSrc = fs.existsSync(mountedSrc) ? mountedSrc : src;\n const target = path.join(distDir, app);\n fs.mkdirSync(target, { recursive: true });\n copyDir(staticSrc, target);\n // Nitro/Vite mounted builds can contain a nested copy of public assets at\n // dist/<app>/<app>/...; the workspace root already supplies the outer\n // mount path, so keeping it would publish duplicate /<app>/<app> URLs.\n fs.rmSync(path.join(target, app), { recursive: true, force: true });\n copyNetlifyFunctionIntoWorkspace(workspaceRoot, app);\n } else {\n const target = path.join(distDir, app);\n fs.mkdirSync(target, { recursive: true });\n copyDir(src, target);\n }\n}\n\n/**\n * Write the Cloudflare Pages `_routes.json` and a dispatcher `_worker.js` at\n * the workspace dist root so each app is reachable under /<app>/*.\n */\nfunction writeCloudflareRoutingManifest(distDir: string, apps: string[]): void {\n // _routes.json tells Cloudflare which paths are dynamic (Functions) vs\n // static. Mark /<app>/* as include so every app's worker handles its\n // subtree.\n const routes = {\n version: 1,\n include: apps.map((a) => `/${a}/*`).concat([\"/\"]),\n exclude: [],\n };\n fs.writeFileSync(\n path.join(distDir, \"_routes.json\"),\n JSON.stringify(routes, null, 2) + \"\\n\",\n );\n\n // Dispatcher worker: inspects the path and forwards to the matching\n // per-app worker.\n const imports = apps\n .map((a) => `import ${moduleIdent(a)} from \"./${a}/_worker.js\";`)\n .join(\"\\n\");\n const dispatch = apps\n .map(\n (a) =>\n ` if (pathname === \"/${a}\" || pathname.startsWith(\"/${a}/\")) return ${moduleIdent(a)}.fetch(request, env, ctx);`,\n )\n .join(\"\\n\");\n\n const worker = `${imports}\n\nexport default {\n async fetch(request, env, ctx) {\n const { pathname } = new URL(request.url);\n${dispatch}\n if (pathname === \"/\") {\n return Response.redirect(new URL(\"/${apps[0]}/\", request.url).toString(), 302);\n }\n return new Response(\"Not found\", { status: 404 });\n },\n};\n`;\n fs.writeFileSync(path.join(distDir, \"_worker.js\"), worker);\n}\n\nfunction writeNetlifyRedirects(distDir: string, apps: string[]): void {\n const lines: string[] = [\n \"# Generated by agent-native deploy --preset netlify\",\n \"# No forced rewrites: Netlify should serve static files from dist/ first.\",\n ];\n\n if (apps.includes(\"dispatch\")) {\n lines.push(\"/ /dispatch/overview 302\");\n lines.push(\"/dispatch /dispatch/overview 302\");\n for (const [from, to] of DISPATCH_WORKSPACE_ROOT_REDIRECTS) {\n lines.push(`/${from} /dispatch/${to} 302`);\n }\n } else {\n lines.push(`/ /${apps[0]}/ 302`);\n }\n\n fs.writeFileSync(path.join(distDir, \"_redirects\"), lines.join(\"\\n\") + \"\\n\");\n}\n\nconst DISPATCH_WORKSPACE_ROOT_REDIRECTS = [\n [\"overview\", \"overview\"],\n [\"apps\", \"apps\"],\n [\"new-app\", \"new-app\"],\n [\"vault\", \"vault\"],\n [\"integrations\", \"integrations\"],\n [\"agents\", \"agents\"],\n [\"workspace\", \"workspace\"],\n [\"messaging\", \"messaging\"],\n [\"destinations\", \"destinations\"],\n [\"identities\", \"identities\"],\n [\"approvals\", \"approvals\"],\n [\"audit\", \"audit\"],\n [\"team\", \"team\"],\n];\n\nfunction copyNetlifyFunctionIntoWorkspace(\n workspaceRoot: string,\n app: string,\n): void {\n const appDir = path.join(workspaceRoot, \"apps\", app);\n const src = path.join(appDir, \".netlify\", \"functions-internal\", \"server\");\n if (!fs.existsSync(src)) {\n throw new Error(\n `Expected Netlify function at ${src} after building ${app}. Check the app's build script and NITRO_PRESET.`,\n );\n }\n\n const dest = path.join(netlifyFunctionsDir(workspaceRoot), `${app}-server`);\n fs.rmSync(dest, { recursive: true, force: true });\n copyDir(src, dest);\n patchNetlifyFunctionEntry(dest, app);\n}\n\nfunction patchNetlifyFunctionEntry(functionDir: string, app: string): void {\n const serverPath = path.join(functionDir, \"server.mjs\");\n if (!fs.existsSync(serverPath)) return;\n\n const basePath = `/${app}`;\n const server = `const basePath = ${JSON.stringify(basePath)};\n\nfunction setBasePathEnv() {\n const processRef = globalThis.process ??= { env: {} };\n processRef.env ??= {};\n Object.assign(processRef.env, {\n APP_BASE_PATH: basePath,\n VITE_APP_BASE_PATH: basePath,\n });\n}\n\nsetBasePathEnv();\n\nlet cachedHandler;\n\nexport default async function handler(...args) {\n setBasePathEnv();\n cachedHandler ??= (await import(\"./main.mjs\")).default;\n return cachedHandler(...args);\n}\n\nexport const config = {\n name: ${JSON.stringify(`${app} server handler`)},\n generator: \"agent-native workspace deploy\",\n path: ${JSON.stringify(`${basePath}/*`)},\n nodeBundler: \"none\",\n includedFiles: [\"**\"],\n excludedPath: [\"/.netlify/*\"],\n preferStatic: true,\n};\n`;\n fs.rmSync(serverPath, { force: true });\n fs.writeFileSync(path.join(functionDir, `${app}-server.mjs`), server);\n}\n\nfunction netlifyFunctionsDir(workspaceRoot: string): string {\n return path.join(workspaceRoot, \".netlify\", \"functions-internal\");\n}\n\nfunction cleanAppBuildOutputs(appDir: string): void {\n for (const name of [\"dist\", \".output\", \"build\"]) {\n fs.rmSync(path.join(appDir, name), { recursive: true, force: true });\n }\n fs.rmSync(path.join(appDir, \".netlify\", \"functions-internal\"), {\n recursive: true,\n force: true,\n });\n}\n\nfunction appUsesNetlifyUnpooledDatabaseUrl(appDir: string): boolean {\n const netlifyPath = path.join(appDir, \"netlify.toml\");\n if (!fs.existsSync(netlifyPath)) return false;\n try {\n return fs\n .readFileSync(netlifyPath, \"utf-8\")\n .includes(\"NETLIFY_DATABASE_URL_UNPOOLED\");\n } catch {\n return false;\n }\n}\n\nfunction parsePresetArg(args: string[]): WorkspaceDeployPreset | null {\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (arg === \"--preset\" && args[i + 1]) {\n return normalizePreset(args[i + 1]);\n }\n if (arg.startsWith(\"--preset=\")) {\n return normalizePreset(arg.slice(\"--preset=\".length));\n }\n }\n return null;\n}\n\nfunction resolvePreset(\n optionPreset: WorkspaceDeployPreset | undefined,\n args: string[],\n): WorkspaceDeployPreset {\n return (\n optionPreset ??\n parsePresetArg(args) ??\n normalizePreset(process.env.NITRO_PRESET) ??\n \"cloudflare_pages\"\n );\n}\n\nfunction normalizePreset(\n value: string | undefined,\n): WorkspaceDeployPreset | null {\n if (!value) return null;\n if (value === \"cloudflare_pages\" || value === \"cloudflare-pages\") {\n return \"cloudflare_pages\";\n }\n if (value === \"netlify\") return \"netlify\";\n throw new Error(\n `Unsupported workspace deploy preset \"${value}\". Supported presets: cloudflare_pages, netlify.`,\n );\n}\n\nfunction moduleIdent(app: string): string {\n return \"app_\" + app.replace(/[^a-zA-Z0-9_]/g, \"_\");\n}\n\nfunction copyDir(src: string, dest: string): void {\n fs.mkdirSync(dest, { recursive: true });\n for (const entry of fs.readdirSync(src, { withFileTypes: true })) {\n const s = path.join(src, entry.name);\n const d = path.join(dest, entry.name);\n if (entry.isSymbolicLink()) {\n try {\n const target = fs.readlinkSync(s);\n fs.symlinkSync(target, d);\n } catch {\n fs.copyFileSync(s, d);\n }\n } else if (entry.isDirectory()) {\n copyDir(s, d);\n } else {\n fs.copyFileSync(s, d);\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"agent-chat-plugin.d.ts","sourceRoot":"","sources":["../../src/server/agent-chat-plugin.ts"],"names":[],"mappings":"AASA,OAAO,EASL,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;AAItC,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,gBAAgB,EAUjB,MAAM,wBAAwB,CAAC;AAknChC,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE9D,MAAM,WAAW,sBAAsB;IACrC,+DAA+D;IAC/D,OAAO,CAAC,EACJ,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAC3B,CAAC,MACG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAC3B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC9C,wCAAwC;IACxC,OAAO,CAAC,EACJ,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAC3B,CAAC,MACG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAC3B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC9C,mEAAmE;IACnE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,MAAM,CAAC,EACH,OAAO,0BA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,GAC/B,CAAC,MACG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAC/B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IAClD,kFAAkF;IAClF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACtE;;;;;;;;;;;;;;OAcG;IACH,YAAY,CAAC,EAAE,CACb,KAAK,EAAE,GAAG,EACV,KAAK,EAAE,MAAM,KACV,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC5C;;;;;;;;;;;;;;OAcG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;;;;;;;;;OAaG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;;;;;;;;;;;;OAkBG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AA6vBD,wBAAgB,qBAAqB,CACnC,OAAO,CAAC,EAAE,sBAAsB,GAC/B,cAAc,CA88EhB;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,cAAwC,CAAC;AAa9E,yEAAyE;AACzE,wBAAgB,mBAAmB,IAAI,gBAAgB,GAAG,IAAI,CAE7D"}
@@ -18,6 +18,8 @@ import nodePath from "node:path";
18
18
  import { readBody } from "./h3-helpers.js";
19
19
  import { getBuilderBrowserConnectUrl } from "./builder-browser.js";
20
20
  import { captureCliOutput } from "./cli-capture.js";
21
+ import { withConfiguredAppBasePath } from "./app-base-path.js";
22
+ import { appendA2AArtifactLinks } from "../a2a/artifact-response.js";
21
23
  // Lazy fs — loaded via dynamic import() on first use.
22
24
  // This avoids require() which bundlers convert to createRequire(import.meta.url)
23
25
  // that crashes on CF Workers where import.meta.url is undefined.
@@ -51,6 +53,22 @@ function wrapCliScript(tool, cliDefault, opts) {
51
53
  },
52
54
  };
53
55
  }
56
+ function resolveArtifactBaseUrl(event) {
57
+ const fromEnv = process.env.APP_URL ||
58
+ process.env.URL ||
59
+ process.env.DEPLOY_URL ||
60
+ process.env.BETTER_AUTH_URL;
61
+ if (fromEnv)
62
+ return withConfiguredAppBasePath(String(fromEnv));
63
+ try {
64
+ const proto = getHeader(event, "x-forwarded-proto") || "https";
65
+ const host = getHeader(event, "host");
66
+ if (host)
67
+ return withConfiguredAppBasePath(`${proto}://${host}`);
68
+ }
69
+ catch { }
70
+ return undefined;
71
+ }
54
72
  /**
55
73
  * Creates the `get-framework-context` tool. Returns detailed instructions
56
74
  * for framework capabilities that are summarized in the compact prompt.
@@ -2240,6 +2258,7 @@ export function createAgentChatPlugin(options) {
2240
2258
  ];
2241
2259
  // Run the SAME agent loop, collect text events, yield as A2A messages
2242
2260
  let accumulatedText = "";
2261
+ const a2aToolResults = [];
2243
2262
  const controller = new AbortController();
2244
2263
  console.log(`[A2A] Starting agent loop: ${a2aTools.length} tools, prompt ${systemPrompt.length} chars`);
2245
2264
  await runAgentLoop({
@@ -2256,6 +2275,12 @@ export function createAgentChatPlugin(options) {
2256
2275
  else if (event.type === "tool_start") {
2257
2276
  console.log(`[A2A] Tool call: ${event.tool}`);
2258
2277
  }
2278
+ else if (event.type === "tool_done") {
2279
+ a2aToolResults.push({
2280
+ tool: event.tool,
2281
+ result: event.result,
2282
+ });
2283
+ }
2259
2284
  else if (event.type === "error") {
2260
2285
  console.error(`[A2A] Error: ${event.error}`);
2261
2286
  }
@@ -2266,13 +2291,14 @@ export function createAgentChatPlugin(options) {
2266
2291
  signal: controller.signal,
2267
2292
  });
2268
2293
  console.log(`[A2A] Loop complete. Text: ${accumulatedText.slice(0, 100)}...`);
2294
+ const finalText = appendA2AArtifactLinks(accumulatedText, a2aToolResults, { baseUrl: resolveArtifactBaseUrl(context.event) });
2269
2295
  // Yield the final accumulated text
2270
2296
  yield {
2271
2297
  role: "agent",
2272
2298
  parts: [
2273
2299
  {
2274
2300
  type: "text",
2275
- text: accumulatedText || "(no response)",
2301
+ text: finalText || "(no response)",
2276
2302
  },
2277
2303
  ],
2278
2304
  };