@@ -59,9 +59,9 @@ type Context = {
59
59
clearPrompt : (
60
60
conversation : Conversation | undefined ,
61
61
newConversations : Conversation [ ] ,
62
- ) => Conversation [ ] ;
63
- handleChangePrompt : ( prompt : ParsedPrompt ) => void ;
64
- selectTemplate : ( template : PromptTemplate ) => void ;
62
+ ) => Promise < Conversation [ ] > ;
63
+ // handleChangePrompt: (prompt: ParsedPrompt) => void;
64
+ selectTemplate : ( template : PromptTemplate ) => Promise < void > ;
65
65
tokenValidator : TokenValidator ;
66
66
usage : Usage | undefined ;
67
67
} ;
@@ -162,7 +162,7 @@ function PromptProvider({
162
162
] ) ;
163
163
164
164
const clearPrompt = useCallback (
165
- ( conversation : Conversation | undefined , newConversations : Conversation [ ] ) => {
165
+ async ( conversation : Conversation | undefined , newConversations : Conversation [ ] ) => {
166
166
setChangedPrompt ( undefined ) ;
167
167
168
168
let updatedConversations = newConversations ;
@@ -171,18 +171,18 @@ function PromptProvider({
171
171
{ ...conversation , currentPrompt : undefined , temp : false } ,
172
172
newConversations ,
173
173
) ;
174
- updateConversations ( updatedConversations ) ;
174
+ await updateConversations ( updatedConversations ) ;
175
175
}
176
176
return updatedConversations ;
177
177
} ,
178
178
[ updateConversations ] ,
179
179
) ;
180
180
181
181
const handleUpdatePrompt = useCallback (
182
- ( prompt : ParsedPrompt | undefined , conversationName = getDefaultConversationName ( t ) ) => {
182
+ async ( prompt : ParsedPrompt | undefined , conversationName = getDefaultConversationName ( t ) ) => {
183
183
if ( prompt ?. raw === '' && tempConversationId ) {
184
184
setChangedPrompt ( undefined ) ;
185
- updateConversations ( conversations . filter ( ( c ) => ! c . temp ) ) ;
185
+ await updateConversations ( conversations . filter ( ( c ) => ! c . temp ) ) ;
186
186
onUpdateTempConversation ( undefined ) ;
187
187
return ;
188
188
}
@@ -191,12 +191,12 @@ function PromptProvider({
191
191
setChangedPrompt ( undefined ) ;
192
192
return ;
193
193
}
194
- let updatedConversations : Conversation [ ] ;
194
+ let updatedConversations : Conversation [ ] | undefined ;
195
195
if ( conversation ) {
196
196
conversation . currentPrompt = prompt ;
197
197
updatedConversations = conversations . filter ( ( c ) => ! ( c . temp && c . id !== conversationId ) ) ;
198
198
updatedConversations = updateConversation ( conversation , updatedConversations , true ) ;
199
- } else {
199
+ } else if ( prompt ?. raw !== '' ) {
200
200
updatedConversations = conversations . filter ( ( c ) => ! c . temp ) ;
201
201
let newConversation = createConversation ( conversationName ) ;
202
202
newConversation . temp = true ;
@@ -211,8 +211,12 @@ function PromptProvider({
211
211
}
212
212
updatedConversations . push ( newConversation ) ;
213
213
onUpdateTempConversation ( newConversation . id ) ;
214
+ } else {
215
+ updatedConversations = conversations . filter ( ( c ) => ! c . temp ) ;
216
+ }
217
+ if ( updatedConversations ) {
218
+ await updateConversations ( updatedConversations ) ;
214
219
}
215
- updateConversations ( updatedConversations ) ;
216
220
setChangedPrompt ( undefined ) ;
217
221
} ,
218
222
[
@@ -230,17 +234,17 @@ function PromptProvider({
230
234
231
235
useDebounceFunc < ParsedPrompt | undefined > ( handleUpdatePrompt , changedPrompt , 500 ) ;
232
236
233
- const handleChangePrompt = useCallback (
237
+ /* const handleChangePrompt = useCallback(
234
238
(prompt: ParsedPrompt) => {
235
239
if (prompt.raw !== conversationPrompt?.raw) {
236
240
setChangedPrompt(prompt);
237
241
}
238
242
},
239
243
[conversationPrompt],
240
- ) ;
244
+ ); */
241
245
242
246
const selectTemplate = useCallback (
243
- ( template : PromptTemplate ) => {
247
+ async ( template : PromptTemplate ) => {
244
248
handleUpdatePrompt ( parseAndValidatePrompt ( template . value ) , template . name ) ;
245
249
} ,
246
250
[ handleUpdatePrompt , parseAndValidatePrompt ] ,
@@ -253,7 +257,7 @@ function PromptProvider({
253
257
parseAndValidatePrompt,
254
258
changedPrompt,
255
259
setChangedPrompt,
256
- handleChangePrompt,
260
+ // handleChangePrompt,
257
261
tokenValidator,
258
262
selectTemplate,
259
263
usage,
@@ -263,7 +267,7 @@ function PromptProvider({
263
267
clearPrompt ,
264
268
parseAndValidatePrompt ,
265
269
changedPrompt ,
266
- handleChangePrompt ,
270
+ // handleChangePrompt,
267
271
tokenValidator ,
268
272
selectTemplate ,
269
273
usage ,
@@ -278,12 +282,12 @@ const usePromptContext = (): Context => {
278
282
if ( ! context ) {
279
283
return {
280
284
conversationPrompt : EmptyParsedPrompt ,
281
- clearPrompt : ( ) => [ ] ,
285
+ clearPrompt : async ( ) => [ ] ,
282
286
parseAndValidatePrompt : ( ) => EmptyParsedPrompt ,
283
287
changedPrompt : undefined ,
284
- handleChangePrompt : ( ) => { } ,
288
+ // handleChangePrompt: () => {},
285
289
tokenValidator : ( ) => [ EmptyPromptToken , undefined ] ,
286
- selectTemplate : ( ) => { } ,
290
+ selectTemplate : async ( ) => { } ,
287
291
setChangedPrompt : ( ) => { } ,
288
292
usage : undefined ,
289
293
} ;
0 commit comments