@omni-commerce/sdk 0.12.0 → 0.17.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.
- package/README.md +108 -12
- package/dist/embed.cjs +7 -1
- package/dist/embed.cjs.map +1 -1
- package/dist/embed.d.cts +5 -0
- package/dist/embed.d.ts +5 -0
- package/dist/embed.global.js +4 -4
- package/dist/embed.global.js.map +1 -1
- package/dist/embed.js +7 -1
- package/dist/embed.js.map +1 -1
- package/dist/index.cjs +513 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5299 -2615
- package/dist/index.d.ts +5299 -2615
- package/dist/index.js +513 -27
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +34 -6
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +34 -6
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/react.cjs
CHANGED
|
@@ -50,6 +50,7 @@ function createApplicationMessageHandler(input) {
|
|
|
50
50
|
input.reply({
|
|
51
51
|
type: "omni-chat:application-response",
|
|
52
52
|
requestId: message.requestId,
|
|
53
|
+
...input.assistant ? { assistant: boundedJson(input.assistant(), 65536) } : {},
|
|
53
54
|
application: application ? boundedJson(
|
|
54
55
|
{
|
|
55
56
|
name: application.name,
|
|
@@ -151,6 +152,7 @@ function mountHostedChat(container, options, target) {
|
|
|
151
152
|
const controller = new AbortController();
|
|
152
153
|
const applicationMessage = createApplicationMessageHandler({
|
|
153
154
|
options,
|
|
155
|
+
assistant: target.assistant,
|
|
154
156
|
signal: controller.signal,
|
|
155
157
|
reply: (message) => {
|
|
156
158
|
if (!destroyed)
|
|
@@ -274,7 +276,11 @@ function createOmniApplicationChatEmbed(container, options) {
|
|
|
274
276
|
const chatId = host.crypto.randomUUID();
|
|
275
277
|
return mountHostedChat(container, options, {
|
|
276
278
|
url: getOmniApplicationChatUrl(options, host.location.origin, chatId),
|
|
277
|
-
scope: { chatId }
|
|
279
|
+
scope: { chatId },
|
|
280
|
+
assistant: () => ({
|
|
281
|
+
...options.systemPrompt !== void 0 ? { systemPrompt: options.systemPrompt } : {},
|
|
282
|
+
...options.tools !== void 0 ? { tools: options.tools } : {}
|
|
283
|
+
})
|
|
278
284
|
});
|
|
279
285
|
}
|
|
280
286
|
|
|
@@ -534,14 +540,16 @@ function OmniChat({
|
|
|
534
540
|
const frame = (0, import_react2.useRef)(null);
|
|
535
541
|
const { baseUrl, deploymentId, onError, application, frontendTools } = options;
|
|
536
542
|
const getSession = "getSession" in options ? options.getSession : void 0;
|
|
537
|
-
const { organizationId, agentId, appId } = options;
|
|
543
|
+
const { organizationId, agentId, appId, systemPrompt, tools } = options;
|
|
538
544
|
const requestClose = onRequestClose ?? closeLayout ?? options.onRequestClose;
|
|
539
545
|
const callbacks = (0, import_react2.useRef)({
|
|
540
546
|
getSession,
|
|
541
547
|
onError,
|
|
542
548
|
application,
|
|
543
549
|
frontendTools,
|
|
544
|
-
requestClose
|
|
550
|
+
requestClose,
|
|
551
|
+
systemPrompt,
|
|
552
|
+
tools
|
|
545
553
|
});
|
|
546
554
|
(0, import_react2.useEffect)(() => {
|
|
547
555
|
callbacks.current = {
|
|
@@ -549,9 +557,19 @@ function OmniChat({
|
|
|
549
557
|
onError,
|
|
550
558
|
application,
|
|
551
559
|
frontendTools,
|
|
552
|
-
requestClose
|
|
560
|
+
requestClose,
|
|
561
|
+
systemPrompt,
|
|
562
|
+
tools
|
|
553
563
|
};
|
|
554
|
-
}, [
|
|
564
|
+
}, [
|
|
565
|
+
getSession,
|
|
566
|
+
onError,
|
|
567
|
+
application,
|
|
568
|
+
frontendTools,
|
|
569
|
+
requestClose,
|
|
570
|
+
systemPrompt,
|
|
571
|
+
tools
|
|
572
|
+
]);
|
|
555
573
|
const hasSessionBroker = Boolean(getSession);
|
|
556
574
|
const frameTitle = title ?? options.title;
|
|
557
575
|
(0, import_react2.useEffect)(() => {
|
|
@@ -564,7 +582,17 @@ function OmniChat({
|
|
|
564
582
|
...deploymentId ? {
|
|
565
583
|
deploymentId,
|
|
566
584
|
getSession: hasSessionBroker ? () => callbacks.current.getSession() : void 0
|
|
567
|
-
} : {
|
|
585
|
+
} : {
|
|
586
|
+
organizationId,
|
|
587
|
+
agentId,
|
|
588
|
+
appId
|
|
589
|
+
},
|
|
590
|
+
get systemPrompt() {
|
|
591
|
+
return callbacks.current.systemPrompt;
|
|
592
|
+
},
|
|
593
|
+
get tools() {
|
|
594
|
+
return callbacks.current.tools;
|
|
595
|
+
},
|
|
568
596
|
get application() {
|
|
569
597
|
return callbacks.current.application;
|
|
570
598
|
},
|
package/dist/react.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react.tsx","../src/application.ts","../../../lib/assistant/application-chat/bridge-scope.ts","../src/hosted-chat.ts","../../../lib/assistant/hosted-chat-origin.ts","../src/chat-origin.ts","../src/application-embed.ts","../src/embed.ts","../src/chat-layout.tsx","../src/chat-layout-styles.ts"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n useContext,\n useEffect,\n useRef,\n type CSSProperties,\n type ReactNode,\n} from \"react\";\nimport { createOmniChatEmbed, type OmniChatEmbedOptions } from \"./embed\";\nimport {\n createOmniApplicationChatEmbed,\n type OmniApplicationChatOptions,\n} from \"./application-embed\";\nimport { ChatLayout, ChatLayoutCloseContext } from \"./chat-layout\";\n\ntype OmniChatOptions = OmniChatEmbedOptions | OmniApplicationChatOptions;\nconst OmniChatContext = createContext<OmniChatOptions | null>(null);\nexport type OmniProviderProps = OmniChatOptions & { children: ReactNode };\n\nexport function OmniProvider({ children, ...options }: OmniProviderProps) {\n return (\n <OmniChatContext.Provider value={options}>\n {children}\n </OmniChatContext.Provider>\n );\n}\nexport interface OmniChatProps {\n className?: string;\n style?: CSSProperties;\n title?: string;\n onRequestClose?: () => void;\n}\nexport interface OmniChatLayoutProps {\n children: ReactNode;\n className?: string;\n title?: string;\n}\n/** Full-height desktop docking; below 960px a launcher opens a full-height modal. */\nexport function OmniChatLayout({\n children,\n className,\n title,\n}: OmniChatLayoutProps) {\n return (\n <ChatLayout\n className={className}\n chat={<OmniChat title={title} style={{ minHeight: 0 }} />}\n >\n {children}\n </ChatLayout>\n );\n}\n/** The hosted assistant owns its styles and runtime, so the host needs no Tailwind or assistant-ui dependencies. */\nexport function OmniChat({\n className,\n style,\n title,\n onRequestClose,\n}: OmniChatProps) {\n const options = useContext(OmniChatContext);\n const closeLayout = useContext(ChatLayoutCloseContext);\n if (!options)\n throw new Error(\"OmniChat must be rendered inside OmniProvider.\");\n const container = useRef<HTMLDivElement>(null);\n const frame = useRef<HTMLIFrameElement | null>(null);\n const { baseUrl, deploymentId, onError, application, frontendTools } =\n options;\n const getSession = \"getSession\" in options ? options.getSession : undefined;\n const { organizationId, agentId, appId } =\n options as OmniApplicationChatOptions;\n const requestClose = onRequestClose ?? closeLayout ?? options.onRequestClose;\n const callbacks = useRef({\n getSession,\n onError,\n application,\n frontendTools,\n requestClose,\n });\n useEffect(() => {\n callbacks.current = {\n getSession,\n onError,\n application,\n frontendTools,\n requestClose,\n };\n }, [getSession, onError, application, frontendTools, requestClose]);\n const hasSessionBroker = Boolean(getSession);\n const frameTitle = title ?? options.title;\n useEffect(() => {\n if (!container.current) return;\n const hostedOptions = {\n baseUrl,\n onError: (error: Error) => callbacks.current.onError?.(error),\n onRequestClose: () => callbacks.current.requestClose?.(),\n title: frameTitle,\n ...(deploymentId\n ? {\n deploymentId,\n getSession: hasSessionBroker\n ? () => callbacks.current.getSession!()\n : undefined,\n }\n : { organizationId, agentId, appId }),\n get application() {\n return callbacks.current.application;\n },\n get frontendTools() {\n return callbacks.current.frontendTools;\n },\n };\n const embed =\n \"deploymentId\" in hostedOptions\n ? createOmniChatEmbed(container.current, hostedOptions)\n : createOmniApplicationChatEmbed(container.current, hostedOptions);\n frame.current = embed.iframe;\n return () => {\n frame.current = null;\n embed.destroy();\n };\n }, [\n baseUrl,\n deploymentId,\n organizationId,\n agentId,\n appId,\n frameTitle,\n hasSessionBroker,\n ]);\n useEffect(() => {\n // A bounded sidebar can override the inline default without replacing chat.\n const minimum = style?.minHeight ?? 320;\n if (frame.current)\n frame.current.style.minHeight =\n typeof minimum === \"number\" ? `${minimum}px` : minimum;\n });\n return (\n <div\n ref={container}\n className={className}\n style={{ height: \"100%\", minHeight: 320, ...style }}\n />\n );\n}\nexport type {\n OmniFrontendTool,\n OmniChatApplication,\n OmniApplicationOptions,\n OmniChatEmbedOptions,\n OmniChatSession,\n OmniApplicationChatOptions,\n} from \"./embed\";\n","/** Host-defined actions execute inside the application, never on the assistant server. */\nexport interface OmniFrontendTool {\n description: string;\n parameters: Record<string, unknown>;\n execute: (\n args: Record<string, unknown>,\n context: { toolCallId: string; abortSignal: AbortSignal },\n ) => unknown | Promise<unknown>;\n}\nexport interface OmniChatApplication {\n name: string;\n description: string;\n /** Return a small, explicitly selected snapshot. Do not include secrets. */\n getContext: () => unknown | Promise<unknown>;\n}\nexport interface OmniApplicationOptions {\n application?: OmniChatApplication;\n /** Names must start with app_; use array arguments for actions with multiple targets. */\n frontendTools?: Record<string, OmniFrontendTool>;\n}\n\nfunction boundedJson(value: unknown, maximum: number): unknown {\n const encoded = JSON.stringify(value);\n if (\n typeof encoded !== \"string\" ||\n new TextEncoder().encode(encoded).length > maximum ||\n /data:[^\"\\s]{0,100};base64,/i.test(encoded)\n )\n throw new Error(\n \"Application data must be bounded JSON without base64 payloads.\",\n );\n return JSON.parse(encoded);\n}\n\nexport function createApplicationMessageHandler(input: {\n options: OmniApplicationOptions;\n signal: AbortSignal;\n reply: (message: Record<string, unknown>) => void;\n}) {\n // A repeated parked call reuses its result instead of applying an action twice.\n const calls = new Map<\n string,\n { signature: string; result: Promise<unknown> }\n >();\n return async (message: Record<string, unknown>) => {\n if (typeof message.requestId !== \"string\" || message.requestId.length > 200)\n return;\n try {\n if (message.type === \"omni-chat:application-request\") {\n const application = input.options.application;\n input.reply({\n type: \"omni-chat:application-response\",\n requestId: message.requestId,\n application: application\n ? boundedJson(\n {\n name: application.name,\n description: application.description,\n context: (await application.getContext()) ?? null,\n tools: Object.entries(input.options.frontendTools ?? {}).map(\n ([name, definition]) => ({\n name,\n description: definition.description,\n parameters: definition.parameters,\n }),\n ),\n },\n 65536,\n )\n : undefined,\n });\n } else if (message.type === \"omni-chat:tool-request\") {\n const name = message.toolName;\n const toolCallId = message.toolCallId;\n if (\n typeof name !== \"string\" ||\n !/^app_[a-z][a-z0-9_]{0,59}$/.test(name) ||\n typeof toolCallId !== \"string\" ||\n !toolCallId ||\n toolCallId.length > 200\n )\n throw new Error(\"Invalid application tool request.\");\n const definition = Object.hasOwn(\n input.options.frontendTools ?? {},\n name,\n )\n ? input.options.frontendTools?.[name]\n : undefined;\n if (!input.options.application || !definition)\n throw new Error(\"This application action is unavailable.\");\n const args = message.args;\n if (!args || typeof args !== \"object\" || Array.isArray(args))\n throw new Error(\"Invalid application action arguments.\");\n const signature = JSON.stringify({ name, args });\n const prior = calls.get(toolCallId);\n if (prior && prior.signature !== signature)\n throw new Error(\"This tool call ID was already used.\");\n const result =\n prior?.result ??\n Promise.resolve().then(() =>\n definition.execute(args as Record<string, unknown>, {\n toolCallId,\n abortSignal: input.signal,\n }),\n );\n if (!prior) {\n if (calls.size >= 200)\n throw new Error(\"Start a new application chat.\");\n calls.set(toolCallId, { signature, result });\n }\n input.reply({\n type: \"omni-chat:tool-response\",\n requestId: message.requestId,\n toolCallId,\n result: boundedJson((await result) ?? null, 12000),\n });\n }\n } catch (error) {\n input.reply({\n type:\n message.type === \"omni-chat:application-request\"\n ? \"omni-chat:application-response\"\n : \"omni-chat:tool-response\",\n requestId: message.requestId,\n toolCallId: message.toolCallId,\n error:\n error instanceof Error\n ? error.message\n : \"The application action failed.\",\n });\n }\n };\n}\n","/** Scope each hosted frame independently; application chats have no deployment. */\nexport type HostedChatScope =\n | { deploymentId: string; chatId?: never }\n | { chatId: string; deploymentId?: never };\n\nexport function hostedChatId(scope: HostedChatScope) {\n return scope.deploymentId ?? scope.chatId;\n}\n\nexport function matchesHostedChatScope(\n message: Record<string, unknown> | null | undefined,\n scope: HostedChatScope,\n) {\n return scope.deploymentId !== undefined\n ? message?.deploymentId === scope.deploymentId &&\n message.chatId === undefined\n : message?.chatId === scope.chatId && message.deploymentId === undefined;\n}\n","import {\n createApplicationMessageHandler,\n type OmniApplicationOptions,\n} from \"./application\";\nimport {\n matchesHostedChatScope,\n type HostedChatScope,\n} from \"../../../lib/assistant/application-chat/bridge-scope\";\nimport type { OmniChatEmbed, OmniChatSession } from \"./embed\";\n\nexport interface OmniHostedChatOptions extends OmniApplicationOptions {\n baseUrl?: string;\n title?: string;\n onError?: (error: Error) => void;\n onRequestClose?: () => void;\n}\n\nexport class ChatSessionError extends Error {\n constructor(\n message: string,\n readonly status: number,\n ) {\n super(message);\n }\n}\n\n/** One frame broker for member application chat and published storefront chat. */\nexport function mountHostedChat(\n container: HTMLElement,\n options: OmniHostedChatOptions,\n target: {\n url: string;\n scope: HostedChatScope;\n mint?: (\n previousToken: string | undefined,\n visitorId: string | undefined,\n signal: AbortSignal,\n ) => Promise<OmniChatSession>;\n },\n): OmniChatEmbed {\n const document = container.ownerDocument;\n const host = document.defaultView;\n if (!host) throw new Error(\"A browser document is required to mount chat.\");\n const iframe = document.createElement(\"iframe\");\n iframe.src = target.url;\n iframe.title = options.title ?? \"OmniCommerce assistant\";\n iframe.referrerPolicy = \"strict-origin-when-cross-origin\";\n iframe.setAttribute(\n \"sandbox\",\n \"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox\",\n );\n Object.assign(iframe.style, {\n width: \"100%\",\n height: \"100%\",\n minHeight: \"320px\",\n border: \"0\",\n display: \"block\",\n });\n const chatOrigin = new URL(iframe.src).origin;\n let destroyed = false;\n let pending: Promise<OmniChatSession> | undefined;\n let previousToken: string | undefined;\n const controller = new AbortController();\n\n const applicationMessage = createApplicationMessageHandler({\n options,\n signal: controller.signal,\n reply: (message) => {\n if (!destroyed)\n iframe.contentWindow?.postMessage(\n { ...message, ...target.scope },\n chatOrigin,\n );\n },\n });\n const receive = (event: MessageEvent) => {\n if (\n destroyed ||\n event.source !== iframe.contentWindow ||\n event.origin !== chatOrigin ||\n !matchesHostedChatScope(event.data, target.scope)\n )\n return;\n if (\n event.data.type === \"omni-chat:application-request\" ||\n event.data.type === \"omni-chat:tool-request\"\n ) {\n void applicationMessage(event.data);\n return;\n }\n if (event.data.type === \"omni-chat:close-request\") {\n options.onRequestClose?.();\n return;\n }\n if (event.data.type !== \"omni-chat:session-request\" || !target.mint) return;\n const visitorId =\n typeof event.data.visitorId === \"string\"\n ? event.data.visitorId\n : undefined;\n pending ??= target.mint(previousToken, visitorId, controller.signal);\n void pending\n .then((session) => {\n if (destroyed) return;\n if (\n typeof session?.token !== \"string\" ||\n !session.token ||\n session.token.length > 4096 ||\n typeof session.threadId !== \"string\" ||\n !session.threadId ||\n !Number.isFinite(session.expiresIn) ||\n session.expiresIn <= 0\n )\n throw new Error(\"Invalid chat session response.\");\n previousToken = session.token;\n iframe.contentWindow?.postMessage(\n {\n type: \"omni-chat:session\",\n ...target.scope,\n session,\n ...(options.application ? { applicationEnabled: true } : {}),\n },\n chatOrigin,\n );\n })\n .catch((error: unknown) => {\n if (destroyed) return;\n const failure =\n error instanceof Error ? error : new Error(\"Could not open chat.\");\n if (\n failure instanceof ChatSessionError &&\n [401, 403].includes(failure.status)\n )\n previousToken = undefined;\n options.onError?.(failure);\n iframe.contentWindow?.postMessage(\n {\n type: \"omni-chat:session-error\",\n ...target.scope,\n error: failure.message,\n ...(options.application ? { applicationEnabled: true } : {}),\n },\n chatOrigin,\n );\n })\n .finally(() => {\n pending = undefined;\n });\n };\n host.addEventListener(\"message\", receive);\n container.append(iframe);\n return {\n iframe,\n focus() {\n if (destroyed) return;\n iframe.focus();\n iframe.contentWindow?.postMessage(\n {\n type: \"omni-chat:focus-composer\",\n ...target.scope,\n },\n chatOrigin,\n );\n },\n destroy() {\n if (destroyed) return;\n destroyed = true;\n controller.abort();\n previousToken = undefined;\n host.removeEventListener(\"message\", receive);\n iframe.remove();\n },\n };\n}\n","/** Exact hosted-chat origins, including trustworthy localhost development hosts. */\nexport function normalizeHostedChatOrigin(value: string): string {\n const url = new URL(value);\n const local =\n url.hostname === \"localhost\" ||\n url.hostname.endsWith(\".localhost\") ||\n url.hostname === \"127.0.0.1\";\n if (\n (url.protocol !== \"https:\" && !(url.protocol === \"http:\" && local)) ||\n url.username ||\n url.password ||\n url.pathname !== \"/\" ||\n url.search ||\n url.hash\n )\n throw new Error(\"Use an HTTPS origin, or HTTP localhost for development.\");\n return url.origin;\n}\n","import { normalizeHostedChatOrigin } from \"../../../lib/assistant/hosted-chat-origin\";\n\nexport function chatOrigin(baseUrl?: string): string {\n return normalizeHostedChatOrigin(baseUrl ?? \"https://omnicommerce.sg\");\n}\n","import { chatOrigin } from \"./chat-origin\";\nimport { mountHostedChat, type OmniHostedChatOptions } from \"./hosted-chat\";\n\n/** Application chat authenticates the viewer; it never uses a storefront deployment. */\nexport interface OmniApplicationChatOptions extends OmniHostedChatOptions {\n deploymentId?: never;\n /** Omit to use the member's currently selected organization. */\n organizationId?: string;\n /** Omit to use the default native assistant. */\n agentId?: string;\n /** Groups this application's conversation history; defaults to its origin. */\n appId?: string;\n}\n\nexport function getOmniApplicationChatUrl(\n options: OmniApplicationChatOptions,\n parentOrigin: string,\n chatId: string,\n) {\n if (\n !/^[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}$/i.test(chatId)\n )\n throw new Error(\"A valid application chat ID is required.\");\n const url = new URL(\"/sdk/application-chat\", chatOrigin(options.baseUrl));\n const parent = chatOrigin(parentOrigin);\n url.searchParams.set(\"parentOrigin\", parent);\n url.searchParams.set(\"chatId\", chatId);\n const appId = options.appId?.trim() ?? parent;\n if (!appId || appId.length > 200)\n throw new Error(\"appId must contain 1–200 characters.\");\n url.searchParams.set(\"appId\", appId);\n for (const key of [\"organizationId\", \"agentId\"] as const) {\n if (options[key] === undefined) continue;\n const value = options[key].trim();\n if (!value || value.length > 120)\n throw new Error(`${key} must contain 1–120 characters.`);\n url.searchParams.set(key, value);\n }\n return url.toString();\n}\n\nexport function createOmniApplicationChatEmbed(\n container: HTMLElement,\n options: OmniApplicationChatOptions,\n) {\n const host = container.ownerDocument.defaultView;\n if (!host) throw new Error(\"A browser document is required to mount chat.\");\n const chatId = host.crypto.randomUUID();\n return mountHostedChat(container, options, {\n url: getOmniApplicationChatUrl(options, host.location.origin, chatId),\n scope: { chatId },\n });\n}\n","import { mountHostedChat, ChatSessionError } from \"./hosted-chat\";\nimport { chatOrigin } from \"./chat-origin\";\nimport { type OmniApplicationOptions } from \"./application\";\nexport type {\n OmniFrontendTool,\n OmniChatApplication,\n OmniApplicationOptions,\n} from \"./application\";\n/** A hosted chat session. Keep its short-lived token in memory, never in iframe URLs. */\nexport {\n createOmniApplicationChatEmbed,\n getOmniApplicationChatUrl,\n type OmniApplicationChatOptions,\n} from \"./application-embed\";\nexport { createOmniChatWidget, type OmniChatWidgetOptions } from \"./widget\";\nexport {\n DEFAULT_WIDGET_OFFSET,\n MAX_WIDGET_OFFSET,\n type OmniChatWidgetPlacement,\n} from \"./widget-placement\";\nexport { getOmniChatEmbedCode, getOmniChatReactCode } from \"./embed-code\";\nexport interface OmniChatSession {\n token: string;\n threadId: string;\n expiresIn: number;\n}\nexport interface OmniChatEmbedOptions extends OmniApplicationOptions {\n deploymentId: string;\n baseUrl?: string;\n /** Optional authenticated session mint on the host application's server. */\n getSession?: () => Promise<OmniChatSession>;\n title?: string;\n onError?: (error: Error) => void;\n /** Floating widgets use this to close on Escape from the hosted chat. */\n onRequestClose?: () => void;\n}\nexport interface OmniChatEmbed {\n iframe: HTMLIFrameElement;\n /** Focus the hosted composer, including when reopening a retained chat. */\n focus(): void;\n destroy(): void;\n}\n\nexport function getOmniChatEmbedUrl(\n options: Pick<OmniChatEmbedOptions, \"baseUrl\" | \"deploymentId\">,\n parentOrigin?: string,\n): string {\n if (\n !/^[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}$/i.test(\n options.deploymentId,\n )\n )\n throw new Error(\"A valid chat deployment ID is required.\");\n const base = chatOrigin(options.baseUrl);\n const url = new URL(`/embed/${options.deploymentId}`, base);\n if (parentOrigin)\n url.searchParams.set(\"parentOrigin\", new URL(parentOrigin).origin);\n return url.toString();\n}\n\n/** Browser-only mounting; importing this entry point is safe during SSR. */\nexport function createOmniChatEmbed(\n container: HTMLElement,\n options: OmniChatEmbedOptions,\n): OmniChatEmbed {\n const host = container.ownerDocument.defaultView;\n if (!host) throw new Error(\"A browser document is required to mount chat.\");\n const url = getOmniChatEmbedUrl(options, host.location.origin);\n const chatOrigin = new URL(url).origin;\n return mountHostedChat(container, options, {\n url,\n scope: { deploymentId: options.deploymentId },\n mint: async (previousToken, visitorId, signal) => {\n if (options.getSession) return options.getSession();\n const response = await host.fetch(\n `${chatOrigin}/api/embed/${options.deploymentId}/session`,\n {\n method: \"POST\",\n credentials: \"include\",\n signal,\n headers: {\n \"Content-Type\": \"application/json\",\n ...(previousToken\n ? { Authorization: `Bearer ${previousToken}` }\n : {}),\n },\n body: JSON.stringify(\n visitorId &&\n /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(\n visitorId,\n )\n ? { visitorId }\n : {},\n ),\n },\n );\n const result = (await response.json()) as OmniChatSession & {\n error?: string;\n };\n if (!response.ok)\n throw new ChatSessionError(\n result.error ?? \"Could not open the chat session.\",\n response.status,\n );\n return result;\n },\n });\n}\n","\"use client\";\n\nimport {\n createContext,\n useEffect,\n useId,\n useRef,\n useState,\n type ReactNode,\n} from \"react\";\nimport { chatLayoutQuery, chatLayoutStyles } from \"./chat-layout-styles\";\n\nexport const ChatLayoutCloseContext = createContext<(() => void) | undefined>(\n undefined,\n);\n\n/** One mounted frame switches between an inline desktop panel and a native modal. */\nexport function ChatLayout({\n children,\n chat,\n className,\n}: {\n children: ReactNode;\n chat: ReactNode;\n className?: string;\n}) {\n const panel = useRef<HTMLDialogElement>(null);\n const launcher = useRef<HTMLButtonElement>(null);\n const restoreFocus = useRef(false);\n const [compact, setCompact] = useState<boolean | null>(null);\n const [open, setOpen] = useState(false);\n const id = useId();\n\n useEffect(() => {\n const media = window.matchMedia(chatLayoutQuery);\n const update = () => {\n setCompact(media.matches);\n // Entering the compact layout gives the application its space back.\n setOpen(false);\n };\n update();\n media.addEventListener(\"change\", update);\n return () => media.removeEventListener(\"change\", update);\n }, []);\n\n useEffect(() => {\n const dialog = panel.current;\n if (!dialog || compact === null) return;\n if (dialog.open) dialog.close();\n if (!compact) dialog.show();\n else if (open) dialog.showModal();\n else if (restoreFocus.current) launcher.current?.focus();\n restoreFocus.current = false;\n }, [compact, open]);\n\n useEffect(() => {\n const viewport = window.visualViewport;\n const dialog = panel.current!;\n const resize = () => {\n if (compact && open && viewport?.scale === 1) {\n dialog.style.setProperty(\n \"--omni-chat-viewport-top\",\n `${viewport.offsetTop}px`,\n );\n dialog.style.setProperty(\n \"--omni-chat-viewport-height\",\n `${viewport.height}px`,\n );\n } else {\n dialog.style.removeProperty(\"--omni-chat-viewport-top\");\n dialog.style.removeProperty(\"--omni-chat-viewport-height\");\n }\n };\n resize();\n viewport?.addEventListener(\"resize\", resize);\n viewport?.addEventListener(\"scroll\", resize);\n return () => {\n viewport?.removeEventListener(\"resize\", resize);\n viewport?.removeEventListener(\"scroll\", resize);\n };\n }, [compact, open]);\n\n const close = () => {\n if (!compact) return;\n restoreFocus.current = true;\n setOpen(false);\n };\n\n return (\n <div className={[\"omni-chat-layout\", className].filter(Boolean).join(\" \")}>\n <style>{chatLayoutStyles}</style>\n <div className=\"omni-chat-layout-content\">{children}</div>\n <button\n ref={launcher}\n type=\"button\"\n className=\"omni-chat-layout-launcher\"\n aria-label=\"Open assistant\"\n aria-controls={id}\n aria-expanded={compact === true && open}\n onClick={() => setOpen(true)}\n >\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.8\"\n aria-hidden=\"true\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n d=\"M21 11.5a8.5 8.5 0 0 1-12.3 7.6L3 21l1.9-5.7A8.5 8.5 0 1 1 21 11.5Z\"\n />\n </svg>\n </button>\n <dialog\n ref={panel}\n id={id}\n className=\"omni-chat-layout-panel\"\n aria-label=\"Application assistant\"\n onCancel={(event) => {\n event.preventDefault();\n close();\n }}\n >\n <div className=\"omni-chat-layout-toolbar\">\n <button type=\"button\" onClick={close}>\n ← Back to application\n </button>\n </div>\n <div className=\"omni-chat-layout-frame\">\n <ChatLayoutCloseContext.Provider value={close}>\n {chat}\n </ChatLayoutCloseContext.Provider>\n </div>\n </dialog>\n </div>\n );\n}\n","export const chatLayoutQuery = \"(max-width: 959px)\";\n\n/** Scoped host layout; the iframe continues to own all conversation styles. */\nexport const chatLayoutStyles = `\n.omni-chat-layout {\n display: grid; grid-template-columns: minmax(0, 1fr) clamp(360px, 30vw, 440px);\n height: 100dvh; min-height: 0; min-width: 0; overflow: hidden;\n}\n.omni-chat-layout-content { min-height: 0; min-width: 0; overflow: auto; }\n.omni-chat-layout-panel {\n position: relative; inset: auto; margin: 0; padding: 0; width: 100%; height: 100%;\n max-width: none; max-height: none; min-width: 0; min-height: 0; overflow: hidden;\n box-sizing: border-box; border: 0; border-inline-start: 1px solid #e4e4e7;\n background: white; color: #18181b;\n}\n.omni-chat-layout-panel[open] { display: flex; flex-direction: column; }\n.omni-chat-layout-panel:not([open]) { display: none; }\n.omni-chat-layout-frame { flex: 1; min-height: 0; min-width: 0; overflow: hidden; }\n.omni-chat-layout-launcher, .omni-chat-layout-toolbar { display: none; }\n.omni-chat-layout-launcher, .omni-chat-layout-toolbar button {\n font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;\n}\n.omni-chat-layout-launcher:focus-visible, .omni-chat-layout-toolbar button:focus-visible {\n outline: 3px solid #2563eb; outline-offset: 3px;\n}\n@media ${chatLayoutQuery} {\n .omni-chat-layout { grid-template-columns: minmax(0, 1fr); }\n .omni-chat-layout-launcher {\n display: flex; align-items: center; justify-content: center;\n position: fixed; right: calc(20px + env(safe-area-inset-right, 0px));\n bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 50;\n width: 56px; height: 56px; padding: 0; border: 0; border-radius: 50%;\n background: #18181b; color: white; box-shadow: 0 4px 16px #0003;\n }\n .omni-chat-layout-launcher svg { width: 24px; height: 24px; }\n .omni-chat-layout-launcher[aria-expanded=\"true\"] { visibility: hidden; }\n .omni-chat-layout-panel {\n position: fixed; top: var(--omni-chat-viewport-top, 0px); left: 0; right: 0;\n width: 100%; height: var(--omni-chat-viewport-height, 100dvh); border: 0;\n padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)\n env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);\n }\n .omni-chat-layout-panel::backdrop { background: #0005; }\n .omni-chat-layout-toolbar { display: flex; flex-shrink: 0; border-bottom: 1px solid #e4e4e7; }\n .omni-chat-layout-toolbar button {\n min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: inherit;\n font-size: 14px;\n }\n}\n`;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAAA,gBAOO;;;ACYP,SAAS,YAAY,OAAgB,SAA0B;AAC7D,QAAM,UAAU,KAAK,UAAU,KAAK;AACpC,MACE,OAAO,YAAY,YACnB,IAAI,YAAY,EAAE,OAAO,OAAO,EAAE,SAAS,WAC3C,8BAA8B,KAAK,OAAO;AAE1C,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO,KAAK,MAAM,OAAO;AAC3B;AAEO,SAAS,gCAAgC,OAI7C;AAED,QAAM,QAAQ,oBAAI,IAGhB;AACF,SAAO,OAAO,YAAqC;AACjD,QAAI,OAAO,Q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OAAO,aAAa;AACpC,QAAI,MAAM;AACR,YAAM,QAAQ,MAAM,YAClB,OAAO,YAAY,WAAW,GAAG,OAAO,OAAO;AAAA,EACrD,CAAC;AACD,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL;AAAA,MACA,OAAO,EAAE,QAAQ,QAAQ,WAAW,KAAK,GAAG,MAAM;AAAA;AAAA,EACpD;AAEJ;","names":["import_react","chatOrigin","chatOrigin","import_jsx_runtime"]}
|
|
1
|
+
{"version":3,"sources":["../src/react.tsx","../src/application.ts","../../../lib/assistant/application-chat/bridge-scope.ts","../src/hosted-chat.ts","../../../lib/assistant/hosted-chat-origin.ts","../src/chat-origin.ts","../src/application-embed.ts","../src/embed.ts","../src/chat-layout.tsx","../src/chat-layout-styles.ts"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n useContext,\n useEffect,\n useRef,\n type CSSProperties,\n type ReactNode,\n} from \"react\";\nimport { createOmniChatEmbed, type OmniChatEmbedOptions } from \"./embed\";\nimport {\n createOmniApplicationChatEmbed,\n type OmniApplicationChatOptions,\n} from \"./application-embed\";\nimport { ChatLayout, ChatLayoutCloseContext } from \"./chat-layout\";\n\ntype OmniChatOptions = OmniChatEmbedOptions | OmniApplicationChatOptions;\nconst OmniChatContext = createContext<OmniChatOptions | null>(null);\nexport type OmniProviderProps = OmniChatOptions & { children: ReactNode };\n\nexport function OmniProvider({ children, ...options }: OmniProviderProps) {\n return (\n <OmniChatContext.Provider value={options}>\n {children}\n </OmniChatContext.Provider>\n );\n}\nexport interface OmniChatProps {\n className?: string;\n style?: CSSProperties;\n title?: string;\n onRequestClose?: () => void;\n}\nexport interface OmniChatLayoutProps {\n children: ReactNode;\n className?: string;\n title?: string;\n}\n/** Full-height desktop docking; below 960px a launcher opens a full-height modal. */\nexport function OmniChatLayout({\n children,\n className,\n title,\n}: OmniChatLayoutProps) {\n return (\n <ChatLayout\n className={className}\n chat={<OmniChat title={title} style={{ minHeight: 0 }} />}\n >\n {children}\n </ChatLayout>\n );\n}\n/** The hosted assistant owns its styles and runtime, so the host needs no Tailwind or assistant-ui dependencies. */\nexport function OmniChat({\n className,\n style,\n title,\n onRequestClose,\n}: OmniChatProps) {\n const options = useContext(OmniChatContext);\n const closeLayout = useContext(ChatLayoutCloseContext);\n if (!options)\n throw new Error(\"OmniChat must be rendered inside OmniProvider.\");\n const container = useRef<HTMLDivElement>(null);\n const frame = useRef<HTMLIFrameElement | null>(null);\n const { baseUrl, deploymentId, onError, application, frontendTools } =\n options;\n const getSession = \"getSession\" in options ? options.getSession : undefined;\n const { organizationId, agentId, appId, systemPrompt, tools } =\n options as OmniApplicationChatOptions;\n const requestClose = onRequestClose ?? closeLayout ?? options.onRequestClose;\n const callbacks = useRef({\n getSession,\n onError,\n application,\n frontendTools,\n requestClose,\n systemPrompt,\n tools,\n });\n useEffect(() => {\n callbacks.current = {\n getSession,\n onError,\n application,\n frontendTools,\n requestClose,\n systemPrompt,\n tools,\n };\n }, [\n getSession,\n onError,\n application,\n frontendTools,\n requestClose,\n systemPrompt,\n tools,\n ]);\n const hasSessionBroker = Boolean(getSession);\n const frameTitle = title ?? options.title;\n useEffect(() => {\n if (!container.current) return;\n const hostedOptions = {\n baseUrl,\n onError: (error: Error) => callbacks.current.onError?.(error),\n onRequestClose: () => callbacks.current.requestClose?.(),\n title: frameTitle,\n ...(deploymentId\n ? {\n deploymentId,\n getSession: hasSessionBroker\n ? () => callbacks.current.getSession!()\n : undefined,\n }\n : {\n organizationId,\n agentId,\n appId,\n }),\n get systemPrompt() {\n return callbacks.current.systemPrompt;\n },\n get tools() {\n return callbacks.current.tools;\n },\n get application() {\n return callbacks.current.application;\n },\n get frontendTools() {\n return callbacks.current.frontendTools;\n },\n };\n const embed =\n \"deploymentId\" in hostedOptions\n ? createOmniChatEmbed(container.current, hostedOptions)\n : createOmniApplicationChatEmbed(container.current, hostedOptions);\n frame.current = embed.iframe;\n return () => {\n frame.current = null;\n embed.destroy();\n };\n }, [\n baseUrl,\n deploymentId,\n organizationId,\n agentId,\n appId,\n frameTitle,\n hasSessionBroker,\n ]);\n useEffect(() => {\n // A bounded sidebar can override the inline default without replacing chat.\n const minimum = style?.minHeight ?? 320;\n if (frame.current)\n frame.current.style.minHeight =\n typeof minimum === \"number\" ? `${minimum}px` : minimum;\n });\n return (\n <div\n ref={container}\n className={className}\n style={{ height: \"100%\", minHeight: 320, ...style }}\n />\n );\n}\nexport type {\n OmniFrontendTool,\n OmniChatApplication,\n OmniApplicationOptions,\n OmniChatEmbedOptions,\n OmniChatSession,\n OmniApplicationChatOptions,\n} from \"./embed\";\n","/** Host-defined actions execute inside the application, never on the assistant server. */\nexport interface OmniFrontendTool {\n description: string;\n parameters: Record<string, unknown>;\n execute: (\n args: Record<string, unknown>,\n context: { toolCallId: string; abortSignal: AbortSignal },\n ) => unknown | Promise<unknown>;\n}\nexport interface OmniChatApplication {\n name: string;\n description: string;\n /** Return a small, explicitly selected snapshot. Do not include secrets. */\n getContext: () => unknown | Promise<unknown>;\n}\nexport interface OmniApplicationOptions {\n application?: OmniChatApplication;\n /** Names must start with app_; use array arguments for actions with multiple targets. */\n frontendTools?: Record<string, OmniFrontendTool>;\n}\n\nfunction boundedJson(value: unknown, maximum: number): unknown {\n const encoded = JSON.stringify(value);\n if (\n typeof encoded !== \"string\" ||\n new TextEncoder().encode(encoded).length > maximum ||\n /data:[^\"\\s]{0,100};base64,/i.test(encoded)\n )\n throw new Error(\n \"Application data must be bounded JSON without base64 payloads.\",\n );\n return JSON.parse(encoded);\n}\n\nexport function createApplicationMessageHandler(input: {\n options: OmniApplicationOptions;\n assistant?: () => { systemPrompt?: string; tools?: readonly string[] };\n signal: AbortSignal;\n reply: (message: Record<string, unknown>) => void;\n}) {\n // A repeated parked call reuses its result instead of applying an action twice.\n const calls = new Map<\n string,\n { signature: string; result: Promise<unknown> }\n >();\n return async (message: Record<string, unknown>) => {\n if (typeof message.requestId !== \"string\" || message.requestId.length > 200)\n return;\n try {\n if (message.type === \"omni-chat:application-request\") {\n const application = input.options.application;\n input.reply({\n type: \"omni-chat:application-response\",\n requestId: message.requestId,\n ...(input.assistant\n ? { assistant: boundedJson(input.assistant(), 65536) }\n : {}),\n application: application\n ? boundedJson(\n {\n name: application.name,\n description: application.description,\n context: (await application.getContext()) ?? null,\n tools: Object.entries(input.options.frontendTools ?? {}).map(\n ([name, definition]) => ({\n name,\n description: definition.description,\n parameters: definition.parameters,\n }),\n ),\n },\n 65536,\n )\n : undefined,\n });\n } else if (message.type === \"omni-chat:tool-request\") {\n const name = message.toolName;\n const toolCallId = message.toolCallId;\n if (\n typeof name !== \"string\" ||\n !/^app_[a-z][a-z0-9_]{0,59}$/.test(name) ||\n typeof toolCallId !== \"string\" ||\n !toolCallId ||\n toolCallId.length > 200\n )\n throw new Error(\"Invalid application tool request.\");\n const definition = Object.hasOwn(\n input.options.frontendTools ?? {},\n name,\n )\n ? input.options.frontendTools?.[name]\n : undefined;\n if (!input.options.application || !definition)\n throw new Error(\"This application action is unavailable.\");\n const args = message.args;\n if (!args || typeof args !== \"object\" || Array.isArray(args))\n throw new Error(\"Invalid application action arguments.\");\n const signature = JSON.stringify({ name, args });\n const prior = calls.get(toolCallId);\n if (prior && prior.signature !== signature)\n throw new Error(\"This tool call ID was already used.\");\n const result =\n prior?.result ??\n Promise.resolve().then(() =>\n definition.execute(args as Record<string, unknown>, {\n toolCallId,\n abortSignal: input.signal,\n }),\n );\n if (!prior) {\n if (calls.size >= 200)\n throw new Error(\"Start a new application chat.\");\n calls.set(toolCallId, { signature, result });\n }\n input.reply({\n type: \"omni-chat:tool-response\",\n requestId: message.requestId,\n toolCallId,\n result: boundedJson((await result) ?? null, 12000),\n });\n }\n } catch (error) {\n input.reply({\n type:\n message.type === \"omni-chat:application-request\"\n ? \"omni-chat:application-response\"\n : \"omni-chat:tool-response\",\n requestId: message.requestId,\n toolCallId: message.toolCallId,\n error:\n error instanceof Error\n ? error.message\n : \"The application action failed.\",\n });\n }\n };\n}\n","/** Scope each hosted frame independently; application chats have no deployment. */\nexport type HostedChatScope =\n | { deploymentId: string; chatId?: never }\n | { chatId: string; deploymentId?: never };\n\nexport function hostedChatId(scope: HostedChatScope) {\n return scope.deploymentId ?? scope.chatId;\n}\n\nexport function matchesHostedChatScope(\n message: Record<string, unknown> | null | undefined,\n scope: HostedChatScope,\n) {\n return scope.deploymentId !== undefined\n ? message?.deploymentId === scope.deploymentId &&\n message.chatId === undefined\n : message?.chatId === scope.chatId && message.deploymentId === undefined;\n}\n","import {\n createApplicationMessageHandler,\n type OmniApplicationOptions,\n} from \"./application\";\nimport {\n matchesHostedChatScope,\n type HostedChatScope,\n} from \"../../../lib/assistant/application-chat/bridge-scope\";\nimport type { OmniChatEmbed, OmniChatSession } from \"./embed\";\n\nexport interface OmniHostedChatOptions extends OmniApplicationOptions {\n baseUrl?: string;\n title?: string;\n onError?: (error: Error) => void;\n onRequestClose?: () => void;\n}\n\nexport class ChatSessionError extends Error {\n constructor(\n message: string,\n readonly status: number,\n ) {\n super(message);\n }\n}\n\n/** One frame broker for member application chat and published storefront chat. */\nexport function mountHostedChat(\n container: HTMLElement,\n options: OmniHostedChatOptions,\n target: {\n url: string;\n scope: HostedChatScope;\n assistant?: () => { systemPrompt?: string; tools?: readonly string[] };\n mint?: (\n previousToken: string | undefined,\n visitorId: string | undefined,\n signal: AbortSignal,\n ) => Promise<OmniChatSession>;\n },\n): OmniChatEmbed {\n const document = container.ownerDocument;\n const host = document.defaultView;\n if (!host) throw new Error(\"A browser document is required to mount chat.\");\n const iframe = document.createElement(\"iframe\");\n iframe.src = target.url;\n iframe.title = options.title ?? \"OmniCommerce assistant\";\n iframe.referrerPolicy = \"strict-origin-when-cross-origin\";\n iframe.setAttribute(\n \"sandbox\",\n \"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox\",\n );\n Object.assign(iframe.style, {\n width: \"100%\",\n height: \"100%\",\n minHeight: \"320px\",\n border: \"0\",\n display: \"block\",\n });\n const chatOrigin = new URL(iframe.src).origin;\n let destroyed = false;\n let pending: Promise<OmniChatSession> | undefined;\n let previousToken: string | undefined;\n const controller = new AbortController();\n\n const applicationMessage = createApplicationMessageHandler({\n options,\n assistant: target.assistant,\n signal: controller.signal,\n reply: (message) => {\n if (!destroyed)\n iframe.contentWindow?.postMessage(\n { ...message, ...target.scope },\n chatOrigin,\n );\n },\n });\n const receive = (event: MessageEvent) => {\n if (\n destroyed ||\n event.source !== iframe.contentWindow ||\n event.origin !== chatOrigin ||\n !matchesHostedChatScope(event.data, target.scope)\n )\n return;\n if (\n event.data.type === \"omni-chat:application-request\" ||\n event.data.type === \"omni-chat:tool-request\"\n ) {\n void applicationMessage(event.data);\n return;\n }\n if (event.data.type === \"omni-chat:close-request\") {\n options.onRequestClose?.();\n return;\n }\n if (event.data.type !== \"omni-chat:session-request\" || !target.mint) return;\n const visitorId =\n typeof event.data.visitorId === \"string\"\n ? event.data.visitorId\n : undefined;\n pending ??= target.mint(previousToken, visitorId, controller.signal);\n void pending\n .then((session) => {\n if (destroyed) return;\n if (\n typeof session?.token !== \"string\" ||\n !session.token ||\n session.token.length > 4096 ||\n typeof session.threadId !== \"string\" ||\n !session.threadId ||\n !Number.isFinite(session.expiresIn) ||\n session.expiresIn <= 0\n )\n throw new Error(\"Invalid chat session response.\");\n previousToken = session.token;\n iframe.contentWindow?.postMessage(\n {\n type: \"omni-chat:session\",\n ...target.scope,\n session,\n ...(options.application ? { applicationEnabled: true } : {}),\n },\n chatOrigin,\n );\n })\n .catch((error: unknown) => {\n if (destroyed) return;\n const failure =\n error instanceof Error ? error : new Error(\"Could not open chat.\");\n if (\n failure instanceof ChatSessionError &&\n [401, 403].includes(failure.status)\n )\n previousToken = undefined;\n options.onError?.(failure);\n iframe.contentWindow?.postMessage(\n {\n type: \"omni-chat:session-error\",\n ...target.scope,\n error: failure.message,\n ...(options.application ? { applicationEnabled: true } : {}),\n },\n chatOrigin,\n );\n })\n .finally(() => {\n pending = undefined;\n });\n };\n host.addEventListener(\"message\", receive);\n container.append(iframe);\n return {\n iframe,\n focus() {\n if (destroyed) return;\n iframe.focus();\n iframe.contentWindow?.postMessage(\n {\n type: \"omni-chat:focus-composer\",\n ...target.scope,\n },\n chatOrigin,\n );\n },\n destroy() {\n if (destroyed) return;\n destroyed = true;\n controller.abort();\n previousToken = undefined;\n host.removeEventListener(\"message\", receive);\n iframe.remove();\n },\n };\n}\n","/** Exact hosted-chat origins, including trustworthy localhost development hosts. */\nexport function normalizeHostedChatOrigin(value: string): string {\n const url = new URL(value);\n const local =\n url.hostname === \"localhost\" ||\n url.hostname.endsWith(\".localhost\") ||\n url.hostname === \"127.0.0.1\";\n if (\n (url.protocol !== \"https:\" && !(url.protocol === \"http:\" && local)) ||\n url.username ||\n url.password ||\n url.pathname !== \"/\" ||\n url.search ||\n url.hash\n )\n throw new Error(\"Use an HTTPS origin, or HTTP localhost for development.\");\n return url.origin;\n}\n","import { normalizeHostedChatOrigin } from \"../../../lib/assistant/hosted-chat-origin\";\n\nexport function chatOrigin(baseUrl?: string): string {\n return normalizeHostedChatOrigin(baseUrl ?? \"https://omnicommerce.sg\");\n}\n","import { chatOrigin } from \"./chat-origin\";\nimport { mountHostedChat, type OmniHostedChatOptions } from \"./hosted-chat\";\n\n/** Application chat authenticates the viewer; it never uses a storefront deployment. */\nexport interface OmniApplicationChatOptions extends OmniHostedChatOptions {\n deploymentId?: never;\n /** Omit to use the member's currently selected organization. */\n organizationId?: string;\n /** Omit to use the default native assistant. */\n agentId?: string;\n /** Groups this application's conversation history; defaults to its origin. */\n appId?: string;\n /** Application role instructions. Omit or clear to use the selected agent's prompt. */\n systemPrompt?: string;\n /** Backend tool/toolkit allowlist within the selected agent's permissions.\n * Omit to inherit; [] allows only registered frontendTools. */\n tools?: readonly string[];\n}\n\nexport function getOmniApplicationChatUrl(\n options: OmniApplicationChatOptions,\n parentOrigin: string,\n chatId: string,\n) {\n if (\n !/^[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}$/i.test(chatId)\n )\n throw new Error(\"A valid application chat ID is required.\");\n const url = new URL(\"/sdk/application-chat\", chatOrigin(options.baseUrl));\n const parent = chatOrigin(parentOrigin);\n url.searchParams.set(\"parentOrigin\", parent);\n url.searchParams.set(\"chatId\", chatId);\n const appId = options.appId?.trim() ?? parent;\n if (!appId || appId.length > 200)\n throw new Error(\"appId must contain 1–200 characters.\");\n url.searchParams.set(\"appId\", appId);\n for (const key of [\"organizationId\", \"agentId\"] as const) {\n if (options[key] === undefined) continue;\n const value = options[key].trim();\n if (!value || value.length > 120)\n throw new Error(`${key} must contain 1–120 characters.`);\n url.searchParams.set(key, value);\n }\n return url.toString();\n}\n\nexport function createOmniApplicationChatEmbed(\n container: HTMLElement,\n options: OmniApplicationChatOptions,\n) {\n const host = container.ownerDocument.defaultView;\n if (!host) throw new Error(\"A browser document is required to mount chat.\");\n const chatId = host.crypto.randomUUID();\n return mountHostedChat(container, options, {\n url: getOmniApplicationChatUrl(options, host.location.origin, chatId),\n scope: { chatId },\n assistant: () => ({\n ...(options.systemPrompt !== undefined\n ? { systemPrompt: options.systemPrompt }\n : {}),\n ...(options.tools !== undefined ? { tools: options.tools } : {}),\n }),\n });\n}\n","import { mountHostedChat, ChatSessionError } from \"./hosted-chat\";\nimport { chatOrigin } from \"./chat-origin\";\nimport { type OmniApplicationOptions } from \"./application\";\nexport type {\n OmniFrontendTool,\n OmniChatApplication,\n OmniApplicationOptions,\n} from \"./application\";\n/** A hosted chat session. Keep its short-lived token in memory, never in iframe URLs. */\nexport {\n createOmniApplicationChatEmbed,\n getOmniApplicationChatUrl,\n type OmniApplicationChatOptions,\n} from \"./application-embed\";\nexport { createOmniChatWidget, type OmniChatWidgetOptions } from \"./widget\";\nexport {\n DEFAULT_WIDGET_OFFSET,\n MAX_WIDGET_OFFSET,\n type OmniChatWidgetPlacement,\n} from \"./widget-placement\";\nexport { getOmniChatEmbedCode, getOmniChatReactCode } from \"./embed-code\";\nexport interface OmniChatSession {\n token: string;\n threadId: string;\n expiresIn: number;\n}\nexport interface OmniChatEmbedOptions extends OmniApplicationOptions {\n deploymentId: string;\n baseUrl?: string;\n /** Optional authenticated session mint on the host application's server. */\n getSession?: () => Promise<OmniChatSession>;\n title?: string;\n onError?: (error: Error) => void;\n /** Floating widgets use this to close on Escape from the hosted chat. */\n onRequestClose?: () => void;\n}\nexport interface OmniChatEmbed {\n iframe: HTMLIFrameElement;\n /** Focus the hosted composer, including when reopening a retained chat. */\n focus(): void;\n destroy(): void;\n}\n\nexport function getOmniChatEmbedUrl(\n options: Pick<OmniChatEmbedOptions, \"baseUrl\" | \"deploymentId\">,\n parentOrigin?: string,\n): string {\n if (\n !/^[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}$/i.test(\n options.deploymentId,\n )\n )\n throw new Error(\"A valid chat deployment ID is required.\");\n const base = chatOrigin(options.baseUrl);\n const url = new URL(`/embed/${options.deploymentId}`, base);\n if (parentOrigin)\n url.searchParams.set(\"parentOrigin\", new URL(parentOrigin).origin);\n return url.toString();\n}\n\n/** Browser-only mounting; importing this entry point is safe during SSR. */\nexport function createOmniChatEmbed(\n container: HTMLElement,\n options: OmniChatEmbedOptions,\n): OmniChatEmbed {\n const host = container.ownerDocument.defaultView;\n if (!host) throw new Error(\"A browser document is required to mount chat.\");\n const url = getOmniChatEmbedUrl(options, host.location.origin);\n const chatOrigin = new URL(url).origin;\n return mountHostedChat(container, options, {\n url,\n scope: { deploymentId: options.deploymentId },\n mint: async (previousToken, visitorId, signal) => {\n if (options.getSession) return options.getSession();\n const response = await host.fetch(\n `${chatOrigin}/api/embed/${options.deploymentId}/session`,\n {\n method: \"POST\",\n credentials: \"include\",\n signal,\n headers: {\n \"Content-Type\": \"application/json\",\n ...(previousToken\n ? { Authorization: `Bearer ${previousToken}` }\n : {}),\n },\n body: JSON.stringify(\n visitorId &&\n /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(\n visitorId,\n )\n ? { visitorId }\n : {},\n ),\n },\n );\n const result = (await response.json()) as OmniChatSession & {\n error?: string;\n };\n if (!response.ok)\n throw new ChatSessionError(\n result.error ?? \"Could not open the chat session.\",\n response.status,\n );\n return result;\n },\n });\n}\n","\"use client\";\n\nimport {\n createContext,\n useEffect,\n useId,\n useRef,\n useState,\n type ReactNode,\n} from \"react\";\nimport { chatLayoutQuery, chatLayoutStyles } from \"./chat-layout-styles\";\n\nexport const ChatLayoutCloseContext = createContext<(() => void) | undefined>(\n undefined,\n);\n\n/** One mounted frame switches between an inline desktop panel and a native modal. */\nexport function ChatLayout({\n children,\n chat,\n className,\n}: {\n children: ReactNode;\n chat: ReactNode;\n className?: string;\n}) {\n const panel = useRef<HTMLDialogElement>(null);\n const launcher = useRef<HTMLButtonElement>(null);\n const restoreFocus = useRef(false);\n const [compact, setCompact] = useState<boolean | null>(null);\n const [open, setOpen] = useState(false);\n const id = useId();\n\n useEffect(() => {\n const media = window.matchMedia(chatLayoutQuery);\n const update = () => {\n setCompact(media.matches);\n // Entering the compact layout gives the application its space back.\n setOpen(false);\n };\n update();\n media.addEventListener(\"change\", update);\n return () => media.removeEventListener(\"change\", update);\n }, []);\n\n useEffect(() => {\n const dialog = panel.current;\n if (!dialog || compact === null) return;\n if (dialog.open) dialog.close();\n if (!compact) dialog.show();\n else if (open) dialog.showModal();\n else if (restoreFocus.current) launcher.current?.focus();\n restoreFocus.current = false;\n }, [compact, open]);\n\n useEffect(() => {\n const viewport = window.visualViewport;\n const dialog = panel.current!;\n const resize = () => {\n if (compact && open && viewport?.scale === 1) {\n dialog.style.setProperty(\n \"--omni-chat-viewport-top\",\n `${viewport.offsetTop}px`,\n );\n dialog.style.setProperty(\n \"--omni-chat-viewport-height\",\n `${viewport.height}px`,\n );\n } else {\n dialog.style.removeProperty(\"--omni-chat-viewport-top\");\n dialog.style.removeProperty(\"--omni-chat-viewport-height\");\n }\n };\n resize();\n viewport?.addEventListener(\"resize\", resize);\n viewport?.addEventListener(\"scroll\", resize);\n return () => {\n viewport?.removeEventListener(\"resize\", resize);\n viewport?.removeEventListener(\"scroll\", resize);\n };\n }, [compact, open]);\n\n const close = () => {\n if (!compact) return;\n restoreFocus.current = true;\n setOpen(false);\n };\n\n return (\n <div className={[\"omni-chat-layout\", className].filter(Boolean).join(\" \")}>\n <style>{chatLayoutStyles}</style>\n <div className=\"omni-chat-layout-content\">{children}</div>\n <button\n ref={launcher}\n type=\"button\"\n className=\"omni-chat-layout-launcher\"\n aria-label=\"Open assistant\"\n aria-controls={id}\n aria-expanded={compact === true && open}\n onClick={() => setOpen(true)}\n >\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.8\"\n aria-hidden=\"true\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n d=\"M21 11.5a8.5 8.5 0 0 1-12.3 7.6L3 21l1.9-5.7A8.5 8.5 0 1 1 21 11.5Z\"\n />\n </svg>\n </button>\n <dialog\n ref={panel}\n id={id}\n className=\"omni-chat-layout-panel\"\n aria-label=\"Application assistant\"\n onCancel={(event) => {\n event.preventDefault();\n close();\n }}\n >\n <div className=\"omni-chat-layout-toolbar\">\n <button type=\"button\" onClick={close}>\n ← Back to application\n </button>\n </div>\n <div className=\"omni-chat-layout-frame\">\n <ChatLayoutCloseContext.Provider value={close}>\n {chat}\n </ChatLayoutCloseContext.Provider>\n </div>\n </dialog>\n </div>\n );\n}\n","export const chatLayoutQuery = \"(max-width: 959px)\";\n\n/** Scoped host layout; the iframe continues to own all conversation styles. */\nexport const chatLayoutStyles = `\n.omni-chat-layout {\n display: grid; grid-template-columns: minmax(0, 1fr) clamp(360px, 30vw, 440px);\n height: 100dvh; min-height: 0; min-width: 0; overflow: hidden;\n}\n.omni-chat-layout-content { min-height: 0; min-width: 0; overflow: auto; }\n.omni-chat-layout-panel {\n position: relative; inset: auto; margin: 0; padding: 0; width: 100%; height: 100%;\n max-width: none; max-height: none; min-width: 0; min-height: 0; overflow: hidden;\n box-sizing: border-box; border: 0; border-inline-start: 1px solid #e4e4e7;\n background: white; color: #18181b;\n}\n.omni-chat-layout-panel[open] { display: flex; flex-direction: column; }\n.omni-chat-layout-panel:not([open]) { display: none; }\n.omni-chat-layout-frame { flex: 1; min-height: 0; min-width: 0; overflow: hidden; }\n.omni-chat-layout-launcher, .omni-chat-layout-toolbar { display: none; }\n.omni-chat-layout-launcher, .omni-chat-layout-toolbar button {\n font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;\n}\n.omni-chat-layout-launcher:focus-visible, .omni-chat-layout-toolbar button:focus-visible {\n outline: 3px solid #2563eb; outline-offset: 3px;\n}\n@media ${chatLayoutQuery} {\n .omni-chat-layout { grid-template-columns: minmax(0, 1fr); }\n .omni-chat-layout-launcher {\n display: flex; align-items: center; justify-content: center;\n position: fixed; right: calc(20px + env(safe-area-inset-right, 0px));\n bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 50;\n width: 56px; height: 56px; padding: 0; border: 0; border-radius: 50%;\n background: #18181b; color: white; box-shadow: 0 4px 16px #0003;\n }\n .omni-chat-layout-launcher svg { width: 24px; height: 24px; }\n .omni-chat-layout-launcher[aria-expanded=\"true\"] { visibility: hidden; }\n .omni-chat-layout-panel {\n position: fixed; top: var(--omni-chat-viewport-top, 0px); left: 0; right: 0;\n width: 100%; height: var(--omni-chat-viewport-height, 100dvh); border: 0;\n padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)\n env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);\n }\n .omni-chat-layout-panel::backdrop { background: #0005; }\n .omni-chat-layout-toolbar { display: flex; flex-shrink: 0; border-bottom: 1px solid #e4e4e7; }\n .omni-chat-layout-toolbar button {\n min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: inherit;\n font-size: 14px;\n }\n}\n`;\n"],"mappings":";;;;;;;;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;","names":["import_react","chatOrigin","chatOrigin","import_jsx_runtime"]}
|
package/dist/react.js
CHANGED
|
@@ -31,6 +31,7 @@ function createApplicationMessageHandler(input) {
|
|
|
31
31
|
input.reply({
|
|
32
32
|
type: "omni-chat:application-response",
|
|
33
33
|
requestId: message.requestId,
|
|
34
|
+
...input.assistant ? { assistant: boundedJson(input.assistant(), 65536) } : {},
|
|
34
35
|
application: application ? boundedJson(
|
|
35
36
|
{
|
|
36
37
|
name: application.name,
|
|
@@ -132,6 +133,7 @@ function mountHostedChat(container, options, target) {
|
|
|
132
133
|
const controller = new AbortController();
|
|
133
134
|
const applicationMessage = createApplicationMessageHandler({
|
|
134
135
|
options,
|
|
136
|
+
assistant: target.assistant,
|
|
135
137
|
signal: controller.signal,
|
|
136
138
|
reply: (message) => {
|
|
137
139
|
if (!destroyed)
|
|
@@ -255,7 +257,11 @@ function createOmniApplicationChatEmbed(container, options) {
|
|
|
255
257
|
const chatId = host.crypto.randomUUID();
|
|
256
258
|
return mountHostedChat(container, options, {
|
|
257
259
|
url: getOmniApplicationChatUrl(options, host.location.origin, chatId),
|
|
258
|
-
scope: { chatId }
|
|
260
|
+
scope: { chatId },
|
|
261
|
+
assistant: () => ({
|
|
262
|
+
...options.systemPrompt !== void 0 ? { systemPrompt: options.systemPrompt } : {},
|
|
263
|
+
...options.tools !== void 0 ? { tools: options.tools } : {}
|
|
264
|
+
})
|
|
259
265
|
});
|
|
260
266
|
}
|
|
261
267
|
|
|
@@ -521,14 +527,16 @@ function OmniChat({
|
|
|
521
527
|
const frame = useRef2(null);
|
|
522
528
|
const { baseUrl, deploymentId, onError, application, frontendTools } = options;
|
|
523
529
|
const getSession = "getSession" in options ? options.getSession : void 0;
|
|
524
|
-
const { organizationId, agentId, appId } = options;
|
|
530
|
+
const { organizationId, agentId, appId, systemPrompt, tools } = options;
|
|
525
531
|
const requestClose = onRequestClose ?? closeLayout ?? options.onRequestClose;
|
|
526
532
|
const callbacks = useRef2({
|
|
527
533
|
getSession,
|
|
528
534
|
onError,
|
|
529
535
|
application,
|
|
530
536
|
frontendTools,
|
|
531
|
-
requestClose
|
|
537
|
+
requestClose,
|
|
538
|
+
systemPrompt,
|
|
539
|
+
tools
|
|
532
540
|
});
|
|
533
541
|
useEffect2(() => {
|
|
534
542
|
callbacks.current = {
|
|
@@ -536,9 +544,19 @@ function OmniChat({
|
|
|
536
544
|
onError,
|
|
537
545
|
application,
|
|
538
546
|
frontendTools,
|
|
539
|
-
requestClose
|
|
547
|
+
requestClose,
|
|
548
|
+
systemPrompt,
|
|
549
|
+
tools
|
|
540
550
|
};
|
|
541
|
-
}, [
|
|
551
|
+
}, [
|
|
552
|
+
getSession,
|
|
553
|
+
onError,
|
|
554
|
+
application,
|
|
555
|
+
frontendTools,
|
|
556
|
+
requestClose,
|
|
557
|
+
systemPrompt,
|
|
558
|
+
tools
|
|
559
|
+
]);
|
|
542
560
|
const hasSessionBroker = Boolean(getSession);
|
|
543
561
|
const frameTitle = title ?? options.title;
|
|
544
562
|
useEffect2(() => {
|
|
@@ -551,7 +569,17 @@ function OmniChat({
|
|
|
551
569
|
...deploymentId ? {
|
|
552
570
|
deploymentId,
|
|
553
571
|
getSession: hasSessionBroker ? () => callbacks.current.getSession() : void 0
|
|
554
|
-
} : {
|
|
572
|
+
} : {
|
|
573
|
+
organizationId,
|
|
574
|
+
agentId,
|
|
575
|
+
appId
|
|
576
|
+
},
|
|
577
|
+
get systemPrompt() {
|
|
578
|
+
return callbacks.current.systemPrompt;
|
|
579
|
+
},
|
|
580
|
+
get tools() {
|
|
581
|
+
return callbacks.current.tools;
|
|
582
|
+
},
|
|
555
583
|
get application() {
|
|
556
584
|
return callbacks.current.application;
|
|
557
585
|
},
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react.tsx","../src/application.ts","../../../lib/assistant/application-chat/bridge-scope.ts","../src/hosted-chat.ts","../../../lib/assistant/hosted-chat-origin.ts","../src/chat-origin.ts","../src/application-embed.ts","../src/embed.ts","../src/chat-layout.tsx","../src/chat-layout-styles.ts"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n useContext,\n useEffect,\n useRef,\n type CSSProperties,\n type ReactNode,\n} from \"react\";\nimport { createOmniChatEmbed, type OmniChatEmbedOptions } from \"./embed\";\nimport {\n createOmniApplicationChatEmbed,\n type OmniApplicationChatOptions,\n} from \"./application-embed\";\nimport { ChatLayout, ChatLayoutCloseContext } from \"./chat-layout\";\n\ntype OmniChatOptions = OmniChatEmbedOptions | OmniApplicationChatOptions;\nconst OmniChatContext = createContext<OmniChatOptions | null>(null);\nexport type OmniProviderProps = OmniChatOptions & { children: ReactNode };\n\nexport function OmniProvider({ children, ...options }: OmniProviderProps) {\n return (\n <OmniChatContext.Provider value={options}>\n {children}\n </OmniChatContext.Provider>\n );\n}\nexport interface OmniChatProps {\n className?: string;\n style?: CSSProperties;\n title?: string;\n onRequestClose?: () => void;\n}\nexport interface OmniChatLayoutProps {\n children: ReactNode;\n className?: string;\n title?: string;\n}\n/** Full-height desktop docking; below 960px a launcher opens a full-height modal. */\nexport function OmniChatLayout({\n children,\n className,\n title,\n}: OmniChatLayoutProps) {\n return (\n <ChatLayout\n className={className}\n chat={<OmniChat title={title} style={{ minHeight: 0 }} />}\n >\n {children}\n </ChatLayout>\n );\n}\n/** The hosted assistant owns its styles and runtime, so the host needs no Tailwind or assistant-ui dependencies. */\nexport function OmniChat({\n className,\n style,\n title,\n onRequestClose,\n}: OmniChatProps) {\n const options = useContext(OmniChatContext);\n const closeLayout = useContext(ChatLayoutCloseContext);\n if (!options)\n throw new Error(\"OmniChat must be rendered inside OmniProvider.\");\n const container = useRef<HTMLDivElement>(null);\n const frame = useRef<HTMLIFrameElement | null>(null);\n const { baseUrl, deploymentId, onError, application, frontendTools } =\n options;\n const getSession = \"getSession\" in options ? options.getSession : undefined;\n const { organizationId, agentId, appId } =\n options as OmniApplicationChatOptions;\n const requestClose = onRequestClose ?? closeLayout ?? options.onRequestClose;\n const callbacks = useRef({\n getSession,\n onError,\n application,\n frontendTools,\n requestClose,\n });\n useEffect(() => {\n callbacks.current = {\n getSession,\n onError,\n application,\n frontendTools,\n requestClose,\n };\n }, [getSession, onError, application, frontendTools, requestClose]);\n const hasSessionBroker = Boolean(getSession);\n const frameTitle = title ?? options.title;\n useEffect(() => {\n if (!container.current) return;\n const hostedOptions = {\n baseUrl,\n onError: (error: Error) => callbacks.current.onError?.(error),\n onRequestClose: () => callbacks.current.requestClose?.(),\n title: frameTitle,\n ...(deploymentId\n ? {\n deploymentId,\n getSession: hasSessionBroker\n ? () => callbacks.current.getSession!()\n : undefined,\n }\n : { organizationId, agentId, appId }),\n get application() {\n return callbacks.current.application;\n },\n get frontendTools() {\n return callbacks.current.frontendTools;\n },\n };\n const embed =\n \"deploymentId\" in hostedOptions\n ? createOmniChatEmbed(container.current, hostedOptions)\n : createOmniApplicationChatEmbed(container.current, hostedOptions);\n frame.current = embed.iframe;\n return () => {\n frame.current = null;\n embed.destroy();\n };\n }, [\n baseUrl,\n deploymentId,\n organizationId,\n agentId,\n appId,\n frameTitle,\n hasSessionBroker,\n ]);\n useEffect(() => {\n // A bounded sidebar can override the inline default without replacing chat.\n const minimum = style?.minHeight ?? 320;\n if (frame.current)\n frame.current.style.minHeight =\n typeof minimum === \"number\" ? `${minimum}px` : minimum;\n });\n return (\n <div\n ref={container}\n className={className}\n style={{ height: \"100%\", minHeight: 320, ...style }}\n />\n );\n}\nexport type {\n OmniFrontendTool,\n OmniChatApplication,\n OmniApplicationOptions,\n OmniChatEmbedOptions,\n OmniChatSession,\n OmniApplicationChatOptions,\n} from \"./embed\";\n","/** Host-defined actions execute inside the application, never on the assistant server. */\nexport interface OmniFrontendTool {\n description: string;\n parameters: Record<string, unknown>;\n execute: (\n args: Record<string, unknown>,\n context: { toolCallId: string; abortSignal: AbortSignal },\n ) => unknown | Promise<unknown>;\n}\nexport interface OmniChatApplication {\n name: string;\n description: string;\n /** Return a small, explicitly selected snapshot. Do not include secrets. */\n getContext: () => unknown | Promise<unknown>;\n}\nexport interface OmniApplicationOptions {\n application?: OmniChatApplication;\n /** Names must start with app_; use array arguments for actions with multiple targets. */\n frontendTools?: Record<string, OmniFrontendTool>;\n}\n\nfunction boundedJson(value: unknown, maximum: number): unknown {\n const encoded = JSON.stringify(value);\n if (\n typeof encoded !== \"string\" ||\n new TextEncoder().encode(encoded).length > maximum ||\n /data:[^\"\\s]{0,100};base64,/i.test(encoded)\n )\n throw new Error(\n \"Application data must be bounded JSON without base64 payloads.\",\n );\n return JSON.parse(encoded);\n}\n\nexport function createApplicationMessageHandler(input: {\n options: OmniApplicationOptions;\n signal: AbortSignal;\n reply: (message: Record<string, unknown>) => void;\n}) {\n // A repeated parked call reuses its result instead of applying an action twice.\n const calls = new Map<\n string,\n { signature: string; result: Promise<unknown> }\n >();\n return async (message: Record<string, unknown>) => {\n if (typeof message.requestId !== \"string\" || message.requestId.length > 200)\n return;\n try {\n if (message.type === \"omni-chat:application-request\") {\n const application = input.options.application;\n input.reply({\n type: \"omni-chat:application-response\",\n requestId: message.requestId,\n application: application\n ? boundedJson(\n {\n name: application.name,\n description: application.description,\n context: (await application.getContext()) ?? null,\n tools: Object.entries(input.options.frontendTools ?? {}).map(\n ([name, definition]) => ({\n name,\n description: definition.description,\n parameters: definition.parameters,\n }),\n ),\n },\n 65536,\n )\n : undefined,\n });\n } else if (message.type === \"omni-chat:tool-request\") {\n const name = message.toolName;\n const toolCallId = message.toolCallId;\n if (\n typeof name !== \"string\" ||\n !/^app_[a-z][a-z0-9_]{0,59}$/.test(name) ||\n typeof toolCallId !== \"string\" ||\n !toolCallId ||\n toolCallId.length > 200\n )\n throw new Error(\"Invalid application tool request.\");\n const definition = Object.hasOwn(\n input.options.frontendTools ?? {},\n name,\n )\n ? input.options.frontendTools?.[name]\n : undefined;\n if (!input.options.application || !definition)\n throw new Error(\"This application action is unavailable.\");\n const args = message.args;\n if (!args || typeof args !== \"object\" || Array.isArray(args))\n throw new Error(\"Invalid application action arguments.\");\n const signature = JSON.stringify({ name, args });\n const prior = calls.get(toolCallId);\n if (prior && prior.signature !== signature)\n throw new Error(\"This tool call ID was already used.\");\n const result =\n prior?.result ??\n Promise.resolve().then(() =>\n definition.execute(args as Record<string, unknown>, {\n toolCallId,\n abortSignal: input.signal,\n }),\n );\n if (!prior) {\n if (calls.size >= 200)\n throw new Error(\"Start a new application chat.\");\n calls.set(toolCallId, { signature, result });\n }\n input.reply({\n type: \"omni-chat:tool-response\",\n requestId: message.requestId,\n toolCallId,\n result: boundedJson((await result) ?? null, 12000),\n });\n }\n } catch (error) {\n input.reply({\n type:\n message.type === \"omni-chat:application-request\"\n ? \"omni-chat:application-response\"\n : \"omni-chat:tool-response\",\n requestId: message.requestId,\n toolCallId: message.toolCallId,\n error:\n error instanceof Error\n ? error.message\n : \"The application action failed.\",\n });\n }\n };\n}\n","/** Scope each hosted frame independently; application chats have no deployment. */\nexport type HostedChatScope =\n | { deploymentId: string; chatId?: never }\n | { chatId: string; deploymentId?: never };\n\nexport function hostedChatId(scope: HostedChatScope) {\n return scope.deploymentId ?? scope.chatId;\n}\n\nexport function matchesHostedChatScope(\n message: Record<string, unknown> | null | undefined,\n scope: HostedChatScope,\n) {\n return scope.deploymentId !== undefined\n ? message?.deploymentId === scope.deploymentId &&\n message.chatId === undefined\n : message?.chatId === scope.chatId && message.deploymentId === undefined;\n}\n","import {\n createApplicationMessageHandler,\n type OmniApplicationOptions,\n} from \"./application\";\nimport {\n matchesHostedChatScope,\n type HostedChatScope,\n} from \"../../../lib/assistant/application-chat/bridge-scope\";\nimport type { OmniChatEmbed, OmniChatSession } from \"./embed\";\n\nexport interface OmniHostedChatOptions extends OmniApplicationOptions {\n baseUrl?: string;\n title?: string;\n onError?: (error: Error) => void;\n onRequestClose?: () => void;\n}\n\nexport class ChatSessionError extends Error {\n constructor(\n message: string,\n readonly status: number,\n ) {\n super(message);\n }\n}\n\n/** One frame broker for member application chat and published storefront chat. */\nexport function mountHostedChat(\n container: HTMLElement,\n options: OmniHostedChatOptions,\n target: {\n url: string;\n scope: HostedChatScope;\n mint?: (\n previousToken: string | undefined,\n visitorId: string | undefined,\n signal: AbortSignal,\n ) => Promise<OmniChatSession>;\n },\n): OmniChatEmbed {\n const document = container.ownerDocument;\n const host = document.defaultView;\n if (!host) throw new Error(\"A browser document is required to mount chat.\");\n const iframe = document.createElement(\"iframe\");\n iframe.src = target.url;\n iframe.title = options.title ?? \"OmniCommerce assistant\";\n iframe.referrerPolicy = \"strict-origin-when-cross-origin\";\n iframe.setAttribute(\n \"sandbox\",\n \"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox\",\n );\n Object.assign(iframe.style, {\n width: \"100%\",\n height: \"100%\",\n minHeight: \"320px\",\n border: \"0\",\n display: \"block\",\n });\n const chatOrigin = new URL(iframe.src).origin;\n let destroyed = false;\n let pending: Promise<OmniChatSession> | undefined;\n let previousToken: string | undefined;\n const controller = new AbortController();\n\n const applicationMessage = createApplicationMessageHandler({\n options,\n signal: controller.signal,\n reply: (message) => {\n if (!destroyed)\n iframe.contentWindow?.postMessage(\n { ...message, ...target.scope },\n chatOrigin,\n );\n },\n });\n const receive = (event: MessageEvent) => {\n if (\n destroyed ||\n event.source !== iframe.contentWindow ||\n event.origin !== chatOrigin ||\n !matchesHostedChatScope(event.data, target.scope)\n )\n return;\n if (\n event.data.type === \"omni-chat:application-request\" ||\n event.data.type === \"omni-chat:tool-request\"\n ) {\n void applicationMessage(event.data);\n return;\n }\n if (event.data.type === \"omni-chat:close-request\") {\n options.onRequestClose?.();\n return;\n }\n if (event.data.type !== \"omni-chat:session-request\" || !target.mint) return;\n const visitorId =\n typeof event.data.visitorId === \"string\"\n ? event.data.visitorId\n : undefined;\n pending ??= target.mint(previousToken, visitorId, controller.signal);\n void pending\n .then((session) => {\n if (destroyed) return;\n if (\n typeof session?.token !== \"string\" ||\n !session.token ||\n session.token.length > 4096 ||\n typeof session.threadId !== \"string\" ||\n !session.threadId ||\n !Number.isFinite(session.expiresIn) ||\n session.expiresIn <= 0\n )\n throw new Error(\"Invalid chat session response.\");\n previousToken = session.token;\n iframe.contentWindow?.postMessage(\n {\n type: \"omni-chat:session\",\n ...target.scope,\n session,\n ...(options.application ? { applicationEnabled: true } : {}),\n },\n chatOrigin,\n );\n })\n .catch((error: unknown) => {\n if (destroyed) return;\n const failure =\n error instanceof Error ? error : new Error(\"Could not open chat.\");\n if (\n failure instanceof ChatSessionError &&\n [401, 403].includes(failure.status)\n )\n previousToken = undefined;\n options.onError?.(failure);\n iframe.contentWindow?.postMessage(\n {\n type: \"omni-chat:session-error\",\n ...target.scope,\n error: failure.message,\n ...(options.application ? { applicationEnabled: true } : {}),\n },\n chatOrigin,\n );\n })\n .finally(() => {\n pending = undefined;\n });\n };\n host.addEventListener(\"message\", receive);\n container.append(iframe);\n return {\n iframe,\n focus() {\n if (destroyed) return;\n iframe.focus();\n iframe.contentWindow?.postMessage(\n {\n type: \"omni-chat:focus-composer\",\n ...target.scope,\n },\n chatOrigin,\n );\n },\n destroy() {\n if (destroyed) return;\n destroyed = true;\n controller.abort();\n previousToken = undefined;\n host.removeEventListener(\"message\", receive);\n iframe.remove();\n },\n };\n}\n","/** Exact hosted-chat origins, including trustworthy localhost development hosts. */\nexport function normalizeHostedChatOrigin(value: string): string {\n const url = new URL(value);\n const local =\n url.hostname === \"localhost\" ||\n url.hostname.endsWith(\".localhost\") ||\n url.hostname === \"127.0.0.1\";\n if (\n (url.protocol !== \"https:\" && !(url.protocol === \"http:\" && local)) ||\n url.username ||\n url.password ||\n url.pathname !== \"/\" ||\n url.search ||\n url.hash\n )\n throw new Error(\"Use an HTTPS origin, or HTTP localhost for development.\");\n return url.origin;\n}\n","import { normalizeHostedChatOrigin } from \"../../../lib/assistant/hosted-chat-origin\";\n\nexport function chatOrigin(baseUrl?: string): string {\n return normalizeHostedChatOrigin(baseUrl ?? \"https://omnicommerce.sg\");\n}\n","import { chatOrigin } from \"./chat-origin\";\nimport { mountHostedChat, type OmniHostedChatOptions } from \"./hosted-chat\";\n\n/** Application chat authenticates the viewer; it never uses a storefront deployment. */\nexport interface OmniApplicationChatOptions extends OmniHostedChatOptions {\n deploymentId?: never;\n /** Omit to use the member's currently selected organization. */\n organizationId?: string;\n /** Omit to use the default native assistant. */\n agentId?: string;\n /** Groups this application's conversation history; defaults to its origin. */\n appId?: string;\n}\n\nexport function getOmniApplicationChatUrl(\n options: OmniApplicationChatOptions,\n parentOrigin: string,\n chatId: string,\n) {\n if (\n !/^[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}$/i.test(chatId)\n )\n throw new Error(\"A valid application chat ID is required.\");\n const url = new URL(\"/sdk/application-chat\", chatOrigin(options.baseUrl));\n const parent = chatOrigin(parentOrigin);\n url.searchParams.set(\"parentOrigin\", parent);\n url.searchParams.set(\"chatId\", chatId);\n const appId = options.appId?.trim() ?? parent;\n if (!appId || appId.length > 200)\n throw new Error(\"appId must contain 1–200 characters.\");\n url.searchParams.set(\"appId\", appId);\n for (const key of [\"organizationId\", \"agentId\"] as const) {\n if (options[key] === undefined) continue;\n const value = options[key].trim();\n if (!value || value.length > 120)\n throw new Error(`${key} must contain 1–120 characters.`);\n url.searchParams.set(key, value);\n }\n return url.toString();\n}\n\nexport function createOmniApplicationChatEmbed(\n container: HTMLElement,\n options: OmniApplicationChatOptions,\n) {\n const host = container.ownerDocument.defaultView;\n if (!host) throw new Error(\"A browser document is required to mount chat.\");\n const chatId = host.crypto.randomUUID();\n return mountHostedChat(container, options, {\n url: getOmniApplicationChatUrl(options, host.location.origin, chatId),\n scope: { chatId },\n });\n}\n","import { mountHostedChat, ChatSessionError } from \"./hosted-chat\";\nimport { chatOrigin } from \"./chat-origin\";\nimport { type OmniApplicationOptions } from \"./application\";\nexport type {\n OmniFrontendTool,\n OmniChatApplication,\n OmniApplicationOptions,\n} from \"./application\";\n/** A hosted chat session. Keep its short-lived token in memory, never in iframe URLs. */\nexport {\n createOmniApplicationChatEmbed,\n getOmniApplicationChatUrl,\n type OmniApplicationChatOptions,\n} from \"./application-embed\";\nexport { createOmniChatWidget, type OmniChatWidgetOptions } from \"./widget\";\nexport {\n DEFAULT_WIDGET_OFFSET,\n MAX_WIDGET_OFFSET,\n type OmniChatWidgetPlacement,\n} from \"./widget-placement\";\nexport { getOmniChatEmbedCode, getOmniChatReactCode } from \"./embed-code\";\nexport interface OmniChatSession {\n token: string;\n threadId: string;\n expiresIn: number;\n}\nexport interface OmniChatEmbedOptions extends OmniApplicationOptions {\n deploymentId: string;\n baseUrl?: string;\n /** Optional authenticated session mint on the host application's server. */\n getSession?: () => Promise<OmniChatSession>;\n title?: string;\n onError?: (error: Error) => void;\n /** Floating widgets use this to close on Escape from the hosted chat. */\n onRequestClose?: () => void;\n}\nexport interface OmniChatEmbed {\n iframe: HTMLIFrameElement;\n /** Focus the hosted composer, including when reopening a retained chat. */\n focus(): void;\n destroy(): void;\n}\n\nexport function getOmniChatEmbedUrl(\n options: Pick<OmniChatEmbedOptions, \"baseUrl\" | \"deploymentId\">,\n parentOrigin?: string,\n): string {\n if (\n !/^[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}$/i.test(\n options.deploymentId,\n )\n )\n throw new Error(\"A valid chat deployment ID is required.\");\n const base = chatOrigin(options.baseUrl);\n const url = new URL(`/embed/${options.deploymentId}`, base);\n if (parentOrigin)\n url.searchParams.set(\"parentOrigin\", new URL(parentOrigin).origin);\n return url.toString();\n}\n\n/** Browser-only mounting; importing this entry point is safe during SSR. */\nexport function createOmniChatEmbed(\n container: HTMLElement,\n options: OmniChatEmbedOptions,\n): OmniChatEmbed {\n const host = container.ownerDocument.defaultView;\n if (!host) throw new Error(\"A browser document is required to mount chat.\");\n const url = getOmniChatEmbedUrl(options, host.location.origin);\n const chatOrigin = new URL(url).origin;\n return mountHostedChat(container, options, {\n url,\n scope: { deploymentId: options.deploymentId },\n mint: async (previousToken, visitorId, signal) => {\n if (options.getSession) return options.getSession();\n const response = await host.fetch(\n `${chatOrigin}/api/embed/${options.deploymentId}/session`,\n {\n method: \"POST\",\n credentials: \"include\",\n signal,\n headers: {\n \"Content-Type\": \"application/json\",\n ...(previousToken\n ? { Authorization: `Bearer ${previousToken}` }\n : {}),\n },\n body: JSON.stringify(\n visitorId &&\n /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(\n visitorId,\n )\n ? { visitorId }\n : {},\n ),\n },\n );\n const result = (await response.json()) as OmniChatSession & {\n error?: string;\n };\n if (!response.ok)\n throw new ChatSessionError(\n result.error ?? \"Could not open the chat session.\",\n response.status,\n );\n return result;\n },\n });\n}\n","\"use client\";\n\nimport {\n createContext,\n useEffect,\n useId,\n useRef,\n useState,\n type ReactNode,\n} from \"react\";\nimport { chatLayoutQuery, chatLayoutStyles } from \"./chat-layout-styles\";\n\nexport const ChatLayoutCloseContext = createContext<(() => void) | undefined>(\n undefined,\n);\n\n/** One mounted frame switches between an inline desktop panel and a native modal. */\nexport function ChatLayout({\n children,\n chat,\n className,\n}: {\n children: ReactNode;\n chat: ReactNode;\n className?: string;\n}) {\n const panel = useRef<HTMLDialogElement>(null);\n const launcher = useRef<HTMLButtonElement>(null);\n const restoreFocus = useRef(false);\n const [compact, setCompact] = useState<boolean | null>(null);\n const [open, setOpen] = useState(false);\n const id = useId();\n\n useEffect(() => {\n const media = window.matchMedia(chatLayoutQuery);\n const update = () => {\n setCompact(media.matches);\n // Entering the compact layout gives the application its space back.\n setOpen(false);\n };\n update();\n media.addEventListener(\"change\", update);\n return () => media.removeEventListener(\"change\", update);\n }, []);\n\n useEffect(() => {\n const dialog = panel.current;\n if (!dialog || compact === null) return;\n if (dialog.open) dialog.close();\n if (!compact) dialog.show();\n else if (open) dialog.showModal();\n else if (restoreFocus.current) launcher.current?.focus();\n restoreFocus.current = false;\n }, [compact, open]);\n\n useEffect(() => {\n const viewport = window.visualViewport;\n const dialog = panel.current!;\n const resize = () => {\n if (compact && open && viewport?.scale === 1) {\n dialog.style.setProperty(\n \"--omni-chat-viewport-top\",\n `${viewport.offsetTop}px`,\n );\n dialog.style.setProperty(\n \"--omni-chat-viewport-height\",\n `${viewport.height}px`,\n );\n } else {\n dialog.style.removeProperty(\"--omni-chat-viewport-top\");\n dialog.style.removeProperty(\"--omni-chat-viewport-height\");\n }\n };\n resize();\n viewport?.addEventListener(\"resize\", resize);\n viewport?.addEventListener(\"scroll\", resize);\n return () => {\n viewport?.removeEventListener(\"resize\", resize);\n viewport?.removeEventListener(\"scroll\", resize);\n };\n }, [compact, open]);\n\n const close = () => {\n if (!compact) return;\n restoreFocus.current = true;\n setOpen(false);\n };\n\n return (\n <div className={[\"omni-chat-layout\", className].filter(Boolean).join(\" \")}>\n <style>{chatLayoutStyles}</style>\n <div className=\"omni-chat-layout-content\">{children}</div>\n <button\n ref={launcher}\n type=\"button\"\n className=\"omni-chat-layout-launcher\"\n aria-label=\"Open assistant\"\n aria-controls={id}\n aria-expanded={compact === true && open}\n onClick={() => setOpen(true)}\n >\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.8\"\n aria-hidden=\"true\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n d=\"M21 11.5a8.5 8.5 0 0 1-12.3 7.6L3 21l1.9-5.7A8.5 8.5 0 1 1 21 11.5Z\"\n />\n </svg>\n </button>\n <dialog\n ref={panel}\n id={id}\n className=\"omni-chat-layout-panel\"\n aria-label=\"Application assistant\"\n onCancel={(event) => {\n event.preventDefault();\n close();\n }}\n >\n <div className=\"omni-chat-layout-toolbar\">\n <button type=\"button\" onClick={close}>\n ← Back to application\n </button>\n </div>\n <div className=\"omni-chat-layout-frame\">\n <ChatLayoutCloseContext.Provider value={close}>\n {chat}\n </ChatLayoutCloseContext.Provider>\n </div>\n </dialog>\n </div>\n );\n}\n","export const chatLayoutQuery = \"(max-width: 959px)\";\n\n/** Scoped host layout; the iframe continues to own all conversation styles. */\nexport const chatLayoutStyles = `\n.omni-chat-layout {\n display: grid; grid-template-columns: minmax(0, 1fr) clamp(360px, 30vw, 440px);\n height: 100dvh; min-height: 0; min-width: 0; overflow: hidden;\n}\n.omni-chat-layout-content { min-height: 0; min-width: 0; overflow: auto; }\n.omni-chat-layout-panel {\n position: relative; inset: auto; margin: 0; padding: 0; width: 100%; height: 100%;\n max-width: none; max-height: none; min-width: 0; min-height: 0; overflow: hidden;\n box-sizing: border-box; border: 0; border-inline-start: 1px solid #e4e4e7;\n background: white; color: #18181b;\n}\n.omni-chat-layout-panel[open] { display: flex; flex-direction: column; }\n.omni-chat-layout-panel:not([open]) { display: none; }\n.omni-chat-layout-frame { flex: 1; min-height: 0; min-width: 0; overflow: hidden; }\n.omni-chat-layout-launcher, .omni-chat-layout-toolbar { display: none; }\n.omni-chat-layout-launcher, .omni-chat-layout-toolbar button {\n font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;\n}\n.omni-chat-layout-launcher:focus-visible, .omni-chat-layout-toolbar button:focus-visible {\n outline: 3px solid #2563eb; outline-offset: 3px;\n}\n@media ${chatLayoutQuery} {\n .omni-chat-layout { grid-template-columns: minmax(0, 1fr); }\n .omni-chat-layout-launcher {\n display: flex; align-items: center; justify-content: center;\n position: fixed; right: calc(20px + env(safe-area-inset-right, 0px));\n bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 50;\n width: 56px; height: 56px; padding: 0; border: 0; border-radius: 50%;\n background: #18181b; color: white; box-shadow: 0 4px 16px #0003;\n }\n .omni-chat-layout-launcher svg { width: 24px; height: 24px; }\n .omni-chat-layout-launcher[aria-expanded=\"true\"] { visibility: hidden; }\n .omni-chat-layout-panel {\n position: fixed; top: var(--omni-chat-viewport-top, 0px); left: 0; right: 0;\n width: 100%; height: var(--omni-chat-viewport-height, 100dvh); border: 0;\n padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)\n env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);\n }\n .omni-chat-layout-panel::backdrop { background: #0005; }\n .omni-chat-layout-toolbar { display: flex; flex-shrink: 0; border-bottom: 1px solid #e4e4e7; }\n .omni-chat-layout-toolbar button {\n min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: inherit;\n font-size: 14px;\n }\n}\n`;\n"],"mappings":";;;;;;AAEA;AAAA,EACE,iBAAAA;AAAA,EACA;AAAA,EACA,aAAAC;AAAA,EACA,UAAAC;AAAA,OAGK;;;ACYP,SAAS,YAAY,OAAgB,SAA0B;AAC7D,QAAM,UAAU,KAAK,UAAU,KAAK;AACpC,MACE,OAAO,YAAY,YACnB,IAAI,YAAY,EAAE,OAAO,OAAO,EAAE,SAAS,WAC3C,8BAA8B,KAAK,OAAO;AAE1C,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO,KAAK,MAAM,OAAO;AAC3B;AAEO,SAAS,gCAAgC,OAI7C;AAED,QAAM,QAAQ,oBAAI,IAGhB;AACF,SAAO,OAAO,YAAqC;AACjD,QAAI,OAAO,QAAQ,cAAc,YAAY,QAAQ,UAAU,SAAS;AACtE;AACF,QAAI;AACF,UAAI,QAAQ,SAAS,iCAAiC;AACpD,cAAM,cAAc,MAAM,QAAQ;AAClC,cAAM,MAAM;AAAA,UACV,MAAM;AAAA,UACN,WAAW,QAAQ;AAAA,UACnB,aAAa,cACT;AAAA,YACE;AAAA,cACE,MAAM,YAAY;AAAA,cAClB,aAAa,YAAY;AAAA,cACzB,SAAU,MAAM,YAAY,WAAW,KAAM;AAAA,cAC7C,OAAO,OAAO,QAAQ,MAAM,QAAQ,iBAAiB,CAAC,CAAC,EAAE;AAAA,gBACvD,CAAC,CAAC,MAAM,UAAU,OAAO;AAAA,kBACvB;AAAA,kBACA,aAAa,WAAW;AAAA,kBACxB,YAAY,WAAW;AAAA,gBACzB;AAAA,cACF;AAAA,YACF;AAAA,YACA;AAAA,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AAAA,WAAU,MAAM;AACd,QAAI,CAAC,UAAU,QAAS;AACxB,UAAM,gBAAgB;AAAA,MACpB;AAAA,MACA,SAAS,CAAC,UAAiB,UAAU,QAAQ,UAAU,KAAK;AAAA,MAC5D,gBAAgB,MAAM,UAAU,QAAQ,eAAe;AAAA,MACvD,OAAO;AAAA,MACP,GAAI,eACA;AAAA,QACE;AAAA,QACA,YAAY,mBACR,MAAM,UAAU,QAAQ,WAAY,IACpC;AAAA,MACN,IACA,EAAE,gBAAgB,SAAS,MAAM;AAAA,MACrC,IAAI,cAAc;AAChB,eAAO,UAAU,QAAQ;AAAA,MAC3B;AAAA,MACA,IAAI,gBAAgB;AAClB,eAAO,UAAU,QAAQ;AAAA,MAC3B;AAAA,IACF;AACA,UAAM,QACJ,kBAAkB,gBACd,oBAAoB,UAAU,SAAS,aAAa,IACpD,+BAA+B,UAAU,SAAS,aAAa;AACrE,UAAM,UAAU,MAAM;AACtB,WAAO,MAAM;AACX,YAAM,UAAU;AAChB,YAAM,QAAQ;AAAA,IAChB;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACD,EAAAA,WAAU,MAAM;AAEd,UAAM,UAAU,OAAO,aAAa;AACpC,QAAI,MAAM;AACR,YAAM,QAAQ,MAAM,YAClB,OAAO,YAAY,WAAW,GAAG,OAAO,OAAO;AAAA,EACrD,CAAC;AACD,SACE,gBAAAH;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL;AAAA,MACA,OAAO,EAAE,QAAQ,QAAQ,WAAW,KAAK,GAAG,MAAM;AAAA;AAAA,EACpD;AAEJ;","names":["createContext","useEffect","useRef","chatOrigin","chatOrigin","jsx","createContext","useRef","useEffect"]}
|
|
1
|
+
{"version":3,"sources":["../src/react.tsx","../src/application.ts","../../../lib/assistant/application-chat/bridge-scope.ts","../src/hosted-chat.ts","../../../lib/assistant/hosted-chat-origin.ts","../src/chat-origin.ts","../src/application-embed.ts","../src/embed.ts","../src/chat-layout.tsx","../src/chat-layout-styles.ts"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n useContext,\n useEffect,\n useRef,\n type CSSProperties,\n type ReactNode,\n} from \"react\";\nimport { createOmniChatEmbed, type OmniChatEmbedOptions } from \"./embed\";\nimport {\n createOmniApplicationChatEmbed,\n type OmniApplicationChatOptions,\n} from \"./application-embed\";\nimport { ChatLayout, ChatLayoutCloseContext } from \"./chat-layout\";\n\ntype OmniChatOptions = OmniChatEmbedOptions | OmniApplicationChatOptions;\nconst OmniChatContext = createContext<OmniChatOptions | null>(null);\nexport type OmniProviderProps = OmniChatOptions & { children: ReactNode };\n\nexport function OmniProvider({ children, ...options }: OmniProviderProps) {\n return (\n <OmniChatContext.Provider value={options}>\n {children}\n </OmniChatContext.Provider>\n );\n}\nexport interface OmniChatProps {\n className?: string;\n style?: CSSProperties;\n title?: string;\n onRequestClose?: () => void;\n}\nexport interface OmniChatLayoutProps {\n children: ReactNode;\n className?: string;\n title?: string;\n}\n/** Full-height desktop docking; below 960px a launcher opens a full-height modal. */\nexport function OmniChatLayout({\n children,\n className,\n title,\n}: OmniChatLayoutProps) {\n return (\n <ChatLayout\n className={className}\n chat={<OmniChat title={title} style={{ minHeight: 0 }} />}\n >\n {children}\n </ChatLayout>\n );\n}\n/** The hosted assistant owns its styles and runtime, so the host needs no Tailwind or assistant-ui dependencies. */\nexport function OmniChat({\n className,\n style,\n title,\n onRequestClose,\n}: OmniChatProps) {\n const options = useContext(OmniChatContext);\n const closeLayout = useContext(ChatLayoutCloseContext);\n if (!options)\n throw new Error(\"OmniChat must be rendered inside OmniProvider.\");\n const container = useRef<HTMLDivElement>(null);\n const frame = useRef<HTMLIFrameElement | null>(null);\n const { baseUrl, deploymentId, onError, application, frontendTools } =\n options;\n const getSession = \"getSession\" in options ? options.getSession : undefined;\n const { organizationId, agentId, appId, systemPrompt, tools } =\n options as OmniApplicationChatOptions;\n const requestClose = onRequestClose ?? closeLayout ?? options.onRequestClose;\n const callbacks = useRef({\n getSession,\n onError,\n application,\n frontendTools,\n requestClose,\n systemPrompt,\n tools,\n });\n useEffect(() => {\n callbacks.current = {\n getSession,\n onError,\n application,\n frontendTools,\n requestClose,\n systemPrompt,\n tools,\n };\n }, [\n getSession,\n onError,\n application,\n frontendTools,\n requestClose,\n systemPrompt,\n tools,\n ]);\n const hasSessionBroker = Boolean(getSession);\n const frameTitle = title ?? options.title;\n useEffect(() => {\n if (!container.current) return;\n const hostedOptions = {\n baseUrl,\n onError: (error: Error) => callbacks.current.onError?.(error),\n onRequestClose: () => callbacks.current.requestClose?.(),\n title: frameTitle,\n ...(deploymentId\n ? {\n deploymentId,\n getSession: hasSessionBroker\n ? () => callbacks.current.getSession!()\n : undefined,\n }\n : {\n organizationId,\n agentId,\n appId,\n }),\n get systemPrompt() {\n return callbacks.current.systemPrompt;\n },\n get tools() {\n return callbacks.current.tools;\n },\n get application() {\n return callbacks.current.application;\n },\n get frontendTools() {\n return callbacks.current.frontendTools;\n },\n };\n const embed =\n \"deploymentId\" in hostedOptions\n ? createOmniChatEmbed(container.current, hostedOptions)\n : createOmniApplicationChatEmbed(container.current, hostedOptions);\n frame.current = embed.iframe;\n return () => {\n frame.current = null;\n embed.destroy();\n };\n }, [\n baseUrl,\n deploymentId,\n organizationId,\n agentId,\n appId,\n frameTitle,\n hasSessionBroker,\n ]);\n useEffect(() => {\n // A bounded sidebar can override the inline default without replacing chat.\n const minimum = style?.minHeight ?? 320;\n if (frame.current)\n frame.current.style.minHeight =\n typeof minimum === \"number\" ? `${minimum}px` : minimum;\n });\n return (\n <div\n ref={container}\n className={className}\n style={{ height: \"100%\", minHeight: 320, ...style }}\n />\n );\n}\nexport type {\n OmniFrontendTool,\n OmniChatApplication,\n OmniApplicationOptions,\n OmniChatEmbedOptions,\n OmniChatSession,\n OmniApplicationChatOptions,\n} from \"./embed\";\n","/** Host-defined actions execute inside the application, never on the assistant server. */\nexport interface OmniFrontendTool {\n description: string;\n parameters: Record<string, unknown>;\n execute: (\n args: Record<string, unknown>,\n context: { toolCallId: string; abortSignal: AbortSignal },\n ) => unknown | Promise<unknown>;\n}\nexport interface OmniChatApplication {\n name: string;\n description: string;\n /** Return a small, explicitly selected snapshot. Do not include secrets. */\n getContext: () => unknown | Promise<unknown>;\n}\nexport interface OmniApplicationOptions {\n application?: OmniChatApplication;\n /** Names must start with app_; use array arguments for actions with multiple targets. */\n frontendTools?: Record<string, OmniFrontendTool>;\n}\n\nfunction boundedJson(value: unknown, maximum: number): unknown {\n const encoded = JSON.stringify(value);\n if (\n typeof encoded !== \"string\" ||\n new TextEncoder().encode(encoded).length > maximum ||\n /data:[^\"\\s]{0,100};base64,/i.test(encoded)\n )\n throw new Error(\n \"Application data must be bounded JSON without base64 payloads.\",\n );\n return JSON.parse(encoded);\n}\n\nexport function createApplicationMessageHandler(input: {\n options: OmniApplicationOptions;\n assistant?: () => { systemPrompt?: string; tools?: readonly string[] };\n signal: AbortSignal;\n reply: (message: Record<string, unknown>) => void;\n}) {\n // A repeated parked call reuses its result instead of applying an action twice.\n const calls = new Map<\n string,\n { signature: string; result: Promise<unknown> }\n >();\n return async (message: Record<string, unknown>) => {\n if (typeof message.requestId !== \"string\" || message.requestId.length > 200)\n return;\n try {\n if (message.type === \"omni-chat:application-request\") {\n const application = input.options.application;\n input.reply({\n type: \"omni-chat:application-response\",\n requestId: message.requestId,\n ...(input.assistant\n ? { assistant: boundedJson(input.assistant(), 65536) }\n : {}),\n application: application\n ? boundedJson(\n {\n name: application.name,\n description: application.description,\n context: (await application.getContext()) ?? null,\n tools: Object.entries(input.options.frontendTools ?? {}).map(\n ([name, definition]) => ({\n name,\n description: definition.description,\n parameters: definition.parameters,\n }),\n ),\n },\n 65536,\n )\n : undefined,\n });\n } else if (message.type === \"omni-chat:tool-request\") {\n const name = message.toolName;\n const toolCallId = message.toolCallId;\n if (\n typeof name !== \"string\" ||\n !/^app_[a-z][a-z0-9_]{0,59}$/.test(name) ||\n typeof toolCallId !== \"string\" ||\n !toolCallId ||\n toolCallId.length > 200\n )\n throw new Error(\"Invalid application tool request.\");\n const definition = Object.hasOwn(\n input.options.frontendTools ?? {},\n name,\n )\n ? input.options.frontendTools?.[name]\n : undefined;\n if (!input.options.application || !definition)\n throw new Error(\"This application action is unavailable.\");\n const args = message.args;\n if (!args || typeof args !== \"object\" || Array.isArray(args))\n throw new Error(\"Invalid application action arguments.\");\n const signature = JSON.stringify({ name, args });\n const prior = calls.get(toolCallId);\n if (prior && prior.signature !== signature)\n throw new Error(\"This tool call ID was already used.\");\n const result =\n prior?.result ??\n Promise.resolve().then(() =>\n definition.execute(args as Record<string, unknown>, {\n toolCallId,\n abortSignal: input.signal,\n }),\n );\n if (!prior) {\n if (calls.size >= 200)\n throw new Error(\"Start a new application chat.\");\n calls.set(toolCallId, { signature, result });\n }\n input.reply({\n type: \"omni-chat:tool-response\",\n requestId: message.requestId,\n toolCallId,\n result: boundedJson((await result) ?? null, 12000),\n });\n }\n } catch (error) {\n input.reply({\n type:\n message.type === \"omni-chat:application-request\"\n ? \"omni-chat:application-response\"\n : \"omni-chat:tool-response\",\n requestId: message.requestId,\n toolCallId: message.toolCallId,\n error:\n error instanceof Error\n ? error.message\n : \"The application action failed.\",\n });\n }\n };\n}\n","/** Scope each hosted frame independently; application chats have no deployment. */\nexport type HostedChatScope =\n | { deploymentId: string; chatId?: never }\n | { chatId: string; deploymentId?: never };\n\nexport function hostedChatId(scope: HostedChatScope) {\n return scope.deploymentId ?? scope.chatId;\n}\n\nexport function matchesHostedChatScope(\n message: Record<string, unknown> | null | undefined,\n scope: HostedChatScope,\n) {\n return scope.deploymentId !== undefined\n ? message?.deploymentId === scope.deploymentId &&\n message.chatId === undefined\n : message?.chatId === scope.chatId && message.deploymentId === undefined;\n}\n","import {\n createApplicationMessageHandler,\n type OmniApplicationOptions,\n} from \"./application\";\nimport {\n matchesHostedChatScope,\n type HostedChatScope,\n} from \"../../../lib/assistant/application-chat/bridge-scope\";\nimport type { OmniChatEmbed, OmniChatSession } from \"./embed\";\n\nexport interface OmniHostedChatOptions extends OmniApplicationOptions {\n baseUrl?: string;\n title?: string;\n onError?: (error: Error) => void;\n onRequestClose?: () => void;\n}\n\nexport class ChatSessionError extends Error {\n constructor(\n message: string,\n readonly status: number,\n ) {\n super(message);\n }\n}\n\n/** One frame broker for member application chat and published storefront chat. */\nexport function mountHostedChat(\n container: HTMLElement,\n options: OmniHostedChatOptions,\n target: {\n url: string;\n scope: HostedChatScope;\n assistant?: () => { systemPrompt?: string; tools?: readonly string[] };\n mint?: (\n previousToken: string | undefined,\n visitorId: string | undefined,\n signal: AbortSignal,\n ) => Promise<OmniChatSession>;\n },\n): OmniChatEmbed {\n const document = container.ownerDocument;\n const host = document.defaultView;\n if (!host) throw new Error(\"A browser document is required to mount chat.\");\n const iframe = document.createElement(\"iframe\");\n iframe.src = target.url;\n iframe.title = options.title ?? \"OmniCommerce assistant\";\n iframe.referrerPolicy = \"strict-origin-when-cross-origin\";\n iframe.setAttribute(\n \"sandbox\",\n \"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox\",\n );\n Object.assign(iframe.style, {\n width: \"100%\",\n height: \"100%\",\n minHeight: \"320px\",\n border: \"0\",\n display: \"block\",\n });\n const chatOrigin = new URL(iframe.src).origin;\n let destroyed = false;\n let pending: Promise<OmniChatSession> | undefined;\n let previousToken: string | undefined;\n const controller = new AbortController();\n\n const applicationMessage = createApplicationMessageHandler({\n options,\n assistant: target.assistant,\n signal: controller.signal,\n reply: (message) => {\n if (!destroyed)\n iframe.contentWindow?.postMessage(\n { ...message, ...target.scope },\n chatOrigin,\n );\n },\n });\n const receive = (event: MessageEvent) => {\n if (\n destroyed ||\n event.source !== iframe.contentWindow ||\n event.origin !== chatOrigin ||\n !matchesHostedChatScope(event.data, target.scope)\n )\n return;\n if (\n event.data.type === \"omni-chat:application-request\" ||\n event.data.type === \"omni-chat:tool-request\"\n ) {\n void applicationMessage(event.data);\n return;\n }\n if (event.data.type === \"omni-chat:close-request\") {\n options.onRequestClose?.();\n return;\n }\n if (event.data.type !== \"omni-chat:session-request\" || !target.mint) return;\n const visitorId =\n typeof event.data.visitorId === \"string\"\n ? event.data.visitorId\n : undefined;\n pending ??= target.mint(previousToken, visitorId, controller.signal);\n void pending\n .then((session) => {\n if (destroyed) return;\n if (\n typeof session?.token !== \"string\" ||\n !session.token ||\n session.token.length > 4096 ||\n typeof session.threadId !== \"string\" ||\n !session.threadId ||\n !Number.isFinite(session.expiresIn) ||\n session.expiresIn <= 0\n )\n throw new Error(\"Invalid chat session response.\");\n previousToken = session.token;\n iframe.contentWindow?.postMessage(\n {\n type: \"omni-chat:session\",\n ...target.scope,\n session,\n ...(options.application ? { applicationEnabled: true } : {}),\n },\n chatOrigin,\n );\n })\n .catch((error: unknown) => {\n if (destroyed) return;\n const failure =\n error instanceof Error ? error : new Error(\"Could not open chat.\");\n if (\n failure instanceof ChatSessionError &&\n [401, 403].includes(failure.status)\n )\n previousToken = undefined;\n options.onError?.(failure);\n iframe.contentWindow?.postMessage(\n {\n type: \"omni-chat:session-error\",\n ...target.scope,\n error: failure.message,\n ...(options.application ? { applicationEnabled: true } : {}),\n },\n chatOrigin,\n );\n })\n .finally(() => {\n pending = undefined;\n });\n };\n host.addEventListener(\"message\", receive);\n container.append(iframe);\n return {\n iframe,\n focus() {\n if (destroyed) return;\n iframe.focus();\n iframe.contentWindow?.postMessage(\n {\n type: \"omni-chat:focus-composer\",\n ...target.scope,\n },\n chatOrigin,\n );\n },\n destroy() {\n if (destroyed) return;\n destroyed = true;\n controller.abort();\n previousToken = undefined;\n host.removeEventListener(\"message\", receive);\n iframe.remove();\n },\n };\n}\n","/** Exact hosted-chat origins, including trustworthy localhost development hosts. */\nexport function normalizeHostedChatOrigin(value: string): string {\n const url = new URL(value);\n const local =\n url.hostname === \"localhost\" ||\n url.hostname.endsWith(\".localhost\") ||\n url.hostname === \"127.0.0.1\";\n if (\n (url.protocol !== \"https:\" && !(url.protocol === \"http:\" && local)) ||\n url.username ||\n url.password ||\n url.pathname !== \"/\" ||\n url.search ||\n url.hash\n )\n throw new Error(\"Use an HTTPS origin, or HTTP localhost for development.\");\n return url.origin;\n}\n","import { normalizeHostedChatOrigin } from \"../../../lib/assistant/hosted-chat-origin\";\n\nexport function chatOrigin(baseUrl?: string): string {\n return normalizeHostedChatOrigin(baseUrl ?? \"https://omnicommerce.sg\");\n}\n","import { chatOrigin } from \"./chat-origin\";\nimport { mountHostedChat, type OmniHostedChatOptions } from \"./hosted-chat\";\n\n/** Application chat authenticates the viewer; it never uses a storefront deployment. */\nexport interface OmniApplicationChatOptions extends OmniHostedChatOptions {\n deploymentId?: never;\n /** Omit to use the member's currently selected organization. */\n organizationId?: string;\n /** Omit to use the default native assistant. */\n agentId?: string;\n /** Groups this application's conversation history; defaults to its origin. */\n appId?: string;\n /** Application role instructions. Omit or clear to use the selected agent's prompt. */\n systemPrompt?: string;\n /** Backend tool/toolkit allowlist within the selected agent's permissions.\n * Omit to inherit; [] allows only registered frontendTools. */\n tools?: readonly string[];\n}\n\nexport function getOmniApplicationChatUrl(\n options: OmniApplicationChatOptions,\n parentOrigin: string,\n chatId: string,\n) {\n if (\n !/^[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}$/i.test(chatId)\n )\n throw new Error(\"A valid application chat ID is required.\");\n const url = new URL(\"/sdk/application-chat\", chatOrigin(options.baseUrl));\n const parent = chatOrigin(parentOrigin);\n url.searchParams.set(\"parentOrigin\", parent);\n url.searchParams.set(\"chatId\", chatId);\n const appId = options.appId?.trim() ?? parent;\n if (!appId || appId.length > 200)\n throw new Error(\"appId must contain 1–200 characters.\");\n url.searchParams.set(\"appId\", appId);\n for (const key of [\"organizationId\", \"agentId\"] as const) {\n if (options[key] === undefined) continue;\n const value = options[key].trim();\n if (!value || value.length > 120)\n throw new Error(`${key} must contain 1–120 characters.`);\n url.searchParams.set(key, value);\n }\n return url.toString();\n}\n\nexport function createOmniApplicationChatEmbed(\n container: HTMLElement,\n options: OmniApplicationChatOptions,\n) {\n const host = container.ownerDocument.defaultView;\n if (!host) throw new Error(\"A browser document is required to mount chat.\");\n const chatId = host.crypto.randomUUID();\n return mountHostedChat(container, options, {\n url: getOmniApplicationChatUrl(options, host.location.origin, chatId),\n scope: { chatId },\n assistant: () => ({\n ...(options.systemPrompt !== undefined\n ? { systemPrompt: options.systemPrompt }\n : {}),\n ...(options.tools !== undefined ? { tools: options.tools } : {}),\n }),\n });\n}\n","import { mountHostedChat, ChatSessionError } from \"./hosted-chat\";\nimport { chatOrigin } from \"./chat-origin\";\nimport { type OmniApplicationOptions } from \"./application\";\nexport type {\n OmniFrontendTool,\n OmniChatApplication,\n OmniApplicationOptions,\n} from \"./application\";\n/** A hosted chat session. Keep its short-lived token in memory, never in iframe URLs. */\nexport {\n createOmniApplicationChatEmbed,\n getOmniApplicationChatUrl,\n type OmniApplicationChatOptions,\n} from \"./application-embed\";\nexport { createOmniChatWidget, type OmniChatWidgetOptions } from \"./widget\";\nexport {\n DEFAULT_WIDGET_OFFSET,\n MAX_WIDGET_OFFSET,\n type OmniChatWidgetPlacement,\n} from \"./widget-placement\";\nexport { getOmniChatEmbedCode, getOmniChatReactCode } from \"./embed-code\";\nexport interface OmniChatSession {\n token: string;\n threadId: string;\n expiresIn: number;\n}\nexport interface OmniChatEmbedOptions extends OmniApplicationOptions {\n deploymentId: string;\n baseUrl?: string;\n /** Optional authenticated session mint on the host application's server. */\n getSession?: () => Promise<OmniChatSession>;\n title?: string;\n onError?: (error: Error) => void;\n /** Floating widgets use this to close on Escape from the hosted chat. */\n onRequestClose?: () => void;\n}\nexport interface OmniChatEmbed {\n iframe: HTMLIFrameElement;\n /** Focus the hosted composer, including when reopening a retained chat. */\n focus(): void;\n destroy(): void;\n}\n\nexport function getOmniChatEmbedUrl(\n options: Pick<OmniChatEmbedOptions, \"baseUrl\" | \"deploymentId\">,\n parentOrigin?: string,\n): string {\n if (\n !/^[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}$/i.test(\n options.deploymentId,\n )\n )\n throw new Error(\"A valid chat deployment ID is required.\");\n const base = chatOrigin(options.baseUrl);\n const url = new URL(`/embed/${options.deploymentId}`, base);\n if (parentOrigin)\n url.searchParams.set(\"parentOrigin\", new URL(parentOrigin).origin);\n return url.toString();\n}\n\n/** Browser-only mounting; importing this entry point is safe during SSR. */\nexport function createOmniChatEmbed(\n container: HTMLElement,\n options: OmniChatEmbedOptions,\n): OmniChatEmbed {\n const host = container.ownerDocument.defaultView;\n if (!host) throw new Error(\"A browser document is required to mount chat.\");\n const url = getOmniChatEmbedUrl(options, host.location.origin);\n const chatOrigin = new URL(url).origin;\n return mountHostedChat(container, options, {\n url,\n scope: { deploymentId: options.deploymentId },\n mint: async (previousToken, visitorId, signal) => {\n if (options.getSession) return options.getSession();\n const response = await host.fetch(\n `${chatOrigin}/api/embed/${options.deploymentId}/session`,\n {\n method: \"POST\",\n credentials: \"include\",\n signal,\n headers: {\n \"Content-Type\": \"application/json\",\n ...(previousToken\n ? { Authorization: `Bearer ${previousToken}` }\n : {}),\n },\n body: JSON.stringify(\n visitorId &&\n /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(\n visitorId,\n )\n ? { visitorId }\n : {},\n ),\n },\n );\n const result = (await response.json()) as OmniChatSession & {\n error?: string;\n };\n if (!response.ok)\n throw new ChatSessionError(\n result.error ?? \"Could not open the chat session.\",\n response.status,\n );\n return result;\n },\n });\n}\n","\"use client\";\n\nimport {\n createContext,\n useEffect,\n useId,\n useRef,\n useState,\n type ReactNode,\n} from \"react\";\nimport { chatLayoutQuery, chatLayoutStyles } from \"./chat-layout-styles\";\n\nexport const ChatLayoutCloseContext = createContext<(() => void) | undefined>(\n undefined,\n);\n\n/** One mounted frame switches between an inline desktop panel and a native modal. */\nexport function ChatLayout({\n children,\n chat,\n className,\n}: {\n children: ReactNode;\n chat: ReactNode;\n className?: string;\n}) {\n const panel = useRef<HTMLDialogElement>(null);\n const launcher = useRef<HTMLButtonElement>(null);\n const restoreFocus = useRef(false);\n const [compact, setCompact] = useState<boolean | null>(null);\n const [open, setOpen] = useState(false);\n const id = useId();\n\n useEffect(() => {\n const media = window.matchMedia(chatLayoutQuery);\n const update = () => {\n setCompact(media.matches);\n // Entering the compact layout gives the application its space back.\n setOpen(false);\n };\n update();\n media.addEventListener(\"change\", update);\n return () => media.removeEventListener(\"change\", update);\n }, []);\n\n useEffect(() => {\n const dialog = panel.current;\n if (!dialog || compact === null) return;\n if (dialog.open) dialog.close();\n if (!compact) dialog.show();\n else if (open) dialog.showModal();\n else if (restoreFocus.current) launcher.current?.focus();\n restoreFocus.current = false;\n }, [compact, open]);\n\n useEffect(() => {\n const viewport = window.visualViewport;\n const dialog = panel.current!;\n const resize = () => {\n if (compact && open && viewport?.scale === 1) {\n dialog.style.setProperty(\n \"--omni-chat-viewport-top\",\n `${viewport.offsetTop}px`,\n );\n dialog.style.setProperty(\n \"--omni-chat-viewport-height\",\n `${viewport.height}px`,\n );\n } else {\n dialog.style.removeProperty(\"--omni-chat-viewport-top\");\n dialog.style.removeProperty(\"--omni-chat-viewport-height\");\n }\n };\n resize();\n viewport?.addEventListener(\"resize\", resize);\n viewport?.addEventListener(\"scroll\", resize);\n return () => {\n viewport?.removeEventListener(\"resize\", resize);\n viewport?.removeEventListener(\"scroll\", resize);\n };\n }, [compact, open]);\n\n const close = () => {\n if (!compact) return;\n restoreFocus.current = true;\n setOpen(false);\n };\n\n return (\n <div className={[\"omni-chat-layout\", className].filter(Boolean).join(\" \")}>\n <style>{chatLayoutStyles}</style>\n <div className=\"omni-chat-layout-content\">{children}</div>\n <button\n ref={launcher}\n type=\"button\"\n className=\"omni-chat-layout-launcher\"\n aria-label=\"Open assistant\"\n aria-controls={id}\n aria-expanded={compact === true && open}\n onClick={() => setOpen(true)}\n >\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.8\"\n aria-hidden=\"true\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n d=\"M21 11.5a8.5 8.5 0 0 1-12.3 7.6L3 21l1.9-5.7A8.5 8.5 0 1 1 21 11.5Z\"\n />\n </svg>\n </button>\n <dialog\n ref={panel}\n id={id}\n className=\"omni-chat-layout-panel\"\n aria-label=\"Application assistant\"\n onCancel={(event) => {\n event.preventDefault();\n close();\n }}\n >\n <div className=\"omni-chat-layout-toolbar\">\n <button type=\"button\" onClick={close}>\n ← Back to application\n </button>\n </div>\n <div className=\"omni-chat-layout-frame\">\n <ChatLayoutCloseContext.Provider value={close}>\n {chat}\n </ChatLayoutCloseContext.Provider>\n </div>\n </dialog>\n </div>\n );\n}\n","export const chatLayoutQuery = \"(max-width: 959px)\";\n\n/** Scoped host layout; the iframe continues to own all conversation styles. */\nexport const chatLayoutStyles = `\n.omni-chat-layout {\n display: grid; grid-template-columns: minmax(0, 1fr) clamp(360px, 30vw, 440px);\n height: 100dvh; min-height: 0; min-width: 0; overflow: hidden;\n}\n.omni-chat-layout-content { min-height: 0; min-width: 0; overflow: auto; }\n.omni-chat-layout-panel {\n position: relative; inset: auto; margin: 0; padding: 0; width: 100%; height: 100%;\n max-width: none; max-height: none; min-width: 0; min-height: 0; overflow: hidden;\n box-sizing: border-box; border: 0; border-inline-start: 1px solid #e4e4e7;\n background: white; color: #18181b;\n}\n.omni-chat-layout-panel[open] { display: flex; flex-direction: column; }\n.omni-chat-layout-panel:not([open]) { display: none; }\n.omni-chat-layout-frame { flex: 1; min-height: 0; min-width: 0; overflow: hidden; }\n.omni-chat-layout-launcher, .omni-chat-layout-toolbar { display: none; }\n.omni-chat-layout-launcher, .omni-chat-layout-toolbar button {\n font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;\n}\n.omni-chat-layout-launcher:focus-visible, .omni-chat-layout-toolbar button:focus-visible {\n outline: 3px solid #2563eb; outline-offset: 3px;\n}\n@media ${chatLayoutQuery} {\n .omni-chat-layout { grid-template-columns: minmax(0, 1fr); }\n .omni-chat-layout-launcher {\n display: flex; align-items: center; justify-content: center;\n position: fixed; right: calc(20px + env(safe-area-inset-right, 0px));\n bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 50;\n width: 56px; height: 56px; padding: 0; border: 0; border-radius: 50%;\n background: #18181b; color: white; box-shadow: 0 4px 16px #0003;\n }\n .omni-chat-layout-launcher svg { width: 24px; height: 24px; }\n .omni-chat-layout-launcher[aria-expanded=\"true\"] { visibility: hidden; }\n .omni-chat-layout-panel {\n position: fixed; top: var(--omni-chat-viewport-top, 0px); left: 0; right: 0;\n width: 100%; height: var(--omni-chat-viewport-height, 100dvh); border: 0;\n padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)\n env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);\n }\n .omni-chat-layout-panel::backdrop { background: #0005; }\n .omni-chat-layout-toolbar { display: flex; flex-shrink: 0; border-bottom: 1px solid #e4e4e7; }\n .omni-chat-layout-toolbar button {\n min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: inherit;\n font-size: 14px;\n }\n}\n`;\n"],"mappings":";;;;;;AAEA;AAAA,EACE,iBAAAA;AAAA,EACA;AAAA,EACA,aAAAC;AAAA,EACA,UAAAC;AAAA,OAGK;;;ACYP,SAAS,YAAY,OAAgB,SAA0B;AAC7D,QAAM,UAAU,KAAK,UAAU,KAAK;AACpC,MACE,OAAO,YAAY,YACnB,IAAI,YAAY,EAAE,OAAO,OAAO,EAAE,SAAS,WAC3C,8BAA8B,KAAK,OAAO;AAE1C,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO,KAAK,MAAM,OAAO;AAC3B;AAEO,SAAS,gCAAgC,OAK7C;AAED,QAAM,QAAQ,oBAAI,IAGhB;AACF,SAAO,OAAO,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Q,WAAY,IACpC;AAAA,MACN,IACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACJ,IAAI,eAAe;AACjB,eAAO,UAAU,QAAQ;AAAA,MAC3B;AAAA,MACA,IAAI,QAAQ;AACV,eAAO,UAAU,QAAQ;AAAA,MAC3B;AAAA,MACA,IAAI,cAAc;AAChB,eAAO,UAAU,QAAQ;AAAA,MAC3B;AAAA,MACA,IAAI,gBAAgB;AAClB,eAAO,UAAU,QAAQ;AAAA,MAC3B;AAAA,IACF;AACA,UAAM,QACJ,kBAAkB,gBACd,oBAAoB,UAAU,SAAS,aAAa,IACpD,+BAA+B,UAAU,SAAS,aAAa;AACrE,UAAM,UAAU,MAAM;AACtB,WAAO,MAAM;AACX,YAAM,UAAU;AAChB,YAAM,QAAQ;AAAA,IAChB;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACD,EAAAA,WAAU,MAAM;AAEd,UAAM,UAAU,OAAO,aAAa;AACpC,QAAI,MAAM;AACR,YAAM,QAAQ,MAAM,YAClB,OAAO,YAAY,WAAW,GAAG,OAAO,OAAO;AAAA,EACrD,CAAC;AACD,SACE,gBAAAH;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL;AAAA,MACA,OAAO,EAAE,QAAQ,QAAQ,WAAW,KAAK,GAAG,MAAM;AAAA;AAAA,EACpD;AAEJ;","names":["createContext","useEffect","useRef","chatOrigin","chatOrigin","jsx","createContext","useRef","useEffect"]}
|