@omni-commerce/sdk 0.8.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -1
- package/dist/embed.cjs +506 -160
- package/dist/embed.cjs.map +1 -1
- package/dist/embed.d.cts +40 -5
- package/dist/embed.d.ts +40 -5
- package/dist/embed.global.js +58 -16
- package/dist/embed.global.js.map +1 -1
- package/dist/embed.js +503 -161
- package/dist/embed.js.map +1 -1
- package/dist/index.cjs +85 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19168 -20085
- package/dist/index.d.ts +19168 -20085
- package/dist/index.js +85 -9
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +373 -74
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +13 -4
- package/dist/react.d.ts +13 -4
- package/dist/react.js +380 -75
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/react.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react.tsx","../src/application.ts","../src/embed.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\";\n\nconst OmniChatContext = createContext<OmniChatEmbedOptions | null>(null);\nexport type OmniProviderProps = OmniChatEmbedOptions & { 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}\n/** The hosted assistant owns its styles and runtime, so the host needs no Tailwind or assistant-ui dependencies. */\nexport function OmniChat({ className, style, title }: OmniChatProps) {\n const options = useContext(OmniChatContext);\n if (!options)\n throw new Error(\"OmniChat must be rendered inside OmniProvider.\");\n const container = useRef<HTMLDivElement>(null);\n const {\n baseUrl,\n deploymentId,\n getSession,\n onError,\n application,\n frontendTools,\n } = options;\n const callbacks = useRef({ getSession, onError, application, frontendTools });\n useEffect(() => {\n callbacks.current = { getSession, onError, application, frontendTools };\n }, [getSession, onError, application, frontendTools]);\n const hasSessionBroker = Boolean(getSession);\n const frameTitle = title ?? options.title;\n useEffect(() => {\n if (!container.current) return;\n const embed = createOmniChatEmbed(container.current, {\n baseUrl,\n deploymentId,\n getSession: hasSessionBroker\n ? () => callbacks.current.getSession!()\n : undefined,\n onError: (error) => callbacks.current.onError?.(error),\n title: frameTitle,\n get application() {\n return callbacks.current.application;\n },\n get frontendTools() {\n return callbacks.current.frontendTools;\n },\n });\n return () => embed.destroy();\n }, [baseUrl, deploymentId, frameTitle, hasSessionBroker]);\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} 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","import {\n createApplicationMessageHandler,\n type OmniApplicationOptions,\n} 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 { createOmniChatWidget, type OmniChatWidgetOptions } from \"./widget\";\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 = new URL(options.baseUrl ?? \"https://omnicommerce.sg\");\n if (\n (base.protocol !== \"https:\" &&\n !(\n base.protocol === \"http:\" &&\n [\"localhost\", \"127.0.0.1\"].includes(base.hostname)\n )) ||\n base.username ||\n base.password ||\n base.pathname !== \"/\" ||\n base.search ||\n base.hash\n )\n throw new Error(\"Chat baseUrl must be an HTTPS origin, or HTTP localhost.\");\n const url = new URL(`/embed/${options.deploymentId}`, base.origin);\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 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 = getOmniChatEmbedUrl(options, host.location.origin);\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 mint = async (): Promise<OmniChatSession> => {\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: controller.signal,\n headers: {\n \"Content-Type\": \"application/json\",\n ...(previousToken\n ? { Authorization: `Bearer ${previousToken}` }\n : {}),\n },\n body: \"{}\",\n },\n );\n const result = (await response.json()) as OmniChatSession & {\n error?: string;\n };\n if (!response.ok) {\n // A rejected renewal must not keep Retry bound to an obsolete session.\n // The next mint still performs the deployment's full access checks.\n if (response.status === 401 || response.status === 403)\n previousToken = undefined;\n throw new Error(result.error ?? \"Could not open the chat session.\");\n }\n return result;\n };\n const applicationMessage = createApplicationMessageHandler({\n options,\n signal: controller.signal,\n reply: (message) => {\n if (!destroyed)\n iframe.contentWindow?.postMessage(\n { ...message, deploymentId: options.deploymentId },\n chatOrigin,\n );\n },\n });\n const receive = (event: MessageEvent) => {\n if (\n destroyed ||\n event.source !== iframe.contentWindow ||\n event.origin !== chatOrigin ||\n event.data?.deploymentId !== options.deploymentId\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\") return;\n pending ??= mint();\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 deploymentId: options.deploymentId,\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 options.onError?.(failure);\n iframe.contentWindow?.postMessage(\n {\n type: \"omni-chat:session-error\",\n deploymentId: options.deploymentId,\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 deploymentId: options.deploymentId,\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAOO;;;ACYP,SAAS,YAAY,OAA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A;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,gBAAY,qBAAO,EAAE,YAAY,SAAS,aAAa,cAAc,CAAC;AAC5E,8BAAU,MAAM;AACd,cAAU,UAAU,EAAE,YAAY,SAAS,aAAa,cAAc;AAAA,EACxE,GAAG,CAAC,YAAY,SAAS,aAAa,aAAa,CAAC;AACpD,QAAM,mBAAmB,QAAQ,UAAU;AAC3C,QAAM,aAAa,SAAS,QAAQ;AACpC,8BAAU,MAAM;AACd,QAAI,CAAC,UAAU,QAAS;AACxB,UAAM,QAAQ,oBAAoB,UAAU,SAAS;AAAA,MACnD;AAAA,MACA;AAAA,MACA,YAAY,mBACR,MAAM,UAAU,QAAQ,WAAY,IACpC;AAAA,MACJ,SAAS,CAAC,UAAU,UAAU,QAAQ,UAAU,KAAK;AAAA,MACrD,OAAO;AAAA,MACP,IAAI,cAAc;AAChB,eAAO,UAAU,QAAQ;AAAA,MAC3B;AAAA,MACA,IAAI,gBAAgB;AAClB,eAAO,UAAU,QAAQ;AAAA,MAC3B;AAAA,IACF,CAAC;AACD,WAAO,MAAM,MAAM,QAAQ;AAAA,EAC7B,GAAG,CAAC,SAAS,cAAc,YAAY,gBAAgB,CAAC;AACxD,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL;AAAA,MACA,OAAO,EAAE,QAAQ,QAAQ,WAAW,KAAK,GAAG,MAAM;AAAA;AAAA,EACpD;AAEJ;","names":[]}
|
|
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,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,UACF,IACA;AAAA,QACN,CAAC;AAAA,MACH,WAAW,QAAQ,SAAS,0BAA0B;AACpD,cAAM,OAAO,QAAQ;AACrB,cAAM,aAAa,QAAQ;AAC3B,YACE,OAAO,SAAS,YAChB,CAAC,6BAA6B,KAAK,IA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AM,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,+BAAU,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;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"]}
|
package/dist/react.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { CSSProperties, ReactNode } from 'react';
|
|
3
|
-
import { OmniChatEmbedOptions } from './embed.cjs';
|
|
3
|
+
import { OmniChatEmbedOptions, OmniApplicationChatOptions } from './embed.cjs';
|
|
4
4
|
export { OmniApplicationOptions, OmniChatApplication, OmniChatSession, OmniFrontendTool } from './embed.cjs';
|
|
5
5
|
|
|
6
|
-
type
|
|
6
|
+
type OmniChatOptions = OmniChatEmbedOptions | OmniApplicationChatOptions;
|
|
7
|
+
type OmniProviderProps = OmniChatOptions & {
|
|
7
8
|
children: ReactNode;
|
|
8
9
|
};
|
|
9
10
|
declare function OmniProvider({ children, ...options }: OmniProviderProps): react_jsx_runtime.JSX.Element;
|
|
@@ -11,8 +12,16 @@ interface OmniChatProps {
|
|
|
11
12
|
className?: string;
|
|
12
13
|
style?: CSSProperties;
|
|
13
14
|
title?: string;
|
|
15
|
+
onRequestClose?: () => void;
|
|
14
16
|
}
|
|
17
|
+
interface OmniChatLayoutProps {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
className?: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Full-height desktop docking; below 960px a launcher opens a full-height modal. */
|
|
23
|
+
declare function OmniChatLayout({ children, className, title, }: OmniChatLayoutProps): react_jsx_runtime.JSX.Element;
|
|
15
24
|
/** The hosted assistant owns its styles and runtime, so the host needs no Tailwind or assistant-ui dependencies. */
|
|
16
|
-
declare function OmniChat({ className, style, title }: OmniChatProps): react_jsx_runtime.JSX.Element;
|
|
25
|
+
declare function OmniChat({ className, style, title, onRequestClose, }: OmniChatProps): react_jsx_runtime.JSX.Element;
|
|
17
26
|
|
|
18
|
-
export { OmniChat, OmniChatEmbedOptions, type OmniChatProps, OmniProvider, type OmniProviderProps };
|
|
27
|
+
export { OmniApplicationChatOptions, OmniChat, OmniChatEmbedOptions, OmniChatLayout, type OmniChatLayoutProps, type OmniChatProps, OmniProvider, type OmniProviderProps };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { CSSProperties, ReactNode } from 'react';
|
|
3
|
-
import { OmniChatEmbedOptions } from './embed.js';
|
|
3
|
+
import { OmniChatEmbedOptions, OmniApplicationChatOptions } from './embed.js';
|
|
4
4
|
export { OmniApplicationOptions, OmniChatApplication, OmniChatSession, OmniFrontendTool } from './embed.js';
|
|
5
5
|
|
|
6
|
-
type
|
|
6
|
+
type OmniChatOptions = OmniChatEmbedOptions | OmniApplicationChatOptions;
|
|
7
|
+
type OmniProviderProps = OmniChatOptions & {
|
|
7
8
|
children: ReactNode;
|
|
8
9
|
};
|
|
9
10
|
declare function OmniProvider({ children, ...options }: OmniProviderProps): react_jsx_runtime.JSX.Element;
|
|
@@ -11,8 +12,16 @@ interface OmniChatProps {
|
|
|
11
12
|
className?: string;
|
|
12
13
|
style?: CSSProperties;
|
|
13
14
|
title?: string;
|
|
15
|
+
onRequestClose?: () => void;
|
|
14
16
|
}
|
|
17
|
+
interface OmniChatLayoutProps {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
className?: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Full-height desktop docking; below 960px a launcher opens a full-height modal. */
|
|
23
|
+
declare function OmniChatLayout({ children, className, title, }: OmniChatLayoutProps): react_jsx_runtime.JSX.Element;
|
|
15
24
|
/** The hosted assistant owns its styles and runtime, so the host needs no Tailwind or assistant-ui dependencies. */
|
|
16
|
-
declare function OmniChat({ className, style, title }: OmniChatProps): react_jsx_runtime.JSX.Element;
|
|
25
|
+
declare function OmniChat({ className, style, title, onRequestClose, }: OmniChatProps): react_jsx_runtime.JSX.Element;
|
|
17
26
|
|
|
18
|
-
export { OmniChat, OmniChatEmbedOptions, type OmniChatProps, OmniProvider, type OmniProviderProps };
|
|
27
|
+
export { OmniApplicationChatOptions, OmniChat, OmniChatEmbedOptions, OmniChatLayout, type OmniChatLayoutProps, type OmniChatProps, OmniProvider, type OmniProviderProps };
|