@carbon/ai-chat 1.13.0 → 1.14.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.
Files changed (31) hide show
  1. package/dist/css/chat-explainability-popover.css +161 -0
  2. package/dist/es/aiChatEntry.js +14 -2
  3. package/dist/es/aiChatEntry.js.map +1 -1
  4. package/dist/es/chat.ChatAppEntry.js +113 -21
  5. package/dist/es/chat.ChatAppEntry.js.map +1 -1
  6. package/dist/es/chat.index.js +581 -0
  7. package/dist/es/chat.index.js.map +1 -0
  8. package/dist/es/chat.languageUtils.js +2 -0
  9. package/dist/es/chat.languageUtils.js.map +1 -1
  10. package/dist/es/web-components/cds-aichat-container/index.js +10 -500
  11. package/dist/es/web-components/cds-aichat-container/index.js.map +1 -1
  12. package/dist/es/web-components/cds-aichat-custom-element/index.js +19 -227
  13. package/dist/es/web-components/cds-aichat-custom-element/index.js.map +1 -1
  14. package/dist/es-custom/aiChatEntry.js +14 -2
  15. package/dist/es-custom/aiChatEntry.js.map +1 -1
  16. package/dist/es-custom/chat.ChatAppEntry.js +113 -21
  17. package/dist/es-custom/chat.ChatAppEntry.js.map +1 -1
  18. package/dist/es-custom/chat.index.js +581 -0
  19. package/dist/es-custom/chat.index.js.map +1 -0
  20. package/dist/es-custom/chat.languageUtils.js +2 -0
  21. package/dist/es-custom/chat.languageUtils.js.map +1 -1
  22. package/dist/es-custom/web-components/cds-aichat-container/index.js +10 -500
  23. package/dist/es-custom/web-components/cds-aichat-container/index.js.map +1 -1
  24. package/dist/es-custom/web-components/cds-aichat-custom-element/index.js +19 -227
  25. package/dist/es-custom/web-components/cds-aichat-custom-element/index.js.map +1 -1
  26. package/dist/scss/_chat-explainability-popover.scss +154 -0
  27. package/dist/types/aiChatEntry.d.ts +2 -2
  28. package/dist/types/{serverEntry-CU81SMOz.d.ts → serverEntry-mONw-M8N.d.ts} +206 -47
  29. package/dist/types/serverEntry.d.ts +1 -1
  30. package/package.json +5 -5
  31. package/telemetry.yml +3 -24
@@ -1,8 +1,10 @@
1
1
  import { __decorate } from "tslib";
2
2
 
3
- export { default as __cds_aichat_container_register } from "../cds-aichat-container/index.js";
3
+ import { F as FlattenedConfigElement } from "../../chat.index.js";
4
4
 
5
- import { LitElement, html } from "lit";
5
+ export { C as __cds_aichat_container_register } from "../../chat.index.js";
6
+
7
+ import { html } from "lit";
6
8
 
7
9
  import { property, state } from "lit/decorators.js";
8
10
 
@@ -228,7 +230,7 @@ import "dayjs/locale/en.js";
228
230
 
229
231
  var ChatCustomElement_1;
230
232
 
231
- let ChatCustomElement = ChatCustomElement_1 = class ChatCustomElement extends LitElement {
233
+ let ChatCustomElement = ChatCustomElement_1 = class ChatCustomElement extends FlattenedConfigElement {
232
234
  constructor() {
233
235
  super(...arguments);
234
236
  this._userDefinedSlotNames = [];
@@ -275,10 +277,12 @@ let ChatCustomElement = ChatCustomElement_1 = class ChatCustomElement extends Li
275
277
  handler: this.userDefinedHandler
276
278
  });
277
279
  }
278
- this._instance.on({
279
- type: BusEventType.CUSTOM_FOOTER_SLOT,
280
- handler: this.customFooterHandler
281
- });
280
+ if (!this.renderCustomMessageFooter) {
281
+ this._instance.on({
282
+ type: BusEventType.CUSTOM_FOOTER_SLOT,
283
+ handler: this.customFooterHandler
284
+ });
285
+ }
282
286
  this.addWriteableElementSlots();
283
287
  await (this.onBeforeRender?.(instance));
284
288
  };
@@ -288,90 +292,6 @@ let ChatCustomElement = ChatCustomElement_1 = class ChatCustomElement extends Li
288
292
  root.adoptedStyleSheets = [ ...root.adoptedStyleSheets, ChatCustomElement_1.hideSheet ];
289
293
  return root;
290
294
  }
291
- get resolvedConfig() {
292
- const baseConfig = this.config ?? {};
293
- const resolvedConfig = {
294
- ...baseConfig
295
- };
296
- if (this.onError !== undefined) {
297
- resolvedConfig.onError = this.onError;
298
- }
299
- if (this.openChatByDefault !== undefined) {
300
- resolvedConfig.openChatByDefault = this.openChatByDefault;
301
- }
302
- if (this.disclaimer !== undefined) {
303
- resolvedConfig.disclaimer = this.disclaimer;
304
- }
305
- if (this.disableCustomElementMobileEnhancements !== undefined) {
306
- resolvedConfig.disableCustomElementMobileEnhancements = this.disableCustomElementMobileEnhancements;
307
- }
308
- if (this.debug !== undefined) {
309
- resolvedConfig.debug = this.debug;
310
- }
311
- if (this.exposeServiceManagerForTesting !== undefined) {
312
- resolvedConfig.exposeServiceManagerForTesting = this.exposeServiceManagerForTesting;
313
- }
314
- if (this.injectCarbonTheme !== undefined) {
315
- resolvedConfig.injectCarbonTheme = this.injectCarbonTheme;
316
- }
317
- if (this.serviceDeskFactory !== undefined) {
318
- resolvedConfig.serviceDeskFactory = this.serviceDeskFactory;
319
- }
320
- if (this.serviceDesk !== undefined) {
321
- resolvedConfig.serviceDesk = this.serviceDesk;
322
- }
323
- if (this.shouldTakeFocusIfOpensAutomatically !== undefined) {
324
- resolvedConfig.shouldTakeFocusIfOpensAutomatically = this.shouldTakeFocusIfOpensAutomatically;
325
- }
326
- if (this.namespace !== undefined) {
327
- resolvedConfig.namespace = this.namespace;
328
- }
329
- if (this.shouldSanitizeHTML !== undefined) {
330
- resolvedConfig.shouldSanitizeHTML = this.shouldSanitizeHTML;
331
- }
332
- if (this.header !== undefined) {
333
- resolvedConfig.header = this.header;
334
- }
335
- if (this.input !== undefined) {
336
- resolvedConfig.input = this.input;
337
- }
338
- if (this.upload !== undefined) {
339
- resolvedConfig.upload = this.upload;
340
- }
341
- if (this.layout !== undefined) {
342
- resolvedConfig.layout = this.layout;
343
- }
344
- if (this.messaging !== undefined) {
345
- resolvedConfig.messaging = this.messaging;
346
- }
347
- if (this.isReadonly !== undefined) {
348
- resolvedConfig.isReadonly = this.isReadonly;
349
- }
350
- if (this.assistantName !== undefined) {
351
- resolvedConfig.assistantName = this.assistantName;
352
- }
353
- if (this.assistantAvatarUrl !== undefined) {
354
- resolvedConfig.assistantAvatarUrl = this.assistantAvatarUrl;
355
- }
356
- if (this.locale !== undefined) {
357
- resolvedConfig.locale = this.locale;
358
- }
359
- if (this.homescreen !== undefined) {
360
- resolvedConfig.homescreen = this.homescreen;
361
- }
362
- if (this.launcher !== undefined) {
363
- resolvedConfig.launcher = this.launcher;
364
- }
365
- if (this.strings !== undefined) {
366
- resolvedConfig.strings = this.strings;
367
- }
368
- if (this.aiDisabled === true) {
369
- resolvedConfig.aiEnabled = false;
370
- } else if (this.aiEnabled !== undefined) {
371
- resolvedConfig.aiEnabled = this.aiEnabled;
372
- }
373
- return resolvedConfig;
374
- }
375
295
  addWriteableElementSlots() {
376
296
  this._writeableElementSlots = Object.keys(this._instance.writeableElements);
377
297
  }
@@ -379,14 +299,16 @@ let ChatCustomElement = ChatCustomElement_1 = class ChatCustomElement extends Li
379
299
  return html`
380
300
  <cds-aichat-container
381
301
  .config=${this.resolvedConfig}
302
+ .header=${this.resolvedConfig.header}
382
303
  .onAfterRender=${this.onAfterRender}
383
304
  .onBeforeRender=${this.onBeforeRenderOverride}
384
305
  .element=${this}
385
306
  .renderUserDefinedResponse=${this.renderUserDefinedResponse}
307
+ .renderCustomMessageFooter=${this.renderCustomMessageFooter}
386
308
  >
387
309
  ${this._writeableElementSlots.map(slot => html`<slot name=${slot} slot=${slot}></slot>`)}
388
310
  ${this.renderUserDefinedResponse ? null : this._userDefinedSlotNames.map(slot => html`<slot name=${slot} slot=${slot}></slot>`)}
389
- ${this._customFooterSlotNames.map(slot => html`<div slot=${slot}><slot name=${slot}></slot></div>`)}
311
+ ${this.renderCustomMessageFooter ? null : this._customFooterSlotNames.map(slot => html`<div slot=${slot}><slot name=${slot}></slot></div>`)}
390
312
  </cds-aichat-container>
391
313
  `;
392
314
  }
@@ -395,143 +317,9 @@ let ChatCustomElement = ChatCustomElement_1 = class ChatCustomElement extends Li
395
317
  ChatCustomElement.hideSheet = new CSSStyleSheet;
396
318
 
397
319
  (() => {
398
- ChatCustomElement_1.hideSheet.replaceSync(`\n :host {\n display: block;\n }\n :host(.cds-aichat--hidden) {\n width: 0 !important;\n height: 0 !important;\n min-width: 0 !important;\n min-height: 0 !important;\n max-width: 0 !important;\n max-height: 0 !important;\n inline-size: 0 !important;\n block-size: 0 !important;\n min-inline-size: 0 !important;\n min-block-size: 0 !important;\n max-inline-size: 0 !important;\n max-block-size: 0 !important;\n overflow: hidden !important;\n display: block !important;\n }\n `);
320
+ ChatCustomElement_1.hideSheet.replaceSync?.(`\n :host {\n display: block;\n }\n :host(.cds-aichat--hidden) {\n width: 0 !important;\n height: 0 !important;\n min-width: 0 !important;\n min-height: 0 !important;\n max-width: 0 !important;\n max-height: 0 !important;\n inline-size: 0 !important;\n block-size: 0 !important;\n min-inline-size: 0 !important;\n min-block-size: 0 !important;\n max-inline-size: 0 !important;\n max-block-size: 0 !important;\n overflow: hidden !important;\n display: block !important;\n }\n `);
399
321
  })();
400
322
 
401
- __decorate([ property({
402
- attribute: false,
403
- type: Object
404
- }) ], ChatCustomElement.prototype, "config", void 0);
405
-
406
- __decorate([ property({
407
- attribute: false
408
- }) ], ChatCustomElement.prototype, "onError", void 0);
409
-
410
- __decorate([ property({
411
- type: Boolean,
412
- attribute: "open-chat-by-default"
413
- }) ], ChatCustomElement.prototype, "openChatByDefault", void 0);
414
-
415
- __decorate([ property({
416
- type: Object
417
- }) ], ChatCustomElement.prototype, "disclaimer", void 0);
418
-
419
- __decorate([ property({
420
- type: Boolean,
421
- attribute: "disable-custom-element-mobile-enhancements"
422
- }) ], ChatCustomElement.prototype, "disableCustomElementMobileEnhancements", void 0);
423
-
424
- __decorate([ property({
425
- type: Boolean
426
- }) ], ChatCustomElement.prototype, "debug", void 0);
427
-
428
- __decorate([ property({
429
- type: Boolean,
430
- attribute: "expose-service-manager-for-testing"
431
- }) ], ChatCustomElement.prototype, "exposeServiceManagerForTesting", void 0);
432
-
433
- __decorate([ property({
434
- type: String,
435
- attribute: "inject-carbon-theme"
436
- }) ], ChatCustomElement.prototype, "injectCarbonTheme", void 0);
437
-
438
- __decorate([ property({
439
- attribute: "ai-enabled",
440
- converter: {
441
- fromAttribute: value => {
442
- if (value === null) {
443
- return undefined;
444
- }
445
- const v = String(value).trim().toLowerCase();
446
- const falsey = v === "false" || v === "0" || v === "off" || v === "no";
447
- return !falsey;
448
- }
449
- }
450
- }) ], ChatCustomElement.prototype, "aiEnabled", void 0);
451
-
452
- __decorate([ property({
453
- type: Boolean,
454
- attribute: "ai-disabled"
455
- }) ], ChatCustomElement.prototype, "aiDisabled", void 0);
456
-
457
- __decorate([ property({
458
- type: Boolean,
459
- attribute: "should-take-focus-if-opens-automatically"
460
- }) ], ChatCustomElement.prototype, "shouldTakeFocusIfOpensAutomatically", void 0);
461
-
462
- __decorate([ property({
463
- type: String
464
- }) ], ChatCustomElement.prototype, "namespace", void 0);
465
-
466
- __decorate([ property({
467
- type: Boolean,
468
- attribute: "should-sanitize-html"
469
- }) ], ChatCustomElement.prototype, "shouldSanitizeHTML", void 0);
470
-
471
- __decorate([ property({
472
- type: Object
473
- }) ], ChatCustomElement.prototype, "header", void 0);
474
-
475
- __decorate([ property({
476
- type: Object
477
- }) ], ChatCustomElement.prototype, "history", void 0);
478
-
479
- __decorate([ property({
480
- type: Object
481
- }) ], ChatCustomElement.prototype, "input", void 0);
482
-
483
- __decorate([ property({
484
- attribute: false,
485
- type: Object
486
- }) ], ChatCustomElement.prototype, "upload", void 0);
487
-
488
- __decorate([ property({
489
- type: Object
490
- }) ], ChatCustomElement.prototype, "layout", void 0);
491
-
492
- __decorate([ property({
493
- type: Object
494
- }) ], ChatCustomElement.prototype, "messaging", void 0);
495
-
496
- __decorate([ property({
497
- type: Boolean,
498
- attribute: "is-readonly"
499
- }) ], ChatCustomElement.prototype, "isReadonly", void 0);
500
-
501
- __decorate([ property({
502
- type: String,
503
- attribute: "assistant-name"
504
- }) ], ChatCustomElement.prototype, "assistantName", void 0);
505
-
506
- __decorate([ property({
507
- type: String
508
- }) ], ChatCustomElement.prototype, "assistantAvatarUrl", void 0);
509
-
510
- __decorate([ property({
511
- type: String
512
- }) ], ChatCustomElement.prototype, "locale", void 0);
513
-
514
- __decorate([ property({
515
- type: Object
516
- }) ], ChatCustomElement.prototype, "homescreen", void 0);
517
-
518
- __decorate([ property({
519
- type: Object
520
- }) ], ChatCustomElement.prototype, "launcher", void 0);
521
-
522
- __decorate([ property({
523
- attribute: false
524
- }) ], ChatCustomElement.prototype, "serviceDeskFactory", void 0);
525
-
526
- __decorate([ property({
527
- type: Object,
528
- attribute: "service-desk"
529
- }) ], ChatCustomElement.prototype, "serviceDesk", void 0);
530
-
531
- __decorate([ property({
532
- type: Object
533
- }) ], ChatCustomElement.prototype, "strings", void 0);
534
-
535
323
  __decorate([ property({
536
324
  attribute: false
537
325
  }) ], ChatCustomElement.prototype, "onBeforeRender", void 0);
@@ -548,6 +336,10 @@ __decorate([ property({
548
336
  attribute: false
549
337
  }) ], ChatCustomElement.prototype, "renderUserDefinedResponse", void 0);
550
338
 
339
+ __decorate([ property({
340
+ attribute: false
341
+ }) ], ChatCustomElement.prototype, "renderCustomMessageFooter", void 0);
342
+
551
343
  __decorate([ state() ], ChatCustomElement.prototype, "_userDefinedSlotNames", void 0);
552
344
 
553
345
  __decorate([ state() ], ChatCustomElement.prototype, "_writeableElementSlots", void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../../../src/web-components/cds-aichat-custom-element/index.ts"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025\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// Ensure the container custom element is registered whenever the\n// custom element module is imported by re-exporting its exports.\n// This prevents bundlers (and our own multi-entry Rollup build)\n// from pruning the side-effect-only import.\nexport { default as __cds_aichat_container_register } from \"../cds-aichat-container\";\nimport \"../cds-aichat-container\";\n\nimport { html, LitElement } from \"lit\";\nimport { property, state } from \"lit/decorators.js\";\n\nimport { carbonElement } from \"@carbon/ai-chat-components/es/globals/decorators/index.js\";\nimport {\n PublicConfig,\n OnErrorData,\n DisclaimerPublicConfig,\n CarbonTheme,\n HeaderConfig,\n HistoryConfig,\n LayoutConfig,\n PublicConfigMessaging,\n LanguagePack,\n InputConfig,\n UploadConfig,\n} from \"../../types/config/PublicConfig\";\nimport { DeepPartial } from \"../../types/utilities/DeepPartial\";\nimport { HomeScreenConfig } from \"../../types/config/HomeScreenConfig\";\nimport { LauncherConfig } from \"../../types/config/LauncherConfig\";\nimport type {\n ServiceDesk,\n ServiceDeskFactoryParameters,\n ServiceDeskPublicConfig,\n} from \"../../types/config/ServiceDeskConfig\";\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 { WCRenderUserDefinedResponse } from \"../../types/component/ChatContainer\";\n\n/**\n * cds-aichat-custom-element will is a pass through to cds-aichat-container. It takes any user_defined and writeable element\n * slotted content and forwards it to cds-aichat-container. It also will setup the custom element with a default viewChange\n * pattern (e.g. hiding and showing the custom element when the chat should be open/closed) if a onViewChange property is not\n * defined. Finally, it registers the custom element with cds-aichat-container so a default \"floating\" element will not be created.\n *\n * The custom element should be sized using external CSS. When hidden, the 'cds-aichat--hidden' class is added to set dimensions to 0x0.\n */\n@carbonElement(\"cds-aichat-custom-element\")\nclass ChatCustomElement extends LitElement {\n @property({ attribute: false, type: Object })\n config?: PublicConfig;\n\n /**\n * Shared stylesheet for hiding styles.\n */\n private static hideSheet = new CSSStyleSheet();\n static {\n // Hide styles that override any external sizing\n ChatCustomElement.hideSheet.replaceSync(`\n :host {\n display: block;\n }\n :host(.cds-aichat--hidden) {\n width: 0 !important;\n height: 0 !important;\n min-width: 0 !important;\n min-height: 0 !important;\n max-width: 0 !important;\n max-height: 0 !important;\n inline-size: 0 !important;\n block-size: 0 !important;\n min-inline-size: 0 !important;\n min-block-size: 0 !important;\n max-inline-size: 0 !important;\n max-block-size: 0 !important;\n overflow: hidden !important;\n display: block !important;\n }\n `);\n }\n\n /**\n * Adopt our stylesheet into every shadowRoot.\n */\n protected createRenderRoot(): ShadowRoot {\n // Lits default createRenderRoot actually returns a ShadowRoot\n const root = super.createRenderRoot() as ShadowRoot;\n\n // now TS knows root.adoptedStyleSheets exists\n root.adoptedStyleSheets = [\n ...root.adoptedStyleSheets,\n ChatCustomElement.hideSheet,\n ];\n return root;\n }\n\n // Flattened PublicConfig properties\n @property({ attribute: false })\n onError?: (data: OnErrorData) => void;\n\n @property({ type: Boolean, attribute: \"open-chat-by-default\" })\n openChatByDefault?: boolean;\n\n @property({ type: Object })\n disclaimer?: DisclaimerPublicConfig;\n\n @property({\n type: Boolean,\n attribute: \"disable-custom-element-mobile-enhancements\",\n })\n disableCustomElementMobileEnhancements?: boolean;\n\n @property({ type: Boolean })\n debug?: boolean;\n\n @property({ type: Boolean, attribute: \"expose-service-manager-for-testing\" })\n exposeServiceManagerForTesting?: boolean;\n\n @property({ type: String, attribute: \"inject-carbon-theme\" })\n injectCarbonTheme?: CarbonTheme;\n\n @property({\n attribute: \"ai-enabled\",\n converter: {\n fromAttribute: (value: string | null) => {\n if (value === null) {\n return undefined;\n }\n const v = String(value).trim().toLowerCase();\n const falsey = v === \"false\" || v === \"0\" || v === \"off\" || v === \"no\";\n return !falsey;\n },\n },\n })\n aiEnabled?: boolean;\n\n @property({ type: Boolean, attribute: \"ai-disabled\" })\n aiDisabled?: boolean;\n\n @property({\n type: Boolean,\n attribute: \"should-take-focus-if-opens-automatically\",\n })\n shouldTakeFocusIfOpensAutomatically?: boolean;\n\n @property({ type: String })\n namespace?: string;\n\n @property({ type: Boolean, attribute: \"should-sanitize-html\" })\n shouldSanitizeHTML?: boolean;\n\n @property({ type: Object })\n header?: HeaderConfig;\n\n @property({ type: Object })\n history?: HistoryConfig;\n\n @property({ type: Object })\n input?: InputConfig;\n\n @property({ attribute: false, type: Object })\n upload?: UploadConfig;\n\n @property({ type: Object })\n layout?: LayoutConfig;\n\n @property({ type: Object })\n messaging?: PublicConfigMessaging;\n\n @property({ type: Boolean, attribute: \"is-readonly\" })\n isReadonly?: boolean;\n\n @property({ type: String, attribute: \"assistant-name\" })\n assistantName?: string;\n\n @property({ type: String })\n assistantAvatarUrl?: string;\n\n @property({ type: String })\n locale?: string;\n\n @property({ type: Object })\n homescreen?: HomeScreenConfig;\n\n @property({ type: Object })\n launcher?: LauncherConfig;\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, attribute: \"service-desk\" })\n serviceDesk?: ServiceDeskPublicConfig;\n\n /** Optional partial language pack overrides */\n @property({ type: Object })\n strings?: DeepPartial<LanguagePack>;\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({ 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 @property({ attribute: false })\n onAfterRender?: (instance: ChatInstance) => Promise<void> | void;\n\n /**\n * Called before a view change (chat opening/closing). The chat will hide the chat shell inside your custom element\n * to prevent invisible keyboard stops when the view change is complete.\n *\n * Use this callback to update your CSS class name values on this element before the view change happens if you want to add any open/close\n * animations to your custom element before the chat shell inner contents are hidden. It is async and so you can\n * tie it to native the AnimationEvent and only return when your animations have completed.\n *\n * A common pattern is to use this for when the chat is closing and to use onViewChange for when the chat opens.\n *\n * Note that this function can only be provided before Carbon AI Chat is loaded as it is registered before the\n * chat renders. After Carbon AI Chat is loaded, the callback will not be updated.\n */\n @property()\n onViewPreChange?: (event: BusEventViewPreChange) => Promise<void> | void;\n\n /**\n * Called when the chat view change is complete. If no callback is provided here, the default behavior will be to set\n * the chat shell to 0x0 size and set all inner contents aside from the launcher, if you are using it, to display: none.\n * The inner contents of the chat shell (aside from the launcher if you are using it) are always set to display: none\n * regardless of what is configured with this callback to prevent invisible tab stops and screen reader issues.\n *\n * Use this callback to update your className value when the chat has finished being opened or closed.\n *\n * You can provide a different callback here if you want custom animation behavior when the chat is opened or closed.\n * The animation behavior defined here will run in concert with the chat inside your custom container being hidden.\n *\n * If you want to run animations before the inner contents of the chat shell is shrunk and the inner contents are hidden,\n * make use of onViewPreChange.\n *\n * A common pattern is to use this for when the chat is opening and to use onViewPreChange for when the chat closes.\n *\n * Note that this function can only be provided before Carbon AI Chat is loaded as it is registered before the\n * chat renders. After Carbon AI Chat is loaded, the callback will not be updated.\n */\n @property()\n onViewChange?: (event: BusEventViewChange, instance: ChatInstance) => void;\n\n /**\n * Optional callback to render user defined responses. When provided, the inner cds-aichat-container\n * manages all event listening, slot tracking, and element lifecycle.\n */\n @property({ attribute: false })\n renderUserDefinedResponse?: WCRenderUserDefinedResponse;\n\n @state()\n private _userDefinedSlotNames: string[] = [];\n\n @state()\n private _writeableElementSlots: string[] = [];\n\n @state()\n private _customFooterSlotNames: string[] = [];\n\n @state()\n private _instance!: ChatInstance;\n\n private defaultViewChangeHandler = (event: BusEventViewChange) => {\n if (event.newViewState.mainWindow) {\n this.classList.remove(\"cds-aichat--hidden\");\n } else {\n this.classList.add(\"cds-aichat--hidden\");\n }\n };\n\n private userDefinedHandler = (\n event: BusEventUserDefinedResponse | BusEventChunkUserDefinedResponse,\n ) => {\n const { slot } = event.data;\n if (!this._userDefinedSlotNames.includes(slot)) {\n this._userDefinedSlotNames = [...this._userDefinedSlotNames, slot];\n }\n };\n\n private customFooterHandler = (event: BusEventCustomFooterSlot) => {\n const { slotName } = event.data;\n if (!this._customFooterSlotNames.includes(slotName)) {\n this._customFooterSlotNames = [...this._customFooterSlotNames, slotName];\n }\n };\n\n private get resolvedConfig(): PublicConfig {\n const baseConfig = this.config ?? {};\n const resolvedConfig: PublicConfig = { ...baseConfig };\n\n if (this.onError !== undefined) {\n resolvedConfig.onError = this.onError;\n }\n if (this.openChatByDefault !== undefined) {\n resolvedConfig.openChatByDefault = this.openChatByDefault;\n }\n if (this.disclaimer !== undefined) {\n resolvedConfig.disclaimer = this.disclaimer;\n }\n if (this.disableCustomElementMobileEnhancements !== undefined) {\n resolvedConfig.disableCustomElementMobileEnhancements =\n this.disableCustomElementMobileEnhancements;\n }\n if (this.debug !== undefined) {\n resolvedConfig.debug = this.debug;\n }\n if (this.exposeServiceManagerForTesting !== undefined) {\n resolvedConfig.exposeServiceManagerForTesting =\n this.exposeServiceManagerForTesting;\n }\n if (this.injectCarbonTheme !== undefined) {\n resolvedConfig.injectCarbonTheme = this.injectCarbonTheme;\n }\n if (this.serviceDeskFactory !== undefined) {\n resolvedConfig.serviceDeskFactory = this.serviceDeskFactory;\n }\n if (this.serviceDesk !== undefined) {\n resolvedConfig.serviceDesk = this.serviceDesk;\n }\n if (this.shouldTakeFocusIfOpensAutomatically !== undefined) {\n resolvedConfig.shouldTakeFocusIfOpensAutomatically =\n this.shouldTakeFocusIfOpensAutomatically;\n }\n if (this.namespace !== undefined) {\n resolvedConfig.namespace = this.namespace;\n }\n if (this.shouldSanitizeHTML !== undefined) {\n resolvedConfig.shouldSanitizeHTML = this.shouldSanitizeHTML;\n }\n if (this.header !== undefined) {\n resolvedConfig.header = this.header;\n }\n if (this.input !== undefined) {\n resolvedConfig.input = this.input;\n }\n if (this.upload !== undefined) {\n resolvedConfig.upload = this.upload;\n }\n if (this.layout !== undefined) {\n resolvedConfig.layout = this.layout;\n }\n if (this.messaging !== undefined) {\n resolvedConfig.messaging = this.messaging;\n }\n if (this.isReadonly !== undefined) {\n resolvedConfig.isReadonly = this.isReadonly;\n }\n if (this.assistantName !== undefined) {\n resolvedConfig.assistantName = this.assistantName;\n }\n if (this.assistantAvatarUrl !== undefined) {\n resolvedConfig.assistantAvatarUrl = this.assistantAvatarUrl;\n }\n if (this.locale !== undefined) {\n resolvedConfig.locale = this.locale;\n }\n if (this.homescreen !== undefined) {\n resolvedConfig.homescreen = this.homescreen;\n }\n if (this.launcher !== undefined) {\n resolvedConfig.launcher = this.launcher;\n }\n if (this.strings !== undefined) {\n resolvedConfig.strings = this.strings;\n }\n\n if (this.aiDisabled === true) {\n resolvedConfig.aiEnabled = false;\n } else if (this.aiEnabled !== undefined) {\n resolvedConfig.aiEnabled = this.aiEnabled;\n }\n\n return resolvedConfig;\n }\n\n private onBeforeRenderOverride = async (instance: ChatInstance) => {\n this._instance = instance;\n if (this.onViewPreChange) {\n this._instance.on({\n type: BusEventType.VIEW_PRE_CHANGE,\n handler: this.onViewPreChange,\n });\n }\n this._instance.on({\n type: BusEventType.VIEW_CHANGE,\n handler: this.onViewChange || this.defaultViewChangeHandler,\n });\n\n if (!this.renderUserDefinedResponse) {\n // Legacy path: custom-element tracks slot names for manual slotting.\n // When renderUserDefinedResponse is set, the inner cds-aichat-container handles everything.\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 this._instance.on({\n type: BusEventType.CUSTOM_FOOTER_SLOT,\n handler: this.customFooterHandler,\n });\n this.addWriteableElementSlots();\n await this.onBeforeRender?.(instance);\n };\n\n private addWriteableElementSlots() {\n this._writeableElementSlots = Object.keys(this._instance.writeableElements);\n }\n\n render() {\n return html`\n <cds-aichat-container\n .config=${this.resolvedConfig}\n .onAfterRender=${this.onAfterRender}\n .onBeforeRender=${this.onBeforeRenderOverride}\n .element=${this}\n .renderUserDefinedResponse=${this.renderUserDefinedResponse}\n >\n ${this._writeableElementSlots.map(\n (slot) => html`<slot name=${slot} slot=${slot}></slot>`,\n )}\n ${this.renderUserDefinedResponse\n ? null\n : this._userDefinedSlotNames.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 </cds-aichat-container>\n `;\n }\n}\n\n/**\n * Attributes interface for the cds-aichat-custom-element web component.\n * This interface extends {@link CdsAiChatContainerAttributes} and {@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 CdsAiChatCustomElementAttributes extends PublicConfig {\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 * An optional listener for \"view:change\" events. Such a listener is required when using a custom element in order\n * to control the visibility of the Carbon AI Chat main window. If no callback is provided here, a default one will be\n * used that injects styling into the app that will show and hide the Carbon AI Chat main window and also change the\n * size of the custom element so it doesn't take up space when the main window is closed.\n *\n * You can provide a different callback here if you want custom behavior such as an animation when the main window\n * is opened or closed.\n *\n * Note that this function can only be provided before Carbon AI Chat is loaded. After Carbon AI Chat is loaded, the event\n * handler will not be updated.\n */\n onViewChange?: (event: BusEventViewChange, instance: ChatInstance) => void;\n\n /**\n * Optional callback to render user defined responses. When provided, the inner cds-aichat-container\n * manages all event listening, slot tracking, streaming state, and element lifecycle.\n */\n renderUserDefinedResponse?: WCRenderUserDefinedResponse;\n}\n\nexport { CdsAiChatCustomElementAttributes };\n\nexport default ChatCustomElement;\n"],"names":["ChatCustomElement","ChatCustomElement_1","LitElement","constructor","this","_userDefinedSlotNames","_writeableElementSlots","_customFooterSlotNames","defaultViewChangeHandler","event","newViewState","mainWindow","classList","remove","add","userDefinedHandler","slot","data","includes","customFooterHandler","slotName","onBeforeRenderOverride","async","instance","_instance","onViewPreChange","on","type","BusEventType","VIEW_PRE_CHANGE","handler","VIEW_CHANGE","onViewChange","renderUserDefinedResponse","USER_DEFINED_RESPONSE","CHUNK_USER_DEFINED_RESPONSE","CUSTOM_FOOTER_SLOT","addWriteableElementSlots","onBeforeRender","createRenderRoot","root","super","adoptedStyleSheets","hideSheet","resolvedConfig","baseConfig","config","onError","undefined","openChatByDefault","disclaimer","disableCustomElementMobileEnhancements","debug","exposeServiceManagerForTesting","injectCarbonTheme","serviceDeskFactory","serviceDesk","shouldTakeFocusIfOpensAutomatically","namespace","shouldSanitizeHTML","header","input","upload","layout","messaging","isReadonly","assistantName","assistantAvatarUrl","locale","homescreen","launcher","strings","aiDisabled","aiEnabled","Object","keys","writeableElements","render","html","onAfterRender","map","CSSStyleSheet","replaceSync","__decorate","property","attribute","prototype","Boolean","String","converter","fromAttribute","value","v","trim","toLowerCase","falsey","state","carbonElement","ChatCustomElement_default"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,IAAMA,oBAAiBC,sBAAvB,MAAMD,0BAA0BE;EAAhC,WAAAC;;IAoNUC,KAAAC,wBAAkC;IAGlCD,KAAAE,yBAAmC;IAGnCF,KAAAG,yBAAmC;IAKnCH,KAAAI,2BAA4BC;MAClC,IAAIA,MAAMC,aAAaC,YAAY;QACjCP,KAAKQ,UAAUC,OAAO;AACxB,aAAO;QACLT,KAAKQ,UAAUE,IAAI;AACrB;;IAGMV,KAAAW,qBACNN;MAEA,OAAMO,QAAWP,MAAMQ;MACvB,KAAKb,KAAKC,sBAAsBa,SAASF,OAAO;QAC9CZ,KAAKC,wBAAwB,KAAID,KAAKC,uBAAuBW;AAC/D;;IAGMZ,KAAAe,sBAAuBV;MAC7B,OAAMW,YAAeX,MAAMQ;MAC3B,KAAKb,KAAKG,uBAAuBW,SAASE,WAAW;QACnDhB,KAAKG,yBAAyB,KAAIH,KAAKG,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custom-element/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// Ensure the container custom element is registered whenever the\n// custom element module is imported by re-exporting its exports.\n// This prevents bundlers (and our own multi-entry Rollup build)\n// from pruning the side-effect-only import.\nexport { default as __cds_aichat_container_register } from \"../cds-aichat-container\";\nimport \"../cds-aichat-container\";\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 WCRenderCustomMessageFooter,\n WCRenderUserDefinedResponse,\n} from \"../../types/component/ChatContainer\";\n\n/**\n * cds-aichat-custom-element will is a pass through to cds-aichat-container. It takes any user_defined and writeable element\n * slotted content and forwards it to cds-aichat-container. It also will setup the custom element with a default viewChange\n * pattern (e.g. hiding and showing the custom element when the chat should be open/closed) if a onViewChange property is not\n * defined. Finally, it registers the custom element with cds-aichat-container so a default \"floating\" element will not be created.\n *\n * The custom element should be sized using external CSS. When hidden, the 'cds-aichat--hidden' class is added to set dimensions to 0x0.\n */\n@carbonElement(\"cds-aichat-custom-element\")\nclass ChatCustomElement extends FlattenedConfigElement {\n /**\n * Shared stylesheet for hiding styles.\n */\n private static hideSheet = new CSSStyleSheet();\n static {\n // Hide styles that override any external sizing. `replaceSync` is absent\n // in non-browser environments (e.g. the jsdom-based test environment), so\n // skip styling there rather than throwing at module-evaluation time.\n ChatCustomElement.hideSheet.replaceSync?.(`\n :host {\n display: block;\n }\n :host(.cds-aichat--hidden) {\n width: 0 !important;\n height: 0 !important;\n min-width: 0 !important;\n min-height: 0 !important;\n max-width: 0 !important;\n max-height: 0 !important;\n inline-size: 0 !important;\n block-size: 0 !important;\n min-inline-size: 0 !important;\n min-block-size: 0 !important;\n max-inline-size: 0 !important;\n max-block-size: 0 !important;\n overflow: hidden !important;\n display: block !important;\n }\n `);\n }\n\n /**\n * Adopt our stylesheet into every shadowRoot.\n */\n protected createRenderRoot(): ShadowRoot {\n // Lits default createRenderRoot actually returns a ShadowRoot\n const root = super.createRenderRoot() as ShadowRoot;\n\n // now TS knows root.adoptedStyleSheets exists\n root.adoptedStyleSheets = [\n ...root.adoptedStyleSheets,\n ChatCustomElement.hideSheet,\n ];\n return root;\n }\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({ 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 @property({ attribute: false })\n onAfterRender?: (instance: ChatInstance) => Promise<void> | void;\n\n /**\n * Called before a view change (chat opening/closing). The chat will hide the chat shell inside your custom element\n * to prevent invisible keyboard stops when the view change is complete.\n *\n * Use this callback to update your CSS class name values on this element before the view change happens if you want to add any open/close\n * animations to your custom element before the chat shell inner contents are hidden. It is async and so you can\n * tie it to native the AnimationEvent and only return when your animations have completed.\n *\n * A common pattern is to use this for when the chat is closing and to use onViewChange for when the chat opens.\n *\n * Note that this function can only be provided before Carbon AI Chat is loaded as it is registered before the\n * chat renders. After Carbon AI Chat is loaded, the callback will not be updated.\n */\n @property()\n onViewPreChange?: (event: BusEventViewPreChange) => Promise<void> | void;\n\n /**\n * Called when the chat view change is complete. If no callback is provided here, the default behavior will be to set\n * the chat shell to 0x0 size and set all inner contents aside from the launcher, if you are using it, to display: none.\n * The inner contents of the chat shell (aside from the launcher if you are using it) are always set to display: none\n * regardless of what is configured with this callback to prevent invisible tab stops and screen reader issues.\n *\n * Use this callback to update your className value when the chat has finished being opened or closed.\n *\n * You can provide a different callback here if you want custom animation behavior when the chat is opened or closed.\n * The animation behavior defined here will run in concert with the chat inside your custom container being hidden.\n *\n * If you want to run animations before the inner contents of the chat shell is shrunk and the inner contents are hidden,\n * make use of onViewPreChange.\n *\n * A common pattern is to use this for when the chat is opening and to use onViewPreChange for when the chat closes.\n *\n * Note that this function can only be provided before Carbon AI Chat is loaded as it is registered before the\n * chat renders. After Carbon AI Chat is loaded, the callback will not be updated.\n */\n @property()\n onViewChange?: (event: BusEventViewChange, instance: ChatInstance) => void;\n\n /**\n * Optional callback to render user defined responses. When provided, the inner cds-aichat-container\n * manages all event listening, slot tracking, and element lifecycle.\n */\n @property({ attribute: false })\n renderUserDefinedResponse?: WCRenderUserDefinedResponse;\n\n /**\n * Optional callback to render custom message footers. When provided, the inner cds-aichat-container\n * manages all event listening, slot tracking, and element lifecycle.\n */\n @property({ attribute: false })\n renderCustomMessageFooter?: WCRenderCustomMessageFooter;\n\n @state()\n private _userDefinedSlotNames: string[] = [];\n\n @state()\n private _writeableElementSlots: string[] = [];\n\n @state()\n private _customFooterSlotNames: string[] = [];\n\n @state()\n private _instance!: ChatInstance;\n\n private defaultViewChangeHandler = (event: BusEventViewChange) => {\n if (event.newViewState.mainWindow) {\n this.classList.remove(\"cds-aichat--hidden\");\n } else {\n this.classList.add(\"cds-aichat--hidden\");\n }\n };\n\n private userDefinedHandler = (\n event: BusEventUserDefinedResponse | BusEventChunkUserDefinedResponse,\n ) => {\n const { slot } = event.data;\n if (!this._userDefinedSlotNames.includes(slot)) {\n this._userDefinedSlotNames = [...this._userDefinedSlotNames, slot];\n }\n };\n\n private customFooterHandler = (event: BusEventCustomFooterSlot) => {\n const { slotName } = event.data;\n if (!this._customFooterSlotNames.includes(slotName)) {\n this._customFooterSlotNames = [...this._customFooterSlotNames, slotName];\n }\n };\n\n private onBeforeRenderOverride = async (instance: ChatInstance) => {\n this._instance = instance;\n if (this.onViewPreChange) {\n this._instance.on({\n type: BusEventType.VIEW_PRE_CHANGE,\n handler: this.onViewPreChange,\n });\n }\n this._instance.on({\n type: BusEventType.VIEW_CHANGE,\n handler: this.onViewChange || this.defaultViewChangeHandler,\n });\n\n if (!this.renderUserDefinedResponse) {\n // Legacy path: custom-element tracks slot names for manual slotting.\n // When renderUserDefinedResponse is set, the inner cds-aichat-container handles everything.\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 if (!this.renderCustomMessageFooter) {\n // Legacy path: custom-element tracks slot names for manual slotting.\n // When renderCustomMessageFooter is set, the inner cds-aichat-container handles everything.\n this._instance.on({\n type: BusEventType.CUSTOM_FOOTER_SLOT,\n handler: this.customFooterHandler,\n });\n }\n this.addWriteableElementSlots();\n await this.onBeforeRender?.(instance);\n };\n\n private addWriteableElementSlots() {\n this._writeableElementSlots = Object.keys(this._instance.writeableElements);\n }\n\n render() {\n return html`\n <cds-aichat-container\n .config=${this.resolvedConfig}\n .header=${this.resolvedConfig.header}\n .onAfterRender=${this.onAfterRender}\n .onBeforeRender=${this.onBeforeRenderOverride}\n .element=${this}\n .renderUserDefinedResponse=${this.renderUserDefinedResponse}\n .renderCustomMessageFooter=${this.renderCustomMessageFooter}\n >\n ${this._writeableElementSlots.map(\n (slot) => html`<slot name=${slot} slot=${slot}></slot>`,\n )}\n ${this.renderUserDefinedResponse\n ? null\n : this._userDefinedSlotNames.map(\n (slot) => html`<slot name=${slot} slot=${slot}></slot>`,\n )}\n ${this.renderCustomMessageFooter\n ? null\n : this._customFooterSlotNames.map(\n (slot) =>\n html`<div slot=${slot}><slot name=${slot}></slot></div>`,\n )}\n </cds-aichat-container>\n `;\n }\n}\n\n/**\n * Attributes interface for the cds-aichat-custom-element 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 CdsAiChatCustomElementAttributes extends PublicConfig {\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 * An optional listener for \"view:change\" events. Such a listener is required when using a custom element in order\n * to control the visibility of the Carbon AI Chat main window. If no callback is provided here, a default one will be\n * used that injects styling into the app that will show and hide the Carbon AI Chat main window and also change the\n * size of the custom element so it doesn't take up space when the main window is closed.\n *\n * You can provide a different callback here if you want custom behavior such as an animation when the main window\n * is opened or closed.\n *\n * Note that this function can only be provided before Carbon AI Chat is loaded. After Carbon AI Chat is loaded, the event\n * handler will not be updated.\n */\n onViewChange?: (event: BusEventViewChange, instance: ChatInstance) => void;\n\n /**\n * Optional callback to render user defined responses. When provided, the inner cds-aichat-container\n * manages all event listening, slot tracking, streaming state, and element lifecycle.\n */\n renderUserDefinedResponse?: WCRenderUserDefinedResponse;\n\n /**\n * Optional callback to render custom message footers. When provided, the inner cds-aichat-container\n * manages all event listening, slot tracking, and element lifecycle.\n */\n renderCustomMessageFooter?: WCRenderCustomMessageFooter;\n}\n\nexport { CdsAiChatCustomElementAttributes };\n\nexport default ChatCustomElement;\n"],"names":["ChatCustomElement","ChatCustomElement_1","FlattenedConfigElement","constructor","this","_userDefinedSlotNames","_writeableElementSlots","_customFooterSlotNames","defaultViewChangeHandler","event","newViewState","mainWindow","classList","remove","add","userDefinedHandler","slot","data","includes","customFooterHandler","slotName","onBeforeRenderOverride","async","instance","_instance","onViewPreChange","on","type","BusEventType","VIEW_PRE_CHANGE","handler","VIEW_CHANGE","onViewChange","renderUserDefinedResponse","USER_DEFINED_RESPONSE","CHUNK_USER_DEFINED_RESPONSE","renderCustomMessageFooter","CUSTOM_FOOTER_SLOT","addWriteableElementSlots","onBeforeRender","createRenderRoot","root","super","adoptedStyleSheets","hideSheet","Object","keys","writeableElements","render","html","resolvedConfig","header","onAfterRender","map","CSSStyleSheet","replaceSync","__decorate","property","attribute","prototype","state","carbonElement","ChatCustomElement_default"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAMA,oBAAiBC,sBAAvB,MAAMD,0BAA0BE;EAAhC,WAAAC;;IAiHUC,KAAAC,wBAAkC;IAGlCD,KAAAE,yBAAmC;IAGnCF,KAAAG,yBAAmC;IAKnCH,KAAAI,2BAA4BC;MAClC,IAAIA,MAAMC,aAAaC,YAAY;QACjCP,KAAKQ,UAAUC,OAAO;AACxB,aAAO;QACLT,KAAKQ,UAAUE,IAAI;AACrB;;IAGMV,KAAAW,qBACNN;MAEA,OAAMO,QAAWP,MAAMQ;MACvB,KAAKb,KAAKC,sBAAsBa,SAASF,OAAO;QAC9CZ,KAAKC,wBAAwB,KAAID,KAAKC,uBAAuBW;AAC/D;;IAGMZ,KAAAe,sBAAuBV;MAC7B,OAAMW,YAAeX,MAAMQ;MAC3B,KAAKb,KAAKG,uBAAuBW,SAASE,WAAW;QACnDhB,KAAKG,yBAAyB,KAAIH,KAAKG,wBAAwBa;AACjE;;IAGMhB,KAAAiB,yBAAyBC,MAAOC;MACtCnB,KAAKoB,YAAYD;MACjB,IAAInB,KAAKqB,iBAAiB;QACxBrB,KAAKoB,UAAUE,GAAG;UAChBC,MAAMC,aAAaC;UACnBC,SAAS1B,KAAKqB;;AAElB;MACArB,KAAKoB,UAAUE,GAAG;QAChBC,MA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AAgBjEH,WAAA,EADCC,cACwEzD,kBAAA2D,WAAA;;AAsBzEH,WAAA,EADCC,cAC0EzD,kBAAA2D,WAAA;;AAO3EH,WAAA,EADCC,SAAS;EAAEC,WAAW;MACiC1D,kBAAA2D,WAAA;;AAOxDH,WAAA,EADCC,SAAS;EAAEC,WAAW;MACiC1D,kBAAA2D,WAAA;;AAGhDH,WAAA,EADPI,WAC4C5D,kBAAA2D,WAAA;;AAGrCH,WAAA,EADPI,WAC6C5D,kBAAA2D,WAAA;;AAGtCH,WAAA,EADPI,WAC6C5D,kBAAA2D,WAAA;;AAGtCH,WAAA,EADPI,WACgC5D,kBAAA2D,WAAA;;AA1H7B3D,oBAAiBC,sBAAAuD,WAAA,EADtBK,cAAc,gCACT7D;;AA4QN,IAAA8D,4BAAe9D;;"}
@@ -271,7 +271,7 @@ const ReactChatContainer = React.memo(createComponent({
271
271
  }));
272
272
 
273
273
  function ChatContainer(props) {
274
- const {onBeforeRender, onAfterRender, strings, serviceDeskFactory, serviceDesk, renderUserDefinedResponse, renderCustomMessageFooter, renderWriteableElements, element, onError, openChatByDefault, disclaimer, disableCustomElementMobileEnhancements, debug, exposeServiceManagerForTesting, injectCarbonTheme, aiEnabled, shouldTakeFocusIfOpensAutomatically, namespace, shouldSanitizeHTML, header, history, layout, messaging, isReadonly, persistFeedback, assistantName, assistantAvatarUrl, locale, homescreen, launcher, input, keyboardShortcuts, upload, ...domProps} = props;
274
+ const {onBeforeRender, onAfterRender, onViewChange, onViewPreChange, strings, serviceDeskFactory, serviceDesk, renderUserDefinedResponse, renderCustomMessageFooter, renderWriteableElements, element, onError, openChatByDefault, disclaimer, disableCustomElementMobileEnhancements, debug, exposeServiceManagerForTesting, injectCarbonTheme, aiEnabled, shouldTakeFocusIfOpensAutomatically, namespace, shouldSanitizeHTML, header, history, layout, messaging, isReadonly, persistFeedback, assistantName, assistantAvatarUrl, locale, homescreen, launcher, input, keyboardShortcuts, upload, ...domProps} = props;
275
275
  const config = useMemo(() => ({
276
276
  onError,
277
277
  openChatByDefault,
@@ -360,9 +360,21 @@ function ChatContainer(props) {
360
360
  setWriteableElementSlots(slots);
361
361
  };
362
362
  addWriteableElementSlots();
363
+ if (onViewPreChange) {
364
+ instance.on({
365
+ type: BusEventType.VIEW_PRE_CHANGE,
366
+ handler: onViewPreChange
367
+ });
368
+ }
369
+ if (onViewChange) {
370
+ instance.on({
371
+ type: BusEventType.VIEW_CHANGE,
372
+ handler: onViewChange
373
+ });
374
+ }
363
375
  onBeforeRender?.(instance);
364
376
  }
365
- }, [ onBeforeRender ]);
377
+ }, [ onBeforeRender, onViewChange, onViewPreChange ]);
366
378
  if (!isBrowser()) {
367
379
  return null;
368
380
  }
@@ -1 +1 @@
1
- {"version":3,"file":"aiChatEntry.js","sources":["../../../../src/globals/utils/readCarbonChatSession.ts","../../../../src/react/ChatContainer.tsx","../../../../src/react/ChatCustomElement.tsx"],"sourcesContent":["/*\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\nimport { VERSION } from \"../../chat/utils/environmentVariables\";\nimport { PersistedState } from \"../../types/state/AppState\";\nimport { IS_SESSION_STORAGE } from \"../../chat/utils/browserUtils\";\nimport { getSuffix } from \"../../chat/services/NamespaceService\";\n\n/**\n * Reads and validates the Carbon AI Chat session from sessionStorage.\n * Returns null if no session exists, if the data is corrupt, or if the\n * session was written by a different version of the library (version mismatch).\n *\n * Pass the same namespace value as {@link PublicConfig.namespace} (if any).\n *\n * @category Utilities\n *\n * @example\n * const session = readCarbonChatSession();\n * const wasOpen = session?.viewState.mainWindow === true;\n *\n * @example\n * // With a namespace matching PublicConfig.namespace\n * const session = readCarbonChatSession(\"myapp\");\n * const wasOpen = session?.viewState.mainWindow === true;\n */\nfunction readCarbonChatSession(namespace?: string): PersistedState | null {\n try {\n if (!IS_SESSION_STORAGE()) {\n return null;\n }\n const key = `CARBON_CHAT_SESSION${getSuffix(namespace)}`;\n const raw = window.sessionStorage.getItem(key);\n if (!raw) {\n return null;\n }\n const session = JSON.parse(raw) as PersistedState;\n if (session?.version !== VERSION) {\n return null;\n }\n return session;\n } catch {\n return null;\n }\n}\n\nexport { readCarbonChatSession };\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\nimport { createComponent } from \"@lit/react\";\nimport { css, LitElement, PropertyValues } from \"lit\";\nimport React, {\n type HTMLAttributes,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\n\nimport ChatAppEntry from \"../chat/ChatAppEntry\";\nimport { carbonElement } from \"@carbon/ai-chat-components/es-custom/globals/decorators/index.js\";\nimport { ChatContainerProps } from \"../types/component/ChatContainer\";\nimport { ChatInstance } from \"../types/instance/ChatInstance\";\nimport { PublicConfig } from \"../types/config/PublicConfig\";\nimport { isBrowser } from \"../chat/utils/browserUtils\";\n\n/**\n * This component creates a custom element protected by a shadow DOM to render the React application into. It creates\n * slotted elements for user_defined responses and for writable elements.\n *\n * The corresponding slots are defined within the React application and are rendered in place.\n */\n\n/**\n * Create a web component to host the React application. We do this so we can provide custom elements and user_defined responses as\n * slotted content so they maintain their own styling in a safe way.\n */\n@carbonElement(\"cds-custom-aichat-react\")\nclass ChatContainerReact extends LitElement {\n static styles = css`\n :host {\n width: 100%;\n height: 100%;\n }\n `;\n\n /**\n * Dispatch a custom event when the shadow DOM is ready\n * This ensures React can safely access shadowRoot\n */\n firstUpdated(changedProperties: PropertyValues) {\n super.firstUpdated(changedProperties);\n this.dispatchEvent(new CustomEvent(\"shadow-ready\", { bubbles: true }));\n }\n}\n\n// Wrap the custom element as a React component\nconst ReactChatContainer = React.memo(\n createComponent({\n tagName: \"cds-custom-aichat-react\",\n elementClass: ChatContainerReact,\n react: React,\n }),\n);\n\n/**\n * The ChatContainer controls rendering the React application into the shadow DOM of the cds-custom-aichat-react web component.\n * It also injects the writeable element and user_defined response slots into said web component.\n *\n * @category React\n */\nfunction ChatContainer(\n props: ChatContainerProps &\n Omit<HTMLAttributes<HTMLElement>, keyof ChatContainerProps>,\n) {\n const {\n onBeforeRender,\n onAfterRender,\n strings,\n serviceDeskFactory,\n serviceDesk,\n renderUserDefinedResponse,\n renderCustomMessageFooter,\n renderWriteableElements,\n element,\n // Flattened PublicConfig properties\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n ...domProps\n } = props;\n // Reconstruct PublicConfig from flattened props\n const config = useMemo(\n (): PublicConfig => ({\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n }),\n [\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n ],\n );\n\n const wrapperRef = useRef(null); // Ref for the React wrapper component\n const [wrapper, setWrapper] = useState(null);\n const [container, setContainer] = useState<HTMLElement | null>(null); // Actual element we render the React Portal to in the Shadowroot.\n\n const [writeableElementSlots, setWriteableElementSlots] = useState<\n HTMLElement[]\n >([]);\n const [currentInstance, setCurrentInstance] = useState<ChatInstance>(null);\n\n /**\n * Setup the DOM nodes of both the web component to be able to inject slotted content into it, and the element inside the\n * shadow DOM we will inject our React application into.\n */\n useEffect(() => {\n if (!wrapperRef.current) {\n return null; // Early return when there's nothing to set up because the element isn't ready.\n }\n\n let eventListenerAdded = false;\n\n const wrapperElement = wrapperRef.current as unknown as ChatContainerReact;\n\n // We need to check if the element in the shadow DOM we are render the React application to exists.\n // If it doesn't, we need to create and append it.\n\n const handleShadowReady = () => {\n // Now we know shadowRoot is definitely available\n let reactElement = wrapperElement.shadowRoot.querySelector(\n \".cds-custom-aichat--react-app\",\n ) as HTMLElement;\n\n if (!reactElement) {\n reactElement = document.createElement(\"div\");\n reactElement.classList.add(\"cds-custom-aichat--react-app\");\n wrapperElement.shadowRoot.appendChild(reactElement);\n }\n\n if (wrapperElement !== wrapper) {\n setWrapper(wrapperElement);\n }\n if (reactElement !== container) {\n setContainer(reactElement);\n }\n };\n\n if (wrapperElement.shadowRoot) {\n // Already ready\n handleShadowReady();\n } else {\n // Wait for ready event\n eventListenerAdded = true;\n wrapperElement.addEventListener(\"shadow-ready\", handleShadowReady, {\n once: true,\n });\n }\n\n return () => {\n if (eventListenerAdded) {\n wrapperElement.removeEventListener(\"shadow-ready\", handleShadowReady);\n }\n };\n }, [container, wrapper, currentInstance]);\n\n /**\n * Here we write the slotted elements into the wrapper so they are passed into the application to be rendered in their slot.\n */\n useEffect(() => {\n if (wrapper) {\n const combinedNodes: HTMLElement[] = [...writeableElementSlots];\n const currentNodes: HTMLElement[] = Array.from(\n wrapper.childNodes,\n ) as HTMLElement[];\n\n // Append new nodes that aren't already in the container\n combinedNodes.forEach((node) => {\n if (!currentNodes.includes(node)) {\n wrapper.appendChild(node);\n }\n });\n }\n }, [writeableElementSlots, wrapper]);\n\n const onBeforeRenderOverride = useCallback(\n (instance: ChatInstance) => {\n if (instance) {\n const addWriteableElementSlots = () => {\n const slots: HTMLElement[] = Object.entries(\n instance.writeableElements,\n ).map((writeableElement) => {\n const [key, element] = writeableElement;\n element.setAttribute(\"slot\", key); // Assign slot attributes dynamically\n return element;\n });\n setWriteableElementSlots(slots);\n };\n\n addWriteableElementSlots();\n onBeforeRender?.(instance);\n }\n },\n [onBeforeRender],\n );\n\n // If we are in SSR mode, just short circuit here. This prevents all of our window.* and document.* stuff from trying\n // to run and erroring out.\n if (!isBrowser()) {\n return null;\n }\n\n return (\n <>\n <ReactChatContainer ref={wrapperRef} {...domProps} />\n {container &&\n createPortal(\n <ChatAppEntry\n key=\"stable-chat-instance\"\n config={config}\n strings={strings}\n serviceDeskFactory={serviceDeskFactory}\n serviceDesk={serviceDesk}\n renderUserDefinedResponse={renderUserDefinedResponse}\n renderCustomMessageFooter={renderCustomMessageFooter}\n renderWriteableElements={renderWriteableElements}\n onBeforeRender={onBeforeRenderOverride}\n onAfterRender={onAfterRender}\n container={container}\n setParentInstance={setCurrentInstance}\n element={element}\n chatWrapper={wrapper}\n />,\n container,\n )}\n </>\n );\n}\n\nexport { ChatContainer, ChatContainerProps };\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\nimport React, {\n type HTMLAttributes,\n useCallback,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\n\nimport { ChatInstance } from \"../types/instance/ChatInstance\";\nimport {\n BusEventType,\n BusEventViewChange,\n BusEventViewPreChange,\n} from \"../types/events/eventBusTypes\";\nimport { ChatContainer, ChatContainerProps } from \"./ChatContainer\";\nimport { isBrowser } from \"../chat/utils/browserUtils\";\n\n/**\n * Properties for the ChatContainer React component. This interface extends\n * {@link ChatContainerProps} and {@link PublicConfig} with additional component-specific props, flattening all\n * config properties as top-level props for better TypeScript IntelliSense.\n *\n * @category React\n */\ninterface ChatCustomElementProps extends ChatContainerProps {\n /**\n * A CSS class name that will be added to the custom element. This class must define the size of the\n * your custom element (width and height or using logical inline-size/block-size).\n *\n * You can make use of onViewPreChange and/or onViewChange to mutate this className value so have open/close animations.\n *\n * By default, the chat will just set the chat shell to a 0x0 size and mark everything but the launcher (is you are using it)\n * as display: none; if the chat is set to closed.\n */\n className: string;\n\n /**\n * An optional id that will be added to the custom element.\n */\n id?: string;\n\n /**\n * Called before a view change (chat opening/closing). The chat will hide the chat shell inside your custom element\n * to prevent invisible keyboard stops when the view change is *complete*.\n *\n * Use this callback to update your className value *before* the view change happens if you want to add any open/close\n * animations to your custom element before the chat shell inner contents are hidden. It is async and so you can\n * tie it to native the AnimationEvent and only return when your animations have completed.\n *\n * A common pattern is to use this for when the chat is closing and to use onViewChange for when the chat opens.\n *\n * Note that this function can only be provided before Carbon AI Chat is loaded as it is registered before the\n * chat renders. After Carbon AI Chat is loaded, the callback will not be updated.\n */\n onViewPreChange?: (\n event: BusEventViewPreChange,\n instance: ChatInstance,\n ) => Promise<void> | void;\n\n /**\n * Called when the chat view change is complete. If no callback is provided here, the default behavior will be to set\n * the chat shell to 0x0 size and set all inner contents aside from the launcher, if you are using it, to display: none.\n * The inner contents of the chat shell (aside from the launcher if you are using it) are always set to display: none\n * regardless of what is configured with this callback to prevent invisible tab stops and screen reader issues.\n *\n * Use this callback to update your className value when the chat has finished being opened or closed.\n *\n * You can provide a different callback here if you want custom animation behavior when the chat is opened or closed.\n * The animation behavior defined here will run in concert with the chat inside your custom container being hidden.\n *\n * If you want to run animations before the inner contents of the chat shell is shrunk and the inner contents are hidden,\n * make use of onViewPreChange.\n *\n * A common pattern is to use this for when the chat is opening and to use onViewPreChange for when the chat closes.\n *\n * Note that this function can only be provided before Carbon AI Chat is loaded as it is registered before the\n * chat renders. After Carbon AI Chat is loaded, the callback will not be updated.\n */\n onViewChange?: (event: BusEventViewChange, instance: ChatInstance) => void;\n}\n\nconst customElementStylesheet =\n isBrowser() && typeof CSSStyleSheet !== \"undefined\"\n ? new CSSStyleSheet()\n : null;\n\nconst hideStyles = `\n .cds-custom-aichat--hidden {\n width: 0 !important;\n height: 0 !important;\n min-width: 0 !important;\n min-height: 0 !important;\n max-width: 0 !important;\n max-height: 0 !important;\n inline-size: 0 !important;\n block-size: 0 !important;\n min-inline-size: 0 !important;\n min-block-size: 0 !important;\n max-inline-size: 0 !important;\n max-block-size: 0 !important;\n overflow: hidden !important;\n }\n`;\n\n// Inject styles using adopted stylesheets when available, fallback to style element\nif (\n isBrowser() &&\n !document.getElementById(\"cds-custom-aichat-custom-element-styles\")\n) {\n if (customElementStylesheet && \"replaceSync\" in customElementStylesheet) {\n customElementStylesheet.replaceSync(hideStyles);\n document.adoptedStyleSheets = [\n ...document.adoptedStyleSheets,\n customElementStylesheet,\n ];\n } else {\n // Fallback for when adoptedStyleSheets are not supported\n const style = document.createElement(\"style\");\n style.id = \"cds-custom-aichat-custom-element-styles\";\n style.textContent = hideStyles;\n document.head.appendChild(style);\n }\n}\n\n/**\n * This is the React component for people injecting a Carbon AI Chat with a custom element.\n *\n * It provides said element any class or id defined on itself for styling. It then calls ChatContainer with the custom\n * element passed in as a property to be used instead of generating an element with the default properties for a\n * floating chat.\n *\n * @category React\n */\nfunction ChatCustomElement(\n props: ChatCustomElementProps &\n Omit<HTMLAttributes<HTMLDivElement>, keyof ChatCustomElementProps>,\n) {\n const {\n strings,\n serviceDeskFactory,\n serviceDesk,\n onBeforeRender,\n onAfterRender,\n renderUserDefinedResponse,\n renderCustomMessageFooter,\n renderWriteableElements,\n className,\n id,\n onViewChange,\n onViewPreChange,\n // Flattened PublicConfig properties\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n ...domProps\n } = props;\n\n const containerRef = useRef<HTMLDivElement>(null);\n const [elementReady, setElementReady] = useState(false);\n\n useLayoutEffect(() => {\n setElementReady(true);\n }, []);\n\n const onBeforeRenderOverride = useCallback(\n async (instance: ChatInstance) => {\n /**\n * A default handler for the \"view:change\" event. This will be used to show or hide the Carbon AI Chat main window\n * by adding/removing a CSS class that sets the element size to 0x0 when hidden.\n */\n function defaultViewChangeHandler(event: BusEventViewChange) {\n const el = containerRef.current;\n if (el) {\n if (event.newViewState.mainWindow) {\n // Show: remove the hidden class, let the provided className handle sizing\n el.classList.remove(\"cds-custom-aichat--hidden\");\n } else {\n // Hide: add the hidden class to set size to 0x0\n el.classList.add(\"cds-custom-aichat--hidden\");\n }\n }\n }\n\n if (onViewPreChange) {\n instance.on({\n type: BusEventType.VIEW_PRE_CHANGE,\n handler: onViewPreChange,\n });\n }\n\n instance.on({\n type: BusEventType.VIEW_CHANGE,\n handler: onViewChange || defaultViewChangeHandler,\n });\n\n return onBeforeRender?.(instance);\n },\n [onViewPreChange, onViewChange, onBeforeRender],\n );\n\n return (\n <div className={className} id={id} ref={containerRef} {...domProps}>\n {elementReady && containerRef.current && (\n <ChatContainer\n // Flattened PublicConfig properties\n onError={onError}\n openChatByDefault={openChatByDefault}\n disclaimer={disclaimer}\n disableCustomElementMobileEnhancements={\n disableCustomElementMobileEnhancements\n }\n debug={debug}\n exposeServiceManagerForTesting={exposeServiceManagerForTesting}\n injectCarbonTheme={injectCarbonTheme}\n aiEnabled={aiEnabled}\n shouldTakeFocusIfOpensAutomatically={\n shouldTakeFocusIfOpensAutomatically\n }\n namespace={namespace}\n shouldSanitizeHTML={shouldSanitizeHTML}\n header={header}\n history={history}\n layout={layout}\n messaging={messaging}\n isReadonly={isReadonly}\n persistFeedback={persistFeedback}\n assistantName={assistantName}\n assistantAvatarUrl={assistantAvatarUrl}\n locale={locale}\n homescreen={homescreen}\n launcher={launcher}\n input={input}\n keyboardShortcuts={keyboardShortcuts}\n upload={upload}\n // Other ChatContainer props\n strings={strings}\n serviceDeskFactory={serviceDeskFactory}\n serviceDesk={serviceDesk}\n onBeforeRender={onBeforeRenderOverride}\n onAfterRender={onAfterRender}\n renderUserDefinedResponse={renderUserDefinedResponse}\n renderCustomMessageFooter={renderCustomMessageFooter}\n renderWriteableElements={renderWriteableElements}\n element={containerRef.current}\n />\n )}\n </div>\n );\n}\n\nexport { ChatCustomElement, ChatCustomElementProps };\n"],"names":["readCarbonChatSession","namespace","IS_SESSION_STORAGE","key","getSuffix","raw","window","sessionStorage","getItem","session","JSON","parse","version","VERSION","ChatContainerReact","LitElement","firstUpdated","changedProperties","super","this","dispatchEvent","CustomEvent","bubbles","styles","css","__decorate","carbonElement","ReactChatContainer","React","memo","createComponent","tagName","elementClass","react","ChatContainer","props","onBeforeRender","onAfterRender","strings","serviceDeskFactory","serviceDesk","renderUserDefinedResponse","renderCustomMessageFooter","renderWriteableElements","element","onError","openChatByDefault","disclaimer","disableCustomElementMobileEnhancements","debug","exposeServiceManagerForTesting","injectCarbonTheme","aiEnabled","shouldTakeFocusIfOpensAutomatically","shouldSanitizeHTML","header","history","layout","messaging","isReadonly","persistFeedback","assistantName","assistantAvatarUrl","locale","homescreen","launcher","input","keyboardShortcuts","upload","domProps","config","useMemo","wrapperRef","useRef","wrapper","setWrapper","useState","container","setContainer","writeableElementSlots","setWriteableElementSlots","currentInstance","setCurrentInstance","useEffect","current","eventListenerAdded","wrapperElement","handleShadowReady","reactElement","shadowRoot","querySelector","document","createElement","classList","add","appendChild","addEventListener","once","removeEventListener","combinedNodes","currentNodes","Array","from","childNodes","forEach","node","includes","onBeforeRenderOverride","useCallback","instance","addWriteableElementSlots","slots","Object","entries","writeableElements","map","writeableElement","setAttribute","isBrowser","Fragment","ref","createPortal","ChatAppEntry","setParentInstance","chatWrapper","customElementStylesheet","CSSStyleSheet","hideStyles","getElementById","replaceSync","adoptedStyleSheets","style","id","textContent","head","ChatCustomElement","className","onViewChange","onViewPreChange","containerRef","elementReady","setElementReady","useLayoutEffect","async","defaultViewChangeHandler","event","el","newViewState","mainWindow","remove","on","type","BusEventType","VIEW_PRE_CHANGE","handler","VIEW_CHANGE"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAASA,sBAAsBC;EAC7B;IACE,KAAKC,sBAAsB;MACzB,OAAO;AACT;IACA,MAAMC,MAAM,sBAAsBC,UAAUH;IAC5C,MAAMI,MAAMC,OAAOC,eAAeC,QAAQL;IAC1C,KAAKE,KAAK;MACR,OAAO;AACT;IACA,MAAMI,UAAUC,KAAKC,MAAMN;IAC3B,IAAII,SAASG,YAAYC,SAAS;MAChC,OAAO;AACT;IACA,OAAOJ;AACT,IAAE;IACA,OAAO;AACT;AACF;;ACVA,IAAMK,qBAAN,MAAMA,2BAA2BC;EAY/B,YAAAC,CAAaC;IACXC,MAAMF,aAAaC;IACnBE,KAAKC,cAAc,IAAIC,YAAY,gBAAgB;MAAEC,SAAS;;AAChE;;;AAdOR,mBAAAS,SAASC,GAAG;;;;;;;AADfV,qBAAkBW,WAAA,EADvBC,cAAc,uBACTZ;;AAmBN,MAAMa,qBAAqBC,MAAMC,KAC/BC,gBAAgB;EACdC,SAAS;EACTC,cAAclB;EACdmB,OAAOL;;;AAUX,SAASM,cACPC;EAGA,OAAMC,gBACUC,eACDC,SACNC,oBACWC,aACPC,2BACcC,2BACAC,yBACFC,SAChBC,SAEAC,mBACUC,YACPC,wCAC4BC,OACjCC,gCACyBC,mBACbC,WACRC,qCAC0BpD,WAC1BqD,oBACSC,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MG,SACGC,oBACWC,aACPJ,gBACGC,eACDI,2BACYC,2BACAC,yBACF6F,WACdJ,IACPK,cACUC,iBACG7F,SAERC,mBACUC,YACPC,wCAC4BC,OACjCC,gCACyBC,mBACbC,WACRC,qCAC0BpD,WAC1BqD,oBACSC,QACZC,SACCC,QACDC,WACGC,YACCC,iBACKC,eACFC,oBACKC,QACZC,YACIC,UACFC,OACHC,mBACYC,WAEdC,YACDlC;EAEJ,MAAMwG,eAAelE,OAAuB;EAC5C,OAAOmE,cAAcC,mBAAmBjE,SAAS;EAEjDkE,gBAAgB;IACdD,gBAAgB;KACf;EAEH,MAAMlC,yBAAyBC,YAC7BmC,MAAOlC;IAKL,SAASmC,yBAAyBC;MAChC,MAAMC,KAAKP,aAAavD;MACxB,IAAI8D,IAAI;QACN,IAAID,MAAME,aAAaC,YAAY;UAEjCF,GAAGrD,UAAUwD,OAAO;AACtB,eAAO;UAELH,GAAGrD,UAAUC,IAAI;AACnB;AACF;AACF;IAEA,IAAI4C,iBAAiB;MACnB7B,SAASyC,GAAG;QACVC,MAAMC,aAAaC;QACnBC,SAAShB;;AAEb;IAEA7B,SAASyC,GAAG;MACVC,MAAMC,aAAaG;MACnBD,SAASjB,gBAAgBO;;IAG3B,OAAO5G,iBAAiByE;KAE1B,EAAC6B,iBAAiBD,cAAcrG;EAGlC,OACER,MAAAgE,cAAA,OAAA;IAAK4C;IAAsBJ;IAAQZ,KAAKmB;OAAkBtE;KACvDuE,gBAAgBD,aAAavD,WAC5BxD,MAAAgE,cAAC1D;IAECW;IACAC;IACAC;IACAC;IAGAC;IACAC;IACAC;IACAC;IACAC;IAGApD;IACAqD;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IAEA9B;IACAC;IACAC;IACAJ,gBAAgBuE;IAChBtE;IACAI;IACAC;IACAC;IACAC,SAAS+F,aAAavD;;AAKhC;;"}
1
+ {"version":3,"file":"aiChatEntry.js","sources":["../../../../src/globals/utils/readCarbonChatSession.ts","../../../../src/react/ChatContainer.tsx","../../../../src/react/ChatCustomElement.tsx"],"sourcesContent":["/*\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\nimport { VERSION } from \"../../chat/utils/environmentVariables\";\nimport { PersistedState } from \"../../types/state/AppState\";\nimport { IS_SESSION_STORAGE } from \"../../chat/utils/browserUtils\";\nimport { getSuffix } from \"../../chat/services/NamespaceService\";\n\n/**\n * Reads and validates the Carbon AI Chat session from sessionStorage.\n * Returns null if no session exists, if the data is corrupt, or if the\n * session was written by a different version of the library (version mismatch).\n *\n * Pass the same namespace value as {@link PublicConfig.namespace} (if any).\n *\n * @category Utilities\n *\n * @example\n * const session = readCarbonChatSession();\n * const wasOpen = session?.viewState.mainWindow === true;\n *\n * @example\n * // With a namespace matching PublicConfig.namespace\n * const session = readCarbonChatSession(\"myapp\");\n * const wasOpen = session?.viewState.mainWindow === true;\n */\nfunction readCarbonChatSession(namespace?: string): PersistedState | null {\n try {\n if (!IS_SESSION_STORAGE()) {\n return null;\n }\n const key = `CARBON_CHAT_SESSION${getSuffix(namespace)}`;\n const raw = window.sessionStorage.getItem(key);\n if (!raw) {\n return null;\n }\n const session = JSON.parse(raw) as PersistedState;\n if (session?.version !== VERSION) {\n return null;\n }\n return session;\n } catch {\n return null;\n }\n}\n\nexport { readCarbonChatSession };\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\nimport { createComponent } from \"@lit/react\";\nimport { css, LitElement, PropertyValues } from \"lit\";\nimport React, {\n type HTMLAttributes,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\n\nimport ChatAppEntry from \"../chat/ChatAppEntry\";\nimport { carbonElement } from \"@carbon/ai-chat-components/es-custom/globals/decorators/index.js\";\nimport { ChatContainerProps } from \"../types/component/ChatContainer\";\nimport { ChatInstance } from \"../types/instance/ChatInstance\";\nimport { BusEventType } from \"../types/events/eventBusTypes\";\nimport { PublicConfig } from \"../types/config/PublicConfig\";\nimport { isBrowser } from \"../chat/utils/browserUtils\";\n\n/**\n * This component creates a custom element protected by a shadow DOM to render the React application into. It creates\n * slotted elements for user_defined responses and for writable elements.\n *\n * The corresponding slots are defined within the React application and are rendered in place.\n */\n\n/**\n * Create a web component to host the React application. We do this so we can provide custom elements and user_defined responses as\n * slotted content so they maintain their own styling in a safe way.\n */\n@carbonElement(\"cds-custom-aichat-react\")\nclass ChatContainerReact extends LitElement {\n static styles = css`\n :host {\n width: 100%;\n height: 100%;\n }\n `;\n\n /**\n * Dispatch a custom event when the shadow DOM is ready\n * This ensures React can safely access shadowRoot\n */\n firstUpdated(changedProperties: PropertyValues) {\n super.firstUpdated(changedProperties);\n this.dispatchEvent(new CustomEvent(\"shadow-ready\", { bubbles: true }));\n }\n}\n\n// Wrap the custom element as a React component\nconst ReactChatContainer = React.memo(\n createComponent({\n tagName: \"cds-custom-aichat-react\",\n elementClass: ChatContainerReact,\n react: React,\n }),\n);\n\n/**\n * The ChatContainer controls rendering the React application into the shadow DOM of the cds-custom-aichat-react web component.\n * It also injects the writeable element and user_defined response slots into said web component.\n *\n * @category React\n */\nfunction ChatContainer(\n props: ChatContainerProps &\n Omit<HTMLAttributes<HTMLElement>, keyof ChatContainerProps>,\n) {\n const {\n onBeforeRender,\n onAfterRender,\n onViewChange,\n onViewPreChange,\n strings,\n serviceDeskFactory,\n serviceDesk,\n renderUserDefinedResponse,\n renderCustomMessageFooter,\n renderWriteableElements,\n element,\n // Flattened PublicConfig properties\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n ...domProps\n } = props;\n // Reconstruct PublicConfig from flattened props\n const config = useMemo(\n (): PublicConfig => ({\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n }),\n [\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n ],\n );\n\n const wrapperRef = useRef(null); // Ref for the React wrapper component\n const [wrapper, setWrapper] = useState(null);\n const [container, setContainer] = useState<HTMLElement | null>(null); // Actual element we render the React Portal to in the Shadowroot.\n\n const [writeableElementSlots, setWriteableElementSlots] = useState<\n HTMLElement[]\n >([]);\n const [currentInstance, setCurrentInstance] = useState<ChatInstance>(null);\n\n /**\n * Setup the DOM nodes of both the web component to be able to inject slotted content into it, and the element inside the\n * shadow DOM we will inject our React application into.\n */\n useEffect(() => {\n if (!wrapperRef.current) {\n return null; // Early return when there's nothing to set up because the element isn't ready.\n }\n\n let eventListenerAdded = false;\n\n const wrapperElement = wrapperRef.current as unknown as ChatContainerReact;\n\n // We need to check if the element in the shadow DOM we are render the React application to exists.\n // If it doesn't, we need to create and append it.\n\n const handleShadowReady = () => {\n // Now we know shadowRoot is definitely available\n let reactElement = wrapperElement.shadowRoot.querySelector(\n \".cds-custom-aichat--react-app\",\n ) as HTMLElement;\n\n if (!reactElement) {\n reactElement = document.createElement(\"div\");\n reactElement.classList.add(\"cds-custom-aichat--react-app\");\n wrapperElement.shadowRoot.appendChild(reactElement);\n }\n\n if (wrapperElement !== wrapper) {\n setWrapper(wrapperElement);\n }\n if (reactElement !== container) {\n setContainer(reactElement);\n }\n };\n\n if (wrapperElement.shadowRoot) {\n // Already ready\n handleShadowReady();\n } else {\n // Wait for ready event\n eventListenerAdded = true;\n wrapperElement.addEventListener(\"shadow-ready\", handleShadowReady, {\n once: true,\n });\n }\n\n return () => {\n if (eventListenerAdded) {\n wrapperElement.removeEventListener(\"shadow-ready\", handleShadowReady);\n }\n };\n }, [container, wrapper, currentInstance]);\n\n /**\n * Here we write the slotted elements into the wrapper so they are passed into the application to be rendered in their slot.\n */\n useEffect(() => {\n if (wrapper) {\n const combinedNodes: HTMLElement[] = [...writeableElementSlots];\n const currentNodes: HTMLElement[] = Array.from(\n wrapper.childNodes,\n ) as HTMLElement[];\n\n // Append new nodes that aren't already in the container\n combinedNodes.forEach((node) => {\n if (!currentNodes.includes(node)) {\n wrapper.appendChild(node);\n }\n });\n }\n }, [writeableElementSlots, wrapper]);\n\n const onBeforeRenderOverride = useCallback(\n (instance: ChatInstance) => {\n if (instance) {\n const addWriteableElementSlots = () => {\n const slots: HTMLElement[] = Object.entries(\n instance.writeableElements,\n ).map((writeableElement) => {\n const [key, element] = writeableElement;\n element.setAttribute(\"slot\", key); // Assign slot attributes dynamically\n return element;\n });\n setWriteableElementSlots(slots);\n };\n\n addWriteableElementSlots();\n\n // Opt-in view-change observation hooks. The float container manages\n // its own visibility, so there is no default handler — a prop is only\n // subscribed when the consumer provides it.\n if (onViewPreChange) {\n instance.on({\n type: BusEventType.VIEW_PRE_CHANGE,\n handler: onViewPreChange,\n });\n }\n if (onViewChange) {\n instance.on({\n type: BusEventType.VIEW_CHANGE,\n handler: onViewChange,\n });\n }\n\n onBeforeRender?.(instance);\n }\n },\n [onBeforeRender, onViewChange, onViewPreChange],\n );\n\n // If we are in SSR mode, just short circuit here. This prevents all of our window.* and document.* stuff from trying\n // to run and erroring out.\n if (!isBrowser()) {\n return null;\n }\n\n return (\n <>\n <ReactChatContainer ref={wrapperRef} {...domProps} />\n {container &&\n createPortal(\n <ChatAppEntry\n key=\"stable-chat-instance\"\n config={config}\n strings={strings}\n serviceDeskFactory={serviceDeskFactory}\n serviceDesk={serviceDesk}\n renderUserDefinedResponse={renderUserDefinedResponse}\n renderCustomMessageFooter={renderCustomMessageFooter}\n renderWriteableElements={renderWriteableElements}\n onBeforeRender={onBeforeRenderOverride}\n onAfterRender={onAfterRender}\n container={container}\n setParentInstance={setCurrentInstance}\n element={element}\n chatWrapper={wrapper}\n />,\n container,\n )}\n </>\n );\n}\n\nexport { ChatContainer, ChatContainerProps };\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\nimport React, {\n type HTMLAttributes,\n useCallback,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\n\nimport { ChatInstance } from \"../types/instance/ChatInstance\";\nimport {\n BusEventType,\n BusEventViewChange,\n BusEventViewPreChange,\n} from \"../types/events/eventBusTypes\";\nimport { ChatContainer, ChatContainerProps } from \"./ChatContainer\";\nimport { isBrowser } from \"../chat/utils/browserUtils\";\n\n/**\n * Properties for the ChatContainer React component. This interface extends\n * {@link ChatContainerProps} and {@link PublicConfig} with additional component-specific props, flattening all\n * config properties as top-level props for better TypeScript IntelliSense.\n *\n * @category React\n */\ninterface ChatCustomElementProps extends ChatContainerProps {\n /**\n * A CSS class name that will be added to the custom element. This class must define the size of the\n * your custom element (width and height or using logical inline-size/block-size).\n *\n * You can make use of onViewPreChange and/or onViewChange to mutate this className value so have open/close animations.\n *\n * By default, the chat will just set the chat shell to a 0x0 size and mark everything but the launcher (is you are using it)\n * as display: none; if the chat is set to closed.\n */\n className: string;\n\n /**\n * An optional id that will be added to the custom element.\n */\n id?: string;\n\n /**\n * Called before a view change (chat opening/closing). The chat will hide the chat shell inside your custom element\n * to prevent invisible keyboard stops when the view change is *complete*.\n *\n * Use this callback to update your className value *before* the view change happens if you want to add any open/close\n * animations to your custom element before the chat shell inner contents are hidden. It is async and so you can\n * tie it to native the AnimationEvent and only return when your animations have completed.\n *\n * A common pattern is to use this for when the chat is closing and to use onViewChange for when the chat opens.\n *\n * Note that this function can only be provided before Carbon AI Chat is loaded as it is registered before the\n * chat renders. After Carbon AI Chat is loaded, the callback will not be updated.\n */\n onViewPreChange?: (\n event: BusEventViewPreChange,\n instance: ChatInstance,\n ) => Promise<void> | void;\n\n /**\n * Called when the chat view change is complete. If no callback is provided here, the default behavior will be to set\n * the chat shell to 0x0 size and set all inner contents aside from the launcher, if you are using it, to display: none.\n * The inner contents of the chat shell (aside from the launcher if you are using it) are always set to display: none\n * regardless of what is configured with this callback to prevent invisible tab stops and screen reader issues.\n *\n * Use this callback to update your className value when the chat has finished being opened or closed.\n *\n * You can provide a different callback here if you want custom animation behavior when the chat is opened or closed.\n * The animation behavior defined here will run in concert with the chat inside your custom container being hidden.\n *\n * If you want to run animations before the inner contents of the chat shell is shrunk and the inner contents are hidden,\n * make use of onViewPreChange.\n *\n * A common pattern is to use this for when the chat is opening and to use onViewPreChange for when the chat closes.\n *\n * Note that this function can only be provided before Carbon AI Chat is loaded as it is registered before the\n * chat renders. After Carbon AI Chat is loaded, the callback will not be updated.\n */\n onViewChange?: (event: BusEventViewChange, instance: ChatInstance) => void;\n}\n\nconst customElementStylesheet =\n isBrowser() && typeof CSSStyleSheet !== \"undefined\"\n ? new CSSStyleSheet()\n : null;\n\nconst hideStyles = `\n .cds-custom-aichat--hidden {\n width: 0 !important;\n height: 0 !important;\n min-width: 0 !important;\n min-height: 0 !important;\n max-width: 0 !important;\n max-height: 0 !important;\n inline-size: 0 !important;\n block-size: 0 !important;\n min-inline-size: 0 !important;\n min-block-size: 0 !important;\n max-inline-size: 0 !important;\n max-block-size: 0 !important;\n overflow: hidden !important;\n }\n`;\n\n// Inject styles using adopted stylesheets when available, fallback to style element\nif (\n isBrowser() &&\n !document.getElementById(\"cds-custom-aichat-custom-element-styles\")\n) {\n if (customElementStylesheet && \"replaceSync\" in customElementStylesheet) {\n customElementStylesheet.replaceSync(hideStyles);\n document.adoptedStyleSheets = [\n ...document.adoptedStyleSheets,\n customElementStylesheet,\n ];\n } else {\n // Fallback for when adoptedStyleSheets are not supported\n const style = document.createElement(\"style\");\n style.id = \"cds-custom-aichat-custom-element-styles\";\n style.textContent = hideStyles;\n document.head.appendChild(style);\n }\n}\n\n/**\n * This is the React component for people injecting a Carbon AI Chat with a custom element.\n *\n * It provides said element any class or id defined on itself for styling. It then calls ChatContainer with the custom\n * element passed in as a property to be used instead of generating an element with the default properties for a\n * floating chat.\n *\n * @category React\n */\nfunction ChatCustomElement(\n props: ChatCustomElementProps &\n Omit<HTMLAttributes<HTMLDivElement>, keyof ChatCustomElementProps>,\n) {\n const {\n strings,\n serviceDeskFactory,\n serviceDesk,\n onBeforeRender,\n onAfterRender,\n renderUserDefinedResponse,\n renderCustomMessageFooter,\n renderWriteableElements,\n className,\n id,\n onViewChange,\n onViewPreChange,\n // Flattened PublicConfig properties\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n ...domProps\n } = props;\n\n const containerRef = useRef<HTMLDivElement>(null);\n const [elementReady, setElementReady] = useState(false);\n\n useLayoutEffect(() => {\n setElementReady(true);\n }, []);\n\n const onBeforeRenderOverride = useCallback(\n async (instance: ChatInstance) => {\n /**\n * A default handler for the \"view:change\" event. This will be used to show or hide the Carbon AI Chat main window\n * by adding/removing a CSS class that sets the element size to 0x0 when hidden.\n */\n function defaultViewChangeHandler(event: BusEventViewChange) {\n const el = containerRef.current;\n if (el) {\n if (event.newViewState.mainWindow) {\n // Show: remove the hidden class, let the provided className handle sizing\n el.classList.remove(\"cds-custom-aichat--hidden\");\n } else {\n // Hide: add the hidden class to set size to 0x0\n el.classList.add(\"cds-custom-aichat--hidden\");\n }\n }\n }\n\n if (onViewPreChange) {\n instance.on({\n type: BusEventType.VIEW_PRE_CHANGE,\n handler: onViewPreChange,\n });\n }\n\n instance.on({\n type: BusEventType.VIEW_CHANGE,\n handler: onViewChange || defaultViewChangeHandler,\n });\n\n return onBeforeRender?.(instance);\n },\n [onViewPreChange, onViewChange, onBeforeRender],\n );\n\n return (\n <div className={className} id={id} ref={containerRef} {...domProps}>\n {elementReady && containerRef.current && (\n <ChatContainer\n // Flattened PublicConfig properties\n onError={onError}\n openChatByDefault={openChatByDefault}\n disclaimer={disclaimer}\n disableCustomElementMobileEnhancements={\n disableCustomElementMobileEnhancements\n }\n debug={debug}\n exposeServiceManagerForTesting={exposeServiceManagerForTesting}\n injectCarbonTheme={injectCarbonTheme}\n aiEnabled={aiEnabled}\n shouldTakeFocusIfOpensAutomatically={\n shouldTakeFocusIfOpensAutomatically\n }\n namespace={namespace}\n shouldSanitizeHTML={shouldSanitizeHTML}\n header={header}\n history={history}\n layout={layout}\n messaging={messaging}\n isReadonly={isReadonly}\n persistFeedback={persistFeedback}\n assistantName={assistantName}\n assistantAvatarUrl={assistantAvatarUrl}\n locale={locale}\n homescreen={homescreen}\n launcher={launcher}\n input={input}\n keyboardShortcuts={keyboardShortcuts}\n upload={upload}\n // Other ChatContainer props\n strings={strings}\n serviceDeskFactory={serviceDeskFactory}\n serviceDesk={serviceDesk}\n onBeforeRender={onBeforeRenderOverride}\n onAfterRender={onAfterRender}\n renderUserDefinedResponse={renderUserDefinedResponse}\n renderCustomMessageFooter={renderCustomMessageFooter}\n renderWriteableElements={renderWriteableElements}\n element={containerRef.current}\n />\n )}\n </div>\n );\n}\n\nexport { ChatCustomElement, ChatCustomElementProps };\n"],"names":["readCarbonChatSession","namespace","IS_SESSION_STORAGE","key","getSuffix","raw","window","sessionStorage","getItem","session","JSON","parse","version","VERSION","ChatContainerReact","LitElement","firstUpdated","changedProperties","super","this","dispatchEvent","CustomEvent","bubbles","styles","css","__decorate","carbonElement","ReactChatContainer","React","memo","createComponent","tagName","elementClass","react","ChatContainer","props","onBeforeRender","onAfterRender","onViewChange","onViewPreChange","strings","serviceDeskFactory","serviceDesk","renderUserDefinedResponse","renderCustomMessageFooter","renderWriteableElements","element","onError","openChatByDefault","disclaimer","disableCustomElementMobileEnhancements","debug","exposeServiceManagerForTesting","injectCarbonTheme","aiEnabled","shouldTakeFocusIfOpensAutomatically","shouldSanitizeHTML","header","history","layout","messaging","isReadonly","persistFeedback","assistantName","assistantAvatarUrl","locale","homescreen","launcher","input","keyboardShortcuts","upload","domProps","config","useMemo","wrapperRef","useRef","wrapper","setWrapper","useState","container","setContainer","writeableElementSlots","setWriteableElementSlots","currentInstance","setCurrentInstance","useEffect","current","eventListenerAdded","wrapperElement","handleShadowReady","reactElement","shadowRoot","querySelector","document","createElement","classList","add","appendChild","addEventListener","once","removeEventListener","combinedNodes","currentNodes","Array","from","childNodes","forEach","node","includes","onBeforeRenderOverride","useCallback","instance","addWriteableElementSlots","slots","Object","entries","writeableElements","map","writeableElement","setAttribute","on","type","BusEventType","VIEW_PRE_CHANGE","handler","VIEW_CHANGE","isBrowser","Fragment","ref","createPortal","ChatAppEntry","setParentInstance","chatWrapper","customElementStylesheet","CSSStyleSheet","hideStyles","getElementById","replaceSync","adoptedStyleSheets","style","id","textContent","head","ChatCustomElement","className","containerRef","elementReady","setElementReady","useLayoutEffect","async","defaultViewChangeHandler","event","el","newViewState","mainWindow","remove"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;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