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

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.
@@ -1,5 +1,4 @@
1
- import { AnimatePresence, motion } from 'motion/react';
2
- import React, { forwardRef, type ComponentProps, type ReactNode, useMemo } from 'react';
1
+ import { forwardRef, type ComponentProps, type ReactNode } from 'react';
3
2
 
4
3
  import {
5
4
  Collapsible,
@@ -14,7 +13,7 @@ import { cn } from '@swisper.ai/web-core';
14
13
  export interface ChatThinkingProcessProps extends Omit<CollapsibleProps, 'isDisabled'> {
15
14
  children: ReactNode;
16
15
  className?: string;
17
- /** The model is still thinking: the label shimmers and, while collapsed, the last step is previewed. */
16
+ /** The model is still thinking: the label shimmers. */
18
17
  isStreaming?: boolean;
19
18
  }
20
19
 
@@ -34,7 +33,7 @@ export const ChatThinkingProcess = forwardRef<HTMLDivElement, ChatThinkingProces
34
33
  data-slot="chat-thinking-process"
35
34
  data-testid="chat-thinking-process"
36
35
  data-streaming={isStreaming}
37
- className={cn('group/thinking-process', 'flex flex-col', className)}
36
+ className={cn('group/thinking-process', 'flex flex-col py-6', className)}
38
37
  >
39
38
  {children}
40
39
  </div>
@@ -51,7 +50,7 @@ export interface ChatThinkingProcessTriggerProps extends ComponentProps<'button'
51
50
  isLoading?: boolean;
52
51
  }
53
52
 
54
- /** The button that expands and collapses the steps; holds the icon, the label and the arrow. */
53
+ /** The button that expands and collapses the steps; holds the icon and the label. */
55
54
  export function ChatThinkingProcessTrigger({
56
55
  children,
57
56
  className,
@@ -61,7 +60,7 @@ export function ChatThinkingProcessTrigger({
61
60
  <CollapsibleTrigger
62
61
  data-slot="chat-thinking-process-trigger"
63
62
  data-testid="chat-thinking-process-trigger"
64
- className={cn('flex w-full items-center gap-4', 'cursor-pointer text-left', className)}
63
+ className={cn('flex w-full items-center gap-8', 'cursor-pointer text-left', className)}
65
64
  {...rest}
66
65
  >
67
66
  {children}
@@ -94,7 +93,12 @@ export function ChatThinkingProcessTriggerIcon({
94
93
  <span
95
94
  data-slot="chat-thinking-process-trigger-icon"
96
95
  data-testid="chat-thinking-process-trigger-icon"
97
- className={cn('inline-flex shrink-0 items-center justify-center', className)}
96
+ className={cn(
97
+ 'inline-flex size-20 shrink-0 items-center justify-center',
98
+ 'text-layout-foreground-light',
99
+ '[&>svg]:size-20',
100
+ className,
101
+ )}
98
102
  {...rest}
99
103
  >
100
104
  {children}
@@ -116,12 +120,11 @@ export function ChatThinkingProcessTriggerLabel({
116
120
  return (
117
121
  <Typography
118
122
  asChild
119
- variant="body-sm"
123
+ variant="body-small-low"
120
124
  data-slot="chat-thinking-process-trigger-label"
121
125
  data-testid="chat-thinking-process-trigger-label"
122
126
  className={cn(
123
- 'text-text-secondary',
124
- 'font-semibold',
127
+ 'text-layout-foreground-light',
125
128
  'group-data-[streaming=true]/thinking-process:mask-[linear-gradient(-60deg,#000_30%,rgba(0,0,0,0.2),#192029_70%)]',
126
129
  'group-data-[streaming=true]/thinking-process:mask-size-[300%_100%]',
127
130
  'group-data-[streaming=true]/thinking-process:mask-right',
@@ -138,7 +141,11 @@ export interface ChatThinkingProcessTriggerArrowProps extends ComponentProps<'sp
138
141
  className?: string;
139
142
  }
140
143
 
141
- /** The chevron after the label; points up while the steps are expanded. Hidden from assistive tech. */
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
+ */
142
149
  export function ChatThinkingProcessTriggerArrow({
143
150
  className,
144
151
  ...rest
@@ -147,7 +154,11 @@ export function ChatThinkingProcessTriggerArrow({
147
154
  <CollapsibleChevron
148
155
  data-slot="chat-thinking-process-trigger-arrow"
149
156
  data-testid="chat-thinking-process-trigger-arrow"
150
- className={cn('items-center justify-center text-text-secondary', 'size-16', className)}
157
+ className={cn(
158
+ 'items-center justify-center text-layout-foreground-light',
159
+ 'size-16',
160
+ className,
161
+ )}
151
162
  {...rest}
152
163
  />
153
164
  );
@@ -155,157 +166,85 @@ export function ChatThinkingProcessTriggerArrow({
155
166
 
156
167
  export interface ChatThinkingProcessContentProps extends ComponentProps<'div'> {
157
168
  children: ReactNode;
158
- /** Classes for the outer wrapper, which holds the preview and the list of steps. */
169
+ /** Classes for the outer wrapper, which holds the list of steps. */
159
170
  className?: string;
160
171
  /** Classes for the expanded list of steps. */
161
172
  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
- /** Classes for the faded preview of the last step. */
169
- previewClassName?: string;
170
- /** Previews the last step while the root is streaming and collapsed. */
171
- hasLastMessagePreview?: boolean;
172
173
  }
173
174
 
174
- /**
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
- */
175
+ /** The steps, listed under the label once expanded. Nothing shows while collapsed. */
178
176
  export function ChatThinkingProcessContent({
179
177
  children,
180
178
  className,
181
179
  itemsClassName,
182
- rowClassName,
183
- markerClassName,
184
- connectorClassName,
185
- previewClassName,
186
- hasLastMessagePreview = true,
187
180
  ...rest
188
181
  }: ChatThinkingProcessContentProps) {
189
- const { lastItemContent, lastItemIndex } = useMemo(() => {
190
- const childrenArray = React.Children.toArray(children);
191
- const lastItemContent = childrenArray.at(-1);
192
- const lastItemIndex = String(childrenArray.length);
193
-
194
- return { lastItemContent, lastItemIndex };
195
- }, [children]);
196
-
197
182
  return (
198
183
  <div
199
184
  data-slot="chat-thinking-process-content"
200
185
  data-testid="chat-thinking-process-content"
201
- data-preview={hasLastMessagePreview}
202
- className={cn('pt-8', className)}
186
+ className={cn('pl-[28px]', className)}
203
187
  >
204
- {hasLastMessagePreview && lastItemContent && (
205
- <AnimatePresence mode="wait">
206
- <ChatThinkingProcessContentPreview contentId={lastItemIndex} className={previewClassName}>
207
- {lastItemContent}
208
- </ChatThinkingProcessContentPreview>
209
- </AnimatePresence>
210
- )}
211
-
212
188
  <CollapsibleContent
213
189
  data-slot="chat-thinking-process-content-items"
214
190
  data-testid="chat-thinking-process-content-items"
215
- className={cn('flex flex-col', itemsClassName)}
191
+ className={cn('flex flex-col gap-4 pt-2', itemsClassName)}
216
192
  {...rest}
217
193
  >
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
- })}
194
+ {children}
253
195
  </CollapsibleContent>
254
196
  </div>
255
197
  );
256
198
  }
257
199
 
258
- export interface ChatThinkingProcessContentPreviewProps {
200
+ export interface ChatThinkingProcessContentItemProps extends ComponentProps<'div'> {
259
201
  children: ReactNode;
260
202
  className?: string;
261
- contentId: string;
262
203
  }
263
204
 
264
- export function ChatThinkingProcessContentPreview({
205
+ /** One step of the process: text, or any node such as streamed Markdown, after an optional icon. */
206
+ export function ChatThinkingProcessContentItem({
265
207
  children,
266
208
  className,
267
- contentId,
268
- }: ChatThinkingProcessContentPreviewProps) {
209
+ ...rest
210
+ }: ChatThinkingProcessContentItemProps) {
269
211
  return (
270
- <motion.div
271
- key={contentId}
272
- data-slot="chat-thinking-process-content-preview"
273
- data-testid="chat-thinking-process-content-preview"
274
- initial={{ opacity: 0 }}
275
- animate={{ opacity: 0.7 }}
276
- exit={{ opacity: 0 }}
277
- transition={{ duration: 0.25, ease: 'easeOut' }}
278
- className={cn(
279
- 'group-data-[streaming=false]/thinking-process:hidden',
280
- 'group-data-[state=open]/thinking-process:hidden',
281
- 'px-4',
282
- className,
283
- )}
212
+ <Typography
213
+ asChild
214
+ variant="body-small-low"
215
+ data-slot="chat-thinking-process-content-item"
216
+ data-testid="chat-thinking-process-content-item"
217
+ className={cn('flex items-center gap-4 italic text-layout-foreground-subtle', className)}
284
218
  >
285
- {children}
286
- </motion.div>
219
+ <div {...rest}>{children}</div>
220
+ </Typography>
287
221
  );
288
222
  }
289
223
 
290
- export interface ChatThinkingProcessContentItemProps extends ComponentProps<'div'> {
224
+ export interface ChatThinkingProcessContentItemIconProps extends ComponentProps<'span'> {
291
225
  children: ReactNode;
292
226
  className?: string;
293
227
  }
294
228
 
295
- /** One step of the process: text, or any node such as streamed Markdown. */
296
- export function ChatThinkingProcessContentItem({
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. */
230
+ export function ChatThinkingProcessContentItemIcon({
297
231
  children,
298
232
  className,
299
233
  ...rest
300
- }: ChatThinkingProcessContentItemProps) {
234
+ }: ChatThinkingProcessContentItemIconProps) {
301
235
  return (
302
- <div
303
- data-slot="chat-thinking-process-content-item"
304
- data-testid="chat-thinking-process-content-item"
305
- className={cn('text-text-secondary text-sm', className)}
236
+ <span
237
+ data-slot="chat-thinking-process-content-item-icon"
238
+ data-testid="chat-thinking-process-content-item-icon"
239
+ className={cn(
240
+ 'inline-flex h-[14px] shrink-0 items-center justify-center',
241
+ '[&>img]:h-full [&>img]:w-auto',
242
+ '[&>svg]:size-[14px]',
243
+ className,
244
+ )}
306
245
  {...rest}
307
246
  >
308
247
  {children}
309
- </div>
248
+ </span>
310
249
  );
311
250
  }
@@ -6,4 +6,5 @@ export {
6
6
  ChatThinkingProcessTriggerArrow,
7
7
  ChatThinkingProcessContent,
8
8
  ChatThinkingProcessContentItem,
9
+ ChatThinkingProcessContentItemIcon,
9
10
  } from './chat-thinking-process';
@@ -26,7 +26,6 @@ import {
26
26
  ChatThinkingProcessContent,
27
27
  ChatThinkingProcessContentItem,
28
28
  ChatThinkingProcessTrigger,
29
- ChatThinkingProcessTriggerArrow,
30
29
  ChatThinkingProcessTriggerIcon,
31
30
  ChatThinkingProcessTriggerLabel,
32
31
  } from '../components/chat-thinking-process';
@@ -489,15 +488,11 @@ function AgentToolCall({ step, isRunning }: AgentToolCallProps) {
489
488
  {' · '}
490
489
  {isRunning ? 'Running…' : isStopped ? 'Stopped' : step.summary}
491
490
  </ChatThinkingProcessTriggerLabel>
492
- <ChatThinkingProcessTriggerArrow />
493
491
  </ChatThinkingProcessTrigger>
494
492
 
495
- <ChatThinkingProcessContent
496
- hasLastMessagePreview={false}
497
- itemsClassName="font-ibm-plex-mono whitespace-pre-wrap"
498
- >
493
+ <ChatThinkingProcessContent itemsClassName="font-ibm-plex-mono whitespace-pre-wrap">
499
494
  {step.lines.map((line, index) => (
500
- <ChatThinkingProcessContentItem key={index} className="text-xs">
495
+ <ChatThinkingProcessContentItem key={index} className="text-xs not-italic">
501
496
  {line}
502
497
  </ChatThinkingProcessContentItem>
503
498
  ))}
@@ -31,7 +31,6 @@ import {
31
31
  ChatThinkingProcessContent,
32
32
  ChatThinkingProcessContentItem,
33
33
  ChatThinkingProcessTrigger,
34
- ChatThinkingProcessTriggerArrow,
35
34
  ChatThinkingProcessTriggerIcon,
36
35
  ChatThinkingProcessTriggerLabel,
37
36
  } from '../components/chat-thinking-process';
@@ -342,9 +341,7 @@ function ChatbotTurn({ turn, pending }: ChatbotTurnProps) {
342
341
  {isThinking
343
342
  ? 'Thinking…'
344
343
  : `Used ${tools.length} ${tools.length === 1 ? 'tool' : 'tools'}`}
345
- </ChatThinkingProcessTriggerLabel>
346
- <ChatThinkingProcessTriggerArrow />
347
- </ChatThinkingProcessTrigger>
344
+ </ChatThinkingProcessTriggerLabel> </ChatThinkingProcessTrigger>
348
345
  <ChatThinkingProcessContent>
349
346
  {tools.map((step) => (
350
347
  <ChatThinkingProcessContentItem key={step}>{step}</ChatThinkingProcessContentItem>
@@ -70,8 +70,7 @@ 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. While thinking, the collapsed trigger
74
- previews the latest step.
73
+ - **`ChatThinkingProcess`**: the tools the assistant ran, listed once expanded.
75
74
  - **`MarkdownViewer`**: renders the model's Markdown, with a caret while it streams.
76
75
  - **`ChatMessageToolbar`**: timestamp and actions under an answer, shown on hover through
77
76
  `ChatMessageActions`.