@agent-native/core 0.92.9 → 0.92.10

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.
@@ -1,5 +1,11 @@
1
1
  # @agent-native/core
2
2
 
3
+ ## 0.92.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 22abd76: Prevent Netlify, Vercel, and AWS Lambda deployments from failing SSR requests when collaboration runtime chunks import Yjs.
8
+
3
9
  ## 0.92.9
4
10
 
5
11
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-native/core",
3
- "version": "0.92.9",
3
+ "version": "0.92.10",
4
4
  "description": "Framework for agent-native application development — where AI agents and UI share SQL state, actions, and context",
5
5
  "homepage": "https://github.com/BuilderIO/agent-native#readme",
6
6
  "bugs": {
@@ -2437,6 +2437,90 @@ export const config = {
2437
2437
  const NETLIFY_DEFAULT_FUNCTION_URL_REDIRECT =
2438
2438
  "/* /.netlify/functions/server 200";
2439
2439
 
2440
+ function hasBareYjsRuntimeImport(source: string): boolean {
2441
+ return /\b(?:from\s*|import\s*\(\s*|import\s*)["']yjs(?:\/[^"']*)?["']/.test(
2442
+ source,
2443
+ );
2444
+ }
2445
+
2446
+ function hasUnsupportedYjsSubpathImport(source: string): boolean {
2447
+ return /\b(?:from\s*|import\s*\(\s*|import\s*)["']yjs\/[^"']*["']/.test(
2448
+ source,
2449
+ );
2450
+ }
2451
+
2452
+ function walkServerJavaScriptFiles(
2453
+ dir: string,
2454
+ onFile: (filePath: string) => void,
2455
+ ): void {
2456
+ if (!fs.existsSync(dir)) return;
2457
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
2458
+ const entryPath = path.join(dir, entry.name);
2459
+ if (entry.isDirectory()) {
2460
+ walkServerJavaScriptFiles(entryPath, onFile);
2461
+ continue;
2462
+ }
2463
+ if (/\.(?:[cm]?js)$/.test(entry.name)) onFile(entryPath);
2464
+ }
2465
+ }
2466
+
2467
+ /**
2468
+ * Nitro can preserve Vite's `yjs` external in a split server chunk even when
2469
+ * its own server build has emitted `_libs/yjs.mjs`. Netlify does not install
2470
+ * that bare package at runtime, so make every emitted server chunk use the
2471
+ * bundled copy before its function is packaged.
2472
+ */
2473
+ export function rewriteBareYjsImportsForServerlessOutput(
2474
+ serverDir: string,
2475
+ ): string[] {
2476
+ const bareImports: string[] = [];
2477
+ const unsupportedSubpathImports: string[] = [];
2478
+ const bundledYjsPath = path.join(serverDir, "_libs", "yjs.mjs");
2479
+
2480
+ walkServerJavaScriptFiles(serverDir, (filePath) => {
2481
+ const source = fs.readFileSync(filePath, "utf-8");
2482
+ if (!hasBareYjsRuntimeImport(source)) return;
2483
+ if (hasUnsupportedYjsSubpathImport(source)) {
2484
+ unsupportedSubpathImports.push(filePath);
2485
+ return;
2486
+ }
2487
+ bareImports.push(filePath);
2488
+ });
2489
+
2490
+ if (unsupportedSubpathImports.length > 0) {
2491
+ throw new Error(
2492
+ `[deploy] Serverless output left unsupported yjs subpath imports in ${unsupportedSubpathImports.join(", ")}`,
2493
+ );
2494
+ }
2495
+ if (bareImports.length === 0) return [];
2496
+ if (!fs.existsSync(bundledYjsPath)) {
2497
+ throw new Error(
2498
+ `[deploy] Serverless output left yjs as a runtime import but did not emit ${bundledYjsPath}`,
2499
+ );
2500
+ }
2501
+
2502
+ for (const filePath of bareImports) {
2503
+ const bundledImport = path
2504
+ .relative(path.dirname(filePath), bundledYjsPath)
2505
+ .split(path.sep)
2506
+ .join("/");
2507
+ const relativeBundledImport = bundledImport.startsWith(".")
2508
+ ? bundledImport
2509
+ : `./${bundledImport}`;
2510
+ const source = fs.readFileSync(filePath, "utf-8");
2511
+ fs.writeFileSync(
2512
+ filePath,
2513
+ source.replace(
2514
+ /(\b(?:from\s*|import\s*\(\s*|import\s*))(["'])yjs\2/g,
2515
+ (_match, importPrefix: string, quote: string) =>
2516
+ `${importPrefix}${quote}${relativeBundledImport}${quote}`,
2517
+ ),
2518
+ );
2519
+ }
2520
+
2521
+ return bareImports;
2522
+ }
2523
+
2440
2524
  export function assertSingleTemplateNetlifyBuildOutput(
2441
2525
  projectCwd: string,
2442
2526
  ): void {
@@ -2519,6 +2603,23 @@ export function assertSingleTemplateNetlifyBuildOutput(
2519
2603
  }
2520
2604
  }
2521
2605
 
2606
+ // Netlify's function packager does not install arbitrary runtime package
2607
+ // imports left in Nitro chunks. A bare Yjs import here would deploy
2608
+ // successfully but fail on the first SSR request with ERR_MODULE_NOT_FOUND.
2609
+ // Keep this check adjacent to the output guard so both local builds and CI
2610
+ // reject that artifact before it reaches Netlify.
2611
+ const bareYjsImports: string[] = [];
2612
+ walkServerJavaScriptFiles(serverDir, (filePath) => {
2613
+ if (hasBareYjsRuntimeImport(fs.readFileSync(filePath, "utf-8"))) {
2614
+ bareYjsImports.push(path.relative(projectCwd, filePath));
2615
+ }
2616
+ });
2617
+ if (bareYjsImports.length > 0) {
2618
+ failures.push(
2619
+ `Netlify server bundle leaves yjs as a runtime import: ${bareYjsImports.join(", ")}`,
2620
+ );
2621
+ }
2622
+
2522
2623
  if (isDurableBackgroundDeployEnabled()) {
2523
2624
  const backgroundDir = path.join(
2524
2625
  internalDir,
@@ -2969,6 +3070,32 @@ const BROWSER_ONLY_SERVER_LIBS = [
2969
3070
  "mermaid",
2970
3071
  ];
2971
3072
 
3073
+ /**
3074
+ * Dependencies that must be bundled into every Nitro server output instead of
3075
+ * being left as runtime package imports.
3076
+ *
3077
+ * `yjs` is a direct core dependency, but it is deliberately externalized from
3078
+ * the intermediate Vite SSR graph so that Vite and Nitro do not create two
3079
+ * incompatible Yjs constructors. On file-traced serverless presets, leaving it
3080
+ * external at Nitro's final build can emit `import "yjs"` into a function
3081
+ * chunk without placing the package in that function's `node_modules`. Bundle
3082
+ * it in Nitro's final output so every template receives the one portable copy.
3083
+ */
3084
+ export const NITRO_SERVER_RUNTIME_BUNDLED_DEPS = ["yjs"] as const;
3085
+
3086
+ /**
3087
+ * Edge runtimes have no node_modules, while Node/serverless outputs only need
3088
+ * the small set above bundled to keep their package manifests traceable.
3089
+ */
3090
+ export function nitroNoExternalsForPreset(
3091
+ targetPreset: string,
3092
+ ): true | readonly string[] {
3093
+ return targetPreset.startsWith("cloudflare") ||
3094
+ targetPreset.startsWith("deno")
3095
+ ? true
3096
+ : NITRO_SERVER_RUNTIME_BUNDLED_DEPS;
3097
+ }
3098
+
2972
3099
  /**
2973
3100
  * Rolldown plugin for the Nitro server bundle that replaces the browser-only
2974
3101
  * renderers above with an inert proxy module.
@@ -3124,11 +3251,11 @@ export default bundle;
3124
3251
  ? { plugins: [providedPluginsNitroPlugin] }
3125
3252
  : {}),
3126
3253
  routeRules: mcpEmbedStaticAssetRouteRules(appBasePath),
3127
- // For edge presets (cloudflare, deno), bundle all deps node_modules
3128
- // aren't available at runtime. Netlify/Vercel/Node have node_modules.
3129
- ...(preset.startsWith("cloudflare") || preset.startsWith("deno")
3130
- ? { noExternals: true }
3131
- : {}),
3254
+ // Edge presets (cloudflare, deno) bundle all deps because node_modules are
3255
+ // unavailable at runtime. Node/serverless presets also bundle Yjs: Nitro's
3256
+ // file tracer otherwise leaves a bare import that Netlify function bundles
3257
+ // cannot resolve under pnpm.
3258
+ noExternals: nitroNoExternalsForPreset(preset),
3132
3259
  } as any);
3133
3260
 
3134
3261
  await runNitroBuildPipeline({
@@ -3145,6 +3272,7 @@ export default bundle;
3145
3272
  copyInstalledResvgPackages(nitro.options.output.serverDir);
3146
3273
  copyInstalledFfmpegStaticPackage(nitro.options.output.serverDir);
3147
3274
  sanitizeServerlessFunctionPackageManifest(nitro.options.output.serverDir);
3275
+ rewriteBareYjsImportsForServerlessOutput(nitro.options.output.serverDir);
3148
3276
  }
3149
3277
 
3150
3278
  // Durable background agent runs (default-OFF / opt-in; enable with a truthy
@@ -62,11 +62,11 @@ export declare const postAwareness: import("h3").EventHandlerWithFetch<import("h
62
62
  error: string;
63
63
  states?: undefined;
64
64
  } | {
65
+ error?: undefined;
65
66
  states: {
66
67
  clientId: number;
67
68
  state: string;
68
69
  }[];
69
- error?: undefined;
70
70
  }>>;
71
71
  /**
72
72
  * GET /_agent-native/collab/:docId/users
@@ -77,10 +77,10 @@ export declare const getActiveUsers: import("h3").EventHandlerWithFetch<import("
77
77
  error: string;
78
78
  users?: undefined;
79
79
  } | {
80
+ error?: undefined;
80
81
  users: {
81
82
  clientId: number;
82
83
  lastSeen: number;
83
84
  }[];
84
- error?: undefined;
85
85
  }>>;
86
86
  //# sourceMappingURL=awareness.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"awareness.d.ts","sourceRoot":"","sources":["../../src/collab/awareness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAgB3C,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAOD,eAAO,MAAM,sBAAsB,EAAG,kBAA2B,CAAC;AAElE,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,kBAAkB,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,MAAM,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,gFAAgF;IAChF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,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,CAAC,MAAM,EAAE,cAAc,CAAC,CAO1E;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,IAAI,CAOnE;AAkCD;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa;;;;;;kBAwDa,MAAM;eAAS,MAAM;;GAoB1D,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,cAAc;;;;;;kBAYM,MAAM;kBAAY,MAAM;;GAMvD,CAAC"}
@@ -26,8 +26,8 @@ export declare const getCollabState: import("h3").EventHandlerWithFetch<import("
26
26
  * Body: { update: string (base64), requestSource?: string }
27
27
  */
28
28
  export declare const postCollabUpdate: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
29
- ok?: undefined;
30
29
  error: string;
30
+ ok?: undefined;
31
31
  } | {
32
32
  error?: undefined;
33
33
  ok: boolean;
@@ -150,6 +150,13 @@ export declare function isDurableBackgroundDeployEnabled(): boolean;
150
150
  * inline 40s synchronous run (see production-agent.ts).
151
151
  */
152
152
  export declare function emitSingleTemplateNetlifyBackgroundFunction(projectCwd: string): void;
153
+ /**
154
+ * Nitro can preserve Vite's `yjs` external in a split server chunk even when
155
+ * its own server build has emitted `_libs/yjs.mjs`. Netlify does not install
156
+ * that bare package at runtime, so make every emitted server chunk use the
157
+ * bundled copy before its function is packaged.
158
+ */
159
+ export declare function rewriteBareYjsImportsForServerlessOutput(serverDir: string): string[];
153
160
  export declare function assertSingleTemplateNetlifyBuildOutput(projectCwd: string): void;
154
161
  /**
155
162
  * Strip the harmful single-template catch-all rewrite that points at
@@ -196,5 +203,22 @@ export interface NitroBuildPipelineOptions {
196
203
  * anything with a file extension.
197
204
  */
198
205
  export declare function runNitroBuildPipeline(opts: NitroBuildPipelineOptions): Promise<void>;
206
+ /**
207
+ * Dependencies that must be bundled into every Nitro server output instead of
208
+ * being left as runtime package imports.
209
+ *
210
+ * `yjs` is a direct core dependency, but it is deliberately externalized from
211
+ * the intermediate Vite SSR graph so that Vite and Nitro do not create two
212
+ * incompatible Yjs constructors. On file-traced serverless presets, leaving it
213
+ * external at Nitro's final build can emit `import "yjs"` into a function
214
+ * chunk without placing the package in that function's `node_modules`. Bundle
215
+ * it in Nitro's final output so every template receives the one portable copy.
216
+ */
217
+ export declare const NITRO_SERVER_RUNTIME_BUNDLED_DEPS: readonly ["yjs"];
218
+ /**
219
+ * Edge runtimes have no node_modules, while Node/serverless outputs only need
220
+ * the small set above bundled to keep their package manifests traceable.
221
+ */
222
+ export declare function nitroNoExternalsForPreset(targetPreset: string): true | readonly string[];
199
223
  export {};
200
224
  //# sourceMappingURL=build.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/deploy/build.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;GAYG;AAmCH,OAAO,EAML,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,qBAAqB,CAAC;AAI7B,eAAO,MAAM,6BAA6B,UAiBzC,CAAC;AAEF,eAAO,MAAM,mCAAmC,UAiB/C,CAAC;AACF,eAAO,MAAM,8BAA8B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAiFjE,CAAC;AA6BF,eAAO,MAAM,2CAA2C,EAAE,MAAM,CAC9D,MAAM,EACN,MAAM,CAmSP,CAAC;AAEF,MAAM,WAAW,0BAA0B;IACzC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,UAAU,wBAAwB;IAChC,KAAK,EAAE,6BAA6B,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,6BAA6B,CAAC,CAAC;IACtD,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,6BAA6B;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,GAAG,CAAC,EAAE,MAA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,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;AAkBD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iCAAiC,YAAI,KAAK,CAAU,CAAC;AAElE;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,GACnB,IAAI,GAAG,SAAS,MAAM,EAAE,CAK1B"}
@@ -2021,6 +2021,66 @@ export const config = {
2021
2021
  * the SSR catch-all runs.
2022
2022
  */
2023
2023
  const NETLIFY_DEFAULT_FUNCTION_URL_REDIRECT = "/* /.netlify/functions/server 200";
2024
+ function hasBareYjsRuntimeImport(source) {
2025
+ return /\b(?:from\s*|import\s*\(\s*|import\s*)["']yjs(?:\/[^"']*)?["']/.test(source);
2026
+ }
2027
+ function hasUnsupportedYjsSubpathImport(source) {
2028
+ return /\b(?:from\s*|import\s*\(\s*|import\s*)["']yjs\/[^"']*["']/.test(source);
2029
+ }
2030
+ function walkServerJavaScriptFiles(dir, onFile) {
2031
+ if (!fs.existsSync(dir))
2032
+ return;
2033
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
2034
+ const entryPath = path.join(dir, entry.name);
2035
+ if (entry.isDirectory()) {
2036
+ walkServerJavaScriptFiles(entryPath, onFile);
2037
+ continue;
2038
+ }
2039
+ if (/\.(?:[cm]?js)$/.test(entry.name))
2040
+ onFile(entryPath);
2041
+ }
2042
+ }
2043
+ /**
2044
+ * Nitro can preserve Vite's `yjs` external in a split server chunk even when
2045
+ * its own server build has emitted `_libs/yjs.mjs`. Netlify does not install
2046
+ * that bare package at runtime, so make every emitted server chunk use the
2047
+ * bundled copy before its function is packaged.
2048
+ */
2049
+ export function rewriteBareYjsImportsForServerlessOutput(serverDir) {
2050
+ const bareImports = [];
2051
+ const unsupportedSubpathImports = [];
2052
+ const bundledYjsPath = path.join(serverDir, "_libs", "yjs.mjs");
2053
+ walkServerJavaScriptFiles(serverDir, (filePath) => {
2054
+ const source = fs.readFileSync(filePath, "utf-8");
2055
+ if (!hasBareYjsRuntimeImport(source))
2056
+ return;
2057
+ if (hasUnsupportedYjsSubpathImport(source)) {
2058
+ unsupportedSubpathImports.push(filePath);
2059
+ return;
2060
+ }
2061
+ bareImports.push(filePath);
2062
+ });
2063
+ if (unsupportedSubpathImports.length > 0) {
2064
+ throw new Error(`[deploy] Serverless output left unsupported yjs subpath imports in ${unsupportedSubpathImports.join(", ")}`);
2065
+ }
2066
+ if (bareImports.length === 0)
2067
+ return [];
2068
+ if (!fs.existsSync(bundledYjsPath)) {
2069
+ throw new Error(`[deploy] Serverless output left yjs as a runtime import but did not emit ${bundledYjsPath}`);
2070
+ }
2071
+ for (const filePath of bareImports) {
2072
+ const bundledImport = path
2073
+ .relative(path.dirname(filePath), bundledYjsPath)
2074
+ .split(path.sep)
2075
+ .join("/");
2076
+ const relativeBundledImport = bundledImport.startsWith(".")
2077
+ ? bundledImport
2078
+ : `./${bundledImport}`;
2079
+ const source = fs.readFileSync(filePath, "utf-8");
2080
+ fs.writeFileSync(filePath, source.replace(/(\b(?:from\s*|import\s*\(\s*|import\s*))(["'])yjs\2/g, (_match, importPrefix, quote) => `${importPrefix}${quote}${relativeBundledImport}${quote}`));
2081
+ }
2082
+ return bareImports;
2083
+ }
2024
2084
  export function assertSingleTemplateNetlifyBuildOutput(projectCwd) {
2025
2085
  const failures = [];
2026
2086
  const publishDir = path.join(projectCwd, "dist");
@@ -2072,6 +2132,20 @@ export function assertSingleTemplateNetlifyBuildOutput(projectCwd) {
2072
2132
  failures.push("Netlify server entry must keep preferStatic: true so /assets/* is served from dist before the SSR catch-all");
2073
2133
  }
2074
2134
  }
2135
+ // Netlify's function packager does not install arbitrary runtime package
2136
+ // imports left in Nitro chunks. A bare Yjs import here would deploy
2137
+ // successfully but fail on the first SSR request with ERR_MODULE_NOT_FOUND.
2138
+ // Keep this check adjacent to the output guard so both local builds and CI
2139
+ // reject that artifact before it reaches Netlify.
2140
+ const bareYjsImports = [];
2141
+ walkServerJavaScriptFiles(serverDir, (filePath) => {
2142
+ if (hasBareYjsRuntimeImport(fs.readFileSync(filePath, "utf-8"))) {
2143
+ bareYjsImports.push(path.relative(projectCwd, filePath));
2144
+ }
2145
+ });
2146
+ if (bareYjsImports.length > 0) {
2147
+ failures.push(`Netlify server bundle leaves yjs as a runtime import: ${bareYjsImports.join(", ")}`);
2148
+ }
2075
2149
  if (isDurableBackgroundDeployEnabled()) {
2076
2150
  const backgroundDir = path.join(internalDir, AGENT_BACKGROUND_FUNCTION_NAME);
2077
2151
  const backgroundEntryPath = path.join(backgroundDir, `${AGENT_BACKGROUND_FUNCTION_NAME}.mjs`);
@@ -2421,6 +2495,28 @@ const BROWSER_ONLY_SERVER_LIBS = [
2421
2495
  "@excalidraw/mermaid-to-excalidraw",
2422
2496
  "mermaid",
2423
2497
  ];
2498
+ /**
2499
+ * Dependencies that must be bundled into every Nitro server output instead of
2500
+ * being left as runtime package imports.
2501
+ *
2502
+ * `yjs` is a direct core dependency, but it is deliberately externalized from
2503
+ * the intermediate Vite SSR graph so that Vite and Nitro do not create two
2504
+ * incompatible Yjs constructors. On file-traced serverless presets, leaving it
2505
+ * external at Nitro's final build can emit `import "yjs"` into a function
2506
+ * chunk without placing the package in that function's `node_modules`. Bundle
2507
+ * it in Nitro's final output so every template receives the one portable copy.
2508
+ */
2509
+ export const NITRO_SERVER_RUNTIME_BUNDLED_DEPS = ["yjs"];
2510
+ /**
2511
+ * Edge runtimes have no node_modules, while Node/serverless outputs only need
2512
+ * the small set above bundled to keep their package manifests traceable.
2513
+ */
2514
+ export function nitroNoExternalsForPreset(targetPreset) {
2515
+ return targetPreset.startsWith("cloudflare") ||
2516
+ targetPreset.startsWith("deno")
2517
+ ? true
2518
+ : NITRO_SERVER_RUNTIME_BUNDLED_DEPS;
2519
+ }
2424
2520
  /**
2425
2521
  * Rolldown plugin for the Nitro server bundle that replaces the browser-only
2426
2522
  * renderers above with an inert proxy module.
@@ -2561,11 +2657,11 @@ export default bundle;
2561
2657
  ? { plugins: [providedPluginsNitroPlugin] }
2562
2658
  : {}),
2563
2659
  routeRules: mcpEmbedStaticAssetRouteRules(appBasePath),
2564
- // For edge presets (cloudflare, deno), bundle all deps node_modules
2565
- // aren't available at runtime. Netlify/Vercel/Node have node_modules.
2566
- ...(preset.startsWith("cloudflare") || preset.startsWith("deno")
2567
- ? { noExternals: true }
2568
- : {}),
2660
+ // Edge presets (cloudflare, deno) bundle all deps because node_modules are
2661
+ // unavailable at runtime. Node/serverless presets also bundle Yjs: Nitro's
2662
+ // file tracer otherwise leaves a bare import that Netlify function bundles
2663
+ // cannot resolve under pnpm.
2664
+ noExternals: nitroNoExternalsForPreset(preset),
2569
2665
  });
2570
2666
  await runNitroBuildPipeline({
2571
2667
  nitro,
@@ -2580,6 +2676,7 @@ export default bundle;
2580
2676
  copyInstalledResvgPackages(nitro.options.output.serverDir);
2581
2677
  copyInstalledFfmpegStaticPackage(nitro.options.output.serverDir);
2582
2678
  sanitizeServerlessFunctionPackageManifest(nitro.options.output.serverDir);
2679
+ rewriteBareYjsImportsForServerlessOutput(nitro.options.output.serverDir);
2583
2680
  }
2584
2681
  // Durable background agent runs (default-OFF / opt-in; enable with a truthy
2585
2682
  // AGENT_CHAT_DURABLE_BACKGROUND). Additive ONLY: emits a SECOND Netlify