@@ -30,7 +30,7 @@ function PureMultimodalInput({
30
30
handleSubmit : (
31
31
event ?: {
32
32
preventDefault ?: ( ) => void ;
33
- } ,
33
+ }
34
34
// chatRequestOptions?: ChatRequestOptions,
35
35
) => void ;
36
36
hasMessages : boolean ;
@@ -67,7 +67,7 @@ function PureMultimodalInput({
67
67
68
68
const [ localStorageInput , setLocalStorageInput ] = useLocalStorage (
69
69
"input" ,
70
- "" ,
70
+ ""
71
71
) ;
72
72
73
73
// biome-ignore lint/correctness/useExhaustiveDependencies: Only run once after hydration
@@ -92,19 +92,37 @@ function PureMultimodalInput({
92
92
93
93
const submitForm = useCallback ( async ( ) => {
94
94
if ( newSession ) {
95
- await fetchClientWithThrow . POST ( "/api/sessions" , {
96
- body : {
97
- id : sessionId ,
98
- title : input . split ( " " ) . reduce ( ( acc , word ) => {
99
- if ( acc . length + word . length + 1 <= 15 ) {
100
- return acc + ( acc ? " " : "" ) + word ;
101
- }
102
- return acc ;
103
- } , "" ) ,
104
- agent_id : agentId ,
105
- } ,
106
- } ) ;
107
- queyrClient . invalidateQueries ( { queryKey : [ "get" , "/api/sessions" , { } ] } ) ;
95
+ try {
96
+ await fetchClientWithThrow . POST ( "/api/sessions" , {
97
+ body : {
98
+ id : sessionId ,
99
+ title : input . split ( " " ) . reduce ( ( acc , word ) => {
100
+ if ( acc . length + word . length + 1 <= 15 ) {
101
+ return acc + ( acc ? " " : "" ) + word ;
102
+ }
103
+ return acc ;
104
+ } , "" ) ,
105
+ agent_id : agentId ,
106
+ } ,
107
+ } ) ;
108
+ queyrClient . invalidateQueries ( {
109
+ queryKey : [ "get" , "/api/sessions" , { } ] ,
110
+ } ) ;
111
+ } catch ( error : any ) {
112
+ const str = error . message || error . toString ( ) ;
113
+ const jsonMatch = str . match ( / { .* } / ) ;
114
+ let err = "Failed to create new session" ;
115
+ if ( jsonMatch ) {
116
+ const parsed = JSON . parse ( jsonMatch [ 0 ] ) ;
117
+ const detail = parsed . detail ;
118
+ if ( detail ) {
119
+ err = `Failed to create new session: ${ detail } ` ;
120
+ }
121
+ }
122
+
123
+ toast . error ( err ) ;
124
+ return ;
125
+ }
108
126
}
109
127
110
128
// navigate({ to: '/session/$sessionId', params: { sessionId: sessionIdToRedir } });
@@ -180,7 +198,7 @@ export const MultimodalInput = memo(
180
198
if ( prevProps . sessionId !== nextProps . sessionId ) return false ;
181
199
182
200
return true ;
183
- } ,
201
+ }
184
202
) ;
185
203
186
204
function PureStopButton ( {
@@ -209,7 +227,10 @@ const StopButton = memo(PureStopButton);
209
227
function PureSendButton ( {
210
228
submitForm,
211
229
input,
212
- } : { submitForm : ( ) => void ; input : string } ) {
230
+ } : {
231
+ submitForm : ( ) => void ;
232
+ input : string ;
233
+ } ) {
213
234
return (
214
235
< Button
215
236
className = "rounded-full p-1.5 h-fit border dark:border-zinc-600"
0 commit comments