@agent-native/core 0.26.3 → 0.26.5

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 (63) hide show
  1. package/dist/cli/skills.d.ts.map +1 -1
  2. package/dist/cli/skills.js +4 -1
  3. package/dist/cli/skills.js.map +1 -1
  4. package/dist/client/mcp-app-host.d.ts +1 -0
  5. package/dist/client/mcp-app-host.d.ts.map +1 -1
  6. package/dist/client/mcp-app-host.js +44 -6
  7. package/dist/client/mcp-app-host.js.map +1 -1
  8. package/dist/deploy/build.d.ts.map +1 -1
  9. package/dist/deploy/build.js +44 -7
  10. package/dist/deploy/build.js.map +1 -1
  11. package/dist/mcp/build-server.d.ts.map +1 -1
  12. package/dist/mcp/build-server.js +95 -8
  13. package/dist/mcp/build-server.js.map +1 -1
  14. package/dist/mcp/embed-app.d.ts.map +1 -1
  15. package/dist/mcp/embed-app.js +247 -30
  16. package/dist/mcp/embed-app.js.map +1 -1
  17. package/dist/mcp/server.d.ts +5 -7
  18. package/dist/mcp/server.d.ts.map +1 -1
  19. package/dist/mcp/server.js +16 -12
  20. package/dist/mcp/server.js.map +1 -1
  21. package/dist/server/action-routes.d.ts.map +1 -1
  22. package/dist/server/action-routes.js +23 -7
  23. package/dist/server/action-routes.js.map +1 -1
  24. package/dist/server/auth.d.ts.map +1 -1
  25. package/dist/server/auth.js +69 -38
  26. package/dist/server/auth.js.map +1 -1
  27. package/dist/server/core-routes-plugin.d.ts +12 -1
  28. package/dist/server/core-routes-plugin.d.ts.map +1 -1
  29. package/dist/server/core-routes-plugin.js +48 -44
  30. package/dist/server/core-routes-plugin.js.map +1 -1
  31. package/dist/server/create-server.d.ts.map +1 -1
  32. package/dist/server/create-server.js +3 -1
  33. package/dist/server/create-server.js.map +1 -1
  34. package/dist/server/credential-provider.d.ts +1 -0
  35. package/dist/server/credential-provider.d.ts.map +1 -1
  36. package/dist/server/credential-provider.js +15 -4
  37. package/dist/server/credential-provider.js.map +1 -1
  38. package/dist/server/embed-route.d.ts.map +1 -1
  39. package/dist/server/embed-route.js +28 -2
  40. package/dist/server/embed-route.js.map +1 -1
  41. package/dist/server/embed-session.d.ts.map +1 -1
  42. package/dist/server/embed-session.js +26 -7
  43. package/dist/server/embed-session.js.map +1 -1
  44. package/dist/server/onboarding-html.d.ts.map +1 -1
  45. package/dist/server/onboarding-html.js +52 -5
  46. package/dist/server/onboarding-html.js.map +1 -1
  47. package/dist/server/ssr-handler.d.ts +1 -1
  48. package/dist/server/ssr-handler.d.ts.map +1 -1
  49. package/dist/server/ssr-handler.js +23 -10
  50. package/dist/server/ssr-handler.js.map +1 -1
  51. package/dist/shared/cache-control.d.ts +2 -0
  52. package/dist/shared/cache-control.d.ts.map +1 -0
  53. package/dist/shared/cache-control.js +2 -0
  54. package/dist/shared/cache-control.js.map +1 -0
  55. package/dist/shared/mcp-embed-headers.d.ts +2 -1
  56. package/dist/shared/mcp-embed-headers.d.ts.map +1 -1
  57. package/dist/shared/mcp-embed-headers.js +3 -1
  58. package/dist/shared/mcp-embed-headers.js.map +1 -1
  59. package/dist/templates/workspace-root/package.json +5 -0
  60. package/docs/content/mcp-protocol.md +0 -1
  61. package/docs/content/template-assets.md +5 -0
  62. package/package.json +2 -2
  63. package/src/templates/workspace-root/package.json +5 -0
@@ -20,7 +20,7 @@
20
20
  import { isMcpActionResult } from "../mcp-client/app-result.js";
21
21
  import { MCP_APP_EXTENSION_ID, MCP_APP_MIME_TYPE, MCP_APP_RESOURCE_URI_META_KEY, } from "../action.js";
22
22
  import { MCP_APP_REQUEST_ORIGIN_CSP_SOURCE } from "./embed-app.js";
23
- import { runWithRequestContext } from "../server/request-context.js";
23
+ import { getRequestContext, runWithRequestContext, } from "../server/request-context.js";
24
24
  import { buildDeepLink, toAbsoluteOpenUrl, toDesktopOpenUrl, } from "../server/deep-link.js";
25
25
  import { isAgentNativeOpenDeepLink, withCollapsedAgentSidebarParam, } from "../shared/agent-sidebar-url.js";
26
26
  import { MCP_APP_CHAT_BRIDGE_QUERY_PARAM } from "../shared/embed-auth.js";
@@ -329,6 +329,57 @@ function mcpAppEmbedOpenLinkMeta(result, resource, meta) {
329
329
  : {}),
330
330
  };
331
331
  }
332
+ async function withServerMintedMcpAppEmbedStart(result, meta) {
333
+ if (!result || typeof result !== "object" || Array.isArray(result)) {
334
+ return result;
335
+ }
336
+ const out = result;
337
+ if (out.embed !== true)
338
+ return result;
339
+ if (typeof out.embedStartUrl === "string" && out.embedStartUrl.trim()) {
340
+ return result;
341
+ }
342
+ if (typeof out.url === "string" &&
343
+ out.url.trim() &&
344
+ isEmbedStartUrl(out.url)) {
345
+ return result;
346
+ }
347
+ const candidate = [out.url, out.path, out.deepLinkUrl].find((value) => typeof value === "string" && value.trim().length > 0);
348
+ if (!candidate)
349
+ return result;
350
+ const trimmed = candidate.trim();
351
+ const isPath = trimmed.startsWith("/") && !trimmed.startsWith("//");
352
+ const isAbsoluteHttp = /^https?:\/\//i.test(trimmed);
353
+ if (!isPath && !isAbsoluteHttp)
354
+ return result;
355
+ if (isAbsoluteHttp && !meta?.origin)
356
+ return result;
357
+ const ctx = getRequestContext();
358
+ const ownerEmail = ctx?.userEmail?.trim();
359
+ if (!ownerEmail)
360
+ return result;
361
+ const { normalizeEmbedTargetPath, createEmbedSessionTicket } = await import("../server/embed-session.js");
362
+ const { buildEmbedStartPath } = await import("../server/embed-route.js");
363
+ const targetPath = normalizeEmbedTargetPath(withMcpChatBridgeParam(trimmed), meta?.origin);
364
+ if (!targetPath)
365
+ return result;
366
+ const ticket = await createEmbedSessionTicket({
367
+ ownerEmail,
368
+ orgId: ctx?.orgId,
369
+ targetPath,
370
+ scope: typeof out.chrome === "string" ? out.chrome : null,
371
+ });
372
+ const startPath = buildEmbedStartPath(ticket.ticket);
373
+ const embedStartUrl = meta?.origin
374
+ ? new URL(startPath, meta.origin).toString()
375
+ : startPath;
376
+ return {
377
+ ...out,
378
+ embedStartUrl,
379
+ embedTargetPath: targetPath,
380
+ embedExpiresAt: ticket.expiresAt,
381
+ };
382
+ }
332
383
  /**
333
384
  * Build the deep-link content block + structured `_meta` for a tool result.
334
385
  * Best-effort: any throw / nullish link is swallowed so a bad `link` builder
@@ -439,7 +490,7 @@ function safeUiSegment(value, fallback) {
439
490
  }
440
491
  // ChatGPT and Claude cache MCP App resource HTML by `ui://` URI. Bump this
441
492
  // when the shared shell changes in a way that must invalidate host caches.
442
- const MCP_APP_RESOURCE_SHELL_VERSION = "shell-v26";
493
+ const MCP_APP_RESOURCE_SHELL_VERSION = "shell-v30";
443
494
  function legacyDefaultMcpAppUri(config, actionName) {
444
495
  const app = safeUiSegment(config.appId ?? config.name, "agent-native");
445
496
  const action = safeUiSegment(actionName, "tool");
@@ -467,6 +518,41 @@ function versionMcpAppResourceUri(rawUri) {
467
518
  ...(versionedUri !== uri ? { legacyUris: [uri] } : {}),
468
519
  };
469
520
  }
521
+ function unversionMcpAppResourceUri(uri) {
522
+ if (!uri.startsWith("ui://"))
523
+ return null;
524
+ try {
525
+ const parsed = new URL(uri);
526
+ parsed.pathname = parsed.pathname
527
+ .replace(/\/+$/g, "")
528
+ .replace(/\/shell-v\d+$/g, "");
529
+ return parsed.toString();
530
+ }
531
+ catch {
532
+ return null;
533
+ }
534
+ }
535
+ function normalizeMcpAppResourceUriForMatch(uri) {
536
+ if (typeof uri !== "string")
537
+ return null;
538
+ const trimmed = uri.trim();
539
+ if (!trimmed.startsWith("ui://"))
540
+ return null;
541
+ return (unversionMcpAppResourceUri(trimmed) ??
542
+ trimmed.replace(/\/+$/g, "").replace(/\/shell-v\d+(?=([?#]|$))/g, ""));
543
+ }
544
+ function matchesMcpAppResourceUri(resourceUri, requestedUri) {
545
+ if (typeof requestedUri !== "string")
546
+ return false;
547
+ const requested = requestedUri.trim();
548
+ if (resourceUri.uri === requested)
549
+ return true;
550
+ if (resourceUri.legacyUris?.includes(requested))
551
+ return true;
552
+ const requestedBase = normalizeMcpAppResourceUriForMatch(requested);
553
+ const currentBase = normalizeMcpAppResourceUriForMatch(resourceUri.uri);
554
+ return Boolean(requestedBase && currentBase && requestedBase === currentBase);
555
+ }
470
556
  function getMcpAppResourceUri(config, actionName, entry) {
471
557
  const resource = entry.mcpApp?.resource;
472
558
  if (!resource)
@@ -932,11 +1018,14 @@ export async function createMCPServerForRequest(config, identity, requestMeta) {
932
1018
  ? result.text
933
1019
  : result;
934
1020
  const mcpAppResource = await resolveMcpAppResourceSafely(config, name, entry, requestMeta);
935
- const { block, _meta } = buildLinkArtifacts(entry, args ?? {}, rawResult, requestMeta);
1021
+ const rawResultForClient = mcpAppResource
1022
+ ? await withServerMintedMcpAppEmbedStart(rawResult, requestMeta)
1023
+ : rawResult;
1024
+ const { block, _meta } = buildLinkArtifacts(entry, args ?? {}, rawResultForClient, requestMeta);
936
1025
  const responseMeta = {
937
1026
  ...(_meta ?? {}),
938
1027
  ...(mcpAppResource
939
- ? mcpAppEmbedOpenLinkMeta(rawResult, mcpAppResource, requestMeta)
1028
+ ? mcpAppEmbedOpenLinkMeta(rawResultForClient, mcpAppResource, requestMeta)
940
1029
  : {}),
941
1030
  ...(mcpAppResource ? openAiToolResultMeta(mcpAppResource) : {}),
942
1031
  };
@@ -946,7 +1035,7 @@ export async function createMCPServerForRequest(config, identity, requestMeta) {
946
1035
  toolVisibility.length > 0 &&
947
1036
  toolVisibility.every((v) => v === "app");
948
1037
  const structuredContent = mcpAppResource
949
- ? mcpAppStructuredContent(rawResult, responseMeta)
1038
+ ? mcpAppStructuredContent(rawResultForClient, responseMeta)
950
1039
  : isAppOnlyVisibility &&
951
1040
  rawResult &&
952
1041
  typeof rawResult === "object" &&
@@ -1018,9 +1107,7 @@ export async function createMCPServerForRequest(config, identity, requestMeta) {
1018
1107
  let found = null;
1019
1108
  for (const [name, entry] of Object.entries(advertisedActions)) {
1020
1109
  const resourceUri = getMcpAppResourceUri(config, name, entry);
1021
- if (!resourceUri ||
1022
- (resourceUri.uri !== uri &&
1023
- !resourceUri.legacyUris?.includes(uri))) {
1110
+ if (!resourceUri || !matchesMcpAppResourceUri(resourceUri, uri)) {
1024
1111
  continue;
1025
1112
  }
1026
1113
  const resource = await resolveMcpAppResourceSafely(config, name, entry, requestMeta);