universal-llm-client 4.1.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/CHANGELOG.md +139 -103
  2. package/LICENSE +21 -21
  3. package/README.md +591 -591
  4. package/dist/ai-model.js.map +1 -1
  5. package/dist/auditor.js.map +1 -1
  6. package/dist/client.js.map +1 -1
  7. package/dist/http.js.map +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/interfaces.d.ts +20 -0
  13. package/dist/interfaces.d.ts.map +1 -1
  14. package/dist/interfaces.js.map +1 -1
  15. package/dist/mcp.js.map +1 -1
  16. package/dist/providers/anthropic.js.map +1 -1
  17. package/dist/providers/google.d.ts.map +1 -1
  18. package/dist/providers/google.js +2 -0
  19. package/dist/providers/google.js.map +1 -1
  20. package/dist/providers/index.js.map +1 -1
  21. package/dist/providers/ollama.js.map +1 -1
  22. package/dist/providers/openai.js.map +1 -1
  23. package/dist/router.js.map +1 -1
  24. package/dist/stream-decoder.js.map +1 -1
  25. package/dist/structured-output.d.ts +24 -1
  26. package/dist/structured-output.d.ts.map +1 -1
  27. package/dist/structured-output.js +58 -5
  28. package/dist/structured-output.js.map +1 -1
  29. package/dist/tools.js.map +1 -1
  30. package/dist/zod-adapter.js.map +1 -1
  31. package/package.json +115 -116
  32. package/src/ai-model.ts +0 -350
  33. package/src/auditor.ts +0 -213
  34. package/src/client.ts +0 -402
  35. package/src/debug/debug-google-streaming.ts +0 -97
  36. package/src/debug/debug-tool-execution.ts +0 -86
  37. package/src/debug/test-lmstudio-tools.ts +0 -155
  38. package/src/demos/README.md +0 -47
  39. package/src/demos/basic/universal-llm-examples.ts +0 -161
  40. package/src/demos/mcp/astrid-memory-demo.ts +0 -295
  41. package/src/demos/mcp/astrid-persona-memory.ts +0 -357
  42. package/src/demos/mcp/mcp-mongodb-demo.ts +0 -275
  43. package/src/demos/mcp/simple-astrid-memory.ts +0 -148
  44. package/src/demos/mcp/simple-mcp-demo.ts +0 -68
  45. package/src/demos/mcp/working-mcp-demo.ts +0 -62
  46. package/src/demos/model-alias-demo.ts +0 -0
  47. package/src/demos/tools/RAG_MEMORY_INTEGRATION.md +0 -267
  48. package/src/demos/tools/astrid-memory-demo.ts +0 -270
  49. package/src/demos/tools/astrid-production-memory-clean.ts +0 -785
  50. package/src/demos/tools/astrid-production-memory.ts +0 -558
  51. package/src/demos/tools/basic-translation-test.ts +0 -66
  52. package/src/demos/tools/chromadb-similarity-tuning.ts +0 -390
  53. package/src/demos/tools/clean-multilingual-conversation.ts +0 -209
  54. package/src/demos/tools/clean-translation-test.ts +0 -119
  55. package/src/demos/tools/clean-universal-multilingual-test.ts +0 -131
  56. package/src/demos/tools/complete-rag-demo.ts +0 -369
  57. package/src/demos/tools/complete-tool-demo.ts +0 -132
  58. package/src/demos/tools/demo-tool-calling.ts +0 -124
  59. package/src/demos/tools/dynamic-language-switching-test.ts +0 -251
  60. package/src/demos/tools/hybrid-thinking-test.ts +0 -154
  61. package/src/demos/tools/memory-integration-test.ts +0 -420
  62. package/src/demos/tools/multilingual-memory-system.ts +0 -802
  63. package/src/demos/tools/ondemand-translation-demo.ts +0 -655
  64. package/src/demos/tools/production-tool-demo.ts +0 -245
  65. package/src/demos/tools/revolutionary-multilingual-test.ts +0 -151
  66. package/src/demos/tools/rigorous-language-analysis.ts +0 -218
  67. package/src/demos/tools/test-universal-memory-system.ts +0 -126
  68. package/src/demos/tools/translation-integration-guide.ts +0 -346
  69. package/src/demos/tools/universal-memory-system.ts +0 -560
  70. package/src/http.ts +0 -247
  71. package/src/index.ts +0 -160
  72. package/src/interfaces.ts +0 -657
  73. package/src/mcp.ts +0 -345
  74. package/src/providers/anthropic.ts +0 -762
  75. package/src/providers/google.ts +0 -620
  76. package/src/providers/index.ts +0 -8
  77. package/src/providers/ollama.ts +0 -469
  78. package/src/providers/openai.ts +0 -392
  79. package/src/router.ts +0 -780
  80. package/src/stream-decoder.ts +0 -361
  81. package/src/structured-output.ts +0 -702
  82. package/src/test-scripts/test-advanced-tools.ts +0 -310
  83. package/src/test-scripts/test-google-streaming-enhanced.ts +0 -147
  84. package/src/test-scripts/test-google-streaming.ts +0 -63
  85. package/src/test-scripts/test-google-system-prompt-comprehensive.ts +0 -189
  86. package/src/test-scripts/test-mcp-config.ts +0 -28
  87. package/src/test-scripts/test-mcp-connection.ts +0 -29
  88. package/src/test-scripts/test-system-message-positions.ts +0 -163
  89. package/src/test-scripts/test-system-prompt-improvement-demo.ts +0 -83
  90. package/src/test-scripts/test-tool-calling.ts +0 -231
  91. package/src/tests/ai-model.test.ts +0 -1614
  92. package/src/tests/auditor.test.ts +0 -224
  93. package/src/tests/http.test.ts +0 -200
  94. package/src/tests/interfaces.test.ts +0 -117
  95. package/src/tests/providers/google.test.ts +0 -660
  96. package/src/tests/providers/ollama.test.ts +0 -954
  97. package/src/tests/providers/openai.test.ts +0 -1122
  98. package/src/tests/router.test.ts +0 -254
  99. package/src/tests/stream-decoder.test.ts +0 -179
  100. package/src/tests/structured-output.test.ts +0 -1340
  101. package/src/tests/tools.test.ts +0 -175
  102. package/src/tools.ts +0 -246
  103. package/src/zod-adapter.ts +0 -72
package/package.json CHANGED
@@ -1,116 +1,115 @@
1
- {
2
- "name": "universal-llm-client",
3
- "version": "4.1.0",
4
- "type": "module",
5
- "description": "A universal LLM client with transparent provider failover, streaming tool execution, pluggable reasoning, and native observability.",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
12
- },
13
- "./interfaces": {
14
- "import": "./dist/interfaces.js",
15
- "types": "./dist/interfaces.d.ts"
16
- },
17
- "./tools": {
18
- "import": "./dist/tools.js",
19
- "types": "./dist/tools.d.ts"
20
- },
21
- "./auditor": {
22
- "import": "./dist/auditor.js",
23
- "types": "./dist/auditor.d.ts"
24
- },
25
- "./stream-decoder": {
26
- "import": "./dist/stream-decoder.js",
27
- "types": "./dist/stream-decoder.d.ts"
28
- },
29
- "./http": {
30
- "import": "./dist/http.js",
31
- "types": "./dist/http.d.ts"
32
- },
33
- "./structured-output": {
34
- "import": "./dist/structured-output.js",
35
- "types": "./dist/structured-output.d.ts"
36
- },
37
- "./zod": {
38
- "import": "./dist/zod-adapter.js",
39
- "types": "./dist/zod-adapter.d.ts"
40
- }
41
- },
42
- "files": [
43
- "dist",
44
- "src",
45
- "README.md",
46
- "CHANGELOG.md",
47
- "LICENSE"
48
- ],
49
- "scripts": {
50
- "build": "bun run clean && bun run compile",
51
- "clean": "rimraf dist",
52
- "compile": "tsc --project tsconfig.json",
53
- "dev": "tsc --watch --project tsconfig.json",
54
- "prepublishOnly": "bun run build",
55
- "test": "bun test",
56
- "typecheck": "tsc --noEmit",
57
- "lint": "tsc --noEmit --strict",
58
- "prepack": "bun run build",
59
- "docs:dev": "vitepress dev docs",
60
- "docs:build": "vitepress build docs",
61
- "docs:preview": "vitepress preview docs"
62
- },
63
- "keywords": [
64
- "llm",
65
- "ai",
66
- "artificial-intelligence",
67
- "openai",
68
- "ollama",
69
- "google-gemini",
70
- "vertex-ai",
71
- "universal",
72
- "failover",
73
- "streaming",
74
- "tool-calling",
75
- "function-calling",
76
- "mcp",
77
- "observability",
78
- "typescript",
79
- "esm"
80
- ],
81
- "dependencies": {},
82
- "devDependencies": {
83
- "@types/node": "^22.0.0",
84
- "rimraf": "^6.0.1",
85
- "typescript": "^5.8.3",
86
- "vitepress": "^1.6.4",
87
- "vue": "^3.5.30",
88
- "zod": "^4.0.0"
89
- },
90
- "peerDependencies": {
91
- "@modelcontextprotocol/sdk": ">=1.24.0",
92
- "zod": "^4.0.0"
93
- },
94
- "peerDependenciesMeta": {
95
- "@modelcontextprotocol/sdk": {
96
- "optional": true
97
- },
98
- "zod": {
99
- "optional": true
100
- }
101
- },
102
- "engines": {
103
- "node": ">=22.0.0",
104
- "bun": ">=1.0.0"
105
- },
106
- "author": "Igor Lins e Silva",
107
- "license": "MIT",
108
- "repository": {
109
- "type": "git",
110
- "url": "https://github.com/igorls/universal-llm-client.git"
111
- },
112
- "homepage": "https://github.com/igorls/universal-llm-client#readme",
113
- "bugs": {
114
- "url": "https://github.com/igorls/universal-llm-client/issues"
115
- }
116
- }
1
+ {
2
+ "name": "universal-llm-client",
3
+ "version": "4.3.0",
4
+ "type": "module",
5
+ "description": "A universal LLM client with transparent provider failover, streaming tool execution, pluggable reasoning, and native observability.",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
13
+ "./interfaces": {
14
+ "import": "./dist/interfaces.js",
15
+ "types": "./dist/interfaces.d.ts"
16
+ },
17
+ "./tools": {
18
+ "import": "./dist/tools.js",
19
+ "types": "./dist/tools.d.ts"
20
+ },
21
+ "./auditor": {
22
+ "import": "./dist/auditor.js",
23
+ "types": "./dist/auditor.d.ts"
24
+ },
25
+ "./stream-decoder": {
26
+ "import": "./dist/stream-decoder.js",
27
+ "types": "./dist/stream-decoder.d.ts"
28
+ },
29
+ "./http": {
30
+ "import": "./dist/http.js",
31
+ "types": "./dist/http.d.ts"
32
+ },
33
+ "./structured-output": {
34
+ "import": "./dist/structured-output.js",
35
+ "types": "./dist/structured-output.d.ts"
36
+ },
37
+ "./zod": {
38
+ "import": "./dist/zod-adapter.js",
39
+ "types": "./dist/zod-adapter.d.ts"
40
+ }
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "README.md",
45
+ "CHANGELOG.md",
46
+ "LICENSE"
47
+ ],
48
+ "scripts": {
49
+ "build": "bun run clean && bun run compile",
50
+ "clean": "rimraf dist",
51
+ "compile": "tsc --project tsconfig.json",
52
+ "dev": "tsc --watch --project tsconfig.json",
53
+ "prepublishOnly": "bun run build",
54
+ "test": "bun test",
55
+ "typecheck": "tsc --noEmit",
56
+ "lint": "tsc --noEmit --strict",
57
+ "prepack": "bun run build",
58
+ "docs:dev": "vitepress dev docs",
59
+ "docs:build": "vitepress build docs",
60
+ "docs:preview": "vitepress preview docs"
61
+ },
62
+ "keywords": [
63
+ "llm",
64
+ "ai",
65
+ "artificial-intelligence",
66
+ "openai",
67
+ "ollama",
68
+ "google-gemini",
69
+ "vertex-ai",
70
+ "universal",
71
+ "failover",
72
+ "streaming",
73
+ "tool-calling",
74
+ "function-calling",
75
+ "mcp",
76
+ "observability",
77
+ "typescript",
78
+ "esm"
79
+ ],
80
+ "dependencies": {},
81
+ "devDependencies": {
82
+ "@types/node": "^22.0.0",
83
+ "rimraf": "^6.0.1",
84
+ "typescript": "^5.8.3",
85
+ "vitepress": "^1.6.4",
86
+ "vue": "^3.5.30",
87
+ "zod": "^4.0.0"
88
+ },
89
+ "peerDependencies": {
90
+ "@modelcontextprotocol/sdk": ">=1.24.0",
91
+ "zod": "^4.0.0"
92
+ },
93
+ "peerDependenciesMeta": {
94
+ "@modelcontextprotocol/sdk": {
95
+ "optional": true
96
+ },
97
+ "zod": {
98
+ "optional": true
99
+ }
100
+ },
101
+ "engines": {
102
+ "node": ">=22.0.0",
103
+ "bun": ">=1.0.0"
104
+ },
105
+ "author": "Igor Lins e Silva",
106
+ "license": "MIT",
107
+ "repository": {
108
+ "type": "git",
109
+ "url": "https://github.com/igorls/universal-llm-client.git"
110
+ },
111
+ "homepage": "https://github.com/igorls/universal-llm-client#readme",
112
+ "bugs": {
113
+ "url": "https://github.com/igorls/universal-llm-client/issues"
114
+ }
115
+ }
package/src/ai-model.ts DELETED
@@ -1,350 +0,0 @@
1
- /**
2
- * Universal LLM Client v3 — AIModel (The Universal Client)
3
- *
4
- * The only public-facing class. Developers configure one model with
5
- * multiple provider backends for transparent failover.
6
- *
7
- * Provider classes are internal — the user never imports them.
8
- */
9
-
10
- import {
11
- AIModelApiType,
12
- type AIModelConfig,
13
- type ProviderConfig,
14
- type LLMClientOptions,
15
- type LLMChatMessage,
16
- type LLMChatResponse,
17
- type ChatOptions,
18
- type ModelMetadata,
19
- type LLMFunction,
20
- type ToolHandler,
21
- } from './interfaces.js';
22
- import type { DecodedEvent } from './stream-decoder.js';
23
- import { Router, type RouterConfig, type ProviderStatus } from './router.js';
24
- import type { Auditor } from './auditor.js';
25
- import { NoopAuditor } from './auditor.js';
26
- import { OllamaClient } from './providers/ollama.js';
27
- import { OpenAICompatibleClient } from './providers/openai.js';
28
- import { GoogleClient } from './providers/google.js';
29
- import { AnthropicClient } from './providers/anthropic.js';
30
- import { BaseLLMClient } from './client.js';
31
- import {
32
- type StructuredOutputResult,
33
- type SchemaConfig,
34
- } from './structured-output.js';
35
-
36
- // ============================================================================
37
- // Default Provider URLs
38
- // ============================================================================
39
-
40
- const DEFAULT_URLS: Record<string, string> = {
41
- ollama: 'http://localhost:11434',
42
- openai: 'https://api.openai.com',
43
- llamacpp: 'http://localhost:8080',
44
- anthropic: 'https://api.anthropic.com',
45
- // google and vertex build their own URLs internally
46
- };
47
-
48
- // ============================================================================
49
- // AIModel — The Universal Client
50
- // ============================================================================
51
-
52
- export class AIModel {
53
- private router: Router;
54
- private auditor: Auditor;
55
- private config: AIModelConfig;
56
-
57
- constructor(config: AIModelConfig) {
58
- this.config = config;
59
- this.auditor = config.auditor ?? new NoopAuditor();
60
-
61
- const routerConfig: RouterConfig = {
62
- retriesPerProvider: config.retries ?? 2,
63
- auditor: this.auditor,
64
- };
65
- this.router = new Router(routerConfig);
66
-
67
- // Initialize providers in order
68
- for (let i = 0; i < config.providers.length; i++) {
69
- const providerConfig = config.providers[i]!;
70
- const client = this.createClient(providerConfig);
71
- const id = `${this.normalizeType(providerConfig.type)}-${i}`;
72
-
73
- this.router.addProvider({
74
- id,
75
- client,
76
- priority: providerConfig.priority ?? i,
77
- modelOverride: providerConfig.model,
78
- });
79
- }
80
- }
81
-
82
- // ========================================================================
83
- // Chat
84
- // ========================================================================
85
-
86
- /** Send a chat request with automatic failover across providers */
87
- async chat(
88
- messages: LLMChatMessage[],
89
- options?: ChatOptions,
90
- ): Promise<LLMChatResponse> {
91
- return this.router.chat(messages, options);
92
- }
93
-
94
- /** Chat with automatic tool execution (multi-turn loop) */
95
- async chatWithTools(
96
- messages: LLMChatMessage[],
97
- options?: ChatOptions & { maxIterations?: number },
98
- ): Promise<LLMChatResponse> {
99
- return this.router.chatWithTools(messages, options);
100
- }
101
-
102
- /** Stream chat response with pluggable decoder strategy */
103
- async *chatStream(
104
- messages: LLMChatMessage[],
105
- options?: ChatOptions,
106
- ): AsyncGenerator<DecodedEvent, LLMChatResponse | void, unknown> {
107
- return yield* this.router.chatStream(messages, options);
108
- }
109
-
110
- // ========================================================================
111
- // Structured Output
112
- // ========================================================================
113
-
114
- /**
115
- * Generate structured output from the LLM with automatic failover.
116
- * Validates the response against the provided Zod schema.
117
- * Throws StructuredOutputError on validation failure.
118
- *
119
- * @template T The output type
120
- * @param config Schema configuration (JSON Schema + optional validator)
121
- * @param messages Chat messages to send
122
- * @param options Additional options (temperature, maxTokens, etc.)
123
- * @returns Promise resolving to validated structured output
124
- * @throws StructuredOutputError if JSON parsing fails or validation fails
125
- *
126
- * @example
127
- * ```typescript
128
- * import { fromZod } from 'universal-llm-client/zod';
129
- * const UserConfig = fromZod(z.object({
130
- * name: z.string(),
131
- * age: z.number(),
132
- * }));
133
- *
134
- * const user = await model.generateStructured(UserConfig, [
135
- * { role: 'user', content: 'Generate a user profile' },
136
- * ]);
137
- * // user.name: string, user.age: number
138
- * ```
139
- */
140
- async generateStructured<T>(
141
- config: SchemaConfig<T>,
142
- messages: LLMChatMessage[],
143
- options?: ChatOptions,
144
- ): Promise<T> {
145
- return this.router.generateStructured(config, messages, options);
146
- }
147
-
148
- /**
149
- * Try to generate structured output, returning a result object instead of throwing.
150
- * Same as generateStructured but returns { ok: true, value } on success
151
- * and { ok: false, error, rawOutput } on failure.
152
- *
153
- * @template T The output type
154
- * @param config Schema configuration (JSON Schema + optional validator)
155
- * @param messages Chat messages to send
156
- * @param options Additional options (temperature, maxTokens, etc.)
157
- * @returns StructuredOutputResult<T> - either success with value or failure with error
158
- *
159
- * @example
160
- * ```typescript
161
- * const result = await model.tryParseStructured(config, messages);
162
- *
163
- * if (result.ok) {
164
- * console.log('User:', result.value.name);
165
- * } else {
166
- * console.log('Error:', result.error.message);
167
- * console.log('Raw output:', result.rawOutput);
168
- * }
169
- * ```
170
- */
171
- async tryParseStructured<T>(
172
- config: SchemaConfig<T>,
173
- messages: LLMChatMessage[],
174
- options?: ChatOptions,
175
- ): Promise<StructuredOutputResult<T>> {
176
- return this.router.tryParseStructured(config, messages, options);
177
- }
178
-
179
- /**
180
- * Stream structured output with partial validated objects.
181
- *
182
- * Yields partial validated objects as JSON generates, then returns the
183
- * complete validated object on stream completion.
184
- *
185
- * For invalid partial JSON, no yield occurs (partial validation is best-effort).
186
- * On stream completion, if the final JSON fails validation, throws StructuredOutputError.
187
- *
188
- * @template T The output type
189
- * @param config Schema configuration (JSON Schema + optional validator)
190
- * @param messages Chat messages to send
191
- * @param options Additional options (temperature, maxTokens, etc.)
192
- * @yields Partial validated objects as the JSON stream progresses
193
- * @returns Complete validated object on stream completion
194
- * @throws StructuredOutputError if final validation fails
195
- *
196
- * @example
197
- * ```typescript
198
- * import { fromZod } from 'universal-llm-client/zod';
199
- * const UserConfig = fromZod(z.object({
200
- * name: z.string(),
201
- * age: z.number(),
202
- * }));
203
- *
204
- * const stream = model.generateStructuredStream(UserConfig, [
205
- * { role: 'user', content: 'Generate a user' },
206
- * ]);
207
- *
208
- * for await (const partial of stream) {
209
- * console.log('Partial user:', partial);
210
- * }
211
- * ```
212
- */
213
- async *generateStructuredStream<T>(
214
- config: SchemaConfig<T>,
215
- messages: LLMChatMessage[],
216
- options?: ChatOptions,
217
- ): AsyncGenerator<T, T, unknown> {
218
- return yield* this.router.generateStructuredStream(config, messages, options);
219
- }
220
-
221
- // ========================================================================
222
- // Embeddings
223
- // ========================================================================
224
-
225
- /** Generate embedding for a single text */
226
- async embed(text: string): Promise<number[]> {
227
- return this.router.embed(text);
228
- }
229
-
230
- /** Generate embeddings for multiple texts */
231
- async embedArray(texts: string[]): Promise<number[][]> {
232
- return this.router.embedArray(texts);
233
- }
234
-
235
- // ========================================================================
236
- // Tool Registration
237
- // ========================================================================
238
-
239
- /** Register a tool callable by the LLM (broadcast to all providers) */
240
- registerTool(
241
- name: string,
242
- description: string,
243
- parameters: LLMFunction['parameters'],
244
- handler: ToolHandler,
245
- ): void {
246
- this.router.registerTool(name, description, parameters, handler);
247
- }
248
-
249
- /** Register multiple tools at once */
250
- registerTools(
251
- tools: Array<{
252
- name: string;
253
- description: string;
254
- parameters: LLMFunction['parameters'];
255
- handler: ToolHandler;
256
- }>,
257
- ): void {
258
- this.router.registerTools(tools);
259
- }
260
-
261
- // ========================================================================
262
- // Model Management
263
- // ========================================================================
264
-
265
- /** Get available models from all configured providers */
266
- async getModels(): Promise<string[]> {
267
- return this.router.getModels();
268
- }
269
-
270
- /** Get metadata about the current model (context length, capabilities) */
271
- async getModelInfo(): Promise<ModelMetadata> {
272
- return this.router.getModelInfo();
273
- }
274
-
275
- /** Switch model at runtime (updates all providers) */
276
- setModel(name: string): void {
277
- this.config.model = name;
278
- // The model name change will be picked up by the providers
279
- // through the router on next request
280
- }
281
-
282
- /** Get the current model name */
283
- get model(): string {
284
- return this.config.model;
285
- }
286
-
287
- // ========================================================================
288
- // Provider Status
289
- // ========================================================================
290
-
291
- /** Get health/status of all configured providers */
292
- getProviderStatus(): ProviderStatus[] {
293
- return this.router.getStatus();
294
- }
295
-
296
- // ========================================================================
297
- // Lifecycle
298
- // ========================================================================
299
-
300
- /** Clean shutdown — flush auditor, disconnect MCP, etc. */
301
- async dispose(): Promise<void> {
302
- await this.auditor.flush?.();
303
- }
304
-
305
- // ========================================================================
306
- // Internal: Provider Factory
307
- // ========================================================================
308
-
309
- private createClient(providerConfig: ProviderConfig): BaseLLMClient {
310
- const type = this.normalizeType(providerConfig.type);
311
- const modelName = providerConfig.model ?? this.config.model;
312
-
313
- const clientOptions: LLMClientOptions = {
314
- model: modelName,
315
- url: providerConfig.url ?? DEFAULT_URLS[type] ?? '',
316
- apiType: type as AIModelApiType,
317
- apiKey: providerConfig.apiKey,
318
- timeout: this.config.timeout ?? 30000,
319
- retries: this.config.retries ?? 2,
320
- debug: this.config.debug ?? false,
321
- defaultParameters: this.config.defaultParameters,
322
- thinking: this.config.thinking ?? false,
323
- region: providerConfig.region,
324
- apiVersion: providerConfig.apiVersion,
325
- };
326
-
327
- switch (type) {
328
- case 'ollama':
329
- return new OllamaClient(clientOptions, this.auditor);
330
-
331
- case 'openai':
332
- case 'llamacpp':
333
- return new OpenAICompatibleClient(clientOptions, this.auditor);
334
-
335
- case 'google':
336
- case 'vertex':
337
- return new GoogleClient(clientOptions, this.auditor);
338
-
339
- case 'anthropic':
340
- return new AnthropicClient(clientOptions, this.auditor);
341
-
342
- default:
343
- throw new Error(`Unknown provider type: ${type}`);
344
- }
345
- }
346
-
347
- private normalizeType(type: string): string {
348
- return type.toLowerCase();
349
- }
350
- }