1
- import { Send , AlertCircle } from "lucide-react" ;
1
+ import { AlertCircle } from "lucide-react" ;
2
2
import { Button } from "@/components/ui/button" ;
3
3
import { Alert , AlertDescription , AlertTitle } from "@/components/ui/alert" ;
4
4
import { TabsContent } from "@/components/ui/tabs" ;
5
5
import { Input } from "@/components/ui/input" ;
6
6
import { Textarea } from "@/components/ui/textarea" ;
7
+ import { useState } from "react" ;
7
8
8
9
export type Prompt = {
9
- id : string ;
10
10
name : string ;
11
+ description ?: string ;
12
+ arguments ?: {
13
+ name : string ;
14
+ description ?: string ;
15
+ required ?: boolean ;
16
+ } [ ] ;
11
17
} ;
12
18
13
19
const PromptsTab = ( {
@@ -21,12 +27,24 @@ const PromptsTab = ({
21
27
} : {
22
28
prompts : Prompt [ ] ;
23
29
listPrompts : ( ) => void ;
24
- getPrompt : ( name : string ) => void ;
30
+ getPrompt : ( name : string , args : Record < string , string > ) => void ;
25
31
selectedPrompt : Prompt | null ;
26
32
setSelectedPrompt : ( prompt : Prompt ) => void ;
27
33
promptContent : string ;
28
34
error : string | null ;
29
35
} ) => {
36
+ const [ promptArgs , setPromptArgs ] = useState < Record < string , string > > ( { } ) ;
37
+
38
+ const handleInputChange = ( argName : string , value : string ) => {
39
+ setPromptArgs ( ( prev ) => ( { ...prev , [ argName ] : value } ) ) ;
40
+ } ;
41
+
42
+ const handleGetPrompt = ( ) => {
43
+ if ( selectedPrompt ) {
44
+ getPrompt ( selectedPrompt . name , promptArgs ) ;
45
+ }
46
+ } ;
47
+
30
48
return (
31
49
< TabsContent value = "prompts" className = "grid grid-cols-2 gap-4" >
32
50
< div className = "bg-white rounded-lg shadow" >
@@ -44,11 +62,11 @@ const PromptsTab = ({
44
62
< div className = "space-y-2" >
45
63
{ prompts . map ( ( prompt ) => (
46
64
< div
47
- key = { prompt . id }
65
+ key = { prompt . name }
48
66
className = "flex items-center p-2 rounded hover:bg-gray-50 cursor-pointer"
49
67
onClick = { ( ) => {
50
68
setSelectedPrompt ( prompt ) ;
51
- getPrompt ( prompt . name ) ;
69
+ setPromptArgs ( { } ) ;
52
70
} }
53
71
>
54
72
< span className = "flex-1" > { prompt . name } </ span >
@@ -73,18 +91,40 @@ const PromptsTab = ({
73
91
</ Alert >
74
92
) : selectedPrompt ? (
75
93
< div className = "space-y-4" >
76
- < Textarea
77
- value = { promptContent }
78
- readOnly
79
- className = "h-64 font-mono"
80
- />
81
- < div className = "flex space-x-2" >
82
- < Input placeholder = "Enter your message" />
83
- < Button >
84
- < Send className = "w-4 h-4 mr-2" />
85
- Send
86
- </ Button >
87
- </ div >
94
+ { selectedPrompt . description && (
95
+ < p className = "text-sm text-gray-600" >
96
+ { selectedPrompt . description }
97
+ </ p >
98
+ ) }
99
+ { selectedPrompt . arguments ?. map ( ( arg ) => (
100
+ < div key = { arg . name } >
101
+ < Input
102
+ placeholder = { `Enter ${ arg . name } ` }
103
+ value = { promptArgs [ arg . name ] || "" }
104
+ onChange = { ( e ) =>
105
+ handleInputChange ( arg . name , e . target . value )
106
+ }
107
+ />
108
+ { arg . description && (
109
+ < p className = "text-xs text-gray-500 mt-1" >
110
+ { arg . description }
111
+ { arg . required && (
112
+ < span className = "text-xs mt-1 ml-1" > (Required)</ span >
113
+ ) }
114
+ </ p >
115
+ ) }
116
+ </ div >
117
+ ) ) }
118
+ < Button onClick = { handleGetPrompt } className = "w-full" >
119
+ Get Prompt
120
+ </ Button >
121
+ { promptContent && (
122
+ < Textarea
123
+ value = { promptContent }
124
+ readOnly
125
+ className = "h-64 font-mono"
126
+ />
127
+ ) }
88
128
</ div >
89
129
) : (
90
130
< Alert >
0 commit comments