|
6 | 6 | */ |
7 | 7 |
|
8 | 8 | import { describe, it, expect } from "vitest"; |
| 9 | +import { LLMClient } from "./llm-client.js"; |
9 | 10 |
|
10 | 11 | // Test the provider configuration logic directly |
11 | 12 | // (extracted from LLMClient to make it testable) |
12 | 13 |
|
13 | | -function getDefaultApiKey(provider: "openai" | "anthropic" | "openrouter"): string | undefined { |
| 14 | +function getDefaultApiKey(provider: "openai" | "anthropic" | "openrouter" | "custom"): string | undefined { |
14 | 15 | switch (provider) { |
15 | 16 | case "openai": |
16 | 17 | return process.env["OPENAI_API_KEY"]; |
17 | 18 | case "anthropic": |
18 | 19 | return process.env["ANTHROPIC_API_KEY"]; |
19 | 20 | case "openrouter": |
20 | 21 | return process.env["OPENROUTER_API_KEY"]; |
| 22 | + case "custom": |
| 23 | + return undefined; |
21 | 24 | } |
22 | 25 | } |
23 | 26 |
|
24 | | -function getDefaultBaseUrl(provider: "openai" | "anthropic" | "openrouter"): string | undefined { |
| 27 | +function getDefaultBaseUrl(provider: "openai" | "anthropic" | "openrouter" | "custom"): string | undefined { |
25 | 28 | switch (provider) { |
26 | 29 | case "openai": |
27 | 30 | return undefined; // Uses default |
28 | 31 | case "anthropic": |
29 | 32 | return "https://api.anthropic.com/v1"; |
30 | 33 | case "openrouter": |
31 | 34 | return "https://openrouter.ai/api/v1"; |
| 35 | + case "custom": |
| 36 | + return undefined; |
32 | 37 | } |
33 | 38 | } |
34 | 39 |
|
@@ -74,5 +79,35 @@ describe("LLMClient provider configuration", () => { |
74 | 79 |
|
75 | 80 | process.env["OPENROUTER_API_KEY"] = original; |
76 | 81 | }); |
| 82 | + |
| 83 | + it("returns undefined for custom provider (must be provided explicitly)", () => { |
| 84 | + expect(getDefaultApiKey("custom")).toBeUndefined(); |
| 85 | + }); |
| 86 | + }); |
| 87 | + |
| 88 | + describe("custom provider", () => { |
| 89 | + it("returns undefined for custom provider base URL", () => { |
| 90 | + expect(getDefaultBaseUrl("custom")).toBeUndefined(); |
| 91 | + }); |
| 92 | + |
| 93 | + it("throws error when custom provider is used without baseUrl", () => { |
| 94 | + expect(() => { |
| 95 | + new LLMClient({ |
| 96 | + provider: "custom", |
| 97 | + model: "my-model", |
| 98 | + apiKey: "test-key", |
| 99 | + }); |
| 100 | + }).toThrow("Custom provider requires a baseUrl to be specified"); |
| 101 | + }); |
| 102 | + |
| 103 | + it("creates client successfully when custom provider has baseUrl", () => { |
| 104 | + const client = new LLMClient({ |
| 105 | + provider: "custom", |
| 106 | + model: "my-model", |
| 107 | + apiKey: "test-key", |
| 108 | + baseUrl: "https://my-custom-api.example.com/v1", |
| 109 | + }); |
| 110 | + expect(client).toBeDefined(); |
| 111 | + }); |
77 | 112 | }); |
78 | 113 | }); |
0 commit comments