From dbeaa78e2c7ed3461655efb15284f30b455f0c39 Mon Sep 17 00:00:00 2001 From: William Valentin Date: Thu, 5 Feb 2026 13:34:25 -0800 Subject: [PATCH] feat: add setLocalClient and getLocalProviderName to ModelRouter --- src/models/router.test.ts | 21 +++++++++++++++++++++ src/models/router.ts | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/models/router.test.ts b/src/models/router.test.ts index 6c08179..b52b241 100644 --- a/src/models/router.test.ts +++ b/src/models/router.test.ts @@ -141,3 +141,24 @@ describe('ModelRouter streaming', () => { expect(chunks).toEqual(['Fallback']); }); }); + +describe('ModelRouter local client switching', () => { + it('allows setting a new local client', () => { + const mockDefault = { chat: vi.fn() } as unknown as ModelClient; + const mockLocal1 = { chat: vi.fn() } as unknown as ModelClient; + const mockLocal2 = { chat: vi.fn() } as unknown as ModelClient; + + const router = new ModelRouter({ + default: mockDefault, + local: mockLocal1, + fallbackChain: [], + }); + + expect(router.getLocalProviderName()).toBe(undefined); + + router.setLocalClient(mockLocal2, 'llamacpp'); + + expect(router.getLocalProviderName()).toBe('llamacpp'); + expect(router.getClient('local')).toBe(mockLocal2); + }); +}); diff --git a/src/models/router.ts b/src/models/router.ts index 3b0704e..87e94b1 100644 --- a/src/models/router.ts +++ b/src/models/router.ts @@ -15,6 +15,7 @@ export class ModelRouter implements ModelClient { private defaultClient: ModelClient; private fallbackChain: ModelClient[]; private currentTier: ModelTier = 'default'; + private localProviderName?: string; constructor(config: ModelRouterConfig) { this.clients = new Map(); @@ -111,4 +112,13 @@ export class ModelRouter implements ModelClient { getClient(tier: ModelTier): ModelClient | undefined { return this.clients.get(tier); } + + setLocalClient(client: ModelClient, providerName: string): void { + this.clients.set('local', client); + this.localProviderName = providerName; + } + + getLocalProviderName(): string | undefined { + return this.localProviderName; + } }