@swisper.ai/web-chat-ui 0.3.0 → 0.3.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 (32) hide show
  1. package/README.md +2 -1
  2. package/dist/components/chat-reasoning/chat-reasoning.d.ts +194 -0
  3. package/dist/components/chat-reasoning/chat-reasoning.d.ts.map +1 -0
  4. package/dist/components/chat-reasoning/chat-reasoning.stories.d.ts +38 -0
  5. package/dist/components/chat-reasoning/chat-reasoning.stories.d.ts.map +1 -0
  6. package/dist/components/chat-reasoning/index.d.ts +2 -0
  7. package/dist/components/chat-reasoning/index.d.ts.map +1 -0
  8. package/dist/components/chat-thinking-process/chat-thinking-process.d.ts +55 -18
  9. package/dist/components/chat-thinking-process/chat-thinking-process.d.ts.map +1 -1
  10. package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts +11 -6
  11. package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts.map +1 -1
  12. package/dist/components/index.d.ts +1 -0
  13. package/dist/components/index.d.ts.map +1 -1
  14. package/dist/docs/agent.stories.d.ts.map +1 -1
  15. package/dist/docs/chatbot-panel.d.ts.map +1 -1
  16. package/dist/index.css +1 -1
  17. package/dist/index.es.js +1371 -883
  18. package/dist/index.es.js.map +1 -1
  19. package/package.json +4 -3
  20. package/src/components/chat-message/__stories__/tool-steps.tsx +44 -20
  21. package/src/components/chat-reasoning/__stories__/fixtures.ts +144 -0
  22. package/src/components/chat-reasoning/chat-reasoning.json +241 -0
  23. package/src/components/chat-reasoning/chat-reasoning.stories.tsx +462 -0
  24. package/src/components/chat-reasoning/chat-reasoning.tsx +1042 -0
  25. package/src/components/chat-reasoning/index.ts +51 -0
  26. package/src/components/chat-thinking-process/chat-thinking-process.json +23 -14
  27. package/src/components/chat-thinking-process/chat-thinking-process.stories.tsx +115 -25
  28. package/src/components/chat-thinking-process/chat-thinking-process.tsx +93 -10
  29. package/src/components/index.ts +1 -0
  30. package/src/docs/agent.stories.tsx +28 -23
  31. package/src/docs/chatbot-panel.tsx +48 -22
  32. package/src/docs/chatbot.mdx +5 -4
@@ -0,0 +1,51 @@
1
+ export {
2
+ ChatReasoning,
3
+ ChatReasoningTrigger,
4
+ ChatReasoningTriggerSymbol,
5
+ ChatReasoningTriggerSymbolSwisper,
6
+ ChatReasoningTriggerLabel,
7
+ ChatReasoningTriggerArrow,
8
+ ChatReasoningSteps,
9
+ ChatReasoningStep,
10
+ ChatReasoningStepHead,
11
+ ChatReasoningStepIcon,
12
+ ChatReasoningStepIconDot,
13
+ ChatReasoningStepIconLogo,
14
+ ChatReasoningStepIconWeb,
15
+ ChatReasoningStepText,
16
+ ChatReasoningStepNotes,
17
+ ChatReasoningStepNote,
18
+ ChatReasoningStepNotePages,
19
+ ChatReasoningStepNotePageRow,
20
+ ChatReasoningStepNotePageIcon,
21
+ ChatReasoningStepNotePageTitle,
22
+ ChatReasoningStepNotePageDomain,
23
+ ChatReasoningEnd,
24
+ ChatReasoningEndIcon,
25
+ ChatReasoningEndText,
26
+ type ChatReasoningStatus,
27
+ type ChatReasoningProps,
28
+ type ChatReasoningTriggerProps,
29
+ type ChatReasoningTriggerSymbolProps,
30
+ type ChatReasoningTriggerSymbolSwisperProps,
31
+ type ChatReasoningTriggerLabelProps,
32
+ type ChatReasoningTriggerArrowProps,
33
+ type ChatReasoningStepsProps,
34
+ type ChatReasoningStepProps,
35
+ type ChatReasoningStepHeadProps,
36
+ type ChatReasoningStepIconProps,
37
+ type ChatReasoningStepIconDotProps,
38
+ type ChatReasoningStepIconLogoProps,
39
+ type ChatReasoningStepIconWebProps,
40
+ type ChatReasoningStepTextProps,
41
+ type ChatReasoningStepNotesProps,
42
+ type ChatReasoningStepNoteProps,
43
+ type ChatReasoningStepNotePagesProps,
44
+ type ChatReasoningStepNotePageRowProps,
45
+ type ChatReasoningStepNotePageIconProps,
46
+ type ChatReasoningStepNotePageTitleProps,
47
+ type ChatReasoningStepNotePageDomainProps,
48
+ type ChatReasoningEndProps,
49
+ type ChatReasoningEndIconProps,
50
+ type ChatReasoningEndTextProps,
51
+ } from './chat-reasoning';
@@ -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>",
@@ -31,13 +33,13 @@
31
33
  "Keeping the steps available but out of the way once the answer is shown"
32
34
  ],
33
35
  "avoidWhen": [
36
+ "Deprecated — use web-chat-ui/chat-reasoning for new code; ChatThinkingProcess stays only so existing imports keep compiling",
34
37
  "A plain wait with no steps to show — use ui/spinner",
35
38
  "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"
39
+ "The answer itself — render it with web-chat-ui/markdown-viewer in the message content"
38
40
  ],
39
41
  "uxPrinciples": [
40
- "The answer is the point: the process stays collapsed by default and shows only its trigger until expanded.",
42
+ "The answer is the point: the process stays collapsed by default and only previews its latest step while it is live.",
41
43
  "The label reports state: what is happening while streaming, what was done afterwards ('Used 3 tools')."
42
44
  ],
43
45
  "accessibility": {
@@ -54,7 +56,7 @@
54
56
  "aria": [
55
57
  "The trigger is a Radix Collapsible trigger: a <button> with aria-expanded and aria-controls pointing at the steps",
56
58
  "ChatThinkingProcessTriggerArrow is aria-hidden",
57
- "No live region: new steps are not announced"
59
+ "No live region: new steps and the streaming preview are not announced"
58
60
  ],
59
61
  "focus": [
60
62
  "One tab stop, the trigger; focus stays on it when it toggles",
@@ -65,18 +67,18 @@
65
67
  "states": [
66
68
  "collapsed",
67
69
  "expanded",
68
- "streaming (collapsed)",
70
+ "streaming (collapsed, previewing the latest step)",
69
71
  "streaming (expanded)"
70
72
  ],
71
73
  "rules": [
72
74
  "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",
75
+ "isStreaming=true marks the model as still thinking: the trigger label shimmers and, while collapsed, the content previews the last step",
76
+ "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
77
  "Expanded, the children of ChatThinkingProcessContent are listed under the label, indented to line up with its text",
76
78
  "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",
79
+ "ChatThinkingProcessTriggerArrow rotates 180° when expanded",
80
+ "ChatThinkingProcessContent takes a class per element it renders: className (outer wrapper), itemsClassName (the expanded list of steps) and previewClassName (the streaming preview)",
81
+ "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
82
  "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
83
  "Other props on ChatThinkingProcessContent go to the expanded list of steps",
82
84
  "A step's content can be any node, including streamed text that grows as it arrives"
@@ -88,6 +90,7 @@
88
90
  "web-chat-ui/ChatThinkingProcessTrigger",
89
91
  "web-chat-ui/ChatThinkingProcessTriggerIcon",
90
92
  "web-chat-ui/ChatThinkingProcessTriggerLabel",
93
+ "web-chat-ui/ChatThinkingProcessTriggerArrow",
91
94
  "web-chat-ui/ChatThinkingProcessContent",
92
95
  "web-chat-ui/ChatThinkingProcessContentItem",
93
96
  "web-chat-ui/ChatThinkingProcessContentItemIcon",
@@ -97,7 +100,7 @@
97
100
  "step text"
98
101
  ],
99
102
  "avoidCombinations": [
100
- "Children of ChatThinkingProcessContent other than ChatThinkingProcessContentItem — each child is a step",
103
+ "Children of ChatThinkingProcessContent other than ChatThinkingProcessContentItem — each child is a step and the preview uses the last one",
101
104
  "Placing it after the answer content — it belongs above web-chat-ui/ChatMessageContent in the assistant's message",
102
105
  "Interactive controls inside steps — the steps are a read-only log"
103
106
  ],
@@ -117,15 +120,21 @@
117
120
  {
118
121
  "condition": "The model is still thinking and no answer text has arrived",
119
122
  "decision": "Set isStreaming on ChatThinkingProcess and keep it collapsed",
120
- "reason": "The shimmer shows progress without expanding the full log"
123
+ "reason": "The shimmer and the latest-step preview show progress without expanding the full log"
121
124
  },
122
125
  {
123
126
  "condition": "Thinking has finished",
124
127
  "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"
128
+ "reason": "The preview hides when not streaming, and the label is the only state cue screen readers get"
129
+ },
130
+ {
131
+ "condition": "The latest-step preview would repeat content shown elsewhere",
132
+ "decision": "Pass hasLastMessagePreview={false} to ChatThinkingProcessContent",
133
+ "reason": "It switches off the collapsed preview while keeping the expandable list"
126
134
  }
127
135
  ],
128
136
  "relatedComponents": [
137
+ "web-chat-ui/chat-reasoning",
129
138
  "ui/collapsible",
130
139
  "web-chat-ui/chat-message",
131
140
  "web-chat-ui/markdown-viewer",
@@ -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,13 +14,15 @@ 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
 
20
21
  /**
21
22
  * Collapsible disclosure of the assistant's reasoning or tool steps. Collapsed by default; exposes
22
23
  * `data-state` (`open` / `closed`) and `data-streaming` for its parts to style from.
24
+ *
25
+ * @deprecated Use `ChatReasoning` (chat-reasoning), with `status` in place of `isStreaming`.
23
26
  */
24
27
  export const ChatThinkingProcess = forwardRef<HTMLDivElement, ChatThinkingProcessProps>(
25
28
  function ChatThinkingProcess(
@@ -50,7 +53,11 @@ export interface ChatThinkingProcessTriggerProps extends ComponentProps<'button'
50
53
  isLoading?: boolean;
51
54
  }
52
55
 
53
- /** The button that expands and collapses the steps; holds the icon and the label. */
56
+ /**
57
+ * The button that expands and collapses the steps; holds the icon, the label and the arrow.
58
+ *
59
+ * @deprecated Use `ChatReasoningTrigger`.
60
+ */
54
61
  export function ChatThinkingProcessTrigger({
55
62
  children,
56
63
  className,
@@ -83,7 +90,11 @@ export interface ChatThinkingProcessTriggerIconProps extends ComponentProps<'spa
83
90
  className?: string;
84
91
  }
85
92
 
86
- /** The icon before the label: what kind of work the process is. */
93
+ /**
94
+ * The icon before the label: what kind of work the process is.
95
+ *
96
+ * @deprecated Use `ChatReasoningTriggerSymbol`, with `ChatReasoningTriggerSymbolSwisper` inside.
97
+ */
87
98
  export function ChatThinkingProcessTriggerIcon({
88
99
  children,
89
100
  className,
@@ -111,7 +122,11 @@ export interface ChatThinkingProcessTriggerLabelProps extends ComponentProps<'sp
111
122
  className?: string;
112
123
  }
113
124
 
114
- /** The trigger's text and accessible name; shimmers while the root is streaming. */
125
+ /**
126
+ * The trigger's text and accessible name; shimmers while the root is streaming.
127
+ *
128
+ * @deprecated Use `ChatReasoningTriggerLabel`.
129
+ */
115
130
  export function ChatThinkingProcessTriggerLabel({
116
131
  children,
117
132
  className,
@@ -144,7 +159,7 @@ export interface ChatThinkingProcessTriggerArrowProps extends ComponentProps<'sp
144
159
  /**
145
160
  * The chevron after the label; points up while the steps are expanded. Hidden from assistive tech.
146
161
  *
147
- * @deprecated The trigger no longer shows an arrow; leave it out. Kept so existing imports compile.
162
+ * @deprecated Use `ChatReasoningTriggerArrow`.
148
163
  */
149
164
  export function ChatThinkingProcessTriggerArrow({
150
165
  className,
@@ -166,25 +181,53 @@ export function ChatThinkingProcessTriggerArrow({
166
181
 
167
182
  export interface ChatThinkingProcessContentProps extends ComponentProps<'div'> {
168
183
  children: ReactNode;
169
- /** Classes for the outer wrapper, which holds the list of steps. */
184
+ /** Classes for the outer wrapper, which holds the preview and the list of steps. */
170
185
  className?: string;
171
186
  /** Classes for the expanded list of steps. */
172
187
  itemsClassName?: string;
188
+ /** Classes for the faded preview of the last step. */
189
+ previewClassName?: string;
190
+ /** Previews the last step while the root is streaming and collapsed. */
191
+ hasLastMessagePreview?: boolean;
173
192
  }
174
193
 
175
- /** The steps, listed under the label once expanded. Nothing shows while collapsed. */
194
+ /**
195
+ * The steps, listed under the label once expanded. The last one is previewed while the root is
196
+ * streaming and collapsed.
197
+ *
198
+ * @deprecated Use `ChatReasoningSteps`.
199
+ */
176
200
  export function ChatThinkingProcessContent({
177
201
  children,
178
202
  className,
179
203
  itemsClassName,
204
+ previewClassName,
205
+ hasLastMessagePreview = true,
180
206
  ...rest
181
207
  }: ChatThinkingProcessContentProps) {
208
+ const { lastItemContent, lastItemIndex } = useMemo(() => {
209
+ const childrenArray = React.Children.toArray(children);
210
+ const lastItemContent = childrenArray.at(-1);
211
+ const lastItemIndex = String(childrenArray.length);
212
+
213
+ return { lastItemContent, lastItemIndex };
214
+ }, [children]);
215
+
182
216
  return (
183
217
  <div
184
218
  data-slot="chat-thinking-process-content"
185
219
  data-testid="chat-thinking-process-content"
220
+ data-preview={hasLastMessagePreview}
186
221
  className={cn('pl-[28px]', className)}
187
222
  >
223
+ {hasLastMessagePreview && lastItemContent && (
224
+ <AnimatePresence mode="wait">
225
+ <ChatThinkingProcessContentPreview contentId={lastItemIndex} className={previewClassName}>
226
+ {lastItemContent}
227
+ </ChatThinkingProcessContentPreview>
228
+ </AnimatePresence>
229
+ )}
230
+
188
231
  <CollapsibleContent
189
232
  data-slot="chat-thinking-process-content-items"
190
233
  data-testid="chat-thinking-process-content-items"
@@ -197,12 +240,48 @@ export function ChatThinkingProcessContent({
197
240
  );
198
241
  }
199
242
 
243
+ export interface ChatThinkingProcessContentPreviewProps {
244
+ children: ReactNode;
245
+ className?: string;
246
+ contentId: string;
247
+ }
248
+
249
+ export function ChatThinkingProcessContentPreview({
250
+ children,
251
+ className,
252
+ contentId,
253
+ }: ChatThinkingProcessContentPreviewProps) {
254
+ return (
255
+ <motion.div
256
+ key={contentId}
257
+ data-slot="chat-thinking-process-content-preview"
258
+ data-testid="chat-thinking-process-content-preview"
259
+ initial={{ opacity: 0 }}
260
+ animate={{ opacity: 0.7 }}
261
+ exit={{ opacity: 0 }}
262
+ transition={{ duration: 0.25, ease: 'easeOut' }}
263
+ className={cn(
264
+ 'group-data-[streaming=false]/thinking-process:hidden',
265
+ 'group-data-[state=open]/thinking-process:hidden',
266
+ 'pt-2',
267
+ className,
268
+ )}
269
+ >
270
+ {children}
271
+ </motion.div>
272
+ );
273
+ }
274
+
200
275
  export interface ChatThinkingProcessContentItemProps extends ComponentProps<'div'> {
201
276
  children: ReactNode;
202
277
  className?: string;
203
278
  }
204
279
 
205
- /** One step of the process: text, or any node such as streamed Markdown, after an optional icon. */
280
+ /**
281
+ * One step of the process: text, or any node such as streamed Markdown, after an optional icon.
282
+ *
283
+ * @deprecated Use `ChatReasoningStep` with a `ChatReasoningStepHead` and a `ChatReasoningStepText`.
284
+ */
206
285
  export function ChatThinkingProcessContentItem({
207
286
  children,
208
287
  className,
@@ -226,7 +305,11 @@ export interface ChatThinkingProcessContentItemIconProps extends ComponentProps<
226
305
  className?: string;
227
306
  }
228
307
 
229
- /** 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. */
308
+ /**
309
+ * 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.
310
+ *
311
+ * @deprecated Use `ChatReasoningStepIcon` with a `ChatReasoningStepIconDot`, `-Logo` or `-Web` inside.
312
+ */
230
313
  export function ChatThinkingProcessContentItemIcon({
231
314
  children,
232
315
  className,
@@ -17,6 +17,7 @@ export * from './chat-thread';
17
17
  export * from './chat-artifact';
18
18
  export * from './canvas-shell';
19
19
  export * from './new-chat-trigger';
20
+ export * from './chat-reasoning';
20
21
  export * from './chat-thinking-process';
21
22
  export * from './deprecated-empty-state';
22
23
  export * from './markdown-viewer';