@agent-native/core 0.12.1 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +9 -0
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/agent-chat.d.ts.map +1 -1
- package/dist/client/agent-chat.js +3 -0
- package/dist/client/agent-chat.js.map +1 -1
- package/dist/client/use-agent-chat.d.ts +1 -1
- package/dist/client/use-agent-chat.js +3 -3
- package/dist/client/use-agent-chat.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-chat.d.ts","sourceRoot":"","sources":["../../src/client/agent-chat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,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,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,wDAAwD;IACxD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;O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;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAyC9D"}
|
|
@@ -67,6 +67,9 @@ export function sendToAgentChat(opts) {
|
|
|
67
67
|
// listens for this event; the parent-frame case is handled by whoever
|
|
68
68
|
// owns that sidebar receiving the postMessage above.
|
|
69
69
|
if (opts.openSidebar !== false && !opts.background) {
|
|
70
|
+
window.dispatchEvent(new CustomEvent("agent-panel:set-mode", {
|
|
71
|
+
detail: { mode: "chat" },
|
|
72
|
+
}));
|
|
70
73
|
window.dispatchEvent(new CustomEvent("agent-panel:open"));
|
|
71
74
|
}
|
|
72
75
|
return tabId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-chat.js","sourceRoot":"","sources":["../../src/client/agent-chat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAqD5B,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;AAEzD;;;GAGG;AACH,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;QAC3C,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,EAAE,CAAC;YACrE,OAAO;QACT,CAAC;QACD,IACE,KAAK,CAAC,IAAI,EAAE,IAAI,KAAK,yBAAyB;YAC9C,KAAK,CAAC,IAAI,EAAE,IAAI,KAAK,qBAAqB,EAC1C,CAAC;YACD,MAAM,CAAC,aAAa,CAClB,IAAI,WAAW,CAAC,yBAAyB,EAAE;gBACzC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI;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;IAC/C,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAE1C,yEAAyE;IACzE,qEAAqE;IACrE,sEAAsE;IACtE,qDAAqD;IACrD,IAAI,IAAI,CAAC,WAAW,KAAK,KAAK,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QACnD,MAAM,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,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 { getFrameOrigin, isTrustedFrameMessage } from \"./frame.js\";\nimport {\n isInBuilderFrame,\n isTrustedBuilderMessage,\n sendToBuilderChat,\n} from \"./builder-frame.js\";\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 /** 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 (local dev frame 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 /** 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\nconst AGENT_CHAT_MESSAGE_TYPE = \"agentNative.submitChat\";\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/**\n * Send a message to the agent chat via postMessage.\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 if (isCodeRequest && isInBuilderFrame()) {\n sendToBuilderChat({\n message: opts.message,\n context: opts.context,\n submit: opts.submit,\n });\n return tabId;\n }\n\n const payload = {\n type: AGENT_CHAT_MESSAGE_TYPE,\n data: { ...opts, tabId },\n };\n\n const targetSelf = !isCodeRequest && isInBuilderFrame();\n const target = targetSelf\n ? window\n : window.parent !== window\n ? window.parent\n : window;\n const targetOrigin = targetSelf\n ? window.location.origin\n : getFrameOrigin() || window.location.origin;\n target.postMessage(payload, targetOrigin);\n\n // Surface the sidebar so the user sees the response. Callers can opt out\n // via `openSidebar: false` for background/silent sends. AgentSidebar\n // listens for this event; the parent-frame case is handled by whoever\n // owns that sidebar receiving the postMessage above.\n if (opts.openSidebar !== false && !opts.background) {\n window.dispatchEvent(new CustomEvent(\"agent-panel:open\"));\n }\n return tabId;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agent-chat.js","sourceRoot":"","sources":["../../src/client/agent-chat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAqD5B,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;AAEzD;;;GAGG;AACH,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;QAC3C,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,EAAE,CAAC;YACrE,OAAO;QACT,CAAC;QACD,IACE,KAAK,CAAC,IAAI,EAAE,IAAI,KAAK,yBAAyB;YAC9C,KAAK,CAAC,IAAI,EAAE,IAAI,KAAK,qBAAqB,EAC1C,CAAC;YACD,MAAM,CAAC,aAAa,CAClB,IAAI,WAAW,CAAC,yBAAyB,EAAE;gBACzC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI;aAC7C,CAAC,CACH,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,+BAA+B;AAC/B,MAAM,UAAU,aAAa;IAC3B,OAAO,QAAQ,IAAI,CAAC,GAAG,EA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W,KAAK,KAAK,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QACnD,MAAM,CAAC,aAAa,CAClB,IAAI,WAAW,CAAC,sBAAsB,EAAE;YACtC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;SACzB,CAAC,CACH,CAAC;QACF,MAAM,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,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 { getFrameOrigin, isTrustedFrameMessage } from \"./frame.js\";\nimport {\n isInBuilderFrame,\n isTrustedBuilderMessage,\n sendToBuilderChat,\n} from \"./builder-frame.js\";\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 /** 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 (local dev frame 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 /** 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\nconst AGENT_CHAT_MESSAGE_TYPE = \"agentNative.submitChat\";\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/**\n * Send a message to the agent chat via postMessage.\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 if (isCodeRequest && isInBuilderFrame()) {\n sendToBuilderChat({\n message: opts.message,\n context: opts.context,\n submit: opts.submit,\n });\n return tabId;\n }\n\n const payload = {\n type: AGENT_CHAT_MESSAGE_TYPE,\n data: { ...opts, tabId },\n };\n\n const targetSelf = !isCodeRequest && isInBuilderFrame();\n const target = targetSelf\n ? window\n : window.parent !== window\n ? window.parent\n : window;\n const targetOrigin = targetSelf\n ? window.location.origin\n : getFrameOrigin() || window.location.origin;\n target.postMessage(payload, targetOrigin);\n\n // Surface the sidebar so the user sees the response. Callers can opt out\n // via `openSidebar: false` for background/silent sends. AgentSidebar\n // listens for this event; the parent-frame case is handled by whoever\n // owns that sidebar receiving the postMessage above.\n if (opts.openSidebar !== false && !opts.background) {\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 }\n return tabId;\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import { type AgentChatMessage } from "./agent-chat.js";
|
|
|
4
4
|
*
|
|
5
5
|
* Returns [isGenerating, send] where:
|
|
6
6
|
* - isGenerating: true after send() is called, false when the
|
|
7
|
-
*
|
|
7
|
+
* agentNative.chatRunning event reports that the run has stopped
|
|
8
8
|
* - send: wrapper around sendToAgentChat that sets isGenerating to true
|
|
9
9
|
*/
|
|
10
10
|
export declare function useAgentChatGenerating(): [
|
|
@@ -5,7 +5,7 @@ import { sendToAgentChat } from "./agent-chat.js";
|
|
|
5
5
|
*
|
|
6
6
|
* Returns [isGenerating, send] where:
|
|
7
7
|
* - isGenerating: true after send() is called, false when the
|
|
8
|
-
*
|
|
8
|
+
* agentNative.chatRunning event reports that the run has stopped
|
|
9
9
|
* - send: wrapper around sendToAgentChat that sets isGenerating to true
|
|
10
10
|
*/
|
|
11
11
|
export function useAgentChatGenerating() {
|
|
@@ -13,8 +13,8 @@ export function useAgentChatGenerating() {
|
|
|
13
13
|
useEffect(() => {
|
|
14
14
|
const handler = (e) => {
|
|
15
15
|
const detail = e.detail;
|
|
16
|
-
if (detail?.isRunning ===
|
|
17
|
-
setIsGenerating(
|
|
16
|
+
if (typeof detail?.isRunning === "boolean") {
|
|
17
|
+
setIsGenerating(detail.isRunning);
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
window.addEventListener("agentNative.chatRunning", handler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-agent-chat.js","sourceRoot":"","sources":["../../src/client/use-agent-chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,eAAe,EAAyB,MAAM,iBAAiB,CAAC;AAEzE;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB;IAIpC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAExD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,CAAC,CAAQ,EAAE,EAAE;YAC3B,MAAM,MAAM,GAAI,CAAiB,CAAC,MAAM,CAAC;YACzC,IAAI,MAAM,EAAE,SAAS,KAAK,
|
|
1
|
+
{"version":3,"file":"use-agent-chat.js","sourceRoot":"","sources":["../../src/client/use-agent-chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,eAAe,EAAyB,MAAM,iBAAiB,CAAC;AAEzE;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB;IAIpC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAExD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,CAAC,CAAQ,EAAE,EAAE;YAC3B,MAAM,MAAM,GAAI,CAAiB,CAAC,MAAM,CAAC;YACzC,IAAI,OAAO,MAAM,EAAE,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC3C,eAAe,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACpC,CAAC;QACH,CAAC,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,yBAAyB,EAAE,OAAO,CAAC,CAAC;QAC5D,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,yBAAyB,EAAE,OAAO,CAAC,CAAC;IAC9E,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,IAAI,GAAG,WAAW,CAAC,CAAC,IAAsB,EAAU,EAAE;QAC1D,eAAe,CAAC,IAAI,CAAC,CAAC;QACtB,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import { useState, useEffect, useCallback } from \"react\";\nimport { sendToAgentChat, type AgentChatMessage } from \"./agent-chat.js\";\n\n/**\n * Hook that wraps sendToAgentChat with a loading state.\n *\n * Returns [isGenerating, send] where:\n * - isGenerating: true after send() is called, false when the\n * agentNative.chatRunning event reports that the run has stopped\n * - send: wrapper around sendToAgentChat that sets isGenerating to true\n */\nexport function useAgentChatGenerating(): [\n boolean,\n (opts: AgentChatMessage) => string,\n] {\n const [isGenerating, setIsGenerating] = useState(false);\n\n useEffect(() => {\n const handler = (e: Event) => {\n const detail = (e as CustomEvent).detail;\n if (typeof detail?.isRunning === \"boolean\") {\n setIsGenerating(detail.isRunning);\n }\n };\n window.addEventListener(\"agentNative.chatRunning\", handler);\n return () => window.removeEventListener(\"agentNative.chatRunning\", handler);\n }, []);\n\n const send = useCallback((opts: AgentChatMessage): string => {\n setIsGenerating(true);\n return sendToAgentChat(opts);\n }, []);\n\n return [isGenerating, send];\n}\n"]}
|