From aeb572e1ce88ba1e1c0e49bb96ec369c0f500ede Mon Sep 17 00:00:00 2001 From: Pachara Nokroy Date: Thu, 6 Aug 2026 18:36:54 +0700 Subject: [PATCH] feat: expose ProviderRegistry.list() --- src/cli/index.ts | 6 +++++- src/providers/registry.ts | 5 +++++ tests/providers.test.ts | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/cli/index.ts b/src/cli/index.ts index 7ec9b70..1107382 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -156,9 +156,13 @@ async function cmdCompare(args: ParsedArgs): Promise { function cmdList(): number { const scorers = defaultScorerRegistry().list().sort(); + const providers = defaultRegistry(process.env).list().sort(); + console.log("Registered scorers:"); for (const s of scorers) console.log(` - ${s}`); - console.log("\nRegistered providers: mock, openai, anthropic, groq, openrouter"); + + console.log("\nRegistered providers:"); + for (const p of providers) console.log(` - ${p}`); return 0; } diff --git a/src/providers/registry.ts b/src/providers/registry.ts index bb5c399..9c9ef33 100644 --- a/src/providers/registry.ts +++ b/src/providers/registry.ts @@ -41,6 +41,11 @@ export class ProviderRegistry { this.cache.set(name, provider); return provider; } + + /** List all registered provider names. */ + list(): string[] { + return [...this.factories.keys()]; + } } /** diff --git a/tests/providers.test.ts b/tests/providers.test.ts index 1867889..ab186d5 100644 --- a/tests/providers.test.ts +++ b/tests/providers.test.ts @@ -68,4 +68,18 @@ describe("ProviderRegistry", () => { expect(reg.has("openai")).toBe(true); expect(reg.has("anthropic")).toBe(true); }); + it("lists built-in and custom providers", () => { + const reg = defaultRegistry({}); + + expect(reg.list().sort()).toEqual([ + "anthropic", + "groq", + "mock", + "openai", + "openrouter", + ]); + + reg.register("custom", () => new MockProvider()); + expect(reg.list()).toContain("custom"); +}); });