@agent-native/core 0.22.19 → 0.22.20
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/dist/client/embed-auth.d.ts.map +1 -1
- package/dist/client/embed-auth.js +85 -3
- package/dist/client/embed-auth.js.map +1 -1
- package/dist/client/mcp-apps/McpAppRenderer.d.ts +3 -0
- package/dist/client/mcp-apps/McpAppRenderer.d.ts.map +1 -1
- package/dist/client/mcp-apps/McpAppRenderer.js +86 -9
- package/dist/client/mcp-apps/McpAppRenderer.js.map +1 -1
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +73 -5
- package/dist/deploy/build.js.map +1 -1
- package/dist/mcp/build-server.d.ts.map +1 -1
- package/dist/mcp/build-server.js +40 -3
- package/dist/mcp/build-server.js.map +1 -1
- package/dist/mcp/builtin-tools.d.ts.map +1 -1
- package/dist/mcp/builtin-tools.js +6 -3
- package/dist/mcp/builtin-tools.js.map +1 -1
- package/dist/mcp/embed-app.d.ts +2 -2
- package/dist/mcp/embed-app.d.ts.map +1 -1
- package/dist/mcp/embed-app.js +390 -17
- package/dist/mcp/embed-app.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +37 -10
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/create-server.d.ts.map +1 -1
- package/dist/server/create-server.js +21 -7
- package/dist/server/create-server.js.map +1 -1
- package/dist/server/embed-route.d.ts.map +1 -1
- package/dist/server/embed-route.js +62 -21
- package/dist/server/embed-route.js.map +1 -1
- package/dist/server/security-headers.d.ts.map +1 -1
- package/dist/server/security-headers.js +9 -1
- package/dist/server/security-headers.js.map +1 -1
- package/dist/server/ssr-handler.d.ts +2 -0
- package/dist/server/ssr-handler.d.ts.map +1 -1
- package/dist/server/ssr-handler.js +66 -11
- package/dist/server/ssr-handler.js.map +1 -1
- package/dist/shared/mcp-embed-headers.d.ts +12 -0
- package/dist/shared/mcp-embed-headers.d.ts.map +1 -0
- package/dist/shared/mcp-embed-headers.js +51 -0
- package/dist/shared/mcp-embed-headers.js.map +1 -0
- package/dist/vite/client.d.ts.map +1 -1
- package/dist/vite/client.js +23 -0
- package/dist/vite/client.js.map +1 -1
- package/docs/content/actions.md +15 -5
- package/docs/content/external-agents.md +53 -27
- package/docs/content/mcp-protocol.md +29 -4
- package/package.json +1 -1
package/dist/deploy/build.js
CHANGED
|
@@ -20,8 +20,12 @@ import { fileURLToPath } from "url";
|
|
|
20
20
|
import { discoverApiRoutes, discoverPlugins, discoverActionFiles, getMissingDefaultPlugins, DEFAULT_PLUGIN_REGISTRY, } from "./route-discovery.js";
|
|
21
21
|
import { getWorkspaceCoreExports, } from "./workspace-core.js";
|
|
22
22
|
import { generateActionRegistryForProject } from "../vite/action-types-plugin.js";
|
|
23
|
+
import { mcpEmbedStaticAssetRouteRules } from "../shared/mcp-embed-headers.js";
|
|
24
|
+
import { EMBED_SESSION_COOKIE, EMBED_TOKEN_QUERY_PARAM, } from "../shared/embed-auth.js";
|
|
23
25
|
const cwd = process.cwd();
|
|
24
26
|
const preset = process.env.NITRO_PRESET || "node";
|
|
27
|
+
const DEFAULT_SSR_CACHE_CONTROL = "public, max-age=5, stale-while-revalidate=604800, stale-if-error=3600";
|
|
28
|
+
const AUTHENTICATED_SSR_CACHE_CONTROL = "private, max-age=5, stale-while-revalidate=604800, stale-if-error=3600";
|
|
25
29
|
function normalizeConfiguredAppBasePath() {
|
|
26
30
|
const raw = process.env.VITE_APP_BASE_PATH || process.env.APP_BASE_PATH;
|
|
27
31
|
if (!raw || raw === "/")
|
|
@@ -259,16 +263,77 @@ function injectHeadScript(html, script) {
|
|
|
259
263
|
return html.slice(0, headCloseIdx) + script + html.slice(headCloseIdx);
|
|
260
264
|
}
|
|
261
265
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
266
|
+
const DEFAULT_SSR_CACHE_CONTROL = ${JSON.stringify(DEFAULT_SSR_CACHE_CONTROL)};
|
|
267
|
+
const AUTHENTICATED_SSR_CACHE_CONTROL = ${JSON.stringify(AUTHENTICATED_SSR_CACHE_CONTROL)};
|
|
268
|
+
const EMBED_SESSION_COOKIE = ${JSON.stringify(EMBED_SESSION_COOKIE)};
|
|
269
|
+
const EMBED_TOKEN_QUERY_PARAM = ${JSON.stringify(EMBED_TOKEN_QUERY_PARAM)};
|
|
270
|
+
const ANONYMOUS_SESSION_COOKIE_NAMES = new Set(["an_docs_session"]);
|
|
271
|
+
const BETTER_AUTH_SESSION_COOKIE_RE = /\\.session_(?:token|data)$/;
|
|
272
|
+
|
|
273
|
+
function isAuthenticatedCookieName(name) {
|
|
274
|
+
if (ANONYMOUS_SESSION_COOKIE_NAMES.has(name)) return false;
|
|
275
|
+
const bareName = String(name || "").replace(/^__(?:Secure|Host)-/, "");
|
|
276
|
+
return (
|
|
277
|
+
bareName === EMBED_SESSION_COOKIE ||
|
|
278
|
+
bareName === "an_session" ||
|
|
279
|
+
bareName === "an_session_workspace" ||
|
|
280
|
+
bareName.startsWith("an_session_") ||
|
|
281
|
+
bareName === "an.session_token" ||
|
|
282
|
+
bareName === "an.session_data" ||
|
|
283
|
+
BETTER_AUTH_SESSION_COOKIE_RE.test(bareName)
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function requestHasAuthenticatedCookie(cookieHeader) {
|
|
288
|
+
if (!cookieHeader) return false;
|
|
289
|
+
return String(cookieHeader)
|
|
290
|
+
.split(";")
|
|
291
|
+
.map((cookie) => cookie.trim().split("=", 1)[0]?.trim())
|
|
292
|
+
.filter(Boolean)
|
|
293
|
+
.some(isAuthenticatedCookieName);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function requestHasAuthSignal(request) {
|
|
297
|
+
const url = new URL(request.url);
|
|
298
|
+
return Boolean(
|
|
299
|
+
request.headers.get("authorization") ||
|
|
300
|
+
requestHasAuthenticatedCookie(request.headers.get("cookie")) ||
|
|
301
|
+
url.searchParams.has(EMBED_TOKEN_QUERY_PARAM) ||
|
|
302
|
+
url.searchParams.has("_session")
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function applyDefaultSsrCacheHeader(headers, status, hasAuthSignal) {
|
|
307
|
+
if (headers.has("cache-control")) return;
|
|
308
|
+
if (status < 200 || status >= 400) return;
|
|
309
|
+
|
|
310
|
+
const contentType = (headers.get("content-type") || "").toLowerCase();
|
|
311
|
+
if (!contentType.includes("text/html")) return;
|
|
265
312
|
|
|
313
|
+
headers.set(
|
|
314
|
+
"cache-control",
|
|
315
|
+
hasAuthSignal ? AUTHENTICATED_SSR_CACHE_CONTROL : DEFAULT_SSR_CACHE_CONTROL,
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
async function rewriteMountedResponse(response, basePath, hasAuthSignal) {
|
|
320
|
+
const sentryClientConfigScript = getSentryClientConfigScript();
|
|
266
321
|
const headers = new Headers(response.headers);
|
|
322
|
+
applyDefaultSsrCacheHeader(headers, response.status, hasAuthSignal);
|
|
323
|
+
|
|
267
324
|
const location = headers.get("location");
|
|
268
325
|
if (location?.startsWith("/") && !location.startsWith("//")) {
|
|
269
326
|
headers.set("location", prefixMountedPath(location, basePath));
|
|
270
327
|
}
|
|
271
328
|
|
|
329
|
+
if (!basePath && !sentryClientConfigScript) {
|
|
330
|
+
return new Response(response.body, {
|
|
331
|
+
status: response.status,
|
|
332
|
+
statusText: response.statusText,
|
|
333
|
+
headers,
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
272
337
|
const contentType = headers.get("content-type") || "";
|
|
273
338
|
if (!contentType.toLowerCase().includes("text/html") || !response.body) {
|
|
274
339
|
return new Response(response.body, {
|
|
@@ -338,7 +403,7 @@ async function getHandler() {
|
|
|
338
403
|
headers: {
|
|
339
404
|
"Access-Control-Allow-Origin": "*",
|
|
340
405
|
"Access-Control-Allow-Methods": "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS",
|
|
341
|
-
"Access-Control-Allow-Headers": "Content-Type,Authorization,X-Requested-With,X-Request-Source",
|
|
406
|
+
"Access-Control-Allow-Headers": "Content-Type,Authorization,X-Requested-With,X-Request-Source,X-Agent-Native-CSRF,X-Agent-Native-Embed-Target",
|
|
342
407
|
},
|
|
343
408
|
});
|
|
344
409
|
}
|
|
@@ -370,6 +435,7 @@ ${actionRegistrations.join("\n")}
|
|
|
370
435
|
return new Response(null, { status: 404 });
|
|
371
436
|
}
|
|
372
437
|
const request = requestWithPathname(event.req, p);
|
|
438
|
+
const hasAuthSignal = requestHasAuthSignal(event.req);
|
|
373
439
|
if (event.req.method === "HEAD") {
|
|
374
440
|
const getRequest = requestWithMethod(request, "GET");
|
|
375
441
|
const response = await rrHandler(getRequest);
|
|
@@ -380,9 +446,10 @@ ${actionRegistrations.join("\n")}
|
|
|
380
446
|
headers: response.headers,
|
|
381
447
|
}),
|
|
382
448
|
basePath,
|
|
449
|
+
hasAuthSignal,
|
|
383
450
|
);
|
|
384
451
|
}
|
|
385
|
-
return rewriteMountedResponse(await rrHandler(request), basePath);
|
|
452
|
+
return rewriteMountedResponse(await rrHandler(request), basePath, hasAuthSignal);
|
|
386
453
|
}));
|
|
387
454
|
|
|
388
455
|
_handler = app.fetch.bind(app);
|
|
@@ -1102,6 +1169,7 @@ export default bundle;
|
|
|
1102
1169
|
virtual: {
|
|
1103
1170
|
"virtual:agents-bundle": agentsBundleModuleSource,
|
|
1104
1171
|
},
|
|
1172
|
+
routeRules: mcpEmbedStaticAssetRouteRules(appBasePath),
|
|
1105
1173
|
// For edge presets (cloudflare, deno), bundle all deps — node_modules
|
|
1106
1174
|
// aren't available at runtime. Netlify/Vercel/Node have node_modules.
|
|
1107
1175
|
...(preset.startsWith("cloudflare") || preset.startsWith("deno")
|