@agent-native/core 0.84.13 → 0.84.16

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 (96) hide show
  1. package/corpus/README.md +1 -1
  2. package/corpus/core/CHANGELOG.md +25 -0
  3. package/corpus/core/package.json +2 -2
  4. package/corpus/core/src/agent/durable-background.ts +18 -5
  5. package/corpus/core/src/agent/engine/builder-engine.ts +7 -3
  6. package/corpus/core/src/agent/production-agent.ts +48 -7
  7. package/corpus/core/src/agent/run-manager.ts +39 -2
  8. package/corpus/core/src/agent/run-store.ts +55 -11
  9. package/corpus/core/src/client/AssistantChat.tsx +30 -4
  10. package/corpus/core/src/client/MultiTabAssistantChat.tsx +11 -3
  11. package/corpus/core/src/client/agent-chat-adapter.ts +21 -3
  12. package/corpus/core/src/client/agent-chat.ts +18 -3
  13. package/corpus/core/src/client/blocks/library/diagram.tsx +3 -3
  14. package/corpus/core/src/client/chat/message-components.tsx +17 -0
  15. package/corpus/core/src/client/use-agent-engine-configured.ts +7 -4
  16. package/corpus/core/src/db/client.ts +10 -1
  17. package/corpus/core/src/observability/traces.ts +17 -3
  18. package/corpus/core/src/server/agent-chat-plugin.ts +80 -44
  19. package/corpus/core/src/styles/blocks.css +44 -1
  20. package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/DashboardFilterBar.tsx +18 -24
  21. package/corpus/templates/analytics/changelog/2026-07-01-dashboard-charts-no-longer-show-future-dates-when-clients-se.md +6 -0
  22. package/corpus/templates/analytics/changelog/2026-07-01-dashboard-filters-take-less-space-and-keep-view-actions-tucked.md +6 -0
  23. package/corpus/templates/analytics/server/lib/first-party-analytics.ts +34 -9
  24. package/corpus/templates/analytics/server/lib/first-party-metric-catalog.ts +6 -2
  25. package/corpus/templates/analytics/server/lib/session-replay.ts +109 -50
  26. package/corpus/templates/analytics/server/plugins/db.ts +21 -0
  27. package/corpus/templates/clips/changelog/2026-07-01-chrome-extension-recordings-stream-uploads-while-recording.md +6 -0
  28. package/corpus/templates/clips/chrome-extension/public/manifest.json +1 -1
  29. package/corpus/templates/clips/chrome-extension/src/background.ts +8 -0
  30. package/corpus/templates/clips/chrome-extension/src/offscreen.ts +61 -16
  31. package/corpus/templates/design/app/pages/DesignEditor.tsx +176 -13
  32. package/corpus/templates/design/changelog/2026-07-01-exporting-a-design-as-png-or-svg-now-downloads-just-the-sele.md +6 -0
  33. package/corpus/templates/plan/app/components/plan/wireframe/html-artboard.css +44 -1
  34. package/corpus/templates/plan/changelog/2026-07-01-visual-plan-and-recap-diagram-labels-now-wrap-inside-their-b.md +6 -0
  35. package/dist/agent/durable-background.d.ts +1 -0
  36. package/dist/agent/durable-background.d.ts.map +1 -1
  37. package/dist/agent/durable-background.js +17 -3
  38. package/dist/agent/durable-background.js.map +1 -1
  39. package/dist/agent/engine/builder-engine.d.ts.map +1 -1
  40. package/dist/agent/engine/builder-engine.js +7 -1
  41. package/dist/agent/engine/builder-engine.js.map +1 -1
  42. package/dist/agent/production-agent.d.ts.map +1 -1
  43. package/dist/agent/production-agent.js +32 -7
  44. package/dist/agent/production-agent.js.map +1 -1
  45. package/dist/agent/run-manager.d.ts +2 -0
  46. package/dist/agent/run-manager.d.ts.map +1 -1
  47. package/dist/agent/run-manager.js +28 -3
  48. package/dist/agent/run-manager.js.map +1 -1
  49. package/dist/agent/run-store.d.ts +9 -0
  50. package/dist/agent/run-store.d.ts.map +1 -1
  51. package/dist/agent/run-store.js +47 -11
  52. package/dist/agent/run-store.js.map +1 -1
  53. package/dist/client/AssistantChat.d.ts +8 -2
  54. package/dist/client/AssistantChat.d.ts.map +1 -1
  55. package/dist/client/AssistantChat.js +18 -2
  56. package/dist/client/AssistantChat.js.map +1 -1
  57. package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
  58. package/dist/client/MultiTabAssistantChat.js +7 -3
  59. package/dist/client/MultiTabAssistantChat.js.map +1 -1
  60. package/dist/client/agent-chat-adapter.d.ts.map +1 -1
  61. package/dist/client/agent-chat-adapter.js +19 -3
  62. package/dist/client/agent-chat-adapter.js.map +1 -1
  63. package/dist/client/agent-chat.d.ts +7 -0
  64. package/dist/client/agent-chat.d.ts.map +1 -1
  65. package/dist/client/agent-chat.js +5 -1
  66. package/dist/client/agent-chat.js.map +1 -1
  67. package/dist/client/blocks/library/diagram.js +3 -3
  68. package/dist/client/blocks/library/diagram.js.map +1 -1
  69. package/dist/client/chat/message-components.d.ts +3 -1
  70. package/dist/client/chat/message-components.d.ts.map +1 -1
  71. package/dist/client/chat/message-components.js +16 -2
  72. package/dist/client/chat/message-components.js.map +1 -1
  73. package/dist/client/use-agent-engine-configured.d.ts.map +1 -1
  74. package/dist/client/use-agent-engine-configured.js +7 -1
  75. package/dist/client/use-agent-engine-configured.js.map +1 -1
  76. package/dist/collab/routes.d.ts +2 -2
  77. package/dist/db/client.d.ts +6 -0
  78. package/dist/db/client.d.ts.map +1 -1
  79. package/dist/db/client.js +8 -1
  80. package/dist/db/client.js.map +1 -1
  81. package/dist/notifications/routes.d.ts +2 -2
  82. package/dist/observability/routes.d.ts +3 -3
  83. package/dist/observability/traces.d.ts +5 -0
  84. package/dist/observability/traces.d.ts.map +1 -1
  85. package/dist/observability/traces.js +9 -3
  86. package/dist/observability/traces.js.map +1 -1
  87. package/dist/progress/routes.d.ts +1 -1
  88. package/dist/resources/handlers.d.ts +3 -3
  89. package/dist/server/agent-chat-plugin.d.ts +2 -1
  90. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  91. package/dist/server/agent-chat-plugin.js +64 -42
  92. package/dist/server/agent-chat-plugin.js.map +1 -1
  93. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  94. package/dist/server/transcribe-voice.d.ts +1 -1
  95. package/dist/styles/blocks.css +44 -1
  96. package/package.json +2 -2
@@ -91,6 +91,13 @@ export interface AgentChatContextSetOptions extends AgentChatContextItem {
91
91
  * Defaults to true so the user can see the staged context.
92
92
  */
93
93
  openSidebar?: boolean;
94
+ /**
95
+ * Whether to move keyboard focus into the composer when staging the item.
96
+ * Defaults to true. Pass `false` for context that mirrors ambient UI state
97
+ * (e.g. a canvas element selection) so staging never steals focus from an
98
+ * unrelated editor — such as an inline text editor in a design canvas.
99
+ */
100
+ focus?: boolean;
94
101
  }
95
102
  /** @deprecated Use `AgentChatContextSetOptions` instead. */
96
103
  export type AgentChatContextMessage = AgentChatContextSetOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"agent-chat.d.ts","sourceRoot":"","sources":["../../src/client/agent-chat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAmBrE,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,MAAM,CAAC;AAElD,MAAM,WAAW,gBAAgB;IAC/B,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qCAAqC;IACrC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B,yCAAyC;IACzC,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAC;IACnC,wEAAwE;IACxE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IAC1B,kFAAkF;IAClF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,6FAA6F;IAC7F,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,MAAM,CAAC,EAAE,eAAe,CAAC;IAC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ACpE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,6EAA6E;IAC7E,WAAW,CAAC,EAAE,oBAAoB,CAAC;IACnC,kEAAkE;IAClE,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,6FAA6F;AAC7F,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,YAAY,GAClB,gBAAgB,GAAG,IAAI,CAoCzB;AAgCD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAgG9D;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,0BAA0B,GAC/B,IAAI,CAkBN;AAED,yDAAyD;AACzD,eAAO,MAAM,qBAAqB,gCAA0B,CAAC;AAE7D,yDAAyD;AACzD,eAAO,MAAM,qBAAqB,gCAA0B,CAAC;AAE7D,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,sBAAsB,EAC3B,OAAO,GAAE,mCAAwC,GAChD,IAAI,CAYN;AAED,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,GAAG,6BAA6B,GAChD,IAAI,CAeN;AAED,wBAAgB,qBAAqB,CACnC,IAAI,GAAE,+BAAoC,GACzC,IAAI,CAQN;AAED,wBAAgB,8BAA8B,IAAI,IAAI,CAGrD"}
@@ -558,7 +558,11 @@ export function setAgentChatContextItem(opts) {
558
558
  if (!item || typeof window === "undefined")
559
559
  return;
560
560
  publishAgentChatContextItems(withReplacedAgentChatContextItem(agentChatContextState.items, item));
561
- postAgentChatContextMessage(AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE, item, {
561
+ // Forward an explicit `focus: false` so the receiving composer can stage the
562
+ // chip without stealing focus. Focus stays enabled by default (field omitted)
563
+ // for every existing caller.
564
+ const messageData = opts.focus === false ? { ...item, focus: false } : item;
565
+ postAgentChatContextMessage(AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE, messageData, {
562
566
  openSidebar: opts.openSidebar !== false,
563
567
  });
564
568
  }
@@ -1 +1 @@
1
- {"version":3,"file":"agent-chat.js","sourceRoot":"","sources":["../../src/client/agent-chat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,4BAA4B,EAC5B,iCAAiC,GAClC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,+BAA+B,EAC/B,qBAAqB,GACtB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AA+I1D,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;AACzD,MAAM,4BAA4B,GAAG,oBAAoB,CAAC;AAC1D,MAAM,wBAAwB,GAAG,wBAAwB,CAAC;AAC1D,MAAM,CAAC,MAAM,gCAAgC,GAC3C,gCAAgC,CAAC;AACnC,MAAM,CAAC,MAAM,mCAAmC,GAAG,4BAA4B,CAAC;AAChF,MAAM,CAAC,MAAM,sCAAsC,GACjD,+BAA+B,CAAC;AAClC,MAAM,CAAC,MAAM,qCAAqC,GAChD,8BAA8B,CAAC;AACjC,MAAM,CAAC,MAAM,wCAAwC,GACnD,qCAAqC,CAAC;AACxC,MAAM,CAAC,MAAM,iCAAiC,GAC5C,uCAAuC,CAAC;AAC1C,MAAM,yBAAyB,GAAG,qBAAqB,CAAC;AAExD,IAAI,qBAAqB,GAA0B;IACjD,KAAK,EAAE,EAAE;IACT,SAAS,EAAE,CAAC;CACb,CAAC;AACF,MAAM,yBAAyB,GAAG,IAAI,GAAG,EAAc,CAAC;AACxD,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CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;KACjB,EACD,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,KAAK,IAAI,EAAE,CAC9C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,SAAiD;IAEjD,MAAM,GAAG,GACP,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAC1E,IAAI,CAAC,GAAG,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO;IAClD,MAAM,WAAW,GACf,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,KAAK,IAAI,CAAC;IAEzE,4BAA4B,CAC1B,qBAAqB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,CAC/D,CAAC;IACF,2BAA2B,CACzB,sCAAsC,EACtC,EAAE,GAAG,EAAE,EACP,EAAE,WAAW,EAAE,CAChB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,IAAI,GAAoC,EAAE;IAE1C,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO;IAC1C,4BAA4B,CAAC,EAAE,CAAC,CAAC;IACjC,2BAA2B,CACzB,qCAAqC,EACrC,EAAE,EACF,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,KAAK,IAAI,EAAE,CAC3C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,8BAA8B;IAC5C,qBAAqB,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACpD,+BAA+B,EAAE,CAAC;AACpC,CAAC","sourcesContent":["/**\n * Agent Chat Bridge (browser)\n *\n * Sends structured messages to the agent chat from UI interactions.\n * Messages are sent via postMessage to the parent window (or self if top-level).\n * Builder frames are special: code requests go to Builder, but content prompts\n * stay inside the embedded app so its own AgentSidebar can receive them.\n */\n\nimport type { ReasoningEffort } from \"../shared/reasoning-effort.js\";\nimport { agentNativePath } from \"./api-path.js\";\nimport {\n isInBuilderFrame,\n isTrustedBuilderMessage,\n sendToBuilderChat,\n} from \"./builder-frame.js\";\nimport {\n isEmbedAuthActive,\n isEmbedMcpChatBridgeActive,\n markEmbedMcpChatBridgeActive,\n readEmbedMcpChatBridgeFlagFromUrl,\n} from \"./embed-auth.js\";\nimport {\n getFramePostMessageTargetOrigin,\n isTrustedFrameMessage,\n} from \"./frame.js\";\nimport { sendMcpAppHostMessage } from \"./mcp-app-host.js\";\n\nexport type AgentChatRequestMode = \"act\" | \"plan\";\n\nexport interface AgentChatMessage {\n /** The visible prompt message sent to the chat */\n message: string;\n /** Hidden context appended to the message (not shown in chat UI) */\n context?: string;\n /** true = auto-submit, false = prefill only, omit = use project setting */\n submit?: boolean;\n /** Optional project slug for structured context */\n projectSlug?: string;\n /** Optional preset name for downstream consumers */\n preset?: string;\n /** Optional reference image paths */\n referenceImagePaths?: string[];\n /** Optional uploaded reference images */\n uploadedReferenceImages?: string[];\n /** Optional image data URLs to include in the submitted chat message */\n images?: string[];\n /** Stable tab identifier — auto-generated if omitted */\n tabId?: string;\n /**\n * Message routing type:\n * - \"content\" (default): stays in the embedded app agent for content/data operations\n * - \"code\": routes to the code editing frame (Agent Native Desktop or Builder.io)\n *\n * When type is \"code\" and no frame is connected, a dialog is shown.\n * `requiresCode: true` is treated as `type: \"code\"` for backward compatibility.\n */\n type?: \"content\" | \"code\";\n /** @deprecated Use `type: \"code\"` instead. If true, treated as `type: \"code\"`. */\n requiresCode?: boolean;\n /** Model preference for this sub-agent (e.g. \"claude-haiku-4-5\"). Uses default if omitted */\n model?: string;\n /** Engine preference paired with model for cross-provider switches. */\n engine?: string;\n /** Reasoning effort preference paired with model. */\n effort?: ReasoningEffort;\n /**\n * Execution mode for this submitted turn. When omitted, sendToAgentChat\n * snapshots the current AgentPanel mode from localStorage when available.\n */\n mode?: AgentChatRequestMode;\n /** @deprecated Use `mode` instead. */\n requestMode?: AgentChatRequestMode;\n /** Scoped system prompt additions for this sub-agent */\n instructions?: string;\n /**\n * Message delivery target. Auto-submitted MCP App messages normally relay to\n * the host chat; use \"local\" when a control explicitly targets this app's\n * own AgentSidebar.\n */\n chatTarget?: \"auto\" | \"local\";\n /**\n * Whether to open the agent sidebar if it's currently hidden.\n * Defaults to true — submitting a chat should make the response visible.\n * Pass `false` for background/silent sends that shouldn't pop the UI open.\n */\n openSidebar?: boolean;\n /**\n * When true, opens a new chat tab before sending the message.\n * Use for creation requests (create tool, dashboard, etc.) that deserve\n * their own isolated thread rather than cluttering an existing conversation.\n */\n newTab?: boolean;\n /**\n * When true with newTab, creates the tab in the background without\n * focusing it or opening the sidebar. The message runs silently.\n */\n background?: boolean;\n}\n\nexport interface AgentChatContextItem {\n /** Stable key used to replace an existing context nugget. */\n key: string;\n /** Short label shown in the composer context chip. */\n title: string;\n /** Hidden context included with the next submitted prompt. */\n context: string;\n}\n\nexport interface AgentChatContextSetOptions extends AgentChatContextItem {\n /**\n * Whether to open the agent sidebar if it's currently hidden.\n * Defaults to true so the user can see the staged context.\n */\n openSidebar?: boolean;\n}\n\n/** @deprecated Use `AgentChatContextSetOptions` instead. */\nexport type AgentChatContextMessage = AgentChatContextSetOptions;\n\nexport interface AgentChatContextState {\n items: AgentChatContextItem[];\n updatedAt: number;\n}\n\nexport interface AgentComposerReference {\n label: string;\n icon?: string;\n source?: string;\n refType: string;\n refId?: string | null;\n refPath?: string | null;\n /** Stable composer slot this reference occupies. Slot references replace older values. */\n slotKey?: string;\n /** Short label shown before the selected value in the composer chip. */\n slotLabel?: string;\n /** Additional app-defined data used by the client for filtering and grouping. */\n metadata?: Record<string, unknown>;\n /** Slots to remove when this reference is inserted or removed. */\n clearsSlots?: string[];\n /** Additional references to insert before this one. */\n relatedReferences?: AgentComposerReference[];\n}\n\nexport interface AgentComposerReferenceInsertOptions {\n /**\n * Whether to open the agent sidebar before inserting the reference.\n * Defaults to false so contextual auto-tags can stay quiet.\n */\n openSidebar?: boolean;\n}\n\nexport interface AgentComposerReferenceInsertPayload extends AgentComposerReference {\n insertMessageId: string;\n}\n\nexport interface AgentChatContextMutationOptions {\n /**\n * Whether to open the agent sidebar if it's currently hidden.\n * Defaults to true for set/add and false for remove/clear.\n */\n openSidebar?: boolean;\n}\n\nexport interface AgentChatContextRemoveOptions extends AgentChatContextMutationOptions {\n /** Stable key of the staged context nugget to remove. */\n key: string;\n}\n\nconst AGENT_CHAT_MESSAGE_TYPE = \"agentNative.submitChat\";\nconst AGENT_CHAT_CONTEXT_STATE_KEY = \"agent-chat-context\";\nconst AGENT_CHAT_EXEC_MODE_KEY = \"agent-native-exec-mode\";\nexport const AGENT_CHAT_CONTEXT_CHANGED_EVENT =\n \"agentNative.chatContextChanged\";\nexport const AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE = \"agentNative.setChatContext\";\nexport const AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE =\n \"agentNative.removeChatContext\";\nexport const AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE =\n \"agentNative.clearChatContext\";\nexport const AGENT_CHAT_INSERT_REFERENCE_MESSAGE_TYPE =\n \"agentNative.insertComposerReference\";\nexport const AGENT_CHAT_INSERT_REFERENCE_EVENT =\n \"agentNative:insert-composer-reference\";\nconst AGENT_PANEL_PREPARE_EVENT = \"agent-panel:prepare\";\n\nlet agentChatContextState: AgentChatContextState = {\n items: [],\n updatedAt: 0,\n};\nconst agentChatContextListeners = new Set<() => void>();\nlet agentChatContextNotifyQueued = false;\n\n/**\n * Listen for chatRunning messages from the frame (postMessage)\n * and re-dispatch as a CustomEvent so hooks like useAgentChatGenerating() work.\n */\nif (typeof window !== \"undefined\") {\n window.addEventListener(\"message\", (event) => {\n if (!isTrustedFrameMessage(event) && !isTrustedBuilderMessage(event)) {\n return;\n }\n if (\n event.data?.type === \"agentNative.chatRunning\" ||\n event.data?.type === \"builder.chatRunning\"\n ) {\n window.dispatchEvent(\n new CustomEvent(\"agentNative.chatRunning\", {\n detail: event.data.detail ?? event.data.data,\n }),\n );\n }\n });\n}\n\n/** Generate a unique tab ID */\nexport function generateTabId(): string {\n return `chat-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n}\n\n/** Unique id for one submitted message, used to dedup live + replayed sends. */\nfunction generateSubmitMessageId(): string {\n return `submit-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n}\n\n// Self-submit buffer: same-window sends post to `window` itself, but the\n// receiver is lazy-loaded and may not be listening yet. Buffer each submit so\n// the panel can replay it on mount; claimAgentChatSubmit dedups by id so a\n// submit received both live and replayed is delivered exactly once.\ninterface BufferedSelfSubmit {\n id: string;\n data: Record<string, unknown>;\n at: number;\n}\n\nconst SELF_SUBMIT_BUFFER_TTL_MS = 8000;\nconst bufferedSelfSubmits: BufferedSelfSubmit[] = [];\nconst claimedSubmitIds = new Set<string>();\n\nfunction pruneSelfSubmitBuffer(now: number): void {\n for (let i = bufferedSelfSubmits.length - 1; i >= 0; i -= 1) {\n if (now - bufferedSelfSubmits[i].at > SELF_SUBMIT_BUFFER_TTL_MS) {\n const [removed] = bufferedSelfSubmits.splice(i, 1);\n if (removed) claimedSubmitIds.delete(removed.id);\n }\n }\n}\n\nfunction bufferSelfSubmit(data: Record<string, unknown>): void {\n const id =\n typeof data.submitMessageId === \"string\" ? data.submitMessageId : undefined;\n if (!id) return;\n const now = Date.now();\n pruneSelfSubmitBuffer(now);\n bufferedSelfSubmits.push({ id, data, at: now });\n}\n\n/** Unclaimed self-submit payloads, for the panel to replay once it mounts. */\nexport function drainBufferedAgentChatSubmits(): Array<\n Record<string, unknown>\n> {\n pruneSelfSubmitBuffer(Date.now());\n return bufferedSelfSubmits\n .filter((entry) => !claimedSubmitIds.has(entry.id))\n .map((entry) => entry.data);\n}\n\n/** Claim a submit; false if already handled. Idless submits always pass. */\nexport function claimAgentChatSubmit(id: string | undefined): boolean {\n if (!id) return true;\n if (claimedSubmitIds.has(id)) return false;\n claimedSubmitIds.add(id);\n return true;\n}\n\n/** Test-only: reset the self-submit buffer and claim set. */\nexport function _resetAgentChatSubmitBufferForTests(): void {\n bufferedSelfSubmits.length = 0;\n claimedSubmitIds.clear();\n}\n\nexport function normalizeAgentChatContextItem(\n item: unknown,\n): AgentChatContextItem | null {\n if (typeof item !== \"object\" || item === null) return null;\n const candidate = item as Partial<AgentChatContextItem>;\n if (\n typeof candidate.key !== \"string\" ||\n typeof candidate.context !== \"string\" ||\n typeof candidate.title !== \"string\"\n ) {\n return null;\n }\n const key = candidate.key.trim();\n const context = candidate.context.trim();\n if (!key || !context) return null;\n return {\n key,\n title: candidate.title.trim() || key,\n context,\n };\n}\n\nexport function normalizeAgentChatContextItems(\n items: unknown,\n): AgentChatContextItem[] {\n if (!Array.isArray(items)) return [];\n const deduped = new Map<string, AgentChatContextItem>();\n for (const rawItem of items) {\n const item = normalizeAgentChatContextItem(rawItem);\n if (!item) continue;\n deduped.set(item.key, item);\n }\n return [...deduped.values()];\n}\n\nfunction normalizeAgentChatContextState(\n value: unknown,\n): AgentChatContextState | null {\n if (!value || typeof value !== \"object\") return null;\n const raw = value as {\n value?: unknown;\n items?: unknown;\n updatedAt?: unknown;\n };\n const candidate =\n raw.value && typeof raw.value === \"object\"\n ? (raw.value as { items?: unknown; updatedAt?: unknown })\n : raw;\n const items = normalizeAgentChatContextItems(candidate.items);\n return {\n items,\n updatedAt:\n typeof candidate.updatedAt === \"number\" ? candidate.updatedAt : 0,\n };\n}\n\nfunction withReplacedAgentChatContextItem(\n items: readonly AgentChatContextItem[],\n item: AgentChatContextItem,\n): AgentChatContextItem[] {\n const index = items.findIndex((current) => current.key === item.key);\n if (index === -1) return [...items, item];\n return items.map((current, currentIndex) =>\n currentIndex === index ? item : current,\n );\n}\n\nfunction notifyAgentChatContextListeners(): void {\n if (agentChatContextNotifyQueued) return;\n agentChatContextNotifyQueued = true;\n const notify = () => {\n agentChatContextNotifyQueued = false;\n for (const listener of Array.from(agentChatContextListeners)) listener();\n };\n if (typeof queueMicrotask === \"function\") {\n queueMicrotask(notify);\n } else {\n setTimeout(notify, 0);\n }\n}\n\nfunction persistAgentChatContextState(state: AgentChatContextState): void {\n if (typeof window === \"undefined\" || typeof fetch !== \"function\") return;\n fetch(\n agentNativePath(\n `/_agent-native/application-state/${AGENT_CHAT_CONTEXT_STATE_KEY}`,\n ),\n {\n method: \"PUT\",\n keepalive: true,\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(state),\n },\n ).catch(() => {});\n}\n\nexport function publishAgentChatContextItems(\n items: readonly AgentChatContextItem[],\n options?: { persist?: boolean; updatedAt?: number },\n): AgentChatContextState {\n const next: AgentChatContextState = {\n items: normalizeAgentChatContextItems([...items]),\n updatedAt: options?.updatedAt ?? Date.now(),\n };\n if (next.updatedAt < agentChatContextState.updatedAt) {\n return agentChatContextState;\n }\n agentChatContextState = next;\n notifyAgentChatContextListeners();\n if (typeof window !== \"undefined\") {\n window.dispatchEvent(\n new CustomEvent(AGENT_CHAT_CONTEXT_CHANGED_EVENT, {\n detail: next,\n }),\n );\n }\n if (options?.persist !== false) {\n persistAgentChatContextState(next);\n }\n return next;\n}\n\nexport function getAgentChatContextState(): AgentChatContextState {\n return agentChatContextState;\n}\n\nexport function listAgentChatContext(): AgentChatContextItem[] {\n return [...agentChatContextState.items];\n}\n\nexport function subscribeAgentChatContext(listener: () => void): () => void {\n agentChatContextListeners.add(listener);\n return () => {\n agentChatContextListeners.delete(listener);\n };\n}\n\nexport async function refreshAgentChatContext(): Promise<AgentChatContextState> {\n if (typeof window === \"undefined\" || typeof fetch !== \"function\") {\n return agentChatContextState;\n }\n try {\n const res = await fetch(\n agentNativePath(\n `/_agent-native/application-state/${AGENT_CHAT_CONTEXT_STATE_KEY}`,\n ),\n );\n if (!res.ok || res.status === 204) return agentChatContextState;\n const text = await res.text();\n if (!text) return agentChatContextState;\n const state = normalizeAgentChatContextState(JSON.parse(text));\n if (!state) return agentChatContextState;\n return publishAgentChatContextItems(state.items, {\n persist: false,\n updatedAt: state.updatedAt,\n });\n } catch {\n return agentChatContextState;\n }\n}\n\nexport function formatAgentChatContextItemsForPrompt(\n items: readonly AgentChatContextItem[],\n): string {\n return items\n .map(normalizeAgentChatContextItem)\n .filter((item): item is AgentChatContextItem => item !== null)\n .map((item) => [`## ${item.title}`, item.context].join(\"\\n\"))\n .join(\"\\n\\n\");\n}\n\nexport function appendAgentChatContextToMessage(\n message: string,\n context: string,\n): string {\n const trimmedContext = context.trim();\n if (!trimmedContext) return message;\n return `${message.trim()}\\n\\n<context>\\n${trimmedContext}\\n</context>`;\n}\n\nfunction normalizeStringArray(value: unknown): string[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const normalized = value\n .filter((item): item is string => typeof item === \"string\")\n .map((item) => item.trim())\n .filter(Boolean);\n return normalized.length > 0 ? normalized : undefined;\n}\n\nfunction normalizeMetadata(\n value: unknown,\n): Record<string, unknown> | undefined {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return undefined;\n }\n return value as Record<string, unknown>;\n}\n\nfunction normalizeAgentComposerReferenceInternal(\n value: unknown,\n depth: number,\n): AgentComposerReference | null {\n if (typeof value !== \"object\" || value === null) return null;\n const candidate = value as Partial<AgentComposerReference>;\n const label =\n typeof candidate.label === \"string\" ? candidate.label.trim() : \"\";\n const refType =\n typeof candidate.refType === \"string\" ? candidate.refType.trim() : \"\";\n if (!label || !refType) return null;\n const normalized: AgentComposerReference = {\n label,\n icon:\n typeof candidate.icon === \"string\" && candidate.icon.trim()\n ? candidate.icon.trim()\n : undefined,\n source:\n typeof candidate.source === \"string\" && candidate.source.trim()\n ? candidate.source.trim()\n : undefined,\n refType,\n refId:\n typeof candidate.refId === \"string\" && candidate.refId.trim()\n ? candidate.refId.trim()\n : null,\n refPath:\n typeof candidate.refPath === \"string\" && candidate.refPath.trim()\n ? candidate.refPath.trim()\n : null,\n };\n const slotKey =\n typeof candidate.slotKey === \"string\" ? candidate.slotKey.trim() : \"\";\n if (slotKey) normalized.slotKey = slotKey;\n const slotLabel =\n typeof candidate.slotLabel === \"string\" ? candidate.slotLabel.trim() : \"\";\n if (slotLabel) normalized.slotLabel = slotLabel;\n const metadata = normalizeMetadata(candidate.metadata);\n if (metadata) normalized.metadata = metadata;\n const clearsSlots = normalizeStringArray(candidate.clearsSlots);\n if (clearsSlots) normalized.clearsSlots = clearsSlots;\n if (depth < 3 && Array.isArray(candidate.relatedReferences)) {\n const relatedReferences = candidate.relatedReferences\n .map((item) => normalizeAgentComposerReferenceInternal(item, depth + 1))\n .filter((item): item is AgentComposerReference => item !== null);\n if (relatedReferences.length > 0) {\n normalized.relatedReferences = relatedReferences;\n }\n }\n return normalized;\n}\n\nexport function normalizeAgentComposerReference(\n value: unknown,\n): AgentComposerReference | null {\n return normalizeAgentComposerReferenceInternal(value, 0);\n}\n\nfunction postAgentChatContextMessage(\n type:\n | typeof AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE\n | typeof AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE\n | typeof AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE,\n data: unknown,\n options: { openSidebar: boolean },\n): void {\n if (typeof window === \"undefined\") return;\n\n const shouldForwardOpenSidebar =\n (type === AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE &&\n options.openSidebar === false) ||\n (type !== AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE &&\n options.openSidebar === true);\n const payloadData =\n shouldForwardOpenSidebar && typeof data === \"object\" && data !== null\n ? {\n ...(data as Record<string, unknown>),\n openSidebar: options.openSidebar,\n }\n : data;\n const payload = { type, data: payloadData };\n const targetSelf = isInBuilderFrame() || isDirectMcpAppEmbedSession();\n const target = targetSelf\n ? window\n : window.parent !== window\n ? window.parent\n : window;\n const targetOrigin = targetSelf\n ? window.location.origin\n : getFramePostMessageTargetOrigin() || window.location.origin;\n\n if (options.openSidebar) {\n window.dispatchEvent(\n new CustomEvent(\"agent-panel:set-mode\", {\n detail: { mode: \"chat\" },\n }),\n );\n window.dispatchEvent(new CustomEvent(\"agent-panel:open\"));\n } else {\n window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));\n }\n\n const postToTarget = () => target.postMessage(payload, targetOrigin);\n if (target === window) {\n setTimeout(postToTarget, 0);\n } else {\n postToTarget();\n }\n}\n\nfunction postAgentChatReferenceMessage(\n payload: AgentComposerReferenceInsertPayload,\n options: { openSidebar: boolean },\n): void {\n if (typeof window === \"undefined\") return;\n\n const message = {\n type: AGENT_CHAT_INSERT_REFERENCE_MESSAGE_TYPE,\n data: payload,\n };\n const targetSelf = isInBuilderFrame() || isDirectMcpAppEmbedSession();\n const target = targetSelf\n ? window\n : window.parent !== window\n ? window.parent\n : window;\n const targetOrigin = targetSelf\n ? window.location.origin\n : getFramePostMessageTargetOrigin() || window.location.origin;\n\n if (options.openSidebar) {\n window.dispatchEvent(\n new CustomEvent(\"agent-panel:set-mode\", {\n detail: { mode: \"chat\" },\n }),\n );\n window.dispatchEvent(new CustomEvent(\"agent-panel:open\"));\n } else {\n window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));\n }\n\n window.dispatchEvent(\n new CustomEvent(AGENT_CHAT_INSERT_REFERENCE_EVENT, {\n detail: payload,\n }),\n );\n\n const postToTarget = () => target.postMessage(message, targetOrigin);\n if (target === window) {\n setTimeout(postToTarget, 0);\n } else {\n postToTarget();\n }\n}\n\nfunction isMcpAppChatBridgeEnabled(): boolean {\n if (typeof window === \"undefined\" || window.parent === window) return false;\n if (readEmbedMcpChatBridgeFlagFromUrl()) markEmbedMcpChatBridgeActive();\n return isEmbedMcpChatBridgeActive() && isEmbedAuthActive();\n}\n\nfunction isDirectMcpAppEmbedSession(): boolean {\n if (typeof window === \"undefined\" || window.parent === window) return false;\n if (readEmbedMcpChatBridgeFlagFromUrl()) markEmbedMcpChatBridgeActive();\n return isEmbedAuthActive() && !isEmbedMcpChatBridgeActive();\n}\n\nfunction dispatchAgentChatRunning(isRunning: boolean): void {\n if (typeof window === \"undefined\") return;\n window.dispatchEvent(\n new CustomEvent(\"agentNative.chatRunning\", {\n detail: { isRunning },\n }),\n );\n}\n\nfunction normalizeAgentChatRequestMode(\n value: unknown,\n): AgentChatRequestMode | undefined {\n return value === \"act\" || value === \"plan\" ? value : undefined;\n}\n\n/** A normalized `agentNative.submitChat` payload — decode via {@link parseSubmitChatMessage}. */\nexport interface ParsedSubmitChat {\n /** Visible prompt text (non-empty). */\n message: string;\n context?: string;\n /** Submit (true) or prefill only (false); defaults to true. */\n submit: boolean;\n openSidebar?: boolean;\n model?: string;\n /** Raw effort hint; the receiver validates it against the model. */\n effort?: unknown;\n newTab?: boolean;\n background?: boolean;\n tabId?: string;\n images?: string[];\n /** Mode as sent; the receiver falls back to its exec mode when undefined. */\n requestMode?: AgentChatRequestMode;\n /** Id used to dedup the live post against a cold-start replay. */\n submitMessageId?: string;\n}\n\n/** Decode a `message` event into a submit payload, or null if it isn't one / has no text. */\nexport function parseSubmitChatMessage(\n event: MessageEvent,\n): ParsedSubmitChat | null {\n const envelope =\n event.data && typeof event.data === \"object\"\n ? (event.data as { type?: unknown; data?: unknown })\n : null;\n if (!envelope || envelope.type !== AGENT_CHAT_MESSAGE_TYPE) return null;\n const raw =\n envelope.data && typeof envelope.data === \"object\"\n ? (envelope.data as Record<string, unknown>)\n : null;\n if (!raw) return null;\n const message = typeof raw.message === \"string\" ? raw.message : \"\";\n if (!message) return null;\n const images = Array.isArray(raw.images)\n ? raw.images.filter(\n (image): image is string =>\n typeof image === \"string\" && image.length > 0,\n )\n : undefined;\n return {\n message,\n context: typeof raw.context === \"string\" ? raw.context : undefined,\n submit: raw.submit !== false,\n openSidebar:\n typeof raw.openSidebar === \"boolean\" ? raw.openSidebar : undefined,\n model: typeof raw.model === \"string\" ? raw.model : undefined,\n effort: raw.effort,\n newTab: typeof raw.newTab === \"boolean\" ? raw.newTab : undefined,\n background:\n typeof raw.background === \"boolean\" ? raw.background : undefined,\n tabId: typeof raw.tabId === \"string\" ? raw.tabId : undefined,\n images,\n requestMode: normalizeAgentChatRequestMode(raw.requestMode ?? raw.mode),\n submitMessageId:\n typeof raw.submitMessageId === \"string\" ? raw.submitMessageId : undefined,\n };\n}\n\nfunction normalizeStoredAgentChatExecMode(\n value: string | null,\n): AgentChatRequestMode | undefined {\n if (value === \"plan\") return \"plan\";\n if (value === \"build\" || value === \"act\") return \"act\";\n return undefined;\n}\n\nfunction readStoredAgentChatRequestMode(): AgentChatRequestMode | undefined {\n if (typeof window === \"undefined\") return undefined;\n try {\n const storage = window.localStorage;\n const saved = normalizeStoredAgentChatExecMode(\n storage.getItem(AGENT_CHAT_EXEC_MODE_KEY),\n );\n if (saved) return saved;\n const scopedModes: AgentChatRequestMode[] = [];\n for (let index = 0; index < storage.length; index += 1) {\n const key = storage.key(index);\n if (!key?.startsWith(`${AGENT_CHAT_EXEC_MODE_KEY}:`)) continue;\n const scopedSaved = normalizeStoredAgentChatExecMode(\n storage.getItem(key),\n );\n if (scopedSaved) scopedModes.push(scopedSaved);\n }\n if (scopedModes.length === 1) return scopedModes[0];\n } catch {}\n return undefined;\n}\n\n/**\n * Send a message to the agent chat via postMessage.\n * Returns the stable tabId for tracking this chat run.\n */\nexport function sendToAgentChat(opts: AgentChatMessage): string {\n const tabId = opts.tabId ?? generateTabId();\n const isCodeRequest = opts.type === \"code\" || opts.requiresCode === true;\n const localChatTarget = opts.chatTarget === \"local\";\n const requestMode =\n normalizeAgentChatRequestMode(opts.requestMode ?? opts.mode) ??\n readStoredAgentChatRequestMode();\n if (isCodeRequest && isInBuilderFrame()) {\n sendToBuilderChat({\n message: opts.message,\n context: opts.context,\n submit: opts.submit,\n ...(requestMode ? { mode: requestMode, requestMode } : {}),\n });\n return tabId;\n }\n\n const submitMessageId = generateSubmitMessageId();\n const payload = {\n type: AGENT_CHAT_MESSAGE_TYPE,\n data: {\n ...opts,\n tabId,\n submitMessageId,\n ...(requestMode ? { mode: requestMode, requestMode } : {}),\n },\n };\n\n if (\n opts.submit !== false &&\n !localChatTarget &&\n isMcpAppChatBridgeEnabled()\n ) {\n const directHostMessage = sendMcpAppHostMessage({\n message: opts.message,\n context: opts.context,\n ...(requestMode ? { mode: requestMode, requestMode } : {}),\n });\n if (directHostMessage) {\n void Promise.resolve(directHostMessage)\n .then((ok) => {\n if (!ok) {\n window.parent.postMessage(\n payload,\n getFramePostMessageTargetOrigin() || \"*\",\n );\n }\n })\n .finally(() => {\n dispatchAgentChatRunning(false);\n });\n return tabId;\n }\n window.parent.postMessage(\n payload,\n getFramePostMessageTargetOrigin() || \"*\",\n );\n return tabId;\n }\n\n const shouldOpenSidebar = opts.openSidebar !== false && !opts.background;\n\n const targetSelf =\n !isCodeRequest &&\n (localChatTarget || isInBuilderFrame() || isDirectMcpAppEmbedSession());\n const target = targetSelf\n ? window\n : window.parent !== window\n ? window.parent\n : window;\n const targetOrigin = targetSelf\n ? window.location.origin\n : getFramePostMessageTargetOrigin() || window.location.origin;\n if (shouldOpenSidebar) {\n window.dispatchEvent(\n new CustomEvent(\"agent-panel:set-mode\", {\n detail: { mode: \"chat\" },\n }),\n );\n window.dispatchEvent(new CustomEvent(\"agent-panel:open\"));\n } else if (!isCodeRequest) {\n window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));\n }\n\n const postToTarget = () => target.postMessage(payload, targetOrigin);\n\n // Same-window: defer one tick so a sidebar mounting now can attach its\n // listener, and buffer the submit so the lazy panel can replay it if it\n // mounts later. The live post and the replay dedup by submitMessageId.\n if (!isCodeRequest && target === window) {\n bufferSelfSubmit(payload.data);\n setTimeout(postToTarget, 0);\n } else {\n postToTarget();\n }\n return tabId;\n}\n\n/**\n * Add or replace a keyed context nugget in the active agent chat composer.\n * The context is not submitted until the user sends the prompt.\n */\nexport function setAgentChatContextItem(\n opts: AgentChatContextSetOptions,\n): void {\n const item = normalizeAgentChatContextItem(opts);\n if (!item || typeof window === \"undefined\") return;\n\n publishAgentChatContextItems(\n withReplacedAgentChatContextItem(agentChatContextState.items, item),\n );\n postAgentChatContextMessage(AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE, item, {\n openSidebar: opts.openSidebar !== false,\n });\n}\n\n/** @deprecated Use `setAgentChatContextItem` instead. */\nexport const setContextToAgentChat = setAgentChatContextItem;\n\n/** @deprecated Use `setAgentChatContextItem` instead. */\nexport const addContextToAgentChat = setAgentChatContextItem;\n\nexport function insertAgentComposerReference(\n ref: AgentComposerReference,\n options: AgentComposerReferenceInsertOptions = {},\n): void {\n const normalized = normalizeAgentComposerReference(ref);\n if (!normalized || typeof window === \"undefined\") return;\n postAgentChatReferenceMessage(\n {\n ...normalized,\n insertMessageId: `reference-${Date.now()}-${Math.random()\n .toString(36)\n .slice(2, 8)}`,\n },\n { openSidebar: options.openSidebar === true },\n );\n}\n\nexport function removeAgentChatContextItem(\n keyOrOpts: string | AgentChatContextRemoveOptions,\n): void {\n const key =\n typeof keyOrOpts === \"string\" ? keyOrOpts.trim() : keyOrOpts.key.trim();\n if (!key || typeof window === \"undefined\") return;\n const openSidebar =\n typeof keyOrOpts === \"string\" ? false : keyOrOpts.openSidebar === true;\n\n publishAgentChatContextItems(\n agentChatContextState.items.filter((item) => item.key !== key),\n );\n postAgentChatContextMessage(\n AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE,\n { key },\n { openSidebar },\n );\n}\n\nexport function clearAgentChatContext(\n opts: AgentChatContextMutationOptions = {},\n): void {\n if (typeof window === \"undefined\") return;\n publishAgentChatContextItems([]);\n postAgentChatContextMessage(\n AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE,\n {},\n { openSidebar: opts.openSidebar === true },\n );\n}\n\nexport function _resetAgentChatContextForTests(): void {\n agentChatContextState = { items: [], updatedAt: 0 };\n notifyAgentChatContextListeners();\n}\n"]}
1
+ {"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ured messages to the agent chat from UI interactions.\n * Messages are sent via postMessage to the parent window (or self if top-level).\n * Builder frames are special: code requests go to Builder, but content prompts\n * stay inside the embedded app so its own AgentSidebar can receive them.\n */\n\nimport type { ReasoningEffort } from \"../shared/reasoning-effort.js\";\nimport { agentNativePath } from \"./api-path.js\";\nimport {\n isInBuilderFrame,\n isTrustedBuilderMessage,\n sendToBuilderChat,\n} from \"./builder-frame.js\";\nimport {\n isEmbedAuthActive,\n isEmbedMcpChatBridgeActive,\n markEmbedMcpChatBridgeActive,\n readEmbedMcpChatBridgeFlagFromUrl,\n} from \"./embed-auth.js\";\nimport {\n getFramePostMessageTargetOrigin,\n isTrustedFrameMessage,\n} from \"./frame.js\";\nimport { sendMcpAppHostMessage } from \"./mcp-app-host.js\";\n\nexport type AgentChatRequestMode = \"act\" | \"plan\";\n\nexport interface AgentChatMessage {\n /** The visible prompt message sent to the chat */\n message: string;\n /** Hidden context appended to the message (not shown in chat UI) */\n context?: string;\n /** true = auto-submit, false = prefill only, omit = use project setting */\n submit?: boolean;\n /** Optional project slug for structured context */\n projectSlug?: string;\n /** Optional preset name for downstream consumers */\n preset?: string;\n /** Optional reference image paths */\n referenceImagePaths?: string[];\n /** Optional uploaded reference images */\n uploadedReferenceImages?: string[];\n /** Optional image data URLs to include in the submitted chat message */\n images?: string[];\n /** Stable tab identifier — auto-generated if omitted */\n tabId?: string;\n /**\n * Message routing type:\n * - \"content\" (default): stays in the embedded app agent for content/data operations\n * - \"code\": routes to the code editing frame (Agent Native Desktop or Builder.io)\n *\n * When type is \"code\" and no frame is connected, a dialog is shown.\n * `requiresCode: true` is treated as `type: \"code\"` for backward compatibility.\n */\n type?: \"content\" | \"code\";\n /** @deprecated Use `type: \"code\"` instead. If true, treated as `type: \"code\"`. */\n requiresCode?: boolean;\n /** Model preference for this sub-agent (e.g. \"claude-haiku-4-5\"). Uses default if omitted */\n model?: string;\n /** Engine preference paired with model for cross-provider switches. */\n engine?: string;\n /** Reasoning effort preference paired with model. */\n effort?: ReasoningEffort;\n /**\n * Execution mode for this submitted turn. When omitted, sendToAgentChat\n * snapshots the current AgentPanel mode from localStorage when available.\n */\n mode?: AgentChatRequestMode;\n /** @deprecated Use `mode` instead. */\n requestMode?: AgentChatRequestMode;\n /** Scoped system prompt additions for this sub-agent */\n instructions?: string;\n /**\n * Message delivery target. Auto-submitted MCP App messages normally relay to\n * the host chat; use \"local\" when a control explicitly targets this app's\n * own AgentSidebar.\n */\n chatTarget?: \"auto\" | \"local\";\n /**\n * Whether to open the agent sidebar if it's currently hidden.\n * Defaults to true — submitting a chat should make the response visible.\n * Pass `false` for background/silent sends that shouldn't pop the UI open.\n */\n openSidebar?: boolean;\n /**\n * When true, opens a new chat tab before sending the message.\n * Use for creation requests (create tool, dashboard, etc.) that deserve\n * their own isolated thread rather than cluttering an existing conversation.\n */\n newTab?: boolean;\n /**\n * When true with newTab, creates the tab in the background without\n * focusing it or opening the sidebar. The message runs silently.\n */\n background?: boolean;\n}\n\nexport interface AgentChatContextItem {\n /** Stable key used to replace an existing context nugget. */\n key: string;\n /** Short label shown in the composer context chip. */\n title: string;\n /** Hidden context included with the next submitted prompt. */\n context: string;\n}\n\nexport interface AgentChatContextSetOptions extends AgentChatContextItem {\n /**\n * Whether to open the agent sidebar if it's currently hidden.\n * Defaults to true so the user can see the staged context.\n */\n openSidebar?: boolean;\n /**\n * Whether to move keyboard focus into the composer when staging the item.\n * Defaults to true. Pass `false` for context that mirrors ambient UI state\n * (e.g. a canvas element selection) so staging never steals focus from an\n * unrelated editor — such as an inline text editor in a design canvas.\n */\n focus?: boolean;\n}\n\n/** @deprecated Use `AgentChatContextSetOptions` instead. */\nexport type AgentChatContextMessage = AgentChatContextSetOptions;\n\nexport interface AgentChatContextState {\n items: AgentChatContextItem[];\n updatedAt: number;\n}\n\nexport interface AgentComposerReference {\n label: string;\n icon?: string;\n source?: string;\n refType: string;\n refId?: string | null;\n refPath?: string | null;\n /** Stable composer slot this reference occupies. Slot references replace older values. */\n slotKey?: string;\n /** Short label shown before the selected value in the composer chip. */\n slotLabel?: string;\n /** Additional app-defined data used by the client for filtering and grouping. */\n metadata?: Record<string, unknown>;\n /** Slots to remove when this reference is inserted or removed. */\n clearsSlots?: string[];\n /** Additional references to insert before this one. */\n relatedReferences?: AgentComposerReference[];\n}\n\nexport interface AgentComposerReferenceInsertOptions {\n /**\n * Whether to open the agent sidebar before inserting the reference.\n * Defaults to false so contextual auto-tags can stay quiet.\n */\n openSidebar?: boolean;\n}\n\nexport interface AgentComposerReferenceInsertPayload extends AgentComposerReference {\n insertMessageId: string;\n}\n\nexport interface AgentChatContextMutationOptions {\n /**\n * Whether to open the agent sidebar if it's currently hidden.\n * Defaults to true for set/add and false for remove/clear.\n */\n openSidebar?: boolean;\n}\n\nexport interface AgentChatContextRemoveOptions extends AgentChatContextMutationOptions {\n /** Stable key of the staged context nugget to remove. */\n key: string;\n}\n\nconst AGENT_CHAT_MESSAGE_TYPE = \"agentNative.submitChat\";\nconst AGENT_CHAT_CONTEXT_STATE_KEY = \"agent-chat-context\";\nconst AGENT_CHAT_EXEC_MODE_KEY = \"agent-native-exec-mode\";\nexport const AGENT_CHAT_CONTEXT_CHANGED_EVENT =\n \"agentNative.chatContextChanged\";\nexport const AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE = \"agentNative.setChatContext\";\nexport const AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE =\n \"agentNative.removeChatContext\";\nexport const AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE =\n \"agentNative.clearChatContext\";\nexport const AGENT_CHAT_INSERT_REFERENCE_MESSAGE_TYPE =\n \"agentNative.insertComposerReference\";\nexport const AGENT_CHAT_INSERT_REFERENCE_EVENT =\n \"agentNative:insert-composer-reference\";\nconst AGENT_PANEL_PREPARE_EVENT = \"agent-panel:prepare\";\n\nlet agentChatContextState: AgentChatContextState = {\n items: [],\n updatedAt: 0,\n};\nconst agentChatContextListeners = new Set<() => void>();\nlet agentChatContextNotifyQueued = false;\n\n/**\n * Listen for chatRunning messages from the frame (postMessage)\n * and re-dispatch as a CustomEvent so hooks like useAgentChatGenerating() work.\n */\nif (typeof window !== \"undefined\") {\n window.addEventListener(\"message\", (event) => {\n if (!isTrustedFrameMessage(event) && !isTrustedBuilderMessage(event)) {\n return;\n }\n if (\n event.data?.type === \"agentNative.chatRunning\" ||\n event.data?.type === \"builder.chatRunning\"\n ) {\n window.dispatchEvent(\n new CustomEvent(\"agentNative.chatRunning\", {\n detail: event.data.detail ?? event.data.data,\n }),\n );\n }\n });\n}\n\n/** Generate a unique tab ID */\nexport function generateTabId(): string {\n return `chat-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n}\n\n/** Unique id for one submitted message, used to dedup live + replayed sends. */\nfunction generateSubmitMessageId(): string {\n return `submit-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n}\n\n// Self-submit buffer: same-window sends post to `window` itself, but the\n// receiver is lazy-loaded and may not be listening yet. Buffer each submit so\n// the panel can replay it on mount; claimAgentChatSubmit dedups by id so a\n// submit received both live and replayed is delivered exactly once.\ninterface BufferedSelfSubmit {\n id: string;\n data: Record<string, unknown>;\n at: number;\n}\n\nconst SELF_SUBMIT_BUFFER_TTL_MS = 8000;\nconst bufferedSelfSubmits: BufferedSelfSubmit[] = [];\nconst claimedSubmitIds = new Set<string>();\n\nfunction pruneSelfSubmitBuffer(now: number): void {\n for (let i = bufferedSelfSubmits.length - 1; i >= 0; i -= 1) {\n if (now - bufferedSelfSubmits[i].at > SELF_SUBMIT_BUFFER_TTL_MS) {\n const [removed] = bufferedSelfSubmits.splice(i, 1);\n if (removed) claimedSubmitIds.delete(removed.id);\n }\n }\n}\n\nfunction bufferSelfSubmit(data: Record<string, unknown>): void {\n const id =\n typeof data.submitMessageId === \"string\" ? data.submitMessageId : undefined;\n if (!id) return;\n const now = Date.now();\n pruneSelfSubmitBuffer(now);\n bufferedSelfSubmits.push({ id, data, at: now });\n}\n\n/** Unclaimed self-submit payloads, for the panel to replay once it mounts. */\nexport function drainBufferedAgentChatSubmits(): Array<\n Record<string, unknown>\n> {\n pruneSelfSubmitBuffer(Date.now());\n return bufferedSelfSubmits\n .filter((entry) => !claimedSubmitIds.has(entry.id))\n .map((entry) => entry.data);\n}\n\n/** Claim a submit; false if already handled. Idless submits always pass. */\nexport function claimAgentChatSubmit(id: string | undefined): boolean {\n if (!id) return true;\n if (claimedSubmitIds.has(id)) return false;\n claimedSubmitIds.add(id);\n return true;\n}\n\n/** Test-only: reset the self-submit buffer and claim set. */\nexport function _resetAgentChatSubmitBufferForTests(): void {\n bufferedSelfSubmits.length = 0;\n claimedSubmitIds.clear();\n}\n\nexport function normalizeAgentChatContextItem(\n item: unknown,\n): AgentChatContextItem | null {\n if (typeof item !== \"object\" || item === null) return null;\n const candidate = item as Partial<AgentChatContextItem>;\n if (\n typeof candidate.key !== \"string\" ||\n typeof candidate.context !== \"string\" ||\n typeof candidate.title !== \"string\"\n ) {\n return null;\n }\n const key = candidate.key.trim();\n const context = candidate.context.trim();\n if (!key || !context) return null;\n return {\n key,\n title: candidate.title.trim() || key,\n context,\n };\n}\n\nexport function normalizeAgentChatContextItems(\n items: unknown,\n): AgentChatContextItem[] {\n if (!Array.isArray(items)) return [];\n const deduped = new Map<string, AgentChatContextItem>();\n for (const rawItem of items) {\n const item = normalizeAgentChatContextItem(rawItem);\n if (!item) continue;\n deduped.set(item.key, item);\n }\n return [...deduped.values()];\n}\n\nfunction normalizeAgentChatContextState(\n value: unknown,\n): AgentChatContextState | null {\n if (!value || typeof value !== \"object\") return null;\n const raw = value as {\n value?: unknown;\n items?: unknown;\n updatedAt?: unknown;\n };\n const candidate =\n raw.value && typeof raw.value === \"object\"\n ? (raw.value as { items?: unknown; updatedAt?: unknown })\n : raw;\n const items = normalizeAgentChatContextItems(candidate.items);\n return {\n items,\n updatedAt:\n typeof candidate.updatedAt === \"number\" ? candidate.updatedAt : 0,\n };\n}\n\nfunction withReplacedAgentChatContextItem(\n items: readonly AgentChatContextItem[],\n item: AgentChatContextItem,\n): AgentChatContextItem[] {\n const index = items.findIndex((current) => current.key === item.key);\n if (index === -1) return [...items, item];\n return items.map((current, currentIndex) =>\n currentIndex === index ? item : current,\n );\n}\n\nfunction notifyAgentChatContextListeners(): void {\n if (agentChatContextNotifyQueued) return;\n agentChatContextNotifyQueued = true;\n const notify = () => {\n agentChatContextNotifyQueued = false;\n for (const listener of Array.from(agentChatContextListeners)) listener();\n };\n if (typeof queueMicrotask === \"function\") {\n queueMicrotask(notify);\n } else {\n setTimeout(notify, 0);\n }\n}\n\nfunction persistAgentChatContextState(state: AgentChatContextState): void {\n if (typeof window === \"undefined\" || typeof fetch !== \"function\") return;\n fetch(\n agentNativePath(\n `/_agent-native/application-state/${AGENT_CHAT_CONTEXT_STATE_KEY}`,\n ),\n {\n method: \"PUT\",\n keepalive: true,\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(state),\n },\n ).catch(() => {});\n}\n\nexport function publishAgentChatContextItems(\n items: readonly AgentChatContextItem[],\n options?: { persist?: boolean; updatedAt?: number },\n): AgentChatContextState {\n const next: AgentChatContextState = {\n items: normalizeAgentChatContextItems([...items]),\n updatedAt: options?.updatedAt ?? Date.now(),\n };\n if (next.updatedAt < agentChatContextState.updatedAt) {\n return agentChatContextState;\n }\n agentChatContextState = next;\n notifyAgentChatContextListeners();\n if (typeof window !== \"undefined\") {\n window.dispatchEvent(\n new CustomEvent(AGENT_CHAT_CONTEXT_CHANGED_EVENT, {\n detail: next,\n }),\n );\n }\n if (options?.persist !== false) {\n persistAgentChatContextState(next);\n }\n return next;\n}\n\nexport function getAgentChatContextState(): AgentChatContextState {\n return agentChatContextState;\n}\n\nexport function listAgentChatContext(): AgentChatContextItem[] {\n return [...agentChatContextState.items];\n}\n\nexport function subscribeAgentChatContext(listener: () => void): () => void {\n agentChatContextListeners.add(listener);\n return () => {\n agentChatContextListeners.delete(listener);\n };\n}\n\nexport async function refreshAgentChatContext(): Promise<AgentChatContextState> {\n if (typeof window === \"undefined\" || typeof fetch !== \"function\") {\n return agentChatContextState;\n }\n try {\n const res = await fetch(\n agentNativePath(\n `/_agent-native/application-state/${AGENT_CHAT_CONTEXT_STATE_KEY}`,\n ),\n );\n if (!res.ok || res.status === 204) return agentChatContextState;\n const text = await res.text();\n if (!text) return agentChatContextState;\n const state = normalizeAgentChatContextState(JSON.parse(text));\n if (!state) return agentChatContextState;\n return publishAgentChatContextItems(state.items, {\n persist: false,\n updatedAt: state.updatedAt,\n });\n } catch {\n return agentChatContextState;\n }\n}\n\nexport function formatAgentChatContextItemsForPrompt(\n items: readonly AgentChatContextItem[],\n): string {\n return items\n .map(normalizeAgentChatContextItem)\n .filter((item): item is AgentChatContextItem => item !== null)\n .map((item) => [`## ${item.title}`, item.context].join(\"\\n\"))\n .join(\"\\n\\n\");\n}\n\nexport function appendAgentChatContextToMessage(\n message: string,\n context: string,\n): string {\n const trimmedContext = context.trim();\n if (!trimmedContext) return message;\n return `${message.trim()}\\n\\n<context>\\n${trimmedContext}\\n</context>`;\n}\n\nfunction normalizeStringArray(value: unknown): string[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const normalized = value\n .filter((item): item is string => typeof item === \"string\")\n .map((item) => item.trim())\n .filter(Boolean);\n return normalized.length > 0 ? normalized : undefined;\n}\n\nfunction normalizeMetadata(\n value: unknown,\n): Record<string, unknown> | undefined {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return undefined;\n }\n return value as Record<string, unknown>;\n}\n\nfunction normalizeAgentComposerReferenceInternal(\n value: unknown,\n depth: number,\n): AgentComposerReference | null {\n if (typeof value !== \"object\" || value === null) return null;\n const candidate = value as Partial<AgentComposerReference>;\n const label =\n typeof candidate.label === \"string\" ? candidate.label.trim() : \"\";\n const refType =\n typeof candidate.refType === \"string\" ? candidate.refType.trim() : \"\";\n if (!label || !refType) return null;\n const normalized: AgentComposerReference = {\n label,\n icon:\n typeof candidate.icon === \"string\" && candidate.icon.trim()\n ? candidate.icon.trim()\n : undefined,\n source:\n typeof candidate.source === \"string\" && candidate.source.trim()\n ? candidate.source.trim()\n : undefined,\n refType,\n refId:\n typeof candidate.refId === \"string\" && candidate.refId.trim()\n ? candidate.refId.trim()\n : null,\n refPath:\n typeof candidate.refPath === \"string\" && candidate.refPath.trim()\n ? candidate.refPath.trim()\n : null,\n };\n const slotKey =\n typeof candidate.slotKey === \"string\" ? candidate.slotKey.trim() : \"\";\n if (slotKey) normalized.slotKey = slotKey;\n const slotLabel =\n typeof candidate.slotLabel === \"string\" ? candidate.slotLabel.trim() : \"\";\n if (slotLabel) normalized.slotLabel = slotLabel;\n const metadata = normalizeMetadata(candidate.metadata);\n if (metadata) normalized.metadata = metadata;\n const clearsSlots = normalizeStringArray(candidate.clearsSlots);\n if (clearsSlots) normalized.clearsSlots = clearsSlots;\n if (depth < 3 && Array.isArray(candidate.relatedReferences)) {\n const relatedReferences = candidate.relatedReferences\n .map((item) => normalizeAgentComposerReferenceInternal(item, depth + 1))\n .filter((item): item is AgentComposerReference => item !== null);\n if (relatedReferences.length > 0) {\n normalized.relatedReferences = relatedReferences;\n }\n }\n return normalized;\n}\n\nexport function normalizeAgentComposerReference(\n value: unknown,\n): AgentComposerReference | null {\n return normalizeAgentComposerReferenceInternal(value, 0);\n}\n\nfunction postAgentChatContextMessage(\n type:\n | typeof AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE\n | typeof AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE\n | typeof AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE,\n data: unknown,\n options: { openSidebar: boolean },\n): void {\n if (typeof window === \"undefined\") return;\n\n const shouldForwardOpenSidebar =\n (type === AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE &&\n options.openSidebar === false) ||\n (type !== AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE &&\n options.openSidebar === true);\n const payloadData =\n shouldForwardOpenSidebar && typeof data === \"object\" && data !== null\n ? {\n ...(data as Record<string, unknown>),\n openSidebar: options.openSidebar,\n }\n : data;\n const payload = { type, data: payloadData };\n const targetSelf = isInBuilderFrame() || isDirectMcpAppEmbedSession();\n const target = targetSelf\n ? window\n : window.parent !== window\n ? window.parent\n : window;\n const targetOrigin = targetSelf\n ? window.location.origin\n : getFramePostMessageTargetOrigin() || window.location.origin;\n\n if (options.openSidebar) {\n window.dispatchEvent(\n new CustomEvent(\"agent-panel:set-mode\", {\n detail: { mode: \"chat\" },\n }),\n );\n window.dispatchEvent(new CustomEvent(\"agent-panel:open\"));\n } else {\n window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));\n }\n\n const postToTarget = () => target.postMessage(payload, targetOrigin);\n if (target === window) {\n setTimeout(postToTarget, 0);\n } else {\n postToTarget();\n }\n}\n\nfunction postAgentChatReferenceMessage(\n payload: AgentComposerReferenceInsertPayload,\n options: { openSidebar: boolean },\n): void {\n if (typeof window === \"undefined\") return;\n\n const message = {\n type: AGENT_CHAT_INSERT_REFERENCE_MESSAGE_TYPE,\n data: payload,\n };\n const targetSelf = isInBuilderFrame() || isDirectMcpAppEmbedSession();\n const target = targetSelf\n ? window\n : window.parent !== window\n ? window.parent\n : window;\n const targetOrigin = targetSelf\n ? window.location.origin\n : getFramePostMessageTargetOrigin() || window.location.origin;\n\n if (options.openSidebar) {\n window.dispatchEvent(\n new CustomEvent(\"agent-panel:set-mode\", {\n detail: { mode: \"chat\" },\n }),\n );\n window.dispatchEvent(new CustomEvent(\"agent-panel:open\"));\n } else {\n window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));\n }\n\n window.dispatchEvent(\n new CustomEvent(AGENT_CHAT_INSERT_REFERENCE_EVENT, {\n detail: payload,\n }),\n );\n\n const postToTarget = () => target.postMessage(message, targetOrigin);\n if (target === window) {\n setTimeout(postToTarget, 0);\n } else {\n postToTarget();\n }\n}\n\nfunction isMcpAppChatBridgeEnabled(): boolean {\n if (typeof window === \"undefined\" || window.parent === window) return false;\n if (readEmbedMcpChatBridgeFlagFromUrl()) markEmbedMcpChatBridgeActive();\n return isEmbedMcpChatBridgeActive() && isEmbedAuthActive();\n}\n\nfunction isDirectMcpAppEmbedSession(): boolean {\n if (typeof window === \"undefined\" || window.parent === window) return false;\n if (readEmbedMcpChatBridgeFlagFromUrl()) markEmbedMcpChatBridgeActive();\n return isEmbedAuthActive() && !isEmbedMcpChatBridgeActive();\n}\n\nfunction dispatchAgentChatRunning(isRunning: boolean): void {\n if (typeof window === \"undefined\") return;\n window.dispatchEvent(\n new CustomEvent(\"agentNative.chatRunning\", {\n detail: { isRunning },\n }),\n );\n}\n\nfunction normalizeAgentChatRequestMode(\n value: unknown,\n): AgentChatRequestMode | undefined {\n return value === \"act\" || value === \"plan\" ? value : undefined;\n}\n\n/** A normalized `agentNative.submitChat` payload — decode via {@link parseSubmitChatMessage}. */\nexport interface ParsedSubmitChat {\n /** Visible prompt text (non-empty). */\n message: string;\n context?: string;\n /** Submit (true) or prefill only (false); defaults to true. */\n submit: boolean;\n openSidebar?: boolean;\n model?: string;\n /** Raw effort hint; the receiver validates it against the model. */\n effort?: unknown;\n newTab?: boolean;\n background?: boolean;\n tabId?: string;\n images?: string[];\n /** Mode as sent; the receiver falls back to its exec mode when undefined. */\n requestMode?: AgentChatRequestMode;\n /** Id used to dedup the live post against a cold-start replay. */\n submitMessageId?: string;\n}\n\n/** Decode a `message` event into a submit payload, or null if it isn't one / has no text. */\nexport function parseSubmitChatMessage(\n event: MessageEvent,\n): ParsedSubmitChat | null {\n const envelope =\n event.data && typeof event.data === \"object\"\n ? (event.data as { type?: unknown; data?: unknown })\n : null;\n if (!envelope || envelope.type !== AGENT_CHAT_MESSAGE_TYPE) return null;\n const raw =\n envelope.data && typeof envelope.data === \"object\"\n ? (envelope.data as Record<string, unknown>)\n : null;\n if (!raw) return null;\n const message = typeof raw.message === \"string\" ? raw.message : \"\";\n if (!message) return null;\n const images = Array.isArray(raw.images)\n ? raw.images.filter(\n (image): image is string =>\n typeof image === \"string\" && image.length > 0,\n )\n : undefined;\n return {\n message,\n context: typeof raw.context === \"string\" ? raw.context : undefined,\n submit: raw.submit !== false,\n openSidebar:\n typeof raw.openSidebar === \"boolean\" ? raw.openSidebar : undefined,\n model: typeof raw.model === \"string\" ? raw.model : undefined,\n effort: raw.effort,\n newTab: typeof raw.newTab === \"boolean\" ? raw.newTab : undefined,\n background:\n typeof raw.background === \"boolean\" ? raw.background : undefined,\n tabId: typeof raw.tabId === \"string\" ? raw.tabId : undefined,\n images,\n requestMode: normalizeAgentChatRequestMode(raw.requestMode ?? raw.mode),\n submitMessageId:\n typeof raw.submitMessageId === \"string\" ? raw.submitMessageId : undefined,\n };\n}\n\nfunction normalizeStoredAgentChatExecMode(\n value: string | null,\n): AgentChatRequestMode | undefined {\n if (value === \"plan\") return \"plan\";\n if (value === \"build\" || value === \"act\") return \"act\";\n return undefined;\n}\n\nfunction readStoredAgentChatRequestMode(): AgentChatRequestMode | undefined {\n if (typeof window === \"undefined\") return undefined;\n try {\n const storage = window.localStorage;\n const saved = normalizeStoredAgentChatExecMode(\n storage.getItem(AGENT_CHAT_EXEC_MODE_KEY),\n );\n if (saved) return saved;\n const scopedModes: AgentChatRequestMode[] = [];\n for (let index = 0; index < storage.length; index += 1) {\n const key = storage.key(index);\n if (!key?.startsWith(`${AGENT_CHAT_EXEC_MODE_KEY}:`)) continue;\n const scopedSaved = normalizeStoredAgentChatExecMode(\n storage.getItem(key),\n );\n if (scopedSaved) scopedModes.push(scopedSaved);\n }\n if (scopedModes.length === 1) return scopedModes[0];\n } catch {}\n return undefined;\n}\n\n/**\n * Send a message to the agent chat via postMessage.\n * Returns the stable tabId for tracking this chat run.\n */\nexport function sendToAgentChat(opts: AgentChatMessage): string {\n const tabId = opts.tabId ?? generateTabId();\n const isCodeRequest = opts.type === \"code\" || opts.requiresCode === true;\n const localChatTarget = opts.chatTarget === \"local\";\n const requestMode =\n normalizeAgentChatRequestMode(opts.requestMode ?? opts.mode) ??\n readStoredAgentChatRequestMode();\n if (isCodeRequest && isInBuilderFrame()) {\n sendToBuilderChat({\n message: opts.message,\n context: opts.context,\n submit: opts.submit,\n ...(requestMode ? { mode: requestMode, requestMode } : {}),\n });\n return tabId;\n }\n\n const submitMessageId = generateSubmitMessageId();\n const payload = {\n type: AGENT_CHAT_MESSAGE_TYPE,\n data: {\n ...opts,\n tabId,\n submitMessageId,\n ...(requestMode ? { mode: requestMode, requestMode } : {}),\n },\n };\n\n if (\n opts.submit !== false &&\n !localChatTarget &&\n isMcpAppChatBridgeEnabled()\n ) {\n const directHostMessage = sendMcpAppHostMessage({\n message: opts.message,\n context: opts.context,\n ...(requestMode ? { mode: requestMode, requestMode } : {}),\n });\n if (directHostMessage) {\n void Promise.resolve(directHostMessage)\n .then((ok) => {\n if (!ok) {\n window.parent.postMessage(\n payload,\n getFramePostMessageTargetOrigin() || \"*\",\n );\n }\n })\n .finally(() => {\n dispatchAgentChatRunning(false);\n });\n return tabId;\n }\n window.parent.postMessage(\n payload,\n getFramePostMessageTargetOrigin() || \"*\",\n );\n return tabId;\n }\n\n const shouldOpenSidebar = opts.openSidebar !== false && !opts.background;\n\n const targetSelf =\n !isCodeRequest &&\n (localChatTarget || isInBuilderFrame() || isDirectMcpAppEmbedSession());\n const target = targetSelf\n ? window\n : window.parent !== window\n ? window.parent\n : window;\n const targetOrigin = targetSelf\n ? window.location.origin\n : getFramePostMessageTargetOrigin() || window.location.origin;\n if (shouldOpenSidebar) {\n window.dispatchEvent(\n new CustomEvent(\"agent-panel:set-mode\", {\n detail: { mode: \"chat\" },\n }),\n );\n window.dispatchEvent(new CustomEvent(\"agent-panel:open\"));\n } else if (!isCodeRequest) {\n window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));\n }\n\n const postToTarget = () => target.postMessage(payload, targetOrigin);\n\n // Same-window: defer one tick so a sidebar mounting now can attach its\n // listener, and buffer the submit so the lazy panel can replay it if it\n // mounts later. The live post and the replay dedup by submitMessageId.\n if (!isCodeRequest && target === window) {\n bufferSelfSubmit(payload.data);\n setTimeout(postToTarget, 0);\n } else {\n postToTarget();\n }\n return tabId;\n}\n\n/**\n * Add or replace a keyed context nugget in the active agent chat composer.\n * The context is not submitted until the user sends the prompt.\n */\nexport function setAgentChatContextItem(\n opts: AgentChatContextSetOptions,\n): void {\n const item = normalizeAgentChatContextItem(opts);\n if (!item || typeof window === \"undefined\") return;\n\n publishAgentChatContextItems(\n withReplacedAgentChatContextItem(agentChatContextState.items, item),\n );\n // Forward an explicit `focus: false` so the receiving composer can stage the\n // chip without stealing focus. Focus stays enabled by default (field omitted)\n // for every existing caller.\n const messageData = opts.focus === false ? { ...item, focus: false } : item;\n postAgentChatContextMessage(\n AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE,\n messageData,\n {\n openSidebar: opts.openSidebar !== false,\n },\n );\n}\n\n/** @deprecated Use `setAgentChatContextItem` instead. */\nexport const setContextToAgentChat = setAgentChatContextItem;\n\n/** @deprecated Use `setAgentChatContextItem` instead. */\nexport const addContextToAgentChat = setAgentChatContextItem;\n\nexport function insertAgentComposerReference(\n ref: AgentComposerReference,\n options: AgentComposerReferenceInsertOptions = {},\n): void {\n const normalized = normalizeAgentComposerReference(ref);\n if (!normalized || typeof window === \"undefined\") return;\n postAgentChatReferenceMessage(\n {\n ...normalized,\n insertMessageId: `reference-${Date.now()}-${Math.random()\n .toString(36)\n .slice(2, 8)}`,\n },\n { openSidebar: options.openSidebar === true },\n );\n}\n\nexport function removeAgentChatContextItem(\n keyOrOpts: string | AgentChatContextRemoveOptions,\n): void {\n const key =\n typeof keyOrOpts === \"string\" ? keyOrOpts.trim() : keyOrOpts.key.trim();\n if (!key || typeof window === \"undefined\") return;\n const openSidebar =\n typeof keyOrOpts === \"string\" ? false : keyOrOpts.openSidebar === true;\n\n publishAgentChatContextItems(\n agentChatContextState.items.filter((item) => item.key !== key),\n );\n postAgentChatContextMessage(\n AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE,\n { key },\n { openSidebar },\n );\n}\n\nexport function clearAgentChatContext(\n opts: AgentChatContextMutationOptions = {},\n): void {\n if (typeof window === \"undefined\") return;\n publishAgentChatContextItems([]);\n postAgentChatContextMessage(\n AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE,\n {},\n { openSidebar: opts.openSidebar === true },\n );\n}\n\nexport function _resetAgentChatContextForTests(): void {\n agentChatContextState = { items: [], updatedAt: 0 };\n notifyAgentChatContextListeners();\n}\n"]}
@@ -140,11 +140,11 @@ function PositionedDiagram({ data, compact, markerId, direction, }) {
140
140
  const to = nodeByIdForDirection.get(edge.to);
141
141
  if (!edge.label || !from || !to)
142
142
  return null;
143
- return (_jsx("span", { className: "absolute z-10 max-w-[130px] -translate-x-1/2 -translate-y-1/2 rounded-full border border-border bg-background px-2 py-0.5 text-center text-[11px] font-semibold text-muted-foreground shadow-sm", style: {
143
+ return (_jsx("span", { className: "absolute z-10 max-w-[130px] -translate-x-1/2 -translate-y-1/2 break-words rounded-full border border-border bg-background px-2 py-0.5 text-center text-[11px] font-semibold text-muted-foreground shadow-sm [overflow-wrap:anywhere]", style: {
144
144
  left: `${(from.displayX + to.displayX) / 2}%`,
145
145
  top: `${(from.displayY + to.displayY) / 2}%`,
146
146
  }, children: edge.label }, `${edge.from}-${edge.to}-${index}-label`));
147
- }), displayNodesForDirection.map((node, index) => (_jsxs("article", { className: "absolute z-20 -translate-x-1/2 -translate-y-1/2 rounded-xl border-2 border-border bg-background p-3 text-foreground shadow-sm", style: {
147
+ }), displayNodesForDirection.map((node, index) => (_jsxs("article", { className: "absolute z-20 -translate-x-1/2 -translate-y-1/2 break-words rounded-xl border-2 border-border bg-background p-3 text-foreground shadow-sm [overflow-wrap:anywhere]", style: {
148
148
  left: `${node.displayX}%`,
149
149
  top: `${node.displayY}%`,
150
150
  width: nodeWidth,
@@ -216,7 +216,7 @@ function SequenceDiagram({ data, compact, direction, }) {
216
216
  ? edges.find((candidate) => (candidate.from === node.id && candidate.to === next.id) ||
217
217
  (candidate.from === next.id && candidate.to === node.id))
218
218
  : undefined;
219
- return (_jsxs("div", { className: "flex min-w-max items-center gap-3", children: [_jsxs("article", { className: cn("w-[180px] rounded-xl border-2 border-border bg-background p-3 text-foreground", compact && "w-[150px]"), children: [_jsx("p", { className: "text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground", children: index + 1 }), _jsx("h3", { className: "mt-2 text-base font-semibold leading-tight", children: node.label }), node.detail && !compact && (_jsx("p", { className: "mt-2 text-xs leading-5 text-muted-foreground", children: node.detail }))] }), next && (_jsxs("div", { className: "grid min-w-[72px] justify-items-center gap-1 text-muted-foreground", children: [edge?.label && (_jsx("span", { className: "max-w-[96px] truncate rounded-full border border-border px-2 py-0.5 text-[11px] font-semibold", children: edge.label })), _jsx("span", { className: "h-0.5 w-full rounded-full border-t-2 border-dashed border-border" })] }))] }, node.id));
219
+ return (_jsxs("div", { className: "flex min-w-max items-center gap-3", children: [_jsxs("article", { className: cn("w-[180px] rounded-xl border-2 border-border bg-background p-3 text-foreground", compact && "w-[150px]"), children: [_jsx("p", { className: "text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground", children: index + 1 }), _jsx("h3", { className: "mt-2 text-base font-semibold leading-tight", children: node.label }), node.detail && !compact && (_jsx("p", { className: "mt-2 text-xs leading-5 text-muted-foreground", children: node.detail }))] }), next && (_jsxs("div", { className: "grid min-w-[72px] justify-items-center gap-1 text-muted-foreground", children: [edge?.label && (_jsx("span", { className: "max-w-[96px] whitespace-normal break-words rounded-full border border-border px-2 py-0.5 text-center text-[11px] font-semibold [overflow-wrap:anywhere]", children: edge.label })), _jsx("span", { className: "h-0.5 w-full rounded-full border-t-2 border-dashed border-border" })] }))] }, node.id));
220
220
  }) }), data.notes && data.notes.length > 0 && !compact && (_jsx("div", { className: "mt-4 grid gap-2 border-t border-border pt-4 text-sm text-muted-foreground md:grid-cols-2", children: data.notes.map((note) => (_jsx("p", { children: note.text }, note.id))) }))] }));
221
221
  }
222
222
  /**