fix(schema): preserve custom agent overrides via catchall
AgentOverridesSchema silently strips custom agent keys during Zod parsing because only 14 built-in names are explicitly defined. Add .catchall(AgentOverrideConfigSchema.optional()) so user-defined agent configs survive validation and reach downstream consumers like resolveModelAndFallbackChain(). Fixes #3229.
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
import { describe, expect, test } from "bun:test"
|
||||||
|
import { AgentOverridesSchema } from "./agent-overrides"
|
||||||
|
|
||||||
|
describe("AgentOverridesSchema", () => {
|
||||||
|
test("preserves custom agent keys after parsing", () => {
|
||||||
|
const input = {
|
||||||
|
sisyphus: { model: "anthropic/claude-opus-4-6" },
|
||||||
|
"technical-writer": {
|
||||||
|
model: "anthropic/claude-sonnet-4-6",
|
||||||
|
temperature: 0.3,
|
||||||
|
prompt_append: "You are a technical writer.",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = AgentOverridesSchema.safeParse(input)
|
||||||
|
|
||||||
|
expect(result.success).toBe(true)
|
||||||
|
if (result.success) {
|
||||||
|
expect(result.data.sisyphus).toBeDefined()
|
||||||
|
expect(result.data["technical-writer"]).toBeDefined()
|
||||||
|
expect(result.data["technical-writer"]?.model).toBe("anthropic/claude-sonnet-4-6")
|
||||||
|
expect(result.data["technical-writer"]?.temperature).toBe(0.3)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test("validates custom agent keys against AgentOverrideConfigSchema", () => {
|
||||||
|
const input = {
|
||||||
|
"custom-agent": {
|
||||||
|
model: "provider/model",
|
||||||
|
temperature: 5, // invalid: max is 2
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = AgentOverridesSchema.safeParse(input)
|
||||||
|
|
||||||
|
expect(result.success).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -72,7 +72,7 @@ export const AgentOverridesSchema = z.object({
|
|||||||
explore: AgentOverrideConfigSchema.optional(),
|
explore: AgentOverrideConfigSchema.optional(),
|
||||||
"multimodal-looker": AgentOverrideConfigSchema.optional(),
|
"multimodal-looker": AgentOverrideConfigSchema.optional(),
|
||||||
atlas: AgentOverrideConfigSchema.optional(),
|
atlas: AgentOverrideConfigSchema.optional(),
|
||||||
})
|
}).catchall(AgentOverrideConfigSchema.optional())
|
||||||
|
|
||||||
export type AgentOverrideConfig = z.infer<typeof AgentOverrideConfigSchema>
|
export type AgentOverrideConfig = z.infer<typeof AgentOverrideConfigSchema>
|
||||||
export type AgentOverrides = z.infer<typeof AgentOverridesSchema>
|
export type AgentOverrides = z.infer<typeof AgentOverridesSchema>
|
||||||
|
|||||||
Reference in New Issue
Block a user