@bangdb/web-sdk 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1619 @@
1
+ "use strict";var de=Object.create;var j=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var me=(o,e)=>{for(var t in e)j(o,t,{get:e[t],enumerable:!0})},I=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of pe(e))!ge.call(o,a)&&a!==t&&j(o,a,{get:()=>e[a],enumerable:!(r=ce(e,a))||r.enumerable});return o};var q=(o,e,t)=>(t=o!=null?de(he(o)):{},I(e||!o||!o.__esModule?j(t,"default",{value:o,enumerable:!0}):t,o)),be=o=>I(j({},"__esModule",{value:!0}),o);var Me={};me(Me,{ChatWidget:()=>C,init:()=>ne});module.exports=be(Me);var R=`
2
+ :root {
3
+ --thread-content-max-width: 32rem;
4
+ }
5
+
6
+ .scrollable {
7
+ scrollbar-gutter: stable;
8
+ scrollbar-color: rgba(0,0,0,0) transparent;
9
+ transition: scrollbar-color .1s ease-out;
10
+ scroll-behavior: smooth;
11
+ }
12
+
13
+ .dark .scrollable {
14
+ scrollbar-color: rgba(255,255,255,.50) transparent;
15
+ }
16
+
17
+ .scrollable:hover {
18
+ scrollbar-color: rgba(0, 0, 0, 0.15) rgba(0, 0, 0, 0);
19
+ }
20
+
21
+ .dark .scrollable:hover {
22
+ scrollbar-color: rgba(255,255,255,.8) transparent;
23
+ }
24
+
25
+ .dark .scrollable {
26
+ &::-webkit-scrollbar-thumb:hover {
27
+ background: color-mix(in oklab, var(--primary) 50%, transparent) !important;
28
+ }
29
+
30
+ &::-webkit-scrollbar-track {
31
+ -webkit-box-shadow: inset 0 0 6px rgba(83, 83, 83, 0.07);
32
+ background-color: var(--secondary);
33
+ }
34
+
35
+ &::-webkit-scrollbar {
36
+ height: 11px;
37
+ }
38
+
39
+ &::-webkit-scrollbar-thumb {
40
+ background-color: color-mix(in oklab, var(--primary) 80%, transparent);
41
+ }
42
+ }
43
+
44
+
45
+ .ai-md {
46
+ max-width: unset;
47
+ }
48
+
49
+ .ai-md pre {
50
+ background: var(--card);
51
+ border-radius: var(--radius-md);
52
+ border: 1px solid var(--border);
53
+ margin-top: calc(var(--spacing) * 2);
54
+ font-family: "JetBrains Mono", monospace;
55
+ font-size: 0.875rem;
56
+ padding: calc(var(--spacing) * 4);
57
+ }
58
+
59
+ .ai-md code {
60
+ font-family: "JetBrains Mono", monospace;
61
+ font-size: 0.875rem;
62
+ background: none;
63
+ }
64
+
65
+ .ai-md pre:first-child {
66
+ margin-top: calc(var(--spacing) * 0)
67
+ }
68
+
69
+ .ai-md h1 {
70
+ --tw-font-weight: var(--font-weight-semibold);
71
+ --tw-tracking: -.04rem;
72
+ font-weight: var(--font-weight-semibold);
73
+ letter-spacing: -.04rem
74
+ }
75
+
76
+ .ai-md h1:first-child {
77
+ margin-top: calc(var(--spacing) * 0)
78
+ }
79
+
80
+ .ai-md h2 {
81
+ --tw-font-weight: var(--font-weight-semibold);
82
+ font-weight: var(--font-weight-semibold);
83
+ margin-bottom: calc(var(--spacing) * 3);
84
+ margin-top: calc(var(--spacing) * 8)
85
+ }
86
+
87
+ .ai-md h2:first-child {
88
+ margin-top: calc(var(--spacing) * 0)
89
+ }
90
+
91
+ .ai-md h3 {
92
+ --tw-font-weight: var(--font-weight-semibold);
93
+ font-weight: var(--font-weight-semibold);
94
+ margin-bottom: calc(var(--spacing) * 2);
95
+ margin-top: calc(var(--spacing) * 6);
96
+ font-size: 1.25em;
97
+ line-height: 1.6;
98
+ }
99
+
100
+ .ai-md h3:first-child {
101
+ margin-top: calc(var(--spacing) * 0);
102
+ }
103
+
104
+ .ai-md h4 {
105
+ --tw-font-weight: var(--font-weight-semibold);
106
+ font-weight: var(--font-weight-semibold);
107
+ margin-bottom: calc(var(--spacing) * 2);
108
+ margin-top: calc(var(--spacing) * 4);
109
+ line-height: 1.5;
110
+ font-size: inherit;
111
+ }
112
+
113
+ .ai-md h4:first-child {
114
+ margin-top: calc(var(--spacing) * 0)
115
+ }
116
+
117
+ .ai-md h5 {
118
+ --tw-font-weight: var(--font-weight-semibold);
119
+ font-weight: var(--font-weight-semibold)
120
+ }
121
+
122
+ .ai-md h5:first-child {
123
+ margin-top: calc(var(--spacing) * 0)
124
+ }
125
+
126
+ .ai-md blockquote {
127
+ --tw-leading: calc(var(--spacing) * 6);
128
+ border-style: solid;
129
+ border-width: 0;
130
+ line-height: calc(var(--spacing) * 6);
131
+ margin: calc(var(--spacing) * 0);
132
+ padding-block: calc(var(--spacing) * 2);
133
+ position: relative
134
+ }
135
+
136
+ [dir=ltr] .ai-md blockquote {
137
+ padding-left: calc(var(--spacing) * 6)
138
+ }
139
+
140
+ [dir=rtl] .ai-md blockquote {
141
+ padding-right: calc(var(--spacing) * 6)
142
+ }
143
+
144
+ .ai-md blockquote > p {
145
+ --tw-font-weight: var(--font-weight-normal);
146
+ font-weight: var(--font-weight-normal);
147
+ margin: calc(var(--spacing) * 0)
148
+ }
149
+
150
+ .ai-md blockquote > p:after, .ai-md blockquote > p:before {
151
+ display: none
152
+ }
153
+
154
+ .ai-md blockquote:after {
155
+ background-color: var(--color-gray-alpha-400);
156
+ border-radius: 2px;
157
+ bottom: .5rem;
158
+ content: "";
159
+ position: absolute;
160
+ top: .5rem;
161
+ width: 4px
162
+ }
163
+
164
+ [dir=ltr] .ai-md blockquote:after {
165
+ left: 0
166
+ }
167
+
168
+ [dir=rtl] .ai-md blockquote:after {
169
+ right: 0
170
+ }
171
+
172
+ .ai-md ol, .ai-md ul {
173
+ margin-bottom: calc(var(--spacing) * 4);
174
+ padding-left: 20px;
175
+ }
176
+
177
+ .ai-md ul li {
178
+ margin-bottom: .5rem;
179
+ font-size: 0.875rem;
180
+ }
181
+
182
+ .ai-md ol li {
183
+ margin-bottom: .5rem;
184
+ font-size: 0.875rem;
185
+ }
186
+
187
+ .ai-md p {
188
+ margin-bottom: .5rem;
189
+ font-size: 0.875rem;
190
+ }
191
+
192
+ .ai-md p:not(:first-child) {
193
+ margin-top: .5rem
194
+ }
195
+
196
+ .ai-md p + :where(ol,ul) {
197
+ margin-top: 0
198
+ }
199
+
200
+ .ai-md :where(ol,ul) > li > :last-child {
201
+ margin-bottom: 0
202
+ }
203
+
204
+ .ai-md :where(ol,ul) > li > :first-child {
205
+ margin-bottom: 0;
206
+ margin-top: 0
207
+ }
208
+
209
+ .ai-md table {
210
+ --tw-border-spacing-x: calc(var(--spacing) * 0);
211
+ --tw-border-spacing-y: calc(var(--spacing) * 0);
212
+ border-collapse: separate;
213
+ border-spacing: var(--tw-border-spacing-x) var(--tw-border-spacing-y);
214
+ margin: calc(var(--spacing) * 0)
215
+ }
216
+
217
+ .ai-md table [data-col-size=sm] {
218
+ max-width: calc(var(--thread-content-max-width) * 6 / 24);
219
+ min-width: calc(var(--thread-content-max-width) * 4 / 24)
220
+ }
221
+
222
+ .ai-md table [data-col-size=md] {
223
+ max-width: calc(var(--thread-content-max-width) * 8 / 24);
224
+ min-width: calc(var(--thread-content-max-width) * 6 / 24)
225
+ }
226
+
227
+ .ai-md table [data-col-size=lg] {
228
+ max-width: calc(var(--thread-content-max-width) * 12 / 24);
229
+ min-width: calc(var(--thread-content-max-width) * 8 / 24)
230
+ }
231
+
232
+ .ai-md table [data-col-size=xl] {
233
+ max-width: calc(var(--thread-content-max-width) * 18 / 24);
234
+ min-width: calc(var(--thread-content-max-width) * 14 / 24)
235
+ }
236
+
237
+ .ai-md th {
238
+ --tw-leading: calc(var(--spacing) * 4);
239
+ border-bottom-style: solid;
240
+ border-bottom-width: 1px;
241
+ border-color: var(--border);
242
+ line-height: calc(var(--spacing) * 4);
243
+ padding-block: calc(var(--spacing) * 2)
244
+ }
245
+
246
+ .ai-md th:not(:last-child) {
247
+ padding-inline-end: calc(var(--spacing) * 6)
248
+ }
249
+
250
+ .ai-md tr:not(:last-child) td {
251
+ border-bottom-style: solid;
252
+ border-bottom-width: 1px;
253
+ border-color: var(--border)
254
+ }
255
+
256
+ .ai-md tr:last-child td {
257
+ padding-bottom: calc(var(--spacing) * 6)
258
+ }
259
+
260
+ .ai-md td {
261
+ padding-block: calc(var(--spacing) * 2.5)
262
+ }
263
+
264
+ .ai-md td:not(:last-child) {
265
+ padding-inline-end: calc(var(--spacing) * 6)
266
+ }
267
+
268
+ .ai-md ol, .ai-md ul {
269
+ margin-bottom: calc(var(--spacing) * 4)
270
+ }
271
+
272
+ .ai-md li::marker {
273
+ --tw-font-weight: var(--font-weight-bold);
274
+ color: var(--secondary);
275
+ font-weight: var(--font-weight-bold)
276
+ }
277
+
278
+ .ai-md a {
279
+ --tw-font-weight: var(--font-weight-normal);
280
+ color: var(--color-blue-500);
281
+ font-weight: var(--font-weight-normal);
282
+ text-decoration-line: none
283
+ }
284
+
285
+ @media (hover: hover) {
286
+ .ai-md a:hover {
287
+ color: var(--color-blue-600)
288
+ }
289
+
290
+ .gizmo .ai-md > :not(pre), .gizmo .ai-md > :not(pre) > :not(a) {
291
+ color: var(--primary)
292
+ }
293
+
294
+ .ai-md .float-image + p {
295
+ margin-top: calc(var(--spacing) * 0)
296
+ }
297
+
298
+ .ai-md hr {
299
+ border-color: var(--border);
300
+ margin-block: calc(var(--spacing) * 10)
301
+ }
302
+
303
+ @keyframes blink {
304
+ to {
305
+ visibility: hidden
306
+ }
307
+ }
308
+ }
309
+
310
+ .ai-chat-code-title {
311
+ display: flex;
312
+ border-bottom: 1px solid var(--border);
313
+ padding-bottom: 16px;
314
+ margin-bottom: 8px;
315
+ align-items: center;
316
+ justify-content: space-between;
317
+ font-family: "Inter", "JetBrains Mono", monospace;
318
+ width: 100%;
319
+ }
320
+
321
+ .ai-chat-code-title a {
322
+ text-decoration: none !important;
323
+ }
324
+
325
+ .response-loader {
326
+ width: 100%;
327
+ display: flex;
328
+ flex-direction: column;
329
+ gap: 10px
330
+ }
331
+
332
+ .animated-bg {
333
+ border-radius: 2px;
334
+ border: none;
335
+ animation: response-loader 2s infinite linear;
336
+ background-color: #f6f7f8;
337
+ background: linear-gradient(to right,var(--color-gray-alpha-200),#f6f6f6,var(--color-gray-alpha-300));
338
+ background-size: 800px 50px;
339
+ height: 20px;
340
+ margin: 0 !important;
341
+ }
342
+
343
+ @keyframes response-loader {
344
+ 0% {
345
+ background-position: -800px 0
346
+ }
347
+
348
+ 50% {
349
+ background-position: 400px 0
350
+ }
351
+
352
+ 100% {
353
+ background-position: 800px 0
354
+ }
355
+
356
+ }
357
+
358
+
359
+ pre code.hljs {
360
+ display: block;
361
+ overflow-x: auto;
362
+ padding: 1em
363
+ }
364
+ code.hljs {
365
+ padding: 3px 5px
366
+ }
367
+ /*!
368
+ Theme: StackOverflow Light
369
+ Description: Light theme as used on stackoverflow.com
370
+ Author: stackoverflow.com
371
+ Maintainer: @Hirse
372
+ Website: https://github.com/StackExchange/Stacks
373
+ License: MIT
374
+ Updated: 2021-05-15
375
+
376
+ Updated for @stackoverflow/stacks v0.64.0
377
+ Code Blocks: /blob/v0.64.0/lib/css/components/_stacks-code-blocks.less
378
+ Colors: /blob/v0.64.0/lib/css/exports/_stacks-constants-colors.less
379
+ */
380
+ .hljs {
381
+ /* var(--highlight-color) */
382
+ color: #2f3337;
383
+ /* var(--highlight-bg) */
384
+ /*background: #f6f6f6*/
385
+ }
386
+ .hljs-subst {
387
+ /* var(--highlight-color) */
388
+ color: #2f3337
389
+ }
390
+ .hljs-comment {
391
+ /* var(--highlight-comment) */
392
+ color: #656e77
393
+ }
394
+ .hljs-keyword,
395
+ .hljs-selector-tag,
396
+ .hljs-meta .hljs-keyword,
397
+ .hljs-doctag,
398
+ .hljs-section {
399
+ /* var(--highlight-keyword) */
400
+ color: #015692
401
+ }
402
+ .hljs-attr {
403
+ /* var(--highlight-attribute); */
404
+ color: #015692
405
+ }
406
+ .hljs-attribute {
407
+ /* var(--highlight-symbol) */
408
+ color: #803378
409
+ }
410
+ .hljs-name,
411
+ .hljs-type,
412
+ .hljs-number,
413
+ .hljs-selector-id,
414
+ .hljs-quote,
415
+ .hljs-template-tag {
416
+ /* var(--highlight-namespace) */
417
+ color: #b75501
418
+ }
419
+ .hljs-selector-class {
420
+ /* var(--highlight-keyword) */
421
+ color: #015692
422
+ }
423
+ .hljs-string,
424
+ .hljs-regexp,
425
+ .hljs-symbol,
426
+ .hljs-variable,
427
+ .hljs-template-variable,
428
+ .hljs-link,
429
+ .hljs-selector-attr {
430
+ /* var(--highlight-variable) */
431
+ color: #54790d
432
+ }
433
+ .hljs-meta,
434
+ .hljs-selector-pseudo {
435
+ /* var(--highlight-keyword) */
436
+ color: #015692
437
+ }
438
+ .hljs-built_in,
439
+ .hljs-title,
440
+ .hljs-literal {
441
+ /* var(--highlight-literal) */
442
+ color: #b75501
443
+ }
444
+ .hljs-bullet,
445
+ .hljs-code {
446
+ /* var(--highlight-punctuation) */
447
+ color: #535a60
448
+ }
449
+ .hljs-meta .hljs-string {
450
+ /* var(--highlight-variable) */
451
+ color: #54790d
452
+ }
453
+ .hljs-deletion {
454
+ /* var(--highlight-deletion) */
455
+ color: #c02d2e
456
+ }
457
+ .hljs-addition {
458
+ /* var(--highlight-addition) */
459
+ color: #2f6f44
460
+ }
461
+ .hljs-emphasis {
462
+ font-style: italic
463
+ }
464
+ .hljs-strong {
465
+ font-weight: bold
466
+ }
467
+ .hljs-formula,
468
+ .hljs-operator,
469
+ .hljs-params,
470
+ .hljs-property,
471
+ .hljs-punctuation,
472
+ .hljs-tag {
473
+ /* purposely ignored */
474
+
475
+ }
476
+
477
+ .dark {
478
+ pre code.hljs {
479
+ display: block;
480
+ overflow-x: auto;
481
+ padding: 1em
482
+ }
483
+ code.hljs {
484
+ padding: 3px 5px
485
+ }
486
+ /*!
487
+ Theme: StackOverflow Dark
488
+ Description: Dark theme as used on stackoverflow.com
489
+ Author: stackoverflow.com
490
+ Maintainer: @Hirse
491
+ Website: https://github.com/StackExchange/Stacks
492
+ License: MIT
493
+ Updated: 2021-05-15
494
+
495
+ Updated for @stackoverflow/stacks v0.64.0
496
+ Code Blocks: /blob/v0.64.0/lib/css/components/_stacks-code-blocks.less
497
+ Colors: /blob/v0.64.0/lib/css/exports/_stacks-constants-colors.less
498
+ */
499
+ .hljs {
500
+ /* var(--highlight-color) */
501
+ color: #ffffff;
502
+ /* var(--highlight-bg) */
503
+ /*background: #1c1b1b*/
504
+ }
505
+ .hljs-subst {
506
+ /* var(--highlight-color) */
507
+ color: #ffffff
508
+ }
509
+ .hljs-comment {
510
+ /* var(--highlight-comment) */
511
+ color: #999999
512
+ }
513
+ .hljs-keyword,
514
+ .hljs-selector-tag,
515
+ .hljs-meta .hljs-keyword,
516
+ .hljs-doctag,
517
+ .hljs-section {
518
+ /* var(--highlight-keyword) */
519
+ color: #88aece
520
+ }
521
+ .hljs-attr {
522
+ /* var(--highlight-attribute); */
523
+ color: #88aece
524
+ }
525
+ .hljs-attribute {
526
+ /* var(--highlight-symbol) */
527
+ color: #c59bc1
528
+ }
529
+ .hljs-name,
530
+ .hljs-type,
531
+ .hljs-number,
532
+ .hljs-selector-id,
533
+ .hljs-quote,
534
+ .hljs-template-tag {
535
+ /* var(--highlight-namespace) */
536
+ color: #f08d49
537
+ }
538
+ .hljs-selector-class {
539
+ /* var(--highlight-keyword) */
540
+ color: #88aece
541
+ }
542
+ .hljs-string,
543
+ .hljs-regexp,
544
+ .hljs-symbol,
545
+ .hljs-variable,
546
+ .hljs-template-variable,
547
+ .hljs-link,
548
+ .hljs-selector-attr {
549
+ /* var(--highlight-variable) */
550
+ color: #b5bd68
551
+ }
552
+ .hljs-meta,
553
+ .hljs-selector-pseudo {
554
+ /* var(--highlight-keyword) */
555
+ color: #88aece
556
+ }
557
+ .hljs-built_in,
558
+ .hljs-title,
559
+ .hljs-literal {
560
+ /* var(--highlight-literal) */
561
+ color: #f08d49
562
+ }
563
+ .hljs-bullet,
564
+ .hljs-code {
565
+ /* var(--highlight-punctuation) */
566
+ color: #cccccc
567
+ }
568
+ .hljs-meta .hljs-string {
569
+ /* var(--highlight-variable) */
570
+ color: #b5bd68
571
+ }
572
+ .hljs-deletion {
573
+ /* var(--highlight-deletion) */
574
+ color: #de7176
575
+ }
576
+ .hljs-addition {
577
+ /* var(--highlight-addition) */
578
+ color: #76c490
579
+ }
580
+ .hljs-emphasis {
581
+ font-style: italic
582
+ }
583
+ .hljs-strong {
584
+ font-weight: bold
585
+ }
586
+ }`;var U=`
587
+ :root {
588
+ --border-xheavy: var(--border);
589
+ }
590
+
591
+ .prose {
592
+ --tw-prose-body: var(--foreground);
593
+ --tw-prose-headings: var(--foreground);
594
+ --tw-prose-lead: var(--foreground);
595
+ --tw-prose-links: var(--foreground);
596
+ --tw-prose-bold: var(--foreground);
597
+ --tw-prose-counters: var(--foreground);
598
+ --tw-prose-bullets: var(--foreground);
599
+ --tw-prose-hr: var(--border-xheavy);
600
+ --tw-prose-quotes: var(--foreground);
601
+ --tw-prose-quote-borders: oklch(92.8% .006 264.531);
602
+ --tw-prose-captions: var(--secondary);
603
+ --tw-prose-code: var(--foreground);
604
+ --tw-prose-pre-code: oklch(92.8% .006 264.531);
605
+ --tw-prose-pre-bg: oklch(27.8% .033 256.848);
606
+ --tw-prose-th-borders: var(--border);
607
+ --tw-prose-td-borders: var(--border);
608
+ --tw-prose-invert-body: var(--foreground);
609
+ --tw-prose-invert-headings: var(--foreground);
610
+ --tw-prose-invert-lead: var(--foreground);
611
+ --tw-prose-invert-links: var(--foreground);
612
+ --tw-prose-invert-bold: var(--foreground);
613
+ --tw-prose-invert-counters: var(--foreground);
614
+ --tw-prose-invert-bullets: var(--foreground);
615
+ --tw-prose-invert-hr: var(--border-xheavy);
616
+ --tw-prose-invert-quotes: var(--foreground);
617
+ --tw-prose-invert-quote-borders: oklch(37.3% .034 259.733);
618
+ --tw-prose-invert-captions: var(--secondary);
619
+ --tw-prose-invert-code: var(--foreground);
620
+ --tw-prose-invert-pre-code: oklch(87.2% .01 258.338);
621
+ --tw-prose-invert-pre-bg: #00000080;
622
+ --tw-prose-invert-th-borders: oklch(44.6% .03 256.802);
623
+ --tw-prose-invert-td-borders: oklch(37.3% .034 259.733);
624
+ color: var(--tw-prose-body);
625
+ font-size: 1rem;
626
+ line-height: 1.75;
627
+ max-width: 65ch
628
+ }
629
+
630
+ /* Cleaned and corrected CSS for .prose styles */
631
+
632
+ .prose [class~="lead"]:not(.not-prose *) {
633
+ color: var(--tw-prose-lead);
634
+ font-size: 1.25em;
635
+ line-height: 1.6;
636
+ margin-top: 1.2em;
637
+ margin-bottom: 1.2em;
638
+ }
639
+
640
+ .prose a:not(.not-prose *) {
641
+ color: var(--tw-prose-links);
642
+ font-weight: 500;
643
+ text-decoration: underline;
644
+ }
645
+
646
+ .prose strong:not(.not-prose *) {
647
+ color: var(--tw-prose-bold);
648
+ font-weight: 600;
649
+ }
650
+
651
+ .prose a strong:not(.not-prose *),
652
+ .prose blockquote strong:not(.not-prose *),
653
+ .prose thead th strong:not(.not-prose *) {
654
+ color: inherit;
655
+ }
656
+
657
+ .prose ol:not(.not-prose *) {
658
+ list-style-type: decimal;
659
+ margin-top: 1.25em;
660
+ margin-bottom: 1.25em;
661
+ }
662
+
663
+ [dir="ltr"] .prose ol:not(.not-prose *) {
664
+ padding-left: 1.625em;
665
+ }
666
+
667
+ [dir="rtl"] .prose ol:not(.not-prose *) {
668
+ padding-right: 1.625em;
669
+ }
670
+
671
+ .prose ol[type="A"],
672
+ .prose ol[type="A s"],
673
+ .prose ol[type="a"],
674
+ .prose ol[type="a s"] {
675
+ list-style-type: upper-alpha;
676
+ }
677
+
678
+ .prose ol[type="I"],
679
+ .prose ol[type="I s"] {
680
+ list-style-type: upper-roman;
681
+ }
682
+
683
+ .prose ol[type="i"],
684
+ .prose ol[type="i s"] {
685
+ list-style-type: lower-roman;
686
+ }
687
+
688
+ .prose ol[type="1"] {
689
+ list-style-type: decimal;
690
+ }
691
+
692
+ .prose ul:not(.not-prose *) {
693
+ list-style-type: disc;
694
+ margin-top: 1.25em;
695
+ margin-bottom: 1.25em;
696
+ }
697
+
698
+ [dir="ltr"] .prose ul:not(.not-prose *) {
699
+ padding-left: 1.625em;
700
+ }
701
+
702
+ [dir="rtl"] .prose ul:not(.not-prose *) {
703
+ padding-right: 1.625em;
704
+ }
705
+
706
+ .prose ol > li::marker {
707
+ color: var(--tw-prose-counters);
708
+ font-weight: 400;
709
+ }
710
+
711
+ .prose ul > li::marker {
712
+ color: var(--tw-prose-bullets);
713
+ }
714
+
715
+ .prose hr:not(.not-prose *) {
716
+ border-top-width: 1px;
717
+ border-color: var(--tw-prose-hr);
718
+ margin-top: 3em;
719
+ margin-bottom: 3em;
720
+ }
721
+
722
+ .prose blockquote:not(.not-prose *) {
723
+ color: var(--tw-prose-quotes);
724
+ font-style: normal;
725
+ font-weight: 500;
726
+ margin-top: 1.6em;
727
+ margin-bottom: 1.6em;
728
+ quotes: "\\201C" "\\201D" "\\2018" "\\2019";
729
+ }
730
+
731
+ [dir="ltr"] .prose blockquote:not(.not-prose *) {
732
+ border-left-width: 0.25rem;
733
+ border-left-color: var(--tw-prose-quote-borders);
734
+ padding-left: 1em;
735
+ }
736
+
737
+ [dir="rtl"] .prose blockquote:not(.not-prose *) {
738
+ border-right-width: 0.25rem;
739
+ border-right-color: var(--tw-prose-quote-borders);
740
+ padding-right: 1em;
741
+ }
742
+
743
+ .prose blockquote p:first-of-type:not(.not-prose *)::before {
744
+ content: open-quote;
745
+ }
746
+
747
+ .prose blockquote p:last-of-type:not(.not-prose *)::after {
748
+ content: close-quote;
749
+ }
750
+
751
+ .prose h1:not(.not-prose *) {
752
+ color: var(--tw-prose-headings);
753
+ font-size: 2.25em;
754
+ font-weight: 800;
755
+ line-height: 1.11111;
756
+ margin-top: 0;
757
+ margin-bottom: 0.888889em;
758
+ }
759
+
760
+ .prose h1 strong:not(.not-prose *) {
761
+ color: inherit;
762
+ font-weight: 900;
763
+ }
764
+
765
+ .prose h2:not(.not-prose *) {
766
+ color: var(--tw-prose-headings);
767
+ font-size: 1.5em;
768
+ font-weight: 700;
769
+ line-height: 1.33333;
770
+ margin-top: 2em;
771
+ margin-bottom: 1em;
772
+ }
773
+
774
+ .prose h2 strong:not(.not-prose *) {
775
+ color: inherit;
776
+ font-weight: 800;
777
+ }
778
+
779
+ .prose h3:not(.not-prose *) {
780
+ color: var(--tw-prose-headings);
781
+ font-size: 1.25em;
782
+ font-weight: 600;
783
+ line-height: 1.6;
784
+ margin-top: 1.6em;
785
+ margin-bottom: 0.6em;
786
+ }
787
+
788
+ .prose h3 strong:not(.not-prose *) {
789
+ color: inherit;
790
+ font-weight: 700;
791
+ }
792
+
793
+ .prose h4:not(.not-prose *) {
794
+ color: var(--tw-prose-headings);
795
+ font-weight: 600;
796
+ line-height: 1.5;
797
+ margin-top: 1.5em;
798
+ margin-bottom: 0.5em;
799
+ }
800
+
801
+ .prose h4 strong:not(.not-prose *) {
802
+ color: inherit;
803
+ font-weight: 700;
804
+ }
805
+
806
+ .prose img:not(.not-prose *) {
807
+ margin-top: 2em;
808
+ margin-bottom: 2em;
809
+ }
810
+
811
+ .prose figure > *:not(.not-prose *) {
812
+ margin-top: 0;
813
+ margin-bottom: 0;
814
+ }
815
+
816
+ .prose figcaption:not(.not-prose *) {
817
+ color: var(--tw-prose-captions);
818
+ font-size: 0.875em;
819
+ line-height: 1.42857;
820
+ margin-top: 0.857143em;
821
+ }
822
+
823
+ .prose code:not(.not-prose *) {
824
+ /*background-color: var(--color-gray-100);*/
825
+ /*border-radius: 0.25rem;*/
826
+ color: var(--tw-prose-code);
827
+ /*font-size: 0.875em;*/
828
+ /*font-weight: 500;*/
829
+ padding: 0.15rem 0.3rem;
830
+ }
831
+
832
+ .prose code::before,
833
+ .prose code::after {
834
+ content: none;
835
+ }
836
+
837
+ .not-prose code::before,
838
+ .not-prose code::after {
839
+ content: unset;
840
+ }
841
+
842
+ .prose a code:not(.not-prose *),
843
+ .prose h1 code:not(.not-prose *) {
844
+ color: inherit;
845
+ }
846
+
847
+ .prose h2 code:not(.not-prose *) {
848
+ color: inherit;
849
+ font-size: 0.875em;
850
+ }
851
+
852
+ .prose h3 code:not(.not-prose *) {
853
+ color: inherit;
854
+ font-size: 0.9em;
855
+ }
856
+
857
+ .prose blockquote code:not(.not-prose *),
858
+ .prose h4 code:not(.not-prose *),
859
+ .prose thead th code:not(.not-prose *) {
860
+ color: inherit;
861
+ }
862
+
863
+ .prose pre:not(.not-prose *) {
864
+ /*background-color: transparent;*/
865
+ /*border-radius: 0.375rem;*/
866
+ /*color: currentColor;*/
867
+ /*font-size: 0.875em;*/
868
+ /*font-weight: 400;*/
869
+ /*line-height: 1.71429;*/
870
+ /*margin: 0;*/
871
+ overflow-x: auto;
872
+ /*padding: 0;*/
873
+ }
874
+
875
+ /*.prose pre code:not(.not-prose *) {*/
876
+ /* !*background-color: transparent;*!*/
877
+ /* border: none;*/
878
+ /* color: inherit;*/
879
+ /* font: inherit;*/
880
+ /* padding: 0;*/
881
+ /*}*/
882
+
883
+ .prose pre code::before,
884
+ .prose pre code::after {
885
+ content: none;
886
+ }
887
+
888
+ .prose table:not(.not-prose *) {
889
+ font-size: 0.875em;
890
+ line-height: 1.71429;
891
+ margin-top: 2em;
892
+ margin-bottom: 2em;
893
+ table-layout: auto;
894
+ width: 100%;
895
+ }
896
+
897
+ [dir="ltr"] .prose table:not(.not-prose *) {
898
+ text-align: left;
899
+ }
900
+
901
+ [dir="rtl"] .prose table:not(.not-prose *) {
902
+ text-align: right;
903
+ }
904
+
905
+ .prose thead:not(.not-prose *) {
906
+ border-bottom-width: 1px;
907
+ border-bottom-color: var(--tw-prose-th-borders);
908
+ }
909
+
910
+ .prose thead th:not(.not-prose *) {
911
+ color: var(--tw-prose-headings);
912
+ font-weight: 600;
913
+ padding: 0 0.571429em 0.571429em;
914
+ vertical-align: bottom;
915
+ }
916
+
917
+ .prose tbody tr:not(.not-prose *) {
918
+ border-bottom-width: 1px;
919
+ border-bottom-color: var(--tw-prose-td-borders);
920
+ }
921
+
922
+ .prose tbody tr:last-child:not(.not-prose *) {
923
+ border-bottom-width: 0;
924
+ }
925
+
926
+ .prose tbody td:not(.not-prose *) {
927
+ vertical-align: baseline;
928
+ }
929
+
930
+ .prose tfoot:not(.not-prose *) {
931
+ border-top-color: var(--tw-prose-th-borders);
932
+ border-top-width: 1px;
933
+ }
934
+
935
+ .prose tfoot td:not(.not-prose *) {
936
+ vertical-align: top;
937
+ }
938
+
939
+ .prose p:not(.not-prose *) {
940
+ margin-top: 1.25em;
941
+ margin-bottom: 1.25em;
942
+ }
943
+
944
+ .prose figure:not(.not-prose *),
945
+ .prose video:not(.not-prose *) {
946
+ margin-top: 2em;
947
+ margin-bottom: 2em;
948
+ }
949
+
950
+ .prose li:not(.not-prose *) {
951
+ margin-top: 0.5em;
952
+ margin-bottom: 0.5em;
953
+ }
954
+
955
+ [dir="ltr"] .prose ol > li:not(.not-prose *),
956
+ [dir="ltr"] .prose ul > li:not(.not-prose *) {
957
+ padding-left: 0.375em;
958
+ }
959
+
960
+ [dir="rtl"] .prose ol > li:not(.not-prose *),
961
+ [dir="rtl"] .prose ul > li:not(.not-prose *) {
962
+ padding-right: 0.375em;
963
+ }
964
+
965
+ .prose ul > li p:not(.not-prose *) {
966
+ margin-top: 0.75em;
967
+ margin-bottom: 0.75em;
968
+ }
969
+
970
+ .prose ul > li > :first-child:not(.not-prose *) {
971
+ margin-top: 1.25em;
972
+ }
973
+
974
+ .prose ul > li > :last-child:not(.not-prose *) {
975
+ margin-bottom: 1.25em;
976
+ }
977
+
978
+ .prose ol > li > :first-child:not(.not-prose *) {
979
+ margin-top: 1.25em;
980
+ }
981
+
982
+ .prose ol > li > :last-child:not(.not-prose *) {
983
+ margin-bottom: 1.25em;
984
+ }
985
+
986
+ .prose ul ul:not(.not-prose *),
987
+ .prose ul ol:not(.not-prose *),
988
+ .prose ol ul:not(.not-prose *),
989
+ .prose ol ol:not(.not-prose *) {
990
+ margin-top: 0.75em;
991
+ margin-bottom: 0.75em;
992
+ }
993
+
994
+ .prose h2 + *:not(.not-prose *),
995
+ .prose h3 + *:not(.not-prose *),
996
+ .prose h4 + *:not(.not-prose *),
997
+ .prose hr + *:not(.not-prose *) {
998
+ margin-top: 0;
999
+ }
1000
+
1001
+ [dir="ltr"] .prose thead th:first-child:not(.not-prose *) {
1002
+ padding-left: 0;
1003
+ }
1004
+
1005
+ [dir="rtl"] .prose thead th:first-child:not(.not-prose *) {
1006
+ padding-right: 0;
1007
+ }
1008
+
1009
+ [dir="ltr"] .prose thead th:last-child:not(.not-prose *) {
1010
+ padding-right: 0;
1011
+ }
1012
+
1013
+ [dir="rtl"] .prose thead th:last-child:not(.not-prose *) {
1014
+ padding-left: 0;
1015
+ }
1016
+
1017
+ .prose tbody td:not(.not-prose *),
1018
+ .prose tfoot td:not(.not-prose *) {
1019
+ padding: 0.571429em;
1020
+ }
1021
+
1022
+ [dir="ltr"] .prose tbody td:first-child:not(.not-prose *),
1023
+ [dir="ltr"] .prose tfoot td:first-child:not(.not-prose *) {
1024
+ padding-left: 0;
1025
+ }
1026
+
1027
+ [dir="rtl"] .prose tbody td:first-child:not(.not-prose *),
1028
+ [dir="rtl"] .prose tfoot td:first-child:not(.not-prose *) {
1029
+ padding-right: 0;
1030
+ }
1031
+
1032
+ [dir="ltr"] .prose tbody td:last-child:not(.not-prose *),
1033
+ [dir="ltr"] .prose tfoot td:last-child:not(.not-prose *) {
1034
+ padding-right: 0;
1035
+ }
1036
+
1037
+ [dir="rtl"] .prose tbody td:last-child:not(.not-prose *),
1038
+ [dir="rtl"] .prose tfoot td:last-child:not(.not-prose *) {
1039
+ padding-left: 0;
1040
+ }
1041
+
1042
+ .prose > :first-child:not(.not-prose *) {
1043
+ margin-top: 0;
1044
+ }
1045
+
1046
+ .prose > :last-child:not(.not-prose *) {
1047
+ margin-bottom: 0;
1048
+ }
1049
+ `;var K=require("@reduxjs/toolkit");var P=require("@reduxjs/toolkit"),ue={activeIndex:"",activeSession:"",sessions:[],useGenAi:!1,mode:0},F=(0,P.createSlice)({name:"chat",initialState:ue,reducers:{changeMode:(o,e)=>{o.mode=e.payload},setActiveIndex:(o,e)=>{o.activeIndex=e.payload},setActiveSession:(o,e)=>{o.activeSession=e.payload},setSessions:(o,e)=>{o.sessions=e.payload},setUseGenAi:(o,e)=>{o.useGenAi=e.payload}}}),{setActiveIndex:_,setActiveSession:D,setSessions:$e,setUseGenAi:Ie,changeMode:v}=F.actions,O=F.reducer;var k=require("@reduxjs/toolkit");var u=class{constructor(e){this.rawResponse=e}detectModelVersion(){let e=this.extractOutput();return!e||e.length===0||!Array.isArray(e)?"unknown":e?.[0]?.content||e?.[1]?.content?"gpt5":e[0]?.message?"gpt4":e?.some(t=>t?.text)?"file-chat":"unknown"}extractOutput(){let e=this.rawResponse;return e?.choices||e?.a?.choices||e?.output||e?.a?.output||e?.content||e?.a?.content||[]}normalizeGPT4Choice(e){return{output:e?.message?.content||""}}normalizeFileChatResponse(e){return{output:e?.text?.value}}normalizeGPT5Output(e){return{output:e.content.map(t=>t.text).join(`
1050
+
1051
+ `)}}parse(){let e=this.extractOutput(),t=this.detectModelVersion(),r=[];return t==="gpt4"?r=e?.filter(({message:a})=>a?.content).map(a=>this.normalizeGPT4Choice(a)):t==="gpt5"?r=e?.filter(a=>a?.content?.length>0).map(a=>this.normalizeGPT5Output(a)):t==="file-chat"&&(r=e?.filter(({text:a})=>a)?.map(a=>this.normalizeFileChatResponse(a))),{messages:r,model:t,raw:this.rawResponse}}};var B=async({baseURL:o,payload:e,apikey:t})=>{try{return await(await fetch("https://"+o+"/ai/vector/chat",{method:"POST",body:JSON.stringify(e),headers:{"x-bang-api-key":t,"x-bang-api-src":"chat-applet"}})).json()}catch{return{error:"Failed to get the response"}}},A=async({baseURL:o,payload:e,apikey:t})=>{try{return await(await fetch("https://"+o+"/ai/vector/metadata",{method:"POST",body:JSON.stringify(e),headers:{"x-bang-api-key":t,"x-bang-api-src":"chat-applet"}})).json()}catch(r){console.error(r)}};var G=(0,k.createAsyncThunk)("chatSession/streamResponse",async({sessionId:o,query:e,indexName:t,fall_back:r,config:{backendURL:a,apikey:n,userid:i}},{getState:s,dispatch:c})=>{let m=s(),{chatData:l,isLoading:d}=m.chatSessions[o];if(!e?.trim()||d)return;c(W({sessionId:o,loading:!0}));let p={query:e,a:{choices:[]}};c(E({sessionId:o,message:p})),c(M({sessionId:o,query:""}));let h=l?.filter(g=>g&&g?.op!=="ADD_FILES"&&!g?.source_file&&!g?.source)?.length,w=Array.isArray(l)?l?.map(g=>{let{messages:$}=new u(g).parse(),f=$?.map(y=>y?.output)?.filter(Boolean)?.join(`
1052
+ `);return!g?.query||!f||f.startsWith("Error: ")?null:{q:g?.query,a:f}})?.filter(g=>g!==null):[],S=await B({baseURL:a,apikey:n,payload:{name:t,qnum:h?h+1:1,fall_back:r,sessionid:o,userid:i,prev_qa:w,query:p?.query}}),ie=new u(S),{raw:se,messages:L}=ie.parse();if(c(W({sessionId:o,loading:!1})),L?.length>0)for(let g=0;g<L.length;g++){let f=(L[g]?.output||"")?.split(" "),y="";for(let T=0;T<f.length;T++)await new Promise(le=>setTimeout(le,20)),y=y+(y?" ":"")+f[T],c(E({sessionId:o,message:{query:p?.query,output:{output:y}}})),T===f.length-1&&(c(N({sessionId:o,chatData:[{query:p?.query,a:se}]})),c(E({sessionId:o,message:null})))}else c(E({sessionId:o,message:null})),c(N({sessionId:o,chatData:[{query:p?.query,a:{choices:[{index:0,message:{content:"Error: "+(S?.error?.[0]||"There is no context in the vector index and fall back option is null")}}]}}]}))}),Q=(0,k.createAsyncThunk)("chatSession/initializeState",async({indexName:o},{dispatch:e})=>{let t="GUEST_SESSION";e(_(o)),e(D(t)),e(ve(t))}),fe={},x={query:"",chatData:[],streamingMessage:null,isLoading:!1},V=(0,k.createSlice)({name:"chatSession",initialState:fe,reducers:{initSession:(o,e)=>{let t=e.payload;o[t]||(o[t]=x)},setLoading:(o,e)=>{let{sessionId:t,loading:r}=e.payload;o[t]||(o[t]=x),o[t].isLoading=r},setQuery:(o,e)=>{let{sessionId:t,query:r}=e.payload;o[t]||(o[t]=x),o[t].query=r},appendChatData:(o,e)=>{let{sessionId:t,chatData:r}=e.payload;o[t]||(o[t]=x),o[t].chatData=[...o[t].chatData||[],...r]},setChatData:(o,e)=>{let{sessionId:t,chatData:r}=e.payload;o[t]||(o[t]=x),o[t].chatData=r},setStreamingMessage:(o,e)=>{let{sessionId:t,message:r}=e.payload;o[t]&&(o[t].streamingMessage=r)}}}),{initSession:ve,setQuery:M,setChatData:We,appendChatData:N,setStreamingMessage:E,setLoading:W}=V.actions;var J=V.reducer;var Y=(0,K.configureStore)({reducer:{chat:O,chatSessions:J}});var z=q(require("highlight.js")),ee=q(require("markdown-it")),te=q(require("@vscode/markdown-it-katex"));var ye=function(o,e,t){let r=t,a=0,n=o.length;for(;r<e.length;){let i=e[r];if(a<=0&&e.slice(r,r+n)===o)return r;i==="\\"?r++:i==="{"?a++:i==="}"&&a--,r++}return-1},we=function(o){return o.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")},xe=/^\\begin{/,ke=function(o,e){let t,r=[],a=new RegExp("("+e.map(n=>we(n.left)).join("|")+")");for(;t=o.search(a),t!==-1;){t>0&&(r.push({type:"text",data:o.slice(0,t)}),o=o.slice(t));let n=e.findIndex(c=>o.startsWith(c.left));if(t=ye(e[n].right,o,e[n].left.length),t===-1)break;let i=o.slice(0,t+e[n].right.length),s=xe.test(i)?i:o.slice(e[n].left.length,t);r.push({type:"math",data:s,rawData:i,display:e[n].display}),o=o.slice(t+e[n].right.length)}return o!==""&&r.push({type:"text",data:o}),r},Z=ke;var rt=require("katex/dist/contrib/mhchem.min.js");function X(o){return new Promise(e=>{setTimeout(e,o)})}var oe=require("lodash"),re=new ee.default({html:!0,breaks:!0,linkify:!0,highlight:function(o,e){let t=e??"auto";if(e&&z.default.getLanguage(e))try{return`<pre class="language-${e}"><div class="ai-chat-code-title">${e}<a class="ai-chat-code-copy cursor-pointer">Copy</a></div><code class="hljs">`+z.default.highlight(o,{language:t,ignoreIllegals:!0}).value+"</code></pre>"}catch{}return'<pre><code class="hljs">'+o+"</code></pre>"}}).enable(["table","code","fence","blockquote","heading","lheading","paragraph"]).enable(["autolink","linkify","backticks","image","link","newline"]).enable(["emphasis","html_inline"]).use(te.default);typeof window<"u"&&window.document.addEventListener("click",o=>{if(o.target?.classList?.contains("ai-chat-code-copy")){let e=o.target.parentNode?.nextSibling?.innerText;navigator.clipboard.writeText(e).then(async()=>{o.target.innerHTML='<span style="margin-right:3px">Copied</span>\u2705',await X(3e3),o.target.innerText="Copy"}).catch(t=>{alert(`Error copying code: ${t.message}`)})}});var Ce={fn:o=>{o()}},nt=(0,oe.debounce)((o=()=>{})=>{Ce.fn(o)},10);var Se=o=>o.replace(/(```mermaid)(?![^]*?```)/g,"```"),Te=o=>Z(o,[{left:"\\[",right:"\\]",display:!0},{left:"\\(",right:"\\)",display:!1}]).reduce((t,r)=>{if(r.type==="text")return t+r.data;let a=r.display?`$$${r.data}$$`:`$${r.data}$`;return t+a},""),je=o=>{let e="",t="",r=!1,a="think-wrapper",n=i=>{let s=i.replace(/<script([^>]*)>/gi,"&lt;script$1&gt;");return s=s.replace(/<\/script>/gi,"&lt;/script&gt;"),s=s.replace(/<script([^>]*)\s*\/>/gi,"&lt;script$1 /&gt;"),s};for(let i=0;i<o.length;i++){let s=o[i],c=o.slice(i,i+7),m=o.slice(i,i+8);if(!r&&c==="<think>"){r=!0,e+=`<div class="${a}">`,i+=6;continue}if(r&&m==="</think>"){r=!1,e+="</div>",i+=7;continue}r?t+=s:e+=s}if(t){let i=n(t),s=re.render(i);e=e.replace(`<div class="${a}">`,`<div class="${a}">${s}`)}return e},Ee=o=>o.replace(/\[source_id:\s*([^\]|]+)(?:\s*\|\s*category:\s*([^\]]+))?\]\.?/g,(e,t,r)=>r?`<source-tag data-source-id="${t.trim()}" data-category="${r.trim()}"></source-tag>`:`<source-tag data-source-id="${t.trim()}"></source-tag>`),H=o=>{let e=je(o),t=Te(e),r=Se(t),a=Ee(r);return re.render(a)};var C=class{constructor(e){this.font={body:'"Inter", sans-serif',mono:'"JetBrains Mono", monospace'};this.TOKENS={background:"oklch(0.2223 0.0060 271.1393)",foreground:"oklch(0.9551 0 0)",card:"oklch(0.2568 0.0076 274.6528)",cardForeground:"oklch(0.9551 0 0)",primary:"oklch(0.611 0.1217 157.75)",primaryForeground:"oklch(0.9491 0 0)",secondary:"oklch(0.2940 0.0130 272.9312)",secondaryForeground:"oklch(0.9551 0 0)",muted:"oklch(0.2940 0.0130 272.9312)",mutedForeground:"oklch(0.7058 0 0)",accent:"oklch(0.2795 0.0368 260.0310)",accentForeground:"oklch(0.7857 0.1153 246.6596)",border:"oklch(0.3289 0.0092 268.3843)",input:"oklch(0.3289 0.0092 268.3843)",ring:"oklch(0.611 0.1217 157.75)",radius:"0.5rem",shadowPanel:"0 32px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.06)",shadowBubble:"0 8px 32px color-mix(in oklab, oklch(0.611 0.1217 157.75) 40%, transparent)",shadowInput:"0 0 0 2px color-mix(in oklab, oklch(0.611 0.1217 157.75) 50%, transparent)"};this.store=Y;this.apiConfig=null;this.bubbleEl=null;this.chatUIEl=null;this.chatAreaEl=null;this.renderedMessageIds=new Set;this.chatTitle="Chat with AI";this.logoUrl="";e.colorTokens&&(this.TOKENS={...this.TOKENS,...e.colorTokens}),e.title&&(this.chatTitle=e.title),e.logo&&(this.logoUrl=e.logo),this.apiConfig=e.config,this.container=document.createElement("div"),this.container.id="ai-chat-widget-root",document.body.appendChild(this.container),this.root=this.container.attachShadow({mode:"open"}),this.injectGlobalFonts(),this.injectThemeVars(),this.init().then(()=>{this.mount(),this.store.subscribe(()=>{let t=this.store.getState(),r=t?.chat?.mode,{chatData:a,streamingMessage:n,isLoading:i}=t?.chatSessions?.[t?.chat?.activeSession]??{};this.handleModeChange(r),this.handleChatDataChange({streamingMessage:n,chatData:a,isLoading:i})})})}injectThemeVars(){let e=this.TOKENS,t=document.createElement("style");t.textContent=`
1053
+ :host {
1054
+ --background: ${e.background};
1055
+ --foreground: ${e.foreground};
1056
+ --card: ${e.card};
1057
+ --card-foreground: ${e.cardForeground};
1058
+ --primary: ${e.primary};
1059
+ --primary-foreground: ${e.primaryForeground};
1060
+ --secondary: ${e.secondary};
1061
+ --secondary-foreground: ${e.secondaryForeground};
1062
+ --muted: ${e.muted};
1063
+ --muted-foreground: ${e.mutedForeground};
1064
+ --accent: ${e.accent};
1065
+ --accent-foreground: ${e.accentForeground};
1066
+ --border: ${e.border};
1067
+ --input: ${e.input};
1068
+ --ring: ${e.ring};
1069
+ --radius: ${e.radius};
1070
+ --radius-sm: calc(${e.radius} - 4px);
1071
+ --radius-md: calc(${e.radius} - 2px);
1072
+ --radius-lg: ${e.radius};
1073
+ --radius-full: 9999px;
1074
+ --shadow-panel: ${e.shadowPanel};
1075
+ --shadow-bubble: ${e.shadowBubble};
1076
+ --shadow-input: ${e.shadowInput};
1077
+ /* Convenience aliases */
1078
+ --font-body: ${this.font.body};
1079
+ --font-mono: ${this.font.mono};
1080
+ }
1081
+ `,this.root.appendChild(t)}injectGlobalFonts(){let e="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=JetBrains+Mono:ital,wght@0,100..800;1,100..800",t=document.createElement("link");t.rel="preconnect",t.href="https://fonts.googleapis.com";let r=document.createElement("link");r.rel="preconnect",r.href="https://fonts.gstatic.com",r.crossOrigin="";let a=document.createElement("link");a.type="text/css",a.rel="stylesheet",a.href=e,this.root.appendChild(t),this.root.appendChild(r),this.root.appendChild(a),document.head.appendChild(t),document.head.appendChild(r),document.head.appendChild(a)}mount(){let e=this.createChatBubble();this.root.appendChild(e),this.bubbleEl=e}async init(){await this.store.dispatch(Q({indexName:this.apiConfig?.indexName}))}handleChatDataChange({chatData:e,streamingMessage:t,isLoading:r}){if(!this.chatAreaEl)return;e||(e=[]);let a=this.chatAreaEl.querySelector(".chat-data-container"),n=this.chatAreaEl.querySelector("#bangdb-chat-area"),i=this.chatAreaEl.querySelector("#bdb-empty-state"),s=()=>{requestAnimationFrame(()=>{n.scrollTo({top:n.scrollHeight,behavior:"smooth"})})},c=e.length>0||!!t?.query;i.style.display=c?"none":"flex";for(let d=0;d<e.length;d++){let p=e[d],h=`msg-${d}`;if(p?.query&&!this.renderedMessageIds.has(h)){this.renderedMessageIds.add(h),a.insertBefore(this.userRequestMessage(p.query),a.querySelector("#chat-window-anchor"));let w=new u(p),{messages:S}=w.parse();S?.length>0&&a.insertBefore(this.aiResponseMessage(p),a.querySelector("#chat-window-anchor")),s()}}let m="bdb-streaming-msg",l=this.root.querySelector(`#${m}`);if(t?.query){l||(l=document.createElement("div"),l.id=m,a.insertBefore(l,a.querySelector("#chat-window-anchor")),l.appendChild(this.userRequestMessage(t.query)),l.style.minHeight=`${n.clientHeight*.8}px`);let d=l.querySelector(".bdb-streaming-ai-area"),p=t.output?.output??"";if(r&&!p&&!d)d=document.createElement("div"),d.className="bdb-streaming-ai-area",d.appendChild(this.loadingIndicator()),l.appendChild(d);else if(p){d||(d=document.createElement("div"),d.className="bdb-streaming-ai-area",l.appendChild(d));let h=d.querySelector(".ai-md");h?h.innerHTML=H(p):(d.innerHTML="",d.appendChild(this.aiResponseMessage(t)))}i.style.display="none",s()}else l&&(l.style.minHeight="",l.remove())}handleModeChange(e){let t=this.bubbleEl?.querySelector(".chat-bubble");if(t)switch(e){case 0:if(t.classList.remove("is-open"),t.setAttribute("aria-label","Open chat"),this.chatUIEl){let n=this.chatUIEl.querySelector(".bdb-chat-panel");n&&(n.style.animation="bdb-panel-out 0.18s ease-in both",n&&(n.style.animation="bdb-panel-out 0.18s ease-in both"),setTimeout(()=>{this.chatUIEl&&(this.chatUIEl.style.display="none")},180))}break;case 1:if(t.setAttribute("aria-label","Close chat"),!this.chatUIEl)this.chatUIEl=this.createChatUI(),this.bubbleEl?.appendChild(this.chatUIEl);else{this.chatUIEl.style.display="";let n=this.chatUIEl.querySelector(".bdb-chat-panel");n&&(n.style.animation="bdb-panel-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both")}t.classList.add("is-open"),this.chatUIEl?.querySelector(".bdb-chat-panel")?.classList.remove("is-fullscreen");break;case 2:if(t.setAttribute("aria-label","Close chat"),!this.chatUIEl)this.chatUIEl=this.createChatUI(),this.bubbleEl?.appendChild(this.chatUIEl);else{this.chatUIEl.style.display="";let n=this.chatUIEl.querySelector(".bdb-chat-panel");n&&(n.style.animation="bdb-panel-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both")}t.classList.add("is-open"),this.chatUIEl?.querySelector(".bdb-chat-panel")?.classList.add("is-fullscreen");break}}createChatBubble(){let e=document.createElement("div");return e.classList.add("bdb-bubble-container"),e.innerHTML=`
1082
+ <style>
1083
+ .bdb-bubble-container {
1084
+ position: fixed;
1085
+ bottom: 1.5rem;
1086
+ right: 1.5rem;
1087
+ z-index: 999999;
1088
+ }
1089
+
1090
+ .chat-bubble::before {
1091
+ content: '';
1092
+ position: absolute;
1093
+ inset: -4px;
1094
+ border-radius: 50%;
1095
+ border: 2px solid var(--primary);
1096
+ opacity: 0;
1097
+ animation: bdb-ring 3s ease-out 2s infinite;
1098
+ }
1099
+
1100
+ @keyframes bdb-ring {
1101
+ 0% { transform: scale(0.95); opacity: 0.7; }
1102
+ 100% { transform: scale(1.35); opacity: 0; }
1103
+ }
1104
+
1105
+ .chat-bubble {
1106
+ position: relative;
1107
+ width: 52px;
1108
+ height: 52px;
1109
+ border-radius: 50%;
1110
+ background: linear-gradient(135deg, var(--primary), var(--ring));
1111
+ cursor: pointer;
1112
+ box-shadow: var(--shadow-bubble);
1113
+ display: flex;
1114
+ align-items: center;
1115
+ justify-content: center;
1116
+ transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.2s;
1117
+ border: none;
1118
+ }
1119
+
1120
+ .chat-bubble:hover {
1121
+ transform: scale(1.1);
1122
+ box-shadow: 0 12px 40px color-mix(in oklab, var(--primary) 50%, transparent);
1123
+ }
1124
+
1125
+ .chat-bubble .icon-chat,
1126
+ .chat-bubble .icon-close {
1127
+ position: absolute;
1128
+ transition: transform 0.2s ease, opacity 0.15s ease;
1129
+ color: var(--primary-foreground);
1130
+ }
1131
+ .chat-bubble .icon-close {
1132
+ opacity: 0;
1133
+ transform: rotate(-90deg) scale(0.6);
1134
+ }
1135
+ .chat-bubble.is-open .icon-chat {
1136
+ opacity: 0;
1137
+ transform: rotate(90deg) scale(0.6);
1138
+ }
1139
+ .chat-bubble.is-open .icon-close {
1140
+ opacity: 1;
1141
+ transform: rotate(0deg) scale(1);
1142
+ }
1143
+ </style>
1144
+
1145
+
1146
+ <button class="chat-bubble" aria-label="Open chat" aria-haspopup="dialog">
1147
+ <span class="icon-chat">
1148
+ <svg focusable="false" aria-hidden="true" viewBox="0 0 28 32" width="22" height="22" fill="white">
1149
+ <path d="M28,32 C28,32 23.2863266,30.1450667 19.4727818,28.6592 L3.43749107,28.6592 C1.53921989,28.6592 0,27.0272 0,25.0144 L0,3.6448 C0,1.632 1.53921989,0 3.43749107,0 L24.5615088,0 C26.45978,0 27.9989999,1.632 27.9989999,3.6448 L27.9989999,22.0490667 L28,22.0490667 L28,32 Z M23.8614088,20.0181333 C23.5309223,19.6105242 22.9540812,19.5633836 22.5692242,19.9125333 C22.5392199,19.9392 19.5537934,22.5941333 13.9989999,22.5941333 C8.51321617,22.5941333 5.48178311,19.9584 5.4277754,19.9104 C5.04295119,19.5629428 4.46760991,19.6105095 4.13759108,20.0170667 C3.97913051,20.2124916 3.9004494,20.4673395 3.91904357,20.7249415 C3.93763774,20.9825435 4.05196575,21.2215447 4.23660523,21.3888 C4.37862552,21.5168 7.77411059,24.5386667 13.9989999,24.5386667 C20.2248893,24.5386667 23.6203743,21.5168 23.7623946,21.3888 C23.9467342,21.2215726 24.0608642,20.9827905 24.0794539,20.7254507 C24.0980436,20.4681109 24.0195551,20.2135019 23.8614088,20.0181333 Z"/>
1150
+ </svg>
1151
+ </span>
1152
+ <span class="icon-close">
1153
+ <svg width="18" height="18" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
1154
+ <path d="M1 1l12 12M13 1L1 13" stroke="white" stroke-width="2" stroke-linecap="round"/>
1155
+ </svg>
1156
+ </span>
1157
+ </button>
1158
+ `,e.querySelector(".chat-bubble").addEventListener("click",()=>{let{chat:r}=this.store.getState();r?.mode===0?this.store.dispatch(v(1)):this.store.dispatch(v(0))}),e}createChatUI(){let e=document.createElement("div");e.innerHTML=`
1159
+ <style>
1160
+ .bdb-chat-widget {
1161
+ display: flex;
1162
+ flex-direction: column;
1163
+ height: 100%;
1164
+ width: 100%;
1165
+ font-family: var(--font-body);
1166
+ color: var(--foreground);
1167
+ background: var(--background);
1168
+ border-radius: var(--radius-lg);
1169
+ overflow: hidden;
1170
+ }
1171
+
1172
+ .bdb-chat-header {
1173
+ display: flex;
1174
+ align-items: center;
1175
+ justify-content: space-between;
1176
+ padding: 0 1.25rem;
1177
+ height: 3.25rem;
1178
+ flex-shrink: 0;
1179
+ background: var(--card);
1180
+ border-bottom: 1px solid var(--border);
1181
+ }
1182
+
1183
+ .bdb-chat-panel.is-fullscreen .bdb-chat-header {
1184
+ max-width: 56rem;
1185
+ margin: 0 auto;
1186
+ width: 100%;
1187
+ background: transparent;
1188
+ border-bottom: 1px solid var(--border);
1189
+ }
1190
+
1191
+ .bdb-chat-title-container {
1192
+ display: flex;
1193
+ align-items: center;
1194
+ gap: 0.25rem;
1195
+ }
1196
+
1197
+ .bdb-chat-title {
1198
+ font-size: 15px;
1199
+ font-weight: 600;
1200
+ font-family: var(--font-body);
1201
+ letter-spacing: -0.01em;
1202
+ color: var(--foreground);
1203
+ margin: 0;
1204
+ }
1205
+
1206
+ .bdb-header-status {
1207
+ display: flex;
1208
+ align-items: center;
1209
+ gap: 6px;
1210
+ font-size: 12px;
1211
+ color: var(--muted-foreground);
1212
+ }
1213
+
1214
+ .bdb-status-dot {
1215
+ width: 7px;
1216
+ height: 7px;
1217
+ border-radius: 50%;
1218
+ background: #22c55e;
1219
+ animation: bdb-pulse 2s ease-in-out infinite;
1220
+ }
1221
+
1222
+ @keyframes bdb-pulse {
1223
+ 0%, 100% { opacity: 1; transform: scale(1); }
1224
+ 50% { opacity: 0.6; transform: scale(0.85); }
1225
+ }
1226
+
1227
+ .bdb-header-actions {
1228
+ display: flex;
1229
+ align-items: center;
1230
+ gap: 4px;
1231
+ }
1232
+
1233
+ .bdb-icon-btn {
1234
+ display: flex;
1235
+ align-items: center;
1236
+ justify-content: center;
1237
+ width: 30px;
1238
+ height: 30px;
1239
+ border-radius: var(--radius-md);
1240
+ border: none;
1241
+ background: transparent;
1242
+ color: var(--muted-foreground);
1243
+ cursor: pointer;
1244
+ transition: background 0.15s, color 0.15s;
1245
+ }
1246
+
1247
+ .bdb-icon-btn:hover {
1248
+ background: color-mix(in oklab, var(--foreground) 7%, transparent);
1249
+ color: var(--foreground);
1250
+ }
1251
+
1252
+ .bdb-chat-panel {
1253
+ display: flex;
1254
+ flex-direction: column;
1255
+ position: fixed;
1256
+ bottom: 5.5rem;
1257
+ right: 1.5rem;
1258
+ width: 500px;
1259
+ height: 750px;
1260
+ background: var(--background);
1261
+ border-radius: var(--radius-lg);
1262
+ box-shadow: var(--shadow-panel);
1263
+ border: 1px solid var(--border);
1264
+ overflow: hidden;
1265
+ transform-origin: bottom right;
1266
+ animation: bdb-panel-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both;
1267
+ z-index: 999998;
1268
+ }
1269
+
1270
+ @keyframes bdb-panel-in {
1271
+ from { opacity: 0; transform: scale(0.85) translateY(12px); }
1272
+ to { opacity: 1; transform: scale(1) translateY(0); }
1273
+ }
1274
+
1275
+ .bdb-chat-panel.is-fullscreen {
1276
+ bottom: 0;
1277
+ right: 0;
1278
+ left: 0;
1279
+ top: 0;
1280
+ width: 100vw;
1281
+ height: 100vh;
1282
+ border-radius: 0;
1283
+ display: flex;
1284
+ align-items: center;
1285
+ justify-content: center;
1286
+ background: color-mix(in oklab, var(--card) 55%, transparent);
1287
+ backdrop-filter: blur(2px);
1288
+ }
1289
+
1290
+ .bdb-chat-panel.is-fullscreen .bdb-chat-widget {
1291
+ width: 90vw;
1292
+ height: 90vh;
1293
+ border-radius: var(--radius-lg);
1294
+ box-shadow: var(--shadow-panel);
1295
+ border: 1px solid var(--border);
1296
+ }
1297
+ </style>
1298
+
1299
+ <div class="bdb-chat-panel">
1300
+ <div class="bdb-chat-widget">
1301
+ <header class="bdb-chat-header">
1302
+ <!-- <div class="bdb-header-status">-->
1303
+ <!-- <span class="bdb-status-dot"></span>-->
1304
+ <!-- <span>AI Assistant</span>-->
1305
+ <!-- </div>-->
1306
+
1307
+ <div class="bdb-chat-title-container">
1308
+ <h3 class="bdb-chat-title">${this.chatTitle}</h3>
1309
+ </div>
1310
+
1311
+ <div class="bdb-header-actions">
1312
+ <button class="bdb-icon-btn js-fullscreen-btn" aria-label="Toggle fullscreen" title="Fullscreen">
1313
+ <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
1314
+ <path d="M1.5 1h4v1.5h-2.5v2.5h-1.5v-4zm8 0h4v4h-1.5v-2.5h-2.5v-1.5zm-8 8h1.5v2.5h2.5v1.5h-4v-4zm10.5 2.5v-2.5h1.5v4h-4v-1.5h2.5z" fill="currentColor"/>
1315
+ </svg>
1316
+ </button>
1317
+
1318
+ <!-- <button class="bdb-icon-btn js-download-btn" aria-label="Download chat" title="Download">-->
1319
+ <!-- <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">-->
1320
+ <!-- <path d="M7.5 10.5l-4-4h2.5v-5h3v5h2.5l-4 4zm-5 2h10v1.5h-10v-1.5z" fill="currentColor"/>-->
1321
+ <!-- </svg>-->
1322
+ <!-- </button>-->
1323
+
1324
+ <button class="bdb-icon-btn js-close-btn" aria-label="Close chat" title="Close">
1325
+ <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
1326
+ <path d="M1 1l12 12M13 1L1 13" stroke="currentColor" stroke-width="1.75" stroke-linecap="round"/>
1327
+ </svg>
1328
+ </button>
1329
+ </div>
1330
+ </header>
1331
+
1332
+ <div class="bdb-chat-body" style="display: flex; flex-direction: column; flex: 1; overflow: hidden;"></div>
1333
+ </div>
1334
+ </div>
1335
+ `;let t=e.querySelector(".bdb-chat-panel"),r=e.querySelector(".bdb-chat-body"),a=e.querySelector(".bdb-chat-title-container");if(t.querySelector(".js-fullscreen-btn")?.addEventListener("click",()=>{this.store.getState().chat.mode===2?this.store.dispatch(v(1)):this.store.dispatch(v(2))}),t.querySelector(".js-close-btn")?.addEventListener("click",()=>{let n=this.store.getState().chat.mode;n===2?this.store.dispatch(v(1)):n===1&&this.store.dispatch(v(0))}),this.logoUrl){let n=document.createElement("div"),i=document.createElement("img");i.src=this.logoUrl,i.style.cssText="width: 24px; height: 24px; margin-right: 0.5rem;",n.appendChild(i),a.prepend(n)}return r.appendChild(this.chatArea()),e}chatArea(){let e=document.createElement("div");e.style.cssText="display: flex; flex-direction: column; flex: 1; overflow: hidden; position: relative;",e.innerHTML=`
1336
+ <style>
1337
+ .bdb-scroll {
1338
+ scrollbar-width: thin;
1339
+ scrollbar-color: color-mix(in oklab, var(--foreground) 10%, transparent) transparent;
1340
+ scroll-behavior: smooth;
1341
+ }
1342
+
1343
+ .bdb-scroll:hover {
1344
+ scrollbar-color: color-mix(in oklab, var(--foreground) 18%, transparent) transparent;
1345
+ }
1346
+
1347
+ .bdb-empty-state {
1348
+ display: flex;
1349
+ flex-direction: column;
1350
+ align-items: center;
1351
+ justify-content: center;
1352
+ gap: 0.75rem;
1353
+ height: 100%;
1354
+ color: var(--muted-foreground);
1355
+ text-align: center;
1356
+ padding: 2rem;
1357
+ }
1358
+
1359
+ .bdb-empty-icon {
1360
+ width: 48px;
1361
+ height: 48px;
1362
+ border-radius: var(--radius-md);
1363
+ background: var(--primary);
1364
+ display: flex;
1365
+ align-items: center;
1366
+ justify-content: center;
1367
+ color: var(--primary-foreground);
1368
+ margin-bottom: 0.25rem;
1369
+ }
1370
+
1371
+ .bdb-empty-title {
1372
+ font-size: 15px;
1373
+ font-weight: 600;
1374
+ color: var(--foreground);
1375
+ font-family: var(--font-body);
1376
+ margin: 0;
1377
+ }
1378
+ .bdb-empty-sub {
1379
+ font-family: var(--font-body);
1380
+ font-size: 13px;
1381
+ margin: 0;
1382
+ line-height: 1.5;
1383
+ }
1384
+
1385
+ .bdb-scroll-fab {
1386
+ position: absolute;
1387
+ bottom: 0.5rem;
1388
+ left: 50%;
1389
+ transform: translateX(-50%);
1390
+ background: var(--card);
1391
+ border: 1px solid var(--border);
1392
+ border-radius: var(--radius-full);
1393
+ width: 32px;
1394
+ height: 32px;
1395
+ display: flex;
1396
+ align-items: center;
1397
+ justify-content: center;
1398
+ cursor: pointer;
1399
+ color: var(--foreground);
1400
+ box-shadow: 0 4px 12px rgba(0,0,0,0.4);
1401
+ transition: opacity 0.2s, transform 0.2s;
1402
+ opacity: 0;
1403
+ pointer-events: none;
1404
+ z-index: 10;
1405
+ }
1406
+ .bdb-scroll-fab.visible {
1407
+ opacity: 1;
1408
+ pointer-events: auto;
1409
+ }
1410
+
1411
+ .bdb-chat-panel.is-fullscreen #chat-query-container {
1412
+ max-width: 56rem;
1413
+ margin: 0 auto;
1414
+ width: 100%;
1415
+ }
1416
+ </style>
1417
+
1418
+ <div style="position: relative; flex: 1; overflow: hidden;">
1419
+ <div class="bdb-scroll" id="bangdb-chat-area"
1420
+ style="height: 100%; overflow-y: auto; padding: 1rem 1.25rem; display: flex; flex-direction: column;">
1421
+
1422
+ <div style="max-width: 56rem; margin: 0 auto; width: 100%; display: flex; flex-direction: column; gap: 0.25rem; flex: 1;">
1423
+ <div class="bdb-empty-state" id="bdb-empty-state">
1424
+ <div class="bdb-empty-icon">
1425
+ <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
1426
+ <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>
1427
+ </svg>
1428
+ </div>
1429
+ <p class="bdb-empty-title">How can I help you?</p>
1430
+ <p class="bdb-empty-sub">Ask me anything. I'm here to assist.</p>
1431
+ </div>
1432
+
1433
+ <div class="chat-data-container" style="display: flex; flex-direction: column; gap: 0.25rem; flex: 1;">
1434
+ <div id="chat-window-anchor" style="overflow-anchor: auto; height: 1px;"></div>
1435
+ </div>
1436
+ </div>
1437
+ </div>
1438
+
1439
+ <button class="bdb-scroll-fab" id="bdb-scroll-fab" aria-label="Scroll to bottom">
1440
+ <svg width="14" height="14" viewBox="0 0 14 14" fill="currentColor">
1441
+ <path d="M7 10.5l-5-5h2.5V1h5v4.5H12L7 10.5zm-4 2h8v1.5H3V12.5z"/>
1442
+ </svg>
1443
+ </button>
1444
+ </div>
1445
+
1446
+ <div id="chat-query-container"
1447
+ style="flex-shrink: 0; background: var(--background); padding: 0.75rem 1rem 1rem;">
1448
+ </div>
1449
+ `;let t=e.querySelector("#bangdb-chat-area"),r=e.querySelector("#chat-query-container"),a=e.querySelector("#bdb-scroll-fab");return r.appendChild(this.chatQueryForm()),t.addEventListener("scroll",()=>{let n=t.scrollHeight-t.scrollTop-t.clientHeight;a.classList.toggle("visible",n>100)}),a.addEventListener("click",()=>{t.scrollTo({top:t.scrollHeight,behavior:"smooth"})}),this.chatAreaEl=e,e}loadingIndicator(){let e=document.createElement("div");return e.innerHTML=`
1450
+ <style>
1451
+ .bdb-loading {
1452
+ display: flex;
1453
+ align-items: center;
1454
+ gap: 12px;
1455
+ padding: 0.75rem 0;
1456
+ color: var(--muted-foreground);
1457
+ font-size: 13px;
1458
+ }
1459
+ .bdb-typing-dots {
1460
+ display: flex;
1461
+ gap: 4px;
1462
+ }
1463
+ .bdb-typing-dots span {
1464
+ width: 6px;
1465
+ height: 6px;
1466
+ border-radius: 50%;
1467
+ background: var(--primary);
1468
+ animation: bdb-bounce 1.2s ease-in-out infinite;
1469
+ }
1470
+ .bdb-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
1471
+ .bdb-typing-dots span:nth-child(3) { animation-delay: 0.3s; }
1472
+ @keyframes bdb-bounce {
1473
+ 0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
1474
+ 40% { transform: translateY(-6px); opacity: 1; }
1475
+ }
1476
+ </style>
1477
+
1478
+ <div class="bdb-loading">
1479
+ <div class="bdb-typing-dots">
1480
+ <span></span><span></span><span></span>
1481
+ </div>
1482
+ <span>Thinking\u2026</span>
1483
+ </div>
1484
+ `,e}userRequestMessage(e){let t=document.createElement("div");return t.style.cssText="display: flex; justify-content: flex-end; margin-block: 0.375rem;",t.innerHTML=`
1485
+ <style>
1486
+ .bdb-user-bubble {
1487
+ max-width: 75%;
1488
+ background: var(--secondary);
1489
+ color: var(--secondary-foreground);
1490
+ border-radius: 18px 18px 4px 18px;
1491
+ padding: 0.6rem 1rem;
1492
+ font-size: 14px;
1493
+ line-height: 1.55;
1494
+ word-break: break-word;
1495
+ box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
1496
+ }
1497
+ </style>
1498
+ <div class="bdb-user-bubble"></div>
1499
+ `,t.querySelector(".bdb-user-bubble").textContent=e,t}aiResponseMessage(e){let t=document.createElement("div");t.style.cssText="display: flex; gap: 0.625rem; align-items: flex-start; margin-block: 0.375rem;",t.innerHTML=`
1500
+ <style>
1501
+ ${U}
1502
+ ${R}
1503
+
1504
+ .ai-md pre {
1505
+ padding: 1rem;
1506
+ background: var(--card);
1507
+ border-radius: var(--radius-md);
1508
+ }
1509
+
1510
+ .bdb-ai-bubble {
1511
+ flex: 1;
1512
+ min-width: 0;
1513
+ padding: 0.5rem 0;
1514
+ font-size: 14px;
1515
+ line-height: 1.65;
1516
+ color: var(--foreground);
1517
+ }
1518
+ </style>
1519
+
1520
+ <div class="bdb-ai-bubble ai-md prose"></div>
1521
+ `;let r=t.querySelector(".ai-md");if(r){let a=new u(e),{messages:n}=a.parse(),i=n.map(s=>s?.output??"").join("");r.innerHTML=H(i),this.renderSourceTags(r,e)}return t}async renderSourceTags(e,t){let r=e.querySelectorAll("source-tag");if(!r.length)return;let a=t?.a?.metadata||t?.metadata||[];for(let n of r){let i=n.getAttribute("data-source-id"),s=n.getAttribute("data-category");if(!i||i.toLowerCase()==="na"){n.remove();continue}let c=document.createElement("span");c.style.cssText="display: block; padding: 0.75rem 0;";let m=i.split("##"),l=m[1]??i,d=m[2],p=document.createElement("span");if(p.style.cssText="display: block; font-size: 12px; color: var(--accent-foreground); padding-bottom: 0.5rem;",p.innerHTML=`
1522
+ <span style="text-decoration: underline; color: var(--accent-foreground);">
1523
+ Source: ${decodeURIComponent(l)}
1524
+ ${d?`<span style="padding: 0 0.5rem;">|</span>Page: ${d}`:""}
1525
+ </span>
1526
+ ${s?`<span style="padding: 0 0.5rem;">|</span>Category: ${s}`:""}
1527
+ `,c.appendChild(p),a.length>0){let h=a.find(w=>w?.source_id===i);h?.table_ids?.length&&await this.renderTables(c,h.table_ids),h?.image_ids?.length&&await this.renderImages(c,h.image_ids)}n.replaceWith(c)}}async renderTables(e,t){for(let r of t){let a=document.createElement("div");a.innerHTML=`<div style="display:grid;grid-template-columns:repeat(9,1fr);gap:2px;">
1528
+ ${Array.from({length:36}).map(()=>'<div style="height:2rem;background:rgba(255,255,255,0.05);border-radius:2px;"></div>').join("")}
1529
+ </div>`,e.appendChild(a);try{let n=await A({baseURL:this.apiConfig.backendURL,apikey:this.apiConfig.apikey,payload:{name:this.apiConfig.indexName,type:"table",id:r}});n?.metadata?.text_as_html&&(a.innerHTML=`<div style="overflow-x:auto;margin-bottom:1rem;">${n.metadata.text_as_html}</div>`)}catch{a.innerHTML='<div style="color:#f87171;font-size:12px;margin-bottom:0.5rem;">Failed to load table</div>'}}}async renderImages(e,t){let r=document.createElement("div");r.style.cssText="display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.75rem; margin-top: 0.5rem;",e.appendChild(r);let{backendURL:a,resourceURL:n,apikey:i,indexName:s}=this.apiConfig,c=`${s}_img_bucket`;for(let m of t){let l=document.createElement("div");l.style.cssText="border-radius: 8px; overflow: hidden; border: 1px solid rgba(255,255,255,0.08); background: rgba(255,255,255,0.03);",l.innerHTML='<div style="height: 8rem; background: rgba(255,255,255,0.05); display:flex; align-items:center; justify-content:center; color: #71717a; font-size:12px;">Loading\u2026</div>',r.appendChild(l);try{let d=await A({baseURL:a,apikey:i,payload:{name:s,type:"image",id:m}});if(!d?.file_name){l.remove();continue}let p=`https://${n}/brs/get/${i}/${c}/${m}_${d.file_name}`;l.innerHTML=`
1530
+ <div style="height:8rem; background-image:url('${p}'); background-size:cover; background-position:center; cursor:pointer;"></div>
1531
+ <div style="padding:0.375rem 0.5rem; font-size:11px; color:#a1a1aa; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">${d.file_name}</div>
1532
+ `,l.querySelector("div")?.addEventListener("click",()=>{let h=document.createElement("div");h.style.cssText="position:fixed;inset:0;background:rgba(0,0,0,0.9);z-index:9999999;display:flex;align-items:center;justify-content:center;cursor:zoom-out;",h.innerHTML=`<img src="${p}" alt="image" style="max-width:90vw;max-height:90vh;border-radius:8px;object-fit:contain;" />`,h.addEventListener("click",()=>h.remove()),document.body.appendChild(h)})}catch{l.remove()}}}chatQueryForm(){let e=document.createElement("div");e.innerHTML=`
1533
+ <style>
1534
+ .bdb-form-wrap {
1535
+ border-radius: var(--radius-lg);
1536
+ border: 1px solid var(--input);
1537
+ background: var(--card);
1538
+ transition: border-color 0.18s, box-shadow 0.18s;
1539
+ overflow: hidden;
1540
+ }
1541
+
1542
+ .bdb-form-wrap:focus-within {
1543
+ border-color: var(--ring);
1544
+ box-shadow: var(--shadow-input);
1545
+ }
1546
+
1547
+ .bdb-textarea {
1548
+ display: block;
1549
+ width: 100%;
1550
+ resize: none;
1551
+ border: none;
1552
+ outline: none;
1553
+ background: transparent;
1554
+ color: var(--foreground);
1555
+ font-family: var(--font-body);
1556
+ font-size: 14px;
1557
+ line-height: 1.6;
1558
+ padding: 0.875rem 1rem 0;
1559
+ min-height: 44px;
1560
+ max-height: 180px;
1561
+ overflow-y: auto;
1562
+ box-sizing: border-box;
1563
+ scrollbar-width: thin;
1564
+ scrollbar-color: color-mix(in oklab,var(--foreground) 10%,transparent) transparent;
1565
+ }
1566
+
1567
+ .bdb-textarea::placeholder {
1568
+ color: var(--muted-foreground);
1569
+ }
1570
+
1571
+ .bdb-form-footer {
1572
+ display: flex;
1573
+ align-items: center;
1574
+ justify-content: flex-end;
1575
+ padding: 0.4rem 0.625rem 0.625rem;
1576
+ gap: 0.5rem;
1577
+ }
1578
+
1579
+ .bdb-send-btn {
1580
+ display: flex;
1581
+ align-items: center;
1582
+ justify-content: center;
1583
+ width: 32px;
1584
+ height: 32px;
1585
+ border-radius: var(--radius-md);
1586
+ border: none;
1587
+ background: var(--primary);
1588
+ color: var(--primary-foreground);
1589
+ cursor: pointer;
1590
+ transition: background 0.15s, transform 0.12s, opacity 0.15s;
1591
+ flex-shrink: 0;
1592
+ }
1593
+
1594
+ .bdb-send-btn:hover:not(:disabled) {
1595
+ filter: brightness(1.1);
1596
+ transform: scale(1.06);
1597
+ }
1598
+
1599
+ .bdb-send-btn:disabled {
1600
+ opacity: 0.35;
1601
+ cursor: not-allowed;
1602
+ transform: none;
1603
+ }
1604
+ </style>
1605
+
1606
+ <div class="bdb-form-wrap">
1607
+ <textarea
1608
+ class="bdb-textarea"
1609
+ rows="1"
1610
+ placeholder="Ask anything\u2026"
1611
+ aria-label="Chat message"
1612
+ ></textarea>
1613
+ <div class="bdb-form-footer">
1614
+ <button class="bdb-send-btn" disabled aria-label="Send message">
1615
+ <svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-send" aria-hidden="true"><path d="M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z"></path><path d="m21.854 2.147-10.94 10.939"></path></svg>
1616
+ </button>
1617
+ </div>
1618
+ </div>
1619
+ `;let t=e.querySelector(".bdb-textarea"),r=e.querySelector(".bdb-send-btn"),a=()=>{t.style.height="auto",t.style.height=Math.min(t.scrollHeight,180)+"px"};return this.store.subscribe(()=>{let{chatSessions:n,chat:i}=this.store.getState(),s=n[i.activeSession]?.query||"";t.value!==s&&(t.value=s,a(),r.disabled=!s.trim())}),t.addEventListener("input",()=>{a();let n=t.value;r.disabled=!n.trim();let{activeSession:i}=this.store.getState().chat;this.store.dispatch(M({sessionId:i,query:n}))}),t.addEventListener("keydown",async n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),r.disabled||await this.sendQuery())}),r.addEventListener("click",()=>this.sendQuery()),e}async sendQuery(){let{chatSessions:e,chat:t}=this.store.getState(),{activeSession:r,activeIndex:a}=t,{query:n}=e[r],i={query:n,output:[]};this.store.dispatch(M({sessionId:r,query:""})),await this.store.dispatch(G({query:i?.query,sessionId:r,indexName:a,config:this.apiConfig}))}downloadChat(){}};var ae=null;function ne(o){return ae=new C(o),ae}typeof window<"u"&&(window.BangdbChatWidget={init:ne});0&&(module.exports={ChatWidget,init});