@agent-native/core 0.22.9 → 0.22.11

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 (42) hide show
  1. package/dist/client/AgentPanel.d.ts.map +1 -1
  2. package/dist/client/AgentPanel.js +8 -12
  3. package/dist/client/AgentPanel.js.map +1 -1
  4. package/dist/client/AssistantChat.d.ts +7 -0
  5. package/dist/client/AssistantChat.d.ts.map +1 -1
  6. package/dist/client/AssistantChat.js +106 -23
  7. package/dist/client/AssistantChat.js.map +1 -1
  8. package/dist/client/FeedbackButton.d.ts +5 -1
  9. package/dist/client/FeedbackButton.d.ts.map +1 -1
  10. package/dist/client/FeedbackButton.js +20 -3
  11. package/dist/client/FeedbackButton.js.map +1 -1
  12. package/dist/client/agent-chat-adapter.d.ts +10 -0
  13. package/dist/client/agent-chat-adapter.d.ts.map +1 -1
  14. package/dist/client/agent-chat-adapter.js +6 -19
  15. package/dist/client/agent-chat-adapter.js.map +1 -1
  16. package/dist/client/analytics.d.ts +1 -1
  17. package/dist/client/analytics.d.ts.map +1 -1
  18. package/dist/client/analytics.js +2 -40
  19. package/dist/client/analytics.js.map +1 -1
  20. package/dist/client/clipboard.d.ts +2 -0
  21. package/dist/client/clipboard.d.ts.map +1 -0
  22. package/dist/client/clipboard.js +51 -0
  23. package/dist/client/clipboard.js.map +1 -0
  24. package/dist/client/feedback-context.d.ts +11 -0
  25. package/dist/client/feedback-context.d.ts.map +1 -0
  26. package/dist/client/feedback-context.js +73 -0
  27. package/dist/client/feedback-context.js.map +1 -0
  28. package/dist/client/url-scrub.d.ts +2 -0
  29. package/dist/client/url-scrub.d.ts.map +1 -0
  30. package/dist/client/url-scrub.js +41 -0
  31. package/dist/client/url-scrub.js.map +1 -0
  32. package/dist/mcp/build-server.d.ts.map +1 -1
  33. package/dist/mcp/build-server.js +161 -17
  34. package/dist/mcp/build-server.js.map +1 -1
  35. package/dist/server/agent-chat-plugin.d.ts +5 -0
  36. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  37. package/dist/server/agent-chat-plugin.js +74 -59
  38. package/dist/server/agent-chat-plugin.js.map +1 -1
  39. package/docs/content/actions.md +2 -2
  40. package/docs/content/external-agents.md +3 -1
  41. package/docs/content/mcp-protocol.md +5 -3
  42. package/package.json +1 -1
@@ -2256,6 +2256,46 @@ function isLocalhost(event) {
2256
2256
  return false;
2257
2257
  }
2258
2258
  }
2259
+ function normalizeAgentChatRequestSurface(value) {
2260
+ const normalized = (value ?? "").trim().toLowerCase();
2261
+ if (normalized === "app" ||
2262
+ normalized === "dev-frame" ||
2263
+ normalized === "desktop") {
2264
+ return normalized;
2265
+ }
2266
+ return null;
2267
+ }
2268
+ function isBrowserUserAgent(userAgent) {
2269
+ return /Mozilla\/|Chrome\/|Safari\/|Firefox\/|Edg\//i.test(userAgent ?? "");
2270
+ }
2271
+ export function shouldBlockInProductCodeEditingSurface(input) {
2272
+ const surface = normalizeAgentChatRequestSurface(input.surface);
2273
+ if (surface === "dev-frame")
2274
+ return false;
2275
+ if (surface === "desktop")
2276
+ return false;
2277
+ if (surface === "app")
2278
+ return true;
2279
+ // Legacy clients used to send `frame` for any iframe, which includes the
2280
+ // app-rendered sidebar inside preview frames. Treat unknown explicit surface
2281
+ // values as app-owned so they cannot accidentally receive dev code tools.
2282
+ if (input.surface && input.surface.trim())
2283
+ return true;
2284
+ const userAgent = input.userAgent ?? "";
2285
+ if (/AgentNativeDesktop/i.test(userAgent))
2286
+ return false;
2287
+ // Missing header from an older browser client. Be conservative for browser
2288
+ // UAs on any host, because preview URLs can be non-local while still running
2289
+ // a dev-mode app whose in-product chat would be reloaded by source edits.
2290
+ if (isBrowserUserAgent(userAgent))
2291
+ return true;
2292
+ const host = (input.host ?? "").toLowerCase();
2293
+ const hostname = host.split(":")[0] ?? "";
2294
+ return (hostname === "localhost" ||
2295
+ hostname === "127.0.0.1" ||
2296
+ hostname === "::1" ||
2297
+ hostname === "[::1]");
2298
+ }
2259
2299
  export function createAgentChatPlugin(options) {
2260
2300
  return (nitroApp) => {
2261
2301
  markDefaultPluginProvided(nitroApp, "agent-chat");
@@ -3536,68 +3576,43 @@ export function createAgentChatPlugin(options) {
3536
3576
  : undefined;
3537
3577
  return buildRuntimeContextPrompt({ timezone });
3538
3578
  };
3539
- // Chat-in-browser-on-localdev is the one surface where the agent must
3540
- // not edit code: source-file edits trigger Vite HMR / page reloads and
3541
- // kill the chat session mid-run. The client sends an
3542
- // `x-agent-native-surface` header (desktop | frame | browser); we fall
3543
- // back to UA + Host inspection when the header is missing (older clients,
3544
- // server-to-server callers, etc.). Returning true forces the prod
3545
- // handler (no shell / no fs) AND injects a redirect-prompt block telling
3546
- // the agent to point users at Desktop / Claude Code / Codex / Builder.io.
3547
- const isChatInBrowserOnLocalDev = (event) => {
3548
- const surface = (getHeader(event, "x-agent-native-surface") || "").toLowerCase();
3549
- const ua = getHeader(event, "user-agent") || "";
3550
- const isDesktop = surface === "desktop" || /AgentNativeDesktop/i.test(ua);
3551
- if (isDesktop)
3552
- return false;
3553
- if (surface === "frame")
3554
- return false;
3555
- const host = (getHeader(event, "host") || "").toLowerCase();
3556
- const hostname = host.split(":")[0] ?? "";
3557
- const isLocal = hostname === "localhost" ||
3558
- hostname === "127.0.0.1" ||
3559
- hostname === "::1" ||
3560
- hostname === "[::1]";
3561
- if (!isLocal)
3562
- return false;
3563
- // No header from an older client + non-desktop UA: be conservative and
3564
- // only trip on plain browser UAs. Treat unknown clients as safe (frame
3565
- // / desktop / scripting) so we don't break their tool access.
3566
- if (!surface) {
3567
- return /Mozilla\/|Chrome\/|Safari\/|Firefox\/|Edg\//i.test(ua);
3568
- }
3569
- return surface === "browser";
3570
- };
3571
- const CHAT_IN_BROWSER_LOCAL_DEV_PROMPT = `
3572
-
3573
- <chat-in-browser-on-localdev>
3574
- This chat is running in a plain browser tab on localhost. Source-code edits would trigger Vite HMR or a full page reload, which kills the chat session mid-run, so source-code work cannot happen on this surface.
3579
+ // The app-rendered sidebar must never edit the app's source code
3580
+ // directly. Source-file edits can trigger HMR or full reloads of the
3581
+ // same React tree that is hosting the chat, interrupting the run and
3582
+ // losing in-progress UI state. Code edits are allowed only from the
3583
+ // outer dev frame (x-agent-native-surface: dev-frame) or from separate
3584
+ // agent surfaces such as Builder/A2A/MCP handoffs.
3585
+ const shouldBlockInProductCodeEditing = (event) => shouldBlockInProductCodeEditingSurface({
3586
+ surface: getHeader(event, "x-agent-native-surface"),
3587
+ userAgent: getHeader(event, "user-agent"),
3588
+ host: getHeader(event, "host"),
3589
+ });
3590
+ const APP_RENDERED_CHAT_NO_DIRECT_CODE_PROMPT = `
3575
3591
 
3576
- When the user asks for ANY of the following — add a feature, edit a component, fix a bug in the app itself, change styles, add a route, scaffold a new app, run shell commands that modify code, or anything else that requires touching source files:
3592
+ <app-rendered-chat-no-direct-code-edits>
3593
+ This chat is rendered by the app itself. It must never edit this app's source files directly, because source edits can hot-reload or replace the same UI that is hosting the chat.
3577
3594
 
3578
- 1. Do NOT call \`connect-builder\`, \`scaffold-workspace-app\`, \`start-workspace-app-creation\`, or any other tool that creates or edits source.
3579
- 2. Do NOT write code, list files, propose patches, or describe what you would change.
3580
- 3. Reply with one short message saying chat-in-browser on localhost can't edit code (page reloads kill the session). If — and only if — the request is specifically to **add or scaffold a new workspace app**, lead with the CLI option since it runs in the same terminal the user is already using:
3581
- - **Agent Native CLI** — \`npx @agent-native/core add-app\` in this workspace directory (best for template apps like Mail/Calendar/Slides; the workspace gateway picks them up automatically)
3595
+ When the user asks to add a feature, edit a component, fix a bug in the app itself, change styles, add a route, scaffold a new app, run shell commands that modify code, or do anything else that requires touching source files:
3582
3596
 
3583
- Then offer these alternatives for general source-editing work, in this order:
3584
- - **Agent Native Desktop** https://www.agent-native.com/download (recommended; same chat, no reload risk)
3585
- - **Claude Code** \`claude\` in the project directory
3586
- - **Codex** — \`codex\` in the project directory
3587
- - **Builder.io** — open the project in Builder for cloud-based code changes
3597
+ 1. Do NOT use dev shell/filesystem tools, write code inline, list source files, propose patches, or describe file-level implementation steps from this chat.
3598
+ 2. For host-app source changes in Act mode, call \`connect-builder\` when that tool is available so a separate Builder/cloud agent can do the work. If Builder is unavailable, give a short handoff to the outer dev frame, Agent Native Desktop, Claude Code, or Codex in the project directory.
3599
+ 3. If the request is specifically to add or scaffold a new workspace app and no Builder handoff is available, mention \`npx @agent-native/core add-app\` in this workspace directory as the CLI path.
3588
3600
 
3589
- Non-code requests are still fine on this surface read data, navigate the UI, summarize, search, create/update extensions (sandboxed Alpine.js mini-apps stored in SQL), and call template actions. The restriction is specifically about editing the app's own source files.
3590
- </chat-in-browser-on-localdev>`;
3601
+ Non-code requests are still fine on this surface: read data, navigate the UI, summarize, search, create/update extensions (sandboxed Alpine.js mini-apps stored in SQL), and call template actions. The restriction is specifically about direct edits to the host app's own source files.
3602
+ </app-rendered-chat-no-direct-code-edits>`;
3591
3603
  const prodHandler = createProductionAgentHandler({
3592
3604
  actions: leanPrompt ? leanActions : prodActions,
3593
3605
  systemPrompt: async (event) => {
3594
3606
  const { owner, extra } = await prepareRun(event);
3595
3607
  const runtimeContext = runtimeContextForEvent(event);
3596
- const browserLocalDev = isChatInBrowserOnLocalDev(event)
3597
- ? CHAT_IN_BROWSER_LOCAL_DEV_PROMPT
3608
+ const codeEditingSurfaceRestriction = shouldBlockInProductCodeEditing(event)
3609
+ ? APP_RENDERED_CHAT_NO_DIRECT_CODE_PROMPT
3598
3610
  : "";
3599
3611
  if (leanPrompt) {
3600
- return setSystemPromptOnContext(leanBasePrompt + runtimeContext + browserLocalDev + extra);
3612
+ return setSystemPromptOnContext(leanBasePrompt +
3613
+ runtimeContext +
3614
+ codeEditingSurfaceRestriction +
3615
+ extra);
3601
3616
  }
3602
3617
  const resources = await loadResourcesForPrompt(owner, lazyContext, options?.appId);
3603
3618
  // In lazy context mode, skip embedding the full schema — the agent
@@ -3609,7 +3624,7 @@ Non-code requests are still fine on this surface — read data, navigate the UI,
3609
3624
  runtimeContext +
3610
3625
  resources +
3611
3626
  schemaBlock +
3612
- browserLocalDev +
3627
+ codeEditingSurfaceRestriction +
3613
3628
  extra);
3614
3629
  },
3615
3630
  model: options?.model,
@@ -4927,15 +4942,15 @@ Non-code requests are still fine on this surface — read data, navigate the UI,
4927
4942
  orgId: resolvedOrgId,
4928
4943
  timezone,
4929
4944
  }, () => {
4930
- // Chat-in-browser on localhost can't host code edits — Vite HMR
4931
- // and full reloads would kill the chat mid-run. Force the prod
4932
- // handler (no shell / no fs); the prompt block injected by
4933
- // `prodHandler.systemPrompt` then steers the agent to suggest
4934
- // Desktop / Claude Code / Codex / Builder.io instead.
4935
- const browserLocalDev = isChatInBrowserOnLocalDev(event);
4945
+ // App-rendered chat can't host direct code edits — HMR/full
4946
+ // reloads would kill the same chat surface mid-run. Force the
4947
+ // prod handler (no shell / no fs); the prompt block injected by
4948
+ // `prodHandler.systemPrompt` then steers source changes to a
4949
+ // separate agent surface such as Builder or the dev frame.
4950
+ const blockInProductCodeEditing = shouldBlockInProductCodeEditing(event);
4936
4951
  const handler = ownerContext.anonymous && anonymousHandler
4937
4952
  ? anonymousHandler
4938
- : !browserLocalDev && currentDevMode && devHandler
4953
+ : !blockInProductCodeEditing && currentDevMode && devHandler
4939
4954
  ? devHandler
4940
4955
  : prodHandler;
4941
4956
  return handler(event);