fix: respect Kiro default agent fallback
This commit is contained in:
@@ -18,6 +18,7 @@ const aiAgentsStatus = {
|
||||
opencode: { status: 'missing' as const, version: null },
|
||||
pi: { status: 'missing' as const, version: null },
|
||||
gemini: { status: 'missing' as const, version: null },
|
||||
kiro: { status: 'missing' as const, version: null },
|
||||
}
|
||||
|
||||
describe('useAiAgentPreferences', () => {
|
||||
@@ -86,6 +87,7 @@ describe('useAiAgentPreferences', () => {
|
||||
opencode: { status: 'missing', version: null },
|
||||
pi: { status: 'missing', version: null },
|
||||
gemini: { status: 'missing', version: null },
|
||||
kiro: { status: 'missing', version: null },
|
||||
},
|
||||
}))
|
||||
|
||||
|
||||
@@ -59,6 +59,32 @@ describe('ai target provider contract', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('accepts legacy agent ids saved in the default target field', () => {
|
||||
const target = resolveAiTarget({
|
||||
default_ai_agent: 'claude_code',
|
||||
default_ai_target: 'kiro',
|
||||
} as Settings)
|
||||
|
||||
expect(target).toMatchObject({
|
||||
kind: 'agent',
|
||||
agent: 'kiro',
|
||||
id: 'agent:kiro',
|
||||
})
|
||||
})
|
||||
|
||||
it('uses the legacy default agent when a saved agent target is stale', () => {
|
||||
const target = resolveAiTarget({
|
||||
default_ai_agent: 'kiro',
|
||||
default_ai_target: 'agent:claude_code',
|
||||
} as Settings)
|
||||
|
||||
expect(target).toMatchObject({
|
||||
kind: 'agent',
|
||||
agent: 'kiro',
|
||||
id: 'agent:kiro',
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps provider defaults in one catalog with stable grouping metadata', () => {
|
||||
const entries = aiModelProviderCatalog()
|
||||
const kinds = entries.map((entry) => entry.kind)
|
||||
|
||||
@@ -125,11 +125,16 @@ export function agentTargets(): AiTarget[] {
|
||||
export function resolveAiTarget(settings: Settings): AiTarget {
|
||||
const providers = normalizeAiModelProviders(settings.ai_model_providers)
|
||||
const targets = [...agentTargets(), ...configuredModelTargets(providers)]
|
||||
const storedTarget = settings.default_ai_target
|
||||
const target = targets.find((candidate) => candidate.id === storedTarget)
|
||||
if (target) return target
|
||||
const storedLegacyAgent = normalizeStoredAiAgent(settings.default_ai_agent)
|
||||
const legacyAgent = storedLegacyAgent ?? DEFAULT_AI_AGENT
|
||||
const target = resolveStoredAiTarget(settings.default_ai_target, targets)
|
||||
if (target) {
|
||||
if (target.kind === 'agent' && storedLegacyAgent && target.agent === DEFAULT_AI_AGENT && target.agent !== storedLegacyAgent) {
|
||||
return agentTargets().find((candidate) => candidate.kind === 'agent' && candidate.agent === legacyAgent) ?? target
|
||||
}
|
||||
return target
|
||||
}
|
||||
|
||||
const legacyAgent = normalizeStoredAiAgent(settings.default_ai_agent) ?? DEFAULT_AI_AGENT
|
||||
return agentTargets().find((candidate) => candidate.kind === 'agent' && candidate.agent === legacyAgent) ?? agentTargets()[0]
|
||||
}
|
||||
|
||||
@@ -137,6 +142,18 @@ export function targetAgent(target: AiTarget): AiAgentId {
|
||||
return target.kind === 'agent' ? target.agent : DEFAULT_AI_AGENT
|
||||
}
|
||||
|
||||
function resolveStoredAiTarget(storedTarget: string | null | undefined, targets: AiTarget[]): AiTarget | null {
|
||||
const target = storedTarget?.trim()
|
||||
if (!target) return null
|
||||
|
||||
const exactTarget = targets.find((candidate) => candidate.id === target)
|
||||
if (exactTarget) return exactTarget
|
||||
|
||||
const legacyAgent = normalizeStoredAiAgent(target)
|
||||
if (!legacyAgent) return null
|
||||
return targets.find((candidate) => candidate.kind === 'agent' && candidate.agent === legacyAgent) ?? null
|
||||
}
|
||||
|
||||
export function normalizeAiModelProviders(providers: AiModelProvider[] | null | undefined): AiModelProvider[] {
|
||||
return (providers ?? []).map(normalizeAiModelProvider).filter((provider): provider is AiModelProvider => provider !== null)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user