@swisper.ai/web-chat-ui 0.3.1 → 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.
- package/README.md +2 -1
- package/dist/components/chat-reasoning/chat-reasoning.d.ts +194 -0
- package/dist/components/chat-reasoning/chat-reasoning.d.ts.map +1 -0
- package/dist/components/chat-reasoning/chat-reasoning.stories.d.ts +38 -0
- package/dist/components/chat-reasoning/chat-reasoning.stories.d.ts.map +1 -0
- package/dist/components/chat-reasoning/index.d.ts +2 -0
- package/dist/components/chat-reasoning/index.d.ts.map +1 -0
- package/dist/components/chat-thinking-process/chat-thinking-process.d.ts +34 -6
- package/dist/components/chat-thinking-process/chat-thinking-process.d.ts.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/docs/agent.stories.d.ts.map +1 -1
- package/dist/docs/chatbot-panel.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.es.js +1816 -1359
- package/dist/index.es.js.map +1 -1
- package/package.json +3 -3
- package/src/components/chat-message/__stories__/tool-steps.tsx +44 -23
- package/src/components/chat-reasoning/__stories__/fixtures.ts +144 -0
- package/src/components/chat-reasoning/chat-reasoning.json +241 -0
- package/src/components/chat-reasoning/chat-reasoning.stories.tsx +462 -0
- package/src/components/chat-reasoning/chat-reasoning.tsx +1042 -0
- package/src/components/chat-reasoning/index.ts +51 -0
- package/src/components/chat-thinking-process/chat-thinking-process.json +2 -0
- package/src/components/chat-thinking-process/chat-thinking-process.tsx +34 -6
- package/src/components/index.ts +1 -0
- package/src/docs/agent.stories.tsx +29 -29
- package/src/docs/chatbot-panel.tsx +48 -25
- package/src/docs/chatbot.mdx +5 -5
|
@@ -0,0 +1,1042 @@
|
|
|
1
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
2
|
+
import { AnimatePresence, motion, useIsPresent, useReducedMotion } from 'motion/react';
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
forwardRef,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useId,
|
|
9
|
+
useMemo,
|
|
10
|
+
useRef,
|
|
11
|
+
useState,
|
|
12
|
+
type ComponentProps,
|
|
13
|
+
type Key,
|
|
14
|
+
type ReactNode,
|
|
15
|
+
} from 'react';
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
Collapsible,
|
|
19
|
+
CollapsibleChevron,
|
|
20
|
+
CollapsibleContent,
|
|
21
|
+
CollapsibleTrigger,
|
|
22
|
+
Typography,
|
|
23
|
+
type CollapsibleProps,
|
|
24
|
+
} from '@swisper.ai/ui';
|
|
25
|
+
import { cn } from '@swisper.ai/web-core';
|
|
26
|
+
|
|
27
|
+
/** Where the work is: still going, finished, or stopped by the person. */
|
|
28
|
+
export type ChatReasoningStatus = 'running' | 'done' | 'stopped';
|
|
29
|
+
|
|
30
|
+
interface ChatReasoningContextValue {
|
|
31
|
+
status: ChatReasoningStatus;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const ChatReasoningContext = createContext<ChatReasoningContextValue>({ status: 'done' });
|
|
35
|
+
|
|
36
|
+
/** How long a line of the trigger stays up before the next one may replace it. */
|
|
37
|
+
const LINE_HOLD_MS = 1000;
|
|
38
|
+
|
|
39
|
+
// Motion values from the design's motion table (Echo DS has no motion tokens).
|
|
40
|
+
const LINE_TRANSITION = { duration: 0.28, ease: [0.4, 0, 0.2, 1] } as const;
|
|
41
|
+
const ROW_TRANSITION = { duration: 0.24, ease: [0.2, 0, 0, 1] } as const;
|
|
42
|
+
const STEP_TEXT_TRANSITION = { duration: 0.35 } as const;
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
* Keyframes, and the light sweep and pulses that need more than one property. The colours are the
|
|
46
|
+
* ct/reasoning tokens, read from their CSS variables so they follow the theme.
|
|
47
|
+
*/
|
|
48
|
+
const CHAT_REASONING_STYLES = `
|
|
49
|
+
@keyframes chat-reasoning-shimmer {
|
|
50
|
+
from { background-position: 100% 0; }
|
|
51
|
+
to { background-position: 0% 0; }
|
|
52
|
+
}
|
|
53
|
+
@keyframes chat-reasoning-symbol-turn {
|
|
54
|
+
0% { transform: rotate(0deg); }
|
|
55
|
+
55%, 100% { transform: rotate(90deg); }
|
|
56
|
+
}
|
|
57
|
+
@keyframes chat-reasoning-symbol-fade {
|
|
58
|
+
0%, 100% { opacity: 1; }
|
|
59
|
+
50% { opacity: 0.55; }
|
|
60
|
+
}
|
|
61
|
+
@keyframes chat-reasoning-pulse-dot {
|
|
62
|
+
from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ct-reasoning-mark-colour-dot-live) 45%, transparent); }
|
|
63
|
+
to { box-shadow: 0 0 0 6px transparent; }
|
|
64
|
+
}
|
|
65
|
+
@keyframes chat-reasoning-pulse-tile {
|
|
66
|
+
from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--st-colour-layout-foreground-light) 35%, transparent); }
|
|
67
|
+
to { box-shadow: 0 0 0 5px transparent; }
|
|
68
|
+
}
|
|
69
|
+
@keyframes chat-reasoning-open {
|
|
70
|
+
from { height: 0; }
|
|
71
|
+
to { height: var(--radix-collapsible-content-height); }
|
|
72
|
+
}
|
|
73
|
+
@keyframes chat-reasoning-close {
|
|
74
|
+
from { height: var(--radix-collapsible-content-height); }
|
|
75
|
+
to { height: 0; }
|
|
76
|
+
}
|
|
77
|
+
[data-slot='chat-reasoning'][data-status='running'][data-state='closed'] [data-slot='chat-reasoning-trigger-label-line'],
|
|
78
|
+
[data-slot='chat-reasoning-step'][data-live='true'] [data-slot='chat-reasoning-step-text-content'] {
|
|
79
|
+
background-image: linear-gradient(90deg, var(--ct-reasoning-row-colour-shimmer-base) 0%, var(--ct-reasoning-row-colour-shimmer-base) 40%, var(--ct-reasoning-row-colour-shimmer-highlight) 50%, var(--ct-reasoning-row-colour-shimmer-base) 60%, var(--ct-reasoning-row-colour-shimmer-base) 100%);
|
|
80
|
+
background-size: 300% 100%;
|
|
81
|
+
background-clip: text;
|
|
82
|
+
-webkit-background-clip: text;
|
|
83
|
+
color: transparent;
|
|
84
|
+
animation: chat-reasoning-shimmer 2.2s linear infinite;
|
|
85
|
+
}
|
|
86
|
+
[data-slot='chat-reasoning-step'][data-live='true'] [data-slot='chat-reasoning-step-icon-dot'] {
|
|
87
|
+
animation: chat-reasoning-pulse-dot 1.4s ease-out infinite;
|
|
88
|
+
}
|
|
89
|
+
[data-slot='chat-reasoning-step'][data-live='true'] [data-slot='chat-reasoning-step-icon-logo'],
|
|
90
|
+
[data-slot='chat-reasoning-step'][data-live='true'] [data-slot='chat-reasoning-step-icon-web'] {
|
|
91
|
+
animation: chat-reasoning-pulse-tile 1.6s ease-out infinite;
|
|
92
|
+
}
|
|
93
|
+
@media (prefers-reduced-motion: reduce) {
|
|
94
|
+
[data-slot='chat-reasoning'] [data-slot='chat-reasoning-trigger-label-line'],
|
|
95
|
+
[data-slot='chat-reasoning'] [data-slot='chat-reasoning-step-text-content'] {
|
|
96
|
+
background: none;
|
|
97
|
+
color: inherit;
|
|
98
|
+
animation: none;
|
|
99
|
+
}
|
|
100
|
+
[data-slot='chat-reasoning'] [data-slot^='chat-reasoning-step-icon-'] {
|
|
101
|
+
animation: none;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
`;
|
|
105
|
+
|
|
106
|
+
/** The key a text part animates on: `contentKey`, or the text itself when it is a string. */
|
|
107
|
+
function getContentKey(children: ReactNode, contentKey: Key | undefined) {
|
|
108
|
+
if (contentKey !== undefined) return contentKey;
|
|
109
|
+
if (typeof children === 'string' || typeof children === 'number') return String(children);
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface ChatReasoningProps extends Omit<CollapsibleProps, 'isDisabled' | 'className'> {
|
|
114
|
+
children: ReactNode;
|
|
115
|
+
className?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Where the work is. `running` turns the Swisper symbol and sweeps a light across the collapsed
|
|
118
|
+
* line; `done` and `stopped` keep it still. Defaults to `done`.
|
|
119
|
+
*/
|
|
120
|
+
status?: ChatReasoningStatus;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The reasoning row above an assistant answer and the window of steps it opens. Collapsed by
|
|
125
|
+
* default; exposes `data-state` (`open` / `closed`) and `data-status` for its parts to style from.
|
|
126
|
+
* Open, it draws the outline box; narrow (under 448px), the row grows to 44px.
|
|
127
|
+
*/
|
|
128
|
+
export const ChatReasoning = forwardRef<HTMLDivElement, ChatReasoningProps>(function ChatReasoning(
|
|
129
|
+
{ children, className, defaultOpen = false, status = 'done', ...rest },
|
|
130
|
+
ref,
|
|
131
|
+
) {
|
|
132
|
+
const value = useMemo(() => ({ status }), [status]);
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<ChatReasoningContext.Provider value={value}>
|
|
136
|
+
<Collapsible defaultOpen={defaultOpen} asChild {...rest}>
|
|
137
|
+
<div
|
|
138
|
+
ref={ref}
|
|
139
|
+
data-slot="chat-reasoning"
|
|
140
|
+
data-testid="chat-reasoning"
|
|
141
|
+
data-status={status}
|
|
142
|
+
className={cn(
|
|
143
|
+
'group/reasoning @container flex w-full min-w-0 flex-col',
|
|
144
|
+
'rounded-reasoning-window-base border border-transparent',
|
|
145
|
+
'data-[state=open]:border-reasoning-window-border',
|
|
146
|
+
className,
|
|
147
|
+
)}
|
|
148
|
+
>
|
|
149
|
+
{children}
|
|
150
|
+
<style>{CHAT_REASONING_STYLES}</style>
|
|
151
|
+
</div>
|
|
152
|
+
</Collapsible>
|
|
153
|
+
</ChatReasoningContext.Provider>
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
ChatReasoning.displayName = 'ChatReasoning';
|
|
158
|
+
|
|
159
|
+
export interface ChatReasoningTriggerProps extends ComponentProps<'button'> {
|
|
160
|
+
children: ReactNode;
|
|
161
|
+
className?: string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The row: one button that opens and closes the window. Holds the symbol, the label and the arrow. */
|
|
165
|
+
export const ChatReasoningTrigger = forwardRef<HTMLButtonElement, ChatReasoningTriggerProps>(
|
|
166
|
+
function ChatReasoningTrigger({ children, className, ...rest }, ref) {
|
|
167
|
+
return (
|
|
168
|
+
<CollapsibleTrigger
|
|
169
|
+
ref={ref}
|
|
170
|
+
data-slot="chat-reasoning-trigger"
|
|
171
|
+
data-testid="chat-reasoning-trigger"
|
|
172
|
+
className={cn(
|
|
173
|
+
'group/reasoning-trigger flex w-full min-w-0 items-center text-left',
|
|
174
|
+
'min-h-reasoning-row-height-desktop gap-reasoning-row-spacing-gap-base',
|
|
175
|
+
'px-reasoning-row-spacing-padding-horizontal-base py-reasoning-row-spacing-padding-vertical-desktop',
|
|
176
|
+
'@max-md:min-h-reasoning-row-height-mobile @max-md:py-reasoning-row-spacing-padding-vertical-mobile',
|
|
177
|
+
'rounded-reasoning-row-base group-data-[state=open]/reasoning:rounded-b-none',
|
|
178
|
+
'outline outline-transparent',
|
|
179
|
+
'hover:bg-reasoning-row-background-hover hover:outline-reasoning-row-background-hover',
|
|
180
|
+
'group-data-[state=open]/reasoning:hover:outline-transparent',
|
|
181
|
+
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary-focus-visible',
|
|
182
|
+
className,
|
|
183
|
+
)}
|
|
184
|
+
{...rest}
|
|
185
|
+
>
|
|
186
|
+
{children}
|
|
187
|
+
</CollapsibleTrigger>
|
|
188
|
+
);
|
|
189
|
+
},
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
ChatReasoningTrigger.displayName = 'ChatReasoningTrigger';
|
|
193
|
+
|
|
194
|
+
export interface ChatReasoningTriggerSymbolProps extends ComponentProps<'span'> {
|
|
195
|
+
children: ReactNode;
|
|
196
|
+
className?: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* The 16px symbol before the label, hidden from assistive tech: `ChatReasoningTriggerSymbolSwisper`
|
|
201
|
+
* while running or done, a stop icon once stopped.
|
|
202
|
+
*/
|
|
203
|
+
export function ChatReasoningTriggerSymbol({
|
|
204
|
+
children,
|
|
205
|
+
className,
|
|
206
|
+
...rest
|
|
207
|
+
}: ChatReasoningTriggerSymbolProps) {
|
|
208
|
+
return (
|
|
209
|
+
<span
|
|
210
|
+
aria-hidden
|
|
211
|
+
data-slot="chat-reasoning-trigger-symbol-wrapper"
|
|
212
|
+
className="flex shrink-0 items-center self-stretch"
|
|
213
|
+
>
|
|
214
|
+
<span
|
|
215
|
+
data-slot="chat-reasoning-trigger-symbol"
|
|
216
|
+
data-testid="chat-reasoning-trigger-symbol"
|
|
217
|
+
className={cn(
|
|
218
|
+
'flex size-16 items-center justify-center',
|
|
219
|
+
'text-reasoning-row-text group-data-[status=done]/reasoning:text-reasoning-row-icon',
|
|
220
|
+
'[&>svg]:size-16',
|
|
221
|
+
className,
|
|
222
|
+
)}
|
|
223
|
+
{...rest}
|
|
224
|
+
>
|
|
225
|
+
{children}
|
|
226
|
+
</span>
|
|
227
|
+
</span>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export type ChatReasoningTriggerSymbolSwisperProps = Omit<ComponentProps<'svg'>, 'children'>;
|
|
232
|
+
|
|
233
|
+
// The Swisper shield and the symbol cut out of it, split so the symbol can turn on its own.
|
|
234
|
+
const SWISPER_SHIELD_PATH =
|
|
235
|
+
'M0 8.65206C0 9.06414 0.0550629 9.47298 0.16195 9.87046C0.500425 11.1181 1.39277 12.1742 2.61225 12.768L6.3954 14.6126L10.185 12.7648C11.3203 12.2115 12.1851 11.2397 12.5592 10.1008C12.7131 9.63197 12.7908 9.14526 12.7908 8.65206V0H0V8.65206Z';
|
|
236
|
+
const SWISPER_SYMBOL_PATH =
|
|
237
|
+
'M1.15237 8.97959L2.73841 7.38436C3.25351 7.69767 3.84598 7.86764 4.46289 7.86764C5.07979 7.86764 5.67227 7.69767 6.18737 7.38436L7.77137 8.97754L8.92374 7.81849L7.33771 6.22326C7.9709 5.1584 7.9709 3.81914 7.33771 2.75634L8.92374 1.1611L7.77137 0.00204784L6.18737 1.59523C5.67227 1.28192 5.07979 1.11195 4.46289 1.11195C3.84598 1.11195 3.25351 1.28192 2.73841 1.59523L1.15237 0L0 1.15905L1.584 2.75224C1.27249 3.27033 1.10351 3.86624 1.10351 4.48672C1.10351 5.10721 1.27249 5.70312 1.584 6.22121L0 7.81439L1.15237 8.97345V8.97959ZM3.2413 3.26419C3.56705 2.93654 4.00072 2.75634 4.46289 2.75634C4.92506 2.75634 5.35873 2.93654 5.68448 3.26419C6.3584 3.94201 6.3584 5.04373 5.68448 5.72155C5.35873 6.04919 4.92506 6.23145 4.46289 6.23145C4.00072 6.23145 3.56705 6.05124 3.2413 5.72155C2.91554 5.39185 2.73433 4.95772 2.73433 4.49287C2.73433 4.02802 2.9135 3.59184 3.2413 3.26419Z';
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* The Swisper logo for `ChatReasoningTriggerSymbol`. While the root is running, the symbol inside
|
|
241
|
+
* the shield turns 90° in each 1.1s cycle; with reduced motion, the shield pulses instead.
|
|
242
|
+
*/
|
|
243
|
+
export function ChatReasoningTriggerSymbolSwisper({
|
|
244
|
+
className,
|
|
245
|
+
...rest
|
|
246
|
+
}: ChatReasoningTriggerSymbolSwisperProps) {
|
|
247
|
+
const maskId = `chat-reasoning-symbol-${useId().replace(/:/g, '')}`;
|
|
248
|
+
|
|
249
|
+
return (
|
|
250
|
+
<svg
|
|
251
|
+
aria-hidden
|
|
252
|
+
viewBox="0 0 16 16"
|
|
253
|
+
width="16"
|
|
254
|
+
height="16"
|
|
255
|
+
fill="none"
|
|
256
|
+
data-slot="chat-reasoning-trigger-symbol-swisper"
|
|
257
|
+
data-testid="chat-reasoning-trigger-symbol-swisper"
|
|
258
|
+
className={cn(
|
|
259
|
+
'motion-reduce:group-data-[status=running]/reasoning:animate-[chat-reasoning-symbol-fade_1.6s_ease-in-out_infinite]',
|
|
260
|
+
className,
|
|
261
|
+
)}
|
|
262
|
+
{...rest}
|
|
263
|
+
>
|
|
264
|
+
<mask id={maskId} maskUnits="userSpaceOnUse" x="0" y="0" width="16" height="16">
|
|
265
|
+
<rect width="16" height="16" fill="white" />
|
|
266
|
+
<g transform="translate(3.5384 3.5783)">
|
|
267
|
+
<path
|
|
268
|
+
d={SWISPER_SYMBOL_PATH}
|
|
269
|
+
fill="black"
|
|
270
|
+
className={cn(
|
|
271
|
+
'[transform-box:fill-box] [transform-origin:center]',
|
|
272
|
+
'motion-safe:group-data-[status=running]/reasoning:animate-[chat-reasoning-symbol-turn_1.1s_cubic-bezier(0.65,0,0.35,1)_infinite]',
|
|
273
|
+
)}
|
|
274
|
+
/>
|
|
275
|
+
</g>
|
|
276
|
+
</mask>
|
|
277
|
+
{/* The mask goes on the group: on the path, its coordinates would include the path's translate. */}
|
|
278
|
+
<g mask={`url(#${maskId})`}>
|
|
279
|
+
<path d={SWISPER_SHIELD_PATH} transform="translate(1.6044 1.3328)" fill="currentColor" />
|
|
280
|
+
</g>
|
|
281
|
+
</svg>
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* The line the trigger shows. A new line waits until the current one has been up for a second while
|
|
287
|
+
* running, then replaces it; otherwise it replaces it at once. Lines without a key update in place.
|
|
288
|
+
*/
|
|
289
|
+
function useHeldLine(key: Key | undefined, content: ReactNode, shouldHold: boolean) {
|
|
290
|
+
const [line, setLine] = useState({ key, content });
|
|
291
|
+
const changedAt = useRef(Date.now());
|
|
292
|
+
|
|
293
|
+
useEffect(() => {
|
|
294
|
+
if (key === line.key) {
|
|
295
|
+
if (content !== line.content) setLine({ key, content });
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const wait = shouldHold ? Math.max(0, LINE_HOLD_MS - (Date.now() - changedAt.current)) : 0;
|
|
300
|
+
const timer = setTimeout(() => {
|
|
301
|
+
changedAt.current = Date.now();
|
|
302
|
+
setLine({ key, content });
|
|
303
|
+
}, wait);
|
|
304
|
+
|
|
305
|
+
return () => clearTimeout(timer);
|
|
306
|
+
}, [key, content, shouldHold, line.key, line.content]);
|
|
307
|
+
|
|
308
|
+
return line;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
interface TriggerLabelLineProps {
|
|
312
|
+
children: ReactNode;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function TriggerLabelLine({ children }: TriggerLabelLineProps) {
|
|
316
|
+
const isPresent = useIsPresent();
|
|
317
|
+
const isReducedMotion = useReducedMotion();
|
|
318
|
+
|
|
319
|
+
return (
|
|
320
|
+
<motion.span
|
|
321
|
+
aria-hidden={!isPresent}
|
|
322
|
+
data-slot="chat-reasoning-trigger-label-line"
|
|
323
|
+
className="truncate [grid-area:1/1]"
|
|
324
|
+
initial={isReducedMotion ? false : { y: 10, opacity: 0 }}
|
|
325
|
+
animate={{ y: 0, opacity: 1 }}
|
|
326
|
+
exit={isReducedMotion ? { opacity: 0, transition: { duration: 0 } } : { y: -10, opacity: 0 }}
|
|
327
|
+
transition={LINE_TRANSITION}
|
|
328
|
+
>
|
|
329
|
+
{children}
|
|
330
|
+
</motion.span>
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export interface ChatReasoningTriggerLabelProps extends ComponentProps<'span'> {
|
|
335
|
+
children: ReactNode;
|
|
336
|
+
className?: string;
|
|
337
|
+
/**
|
|
338
|
+
* What the line is, for the change animation. Defaults to the text when `children` is a string;
|
|
339
|
+
* set it when the line is any other node, or the line updates without animating.
|
|
340
|
+
*/
|
|
341
|
+
contentKey?: Key;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* The row's one line and the trigger's accessible name, cut with an ellipsis. A new line slides in
|
|
346
|
+
* from below once the old one has been up for a second. Sweeps a light while running and collapsed.
|
|
347
|
+
*/
|
|
348
|
+
export function ChatReasoningTriggerLabel({
|
|
349
|
+
children,
|
|
350
|
+
className,
|
|
351
|
+
contentKey,
|
|
352
|
+
...rest
|
|
353
|
+
}: ChatReasoningTriggerLabelProps) {
|
|
354
|
+
const { status } = useContext(ChatReasoningContext);
|
|
355
|
+
const line = useHeldLine(getContentKey(children, contentKey), children, status === 'running');
|
|
356
|
+
|
|
357
|
+
return (
|
|
358
|
+
<Typography
|
|
359
|
+
asChild
|
|
360
|
+
variant="body-small-low"
|
|
361
|
+
data-slot="chat-reasoning-trigger-label"
|
|
362
|
+
data-testid="chat-reasoning-trigger-label"
|
|
363
|
+
className={cn(
|
|
364
|
+
'grid min-w-0 flex-1 overflow-hidden',
|
|
365
|
+
'text-reasoning-row-text group-hover/reasoning-trigger:text-reasoning-row-text-hover',
|
|
366
|
+
className,
|
|
367
|
+
)}
|
|
368
|
+
>
|
|
369
|
+
<span aria-live="polite" {...rest}>
|
|
370
|
+
<AnimatePresence initial={false}>
|
|
371
|
+
<TriggerLabelLine key={line.key ?? 'line'}>{line.content}</TriggerLabelLine>
|
|
372
|
+
</AnimatePresence>
|
|
373
|
+
</span>
|
|
374
|
+
</Typography>
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export interface ChatReasoningTriggerArrowProps extends ComponentProps<'span'> {
|
|
379
|
+
className?: string;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** The chevron at the end of the row; turns 180° while the window is open. Hidden from assistive tech. */
|
|
383
|
+
export function ChatReasoningTriggerArrow({ className, ...rest }: ChatReasoningTriggerArrowProps) {
|
|
384
|
+
return (
|
|
385
|
+
<CollapsibleChevron
|
|
386
|
+
data-slot="chat-reasoning-trigger-arrow"
|
|
387
|
+
data-testid="chat-reasoning-trigger-arrow"
|
|
388
|
+
className={cn(
|
|
389
|
+
'size-20 items-center justify-center text-reasoning-row-icon',
|
|
390
|
+
'duration-200 motion-reduce:transition-none [&_svg]:size-20',
|
|
391
|
+
className,
|
|
392
|
+
)}
|
|
393
|
+
{...rest}
|
|
394
|
+
/>
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export interface ChatReasoningStepsProps extends ComponentProps<'div'> {
|
|
399
|
+
children: ReactNode;
|
|
400
|
+
className?: string;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** The window under the row: the steps, then the end row. Opens and closes with a height animation. */
|
|
404
|
+
export function ChatReasoningSteps({ children, className, ...rest }: ChatReasoningStepsProps) {
|
|
405
|
+
return (
|
|
406
|
+
<CollapsibleContent
|
|
407
|
+
data-slot="chat-reasoning-steps"
|
|
408
|
+
data-testid="chat-reasoning-steps"
|
|
409
|
+
className={() =>
|
|
410
|
+
cn(
|
|
411
|
+
'overflow-hidden',
|
|
412
|
+
'data-[state=open]:animate-[chat-reasoning-open_260ms_cubic-bezier(0.4,0,0.2,1)]',
|
|
413
|
+
'data-[state=closed]:animate-[chat-reasoning-close_260ms_cubic-bezier(0.4,0,0.2,1)]',
|
|
414
|
+
'motion-reduce:animate-none',
|
|
415
|
+
className,
|
|
416
|
+
)
|
|
417
|
+
}
|
|
418
|
+
{...rest}
|
|
419
|
+
>
|
|
420
|
+
<div className="flex flex-col gap-reasoning-window-spacing-gap-steps py-reasoning-window-spacing-padding-vertical-base">
|
|
421
|
+
{children}
|
|
422
|
+
</div>
|
|
423
|
+
</CollapsibleContent>
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
interface EnteringRowProps {
|
|
428
|
+
children: ReactNode;
|
|
429
|
+
className?: string;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Grows a row from 0 to its height and fades it in when it is added while the root is running, so
|
|
434
|
+
* the window and the chat under it move smoothly. Rows already there when the window opens, or in a
|
|
435
|
+
* finished answer, show at once.
|
|
436
|
+
*/
|
|
437
|
+
function EnteringRow({ children, className }: EnteringRowProps) {
|
|
438
|
+
const { status } = useContext(ChatReasoningContext);
|
|
439
|
+
const isReducedMotion = useReducedMotion();
|
|
440
|
+
const isEntering = status === 'running' && !isReducedMotion;
|
|
441
|
+
|
|
442
|
+
return (
|
|
443
|
+
<motion.div
|
|
444
|
+
className={className}
|
|
445
|
+
initial={isEntering ? { height: 0, opacity: 0, overflow: 'hidden' } : false}
|
|
446
|
+
animate={{ height: 'auto', opacity: 1, transitionEnd: { overflow: 'visible' } }}
|
|
447
|
+
transition={ROW_TRANSITION}
|
|
448
|
+
>
|
|
449
|
+
{children}
|
|
450
|
+
</motion.div>
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export interface ChatReasoningStepProps extends ComponentProps<'div'> {
|
|
455
|
+
children: ReactNode;
|
|
456
|
+
className?: string;
|
|
457
|
+
/**
|
|
458
|
+
* The step is happening now: its text gets the light sweep and its mark pulses. Several steps can
|
|
459
|
+
* be live at once when tools run in parallel.
|
|
460
|
+
*/
|
|
461
|
+
isLive?: boolean;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** One step: a head (mark and text) and, optionally, notes hanging under it as a tree. */
|
|
465
|
+
export function ChatReasoningStep({
|
|
466
|
+
children,
|
|
467
|
+
className,
|
|
468
|
+
isLive = false,
|
|
469
|
+
...rest
|
|
470
|
+
}: ChatReasoningStepProps) {
|
|
471
|
+
return (
|
|
472
|
+
<EnteringRow>
|
|
473
|
+
<div
|
|
474
|
+
data-slot="chat-reasoning-step"
|
|
475
|
+
data-testid="chat-reasoning-step"
|
|
476
|
+
data-live={isLive}
|
|
477
|
+
className={cn(
|
|
478
|
+
'group/reasoning-step flex flex-col',
|
|
479
|
+
'pr-reasoning-step-spacing-padding-right-base py-reasoning-step-spacing-padding-vertical-base',
|
|
480
|
+
className,
|
|
481
|
+
)}
|
|
482
|
+
{...rest}
|
|
483
|
+
>
|
|
484
|
+
{children}
|
|
485
|
+
</div>
|
|
486
|
+
</EnteringRow>
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
export interface ChatReasoningStepHeadProps extends ComponentProps<'div'> {
|
|
491
|
+
children: ReactNode;
|
|
492
|
+
className?: string;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/** The step's row: the 36px mark column and the text. Draws the tree's trunk when the step has notes. */
|
|
496
|
+
export function ChatReasoningStepHead({
|
|
497
|
+
children,
|
|
498
|
+
className,
|
|
499
|
+
...rest
|
|
500
|
+
}: ChatReasoningStepHeadProps) {
|
|
501
|
+
return (
|
|
502
|
+
<div
|
|
503
|
+
data-slot="chat-reasoning-step-head"
|
|
504
|
+
data-testid="chat-reasoning-step-head"
|
|
505
|
+
className={cn(
|
|
506
|
+
'relative flex items-start',
|
|
507
|
+
'before:absolute before:top-reasoning-step-spacing-trunk-offset-base before:bottom-0 before:left-[17.5px] before:hidden',
|
|
508
|
+
'before:w-reasoning-tree-line-base before:bg-reasoning-tree-line',
|
|
509
|
+
'group-has-[[data-slot=chat-reasoning-step-notes]]/reasoning-step:before:block',
|
|
510
|
+
'group-has-[[data-slot=chat-reasoning-step-notes]]/reasoning-step:pb-reasoning-step-notes-gap-base',
|
|
511
|
+
className,
|
|
512
|
+
)}
|
|
513
|
+
{...rest}
|
|
514
|
+
>
|
|
515
|
+
{children}
|
|
516
|
+
</div>
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
export interface ChatReasoningStepIconProps extends ComponentProps<'span'> {
|
|
521
|
+
children: ReactNode;
|
|
522
|
+
className?: string;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* The step's 20px mark, centred in the 36px mark column (the tree's lines run from that column's
|
|
527
|
+
* centre): a `ChatReasoningStepIconDot` for Swisper's own steps, or a `ChatReasoningStepIconLogo` /
|
|
528
|
+
* `ChatReasoningStepIconWeb` for a source.
|
|
529
|
+
*/
|
|
530
|
+
export function ChatReasoningStepIcon({
|
|
531
|
+
children,
|
|
532
|
+
className,
|
|
533
|
+
...rest
|
|
534
|
+
}: ChatReasoningStepIconProps) {
|
|
535
|
+
return (
|
|
536
|
+
<span
|
|
537
|
+
data-slot="chat-reasoning-step-icon-wrapper"
|
|
538
|
+
className="relative flex min-h-reasoning-step-text-height-base w-reasoning-step-mark-column-base shrink-0 items-center justify-center"
|
|
539
|
+
>
|
|
540
|
+
<span
|
|
541
|
+
data-slot="chat-reasoning-step-icon"
|
|
542
|
+
data-testid="chat-reasoning-step-icon"
|
|
543
|
+
className={cn('flex size-reasoning-mark-ring-base items-center justify-center', className)}
|
|
544
|
+
{...rest}
|
|
545
|
+
>
|
|
546
|
+
{children}
|
|
547
|
+
</span>
|
|
548
|
+
</span>
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
export type ChatReasoningStepIconDotProps = Omit<ComponentProps<'span'>, 'children'>;
|
|
553
|
+
|
|
554
|
+
/** The mark of Swisper's own steps: a 4px dot, 6px and pulsing while the step is live. */
|
|
555
|
+
export function ChatReasoningStepIconDot({ className, ...rest }: ChatReasoningStepIconDotProps) {
|
|
556
|
+
return (
|
|
557
|
+
<span
|
|
558
|
+
aria-hidden
|
|
559
|
+
data-slot="chat-reasoning-step-icon-dot"
|
|
560
|
+
data-testid="chat-reasoning-step-icon-dot"
|
|
561
|
+
className={cn(
|
|
562
|
+
'size-reasoning-mark-dot rounded-full bg-reasoning-mark-dot',
|
|
563
|
+
'group-data-[live=true]/reasoning-step:size-reasoning-mark-dot-live',
|
|
564
|
+
'group-data-[live=true]/reasoning-step:bg-reasoning-mark-dot-live',
|
|
565
|
+
className,
|
|
566
|
+
)}
|
|
567
|
+
{...rest}
|
|
568
|
+
/>
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
export interface ChatReasoningStepIconLogoProps extends ComponentProps<'span'> {
|
|
573
|
+
/** The source's logo, an icon or image of 16px. Give it a label ("SBB"), which the text may not name. */
|
|
574
|
+
children: ReactNode;
|
|
575
|
+
className?: string;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/** A source's logo in the mark column. While the step is live it sits on a 20px tile that pulses. */
|
|
579
|
+
export function ChatReasoningStepIconLogo({
|
|
580
|
+
children,
|
|
581
|
+
className,
|
|
582
|
+
...rest
|
|
583
|
+
}: ChatReasoningStepIconLogoProps) {
|
|
584
|
+
return (
|
|
585
|
+
<span
|
|
586
|
+
data-slot="chat-reasoning-step-icon-logo"
|
|
587
|
+
data-testid="chat-reasoning-step-icon-logo"
|
|
588
|
+
className={cn(
|
|
589
|
+
'flex size-reasoning-mark-ring-base items-center justify-center rounded-reasoning-mark-logo',
|
|
590
|
+
'group-data-[live=true]/reasoning-step:bg-reasoning-mark-ring',
|
|
591
|
+
'[&>img]:size-16 [&>svg]:size-16',
|
|
592
|
+
className,
|
|
593
|
+
)}
|
|
594
|
+
{...rest}
|
|
595
|
+
>
|
|
596
|
+
{children}
|
|
597
|
+
</span>
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
export interface ChatReasoningStepIconWebProps extends ComponentProps<'span'> {
|
|
602
|
+
/** The web search icon, 16px. Give it a label ("Web search"), which the text may not name. */
|
|
603
|
+
children: ReactNode;
|
|
604
|
+
className?: string;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* The web search mark in the mark column, on a round tile. While the step is live the tile shows and
|
|
609
|
+
* pulses, and the icon brightens.
|
|
610
|
+
*/
|
|
611
|
+
export function ChatReasoningStepIconWeb({
|
|
612
|
+
children,
|
|
613
|
+
className,
|
|
614
|
+
...rest
|
|
615
|
+
}: ChatReasoningStepIconWebProps) {
|
|
616
|
+
return (
|
|
617
|
+
<span
|
|
618
|
+
data-slot="chat-reasoning-step-icon-web"
|
|
619
|
+
data-testid="chat-reasoning-step-icon-web"
|
|
620
|
+
className={cn(
|
|
621
|
+
'flex size-reasoning-mark-ring-base items-center justify-center rounded-reasoning-mark-web',
|
|
622
|
+
'text-reasoning-source-icon',
|
|
623
|
+
'group-data-[live=true]/reasoning-step:bg-reasoning-mark-ring',
|
|
624
|
+
'group-data-[live=true]/reasoning-step:text-reasoning-mark-icon-live',
|
|
625
|
+
'[&>img]:size-16 [&>svg]:size-16',
|
|
626
|
+
className,
|
|
627
|
+
)}
|
|
628
|
+
{...rest}
|
|
629
|
+
>
|
|
630
|
+
{children}
|
|
631
|
+
</span>
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
export interface ChatReasoningStepTextProps extends ComponentProps<'span'> {
|
|
636
|
+
children: ReactNode;
|
|
637
|
+
className?: string;
|
|
638
|
+
/**
|
|
639
|
+
* What the text is, for the change fade. Defaults to the text when `children` is a string; set it
|
|
640
|
+
* when the text is any other node, such as streamed Markdown.
|
|
641
|
+
*/
|
|
642
|
+
contentKey?: Key;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/** The step's text. Fades when it changes (what Swisper says it will do, then what it did). */
|
|
646
|
+
export function ChatReasoningStepText({
|
|
647
|
+
children,
|
|
648
|
+
className,
|
|
649
|
+
contentKey,
|
|
650
|
+
...rest
|
|
651
|
+
}: ChatReasoningStepTextProps) {
|
|
652
|
+
const isReducedMotion = useReducedMotion();
|
|
653
|
+
|
|
654
|
+
return (
|
|
655
|
+
<Typography
|
|
656
|
+
asChild
|
|
657
|
+
variant="body-small-low"
|
|
658
|
+
data-slot="chat-reasoning-step-text"
|
|
659
|
+
data-testid="chat-reasoning-step-text"
|
|
660
|
+
className={cn(
|
|
661
|
+
'flex min-h-reasoning-step-text-height-base min-w-0 flex-1 items-center',
|
|
662
|
+
'text-reasoning-step-text',
|
|
663
|
+
className,
|
|
664
|
+
)}
|
|
665
|
+
>
|
|
666
|
+
<span {...rest}>
|
|
667
|
+
<AnimatePresence initial={false}>
|
|
668
|
+
<motion.span
|
|
669
|
+
key={getContentKey(children, contentKey) ?? 'text'}
|
|
670
|
+
data-slot="chat-reasoning-step-text-content"
|
|
671
|
+
initial={isReducedMotion ? false : { opacity: 0 }}
|
|
672
|
+
animate={{ opacity: 1 }}
|
|
673
|
+
transition={STEP_TEXT_TRANSITION}
|
|
674
|
+
>
|
|
675
|
+
{children}
|
|
676
|
+
</motion.span>
|
|
677
|
+
</AnimatePresence>
|
|
678
|
+
</span>
|
|
679
|
+
</Typography>
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
export interface ChatReasoningStepNotesProps extends ComponentProps<'div'> {
|
|
684
|
+
children: ReactNode;
|
|
685
|
+
className?: string;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/** The details under a step, joined to its mark by a tree drawn from their order. */
|
|
689
|
+
export function ChatReasoningStepNotes({
|
|
690
|
+
children,
|
|
691
|
+
className,
|
|
692
|
+
...rest
|
|
693
|
+
}: ChatReasoningStepNotesProps) {
|
|
694
|
+
return (
|
|
695
|
+
<div
|
|
696
|
+
data-slot="chat-reasoning-step-notes"
|
|
697
|
+
data-testid="chat-reasoning-step-notes"
|
|
698
|
+
className={cn('flex flex-col', className)}
|
|
699
|
+
{...rest}
|
|
700
|
+
>
|
|
701
|
+
{children}
|
|
702
|
+
</div>
|
|
703
|
+
);
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
const treeLineClassName = 'absolute left-[17.5px] bg-reasoning-tree-line';
|
|
707
|
+
|
|
708
|
+
/** The tree beside a text note: the trunk runs on and a tick points at it, or it bends into the last one. */
|
|
709
|
+
function NoteTree() {
|
|
710
|
+
return (
|
|
711
|
+
<span aria-hidden className="relative w-reasoning-step-mark-column-base shrink-0">
|
|
712
|
+
<span
|
|
713
|
+
className={cn(
|
|
714
|
+
treeLineClassName,
|
|
715
|
+
'top-0 bottom-0 w-reasoning-tree-line-base',
|
|
716
|
+
'group-last/reasoning-note:bottom-auto group-last/reasoning-note:h-[5px]',
|
|
717
|
+
)}
|
|
718
|
+
/>
|
|
719
|
+
<span
|
|
720
|
+
className={cn(
|
|
721
|
+
treeLineClassName,
|
|
722
|
+
'top-[10.5px] h-reasoning-tree-line-base w-reasoning-tree-branch-base',
|
|
723
|
+
'group-last/reasoning-note:hidden',
|
|
724
|
+
)}
|
|
725
|
+
/>
|
|
726
|
+
<span
|
|
727
|
+
className={cn(
|
|
728
|
+
'absolute top-[4.5px] left-[17.5px] hidden h-[7px] w-reasoning-tree-branch-base',
|
|
729
|
+
'rounded-bl-reasoning-tree-base border-b border-l border-reasoning-tree-line',
|
|
730
|
+
'group-last/reasoning-note:block',
|
|
731
|
+
)}
|
|
732
|
+
/>
|
|
733
|
+
</span>
|
|
734
|
+
);
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/** The tree beside a list of pages: the tick and the bend point at the first page row. */
|
|
738
|
+
function NotePagesTree() {
|
|
739
|
+
return (
|
|
740
|
+
<span aria-hidden className="relative w-reasoning-step-mark-column-base shrink-0">
|
|
741
|
+
<span
|
|
742
|
+
className={cn(
|
|
743
|
+
treeLineClassName,
|
|
744
|
+
'top-0 bottom-0 w-reasoning-tree-line-base',
|
|
745
|
+
'group-last/reasoning-note:bottom-auto group-last/reasoning-note:h-[11px]',
|
|
746
|
+
)}
|
|
747
|
+
/>
|
|
748
|
+
<span
|
|
749
|
+
className={cn(
|
|
750
|
+
treeLineClassName,
|
|
751
|
+
'top-[16.5px] h-reasoning-tree-line-base w-reasoning-tree-branch-base',
|
|
752
|
+
'group-last/reasoning-note:hidden',
|
|
753
|
+
)}
|
|
754
|
+
/>
|
|
755
|
+
<span
|
|
756
|
+
className={cn(
|
|
757
|
+
'absolute top-[10.5px] left-[17.5px] hidden h-[7px] w-reasoning-tree-branch-base',
|
|
758
|
+
'rounded-bl-reasoning-tree-base border-b border-l border-reasoning-tree-line',
|
|
759
|
+
'group-last/reasoning-note:block',
|
|
760
|
+
)}
|
|
761
|
+
/>
|
|
762
|
+
</span>
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
export interface ChatReasoningStepNoteProps extends ComponentProps<'div'> {
|
|
767
|
+
children: ReactNode;
|
|
768
|
+
className?: string;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/** A detail under a step in 12px text, lined up with the step's text. */
|
|
772
|
+
export function ChatReasoningStepNote({
|
|
773
|
+
children,
|
|
774
|
+
className,
|
|
775
|
+
...rest
|
|
776
|
+
}: ChatReasoningStepNoteProps) {
|
|
777
|
+
return (
|
|
778
|
+
<EnteringRow className="group/reasoning-note">
|
|
779
|
+
<div
|
|
780
|
+
data-slot="chat-reasoning-step-note"
|
|
781
|
+
data-testid="chat-reasoning-step-note"
|
|
782
|
+
className={cn('flex items-stretch', className)}
|
|
783
|
+
{...rest}
|
|
784
|
+
>
|
|
785
|
+
<NoteTree />
|
|
786
|
+
<Typography
|
|
787
|
+
asChild
|
|
788
|
+
variant="caption-md"
|
|
789
|
+
fontWeight="normal"
|
|
790
|
+
className={cn(
|
|
791
|
+
'min-w-0 flex-1 leading-none text-reasoning-note-text [text-box:trim-both_cap_alphabetic]',
|
|
792
|
+
'pt-reasoning-note-spacing-padding-top-base pb-reasoning-note-spacing-padding-bottom-base',
|
|
793
|
+
)}
|
|
794
|
+
>
|
|
795
|
+
<span>{children}</span>
|
|
796
|
+
</Typography>
|
|
797
|
+
</div>
|
|
798
|
+
</EnteringRow>
|
|
799
|
+
);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
export interface ChatReasoningStepNotePagesProps extends ComponentProps<'div'> {
|
|
803
|
+
children: ReactNode;
|
|
804
|
+
className?: string;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/** The pages Swisper read for a web step: a plain list of `ChatReasoningStepNotePageRow`. */
|
|
808
|
+
export function ChatReasoningStepNotePages({
|
|
809
|
+
children,
|
|
810
|
+
className,
|
|
811
|
+
...rest
|
|
812
|
+
}: ChatReasoningStepNotePagesProps) {
|
|
813
|
+
return (
|
|
814
|
+
<EnteringRow className="group/reasoning-note">
|
|
815
|
+
<div
|
|
816
|
+
data-slot="chat-reasoning-step-note-pages"
|
|
817
|
+
data-testid="chat-reasoning-step-note-pages"
|
|
818
|
+
className={cn('flex items-stretch', className)}
|
|
819
|
+
{...rest}
|
|
820
|
+
>
|
|
821
|
+
<NotePagesTree />
|
|
822
|
+
<div className="min-w-0 flex-1 py-reasoning-note-pages-spacing-padding-vertical-base">
|
|
823
|
+
<div className="flex flex-col py-reasoning-note-pages-spacing-padding-list-base">
|
|
824
|
+
{children}
|
|
825
|
+
</div>
|
|
826
|
+
</div>
|
|
827
|
+
</div>
|
|
828
|
+
</EnteringRow>
|
|
829
|
+
);
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
export interface ChatReasoningStepNotePageRowProps extends ComponentProps<'div'> {
|
|
833
|
+
children: ReactNode;
|
|
834
|
+
className?: string;
|
|
835
|
+
/**
|
|
836
|
+
* Merges the row onto its one child, usually your `<a>` or router link, so the whole row is the
|
|
837
|
+
* link. The hover fill, the brighter title and domain, and the focus outline apply to it.
|
|
838
|
+
*/
|
|
839
|
+
asChild?: boolean;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/** One page: favicon, title and domain in a 26px row. Pass `asChild` to render it as your link. */
|
|
843
|
+
export const ChatReasoningStepNotePageRow = forwardRef<
|
|
844
|
+
HTMLDivElement,
|
|
845
|
+
ChatReasoningStepNotePageRowProps
|
|
846
|
+
>(function ChatReasoningStepNotePageRow({ children, className, asChild = false, ...rest }, ref) {
|
|
847
|
+
const Component = asChild ? Slot : 'div';
|
|
848
|
+
|
|
849
|
+
return (
|
|
850
|
+
<Component
|
|
851
|
+
ref={ref}
|
|
852
|
+
data-slot="chat-reasoning-step-note-page-row"
|
|
853
|
+
data-testid="chat-reasoning-step-note-page-row"
|
|
854
|
+
className={cn(
|
|
855
|
+
'group/reasoning-page-row flex min-w-0 items-center',
|
|
856
|
+
'gap-reasoning-page-row-spacing-gap-base rounded-reasoning-page-row-base',
|
|
857
|
+
'px-reasoning-page-row-spacing-padding-horizontal-base py-reasoning-page-row-spacing-padding-vertical-base',
|
|
858
|
+
'hover:bg-reasoning-page-row-background-hover',
|
|
859
|
+
'focus-visible:bg-reasoning-page-row-background-focus focus-visible:outline-2 focus-visible:outline-reasoning-page-row-border-focus',
|
|
860
|
+
className,
|
|
861
|
+
)}
|
|
862
|
+
{...rest}
|
|
863
|
+
>
|
|
864
|
+
{children}
|
|
865
|
+
</Component>
|
|
866
|
+
);
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
ChatReasoningStepNotePageRow.displayName = 'ChatReasoningStepNotePageRow';
|
|
870
|
+
|
|
871
|
+
export interface ChatReasoningStepNotePageIconProps extends ComponentProps<'span'> {
|
|
872
|
+
/** The page's favicon as an `<img>` (decorative, `alt=""`), or a letter when there is none. */
|
|
873
|
+
children: ReactNode;
|
|
874
|
+
className?: string;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/** The page's 16px favicon tile; a letter stands in when there is no favicon. */
|
|
878
|
+
export function ChatReasoningStepNotePageIcon({
|
|
879
|
+
children,
|
|
880
|
+
className,
|
|
881
|
+
...rest
|
|
882
|
+
}: ChatReasoningStepNotePageIconProps) {
|
|
883
|
+
return (
|
|
884
|
+
<span
|
|
885
|
+
data-slot="chat-reasoning-step-note-page-icon"
|
|
886
|
+
data-testid="chat-reasoning-step-note-page-icon"
|
|
887
|
+
className="flex size-reasoning-source-box-medium shrink-0 items-center justify-center"
|
|
888
|
+
>
|
|
889
|
+
<Typography
|
|
890
|
+
asChild
|
|
891
|
+
variant="caption-md"
|
|
892
|
+
fontWeight="normal"
|
|
893
|
+
className={cn(
|
|
894
|
+
'flex size-reasoning-source-favicon-medium items-center justify-center overflow-hidden',
|
|
895
|
+
'rounded-reasoning-source-favicon bg-reasoning-source-favicon-background',
|
|
896
|
+
'leading-none text-reasoning-source-favicon-letter',
|
|
897
|
+
'[&>img]:size-full [&>img]:object-cover',
|
|
898
|
+
className,
|
|
899
|
+
)}
|
|
900
|
+
>
|
|
901
|
+
<span {...rest}>{children}</span>
|
|
902
|
+
</Typography>
|
|
903
|
+
</span>
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
export interface ChatReasoningStepNotePageTitleProps extends ComponentProps<'span'> {
|
|
908
|
+
children: ReactNode;
|
|
909
|
+
className?: string;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/** The page's title, cut with an ellipsis. Brightens while the row is hovered. */
|
|
913
|
+
export function ChatReasoningStepNotePageTitle({
|
|
914
|
+
children,
|
|
915
|
+
className,
|
|
916
|
+
...rest
|
|
917
|
+
}: ChatReasoningStepNotePageTitleProps) {
|
|
918
|
+
return (
|
|
919
|
+
<Typography
|
|
920
|
+
asChild
|
|
921
|
+
variant="caption-md"
|
|
922
|
+
fontWeight="normal"
|
|
923
|
+
data-slot="chat-reasoning-step-note-page-title"
|
|
924
|
+
data-testid="chat-reasoning-step-note-page-title"
|
|
925
|
+
className={cn(
|
|
926
|
+
'min-w-0 flex-1 truncate leading-none text-reasoning-page-row-title',
|
|
927
|
+
'group-hover/reasoning-page-row:text-reasoning-page-row-title-hover',
|
|
928
|
+
className,
|
|
929
|
+
)}
|
|
930
|
+
>
|
|
931
|
+
<span {...rest}>{children}</span>
|
|
932
|
+
</Typography>
|
|
933
|
+
);
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
export interface ChatReasoningStepNotePageDomainProps extends ComponentProps<'span'> {
|
|
937
|
+
children: ReactNode;
|
|
938
|
+
className?: string;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/** The page's domain at the end of the row. Turns blue while the row is hovered or focused. */
|
|
942
|
+
export function ChatReasoningStepNotePageDomain({
|
|
943
|
+
children,
|
|
944
|
+
className,
|
|
945
|
+
...rest
|
|
946
|
+
}: ChatReasoningStepNotePageDomainProps) {
|
|
947
|
+
return (
|
|
948
|
+
<Typography
|
|
949
|
+
asChild
|
|
950
|
+
variant="caption-md"
|
|
951
|
+
fontWeight="normal"
|
|
952
|
+
data-slot="chat-reasoning-step-note-page-domain"
|
|
953
|
+
data-testid="chat-reasoning-step-note-page-domain"
|
|
954
|
+
className={cn(
|
|
955
|
+
'shrink-0 leading-none whitespace-nowrap text-reasoning-page-row-domain',
|
|
956
|
+
'group-hover/reasoning-page-row:text-reasoning-page-row-domain-hover',
|
|
957
|
+
'group-focus-visible/reasoning-page-row:text-reasoning-page-row-domain-focus',
|
|
958
|
+
className,
|
|
959
|
+
)}
|
|
960
|
+
>
|
|
961
|
+
<span {...rest}>{children}</span>
|
|
962
|
+
</Typography>
|
|
963
|
+
);
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
export interface ChatReasoningEndProps extends ComponentProps<'div'> {
|
|
967
|
+
children: ReactNode;
|
|
968
|
+
className?: string;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* The last row of the window: how the work ended ("Done in 40 s", "Stopped"). Render it once the
|
|
973
|
+
* root is done or stopped, after the last step.
|
|
974
|
+
*/
|
|
975
|
+
export function ChatReasoningEnd({ children, className, ...rest }: ChatReasoningEndProps) {
|
|
976
|
+
return (
|
|
977
|
+
<EnteringRow>
|
|
978
|
+
<div
|
|
979
|
+
data-slot="chat-reasoning-end"
|
|
980
|
+
data-testid="chat-reasoning-end"
|
|
981
|
+
className={cn(
|
|
982
|
+
'flex items-start',
|
|
983
|
+
'pr-reasoning-end-row-spacing-padding-right-base py-reasoning-end-row-spacing-padding-vertical-base',
|
|
984
|
+
className,
|
|
985
|
+
)}
|
|
986
|
+
{...rest}
|
|
987
|
+
>
|
|
988
|
+
{children}
|
|
989
|
+
</div>
|
|
990
|
+
</EnteringRow>
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
export interface ChatReasoningEndIconProps extends ComponentProps<'span'> {
|
|
995
|
+
/** A check once done, a stop icon once stopped. */
|
|
996
|
+
children: ReactNode;
|
|
997
|
+
className?: string;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/** The end row's 14px icon, in the mark column. Hidden from assistive tech: the text says it. */
|
|
1001
|
+
export function ChatReasoningEndIcon({ children, className, ...rest }: ChatReasoningEndIconProps) {
|
|
1002
|
+
return (
|
|
1003
|
+
<span
|
|
1004
|
+
aria-hidden
|
|
1005
|
+
data-slot="chat-reasoning-end-icon"
|
|
1006
|
+
data-testid="chat-reasoning-end-icon"
|
|
1007
|
+
className={cn(
|
|
1008
|
+
'flex shrink-0 items-center justify-center text-reasoning-end-row-icon',
|
|
1009
|
+
'h-reasoning-end-row-mark-column-height-base w-reasoning-end-row-mark-column-base',
|
|
1010
|
+
'[&>svg]:size-reasoning-end-row-icon-base',
|
|
1011
|
+
className,
|
|
1012
|
+
)}
|
|
1013
|
+
{...rest}
|
|
1014
|
+
>
|
|
1015
|
+
{children}
|
|
1016
|
+
</span>
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
export interface ChatReasoningEndTextProps extends ComponentProps<'span'> {
|
|
1021
|
+
children: ReactNode;
|
|
1022
|
+
className?: string;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
/** The end row's text: "Done in 40 s" or "Stopped". */
|
|
1026
|
+
export function ChatReasoningEndText({ children, className, ...rest }: ChatReasoningEndTextProps) {
|
|
1027
|
+
return (
|
|
1028
|
+
<Typography
|
|
1029
|
+
asChild
|
|
1030
|
+
variant="body-small-low"
|
|
1031
|
+
data-slot="chat-reasoning-end-text"
|
|
1032
|
+
data-testid="chat-reasoning-end-text"
|
|
1033
|
+
className={cn(
|
|
1034
|
+
'flex min-h-reasoning-end-row-text-height-base min-w-0 flex-1 items-center',
|
|
1035
|
+
'text-reasoning-end-row-text',
|
|
1036
|
+
className,
|
|
1037
|
+
)}
|
|
1038
|
+
>
|
|
1039
|
+
<span {...rest}>{children}</span>
|
|
1040
|
+
</Typography>
|
|
1041
|
+
);
|
|
1042
|
+
}
|