fix(models): make tier-change listener registration non-destructive
This commit is contained in:
@@ -463,4 +463,22 @@ describe('setClient and labels', () => {
|
||||
expect(fallback.chat).not.toHaveBeenCalled();
|
||||
expect(router.isTierStrict('default')).toBe(true);
|
||||
});
|
||||
|
||||
it('setOnTierChange does not replace existing listeners', () => {
|
||||
const router = new ModelRouter({
|
||||
default: { chat: vi.fn() } as unknown as ModelClient,
|
||||
fast: { chat: vi.fn() } as unknown as ModelClient,
|
||||
fallbackChain: [],
|
||||
});
|
||||
|
||||
const first = vi.fn();
|
||||
const second = vi.fn();
|
||||
router.addOnTierChange(first);
|
||||
router.setOnTierChange(second);
|
||||
|
||||
router.setTier('fast');
|
||||
|
||||
expect(first).toHaveBeenCalledWith('fast');
|
||||
expect(second).toHaveBeenCalledWith('fast');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -67,7 +67,7 @@ export class ModelRouter implements ModelClient {
|
||||
}
|
||||
|
||||
setOnTierChange(callback: (tier: ModelTier) => void): void {
|
||||
this.tierChangeListeners = [callback];
|
||||
this.addOnTierChange(callback);
|
||||
}
|
||||
|
||||
addOnTierChange(callback: (tier: ModelTier) => void): void {
|
||||
|
||||
Reference in New Issue
Block a user