@jami-studio/core 0.92.13 → 0.92.15
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/core/CHANGELOG.md +12 -0
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/deploy/build.ts +31 -0
- package/corpus/core/src/deploy/workspace-deploy.ts +1458 -1453
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +30 -0
- package/dist/deploy/build.js.map +1 -1
- package/dist/deploy/workspace-deploy.js +207 -202
- package/dist/deploy/workspace-deploy.js.map +1 -1
- package/package.json +1 -1
|
@@ -266,45 +266,45 @@ function writeCloudflareRoutingManifest(distDir, apps) {
|
|
|
266
266
|
.map((a) => ` if (pathname === "/${a}" || pathname.startsWith("/${a}/")) return ${moduleIdent(a)}.fetch(requestForMountedApp(request, "/${a}"), env, ctx);`)
|
|
267
267
|
.join("\n");
|
|
268
268
|
const dispatchRootFrameworkRoutes = apps.includes("dispatch")
|
|
269
|
-
? ` if (pathname === "/_agent-native" || pathname.startsWith("/_agent-native/") || pathname === "/.well-known" || pathname.startsWith("/.well-known/")) return ${moduleIdent("dispatch")}.fetch(request, env, ctx);
|
|
269
|
+
? ` if (pathname === "/_agent-native" || pathname.startsWith("/_agent-native/") || pathname === "/.well-known" || pathname.startsWith("/.well-known/")) return ${moduleIdent("dispatch")}.fetch(request, env, ctx);
|
|
270
270
|
`
|
|
271
271
|
: "";
|
|
272
272
|
const dispatchRootFaviconRoute = dispatchFaviconAsset
|
|
273
|
-
? ` if (pathname === "/favicon.ico") return Response.redirect(new URL("/dispatch/${dispatchFaviconAsset}", request.url).toString(), 302);
|
|
273
|
+
? ` if (pathname === "/favicon.ico") return Response.redirect(new URL("/dispatch/${dispatchFaviconAsset}", request.url).toString(), 302);
|
|
274
274
|
`
|
|
275
275
|
: "";
|
|
276
276
|
const dispatchRootAliasRoutes = apps.includes("dispatch")
|
|
277
277
|
? DISPATCH_WORKSPACE_ROOT_REDIRECTS.map(([from, to]) => ` if (pathname === "/${from}") return Response.redirect(new URL("/dispatch/${to}" + search, request.url).toString(), 302);`).join("\n") + "\n"
|
|
278
278
|
: "";
|
|
279
279
|
const dispatchRootDynamicAliasRoutes = apps.includes("dispatch")
|
|
280
|
-
? ` if (pathname.startsWith("/apps/")) return Response.redirect(new URL("/dispatch" + pathname + search, request.url).toString(), 302);
|
|
280
|
+
? ` if (pathname.startsWith("/apps/")) return Response.redirect(new URL("/dispatch" + pathname + search, request.url).toString(), 302);
|
|
281
281
|
`
|
|
282
282
|
: "";
|
|
283
283
|
const dispatchMountedRootRedirect = apps.includes("dispatch")
|
|
284
|
-
? ` if (pathname === "/dispatch" || pathname === "/dispatch/") return Response.redirect(new URL("/dispatch/overview" + search, request.url).toString(), 302);
|
|
284
|
+
? ` if (pathname === "/dispatch" || pathname === "/dispatch/") return Response.redirect(new URL("/dispatch/overview" + search, request.url).toString(), 302);
|
|
285
285
|
`
|
|
286
286
|
: "";
|
|
287
|
-
const worker = `${imports}
|
|
288
|
-
|
|
289
|
-
function requestForMountedApp(request, basePath) {
|
|
290
|
-
const url = new URL(request.url);
|
|
291
|
-
if (url.pathname !== basePath && url.pathname !== \`\${basePath}/\`) {
|
|
292
|
-
return request;
|
|
293
|
-
}
|
|
294
|
-
url.pathname = \`\${basePath}//\`;
|
|
295
|
-
return new Request(url, request);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
export default {
|
|
299
|
-
async fetch(request, env, ctx) {
|
|
300
|
-
const { pathname, search } = new URL(request.url);
|
|
301
|
-
${dispatchRootFrameworkRoutes}${dispatchRootFaviconRoute}${dispatchRootAliasRoutes}${dispatchRootDynamicAliasRoutes}${dispatchMountedRootRedirect}${dispatch}
|
|
302
|
-
if (pathname === "/") {
|
|
303
|
-
return Response.redirect(new URL("${cloudflareRootRedirectPath(apps)}", request.url).toString(), 302);
|
|
304
|
-
}
|
|
305
|
-
return new Response("Not found", { status: 404 });
|
|
306
|
-
},
|
|
307
|
-
};
|
|
287
|
+
const worker = `${imports}
|
|
288
|
+
|
|
289
|
+
function requestForMountedApp(request, basePath) {
|
|
290
|
+
const url = new URL(request.url);
|
|
291
|
+
if (url.pathname !== basePath && url.pathname !== \`\${basePath}/\`) {
|
|
292
|
+
return request;
|
|
293
|
+
}
|
|
294
|
+
url.pathname = \`\${basePath}//\`;
|
|
295
|
+
return new Request(url, request);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export default {
|
|
299
|
+
async fetch(request, env, ctx) {
|
|
300
|
+
const { pathname, search } = new URL(request.url);
|
|
301
|
+
${dispatchRootFrameworkRoutes}${dispatchRootFaviconRoute}${dispatchRootAliasRoutes}${dispatchRootDynamicAliasRoutes}${dispatchMountedRootRedirect}${dispatch}
|
|
302
|
+
if (pathname === "/") {
|
|
303
|
+
return Response.redirect(new URL("${cloudflareRootRedirectPath(apps)}", request.url).toString(), 302);
|
|
304
|
+
}
|
|
305
|
+
return new Response("Not found", { status: 404 });
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
308
|
`;
|
|
309
309
|
fs.writeFileSync(path.join(distDir, "_worker.js"), worker);
|
|
310
310
|
}
|
|
@@ -526,73 +526,73 @@ function emitNetlifyBackgroundFunction(workspaceRoot, app, srcServerDir, workspa
|
|
|
526
526
|
// The function is reached at its default url, so the entry rewrites the
|
|
527
527
|
// incoming pathname to `/<app>/_agent-native/agent-chat/_process-run`.
|
|
528
528
|
const processRunPath = `${basePath}${AGENT_CHAT_PROCESS_RUN_PATH}`;
|
|
529
|
-
const server = `// Mark this isolate as the durable background runtime BEFORE the handler bundle
|
|
530
|
-
// is imported, so isInBackgroundFunctionRuntime() reliably returns true in this
|
|
531
|
-
// function (the deployed Lambda name is not guaranteed to end in -background). A
|
|
532
|
-
// globalThis flag (NOT process.env) avoids the no-env-mutation guard and carries
|
|
533
|
-
// no cross-request state.
|
|
534
|
-
globalThis.__AGENT_NATIVE_BACKGROUND_RUNTIME__ = true;
|
|
535
|
-
|
|
536
|
-
const basePath = ${JSON.stringify(basePath)};
|
|
537
|
-
// The base-path-prefixed framework route the Nitro router dispatches to.
|
|
538
|
-
const PROCESS_RUN_PATH = ${JSON.stringify(processRunPath)};
|
|
539
|
-
|
|
540
|
-
function setBasePathEnv() {
|
|
541
|
-
const processRef = globalThis.process ??= { env: {} };
|
|
542
|
-
processRef.env ??= {};
|
|
543
|
-
Object.assign(processRef.env, {
|
|
544
|
-
AGENT_NATIVE_WORKSPACE: "1",
|
|
545
|
-
AGENT_NATIVE_WORKSPACE_APP_ID: ${JSON.stringify(app)},
|
|
546
|
-
APP_BASE_PATH: basePath,
|
|
547
|
-
AGENT_NATIVE_WORKSPACE_APP_AUDIENCE: ${JSON.stringify(workspaceAppAudience)},
|
|
548
|
-
AGENT_NATIVE_WORKSPACE_APP_PUBLIC_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.publicPaths))},
|
|
549
|
-
AGENT_NATIVE_WORKSPACE_APP_PROTECTED_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.protectedPaths))},
|
|
550
|
-
VITE_AGENT_NATIVE_WORKSPACE: "1",
|
|
551
|
-
VITE_AGENT_NATIVE_WORKSPACE_APP_ID: ${JSON.stringify(app)},
|
|
552
|
-
VITE_APP_BASE_PATH: basePath,
|
|
553
|
-
VITE_AGENT_NATIVE_WORKSPACE_APP_AUDIENCE: ${JSON.stringify(workspaceAppAudience)},
|
|
554
|
-
VITE_AGENT_NATIVE_WORKSPACE_APP_PUBLIC_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.publicPaths))},
|
|
555
|
-
VITE_AGENT_NATIVE_WORKSPACE_APP_PROTECTED_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.protectedPaths))},
|
|
556
|
-
VITE_AGENT_NATIVE_WORKSPACE_APPS_JSON: ${JSON.stringify(JSON.stringify(workspaceApps))},
|
|
557
|
-
${JSON.stringify(WORKSPACE_APPS_ENV_KEY)}: ${JSON.stringify(JSON.stringify(workspaceApps))},
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
setBasePathEnv();
|
|
562
|
-
|
|
563
|
-
let cachedHandler;
|
|
564
|
-
|
|
565
|
-
// Reached at the DEFAULT url /.netlify/functions/${backgroundName}; REWRITE the
|
|
566
|
-
// incoming pathname to the base-path-prefixed _process-run route so the Nitro
|
|
567
|
-
// router runs the plugin. Method, ALL headers (the HMAC Authorization: Bearer
|
|
568
|
-
// MUST survive) and the body are preserved.
|
|
569
|
-
export default async function handler(request) {
|
|
570
|
-
setBasePathEnv();
|
|
571
|
-
cachedHandler ??= (await import("./main.mjs")).default;
|
|
572
|
-
const url = new URL(request.url);
|
|
573
|
-
url.pathname = PROCESS_RUN_PATH;
|
|
574
|
-
const method = request.method || "POST";
|
|
575
|
-
const hasBody = method !== "GET" && method !== "HEAD";
|
|
576
|
-
const body = hasBody ? await request.text() : undefined;
|
|
577
|
-
const rewritten = new Request(url.toString(), {
|
|
578
|
-
method,
|
|
579
|
-
headers: request.headers,
|
|
580
|
-
body,
|
|
581
|
-
});
|
|
582
|
-
return cachedHandler(rewritten);
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
export const config = {
|
|
586
|
-
name: ${JSON.stringify(`${app} agent background handler`)},
|
|
587
|
-
generator: "agent-native workspace deploy",
|
|
588
|
-
// background: true → async invoke (202, 15-min budget). NO custom path: the
|
|
589
|
-
// function keeps its default url /.netlify/functions/${backgroundName}, which
|
|
590
|
-
// the <app>-server catch-all never shadows (it excludes /.netlify/*).
|
|
591
|
-
background: true,
|
|
592
|
-
nodeBundler: "none",
|
|
593
|
-
includedFiles: ["**"],
|
|
594
|
-
preferStatic: false,
|
|
595
|
-
};
|
|
529
|
+
const server = `// Mark this isolate as the durable background runtime BEFORE the handler bundle
|
|
530
|
+
// is imported, so isInBackgroundFunctionRuntime() reliably returns true in this
|
|
531
|
+
// function (the deployed Lambda name is not guaranteed to end in -background). A
|
|
532
|
+
// globalThis flag (NOT process.env) avoids the no-env-mutation guard and carries
|
|
533
|
+
// no cross-request state.
|
|
534
|
+
globalThis.__AGENT_NATIVE_BACKGROUND_RUNTIME__ = true;
|
|
535
|
+
|
|
536
|
+
const basePath = ${JSON.stringify(basePath)};
|
|
537
|
+
// The base-path-prefixed framework route the Nitro router dispatches to.
|
|
538
|
+
const PROCESS_RUN_PATH = ${JSON.stringify(processRunPath)};
|
|
539
|
+
|
|
540
|
+
function setBasePathEnv() {
|
|
541
|
+
const processRef = globalThis.process ??= { env: {} };
|
|
542
|
+
processRef.env ??= {};
|
|
543
|
+
Object.assign(processRef.env, {
|
|
544
|
+
AGENT_NATIVE_WORKSPACE: "1",
|
|
545
|
+
AGENT_NATIVE_WORKSPACE_APP_ID: ${JSON.stringify(app)},
|
|
546
|
+
APP_BASE_PATH: basePath,
|
|
547
|
+
AGENT_NATIVE_WORKSPACE_APP_AUDIENCE: ${JSON.stringify(workspaceAppAudience)},
|
|
548
|
+
AGENT_NATIVE_WORKSPACE_APP_PUBLIC_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.publicPaths))},
|
|
549
|
+
AGENT_NATIVE_WORKSPACE_APP_PROTECTED_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.protectedPaths))},
|
|
550
|
+
VITE_AGENT_NATIVE_WORKSPACE: "1",
|
|
551
|
+
VITE_AGENT_NATIVE_WORKSPACE_APP_ID: ${JSON.stringify(app)},
|
|
552
|
+
VITE_APP_BASE_PATH: basePath,
|
|
553
|
+
VITE_AGENT_NATIVE_WORKSPACE_APP_AUDIENCE: ${JSON.stringify(workspaceAppAudience)},
|
|
554
|
+
VITE_AGENT_NATIVE_WORKSPACE_APP_PUBLIC_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.publicPaths))},
|
|
555
|
+
VITE_AGENT_NATIVE_WORKSPACE_APP_PROTECTED_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.protectedPaths))},
|
|
556
|
+
VITE_AGENT_NATIVE_WORKSPACE_APPS_JSON: ${JSON.stringify(JSON.stringify(workspaceApps))},
|
|
557
|
+
${JSON.stringify(WORKSPACE_APPS_ENV_KEY)}: ${JSON.stringify(JSON.stringify(workspaceApps))},
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
setBasePathEnv();
|
|
562
|
+
|
|
563
|
+
let cachedHandler;
|
|
564
|
+
|
|
565
|
+
// Reached at the DEFAULT url /.netlify/functions/${backgroundName}; REWRITE the
|
|
566
|
+
// incoming pathname to the base-path-prefixed _process-run route so the Nitro
|
|
567
|
+
// router runs the plugin. Method, ALL headers (the HMAC Authorization: Bearer
|
|
568
|
+
// MUST survive) and the body are preserved.
|
|
569
|
+
export default async function handler(request) {
|
|
570
|
+
setBasePathEnv();
|
|
571
|
+
cachedHandler ??= (await import("./main.mjs")).default;
|
|
572
|
+
const url = new URL(request.url);
|
|
573
|
+
url.pathname = PROCESS_RUN_PATH;
|
|
574
|
+
const method = request.method || "POST";
|
|
575
|
+
const hasBody = method !== "GET" && method !== "HEAD";
|
|
576
|
+
const body = hasBody ? await request.text() : undefined;
|
|
577
|
+
const rewritten = new Request(url.toString(), {
|
|
578
|
+
method,
|
|
579
|
+
headers: request.headers,
|
|
580
|
+
body,
|
|
581
|
+
});
|
|
582
|
+
return cachedHandler(rewritten);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
export const config = {
|
|
586
|
+
name: ${JSON.stringify(`${app} agent background handler`)},
|
|
587
|
+
generator: "agent-native workspace deploy",
|
|
588
|
+
// background: true → async invoke (202, 15-min budget). NO custom path: the
|
|
589
|
+
// function keeps its default url /.netlify/functions/${backgroundName}, which
|
|
590
|
+
// the <app>-server catch-all never shadows (it excludes /.netlify/*).
|
|
591
|
+
background: true,
|
|
592
|
+
nodeBundler: "none",
|
|
593
|
+
includedFiles: ["**"],
|
|
594
|
+
preferStatic: false,
|
|
595
|
+
};
|
|
596
596
|
`;
|
|
597
597
|
// Remove the original Nitro entry (server.mjs) so only our background entry
|
|
598
598
|
// is the function entrypoint, mirroring patchNetlifyFunctionEntry.
|
|
@@ -616,66 +616,66 @@ function patchNetlifyFunctionEntry(functionDir, app, workspaceApps, staticDir) {
|
|
|
616
616
|
: [basePath, `${basePath}/*`];
|
|
617
617
|
const normalizeBasePathHelper = app === "dispatch"
|
|
618
618
|
? ""
|
|
619
|
-
: `
|
|
620
|
-
function normalizeBasePathArgs(args) {
|
|
621
|
-
const request = args[0];
|
|
622
|
-
if (!request || typeof request.url !== "string" || typeof Request !== "function") {
|
|
623
|
-
return args;
|
|
624
|
-
}
|
|
625
|
-
const url = new URL(request.url);
|
|
626
|
-
if (url.pathname === basePath || url.pathname === \`\${basePath}/\`) {
|
|
627
|
-
url.pathname = \`\${basePath}//\`;
|
|
628
|
-
return [new Request(url, request), ...args.slice(1)];
|
|
629
|
-
}
|
|
630
|
-
return args;
|
|
631
|
-
}
|
|
619
|
+
: `
|
|
620
|
+
function normalizeBasePathArgs(args) {
|
|
621
|
+
const request = args[0];
|
|
622
|
+
if (!request || typeof request.url !== "string" || typeof Request !== "function") {
|
|
623
|
+
return args;
|
|
624
|
+
}
|
|
625
|
+
const url = new URL(request.url);
|
|
626
|
+
if (url.pathname === basePath || url.pathname === \`\${basePath}/\`) {
|
|
627
|
+
url.pathname = \`\${basePath}//\`;
|
|
628
|
+
return [new Request(url, request), ...args.slice(1)];
|
|
629
|
+
}
|
|
630
|
+
return args;
|
|
631
|
+
}
|
|
632
632
|
`;
|
|
633
633
|
const handlerArgs = app === "dispatch" ? "...args" : "...normalizeBasePathArgs(args)";
|
|
634
|
-
const server = `const basePath = ${JSON.stringify(basePath)};
|
|
635
|
-
|
|
636
|
-
function setBasePathEnv() {
|
|
637
|
-
const processRef = globalThis.process ??= { env: {} };
|
|
638
|
-
processRef.env ??= {};
|
|
639
|
-
Object.assign(processRef.env, {
|
|
640
|
-
AGENT_NATIVE_WORKSPACE: "1",
|
|
641
|
-
AGENT_NATIVE_WORKSPACE_APP_ID: ${JSON.stringify(app)},
|
|
642
|
-
APP_BASE_PATH: basePath,
|
|
643
|
-
AGENT_NATIVE_WORKSPACE_APP_AUDIENCE: ${JSON.stringify(workspaceAppAudience)},
|
|
644
|
-
AGENT_NATIVE_WORKSPACE_APP_PUBLIC_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.publicPaths))},
|
|
645
|
-
AGENT_NATIVE_WORKSPACE_APP_PROTECTED_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.protectedPaths))},
|
|
646
|
-
VITE_AGENT_NATIVE_WORKSPACE: "1",
|
|
647
|
-
VITE_AGENT_NATIVE_WORKSPACE_APP_ID: ${JSON.stringify(app)},
|
|
648
|
-
VITE_APP_BASE_PATH: basePath,
|
|
649
|
-
VITE_AGENT_NATIVE_WORKSPACE_APP_AUDIENCE: ${JSON.stringify(workspaceAppAudience)},
|
|
650
|
-
VITE_AGENT_NATIVE_WORKSPACE_APP_PUBLIC_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.publicPaths))},
|
|
651
|
-
VITE_AGENT_NATIVE_WORKSPACE_APP_PROTECTED_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.protectedPaths))},
|
|
652
|
-
VITE_AGENT_NATIVE_WORKSPACE_APPS_JSON: ${JSON.stringify(JSON.stringify(workspaceApps))},
|
|
653
|
-
${JSON.stringify(WORKSPACE_APPS_ENV_KEY)}: ${JSON.stringify(JSON.stringify(workspaceApps))},
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
setBasePathEnv();
|
|
658
|
-
${normalizeBasePathHelper}
|
|
659
|
-
|
|
660
|
-
let cachedHandler;
|
|
661
|
-
|
|
662
|
-
export default async function handler(...args) {
|
|
663
|
-
setBasePathEnv();
|
|
664
|
-
cachedHandler ??= (await import("./main.mjs")).default;
|
|
665
|
-
return cachedHandler(${handlerArgs});
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
export const config = {
|
|
669
|
-
name: ${JSON.stringify(`${app} server handler`)},
|
|
670
|
-
generator: "agent-native workspace deploy",
|
|
671
|
-
path: ${JSON.stringify(pathConfig)},
|
|
672
|
-
nodeBundler: "none",
|
|
673
|
-
includedFiles: ["**"],
|
|
634
|
+
const server = `const basePath = ${JSON.stringify(basePath)};
|
|
635
|
+
|
|
636
|
+
function setBasePathEnv() {
|
|
637
|
+
const processRef = globalThis.process ??= { env: {} };
|
|
638
|
+
processRef.env ??= {};
|
|
639
|
+
Object.assign(processRef.env, {
|
|
640
|
+
AGENT_NATIVE_WORKSPACE: "1",
|
|
641
|
+
AGENT_NATIVE_WORKSPACE_APP_ID: ${JSON.stringify(app)},
|
|
642
|
+
APP_BASE_PATH: basePath,
|
|
643
|
+
AGENT_NATIVE_WORKSPACE_APP_AUDIENCE: ${JSON.stringify(workspaceAppAudience)},
|
|
644
|
+
AGENT_NATIVE_WORKSPACE_APP_PUBLIC_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.publicPaths))},
|
|
645
|
+
AGENT_NATIVE_WORKSPACE_APP_PROTECTED_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.protectedPaths))},
|
|
646
|
+
VITE_AGENT_NATIVE_WORKSPACE: "1",
|
|
647
|
+
VITE_AGENT_NATIVE_WORKSPACE_APP_ID: ${JSON.stringify(app)},
|
|
648
|
+
VITE_APP_BASE_PATH: basePath,
|
|
649
|
+
VITE_AGENT_NATIVE_WORKSPACE_APP_AUDIENCE: ${JSON.stringify(workspaceAppAudience)},
|
|
650
|
+
VITE_AGENT_NATIVE_WORKSPACE_APP_PUBLIC_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.publicPaths))},
|
|
651
|
+
VITE_AGENT_NATIVE_WORKSPACE_APP_PROTECTED_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.protectedPaths))},
|
|
652
|
+
VITE_AGENT_NATIVE_WORKSPACE_APPS_JSON: ${JSON.stringify(JSON.stringify(workspaceApps))},
|
|
653
|
+
${JSON.stringify(WORKSPACE_APPS_ENV_KEY)}: ${JSON.stringify(JSON.stringify(workspaceApps))},
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
setBasePathEnv();
|
|
658
|
+
${normalizeBasePathHelper}
|
|
659
|
+
|
|
660
|
+
let cachedHandler;
|
|
661
|
+
|
|
662
|
+
export default async function handler(...args) {
|
|
663
|
+
setBasePathEnv();
|
|
664
|
+
cachedHandler ??= (await import("./main.mjs")).default;
|
|
665
|
+
return cachedHandler(${handlerArgs});
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
export const config = {
|
|
669
|
+
name: ${JSON.stringify(`${app} server handler`)},
|
|
670
|
+
generator: "agent-native workspace deploy",
|
|
671
|
+
path: ${JSON.stringify(pathConfig)},
|
|
672
|
+
nodeBundler: "none",
|
|
673
|
+
includedFiles: ["**"],
|
|
674
674
|
excludedPath: ${JSON.stringify(netlifyFunctionExcludedPaths(app, staticDir), null, 2)
|
|
675
675
|
.split("\n")
|
|
676
|
-
.join("\n ")},
|
|
677
|
-
preferStatic: false,
|
|
678
|
-
};
|
|
676
|
+
.join("\n ")},
|
|
677
|
+
preferStatic: false,
|
|
678
|
+
};
|
|
679
679
|
`;
|
|
680
680
|
fs.rmSync(serverPath, { force: true });
|
|
681
681
|
fs.writeFileSync(path.join(functionDir, `${app}-server.mjs`), server);
|
|
@@ -690,59 +690,59 @@ function patchVercelFunctionEntry(functionDir, app, workspaceApps) {
|
|
|
690
690
|
const basePath = `/${app}`;
|
|
691
691
|
const workspaceAppAudience = workspaceAppAudienceForApp(workspaceApps, app);
|
|
692
692
|
const workspaceAppRouteAccess = workspaceAppRouteAccessForApp(workspaceApps, app);
|
|
693
|
-
const entry = `const basePath = ${JSON.stringify(basePath)};
|
|
694
|
-
|
|
695
|
-
function setBasePathEnv() {
|
|
696
|
-
const processRef = globalThis.process ??= { env: {} };
|
|
697
|
-
processRef.env ??= {};
|
|
698
|
-
Object.assign(processRef.env, {
|
|
699
|
-
AGENT_NATIVE_WORKSPACE: "1",
|
|
700
|
-
AGENT_NATIVE_WORKSPACE_APP_ID: ${JSON.stringify(app)},
|
|
701
|
-
APP_BASE_PATH: basePath,
|
|
702
|
-
AGENT_NATIVE_WORKSPACE_APP_AUDIENCE: ${JSON.stringify(workspaceAppAudience)},
|
|
703
|
-
AGENT_NATIVE_WORKSPACE_APP_PUBLIC_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.publicPaths))},
|
|
704
|
-
AGENT_NATIVE_WORKSPACE_APP_PROTECTED_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.protectedPaths))},
|
|
705
|
-
VITE_AGENT_NATIVE_WORKSPACE: "1",
|
|
706
|
-
VITE_AGENT_NATIVE_WORKSPACE_APP_ID: ${JSON.stringify(app)},
|
|
707
|
-
VITE_APP_BASE_PATH: basePath,
|
|
708
|
-
VITE_AGENT_NATIVE_WORKSPACE_APP_AUDIENCE: ${JSON.stringify(workspaceAppAudience)},
|
|
709
|
-
VITE_AGENT_NATIVE_WORKSPACE_APP_PUBLIC_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.publicPaths))},
|
|
710
|
-
VITE_AGENT_NATIVE_WORKSPACE_APP_PROTECTED_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.protectedPaths))},
|
|
711
|
-
VITE_AGENT_NATIVE_WORKSPACE_APPS_JSON: ${JSON.stringify(JSON.stringify(workspaceApps))},
|
|
712
|
-
${JSON.stringify(WORKSPACE_APPS_ENV_KEY)}: ${JSON.stringify(JSON.stringify(workspaceApps))},
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
function normalizeBasePathArgs(args) {
|
|
717
|
-
const request = args[0];
|
|
718
|
-
if (!request) return args;
|
|
719
|
-
|
|
720
|
-
if (typeof Request === "function" && request instanceof Request) {
|
|
721
|
-
const url = new URL(request.url);
|
|
722
|
-
if (url.pathname === basePath || url.pathname === \`\${basePath}/\`) {
|
|
723
|
-
url.pathname = \`\${basePath}//\`;
|
|
724
|
-
return [new Request(url, request), ...args.slice(1)];
|
|
725
|
-
}
|
|
726
|
-
return args;
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
if (typeof request.url !== "string") return args;
|
|
730
|
-
const url = new URL(request.url, "http://agent-native.local");
|
|
731
|
-
if (url.pathname === basePath || url.pathname === \`\${basePath}/\`) {
|
|
732
|
-
request.url = \`\${basePath}//\${url.search}\`;
|
|
733
|
-
}
|
|
734
|
-
return args;
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
setBasePathEnv();
|
|
738
|
-
|
|
739
|
-
let cachedHandler;
|
|
740
|
-
|
|
741
|
-
export default async function handler(...args) {
|
|
742
|
-
setBasePathEnv();
|
|
743
|
-
cachedHandler ??= (await import("./main.mjs")).default;
|
|
744
|
-
return cachedHandler(...normalizeBasePathArgs(args));
|
|
745
|
-
}
|
|
693
|
+
const entry = `const basePath = ${JSON.stringify(basePath)};
|
|
694
|
+
|
|
695
|
+
function setBasePathEnv() {
|
|
696
|
+
const processRef = globalThis.process ??= { env: {} };
|
|
697
|
+
processRef.env ??= {};
|
|
698
|
+
Object.assign(processRef.env, {
|
|
699
|
+
AGENT_NATIVE_WORKSPACE: "1",
|
|
700
|
+
AGENT_NATIVE_WORKSPACE_APP_ID: ${JSON.stringify(app)},
|
|
701
|
+
APP_BASE_PATH: basePath,
|
|
702
|
+
AGENT_NATIVE_WORKSPACE_APP_AUDIENCE: ${JSON.stringify(workspaceAppAudience)},
|
|
703
|
+
AGENT_NATIVE_WORKSPACE_APP_PUBLIC_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.publicPaths))},
|
|
704
|
+
AGENT_NATIVE_WORKSPACE_APP_PROTECTED_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.protectedPaths))},
|
|
705
|
+
VITE_AGENT_NATIVE_WORKSPACE: "1",
|
|
706
|
+
VITE_AGENT_NATIVE_WORKSPACE_APP_ID: ${JSON.stringify(app)},
|
|
707
|
+
VITE_APP_BASE_PATH: basePath,
|
|
708
|
+
VITE_AGENT_NATIVE_WORKSPACE_APP_AUDIENCE: ${JSON.stringify(workspaceAppAudience)},
|
|
709
|
+
VITE_AGENT_NATIVE_WORKSPACE_APP_PUBLIC_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.publicPaths))},
|
|
710
|
+
VITE_AGENT_NATIVE_WORKSPACE_APP_PROTECTED_PATHS: ${JSON.stringify(JSON.stringify(workspaceAppRouteAccess.protectedPaths))},
|
|
711
|
+
VITE_AGENT_NATIVE_WORKSPACE_APPS_JSON: ${JSON.stringify(JSON.stringify(workspaceApps))},
|
|
712
|
+
${JSON.stringify(WORKSPACE_APPS_ENV_KEY)}: ${JSON.stringify(JSON.stringify(workspaceApps))},
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
function normalizeBasePathArgs(args) {
|
|
717
|
+
const request = args[0];
|
|
718
|
+
if (!request) return args;
|
|
719
|
+
|
|
720
|
+
if (typeof Request === "function" && request instanceof Request) {
|
|
721
|
+
const url = new URL(request.url);
|
|
722
|
+
if (url.pathname === basePath || url.pathname === \`\${basePath}/\`) {
|
|
723
|
+
url.pathname = \`\${basePath}//\`;
|
|
724
|
+
return [new Request(url, request), ...args.slice(1)];
|
|
725
|
+
}
|
|
726
|
+
return args;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
if (typeof request.url !== "string") return args;
|
|
730
|
+
const url = new URL(request.url, "http://agent-native.local");
|
|
731
|
+
if (url.pathname === basePath || url.pathname === \`\${basePath}/\`) {
|
|
732
|
+
request.url = \`\${basePath}//\${url.search}\`;
|
|
733
|
+
}
|
|
734
|
+
return args;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
setBasePathEnv();
|
|
738
|
+
|
|
739
|
+
let cachedHandler;
|
|
740
|
+
|
|
741
|
+
export default async function handler(...args) {
|
|
742
|
+
setBasePathEnv();
|
|
743
|
+
cachedHandler ??= (await import("./main.mjs")).default;
|
|
744
|
+
return cachedHandler(...normalizeBasePathArgs(args));
|
|
745
|
+
}
|
|
746
746
|
`;
|
|
747
747
|
fs.writeFileSync(entryPath, entry);
|
|
748
748
|
}
|
|
@@ -771,7 +771,12 @@ function netlifyFunctionsDir(workspaceRoot) {
|
|
|
771
771
|
return path.join(workspaceRoot, ".netlify", "functions-internal");
|
|
772
772
|
}
|
|
773
773
|
function cleanAppBuildOutputs(appDir) {
|
|
774
|
-
|
|
774
|
+
// .deploy-tmp: a crashed prior per-app build leaves partial artifacts that
|
|
775
|
+
// silently poison the next build for that app (observed on Windows: stale
|
|
776
|
+
// state made a cloudflare_pages build die after the vite phases with no
|
|
777
|
+
// error output). The deploy post-build also sweeps it, but clean here too
|
|
778
|
+
// so the unified build never depends on the child's hygiene.
|
|
779
|
+
for (const name of ["dist", ".output", "build", ".deploy-tmp"]) {
|
|
775
780
|
fs.rmSync(path.join(appDir, name), { recursive: true, force: true });
|
|
776
781
|
}
|
|
777
782
|
fs.rmSync(path.join(appDir, ".netlify", "functions-internal"), {
|