@swisper.ai/web-chat-ui 0.3.0 → 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.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "React components for the Swisper chat: messages, composer and cards",
5
5
  "keywords": [
6
6
  "react",
@@ -80,6 +80,7 @@
80
80
  "lexical": "^0.46.0",
81
81
  "mdast": "^3.0.0",
82
82
  "mime": "^4.1.0",
83
+ "motion": "^12.23.22",
83
84
  "nanoid": "^5.1.16",
84
85
  "react-intersection-observer": "9.16.0",
85
86
  "rehype-sanitize": "^6.0.0",
@@ -5,6 +5,7 @@ import {
5
5
  ChatThinkingProcessContent,
6
6
  ChatThinkingProcessContentItem,
7
7
  ChatThinkingProcessTrigger,
8
+ ChatThinkingProcessTriggerArrow,
8
9
  ChatThinkingProcessTriggerIcon,
9
10
  ChatThinkingProcessTriggerLabel,
10
11
  } from '../../chat-thinking-process';
@@ -23,7 +24,9 @@ export function ToolSteps({ steps }: ToolStepsProps) {
23
24
  </ChatThinkingProcessTriggerIcon>
24
25
  <ChatThinkingProcessTriggerLabel>
25
26
  {`Used ${steps.length} ${steps.length === 1 ? 'tool' : 'tools'}`}
26
- </ChatThinkingProcessTriggerLabel> </ChatThinkingProcessTrigger>
27
+ </ChatThinkingProcessTriggerLabel>
28
+ <ChatThinkingProcessTriggerArrow />
29
+ </ChatThinkingProcessTrigger>
27
30
  <ChatThinkingProcessContent>
28
31
  {steps.map((step) => (
29
32
  <ChatThinkingProcessContentItem key={step}>{step}</ChatThinkingProcessContentItem>
@@ -1,13 +1,14 @@
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) and a list of steps, each with an optional logo, with a shimmering label while the model is still thinking. Parts: ChatThinkingProcessTrigger, ChatThinkingProcessTriggerIcon, ChatThinkingProcessTriggerLabel, ChatThinkingProcessContent, ChatThinkingProcessContentItem, ChatThinkingProcessContentItemIcon.",
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,",
8
8
  " ChatThinkingProcessTrigger,",
9
9
  " ChatThinkingProcessTriggerIcon,",
10
10
  " ChatThinkingProcessTriggerLabel,",
11
+ " ChatThinkingProcessTriggerArrow,",
11
12
  " ChatThinkingProcessContent,",
12
13
  " ChatThinkingProcessContentItem,",
13
14
  " ChatThinkingProcessContentItemIcon,",
@@ -17,6 +18,7 @@
17
18
  " <ChatThinkingProcessTrigger>",
18
19
  " <ChatThinkingProcessTriggerIcon />",
19
20
  " <ChatThinkingProcessTriggerLabel />",
21
+ " <ChatThinkingProcessTriggerArrow />",
20
22
  " </ChatThinkingProcessTrigger>",
21
23
  " <ChatThinkingProcessContent>",
22
24
  " <ChatThinkingProcessContentItem>",
@@ -33,11 +35,10 @@
33
35
  "avoidWhen": [
34
36
  "A plain wait with no steps to show — use ui/spinner",
35
37
  "Collapsible content that is not the assistant's process (settings, FAQs, details) — use ui/collapsible",
36
- "The answer itself — render it with web-chat-ui/markdown-viewer in the message content",
37
- "Deprecated — leave out ChatThinkingProcessTriggerArrow; it stays only so existing imports keep compiling"
38
+ "The answer itself — render it with web-chat-ui/markdown-viewer in the message content"
38
39
  ],
39
40
  "uxPrinciples": [
40
- "The answer is the point: the process stays collapsed by default and shows only its trigger until expanded.",
41
+ "The answer is the point: the process stays collapsed by default and only previews its latest step while it is live.",
41
42
  "The label reports state: what is happening while streaming, what was done afterwards ('Used 3 tools')."
42
43
  ],
43
44
  "accessibility": {
@@ -54,7 +55,7 @@
54
55
  "aria": [
55
56
  "The trigger is a Radix Collapsible trigger: a <button> with aria-expanded and aria-controls pointing at the steps",
56
57
  "ChatThinkingProcessTriggerArrow is aria-hidden",
57
- "No live region: new steps are not announced"
58
+ "No live region: new steps and the streaming preview are not announced"
58
59
  ],
59
60
  "focus": [
60
61
  "One tab stop, the trigger; focus stays on it when it toggles",
@@ -65,18 +66,18 @@
65
66
  "states": [
66
67
  "collapsed",
67
68
  "expanded",
68
- "streaming (collapsed)",
69
+ "streaming (collapsed, previewing the latest step)",
69
70
  "streaming (expanded)"
70
71
  ],
71
72
  "rules": [
72
73
  "Uncontrolled by default and collapsed on first render (defaultOpen=false, unlike ui/collapsible); pass open with onOpenChange to control it",
73
- "isStreaming=true marks the model as still thinking: the trigger label shimmers",
74
- "Steps show only when expanded, streaming or not; collapsed, only the trigger shows",
74
+ "isStreaming=true marks the model as still thinking: the trigger label shimmers and, while collapsed, the content previews the last step",
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",
75
76
  "Expanded, the children of ChatThinkingProcessContent are listed under the label, indented to line up with its text",
76
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",
77
- "Deprecated — leave out ChatThinkingProcessTriggerArrow; it stays only so existing imports keep compiling, and still rotates 180° when expanded",
78
- "ChatThinkingProcessContent takes a class per element it renders: className (outer wrapper) and itemsClassName (the expanded list of steps)",
79
- "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-item, -content-item-icon",
78
+ "ChatThinkingProcessTriggerArrow rotates 180° when expanded",
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",
80
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:",
81
82
  "Other props on ChatThinkingProcessContent go to the expanded list of steps",
82
83
  "A step's content can be any node, including streamed text that grows as it arrives"
@@ -88,6 +89,7 @@
88
89
  "web-chat-ui/ChatThinkingProcessTrigger",
89
90
  "web-chat-ui/ChatThinkingProcessTriggerIcon",
90
91
  "web-chat-ui/ChatThinkingProcessTriggerLabel",
92
+ "web-chat-ui/ChatThinkingProcessTriggerArrow",
91
93
  "web-chat-ui/ChatThinkingProcessContent",
92
94
  "web-chat-ui/ChatThinkingProcessContentItem",
93
95
  "web-chat-ui/ChatThinkingProcessContentItemIcon",
@@ -97,7 +99,7 @@
97
99
  "step text"
98
100
  ],
99
101
  "avoidCombinations": [
100
- "Children of ChatThinkingProcessContent other than ChatThinkingProcessContentItem — each child is a step",
102
+ "Children of ChatThinkingProcessContent other than ChatThinkingProcessContentItem — each child is a step and the preview uses the last one",
101
103
  "Placing it after the answer content — it belongs above web-chat-ui/ChatMessageContent in the assistant's message",
102
104
  "Interactive controls inside steps — the steps are a read-only log"
103
105
  ],
@@ -117,12 +119,17 @@
117
119
  {
118
120
  "condition": "The model is still thinking and no answer text has arrived",
119
121
  "decision": "Set isStreaming on ChatThinkingProcess and keep it collapsed",
120
- "reason": "The shimmer shows progress without expanding the full log"
122
+ "reason": "The shimmer and the latest-step preview show progress without expanding the full log"
121
123
  },
122
124
  {
123
125
  "condition": "Thinking has finished",
124
126
  "decision": "Set isStreaming={false} and change the label to a summary of the steps",
125
- "reason": "The label is the only state cue screen readers get"
127
+ "reason": "The preview hides when not streaming, and the label is the only state cue screen readers get"
128
+ },
129
+ {
130
+ "condition": "The latest-step preview would repeat content shown elsewhere",
131
+ "decision": "Pass hasLastMessagePreview={false} to ChatThinkingProcessContent",
132
+ "reason": "It switches off the collapsed preview while keeping the expandable list"
126
133
  }
127
134
  ],
128
135
  "relatedComponents": [
@@ -1,6 +1,6 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite';
2
2
  import type { ReactNode } from 'react';
3
- import { expect, fn } from 'storybook/test';
3
+ import { expect, fn, waitFor } from 'storybook/test';
4
4
 
5
5
  import { BrainIcon, SearchIcon, ToolIcon } from '@swisper.ai/icons';
6
6
  import { ImagePlaceholder } from '@swisper.ai/ui/storybook';
@@ -53,7 +53,8 @@ const meta: Meta<typeof ChatThinkingProcess> = {
53
53
  argTypes: {
54
54
  isStreaming: {
55
55
  control: 'boolean',
56
- description: 'Set while the model is still thinking: shimmers the trigger label.',
56
+ description:
57
+ 'Set while the model is still thinking: shimmers the trigger label and, when collapsed, previews the latest step.',
57
58
  table: { defaultValue: { summary: 'false' } },
58
59
  },
59
60
  defaultOpen: {
@@ -72,7 +73,7 @@ const meta: Meta<typeof ChatThinkingProcess> = {
72
73
  children: {
73
74
  control: false,
74
75
  description:
75
- 'A `ChatThinkingProcessTrigger` (icon, label) followed by a `ChatThinkingProcessContent` with the steps.',
76
+ 'A `ChatThinkingProcessTrigger` (icon, label, arrow) followed by a `ChatThinkingProcessContent` with the steps.',
76
77
  },
77
78
  className: {
78
79
  control: 'text',
@@ -99,7 +100,9 @@ export const Default: Story = {
99
100
  </ChatThinkingProcessTriggerIcon>
100
101
  <ChatThinkingProcessTriggerLabel>
101
102
  Used {EXPENSE_STEPS.length} tools
102
- </ChatThinkingProcessTriggerLabel> </ChatThinkingProcessTrigger>
103
+ </ChatThinkingProcessTriggerLabel>
104
+ <ChatThinkingProcessTriggerArrow />
105
+ </ChatThinkingProcessTrigger>
103
106
 
104
107
  <ChatThinkingProcessContent>
105
108
  {EXPENSE_STEPS.map((step) => (
@@ -119,7 +122,9 @@ export const WithItemIcons: Story = {
119
122
  <ChatThinkingProcessTriggerIcon>
120
123
  <ToolIcon />
121
124
  </ChatThinkingProcessTriggerIcon>
122
- <ChatThinkingProcessTriggerLabel>Mobility tool execution</ChatThinkingProcessTriggerLabel> </ChatThinkingProcessTrigger>
125
+ <ChatThinkingProcessTriggerLabel>Mobility tool execution</ChatThinkingProcessTriggerLabel>
126
+ <ChatThinkingProcessTriggerArrow />
127
+ </ChatThinkingProcessTrigger>
123
128
 
124
129
  <ChatThinkingProcessContent>
125
130
  <ChatThinkingProcessContentItem>
@@ -139,7 +144,29 @@ export const WithItemIcons: Story = {
139
144
  ),
140
145
  };
141
146
 
142
- /** Still thinking: the label shimmers, and the steps show only once expanded. */
147
+ /** Still thinking with the preview switched off: the label shimmers, and the steps show only once expanded. */
148
+ export const WithoutPreview: Story = {
149
+ args: { isStreaming: true },
150
+ render: (args) => (
151
+ <ChatThinkingProcess {...args}>
152
+ <ChatThinkingProcessTrigger>
153
+ <ChatThinkingProcessTriggerIcon>
154
+ <BrainIcon />
155
+ </ChatThinkingProcessTriggerIcon>
156
+ <ChatThinkingProcessTriggerLabel>Thinking…</ChatThinkingProcessTriggerLabel>
157
+ <ChatThinkingProcessTriggerArrow />
158
+ </ChatThinkingProcessTrigger>
159
+
160
+ <ChatThinkingProcessContent hasLastMessagePreview={false}>
161
+ {EXPENSE_STEPS.slice(0, 2).map((step) => (
162
+ <ChatThinkingProcessContentItem key={step}>{step}</ChatThinkingProcessContentItem>
163
+ ))}
164
+ </ChatThinkingProcessContent>
165
+ </ChatThinkingProcess>
166
+ ),
167
+ };
168
+
169
+ /** Still thinking: the label shimmers and the latest step is previewed under the collapsed trigger. */
143
170
  export const Streaming: Story = {
144
171
  args: { isStreaming: true },
145
172
  render: (args) => (
@@ -148,7 +175,9 @@ export const Streaming: Story = {
148
175
  <ChatThinkingProcessTriggerIcon>
149
176
  <BrainIcon />
150
177
  </ChatThinkingProcessTriggerIcon>
151
- <ChatThinkingProcessTriggerLabel>Thinking…</ChatThinkingProcessTriggerLabel> </ChatThinkingProcessTrigger>
178
+ <ChatThinkingProcessTriggerLabel>Thinking…</ChatThinkingProcessTriggerLabel>
179
+ <ChatThinkingProcessTriggerArrow />
180
+ </ChatThinkingProcessTrigger>
152
181
 
153
182
  <ChatThinkingProcessContent>
154
183
  {EXPENSE_STEPS.slice(0, 2).map((step) => (
@@ -173,7 +202,9 @@ export const StreamingWithContent: Story = {
173
202
  </ChatThinkingProcessTriggerIcon>
174
203
  <ChatThinkingProcessTriggerLabel>
175
204
  {isStreaming ? 'Thinking…' : 'Used 2 tools'}
176
- </ChatThinkingProcessTriggerLabel> </ChatThinkingProcessTrigger>
205
+ </ChatThinkingProcessTriggerLabel>
206
+ <ChatThinkingProcessTriggerArrow />
207
+ </ChatThinkingProcessTrigger>
177
208
  <ChatThinkingProcessContent>
178
209
  <ChatThinkingProcessContentItem>Connecting to mailbox…</ChatThinkingProcessContentItem>
179
210
  <ChatThinkingProcessContentItem className="whitespace-pre-wrap">
@@ -193,19 +224,22 @@ export const DefaultOpenAndClose: Story = {
193
224
  play: async ({ args, canvas, userEvent, step }) => {
194
225
  const trigger = canvas.getByRole('button', { name: 'Used 4 tools' });
195
226
 
196
- await step('Starts collapsed with no step', async () => {
227
+ await step('Starts collapsed with no step and no preview', async () => {
197
228
  await expect(trigger).toHaveAttribute('aria-expanded', 'false');
198
- for (const text of EXPENSE_STEPS) {
199
- await expect(canvas.queryByText(text)).toBeNull();
200
- }
229
+ await expect(canvas.queryByText(EXPENSE_STEPS[0])).toBeNull();
230
+ // The last step stays mounted for the preview, which only shows while streaming.
231
+ await expect(canvas.getByText(EXPENSE_STEPS[3])).not.toBeVisible();
201
232
  });
202
233
 
203
234
  await step('Expands to every step', async () => {
204
235
  await userEvent.click(trigger);
205
236
  await expect(trigger).toHaveAttribute('aria-expanded', 'true');
206
- for (const text of EXPENSE_STEPS) {
237
+ for (const text of EXPENSE_STEPS.slice(0, 3)) {
207
238
  await expect(canvas.getByText(text)).toBeVisible();
208
239
  }
240
+ await expect(
241
+ canvas.getAllByText(EXPENSE_STEPS[3]).filter((copy) => copy.checkVisibility()),
242
+ ).toHaveLength(1);
209
243
  await expect(args.onOpenChange).toHaveBeenLastCalledWith(true);
210
244
  });
211
245
 
@@ -248,8 +282,8 @@ export const DefaultKeyboard: Story = {
248
282
  },
249
283
  };
250
284
 
251
- /** While streaming, a collapsed process shows no step until it is expanded. */
252
- export const StreamingHidesSteps: Story = {
285
+ /** While streaming, the collapsed process previews its last step and drops the preview once expanded. */
286
+ export const StreamingPreview: Story = {
253
287
  ...Streaming,
254
288
  tags: ['e2e', '!autodocs'],
255
289
  args: { isStreaming: true, onOpenChange: fn() },
@@ -257,23 +291,50 @@ export const StreamingHidesSteps: Story = {
257
291
  const trigger = canvas.getByRole('button', { name: 'Thinking…' });
258
292
  const [firstStep, lastStep] = EXPENSE_STEPS;
259
293
 
260
- await step('Collapsed: no step is rendered', async () => {
294
+ await step('Collapsed: only the last step shows, as the preview', async () => {
261
295
  await expect(trigger).toHaveAttribute('aria-expanded', 'false');
296
+ // The preview fades in.
297
+ await waitFor(() => expect(canvas.getByText(lastStep)).toBeVisible());
262
298
  await expect(canvas.queryByText(firstStep)).toBeNull();
263
- await expect(canvas.queryByText(lastStep)).toBeNull();
264
299
  });
265
300
 
266
- await step('Expanded: each step shows once', async () => {
301
+ await step('Expanded: the full list replaces the preview', async () => {
267
302
  await userEvent.click(trigger);
268
303
  await expect(canvas.getByText(firstStep)).toBeVisible();
269
- await expect(canvas.getByText(lastStep)).toBeVisible();
304
+ const lastStepCopies = canvas.getAllByText(lastStep);
305
+ await expect(lastStepCopies).toHaveLength(2);
306
+ await expect(
307
+ lastStepCopies.filter((copy) => copy.checkVisibility({ opacityProperty: true })),
308
+ ).toHaveLength(1);
270
309
  });
271
310
 
272
- await step('Collapsed again: no step is rendered', async () => {
311
+ await step('Collapsed again: the preview is back', async () => {
273
312
  await userEvent.click(trigger);
313
+ await expect(canvas.queryByText(firstStep)).toBeNull();
314
+ await expect(canvas.getByText(lastStep)).toBeVisible();
315
+ });
316
+ },
317
+ };
318
+
319
+ /** With the preview off, a streaming process shows no step until it is expanded. */
320
+ export const WithoutPreviewHidesSteps: Story = {
321
+ ...WithoutPreview,
322
+ tags: ['e2e', '!autodocs'],
323
+ args: { isStreaming: true, onOpenChange: fn() },
324
+ play: async ({ canvas, userEvent, step }) => {
325
+ const trigger = canvas.getByRole('button', { name: 'Thinking…' });
326
+ const [firstStep, lastStep] = EXPENSE_STEPS;
327
+
328
+ await step('Collapsed: no step is rendered', async () => {
274
329
  await expect(canvas.queryByText(firstStep)).toBeNull();
275
330
  await expect(canvas.queryByText(lastStep)).toBeNull();
276
331
  });
332
+
333
+ await step('Expanded: each step shows once', async () => {
334
+ await userEvent.click(trigger);
335
+ await expect(canvas.getByText(firstStep)).toBeVisible();
336
+ await expect(canvas.getByText(lastStep)).toBeVisible();
337
+ });
277
338
  },
278
339
  };
279
340
 
@@ -289,7 +350,9 @@ export const Examples: Story = {
289
350
  <ChatThinkingProcessTriggerIcon>
290
351
  <BrainIcon />
291
352
  </ChatThinkingProcessTriggerIcon>
292
- <ChatThinkingProcessTriggerLabel>Thinking…</ChatThinkingProcessTriggerLabel> </ChatThinkingProcessTrigger>
353
+ <ChatThinkingProcessTriggerLabel>Thinking…</ChatThinkingProcessTriggerLabel>
354
+ <ChatThinkingProcessTriggerArrow />
355
+ </ChatThinkingProcessTrigger>
293
356
  <ChatThinkingProcessContent>
294
357
  {EXPENSE_STEPS.slice(0, 2).map((step) => (
295
358
  <ChatThinkingProcessContentItem key={step}>{step}</ChatThinkingProcessContentItem>
@@ -310,7 +373,9 @@ export const Examples: Story = {
310
373
  <ChatThinkingProcessTriggerIcon>
311
374
  <BrainIcon />
312
375
  </ChatThinkingProcessTriggerIcon>
313
- <ChatThinkingProcessTriggerLabel>Reasoned for 12s</ChatThinkingProcessTriggerLabel> </ChatThinkingProcessTrigger>
376
+ <ChatThinkingProcessTriggerLabel>Reasoned for 12s</ChatThinkingProcessTriggerLabel>
377
+ <ChatThinkingProcessTriggerArrow />
378
+ </ChatThinkingProcessTrigger>
314
379
  <ChatThinkingProcessContent>
315
380
  <ChatThinkingProcessContentItem>{AGENT_REASONING}</ChatThinkingProcessContentItem>
316
381
  </ChatThinkingProcessContent>
@@ -326,10 +391,14 @@ export const Examples: Story = {
326
391
  interface ChatThinkingProcessPlaygroundProps
327
392
  extends
328
393
  Omit<ChatThinkingProcessProps, 'children'>,
329
- Pick<ChatThinkingProcessContentProps, 'itemsClassName'> {
394
+ Pick<
395
+ ChatThinkingProcessContentProps,
396
+ 'itemsClassName' | 'previewClassName' | 'hasLastMessagePreview'
397
+ > {
330
398
  label: string;
331
399
  icon: ReactNode;
332
400
  stepCount: number;
401
+ hasArrow: boolean;
333
402
  hasItemIcons: boolean;
334
403
  }
335
404
 
@@ -338,7 +407,10 @@ function ChatThinkingProcessPlayground({
338
407
  icon,
339
408
  stepCount,
340
409
  itemsClassName,
410
+ previewClassName,
341
411
  defaultOpen,
412
+ hasArrow,
413
+ hasLastMessagePreview,
342
414
  hasItemIcons,
343
415
  ...rest
344
416
  }: ChatThinkingProcessPlaygroundProps) {
@@ -348,9 +420,14 @@ function ChatThinkingProcessPlayground({
348
420
  <ChatThinkingProcessTrigger>
349
421
  {icon && <ChatThinkingProcessTriggerIcon>{icon}</ChatThinkingProcessTriggerIcon>}
350
422
  <ChatThinkingProcessTriggerLabel>{label}</ChatThinkingProcessTriggerLabel>
423
+ {hasArrow && <ChatThinkingProcessTriggerArrow />}
351
424
  </ChatThinkingProcessTrigger>
352
425
 
353
- <ChatThinkingProcessContent itemsClassName={itemsClassName}>
426
+ <ChatThinkingProcessContent
427
+ itemsClassName={itemsClassName}
428
+ previewClassName={previewClassName}
429
+ hasLastMessagePreview={hasLastMessagePreview}
430
+ >
354
431
  {EXPENSE_STEPS.slice(0, stepCount).map((step) => (
355
432
  <ChatThinkingProcessContentItem key={step}>
356
433
  {hasItemIcons && (
@@ -366,7 +443,7 @@ function ChatThinkingProcessPlayground({
366
443
  );
367
444
  }
368
445
 
369
- /** Every supported part at once, with each part and prop of the root and the content on the Controls panel. */
446
+ /** Every part at once, with each part and prop of the root and the content on the Controls panel. */
370
447
  export const Playground: StoryObj<typeof ChatThinkingProcessPlayground> = {
371
448
  tags: ['!autodocs'],
372
449
  args: {
@@ -375,6 +452,8 @@ export const Playground: StoryObj<typeof ChatThinkingProcessPlayground> = {
375
452
  stepCount: EXPENSE_STEPS.length,
376
453
  isStreaming: true,
377
454
  defaultOpen: false,
455
+ hasArrow: true,
456
+ hasLastMessagePreview: true,
378
457
  hasItemIcons: false,
379
458
  onOpenChange: fn(),
380
459
  },
@@ -399,6 +478,12 @@ export const Playground: StoryObj<typeof ChatThinkingProcessPlayground> = {
399
478
  control: { type: 'number', min: 0, max: EXPENSE_STEPS.length },
400
479
  description: 'Number of `ChatThinkingProcessContentItem` steps.',
401
480
  },
481
+ hasArrow: { control: 'boolean', description: 'Renders `ChatThinkingProcessTriggerArrow`.' },
482
+ hasLastMessagePreview: {
483
+ control: 'boolean',
484
+ description:
485
+ '`hasLastMessagePreview` on `ChatThinkingProcessContent`: previews the last step while streaming and collapsed.',
486
+ },
402
487
  hasItemIcons: {
403
488
  control: 'boolean',
404
489
  description: 'Renders a `ChatThinkingProcessContentItemIcon` in each step.',
@@ -407,6 +492,11 @@ export const Playground: StoryObj<typeof ChatThinkingProcessPlayground> = {
407
492
  control: 'text',
408
493
  description: '`itemsClassName` on `ChatThinkingProcessContent`: the expanded list of steps.',
409
494
  },
495
+ previewClassName: {
496
+ control: 'text',
497
+ description:
498
+ '`previewClassName` on `ChatThinkingProcessContent`: the preview of the last step.',
499
+ },
410
500
  },
411
501
  render: (args) => <ChatThinkingProcessPlayground {...args} />,
412
502
  };
@@ -1,4 +1,5 @@
1
- import { forwardRef, type ComponentProps, type ReactNode } from 'react';
1
+ import { AnimatePresence, motion } from 'motion/react';
2
+ import React, { forwardRef, type ComponentProps, type ReactNode, useMemo } from 'react';
2
3
 
3
4
  import {
4
5
  Collapsible,
@@ -13,7 +14,7 @@ import { cn } from '@swisper.ai/web-core';
13
14
  export interface ChatThinkingProcessProps extends Omit<CollapsibleProps, 'isDisabled'> {
14
15
  children: ReactNode;
15
16
  className?: string;
16
- /** The model is still thinking: the label shimmers. */
17
+ /** The model is still thinking: the label shimmers and, while collapsed, the last step is previewed. */
17
18
  isStreaming?: boolean;
18
19
  }
19
20
 
@@ -50,7 +51,7 @@ export interface ChatThinkingProcessTriggerProps extends ComponentProps<'button'
50
51
  isLoading?: boolean;
51
52
  }
52
53
 
53
- /** The button that expands and collapses the steps; holds the icon and the label. */
54
+ /** The button that expands and collapses the steps; holds the icon, the label and the arrow. */
54
55
  export function ChatThinkingProcessTrigger({
55
56
  children,
56
57
  className,
@@ -141,11 +142,7 @@ export interface ChatThinkingProcessTriggerArrowProps extends ComponentProps<'sp
141
142
  className?: string;
142
143
  }
143
144
 
144
- /**
145
- * The chevron after the label; points up while the steps are expanded. Hidden from assistive tech.
146
- *
147
- * @deprecated The trigger no longer shows an arrow; leave it out. Kept so existing imports compile.
148
- */
145
+ /** The chevron after the label; points up while the steps are expanded. Hidden from assistive tech. */
149
146
  export function ChatThinkingProcessTriggerArrow({
150
147
  className,
151
148
  ...rest
@@ -166,25 +163,51 @@ export function ChatThinkingProcessTriggerArrow({
166
163
 
167
164
  export interface ChatThinkingProcessContentProps extends ComponentProps<'div'> {
168
165
  children: ReactNode;
169
- /** Classes for the outer wrapper, which holds the list of steps. */
166
+ /** Classes for the outer wrapper, which holds the preview and the list of steps. */
170
167
  className?: string;
171
168
  /** Classes for the expanded list of steps. */
172
169
  itemsClassName?: string;
170
+ /** Classes for the faded preview of the last step. */
171
+ previewClassName?: string;
172
+ /** Previews the last step while the root is streaming and collapsed. */
173
+ hasLastMessagePreview?: boolean;
173
174
  }
174
175
 
175
- /** The steps, listed under the label once expanded. Nothing shows while collapsed. */
176
+ /**
177
+ * The steps, listed under the label once expanded. The last one is previewed while the root is
178
+ * streaming and collapsed.
179
+ */
176
180
  export function ChatThinkingProcessContent({
177
181
  children,
178
182
  className,
179
183
  itemsClassName,
184
+ previewClassName,
185
+ hasLastMessagePreview = true,
180
186
  ...rest
181
187
  }: ChatThinkingProcessContentProps) {
188
+ const { lastItemContent, lastItemIndex } = useMemo(() => {
189
+ const childrenArray = React.Children.toArray(children);
190
+ const lastItemContent = childrenArray.at(-1);
191
+ const lastItemIndex = String(childrenArray.length);
192
+
193
+ return { lastItemContent, lastItemIndex };
194
+ }, [children]);
195
+
182
196
  return (
183
197
  <div
184
198
  data-slot="chat-thinking-process-content"
185
199
  data-testid="chat-thinking-process-content"
200
+ data-preview={hasLastMessagePreview}
186
201
  className={cn('pl-[28px]', className)}
187
202
  >
203
+ {hasLastMessagePreview && lastItemContent && (
204
+ <AnimatePresence mode="wait">
205
+ <ChatThinkingProcessContentPreview contentId={lastItemIndex} className={previewClassName}>
206
+ {lastItemContent}
207
+ </ChatThinkingProcessContentPreview>
208
+ </AnimatePresence>
209
+ )}
210
+
188
211
  <CollapsibleContent
189
212
  data-slot="chat-thinking-process-content-items"
190
213
  data-testid="chat-thinking-process-content-items"
@@ -197,6 +220,38 @@ export function ChatThinkingProcessContent({
197
220
  );
198
221
  }
199
222
 
223
+ export interface ChatThinkingProcessContentPreviewProps {
224
+ children: ReactNode;
225
+ className?: string;
226
+ contentId: string;
227
+ }
228
+
229
+ export function ChatThinkingProcessContentPreview({
230
+ children,
231
+ className,
232
+ contentId,
233
+ }: ChatThinkingProcessContentPreviewProps) {
234
+ return (
235
+ <motion.div
236
+ key={contentId}
237
+ data-slot="chat-thinking-process-content-preview"
238
+ data-testid="chat-thinking-process-content-preview"
239
+ initial={{ opacity: 0 }}
240
+ animate={{ opacity: 0.7 }}
241
+ exit={{ opacity: 0 }}
242
+ transition={{ duration: 0.25, ease: 'easeOut' }}
243
+ className={cn(
244
+ 'group-data-[streaming=false]/thinking-process:hidden',
245
+ 'group-data-[state=open]/thinking-process:hidden',
246
+ 'pt-2',
247
+ className,
248
+ )}
249
+ >
250
+ {children}
251
+ </motion.div>
252
+ );
253
+ }
254
+
200
255
  export interface ChatThinkingProcessContentItemProps extends ComponentProps<'div'> {
201
256
  children: ReactNode;
202
257
  className?: string;
@@ -26,6 +26,7 @@ import {
26
26
  ChatThinkingProcessContent,
27
27
  ChatThinkingProcessContentItem,
28
28
  ChatThinkingProcessTrigger,
29
+ ChatThinkingProcessTriggerArrow,
29
30
  ChatThinkingProcessTriggerIcon,
30
31
  ChatThinkingProcessTriggerLabel,
31
32
  } from '../components/chat-thinking-process';
@@ -488,9 +489,13 @@ function AgentToolCall({ step, isRunning }: AgentToolCallProps) {
488
489
  {' · '}
489
490
  {isRunning ? 'Running…' : isStopped ? 'Stopped' : step.summary}
490
491
  </ChatThinkingProcessTriggerLabel>
492
+ <ChatThinkingProcessTriggerArrow />
491
493
  </ChatThinkingProcessTrigger>
492
494
 
493
- <ChatThinkingProcessContent itemsClassName="font-ibm-plex-mono whitespace-pre-wrap">
495
+ <ChatThinkingProcessContent
496
+ hasLastMessagePreview={false}
497
+ itemsClassName="font-ibm-plex-mono whitespace-pre-wrap"
498
+ >
494
499
  {step.lines.map((line, index) => (
495
500
  <ChatThinkingProcessContentItem key={index} className="text-xs not-italic">
496
501
  {line}
@@ -31,6 +31,7 @@ import {
31
31
  ChatThinkingProcessContent,
32
32
  ChatThinkingProcessContentItem,
33
33
  ChatThinkingProcessTrigger,
34
+ ChatThinkingProcessTriggerArrow,
34
35
  ChatThinkingProcessTriggerIcon,
35
36
  ChatThinkingProcessTriggerLabel,
36
37
  } from '../components/chat-thinking-process';
@@ -341,7 +342,9 @@ function ChatbotTurn({ turn, pending }: ChatbotTurnProps) {
341
342
  {isThinking
342
343
  ? 'Thinking…'
343
344
  : `Used ${tools.length} ${tools.length === 1 ? 'tool' : 'tools'}`}
344
- </ChatThinkingProcessTriggerLabel> </ChatThinkingProcessTrigger>
345
+ </ChatThinkingProcessTriggerLabel>
346
+ <ChatThinkingProcessTriggerArrow />
347
+ </ChatThinkingProcessTrigger>
345
348
  <ChatThinkingProcessContent>
346
349
  {tools.map((step) => (
347
350
  <ChatThinkingProcessContentItem key={step}>{step}</ChatThinkingProcessContentItem>
@@ -70,7 +70,8 @@ stream in.
70
70
  - **`ChatThreadGroup`**: one question and its answer; `groupId` tells history apart from new messages.
71
71
  - **`ChatMessage`, `ChatMessageContent`**: a question bubble aligned to the end, or an answer at full
72
72
  width.
73
- - **`ChatThinkingProcess`**: the tools the assistant ran, listed once expanded.
73
+ - **`ChatThinkingProcess`**: the tools the assistant ran. While thinking, the collapsed trigger
74
+ previews the latest step.
74
75
  - **`MarkdownViewer`**: renders the model's Markdown, with a caret while it streams.
75
76
  - **`ChatMessageToolbar`**: timestamp and actions under an answer, shown on hover through
76
77
  `ChatMessageActions`.