@swisper.ai/web-chat-ui 0.2.15 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swisper.ai/web-chat-ui",
3
- "version": "0.2.15",
3
+ "version": "0.3.1",
4
4
  "description": "React components for the Swisper chat: messages, composer and cards",
5
5
  "keywords": [
6
6
  "react",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "../../../../int-eslint-config/schemas/component.schema.json",
3
3
  "component": "chat-thinking-process",
4
- "purpose": "Collapsible disclosure of the assistant's reasoning or tool-use steps above its answer: a trigger (icon, label, chevron) and a timeline of steps, with a shimmering label and a preview of the latest step while the model is still thinking. Parts: ChatThinkingProcessTrigger, ChatThinkingProcessTriggerIcon, ChatThinkingProcessTriggerLabel, ChatThinkingProcessTriggerArrow, ChatThinkingProcessContent, ChatThinkingProcessContentItem.",
4
+ "purpose": "Collapsible disclosure of the assistant's reasoning or tool-use steps above its answer: a trigger (icon, label, chevron) and a list of steps, each with an optional logo, with a shimmering label and a preview of the latest step while the model is still thinking. Parts: ChatThinkingProcessTrigger, ChatThinkingProcessTriggerIcon, ChatThinkingProcessTriggerLabel, ChatThinkingProcessTriggerArrow, ChatThinkingProcessContent, ChatThinkingProcessContentItem, ChatThinkingProcessContentItemIcon.",
5
5
  "anatomy": [
6
6
  "import {",
7
7
  " ChatThinkingProcess,",
@@ -11,6 +11,7 @@
11
11
  " ChatThinkingProcessTriggerArrow,",
12
12
  " ChatThinkingProcessContent,",
13
13
  " ChatThinkingProcessContentItem,",
14
+ " ChatThinkingProcessContentItemIcon,",
14
15
  "} from '@swisper.ai/web-chat-ui';",
15
16
  "",
16
17
  "<ChatThinkingProcess>",
@@ -20,7 +21,9 @@
20
21
  " <ChatThinkingProcessTriggerArrow />",
21
22
  " </ChatThinkingProcessTrigger>",
22
23
  " <ChatThinkingProcessContent>",
23
- " <ChatThinkingProcessContentItem />",
24
+ " <ChatThinkingProcessContentItem>",
25
+ " <ChatThinkingProcessContentItemIcon />",
26
+ " </ChatThinkingProcessContentItem>",
24
27
  " </ChatThinkingProcessContent>",
25
28
  "</ChatThinkingProcess>"
26
29
  ],
@@ -42,7 +45,8 @@
42
45
  "required": [
43
46
  "ChatThinkingProcessTriggerLabel must contain text: it is the trigger button's accessible name",
44
47
  "Change the label text when thinking ends ('Thinking…' → 'Used 3 tools'); the shimmer alone does not tell assistive tech the state changed",
45
- "Keep each step's text self-contained; the timeline dots and connectors are hidden from assistive tech"
48
+ "Keep each step's text self-contained",
49
+ "A logo image in ChatThinkingProcessContentItemIcon needs an alt naming the tool, because the step's text may not name it"
46
50
  ],
47
51
  "keyboard": [
48
52
  "Tab focuses the trigger button",
@@ -50,7 +54,7 @@
50
54
  ],
51
55
  "aria": [
52
56
  "The trigger is a Radix Collapsible trigger: a <button> with aria-expanded and aria-controls pointing at the steps",
53
- "ChatThinkingProcessTriggerArrow and the timeline markers are aria-hidden",
57
+ "ChatThinkingProcessTriggerArrow is aria-hidden",
54
58
  "No live region: new steps and the streaming preview are not announced"
55
59
  ],
56
60
  "focus": [
@@ -69,12 +73,13 @@
69
73
  "Uncontrolled by default and collapsed on first render (defaultOpen=false, unlike ui/collapsible); pass open with onOpenChange to control it",
70
74
  "isStreaming=true marks the model as still thinking: the trigger label shimmers and, while collapsed, the content previews the last step",
71
75
  "The preview shows the last child of ChatThinkingProcessContent, faded, and cross-fades each time a new step is added; it is hidden when expanded or not streaming. hasLastMessagePreview=false turns it off",
72
- "Expanded, every child of ChatThinkingProcessContent becomes a timeline row with a dot, joined to the next row by a line; the last row has no connector",
76
+ "Expanded, the children of ChatThinkingProcessContent are listed under the label, indented to line up with its text",
77
+ "ChatThinkingProcessContentItemIcon sits before a step's text at a fixed 14px height; a logo image keeps its own width, so logos of different widths do not line up the text",
73
78
  "ChatThinkingProcessTriggerArrow rotates 180° when expanded",
74
- "ChatThinkingProcessContent takes a class per element it renders: className (outer wrapper), itemsClassName (the expanded list of steps), rowClassName (each timeline row), markerClassName (the dot), connectorClassName (the line to the next dot) and previewClassName (the streaming preview)",
75
- "Every part takes a className, merged last so it replaces the part's own classes, and sets a data-slot: chat-thinking-process, -trigger, -trigger-icon, -trigger-label, -trigger-arrow, -content, -content-items, -content-row, -content-marker, -content-connector, -content-preview, -content-item",
79
+ "ChatThinkingProcessContent takes a class per element it renders: className (outer wrapper), itemsClassName (the expanded list of steps) and previewClassName (the streaming preview)",
80
+ "Every part takes a className, merged last so it replaces the part's own classes, and sets a data-slot: chat-thinking-process, -trigger, -trigger-icon, -trigger-label, -trigger-arrow, -content, -content-items, -content-preview, -content-item, -content-item-icon",
76
81
  "The root carries the state as data-state (open / closed) and data-streaming (true / false); style a part from it with group-data-[state=open]/thinking-process: or group-data-[streaming=true]/thinking-process:",
77
- "Other props on ChatThinkingProcessContent go to the expanded list of steps, not to its rows",
82
+ "Other props on ChatThinkingProcessContent go to the expanded list of steps",
78
83
  "A step's content can be any node, including streamed text that grows as it arrives"
79
84
  ]
80
85
  },
@@ -87,12 +92,14 @@
87
92
  "web-chat-ui/ChatThinkingProcessTriggerArrow",
88
93
  "web-chat-ui/ChatThinkingProcessContent",
89
94
  "web-chat-ui/ChatThinkingProcessContentItem",
95
+ "web-chat-ui/ChatThinkingProcessContentItemIcon",
90
96
  "icon (in ChatThinkingProcessTriggerIcon)",
97
+ "logo image or icon (in ChatThinkingProcessContentItemIcon)",
91
98
  "text label",
92
99
  "step text"
93
100
  ],
94
101
  "avoidCombinations": [
95
- "Children of ChatThinkingProcessContent other than ChatThinkingProcessContentItem — each child becomes a timeline row and the preview uses the last one",
102
+ "Children of ChatThinkingProcessContent other than ChatThinkingProcessContentItem — each child is a step and the preview uses the last one",
96
103
  "Placing it after the answer content — it belongs above web-chat-ui/ChatMessageContent in the assistant's message",
97
104
  "Interactive controls inside steps — the steps are a read-only log"
98
105
  ],
@@ -129,7 +136,6 @@
129
136
  "ui/collapsible",
130
137
  "web-chat-ui/chat-message",
131
138
  "web-chat-ui/markdown-viewer",
132
- "ui/spinner",
133
- "ui/timeline"
139
+ "ui/spinner"
134
140
  ]
135
141
  }
@@ -3,6 +3,7 @@ import type { ReactNode } from 'react';
3
3
  import { expect, fn, waitFor } from 'storybook/test';
4
4
 
5
5
  import { BrainIcon, SearchIcon, ToolIcon } from '@swisper.ai/icons';
6
+ import { ImagePlaceholder } from '@swisper.ai/ui/storybook';
6
7
 
7
8
  import { ParentBlock } from '../../__storybook__/parent-block';
8
9
  import { useStreamingMarkdown } from '../../utils/use-streaming-markdown';
@@ -19,6 +20,7 @@ import {
19
20
  ChatThinkingProcess,
20
21
  ChatThinkingProcessContent,
21
22
  ChatThinkingProcessContentItem,
23
+ ChatThinkingProcessContentItemIcon,
22
24
  ChatThinkingProcessTrigger,
23
25
  ChatThinkingProcessTriggerArrow,
24
26
  ChatThinkingProcessTriggerIcon,
@@ -37,6 +39,7 @@ const meta: Meta<typeof ChatThinkingProcess> = {
37
39
  ChatThinkingProcessTriggerArrow,
38
40
  ChatThinkingProcessContent,
39
41
  ChatThinkingProcessContentItem,
42
+ ChatThinkingProcessContentItemIcon,
40
43
  },
41
44
  parameters: { layout: 'padded' },
42
45
  tags: ['autodocs'],
@@ -110,6 +113,37 @@ export const Default: Story = {
110
113
  ),
111
114
  };
112
115
 
116
+ /** Expanded steps that each open with the logo of the tool they used. Logos keep their own width. */
117
+ export const WithItemIcons: Story = {
118
+ args: { defaultOpen: true },
119
+ render: (args) => (
120
+ <ChatThinkingProcess {...args}>
121
+ <ChatThinkingProcessTrigger>
122
+ <ChatThinkingProcessTriggerIcon>
123
+ <ToolIcon />
124
+ </ChatThinkingProcessTriggerIcon>
125
+ <ChatThinkingProcessTriggerLabel>Mobility tool execution</ChatThinkingProcessTriggerLabel>
126
+ <ChatThinkingProcessTriggerArrow />
127
+ </ChatThinkingProcessTrigger>
128
+
129
+ <ChatThinkingProcessContent>
130
+ <ChatThinkingProcessContentItem>
131
+ <ChatThinkingProcessContentItemIcon>
132
+ <ImagePlaceholder className="h-[14px] w-[128px] overflow-hidden" />
133
+ </ChatThinkingProcessContentItemIcon>
134
+ Searching return trains to Winterthur
135
+ </ChatThinkingProcessContentItem>
136
+ <ChatThinkingProcessContentItem>
137
+ <ChatThinkingProcessContentItemIcon>
138
+ <ImagePlaceholder className="h-[14px] w-[48px] overflow-hidden" />
139
+ </ChatThinkingProcessContentItemIcon>
140
+ Searching hotels in Interlaken
141
+ </ChatThinkingProcessContentItem>
142
+ </ChatThinkingProcessContent>
143
+ </ChatThinkingProcess>
144
+ ),
145
+ };
146
+
113
147
  /** Still thinking with the preview switched off: the label shimmers, and the steps show only once expanded. */
114
148
  export const WithoutPreview: Story = {
115
149
  args: { isStreaming: true },
@@ -359,17 +393,13 @@ interface ChatThinkingProcessPlaygroundProps
359
393
  Omit<ChatThinkingProcessProps, 'children'>,
360
394
  Pick<
361
395
  ChatThinkingProcessContentProps,
362
- | 'itemsClassName'
363
- | 'rowClassName'
364
- | 'markerClassName'
365
- | 'connectorClassName'
366
- | 'previewClassName'
367
- | 'hasLastMessagePreview'
396
+ 'itemsClassName' | 'previewClassName' | 'hasLastMessagePreview'
368
397
  > {
369
398
  label: string;
370
399
  icon: ReactNode;
371
400
  stepCount: number;
372
401
  hasArrow: boolean;
402
+ hasItemIcons: boolean;
373
403
  }
374
404
 
375
405
  function ChatThinkingProcessPlayground({
@@ -377,13 +407,11 @@ function ChatThinkingProcessPlayground({
377
407
  icon,
378
408
  stepCount,
379
409
  itemsClassName,
380
- rowClassName,
381
- markerClassName,
382
- connectorClassName,
383
410
  previewClassName,
384
411
  defaultOpen,
385
412
  hasArrow,
386
413
  hasLastMessagePreview,
414
+ hasItemIcons,
387
415
  ...rest
388
416
  }: ChatThinkingProcessPlaygroundProps) {
389
417
  return (
@@ -397,14 +425,18 @@ function ChatThinkingProcessPlayground({
397
425
 
398
426
  <ChatThinkingProcessContent
399
427
  itemsClassName={itemsClassName}
400
- rowClassName={rowClassName}
401
- markerClassName={markerClassName}
402
- connectorClassName={connectorClassName}
403
428
  previewClassName={previewClassName}
404
429
  hasLastMessagePreview={hasLastMessagePreview}
405
430
  >
406
431
  {EXPENSE_STEPS.slice(0, stepCount).map((step) => (
407
- <ChatThinkingProcessContentItem key={step}>{step}</ChatThinkingProcessContentItem>
432
+ <ChatThinkingProcessContentItem key={step}>
433
+ {hasItemIcons && (
434
+ <ChatThinkingProcessContentItemIcon>
435
+ <ImagePlaceholder className="h-[14px] w-[48px] overflow-hidden" />
436
+ </ChatThinkingProcessContentItemIcon>
437
+ )}
438
+ {step}
439
+ </ChatThinkingProcessContentItem>
408
440
  ))}
409
441
  </ChatThinkingProcessContent>
410
442
  </ChatThinkingProcess>
@@ -422,6 +454,7 @@ export const Playground: StoryObj<typeof ChatThinkingProcessPlayground> = {
422
454
  defaultOpen: false,
423
455
  hasArrow: true,
424
456
  hasLastMessagePreview: true,
457
+ hasItemIcons: false,
425
458
  onOpenChange: fn(),
426
459
  },
427
460
  argTypes: {
@@ -451,23 +484,14 @@ export const Playground: StoryObj<typeof ChatThinkingProcessPlayground> = {
451
484
  description:
452
485
  '`hasLastMessagePreview` on `ChatThinkingProcessContent`: previews the last step while streaming and collapsed.',
453
486
  },
487
+ hasItemIcons: {
488
+ control: 'boolean',
489
+ description: 'Renders a `ChatThinkingProcessContentItemIcon` in each step.',
490
+ },
454
491
  itemsClassName: {
455
492
  control: 'text',
456
493
  description: '`itemsClassName` on `ChatThinkingProcessContent`: the expanded list of steps.',
457
494
  },
458
- rowClassName: {
459
- control: 'text',
460
- description: '`rowClassName` on `ChatThinkingProcessContent`: each timeline row.',
461
- },
462
- markerClassName: {
463
- control: 'text',
464
- description: '`markerClassName` on `ChatThinkingProcessContent`: the dot of each step.',
465
- },
466
- connectorClassName: {
467
- control: 'text',
468
- description:
469
- '`connectorClassName` on `ChatThinkingProcessContent`: the line between two dots.',
470
- },
471
495
  previewClassName: {
472
496
  control: 'text',
473
497
  description:
@@ -34,7 +34,7 @@ export const ChatThinkingProcess = forwardRef<HTMLDivElement, ChatThinkingProces
34
34
  data-slot="chat-thinking-process"
35
35
  data-testid="chat-thinking-process"
36
36
  data-streaming={isStreaming}
37
- className={cn('group/thinking-process', 'flex flex-col', className)}
37
+ className={cn('group/thinking-process', 'flex flex-col py-6', className)}
38
38
  >
39
39
  {children}
40
40
  </div>
@@ -61,7 +61,7 @@ export function ChatThinkingProcessTrigger({
61
61
  <CollapsibleTrigger
62
62
  data-slot="chat-thinking-process-trigger"
63
63
  data-testid="chat-thinking-process-trigger"
64
- className={cn('flex w-full items-center gap-4', 'cursor-pointer text-left', className)}
64
+ className={cn('flex w-full items-center gap-8', 'cursor-pointer text-left', className)}
65
65
  {...rest}
66
66
  >
67
67
  {children}
@@ -94,7 +94,12 @@ export function ChatThinkingProcessTriggerIcon({
94
94
  <span
95
95
  data-slot="chat-thinking-process-trigger-icon"
96
96
  data-testid="chat-thinking-process-trigger-icon"
97
- className={cn('inline-flex shrink-0 items-center justify-center', className)}
97
+ className={cn(
98
+ 'inline-flex size-20 shrink-0 items-center justify-center',
99
+ 'text-layout-foreground-light',
100
+ '[&>svg]:size-20',
101
+ className,
102
+ )}
98
103
  {...rest}
99
104
  >
100
105
  {children}
@@ -116,12 +121,11 @@ export function ChatThinkingProcessTriggerLabel({
116
121
  return (
117
122
  <Typography
118
123
  asChild
119
- variant="body-sm"
124
+ variant="body-small-low"
120
125
  data-slot="chat-thinking-process-trigger-label"
121
126
  data-testid="chat-thinking-process-trigger-label"
122
127
  className={cn(
123
- 'text-text-secondary',
124
- 'font-semibold',
128
+ 'text-layout-foreground-light',
125
129
  'group-data-[streaming=true]/thinking-process:mask-[linear-gradient(-60deg,#000_30%,rgba(0,0,0,0.2),#192029_70%)]',
126
130
  'group-data-[streaming=true]/thinking-process:mask-size-[300%_100%]',
127
131
  'group-data-[streaming=true]/thinking-process:mask-right',
@@ -147,7 +151,11 @@ export function ChatThinkingProcessTriggerArrow({
147
151
  <CollapsibleChevron
148
152
  data-slot="chat-thinking-process-trigger-arrow"
149
153
  data-testid="chat-thinking-process-trigger-arrow"
150
- className={cn('items-center justify-center text-text-secondary', 'size-16', className)}
154
+ className={cn(
155
+ 'items-center justify-center text-layout-foreground-light',
156
+ 'size-16',
157
+ className,
158
+ )}
151
159
  {...rest}
152
160
  />
153
161
  );
@@ -159,12 +167,6 @@ export interface ChatThinkingProcessContentProps extends ComponentProps<'div'> {
159
167
  className?: string;
160
168
  /** Classes for the expanded list of steps. */
161
169
  itemsClassName?: string;
162
- /** Classes for each timeline row: the marker column and the step beside it. */
163
- rowClassName?: string;
164
- /** Classes for the dot that marks each step. */
165
- markerClassName?: string;
166
- /** Classes for the line that joins a step's dot to the next one. */
167
- connectorClassName?: string;
168
170
  /** Classes for the faded preview of the last step. */
169
171
  previewClassName?: string;
170
172
  /** Previews the last step while the root is streaming and collapsed. */
@@ -172,16 +174,13 @@ export interface ChatThinkingProcessContentProps extends ComponentProps<'div'> {
172
174
  }
173
175
 
174
176
  /**
175
- * The steps. Each child becomes a timeline row in the expanded list, and the last child is
176
- * previewed while the root is streaming and collapsed.
177
+ * The steps, listed under the label once expanded. The last one is previewed while the root is
178
+ * streaming and collapsed.
177
179
  */
178
180
  export function ChatThinkingProcessContent({
179
181
  children,
180
182
  className,
181
183
  itemsClassName,
182
- rowClassName,
183
- markerClassName,
184
- connectorClassName,
185
184
  previewClassName,
186
185
  hasLastMessagePreview = true,
187
186
  ...rest
@@ -199,7 +198,7 @@ export function ChatThinkingProcessContent({
199
198
  data-slot="chat-thinking-process-content"
200
199
  data-testid="chat-thinking-process-content"
201
200
  data-preview={hasLastMessagePreview}
202
- className={cn('pt-8', className)}
201
+ className={cn('pl-[28px]', className)}
203
202
  >
204
203
  {hasLastMessagePreview && lastItemContent && (
205
204
  <AnimatePresence mode="wait">
@@ -212,44 +211,10 @@ export function ChatThinkingProcessContent({
212
211
  <CollapsibleContent
213
212
  data-slot="chat-thinking-process-content-items"
214
213
  data-testid="chat-thinking-process-content-items"
215
- className={cn('flex flex-col', itemsClassName)}
214
+ className={cn('flex flex-col gap-4 pt-2', itemsClassName)}
216
215
  {...rest}
217
216
  >
218
- {React.Children.map(children, (child) => {
219
- return (
220
- <div
221
- data-slot="chat-thinking-process-content-row"
222
- className={cn(
223
- 'relative flex gap-8 text-text-secondary text-sm last:pb-0',
224
- 'pl-8',
225
- 'last:[&>div:first-child>span:last-child]:hidden',
226
- rowClassName,
227
- )}
228
- >
229
- <div
230
- className="relative flex w-8 shrink-0 flex-col items-center self-stretch"
231
- aria-hidden
232
- >
233
- <span
234
- data-slot="chat-thinking-process-content-marker"
235
- className={cn(
236
- 'mt-[7px] size-[6px] shrink-0 rounded-full bg-text-secondary',
237
- markerClassName,
238
- )}
239
- />
240
- <span
241
- data-slot="chat-thinking-process-content-connector"
242
- className={cn(
243
- 'absolute top-[16px] bottom-[-4px] left-1/2 w-px -translate-x-1/2 bg-component-divider',
244
- connectorClassName,
245
- )}
246
- />
247
- </div>
248
-
249
- <div className="min-w-0 flex-1 pb-8">{child}</div>
250
- </div>
251
- );
252
- })}
217
+ {children}
253
218
  </CollapsibleContent>
254
219
  </div>
255
220
  );
@@ -278,7 +243,7 @@ export function ChatThinkingProcessContentPreview({
278
243
  className={cn(
279
244
  'group-data-[streaming=false]/thinking-process:hidden',
280
245
  'group-data-[state=open]/thinking-process:hidden',
281
- 'px-4',
246
+ 'pt-2',
282
247
  className,
283
248
  )}
284
249
  >
@@ -292,20 +257,49 @@ export interface ChatThinkingProcessContentItemProps extends ComponentProps<'div
292
257
  className?: string;
293
258
  }
294
259
 
295
- /** One step of the process: text, or any node such as streamed Markdown. */
260
+ /** One step of the process: text, or any node such as streamed Markdown, after an optional icon. */
296
261
  export function ChatThinkingProcessContentItem({
297
262
  children,
298
263
  className,
299
264
  ...rest
300
265
  }: ChatThinkingProcessContentItemProps) {
301
266
  return (
302
- <div
267
+ <Typography
268
+ asChild
269
+ variant="body-small-low"
303
270
  data-slot="chat-thinking-process-content-item"
304
271
  data-testid="chat-thinking-process-content-item"
305
- className={cn('text-text-secondary text-sm', className)}
272
+ className={cn('flex items-center gap-4 italic text-layout-foreground-subtle', className)}
273
+ >
274
+ <div {...rest}>{children}</div>
275
+ </Typography>
276
+ );
277
+ }
278
+
279
+ export interface ChatThinkingProcessContentItemIconProps extends ComponentProps<'span'> {
280
+ children: ReactNode;
281
+ className?: string;
282
+ }
283
+
284
+ /** The logo or icon before a step's text: which tool the step used. The height is fixed; a logo's width follows its image. */
285
+ export function ChatThinkingProcessContentItemIcon({
286
+ children,
287
+ className,
288
+ ...rest
289
+ }: ChatThinkingProcessContentItemIconProps) {
290
+ return (
291
+ <span
292
+ data-slot="chat-thinking-process-content-item-icon"
293
+ data-testid="chat-thinking-process-content-item-icon"
294
+ className={cn(
295
+ 'inline-flex h-[14px] shrink-0 items-center justify-center',
296
+ '[&>img]:h-full [&>img]:w-auto',
297
+ '[&>svg]:size-[14px]',
298
+ className,
299
+ )}
306
300
  {...rest}
307
301
  >
308
302
  {children}
309
- </div>
303
+ </span>
310
304
  );
311
305
  }
@@ -6,4 +6,5 @@ export {
6
6
  ChatThinkingProcessTriggerArrow,
7
7
  ChatThinkingProcessContent,
8
8
  ChatThinkingProcessContentItem,
9
+ ChatThinkingProcessContentItemIcon,
9
10
  } from './chat-thinking-process';
@@ -497,7 +497,7 @@ function AgentToolCall({ step, isRunning }: AgentToolCallProps) {
497
497
  itemsClassName="font-ibm-plex-mono whitespace-pre-wrap"
498
498
  >
499
499
  {step.lines.map((line, index) => (
500
- <ChatThinkingProcessContentItem key={index} className="text-xs">
500
+ <ChatThinkingProcessContentItem key={index} className="text-xs not-italic">
501
501
  {line}
502
502
  </ChatThinkingProcessContentItem>
503
503
  ))}