@leitware/composables 0.1.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.
- package/LICENSE +21 -0
- package/README.md +387 -0
- package/dist/presets/brutalist.css +298 -0
- package/dist/presets/default.css +298 -0
- package/dist/presets/signal-pop.css +369 -0
- package/dist/styles.css +2 -0
- package/package.json +216 -0
- package/rules/composables.md +244 -0
- package/src/_internal/accordion.tsx +93 -0
- package/src/_internal/ai-elements/attachments.tsx +385 -0
- package/src/_internal/ai-elements/chain-of-thought.tsx +197 -0
- package/src/_internal/ai-elements/code-block.tsx +516 -0
- package/src/_internal/ai-elements/confirmation.tsx +150 -0
- package/src/_internal/ai-elements/conversation.tsx +148 -0
- package/src/_internal/ai-elements/inline-citation.tsx +248 -0
- package/src/_internal/ai-elements/message.tsx +292 -0
- package/src/_internal/ai-elements/plan.tsx +126 -0
- package/src/_internal/ai-elements/prompt-input.tsx +1285 -0
- package/src/_internal/ai-elements/reasoning.tsx +208 -0
- package/src/_internal/ai-elements/shimmer.tsx +72 -0
- package/src/_internal/ai-elements/sources.tsx +53 -0
- package/src/_internal/ai-elements/suggestion.tsx +48 -0
- package/src/_internal/ai-elements/task.tsx +64 -0
- package/src/_internal/ai-elements/tool.tsx +156 -0
- package/src/_internal/alert-dialog.tsx +159 -0
- package/src/_internal/alert.tsx +88 -0
- package/src/_internal/aspect-ratio.tsx +23 -0
- package/src/_internal/avatar.tsx +58 -0
- package/src/_internal/badge.tsx +60 -0
- package/src/_internal/breadcrumb.tsx +104 -0
- package/src/_internal/bubble.tsx +125 -0
- package/src/_internal/button-group.tsx +78 -0
- package/src/_internal/button.tsx +62 -0
- package/src/_internal/calendar.tsx +179 -0
- package/src/_internal/card.tsx +83 -0
- package/src/_internal/carousel.tsx +215 -0
- package/src/_internal/checkbox.tsx +26 -0
- package/src/_internal/code-block.tsx +53 -0
- package/src/_internal/collapsible.tsx +15 -0
- package/src/_internal/combobox.tsx +264 -0
- package/src/_internal/command.tsx +155 -0
- package/src/_internal/container.tsx +35 -0
- package/src/_internal/dialog.tsx +132 -0
- package/src/_internal/direction.tsx +12 -0
- package/src/_internal/divider.tsx +162 -0
- package/src/_internal/dropdown-menu.tsx +247 -0
- package/src/_internal/dropzone.tsx +481 -0
- package/src/_internal/empty.tsx +94 -0
- package/src/_internal/field.tsx +221 -0
- package/src/_internal/grid-overlay.tsx +48 -0
- package/src/_internal/grid.tsx +109 -0
- package/src/_internal/hover-card.tsx +47 -0
- package/src/_internal/icon.tsx +45 -0
- package/src/_internal/input-group.tsx +146 -0
- package/src/_internal/input.tsx +24 -0
- package/src/_internal/item.tsx +187 -0
- package/src/_internal/kbd.tsx +28 -0
- package/src/_internal/label.tsx +18 -0
- package/src/_internal/layout-bento.tsx +386 -0
- package/src/_internal/layout.tsx +174 -0
- package/src/_internal/marker.tsx +66 -0
- package/src/_internal/message.tsx +85 -0
- package/src/_internal/native-select.tsx +50 -0
- package/src/_internal/pagination.tsx +108 -0
- package/src/_internal/popover.tsx +83 -0
- package/src/_internal/progress.tsx +59 -0
- package/src/_internal/radio-group.tsx +36 -0
- package/src/_internal/resizable.tsx +44 -0
- package/src/_internal/scroll-area.tsx +48 -0
- package/src/_internal/select.tsx +187 -0
- package/src/_internal/separator.tsx +19 -0
- package/src/_internal/sheet.tsx +122 -0
- package/src/_internal/sidebar.tsx +687 -0
- package/src/_internal/skeleton.tsx +13 -0
- package/src/_internal/slider.tsx +60 -0
- package/src/_internal/sonner.tsx +51 -0
- package/src/_internal/spacer.tsx +42 -0
- package/src/_internal/spinner.tsx +16 -0
- package/src/_internal/stack.tsx +78 -0
- package/src/_internal/switch.tsx +31 -0
- package/src/_internal/table.tsx +84 -0
- package/src/_internal/tabs.tsx +74 -0
- package/src/_internal/textarea.tsx +19 -0
- package/src/_internal/toggle-group.tsx +99 -0
- package/src/_internal/toggle.tsx +42 -0
- package/src/_internal/tooltip.tsx +55 -0
- package/src/_internal/typography.tsx +129 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/hooks/use-numeric-input.ts +119 -0
- package/src/index.ts +443 -0
- package/src/lib/numeric-input.ts +88 -0
- package/src/lib/utils.ts +39 -0
- package/src/opinionated/accordion.tsx +92 -0
- package/src/opinionated/ai/attachments.tsx +27 -0
- package/src/opinionated/ai/chain-of-thought.tsx +16 -0
- package/src/opinionated/ai/code-block.tsx +22 -0
- package/src/opinionated/ai/confirmation.tsx +16 -0
- package/src/opinionated/ai/conversation.tsx +13 -0
- package/src/opinionated/ai/index.ts +15 -0
- package/src/opinionated/ai/inline-citation.tsx +30 -0
- package/src/opinionated/ai/message.tsx +26 -0
- package/src/opinionated/ai/plan.tsx +18 -0
- package/src/opinionated/ai/prompt-input.tsx +29 -0
- package/src/opinionated/ai/reasoning.tsx +9 -0
- package/src/opinionated/ai/shimmer.tsx +4 -0
- package/src/opinionated/ai/sources.tsx +10 -0
- package/src/opinionated/ai/suggestion.tsx +6 -0
- package/src/opinionated/ai/task.tsx +12 -0
- package/src/opinionated/ai/tool.tsx +14 -0
- package/src/opinionated/alert-dialog.tsx +143 -0
- package/src/opinionated/alert.tsx +99 -0
- package/src/opinionated/aspect-ratio.tsx +12 -0
- package/src/opinionated/avatar.tsx +59 -0
- package/src/opinionated/badge.tsx +33 -0
- package/src/opinionated/breadcrumb.tsx +99 -0
- package/src/opinionated/bubble.tsx +9 -0
- package/src/opinionated/button.tsx +59 -0
- package/src/opinionated/calendar.tsx +20 -0
- package/src/opinionated/card.tsx +83 -0
- package/src/opinionated/carousel.tsx +99 -0
- package/src/opinionated/checkbox.tsx +11 -0
- package/src/opinionated/code-block.tsx +12 -0
- package/src/opinionated/collapsible.tsx +123 -0
- package/src/opinionated/combobox.tsx +123 -0
- package/src/opinionated/container.tsx +12 -0
- package/src/opinionated/dialog.tsx +124 -0
- package/src/opinionated/direction.tsx +6 -0
- package/src/opinionated/divider.tsx +13 -0
- package/src/opinionated/dropdown-menu.tsx +131 -0
- package/src/opinionated/dropzone.tsx +39 -0
- package/src/opinionated/empty.tsx +191 -0
- package/src/opinionated/field.tsx +26 -0
- package/src/opinionated/form-calendar-popover.tsx +138 -0
- package/src/opinionated/form-checkbox.tsx +107 -0
- package/src/opinionated/form-combobox.tsx +181 -0
- package/src/opinionated/form-date-of-birth.tsx +193 -0
- package/src/opinionated/form-dropzone.tsx +126 -0
- package/src/opinionated/form-input-group.tsx +184 -0
- package/src/opinionated/form-input.tsx +118 -0
- package/src/opinionated/form-multi-combobox.tsx +213 -0
- package/src/opinionated/form-multi-dropzone.tsx +141 -0
- package/src/opinionated/form-radiogroup.tsx +116 -0
- package/src/opinionated/form-select.tsx +176 -0
- package/src/opinionated/form-slider.tsx +100 -0
- package/src/opinionated/form-switch.tsx +117 -0
- package/src/opinionated/form-textarea.tsx +79 -0
- package/src/opinionated/grid-overlay.tsx +11 -0
- package/src/opinionated/grid.tsx +14 -0
- package/src/opinionated/hover-card.tsx +59 -0
- package/src/opinionated/icon.tsx +14 -0
- package/src/opinionated/input-group.tsx +20 -0
- package/src/opinionated/input.tsx +11 -0
- package/src/opinionated/item.tsx +182 -0
- package/src/opinionated/kbd.tsx +16 -0
- package/src/opinionated/label.tsx +11 -0
- package/src/opinionated/layout-bento.tsx +29 -0
- package/src/opinionated/layout.tsx +26 -0
- package/src/opinionated/list.tsx +94 -0
- package/src/opinionated/marker.tsx +7 -0
- package/src/opinionated/message.tsx +8 -0
- package/src/opinionated/native-select.tsx +51 -0
- package/src/opinionated/pagination.tsx +204 -0
- package/src/opinionated/popover.tsx +68 -0
- package/src/opinionated/progress.tsx +48 -0
- package/src/opinionated/radio-group.tsx +13 -0
- package/src/opinionated/resizable.tsx +2 -0
- package/src/opinionated/scroll-area.tsx +82 -0
- package/src/opinionated/select.tsx +101 -0
- package/src/opinionated/separator.tsx +11 -0
- package/src/opinionated/sheet.tsx +120 -0
- package/src/opinionated/sidebar.tsx +68 -0
- package/src/opinionated/skeleton.tsx +246 -0
- package/src/opinionated/slider.tsx +11 -0
- package/src/opinionated/sonner.tsx +15 -0
- package/src/opinionated/spacer.tsx +11 -0
- package/src/opinionated/stack.tsx +18 -0
- package/src/opinionated/switch.tsx +11 -0
- package/src/opinionated/table.tsx +11 -0
- package/src/opinionated/tabs.tsx +68 -0
- package/src/opinionated/textarea.tsx +11 -0
- package/src/opinionated/theme-injector.tsx +31 -0
- package/src/opinionated/toggle-group.tsx +63 -0
- package/src/opinionated/toggle.tsx +75 -0
- package/src/opinionated/token-config-panel/color-editor.tsx +85 -0
- package/src/opinionated/token-config-panel/helpers.ts +31 -0
- package/src/opinionated/token-config-panel/index.tsx +398 -0
- package/src/opinionated/token-config-panel/json-import-export.tsx +89 -0
- package/src/opinionated/token-config-panel/preset-manager.ts +31 -0
- package/src/opinionated/token-config-panel/presets-data.ts +23 -0
- package/src/opinionated/token-config-panel/spacing-editor.tsx +325 -0
- package/src/opinionated/token-config-panel/types.ts +39 -0
- package/src/opinionated/token-config-panel/typography-editor.tsx +145 -0
- package/src/opinionated/tooltip.tsx +62 -0
- package/src/opinionated/typography.tsx +7 -0
- package/src/scripts/lint-no-arbitrary.ts +155 -0
- package/src/styles/composable.css +68 -0
- package/src/styles/presets/brutalist.css +298 -0
- package/src/styles/presets/default.css +298 -0
- package/src/styles/presets/signal-pop.css +369 -0
- package/src/styles/presets-data/brutalist.ts +325 -0
- package/src/styles/presets-data/default.ts +315 -0
- package/src/styles/presets-data/index.ts +45 -0
- package/src/styles/presets-data/signal-pop.ts +393 -0
- package/src/styles/tokens/base.css +71 -0
- package/src/styles/tokens/components.css +150 -0
- package/src/styles/tokens/palette.css +795 -0
- package/src/styles/tokens/registry.ts +324 -0
- package/src/styles/tokens/semantic.css +266 -0
- package/src/styles/tokens/tailwind-theme.css +247 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useControllableState } from '@radix-ui/react-use-controllable-state'
|
|
4
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../collapsible'
|
|
5
|
+
import { cn } from '../../lib/utils'
|
|
6
|
+
import { cjk } from '@streamdown/cjk'
|
|
7
|
+
import { code } from '@streamdown/code'
|
|
8
|
+
import { math } from '@streamdown/math'
|
|
9
|
+
import { mermaid } from '@streamdown/mermaid'
|
|
10
|
+
import { BrainIcon, ChevronDownIcon } from 'lucide-react'
|
|
11
|
+
import type { ComponentProps, ReactNode } from 'react'
|
|
12
|
+
import {
|
|
13
|
+
createContext,
|
|
14
|
+
memo,
|
|
15
|
+
useCallback,
|
|
16
|
+
useContext,
|
|
17
|
+
useEffect,
|
|
18
|
+
useMemo,
|
|
19
|
+
useRef,
|
|
20
|
+
useState,
|
|
21
|
+
} from 'react'
|
|
22
|
+
import { Streamdown } from 'streamdown'
|
|
23
|
+
|
|
24
|
+
import { Shimmer } from './shimmer'
|
|
25
|
+
|
|
26
|
+
interface ReasoningContextValue {
|
|
27
|
+
isStreaming: boolean
|
|
28
|
+
isOpen: boolean
|
|
29
|
+
setIsOpen: (open: boolean) => void
|
|
30
|
+
duration: number | undefined
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const ReasoningContext = createContext<ReasoningContextValue | null>(null)
|
|
34
|
+
|
|
35
|
+
export const useReasoning = () => {
|
|
36
|
+
const context = useContext(ReasoningContext)
|
|
37
|
+
if (!context) {
|
|
38
|
+
throw new Error('Reasoning components must be used within Reasoning')
|
|
39
|
+
}
|
|
40
|
+
return context
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ReasoningProps = ComponentProps<typeof Collapsible> & {
|
|
44
|
+
isStreaming?: boolean
|
|
45
|
+
open?: boolean
|
|
46
|
+
defaultOpen?: boolean
|
|
47
|
+
onOpenChange?: (open: boolean) => void
|
|
48
|
+
duration?: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const AUTO_CLOSE_DELAY = 1000
|
|
52
|
+
const MS_IN_S = 1000
|
|
53
|
+
|
|
54
|
+
export const Reasoning = memo(
|
|
55
|
+
({
|
|
56
|
+
className,
|
|
57
|
+
isStreaming = false,
|
|
58
|
+
open,
|
|
59
|
+
defaultOpen,
|
|
60
|
+
onOpenChange,
|
|
61
|
+
duration: durationProp,
|
|
62
|
+
children,
|
|
63
|
+
...props
|
|
64
|
+
}: ReasoningProps) => {
|
|
65
|
+
const resolvedDefaultOpen = defaultOpen ?? isStreaming
|
|
66
|
+
// Track if defaultOpen was explicitly set to false (to prevent auto-open)
|
|
67
|
+
const isExplicitlyClosed = defaultOpen === false
|
|
68
|
+
|
|
69
|
+
const [isOpen, setIsOpen] = useControllableState<boolean>({
|
|
70
|
+
defaultProp: resolvedDefaultOpen,
|
|
71
|
+
onChange: onOpenChange,
|
|
72
|
+
prop: open,
|
|
73
|
+
})
|
|
74
|
+
const [duration, setDuration] = useControllableState<number | undefined>({
|
|
75
|
+
defaultProp: undefined,
|
|
76
|
+
prop: durationProp,
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const hasEverStreamedRef = useRef(isStreaming)
|
|
80
|
+
const [hasAutoClosed, setHasAutoClosed] = useState(false)
|
|
81
|
+
const startTimeRef = useRef<number | null>(null)
|
|
82
|
+
|
|
83
|
+
// Track when streaming starts and compute duration
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (isStreaming) {
|
|
86
|
+
hasEverStreamedRef.current = true
|
|
87
|
+
if (startTimeRef.current === null) {
|
|
88
|
+
startTimeRef.current = Date.now()
|
|
89
|
+
}
|
|
90
|
+
} else if (startTimeRef.current !== null) {
|
|
91
|
+
setDuration(Math.ceil((Date.now() - startTimeRef.current) / MS_IN_S))
|
|
92
|
+
startTimeRef.current = null
|
|
93
|
+
}
|
|
94
|
+
}, [isStreaming, setDuration])
|
|
95
|
+
|
|
96
|
+
// Auto-open when streaming starts (unless explicitly closed)
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (isStreaming && !isOpen && !isExplicitlyClosed) {
|
|
99
|
+
setIsOpen(true)
|
|
100
|
+
}
|
|
101
|
+
}, [isStreaming, isOpen, setIsOpen, isExplicitlyClosed])
|
|
102
|
+
|
|
103
|
+
// Auto-close when streaming ends (once only, and only if it ever streamed)
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (hasEverStreamedRef.current && !isStreaming && isOpen && !hasAutoClosed) {
|
|
106
|
+
const timer = setTimeout(() => {
|
|
107
|
+
setIsOpen(false)
|
|
108
|
+
setHasAutoClosed(true)
|
|
109
|
+
}, AUTO_CLOSE_DELAY)
|
|
110
|
+
|
|
111
|
+
return () => clearTimeout(timer)
|
|
112
|
+
}
|
|
113
|
+
}, [isStreaming, isOpen, setIsOpen, hasAutoClosed])
|
|
114
|
+
|
|
115
|
+
const handleOpenChange = useCallback(
|
|
116
|
+
(newOpen: boolean) => {
|
|
117
|
+
setIsOpen(newOpen)
|
|
118
|
+
},
|
|
119
|
+
[setIsOpen],
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
const contextValue = useMemo(
|
|
123
|
+
() => ({ duration, isOpen, isStreaming, setIsOpen }),
|
|
124
|
+
[duration, isOpen, isStreaming, setIsOpen],
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<ReasoningContext.Provider value={contextValue}>
|
|
129
|
+
<Collapsible
|
|
130
|
+
className={cn('not-prose mb-4', className)}
|
|
131
|
+
onOpenChange={handleOpenChange}
|
|
132
|
+
open={isOpen}
|
|
133
|
+
{...props}
|
|
134
|
+
>
|
|
135
|
+
{children}
|
|
136
|
+
</Collapsible>
|
|
137
|
+
</ReasoningContext.Provider>
|
|
138
|
+
)
|
|
139
|
+
},
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
export type ReasoningTriggerProps = ComponentProps<typeof CollapsibleTrigger> & {
|
|
143
|
+
getThinkingMessage?: (isStreaming: boolean, duration?: number) => ReactNode
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const defaultGetThinkingMessage = (isStreaming: boolean, duration?: number) => {
|
|
147
|
+
if (isStreaming || duration === 0) {
|
|
148
|
+
return <Shimmer duration={1}>Thinking...</Shimmer>
|
|
149
|
+
}
|
|
150
|
+
if (duration === undefined) {
|
|
151
|
+
return <p>Thought for a few seconds</p>
|
|
152
|
+
}
|
|
153
|
+
return <p>Thought for {duration} seconds</p>
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export const ReasoningTrigger = memo(
|
|
157
|
+
({
|
|
158
|
+
className,
|
|
159
|
+
children,
|
|
160
|
+
getThinkingMessage = defaultGetThinkingMessage,
|
|
161
|
+
...props
|
|
162
|
+
}: ReasoningTriggerProps) => {
|
|
163
|
+
const { isStreaming, isOpen, duration } = useReasoning()
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<CollapsibleTrigger
|
|
167
|
+
className={cn(
|
|
168
|
+
'flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground',
|
|
169
|
+
className,
|
|
170
|
+
)}
|
|
171
|
+
{...props}
|
|
172
|
+
>
|
|
173
|
+
{children ?? (
|
|
174
|
+
<>
|
|
175
|
+
<BrainIcon className="size-4" />
|
|
176
|
+
{getThinkingMessage(isStreaming, duration)}
|
|
177
|
+
<ChevronDownIcon
|
|
178
|
+
className={cn('size-4 transition-transform', isOpen ? 'rotate-180' : 'rotate-0')}
|
|
179
|
+
/>
|
|
180
|
+
</>
|
|
181
|
+
)}
|
|
182
|
+
</CollapsibleTrigger>
|
|
183
|
+
)
|
|
184
|
+
},
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
export type ReasoningContentProps = ComponentProps<typeof CollapsibleContent> & {
|
|
188
|
+
children: string
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const streamdownPlugins = { cjk, code, math, mermaid }
|
|
192
|
+
|
|
193
|
+
export const ReasoningContent = memo(({ className, children, ...props }: ReasoningContentProps) => (
|
|
194
|
+
<CollapsibleContent
|
|
195
|
+
className={cn(
|
|
196
|
+
'mt-4 text-sm',
|
|
197
|
+
'data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-muted-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in',
|
|
198
|
+
className,
|
|
199
|
+
)}
|
|
200
|
+
{...props}
|
|
201
|
+
>
|
|
202
|
+
<Streamdown plugins={streamdownPlugins}>{children}</Streamdown>
|
|
203
|
+
</CollapsibleContent>
|
|
204
|
+
))
|
|
205
|
+
|
|
206
|
+
Reasoning.displayName = 'Reasoning'
|
|
207
|
+
ReasoningTrigger.displayName = 'ReasoningTrigger'
|
|
208
|
+
ReasoningContent.displayName = 'ReasoningContent'
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { cn } from '../../lib/utils'
|
|
4
|
+
import type { MotionProps } from 'motion/react'
|
|
5
|
+
import { motion } from 'motion/react'
|
|
6
|
+
import type { CSSProperties, ElementType, JSX } from 'react'
|
|
7
|
+
import { memo, useMemo } from 'react'
|
|
8
|
+
|
|
9
|
+
type MotionHTMLProps = MotionProps & Record<string, unknown>
|
|
10
|
+
|
|
11
|
+
// Cache motion components at module level to avoid creating during render
|
|
12
|
+
const motionComponentCache = new Map<
|
|
13
|
+
keyof JSX.IntrinsicElements,
|
|
14
|
+
React.ComponentType<MotionHTMLProps>
|
|
15
|
+
>()
|
|
16
|
+
|
|
17
|
+
const getMotionComponent = (element: keyof JSX.IntrinsicElements) => {
|
|
18
|
+
let component = motionComponentCache.get(element)
|
|
19
|
+
if (!component) {
|
|
20
|
+
component = motion.create(element)
|
|
21
|
+
motionComponentCache.set(element, component)
|
|
22
|
+
}
|
|
23
|
+
return component
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface TextShimmerProps {
|
|
27
|
+
children: string
|
|
28
|
+
as?: ElementType
|
|
29
|
+
className?: string
|
|
30
|
+
duration?: number
|
|
31
|
+
spread?: number
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const ShimmerComponent = ({
|
|
35
|
+
children,
|
|
36
|
+
as: Component = 'p',
|
|
37
|
+
className,
|
|
38
|
+
duration = 2,
|
|
39
|
+
spread = 2,
|
|
40
|
+
}: TextShimmerProps) => {
|
|
41
|
+
const MotionComponent = getMotionComponent(Component as keyof JSX.IntrinsicElements)
|
|
42
|
+
|
|
43
|
+
const dynamicSpread = useMemo(() => (children?.length ?? 0) * spread, [children, spread])
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<MotionComponent
|
|
47
|
+
animate={{ backgroundPosition: '0% center' }}
|
|
48
|
+
className={cn(
|
|
49
|
+
'relative inline-block bg-[length:250%_100%,auto] bg-clip-text text-transparent',
|
|
50
|
+
'[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]',
|
|
51
|
+
className,
|
|
52
|
+
)}
|
|
53
|
+
initial={{ backgroundPosition: '100% center' }}
|
|
54
|
+
style={
|
|
55
|
+
{
|
|
56
|
+
'--spread': `${dynamicSpread}px`,
|
|
57
|
+
backgroundImage:
|
|
58
|
+
'var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))',
|
|
59
|
+
} as CSSProperties
|
|
60
|
+
}
|
|
61
|
+
transition={{
|
|
62
|
+
duration,
|
|
63
|
+
ease: 'linear',
|
|
64
|
+
repeat: Number.POSITIVE_INFINITY,
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
{children}
|
|
68
|
+
</MotionComponent>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const Shimmer = memo(ShimmerComponent)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../collapsible'
|
|
4
|
+
import { cn } from '../../lib/utils'
|
|
5
|
+
import { BookIcon, ChevronDownIcon } from 'lucide-react'
|
|
6
|
+
import type { ComponentProps } from 'react'
|
|
7
|
+
|
|
8
|
+
export type SourcesProps = ComponentProps<'div'>
|
|
9
|
+
|
|
10
|
+
export const Sources = ({ className, ...props }: SourcesProps) => (
|
|
11
|
+
<Collapsible className={cn('not-prose mb-4 text-primary text-xs', className)} {...props} />
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
export type SourcesTriggerProps = ComponentProps<typeof CollapsibleTrigger> & {
|
|
15
|
+
count: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const SourcesTrigger = ({ className, count, children, ...props }: SourcesTriggerProps) => (
|
|
19
|
+
<CollapsibleTrigger className={cn('flex items-center gap-2', className)} {...props}>
|
|
20
|
+
{children ?? (
|
|
21
|
+
<>
|
|
22
|
+
<p className="font-medium">Used {count} sources</p>
|
|
23
|
+
<ChevronDownIcon className="h-4 w-4" />
|
|
24
|
+
</>
|
|
25
|
+
)}
|
|
26
|
+
</CollapsibleTrigger>
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
export type SourcesContentProps = ComponentProps<typeof CollapsibleContent>
|
|
30
|
+
|
|
31
|
+
export const SourcesContent = ({ className, ...props }: SourcesContentProps) => (
|
|
32
|
+
<CollapsibleContent
|
|
33
|
+
className={cn(
|
|
34
|
+
'mt-3 flex w-fit flex-col gap-2',
|
|
35
|
+
'data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 outline-none data-[state=closed]:animate-out data-[state=open]:animate-in',
|
|
36
|
+
className,
|
|
37
|
+
)}
|
|
38
|
+
{...props}
|
|
39
|
+
/>
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
export type SourceProps = ComponentProps<'a'>
|
|
43
|
+
|
|
44
|
+
export const Source = ({ href, title, children, ...props }: SourceProps) => (
|
|
45
|
+
<a className="flex items-center gap-2" href={href} rel="noreferrer" target="_blank" {...props}>
|
|
46
|
+
{children ?? (
|
|
47
|
+
<>
|
|
48
|
+
<BookIcon className="h-4 w-4" />
|
|
49
|
+
<span className="block font-medium">{title}</span>
|
|
50
|
+
</>
|
|
51
|
+
)}
|
|
52
|
+
</a>
|
|
53
|
+
)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Button } from '../button'
|
|
4
|
+
import { ScrollArea, ScrollBar } from '../scroll-area'
|
|
5
|
+
import { cn } from '../../lib/utils'
|
|
6
|
+
import type { ComponentProps } from 'react'
|
|
7
|
+
import { useCallback } from 'react'
|
|
8
|
+
|
|
9
|
+
export type SuggestionsProps = ComponentProps<typeof ScrollArea>
|
|
10
|
+
|
|
11
|
+
export const Suggestions = ({ className, children, ...props }: SuggestionsProps) => (
|
|
12
|
+
<ScrollArea className="w-full overflow-x-auto whitespace-nowrap" {...props}>
|
|
13
|
+
<div className={cn('flex w-max flex-nowrap items-center gap-2', className)}>{children}</div>
|
|
14
|
+
<ScrollBar className="hidden" orientation="horizontal" />
|
|
15
|
+
</ScrollArea>
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
export type SuggestionProps = Omit<ComponentProps<typeof Button>, 'onClick'> & {
|
|
19
|
+
suggestion: string
|
|
20
|
+
onClick?: (suggestion: string) => void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const Suggestion = ({
|
|
24
|
+
suggestion,
|
|
25
|
+
onClick,
|
|
26
|
+
className,
|
|
27
|
+
variant = 'outline',
|
|
28
|
+
size = 'sm',
|
|
29
|
+
children,
|
|
30
|
+
...props
|
|
31
|
+
}: SuggestionProps) => {
|
|
32
|
+
const handleClick = useCallback(() => {
|
|
33
|
+
onClick?.(suggestion)
|
|
34
|
+
}, [onClick, suggestion])
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<Button
|
|
38
|
+
className={cn('cursor-pointer rounded-full px-4', className)}
|
|
39
|
+
onClick={handleClick}
|
|
40
|
+
size={size}
|
|
41
|
+
type="button"
|
|
42
|
+
variant={variant}
|
|
43
|
+
{...props}
|
|
44
|
+
>
|
|
45
|
+
{children || suggestion}
|
|
46
|
+
</Button>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../collapsible'
|
|
4
|
+
import { cn } from '../../lib/utils'
|
|
5
|
+
import { ChevronDownIcon, SearchIcon } from 'lucide-react'
|
|
6
|
+
import type { ComponentProps } from 'react'
|
|
7
|
+
|
|
8
|
+
export type TaskItemFileProps = ComponentProps<'div'>
|
|
9
|
+
|
|
10
|
+
export const TaskItemFile = ({ children, className, ...props }: TaskItemFileProps) => (
|
|
11
|
+
<div
|
|
12
|
+
className={cn(
|
|
13
|
+
'inline-flex items-center gap-1 rounded-md border bg-secondary px-1.5 py-0.5 text-foreground text-xs',
|
|
14
|
+
className,
|
|
15
|
+
)}
|
|
16
|
+
{...props}
|
|
17
|
+
>
|
|
18
|
+
{children}
|
|
19
|
+
</div>
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
export type TaskItemProps = ComponentProps<'div'>
|
|
23
|
+
|
|
24
|
+
export const TaskItem = ({ children, className, ...props }: TaskItemProps) => (
|
|
25
|
+
<div className={cn('text-muted-foreground text-sm', className)} {...props}>
|
|
26
|
+
{children}
|
|
27
|
+
</div>
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
export type TaskProps = ComponentProps<typeof Collapsible>
|
|
31
|
+
|
|
32
|
+
export const Task = ({ defaultOpen = true, className, ...props }: TaskProps) => (
|
|
33
|
+
<Collapsible className={cn(className)} defaultOpen={defaultOpen} {...props} />
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
export type TaskTriggerProps = ComponentProps<typeof CollapsibleTrigger> & {
|
|
37
|
+
title: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const TaskTrigger = ({ children, className, title, ...props }: TaskTriggerProps) => (
|
|
41
|
+
<CollapsibleTrigger className={cn('group w-full text-left', className)} {...props}>
|
|
42
|
+
{children ?? (
|
|
43
|
+
<div className="flex w-full cursor-pointer items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground">
|
|
44
|
+
<SearchIcon className="size-4" />
|
|
45
|
+
<p className="text-sm">{title}</p>
|
|
46
|
+
<ChevronDownIcon className="size-4 transition-transform group-data-[state=open]:rotate-180" />
|
|
47
|
+
</div>
|
|
48
|
+
)}
|
|
49
|
+
</CollapsibleTrigger>
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
export type TaskContentProps = ComponentProps<typeof CollapsibleContent>
|
|
53
|
+
|
|
54
|
+
export const TaskContent = ({ children, className, ...props }: TaskContentProps) => (
|
|
55
|
+
<CollapsibleContent
|
|
56
|
+
className={cn(
|
|
57
|
+
'data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in',
|
|
58
|
+
className,
|
|
59
|
+
)}
|
|
60
|
+
{...props}
|
|
61
|
+
>
|
|
62
|
+
<div className="mt-4 space-y-2 border-muted border-l-2 pl-4">{children}</div>
|
|
63
|
+
</CollapsibleContent>
|
|
64
|
+
)
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Badge } from '../badge'
|
|
4
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../collapsible'
|
|
5
|
+
import { cn } from '../../lib/utils'
|
|
6
|
+
import type { DynamicToolUIPart, ToolUIPart } from 'ai'
|
|
7
|
+
import {
|
|
8
|
+
CheckCircleIcon,
|
|
9
|
+
ChevronDownIcon,
|
|
10
|
+
CircleIcon,
|
|
11
|
+
ClockIcon,
|
|
12
|
+
WrenchIcon,
|
|
13
|
+
XCircleIcon,
|
|
14
|
+
} from 'lucide-react'
|
|
15
|
+
import type { ComponentProps, ReactNode } from 'react'
|
|
16
|
+
import { isValidElement } from 'react'
|
|
17
|
+
|
|
18
|
+
import { CodeBlock } from './code-block'
|
|
19
|
+
|
|
20
|
+
export type ToolProps = ComponentProps<typeof Collapsible>
|
|
21
|
+
|
|
22
|
+
export const Tool = ({ className, ...props }: ToolProps) => (
|
|
23
|
+
<Collapsible
|
|
24
|
+
className={cn('group not-prose mb-4 w-full rounded-md border', className)}
|
|
25
|
+
{...props}
|
|
26
|
+
/>
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
export type ToolPart = ToolUIPart | DynamicToolUIPart
|
|
30
|
+
|
|
31
|
+
export type ToolHeaderProps = {
|
|
32
|
+
title?: string
|
|
33
|
+
className?: string
|
|
34
|
+
} & (
|
|
35
|
+
| { type: ToolUIPart['type']; state: ToolUIPart['state']; toolName?: never }
|
|
36
|
+
| {
|
|
37
|
+
type: DynamicToolUIPart['type']
|
|
38
|
+
state: DynamicToolUIPart['state']
|
|
39
|
+
toolName: string
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const statusLabels: Record<ToolPart['state'], string> = {
|
|
44
|
+
'approval-requested': 'Awaiting Approval',
|
|
45
|
+
'approval-responded': 'Responded',
|
|
46
|
+
'input-available': 'Running',
|
|
47
|
+
'input-streaming': 'Pending',
|
|
48
|
+
'output-available': 'Completed',
|
|
49
|
+
'output-denied': 'Denied',
|
|
50
|
+
'output-error': 'Error',
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const statusIcons: Record<ToolPart['state'], ReactNode> = {
|
|
54
|
+
'approval-requested': <ClockIcon className="size-4 text-warning" />,
|
|
55
|
+
'approval-responded': <CheckCircleIcon className="size-4 text-info" />,
|
|
56
|
+
'input-available': <ClockIcon className="size-4 animate-pulse" />,
|
|
57
|
+
'input-streaming': <CircleIcon className="size-4" />,
|
|
58
|
+
'output-available': <CheckCircleIcon className="size-4 text-success" />,
|
|
59
|
+
'output-denied': <XCircleIcon className="size-4 text-warning" />,
|
|
60
|
+
'output-error': <XCircleIcon className="size-4 text-critical" />,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const getStatusBadge = (status: ToolPart['state']) => (
|
|
64
|
+
<Badge className="gap-1.5 rounded-full text-xs" variant="secondary">
|
|
65
|
+
{statusIcons[status]}
|
|
66
|
+
{statusLabels[status]}
|
|
67
|
+
</Badge>
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
export const ToolHeader = ({
|
|
71
|
+
className,
|
|
72
|
+
title,
|
|
73
|
+
type,
|
|
74
|
+
state,
|
|
75
|
+
toolName,
|
|
76
|
+
...props
|
|
77
|
+
}: ToolHeaderProps) => {
|
|
78
|
+
const derivedName = type === 'dynamic-tool' ? toolName : type.split('-').slice(1).join('-')
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<CollapsibleTrigger
|
|
82
|
+
className={cn('flex w-full items-center justify-between gap-4 p-3', className)}
|
|
83
|
+
{...props}
|
|
84
|
+
>
|
|
85
|
+
<div className="flex items-center gap-2">
|
|
86
|
+
<WrenchIcon className="size-4 text-muted-foreground" />
|
|
87
|
+
<span className="font-medium text-sm">{title ?? derivedName}</span>
|
|
88
|
+
{getStatusBadge(state)}
|
|
89
|
+
</div>
|
|
90
|
+
<ChevronDownIcon className="size-4 text-muted-foreground transition-transform group-data-[state=open]:rotate-180" />
|
|
91
|
+
</CollapsibleTrigger>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type ToolContentProps = ComponentProps<typeof CollapsibleContent>
|
|
96
|
+
|
|
97
|
+
export const ToolContent = ({ className, ...props }: ToolContentProps) => (
|
|
98
|
+
<CollapsibleContent
|
|
99
|
+
className={cn(
|
|
100
|
+
'data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 space-y-4 p-4 text-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in',
|
|
101
|
+
className,
|
|
102
|
+
)}
|
|
103
|
+
{...props}
|
|
104
|
+
/>
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
export type ToolInputProps = ComponentProps<'div'> & {
|
|
108
|
+
input: ToolPart['input']
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const ToolInput = ({ className, input, ...props }: ToolInputProps) => (
|
|
112
|
+
<div className={cn('space-y-2 overflow-hidden', className)} {...props}>
|
|
113
|
+
<h4 className="font-medium text-muted-foreground text-xs uppercase tracking-wide">
|
|
114
|
+
Parameters
|
|
115
|
+
</h4>
|
|
116
|
+
<div className="rounded-md bg-muted/50">
|
|
117
|
+
<CodeBlock code={JSON.stringify(input, null, 2)} language="json" />
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
export type ToolOutputProps = ComponentProps<'div'> & {
|
|
123
|
+
output: ToolPart['output']
|
|
124
|
+
errorText: ToolPart['errorText']
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const ToolOutput = ({ className, output, errorText, ...props }: ToolOutputProps) => {
|
|
128
|
+
if (!(output || errorText)) {
|
|
129
|
+
return null
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let Output = <div>{output as ReactNode}</div>
|
|
133
|
+
|
|
134
|
+
if (typeof output === 'object' && !isValidElement(output)) {
|
|
135
|
+
Output = <CodeBlock code={JSON.stringify(output, null, 2)} language="json" />
|
|
136
|
+
} else if (typeof output === 'string') {
|
|
137
|
+
Output = <CodeBlock code={output} language="json" />
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<div className={cn('space-y-2', className)} {...props}>
|
|
142
|
+
<h4 className="font-medium text-muted-foreground text-xs uppercase tracking-wide">
|
|
143
|
+
{errorText ? 'Error' : 'Result'}
|
|
144
|
+
</h4>
|
|
145
|
+
<div
|
|
146
|
+
className={cn(
|
|
147
|
+
'overflow-x-auto rounded-md text-xs [&_table]:w-full',
|
|
148
|
+
errorText ? 'bg-surface-critical/10 text-critical' : 'bg-muted/50 text-foreground',
|
|
149
|
+
)}
|
|
150
|
+
>
|
|
151
|
+
{errorText && <div>{errorText}</div>}
|
|
152
|
+
{Output}
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
)
|
|
156
|
+
}
|