@@ -19,13 +19,14 @@ import { extractReasoningMiddleware, streamText, wrapLanguageModel } from 'ai';
1919import { Alert , App , Card , CardProps } from 'antd' ;
2020import { createStyles } from 'antd-style' ;
2121import graphql from 'babel-plugin-relay/macro' ;
22- import { includes , isEmpty , map } from 'lodash' ;
22+ import _ from 'lodash' ;
2323import React , {
2424 startTransition ,
2525 useEffect ,
2626 useMemo ,
2727 useRef ,
2828 useState ,
29+ useTransition ,
2930} from 'react' ;
3031import { useFragment } from 'react-relay' ;
3132
@@ -143,15 +144,15 @@ function useModels(
143144 } ,
144145 } ) ;
145146
146- const models = map ( modelsResult ?. data , ( m ) => ( {
147+ const models = _ . map ( modelsResult ?. data || [ ] , ( m ) => ( {
147148 id : m . id ,
148149 name : m . id ,
149150 } ) ) as BAIModel [ ] ;
150151
151152 const selectedModelId = useMemo (
152153 ( ) =>
153154 provider . modelId &&
154- includes ( map ( modelsResult ?. data , 'id' ) , provider . modelId )
155+ _ . includes ( _ . map ( modelsResult ?. data || [ ] , 'id' ) , provider . modelId )
155156 ? provider . modelId
156157 : ( modelsResult ?. data ?. [ 0 ] ?. id ?? 'custom' ) ,
157158 [ modelsResult ?. data , provider . modelId ] ,
@@ -208,6 +209,8 @@ const ChatCard: React.FC<ChatCardProps> = ({
208209 const {
209210 styles : { chatCard : chatCardStyle , alert : alertStyle , ...chatCardStyles } ,
210211 } = useStyles ( ) ;
212+ const [ isPendingUpdate , startUpdateTransition ] = useTransition ( ) ;
213+
211214 const dropContainerRef = useRef < HTMLDivElement > ( null ) ;
212215 const [ fetchKey , updateFetchKey ] = useUpdatableState ( 'first' ) ;
213216 const [ startTime , setStartTime ] = useState < number | null > ( null ) ;
@@ -308,19 +311,22 @@ const ChatCard: React.FC<ChatCardProps> = ({
308311 }
309312 ref = { dropContainerRef }
310313 >
311- { isEmpty ( models ) && (
314+ { _ . isEmpty ( models ) && (
312315 < CustomModelForm
313316 baseURL = { baseURL }
314317 token = { token }
315318 endpointId = { endpoint ?. endpoint_id }
319+ loading = { isPendingUpdate }
316320 onSubmit = { ( data ) => {
317- updateFetchKey ( ) ;
318- setBaseURL ( data . baseURL ) ;
319- setToken ( data . token ) ;
321+ startUpdateTransition ( ( ) => {
322+ updateFetchKey ( ) ;
323+ setBaseURL ( data . baseURL ) ;
324+ setToken ( data . token ) ;
325+ } ) ;
320326 } }
321327 />
322328 ) }
323- { ! isEmpty ( error ?. message ) ? (
329+ { ! _ . isEmpty ( error ?. message ) ? (
324330 < Alert
325331 message = { error ?. message }
326332 type = "error"
0 commit comments