@cloudbase/agent-react-ui 1.0.1-alpha.32
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 +123 -0
- package/components.json +21 -0
- package/dist/index.css +4241 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +59 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +2169 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2182 -0
- package/dist/index.mjs.map +1 -0
- package/example/.env.sample +2 -0
- package/example/App.tsx +368 -0
- package/example/app.css +1 -0
- package/example/index.html +12 -0
- package/example/main.tsx +9 -0
- package/example/vite.config.ts +34 -0
- package/package.json +75 -0
- package/postcss.config.cjs +3 -0
- package/src/components/ai-elements/agent.tsx +140 -0
- package/src/components/ai-elements/artifact.tsx +147 -0
- package/src/components/ai-elements/attachments.tsx +421 -0
- package/src/components/ai-elements/audio-player.tsx +228 -0
- package/src/components/ai-elements/canvas.tsx +22 -0
- package/src/components/ai-elements/chain-of-thought.tsx +228 -0
- package/src/components/ai-elements/checkpoint.tsx +71 -0
- package/src/components/ai-elements/code-block.tsx +532 -0
- package/src/components/ai-elements/commit.tsx +448 -0
- package/src/components/ai-elements/confirmation.tsx +176 -0
- package/src/components/ai-elements/connection.tsx +28 -0
- package/src/components/ai-elements/context.tsx +408 -0
- package/src/components/ai-elements/controls.tsx +18 -0
- package/src/components/ai-elements/conversation.tsx +100 -0
- package/src/components/ai-elements/edge.tsx +140 -0
- package/src/components/ai-elements/environment-variables.tsx +295 -0
- package/src/components/ai-elements/file-tree.tsx +258 -0
- package/src/components/ai-elements/image.tsx +24 -0
- package/src/components/ai-elements/inline-citation.tsx +287 -0
- package/src/components/ai-elements/message.tsx +336 -0
- package/src/components/ai-elements/mic-selector.tsx +370 -0
- package/src/components/ai-elements/model-selector.tsx +211 -0
- package/src/components/ai-elements/node.tsx +71 -0
- package/src/components/ai-elements/open-in-chat.tsx +365 -0
- package/src/components/ai-elements/package-info.tsx +233 -0
- package/src/components/ai-elements/panel.tsx +15 -0
- package/src/components/ai-elements/persona.tsx +270 -0
- package/src/components/ai-elements/plan.tsx +142 -0
- package/src/components/ai-elements/prompt-input.tsx +1263 -0
- package/src/components/ai-elements/queue.tsx +274 -0
- package/src/components/ai-elements/reasoning.tsx +193 -0
- package/src/components/ai-elements/sandbox.tsx +126 -0
- package/src/components/ai-elements/schema-display.tsx +458 -0
- package/src/components/ai-elements/shimmer.tsx +64 -0
- package/src/components/ai-elements/snippet.tsx +139 -0
- package/src/components/ai-elements/sources.tsx +77 -0
- package/src/components/ai-elements/speech-input.tsx +301 -0
- package/src/components/ai-elements/stack-trace.tsx +482 -0
- package/src/components/ai-elements/suggestion.tsx +53 -0
- package/src/components/ai-elements/task.tsx +87 -0
- package/src/components/ai-elements/terminal.tsx +261 -0
- package/src/components/ai-elements/test-results.tsx +485 -0
- package/src/components/ai-elements/tool.tsx +174 -0
- package/src/components/ai-elements/toolbar.tsx +16 -0
- package/src/components/ai-elements/transcription.tsx +124 -0
- package/src/components/ai-elements/voice-selector.tsx +479 -0
- package/src/components/ai-elements/web-preview.tsx +263 -0
- package/src/components/chat/Chat.tsx +178 -0
- package/src/components/chat/Input.tsx +98 -0
- package/src/components/chat/Message.tsx +276 -0
- package/src/components/chat/index.ts +2 -0
- package/src/components/index.ts +1 -0
- package/src/components/ui/accordion.tsx +64 -0
- package/src/components/ui/alert.tsx +66 -0
- package/src/components/ui/avatar.tsx +107 -0
- package/src/components/ui/badge.tsx +48 -0
- package/src/components/ui/button-group.tsx +83 -0
- package/src/components/ui/button.tsx +64 -0
- package/src/components/ui/card.tsx +92 -0
- package/src/components/ui/carousel.tsx +239 -0
- package/src/components/ui/collapsible.tsx +31 -0
- package/src/components/ui/command.tsx +184 -0
- package/src/components/ui/dialog.tsx +158 -0
- package/src/components/ui/dropdown-menu.tsx +257 -0
- package/src/components/ui/hover-card.tsx +42 -0
- package/src/components/ui/input-group.tsx +168 -0
- package/src/components/ui/input.tsx +21 -0
- package/src/components/ui/popover.tsx +87 -0
- package/src/components/ui/progress.tsx +31 -0
- package/src/components/ui/scroll-area.tsx +56 -0
- package/src/components/ui/select.tsx +190 -0
- package/src/components/ui/separator.tsx +28 -0
- package/src/components/ui/spinner.tsx +16 -0
- package/src/components/ui/switch.tsx +33 -0
- package/src/components/ui/tabs.tsx +91 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/ui/tooltip.tsx +61 -0
- package/src/css/global.css +123 -0
- package/src/css/index.css +1 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-copy-to-clipboard.ts +31 -0
- package/src/index.ts +4 -0
- package/src/lib/utils.ts +6 -0
- package/src/locales/context.ts +8 -0
- package/src/locales/hooks.ts +20 -0
- package/src/locales/index.ts +3 -0
- package/src/locales/langs/en.ts +17 -0
- package/src/locales/langs/index.ts +12 -0
- package/src/locales/langs/zh-cn.ts +18 -0
- package/tsconfig.json +21 -0
- package/tsup.config.ts +21 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Collapsible,
|
|
5
|
+
CollapsibleContent,
|
|
6
|
+
CollapsibleTrigger,
|
|
7
|
+
} from "@/components/ui/collapsible";
|
|
8
|
+
import { cn } from "@/lib/utils";
|
|
9
|
+
import { BookIcon, ChevronDownIcon } from "lucide-react";
|
|
10
|
+
import type { ComponentProps } from "react";
|
|
11
|
+
|
|
12
|
+
export type SourcesProps = ComponentProps<"div">;
|
|
13
|
+
|
|
14
|
+
export const Sources = ({ className, ...props }: SourcesProps) => (
|
|
15
|
+
<Collapsible
|
|
16
|
+
className={cn("not-prose mb-4 text-primary text-xs", className)}
|
|
17
|
+
{...props}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export type SourcesTriggerProps = ComponentProps<typeof CollapsibleTrigger> & {
|
|
22
|
+
count: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const SourcesTrigger = ({
|
|
26
|
+
className,
|
|
27
|
+
count,
|
|
28
|
+
children,
|
|
29
|
+
...props
|
|
30
|
+
}: SourcesTriggerProps) => (
|
|
31
|
+
<CollapsibleTrigger
|
|
32
|
+
className={cn("flex items-center gap-2", className)}
|
|
33
|
+
{...props}
|
|
34
|
+
>
|
|
35
|
+
{children ?? (
|
|
36
|
+
<>
|
|
37
|
+
<p className="font-medium">Used {count} sources</p>
|
|
38
|
+
<ChevronDownIcon className="h-4 w-4" />
|
|
39
|
+
</>
|
|
40
|
+
)}
|
|
41
|
+
</CollapsibleTrigger>
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
export type SourcesContentProps = ComponentProps<typeof CollapsibleContent>;
|
|
45
|
+
|
|
46
|
+
export const SourcesContent = ({
|
|
47
|
+
className,
|
|
48
|
+
...props
|
|
49
|
+
}: SourcesContentProps) => (
|
|
50
|
+
<CollapsibleContent
|
|
51
|
+
className={cn(
|
|
52
|
+
"mt-3 flex w-fit flex-col gap-2",
|
|
53
|
+
"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",
|
|
54
|
+
className
|
|
55
|
+
)}
|
|
56
|
+
{...props}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
export type SourceProps = ComponentProps<"a">;
|
|
61
|
+
|
|
62
|
+
export const Source = ({ href, title, children, ...props }: SourceProps) => (
|
|
63
|
+
<a
|
|
64
|
+
className="flex items-center gap-2"
|
|
65
|
+
href={href}
|
|
66
|
+
rel="noreferrer"
|
|
67
|
+
target="_blank"
|
|
68
|
+
{...props}
|
|
69
|
+
>
|
|
70
|
+
{children ?? (
|
|
71
|
+
<>
|
|
72
|
+
<BookIcon className="h-4 w-4" />
|
|
73
|
+
<span className="block font-medium">{title}</span>
|
|
74
|
+
</>
|
|
75
|
+
)}
|
|
76
|
+
</a>
|
|
77
|
+
);
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button } from "@/components/ui/button";
|
|
4
|
+
import { Spinner } from "@/components/ui/spinner";
|
|
5
|
+
import { cn } from "@/lib/utils";
|
|
6
|
+
import { MicIcon, SquareIcon } from "lucide-react";
|
|
7
|
+
import {
|
|
8
|
+
type ComponentProps,
|
|
9
|
+
useCallback,
|
|
10
|
+
useEffect,
|
|
11
|
+
useRef,
|
|
12
|
+
useState,
|
|
13
|
+
} from "react";
|
|
14
|
+
|
|
15
|
+
interface SpeechRecognition extends EventTarget {
|
|
16
|
+
continuous: boolean;
|
|
17
|
+
interimResults: boolean;
|
|
18
|
+
lang: string;
|
|
19
|
+
start(): void;
|
|
20
|
+
stop(): void;
|
|
21
|
+
onstart: ((this: SpeechRecognition, ev: Event) => void) | null;
|
|
22
|
+
onend: ((this: SpeechRecognition, ev: Event) => void) | null;
|
|
23
|
+
onresult:
|
|
24
|
+
| ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => void)
|
|
25
|
+
| null;
|
|
26
|
+
onerror:
|
|
27
|
+
| ((this: SpeechRecognition, ev: SpeechRecognitionErrorEvent) => void)
|
|
28
|
+
| null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface SpeechRecognitionEvent extends Event {
|
|
32
|
+
results: SpeechRecognitionResultList;
|
|
33
|
+
resultIndex: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface SpeechRecognitionResultList {
|
|
37
|
+
readonly length: number;
|
|
38
|
+
item(index: number): SpeechRecognitionResult;
|
|
39
|
+
[index: number]: SpeechRecognitionResult;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface SpeechRecognitionResult {
|
|
43
|
+
readonly length: number;
|
|
44
|
+
item(index: number): SpeechRecognitionAlternative;
|
|
45
|
+
[index: number]: SpeechRecognitionAlternative;
|
|
46
|
+
isFinal: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface SpeechRecognitionAlternative {
|
|
50
|
+
transcript: string;
|
|
51
|
+
confidence: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface SpeechRecognitionErrorEvent extends Event {
|
|
55
|
+
error: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare global {
|
|
59
|
+
interface Window {
|
|
60
|
+
SpeechRecognition: {
|
|
61
|
+
new (): SpeechRecognition;
|
|
62
|
+
};
|
|
63
|
+
webkitSpeechRecognition: {
|
|
64
|
+
new (): SpeechRecognition;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type SpeechInputMode = "speech-recognition" | "media-recorder" | "none";
|
|
70
|
+
|
|
71
|
+
export type SpeechInputProps = ComponentProps<typeof Button> & {
|
|
72
|
+
onTranscriptionChange?: (text: string) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Callback for when audio is recorded using MediaRecorder fallback.
|
|
75
|
+
* This is called in browsers that don't support the Web Speech API (Firefox, Safari).
|
|
76
|
+
* The callback receives an audio Blob that should be sent to a transcription service.
|
|
77
|
+
* Return the transcribed text, which will be passed to onTranscriptionChange.
|
|
78
|
+
*/
|
|
79
|
+
onAudioRecorded?: (audioBlob: Blob) => Promise<string>;
|
|
80
|
+
lang?: string;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const detectSpeechInputMode = (): SpeechInputMode => {
|
|
84
|
+
if (typeof window === "undefined") {
|
|
85
|
+
return "none";
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if ("SpeechRecognition" in window || "webkitSpeechRecognition" in window) {
|
|
89
|
+
return "speech-recognition";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if ("MediaRecorder" in window && "mediaDevices" in navigator) {
|
|
93
|
+
return "media-recorder";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return "none";
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const SpeechInput = ({
|
|
100
|
+
className,
|
|
101
|
+
onTranscriptionChange,
|
|
102
|
+
onAudioRecorded,
|
|
103
|
+
lang = "en-US",
|
|
104
|
+
...props
|
|
105
|
+
}: SpeechInputProps) => {
|
|
106
|
+
const [isListening, setIsListening] = useState(false);
|
|
107
|
+
const [isProcessing, setIsProcessing] = useState(false);
|
|
108
|
+
const [mode, setMode] = useState<SpeechInputMode>("none");
|
|
109
|
+
const [recognition, setRecognition] = useState<SpeechRecognition | null>(
|
|
110
|
+
null
|
|
111
|
+
);
|
|
112
|
+
const recognitionRef = useRef<SpeechRecognition | null>(null);
|
|
113
|
+
const mediaRecorderRef = useRef<MediaRecorder | null>(null);
|
|
114
|
+
const audioChunksRef = useRef<Blob[]>([]);
|
|
115
|
+
|
|
116
|
+
// Detect mode on mount
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
setMode(detectSpeechInputMode());
|
|
119
|
+
}, []);
|
|
120
|
+
|
|
121
|
+
// Initialize Speech Recognition when mode is speech-recognition
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
if (mode !== "speech-recognition") {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const SpeechRecognition =
|
|
128
|
+
window.SpeechRecognition || window.webkitSpeechRecognition;
|
|
129
|
+
const speechRecognition = new SpeechRecognition();
|
|
130
|
+
|
|
131
|
+
speechRecognition.continuous = true;
|
|
132
|
+
speechRecognition.interimResults = true;
|
|
133
|
+
speechRecognition.lang = lang;
|
|
134
|
+
|
|
135
|
+
speechRecognition.onstart = () => {
|
|
136
|
+
setIsListening(true);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
speechRecognition.onend = () => {
|
|
140
|
+
setIsListening(false);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
speechRecognition.onresult = (event) => {
|
|
144
|
+
let finalTranscript = "";
|
|
145
|
+
|
|
146
|
+
for (let i = event.resultIndex; i < event.results.length; i++) {
|
|
147
|
+
const result = event.results[i];
|
|
148
|
+
if (result.isFinal) {
|
|
149
|
+
finalTranscript += result[0]?.transcript ?? "";
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (finalTranscript) {
|
|
154
|
+
onTranscriptionChange?.(finalTranscript);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
speechRecognition.onerror = (event) => {
|
|
159
|
+
console.error("Speech recognition error:", event.error);
|
|
160
|
+
setIsListening(false);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
recognitionRef.current = speechRecognition;
|
|
164
|
+
setRecognition(speechRecognition);
|
|
165
|
+
|
|
166
|
+
return () => {
|
|
167
|
+
if (recognitionRef.current) {
|
|
168
|
+
recognitionRef.current.stop();
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}, [mode, onTranscriptionChange, lang]);
|
|
172
|
+
|
|
173
|
+
// Start MediaRecorder recording
|
|
174
|
+
const startMediaRecorder = useCallback(async () => {
|
|
175
|
+
if (!onAudioRecorded) {
|
|
176
|
+
console.warn(
|
|
177
|
+
"SpeechInput: onAudioRecorded callback is required for MediaRecorder fallback"
|
|
178
|
+
);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
184
|
+
const mediaRecorder = new MediaRecorder(stream);
|
|
185
|
+
audioChunksRef.current = [];
|
|
186
|
+
|
|
187
|
+
mediaRecorder.ondataavailable = (event) => {
|
|
188
|
+
if (event.data.size > 0) {
|
|
189
|
+
audioChunksRef.current.push(event.data);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
mediaRecorder.onstop = async () => {
|
|
194
|
+
// Stop all tracks to release the microphone
|
|
195
|
+
for (const track of stream.getTracks()) {
|
|
196
|
+
track.stop();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const audioBlob = new Blob(audioChunksRef.current, {
|
|
200
|
+
type: "audio/webm",
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
if (audioBlob.size > 0) {
|
|
204
|
+
setIsProcessing(true);
|
|
205
|
+
try {
|
|
206
|
+
const transcript = await onAudioRecorded(audioBlob);
|
|
207
|
+
if (transcript) {
|
|
208
|
+
onTranscriptionChange?.(transcript);
|
|
209
|
+
}
|
|
210
|
+
} catch (error) {
|
|
211
|
+
console.error("Transcription error:", error);
|
|
212
|
+
} finally {
|
|
213
|
+
setIsProcessing(false);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
mediaRecorder.onerror = (event) => {
|
|
219
|
+
console.error("MediaRecorder error:", event);
|
|
220
|
+
setIsListening(false);
|
|
221
|
+
// Stop all tracks on error
|
|
222
|
+
for (const track of stream.getTracks()) {
|
|
223
|
+
track.stop();
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
mediaRecorderRef.current = mediaRecorder;
|
|
228
|
+
mediaRecorder.start();
|
|
229
|
+
setIsListening(true);
|
|
230
|
+
} catch (error) {
|
|
231
|
+
console.error("Failed to start MediaRecorder:", error);
|
|
232
|
+
setIsListening(false);
|
|
233
|
+
}
|
|
234
|
+
}, [onAudioRecorded, onTranscriptionChange]);
|
|
235
|
+
|
|
236
|
+
// Stop MediaRecorder recording
|
|
237
|
+
const stopMediaRecorder = useCallback(() => {
|
|
238
|
+
if (mediaRecorderRef.current?.state === "recording") {
|
|
239
|
+
mediaRecorderRef.current.stop();
|
|
240
|
+
}
|
|
241
|
+
setIsListening(false);
|
|
242
|
+
}, []);
|
|
243
|
+
|
|
244
|
+
const toggleListening = useCallback(() => {
|
|
245
|
+
if (mode === "speech-recognition" && recognition) {
|
|
246
|
+
if (isListening) {
|
|
247
|
+
recognition.stop();
|
|
248
|
+
} else {
|
|
249
|
+
recognition.start();
|
|
250
|
+
}
|
|
251
|
+
} else if (mode === "media-recorder") {
|
|
252
|
+
if (isListening) {
|
|
253
|
+
stopMediaRecorder();
|
|
254
|
+
} else {
|
|
255
|
+
startMediaRecorder();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}, [mode, recognition, isListening, startMediaRecorder, stopMediaRecorder]);
|
|
259
|
+
|
|
260
|
+
// Determine if button should be disabled
|
|
261
|
+
const isDisabled =
|
|
262
|
+
mode === "none" ||
|
|
263
|
+
(mode === "speech-recognition" && !recognition) ||
|
|
264
|
+
(mode === "media-recorder" && !onAudioRecorded) ||
|
|
265
|
+
isProcessing;
|
|
266
|
+
|
|
267
|
+
return (
|
|
268
|
+
<div className="relative inline-flex items-center justify-center">
|
|
269
|
+
{/* Animated pulse rings */}
|
|
270
|
+
{isListening &&
|
|
271
|
+
[0, 1, 2].map((index) => (
|
|
272
|
+
<div
|
|
273
|
+
className="absolute inset-0 animate-ping rounded-full border-2 border-red-400/30"
|
|
274
|
+
key={index}
|
|
275
|
+
style={{
|
|
276
|
+
animationDelay: `${index * 0.3}s`,
|
|
277
|
+
animationDuration: "2s",
|
|
278
|
+
}}
|
|
279
|
+
/>
|
|
280
|
+
))}
|
|
281
|
+
|
|
282
|
+
{/* Main record button */}
|
|
283
|
+
<Button
|
|
284
|
+
className={cn(
|
|
285
|
+
"relative z-10 rounded-full transition-all duration-300",
|
|
286
|
+
isListening
|
|
287
|
+
? "bg-destructive text-white hover:bg-destructive/80 hover:text-white"
|
|
288
|
+
: "bg-primary text-primary-foreground hover:bg-primary/80 hover:text-primary-foreground",
|
|
289
|
+
className
|
|
290
|
+
)}
|
|
291
|
+
disabled={isDisabled}
|
|
292
|
+
onClick={toggleListening}
|
|
293
|
+
{...props}
|
|
294
|
+
>
|
|
295
|
+
{isProcessing && <Spinner />}
|
|
296
|
+
{!isProcessing && isListening && <SquareIcon className="size-4" />}
|
|
297
|
+
{!(isProcessing || isListening) && <MicIcon className="size-4" />}
|
|
298
|
+
</Button>
|
|
299
|
+
</div>
|
|
300
|
+
);
|
|
301
|
+
};
|