@jsb188/ai-chat 0.0.0-stage → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +109 -2
  2. package/VERIFICATION.md +118 -0
  3. package/benchmarks/browser.mjs +204 -0
  4. package/benchmarks/streaming.mjs +89 -0
  5. package/package.json +36 -5
  6. package/src/main.ts +5 -0
  7. package/src/modules/AIChatContent.tsx +84 -0
  8. package/src/modules/AgentNoteActionsMenu.tsx +121 -0
  9. package/src/modules/AgentNoteBootstrapProgress.tsx +41 -0
  10. package/src/modules/AgentNoteItem.helpers.ts +115 -0
  11. package/src/modules/AgentNoteItem.tsx +232 -0
  12. package/src/modules/AgentNotes.constants.ts +10 -0
  13. package/src/modules/AgentNotes.helpers.ts +274 -0
  14. package/src/modules/AgentNotes.hooks.ts +449 -0
  15. package/src/modules/AgentNotes.tsx +74 -0
  16. package/src/modules/AgentNotes.types.ts +50 -0
  17. package/src/modules/AgentNotesCollection.hooks.ts +69 -0
  18. package/src/modules/AgentNotesSection.tsx +145 -0
  19. package/src/parser.ts +4 -0
  20. package/src/types/content.ts +103 -0
  21. package/src/ui/AIChatUI.css +557 -0
  22. package/src/ui/AIChatUI.tsx +816 -0
  23. package/src/ui/AgentNotesUI.tsx +375 -0
  24. package/src/ui/AgentNotesUI.types.ts +19 -0
  25. package/src/ui/ChatBlocks.tsx +92 -0
  26. package/src/ui/ChatCodeBlock.tsx +16 -0
  27. package/src/ui/ChatInline.helpers.ts +20 -0
  28. package/src/ui/ChatInline.tsx +89 -0
  29. package/src/ui/ChatTable.helpers.ts +37 -0
  30. package/src/ui/ChatTable.tsx +126 -0
  31. package/src/utils/contentIdentity.ts +108 -0
  32. package/src/utils/parseBlocks.helpers.ts +50 -0
  33. package/src/utils/parseBlocks.ts +266 -0
  34. package/src/utils/parseContent.helpers.ts +102 -0
  35. package/src/utils/parseContent.ts +33 -0
  36. package/src/utils/parseContentIncrementally.ts +46 -0
  37. package/src/utils/parseCsv.ts +99 -0
  38. package/src/utils/parseInline.helpers.ts +48 -0
  39. package/src/utils/parseInline.ts +396 -0
  40. package/src/utils/parseTable.ts +202 -0
  41. package/tests/AgentNotes.test.tsx +1672 -0
  42. package/tests/fixtures/content.ts +13 -0
  43. package/tests/parseContent.test.ts +227 -0
  44. package/tests/parseCsv.test.ts +82 -0
  45. package/tests/parseInline.test.ts +222 -0
  46. package/tests/renderContent.ssr.test.tsx +19 -0
  47. package/tests/renderContent.test.tsx +282 -0
  48. package/tests/streaming.test.ts +51 -0
  49. package/tests/streamingEquivalence.test.ts +265 -0
  50. package/tsconfig.json +16 -0
  51. package/vitest.config.ts +18 -0
@@ -0,0 +1,557 @@
1
+ /* Variables for AI Chat */
2
+
3
+ .mdy_msg {
4
+ /* This is 50% of .av_sm (old) */
5
+ /*--bubble-radius: 1.1875rem;*/
6
+
7
+ /*This is 50% of .av_df */
8
+ --bubble-ht: 44px;
9
+ --bubble-radius: 22px;
10
+ --bubble-corner-radius: 8px;
11
+
12
+ /* 42.87 */
13
+ }
14
+
15
+ /* Agent notes */
16
+
17
+ .an_item {
18
+ position: relative;
19
+ isolation: isolate;
20
+ }
21
+
22
+ .an_item:before {
23
+ content: "";
24
+ position: absolute;
25
+ inset: 0;
26
+ z-index: -1;
27
+ border-radius: inherit;
28
+ /*background-color: rgb(var(--color-assist-faded-solid));*/
29
+ /*background-color: rgba(var(--color-primary), .1);*/
30
+ /*border: solid 1px rgba(var(--color-primary), 0.2);*/
31
+ border: solid 1px var(--color-darker-light);
32
+ opacity: 0;
33
+ pointer-events: none;
34
+ transition:
35
+ opacity 0.25s ease-in-out,
36
+ inset 0.25s ease-in-out;
37
+ }
38
+
39
+ .an_item.expanded:before {
40
+ inset: -10px;
41
+ opacity: 1;
42
+ }
43
+
44
+ /* Include the expanded border's 10px outset in the clipped disclosure area. */
45
+ .an_item > .accordian_panel {
46
+ margin-inline: -10px;
47
+ }
48
+
49
+ /* Bleed through the body's 24px padding, leaving 1px for the item border. */
50
+ .an_item .mdy_msg .chat_table {
51
+ margin-inline: -23px;
52
+ }
53
+
54
+ .an_item .mdy_msg .chat_table [role="row"] > .tdcol:first-child {
55
+ padding-left: 23px;
56
+ }
57
+
58
+ .an_item .mdy_msg .chat_table [role="row"] > .tdcol:last-child {
59
+ padding-right: 23px;
60
+ }
61
+
62
+ /* Textarea */
63
+
64
+ /* Reserve the scrollbar gutter on the chat scroll area so the sticky textarea
65
+ keeps a constant width and horizontal position whether or not the message
66
+ list overflows. Without this, the loading skeleton (whose full-height mock
67
+ list always overflows) shows a scrollbar and renders the textarea slightly
68
+ narrower/shifted compared to a loaded chat that fits without one. */
69
+ .app_scr.v_top {
70
+ scrollbar-gutter: stable;
71
+ }
72
+
73
+ .cm_textarea_cnt {
74
+ position: sticky;
75
+ bottom: 0;
76
+ padding-bottom: calc(1rem + 0.5vh);
77
+ }
78
+
79
+ .cm_textarea_cnt:before {
80
+ content: "";
81
+ position: absolute;
82
+ z-index: 10;
83
+ top: -24px;
84
+ left: 0;
85
+ right: 0;
86
+ height: 24px;
87
+ background: linear-gradient(180deg, transparent, rgb(var(--color-bg)));
88
+ }
89
+
90
+ /* Single rounded pill container that wraps the (+) button, input and submit button */
91
+
92
+ .cm_textarea_body {
93
+ position: relative;
94
+ z-index: 11;
95
+ flex: 1;
96
+ flex-shrink: 0;
97
+ padding: 6px;
98
+ /* border: 1px solid var(--color-darker-soft); */
99
+ box-shadow:
100
+ 0 3px 5px rgba(0, 0, 0, 0.035),
101
+ 0 5px 12px rgba(0, 0, 0, 0.035);
102
+ border: 1px solid var(--color-darker-light);
103
+ border-radius: calc(var(--bubble-radius) + var(--rem-xsmall));
104
+ background-color: rgb(var(--color-bg));
105
+ transform: translateY(-10px);
106
+ }
107
+
108
+ .cm_textarea {
109
+ position: relative;
110
+ z-index: 31;
111
+ outline: none;
112
+ overflow-y: auto;
113
+
114
+ flex: 1;
115
+ min-width: 0;
116
+ /* IMPORTANT: If max-width is 100%, this will make word break NOT work, so you have to use "none" */
117
+ max-width: none !important;
118
+ max-height: max(200px, 20vh);
119
+ border-radius: var(--bubble-radius);
120
+ background-color: transparent;
121
+
122
+ white-space: pre-wrap;
123
+ word-wrap: break-word;
124
+ }
125
+
126
+ /* Typography */
127
+
128
+ .mdy_msg a {
129
+ color: #5B93EB;
130
+ text-decoration: underline;
131
+ }
132
+
133
+ .mdy_msg a:hover {
134
+ /*background-color: rgba(var(--color-main), .1);*/
135
+ color: #30CF94;
136
+ }
137
+
138
+ .mdy_msg h1 {
139
+ font-size: 2em;
140
+ margin-top: 1.64rem;
141
+ padding-top: 2.25rem;
142
+ padding-bottom: 1.35rem;
143
+ }
144
+
145
+ .mdy_msg h2 {
146
+ font-size: 1.75em;
147
+ margin-top: 1.4rem;
148
+ padding-top: 1.75rem;
149
+ padding-bottom: 1.1rem;
150
+ }
151
+
152
+ .mdy_msg h3 {
153
+ font-size: 1.64em;
154
+ margin-top: 1.2rem;
155
+ padding-top: 1.5rem;
156
+ padding-bottom: 1rem;
157
+ }
158
+
159
+ .mdy_msg h4 {
160
+ font-size: 1.45em;
161
+ margin-top: 1.1rem;
162
+ padding-top: 1.25rem;
163
+ padding-bottom: 0.64rem;
164
+ }
165
+
166
+ .mdy_msg h5 {
167
+ font-size: 1.25em;
168
+ margin-top: 1rem;
169
+ padding-top: 1rem;
170
+ padding-bottom: 0.5rem;
171
+ }
172
+
173
+ .mdy_msg h6 {
174
+ font-size: 1.1em;
175
+ margin-top: 1rem;
176
+ padding-top: 0.8rem;
177
+ padding-bottom: 0.35rem;
178
+ }
179
+
180
+ .mdy_msg h1:first-child,
181
+ .mdy_msg h2:first-child,
182
+ .mdy_msg h3:first-child,
183
+ .mdy_msg h4:first-child,
184
+ .mdy_msg h5:first-child,
185
+ .mdy_msg h6:first-child {
186
+ margin-top: 0;
187
+ }
188
+
189
+ .cm_textarea p:not(:last-child),
190
+ .mdy_msg p:not(:last-child),
191
+ .mdy_msg_item.other .mdy_msg {
192
+ /* margin-bottom: 1.25rem; */
193
+ margin-bottom: 0.7rem;
194
+ }
195
+
196
+ .mdy_msg.tool_call .noto_emoji {
197
+ margin-right: 0.4rem;
198
+ }
199
+
200
+ /* Sizing for non-bubbled items for AI */
201
+
202
+ .mdy_msg_item.other .mdy_msg {
203
+ line-height: 1.7;
204
+ /* padding-top: .4rem; */
205
+ /* padding-bottom: .4rem; */
206
+ padding-top: 0;
207
+ }
208
+
209
+ /* Sizing for bubbled items and textarea */
210
+
211
+ .cm_textarea,
212
+ .cm_textarea.multilined {
213
+ min-height: var(--bubble-ht);
214
+ }
215
+
216
+ .mdy_msg_item.self .mdy_msg,
217
+ .mdy_msg_item.bubble .mdy_msg,
218
+ .mdy_msg_item.self.multilined .mdy_msg,
219
+ .mdy_msg_item.bubble.multilined .mdy_msg {
220
+ min-height: var(--bubble-ht);
221
+ }
222
+
223
+ .cm_textarea,
224
+ .mdy_msg_item.self .mdy_msg,
225
+ .mdy_msg_item.bubble .mdy_msg {
226
+ padding-top: 0.53rem;
227
+ padding-bottom: 0.53rem;
228
+ transition:
229
+ padding 0.2s ease,
230
+ margin-top 0.2s ease;
231
+ }
232
+
233
+ .cm_textarea.multilined,
234
+ .mdy_msg_item.self.multilined .mdy_msg,
235
+ .mdy_msg_item.bubble.multilined .mdy_msg {
236
+ padding-top: 1.2rem;
237
+ padding-bottom: 1.2rem;
238
+ }
239
+
240
+ .mdy_msg_item.self.multilined .mdy_msg.top,
241
+ .mdy_msg_item.bubble.multilined .mdy_msg.top {
242
+ /* transform: translateY(-0.85rem); */
243
+ margin-top: -0.85rem;
244
+ }
245
+
246
+ .mdy_msg_item.self .mdy_msg,
247
+ .mdy_msg_item.bubble .mdy_msg {
248
+ padding-left: var(--rem-small);
249
+ padding-right: var(--rem-small);
250
+ }
251
+
252
+ .cm_textarea:empty:before {
253
+ content: attr(data-placeholder);
254
+ color: var(--color-text-light);
255
+ }
256
+
257
+ .cm_textarea::-webkit-scrollbar-track {
258
+ border-top-right-radius: var(--bubble-radius);
259
+ border-bottom-right-radius: var(--bubble-radius);
260
+ }
261
+
262
+ /* Attachment */
263
+
264
+ .mdy_msg_item.self .mdy_msg.attachment_file,
265
+ .mdy_msg_item.bubble .mdy_msg.attachment_file {
266
+ padding: 0;
267
+ margin-bottom: 5px;
268
+ }
269
+
270
+ .attachment_grp {
271
+ padding: 0 !important;
272
+ margin-bottom: 4px !important;
273
+ }
274
+
275
+ .attachment_btn {
276
+ border-radius: var(--bubble-corner-radius);
277
+ }
278
+
279
+ .attachment_btn:first-child {
280
+ border-top-left-radius: var(--bubble-radius);
281
+ border-bottom-left-radius: var(--bubble-radius);
282
+ }
283
+
284
+ .attachment_btn:first-child:last-child,
285
+ .attachment_btn:nth-child(2):last-child,
286
+ .attachment_btn:nth-child(3) {
287
+ border-top-right-radius: var(--bubble-radius);
288
+ }
289
+
290
+ .attachment_btn:nth-child(4) {
291
+ border-bottom-left-radius: var(--bubble-radius);
292
+ }
293
+
294
+ .attachment_btn:last-child {
295
+ border-bottom-right-radius: var(--bubble-corner-radius);
296
+ }
297
+
298
+ /* Sides of textarea */
299
+
300
+ .cm_btn {
301
+ position: relative;
302
+ z-index: 31;
303
+ width: var(--bubble-ht);
304
+ height: var(--bubble-ht);
305
+ }
306
+
307
+ /* The (+) button (left) and submit button (right) sit in the bottom corners of
308
+ the composer pill as absolute elements, so they hold their horizontal
309
+ position while the input grows. 6px matches the pill's own padding. */
310
+
311
+ .cm_btn_left,
312
+ .cm_btn_right {
313
+ position: absolute;
314
+ bottom: 6px;
315
+ z-index: 32;
316
+ }
317
+
318
+ .cm_btn_left {
319
+ left: 6px;
320
+ }
321
+
322
+ .cm_btn_right {
323
+ right: 6px;
324
+ }
325
+
326
+ /* Single line: the input reserves horizontal room on both sides so its text
327
+ never sits under the buttons. Padding transitions (see the base rule) so the
328
+ swap to the multi-line layout animates. */
329
+
330
+ .cm_textarea {
331
+ padding-left: calc(var(--bubble-ht) + 4px);
332
+ padding-right: calc(var(--bubble-ht) + 4px);
333
+ /* Animate the side padding as the input expands to the full width. */
334
+ transition: padding 0.2s ease;
335
+ }
336
+
337
+ /* Multi-line: the side padding collapses so the text spans the full width, and
338
+ the pill reserves a button row outside the scrollable input. */
339
+
340
+ .cm_textarea_body.expanded {
341
+ padding-bottom: calc(6px + var(--bubble-ht));
342
+ }
343
+
344
+ .cm_textarea_body.expanded .cm_textarea {
345
+ padding-left: 8px;
346
+ padding-right: 8px;
347
+ }
348
+
349
+ /* Message items */
350
+
351
+ .mdy_msg_item {
352
+ position: relative;
353
+ }
354
+
355
+ .mdy_msg_item .mdy_msg {
356
+ position: relative;
357
+ z-index: 2;
358
+ align-self: flex-start;
359
+ max-width: 82%;
360
+ }
361
+
362
+ /* Self messages */
363
+
364
+ .mdy_msg_item.self {
365
+ display: flex;
366
+ flex-direction: row-reverse;
367
+ }
368
+
369
+ .mdy_msg_item.self .mdy_msg,
370
+ .mdy_msg_item.bubble .mdy_msg {
371
+ margin-bottom: 2px;
372
+ border-radius: var(--bubble-corner-radius);
373
+ }
374
+
375
+ .mdy_msg_item.self .mdy_msg,
376
+ .mdy_msg_item.bubble .mdy_msg,
377
+ .cm_textarea {
378
+ /* line-height: 1.4; */
379
+ line-height: 1.7;
380
+ }
381
+
382
+ .mdy_msg_item.self .mdy_msg,
383
+ .mdy_msg_item.self_mock .mdy_msg {
384
+ border-top-left-radius: var(--bubble-radius);
385
+ border-bottom-left-radius: var(--bubble-radius);
386
+ }
387
+
388
+ .mdy_msg_item.self.active .mdy_msg.bg_self {
389
+ background: rgba(var(--color-assist), 0.15)
390
+ /*linear-gradient(180deg, rgba(var(--color-assist), 0.1), rgba(var(--color-assist), 0.15)) fixed;*/
391
+ /*linear-gradient(180deg, hsl(203.2, 93.9%, 93.5%), hsl(203.2, 93.9%, 96.4%)) fixed;*/
392
+ linear-gradient(180deg, hsl(203.2, 93.9%, 96.4%), hsl(203.2, 100%, 92.8%)) fixed;
393
+ /* color: var(--color-solid); */
394
+ }
395
+
396
+ .mdy_msg_item.self.active .mdy_msg.bg_self ::selection {
397
+ background-color: rgba(var(--color-assist), 0.4);
398
+ }
399
+
400
+ .mdy_msg_item.self.active .mdy_msg.bg_self .cl_primary {
401
+ position: relative;
402
+ color: inherit !important;
403
+ }
404
+
405
+ .theme_preview_area .mdy_msg_item.self .mdy_msg.bg_self {
406
+ background-size: 100vw 100vh;
407
+ background-position: 25% 50%;
408
+ }
409
+
410
+ .mdy_msg_item.self .mdy_msg.top,
411
+ .mdy_msg_item.self_mock .mdy_msg.top {
412
+ border-top-right-radius: var(--bubble-radius);
413
+ }
414
+
415
+ .mdy_msg_item.self .mdy_msg.bottom,
416
+ .mdy_msg_item.self_mock .mdy_msg.bottom {
417
+ border-bottom-right-radius: var(--bubble-radius);
418
+ }
419
+
420
+ /* Other's messages */
421
+
422
+ .mdy_msg_item.other,
423
+ .mdy_msg_item.bubble {
424
+ display: flex;
425
+ }
426
+
427
+ .mdy_msg_item.other .mdy_msg {
428
+ padding-left: 0.3rem;
429
+ /* .3rem + .8rem (on the left) */
430
+ padding-right: 1.1rem;
431
+ max-width: none;
432
+ }
433
+
434
+ .mdy_msg_item.other.no_avatar .mdy_msg {
435
+ /* margin-left: 100px; */
436
+ padding-left: var(--rem-small);
437
+ /* margin-left: .8rem !important; */
438
+ }
439
+
440
+ .mdy_msg_item.mocked.other .mdy_msg {
441
+ height: 30px;
442
+ min-height: 30px;
443
+ padding-bottom: 0.1rem;
444
+ margin-bottom: 0;
445
+ }
446
+
447
+ .mdy_msg_item.other .mdy_msg_opts .av.main {
448
+ position: absolute;
449
+ top: -6px;
450
+ }
451
+
452
+ /* Other's messages (bubbled) */
453
+
454
+ .mdy_msg_item.bubble .mdy_msg {
455
+ border-top-right-radius: var(--bubble-radius);
456
+ border-bottom-right-radius: var(--bubble-radius);
457
+ }
458
+
459
+ .mdy_msg_item.bubble .mdy_msg.top {
460
+ border-top-left-radius: var(--bubble-radius);
461
+ }
462
+
463
+ .mdy_msg_item.bubble .mdy_msg.bottom {
464
+ border-bottom-left-radius: var(--bubble-radius);
465
+ }
466
+
467
+ /* Message item; options with sender avatar */
468
+
469
+ .mdy_msg_opts {
470
+ position: relative;
471
+ z-index: 1;
472
+ width: var(--bubble-ht);
473
+ }
474
+
475
+ .mdy_msg_opts.cmo_hidden {
476
+ position: absolute;
477
+ left: 100%;
478
+ }
479
+
480
+ .other .mdy_msg_opts,
481
+ .bubble .mdy_msg_opts {
482
+ margin-right: var(--rem-xsmall);
483
+ }
484
+
485
+ .self .mdy_msg_opts {
486
+ margin-left: var(--rem-xsmall);
487
+ }
488
+
489
+ /* AI chat message loader; reserve the text line before the first token arrives. */
490
+
491
+ .cm_loader_cnt {
492
+ position: relative;
493
+ display: inline-block;
494
+ width: 14px;
495
+ height: 1lh;
496
+ margin-left: 10px;
497
+ vertical-align: bottom;
498
+ }
499
+
500
+ .cm_loader_cnt:first-child {
501
+ margin-left: 0;
502
+ }
503
+
504
+ .cm_response_incomplete {
505
+ vertical-align: middle;
506
+ transform: translate(4px, -3px);
507
+ }
508
+
509
+ .cm_loader {
510
+ width: 40px;
511
+ height: 40px;
512
+ position: absolute;
513
+ top: 50%;
514
+ left: 50%;
515
+ transform: translate(-50%, -50%);
516
+ }
517
+
518
+ .cm_loader::after,
519
+ .cm_loader::before {
520
+ content: "";
521
+ box-sizing: border-box;
522
+ border-radius: 50%;
523
+ position: absolute;
524
+ }
525
+
526
+ .cm_loader::before {
527
+ background: rgba(var(--color-assist), 0.64);
528
+ width: 14px;
529
+ height: 14px;
530
+ top: 13px;
531
+ left: 13px;
532
+ }
533
+
534
+ .cm_loader::after {
535
+ background: rgba(var(--color-assist), 0.4);
536
+ width: 40px;
537
+ height: 40px;
538
+ left: 0;
539
+ top: 0;
540
+ opacity: 0;
541
+ animation: anim_cm_loader 2s linear infinite;
542
+ }
543
+
544
+ @keyframes anim_cm_loader {
545
+ 0% {
546
+ transform: scale(0.35);
547
+ opacity: 0;
548
+ }
549
+ 50% {
550
+ transform: scale(0.35);
551
+ opacity: 1;
552
+ }
553
+ 100% {
554
+ transform: scale(1);
555
+ opacity: 0;
556
+ }
557
+ }