@agent-native/core 0.58.4 → 0.59.0

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.
@@ -109,6 +109,12 @@ export declare const AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE = "agentNative.remov
109
109
  export declare const AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE = "agentNative.clearChatContext";
110
110
  /** Generate a unique tab ID */
111
111
  export declare function generateTabId(): string;
112
+ /** Unclaimed self-submit payloads, for the panel to replay once it mounts. */
113
+ export declare function drainBufferedAgentChatSubmits(): Array<Record<string, unknown>>;
114
+ /** Claim a submit; false if already handled. Idless submits always pass. */
115
+ export declare function claimAgentChatSubmit(id: string | undefined): boolean;
116
+ /** Test-only: reset the self-submit buffer and claim set. */
117
+ export declare function _resetAgentChatSubmitBufferForTests(): void;
112
118
  export declare function normalizeAgentChatContextItem(item: unknown): AgentChatContextItem | null;
113
119
  export declare function normalizeAgentChatContextItems(items: unknown): AgentChatContextItem[];
114
120
  export declare function publishAgentChatContextItems(items: readonly AgentChatContextItem[], options?: {
@@ -121,6 +127,28 @@ export declare function subscribeAgentChatContext(listener: () => void): () => v
121
127
  export declare function refreshAgentChatContext(): Promise<AgentChatContextState>;
122
128
  export declare function formatAgentChatContextItemsForPrompt(items: readonly AgentChatContextItem[]): string;
123
129
  export declare function appendAgentChatContextToMessage(message: string, context: string): string;
130
+ /** A normalized `agentNative.submitChat` payload — decode via {@link parseSubmitChatMessage}. */
131
+ export interface ParsedSubmitChat {
132
+ /** Visible prompt text (non-empty). */
133
+ message: string;
134
+ context?: string;
135
+ /** Submit (true) or prefill only (false); defaults to true. */
136
+ submit: boolean;
137
+ openSidebar?: boolean;
138
+ model?: string;
139
+ /** Raw effort hint; the receiver validates it against the model. */
140
+ effort?: unknown;
141
+ newTab?: boolean;
142
+ background?: boolean;
143
+ tabId?: string;
144
+ images?: string[];
145
+ /** Mode as sent; the receiver falls back to its exec mode when undefined. */
146
+ requestMode?: AgentChatRequestMode;
147
+ /** Id used to dedup the live post against a cold-start replay. */
148
+ submitMessageId?: string;
149
+ }
150
+ /** Decode a `message` event into a submit payload, or null if it isn't one / has no text. */
151
+ export declare function parseSubmitChatMessage(event: MessageEvent): ParsedSubmitChat | null;
124
152
  /**
125
153
  * Send a message to the agent chat via postMessage.
126
154
  * Returns the stable tabId for tracking this chat run.
@@ -1 +1 @@
1
- {"version":3,"file":"agent-chat.d.ts","sourceRoot":"","sources":["../../src/client/agent-chat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAerE,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,eA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G,MAAM,CA0F9D;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,0BAA0B,GAC/B,IAAI,CAUN;AAED,yDAAyD;AACzD,eAAO,MAAM,qBAAqB,gCAA0B,CAAC;AAE7D,yDAAyD;AACzD,eAAO,MAAM,qBAAqB,gCAA0B,CAAC;AAE7D,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"}
@@ -45,6 +45,51 @@ if (typeof window !== "undefined") {
45
45
  export function generateTabId() {
46
46
  return `chat-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
47
47
  }
48
+ /** Unique id for one submitted message, used to dedup live + replayed sends. */
49
+ function generateSubmitMessageId() {
50
+ return `submit-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
51
+ }
52
+ const SELF_SUBMIT_BUFFER_TTL_MS = 8000;
53
+ const bufferedSelfSubmits = [];
54
+ const claimedSubmitIds = new Set();
55
+ function pruneSelfSubmitBuffer(now) {
56
+ for (let i = bufferedSelfSubmits.length - 1; i >= 0; i -= 1) {
57
+ if (now - bufferedSelfSubmits[i].at > SELF_SUBMIT_BUFFER_TTL_MS) {
58
+ const [removed] = bufferedSelfSubmits.splice(i, 1);
59
+ if (removed)
60
+ claimedSubmitIds.delete(removed.id);
61
+ }
62
+ }
63
+ }
64
+ function bufferSelfSubmit(data) {
65
+ const id = typeof data.submitMessageId === "string" ? data.submitMessageId : undefined;
66
+ if (!id)
67
+ return;
68
+ const now = Date.now();
69
+ pruneSelfSubmitBuffer(now);
70
+ bufferedSelfSubmits.push({ id, data, at: now });
71
+ }
72
+ /** Unclaimed self-submit payloads, for the panel to replay once it mounts. */
73
+ export function drainBufferedAgentChatSubmits() {
74
+ pruneSelfSubmitBuffer(Date.now());
75
+ return bufferedSelfSubmits
76
+ .filter((entry) => !claimedSubmitIds.has(entry.id))
77
+ .map((entry) => entry.data);
78
+ }
79
+ /** Claim a submit; false if already handled. Idless submits always pass. */
80
+ export function claimAgentChatSubmit(id) {
81
+ if (!id)
82
+ return true;
83
+ if (claimedSubmitIds.has(id))
84
+ return false;
85
+ claimedSubmitIds.add(id);
86
+ return true;
87
+ }
88
+ /** Test-only: reset the self-submit buffer and claim set. */
89
+ export function _resetAgentChatSubmitBufferForTests() {
90
+ bufferedSelfSubmits.length = 0;
91
+ claimedSubmitIds.clear();
92
+ }
48
93
  export function normalizeAgentChatContextItem(item) {
49
94
  if (typeof item !== "object" || item === null)
50
95
  return null;
@@ -231,6 +276,39 @@ function dispatchAgentChatRunning(isRunning) {
231
276
  function normalizeAgentChatRequestMode(value) {
232
277
  return value === "act" || value === "plan" ? value : undefined;
233
278
  }
279
+ /** Decode a `message` event into a submit payload, or null if it isn't one / has no text. */
280
+ export function parseSubmitChatMessage(event) {
281
+ const envelope = event.data && typeof event.data === "object"
282
+ ? event.data
283
+ : null;
284
+ if (!envelope || envelope.type !== AGENT_CHAT_MESSAGE_TYPE)
285
+ return null;
286
+ const raw = envelope.data && typeof envelope.data === "object"
287
+ ? envelope.data
288
+ : null;
289
+ if (!raw)
290
+ return null;
291
+ const message = typeof raw.message === "string" ? raw.message : "";
292
+ if (!message)
293
+ return null;
294
+ const images = Array.isArray(raw.images)
295
+ ? raw.images.filter((image) => typeof image === "string" && image.length > 0)
296
+ : undefined;
297
+ return {
298
+ message,
299
+ context: typeof raw.context === "string" ? raw.context : undefined,
300
+ submit: raw.submit !== false,
301
+ openSidebar: typeof raw.openSidebar === "boolean" ? raw.openSidebar : undefined,
302
+ model: typeof raw.model === "string" ? raw.model : undefined,
303
+ effort: raw.effort,
304
+ newTab: typeof raw.newTab === "boolean" ? raw.newTab : undefined,
305
+ background: typeof raw.background === "boolean" ? raw.background : undefined,
306
+ tabId: typeof raw.tabId === "string" ? raw.tabId : undefined,
307
+ images,
308
+ requestMode: normalizeAgentChatRequestMode(raw.requestMode ?? raw.mode),
309
+ submitMessageId: typeof raw.submitMessageId === "string" ? raw.submitMessageId : undefined,
310
+ };
311
+ }
234
312
  function normalizeStoredAgentChatExecMode(value) {
235
313
  if (value === "plan")
236
314
  return "plan";
@@ -279,11 +357,13 @@ export function sendToAgentChat(opts) {
279
357
  });
280
358
  return tabId;
281
359
  }
360
+ const submitMessageId = generateSubmitMessageId();
282
361
  const payload = {
283
362
  type: AGENT_CHAT_MESSAGE_TYPE,
284
363
  data: {
285
364
  ...opts,
286
365
  tabId,
366
+ submitMessageId,
287
367
  ...(requestMode ? { mode: requestMode, requestMode } : {}),
288
368
  },
289
369
  };
@@ -328,10 +408,11 @@ export function sendToAgentChat(opts) {
328
408
  window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));
329
409
  }
330
410
  const postToTarget = () => target.postMessage(payload, targetOrigin);
331
- // When the local app owns the chat surface, opening/preparing the sidebar
332
- // may mount the MessageEvent listener that receives this payload. Defer the
333
- // post one tick so a closed sidebar cannot drop the prompt while mounting.
411
+ // Same-window: defer one tick so a sidebar mounting now can attach its
412
+ // listener, and buffer the submit so the lazy panel can replay it if it
413
+ // mounts later. The live post and the replay dedup by submitMessageId.
334
414
  if (!isCodeRequest && target === window) {
415
+ bufferSelfSubmit(payload.data);
335
416
  setTimeout(postToTarget, 0);
336
417
  }
337
418
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"agent-chat.js","sourceRoot":"","sources":["../../src/client/agent-chat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,+BAA+B,EAC/B,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,4BAA4B,EAC5B,iCAAiC,GAClC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EACL,gB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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,OAAwC,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 {\n getFramePostMessageTargetOrigin,\n isTrustedFrameMessage,\n} from \"./frame.js\";\nimport type { ReasoningEffort } from \"../shared/reasoning-effort.js\";\nimport {\n isEmbedAuthActive,\n isEmbedMcpChatBridgeActive,\n markEmbedMcpChatBridgeActive,\n readEmbedMcpChatBridgeFlagFromUrl,\n} from \"./embed-auth.js\";\nimport { sendMcpAppHostMessage } from \"./mcp-app-host.js\";\nimport {\n isInBuilderFrame,\n isTrustedBuilderMessage,\n sendToBuilderChat,\n} from \"./builder-frame.js\";\nimport { agentNativePath } from \"./api-path.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 * 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 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\";\nconst AGENT_PANEL_PREPARE_EVENT = \"agent-panel:prepare\";\n\nlet agentChatContextState: AgentChatContextState = {\n items: [],\n updatedAt: 0,\n};\nconst agentChatContextListeners = new Set<() => void>();\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\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 for (const listener of agentChatContextListeners) listener();\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 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 payload = { type, data };\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 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\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 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 payload = {\n type: AGENT_CHAT_MESSAGE_TYPE,\n data: {\n ...opts,\n tabId,\n ...(requestMode ? { mode: requestMode, requestMode } : {}),\n },\n };\n\n if (opts.submit !== false && isMcpAppChatBridgeEnabled()) {\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 && (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 // When the local app owns the chat surface, opening/preparing the sidebar\n // may mount the MessageEvent listener that receives this payload. Defer the\n // post one tick so a closed sidebar cannot drop the prompt while mounting.\n if (!isCodeRequest && target === window) {\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 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
+ {"version":3,"file":"agent-chat.js","sourceRoot":"","sources":["../../src/client/agent-chat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,+BAA+B,EAC/B,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,4BAA4B,EAC5B,iCAAiC,GAClC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC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,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,OAAwC,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 {\n getFramePostMessageTargetOrigin,\n isTrustedFrameMessage,\n} from \"./frame.js\";\nimport type { ReasoningEffort } from \"../shared/reasoning-effort.js\";\nimport {\n isEmbedAuthActive,\n isEmbedMcpChatBridgeActive,\n markEmbedMcpChatBridgeActive,\n readEmbedMcpChatBridgeFlagFromUrl,\n} from \"./embed-auth.js\";\nimport { sendMcpAppHostMessage } from \"./mcp-app-host.js\";\nimport {\n isInBuilderFrame,\n isTrustedBuilderMessage,\n sendToBuilderChat,\n} from \"./builder-frame.js\";\nimport { agentNativePath } from \"./api-path.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 * 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 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\";\nconst AGENT_PANEL_PREPARE_EVENT = \"agent-panel:prepare\";\n\nlet agentChatContextState: AgentChatContextState = {\n items: [],\n updatedAt: 0,\n};\nconst agentChatContextListeners = new Set<() => void>();\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 for (const listener of agentChatContextListeners) listener();\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 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 payload = { type, data };\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 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 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 (opts.submit !== false && isMcpAppChatBridgeEnabled()) {\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 && (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 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"]}
@@ -18,9 +18,10 @@ export declare function BuilderConnectCta({ variant, onConnected, }: {
18
18
  export declare function ApiKeyConnect({ onConnected }: {
19
19
  onConnected?: () => void;
20
20
  }): import("react/jsx-runtime").JSX.Element;
21
- export declare function BuilderSetupCard({ onConnected, bouncePulse, }: {
21
+ export declare function BuilderSetupCard({ onConnected, bouncePulse, fullWidth, }: {
22
22
  onConnected?: () => void;
23
23
  bouncePulse?: number;
24
+ fullWidth?: boolean;
24
25
  }): import("react/jsx-runtime").JSX.Element;
25
26
  export declare function RunErrorRecoveryCard({ info, onContinue, onRetry, onFork, onDismiss, }: {
26
27
  info: RunErrorInfo;
@@ -1 +1 @@
1
- {"version":3,"file":"run-recovery.d.ts","sourceRoot":"","sources":["../../../src/client/chat/run-recovery.tsx"],"names":[],"mappings":"AAmCA,MAAM,MAAM,aAAa,GAAG;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAgBF,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CAc3E;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,GAAG,IAAI,CAgCzE;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,OAAO,GACf,KAAK,GAAG,MAAM,GAAG,IAAI,CASvB;AA4DD,wBAAgB,iBAAiB,CAAC,EAChC,OAAmB,EACnB,WAAW,GACZ,EAAE;IACD,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;CAC1B,2CAgGA;AAaD,wBAAgB,aAAa,CAAC,EAAE,WAAW,EAAE,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;CAAE,2CAoG1E;AAID,wBAAgB,gBAAgB,CAAC,EAC/B,WAAW,EACX,WAAW,GACZ,EAAE;IACD,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IAC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;IAC5B,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B,2CAyCA"}
@@ -165,7 +165,7 @@ export function ApiKeyConnect({ onConnected }) {
165
165
  }, className: "h-8 min-w-0 flex-1 rounded-md border border-input bg-background px-2.5 text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-1 focus:ring-offset-background" }), _jsx("button", { type: "button", onClick: handleSave, disabled: !apiKey.trim() || saving, className: "inline-flex h-8 shrink-0 items-center gap-1 rounded-md bg-foreground px-3 text-[11px] font-medium text-background hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-60", children: saving ? (_jsxs(_Fragment, { children: [_jsx(IconLoader2, { size: 11, className: "animate-spin" }), "Saving\u2026"] })) : ("Save") })] }), error ? (_jsx("p", { className: "mt-2 text-[11px] text-destructive", children: error })) : null] }));
166
166
  }
167
167
  // ─── BuilderSetupCard ─────────────────────────────────────────────────────────
168
- export function BuilderSetupCard({ onConnected, bouncePulse, }) {
168
+ export function BuilderSetupCard({ onConnected, bouncePulse, fullWidth, }) {
169
169
  // Progressive disclosure: the card leads with one-click Builder connect while
170
170
  // keeping the bring-your-own-key path close by.
171
171
  const [keyOpen, setKeyOpen] = useState(false);
@@ -183,7 +183,9 @@ export function BuilderSetupCard({ onConnected, bouncePulse, }) {
183
183
  void el.offsetWidth;
184
184
  el.classList.add("animate-bounce-once");
185
185
  }, [bouncePulse]);
186
- return (_jsx("div", { ref: cardRef, className: "mx-auto w-full max-w-[42rem] px-3 pb-2 sm:w-fit", children: _jsxs("div", { className: "rounded-lg border border-border/80 bg-background/80 p-3 shadow-sm backdrop-blur", children: [_jsxs("div", { className: "flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("h3", { className: "text-[13px] font-medium text-foreground", children: "Connect AI" }), _jsx("p", { className: "mt-0.5 text-[11px] leading-relaxed text-muted-foreground", children: "Use Builder.io (free credits), or add an Anthropic/OpenAI key." })] }), _jsxs("div", { className: "flex shrink-0 flex-nowrap items-center gap-2", children: [_jsx(BuilderConnectCta, { variant: "compact", onConnected: onConnected }), _jsx("button", { type: "button", onClick: () => setKeyOpen((open) => !open), className: "inline-flex h-8 shrink-0 items-center whitespace-nowrap rounded-md border border-border bg-background px-3 text-[11px] font-medium text-foreground hover:bg-accent", "aria-expanded": keyOpen, children: "Use API key" })] })] }), keyOpen ? (_jsx("div", { className: "mt-3", children: _jsx(ApiKeyConnect, { onConnected: onConnected }) })) : null] }) }));
186
+ return (_jsx("div", { ref: cardRef, className: fullWidth
187
+ ? "w-full pb-2"
188
+ : "mx-auto w-full max-w-[42rem] px-3 pb-2 sm:w-fit", children: _jsxs("div", { className: "rounded-lg border border-border/80 bg-background/80 p-3 shadow-sm backdrop-blur", children: [_jsxs("div", { className: "flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("h3", { className: "text-[13px] font-medium text-foreground", children: "Connect AI" }), _jsx("p", { className: "mt-0.5 text-[11px] leading-relaxed text-muted-foreground", children: "Use Builder.io (free credits), or add an Anthropic/OpenAI key." })] }), _jsxs("div", { className: "flex shrink-0 flex-nowrap items-center gap-2", children: [_jsx(BuilderConnectCta, { variant: "compact", onConnected: onConnected }), _jsx("button", { type: "button", onClick: () => setKeyOpen((open) => !open), className: "inline-flex h-8 shrink-0 items-center whitespace-nowrap rounded-md border border-border bg-background px-3 text-[11px] font-medium text-foreground hover:bg-accent", "aria-expanded": keyOpen, children: "Use API key" })] })] }), keyOpen ? (_jsx("div", { className: "mt-3", children: _jsx(ApiKeyConnect, { onConnected: onConnected }) })) : null] }) }));
187
189
  }
188
190
  // ─── RunErrorRecoveryCard ─────────────────────────────────────────────────────
189
191
  export function RunErrorRecoveryCard({ info, onContinue, onRetry, onFork, onDismiss, }) {