Skip to content

Commit e4021c1

Browse files
committed
fix(types): resolve all project build errors in tsc -b
- Safely resolve slot models via get_agent_slot_model in useAgentConfig to eliminate TS18048 undefined checks - Normalize model configs to strictly typed ModelConfigDto in normalizers.ts to eliminate TS2322 - Correct AgentDto import path to contracts/agent in agent_telemetry_store to eliminate TS2305 - Add required category field to Agent mock fixtures in agent_mappers.test.ts to eliminate TS2741
1 parent 03d69b2 commit e4021c1

5 files changed

Lines changed: 78 additions & 83 deletions

File tree

src/components/agent-config/useAgentConfig.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { tadpole_os_service } from '../../services/tadpoleos_service';
1616
import { event_bus } from '../../services/event_bus';
1717
import { use_role_store } from '../../stores/role_store';
1818
import { use_model_store } from '../../stores/model_store';
19-
import { resolve_agent_model_config, resolve_technical_model_id } from '../../utils/model_utils';
19+
import { resolve_agent_model_config, resolve_technical_model_id, get_agent_slot_model } from '../../utils/model_utils';
2020
import { ValidationUtils } from '../../utils/validation_utils';
2121
import { i18n } from '../../i18n';
2222
import type { Agent, AgentPatch, Role_Definition, Agent_Model_Slot_Key, Department } from '../../contracts/agent';
@@ -59,12 +59,12 @@ export function useAgentConfig(
5959
last_seen_agent_ref.current = agent;
6060

6161
// Skip rehydration if the parent/external store didn't update the agent structurally
62-
const last_m1 = last_seen.model_config?.modelId || (last_seen.model_config as unknown as { model_id?: string })?.model_id;
63-
const curr_m1 = agent.model_config?.modelId || (agent.model_config as unknown as { model_id?: string })?.model_id;
64-
const last_m2 = last_seen.model_config2?.modelId || (last_seen.model_config2 as unknown as { model_id?: string })?.model_id;
65-
const curr_m2 = agent.model_config2?.modelId || (agent.model_config2 as unknown as { model_id?: string })?.model_id;
66-
const last_m3 = last_seen.model_config3?.modelId || (last_seen.model_config3 as unknown as { model_id?: string })?.model_id;
67-
const curr_m3 = agent.model_config3?.modelId || (agent.model_config3 as unknown as { model_id?: string })?.model_id;
62+
const last_m1 = get_agent_slot_model(last_seen, 1);
63+
const curr_m1 = get_agent_slot_model(agent, 1);
64+
const last_m2 = get_agent_slot_model(last_seen, 2);
65+
const curr_m2 = get_agent_slot_model(agent, 2);
66+
const last_m3 = get_agent_slot_model(last_seen, 3);
67+
const curr_m3 = get_agent_slot_model(agent, 3);
6868

6969
if (last_seen &&
7070
last_seen.id === agent.id &&

src/contracts/agent/domain.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
*/
1212

1313
import type { ModelConfigDto } from './wire';
14-
import type {
15-
Agent_Status,
16-
Department,
17-
Agent_Metadata,
14+
import type {
15+
Agent_Status,
16+
Department,
17+
Agent_Metadata,
1818
Agent_Connector_Config,
1919
Agent_Voice_Engine,
2020
Agent_Stt_Engine
@@ -29,7 +29,7 @@ export interface Agent {
2929
status: Agent_Status;
3030
tokens_used?: number;
3131
current_task?: string;
32-
model: string;
32+
model: string;
3333
model_2?: string;
3434
model_3?: string;
3535
model_config?: ModelConfigDto;
@@ -52,15 +52,15 @@ export interface Agent {
5252
output_tokens?: number;
5353
failure_count?: number;
5454
last_failure_at?: string;
55-
category: string;
55+
category: string;
5656
connector_configs?: Agent_Connector_Config[];
5757
metadata?: Agent_Metadata;
5858
current_reasoning_turn?: number;
5959
reasoning_depth?: number;
6060
workspace_path?: string;
6161
_local_timestamp?: number;
6262
_telemetry_timestamp?: number;
63-
active_mission?: {
63+
active_mission?: {
6464
id: string;
6565
objective?: string;
6666
constraints?: string[];
@@ -103,41 +103,41 @@ export interface Agent_Memory_Entry {
103103
* Represents a unit of work assigned to an agent.
104104
*/
105105
export interface Task {
106-
id: string;
107-
title: string;
108-
assigned_to: string;
109-
status: 'pending' | 'in-progress' | 'completed' | 'failed';
110-
priority: 'low' | 'medium' | 'high';
111-
created_at: string;
112-
logs: string[];
106+
id: string;
107+
title: string;
108+
assigned_to: string;
109+
status: 'pending' | 'in-progress' | 'completed' | 'failed';
110+
priority: 'low' | 'medium' | 'high';
111+
created_at: string;
112+
logs: string[];
113113
}
114114

115115
/**
116116
* Task_Payload
117117
* Payload for sending a command/task to an agent.
118118
*/
119119
export interface Task_Payload {
120-
message: string;
121-
cluster_id?: string;
122-
department?: string;
123-
provider?: string;
124-
model_id?: string;
125-
api_key?: string;
126-
base_url?: string;
127-
rpm?: number;
128-
tpm?: number;
129-
rpd?: number;
130-
tpd?: number;
131-
budget_usd?: number;
132-
external_id?: string;
133-
safe_mode?: boolean;
134-
analysis?: boolean;
135-
swarm_depth?: number;
136-
swarm_lineage?: string[];
137-
recent_findings?: string;
138-
traceparent?: string;
139-
parent_node_id?: string;
140-
enabled_skills?: string[];
120+
message: string;
121+
cluster_id?: string;
122+
department?: string;
123+
provider?: string;
124+
model_id?: string;
125+
api_key?: string;
126+
base_url?: string;
127+
rpm?: number;
128+
tpm?: number;
129+
rpd?: number;
130+
tpd?: number;
131+
budget_usd?: number;
132+
external_id?: string;
133+
safe_mode?: boolean;
134+
analysis?: boolean;
135+
swarm_depth?: number;
136+
swarm_lineage?: string[];
137+
recent_findings?: string;
138+
traceparent?: string;
139+
parent_node_id?: string;
140+
enabled_skills?: string[];
141141
}
142142

143143
export type AgentPatch = Partial<Agent>;

src/domain/agents/normalizers.ts

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import type {
1414
Agent,
1515
AgentDto,
16+
ModelConfigDto,
1617
Department,
1718
Agent_Status,
1819
Agent_Memory_Entry,
@@ -23,6 +24,19 @@ import type {
2324
import { resolve_friendly_model_name } from '../../utils/model_utils';
2425
import { get_settings } from '../../stores/settings_store';
2526
import { 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+
};
2640
import { 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),

src/services/agent_mappers.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ describe('agent_mappers', () => {
211211
model_2: 'claude-3-5-sonnet',
212212
model_config2: { modelId: 'claude-3-5-sonnet', provider: 'anthropic', temperature: 0.5 },
213213
active_model_slot: 2,
214+
category: 'general',
214215
skills: [],
215216
workflows: []
216217
};
@@ -235,6 +236,7 @@ describe('agent_mappers', () => {
235236
model: 'Gemini 1.5 Flash',
236237
model_config: { modelId: 'gemini-1.5-flash', provider: 'google', temperature: 0.7 },
237238
active_model_slot: 1,
239+
category: 'general',
238240
skills: [],
239241
workflows: []
240242
};

src/stores/agent_telemetry_store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import { create } from 'zustand';
1919
import { tadpole_os_socket } from '../services/socket';
2020
import { use_agent_registry_store } from './agent_registry_store';
21-
import type { Agent, AgentDto } from '../types';
21+
import type { Agent, AgentDto } from '../contracts/agent';
2222
import { normalize_agent_dto } from '../domain/agents/normalizers';
2323

2424
export interface Telemetry_State {

0 commit comments

Comments
 (0)