1
1
import { Button } from "@/components/ui/button"
2
2
import {
3
- Dialog ,
4
- DialogContent ,
5
- DialogFooter ,
6
- DialogHeader ,
7
- DialogTitle
8
- } from "@/components/ui/dialog "
3
+ Sheet ,
4
+ SheetContent ,
5
+ SheetFooter ,
6
+ SheetHeader ,
7
+ SheetTitle
8
+ } from "@/components/ui/sheet "
9
9
import { ChatbotUIContext } from "@/context/context"
10
10
import { createAssistant , updateAssistant } from "@/db/assistants"
11
11
import { createChat } from "@/db/chats"
@@ -18,6 +18,7 @@ import {
18
18
getAssistantImageFromStorage ,
19
19
uploadAssistantImage
20
20
} from "@/db/storage/assistant-images"
21
+ import { createTool } from "@/db/tools"
21
22
import { convertBlobToBase64 } from "@/lib/blob-to-b64"
22
23
import { Tables , TablesInsert } from "@/supabase/types"
23
24
import { ContentType } from "@/types"
@@ -47,7 +48,8 @@ export const SidebarCreateItem: FC<SidebarCreateItemProps> = ({
47
48
setFiles,
48
49
setCollections,
49
50
setAssistants,
50
- setAssistantImages
51
+ setAssistantImages,
52
+ setTools
51
53
} = useContext ( ChatbotUIContext )
52
54
53
55
const buttonRef = useRef < HTMLButtonElement > ( null )
@@ -105,32 +107,37 @@ export const SidebarCreateItem: FC<SidebarCreateItemProps> = ({
105
107
106
108
const createdAssistant = await createAssistant ( rest , workspaceId )
107
109
108
- const filePath = await uploadAssistantImage ( createdAssistant , image )
110
+ let updatedAssistant = createdAssistant
109
111
110
- const updatedAssistant = await updateAssistant ( createdAssistant . id , {
111
- image_path : filePath
112
- } )
112
+ if ( image ) {
113
+ const filePath = await uploadAssistantImage ( createdAssistant , image )
113
114
114
- const url = ( await getAssistantImageFromStorage ( filePath ) ) || ""
115
+ const updatedAssistant = await updateAssistant ( createdAssistant . id , {
116
+ image_path : filePath
117
+ } )
115
118
116
- if ( url ) {
117
- const response = await fetch ( url )
118
- const blob = await response . blob ( )
119
- const base64 = await convertBlobToBase64 ( blob )
119
+ const url = ( await getAssistantImageFromStorage ( filePath ) ) || ""
120
120
121
- setAssistantImages ( prev => [
122
- ...prev ,
123
- {
124
- assistantId : updatedAssistant . id ,
125
- path : filePath ,
126
- base64,
127
- url
128
- }
129
- ] )
121
+ if ( url ) {
122
+ const response = await fetch ( url )
123
+ const blob = await response . blob ( )
124
+ const base64 = await convertBlobToBase64 ( blob )
125
+
126
+ setAssistantImages ( prev => [
127
+ ...prev ,
128
+ {
129
+ assistantId : updatedAssistant . id ,
130
+ path : filePath ,
131
+ base64,
132
+ url
133
+ }
134
+ ] )
135
+ }
130
136
}
131
137
132
138
return updatedAssistant
133
- }
139
+ } ,
140
+ tools : createTool
134
141
}
135
142
136
143
const stateUpdateFunctions = {
@@ -139,7 +146,8 @@ export const SidebarCreateItem: FC<SidebarCreateItemProps> = ({
139
146
prompts : setPrompts ,
140
147
files : setFiles ,
141
148
collections : setCollections ,
142
- assistants : setAssistants
149
+ assistants : setAssistants ,
150
+ tools : setTools
143
151
}
144
152
145
153
const handleCreate = async ( ) => {
@@ -173,17 +181,24 @@ export const SidebarCreateItem: FC<SidebarCreateItemProps> = ({
173
181
}
174
182
175
183
return (
176
- < Dialog open = { isOpen } onOpenChange = { onOpenChange } >
177
- < DialogContent onKeyDown = { handleKeyDown } >
178
- < DialogHeader >
179
- < DialogTitle className = "text-2xl font-bold" >
180
- Create { contentType . slice ( 0 , - 1 ) }
181
- </ DialogTitle >
182
- </ DialogHeader >
183
-
184
- < div className = "space-y-3" > { renderInputs ( ) } </ div >
185
-
186
- < DialogFooter className = "mt-2 flex justify-between" >
184
+ < Sheet open = { isOpen } onOpenChange = { onOpenChange } >
185
+ < SheetContent
186
+ className = "flex flex-col justify-between"
187
+ side = "left"
188
+ onKeyDown = { handleKeyDown }
189
+ >
190
+ < div className = "grow" >
191
+ < SheetHeader >
192
+ < SheetTitle className = "text-2xl font-bold" >
193
+ Create{ " " }
194
+ { contentType . charAt ( 0 ) . toUpperCase ( ) + contentType . slice ( 1 , - 1 ) }
195
+ </ SheetTitle >
196
+ </ SheetHeader >
197
+
198
+ < div className = "mt-4 space-y-3" > { renderInputs ( ) } </ div >
199
+ </ div >
200
+
201
+ < SheetFooter className = "mt-2 flex justify-between" >
187
202
< div className = "flex grow justify-end space-x-2" >
188
203
< Button
189
204
disabled = { creating }
@@ -197,8 +212,8 @@ export const SidebarCreateItem: FC<SidebarCreateItemProps> = ({
197
212
{ creating ? "Creating..." : "Create" }
198
213
</ Button >
199
214
</ div >
200
- </ DialogFooter >
201
- </ DialogContent >
202
- </ Dialog >
215
+ </ SheetFooter >
216
+ </ SheetContent >
217
+ </ Sheet >
203
218
)
204
219
}
0 commit comments