1313import type {
1414 Agent ,
1515 AgentDto ,
16+ ModelConfigDto ,
1617 Department ,
1718 Agent_Status ,
1819 Agent_Memory_Entry ,
@@ -23,6 +24,19 @@ import type {
2324import { resolve_friendly_model_name } from '../../utils/model_utils' ;
2425import { get_settings } from '../../stores/settings_store' ;
2526import { use_trace_store } from '../../stores/trace_store' ;
27+
28+ const normalize_model_config = ( raw : unknown , default_model_id ?: string ) : ModelConfigDto | undefined => {
29+ if ( ! raw || typeof raw !== 'object' ) return undefined ;
30+ const cfg = raw as Record < string , unknown > ;
31+ const modelId = ( cfg . modelId || cfg . model_id || cfg . model || default_model_id ) as string | undefined ;
32+ if ( ! modelId || modelId === 'unknown' ) return undefined ;
33+ const provider = ( cfg . provider as string | undefined ) || 'ollama' ;
34+ return {
35+ ...cfg ,
36+ provider,
37+ modelId,
38+ } as ModelConfigDto ;
39+ } ;
2640import { v4 as uuidv4 } from 'uuid' ;
2741
2842
@@ -154,6 +168,20 @@ export const normalize_agent_dto = (dto: AgentDto, workspace_path?: string, exis
154168 || default_model ;
155169 const model = resolve_friendly_model_name ( raw_model ) || raw_model ;
156170
171+ const cfg2 = get_val ( 'modelConfig2' , 'model_config2' , undefined ) as Record < string , unknown > | undefined ;
172+ const m2_config_id = ( cfg2 ?. modelId || cfg2 ?. model_id || cfg2 ?. model ) as string | undefined ;
173+ const m2_name = get_val < string | undefined > ( 'model2' , 'model_2' , undefined ) ;
174+ const raw_m2 = ( m2_config_id && m2_config_id !== 'unknown' ? m2_config_id : undefined )
175+ || ( m2_name && m2_name !== 'unknown' ? m2_name : undefined ) ;
176+ const model_2 = raw_m2 ? ( resolve_friendly_model_name ( raw_m2 ) || raw_m2 ) : undefined ;
177+
178+ const cfg3 = get_val ( 'modelConfig3' , 'model_config3' , undefined ) as Record < string , unknown > | undefined ;
179+ const m3_config_id = ( cfg3 ?. modelId || cfg3 ?. model_id || cfg3 ?. model ) as string | undefined ;
180+ const m3_name = get_val < string | undefined > ( 'model3' , 'model_3' , undefined ) ;
181+ const raw_m3 = ( m3_config_id && m3_config_id !== 'unknown' ? m3_config_id : undefined )
182+ || ( m3_name && m3_name !== 'unknown' ? m3_name : undefined ) ;
183+ const model_3 = raw_m3 ? ( resolve_friendly_model_name ( raw_m3 ) || raw_m3 ) : undefined ;
184+
157185 const input_tokens = ( dto . tokenUsage ?. inputTokens ?? d . input_tokens ?? existing_agent ?. input_tokens ?? 0 ) ;
158186 const output_tokens = ( dto . tokenUsage ?. outputTokens ?? d . output_tokens ?? existing_agent ?. output_tokens ?? 0 ) ;
159187 const tokens_used = ( dto . tokenUsage ?. totalTokens ?? d . tokensUsed ?? d . tokens_used ?? ( input_tokens + output_tokens ) ) ;
@@ -167,14 +195,7 @@ export const normalize_agent_dto = (dto: AgentDto, workspace_path?: string, exis
167195 status : status ,
168196 tokens_used,
169197 model : model ,
170- model_config : ( ( ) => {
171- const cfg = get_val ( 'modelConfig' , 'model_config' , undefined ) as Record < string , unknown > | undefined ;
172- if ( ! cfg ) return undefined ;
173- if ( ! cfg . modelId && cfg . model_id ) {
174- return { ...cfg , modelId : cfg . model_id } ;
175- }
176- return cfg ;
177- } ) ( ) ,
198+ model_config : normalize_model_config ( cfg1 , raw_model ) ,
178199 workspace_path : workspace_path || get_val ( 'workspace' , 'workspace_path' , undefined ) ,
179200 current_task : current_task || undefined ,
180201 skills : parse_json_array ( 'skills' , 'skills' ) ,
@@ -184,38 +205,10 @@ export const normalize_agent_dto = (dto: AgentDto, workspace_path?: string, exis
184205 budget_usd : get_val ( 'budgetUsd' , 'budget_usd' , 0 ) ,
185206 cost_usd : get_val ( 'costUsd' , 'cost_usd' , 0 ) ,
186207 requires_oversight : get_val ( 'requiresOversight' , 'requires_oversight' , false ) ,
187- model_2 : ( ( ) => {
188- const cfg2 = get_val ( 'modelConfig2' , 'model_config2' , undefined ) as Record < string , unknown > | undefined ;
189- const m2_config_id = ( cfg2 ?. modelId || cfg2 ?. model_id || cfg2 ?. model ) as string | undefined ;
190- const m2_name = get_val < string | undefined > ( 'model2' , 'model_2' , undefined ) ;
191- const raw_m2 = ( m2_config_id && m2_config_id !== 'unknown' ? m2_config_id : undefined )
192- || ( m2_name && m2_name !== 'unknown' ? m2_name : undefined ) ;
193- return raw_m2 ? ( resolve_friendly_model_name ( raw_m2 ) || raw_m2 ) : undefined ;
194- } ) ( ) ,
195- model_3 : ( ( ) => {
196- const cfg3 = get_val ( 'modelConfig3' , 'model_config3' , undefined ) as Record < string , unknown > | undefined ;
197- const m3_config_id = ( cfg3 ?. modelId || cfg3 ?. model_id || cfg3 ?. model ) as string | undefined ;
198- const m3_name = get_val < string | undefined > ( 'model3' , 'model_3' , undefined ) ;
199- const raw_m3 = ( m3_config_id && m3_config_id !== 'unknown' ? m3_config_id : undefined )
200- || ( m3_name && m3_name !== 'unknown' ? m3_name : undefined ) ;
201- return raw_m3 ? ( resolve_friendly_model_name ( raw_m3 ) || raw_m3 ) : undefined ;
202- } ) ( ) ,
203- model_config2 : ( ( ) => {
204- const cfg2 = get_val ( 'modelConfig2' , 'model_config2' , undefined ) as Record < string , unknown > | undefined ;
205- if ( ! cfg2 ) return undefined ;
206- const m2_id = cfg2 . modelId || cfg2 . model_id || cfg2 . model ;
207- if ( ! m2_id || m2_id === 'unknown' ) return undefined ;
208- if ( ! cfg2 . modelId && cfg2 . model_id ) return { ...cfg2 , modelId : cfg2 . model_id } ;
209- return cfg2 ;
210- } ) ( ) ,
211- model_config3 : ( ( ) => {
212- const cfg3 = get_val ( 'modelConfig3' , 'model_config3' , undefined ) as Record < string , unknown > | undefined ;
213- if ( ! cfg3 ) return undefined ;
214- const m3_id = cfg3 . modelId || cfg3 . model_id || cfg3 . model ;
215- if ( ! m3_id || m3_id === 'unknown' ) return undefined ;
216- if ( ! cfg3 . modelId && cfg3 . model_id ) return { ...cfg3 , modelId : cfg3 . model_id } ;
217- return cfg3 ;
218- } ) ( ) ,
208+ model_2,
209+ model_3,
210+ model_config2 : normalize_model_config ( cfg2 , raw_m2 ) ,
211+ model_config3 : normalize_model_config ( cfg3 , raw_m3 ) ,
219212 active_model_slot : ( get_val ( 'activeModelSlot' , 'active_model_slot' , 1 ) as 1 | 2 | 3 ) ,
220213 failure_count : get_val ( 'failureCount' , 'failure_count' , 0 ) ,
221214 last_failure_at : get_val ( 'lastFailureAt' , 'last_failure_at' , undefined ) ,
0 commit comments