@admin-layout/tailwind-chat-pro 12.2.4-alpha.81 → 12.2.4-alpha.82

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/CHANGELOG.md +6 -0
  2. package/lib/components/messages-container-ui/ErrorFixCard.d.ts +10 -0
  3. package/lib/components/messages-container-ui/ErrorFixCard.d.ts.map +1 -0
  4. package/lib/components/messages-container-ui/ErrorFixCard.js +219 -0
  5. package/lib/components/messages-container-ui/ErrorFixCard.js.map +1 -0
  6. package/lib/components/messages-container-ui/FilesList.d.ts +19 -0
  7. package/lib/components/messages-container-ui/FilesList.d.ts.map +1 -0
  8. package/lib/components/messages-container-ui/FilesList.js +75 -0
  9. package/lib/components/messages-container-ui/FilesList.js.map +1 -0
  10. package/lib/components/messages-container-ui/ModernMessageGroup.d.ts +46 -0
  11. package/lib/components/messages-container-ui/ModernMessageGroup.d.ts.map +1 -0
  12. package/lib/components/messages-container-ui/ModernMessageGroup.js +1883 -0
  13. package/lib/components/messages-container-ui/ModernMessageGroup.js.map +1 -0
  14. package/lib/components/messages-container-ui/index.d.ts +3 -0
  15. package/lib/components/messages-container-ui/index.d.ts.map +1 -1
  16. package/lib/components/messages-container-ui/messenger-slot-fill-name-enum.d.ts +14 -0
  17. package/lib/components/messages-container-ui/messenger-slot-fill-name-enum.d.ts.map +1 -0
  18. package/lib/components/messages-container-ui/messenger-slot-fill-name-enum.js +14 -0
  19. package/lib/components/messages-container-ui/messenger-slot-fill-name-enum.js.map +1 -0
  20. package/lib/components/messages-container-ui/modernStreaming.d.ts +11 -0
  21. package/lib/components/messages-container-ui/modernStreaming.d.ts.map +1 -0
  22. package/lib/components/messages-container-ui/modernStreaming.js +17 -0
  23. package/lib/components/messages-container-ui/modernStreaming.js.map +1 -0
  24. package/lib/index.js +1 -1
  25. package/package.json +11 -5
  26. package/src/components/messages-container-ui/ErrorFixCard.tsx +239 -0
  27. package/src/components/messages-container-ui/FilesList.tsx +89 -0
  28. package/src/components/messages-container-ui/ModernMessageGroup.tsx +2224 -0
  29. package/src/components/messages-container-ui/index.ts +10 -0
  30. package/src/components/messages-container-ui/messenger-slot-fill-name-enum.ts +13 -0
  31. package/src/components/messages-container-ui/modernStreaming.tsx +18 -0
@@ -0,0 +1,2224 @@
1
+ import { Slot } from '@common-stack/components-pro';
2
+ import { AiAgentMessageRole, IAuthUser, IPost } from 'common';
3
+ import { differenceInMinutes, format } from 'date-fns';
4
+ import { marked } from 'marked';
5
+ import React, { useEffect, useMemo } from 'react';
6
+ import ReactMarkdown from 'react-markdown';
7
+ import remarkBreaks from 'remark-breaks';
8
+ import remarkGfm from 'remark-gfm';
9
+ import { MessengerSlotFillNameEnum } from './messenger-slot-fill-name-enum';
10
+ import { FilesList } from './FilesList';
11
+ import { ErrorFixCard } from './ErrorFixCard';
12
+
13
+ // Configure marked for better markdown rendering
14
+ marked.setOptions({
15
+ breaks: true, // Convert line breaks to <br>
16
+ gfm: true, // GitHub Flavored Markdown
17
+ headerIds: false, // Disable header IDs for cleaner HTML
18
+ mangle: false, // Don't mangle email addresses
19
+ });
20
+
21
+ const ASSISTANT_RESPONSE_THEME_CLASS = 'llm-response-theme';
22
+ const ASSISTANT_RESPONSE_CLASS = 'llm-response';
23
+ const ASSISTANT_RESPONSE_BUBBLE_CLASS = 'llm-response__bubble';
24
+ const ASSISTANT_RESPONSE_MARKDOWN_CLASS = 'llm-response__markdown';
25
+ const USER_MESSAGE_TEXT_SIZE_CLASS = 'text-base';
26
+ const USER_MESSAGE_PROSE_SIZE_CLASS = 'prose-base';
27
+
28
+ function getAssistantResponseClasses(innerClassName?: string): string {
29
+ return [ASSISTANT_RESPONSE_MARKDOWN_CLASS, innerClassName].filter(Boolean).join(' ');
30
+ }
31
+
32
+ export function AssistantResponseWrapper({
33
+ children,
34
+ bubbleClassName,
35
+ }: {
36
+ children: React.ReactNode;
37
+ bubbleClassName?: string;
38
+ }) {
39
+ return (
40
+ <div className={ASSISTANT_RESPONSE_THEME_CLASS}>
41
+ <div className={ASSISTANT_RESPONSE_CLASS}>
42
+ <div className={[ASSISTANT_RESPONSE_BUBBLE_CLASS, bubbleClassName].filter(Boolean).join(' ')}>
43
+ {children}
44
+ </div>
45
+ </div>
46
+ </div>
47
+ );
48
+ }
49
+
50
+ // Enhanced CSS styles for HTML content rendering with prettification
51
+ const htmlContentStyles = `
52
+ .html-content {
53
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
54
+ line-height: 1.6;
55
+ color: #374151;
56
+ }
57
+
58
+ .html-content h1, .html-content h2, .html-content h3, .html-content h4, .html-content h5, .html-content h6 {
59
+ margin-top: 1.5rem;
60
+ margin-bottom: 1rem;
61
+ font-weight: 600;
62
+ line-height: 1.25;
63
+ color: #111827;
64
+ }
65
+
66
+ .html-content h1 {
67
+ font-size: 1.875rem;
68
+ border-bottom: 2px solid #e5e7eb;
69
+ padding-bottom: 0.5rem;
70
+ }
71
+ .${ASSISTANT_RESPONSE_THEME_CLASS} {
72
+ --llm-content-max-width: 100%;
73
+ --llm-font-sans: 'Avenir Next', 'Segoe UI', sans-serif;
74
+ --llm-font-mono: 'IBM Plex Mono', 'SFMono-Regular', Menlo, Consolas, monospace;
75
+ --llm-color-bg: #ffffff;
76
+ --llm-color-surface: #f6f7f8;
77
+ --llm-color-surface-2: #eef1f4;
78
+ --llm-color-surface-hover: #e9edf2;
79
+ --llm-color-border: #e3e7ee;
80
+ --llm-color-border-strong: #cfd7e3;
81
+ --llm-color-text: #121926;
82
+ --llm-color-text-secondary: #667085;
83
+ --llm-color-marker: #8e98a8;
84
+ --llm-color-link-underline: rgba(18, 25, 38, 0.18);
85
+ --llm-color-code-bg: rgba(249, 115, 22, 0.1);
86
+ --llm-color-code-text: #d96b00;
87
+ --llm-color-code-block-border: #ebeef3;
88
+ --llm-shadow-soft: 0 1px 2px rgba(18, 25, 38, 0.04), 0 10px 32px rgba(18, 25, 38, 0.05);
89
+ --llm-radius-bubble: 1.5rem;
90
+ --llm-radius-code: 0.85rem;
91
+ --llm-line-height-body: 1.62;
92
+ --llm-line-height-mobile: 1.55;
93
+ --llm-line-height-heading: 1.35;
94
+ --llm-space-heading-top: 1.45rem;
95
+ --llm-space-heading-bottom: 0.75rem;
96
+ --llm-space-paragraph: 1rem;
97
+ --llm-space-list: 0.9rem;
98
+ color: var(--llm-color-text);
99
+ background: transparent;
100
+ }
101
+
102
+ .${ASSISTANT_RESPONSE_THEME_CLASS}[data-color-mode='dark'],
103
+ [data-color-mode='dark'] .${ASSISTANT_RESPONSE_THEME_CLASS} {
104
+ --llm-color-bg: #0f1115;
105
+ --llm-color-surface: #171a20;
106
+ --llm-color-surface-2: #1f2530;
107
+ --llm-color-surface-hover: #232a36;
108
+ --llm-color-border: #2a3240;
109
+ --llm-color-border-strong: #364052;
110
+ --llm-color-text: #f3f5f8;
111
+ --llm-color-text-secondary: #aab3c2;
112
+ --llm-color-marker: #7f8999;
113
+ --llm-color-link-underline: rgba(243, 245, 248, 0.24);
114
+ --llm-color-code-bg: rgba(251, 146, 60, 0.14);
115
+ --llm-color-code-text: #ffb36b;
116
+ --llm-color-code-block-border: #262d39;
117
+ --llm-shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.28), 0 14px 36px rgba(0, 0, 0, 0.3);
118
+ }
119
+
120
+ .${ASSISTANT_RESPONSE_CLASS} {
121
+ position: relative;
122
+ display: flex;
123
+ flex-direction: column;
124
+ align-items: flex-start;
125
+ justify-content: center;
126
+ width: 100%;
127
+ max-width: var(--llm-content-max-width);
128
+ font-family: var(--llm-font-sans);
129
+ color: var(--llm-color-text);
130
+ }
131
+
132
+ .${ASSISTANT_RESPONSE_BUBBLE_CLASS} {
133
+ position: relative;
134
+ width: 100%;
135
+ min-height: 1.75rem;
136
+ border-radius: var(--llm-radius-bubble);
137
+ color: inherit;
138
+ word-break: break-word;
139
+ }
140
+
141
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} {
142
+ position: relative;
143
+ width: 100%;
144
+ max-width: none;
145
+ color: inherit;
146
+ font-size: 1rem;
147
+ line-height: var(--llm-line-height-body);
148
+ }
149
+
150
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} > :first-child {
151
+ margin-top: 0;
152
+ }
153
+
154
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} > :last-child {
155
+ margin-bottom: 0;
156
+ }
157
+
158
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} p,
159
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} li,
160
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} th,
161
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} td,
162
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} blockquote,
163
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS}.html-content,
164
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS}.assistant-html-content {
165
+ color: inherit;
166
+ }
167
+
168
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} p,
169
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS}.html-content p,
170
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS}.assistant-html-content p {
171
+ margin: 0 0 var(--llm-space-paragraph);
172
+ white-space: pre-wrap;
173
+ }
174
+
175
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} h1,
176
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} h2,
177
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} h3,
178
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} h4,
179
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} h5,
180
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} h6 {
181
+ margin: var(--llm-space-heading-top) 0 var(--llm-space-heading-bottom);
182
+ font-weight: 600;
183
+ letter-spacing: -0.02em;
184
+ line-height: var(--llm-line-height-heading);
185
+ color: var(--llm-color-text);
186
+ }
187
+
188
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} h1 { font-size: 1.75rem; }
189
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} h2 { font-size: 1.5rem; }
190
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} h3 { font-size: 1.25rem; }
191
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} h4 { font-size: 1.05rem; }
192
+
193
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} strong,
194
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} b {
195
+ font-weight: 600;
196
+ color: var(--llm-color-text);
197
+ }
198
+
199
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} em,
200
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} i {
201
+ color: var(--llm-color-text-secondary);
202
+ }
203
+
204
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} a {
205
+ color: currentColor;
206
+ text-decoration: underline;
207
+ text-decoration-color: var(--llm-color-link-underline);
208
+ text-underline-offset: 0.18em;
209
+ transition: color 120ms ease, text-decoration-color 120ms ease;
210
+ }
211
+
212
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} a:hover {
213
+ color: var(--llm-color-text);
214
+ text-decoration-color: currentColor;
215
+ }
216
+
217
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} ul,
218
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} ol {
219
+ margin: 0.35rem 0 var(--llm-space-list);
220
+ padding-left: 1.15rem;
221
+ }
222
+
223
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} ul {
224
+ list-style-type: disc;
225
+ }
226
+
227
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} ol {
228
+ list-style-type: decimal;
229
+ /* Wider gutter so multi-digit markers (e.g. "60.") aren't clipped at the
230
+ content's left edge — long numbered content (verse, step lists) showed
231
+ "0." for line 60. */
232
+ padding-left: 2rem;
233
+ }
234
+
235
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} li {
236
+ margin: 0.28rem 0;
237
+ padding-inline-start: 0.1rem;
238
+ /* \`normal\` collapses the stray "\\n" react-markdown inserts between <li>
239
+ and its child <p>; with \`pre-wrap\` that newline rendered as a blank
240
+ first line, stranding the marker above its text. Intra-paragraph
241
+ whitespace is preserved by the \`li > p\` rule below. */
242
+ white-space: normal;
243
+ }
244
+
245
+ /* Loose list items wrap their text in <p>. Keep pre-wrap for the text but
246
+ drop the paragraph margins so each item is a single tight line — fixes
247
+ poems / verse the model emits as numbered lists rendering as a sprawling,
248
+ double-spaced listicle. */
249
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} li > p {
250
+ margin-top: 0;
251
+ white-space: pre-wrap;
252
+ }
253
+
254
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} li > p:last-child {
255
+ margin-bottom: 0;
256
+ }
257
+
258
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} li > ul,
259
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} li > ol {
260
+ margin-top: 0.35rem;
261
+ margin-bottom: 0.15rem;
262
+ white-space: normal;
263
+ }
264
+
265
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} ::marker {
266
+ color: var(--llm-color-marker);
267
+ }
268
+
269
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} hr {
270
+ margin: 1.25rem 0;
271
+ border: 0;
272
+ border-top: 1px solid var(--llm-color-border);
273
+ }
274
+
275
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} blockquote {
276
+ margin: 1rem 0;
277
+ padding: 0.2rem 0 0.2rem 1rem;
278
+ border-left: 2px solid var(--llm-color-border-strong);
279
+ background: transparent;
280
+ color: var(--llm-color-text-secondary);
281
+ }
282
+
283
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} blockquote p {
284
+ margin-bottom: 0;
285
+ color: inherit;
286
+ }
287
+
288
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} :not(pre) > code,
289
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} .llm-inline-code {
290
+ display: inline-block;
291
+ padding: 0.08rem 0.38rem;
292
+ border: 0;
293
+ border-radius: 0.32rem;
294
+ font-family: var(--llm-font-mono);
295
+ font-size: 0.875em;
296
+ line-height: 1.45;
297
+ background: var(--llm-color-code-bg);
298
+ color: var(--llm-color-code-text);
299
+ box-decoration-break: clone;
300
+ -webkit-box-decoration-break: clone;
301
+ }
302
+
303
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} table {
304
+ width: 100%;
305
+ margin: 1rem 0 1.1rem;
306
+ border-collapse: separate;
307
+ border-spacing: 0;
308
+ border: 1px solid var(--llm-color-border);
309
+ border-radius: 1rem;
310
+ overflow: hidden;
311
+ box-shadow: var(--llm-shadow-soft);
312
+ }
313
+
314
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} thead {
315
+ background: var(--llm-color-surface);
316
+ }
317
+
318
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} th,
319
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} td {
320
+ padding: 0.85rem 1rem;
321
+ border-bottom: 1px solid var(--llm-color-border);
322
+ text-align: left;
323
+ vertical-align: top;
324
+ }
325
+
326
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} th {
327
+ font-size: 0.8rem;
328
+ font-weight: 600;
329
+ letter-spacing: 0.02em;
330
+ color: var(--llm-color-text-secondary);
331
+ background: var(--llm-color-surface);
332
+ }
333
+
334
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} td {
335
+ color: var(--llm-color-text);
336
+ background: var(--llm-color-bg);
337
+ }
338
+
339
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} tbody tr:last-child td {
340
+ border-bottom: 0;
341
+ }
342
+
343
+ @media (max-width: 768px) {
344
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} {
345
+ font-size: 0.95rem;
346
+ line-height: var(--llm-line-height-mobile);
347
+ }
348
+
349
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} th,
350
+ .${ASSISTANT_RESPONSE_MARKDOWN_CLASS} td {
351
+ padding: 0.75rem 0.8rem;
352
+ }
353
+ }
354
+ * we must neutralize it so it doesn't override the pill background/padding.
355
+ */
356
+ .user-message .message-container {
357
+ background: transparent !important;
358
+ padding-top: 0 !important;
359
+ padding-bottom: 0 !important;
360
+ margin: 0 !important;
361
+ transition: none !important;
362
+ box-shadow: none !important;
363
+ }
364
+
365
+ .assistant-message-container {
366
+ background: transparent;
367
+ padding-top: 0;
368
+ padding-bottom: 0;
369
+ margin: 0;
370
+ transition: none;
371
+ box-shadow: none;
372
+ }
373
+
374
+ .assistant-html-content {
375
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
376
+ line-height: 1.6;
377
+ color: #374151;
378
+ }
379
+
380
+ .assistant-html-content h1,
381
+ .assistant-html-content h2,
382
+ .assistant-html-content h3,
383
+ .assistant-html-content h4,
384
+ .assistant-html-content h5,
385
+ .assistant-html-content h6 {
386
+ font-weight: 600;
387
+ line-height: 1.25;
388
+ color: #111827;
389
+ }
390
+
391
+ .assistant-html-content h1 {
392
+ font-size: 1.875rem;
393
+ margin-top: 2rem;
394
+ margin-bottom: 1rem;
395
+ }
396
+
397
+ .assistant-html-content h2 {
398
+ font-size: 1.5rem;
399
+ margin-top: 2rem;
400
+ margin-bottom: 1rem;
401
+ }
402
+
403
+ .assistant-html-content h3 {
404
+ font-size: 1.25rem;
405
+ margin-top: 1.5rem;
406
+ margin-bottom: 1rem;
407
+ }
408
+
409
+ .assistant-html-content h4 {
410
+ font-size: 1.125rem;
411
+ margin-top: 1rem;
412
+ margin-bottom: 0.5rem;
413
+ }
414
+
415
+ .assistant-html-content p {
416
+ margin-top: 0;
417
+ margin-bottom: 1rem;
418
+ line-height: 1.625;
419
+ color: #374151;
420
+ }
421
+
422
+ .assistant-html-content ul,
423
+ .assistant-html-content ol {
424
+ margin: 1rem 0;
425
+ padding-left: 1.25rem;
426
+ }
427
+
428
+ .assistant-html-content ul {
429
+ list-style-type: disc;
430
+ }
431
+
432
+ .assistant-html-content ol {
433
+ list-style-type: decimal;
434
+ }
435
+
436
+ .assistant-html-content li {
437
+ margin-bottom: 0.375rem;
438
+ line-height: 1.625;
439
+ color: #374151;
440
+ }
441
+
442
+ .assistant-html-content li > ul,
443
+ .assistant-html-content li > ol {
444
+ margin-top: 0.375rem;
445
+ margin-bottom: 0.375rem;
446
+ }
447
+
448
+ .assistant-html-content a {
449
+ color: #2563eb;
450
+ text-decoration: none;
451
+ }
452
+
453
+ .assistant-html-content a:hover {
454
+ color: #1d4ed8;
455
+ text-decoration: underline;
456
+ text-underline-offset: 2px;
457
+ }
458
+
459
+ .assistant-html-content strong,
460
+ .assistant-html-content b {
461
+ font-weight: 600;
462
+ color: #111827;
463
+ }
464
+
465
+ .assistant-html-content em,
466
+ .assistant-html-content i {
467
+ font-style: italic;
468
+ color: #4b5563;
469
+ }
470
+
471
+ .assistant-html-content code {
472
+ background-color: #f3f4f6;
473
+ padding: 0.25rem 0.5rem;
474
+ border-radius: 0.375rem;
475
+ font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
476
+ font-size: 0.875rem;
477
+ color: #dc2626;
478
+ border: 1px solid #e5e7eb;
479
+ }
480
+
481
+ .assistant-html-content pre {
482
+ background-color: #f9fafb;
483
+ padding: 1rem;
484
+ border-radius: 0.5rem;
485
+ overflow-x: auto;
486
+ font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
487
+ font-size: 0.875rem;
488
+ line-height: 1.5;
489
+ border: 1px solid #e5e7eb;
490
+ margin: 1.5rem 0;
491
+ }
492
+
493
+ .assistant-html-content pre code {
494
+ background-color: transparent;
495
+ padding: 0;
496
+ border: none;
497
+ color: #374151;
498
+ font-size: inherit;
499
+ }
500
+
501
+ .assistant-html-content blockquote {
502
+ margin: 1.5rem 0;
503
+ padding: 0 0 0 1rem;
504
+ border-left: 4px solid #d1d5db;
505
+ font-style: italic;
506
+ color: #6b7280;
507
+ background-color: transparent;
508
+ border-radius: 0;
509
+ }
510
+
511
+ .assistant-html-content blockquote p {
512
+ margin-bottom: 0;
513
+ }
514
+
515
+ .assistant-html-content table {
516
+ border-collapse: collapse;
517
+ border: 1px solid #e5e7eb;
518
+ width: 100%;
519
+ margin: 1rem 0;
520
+ }
521
+
522
+ .assistant-html-content th,
523
+ .assistant-html-content td {
524
+ text-align: left;
525
+ vertical-align: top;
526
+ }
527
+
528
+ .assistant-html-content th {
529
+ padding: 0.5rem 1rem;
530
+ background-color: #f9fafb;
531
+ border: 1px solid #e5e7eb;
532
+ font-weight: 500;
533
+ font-size: 0.75rem;
534
+ letter-spacing: 0.04em;
535
+ text-transform: uppercase;
536
+ color: #4b5563;
537
+ }
538
+
539
+ .assistant-html-content td {
540
+ padding: 0.5rem 1rem;
541
+ border-top: 1px solid #e5e7eb;
542
+ color: #374151;
543
+ }
544
+
545
+ .assistant-html-content hr {
546
+ border: none;
547
+ border-top: 1px solid #e5e7eb;
548
+ margin: 2rem 0;
549
+ }
550
+
551
+ /* Markdown content styling */
552
+ .markdown-content {
553
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
554
+ line-height: 1.6;
555
+ color: #374151;
556
+ }
557
+
558
+ .markdown-content h1 {
559
+ font-size: 1.5rem;
560
+ font-weight: 700;
561
+ margin-top: 1.5rem;
562
+ margin-bottom: 1rem;
563
+ color: #111827;
564
+ padding-bottom: 0.5rem;
565
+ border-bottom: 2px solid #e5e7eb;
566
+ }
567
+
568
+ .markdown-content h2 {
569
+ font-size: 1.25rem;
570
+ font-weight: 600;
571
+ margin-top: 1.25rem;
572
+ margin-bottom: 0.75rem;
573
+ color: #1f2937;
574
+ padding-bottom: 0.375rem;
575
+ border-bottom: 1px solid #e5e7eb;
576
+ }
577
+
578
+ .markdown-content h3 {
579
+ font-size: 1.125rem;
580
+ font-weight: 600;
581
+ margin-top: 1rem;
582
+ margin-bottom: 0.5rem;
583
+ color: #374151;
584
+ }
585
+
586
+ .markdown-content p {
587
+ margin-bottom: 0.75rem;
588
+ line-height: 1.6;
589
+ color: #4b5563;
590
+ }
591
+
592
+ .markdown-content ul, .markdown-content ol {
593
+ margin: 1rem 0;
594
+ padding-left: 1.5rem;
595
+ }
596
+
597
+ .markdown-content li {
598
+ margin-bottom: 0.5rem;
599
+ line-height: 1.6;
600
+ }
601
+
602
+ .markdown-content code {
603
+ background-color: #f3f4f6;
604
+ padding: 0.125rem 0.375rem;
605
+ border-radius: 0.25rem;
606
+ font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
607
+ font-size: 0.875rem;
608
+ color: #dc2626;
609
+ border: 1px solid #e5e7eb;
610
+ }
611
+
612
+ .markdown-content pre {
613
+ color: #1f2937;
614
+ border-radius: 8px;
615
+ overflow-x: auto;
616
+ font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
617
+ font-size: 0.875rem;
618
+ line-height: 1.5;
619
+ margin: 1rem 0;
620
+ }
621
+
622
+ .markdown-content pre code {
623
+ background-color: transparent;
624
+ padding: 0;
625
+ border: none;
626
+ color: #1f2937;
627
+ font-size: inherit;
628
+ }
629
+
630
+ .markdown-content blockquote {
631
+ border-left: 4px solid #3b82f6;
632
+ background-color: #f8fafc;
633
+ padding: 1rem;
634
+ margin: 1rem 0;
635
+ border-radius: 6px;
636
+ font-style: italic;
637
+ color: #475569;
638
+ border-top: 1px solid #e5e7eb;
639
+ border-right: 1px solid #e5e7eb;
640
+ border-bottom: 1px solid #e5e7eb;
641
+ }
642
+
643
+ .markdown-content table {
644
+ border-collapse: collapse;
645
+ border: 1px solid #e5e7eb;
646
+ width: 100%;
647
+ margin: 1rem 0;
648
+ border-radius: 8px;
649
+ overflow: hidden;
650
+ box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
651
+ }
652
+
653
+ .markdown-content th {
654
+ background-color: #f9fafb;
655
+ color: #374151;
656
+ font-weight: 600;
657
+ padding: 0.75rem;
658
+ text-align: left;
659
+ border-bottom: 1px solid #e5e7eb;
660
+ font-size: 0.875rem;
661
+ }
662
+
663
+ .markdown-content td {
664
+ border: 1px solid #e5e7eb;
665
+ padding: 0.75rem;
666
+ text-align: left;
667
+ vertical-align: top;
668
+ background-color: white;
669
+ font-size: 0.875rem;
670
+ }
671
+
672
+ .markdown-content tr:nth-child(even) td {
673
+ background-color: #f9fafb;
674
+ }
675
+
676
+ .markdown-content tr:hover td {
677
+ background-color: #f3f4f6;
678
+ }
679
+
680
+ /* Enhanced list styling */
681
+ .markdown-content ul li {
682
+ position: relative;
683
+ padding-left: 0.5rem;
684
+ }
685
+
686
+ .markdown-content ul li::before {
687
+ content: "•";
688
+ color: #000;
689
+ font-weight: bold;
690
+ position: absolute;
691
+ left: -1rem;
692
+ }
693
+
694
+ .markdown-content ol li {
695
+ position: relative;
696
+ padding-left: 0.5rem;
697
+ }
698
+
699
+ .markdown-content ol li::before {
700
+ content: counter(list-item) ".";
701
+ font-weight: 600;
702
+ position: absolute;
703
+ left: -1.5rem;
704
+ }
705
+
706
+ /* Code block container styling */
707
+ .code-block-container {
708
+ background: #ffffff;
709
+ border: 1px solid #e5e7eb;
710
+ border-radius: 8px;
711
+ overflow: hidden;
712
+ margin: 1rem 0;
713
+ box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
714
+ }
715
+
716
+ .code-block-header {
717
+ background: #f9fafb;
718
+ padding: 0.5rem 1rem;
719
+ border-bottom: 1px solid #e5e7eb;
720
+ font-weight: 600;
721
+ color: #374151;
722
+ font-size: 0.875rem;
723
+ text-transform: uppercase;
724
+ letter-spacing: 0.05em;
725
+ }
726
+
727
+ .code-block-content {
728
+ padding: 1rem;
729
+ overflow-x: auto;
730
+ }
731
+
732
+ /* Enhanced prose styling for markdown content */
733
+ .prose pre {
734
+ background-color: #f9fafb;
735
+ border: 1px solid #e5e7eb;
736
+ border-radius: 0.5rem;
737
+ padding: 1rem;
738
+ overflow-x: auto;
739
+ }
740
+
741
+ .prose code {
742
+ background-color: #f3f4f6;
743
+ padding: 0.125rem 0.375rem;
744
+ border-radius: 0.25rem;
745
+ font-size: 0.875rem;
746
+ border: 1px solid #e5e7eb;
747
+ }
748
+
749
+ .prose pre code {
750
+ background-color: transparent;
751
+ padding: 0;
752
+ border: none;
753
+ color:#000;
754
+ }
755
+
756
+ .hover\:bg-gray-100:hover {
757
+ background-color: transparent !important;
758
+ }
759
+ `;
760
+
761
+ // Hook to inject CSS styles
762
+ const useInjectStyles = () => {
763
+ useEffect(() => {
764
+ const styleElementPresent = !!document.getElementById('html-content-styles');
765
+
766
+ // Check if styles are already injected
767
+ if (styleElementPresent) {
768
+ return;
769
+ }
770
+
771
+ // Create and inject style element
772
+ const styleElement = document.createElement('style');
773
+ styleElement.id = 'html-content-styles';
774
+ styleElement.textContent = htmlContentStyles;
775
+ document.head.appendChild(styleElement);
776
+
777
+ // Cleanup function
778
+ return () => {
779
+ const existingStyle = document.getElementById('html-content-styles');
780
+ if (existingStyle) {
781
+ existingStyle.remove();
782
+ }
783
+ };
784
+ }, []);
785
+ };
786
+
787
+ interface ModernMessageGroupProps {
788
+ showAuthorName?: boolean;
789
+ showAvatar?: boolean;
790
+ showTimestamp?: boolean;
791
+ messages: IPost[];
792
+ currentUser: IAuthUser;
793
+ onOpen: (element?: any) => void;
794
+ onMessageClick: (msg: IPost) => void;
795
+ isDesktopView?: boolean;
796
+ isSmallScreen?: boolean;
797
+ sandboxErrors?: any[];
798
+ currentFiles?: Record<string, string>;
799
+ onFixError?: (errorMessage: string) => Promise<void>;
800
+ onRecreateSandbox?: (fragmentId: string) => void;
801
+ /** When true, code blocks show copy and download actions in header and footer (default: true) */
802
+ showCopyDownloadOnCodeBlock?: boolean;
803
+ }
804
+
805
+ interface MessageGroupProps {
806
+ showAuthorName?: boolean;
807
+ showAvatar?: boolean;
808
+ showTimestamp?: boolean;
809
+ author: any;
810
+ messages: IPost[];
811
+ currentUser: IAuthUser;
812
+ onOpen: (element?: any) => void;
813
+ onMessageClick: (msg: IPost) => void;
814
+ isDesktopView?: boolean;
815
+ isSmallScreen?: boolean;
816
+ showCopyDownloadOnCodeBlock?: boolean;
817
+ }
818
+
819
+ // Enhanced utility function to group messages by user and time
820
+ export const groupMessagesByUserAndTime = (messages: IPost[], timeThresholdMinutes = 5): IPost[][] => {
821
+ if (!messages || messages.length === 0) return [];
822
+
823
+ const groups: IPost[][] = [];
824
+ let currentGroup: IPost[] = [];
825
+ let lastMessage: IPost | null = null;
826
+
827
+ for (const message of messages) {
828
+ if (typeof message === 'string') continue; // Skip date separators
829
+
830
+ const shouldStartNewGroup =
831
+ !lastMessage ||
832
+ lastMessage.author?.id !== message.author?.id ||
833
+ differenceInMinutes(new Date(message.createdAt), new Date(lastMessage.createdAt)) > timeThresholdMinutes;
834
+
835
+ if (shouldStartNewGroup) {
836
+ if (currentGroup.length > 0) {
837
+ groups.push(currentGroup);
838
+ }
839
+ currentGroup = [message];
840
+ } else {
841
+ currentGroup.push(message);
842
+ }
843
+
844
+ lastMessage = message;
845
+ }
846
+
847
+ if (currentGroup.length > 0) {
848
+ groups.push(currentGroup);
849
+ }
850
+
851
+ return groups;
852
+ };
853
+
854
+ // Enhanced content detection that properly identifies different content types
855
+ export const detectContentType = (value: string): 'html' | 'markdown' | 'code' | 'text' => {
856
+ if (!value) return 'text';
857
+
858
+ const trimmed = value.trim();
859
+
860
+ // Check for markdown patterns FIRST (before code, as markdown can contain code blocks)
861
+ const markdownPatterns = [
862
+ /^#{1,6}\s+.+$/gm, // Headers (must have text after #)
863
+ /^\s*[-*+]\s+.+$/gm, // Unordered lists
864
+ /^\s*\d+\.\s+.+$/gm, // Numbered lists
865
+ /\[.+?\]\(.+?\)/g, // Links
866
+ /!\[.+?\]\(.+?\)/g, // Images
867
+ /```[\s\S]*?```/g, // Fenced code blocks (markdown feature)
868
+ /^\s*>\s+/gm, // Blockquotes
869
+ /\*\*.*?\*\*/g, // Bold
870
+ /\*[^*].*?\*/g, // Italic (not just asterisks)
871
+ /^\s*\|.+\|/gm, // Tables
872
+ ];
873
+
874
+ // Count markdown patterns - if we have multiple, it's likely markdown
875
+ const markdownMatches = markdownPatterns.filter((pattern) => {
876
+ const matches = trimmed.match(pattern);
877
+ return matches && matches.length > 0;
878
+ }).length;
879
+
880
+ // If we have 2+ markdown patterns, it's definitely markdown
881
+ if (markdownMatches >= 2) return 'markdown';
882
+
883
+ // If we have headers or lists, it's likely markdown
884
+ if (/^#{1,6}\s+/gm.test(trimmed) || /^\s*[-*+]\s+/gm.test(trimmed) || /^\s*\d+\.\s+/gm.test(trimmed)) {
885
+ return 'markdown';
886
+ }
887
+
888
+ // Check for pure code patterns (without markdown context)
889
+ const pureCodePatterns = [
890
+ /^---\s*\w+\.\w+\s*---$/gm, // File separators (standalone)
891
+ /^@tailwind\s+\w+/gm, // Tailwind directives at start
892
+ /^export\s+default\s*\{/gm, // JS/TS exports at start
893
+ /^import\s+.*\s+from\s+['"]/gm, // Import statements at start
894
+ ];
895
+
896
+ const hasPureCodePatterns = pureCodePatterns.some((pattern) => pattern.test(trimmed));
897
+ if (hasPureCodePatterns && markdownMatches === 0) return 'code';
898
+
899
+ // Check for HTML patterns
900
+ const htmlPatterns = [
901
+ /<[a-z][\s\S]*?>/i, // HTML tags
902
+ /&[a-z0-9#]+;/i, // HTML entities
903
+ /<[^>]+>[^<]*<\/[^>]+>/i, // HTML structure
904
+ ];
905
+
906
+ const hasHtmlPatterns = htmlPatterns.some((pattern) => pattern.test(trimmed));
907
+ // Only return HTML if it's clearly HTML and not markdown
908
+ if (hasHtmlPatterns && markdownMatches === 0) return 'html';
909
+
910
+ // Default to text, but FormattedMessageContent will still try to parse as markdown
911
+ return 'text';
912
+ };
913
+
914
+ // Legacy function for backward compatibility
915
+ const isProbablyHTML = (value: string): boolean => {
916
+ return detectContentType(value) === 'html';
917
+ };
918
+
919
+ /** Map message type (THINKING, TOOLUSE, etc.) to slot fill name for Kimi-like streaming UI */
920
+ const getMessageSlotName = (type: string | undefined): string | null => {
921
+ if (!type) return null;
922
+ const t = String(type).toUpperCase();
923
+ if (t === 'THINKING') return MessengerSlotFillNameEnum.THINKING_NAME;
924
+ if (t === 'TOOLUSE') return MessengerSlotFillNameEnum.TOOLUSE_NAME;
925
+ if (t === 'CODEBLOCK') return MessengerSlotFillNameEnum.CODEBLOCK_NAME;
926
+ if (t === 'SERVICE') return MessengerSlotFillNameEnum.SERVICE_NAME;
927
+ if (t === 'AIASSISTANT' || t === 'ASSISTANT') return MessengerSlotFillNameEnum.AIASSISTANT_NAME;
928
+ if (t === 'TRAVEL') return MessengerSlotFillNameEnum.TRAVEL_NAME;
929
+ if (t === 'MEDIA') return MessengerSlotFillNameEnum.MEDIA_NAME;
930
+ if (t === 'WORKFLOW') return MessengerSlotFillNameEnum.WORKFLOW_NAME;
931
+ return null;
932
+ };
933
+
934
+ // Enhanced sanitizer that allows most HTML tags while maintaining security
935
+ const sanitizeHtml = (html: string): string => {
936
+ try {
937
+ if (typeof window === 'undefined' || typeof window.DOMParser === 'undefined') {
938
+ return html
939
+ .replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi, '')
940
+ .replace(/<style[\s\S]*?>[\s\S]*?<\/style>/gi, '')
941
+ .replace(/on\w+\s*=\s*"[^"]*"/gi, '')
942
+ .replace(/on\w+\s*=\s*'[^']*'/gi, '')
943
+ .replace(/on\w+\s*=\s*[^\s>]+/gi, '')
944
+ .replace(/javascript:/gi, '')
945
+ .replace(/data:text\/html/gi, '');
946
+ }
947
+
948
+ const parser = new window.DOMParser();
949
+ const doc = parser.parseFromString(html, 'text/html');
950
+
951
+ // Only remove the most dangerous tags
952
+ const dangerousTags = ['script', 'style'];
953
+ dangerousTags.forEach((tag) => {
954
+ doc.querySelectorAll(tag).forEach((el) => el.remove());
955
+ });
956
+
957
+ const walker = doc.createTreeWalker(doc.body, (NodeFilter as any).SHOW_ELEMENT);
958
+ let node = walker.nextNode() as Element | null;
959
+ while (node) {
960
+ Array.from(node.attributes).forEach((attr) => {
961
+ const name = attr.name.toLowerCase();
962
+ const value = (attr.value || '').toLowerCase();
963
+
964
+ // Remove event handlers and javascript protocols
965
+ if (name.startsWith('on') || value.startsWith('javascript:')) {
966
+ node?.removeAttribute(attr.name);
967
+ }
968
+
969
+ // Allow most attributes but validate URLs for src/href
970
+ if ((name === 'src' || name === 'href') && !/^https?:|^\/.*/.test(attr.value)) {
971
+ node?.removeAttribute(attr.name);
972
+ }
973
+ });
974
+ node = walker.nextNode() as Element | null;
975
+ }
976
+
977
+ return doc.body.innerHTML;
978
+ } catch (e) {
979
+ return html.replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi, '');
980
+ }
981
+ };
982
+
983
+ // Function to prettify HTML content
984
+ const prettifyHtmlContent = (htmlContent: string): string => {
985
+ // Add semantic classes for better styling
986
+ let prettified = htmlContent;
987
+
988
+ // Enhance headings with better styling
989
+ prettified = prettified.replace(/<h([1-6])>/g, '<h$1 class="html-heading html-heading-$1">');
990
+
991
+ // Enhance lists with better styling
992
+ prettified = prettified.replace(/<ul>/g, '<ul class="html-list html-list-unordered">');
993
+ prettified = prettified.replace(/<ol>/g, '<ol class="html-list html-list-ordered">');
994
+
995
+ // Enhance paragraphs with better spacing
996
+ prettified = prettified.replace(/<p>/g, '<p class="html-paragraph">');
997
+
998
+ // Enhance code blocks
999
+ prettified = prettified.replace(/<code>/g, '<code class="html-inline-code">');
1000
+ prettified = prettified.replace(/<pre>/g, '<pre class="html-code-block">');
1001
+
1002
+ // Enhance blockquotes
1003
+ prettified = prettified.replace(/<blockquote>/g, '<blockquote class="html-blockquote">');
1004
+
1005
+ // Enhance tables
1006
+ prettified = prettified.replace(/<table>/g, '<table class="html-table">');
1007
+ prettified = prettified.replace(/<th>/g, '<th class="html-table-header">');
1008
+ prettified = prettified.replace(/<td>/g, '<td class="html-table-cell">');
1009
+
1010
+ // Add info boxes for certain content patterns
1011
+ prettified = prettified.replace(
1012
+ /<p>(Note|Tip|Info|Warning|Error):\s*(.*?)<\/p>/gi,
1013
+ '<div class="html-info-box"><strong>$1:</strong> $2</div>',
1014
+ );
1015
+
1016
+ return prettified;
1017
+ };
1018
+
1019
+ // Minimal Builder-like blocks renderer (text/image/button/columns)
1020
+ const BuilderLikeRenderer: React.FC<{ blocks?: any[] }> = ({ blocks }) => {
1021
+ if (!blocks || !Array.isArray(blocks) || blocks.length === 0) return null;
1022
+
1023
+ return (
1024
+ <div className="space-y-3">
1025
+ {blocks.map((block, idx) => {
1026
+ const type = block?.['@type'] || block?.type;
1027
+ if (!type) return null;
1028
+
1029
+ if (/text/i.test(type)) {
1030
+ const html = sanitizeHtml(block?.text || block?.data?.text || '');
1031
+ return (
1032
+ <div
1033
+ key={idx}
1034
+ className="max-w-none text-gray-800"
1035
+ dangerouslySetInnerHTML={{ __html: html }}
1036
+ />
1037
+ );
1038
+ }
1039
+
1040
+ if (/image/i.test(type)) {
1041
+ const src = block?.src || block?.image || block?.data?.src;
1042
+ const alt = block?.alt || block?.data?.alt || '';
1043
+ if (!src) return null;
1044
+ return (
1045
+ <div key={idx} className="rounded-lg overflow-hidden border border-gray-200">
1046
+ <img className="w-full h-auto" src={src} alt={alt} />
1047
+ </div>
1048
+ );
1049
+ }
1050
+
1051
+ if (/button/i.test(type)) {
1052
+ const text = block?.text || block?.data?.text || 'Button';
1053
+ const href = block?.href || block?.link || block?.data?.href || '#';
1054
+ return (
1055
+ <a
1056
+ key={idx}
1057
+ href={href}
1058
+ target="_blank"
1059
+ rel="noopener noreferrer"
1060
+ className="inline-flex items-center px-3 py-1.5 rounded-md bg-blue-600 text-white text-sm hover:bg-blue-700"
1061
+ >
1062
+ {text}
1063
+ </a>
1064
+ );
1065
+ }
1066
+
1067
+ if (/columns?/i.test(type)) {
1068
+ const cols = block?.columns || block?.data?.columns || [];
1069
+ return (
1070
+ <div key={idx} className="grid grid-cols-1 sm:grid-cols-2 gap-3">
1071
+ {cols.map((col: any, colIdx: number) => (
1072
+ <div key={colIdx} className="space-y-2">
1073
+ <BuilderLikeRenderer blocks={col?.blocks || col?.children} />
1074
+ </div>
1075
+ ))}
1076
+ </div>
1077
+ );
1078
+ }
1079
+
1080
+ return (
1081
+ <div key={idx} className="message-container">
1082
+ <pre className="text-xs text-gray-600 overflow-x-auto">{JSON.stringify(block, null, 2)}</pre>
1083
+ </div>
1084
+ );
1085
+ })}
1086
+ </div>
1087
+ );
1088
+ };
1089
+
1090
+ // Code block with optional header (language + copy) and footer (copy + download) per Image 2
1091
+ const CodeBlockWithActions: React.FC<{
1092
+ content: string;
1093
+ language?: string;
1094
+ showCopyDownload?: boolean;
1095
+ }> = ({ content, language, showCopyDownload = true }) => {
1096
+ const [copied, setCopied] = React.useState(false);
1097
+
1098
+ const handleCopy = React.useCallback(() => {
1099
+ navigator.clipboard.writeText(content).then(() => {
1100
+ setCopied(true);
1101
+ setTimeout(() => setCopied(false), 2000);
1102
+ });
1103
+ }, [content]);
1104
+
1105
+ const handleDownload = React.useCallback(() => {
1106
+ const ext =
1107
+ language === 'jsx' || language === 'tsx' ? '.tsx' : language === 'js' || language === 'ts' ? '.ts' : '.txt';
1108
+ const blob = new Blob([content], { type: 'text/plain' });
1109
+ const url = URL.createObjectURL(blob);
1110
+ const a = document.createElement('a');
1111
+ a.href = url;
1112
+ a.download = `snippet${ext}`;
1113
+ a.click();
1114
+ URL.revokeObjectURL(url);
1115
+ }, [content, language]);
1116
+
1117
+ const langLabel = (language || 'code').toUpperCase();
1118
+
1119
+ /**
1120
+ * Duplicate / copy: back square offset top-left (only its top-left shows behind),
1121
+ * front square on top toward bottom-right — matches typical “two sheets” reference art.
1122
+ */
1123
+ const IconCopy = ({ className }: { className?: string }) => (
1124
+ <svg className={className} viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden>
1125
+ <rect
1126
+ x="3.25"
1127
+ y="3.25"
1128
+ width="10.5"
1129
+ height="10.5"
1130
+ rx="2.25"
1131
+ ry="2.25"
1132
+ stroke="currentColor"
1133
+ strokeWidth="1.5"
1134
+ strokeLinecap="round"
1135
+ strokeLinejoin="round"
1136
+ />
1137
+ <rect
1138
+ x="8.75"
1139
+ y="8.75"
1140
+ width="10.5"
1141
+ height="10.5"
1142
+ rx="2.25"
1143
+ ry="2.25"
1144
+ stroke="currentColor"
1145
+ strokeWidth="1.5"
1146
+ strokeLinecap="round"
1147
+ strokeLinejoin="round"
1148
+ />
1149
+ </svg>
1150
+ );
1151
+
1152
+ /** Arrow into tray (download) */
1153
+ const IconDownload = ({ className }: { className?: string }) => (
1154
+ <svg
1155
+ className={className}
1156
+ viewBox="0 0 24 24"
1157
+ fill="none"
1158
+ stroke="currentColor"
1159
+ strokeWidth={1.5}
1160
+ strokeLinecap="round"
1161
+ strokeLinejoin="round"
1162
+ aria-hidden
1163
+ >
1164
+ <path d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3" />
1165
+ </svg>
1166
+ );
1167
+
1168
+ const IconCheck = ({ className }: { className?: string }) => (
1169
+ <svg
1170
+ className={className}
1171
+ viewBox="0 0 24 24"
1172
+ fill="none"
1173
+ stroke="currentColor"
1174
+ strokeWidth={1.75}
1175
+ strokeLinecap="round"
1176
+ strokeLinejoin="round"
1177
+ aria-hidden
1178
+ >
1179
+ <path d="M5 13l4 4L19 7" />
1180
+ </svg>
1181
+ );
1182
+
1183
+ const iconMuted = 'text-slate-500 hover:text-slate-600';
1184
+
1185
+ return (
1186
+ <div className="rounded-xl bg-white overflow-hidden my-3 shadow-sm ring-1 ring-slate-200/60">
1187
+ {/* Header: label + copy — padding aligned with inner code gutter (image 3) */}
1188
+ <div className="flex items-center justify-between px-4 pt-4 pb-3 bg-white">
1189
+ <span className="text-[11px] font-semibold uppercase tracking-wide text-slate-500">{langLabel}</span>
1190
+ <button
1191
+ type="button"
1192
+ onClick={handleCopy}
1193
+ className={`p-1 rounded-md hover:bg-slate-100/80 transition-colors ${iconMuted}`}
1194
+ title="Copy"
1195
+ aria-label="Copy to clipboard"
1196
+ >
1197
+ <IconCopy className="w-[15px] h-[15px] shrink-0" />
1198
+ </button>
1199
+ </div>
1200
+ {/* Code body: white, no inner border (single flat surface inside the card) */}
1201
+ <div className="px-4 pb-4">
1202
+ <div className="overflow-x-auto bg-white py-4">
1203
+ <pre className="text-sm text-slate-900 font-mono leading-relaxed whitespace-pre-wrap break-words m-0 p-0 border-0 bg-transparent">
1204
+ <code className="bg-transparent">{content}</code>
1205
+ </pre>
1206
+ </div>
1207
+ </div>
1208
+ {showCopyDownload && (
1209
+ <div className="flex items-center justify-start gap-0.5 px-4 pb-3 pt-0 mt-2 bg-white">
1210
+ <button
1211
+ type="button"
1212
+ onClick={handleCopy}
1213
+ className={`p-1 rounded-md hover:bg-slate-100/80 transition-colors ${iconMuted}`}
1214
+ title={copied ? 'Copied' : 'Copy'}
1215
+ aria-label={copied ? 'Copied' : 'Copy to clipboard'}
1216
+ >
1217
+ {copied ? (
1218
+ <IconCheck className="w-[15px] h-[15px] text-emerald-600" />
1219
+ ) : (
1220
+ <IconCopy className="w-[15px] h-[15px] shrink-0" />
1221
+ )}
1222
+ </button>
1223
+ <button
1224
+ type="button"
1225
+ onClick={handleDownload}
1226
+ className={`p-1 rounded-md hover:bg-slate-100/80 transition-colors ${iconMuted}`}
1227
+ title="Download"
1228
+ aria-label="Download"
1229
+ >
1230
+ <IconDownload className="w-[15px] h-[15px] shrink-0" />
1231
+ </button>
1232
+ </div>
1233
+ )}
1234
+ </div>
1235
+ );
1236
+ };
1237
+
1238
+ // Infer language from file extension or content
1239
+ const inferCodeLanguage = (section: string, filename?: string): string => {
1240
+ if (filename) {
1241
+ const ext = filename.split('.').pop()?.toLowerCase();
1242
+ const map: Record<string, string> = {
1243
+ tsx: 'tsx',
1244
+ jsx: 'jsx',
1245
+ ts: 'ts',
1246
+ js: 'js',
1247
+ css: 'css',
1248
+ html: 'html',
1249
+ json: 'json',
1250
+ };
1251
+ return map[ext ?? ''] ?? ext ?? 'code';
1252
+ }
1253
+ if (/\bimport\b.*from\s+['"]react['"]/i.test(section) || /<\w+[\s>]/.test(section)) return 'jsx';
1254
+ if (/\bimport\b/.test(section) && /\.(ts|tsx)\b/.test(section)) return 'ts';
1255
+ return 'code';
1256
+ };
1257
+
1258
+ // Enhanced code formatter for raw code content
1259
+ export const CodeFormatter: React.FC<{
1260
+ content: string;
1261
+ showCopyDownload?: boolean;
1262
+ variant?: 'default' | 'user';
1263
+ /** When variant is `user`, use primary-foreground only on plan-mode bubbles (bg-primary). */
1264
+ planMode?: boolean;
1265
+ }> = ({ content, showCopyDownload = true, variant = 'default', planMode = false }) => {
1266
+ if (!content) return null;
1267
+
1268
+ // Split content by file separators and format each section
1269
+ const sections = content.split(/(---\s*\w+\.\w+\s*---)/g);
1270
+
1271
+ return (
1272
+ <div className={variant === 'user' ? '' : 'message-container'}>
1273
+ <div className="space-y-4">
1274
+ {sections.map((section, index) => {
1275
+ if (!section.trim()) return null;
1276
+
1277
+ // Check if this is a file separator
1278
+ const fileMatch = section.match(/---\s*(\w+\.\w+)\s*---/);
1279
+ if (fileMatch) {
1280
+ return (
1281
+ <div key={index} className="code-block-container">
1282
+ <div className="code-block-header">📄 {fileMatch[1]}</div>
1283
+ </div>
1284
+ );
1285
+ }
1286
+
1287
+ // Format the code content
1288
+ const lines = section.trim().split('\n');
1289
+ const isCode = lines.some(
1290
+ (line) =>
1291
+ line.includes('@tailwind') ||
1292
+ line.includes('export default') ||
1293
+ line.includes('import ') ||
1294
+ line.includes('{') ||
1295
+ line.includes('}') ||
1296
+ line.includes('//') ||
1297
+ line.includes('/*'),
1298
+ );
1299
+
1300
+ if (isCode) {
1301
+ const lang = inferCodeLanguage(section);
1302
+ return (
1303
+ <CodeBlockWithActions
1304
+ key={index}
1305
+ content={section.trim()}
1306
+ language={lang}
1307
+ showCopyDownload={showCopyDownload}
1308
+ />
1309
+ );
1310
+ }
1311
+
1312
+ // Regular text content
1313
+ return (
1314
+ <div
1315
+ key={index}
1316
+ className={`${variant === 'user' ? USER_MESSAGE_TEXT_SIZE_CLASS : 'text-sm'} ${
1317
+ variant === 'user'
1318
+ ? planMode
1319
+ ? 'text-primary-foreground'
1320
+ : 'text-gray-900'
1321
+ : 'text-gray-700'
1322
+ } leading-relaxed whitespace-pre-wrap break-words`}
1323
+ >
1324
+ {section.trim()}
1325
+ </div>
1326
+ );
1327
+ })}
1328
+ </div>
1329
+ </div>
1330
+ );
1331
+ };
1332
+
1333
+ // Enhanced markdown renderer using marked (similar to MessageBubble.tsx)
1334
+ export const FormattedMessageContent: React.FC<{
1335
+ content: string;
1336
+ variant?: 'default' | 'user';
1337
+ /** When variant is `user`, use primary-foreground only on plan-mode bubbles (bg-primary). */
1338
+ planMode?: boolean;
1339
+ /**
1340
+ * When true, fenced code blocks use the same copy/download UI as elsewhere.
1341
+ * Implemented via react-markdown (safe) instead of raw HTML from marked.
1342
+ */
1343
+ showCopyDownloadOnCodeBlock?: boolean;
1344
+ }> = ({ content, variant = 'default', planMode = false, showCopyDownloadOnCodeBlock = false }) => {
1345
+ if (!content) return null;
1346
+
1347
+ // Parse markdown using marked - be more aggressive in detection
1348
+ const { htmlContent, markdownSource } = useMemo(() => {
1349
+ try {
1350
+ const trimmed = content.trim();
1351
+
1352
+ // Comprehensive markdown detection patterns
1353
+ const markdownIndicators = [
1354
+ /^#{1,6}\s+.+$/gm, // Headers with text
1355
+ /^\s*[-*+]\s+.+$/gm, // Unordered lists
1356
+ /^\s*\d+\.\s+.+$/gm, // Numbered lists
1357
+ /\[.+?\]\(.+?\)/g, // Links
1358
+ /!\[.+?\]\(.+?\)/g, // Images
1359
+ /```[\s\S]*?```/g, // Fenced code blocks
1360
+ /^\s*>\s+/gm, // Blockquotes
1361
+ /\*\*[^*]+\*\*/g, // Bold text
1362
+ /\*[^*\n]+\*/g, // Italic text (not just asterisks)
1363
+ /^\s*\|.+\|/gm, // Tables
1364
+ /~~.+~~/g, // Strikethrough
1365
+ ];
1366
+
1367
+ // Check if content has markdown patterns
1368
+ const hasMarkdown = markdownIndicators.some((pattern) => {
1369
+ const matches = trimmed.match(pattern);
1370
+ return matches && matches.length > 0;
1371
+ });
1372
+
1373
+ // Also check for common markdown characters that suggest markdown content
1374
+ const hasMarkdownChars = /[#*`>|\[\]()]/.test(trimmed) && trimmed.length > 10;
1375
+
1376
+ // If we detect markdown, parse it
1377
+ if (hasMarkdown || hasMarkdownChars) {
1378
+ const parsed = marked.parse(trimmed, { async: false }) as string;
1379
+ // Only return if parsing actually produced HTML (not just the same text)
1380
+ if (parsed && parsed.trim() !== trimmed && parsed.includes('<')) {
1381
+ return { htmlContent: parsed, markdownSource: trimmed as string };
1382
+ }
1383
+ }
1384
+
1385
+ return { htmlContent: null as string | null, markdownSource: null as string | null };
1386
+ } catch (error) {
1387
+ console.error('Error parsing markdown:', error);
1388
+ return { htmlContent: null as string | null, markdownSource: null as string | null };
1389
+ }
1390
+ }, [content]);
1391
+
1392
+ const userMarkdownClasses = `${USER_MESSAGE_TEXT_SIZE_CLASS} prose ${USER_MESSAGE_PROSE_SIZE_CLASS} max-w-none leading-relaxed break-words
1393
+ prose-p:my-2 prose-p:text-gray-700
1394
+ prose-pre:my-2 prose-pre:bg-transparent prose-pre:border-0 prose-pre:p-0
1395
+ prose-ul:my-2 prose-ol:my-2
1396
+ prose-code:break-words prose-code:bg-gray-50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-sm prose-code:font-mono
1397
+ prose-headings:font-semibold prose-headings:text-gray-900 prose-headings:mt-4 prose-headings:mb-2
1398
+ prose-h1:text-2xl prose-h1:border-b prose-h1:border-gray-200 prose-h1:pb-2
1399
+ prose-h2:text-xl prose-h2:border-b prose-h2:border-gray-200 prose-h2:pb-1
1400
+ prose-h3:text-lg
1401
+ prose-h4:text-base
1402
+ prose-a:text-blue-600 prose-a:no-underline hover:prose-a:underline
1403
+ prose-strong:font-semibold prose-strong:text-gray-900
1404
+ prose-em:text-gray-600
1405
+ prose-blockquote:border-l-4 prose-blockquote:border-blue-400 prose-blockquote:pl-4 prose-blockquote:py-2 prose-blockquote:bg-blue-50 prose-blockquote:rounded-r-md prose-blockquote:my-3 prose-blockquote:italic
1406
+ prose-table:w-full prose-table:border prose-table:border-gray-200 prose-table:rounded-md prose-table:my-4
1407
+ prose-th:px-3 prose-th:py-2 prose-th:text-left prose-th:font-semibold prose-th:bg-gray-50 prose-th:border prose-th:border-gray-200
1408
+ prose-td:px-3 prose-td:py-2 prose-td:border prose-td:border-gray-200 prose-td:text-gray-700
1409
+ prose-li:my-1 prose-li:text-gray-700
1410
+ prose-hr:my-4 prose-hr:border-gray-200
1411
+ ${
1412
+ planMode
1413
+ ? '!prose-p:text-primary-foreground !prose-li:text-primary-foreground !prose-strong:text-primary-foreground !prose-em:text-primary-foreground !prose-a:text-primary-foreground'
1414
+ : '!prose-p:text-gray-900 !prose-li:text-gray-900 !prose-strong:text-gray-900 !prose-em:text-gray-700 !prose-a:text-blue-600'
1415
+ }`;
1416
+
1417
+ const userHtmlClasses = `${USER_MESSAGE_TEXT_SIZE_CLASS} prose ${USER_MESSAGE_PROSE_SIZE_CLASS} max-w-none leading-relaxed break-words
1418
+ prose-p:my-2 prose-p:text-gray-700
1419
+ prose-pre:my-2 prose-pre:bg-gray-50 prose-pre:border prose-pre:border-gray-200 prose-pre:rounded prose-pre:p-3
1420
+ prose-ul:my-2 prose-ol:my-2
1421
+ prose-pre:whitespace-pre-wrap prose-pre:break-words prose-pre:overflow-x-auto
1422
+ prose-code:break-words prose-code:bg-gray-50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-sm prose-code:font-mono
1423
+ prose-headings:font-semibold prose-headings:text-gray-900 prose-headings:mt-4 prose-headings:mb-2
1424
+ prose-h1:text-2xl prose-h1:border-b prose-h1:border-gray-200 prose-h1:pb-2
1425
+ prose-h2:text-xl prose-h2:border-b prose-h2:border-gray-200 prose-h2:pb-1
1426
+ prose-h3:text-lg
1427
+ prose-h4:text-base
1428
+ prose-a:text-blue-600 prose-a:no-underline hover:prose-a:underline
1429
+ prose-strong:font-semibold prose-strong:text-gray-900
1430
+ prose-em:text-gray-600
1431
+ prose-blockquote:border-l-4 prose-blockquote:border-blue-400 prose-blockquote:pl-4 prose-blockquote:py-2 prose-blockquote:bg-blue-50 prose-blockquote:rounded-r-md prose-blockquote:my-3 prose-blockquote:italic
1432
+ prose-table:w-full prose-table:border prose-table:border-gray-200 prose-table:rounded-md prose-table:my-4
1433
+ prose-th:px-3 prose-th:py-2 prose-th:text-left prose-th:font-semibold prose-th:bg-gray-50 prose-th:border prose-th:border-gray-200
1434
+ prose-td:px-3 prose-td:py-2 prose-td:border prose-td:border-gray-200 prose-td:text-gray-700
1435
+ prose-li:my-1 prose-li:text-gray-700
1436
+ prose-hr:my-4 prose-hr:border-gray-200
1437
+ ${
1438
+ planMode
1439
+ ? '!prose-p:text-primary-foreground !prose-li:text-primary-foreground !prose-strong:text-primary-foreground !prose-em:text-primary-foreground !prose-a:text-primary-foreground'
1440
+ : '!prose-p:text-gray-900 !prose-li:text-gray-900 !prose-strong:text-gray-900 !prose-em:text-gray-700 !prose-a:text-blue-600'
1441
+ }`;
1442
+
1443
+ const markdownComponents = useMemo(() => {
1444
+ const isUserVariant = variant === 'user';
1445
+ const userTextClass = planMode ? 'text-primary-foreground' : 'text-gray-900';
1446
+ const userMutedTextClass = planMode ? 'text-primary-foreground' : 'text-gray-700';
1447
+ const userLinkClass = planMode
1448
+ ? 'text-primary-foreground underline underline-offset-2'
1449
+ : 'text-blue-600 hover:underline underline-offset-2';
1450
+
1451
+ return {
1452
+ p: ({ children }: { children?: React.ReactNode }) =>
1453
+ isUserVariant ? (
1454
+ <p className={`break-words mb-4 last:mb-0 leading-relaxed ${userTextClass}`}>{children}</p>
1455
+ ) : (
1456
+ <p>{children}</p>
1457
+ ),
1458
+ h1: ({ children }: { children?: React.ReactNode }) =>
1459
+ isUserVariant ? (
1460
+ <h1 className={`text-2xl font-semibold mt-6 mb-3 first:mt-0 ${userTextClass}`}>{children}</h1>
1461
+ ) : (
1462
+ <h1>{children}</h1>
1463
+ ),
1464
+ h2: ({ children }: { children?: React.ReactNode }) =>
1465
+ isUserVariant ? (
1466
+ <h2 className={`text-xl font-semibold mt-5 mb-3 first:mt-0 ${userTextClass}`}>{children}</h2>
1467
+ ) : (
1468
+ <h2>{children}</h2>
1469
+ ),
1470
+ h3: ({ children }: { children?: React.ReactNode }) =>
1471
+ isUserVariant ? (
1472
+ <h3 className={`text-lg font-semibold mt-4 mb-2 first:mt-0 ${userTextClass}`}>{children}</h3>
1473
+ ) : (
1474
+ <h3>{children}</h3>
1475
+ ),
1476
+ h4: ({ children }: { children?: React.ReactNode }) =>
1477
+ isUserVariant ? (
1478
+ <h4 className={`text-base font-semibold mt-4 mb-2 first:mt-0 ${userTextClass}`}>{children}</h4>
1479
+ ) : (
1480
+ <h4>{children}</h4>
1481
+ ),
1482
+ blockquote: ({ children }: { children?: React.ReactNode }) =>
1483
+ isUserVariant ? (
1484
+ <blockquote
1485
+ className={`border-l-4 border-blue-400 pl-4 py-2 bg-blue-50 rounded-r-md my-3 italic ${userMutedTextClass}`}
1486
+ >
1487
+ {children}
1488
+ </blockquote>
1489
+ ) : (
1490
+ <blockquote>{children}</blockquote>
1491
+ ),
1492
+ hr: () => (isUserVariant ? <hr className="my-4 border-gray-200" /> : <hr />),
1493
+ ul: ({ children }: { children?: React.ReactNode }) => (
1494
+ <ul
1495
+ className={
1496
+ isUserVariant
1497
+ ? `list-disc pl-5 mb-4 space-y-1.5 marker:text-gray-500 [&_ul]:mt-1.5 [&_ol]:mt-1.5 ${userTextClass}`
1498
+ : 'list-disc pl-5'
1499
+ }
1500
+ >
1501
+ {children}
1502
+ </ul>
1503
+ ),
1504
+ ol: ({ children }: { children?: React.ReactNode }) => (
1505
+ <ol
1506
+ className={
1507
+ isUserVariant
1508
+ ? `list-decimal pl-5 mb-4 space-y-1.5 marker:text-gray-500 [&_ul]:mt-1.5 [&_ol]:mt-1.5 ${userTextClass}`
1509
+ : 'list-decimal pl-5'
1510
+ }
1511
+ >
1512
+ {children}
1513
+ </ol>
1514
+ ),
1515
+ li: ({ children }: { children?: React.ReactNode }) => (
1516
+ <li
1517
+ className={
1518
+ isUserVariant
1519
+ ? `break-words whitespace-pre-wrap leading-relaxed [&>ul]:whitespace-normal [&>ol]:whitespace-normal ${userMutedTextClass}`
1520
+ : 'break-words whitespace-pre-wrap leading-relaxed [&>ul]:whitespace-normal [&>ol]:whitespace-normal'
1521
+ }
1522
+ >
1523
+ {children}
1524
+ </li>
1525
+ ),
1526
+ a: ({ href, children }: { href?: string; children?: React.ReactNode }) =>
1527
+ isUserVariant ? (
1528
+ <a href={href} className={userLinkClass}>
1529
+ {children}
1530
+ </a>
1531
+ ) : (
1532
+ <a href={href}>{children}</a>
1533
+ ),
1534
+ table: ({
1535
+ children,
1536
+ ...props
1537
+ }: React.TableHTMLAttributes<HTMLTableElement> & { children?: React.ReactNode }) =>
1538
+ isUserVariant ? (
1539
+ <div className="overflow-x-auto my-4 w-full rounded-md border border-gray-200">
1540
+ <table className="w-full text-sm" {...props}>
1541
+ {children}
1542
+ </table>
1543
+ </div>
1544
+ ) : (
1545
+ <div className="overflow-x-auto my-4 w-full">
1546
+ <table {...props}>{children}</table>
1547
+ </div>
1548
+ ),
1549
+ thead: ({ children }: { children?: React.ReactNode }) =>
1550
+ isUserVariant ? <thead className="bg-gray-50 text-left">{children}</thead> : <thead>{children}</thead>,
1551
+ th: ({ children }: { children?: React.ReactNode }) =>
1552
+ isUserVariant ? (
1553
+ <th className={`px-3 py-2 text-left font-semibold ${userTextClass}`}>{children}</th>
1554
+ ) : (
1555
+ <th>{children}</th>
1556
+ ),
1557
+ td: ({ children }: { children?: React.ReactNode }) =>
1558
+ isUserVariant ? <td className={`px-3 py-2 ${userMutedTextClass}`}>{children}</td> : <td>{children}</td>,
1559
+ pre: ({ children }: { children?: React.ReactNode }) => <>{children}</>,
1560
+ code: ({ className, children, ...rest }: { className?: string; children?: React.ReactNode }) => {
1561
+ const match = /language-(\w+)/.exec(className || '');
1562
+ const text = String(children).replace(/\n$/, '');
1563
+ if (match) {
1564
+ return (
1565
+ <div className="not-prose max-w-none">
1566
+ <CodeBlockWithActions
1567
+ content={text}
1568
+ language={match[1]}
1569
+ showCopyDownload={showCopyDownloadOnCodeBlock}
1570
+ />
1571
+ </div>
1572
+ );
1573
+ }
1574
+ if (text.includes('\n')) {
1575
+ return (
1576
+ <div className="not-prose max-w-none">
1577
+ <CodeBlockWithActions
1578
+ content={text}
1579
+ language="code"
1580
+ showCopyDownload={showCopyDownloadOnCodeBlock}
1581
+ />
1582
+ </div>
1583
+ );
1584
+ }
1585
+ return (
1586
+ <code
1587
+ className={
1588
+ isUserVariant
1589
+ ? `rounded px-1.5 py-0.5 text-sm font-mono bg-gray-50 break-words ${className || ''}`
1590
+ : `llm-inline-code break-words ${className || ''}`
1591
+ }
1592
+ {...rest}
1593
+ >
1594
+ {children}
1595
+ </code>
1596
+ );
1597
+ },
1598
+ };
1599
+ }, [planMode, showCopyDownloadOnCodeBlock, variant]);
1600
+
1601
+ // Fenced code copy/download needs React tree (not marked HTML)
1602
+ if (showCopyDownloadOnCodeBlock && markdownSource) {
1603
+ if (variant === 'user') {
1604
+ return (
1605
+ <div className={userMarkdownClasses}>
1606
+ <ReactMarkdown remarkPlugins={[remarkGfm, remarkBreaks]} components={markdownComponents}>
1607
+ {markdownSource}
1608
+ </ReactMarkdown>
1609
+ </div>
1610
+ );
1611
+ }
1612
+
1613
+ return (
1614
+ <AssistantResponseWrapper>
1615
+ <div className={getAssistantResponseClasses('min-w-0')}>
1616
+ <ReactMarkdown remarkPlugins={[remarkGfm, remarkBreaks]} components={markdownComponents}>
1617
+ {markdownSource}
1618
+ </ReactMarkdown>
1619
+ </div>
1620
+ </AssistantResponseWrapper>
1621
+ );
1622
+ }
1623
+
1624
+ // If markdown was parsed, render as HTML with prose styling
1625
+ if (htmlContent) {
1626
+ if (variant === 'user') {
1627
+ return <div className={userHtmlClasses} dangerouslySetInnerHTML={{ __html: htmlContent }} />;
1628
+ }
1629
+
1630
+ return (
1631
+ <AssistantResponseWrapper>
1632
+ <div
1633
+ className={getAssistantResponseClasses('min-w-0')}
1634
+ dangerouslySetInnerHTML={{ __html: htmlContent }}
1635
+ />
1636
+ </AssistantResponseWrapper>
1637
+ );
1638
+ }
1639
+
1640
+ // For plain text content
1641
+ return variant === 'user' ? (
1642
+ <p
1643
+ className={`${USER_MESSAGE_TEXT_SIZE_CLASS} leading-relaxed whitespace-pre-wrap break-words ${
1644
+ planMode ? 'text-primary-foreground' : 'text-gray-900'
1645
+ }`}
1646
+ >
1647
+ {content}
1648
+ </p>
1649
+ ) : (
1650
+ <AssistantResponseWrapper>
1651
+ <div className={getAssistantResponseClasses()}>
1652
+ <p className="leading-relaxed whitespace-pre-wrap break-words">{content}</p>
1653
+ </div>
1654
+ </AssistantResponseWrapper>
1655
+ );
1656
+ };
1657
+
1658
+ // Detect predominant text direction (RTL/LTR) for international content
1659
+ const detectTextDirection = (text: string): 'rtl' | 'ltr' => {
1660
+ if (!text) return 'ltr';
1661
+ const rtlRanges = /[\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC]/g; // Hebrew, Arabic, etc.
1662
+ const ltrRanges = /[A-Za-z\u00C0-\u024F\u1E00-\u1EFF]/g;
1663
+ const rtlCount = (text.match(rtlRanges) || []).length;
1664
+ const ltrCount = (text.match(ltrRanges) || []).length;
1665
+ return rtlCount > ltrCount ? 'rtl' : 'ltr';
1666
+ };
1667
+
1668
+ // Lightweight language heuristic for lang attribute
1669
+ const detectLanguageTag = (text: string): string => {
1670
+ if (!text) return 'en';
1671
+ if (/\p{Script=Arabic}/u.test(text)) return 'ar';
1672
+ if (/[\u0590-\u05FF]/.test(text)) return 'he';
1673
+ if (/[\u0600-\u06FF]/.test(text)) return 'fa';
1674
+ if (/[\u0900-\u097F]/.test(text)) return 'hi';
1675
+ if (/[\u4E00-\u9FFF]/.test(text)) return 'zh';
1676
+ if (/[\u3040-\u309F\u30A0-\u30FF]/.test(text)) return 'ja';
1677
+ if (/[\uAC00-\uD7AF]/.test(text)) return 'ko';
1678
+ if (/[\u0400-\u04FF]/.test(text)) return 'ru';
1679
+ if (/[\u0E00-\u0E7F]/.test(text)) return 'th';
1680
+ return 'en';
1681
+ };
1682
+
1683
+ // Attempt to parse Builder.io-like JSON blocks embedded as message string
1684
+ const tryExtractBuilderBlocks = (content?: string): any[] | null => {
1685
+ if (!content || content.length < 2) return null;
1686
+ try {
1687
+ const trimmed = content.trim();
1688
+ const jsonMatch = trimmed.match(/([\[{][\s\S]*[\]}])/);
1689
+ const jsonText = jsonMatch ? jsonMatch[1] : trimmed;
1690
+ const parsed = JSON.parse(jsonText);
1691
+ if (Array.isArray(parsed)) {
1692
+ if (parsed.length && (parsed[0]['@type'] || parsed[0].type)) return parsed;
1693
+ } else if (parsed && typeof parsed === 'object') {
1694
+ if (Array.isArray(parsed.blocks)) return parsed.blocks;
1695
+ if (Array.isArray(parsed?.data?.blocks)) return parsed.data.blocks;
1696
+ }
1697
+ return null;
1698
+ } catch {
1699
+ return null;
1700
+ }
1701
+ };
1702
+
1703
+ const ModernMessageGroup: React.FC<MessageGroupProps> = ({
1704
+ author,
1705
+ messages,
1706
+ currentUser,
1707
+ showAuthorName = false,
1708
+ showAvatar = false,
1709
+ showTimestamp = false,
1710
+ onOpen,
1711
+ onMessageClick,
1712
+ isDesktopView = false,
1713
+ isSmallScreen = false,
1714
+ showCopyDownloadOnCodeBlock = false,
1715
+ }) => {
1716
+ // Inject CSS styles for HTML content
1717
+ useInjectStyles();
1718
+
1719
+ // Preserve server / store order for posts (TOOLUSE, THINKING, etc.); no client-side reordering
1720
+ const displayMessages = messages;
1721
+
1722
+ //const isOwnMessage = author?.id === currentUser?.id;
1723
+ //const isOwnMessage = messages.some((message: any) => (message as any)?.propsConfiguration?.contents?.role === AiAgentMessageRole.User);
1724
+ const isOwnMessage =
1725
+ displayMessages.some(
1726
+ (message: any) => (message as any)?.propsConfiguration?.contents?.role === AiAgentMessageRole.User,
1727
+ ) ||
1728
+ (Array.isArray(author?.alias) &&
1729
+ typeof currentUser?.authUserId === 'string' &&
1730
+ author.alias.some((alias: string) => alias?.toLowerCase() === currentUser.authUserId.toLowerCase()));
1731
+
1732
+ const authorName =
1733
+ author?.givenName && author?.familyName
1734
+ ? `${author.givenName} ${author.familyName}`
1735
+ : author?.username || 'Unknown User';
1736
+
1737
+ const firstMessage = displayMessages[0];
1738
+ const formatTime = (timestamp: string) => {
1739
+ const date = new Date(timestamp);
1740
+ return format(date, 'h:mm a');
1741
+ };
1742
+
1743
+ // Determine if this is an AI/system message for special styling
1744
+ const isSystemMessage =
1745
+ author?.username?.toLowerCase().includes('ai') ||
1746
+ author?.username?.toLowerCase().includes('assistant') ||
1747
+ author?.username?.toLowerCase().includes('system');
1748
+ // const isSystemMessage = messages.some(
1749
+ // (message: any) => (message as any)?.propsConfiguration?.contents?.role === AiAgentMessageRole.Assistant,
1750
+ // );
1751
+
1752
+ // For user messages, don't show group header, just individual messages with avatars
1753
+ if (isOwnMessage) {
1754
+ return (
1755
+ <div
1756
+ className={`min-h-fit ${
1757
+ isDesktopView ? 'space-y-1 mb-3' : isSmallScreen ? 'space-y-0.5 mb-2' : 'space-y-0.5 mb-2'
1758
+ }`}
1759
+ >
1760
+ {displayMessages.map((message, index) => (
1761
+ <ModernMessageBubble
1762
+ key={message.id}
1763
+ message={message}
1764
+ isOwnMessage={isOwnMessage}
1765
+ isSystemMessage={isSystemMessage}
1766
+ isFirstInGroup={index === 0}
1767
+ isLastInGroup={index === displayMessages.length - 1}
1768
+ onMessageClick={onMessageClick}
1769
+ formatTime={formatTime}
1770
+ showAuthorName={showAuthorName}
1771
+ showAvatar={showAvatar}
1772
+ showTimestamp={showTimestamp}
1773
+ showCopyDownloadOnCodeBlock={showCopyDownloadOnCodeBlock}
1774
+ />
1775
+ ))}
1776
+ </div>
1777
+ );
1778
+ }
1779
+
1780
+ // For other messages (non-user), show the traditional group layout
1781
+ return (
1782
+ <div
1783
+ className={`group transition-all duration-300 ease-in-out ${
1784
+ isDesktopView ? 'mb-4 px-4 py-3' : isSmallScreen ? 'mb-2 px-2 py-1' : 'mb-3 px-3 py-1'
1785
+ } ${isSystemMessage ? 'bg-white rounded-lg' : ' rounded-lg'}`}
1786
+ >
1787
+ <div
1788
+ className={`flex items-start ${
1789
+ isDesktopView ? 'space-x-4' : isSmallScreen ? 'space-x-2' : 'space-x-3'
1790
+ }`}
1791
+ >
1792
+ {/* Enhanced Avatar - Only show for non-system messages */}
1793
+ {/* {!isSystemMessage && (
1794
+ <div className="flex-shrink-0 mt-1">
1795
+ <div className="relative rounded-lg overflow-hidden">
1796
+ <img
1797
+ className={`cursor-pointer hover:opacity-80 transition-opacity ${
1798
+ isDesktopView ? 'w-12 h-12' : isSmallScreen ? 'w-8 h-8' : 'w-10 h-10'
1799
+ } rounded-lg object-cover`}
1800
+ src={author?.picture || '/default-avatar.svg'}
1801
+ alt={authorName}
1802
+ onClick={() => onOpen(firstMessage)}
1803
+ onError={(e) => {
1804
+ e.currentTarget.src = '/default-avatar.svg';
1805
+ }}
1806
+ />
1807
+ </div>
1808
+ </div>
1809
+ )} */}
1810
+
1811
+ <div className="flex-1 min-w-0 overflow-hidden">
1812
+ {/* Enhanced author header - Only show for non-system messages */}
1813
+ {/* {!isSystemMessage && (
1814
+ <div className="flex items-center space-x-3 mb-2">
1815
+ <span className="font-semibold truncate text-gray-900">{authorName}</span>
1816
+ </div>
1817
+ )} */}
1818
+
1819
+ {/* Enhanced Messages with rich formatting */}
1820
+ <div className="space-y-1">
1821
+ {displayMessages.map((message, index) => (
1822
+ <ModernMessageBubble
1823
+ key={message.id}
1824
+ message={message}
1825
+ isOwnMessage={isOwnMessage}
1826
+ isSystemMessage={isSystemMessage}
1827
+ isFirstInGroup={index === 0}
1828
+ isLastInGroup={index === displayMessages.length - 1}
1829
+ onMessageClick={onMessageClick}
1830
+ formatTime={formatTime}
1831
+ showTimestamp={showTimestamp}
1832
+ showCopyDownloadOnCodeBlock={showCopyDownloadOnCodeBlock}
1833
+ />
1834
+ ))}
1835
+ </div>
1836
+ </div>
1837
+ </div>
1838
+ </div>
1839
+ );
1840
+ };
1841
+
1842
+ interface ModernMessageBubbleProps {
1843
+ showAuthorName?: boolean;
1844
+ showAvatar?: boolean;
1845
+ showTimestamp?: boolean;
1846
+ message: IPost;
1847
+ isOwnMessage: boolean;
1848
+ isSystemMessage: boolean;
1849
+ isFirstInGroup: boolean;
1850
+ isLastInGroup: boolean;
1851
+ onMessageClick: (msg: IPost) => void;
1852
+ formatTime: (timestamp: string) => string;
1853
+ showCopyDownloadOnCodeBlock?: boolean;
1854
+ }
1855
+
1856
+ const ModernMessageBubble: React.FC<ModernMessageBubbleProps> = ({
1857
+ showAuthorName = false,
1858
+ showAvatar = false,
1859
+ showTimestamp = false,
1860
+ message,
1861
+ isOwnMessage,
1862
+ isSystemMessage,
1863
+ isFirstInGroup,
1864
+ isLastInGroup,
1865
+ onMessageClick,
1866
+ formatTime,
1867
+ showCopyDownloadOnCodeBlock = false,
1868
+ }) => {
1869
+ const handleClick = () => {
1870
+ onMessageClick?.(message);
1871
+ };
1872
+
1873
+ const isAssistantRole = (message as any)?.propsConfiguration?.contents?.role === AiAgentMessageRole.Assistant;
1874
+ const messageMode =
1875
+ (message as any)?.propsConfiguration?.contents?.mode ??
1876
+ (message as any)?.propsConfiguration?.content?.mode ??
1877
+ (message as any)?.props?.mode;
1878
+ const isPlanMode = messageMode === 'plan';
1879
+ // For user messages, create a right-aligned layout with avatar and name
1880
+ if (isOwnMessage) {
1881
+ const authorName =
1882
+ message.author?.givenName && message.author?.familyName
1883
+ ? `${message.author.givenName} ${message.author.familyName}`
1884
+ : message.author?.username || 'You';
1885
+
1886
+ return (
1887
+ <div className="py-1 px-1 sm:px-2 -mx-1 sm:-mx-2 group">
1888
+ <div className="flex items-start justify-end gap-2">
1889
+ <div className="flex flex-col items-end max-w-[85%]">
1890
+ {showAuthorName && (
1891
+ <div className="flex items-end space-x-2 mb-0.5">
1892
+ <span className="text-sm font-semibold text-gray-900">{authorName}</span>
1893
+ </div>
1894
+ )}
1895
+
1896
+ {/* User message bubble (Image 2) */}
1897
+ <div
1898
+ className={`${isAssistantRole ? 'text-sm' : USER_MESSAGE_TEXT_SIZE_CLASS} ${
1899
+ isAssistantRole
1900
+ ? 'cursor-pointer rounded-2xl border border-gray-200 bg-gray-50 text-gray-900 px-4 py-2.5'
1901
+ : // : 'user-message rounded-[22px] rounded-br-[4px] px-4 py-3 bg-primary text-primary-foreground shadow-sm'
1902
+ isPlanMode
1903
+ ? 'user-message rounded-[22px] rounded-br-[4px] px-4 py-3 bg-primary text-primary-foreground shadow-sm'
1904
+ : 'user-message rounded-[22px] rounded-br-[4px] px-4 py-3 '
1905
+ }`}
1906
+ onClick={isAssistantRole ? handleClick : undefined}
1907
+ dir={detectTextDirection((message as any)?.message || '')}
1908
+ lang={detectLanguageTag((message as any)?.message || '')}
1909
+ >
1910
+ {message.message && (
1911
+ <div className="max-w-none">
1912
+ {(() => {
1913
+ const contentType = detectContentType(message.message);
1914
+
1915
+ if (contentType === 'code') {
1916
+ return (
1917
+ <CodeFormatter
1918
+ content={message.message}
1919
+ showCopyDownload={showCopyDownloadOnCodeBlock}
1920
+ variant={isAssistantRole ? 'default' : 'user'}
1921
+ planMode={!isAssistantRole && isPlanMode}
1922
+ />
1923
+ );
1924
+ } else if (contentType === 'html') {
1925
+ if (isAssistantRole) {
1926
+ return (
1927
+ <AssistantResponseWrapper>
1928
+ <div
1929
+ className={getAssistantResponseClasses('min-w-0')}
1930
+ dangerouslySetInnerHTML={{
1931
+ __html: prettifyHtmlContent(
1932
+ sanitizeHtml(message.message),
1933
+ ),
1934
+ }}
1935
+ />
1936
+ </AssistantResponseWrapper>
1937
+ );
1938
+ }
1939
+
1940
+ return (
1941
+ <div
1942
+ className={
1943
+ isPlanMode
1944
+ ? '!text-primary-foreground html-content'
1945
+ : 'text-gray-900 html-content'
1946
+ }
1947
+ dangerouslySetInnerHTML={{
1948
+ __html: prettifyHtmlContent(sanitizeHtml(message.message)),
1949
+ }}
1950
+ />
1951
+ );
1952
+ } else {
1953
+ return (
1954
+ <FormattedMessageContent
1955
+ content={message.message}
1956
+ variant={isAssistantRole ? 'default' : 'user'}
1957
+ planMode={!isAssistantRole && isPlanMode}
1958
+ showCopyDownloadOnCodeBlock={showCopyDownloadOnCodeBlock}
1959
+ />
1960
+ );
1961
+ }
1962
+ })()}
1963
+ </div>
1964
+ )}
1965
+
1966
+ {tryExtractBuilderBlocks((message as any)?.message)?.length ? (
1967
+ <div className="mt-2">
1968
+ <BuilderLikeRenderer blocks={tryExtractBuilderBlocks((message as any)?.message)} />
1969
+ </div>
1970
+ ) : null}
1971
+
1972
+ {(message as any)?.props?.blocks?.length ? (
1973
+ <div className="mt-2">
1974
+ <BuilderLikeRenderer blocks={(message as any).props.blocks} />
1975
+ </div>
1976
+ ) : null}
1977
+
1978
+ {message.files?.totalCount > 0 && (
1979
+ <div className="mt-2">
1980
+ <FilesList uploaded files={message.files.data} />
1981
+ </div>
1982
+ )}
1983
+ {showTimestamp ? (
1984
+ <div
1985
+ className={`text-[10px] mt-1 text-right ${
1986
+ isAssistantRole
1987
+ ? 'text-gray-500'
1988
+ : isPlanMode
1989
+ ? 'text-primary-foreground/80'
1990
+ : 'text-gray-500'
1991
+ }`}
1992
+ >
1993
+ {formatTime(message.createdAt)}
1994
+ </div>
1995
+ ) : null}
1996
+ </div>
1997
+ </div>
1998
+
1999
+ {/* User avatar on the right */}
2000
+ {showAvatar && (
2001
+ <div className="flex-shrink-0 mt-0.5">
2002
+ <img
2003
+ className={`w-8 h-8 sm:w-10 sm:h-10 rounded-lg ${
2004
+ isAssistantRole ? '' : 'cursor-pointer hover:opacity-80'
2005
+ } transition-opacity object-cover`}
2006
+ src={message.author?.picture || '/default-avatar.svg'}
2007
+ alt={authorName}
2008
+ //onClick={isAssistantRole ? undefined : handleClick}
2009
+ onClick={isAssistantRole ? handleClick : undefined}
2010
+ onError={(e) => {
2011
+ e.currentTarget.src = '/default-avatar.svg';
2012
+ }}
2013
+ />
2014
+ </div>
2015
+ )}
2016
+ </div>
2017
+ </div>
2018
+ );
2019
+ }
2020
+
2021
+ // For other messages (left-aligned) — use Slot for streaming types (THINKING, TOOLUSE, etc.) like Kimi
2022
+ const attachment =
2023
+ (message as any)?.props?.attachment ?? (message as any)?.propsConfiguration?.contents?.attachment;
2024
+ const slotName = getMessageSlotName((message as any)?.type);
2025
+ // Don't show THINKING slot when attachment has no meaningful content or when dismissed
2026
+ const isThinkingSlot = slotName === MessengerSlotFillNameEnum.THINKING_NAME;
2027
+ const shouldShowThinkingSlot =
2028
+ !!attachment &&
2029
+ attachment.dismissed !== true &&
2030
+ (attachment.isThinking === true || (attachment.thought != null && String(attachment.thought).trim() !== ''));
2031
+ const shouldShowSlot = isThinkingSlot ? shouldShowThinkingSlot : !!attachment;
2032
+ const hasStreamingSlot = !!slotName && shouldShowSlot;
2033
+ return (
2034
+ <div
2035
+ className={`group/message w-full min-w-0 px-0 py-2 ${
2036
+ isSystemMessage || isAssistantRole ? 'cursor-pointer' : ''
2037
+ }`}
2038
+ onClick={isSystemMessage || isAssistantRole ? handleClick : undefined}
2039
+ >
2040
+ <div className="flex items-start justify-between gap-3">
2041
+ <div className="flex-1 min-w-0">
2042
+ {/* Slot fill for streaming message types (THINKING, TOOLUSE, CODEBLOCK, SERVICE, AIASSISTANT) */}
2043
+ {slotName && shouldShowSlot && (
2044
+ <Slot
2045
+ name={slotName}
2046
+ fillProps={{
2047
+ active: true,
2048
+ message,
2049
+ index: 0,
2050
+ onMessageClick,
2051
+ }}
2052
+ />
2053
+ )}
2054
+ {/* Default content when no slot or attachment (slot returns null when active: false) */}
2055
+ {!hasStreamingSlot && message.message && (
2056
+ <div
2057
+ className={`min-w-0 relative max-w-full w-full ${
2058
+ isSystemMessage ? 'text-gray-800' : 'text-gray-900'
2059
+ }`}
2060
+ dir={detectTextDirection((message as any)?.message || '')}
2061
+ lang={detectLanguageTag((message as any)?.message || '')}
2062
+ >
2063
+ {(() => {
2064
+ const contentType = detectContentType(message.message);
2065
+
2066
+ // Markdown and text both go through FormattedMessageContent
2067
+ // which will intelligently detect and render markdown
2068
+ if (contentType === 'code') {
2069
+ return (
2070
+ <CodeFormatter
2071
+ content={message.message}
2072
+ showCopyDownload={showCopyDownloadOnCodeBlock}
2073
+ />
2074
+ );
2075
+ } else if (contentType === 'html') {
2076
+ return (
2077
+ <AssistantResponseWrapper>
2078
+ <div
2079
+ className={getAssistantResponseClasses(
2080
+ 'min-w-0 relative max-w-full w-full',
2081
+ )}
2082
+ dangerouslySetInnerHTML={{
2083
+ __html: prettifyHtmlContent(sanitizeHtml(message.message)),
2084
+ }}
2085
+ />
2086
+ </AssistantResponseWrapper>
2087
+ );
2088
+ } else {
2089
+ // Handle both 'markdown' and 'text' - FormattedMessageContent
2090
+ // will detect markdown patterns and render accordingly
2091
+ return (
2092
+ <FormattedMessageContent
2093
+ content={message.message}
2094
+ showCopyDownloadOnCodeBlock={showCopyDownloadOnCodeBlock}
2095
+ />
2096
+ );
2097
+ }
2098
+ })()}
2099
+ </div>
2100
+ )}
2101
+
2102
+ {!hasStreamingSlot && tryExtractBuilderBlocks((message as any)?.message)?.length ? (
2103
+ <div className="mt-3 p-3 bg-gray-50 rounded-lg border border-gray-200">
2104
+ <BuilderLikeRenderer blocks={tryExtractBuilderBlocks((message as any)?.message)} />
2105
+ </div>
2106
+ ) : null}
2107
+
2108
+ {!hasStreamingSlot && (message as any)?.props?.blocks?.length ? (
2109
+ <div className="mt-3 p-3 bg-gray-50 rounded-lg border border-gray-200">
2110
+ <BuilderLikeRenderer blocks={(message as any).props.blocks} />
2111
+ </div>
2112
+ ) : null}
2113
+
2114
+ {!hasStreamingSlot && message.files?.totalCount > 0 ? (
2115
+ <div className="mt-3 p-3 bg-gray-50 rounded-lg border border-gray-200">
2116
+ <FilesList uploaded files={message.files.data} />
2117
+ </div>
2118
+ ) : null}
2119
+ </div>
2120
+
2121
+ {/* Action buttons on hover - Only show for non-system messages */}
2122
+ {/* {!isSystemMessage && (
2123
+ <div className="flex-shrink-0 mt-1">
2124
+ <div className="opacity-0 group-hover/message:opacity-100 transition-opacity duration-200 flex space-x-1">
2125
+ <button className="p-1 hover:bg-gray-200 rounded transition-colors">
2126
+ <svg
2127
+ className="w-3 h-3 text-gray-400"
2128
+ fill="none"
2129
+ stroke="currentColor"
2130
+ viewBox="0 0 24 24"
2131
+ >
2132
+ <path
2133
+ strokeLinecap="round"
2134
+ strokeLinejoin="round"
2135
+ strokeWidth={2}
2136
+ d="M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.367 2.684 3 3 0 00-5.367-2.684z"
2137
+ />
2138
+ </svg>
2139
+ </button>
2140
+ <button className="p-1 hover:bg-gray-200 rounded transition-colors">
2141
+ <svg
2142
+ className="w-3 h-3 text-gray-400"
2143
+ fill="none"
2144
+ stroke="currentColor"
2145
+ viewBox="0 0 24 24"
2146
+ >
2147
+ <path
2148
+ strokeLinecap="round"
2149
+ strokeLinejoin="round"
2150
+ strokeWidth={2}
2151
+ d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"
2152
+ />
2153
+ </svg>
2154
+ </button>
2155
+ </div>
2156
+ </div>
2157
+ )} */}
2158
+ </div>
2159
+ {showTimestamp ? (
2160
+ <div className="text-[10px] text-gray-500 mt-1 text-right">{formatTime(message.createdAt)}</div>
2161
+ ) : null}
2162
+ </div>
2163
+ );
2164
+ };
2165
+
2166
+ export const ModernMessageGroupComponent: React.FC<ModernMessageGroupProps> = ({
2167
+ messages,
2168
+ currentUser,
2169
+ showAuthorName = false,
2170
+ showAvatar = false,
2171
+ showTimestamp = false,
2172
+ onOpen,
2173
+ onMessageClick,
2174
+ isDesktopView = false,
2175
+ isSmallScreen = false,
2176
+ sandboxErrors = [],
2177
+ currentFiles = {},
2178
+ onFixError,
2179
+ showCopyDownloadOnCodeBlock = false,
2180
+ }) => {
2181
+ // Inject CSS styles for HTML content
2182
+ useInjectStyles();
2183
+
2184
+ // Filter out non-message items (like date strings)
2185
+ const actualMessages = messages.filter((msg) => typeof msg !== 'string') as IPost[];
2186
+
2187
+ // Group messages by user and time
2188
+ const messageGroups = groupMessagesByUserAndTime(actualMessages);
2189
+
2190
+ return (
2191
+ <div className={`min-h-fit ${isDesktopView ? 'space-y-6' : isSmallScreen ? 'space-y-4' : 'space-y-5'}`}>
2192
+ {messageGroups.map((group, groupIndex) => {
2193
+ const author = group[0]?.author;
2194
+ return (
2195
+ <ModernMessageGroup
2196
+ key={`group-${groupIndex}-${group[0]?.id}`}
2197
+ author={author}
2198
+ messages={group}
2199
+ currentUser={currentUser}
2200
+ onOpen={onOpen}
2201
+ onMessageClick={onMessageClick}
2202
+ isDesktopView={isDesktopView}
2203
+ isSmallScreen={isSmallScreen}
2204
+ showAuthorName={showAuthorName}
2205
+ showAvatar={showAvatar}
2206
+ showTimestamp={showTimestamp}
2207
+ showCopyDownloadOnCodeBlock={showCopyDownloadOnCodeBlock}
2208
+ />
2209
+ );
2210
+ })}
2211
+
2212
+ {sandboxErrors?.map((error) => (
2213
+ <div key={error.id} className="px-2">
2214
+ <ErrorFixCard
2215
+ error={error}
2216
+ onFixError={onFixError || (() => Promise.resolve())}
2217
+ currentFiles={currentFiles}
2218
+ isFixing={false}
2219
+ />
2220
+ </div>
2221
+ ))}
2222
+ </div>
2223
+ );
2224
+ };