@carbon/ai-chat 1.16.0-rc.0 → 1.16.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.
@@ -418,6 +418,17 @@ let ChatContainer = class ChatContainer extends FlattenedConfigElement {
418
418
  return;
419
419
  }
420
420
  event.preventDefault();
421
+ if (detail.element) {
422
+ const element = detail.element;
423
+ element.setAttribute("slot", detail.slotName);
424
+ if (!detail.isInline) {
425
+ element.style.marginBlockStart = "1rem";
426
+ }
427
+ if (element.parentElement !== this) {
428
+ this.appendChild(element);
429
+ }
430
+ return;
431
+ }
421
432
  let host = this._pluginHosts.get(detail.slotName);
422
433
  if (!host) {
423
434
  host = document.createElement(detail.isInline ? "span" : "div");
@@ -428,8 +439,8 @@ let ChatContainer = class ChatContainer extends FlattenedConfigElement {
428
439
  this._pluginHosts.set(detail.slotName, host);
429
440
  this.appendChild(host);
430
441
  }
431
- if (host.innerHTML !== detail.html) {
432
- host.innerHTML = detail.html;
442
+ if (host.innerHTML !== (detail.html ?? "")) {
443
+ host.innerHTML = detail.html ?? "";
433
444
  }
434
445
  };
435
446
  this.handlePluginHostUpdate = event => {
@@ -1 +1 @@
1
- {"version":3,"file":"chat.index.js","sources":["../../../../src/web-components/cds-aichat-container/cds-aichat-internal.tsx","../../../../src/web-components/shared/flattenedPublicConfig.ts","../../../../src/web-components/shared/FlattenedConfigElement.ts","../../../../src/web-components/cds-aichat-container/index.ts"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\n/**\n * This component is mostly a pass-through. Its takes any properties passed into the ChatContainer\n * custom element and then renders the React Carbon AI Chat application while passing in properties.\n */\n\nimport { css, LitElement, PropertyValues } from \"lit\";\nimport { property } from \"lit/decorators.js\";\nimport React from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\n\nimport ChatAppEntry from \"../../chat/ChatAppEntry\";\nimport { carbonElement } from \"@carbon/ai-chat-components/es/globals/decorators/index.js\";\nimport { PublicConfig } from \"../../types/config/PublicConfig\";\nimport { ChatInstance } from \"../../types/instance/ChatInstance\";\nimport { DeepPartial } from \"../../types/utilities/DeepPartial\";\nimport { LanguagePack } from \"../../types/config/PublicConfig\";\nimport type {\n ServiceDesk,\n ServiceDeskFactoryParameters,\n ServiceDeskPublicConfig,\n} from \"../../types/config/ServiceDeskConfig\";\nimport type { MarkdownConfigContextValue } from \"../../chat/contexts/MarkdownConfigContext\";\n\n@carbonElement(\"cds-aichat-internal\")\nclass ChatContainerInternal extends LitElement {\n static styles = css`\n :host {\n display: block;\n width: 100%;\n height: 100%;\n box-sizing: border-box;\n z-index: var(--cds-aichat-z-index, auto);\n }\n `;\n\n /**\n * The config to use to load Carbon AI Chat. Note that the \"onLoad\" property is overridden by this component. If you\n * need to perform any actions after Carbon AI Chat been loaded, use the \"onBeforeRender\" or \"onAfterRender\" props.\n */\n @property({ type: Object })\n config: PublicConfig;\n\n /** Optional partial language pack overrides */\n @property({ type: Object })\n strings?: DeepPartial<LanguagePack>;\n\n /** A factory for the {@link ServiceDesk} integration. */\n @property({ attribute: false })\n serviceDeskFactory?: (\n parameters: ServiceDeskFactoryParameters,\n ) => Promise<ServiceDesk>;\n\n /** Public configuration for the service desk integration. */\n @property({ type: Object })\n serviceDesk?: ServiceDeskPublicConfig;\n\n /**\n * The optional HTML element to mount the chat to.\n */\n @property({ type: HTMLElement })\n element?: HTMLElement;\n\n /**\n * This function is called before the render function of Carbon AI Chat is called. This function can return a Promise\n * which will cause Carbon AI Chat to wait for it before rendering.\n */\n @property()\n onBeforeRender: (instance: ChatInstance) => Promise<void> | void;\n\n /**\n * This function is called after the render function of Carbon AI Chat is called. This function can return a Promise\n * which will cause Carbon AI Chat to wait for it before rendering.\n */\n @property()\n onAfterRender: (instance: ChatInstance) => Promise<void> | void;\n\n /**\n * Merged markdown config (framework-neutral `markdownItPlugins` plus\n * layer-specific `customRenderers`). Forwarded to the React app via\n * `MarkdownConfigContext` so {@link MarkdownWithDefaults} can portal\n * consumer overrides into the rendered markdown components.\n *\n * @experimental\n */\n @property({ attribute: false })\n markdown?: MarkdownConfigContextValue;\n\n firstUpdated() {\n if (this.config) {\n this.renderReactApp();\n }\n }\n\n updated(changedProperties: PropertyValues) {\n // Re-render React app when config or other properties change\n if (\n this.config &&\n (changedProperties.has(\"config\") ||\n changedProperties.has(\"strings\") ||\n changedProperties.has(\"serviceDeskFactory\") ||\n changedProperties.has(\"serviceDesk\") ||\n changedProperties.has(\"onBeforeRender\") ||\n changedProperties.has(\"onAfterRender\") ||\n changedProperties.has(\"element\") ||\n changedProperties.has(\"markdown\"))\n ) {\n this.renderReactApp();\n }\n }\n\n /**\n * Track if a previous React 18+ root was already created so we don't create a memory leak on re-renders.\n */\n root: Root;\n\n /**\n * Cache the container we hand to React so we can reuse it between renders.\n */\n reactContainer?: HTMLDivElement;\n\n async renderReactApp() {\n const container = this.ensureReactRoot();\n\n this.root.render(\n <ChatAppEntry\n config={this.config}\n strings={this.strings}\n serviceDeskFactory={this.serviceDeskFactory}\n serviceDesk={this.serviceDesk}\n onBeforeRender={this.onBeforeRender}\n onAfterRender={this.onAfterRender}\n container={container}\n element={this.element}\n markdown={this.markdown}\n />,\n );\n }\n\n private ensureReactRoot(): HTMLDivElement {\n if (!this.reactContainer) {\n const container = document.createElement(\"div\");\n container.classList.add(\"cds-aichat--react-app\");\n this.shadowRoot.appendChild(container);\n this.reactContainer = container;\n }\n\n // Make sure we only create one root and reuse it for prop updates.\n if (!this.root) {\n this.root = createRoot(this.reactContainer);\n }\n\n return this.reactContainer;\n }\n\n disconnectedCallback(): void {\n this.root?.unmount();\n super.disconnectedCallback();\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"cds-aichat-internal\": ChatContainerInternal;\n }\n}\n\nexport default ChatContainerInternal;\n","/*\n * Copyright IBM Corp. 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\n/**\n * Single source of truth for the {@link PublicConfig} fields that the\n * `cds-aichat-container` and `cds-aichat-custom-element` web components expose\n * as flattened top-level attributes/properties.\n *\n * Both components build their Lit reactive properties and reconstruct a\n * `PublicConfig` from this one table, so every config field is declared in\n * exactly one place. Adding a field to {@link PublicConfig} requires adding a\n * single entry here — the compile-time guard at the bottom of this file fails\n * the build until that happens.\n */\n\nimport type { ComplexAttributeConverter, PropertyDeclaration } from \"lit\";\n\nimport { PublicConfig } from \"../../types/config/PublicConfig\";\n\n/**\n * A single flattened-config field: a {@link PublicConfig} key plus the exact\n * Lit property options used to expose it on the web components.\n */\nexport interface FlattenedConfigFieldEntry {\n /** The {@link PublicConfig} key this entry maps to. */\n readonly name: keyof PublicConfig;\n /** The Lit property declaration options for this field. */\n readonly options: PropertyDeclaration;\n /**\n * When true, {@link resolveFlattenedConfig} skips this field in its generic\n * loop because its resolution rule is non-uniform. Only `aiEnabled` uses\n * this — it is resolved together with the synthetic `aiDisabled` opt-out.\n */\n readonly resolveManually?: boolean;\n}\n\n/**\n * Custom converter for the `ai-enabled` attribute so HTML authors can write\n * `ai-enabled=\"false\" | \"0\" | \"off\" | \"no\"`, while an absent attribute stays\n * `undefined` (so defaults apply further down the stack).\n */\nconst aiEnabledConverter: ComplexAttributeConverter<boolean | undefined> = {\n fromAttribute: (value: string | null) => {\n if (value === null) {\n return undefined; // attribute absent -> leave undefined to use defaults\n }\n const v = String(value).trim().toLowerCase();\n const falsey = v === \"false\" || v === \"0\" || v === \"off\" || v === \"no\";\n // Any presence that's not an explicit falsey string is treated as true.\n return !falsey;\n },\n};\n\n/**\n * Every {@link PublicConfig} field exposed as a flattened attribute/property\n * on the web components, with the exact Lit property options for each.\n *\n * `as const satisfies` keeps the `name` values as string literals (required by\n * the exhaustiveness guard below) while type-checking every entry.\n */\nexport const FLATTENED_PUBLIC_CONFIG_FIELDS = [\n { name: \"onError\", options: { attribute: false } },\n {\n name: \"openChatByDefault\",\n options: { type: Boolean, attribute: \"open-chat-by-default\" },\n },\n { name: \"disclaimer\", options: { type: Object } },\n {\n name: \"disableCustomElementMobileEnhancements\",\n options: {\n type: Boolean,\n attribute: \"disable-custom-element-mobile-enhancements\",\n },\n },\n { name: \"debug\", options: { type: Boolean } },\n {\n name: \"exposeServiceManagerForTesting\",\n options: { type: Boolean, attribute: \"expose-service-manager-for-testing\" },\n },\n {\n name: \"injectCarbonTheme\",\n options: { type: String, attribute: \"inject-carbon-theme\" },\n },\n {\n name: \"aiEnabled\",\n options: { attribute: \"ai-enabled\", converter: aiEnabledConverter },\n resolveManually: true,\n },\n { name: \"serviceDeskFactory\", options: { attribute: false } },\n {\n name: \"serviceDesk\",\n options: { type: Object, attribute: \"service-desk\" },\n },\n {\n name: \"shouldTakeFocusIfOpensAutomatically\",\n options: {\n type: Boolean,\n attribute: \"should-take-focus-if-opens-automatically\",\n },\n },\n { name: \"namespace\", options: { type: String } },\n {\n name: \"shouldSanitizeHTML\",\n options: { type: Boolean, attribute: \"should-sanitize-html\" },\n },\n { name: \"header\", options: { type: Object } },\n { name: \"history\", options: { type: Object } },\n { name: \"layout\", options: { type: Object } },\n { name: \"messaging\", options: { type: Object } },\n { name: \"isReadonly\", options: { type: Boolean, attribute: \"is-readonly\" } },\n {\n name: \"persistFeedback\",\n options: { type: Boolean, attribute: \"persist-feedback\" },\n },\n {\n name: \"assistantName\",\n options: { type: String, attribute: \"assistant-name\" },\n },\n // Note: no explicit `attribute` — Lit derives `assistantavatarurl`.\n { name: \"assistantAvatarUrl\", options: { type: String } },\n { name: \"locale\", options: { type: String } },\n { name: \"homescreen\", options: { type: Object } },\n { name: \"launcher\", options: { type: Object } },\n { name: \"input\", options: { type: Object } },\n { name: \"upload\", options: { attribute: false, type: Object } },\n { name: \"strings\", options: { type: Object } },\n { name: \"keyboardShortcuts\", options: { type: Object } },\n { name: \"markdown\", options: { attribute: false } },\n] as const satisfies readonly FlattenedConfigFieldEntry[];\n\n/**\n * The shape consumed by {@link resolveFlattenedConfig}: any flattened\n * {@link PublicConfig} field, plus the base `config` object and the synthetic\n * `aiDisabled` opt-out. Both web components structurally satisfy this.\n */\nexport interface FlattenedConfigSource extends Partial<PublicConfig> {\n /** Base config object; flattened fields override individual keys on it. */\n config?: PublicConfig;\n /** Synthetic opt-out attribute; when true it forces `aiEnabled` to false. */\n aiDisabled?: boolean;\n}\n\n/**\n * Builds a {@link PublicConfig} from a flattened source by layering each\n * defined flattened field over the base `config` object.\n *\n * Pure and DOM-free so it can be unit tested directly.\n *\n * @param source - The web component (or any object) carrying flattened fields.\n * @returns The reconstructed `PublicConfig`.\n */\nexport function resolveFlattenedConfig(\n source: FlattenedConfigSource,\n): PublicConfig {\n const resolved: PublicConfig = { ...(source.config ?? {}) };\n\n for (const field of FLATTENED_PUBLIC_CONFIG_FIELDS) {\n // aiEnabled is resolved together with aiDisabled below.\n if (\"resolveManually\" in field && field.resolveManually) {\n continue;\n }\n const value = source[field.name];\n if (value !== undefined) {\n (resolved as Record<string, unknown>)[field.name] = value;\n }\n }\n\n // aiEnabled / aiDisabled precedence is non-uniform: an explicit aiDisabled\n // attribute always wins over ai-enabled.\n if (source.aiDisabled === true) {\n resolved.aiEnabled = false;\n } else if (source.aiEnabled !== undefined) {\n resolved.aiEnabled = source.aiEnabled;\n }\n\n return resolved;\n}\n\n/**\n * Compile-time exhaustiveness guard.\n *\n * `_AssertTableCoversPublicConfig` fails to compile unless the set of field\n * names in {@link FLATTENED_PUBLIC_CONFIG_FIELDS} is exactly `keyof\n * PublicConfig`. Adding a field to {@link PublicConfig} without adding it to\n * the table — or vice versa — breaks the build here.\n */\ntype Equals<A, B> =\n (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2\n ? true\n : false;\ntype Expect<T extends true> = T;\ntype FlattenedFieldName =\n (typeof FLATTENED_PUBLIC_CONFIG_FIELDS)[number][\"name\"];\n\n// The `_` prefix matches the lint config's varsIgnorePattern; this alias only\n// exists to be type-checked.\ntype _AssertTableCoversPublicConfig = Expect<\n Equals<FlattenedFieldName, keyof PublicConfig>\n>;\n","/*\n * Copyright IBM Corp. 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\n/**\n * Shared Lit base class for the web components that expose a flattened\n * {@link PublicConfig} surface (`cds-aichat-container` and\n * `cds-aichat-custom-element`).\n *\n * It contributes every flattened reactive property from the single\n * {@link FLATTENED_PUBLIC_CONFIG_FIELDS} table and derives `resolvedConfig`\n * from that same table, so each config field is defined in exactly one place.\n */\n\nimport { LitElement } from \"lit\";\nimport type { PropertyDeclaration, PropertyDeclarations } from \"lit\";\n\nimport { PublicConfig } from \"../../types/config/PublicConfig\";\nimport {\n FLATTENED_PUBLIC_CONFIG_FIELDS,\n resolveFlattenedConfig,\n} from \"./flattenedPublicConfig\";\n\n/**\n * Builds the Lit `static properties` object from the shared field table plus\n * the synthetic `config` (base config object) and `aiDisabled` (opt-out)\n * properties.\n */\nfunction buildFlattenedProperties(): PropertyDeclarations {\n const properties: Record<string, PropertyDeclaration> = {\n config: { attribute: false, type: Object },\n aiDisabled: { type: Boolean, attribute: \"ai-disabled\" },\n };\n for (const field of FLATTENED_PUBLIC_CONFIG_FIELDS) {\n properties[field.name] = field.options;\n }\n return properties;\n}\n\n/**\n * Declaration merging gives the instance typed access to `this.history`,\n * `this.debug`, ... without re-listing every {@link PublicConfig} field and\n * without emitting any runtime class field (so nothing shadows the accessors\n * Lit installs from `static properties`).\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\ninterface FlattenedConfigElement extends Partial<PublicConfig> {}\n\n/**\n * Base class contributing all flattened `PublicConfig` reactive properties.\n * Not registered as a custom element — only the concrete subclasses are.\n */\nabstract class FlattenedConfigElement extends LitElement {\n static properties: PropertyDeclarations = buildFlattenedProperties();\n\n /** Base config object. Flattened properties layer on top of this. */\n config?: PublicConfig;\n\n /**\n * Optional explicit opt-out attribute. If present, it wins over `ai-enabled`.\n * Not a {@link PublicConfig} field — it resolves into `config.aiEnabled`.\n */\n aiDisabled?: boolean;\n\n /**\n * The {@link PublicConfig} reconstructed from `config` plus every defined\n * flattened property.\n */\n protected get resolvedConfig(): PublicConfig {\n return resolveFlattenedConfig(this);\n }\n}\n\nexport { FlattenedConfigElement };\n","/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\n/**\n * This is the exposed web component for a basic floating chat.\n */\n\nimport \"./cds-aichat-internal\";\n\nimport { html } from \"lit\";\nimport { property, state } from \"lit/decorators.js\";\n\nimport { carbonElement } from \"@carbon/ai-chat-components/es/globals/decorators/index.js\";\nimport { PublicConfig } from \"../../types/config/PublicConfig\";\nimport { FlattenedConfigElement } from \"../shared/FlattenedConfigElement\";\nimport { ChatInstance } from \"../../types/instance/ChatInstance\";\nimport {\n BusEventChunkUserDefinedResponse,\n BusEventCustomFooterSlot,\n BusEventType,\n BusEventUserDefinedResponse,\n BusEventViewChange,\n BusEventViewPreChange,\n} from \"../../types/events/eventBusTypes\";\nimport type {\n RenderCustomMessageFooterState,\n RenderUserDefinedState,\n WCMarkdown,\n WCRenderCustomMessageFooter,\n WCRenderUserDefinedResponse,\n} from \"../../types/component/ChatContainer\";\n\n/**\n * The cds-aichat-container managing creating slotted elements for user_defined responses, custom message footers, and writable elements.\n * It then passes that slotted content into cds-aichat-internal. That component will boot up the full chat application\n * and pass the slotted elements into their slots.\n */\n@carbonElement(\"cds-aichat-container\")\nclass ChatContainer extends FlattenedConfigElement {\n /**\n * The element to render to instead of the default float element.\n *\n * @internal\n */\n @property({ type: HTMLElement })\n element?: HTMLElement;\n\n /**\n * This function is called before the render function of Carbon AI Chat is called. This function can return a Promise\n * which will cause Carbon AI Chat to wait for it before rendering.\n *\n * Use it to capture the {@link ChatInstance} so you can call instance methods later.\n *\n * @example\n * ```ts\n * const onBeforeRender = (instance: ChatInstance) => {\n * this.instance = instance;\n * };\n * // <cds-aichat-container .onBeforeRender=${onBeforeRender}></cds-aichat-container>\n * ```\n */\n @property({ attribute: false })\n onBeforeRender: (instance: ChatInstance) => Promise<void> | void;\n\n /**\n * This function is called after the render function of Carbon AI Chat is called.\n *\n * Like `onBeforeRender`, it receives the {@link ChatInstance}; use it when you need the instance only after the\n * first render has completed.\n */\n @property({ attribute: false })\n onAfterRender: (instance: ChatInstance) => Promise<void> | void;\n\n /**\n * Called before a view change (the chat opening or closing). Async — return a\n * Promise to defer the view change until it resolves.\n *\n * This is an opt-in observation hook. Unlike `cds-aichat-custom-element`, the\n * container has no wrapping element to size, so no default visibility\n * behavior runs when this property is omitted.\n */\n @property()\n onViewPreChange?: (event: BusEventViewPreChange) => Promise<void> | void;\n\n /**\n * Called when a view change (the chat opening or closing) is complete.\n *\n * This is an opt-in observation hook. Unlike `cds-aichat-custom-element`, the\n * container has no wrapping element to size, so no default visibility\n * behavior runs when this property is omitted.\n */\n @property()\n onViewChange?: (event: BusEventViewChange, instance: ChatInstance) => void;\n\n /**\n * Optional callback to render user defined responses. When provided, the library manages all event listening,\n * slot tracking, streaming state, and element lifecycle. The callback receives the accumulated state and should\n * return an HTMLElement or null.\n *\n * When this property is not set, the existing event + manual slot approach continues to work.\n */\n @property({ attribute: false })\n renderUserDefinedResponse?: WCRenderUserDefinedResponse;\n\n /**\n * Optional callback to render custom message footers. When provided, the library manages all event listening,\n * slot tracking, and element lifecycle. The callback receives the accumulated state and should\n * return an HTMLElement or null.\n *\n * When this property is not set, the existing event + manual slot approach continues to work.\n */\n @property({ attribute: false })\n renderCustomMessageFooter?: WCRenderCustomMessageFooter;\n\n // markdown is declared on the FlattenedConfigElement base; the attributes\n // interface narrows its type.\n\n /**\n * The existing array of slot names for all user_defined components.\n */\n @state()\n _userDefinedSlotNames: string[] = [];\n\n /**\n * The existing array of slot names for all custom footers.\n */\n @state()\n _customFooterSlotNames: string[] = [];\n\n /**\n * The existing array of slot names for all writeable elements.\n */\n @state()\n _writeableElementSlots: string[] = [];\n\n /**\n * Active slot names for markdown-plugin output hosted at this element.\n * Populated when this element takes over from the markdown element by\n * accepting the host-mount event; drained when the matching unmount\n * event fires.\n */\n @state()\n _pluginSlotNames: string[] = [];\n\n /**\n * Page-level host elements created for plugin-output slots, keyed by slot\n * name. Created in this element's outer light DOM so consumer-loaded\n * stylesheets (e.g. KaTeX) reach the rendered HTML normally.\n */\n private _pluginHosts: Map<string, HTMLElement> = new Map();\n\n /**\n * The chat instance.\n */\n @state()\n _instance: ChatInstance;\n\n /**\n * Accumulated state per slot for user_defined responses when renderUserDefinedResponse is provided.\n */\n @state()\n _userDefinedStateBySlot: Record<string, RenderUserDefinedState> = {};\n\n /**\n * Accumulated state per slot for custom message footers when renderCustomMessageFooter is provided.\n */\n @state()\n _customFooterStateBySlot: Record<string, RenderCustomMessageFooterState> = {};\n\n /**\n * Tracks the wrapper elements created by the callback rendering path.\n */\n private _callbackElements = new Map<string, HTMLElement>();\n\n /**\n * Tracks the wrapper elements created by the custom-footer callback rendering path.\n */\n private _callbackFooterElements = new Map<string, HTMLElement>();\n\n /**\n * Adds the slot attribute to the element for the user_defined response type and then injects it into the component by\n * updating this._userDefinedSlotNames;\n */\n userDefinedHandler = (\n event: BusEventUserDefinedResponse | BusEventChunkUserDefinedResponse,\n ) => {\n // This element already has `slot` as an attribute.\n const { slot } = event.data;\n if (!this._userDefinedSlotNames.includes(slot)) {\n this._userDefinedSlotNames = [...this._userDefinedSlotNames, slot];\n }\n };\n\n /**\n * Adds the slot attribute to the element for the custom_footer_slot type and then injects it into the component by\n * updating this._customFooterSlotNames;\n */\n customFooterHandler = (event: BusEventCustomFooterSlot) => {\n // This element already has `slotName` as an attribute.\n const { slotName } = event.data;\n if (!this._customFooterSlotNames.includes(slotName)) {\n this._customFooterSlotNames = [...this._customFooterSlotNames, slotName];\n }\n };\n\n /**\n * Enhanced handler for CUSTOM_FOOTER_SLOT when the renderCustomMessageFooter callback is provided.\n * Tracks both slot names and the full per-slot state used by the callback rendering path.\n */\n private enhancedCustomFooterHandler = (event: BusEventCustomFooterSlot) => {\n const { slotName, message, messageItem, additionalData } = event.data;\n if (!this._customFooterSlotNames.includes(slotName)) {\n this._customFooterSlotNames = [...this._customFooterSlotNames, slotName];\n }\n this._customFooterStateBySlot = {\n ...this._customFooterStateBySlot,\n [slotName]: {\n slotName,\n message,\n messageItem,\n additionalData: additionalData as Record<string, unknown> | undefined,\n },\n };\n };\n\n /**\n * Enhanced handler for USER_DEFINED_RESPONSE when renderUserDefinedResponse callback is provided.\n * Tracks both slot names and full message state per slot.\n */\n private enhancedUserDefinedHandler = (event: BusEventUserDefinedResponse) => {\n const { slot } = event.data;\n if (!this._userDefinedSlotNames.includes(slot)) {\n this._userDefinedSlotNames = [...this._userDefinedSlotNames, slot];\n }\n this._userDefinedStateBySlot = {\n ...this._userDefinedStateBySlot,\n [slot]: {\n fullMessage: event.data.fullMessage,\n messageItem: event.data.message,\n state: event.data.state,\n },\n };\n };\n\n /**\n * Enhanced handler for CHUNK_USER_DEFINED_RESPONSE when renderUserDefinedResponse callback is provided.\n * Handles both complete_item and partial_item chunks, accumulating state per slot.\n */\n private enhancedUserDefinedChunkHandler = (\n event: BusEventChunkUserDefinedResponse,\n ) => {\n const { slot, chunk } = event.data;\n if (!this._userDefinedSlotNames.includes(slot)) {\n this._userDefinedSlotNames = [...this._userDefinedSlotNames, slot];\n }\n\n if (\"complete_item\" in chunk) {\n this._userDefinedStateBySlot = {\n ...this._userDefinedStateBySlot,\n [slot]: { messageItem: chunk.complete_item },\n };\n } else if (\"partial_item\" in chunk) {\n const existing = this._userDefinedStateBySlot[slot];\n this._userDefinedStateBySlot = {\n ...this._userDefinedStateBySlot,\n [slot]: {\n ...existing,\n partialItems: [...(existing?.partialItems ?? []), chunk.partial_item],\n },\n };\n }\n };\n\n /**\n * Handles RESTART_CONVERSATION when the renderUserDefinedResponse and/or renderCustomMessageFooter\n * callback is provided. Clears all accumulated state and removes callback-rendered elements from the DOM.\n *\n * The custom-footer cleanup is guarded by renderCustomMessageFooter so the legacy footer passthrough\n * path (which the host clears itself) is left untouched.\n */\n private restartHandler = () => {\n this._userDefinedStateBySlot = {};\n this._userDefinedSlotNames = [];\n for (const el of this._callbackElements.values()) {\n el.remove();\n }\n this._callbackElements.clear();\n\n if (this.renderCustomMessageFooter) {\n this._customFooterStateBySlot = {};\n this._customFooterSlotNames = [];\n for (const el of this._callbackFooterElements.values()) {\n el.remove();\n }\n this._callbackFooterElements.clear();\n }\n };\n\n /**\n * Synchronizes callback-rendered elements in the light DOM based on current state.\n * Called from render() when renderUserDefinedResponse is provided.\n */\n private syncCallbackRenderedElements() {\n for (const [slot, slotState] of Object.entries(\n this._userDefinedStateBySlot,\n )) {\n const newContent =\n this.renderUserDefinedResponse?.(slotState, this._instance) ?? null;\n\n if (!newContent) {\n const existing = this._callbackElements.get(slot);\n if (existing) {\n existing.remove();\n this._callbackElements.delete(slot);\n }\n continue;\n }\n\n let wrapper = this._callbackElements.get(slot);\n if (!wrapper) {\n wrapper = document.createElement(\"div\");\n wrapper.setAttribute(\"slot\", slot);\n this._callbackElements.set(slot, wrapper);\n this.appendChild(wrapper);\n }\n\n wrapper.replaceChildren(newContent);\n }\n\n // Clean up wrappers for slots that no longer exist in state\n for (const [slot, el] of this._callbackElements.entries()) {\n if (!(slot in this._userDefinedStateBySlot)) {\n el.remove();\n this._callbackElements.delete(slot);\n }\n }\n }\n\n /**\n * Synchronizes custom-footer callback-rendered elements in the light DOM based on current state.\n * Called from render() when renderCustomMessageFooter is provided. Direct analogue of\n * syncCallbackRenderedElements().\n */\n private syncCallbackRenderedFooterElements() {\n for (const [slotName, slotState] of Object.entries(\n this._customFooterStateBySlot,\n )) {\n const newContent =\n this.renderCustomMessageFooter?.(slotState, this._instance) ?? null;\n\n if (!newContent) {\n const existing = this._callbackFooterElements.get(slotName);\n if (existing) {\n existing.remove();\n this._callbackFooterElements.delete(slotName);\n }\n continue;\n }\n\n let wrapper = this._callbackFooterElements.get(slotName);\n if (!wrapper) {\n wrapper = document.createElement(\"div\");\n wrapper.setAttribute(\"slot\", slotName);\n this._callbackFooterElements.set(slotName, wrapper);\n this.appendChild(wrapper);\n }\n\n wrapper.replaceChildren(newContent);\n }\n\n // Clean up wrappers for slots that no longer exist in state\n for (const [slotName, el] of this._callbackFooterElements.entries()) {\n if (!(slotName in this._customFooterStateBySlot)) {\n el.remove();\n this._callbackFooterElements.delete(slotName);\n }\n }\n }\n\n /**\n * True when an outer chat element (cds-aichat-custom-element) further up\n * the composed path will catch the host-mount event. When true, this\n * element only forwards the slot through its render template and lets the\n * outer element create the page-level host. When false, this element is\n * outermost and must create the host itself.\n */\n private hasOuterChatHandler(event: Event): boolean {\n const path = event.composedPath();\n const myIndex = path.indexOf(this);\n if (myIndex < 0) {\n return false;\n }\n for (let i = myIndex + 1; i < path.length; i++) {\n const node = path[i] as Element;\n if (\n node?.tagName === \"CDS-AICHAT-CUSTOM-ELEMENT\" ||\n node?.tagName === \"CDS-AICHAT-REACT\"\n ) {\n return true;\n }\n }\n return false;\n }\n\n private handlePluginHostMount = (event: Event) => {\n const detail = (\n event as CustomEvent<{\n slotName: string;\n html: string;\n isInline: boolean;\n }>\n ).detail;\n if (!detail?.slotName) {\n return;\n }\n // Track the slot regardless of who owns hosting so our render forwarder\n // projects the page-level content into cds-aichat-internal's slot.\n if (!this._pluginSlotNames.includes(detail.slotName)) {\n this._pluginSlotNames = [...this._pluginSlotNames, detail.slotName];\n }\n if (this.hasOuterChatHandler(event)) {\n // An outer chat element will create the page-level host; just forward.\n return;\n }\n event.preventDefault();\n let host = this._pluginHosts.get(detail.slotName);\n if (!host) {\n host = document.createElement(detail.isInline ? \"span\" : \"div\");\n host.setAttribute(\"slot\", detail.slotName);\n // Match `.cds-aichat-markdown-stack > *:not(:first-child)` spacing;\n // shadow CSS doesn't reach this host (it lives in this element's\n // outer light DOM), so apply it inline. Inline output flows with\n // text and gets no extra spacing.\n if (!detail.isInline) {\n host.style.marginBlockStart = \"1rem\";\n }\n this._pluginHosts.set(detail.slotName, host);\n this.appendChild(host);\n }\n if (host.innerHTML !== detail.html) {\n host.innerHTML = detail.html;\n }\n };\n\n private handlePluginHostUpdate = (event: Event) => {\n const detail = (event as CustomEvent<{ slotName: string; html: string }>)\n .detail;\n if (!detail?.slotName) {\n return;\n }\n const host = this._pluginHosts.get(detail.slotName);\n if (host && host.innerHTML !== detail.html) {\n host.innerHTML = detail.html;\n }\n };\n\n private handlePluginHostUnmount = (event: Event) => {\n const detail = (event as CustomEvent<{ slotName: string }>).detail;\n if (!detail?.slotName) {\n return;\n }\n this._pluginSlotNames = this._pluginSlotNames.filter(\n (n) => n !== detail.slotName,\n );\n const host = this._pluginHosts.get(detail.slotName);\n if (host) {\n host.remove();\n this._pluginHosts.delete(detail.slotName);\n }\n };\n\n connectedCallback() {\n super.connectedCallback();\n this.addEventListener(\n \"cds-aichat-markdown-plugin-host-mount\",\n this.handlePluginHostMount,\n );\n this.addEventListener(\n \"cds-aichat-markdown-plugin-host-update\",\n this.handlePluginHostUpdate,\n );\n this.addEventListener(\n \"cds-aichat-markdown-plugin-host-unmount\",\n this.handlePluginHostUnmount,\n );\n }\n\n disconnectedCallback() {\n this.removeEventListener(\n \"cds-aichat-markdown-plugin-host-mount\",\n this.handlePluginHostMount,\n );\n this.removeEventListener(\n \"cds-aichat-markdown-plugin-host-update\",\n this.handlePluginHostUpdate,\n );\n this.removeEventListener(\n \"cds-aichat-markdown-plugin-host-unmount\",\n this.handlePluginHostUnmount,\n );\n for (const host of this._pluginHosts.values()) {\n host.remove();\n }\n this._pluginHosts.clear();\n super.disconnectedCallback();\n }\n\n onBeforeRenderOverride = async (instance: ChatInstance) => {\n this._instance = instance;\n\n // Opt-in view-change observation hooks. The float container manages its own\n // visibility, so there is no default handler — a prop is only subscribed\n // when the consumer provides it.\n if (this.onViewPreChange) {\n this._instance.on({\n type: BusEventType.VIEW_PRE_CHANGE,\n handler: this.onViewPreChange,\n });\n }\n if (this.onViewChange) {\n this._instance.on({\n type: BusEventType.VIEW_CHANGE,\n handler: this.onViewChange,\n });\n }\n\n if (this.renderUserDefinedResponse) {\n // Enhanced path: library manages full state for callback rendering\n this._instance.on({\n type: BusEventType.USER_DEFINED_RESPONSE,\n handler: this.enhancedUserDefinedHandler,\n });\n this._instance.on({\n type: BusEventType.CHUNK_USER_DEFINED_RESPONSE,\n handler: this.enhancedUserDefinedChunkHandler,\n });\n } else {\n // Legacy path: container only tracks slot names\n this._instance.on({\n type: BusEventType.USER_DEFINED_RESPONSE,\n handler: this.userDefinedHandler,\n });\n this._instance.on({\n type: BusEventType.CHUNK_USER_DEFINED_RESPONSE,\n handler: this.userDefinedHandler,\n });\n }\n\n // Enhanced path manages full per-slot state for callback rendering; the\n // legacy path only tracks slot names for manual slotting.\n this._instance.on({\n type: BusEventType.CUSTOM_FOOTER_SLOT,\n handler: this.renderCustomMessageFooter\n ? this.enhancedCustomFooterHandler\n : this.customFooterHandler,\n });\n\n // A single RESTART_CONVERSATION subscription clears whichever callback\n // paths are active. Registered once so the handler does not fire twice\n // when both callbacks are provided.\n if (this.renderUserDefinedResponse || this.renderCustomMessageFooter) {\n this._instance.on({\n type: BusEventType.RESTART_CONVERSATION,\n handler: this.restartHandler,\n });\n }\n\n this.addWriteableElementSlots();\n this.attachWriteableElements();\n await this.onBeforeRender?.(instance);\n };\n\n addWriteableElementSlots() {\n const writeableElementSlots: string[] = [];\n Object.keys(this._instance.writeableElements).forEach(\n (writeableElementKey) => {\n writeableElementSlots.push(writeableElementKey);\n },\n );\n this._writeableElementSlots = writeableElementSlots;\n }\n\n private attachWriteableElements() {\n const writeableElements = this._instance?.writeableElements;\n if (!writeableElements) {\n return;\n }\n\n Object.entries(writeableElements).forEach(([slot, element]) => {\n if (!element) {\n return;\n }\n\n element.setAttribute(\"slot\", slot);\n\n if (!element.isConnected) {\n this.appendChild(element);\n }\n });\n }\n\n /**\n * Renders the template while passing in class functionality\n */\n render() {\n if (this.renderUserDefinedResponse) {\n this.syncCallbackRenderedElements();\n }\n if (this.renderCustomMessageFooter) {\n this.syncCallbackRenderedFooterElements();\n }\n\n return html`<cds-aichat-internal\n .config=${this.resolvedConfig}\n .onAfterRender=${this.onAfterRender}\n .onBeforeRender=${this.onBeforeRenderOverride}\n .element=${this.element}\n .markdown=${this.markdown as WCMarkdown | undefined}\n >\n ${this._writeableElementSlots.map(\n (slot) => html`<slot name=${slot} slot=${slot}></slot>`,\n )}\n ${this._userDefinedSlotNames.map(\n (slot) => html`<slot name=${slot} slot=${slot}></slot>`,\n )}\n ${this.renderCustomMessageFooter\n ? this._customFooterSlotNames.map(\n (slot) => html`<slot name=${slot} slot=${slot}></slot>`,\n )\n : this._customFooterSlotNames.map(\n (slot) => html`<div slot=${slot}><slot name=${slot}></slot></div>`,\n )}\n ${this._pluginSlotNames.map(\n (slot) => html`<slot name=${slot} slot=${slot}></slot>`,\n )}\n </cds-aichat-internal>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"cds-aichat-container\": ChatContainer;\n }\n}\n\n/**\n * Attributes interface for the cds-aichat-container web component.\n * This interface extends {@link PublicConfig} with additional component-specific props,\n * flattening all config properties as top-level properties for better TypeScript IntelliSense.\n *\n * @category Web component\n */\ninterface CdsAiChatContainerAttributes extends Omit<PublicConfig, \"markdown\"> {\n /**\n * Markdown rendering customization. Extends the framework-neutral\n * `PublicConfig.markdown` with web-component `customRenderers`.\n *\n * @experimental\n */\n markdown?: WCMarkdown;\n\n /**\n * This function is called before the render function of Carbon AI Chat is called. This function can return a Promise\n * which will cause Carbon AI Chat to wait for it before rendering.\n */\n onBeforeRender?: (instance: ChatInstance) => Promise<void> | void;\n\n /**\n * This function is called after the render function of Carbon AI Chat is called.\n */\n onAfterRender?: (instance: ChatInstance) => Promise<void> | void;\n\n /**\n * Called before a view change (the chat opening or closing). Async — return a Promise to defer the view\n * change until it resolves. This is an opt-in observation hook with no default visibility behavior.\n */\n onViewPreChange?: (event: BusEventViewPreChange) => Promise<void> | void;\n\n /**\n * Called when a view change (the chat opening or closing) is complete. This is an opt-in observation hook\n * with no default visibility behavior.\n */\n onViewChange?: (event: BusEventViewChange, instance: ChatInstance) => void;\n\n /**\n * Optional callback to render user defined responses. When provided, the library manages all event listening,\n * slot tracking, streaming state, and element lifecycle.\n */\n renderUserDefinedResponse?: WCRenderUserDefinedResponse;\n\n /**\n * Optional callback to render custom message footers. When provided, the library manages all event listening,\n * slot tracking, and element lifecycle. When omitted, the legacy event + manual slot approach continues to work.\n */\n renderCustomMessageFooter?: WCRenderCustomMessageFooter;\n}\n\nexport { CdsAiChatContainerAttributes };\nexport default ChatContainer;\n"],"names":["ChatContainerInternal","LitElement","firstUpdated","this","config","renderReactApp","updated","changedProperties","has","container","ensureReactRoot","root","render","React","createElement","ChatAppEntry","strings","serviceDeskFactory","serviceDesk","onBeforeRender","onAfterRender","element","markdown","reactContainer","document","classList","add","shadowRoot","appendChild","createRoot","disconnectedCallback","unmount","super","styles","css","__decorate","property","type","Object","prototype","attribute","HTMLElement","carbonElement","aiEnabledConverter","fromAttribute","value","undefined","v","String","trim","toLowerCase","falsey","FLATTENED_PUBLIC_CONFIG_FIELDS","name","options","Boolean","converter","resolveManually","resolveFlattenedConfig","source","resolved","field","aiDisabled","aiEnabled","buildFlattenedProperties","properties","FlattenedConfigElement","resolvedConfig","ChatContainer","constructor","_userDefinedSlotNames","_customFooterSlotNames","_writeableElementSlots","_pluginSlotNames","_pluginHosts","Map","_userDefinedStateBySlot","_customFooterStateBySlot","_callbackElements","_callbackFooterElements","userDefinedHandler","event","slot","data","includes","customFooterHandler","slotName","enhancedCustomFooterHandler","message","messageItem","additionalData","enhancedUserDefinedHandler","fullMessage","state","enhancedUserDefinedChunkHandler","chunk","complete_item","existing","partialItems","partial_item","restartHandler","el","values","remove","clear","renderCustomMessageFooter","handlePluginHostMount","detail","hasOuterChatHandler","preventDefault","host","get","isInline","setAttribute","style","marginBlockStart","set","innerHTML","html","handlePluginHostUpdate","handlePluginHostUnmount","filter","n","delete","onBeforeRenderOverride","async","instance","_instance","onViewPreChange","on","BusEventType","VIEW_PRE_CHANGE","handler","onViewChange","VIEW_CHANGE","renderUserDefinedResponse","USER_DEFINED_RESPONSE","CHUNK_USER_DEFINED_RESPONSE","CUSTOM_FOOTER_SLOT","RESTART_CONVERSATION","addWriteableElementSlots","attachWriteableElements","syncCallbackRenderedElements","slotState","entries","newContent","wrapper","replaceChildren","syncCallbackRenderedFooterElements","path","composedPath","myIndex","indexOf","i","length","node","tagName","connectedCallback","addEventListener","removeEventListener","writeableElementSlots","keys","writeableElements","forEach","writeableElementKey","push","isConnected","map","ChatContainer_default"],"mappings":";;;;;;;;;;;;;;;;AAiCA,IAAMA,wBAAN,MAAMA,8BAA8BC;EA+DlC,YAAAC;IACE,IAAIC,KAAKC,QAAQ;MACfD,KAAKE;AACP;AACF;EAEA,OAAAC,CAAQC;IAEN,IACEJ,KAAKC,WACJG,kBAAkBC,IAAI,aACrBD,kBAAkBC,IAAI,cACtBD,kBAAkBC,IAAI,yBACtBD,kBAAkBC,IAAI,kBACtBD,kBAAkBC,IAAI,qBACtBD,kBAAkBC,IAAI,oBACtBD,kBAAkBC,IAAI,cACtBD,kBAAkBC,IAAI,cACxB;MACAL,KAAKE;AACP;AACF;EAYA,oBAAMA;IACJ,MAAMI,YAAYN,KAAKO;IAEvBP,KAAKQ,KAAKC,OACRC,MAAAC,cAACC,cAAY;MACXX,QAAQD,KAAKC;MACbY,SAASb,KAAKa;MACdC,oBAAoBd,KAAKc;MACzBC,aAAaf,KAAKe;MAClBC,gBAAgBhB,KAAKgB;MACrBC,eAAejB,KAAKiB;MACpBX;MACAY,SAASlB,KAAKkB;MACdC,UAAUnB,KAAKmB;;AAGrB;EAEQ,eAAAZ;IACN,KAAKP,KAAKoB,gBAAgB;MACxB,MAAMd,YAAYe,SAASV,cAAc;MACzCL,UAAUgB,UAAUC,IAAI;MACxBvB,KAAKwB,WAAWC,YAAYnB;MAC5BN,KAA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MACiC4B,cAAA7B,WAAA;;AAUxDJ,WAAA,EADCC,SAAS;EAAEI,WAAW;MACiC4B,cAAA7B,WAAA;;AASxDJ,WAAA,EADC0D,WACoCzB,cAAA7B,WAAA;;AAMrCJ,WAAA,EADC0D,WACqCzB,cAAA7B,WAAA;;AAMtCJ,WAAA,EADC0D,WACqCzB,cAAA7B,WAAA;;AAStCJ,WAAA,EADC0D,WAC+BzB,cAAA7B,WAAA;;AAahCJ,WAAA,EADC0D,WACuBzB,cAAA7B,WAAA;;AAMxBJ,WAAA,EADC0D,WACoEzB,cAAA7B,WAAA;;AAMrEJ,WAAA,EADC0D,WAC6EzB,cAAA7B,WAAA;;AAjI1E6B,gBAAajC,WAAA,EADlBO,cAAc,2BACT0B;;AAopBN,IAAAoG,wBAAepG;;"}
1
+ {"version":3,"file":"chat.index.js","sources":["../../../../src/web-components/cds-aichat-container/cds-aichat-internal.tsx","../../../../src/web-components/shared/flattenedPublicConfig.ts","../../../../src/web-components/shared/FlattenedConfigElement.ts","../../../../src/web-components/cds-aichat-container/index.ts"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\n/**\n * This component is mostly a pass-through. Its takes any properties passed into the ChatContainer\n * custom element and then renders the React Carbon AI Chat application while passing in properties.\n */\n\nimport { css, LitElement, PropertyValues } from \"lit\";\nimport { property } from \"lit/decorators.js\";\nimport React from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\n\nimport ChatAppEntry from \"../../chat/ChatAppEntry\";\nimport { carbonElement } from \"@carbon/ai-chat-components/es/globals/decorators/index.js\";\nimport { PublicConfig } from \"../../types/config/PublicConfig\";\nimport { ChatInstance } from \"../../types/instance/ChatInstance\";\nimport { DeepPartial } from \"../../types/utilities/DeepPartial\";\nimport { LanguagePack } from \"../../types/config/PublicConfig\";\nimport type {\n ServiceDesk,\n ServiceDeskFactoryParameters,\n ServiceDeskPublicConfig,\n} from \"../../types/config/ServiceDeskConfig\";\nimport type { MarkdownConfigContextValue } from \"../../chat/contexts/MarkdownConfigContext\";\n\n@carbonElement(\"cds-aichat-internal\")\nclass ChatContainerInternal extends LitElement {\n static styles = css`\n :host {\n display: block;\n width: 100%;\n height: 100%;\n box-sizing: border-box;\n z-index: var(--cds-aichat-z-index, auto);\n }\n `;\n\n /**\n * The config to use to load Carbon AI Chat. Note that the \"onLoad\" property is overridden by this component. If you\n * need to perform any actions after Carbon AI Chat been loaded, use the \"onBeforeRender\" or \"onAfterRender\" props.\n */\n @property({ type: Object })\n config: PublicConfig;\n\n /** Optional partial language pack overrides */\n @property({ type: Object })\n strings?: DeepPartial<LanguagePack>;\n\n /** A factory for the {@link ServiceDesk} integration. */\n @property({ attribute: false })\n serviceDeskFactory?: (\n parameters: ServiceDeskFactoryParameters,\n ) => Promise<ServiceDesk>;\n\n /** Public configuration for the service desk integration. */\n @property({ type: Object })\n serviceDesk?: ServiceDeskPublicConfig;\n\n /**\n * The optional HTML element to mount the chat to.\n */\n @property({ type: HTMLElement })\n element?: HTMLElement;\n\n /**\n * This function is called before the render function of Carbon AI Chat is called. This function can return a Promise\n * which will cause Carbon AI Chat to wait for it before rendering.\n */\n @property()\n onBeforeRender: (instance: ChatInstance) => Promise<void> | void;\n\n /**\n * This function is called after the render function of Carbon AI Chat is called. This function can return a Promise\n * which will cause Carbon AI Chat to wait for it before rendering.\n */\n @property()\n onAfterRender: (instance: ChatInstance) => Promise<void> | void;\n\n /**\n * Merged markdown config (framework-neutral `markdownItPlugins` plus\n * layer-specific `customRenderers`). Forwarded to the React app via\n * `MarkdownConfigContext` so {@link MarkdownWithDefaults} can portal\n * consumer overrides into the rendered markdown components.\n *\n * @experimental\n */\n @property({ attribute: false })\n markdown?: MarkdownConfigContextValue;\n\n firstUpdated() {\n if (this.config) {\n this.renderReactApp();\n }\n }\n\n updated(changedProperties: PropertyValues) {\n // Re-render React app when config or other properties change\n if (\n this.config &&\n (changedProperties.has(\"config\") ||\n changedProperties.has(\"strings\") ||\n changedProperties.has(\"serviceDeskFactory\") ||\n changedProperties.has(\"serviceDesk\") ||\n changedProperties.has(\"onBeforeRender\") ||\n changedProperties.has(\"onAfterRender\") ||\n changedProperties.has(\"element\") ||\n changedProperties.has(\"markdown\"))\n ) {\n this.renderReactApp();\n }\n }\n\n /**\n * Track if a previous React 18+ root was already created so we don't create a memory leak on re-renders.\n */\n root: Root;\n\n /**\n * Cache the container we hand to React so we can reuse it between renders.\n */\n reactContainer?: HTMLDivElement;\n\n async renderReactApp() {\n const container = this.ensureReactRoot();\n\n this.root.render(\n <ChatAppEntry\n config={this.config}\n strings={this.strings}\n serviceDeskFactory={this.serviceDeskFactory}\n serviceDesk={this.serviceDesk}\n onBeforeRender={this.onBeforeRender}\n onAfterRender={this.onAfterRender}\n container={container}\n element={this.element}\n markdown={this.markdown}\n />,\n );\n }\n\n private ensureReactRoot(): HTMLDivElement {\n if (!this.reactContainer) {\n const container = document.createElement(\"div\");\n container.classList.add(\"cds-aichat--react-app\");\n this.shadowRoot.appendChild(container);\n this.reactContainer = container;\n }\n\n // Make sure we only create one root and reuse it for prop updates.\n if (!this.root) {\n this.root = createRoot(this.reactContainer);\n }\n\n return this.reactContainer;\n }\n\n disconnectedCallback(): void {\n this.root?.unmount();\n super.disconnectedCallback();\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"cds-aichat-internal\": ChatContainerInternal;\n }\n}\n\nexport default ChatContainerInternal;\n","/*\n * Copyright IBM Corp. 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\n/**\n * Single source of truth for the {@link PublicConfig} fields that the\n * `cds-aichat-container` and `cds-aichat-custom-element` web components expose\n * as flattened top-level attributes/properties.\n *\n * Both components build their Lit reactive properties and reconstruct a\n * `PublicConfig` from this one table, so every config field is declared in\n * exactly one place. Adding a field to {@link PublicConfig} requires adding a\n * single entry here — the compile-time guard at the bottom of this file fails\n * the build until that happens.\n */\n\nimport type { ComplexAttributeConverter, PropertyDeclaration } from \"lit\";\n\nimport { PublicConfig } from \"../../types/config/PublicConfig\";\n\n/**\n * A single flattened-config field: a {@link PublicConfig} key plus the exact\n * Lit property options used to expose it on the web components.\n */\nexport interface FlattenedConfigFieldEntry {\n /** The {@link PublicConfig} key this entry maps to. */\n readonly name: keyof PublicConfig;\n /** The Lit property declaration options for this field. */\n readonly options: PropertyDeclaration;\n /**\n * When true, {@link resolveFlattenedConfig} skips this field in its generic\n * loop because its resolution rule is non-uniform. Only `aiEnabled` uses\n * this — it is resolved together with the synthetic `aiDisabled` opt-out.\n */\n readonly resolveManually?: boolean;\n}\n\n/**\n * Custom converter for the `ai-enabled` attribute so HTML authors can write\n * `ai-enabled=\"false\" | \"0\" | \"off\" | \"no\"`, while an absent attribute stays\n * `undefined` (so defaults apply further down the stack).\n */\nconst aiEnabledConverter: ComplexAttributeConverter<boolean | undefined> = {\n fromAttribute: (value: string | null) => {\n if (value === null) {\n return undefined; // attribute absent -> leave undefined to use defaults\n }\n const v = String(value).trim().toLowerCase();\n const falsey = v === \"false\" || v === \"0\" || v === \"off\" || v === \"no\";\n // Any presence that's not an explicit falsey string is treated as true.\n return !falsey;\n },\n};\n\n/**\n * Every {@link PublicConfig} field exposed as a flattened attribute/property\n * on the web components, with the exact Lit property options for each.\n *\n * `as const satisfies` keeps the `name` values as string literals (required by\n * the exhaustiveness guard below) while type-checking every entry.\n */\nexport const FLATTENED_PUBLIC_CONFIG_FIELDS = [\n { name: \"onError\", options: { attribute: false } },\n {\n name: \"openChatByDefault\",\n options: { type: Boolean, attribute: \"open-chat-by-default\" },\n },\n { name: \"disclaimer\", options: { type: Object } },\n {\n name: \"disableCustomElementMobileEnhancements\",\n options: {\n type: Boolean,\n attribute: \"disable-custom-element-mobile-enhancements\",\n },\n },\n { name: \"debug\", options: { type: Boolean } },\n {\n name: \"exposeServiceManagerForTesting\",\n options: { type: Boolean, attribute: \"expose-service-manager-for-testing\" },\n },\n {\n name: \"injectCarbonTheme\",\n options: { type: String, attribute: \"inject-carbon-theme\" },\n },\n {\n name: \"aiEnabled\",\n options: { attribute: \"ai-enabled\", converter: aiEnabledConverter },\n resolveManually: true,\n },\n { name: \"serviceDeskFactory\", options: { attribute: false } },\n {\n name: \"serviceDesk\",\n options: { type: Object, attribute: \"service-desk\" },\n },\n {\n name: \"shouldTakeFocusIfOpensAutomatically\",\n options: {\n type: Boolean,\n attribute: \"should-take-focus-if-opens-automatically\",\n },\n },\n { name: \"namespace\", options: { type: String } },\n {\n name: \"shouldSanitizeHTML\",\n options: { type: Boolean, attribute: \"should-sanitize-html\" },\n },\n { name: \"header\", options: { type: Object } },\n { name: \"history\", options: { type: Object } },\n { name: \"layout\", options: { type: Object } },\n { name: \"messaging\", options: { type: Object } },\n { name: \"isReadonly\", options: { type: Boolean, attribute: \"is-readonly\" } },\n {\n name: \"persistFeedback\",\n options: { type: Boolean, attribute: \"persist-feedback\" },\n },\n {\n name: \"assistantName\",\n options: { type: String, attribute: \"assistant-name\" },\n },\n // Note: no explicit `attribute` — Lit derives `assistantavatarurl`.\n { name: \"assistantAvatarUrl\", options: { type: String } },\n { name: \"locale\", options: { type: String } },\n { name: \"homescreen\", options: { type: Object } },\n { name: \"launcher\", options: { type: Object } },\n { name: \"input\", options: { type: Object } },\n { name: \"upload\", options: { attribute: false, type: Object } },\n { name: \"strings\", options: { type: Object } },\n { name: \"keyboardShortcuts\", options: { type: Object } },\n { name: \"markdown\", options: { attribute: false } },\n] as const satisfies readonly FlattenedConfigFieldEntry[];\n\n/**\n * The shape consumed by {@link resolveFlattenedConfig}: any flattened\n * {@link PublicConfig} field, plus the base `config` object and the synthetic\n * `aiDisabled` opt-out. Both web components structurally satisfy this.\n */\nexport interface FlattenedConfigSource extends Partial<PublicConfig> {\n /** Base config object; flattened fields override individual keys on it. */\n config?: PublicConfig;\n /** Synthetic opt-out attribute; when true it forces `aiEnabled` to false. */\n aiDisabled?: boolean;\n}\n\n/**\n * Builds a {@link PublicConfig} from a flattened source by layering each\n * defined flattened field over the base `config` object.\n *\n * Pure and DOM-free so it can be unit tested directly.\n *\n * @param source - The web component (or any object) carrying flattened fields.\n * @returns The reconstructed `PublicConfig`.\n */\nexport function resolveFlattenedConfig(\n source: FlattenedConfigSource,\n): PublicConfig {\n const resolved: PublicConfig = { ...(source.config ?? {}) };\n\n for (const field of FLATTENED_PUBLIC_CONFIG_FIELDS) {\n // aiEnabled is resolved together with aiDisabled below.\n if (\"resolveManually\" in field && field.resolveManually) {\n continue;\n }\n const value = source[field.name];\n if (value !== undefined) {\n (resolved as Record<string, unknown>)[field.name] = value;\n }\n }\n\n // aiEnabled / aiDisabled precedence is non-uniform: an explicit aiDisabled\n // attribute always wins over ai-enabled.\n if (source.aiDisabled === true) {\n resolved.aiEnabled = false;\n } else if (source.aiEnabled !== undefined) {\n resolved.aiEnabled = source.aiEnabled;\n }\n\n return resolved;\n}\n\n/**\n * Compile-time exhaustiveness guard.\n *\n * `_AssertTableCoversPublicConfig` fails to compile unless the set of field\n * names in {@link FLATTENED_PUBLIC_CONFIG_FIELDS} is exactly `keyof\n * PublicConfig`. Adding a field to {@link PublicConfig} without adding it to\n * the table — or vice versa — breaks the build here.\n */\ntype Equals<A, B> =\n (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2\n ? true\n : false;\ntype Expect<T extends true> = T;\ntype FlattenedFieldName =\n (typeof FLATTENED_PUBLIC_CONFIG_FIELDS)[number][\"name\"];\n\n// The `_` prefix matches the lint config's varsIgnorePattern; this alias only\n// exists to be type-checked.\ntype _AssertTableCoversPublicConfig = Expect<\n Equals<FlattenedFieldName, keyof PublicConfig>\n>;\n","/*\n * Copyright IBM Corp. 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\n/**\n * Shared Lit base class for the web components that expose a flattened\n * {@link PublicConfig} surface (`cds-aichat-container` and\n * `cds-aichat-custom-element`).\n *\n * It contributes every flattened reactive property from the single\n * {@link FLATTENED_PUBLIC_CONFIG_FIELDS} table and derives `resolvedConfig`\n * from that same table, so each config field is defined in exactly one place.\n */\n\nimport { LitElement } from \"lit\";\nimport type { PropertyDeclaration, PropertyDeclarations } from \"lit\";\n\nimport { PublicConfig } from \"../../types/config/PublicConfig\";\nimport {\n FLATTENED_PUBLIC_CONFIG_FIELDS,\n resolveFlattenedConfig,\n} from \"./flattenedPublicConfig\";\n\n/**\n * Builds the Lit `static properties` object from the shared field table plus\n * the synthetic `config` (base config object) and `aiDisabled` (opt-out)\n * properties.\n */\nfunction buildFlattenedProperties(): PropertyDeclarations {\n const properties: Record<string, PropertyDeclaration> = {\n config: { attribute: false, type: Object },\n aiDisabled: { type: Boolean, attribute: \"ai-disabled\" },\n };\n for (const field of FLATTENED_PUBLIC_CONFIG_FIELDS) {\n properties[field.name] = field.options;\n }\n return properties;\n}\n\n/**\n * Declaration merging gives the instance typed access to `this.history`,\n * `this.debug`, ... without re-listing every {@link PublicConfig} field and\n * without emitting any runtime class field (so nothing shadows the accessors\n * Lit installs from `static properties`).\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\ninterface FlattenedConfigElement extends Partial<PublicConfig> {}\n\n/**\n * Base class contributing all flattened `PublicConfig` reactive properties.\n * Not registered as a custom element — only the concrete subclasses are.\n */\nabstract class FlattenedConfigElement extends LitElement {\n static properties: PropertyDeclarations = buildFlattenedProperties();\n\n /** Base config object. Flattened properties layer on top of this. */\n config?: PublicConfig;\n\n /**\n * Optional explicit opt-out attribute. If present, it wins over `ai-enabled`.\n * Not a {@link PublicConfig} field — it resolves into `config.aiEnabled`.\n */\n aiDisabled?: boolean;\n\n /**\n * The {@link PublicConfig} reconstructed from `config` plus every defined\n * flattened property.\n */\n protected get resolvedConfig(): PublicConfig {\n return resolveFlattenedConfig(this);\n }\n}\n\nexport { FlattenedConfigElement };\n","/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\n/**\n * This is the exposed web component for a basic floating chat.\n */\n\nimport \"./cds-aichat-internal\";\n\nimport { html } from \"lit\";\nimport { property, state } from \"lit/decorators.js\";\n\nimport { carbonElement } from \"@carbon/ai-chat-components/es/globals/decorators/index.js\";\nimport { PublicConfig } from \"../../types/config/PublicConfig\";\nimport { FlattenedConfigElement } from \"../shared/FlattenedConfigElement\";\nimport { ChatInstance } from \"../../types/instance/ChatInstance\";\nimport {\n BusEventChunkUserDefinedResponse,\n BusEventCustomFooterSlot,\n BusEventType,\n BusEventUserDefinedResponse,\n BusEventViewChange,\n BusEventViewPreChange,\n} from \"../../types/events/eventBusTypes\";\nimport type {\n RenderCustomMessageFooterState,\n RenderUserDefinedState,\n WCMarkdown,\n WCRenderCustomMessageFooter,\n WCRenderUserDefinedResponse,\n} from \"../../types/component/ChatContainer\";\n\n/**\n * The cds-aichat-container managing creating slotted elements for user_defined responses, custom message footers, and writable elements.\n * It then passes that slotted content into cds-aichat-internal. That component will boot up the full chat application\n * and pass the slotted elements into their slots.\n */\n@carbonElement(\"cds-aichat-container\")\nclass ChatContainer extends FlattenedConfigElement {\n /**\n * The element to render to instead of the default float element.\n *\n * @internal\n */\n @property({ type: HTMLElement })\n element?: HTMLElement;\n\n /**\n * This function is called before the render function of Carbon AI Chat is called. This function can return a Promise\n * which will cause Carbon AI Chat to wait for it before rendering.\n *\n * Use it to capture the {@link ChatInstance} so you can call instance methods later.\n *\n * @example\n * ```ts\n * const onBeforeRender = (instance: ChatInstance) => {\n * this.instance = instance;\n * };\n * // <cds-aichat-container .onBeforeRender=${onBeforeRender}></cds-aichat-container>\n * ```\n */\n @property({ attribute: false })\n onBeforeRender: (instance: ChatInstance) => Promise<void> | void;\n\n /**\n * This function is called after the render function of Carbon AI Chat is called.\n *\n * Like `onBeforeRender`, it receives the {@link ChatInstance}; use it when you need the instance only after the\n * first render has completed.\n */\n @property({ attribute: false })\n onAfterRender: (instance: ChatInstance) => Promise<void> | void;\n\n /**\n * Called before a view change (the chat opening or closing). Async — return a\n * Promise to defer the view change until it resolves.\n *\n * This is an opt-in observation hook. Unlike `cds-aichat-custom-element`, the\n * container has no wrapping element to size, so no default visibility\n * behavior runs when this property is omitted.\n */\n @property()\n onViewPreChange?: (event: BusEventViewPreChange) => Promise<void> | void;\n\n /**\n * Called when a view change (the chat opening or closing) is complete.\n *\n * This is an opt-in observation hook. Unlike `cds-aichat-custom-element`, the\n * container has no wrapping element to size, so no default visibility\n * behavior runs when this property is omitted.\n */\n @property()\n onViewChange?: (event: BusEventViewChange, instance: ChatInstance) => void;\n\n /**\n * Optional callback to render user defined responses. When provided, the library manages all event listening,\n * slot tracking, streaming state, and element lifecycle. The callback receives the accumulated state and should\n * return an HTMLElement or null.\n *\n * When this property is not set, the existing event + manual slot approach continues to work.\n */\n @property({ attribute: false })\n renderUserDefinedResponse?: WCRenderUserDefinedResponse;\n\n /**\n * Optional callback to render custom message footers. When provided, the library manages all event listening,\n * slot tracking, and element lifecycle. The callback receives the accumulated state and should\n * return an HTMLElement or null.\n *\n * When this property is not set, the existing event + manual slot approach continues to work.\n */\n @property({ attribute: false })\n renderCustomMessageFooter?: WCRenderCustomMessageFooter;\n\n // markdown is declared on the FlattenedConfigElement base; the attributes\n // interface narrows its type.\n\n /**\n * The existing array of slot names for all user_defined components.\n */\n @state()\n _userDefinedSlotNames: string[] = [];\n\n /**\n * The existing array of slot names for all custom footers.\n */\n @state()\n _customFooterSlotNames: string[] = [];\n\n /**\n * The existing array of slot names for all writeable elements.\n */\n @state()\n _writeableElementSlots: string[] = [];\n\n /**\n * Active slot names for markdown-plugin output hosted at this element.\n * Populated when this element takes over from the markdown element by\n * accepting the host-mount event; drained when the matching unmount\n * event fires.\n */\n @state()\n _pluginSlotNames: string[] = [];\n\n /**\n * Page-level host elements created for plugin-output slots, keyed by slot\n * name. Created in this element's outer light DOM so consumer-loaded\n * stylesheets (e.g. KaTeX) reach the rendered HTML normally.\n */\n private _pluginHosts: Map<string, HTMLElement> = new Map();\n\n /**\n * The chat instance.\n */\n @state()\n _instance: ChatInstance;\n\n /**\n * Accumulated state per slot for user_defined responses when renderUserDefinedResponse is provided.\n */\n @state()\n _userDefinedStateBySlot: Record<string, RenderUserDefinedState> = {};\n\n /**\n * Accumulated state per slot for custom message footers when renderCustomMessageFooter is provided.\n */\n @state()\n _customFooterStateBySlot: Record<string, RenderCustomMessageFooterState> = {};\n\n /**\n * Tracks the wrapper elements created by the callback rendering path.\n */\n private _callbackElements = new Map<string, HTMLElement>();\n\n /**\n * Tracks the wrapper elements created by the custom-footer callback rendering path.\n */\n private _callbackFooterElements = new Map<string, HTMLElement>();\n\n /**\n * Adds the slot attribute to the element for the user_defined response type and then injects it into the component by\n * updating this._userDefinedSlotNames;\n */\n userDefinedHandler = (\n event: BusEventUserDefinedResponse | BusEventChunkUserDefinedResponse,\n ) => {\n // This element already has `slot` as an attribute.\n const { slot } = event.data;\n if (!this._userDefinedSlotNames.includes(slot)) {\n this._userDefinedSlotNames = [...this._userDefinedSlotNames, slot];\n }\n };\n\n /**\n * Adds the slot attribute to the element for the custom_footer_slot type and then injects it into the component by\n * updating this._customFooterSlotNames;\n */\n customFooterHandler = (event: BusEventCustomFooterSlot) => {\n // This element already has `slotName` as an attribute.\n const { slotName } = event.data;\n if (!this._customFooterSlotNames.includes(slotName)) {\n this._customFooterSlotNames = [...this._customFooterSlotNames, slotName];\n }\n };\n\n /**\n * Enhanced handler for CUSTOM_FOOTER_SLOT when the renderCustomMessageFooter callback is provided.\n * Tracks both slot names and the full per-slot state used by the callback rendering path.\n */\n private enhancedCustomFooterHandler = (event: BusEventCustomFooterSlot) => {\n const { slotName, message, messageItem, additionalData } = event.data;\n if (!this._customFooterSlotNames.includes(slotName)) {\n this._customFooterSlotNames = [...this._customFooterSlotNames, slotName];\n }\n this._customFooterStateBySlot = {\n ...this._customFooterStateBySlot,\n [slotName]: {\n slotName,\n message,\n messageItem,\n additionalData: additionalData as Record<string, unknown> | undefined,\n },\n };\n };\n\n /**\n * Enhanced handler for USER_DEFINED_RESPONSE when renderUserDefinedResponse callback is provided.\n * Tracks both slot names and full message state per slot.\n */\n private enhancedUserDefinedHandler = (event: BusEventUserDefinedResponse) => {\n const { slot } = event.data;\n if (!this._userDefinedSlotNames.includes(slot)) {\n this._userDefinedSlotNames = [...this._userDefinedSlotNames, slot];\n }\n this._userDefinedStateBySlot = {\n ...this._userDefinedStateBySlot,\n [slot]: {\n fullMessage: event.data.fullMessage,\n messageItem: event.data.message,\n state: event.data.state,\n },\n };\n };\n\n /**\n * Enhanced handler for CHUNK_USER_DEFINED_RESPONSE when renderUserDefinedResponse callback is provided.\n * Handles both complete_item and partial_item chunks, accumulating state per slot.\n */\n private enhancedUserDefinedChunkHandler = (\n event: BusEventChunkUserDefinedResponse,\n ) => {\n const { slot, chunk } = event.data;\n if (!this._userDefinedSlotNames.includes(slot)) {\n this._userDefinedSlotNames = [...this._userDefinedSlotNames, slot];\n }\n\n if (\"complete_item\" in chunk) {\n this._userDefinedStateBySlot = {\n ...this._userDefinedStateBySlot,\n [slot]: { messageItem: chunk.complete_item },\n };\n } else if (\"partial_item\" in chunk) {\n const existing = this._userDefinedStateBySlot[slot];\n this._userDefinedStateBySlot = {\n ...this._userDefinedStateBySlot,\n [slot]: {\n ...existing,\n partialItems: [...(existing?.partialItems ?? []), chunk.partial_item],\n },\n };\n }\n };\n\n /**\n * Handles RESTART_CONVERSATION when the renderUserDefinedResponse and/or renderCustomMessageFooter\n * callback is provided. Clears all accumulated state and removes callback-rendered elements from the DOM.\n *\n * The custom-footer cleanup is guarded by renderCustomMessageFooter so the legacy footer passthrough\n * path (which the host clears itself) is left untouched.\n */\n private restartHandler = () => {\n this._userDefinedStateBySlot = {};\n this._userDefinedSlotNames = [];\n for (const el of this._callbackElements.values()) {\n el.remove();\n }\n this._callbackElements.clear();\n\n if (this.renderCustomMessageFooter) {\n this._customFooterStateBySlot = {};\n this._customFooterSlotNames = [];\n for (const el of this._callbackFooterElements.values()) {\n el.remove();\n }\n this._callbackFooterElements.clear();\n }\n };\n\n /**\n * Synchronizes callback-rendered elements in the light DOM based on current state.\n * Called from render() when renderUserDefinedResponse is provided.\n */\n private syncCallbackRenderedElements() {\n for (const [slot, slotState] of Object.entries(\n this._userDefinedStateBySlot,\n )) {\n const newContent =\n this.renderUserDefinedResponse?.(slotState, this._instance) ?? null;\n\n if (!newContent) {\n const existing = this._callbackElements.get(slot);\n if (existing) {\n existing.remove();\n this._callbackElements.delete(slot);\n }\n continue;\n }\n\n let wrapper = this._callbackElements.get(slot);\n if (!wrapper) {\n wrapper = document.createElement(\"div\");\n wrapper.setAttribute(\"slot\", slot);\n this._callbackElements.set(slot, wrapper);\n this.appendChild(wrapper);\n }\n\n wrapper.replaceChildren(newContent);\n }\n\n // Clean up wrappers for slots that no longer exist in state\n for (const [slot, el] of this._callbackElements.entries()) {\n if (!(slot in this._userDefinedStateBySlot)) {\n el.remove();\n this._callbackElements.delete(slot);\n }\n }\n }\n\n /**\n * Synchronizes custom-footer callback-rendered elements in the light DOM based on current state.\n * Called from render() when renderCustomMessageFooter is provided. Direct analogue of\n * syncCallbackRenderedElements().\n */\n private syncCallbackRenderedFooterElements() {\n for (const [slotName, slotState] of Object.entries(\n this._customFooterStateBySlot,\n )) {\n const newContent =\n this.renderCustomMessageFooter?.(slotState, this._instance) ?? null;\n\n if (!newContent) {\n const existing = this._callbackFooterElements.get(slotName);\n if (existing) {\n existing.remove();\n this._callbackFooterElements.delete(slotName);\n }\n continue;\n }\n\n let wrapper = this._callbackFooterElements.get(slotName);\n if (!wrapper) {\n wrapper = document.createElement(\"div\");\n wrapper.setAttribute(\"slot\", slotName);\n this._callbackFooterElements.set(slotName, wrapper);\n this.appendChild(wrapper);\n }\n\n wrapper.replaceChildren(newContent);\n }\n\n // Clean up wrappers for slots that no longer exist in state\n for (const [slotName, el] of this._callbackFooterElements.entries()) {\n if (!(slotName in this._customFooterStateBySlot)) {\n el.remove();\n this._callbackFooterElements.delete(slotName);\n }\n }\n }\n\n /**\n * True when an outer chat element (cds-aichat-custom-element) further up\n * the composed path will catch the host-mount event. When true, this\n * element only forwards the slot through its render template and lets the\n * outer element create the page-level host. When false, this element is\n * outermost and must create the host itself.\n */\n private hasOuterChatHandler(event: Event): boolean {\n const path = event.composedPath();\n const myIndex = path.indexOf(this);\n if (myIndex < 0) {\n return false;\n }\n for (let i = myIndex + 1; i < path.length; i++) {\n const node = path[i] as Element;\n if (\n node?.tagName === \"CDS-AICHAT-CUSTOM-ELEMENT\" ||\n node?.tagName === \"CDS-AICHAT-REACT\"\n ) {\n return true;\n }\n }\n return false;\n }\n\n private handlePluginHostMount = (event: Event) => {\n const detail = (\n event as CustomEvent<{\n slotName: string;\n html?: string;\n element?: HTMLElement;\n isInline: boolean;\n }>\n ).detail;\n if (!detail?.slotName) {\n return;\n }\n // Track the slot regardless of who owns hosting so our render forwarder\n // projects the page-level content into cds-aichat-internal's slot.\n if (!this._pluginSlotNames.includes(detail.slotName)) {\n this._pluginSlotNames = [...this._pluginSlotNames, detail.slotName];\n }\n if (this.hasOuterChatHandler(event)) {\n // An outer chat element will create the page-level host; just forward.\n // This applies to the live-element path too: appending here would land\n // the node in this element's light DOM (inside the outer chat element's\n // shadow root), where global CSS still wouldn't reach it.\n return;\n }\n event.preventDefault();\n // Custom-renderer hosts (table/codeBlock) forward a live element — the\n // markdown element keeps ownership of its content; we only relocate the\n // node into our outer light DOM so the consumer's global CSS reaches it.\n // Plugin fallbacks forward an HTML string instead.\n if (detail.element) {\n const element = detail.element;\n element.setAttribute(\"slot\", detail.slotName);\n if (!detail.isInline) {\n element.style.marginBlockStart = \"1rem\";\n }\n if (element.parentElement !== this) {\n this.appendChild(element);\n }\n return;\n }\n let host = this._pluginHosts.get(detail.slotName);\n if (!host) {\n host = document.createElement(detail.isInline ? \"span\" : \"div\");\n host.setAttribute(\"slot\", detail.slotName);\n // Match `.cds-aichat-markdown-stack > *:not(:first-child)` spacing;\n // shadow CSS doesn't reach this host (it lives in this element's\n // outer light DOM), so apply it inline. Inline output flows with\n // text and gets no extra spacing.\n if (!detail.isInline) {\n host.style.marginBlockStart = \"1rem\";\n }\n this._pluginHosts.set(detail.slotName, host);\n this.appendChild(host);\n }\n if (host.innerHTML !== (detail.html ?? \"\")) {\n host.innerHTML = detail.html ?? \"\";\n }\n };\n\n private handlePluginHostUpdate = (event: Event) => {\n const detail = (event as CustomEvent<{ slotName: string; html: string }>)\n .detail;\n if (!detail?.slotName) {\n return;\n }\n const host = this._pluginHosts.get(detail.slotName);\n if (host && host.innerHTML !== detail.html) {\n host.innerHTML = detail.html;\n }\n };\n\n private handlePluginHostUnmount = (event: Event) => {\n const detail = (event as CustomEvent<{ slotName: string }>).detail;\n if (!detail?.slotName) {\n return;\n }\n this._pluginSlotNames = this._pluginSlotNames.filter(\n (n) => n !== detail.slotName,\n );\n const host = this._pluginHosts.get(detail.slotName);\n if (host) {\n host.remove();\n this._pluginHosts.delete(detail.slotName);\n }\n };\n\n connectedCallback() {\n super.connectedCallback();\n this.addEventListener(\n \"cds-aichat-markdown-plugin-host-mount\",\n this.handlePluginHostMount,\n );\n this.addEventListener(\n \"cds-aichat-markdown-plugin-host-update\",\n this.handlePluginHostUpdate,\n );\n this.addEventListener(\n \"cds-aichat-markdown-plugin-host-unmount\",\n this.handlePluginHostUnmount,\n );\n }\n\n disconnectedCallback() {\n this.removeEventListener(\n \"cds-aichat-markdown-plugin-host-mount\",\n this.handlePluginHostMount,\n );\n this.removeEventListener(\n \"cds-aichat-markdown-plugin-host-update\",\n this.handlePluginHostUpdate,\n );\n this.removeEventListener(\n \"cds-aichat-markdown-plugin-host-unmount\",\n this.handlePluginHostUnmount,\n );\n for (const host of this._pluginHosts.values()) {\n host.remove();\n }\n this._pluginHosts.clear();\n super.disconnectedCallback();\n }\n\n onBeforeRenderOverride = async (instance: ChatInstance) => {\n this._instance = instance;\n\n // Opt-in view-change observation hooks. The float container manages its own\n // visibility, so there is no default handler — a prop is only subscribed\n // when the consumer provides it.\n if (this.onViewPreChange) {\n this._instance.on({\n type: BusEventType.VIEW_PRE_CHANGE,\n handler: this.onViewPreChange,\n });\n }\n if (this.onViewChange) {\n this._instance.on({\n type: BusEventType.VIEW_CHANGE,\n handler: this.onViewChange,\n });\n }\n\n if (this.renderUserDefinedResponse) {\n // Enhanced path: library manages full state for callback rendering\n this._instance.on({\n type: BusEventType.USER_DEFINED_RESPONSE,\n handler: this.enhancedUserDefinedHandler,\n });\n this._instance.on({\n type: BusEventType.CHUNK_USER_DEFINED_RESPONSE,\n handler: this.enhancedUserDefinedChunkHandler,\n });\n } else {\n // Legacy path: container only tracks slot names\n this._instance.on({\n type: BusEventType.USER_DEFINED_RESPONSE,\n handler: this.userDefinedHandler,\n });\n this._instance.on({\n type: BusEventType.CHUNK_USER_DEFINED_RESPONSE,\n handler: this.userDefinedHandler,\n });\n }\n\n // Enhanced path manages full per-slot state for callback rendering; the\n // legacy path only tracks slot names for manual slotting.\n this._instance.on({\n type: BusEventType.CUSTOM_FOOTER_SLOT,\n handler: this.renderCustomMessageFooter\n ? this.enhancedCustomFooterHandler\n : this.customFooterHandler,\n });\n\n // A single RESTART_CONVERSATION subscription clears whichever callback\n // paths are active. Registered once so the handler does not fire twice\n // when both callbacks are provided.\n if (this.renderUserDefinedResponse || this.renderCustomMessageFooter) {\n this._instance.on({\n type: BusEventType.RESTART_CONVERSATION,\n handler: this.restartHandler,\n });\n }\n\n this.addWriteableElementSlots();\n this.attachWriteableElements();\n await this.onBeforeRender?.(instance);\n };\n\n addWriteableElementSlots() {\n const writeableElementSlots: string[] = [];\n Object.keys(this._instance.writeableElements).forEach(\n (writeableElementKey) => {\n writeableElementSlots.push(writeableElementKey);\n },\n );\n this._writeableElementSlots = writeableElementSlots;\n }\n\n private attachWriteableElements() {\n const writeableElements = this._instance?.writeableElements;\n if (!writeableElements) {\n return;\n }\n\n Object.entries(writeableElements).forEach(([slot, element]) => {\n if (!element) {\n return;\n }\n\n element.setAttribute(\"slot\", slot);\n\n if (!element.isConnected) {\n this.appendChild(element);\n }\n });\n }\n\n /**\n * Renders the template while passing in class functionality\n */\n render() {\n if (this.renderUserDefinedResponse) {\n this.syncCallbackRenderedElements();\n }\n if (this.renderCustomMessageFooter) {\n this.syncCallbackRenderedFooterElements();\n }\n\n return html`<cds-aichat-internal\n .config=${this.resolvedConfig}\n .onAfterRender=${this.onAfterRender}\n .onBeforeRender=${this.onBeforeRenderOverride}\n .element=${this.element}\n .markdown=${this.markdown as WCMarkdown | undefined}\n >\n ${this._writeableElementSlots.map(\n (slot) => html`<slot name=${slot} slot=${slot}></slot>`,\n )}\n ${this._userDefinedSlotNames.map(\n (slot) => html`<slot name=${slot} slot=${slot}></slot>`,\n )}\n ${this.renderCustomMessageFooter\n ? this._customFooterSlotNames.map(\n (slot) => html`<slot name=${slot} slot=${slot}></slot>`,\n )\n : this._customFooterSlotNames.map(\n (slot) => html`<div slot=${slot}><slot name=${slot}></slot></div>`,\n )}\n ${this._pluginSlotNames.map(\n (slot) => html`<slot name=${slot} slot=${slot}></slot>`,\n )}\n </cds-aichat-internal>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"cds-aichat-container\": ChatContainer;\n }\n}\n\n/**\n * Attributes interface for the cds-aichat-container web component.\n * This interface extends {@link PublicConfig} with additional component-specific props,\n * flattening all config properties as top-level properties for better TypeScript IntelliSense.\n *\n * @category Web component\n */\ninterface CdsAiChatContainerAttributes extends Omit<PublicConfig, \"markdown\"> {\n /**\n * Markdown rendering customization. Extends the framework-neutral\n * `PublicConfig.markdown` with web-component `customRenderers`.\n *\n * @experimental\n */\n markdown?: WCMarkdown;\n\n /**\n * This function is called before the render function of Carbon AI Chat is called. This function can return a Promise\n * which will cause Carbon AI Chat to wait for it before rendering.\n */\n onBeforeRender?: (instance: ChatInstance) => Promise<void> | void;\n\n /**\n * This function is called after the render function of Carbon AI Chat is called.\n */\n onAfterRender?: (instance: ChatInstance) => Promise<void> | void;\n\n /**\n * Called before a view change (the chat opening or closing). Async — return a Promise to defer the view\n * change until it resolves. This is an opt-in observation hook with no default visibility behavior.\n */\n onViewPreChange?: (event: BusEventViewPreChange) => Promise<void> | void;\n\n /**\n * Called when a view change (the chat opening or closing) is complete. This is an opt-in observation hook\n * with no default visibility behavior.\n */\n onViewChange?: (event: BusEventViewChange, instance: ChatInstance) => void;\n\n /**\n * Optional callback to render user defined responses. When provided, the library manages all event listening,\n * slot tracking, streaming state, and element lifecycle.\n */\n renderUserDefinedResponse?: WCRenderUserDefinedResponse;\n\n /**\n * Optional callback to render custom message footers. When provided, the library manages all event listening,\n * slot tracking, and element lifecycle. When omitted, the legacy event + manual slot approach continues to work.\n */\n renderCustomMessageFooter?: WCRenderCustomMessageFooter;\n}\n\nexport { CdsAiChatContainerAttributes };\nexport default ChatContainer;\n"],"names":["ChatContainerInternal","LitElement","firstUpdated","this","config","renderReactApp","updated","changedProperties","has","container","ensureReactRoot","root","render","React","createElement","ChatAppEntry","strings","serviceDeskFactory","serviceDesk","onBeforeRender","onAfterRender","element","markdown","reactContainer","document","classList","add","shadowRoot","appendChild","createRoot","disconnectedCallback","unmount","super","styles","css","__decorate","property","type","Object","prototype","attribute","HTMLElement","carbonElement","aiEnabledConverter","fromAttribute","value","undefined","v","String","trim","toLowerCase","falsey","FLATTENED_PUBLIC_CONFIG_FIELDS","name","options","Boolean","converter","resolveManually","resolveFlattenedConfig","source","resolved","field","aiDisabled","aiEnabled","buildFlattenedProperties","properties","FlattenedConfigElement","resolvedConfig","ChatContainer","constructor","_userDefinedSlotNames","_customFooterSlotNames","_writeableElementSlots","_pluginSlotNames","_pluginHosts","Map","_userDefinedStateBySlot","_customFooterStateBySlot","_callbackElements","_callbackFooterElements","userDefinedHandler","event","slot","data","includes","customFooterHandler","slotName","enhancedCustomFooterHandler","message","messageItem","additionalData","enhancedUserDefinedHandler","fullMessage","state","enhancedUserDefinedChunkHandler","chunk","complete_item","existing","partialItems","partial_item","restartHandler","el","values","remove","clear","renderCustomMessageFooter","handlePluginHostMount","detail","hasOuterChatHandler","preventDefault","setAttribute","isInline","style","marginBlockStart","parentElement","host","get","set","innerHTML","html","handlePluginHostUpdate","handlePluginHostUnmount","filter","n","delete","onBeforeRenderOverride","async","instance","_instance","onViewPreChange","on","BusEventType","VIEW_PRE_CHANGE","handler","onViewChange","VIEW_CHANGE","renderUserDefinedResponse","USER_DEFINED_RESPONSE","CHUNK_USER_DEFINED_RESPONSE","CUSTOM_FOOTER_SLOT","RESTART_CONVERSATION","addWriteableElementSlots","attachWriteableElements","syncCallbackRenderedElements","slotState","entries","newContent","wrapper","replaceChildren","syncCallbackRenderedFooterElements","path","composedPath","myIndex","indexOf","i","length","node","tagName","connectedCallback","addEventListener","removeEventListener","writeableElementSlots","keys","writeableElements","forEach","writeableElementKey","push","isConnected","map","ChatContainer_default"],"mappings":";;;;;;;;;;;;;;;;AAiCA,IAAMA,wBAAN,MAAMA,8BAA8BC;EA+DlC,YAAAC;IACE,IAAIC,KAAKC,QAAQ;MACfD,KAAKE;AACP;AACF;EAEA,OAAAC,CAAQC;IAEN,IACEJ,KAAKC,WACJG,kBAAkBC,IAAI,aACrBD,kBAAkBC,IAAI,cACtBD,kBAAkBC,IAAI,yBACtBD,kBAAkBC,IAAI,kBACtBD,kBAAkBC,IAAI,qBACtBD,kBAAkBC,IAAI,oBACtBD,kBAAkBC,IAAI,cACtBD,kBAAkBC,IAAI,cACxB;MACAL,KAAKE;AACP;AACF;EAYA,oBAAMA;IACJ,MAAMI,YAAYN,KAAKO;IAEvBP,KAAKQ,KAAKC,OACRC,MAAAC,cAACC,cAAY;MACXX,QAAQD,KAAKC;MACbY,SAASb,KAAKa;MACdC,oBAAoBd,KAAKc;MACzBC,aAAaf,KAAKe;MAClBC,gBAAgBhB,KAAKgB;MACrBC,eAAejB,KAAKiB;MACpBX;MACAY,SAASlB,KAAKkB;MACdC,UAAUnB,KAAKmB;;AAGrB;EAEQ,eAAAZ;IAC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