@istmx/ui 0.1.8 → 0.1.10
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/LICENSE +21 -0
- package/README.md +115 -1
- package/bin/istmx.mjs +53 -12
- package/package.json +2 -2
- package/registry/ai-chat-block/ai-chat-block.tsx +460 -0
- package/registry/ai-chat-block/ai-chat-input.tsx +690 -0
- package/registry/ai-chat-block/attachment.tsx +605 -0
- package/registry/ai-chat-block/chat-code-block.tsx +50 -0
- package/registry/ai-chat-block/chat-composer.tsx +51 -0
- package/registry/ai-chat-block/chat-logo.tsx +18 -0
- package/registry/ai-chat-block/chat-message.tsx +161 -0
- package/registry/ai-chat-block/chat-sidebar.tsx +273 -0
- package/registry/ai-chat-block/chat-user-avatar.tsx +9 -0
- package/registry/ai-chat-block/code-highlighter.tsx +357 -0
- package/registry/ai-chat-block/default-attachments.tsx +42 -0
- package/registry/ai-chat-block/index.ts +16 -0
- package/registry/ai-chat-block/message-content.tsx +287 -0
- package/registry/ai-chat-block/message-list.tsx +93 -0
- package/registry/ai-chat-block/send-button.tsx +102 -0
- package/registry/ai-chat-block/types.ts +71 -0
- package/registry/ai-chat-block/utils.ts +6 -0
- package/registry/ai-chat-block/voice-button.tsx +66 -0
- package/registry/ai-chat-input/ai-chat-input.tsx +690 -0
- package/registry/ai-chat-input/attachment.tsx +605 -0
- package/registry/ai-chat-input/send-button.tsx +102 -0
- package/registry/ai-chat-input/types.ts +71 -0
- package/registry/ai-chat-input/utils.ts +6 -0
- package/registry/ai-chat-input/voice-button.tsx +66 -0
- package/registry/button.tsx +4 -7
- package/registry/streaming-text.tsx +278 -0
- package/registry/text-reveal.tsx +307 -0
- package/registry/image-effects-card.tsx +0 -197
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef } from 'react'
|
|
4
|
+
import type { ReactNode } from 'react'
|
|
5
|
+
import { cn } from './utils'
|
|
6
|
+
import { AnimatePresence, motion, useReducedMotion } from 'motion/react'
|
|
7
|
+
import type { ChatTurn } from './types'
|
|
8
|
+
import ChatMessage from './chat-message'
|
|
9
|
+
import ChatLogo from './chat-logo'
|
|
10
|
+
|
|
11
|
+
export type MessageListProps = {
|
|
12
|
+
messages: readonly ChatTurn[]
|
|
13
|
+
userName: string
|
|
14
|
+
assistantName: string
|
|
15
|
+
userAvatar?: ReactNode
|
|
16
|
+
assistantAvatar?: ReactNode
|
|
17
|
+
onRetry?: (turnId: string) => void
|
|
18
|
+
retryDisabled?: boolean
|
|
19
|
+
emptyMessage?: string
|
|
20
|
+
className?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default function MessageList({
|
|
24
|
+
messages,
|
|
25
|
+
userName,
|
|
26
|
+
assistantName,
|
|
27
|
+
userAvatar,
|
|
28
|
+
assistantAvatar,
|
|
29
|
+
onRetry,
|
|
30
|
+
retryDisabled,
|
|
31
|
+
emptyMessage = 'Start a conversation. Your messages will appear here.',
|
|
32
|
+
className,
|
|
33
|
+
}: MessageListProps) {
|
|
34
|
+
const logRef = useRef<HTMLDivElement>(null)
|
|
35
|
+
const wasAtBottom = useRef(true)
|
|
36
|
+
const previousCount = useRef(messages.length)
|
|
37
|
+
const reduceMotion = useReducedMotion()
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const log = logRef.current
|
|
41
|
+
if (!log) return
|
|
42
|
+
const newMessageAdded = messages.length > previousCount.current
|
|
43
|
+
previousCount.current = messages.length
|
|
44
|
+
if (wasAtBottom.current || newMessageAdded) log.scrollTop = log.scrollHeight
|
|
45
|
+
}, [messages])
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div
|
|
49
|
+
role="log"
|
|
50
|
+
ref={logRef}
|
|
51
|
+
onScroll={(event) => {
|
|
52
|
+
const log = event.currentTarget
|
|
53
|
+
wasAtBottom.current = log.scrollHeight - log.scrollTop - log.clientHeight < 48
|
|
54
|
+
}}
|
|
55
|
+
aria-label="Chat conversation"
|
|
56
|
+
aria-relevant="additions text"
|
|
57
|
+
className={cn('[scrollbar-width:none] [&::-webkit-scrollbar]:hidden min-h-0 flex-1 overflow-y-auto overscroll-contain px-3 py-4 sm:px-5 sm:py-5', className)}
|
|
58
|
+
>
|
|
59
|
+
{messages.length ? (
|
|
60
|
+
<div className="space-y-5 sm:space-y-6">
|
|
61
|
+
<AnimatePresence initial={false}>
|
|
62
|
+
{messages.map((turn) => (
|
|
63
|
+
<ChatMessage
|
|
64
|
+
key={turn.id}
|
|
65
|
+
turn={turn}
|
|
66
|
+
userName={userName}
|
|
67
|
+
assistantName={assistantName}
|
|
68
|
+
userAvatar={userAvatar}
|
|
69
|
+
assistantAvatar={assistantAvatar}
|
|
70
|
+
onRetry={turn.status === 'error' && onRetry ? () => onRetry(turn.id) : undefined}
|
|
71
|
+
retryDisabled={retryDisabled}
|
|
72
|
+
/>
|
|
73
|
+
))}
|
|
74
|
+
</AnimatePresence>
|
|
75
|
+
<div aria-hidden="true" />
|
|
76
|
+
</div>
|
|
77
|
+
) : (
|
|
78
|
+
<motion.div
|
|
79
|
+
initial={{ opacity: 0 }}
|
|
80
|
+
animate={{ opacity: 1 }}
|
|
81
|
+
transition={{ duration: reduceMotion ? 0 : 0.3 }}
|
|
82
|
+
className="flex min-h-48 flex-col items-center justify-center px-4 text-center sm:min-h-56"
|
|
83
|
+
>
|
|
84
|
+
<span className="bg-[var(--chat-accent,var(--foreground))]/10 text-[var(--chat-accent,var(--foreground))] mb-3 flex size-10 items-center justify-center rounded-2xl">
|
|
85
|
+
<ChatLogo className="size-5" />
|
|
86
|
+
</span>
|
|
87
|
+
<p className="font-display text-sm font-medium">Start a conversation</p>
|
|
88
|
+
<p className="text-muted mt-1 max-w-sm text-xs leading-5">{emptyMessage}</p>
|
|
89
|
+
</motion.div>
|
|
90
|
+
)}
|
|
91
|
+
</div>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AnimatePresence,
|
|
5
|
+
motion,
|
|
6
|
+
useAnimationControls,
|
|
7
|
+
useReducedMotion,
|
|
8
|
+
} from 'motion/react'
|
|
9
|
+
import { IconArrowUp, IconCheck, IconLoader, IconPlayerStop } from '@tabler/icons-react'
|
|
10
|
+
|
|
11
|
+
export type SendButtonProps = {
|
|
12
|
+
state: 'idle' | 'ready' | 'sending' | 'sent'
|
|
13
|
+
disabled?: boolean
|
|
14
|
+
label?: string
|
|
15
|
+
shakeControls?: ReturnType<typeof useAnimationControls>
|
|
16
|
+
onClick: () => void
|
|
17
|
+
onStop?: () => void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function SendButton({
|
|
21
|
+
state,
|
|
22
|
+
disabled = false,
|
|
23
|
+
label = 'Send message',
|
|
24
|
+
shakeControls,
|
|
25
|
+
onClick,
|
|
26
|
+
onStop,
|
|
27
|
+
}: SendButtonProps) {
|
|
28
|
+
const reduceMotion = useReducedMotion()
|
|
29
|
+
const active = state === 'ready' || state === 'sent'
|
|
30
|
+
const canStop = state === 'sending' && Boolean(onStop)
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<motion.button
|
|
34
|
+
type="button"
|
|
35
|
+
onClick={canStop ? onStop : onClick}
|
|
36
|
+
aria-label={canStop ? 'Stop generating response' : state === 'sending' ? 'Sending message' : label}
|
|
37
|
+
title={canStop ? 'Stop generating' : label}
|
|
38
|
+
aria-disabled={disabled || (!active && !canStop)}
|
|
39
|
+
disabled={disabled || (!active && !canStop)}
|
|
40
|
+
animate={shakeControls}
|
|
41
|
+
whileTap={reduceMotion || (!active && !canStop) ? undefined : { scale: 0.9 }}
|
|
42
|
+
whileHover={reduceMotion || state !== 'ready' ? undefined : { y: -1 }}
|
|
43
|
+
className={`focus-visible:outline-foreground relative flex size-8 shrink-0 items-center justify-center rounded-xl border transition-[color,background-color,border-color,box-shadow] duration-200 focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-60 sm:size-9 ${
|
|
44
|
+
canStop
|
|
45
|
+
? 'border-[var(--chat-accent,var(--foreground))] bg-[var(--chat-accent,var(--foreground))] text-white hover:opacity-85'
|
|
46
|
+
: active
|
|
47
|
+
? 'border-[var(--chat-accent,var(--foreground))] bg-[var(--chat-accent,var(--foreground))] text-white hover:shadow-[0_10px_26px_-12px_var(--chat-accent,var(--foreground))]'
|
|
48
|
+
: 'border-border/70 bg-surface/40 text-muted/60'
|
|
49
|
+
}`}
|
|
50
|
+
>
|
|
51
|
+
<AnimatePresence mode="wait" initial={false}>
|
|
52
|
+
{state === 'sending' && canStop ? (
|
|
53
|
+
<motion.span
|
|
54
|
+
key="stop"
|
|
55
|
+
initial={{ opacity: 0, scale: 0.7 }}
|
|
56
|
+
animate={{ opacity: 1, scale: 1 }}
|
|
57
|
+
exit={{ opacity: 0, scale: 0.7 }}
|
|
58
|
+
className="flex items-center justify-center"
|
|
59
|
+
>
|
|
60
|
+
<IconPlayerStop size={13} fill="currentColor" aria-hidden="true" />
|
|
61
|
+
</motion.span>
|
|
62
|
+
) : state === 'sending' ? (
|
|
63
|
+
<motion.span
|
|
64
|
+
key="sending"
|
|
65
|
+
initial={{ opacity: 0, scale: 0.7 }}
|
|
66
|
+
animate={{ opacity: 1, scale: 1 }}
|
|
67
|
+
exit={{ opacity: 0, scale: 0.7 }}
|
|
68
|
+
className="flex items-center justify-center"
|
|
69
|
+
>
|
|
70
|
+
<IconLoader
|
|
71
|
+
size={16}
|
|
72
|
+
stroke={1.8}
|
|
73
|
+
aria-hidden="true"
|
|
74
|
+
className="motion-safe:animate-spin"
|
|
75
|
+
/>
|
|
76
|
+
</motion.span>
|
|
77
|
+
) : state === 'sent' ? (
|
|
78
|
+
<motion.span
|
|
79
|
+
key="sent"
|
|
80
|
+
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.5 }}
|
|
81
|
+
animate={{ opacity: 1, scale: 1 }}
|
|
82
|
+
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.5 }}
|
|
83
|
+
transition={reduceMotion ? { duration: 0 } : { type: 'spring', stiffness: 520, damping: 24 }}
|
|
84
|
+
className="flex items-center justify-center"
|
|
85
|
+
>
|
|
86
|
+
<IconCheck size={17} stroke={2} aria-hidden="true" />
|
|
87
|
+
</motion.span>
|
|
88
|
+
) : (
|
|
89
|
+
<motion.span
|
|
90
|
+
key="idle"
|
|
91
|
+
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, y: 5 }}
|
|
92
|
+
animate={{ opacity: 1, y: 0 }}
|
|
93
|
+
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, y: -5 }}
|
|
94
|
+
className="flex items-center justify-center"
|
|
95
|
+
>
|
|
96
|
+
<IconArrowUp size={17} stroke={1.9} aria-hidden="true" />
|
|
97
|
+
</motion.span>
|
|
98
|
+
)}
|
|
99
|
+
</AnimatePresence>
|
|
100
|
+
</motion.button>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
export type ChatAttachmentKind = 'image' | 'video' | 'audio' | 'file'
|
|
4
|
+
|
|
5
|
+
export type ChatAttachment = {
|
|
6
|
+
id: string
|
|
7
|
+
name: string
|
|
8
|
+
kind: ChatAttachmentKind
|
|
9
|
+
size: number
|
|
10
|
+
file: File
|
|
11
|
+
url?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type AttachmentOption = {
|
|
15
|
+
id: string
|
|
16
|
+
label: string
|
|
17
|
+
description?: string
|
|
18
|
+
icon?: ReactNode
|
|
19
|
+
accept: string
|
|
20
|
+
multiple?: boolean
|
|
21
|
+
capture?: 'user' | 'environment'
|
|
22
|
+
disabled?: boolean
|
|
23
|
+
onSelect?: () => void
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type ChatTurn = {
|
|
27
|
+
id: string
|
|
28
|
+
role: 'user' | 'assistant'
|
|
29
|
+
content: string
|
|
30
|
+
/** Text added in the latest throttled stream update, for a small reveal. */
|
|
31
|
+
streamingDelta?: string
|
|
32
|
+
attachments?: ChatAttachment[]
|
|
33
|
+
status?: 'streaming' | 'complete' | 'error'
|
|
34
|
+
error?: {
|
|
35
|
+
message: string
|
|
36
|
+
retryAfterMs?: number
|
|
37
|
+
retryAt?: number
|
|
38
|
+
}
|
|
39
|
+
thinking?: string
|
|
40
|
+
thinkingStatus?: 'thinking' | 'complete'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ChatThread = {
|
|
44
|
+
id: string
|
|
45
|
+
title: string
|
|
46
|
+
messages: readonly ChatTurn[]
|
|
47
|
+
pinned?: boolean
|
|
48
|
+
archived?: boolean
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type ChatRequest = {
|
|
52
|
+
message: string
|
|
53
|
+
attachments: readonly ChatAttachment[]
|
|
54
|
+
signal: AbortSignal
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type ChatStreamChunk =
|
|
58
|
+
| string
|
|
59
|
+
| {
|
|
60
|
+
content?: unknown
|
|
61
|
+
text?: unknown
|
|
62
|
+
delta?: unknown
|
|
63
|
+
type?: 'text-delta' | 'thinking-delta' | 'reasoning-delta'
|
|
64
|
+
}
|
|
65
|
+
| readonly unknown[]
|
|
66
|
+
|
|
67
|
+
export type ChatResponse = string | AsyncIterable<ChatStreamChunk>
|
|
68
|
+
|
|
69
|
+
export type ChatSendError = Error & {
|
|
70
|
+
retryAfterMs?: number
|
|
71
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { AnimatePresence, motion, useReducedMotion } from 'motion/react'
|
|
4
|
+
import { IconMicrophone, IconPlayerStop } from '@tabler/icons-react'
|
|
5
|
+
|
|
6
|
+
export type VoiceButtonProps = {
|
|
7
|
+
listening: boolean
|
|
8
|
+
disabled?: boolean
|
|
9
|
+
onClick: () => void
|
|
10
|
+
startLabel?: string
|
|
11
|
+
stopLabel?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default function VoiceButton({
|
|
15
|
+
listening,
|
|
16
|
+
disabled = false,
|
|
17
|
+
onClick,
|
|
18
|
+
startLabel = 'Start voice input',
|
|
19
|
+
stopLabel = 'Stop voice input',
|
|
20
|
+
}: VoiceButtonProps) {
|
|
21
|
+
const reduceMotion = useReducedMotion()
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<motion.button
|
|
25
|
+
type="button"
|
|
26
|
+
onClick={onClick}
|
|
27
|
+
aria-pressed={listening}
|
|
28
|
+
aria-label={listening ? stopLabel : startLabel}
|
|
29
|
+
title={listening ? stopLabel : startLabel}
|
|
30
|
+
disabled={disabled}
|
|
31
|
+
whileTap={reduceMotion ? undefined : { scale: 0.9 }}
|
|
32
|
+
whileHover={reduceMotion ? undefined : { y: -1 }}
|
|
33
|
+
className={`focus-visible:outline-foreground relative flex size-8 shrink-0 cursor-pointer items-center justify-center overflow-visible rounded-xl border transition-colors duration-200 focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-50 sm:size-9 ${
|
|
34
|
+
listening
|
|
35
|
+
? 'border-[var(--chat-accent,var(--foreground))] bg-[var(--chat-accent,var(--foreground))] text-white'
|
|
36
|
+
: 'border-border/70 bg-surface/40 text-muted hover:border-foreground/40 hover:text-foreground'
|
|
37
|
+
}`}
|
|
38
|
+
>
|
|
39
|
+
{listening && !reduceMotion ? (
|
|
40
|
+
<motion.span
|
|
41
|
+
aria-hidden="true"
|
|
42
|
+
className="border-[var(--chat-accent,var(--foreground))] pointer-events-none absolute inset-0 rounded-[inherit] border"
|
|
43
|
+
initial={{ opacity: 0.5, scale: 1 }}
|
|
44
|
+
animate={{ opacity: 0, scale: 1.55 }}
|
|
45
|
+
transition={{ repeat: Infinity, duration: 1.5, ease: 'easeOut' }}
|
|
46
|
+
/>
|
|
47
|
+
) : null}
|
|
48
|
+
<AnimatePresence mode="wait" initial={false}>
|
|
49
|
+
<motion.span
|
|
50
|
+
key={listening ? 'on' : 'off'}
|
|
51
|
+
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.6, rotate: -35 }}
|
|
52
|
+
animate={{ opacity: 1, scale: 1, rotate: 0 }}
|
|
53
|
+
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.6, rotate: 35 }}
|
|
54
|
+
transition={{ duration: reduceMotion ? 0 : 0.16 }}
|
|
55
|
+
className="relative flex items-center justify-center"
|
|
56
|
+
>
|
|
57
|
+
{listening ? (
|
|
58
|
+
<IconPlayerStop size={13} stroke={1.6} aria-hidden="true" />
|
|
59
|
+
) : (
|
|
60
|
+
<IconMicrophone size={17} stroke={1.7} aria-hidden="true" />
|
|
61
|
+
)}
|
|
62
|
+
</motion.span>
|
|
63
|
+
</AnimatePresence>
|
|
64
|
+
</motion.button>
|
|
65
|
+
)
|
|
66
|
+
}
|