forked from accordproject/template-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAICommandPalette.tsx
More file actions
56 lines (50 loc) · 1.38 KB
/
AICommandPalette.tsx
File metadata and controls
56 lines (50 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { useState } from "react";
import { Modal, Input, message } from "antd";
import { useAI } from "../../hooks/useAI";
import type { EditorType } from "../../services/ai/AIService";
interface AICommandPaletteProps {
isOpen: boolean;
onClose: () => void;
editorType: EditorType;
currentContent: string;
onComplete: (completion: any) => void;
}
const { TextArea } = Input;
export function AICommandPalette({ isOpen, onClose, editorType, currentContent, onComplete }: AICommandPaletteProps) {
const [prompt, setPrompt] = useState("");
const { isProcessing, getCompletion } = useAI();
const handleSubmit = async () => {
if (!prompt.trim()) {
return;
}
try {
const completion = await getCompletion({
prompt,
editorType,
currentContent,
});
onComplete(completion);
onClose();
setPrompt("");
} catch (error) {
console.error("AI completion error:", error);
message.error("Failed to get AI completion. Please try again.");
}
};
return (
<Modal
title="AI Assistant"
open={isOpen}
onOk={handleSubmit}
onCancel={onClose}
okButtonProps={{ loading: isProcessing }}
>
<TextArea
value={prompt}
onChange={(e: any) => setPrompt(e.target.value)}
placeholder="What would you like me to help you with?"
rows={4}
/>
</Modal>
);
}