-
Notifications
You must be signed in to change notification settings - Fork 543
fix: merge agenticTiers/ecoTiers/premiumTiers in routing config overrides #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
kagura-agent
wants to merge
3
commits into
BlockRunAI:main
from
kagura-agent:fix/merge-agentic-tiers
+141
−1
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { mergeRoutingConfig, mergeTierRecord } from "./proxy.js"; | ||
| import { DEFAULT_ROUTING_CONFIG } from "./router/index.js"; | ||
| import type { Tier, TierConfig } from "./router/index.js"; | ||
|
|
||
| describe("mergeTierRecord", () => { | ||
| const baseTiers: Record<Tier, TierConfig> = { | ||
| SIMPLE: { primary: "model-a", fallback: ["model-b"] }, | ||
| MEDIUM: { primary: "model-c", fallback: [] }, | ||
| COMPLEX: { primary: "model-d", fallback: [] }, | ||
| REASONING: { primary: "model-e", fallback: [] }, | ||
| }; | ||
|
|
||
| it("returns base when override is undefined", () => { | ||
| expect(mergeTierRecord(baseTiers, undefined)).toBe(baseTiers); | ||
| }); | ||
|
|
||
| it("returns undefined when override is null (disables tier set)", () => { | ||
| expect(mergeTierRecord(baseTiers, null)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("shallow-merges override into base", () => { | ||
| const override: Record<Tier, TierConfig> = { | ||
| ...baseTiers, | ||
| SIMPLE: { primary: "custom-model", fallback: ["custom-fallback"] }, | ||
| }; | ||
| const result = mergeTierRecord(baseTiers, override); | ||
| expect(result!.SIMPLE.primary).toBe("custom-model"); | ||
| expect(result!.MEDIUM.primary).toBe("model-c"); | ||
| }); | ||
|
|
||
| it("returns override when base is undefined", () => { | ||
| const override = baseTiers; | ||
| expect(mergeTierRecord(undefined, override)).toBe(override); | ||
| }); | ||
| }); | ||
|
|
||
| describe("mergeRoutingConfig", () => { | ||
| it("returns DEFAULT_ROUTING_CONFIG when no overrides provided", () => { | ||
| expect(mergeRoutingConfig()).toBe(DEFAULT_ROUTING_CONFIG); | ||
| expect(mergeRoutingConfig(undefined)).toBe(DEFAULT_ROUTING_CONFIG); | ||
| }); | ||
|
|
||
| it("keeps default agenticTiers when not overridden", () => { | ||
| const result = mergeRoutingConfig({ overrides: DEFAULT_ROUTING_CONFIG.overrides }); | ||
| expect(result.agenticTiers).toEqual(DEFAULT_ROUTING_CONFIG.agenticTiers); | ||
| }); | ||
|
|
||
| it("disables agenticTiers when set to null", () => { | ||
| const result = mergeRoutingConfig({ | ||
| agenticTiers: null as unknown as Record<Tier, TierConfig>, | ||
| }); | ||
| expect(result.agenticTiers).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("merges custom agenticTiers with defaults", () => { | ||
| const customSimple: TierConfig = { | ||
| primary: "custom/agentic-model", | ||
| fallback: ["custom/fallback"], | ||
| }; | ||
| const result = mergeRoutingConfig({ | ||
| agenticTiers: { | ||
| ...DEFAULT_ROUTING_CONFIG.agenticTiers!, | ||
| SIMPLE: customSimple, | ||
| }, | ||
| }); | ||
| expect(result.agenticTiers!.SIMPLE).toEqual(customSimple); | ||
| // Other tiers preserved from default | ||
| expect(result.agenticTiers!.COMPLEX).toEqual(DEFAULT_ROUTING_CONFIG.agenticTiers!.COMPLEX); | ||
| }); | ||
|
|
||
| it("disables ecoTiers when set to null", () => { | ||
| const result = mergeRoutingConfig({ | ||
| ecoTiers: null as unknown as Record<Tier, TierConfig>, | ||
| }); | ||
| expect(result.ecoTiers).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("merges custom ecoTiers with defaults", () => { | ||
| const customMedium: TierConfig = { | ||
| primary: "custom/eco-model", | ||
| fallback: [], | ||
| }; | ||
| const result = mergeRoutingConfig({ | ||
| ecoTiers: { | ||
| ...DEFAULT_ROUTING_CONFIG.ecoTiers!, | ||
| MEDIUM: customMedium, | ||
| }, | ||
| }); | ||
| expect(result.ecoTiers!.MEDIUM).toEqual(customMedium); | ||
| expect(result.ecoTiers!.SIMPLE).toEqual(DEFAULT_ROUTING_CONFIG.ecoTiers!.SIMPLE); | ||
| }); | ||
|
|
||
| it("merges custom premiumTiers with defaults", () => { | ||
| const customComplex: TierConfig = { | ||
| primary: "custom/premium-model", | ||
| fallback: ["custom/premium-fallback"], | ||
| }; | ||
| const result = mergeRoutingConfig({ | ||
| premiumTiers: { | ||
| ...DEFAULT_ROUTING_CONFIG.premiumTiers!, | ||
| COMPLEX: customComplex, | ||
| }, | ||
| }); | ||
| expect(result.premiumTiers!.COMPLEX).toEqual(customComplex); | ||
| expect(result.premiumTiers!.SIMPLE).toEqual(DEFAULT_ROUTING_CONFIG.premiumTiers!.SIMPLE); | ||
| }); | ||
|
|
||
| it("disables premiumTiers when set to null", () => { | ||
| const result = mergeRoutingConfig({ | ||
| premiumTiers: null as unknown as Record<Tier, TierConfig>, | ||
| }); | ||
| expect(result.premiumTiers).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("still merges other fields correctly alongside tier overrides", () => { | ||
| const result = mergeRoutingConfig({ | ||
| agenticTiers: null as unknown as Record<Tier, TierConfig>, | ||
| overrides: { ...DEFAULT_ROUTING_CONFIG.overrides, agenticMode: true }, | ||
| }); | ||
| expect(result.agenticTiers).toBeUndefined(); | ||
| expect(result.overrides.agenticMode).toBe(true); | ||
| expect(result.tiers).toEqual(DEFAULT_ROUTING_CONFIG.tiers); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mergeTierRecordis not deep-merging per-tier configs.At Line 1295,
{ ...base, ...override }replaces the whole tier entry. If an override provides only part of aTierConfig, default fields in that tier are lost instead of merged.Proposed fix
export function mergeTierRecord( base: Record<Tier, TierConfig> | undefined, override: Record<Tier, TierConfig> | null | undefined, ): Record<Tier, TierConfig> | undefined { if (override === null) return undefined; // explicitly disabled if (override === undefined) return base; // not provided, keep default if (!base) return override; // no default, use override as-is - return { ...base, ...override }; + const merged = { ...base }; + for (const tier of Object.keys(override) as Tier[]) { + merged[tier] = { ...base[tier], ...override[tier] }; + } + return merged; }📝 Committable suggestion
🤖 Prompt for AI Agents