@agent-native/core 0.79.10 → 0.79.12
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 +343 -27
- package/dist/collab/awareness.d.ts +2 -2
- package/dist/collab/awareness.d.ts.map +1 -1
- package/dist/collab/routes.d.ts +2 -2
- package/dist/deploy/build.d.ts +27 -1
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +245 -26
- package/dist/deploy/build.js.map +1 -1
- package/dist/resources/handlers.d.ts +3 -3
- package/dist/server/transcribe-voice.d.ts +1 -1
- package/package.json +1 -1
package/corpus/core/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @agent-native/core
|
|
2
2
|
|
|
3
|
+
## 0.79.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- aec5806: Keep Cloudflare Pages workers under the bundle size limit by serving app HTML from a build-time static shell.
|
|
8
|
+
|
|
9
|
+
## 0.79.11
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 72c1b3d: Fix Cloudflare Pages worker builds for apps with browser screenshot helpers.
|
|
14
|
+
|
|
3
15
|
## 0.79.10
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/corpus/core/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-native/core",
|
|
3
|
-
"version": "0.79.
|
|
3
|
+
"version": "0.79.12",
|
|
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": {
|
|
@@ -82,6 +82,53 @@ export const NITRO_RUNTIME_IGNORE_PATTERNS = [
|
|
|
82
82
|
"**/*.test.cjs",
|
|
83
83
|
];
|
|
84
84
|
|
|
85
|
+
export const CLOUDFLARE_WORKER_ESBUILD_EXTERNALS = [
|
|
86
|
+
"mermaid",
|
|
87
|
+
"@excalidraw/excalidraw",
|
|
88
|
+
"@excalidraw/mermaid-to-excalidraw",
|
|
89
|
+
"pdf-parse",
|
|
90
|
+
"pdfjs-dist",
|
|
91
|
+
"@google/genai",
|
|
92
|
+
"chartjs-node-canvas",
|
|
93
|
+
"@napi-rs/canvas",
|
|
94
|
+
"@anthropic-ai/tokenizer",
|
|
95
|
+
"@resvg/resvg-js",
|
|
96
|
+
"playwright",
|
|
97
|
+
"playwright-core",
|
|
98
|
+
"chromium-bidi",
|
|
99
|
+
"chromium-bidi/*",
|
|
100
|
+
"@sparticuz/chromium-min",
|
|
101
|
+
"fsevents",
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
export interface GenerateWorkerEntryOptions {
|
|
105
|
+
includeReactRouterSsr?: boolean;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
interface ReactRouterAssetManifest {
|
|
109
|
+
entry: ReactRouterAssetManifestEntry;
|
|
110
|
+
routes: Record<string, ReactRouterAssetManifestRoute>;
|
|
111
|
+
url: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface ReactRouterAssetManifestEntry {
|
|
115
|
+
module: string;
|
|
116
|
+
imports?: string[];
|
|
117
|
+
css?: string[];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
interface ReactRouterAssetManifestRoute {
|
|
121
|
+
id: string;
|
|
122
|
+
module: string;
|
|
123
|
+
imports?: string[];
|
|
124
|
+
css?: string[];
|
|
125
|
+
hasLoader?: boolean;
|
|
126
|
+
clientActionModule?: string;
|
|
127
|
+
clientLoaderModule?: string;
|
|
128
|
+
clientMiddlewareModule?: string;
|
|
129
|
+
hydrateFallbackModule?: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
85
132
|
function normalizeConfiguredAppBasePath(): string {
|
|
86
133
|
return normalizeAppBasePath(
|
|
87
134
|
process.env.VITE_APP_BASE_PATH || process.env.APP_BASE_PATH,
|
|
@@ -181,7 +228,9 @@ export function generateWorkerEntry(
|
|
|
181
228
|
workspaceCore: WorkspaceCoreExports | null = null,
|
|
182
229
|
immutableAssetPaths: string[] = [],
|
|
183
230
|
builtAppBasePath = normalizeConfiguredAppBasePath(),
|
|
231
|
+
options: GenerateWorkerEntryOptions = {},
|
|
184
232
|
): string {
|
|
233
|
+
const includeReactRouterSsr = options.includeReactRouterSsr ?? true;
|
|
185
234
|
const routeImports: string[] = [];
|
|
186
235
|
const routeRegistrations: string[] = [];
|
|
187
236
|
|
|
@@ -303,8 +352,8 @@ export function generateWorkerEntry(
|
|
|
303
352
|
return `
|
|
304
353
|
// Auto-generated worker entry point for ${preset}
|
|
305
354
|
import { H3, defineEventHandler, readBody, toResponse } from "h3";
|
|
306
|
-
import { createRequestHandler } from "react-router";
|
|
307
|
-
import * as serverBuild from "./server-build.js";
|
|
355
|
+
${includeReactRouterSsr ? 'import { createRequestHandler } from "react-router";' : ""}
|
|
356
|
+
${includeReactRouterSsr ? 'import * as serverBuild from "./server-build.js";' : ""}
|
|
308
357
|
|
|
309
358
|
function normalizeAppBasePath(value) {
|
|
310
359
|
if (!value || value === "/") return "";
|
|
@@ -634,6 +683,52 @@ function requestWithPathname(request, pathname) {
|
|
|
634
683
|
return new Request(url, request);
|
|
635
684
|
}
|
|
636
685
|
|
|
686
|
+
function isStaticAppShellRequest(request) {
|
|
687
|
+
if (request.method !== "GET" && request.method !== "HEAD") return false;
|
|
688
|
+
const p = stripAppBasePath(new URL(request.url).pathname);
|
|
689
|
+
if (
|
|
690
|
+
p.startsWith("/.well-known/") ||
|
|
691
|
+
p.startsWith("/_agent-native/") ||
|
|
692
|
+
isApiPath(p) ||
|
|
693
|
+
p === "/favicon.ico" ||
|
|
694
|
+
p === "/favicon.png" ||
|
|
695
|
+
/\\.\\w+$/.test(p)
|
|
696
|
+
) {
|
|
697
|
+
return false;
|
|
698
|
+
}
|
|
699
|
+
return true;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
async function fetchStaticAppShell(request, env) {
|
|
703
|
+
if (!env?.ASSETS || !isStaticAppShellRequest(request)) return null;
|
|
704
|
+
const basePath = getAppBasePath();
|
|
705
|
+
const p = stripAppBasePath(new URL(request.url).pathname);
|
|
706
|
+
const shellRequest = requestWithPathname(
|
|
707
|
+
requestWithMethod(request, "GET"),
|
|
708
|
+
"/index.html",
|
|
709
|
+
);
|
|
710
|
+
let response;
|
|
711
|
+
try {
|
|
712
|
+
response = await env.ASSETS.fetch(shellRequest);
|
|
713
|
+
} catch {
|
|
714
|
+
return null;
|
|
715
|
+
}
|
|
716
|
+
if (response.status === 404) return null;
|
|
717
|
+
if (request.method === "HEAD") {
|
|
718
|
+
return rewriteMountedResponse(
|
|
719
|
+
new Response(null, {
|
|
720
|
+
status: response.status,
|
|
721
|
+
statusText: response.statusText,
|
|
722
|
+
headers: response.headers,
|
|
723
|
+
}),
|
|
724
|
+
basePath,
|
|
725
|
+
p,
|
|
726
|
+
request,
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
return rewriteMountedResponse(response, basePath, p, request);
|
|
730
|
+
}
|
|
731
|
+
|
|
637
732
|
// API route handlers
|
|
638
733
|
${routeImports.join("\n")}
|
|
639
734
|
|
|
@@ -689,7 +784,9 @@ ${routeRegistrations.join("\n")}
|
|
|
689
784
|
// Register action routes (/_agent-native/actions/*)
|
|
690
785
|
${actionRegistrations.join("\n")}
|
|
691
786
|
|
|
692
|
-
|
|
787
|
+
${
|
|
788
|
+
includeReactRouterSsr
|
|
789
|
+
? ` // SSR catch-all for React Router
|
|
693
790
|
const rrHandler = createRequestHandler(() => serverBuild);
|
|
694
791
|
app.all("/**", defineEventHandler(async (event) => {
|
|
695
792
|
const basePath = getAppBasePath();
|
|
@@ -720,7 +817,9 @@ ${actionRegistrations.join("\n")}
|
|
|
720
817
|
);
|
|
721
818
|
}
|
|
722
819
|
return rewriteMountedResponse(await rrHandler(request), basePath, p, request);
|
|
723
|
-
}))
|
|
820
|
+
}));`
|
|
821
|
+
: ""
|
|
822
|
+
}
|
|
724
823
|
|
|
725
824
|
_handler = app.fetch.bind(app);
|
|
726
825
|
return _handler;
|
|
@@ -759,12 +858,227 @@ export default {
|
|
|
759
858
|
}
|
|
760
859
|
|
|
761
860
|
const handler = await getHandler();
|
|
762
|
-
|
|
861
|
+
const response = await handler(requestWithMountedApiPrefixStripped(request));
|
|
862
|
+
${
|
|
863
|
+
includeReactRouterSsr
|
|
864
|
+
? " return response;"
|
|
865
|
+
: ` if (response.status === 404) {
|
|
866
|
+
const shellResponse = await fetchStaticAppShell(request, env);
|
|
867
|
+
if (shellResponse) return shellResponse;
|
|
868
|
+
}
|
|
869
|
+
return response;`
|
|
870
|
+
}
|
|
763
871
|
}
|
|
764
872
|
};
|
|
765
873
|
`;
|
|
766
874
|
}
|
|
767
875
|
|
|
876
|
+
function escapeHtmlAttribute(value: string): string {
|
|
877
|
+
return value
|
|
878
|
+
.replaceAll("&", "&")
|
|
879
|
+
.replaceAll('"', """)
|
|
880
|
+
.replaceAll("<", "<")
|
|
881
|
+
.replaceAll(">", ">");
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
function findReactRouterManifest(distDir: string): ReactRouterAssetManifest {
|
|
885
|
+
const assetsDir = path.join(distDir, "assets");
|
|
886
|
+
const manifestFile = fs
|
|
887
|
+
.readdirSync(assetsDir)
|
|
888
|
+
.find((file) => /^manifest-[\w-]+\.js$/.test(file));
|
|
889
|
+
if (!manifestFile) {
|
|
890
|
+
throw new Error(`React Router client manifest not found in ${assetsDir}`);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
const source = fs.readFileSync(path.join(assetsDir, manifestFile), "utf8");
|
|
894
|
+
const match = source.match(/^window\.__reactRouterManifest=(.*);?\s*$/);
|
|
895
|
+
if (!match) {
|
|
896
|
+
throw new Error(`Could not parse React Router manifest ${manifestFile}`);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
return JSON.parse(match[1].replace(/;$/, "")) as ReactRouterAssetManifest;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
function collectModulePreloads(
|
|
903
|
+
manifest: ReactRouterAssetManifest,
|
|
904
|
+
route: ReactRouterAssetManifestRoute,
|
|
905
|
+
): string[] {
|
|
906
|
+
const paths = new Set<string>();
|
|
907
|
+
const add = (value: string | undefined) => {
|
|
908
|
+
if (value) paths.add(value);
|
|
909
|
+
};
|
|
910
|
+
add(manifest.url);
|
|
911
|
+
add(manifest.entry.module);
|
|
912
|
+
manifest.entry.imports?.forEach(add);
|
|
913
|
+
add(route.module);
|
|
914
|
+
route.imports?.forEach(add);
|
|
915
|
+
add(route.clientActionModule);
|
|
916
|
+
add(route.clientLoaderModule);
|
|
917
|
+
add(route.clientMiddlewareModule);
|
|
918
|
+
add(route.hydrateFallbackModule);
|
|
919
|
+
return [...paths];
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
function collectStylesheetLinks(
|
|
923
|
+
manifest: ReactRouterAssetManifest,
|
|
924
|
+
route: ReactRouterAssetManifestRoute,
|
|
925
|
+
): string[] {
|
|
926
|
+
return [...new Set([...(manifest.entry.css ?? []), ...(route.css ?? [])])];
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
function generateRouteModuleImportScript(
|
|
930
|
+
manifest: ReactRouterAssetManifest,
|
|
931
|
+
route: ReactRouterAssetManifestRoute,
|
|
932
|
+
): string {
|
|
933
|
+
const modules = [
|
|
934
|
+
["route0", route.module],
|
|
935
|
+
["route0_clientAction", route.clientActionModule],
|
|
936
|
+
["route0_clientLoader", route.clientLoaderModule],
|
|
937
|
+
["route0_clientMiddleware", route.clientMiddlewareModule],
|
|
938
|
+
["route0_hydrateFallback", route.hydrateFallbackModule],
|
|
939
|
+
] as const;
|
|
940
|
+
const imports = modules
|
|
941
|
+
.filter(([, modulePath]) => modulePath)
|
|
942
|
+
.map(
|
|
943
|
+
([name, modulePath]) =>
|
|
944
|
+
`import * as ${name} from ${JSON.stringify(modulePath)};`,
|
|
945
|
+
);
|
|
946
|
+
const parts = modules
|
|
947
|
+
.filter(([, modulePath]) => modulePath)
|
|
948
|
+
.map(([name]) => `...${name}`);
|
|
949
|
+
|
|
950
|
+
return [
|
|
951
|
+
`import ${JSON.stringify(manifest.url)};`,
|
|
952
|
+
...imports,
|
|
953
|
+
`window.__reactRouterRouteModules = {${JSON.stringify(route.id)}:{${parts.join(",")}}};`,
|
|
954
|
+
`import(${JSON.stringify(manifest.entry.module)});`,
|
|
955
|
+
].join("\n");
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
const EMPTY_REACT_ROUTER_TURBO_STREAM =
|
|
959
|
+
'[{"_1":2,"_3":-5,"_4":-5},"loaderData",{},"actionData","errors"]\n';
|
|
960
|
+
|
|
961
|
+
// Manifest fallbacks cannot execute server loaders, so root loaders get the
|
|
962
|
+
// framework's default locale shape to keep hydration from reading undefined.
|
|
963
|
+
const DEFAULT_ROOT_LOADER_REACT_ROUTER_TURBO_STREAM =
|
|
964
|
+
'[{"_1":2,"_3":-5,"_4":-5},"loaderData",{"_5":6},"actionData","errors","root",{"_7":8,"_9":10,"_11":12,"_13":14},"locale","en-US","preference",{"_7":15},"dir","ltr","messages",{},"system"]\n';
|
|
965
|
+
|
|
966
|
+
export function generateCloudflarePagesStaticShellFromManifest(
|
|
967
|
+
manifest: ReactRouterAssetManifest,
|
|
968
|
+
basePath = normalizeConfiguredAppBasePath(),
|
|
969
|
+
): string {
|
|
970
|
+
const rootRoute = manifest.routes.root;
|
|
971
|
+
if (!rootRoute) {
|
|
972
|
+
throw new Error("React Router manifest is missing the root route");
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
const modulePreloads = collectModulePreloads(manifest, rootRoute)
|
|
976
|
+
.map(
|
|
977
|
+
(href) =>
|
|
978
|
+
`<link rel="modulepreload" href="${escapeHtmlAttribute(href)}"/>`,
|
|
979
|
+
)
|
|
980
|
+
.join("");
|
|
981
|
+
const stylesheets = collectStylesheetLinks(manifest, rootRoute)
|
|
982
|
+
.map(
|
|
983
|
+
(href) => `<link rel="stylesheet" href="${escapeHtmlAttribute(href)}"/>`,
|
|
984
|
+
)
|
|
985
|
+
.join("");
|
|
986
|
+
const routeModuleScript = generateRouteModuleImportScript(
|
|
987
|
+
manifest,
|
|
988
|
+
rootRoute,
|
|
989
|
+
);
|
|
990
|
+
const context = {
|
|
991
|
+
basename: basePath || "/",
|
|
992
|
+
future: { unstable_optimizeDeps: false },
|
|
993
|
+
routeDiscovery: { mode: "initial" },
|
|
994
|
+
ssr: true,
|
|
995
|
+
isSpaMode: true,
|
|
996
|
+
};
|
|
997
|
+
const encodedInitialState = rootRoute.hasLoader
|
|
998
|
+
? DEFAULT_ROOT_LOADER_REACT_ROUTER_TURBO_STREAM
|
|
999
|
+
: EMPTY_REACT_ROUTER_TURBO_STREAM;
|
|
1000
|
+
|
|
1001
|
+
return `<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/><link rel="manifest" href="/manifest.json"/><link rel="icon" type="image/svg+xml" href="/favicon.svg"/>${modulePreloads}${stylesheets}</head><body><div style="display:flex;align-items:center;justify-content:center;height:100vh;width:100%"><svg role="status" aria-label="Loading" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="animation:an-spin 1s linear infinite;opacity:0.7"><path d="M21 12a9 9 0 1 1-6.219-8.56"></path></svg><style>@keyframes an-spin { to { transform: rotate(360deg) } } @media (prefers-color-scheme: dark) { html { background: #09090b; color: #fafafa } }</style></div><script>window.__reactRouterContext = ${JSON.stringify(context)};window.__reactRouterContext.stream = new ReadableStream({start(controller){window.__reactRouterContext.streamController = controller;}}).pipeThrough(new TextEncoderStream());</script><script type="module" async="">${routeModuleScript}</script><!--$--><script>window.__reactRouterContext.streamController.enqueue(${JSON.stringify(encodedInitialState)});</script><!--$--><script>window.__reactRouterContext.streamController.close();</script><!--/$--><!--/$--></body></html>`;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
function writeCloudflarePagesStaticShell({
|
|
1005
|
+
serverDir,
|
|
1006
|
+
distDir,
|
|
1007
|
+
tmpDir,
|
|
1008
|
+
}: {
|
|
1009
|
+
serverDir: string;
|
|
1010
|
+
distDir: string;
|
|
1011
|
+
tmpDir: string;
|
|
1012
|
+
}): void {
|
|
1013
|
+
const serverEntry = path.join(serverDir, "index.js");
|
|
1014
|
+
if (!fs.existsSync(serverEntry)) {
|
|
1015
|
+
throw new Error(`React Router server build not found at ${serverEntry}`);
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
const outFile = path.join(distDir, "index.html");
|
|
1019
|
+
const renderScript = path.join(tmpDir, "render-cloudflare-static-shell.mjs");
|
|
1020
|
+
const basePath = normalizeConfiguredAppBasePath();
|
|
1021
|
+
fs.writeFileSync(
|
|
1022
|
+
renderScript,
|
|
1023
|
+
`
|
|
1024
|
+
import fs from "node:fs";
|
|
1025
|
+
import { createRequire } from "node:module";
|
|
1026
|
+
import { pathToFileURL } from "node:url";
|
|
1027
|
+
|
|
1028
|
+
const cwd = ${JSON.stringify(cwd)};
|
|
1029
|
+
const serverEntry = ${JSON.stringify(serverEntry)};
|
|
1030
|
+
const outFile = ${JSON.stringify(outFile)};
|
|
1031
|
+
const basePath = ${JSON.stringify(basePath)};
|
|
1032
|
+
|
|
1033
|
+
const requireFromApp = createRequire(cwd + "/package.json");
|
|
1034
|
+
const reactRouterEntry = requireFromApp.resolve("react-router");
|
|
1035
|
+
const { createRequestHandler } = await import(pathToFileURL(reactRouterEntry).href);
|
|
1036
|
+
const serverBuild = await import(pathToFileURL(serverEntry).href);
|
|
1037
|
+
const handler = createRequestHandler(serverBuild, "production");
|
|
1038
|
+
const pathname = basePath ? basePath + "/" : "/";
|
|
1039
|
+
const response = await handler(
|
|
1040
|
+
new Request(new URL(pathname, "https://agent-native.local"), {
|
|
1041
|
+
headers: { "X-React-Router-SPA-Mode": "yes" },
|
|
1042
|
+
}),
|
|
1043
|
+
);
|
|
1044
|
+
const html = await response.text();
|
|
1045
|
+
|
|
1046
|
+
if (!html || !html.includes("__reactRouterContext") || !html.includes("entry.client")) {
|
|
1047
|
+
throw new Error("React Router did not render a usable Cloudflare Pages static shell");
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
fs.writeFileSync(outFile, html);
|
|
1051
|
+
process.exit(0);
|
|
1052
|
+
`,
|
|
1053
|
+
);
|
|
1054
|
+
|
|
1055
|
+
try {
|
|
1056
|
+
execFileSync(process.execPath, [renderScript], {
|
|
1057
|
+
cwd,
|
|
1058
|
+
env: {
|
|
1059
|
+
...process.env,
|
|
1060
|
+
NODE_ENV: process.env.NODE_ENV || "production",
|
|
1061
|
+
IS_RR_BUILD_REQUEST: "yes",
|
|
1062
|
+
},
|
|
1063
|
+
stdio: "inherit",
|
|
1064
|
+
});
|
|
1065
|
+
console.log("[deploy] Wrote Cloudflare Pages static app shell.");
|
|
1066
|
+
} catch (error) {
|
|
1067
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1068
|
+
console.warn(
|
|
1069
|
+
`[deploy] React Router static shell render failed; using manifest fallback. ${message}`,
|
|
1070
|
+
);
|
|
1071
|
+
fs.writeFileSync(
|
|
1072
|
+
outFile,
|
|
1073
|
+
generateCloudflarePagesStaticShellFromManifest(
|
|
1074
|
+
findReactRouterManifest(distDir),
|
|
1075
|
+
basePath,
|
|
1076
|
+
),
|
|
1077
|
+
);
|
|
1078
|
+
console.log("[deploy] Wrote Cloudflare Pages static app shell fallback.");
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
768
1082
|
/**
|
|
769
1083
|
* Build for Cloudflare Pages.
|
|
770
1084
|
* Output structure:
|
|
@@ -797,6 +1111,10 @@ async function buildCloudflarePages() {
|
|
|
797
1111
|
// Copy client assets to dist/
|
|
798
1112
|
copyDir(clientDir, distDir);
|
|
799
1113
|
|
|
1114
|
+
const tmpDir = path.join(cwd, ".deploy-tmp");
|
|
1115
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
1116
|
+
writeCloudflarePagesStaticShell({ serverDir, distDir, tmpDir });
|
|
1117
|
+
|
|
800
1118
|
// Exclude _worker.js from being served as a public asset
|
|
801
1119
|
fs.writeFileSync(path.join(distDir, ".assetsignore"), "_worker.js\n");
|
|
802
1120
|
|
|
@@ -822,6 +1140,7 @@ async function buildCloudflarePages() {
|
|
|
822
1140
|
const actions = await discoverActionFiles(cwd);
|
|
823
1141
|
const missingDefaults = await getMissingDefaultPlugins(cwd);
|
|
824
1142
|
const workspaceCore = await getWorkspaceCoreExports(cwd);
|
|
1143
|
+
const includeReactRouterSsr = false;
|
|
825
1144
|
|
|
826
1145
|
const workspaceSlotCount = workspaceCore
|
|
827
1146
|
? Object.keys(workspaceCore.plugins).length
|
|
@@ -839,6 +1158,8 @@ async function buildCloudflarePages() {
|
|
|
839
1158
|
actions,
|
|
840
1159
|
workspaceCore,
|
|
841
1160
|
immutableAssetPaths,
|
|
1161
|
+
normalizeConfiguredAppBasePath(),
|
|
1162
|
+
{ includeReactRouterSsr },
|
|
842
1163
|
);
|
|
843
1164
|
|
|
844
1165
|
// Create _worker.js output directory
|
|
@@ -848,23 +1169,27 @@ async function buildCloudflarePages() {
|
|
|
848
1169
|
// Write the worker entry
|
|
849
1170
|
const entryFile = path.join(workerOutDir, "index.js");
|
|
850
1171
|
|
|
851
|
-
// Rewrite the server-build import to point at the copied files
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
1172
|
+
// Rewrite the server-build import to point at the copied files when this
|
|
1173
|
+
// worker intentionally includes React Router SSR.
|
|
1174
|
+
const adjustedEntry = includeReactRouterSsr
|
|
1175
|
+
? entrySource.replace(
|
|
1176
|
+
`import * as serverBuild from "./server-build.js";`,
|
|
1177
|
+
`import * as serverBuild from "./server/index.js";`,
|
|
1178
|
+
)
|
|
1179
|
+
: entrySource;
|
|
856
1180
|
|
|
857
1181
|
// Write a temp file for esbuild to bundle everything into a single worker entry.
|
|
858
|
-
//
|
|
859
|
-
|
|
860
|
-
|
|
1182
|
+
// When React Router SSR is enabled, the server build is copied to tmp so
|
|
1183
|
+
// esbuild can resolve it. Cloudflare Pages currently uses a static app shell
|
|
1184
|
+
// instead so the worker stays under the platform bundle size limit.
|
|
861
1185
|
// Name the entry "index.js" so esbuild outputs index.js in the outdir,
|
|
862
1186
|
// matching the _worker.js/index.js entry point that Cloudflare Pages expects.
|
|
863
1187
|
const tmpEntry = path.join(tmpDir, "index.js");
|
|
864
1188
|
fs.writeFileSync(tmpEntry, adjustedEntry);
|
|
865
1189
|
|
|
866
|
-
|
|
867
|
-
|
|
1190
|
+
if (includeReactRouterSsr) {
|
|
1191
|
+
copyDir(serverDir, path.join(tmpDir, "server"));
|
|
1192
|
+
}
|
|
868
1193
|
|
|
869
1194
|
// Create a require shim so CJS require("fs") calls resolve via ESM imports.
|
|
870
1195
|
// This is injected via esbuild --inject to replace its broken __require shim.
|
|
@@ -946,18 +1271,9 @@ async function buildCloudflarePages() {
|
|
|
946
1271
|
// files. Both import sites degrade gracefully when the runtime import
|
|
947
1272
|
// fails: context-xray token counts fall back to char/4 estimates and the
|
|
948
1273
|
// OG image route falls back to SVG.
|
|
949
|
-
const heavyClientExternals =
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
"@excalidraw/mermaid-to-excalidraw",
|
|
953
|
-
"pdf-parse",
|
|
954
|
-
"pdfjs-dist",
|
|
955
|
-
"@google/genai",
|
|
956
|
-
"chartjs-node-canvas",
|
|
957
|
-
"@napi-rs/canvas",
|
|
958
|
-
"@anthropic-ai/tokenizer",
|
|
959
|
-
"@resvg/resvg-js",
|
|
960
|
-
].map((p) => `--external:${p}`);
|
|
1274
|
+
const heavyClientExternals = CLOUDFLARE_WORKER_ESBUILD_EXTERNALS.map(
|
|
1275
|
+
(p) => `--external:${p}`,
|
|
1276
|
+
);
|
|
961
1277
|
|
|
962
1278
|
execFileSync(
|
|
963
1279
|
esbuildBin,
|
|
@@ -49,11 +49,11 @@ export declare const postAwareness: import("h3").EventHandlerWithFetch<import("h
|
|
|
49
49
|
error: string;
|
|
50
50
|
states?: undefined;
|
|
51
51
|
} | {
|
|
52
|
+
error?: undefined;
|
|
52
53
|
states: {
|
|
53
54
|
clientId: number;
|
|
54
55
|
state: string;
|
|
55
56
|
}[];
|
|
56
|
-
error?: undefined;
|
|
57
57
|
}>>;
|
|
58
58
|
/**
|
|
59
59
|
* GET /_agent-native/collab/:docId/users
|
|
@@ -64,10 +64,10 @@ export declare const getActiveUsers: import("h3").EventHandlerWithFetch<import("
|
|
|
64
64
|
error: string;
|
|
65
65
|
users?: undefined;
|
|
66
66
|
} | {
|
|
67
|
+
error?: undefined;
|
|
67
68
|
users: {
|
|
68
69
|
clientId: number;
|
|
69
70
|
lastSeen: number;
|
|
70
71
|
}[];
|
|
71
|
-
error?: undefined;
|
|
72
72
|
}>>;
|
|
73
73
|
//# 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;AAS3C,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,E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,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAKD,wBAAgB,mBAAmB,IAAI,YAAY,CAElD;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,EAClD,KAAK,CAAC,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,MAAM,GACb,IAAI,CAUN;AAKD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAO1E;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,IAAI,CAOnE;AAUD;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa;;;;;;kBAuCa,MAAM;eAAS,MAAM;;GAa1D,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,cAAc;;;;;;kBAWM,MAAM;kBAAY,MAAM;;GAMvD,CAAC"}
|
package/dist/collab/routes.d.ts
CHANGED
|
@@ -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;
|
|
@@ -42,8 +42,8 @@ export declare const postCollabUpdate: import("h3").EventHandlerWithFetch<import
|
|
|
42
42
|
*/
|
|
43
43
|
export declare const postCollabText: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
44
44
|
ok?: undefined;
|
|
45
|
-
text?: undefined;
|
|
46
45
|
error: string;
|
|
46
|
+
text?: undefined;
|
|
47
47
|
} | {
|
|
48
48
|
error?: undefined;
|
|
49
49
|
ok: boolean;
|
package/dist/deploy/build.d.ts
CHANGED
|
@@ -15,6 +15,31 @@
|
|
|
15
15
|
import { type DiscoveredRoute, type DiscoveredAction } from "./route-discovery.js";
|
|
16
16
|
import { type WorkspaceCoreExports } from "./workspace-core.js";
|
|
17
17
|
export declare const NITRO_RUNTIME_IGNORE_PATTERNS: string[];
|
|
18
|
+
export declare const CLOUDFLARE_WORKER_ESBUILD_EXTERNALS: string[];
|
|
19
|
+
export interface GenerateWorkerEntryOptions {
|
|
20
|
+
includeReactRouterSsr?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface ReactRouterAssetManifest {
|
|
23
|
+
entry: ReactRouterAssetManifestEntry;
|
|
24
|
+
routes: Record<string, ReactRouterAssetManifestRoute>;
|
|
25
|
+
url: string;
|
|
26
|
+
}
|
|
27
|
+
interface ReactRouterAssetManifestEntry {
|
|
28
|
+
module: string;
|
|
29
|
+
imports?: string[];
|
|
30
|
+
css?: string[];
|
|
31
|
+
}
|
|
32
|
+
interface ReactRouterAssetManifestRoute {
|
|
33
|
+
id: string;
|
|
34
|
+
module: string;
|
|
35
|
+
imports?: string[];
|
|
36
|
+
css?: string[];
|
|
37
|
+
hasLoader?: boolean;
|
|
38
|
+
clientActionModule?: string;
|
|
39
|
+
clientLoaderModule?: string;
|
|
40
|
+
clientMiddlewareModule?: string;
|
|
41
|
+
hydrateFallbackModule?: string;
|
|
42
|
+
}
|
|
18
43
|
export declare function generateProvidedPluginsNitroPluginSource(pluginStems: string[]): string;
|
|
19
44
|
type RouteRules = Record<string, {
|
|
20
45
|
headers?: Record<string, string>;
|
|
@@ -29,7 +54,8 @@ export declare function addImmutableAssetRouteRulesForClientBuild(routeRules: Ro
|
|
|
29
54
|
* `@agent-native/core/server`. This is the middle layer of the three-layer
|
|
30
55
|
* inheritance model: app local > workspace core > framework default.
|
|
31
56
|
*/
|
|
32
|
-
export declare function generateWorkerEntry(routes: DiscoveredRoute[], pluginPaths: string[], defaultPluginStems?: string[], actions?: DiscoveredAction[], workspaceCore?: WorkspaceCoreExports | null, immutableAssetPaths?: string[], builtAppBasePath?: string): string;
|
|
57
|
+
export declare function generateWorkerEntry(routes: DiscoveredRoute[], pluginPaths: string[], defaultPluginStems?: string[], actions?: DiscoveredAction[], workspaceCore?: WorkspaceCoreExports | null, immutableAssetPaths?: string[], builtAppBasePath?: string, options?: GenerateWorkerEntryOptions): string;
|
|
58
|
+
export declare function generateCloudflarePagesStaticShellFromManifest(manifest: ReactRouterAssetManifest, basePath?: string): string;
|
|
33
59
|
export declare function getNodeBuiltinNames(): string[];
|
|
34
60
|
export declare function copyDir(src: string, dest: string, ancestorRealPaths?: Set<string>): void;
|
|
35
61
|
type ServerlessFfmpegStaticArch = "arm64" | "x64";
|
|
@@ -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;
|
|
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;AAEF,MAAM,WAAW,0BAA0B;IACzC,qBAAqB,CAAC,EA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