@@ -3,12 +3,14 @@ import { id } from "tsafe/id";
33
44export const name = "ai" ;
55
6+ export type AiModel = { id : string ; name : string } ;
7+
68export type CustomAiProvider = {
79 id : string ;
810 label : string ;
911 apiBase : string ;
1012 apiKey : string ;
11- availableModels : string [ ] ;
13+ availableModels : AiModel [ ] ;
1214 selectedModel : string | undefined ;
1315 modelsFetchStatus : "fetching" | "success" | "error" ;
1416} ;
@@ -26,7 +28,7 @@ export declare namespace State {
2628 webUiUrl : string ;
2729 apiBase : string ;
2830 token : string | undefined ;
29- availableModels : string [ ] ;
31+ availableModels : AiModel [ ] ;
3032 selectedModel : string | undefined ;
3133 customProviders : CustomAiProvider [ ] ;
3234 } ;
@@ -59,7 +61,7 @@ export const { reducer, actions } = createUsecaseActions({
5961 webUiUrl : string ;
6062 apiBase : string ;
6163 token : string ;
62- availableModels : string [ ] ;
64+ availableModels : AiModel [ ] ;
6365 selectedModel : string | undefined ;
6466 customProviders : CustomAiProvider [ ] ;
6567 } ;
@@ -80,7 +82,7 @@ export const { reducer, actions } = createUsecaseActions({
8082 apiBase,
8183 token,
8284 availableModels,
83- selectedModel : selectedModel ?? availableModels [ 0 ] ,
85+ selectedModel : selectedModel ?? availableModels [ 0 ] ?. id ,
8486 customProviders
8587 } ) ;
8688 } ,
@@ -107,15 +109,15 @@ export const { reducer, actions } = createUsecaseActions({
107109 } ,
108110 customProviderModelsLoaded : (
109111 state ,
110- { payload } : { payload : { id : string ; models : string [ ] } }
112+ { payload } : { payload : { id : string ; models : AiModel [ ] } }
111113 ) => {
112114 if ( ! state . isEnabled ) return ;
113115 const provider = state . customProviders . find ( p => p . id === payload . id ) ;
114116 if ( provider === undefined ) return ;
115117 provider . availableModels = payload . models ;
116118 provider . modelsFetchStatus = "success" ;
117119 if ( provider . selectedModel === undefined && payload . models . length > 0 ) {
118- provider . selectedModel = payload . models [ 0 ] ;
120+ provider . selectedModel = payload . models [ 0 ] . id ;
119121 }
120122 } ,
121123 customProviderModelsFetchFailed : (
0 commit comments