@istmx/ui 0.1.11 → 0.1.13

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 (55) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +533 -463
  3. package/bin/istmx.mjs +481 -314
  4. package/package.json +27 -27
  5. package/registry/accordion.tsx +186 -0
  6. package/registry/ai-chat-block/ai-chat-block.tsx +456 -460
  7. package/registry/ai-chat-block/ai-chat-input.tsx +694 -694
  8. package/registry/ai-chat-block/attachment.tsx +466 -466
  9. package/registry/ai-chat-block/chat-code-block.tsx +50 -50
  10. package/registry/ai-chat-block/chat-composer.tsx +51 -51
  11. package/registry/ai-chat-block/chat-logo.tsx +18 -18
  12. package/registry/ai-chat-block/chat-message.tsx +161 -161
  13. package/registry/ai-chat-block/chat-sidebar.tsx +273 -273
  14. package/registry/ai-chat-block/chat-user-avatar.tsx +9 -9
  15. package/registry/ai-chat-block/code-highlighter.tsx +342 -357
  16. package/registry/ai-chat-block/default-attachments.tsx +42 -42
  17. package/registry/ai-chat-block/index.ts +30 -30
  18. package/registry/ai-chat-block/message-content.tsx +287 -287
  19. package/registry/ai-chat-block/message-list.tsx +93 -93
  20. package/registry/ai-chat-block/send-button.tsx +102 -102
  21. package/registry/ai-chat-block/types.ts +70 -71
  22. package/registry/ai-chat-block/utils.ts +6 -6
  23. package/registry/ai-chat-block/voice-button.tsx +66 -66
  24. package/registry/alert-dialog.tsx +229 -0
  25. package/registry/alert.tsx +188 -0
  26. package/registry/animated-text.tsx +228 -225
  27. package/registry/aspect-ratio.tsx +32 -0
  28. package/registry/avatar-group.tsx +66 -0
  29. package/registry/avatar.tsx +121 -0
  30. package/registry/badge.tsx +52 -0
  31. package/registry/bento-grid.tsx +438 -433
  32. package/registry/button.tsx +156 -237
  33. package/registry/carousel.tsx +184 -0
  34. package/registry/dock-navigation.tsx +200 -198
  35. package/registry/drift-canvas.tsx +383 -0
  36. package/registry/drift-wall.tsx +361 -0
  37. package/registry/flex-carousel.tsx +1430 -0
  38. package/registry/guided-gallery.tsx +1506 -0
  39. package/registry/image-accordion.tsx +306 -302
  40. package/registry/image-trail.tsx +126 -121
  41. package/registry/infinite-image-canvas.tsx +268 -263
  42. package/registry/input-otp.tsx +332 -0
  43. package/registry/list-card.tsx +130 -0
  44. package/registry/mobile-menu-dock.tsx +216 -211
  45. package/registry/morph-slider.tsx +756 -0
  46. package/registry/pixel-cat.tsx +972 -1020
  47. package/registry/scroll-canvas-cards.tsx +643 -0
  48. package/registry/scroll-parallax-hero.tsx +566 -565
  49. package/registry/scroll-story-cards.tsx +443 -438
  50. package/registry/slider.tsx +163 -0
  51. package/registry/spotlight-grid.tsx +226 -0
  52. package/registry/streaming-text.tsx +269 -278
  53. package/registry/text-reveal.tsx +311 -307
  54. package/registry/user-avatar.tsx +99 -0
  55. package/registry/utils.ts +6 -6
@@ -1,50 +1,50 @@
1
- 'use client'
2
-
3
- import { useMemo, useState } from 'react'
4
- import { IconCheck, IconCopy, IconFileCode } from '@tabler/icons-react'
5
- import { tokenizeCode, TokenSpan } from './code-highlighter'
6
- import { cn } from './utils'
7
-
8
- export default function ChatCodeBlock({
9
- children,
10
- label = 'code',
11
- className,
12
- }: {
13
- children: string
14
- label?: string
15
- className?: string
16
- }) {
17
- const [copied, setCopied] = useState(false)
18
- const lines = useMemo(() => tokenizeCode(children), [children])
19
-
20
- async function copyCode() {
21
- try {
22
- await navigator.clipboard.writeText(children)
23
- setCopied(true)
24
- window.setTimeout(() => setCopied(false), 1600)
25
- } catch {
26
- setCopied(false)
27
- }
28
- }
29
-
30
- return (
31
- <div className={cn('border-border/70 my-3 overflow-hidden rounded-xl border bg-[#09090b] text-left', className)}>
32
- <div className="flex items-center justify-between border-b border-neutral-800/80 bg-[#0d0d10]/95 px-3.5 py-2">
33
- <span className="flex items-center gap-2 font-mono text-[11px] text-neutral-400">
34
- <IconFileCode size={14} className="text-neutral-500" aria-hidden="true" />
35
- {label}
36
- </span>
37
- <button type="button" onClick={copyCode} aria-label={copied ? 'Code copied' : 'Copy code'} className="flex size-7 cursor-pointer items-center justify-center rounded text-neutral-500 transition-colors hover:text-neutral-200">
38
- {copied ? <IconCheck size={14} className="text-emerald-400" aria-hidden="true" /> : <IconCopy size={14} aria-hidden="true" />}
39
- </button>
40
- </div>
41
- <pre className="max-w-full overflow-x-auto p-4 font-mono text-[13px] leading-[1.7] antialiased select-text">
42
- <code>{lines.map((line, lineIndex) => (
43
- <span key={`line-${lineIndex}`} className="block min-h-[1.7em] whitespace-pre">
44
- {line.length ? line.map((token, tokenIndex) => <TokenSpan key={`${lineIndex}-${tokenIndex}`} token={token} />) : <>&nbsp;</>}
45
- </span>
46
- ))}</code>
47
- </pre>
48
- </div>
49
- )
50
- }
1
+ 'use client'
2
+
3
+ import { useMemo, useState } from 'react'
4
+ import { IconCheck, IconCopy, IconFileCode } from '@tabler/icons-react'
5
+ import { tokenizeCode, TokenSpan } from './code-highlighter'
6
+ import { cn } from './utils'
7
+
8
+ export default function ChatCodeBlock({
9
+ children,
10
+ label = 'code',
11
+ className,
12
+ }: {
13
+ children: string
14
+ label?: string
15
+ className?: string
16
+ }) {
17
+ const [copied, setCopied] = useState(false)
18
+ const lines = useMemo(() => tokenizeCode(children), [children])
19
+
20
+ async function copyCode() {
21
+ try {
22
+ await navigator.clipboard.writeText(children)
23
+ setCopied(true)
24
+ window.setTimeout(() => setCopied(false), 1600)
25
+ } catch {
26
+ setCopied(false)
27
+ }
28
+ }
29
+
30
+ return (
31
+ <div className={cn('border-border/70 my-3 overflow-hidden rounded-xl border bg-[#09090b] text-left', className)}>
32
+ <div className="flex items-center justify-between border-b border-neutral-800/80 bg-[#0d0d10]/95 px-3.5 py-2">
33
+ <span className="flex items-center gap-2 font-mono text-[11px] text-neutral-400">
34
+ <IconFileCode size={14} className="text-neutral-500" aria-hidden="true" />
35
+ {label}
36
+ </span>
37
+ <button type="button" onClick={copyCode} aria-label={copied ? 'Code copied' : 'Copy code'} className="flex size-7 cursor-pointer items-center justify-center rounded text-neutral-500 transition-colors hover:text-neutral-200">
38
+ {copied ? <IconCheck size={14} className="text-emerald-400" aria-hidden="true" /> : <IconCopy size={14} aria-hidden="true" />}
39
+ </button>
40
+ </div>
41
+ <pre className="max-w-full overflow-x-auto p-4 font-mono text-[13px] leading-[1.7] antialiased select-text">
42
+ <code>{lines.map((line, lineIndex) => (
43
+ <span key={`line-${lineIndex}`} className="block min-h-[1.7em] whitespace-pre">
44
+ {line.length ? line.map((token, tokenIndex) => <TokenSpan key={`${lineIndex}-${tokenIndex}`} token={token} />) : <>&nbsp;</>}
45
+ </span>
46
+ ))}</code>
47
+ </pre>
48
+ </div>
49
+ )
50
+ }
@@ -1,51 +1,51 @@
1
- 'use client'
2
-
3
- import AiChatInput from './ai-chat-input'
4
- import type { AiChatInputAction, AiChatInputAttachment } from './ai-chat-input'
5
-
6
- export type ChatComposerProps = {
7
- actions: readonly AiChatInputAction[]
8
- disabled?: boolean
9
- busy?: boolean
10
- maxAttachments?: number
11
- maxFileSizeBytes?: number
12
- showVoice?: boolean
13
- placeholder?: string
14
- accentColor?: string
15
- onSubmit: (message: string, attachments: AiChatInputAttachment[]) => void
16
- onStop?: () => void
17
- onListeningChange?: (listening: boolean) => void
18
- onAttachmentError?: (message: string) => void
19
- }
20
-
21
- export default function ChatComposer({
22
- actions,
23
- disabled,
24
- busy,
25
- maxAttachments,
26
- maxFileSizeBytes,
27
- showVoice,
28
- placeholder,
29
- accentColor,
30
- onSubmit,
31
- onStop,
32
- onListeningChange,
33
- onAttachmentError,
34
- }: ChatComposerProps) {
35
- return (
36
- <AiChatInput
37
- actions={actions}
38
- disabled={disabled}
39
- busy={busy}
40
- maxAttachments={maxAttachments}
41
- maxFileSizeBytes={maxFileSizeBytes}
42
- showVoice={showVoice}
43
- placeholder={placeholder}
44
- accentColor={accentColor}
45
- onSubmit={onSubmit}
46
- onStop={onStop}
47
- onListeningChange={onListeningChange}
48
- onAttachmentError={onAttachmentError}
49
- />
50
- )
51
- }
1
+ 'use client'
2
+
3
+ import AiChatInput from './ai-chat-input'
4
+ import type { AiChatInputAction, AiChatInputAttachment } from './ai-chat-input'
5
+
6
+ export type ChatComposerProps = {
7
+ actions: readonly AiChatInputAction[]
8
+ disabled?: boolean
9
+ busy?: boolean
10
+ maxAttachments?: number
11
+ maxFileSizeBytes?: number
12
+ showVoice?: boolean
13
+ placeholder?: string
14
+ accentColor?: string
15
+ onSubmit: (message: string, attachments: AiChatInputAttachment[]) => void
16
+ onStop?: () => void
17
+ onListeningChange?: (listening: boolean) => void
18
+ onAttachmentError?: (message: string) => void
19
+ }
20
+
21
+ export default function ChatComposer({
22
+ actions,
23
+ disabled,
24
+ busy,
25
+ maxAttachments,
26
+ maxFileSizeBytes,
27
+ showVoice,
28
+ placeholder,
29
+ accentColor,
30
+ onSubmit,
31
+ onStop,
32
+ onListeningChange,
33
+ onAttachmentError,
34
+ }: ChatComposerProps) {
35
+ return (
36
+ <AiChatInput
37
+ actions={actions}
38
+ disabled={disabled}
39
+ busy={busy}
40
+ maxAttachments={maxAttachments}
41
+ maxFileSizeBytes={maxFileSizeBytes}
42
+ showVoice={showVoice}
43
+ placeholder={placeholder}
44
+ accentColor={accentColor}
45
+ onSubmit={onSubmit}
46
+ onStop={onStop}
47
+ onListeningChange={onListeningChange}
48
+ onAttachmentError={onAttachmentError}
49
+ />
50
+ )
51
+ }
@@ -1,18 +1,18 @@
1
- export default function ChatLogo({ className = '' }: { className?: string }) {
2
- return (
3
- <svg
4
- xmlns="http://www.w3.org/2000/svg"
5
- viewBox="0 0 512 512"
6
- fill="none"
7
- aria-label="istmX"
8
- className={className}
9
- >
10
- <g fill="currentColor">
11
- <path d="M118 132L238 132L304 211L247 269L191 205L151 247V334H118V132Z" />
12
- <path d="M129 401L157 350L362 145L408 100L382 164L334 219L276 277L407 407H302L225 329L129 401Z" />
13
- <path d="M273 151H320L296 198L273 151Z" />
14
- <path d="M224 365H271L247 319L224 365Z" />
15
- </g>
16
- </svg>
17
- )
18
- }
1
+ export default function ChatLogo({ className = '' }: { className?: string }) {
2
+ return (
3
+ <svg
4
+ xmlns="http://www.w3.org/2000/svg"
5
+ viewBox="0 0 512 512"
6
+ fill="none"
7
+ aria-label="istmX"
8
+ className={className}
9
+ >
10
+ <g fill="currentColor">
11
+ <path d="M118 132L238 132L304 211L247 269L191 205L151 247V334H118V132Z" />
12
+ <path d="M129 401L157 350L362 145L408 100L382 164L334 219L276 277L407 407H302L225 329L129 401Z" />
13
+ <path d="M273 151H320L296 198L273 151Z" />
14
+ <path d="M224 365H271L247 319L224 365Z" />
15
+ </g>
16
+ </svg>
17
+ )
18
+ }
@@ -1,161 +1,161 @@
1
- 'use client'
2
-
3
- import { memo, useState } from 'react'
4
- import type { ReactNode } from 'react'
5
- import { AnimatePresence, motion, useReducedMotion } from 'motion/react'
6
- import { IconUser, IconX } from '@tabler/icons-react'
7
- import type { ChatAttachment, ChatTurn } from './types'
8
- import MessageContent from './message-content'
9
- import ChatLogo from './chat-logo'
10
- import { AttachmentPreview } from './attachment'
11
-
12
- function formatBytes(size: number) {
13
- if (size < 1024) return `${size} B`
14
- if (size < 1024 * 1024) return `${Math.round(size / 1024)} KB`
15
- return `${(size / (1024 * 1024)).toFixed(1)} MB`
16
- }
17
-
18
- function MessageFiles({ files }: { files: readonly ChatAttachment[] }) {
19
- return (
20
- <ul className="mt-2 flex flex-wrap gap-2">
21
- {files.map((file) => (
22
- <li
23
- key={file.id}
24
- className="border-border/70 bg-background/70 flex max-w-[15rem] items-center gap-2 rounded-xl border p-1.5"
25
- >
26
- <AttachmentPreview file={file.file} name={file.name} kind={file.kind} thumbnailClassName="size-12 rounded-lg" />
27
- <span className="min-w-0 pr-2">
28
- <span className="block truncate text-xs font-medium">{file.name}</span>
29
- <span className="text-muted mt-0.5 block font-mono text-[9px] uppercase">
30
- {formatBytes(file.size)}
31
- </span>
32
- </span>
33
- </li>
34
- ))}
35
- </ul>
36
- )
37
- }
38
-
39
- export type ChatMessageProps = {
40
- turn: ChatTurn
41
- userName: string
42
- assistantName: string
43
- userAvatar?: ReactNode
44
- assistantAvatar?: ReactNode
45
- onRetry?: () => void
46
- retryDisabled?: boolean
47
- }
48
-
49
- function ChatMessage({
50
- turn,
51
- userName,
52
- assistantName,
53
- userAvatar,
54
- assistantAvatar,
55
- onRetry,
56
- retryDisabled,
57
- }: ChatMessageProps) {
58
- const reduceMotion = useReducedMotion()
59
- const [manualThinkingOpen, setManualThinkingOpen] = useState<boolean | null>(null)
60
- const user = turn.role === 'user'
61
- const name = user ? userName : assistantName
62
- const avatar = user ? userAvatar : assistantAvatar
63
-
64
- const thinkingOpen = manualThinkingOpen ?? turn.status === 'streaming'
65
-
66
- return (
67
- <motion.article
68
- layout={!reduceMotion && turn.status !== 'streaming'}
69
- initial={reduceMotion ? { opacity: 0 } : { opacity: 0, y: 10 }}
70
- animate={{ opacity: 1, y: 0 }}
71
- transition={reduceMotion ? { duration: 0.1 } : { duration: 0.24, ease: 'easeOut' }}
72
- aria-label={`${name} message`}
73
- className={`flex items-start gap-2.5 sm:gap-3 ${user ? 'flex-row-reverse' : ''}`}
74
- >
75
- <span
76
- aria-hidden="true"
77
- className={`border-border/70 flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-full border ${user ? 'bg-surface/70 text-muted' : 'bg-[var(--chat-accent,var(--foreground))] text-white'}`}
78
- >
79
- {avatar ??
80
- (user ? (
81
- <IconUser size={15} stroke={1.7} />
82
- ) : (
83
- <ChatLogo className="size-4" />
84
- ))}
85
- </span>
86
-
87
- <div className={`min-w-0 max-w-[min(88%,44rem)] ${user ? 'items-end' : 'items-start'} flex flex-col`}>
88
- <span className={`text-muted mb-1 px-1 text-[10px] ${user ? 'text-right' : ''}`}>
89
- {name}
90
- </span>
91
- {turn.content || !user ? (
92
- <div className={`min-w-0 ${user ? 'rounded-2xl rounded-tr-md border border-[var(--chat-accent)]/80 bg-[var(--chat-accent)] px-3.5 py-2.5 text-white shadow-sm sm:px-4 sm:py-3' : 'w-full px-0 py-0 text-foreground'}`}>
93
- {!user && (turn.thinking || turn.status === 'streaming') ? (
94
- <div className="mb-2 max-w-full">
95
- <button type="button" aria-expanded={thinkingOpen} onClick={() => setManualThinkingOpen(!thinkingOpen)} className="text-muted hover:text-foreground w-fit cursor-pointer text-left text-[11px] transition-colors">
96
- <span className="inline-flex items-center gap-1.5">
97
- {turn.thinkingStatus === 'thinking' ? (
98
- <span className="bg-[var(--chat-accent)] size-1.5 animate-pulse rounded-full" />
99
- ) : null}
100
- {turn.thinkingStatus === 'thinking' ? 'Thinking…' : 'Thought process'}
101
- </span>
102
- </button>
103
- {thinkingOpen && turn.thinking ? <p className="text-muted mt-2 whitespace-pre-wrap text-xs leading-5">{turn.thinking}</p> : null}
104
- </div>
105
- ) : null}
106
- {turn.content ? (
107
- <MessageContent
108
- content={turn.content}
109
- streaming={turn.status === 'streaming'}
110
- streamingDelta={turn.streamingDelta}
111
- />
112
- ) : turn.status === 'streaming' ? (
113
- <MessageContent content="" streaming />
114
- ) : null}
115
- {!user && turn.attachments?.length ? (
116
- <MessageFiles files={turn.attachments} />
117
- ) : null}
118
- </div>
119
- ) : null}
120
- {user && turn.attachments?.length ? (
121
- <div className="mt-2 flex w-full justify-end">
122
- <MessageFiles files={turn.attachments} />
123
- </div>
124
- ) : null}
125
- <AnimatePresence>
126
- {turn.status === 'error' && turn.error ? (
127
- <motion.div
128
- initial={{ opacity: 0, height: 0, y: 5 }}
129
- animate={{ opacity: 1, height: 'auto', y: 0 }}
130
- exit={{ opacity: 0, height: 0 }}
131
- className="border-rose-500/30 bg-rose-500/5 mt-2 flex max-w-full items-start gap-2 rounded-xl border px-3 py-2.5 text-xs text-rose-200"
132
- role="alert"
133
- >
134
- <IconX size={14} stroke={1.8} className="mt-0.5 shrink-0" aria-hidden="true" />
135
- <span className="min-w-0 flex-1 leading-5">
136
- {turn.error.message}
137
- {turn.error.retryAfterMs ? (
138
- <span className="text-rose-200/70 mt-0.5 block font-mono text-[10px]">
139
- Retry after {Math.ceil(turn.error.retryAfterMs / 1000)}s
140
- </span>
141
- ) : null}
142
- </span>
143
- {onRetry ? (
144
- <button
145
- type="button"
146
- onClick={onRetry}
147
- disabled={retryDisabled}
148
- className="shrink-0 cursor-pointer rounded-md px-2 py-1 font-medium text-rose-100 underline underline-offset-2 disabled:cursor-not-allowed disabled:opacity-45"
149
- >
150
- Retry
151
- </button>
152
- ) : null}
153
- </motion.div>
154
- ) : null}
155
- </AnimatePresence>
156
- </div>
157
- </motion.article>
158
- )
159
- }
160
-
161
- export default memo(ChatMessage)
1
+ 'use client'
2
+
3
+ import { memo, useState } from 'react'
4
+ import type { ReactNode } from 'react'
5
+ import { AnimatePresence, motion, useReducedMotion } from 'motion/react'
6
+ import { IconUser, IconX } from '@tabler/icons-react'
7
+ import type { ChatAttachment, ChatTurn } from './types'
8
+ import MessageContent from './message-content'
9
+ import ChatLogo from './chat-logo'
10
+ import { AttachmentPreview } from './attachment'
11
+
12
+ function formatBytes(size: number) {
13
+ if (size < 1024) return `${size} B`
14
+ if (size < 1024 * 1024) return `${Math.round(size / 1024)} KB`
15
+ return `${(size / (1024 * 1024)).toFixed(1)} MB`
16
+ }
17
+
18
+ function MessageFiles({ files }: { files: readonly ChatAttachment[] }) {
19
+ return (
20
+ <ul className="mt-2 flex flex-wrap gap-2">
21
+ {files.map((file) => (
22
+ <li
23
+ key={file.id}
24
+ className="border-border/70 bg-background/70 flex max-w-[15rem] items-center gap-2 rounded-xl border p-1.5"
25
+ >
26
+ <AttachmentPreview file={file.file} name={file.name} kind={file.kind} thumbnailClassName="size-12 rounded-lg" />
27
+ <span className="min-w-0 pr-2">
28
+ <span className="block truncate text-xs font-medium">{file.name}</span>
29
+ <span className="text-muted mt-0.5 block font-mono text-[9px] uppercase">
30
+ {formatBytes(file.size)}
31
+ </span>
32
+ </span>
33
+ </li>
34
+ ))}
35
+ </ul>
36
+ )
37
+ }
38
+
39
+ export type ChatMessageProps = {
40
+ turn: ChatTurn
41
+ userName: string
42
+ assistantName: string
43
+ userAvatar?: ReactNode
44
+ assistantAvatar?: ReactNode
45
+ onRetry?: () => void
46
+ retryDisabled?: boolean
47
+ }
48
+
49
+ function ChatMessage({
50
+ turn,
51
+ userName,
52
+ assistantName,
53
+ userAvatar,
54
+ assistantAvatar,
55
+ onRetry,
56
+ retryDisabled,
57
+ }: ChatMessageProps) {
58
+ const reduceMotion = useReducedMotion()
59
+ const [manualThinkingOpen, setManualThinkingOpen] = useState<boolean | null>(null)
60
+ const user = turn.role === 'user'
61
+ const name = user ? userName : assistantName
62
+ const avatar = user ? userAvatar : assistantAvatar
63
+
64
+ const thinkingOpen = manualThinkingOpen ?? turn.status === 'streaming'
65
+
66
+ return (
67
+ <motion.article
68
+ layout={!reduceMotion && turn.status !== 'streaming'}
69
+ initial={reduceMotion ? { opacity: 0 } : { opacity: 0, y: 10 }}
70
+ animate={{ opacity: 1, y: 0 }}
71
+ transition={reduceMotion ? { duration: 0.1 } : { duration: 0.24, ease: 'easeOut' }}
72
+ aria-label={`${name} message`}
73
+ className={`flex items-start gap-2.5 sm:gap-3 ${user ? 'flex-row-reverse' : ''}`}
74
+ >
75
+ <span
76
+ aria-hidden="true"
77
+ className={`border-border/70 flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-full border ${user ? 'bg-surface/70 text-muted' : 'bg-[var(--chat-accent,var(--foreground))] text-white'}`}
78
+ >
79
+ {avatar ??
80
+ (user ? (
81
+ <IconUser size={15} stroke={1.7} />
82
+ ) : (
83
+ <ChatLogo className="size-4" />
84
+ ))}
85
+ </span>
86
+
87
+ <div className={`min-w-0 max-w-[min(88%,44rem)] ${user ? 'items-end' : 'items-start'} flex flex-col`}>
88
+ <span className={`text-muted mb-1 px-1 text-[10px] ${user ? 'text-right' : ''}`}>
89
+ {name}
90
+ </span>
91
+ {turn.content || !user ? (
92
+ <div className={`min-w-0 ${user ? 'rounded-2xl rounded-tr-md border border-[var(--chat-accent)]/80 bg-[var(--chat-accent)] px-3.5 py-2.5 text-white shadow-sm sm:px-4 sm:py-3' : 'w-full px-0 py-0 text-foreground'}`}>
93
+ {!user && (turn.thinking || turn.status === 'streaming') ? (
94
+ <div className="mb-2 max-w-full">
95
+ <button type="button" aria-expanded={thinkingOpen} onClick={() => setManualThinkingOpen(!thinkingOpen)} className="text-muted hover:text-foreground w-fit cursor-pointer text-left text-[11px] transition-colors">
96
+ <span className="inline-flex items-center gap-1.5">
97
+ {turn.thinkingStatus === 'thinking' ? (
98
+ <span className="bg-[var(--chat-accent)] size-1.5 animate-pulse rounded-full" />
99
+ ) : null}
100
+ {turn.thinkingStatus === 'thinking' ? 'Thinking…' : 'Thought process'}
101
+ </span>
102
+ </button>
103
+ {thinkingOpen && turn.thinking ? <p className="text-muted mt-2 whitespace-pre-wrap text-xs leading-5">{turn.thinking}</p> : null}
104
+ </div>
105
+ ) : null}
106
+ {turn.content ? (
107
+ <MessageContent
108
+ content={turn.content}
109
+ streaming={turn.status === 'streaming'}
110
+ streamingDelta={turn.streamingDelta}
111
+ />
112
+ ) : turn.status === 'streaming' ? (
113
+ <MessageContent content="" streaming />
114
+ ) : null}
115
+ {!user && turn.attachments?.length ? (
116
+ <MessageFiles files={turn.attachments} />
117
+ ) : null}
118
+ </div>
119
+ ) : null}
120
+ {user && turn.attachments?.length ? (
121
+ <div className="mt-2 flex w-full justify-end">
122
+ <MessageFiles files={turn.attachments} />
123
+ </div>
124
+ ) : null}
125
+ <AnimatePresence>
126
+ {turn.status === 'error' && turn.error ? (
127
+ <motion.div
128
+ initial={{ opacity: 0, height: 0, y: 5 }}
129
+ animate={{ opacity: 1, height: 'auto', y: 0 }}
130
+ exit={{ opacity: 0, height: 0 }}
131
+ className="border-rose-500/30 bg-rose-500/5 mt-2 flex max-w-full items-start gap-2 rounded-xl border px-3 py-2.5 text-xs text-rose-200"
132
+ role="alert"
133
+ >
134
+ <IconX size={14} stroke={1.8} className="mt-0.5 shrink-0" aria-hidden="true" />
135
+ <span className="min-w-0 flex-1 leading-5">
136
+ {turn.error.message}
137
+ {turn.error.retryAfterMs ? (
138
+ <span className="text-rose-200/70 mt-0.5 block font-mono text-[10px]">
139
+ Retry after {Math.ceil(turn.error.retryAfterMs / 1000)}s
140
+ </span>
141
+ ) : null}
142
+ </span>
143
+ {onRetry ? (
144
+ <button
145
+ type="button"
146
+ onClick={onRetry}
147
+ disabled={retryDisabled}
148
+ className="shrink-0 cursor-pointer rounded-md px-2 py-1 font-medium text-rose-100 underline underline-offset-2 disabled:cursor-not-allowed disabled:opacity-45"
149
+ >
150
+ Retry
151
+ </button>
152
+ ) : null}
153
+ </motion.div>
154
+ ) : null}
155
+ </AnimatePresence>
156
+ </div>
157
+ </motion.article>
158
+ )
159
+ }
160
+
161
+ export default memo(ChatMessage)