@contentgrowth/llm-service 1.3.2 → 1.3.4
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.
- package/dist/index.cjs +143 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -5
- package/dist/index.d.ts +45 -5
- package/dist/index.js +141 -50
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -110,7 +110,7 @@ declare class BaseLLMProvider {
|
|
|
110
110
|
|
|
111
111
|
declare class OpenAIProvider extends BaseLLMProvider {
|
|
112
112
|
client: OpenAI;
|
|
113
|
-
models:
|
|
113
|
+
models: {};
|
|
114
114
|
defaultModel: any;
|
|
115
115
|
chat(userMessage: any, systemPrompt?: string, options?: {}): Promise<{
|
|
116
116
|
text: string;
|
|
@@ -129,6 +129,11 @@ declare class OpenAIProvider extends BaseLLMProvider {
|
|
|
129
129
|
total_tokens: number;
|
|
130
130
|
};
|
|
131
131
|
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Per-call model resolution: explicit options.model > options.tier > default
|
|
134
|
+
*/
|
|
135
|
+
_resolveModel(options?: {}): any;
|
|
136
|
+
_isReasoningModel(modelName: any): boolean;
|
|
132
137
|
_chatCompletionWithModel(messages: any, systemPrompt: any, tools: any, modelName: any, maxTokens: any, temperature: any, options?: {}): Promise<{
|
|
133
138
|
model: any;
|
|
134
139
|
parsedContent?: any;
|
|
@@ -164,7 +169,7 @@ declare class OpenAIProvider extends BaseLLMProvider {
|
|
|
164
169
|
}
|
|
165
170
|
|
|
166
171
|
declare class AnthropicProvider extends BaseLLMProvider {
|
|
167
|
-
models:
|
|
172
|
+
models: {};
|
|
168
173
|
defaultModel: any;
|
|
169
174
|
client: Anthropic;
|
|
170
175
|
chat(userMessage: any, systemPrompt?: string, options?: {}): Promise<{
|
|
@@ -232,6 +237,11 @@ declare class AnthropicProvider extends BaseLLMProvider {
|
|
|
232
237
|
_formatTools(tools: any): any;
|
|
233
238
|
executeTools(tool_calls: any, messages: any, tenantId: any, toolImplementations: any, env: any): Promise<void>;
|
|
234
239
|
_getModelForTier(tier: any): any;
|
|
240
|
+
/**
|
|
241
|
+
* Per-call model resolution: explicit options.model > options.tier > default
|
|
242
|
+
*/
|
|
243
|
+
_resolveModel(options?: {}): any;
|
|
244
|
+
_supportsSamplingParams(modelName: any): boolean;
|
|
235
245
|
_shouldAutoParse(options: any): boolean;
|
|
236
246
|
_safeJsonParse(text: any): any;
|
|
237
247
|
normalizeFinishReason(providerReason: any): string;
|
|
@@ -434,9 +444,17 @@ declare class DefaultConfigProvider extends BaseConfigProvider$1 {
|
|
|
434
444
|
location?: undefined;
|
|
435
445
|
}>;
|
|
436
446
|
_loadFromTenantDO(tenantId: any, env: any): Promise<any>;
|
|
447
|
+
/**
|
|
448
|
+
* Resolve the model map for a tenant.
|
|
449
|
+
* Precedence (highest first):
|
|
450
|
+
* 1. tenantConfig.model - single model chosen by the tenant (becomes `default`)
|
|
451
|
+
* 2. tenantConfig.models[tier] - per-tier overrides supplied by the tenant
|
|
452
|
+
* 3. MODEL_CONFIGS[provider] - library defaults
|
|
453
|
+
*/
|
|
454
|
+
_resolveTenantModels(tenantConfig: any): {};
|
|
437
455
|
_buildTenantConfig(tenantConfig: any, env: any): {
|
|
438
456
|
provider: any;
|
|
439
|
-
models:
|
|
457
|
+
models: {};
|
|
440
458
|
apiKey: any;
|
|
441
459
|
baseURL: any;
|
|
442
460
|
project: any;
|
|
@@ -467,6 +485,12 @@ declare class DefaultConfigProvider extends BaseConfigProvider$1 {
|
|
|
467
485
|
};
|
|
468
486
|
}
|
|
469
487
|
|
|
488
|
+
/**
|
|
489
|
+
* Map a known-invalid legacy model ID to a valid one. Unknown IDs pass through untouched.
|
|
490
|
+
* @param {string} model
|
|
491
|
+
* @returns {string}
|
|
492
|
+
*/
|
|
493
|
+
declare function normalizeModelId(model: string): string;
|
|
470
494
|
declare namespace MODEL_CONFIGS {
|
|
471
495
|
namespace openai {
|
|
472
496
|
let _default: string;
|
|
@@ -519,6 +543,22 @@ declare namespace MODEL_CONFIGS {
|
|
|
519
543
|
export { free_3 as free };
|
|
520
544
|
}
|
|
521
545
|
}
|
|
546
|
+
/**
|
|
547
|
+
* Invalid model IDs that earlier versions of this library shipped as defaults.
|
|
548
|
+
* Consumers persisted some of them (e.g. saved BYOK key configs), so we map them
|
|
549
|
+
* to a valid equivalent instead of letting the provider return 404.
|
|
550
|
+
*/
|
|
551
|
+
declare const LEGACY_MODEL_ALIASES: {
|
|
552
|
+
'gpt-5.5-instant': string;
|
|
553
|
+
'gpt-5.5-thinking': string;
|
|
554
|
+
'gemini-3.5-pro': string;
|
|
555
|
+
'gemini-3.7-pro': string;
|
|
556
|
+
'gemini-3.5-pro-image-preview': string;
|
|
557
|
+
'gemini-3.7-pro-image-preview': string;
|
|
558
|
+
'claude-4.5-haiku': string;
|
|
559
|
+
'claude-4.6-sonnet': string;
|
|
560
|
+
'claude-4.8-opus': string;
|
|
561
|
+
};
|
|
522
562
|
declare class ConfigManager {
|
|
523
563
|
static _provider: DefaultConfigProvider;
|
|
524
564
|
/**
|
|
@@ -556,7 +596,7 @@ declare class ConfigManager {
|
|
|
556
596
|
* - Vertex + ADC/IAM: { vertexai: true, project, location } — no apiKey
|
|
557
597
|
*/
|
|
558
598
|
declare class GoogleProvider extends BaseLLMProvider {
|
|
559
|
-
models:
|
|
599
|
+
models: {};
|
|
560
600
|
defaultModel: any;
|
|
561
601
|
_pendingOperations: Map<any, any>;
|
|
562
602
|
client: GoogleGenAI;
|
|
@@ -794,4 +834,4 @@ declare class TranscriptionServiceException extends Error {
|
|
|
794
834
|
statusCode: number;
|
|
795
835
|
}
|
|
796
836
|
|
|
797
|
-
export { AnthropicProvider, BaseConfigProvider$1 as BaseConfigProvider, ConfigManager, DefaultConfigProvider, FINISH_REASONS, GoogleProvider as GeminiProvider, GoogleProvider, LLMService, LLMServiceException, MODEL_CONFIGS, OpenAIProvider, TranscriptionService, TranscriptionServiceException, GoogleProvider as VertexProvider, createSpeechHandler, extractJsonFromResponse, extractTextAndJson, handleApiError, sanitizeError };
|
|
837
|
+
export { AnthropicProvider, BaseConfigProvider$1 as BaseConfigProvider, ConfigManager, DefaultConfigProvider, FINISH_REASONS, GoogleProvider as GeminiProvider, GoogleProvider, LEGACY_MODEL_ALIASES, LLMService, LLMServiceException, MODEL_CONFIGS, OpenAIProvider, TranscriptionService, TranscriptionServiceException, GoogleProvider as VertexProvider, createSpeechHandler, extractJsonFromResponse, extractTextAndJson, handleApiError, normalizeModelId, sanitizeError };
|
package/dist/index.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ declare class BaseLLMProvider {
|
|
|
110
110
|
|
|
111
111
|
declare class OpenAIProvider extends BaseLLMProvider {
|
|
112
112
|
client: OpenAI;
|
|
113
|
-
models:
|
|
113
|
+
models: {};
|
|
114
114
|
defaultModel: any;
|
|
115
115
|
chat(userMessage: any, systemPrompt?: string, options?: {}): Promise<{
|
|
116
116
|
text: string;
|
|
@@ -129,6 +129,11 @@ declare class OpenAIProvider extends BaseLLMProvider {
|
|
|
129
129
|
total_tokens: number;
|
|
130
130
|
};
|
|
131
131
|
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Per-call model resolution: explicit options.model > options.tier > default
|
|
134
|
+
*/
|
|
135
|
+
_resolveModel(options?: {}): any;
|
|
136
|
+
_isReasoningModel(modelName: any): boolean;
|
|
132
137
|
_chatCompletionWithModel(messages: any, systemPrompt: any, tools: any, modelName: any, maxTokens: any, temperature: any, options?: {}): Promise<{
|
|
133
138
|
model: any;
|
|
134
139
|
parsedContent?: any;
|
|
@@ -164,7 +169,7 @@ declare class OpenAIProvider extends BaseLLMProvider {
|
|
|
164
169
|
}
|
|
165
170
|
|
|
166
171
|
declare class AnthropicProvider extends BaseLLMProvider {
|
|
167
|
-
models:
|
|
172
|
+
models: {};
|
|
168
173
|
defaultModel: any;
|
|
169
174
|
client: Anthropic;
|
|
170
175
|
chat(userMessage: any, systemPrompt?: string, options?: {}): Promise<{
|
|
@@ -232,6 +237,11 @@ declare class AnthropicProvider extends BaseLLMProvider {
|
|
|
232
237
|
_formatTools(tools: any): any;
|
|
233
238
|
executeTools(tool_calls: any, messages: any, tenantId: any, toolImplementations: any, env: any): Promise<void>;
|
|
234
239
|
_getModelForTier(tier: any): any;
|
|
240
|
+
/**
|
|
241
|
+
* Per-call model resolution: explicit options.model > options.tier > default
|
|
242
|
+
*/
|
|
243
|
+
_resolveModel(options?: {}): any;
|
|
244
|
+
_supportsSamplingParams(modelName: any): boolean;
|
|
235
245
|
_shouldAutoParse(options: any): boolean;
|
|
236
246
|
_safeJsonParse(text: any): any;
|
|
237
247
|
normalizeFinishReason(providerReason: any): string;
|
|
@@ -434,9 +444,17 @@ declare class DefaultConfigProvider extends BaseConfigProvider$1 {
|
|
|
434
444
|
location?: undefined;
|
|
435
445
|
}>;
|
|
436
446
|
_loadFromTenantDO(tenantId: any, env: any): Promise<any>;
|
|
447
|
+
/**
|
|
448
|
+
* Resolve the model map for a tenant.
|
|
449
|
+
* Precedence (highest first):
|
|
450
|
+
* 1. tenantConfig.model - single model chosen by the tenant (becomes `default`)
|
|
451
|
+
* 2. tenantConfig.models[tier] - per-tier overrides supplied by the tenant
|
|
452
|
+
* 3. MODEL_CONFIGS[provider] - library defaults
|
|
453
|
+
*/
|
|
454
|
+
_resolveTenantModels(tenantConfig: any): {};
|
|
437
455
|
_buildTenantConfig(tenantConfig: any, env: any): {
|
|
438
456
|
provider: any;
|
|
439
|
-
models:
|
|
457
|
+
models: {};
|
|
440
458
|
apiKey: any;
|
|
441
459
|
baseURL: any;
|
|
442
460
|
project: any;
|
|
@@ -467,6 +485,12 @@ declare class DefaultConfigProvider extends BaseConfigProvider$1 {
|
|
|
467
485
|
};
|
|
468
486
|
}
|
|
469
487
|
|
|
488
|
+
/**
|
|
489
|
+
* Map a known-invalid legacy model ID to a valid one. Unknown IDs pass through untouched.
|
|
490
|
+
* @param {string} model
|
|
491
|
+
* @returns {string}
|
|
492
|
+
*/
|
|
493
|
+
declare function normalizeModelId(model: string): string;
|
|
470
494
|
declare namespace MODEL_CONFIGS {
|
|
471
495
|
namespace openai {
|
|
472
496
|
let _default: string;
|
|
@@ -519,6 +543,22 @@ declare namespace MODEL_CONFIGS {
|
|
|
519
543
|
export { free_3 as free };
|
|
520
544
|
}
|
|
521
545
|
}
|
|
546
|
+
/**
|
|
547
|
+
* Invalid model IDs that earlier versions of this library shipped as defaults.
|
|
548
|
+
* Consumers persisted some of them (e.g. saved BYOK key configs), so we map them
|
|
549
|
+
* to a valid equivalent instead of letting the provider return 404.
|
|
550
|
+
*/
|
|
551
|
+
declare const LEGACY_MODEL_ALIASES: {
|
|
552
|
+
'gpt-5.5-instant': string;
|
|
553
|
+
'gpt-5.5-thinking': string;
|
|
554
|
+
'gemini-3.5-pro': string;
|
|
555
|
+
'gemini-3.7-pro': string;
|
|
556
|
+
'gemini-3.5-pro-image-preview': string;
|
|
557
|
+
'gemini-3.7-pro-image-preview': string;
|
|
558
|
+
'claude-4.5-haiku': string;
|
|
559
|
+
'claude-4.6-sonnet': string;
|
|
560
|
+
'claude-4.8-opus': string;
|
|
561
|
+
};
|
|
522
562
|
declare class ConfigManager {
|
|
523
563
|
static _provider: DefaultConfigProvider;
|
|
524
564
|
/**
|
|
@@ -556,7 +596,7 @@ declare class ConfigManager {
|
|
|
556
596
|
* - Vertex + ADC/IAM: { vertexai: true, project, location } — no apiKey
|
|
557
597
|
*/
|
|
558
598
|
declare class GoogleProvider extends BaseLLMProvider {
|
|
559
|
-
models:
|
|
599
|
+
models: {};
|
|
560
600
|
defaultModel: any;
|
|
561
601
|
_pendingOperations: Map<any, any>;
|
|
562
602
|
client: GoogleGenAI;
|
|
@@ -794,4 +834,4 @@ declare class TranscriptionServiceException extends Error {
|
|
|
794
834
|
statusCode: number;
|
|
795
835
|
}
|
|
796
836
|
|
|
797
|
-
export { AnthropicProvider, BaseConfigProvider$1 as BaseConfigProvider, ConfigManager, DefaultConfigProvider, FINISH_REASONS, GoogleProvider as GeminiProvider, GoogleProvider, LLMService, LLMServiceException, MODEL_CONFIGS, OpenAIProvider, TranscriptionService, TranscriptionServiceException, GoogleProvider as VertexProvider, createSpeechHandler, extractJsonFromResponse, extractTextAndJson, handleApiError, sanitizeError };
|
|
837
|
+
export { AnthropicProvider, BaseConfigProvider$1 as BaseConfigProvider, ConfigManager, DefaultConfigProvider, FINISH_REASONS, GoogleProvider as GeminiProvider, GoogleProvider, LEGACY_MODEL_ALIASES, LLMService, LLMServiceException, MODEL_CONFIGS, OpenAIProvider, TranscriptionService, TranscriptionServiceException, GoogleProvider as VertexProvider, createSpeechHandler, extractJsonFromResponse, extractTextAndJson, handleApiError, normalizeModelId, sanitizeError };
|
package/dist/index.js
CHANGED
|
@@ -68,10 +68,27 @@ var DefaultConfigProvider = class extends BaseConfigProvider {
|
|
|
68
68
|
return null;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Resolve the model map for a tenant.
|
|
73
|
+
* Precedence (highest first):
|
|
74
|
+
* 1. tenantConfig.model - single model chosen by the tenant (becomes `default`)
|
|
75
|
+
* 2. tenantConfig.models[tier] - per-tier overrides supplied by the tenant
|
|
76
|
+
* 3. MODEL_CONFIGS[provider] - library defaults
|
|
77
|
+
*/
|
|
78
|
+
_resolveTenantModels(tenantConfig) {
|
|
79
|
+
const models = {
|
|
80
|
+
...MODEL_CONFIGS[tenantConfig.provider] || {},
|
|
81
|
+
...tenantConfig.models || {}
|
|
82
|
+
};
|
|
83
|
+
if (typeof tenantConfig.model === "string" && tenantConfig.model.trim()) {
|
|
84
|
+
models.default = tenantConfig.model;
|
|
85
|
+
}
|
|
86
|
+
return normalizeModelMap(models);
|
|
87
|
+
}
|
|
71
88
|
_buildTenantConfig(tenantConfig, env) {
|
|
72
89
|
return {
|
|
73
90
|
provider: tenantConfig.provider,
|
|
74
|
-
models:
|
|
91
|
+
models: this._resolveTenantModels(tenantConfig),
|
|
75
92
|
// for backward compatibility, api_key is deprecated and shall never be used!!
|
|
76
93
|
apiKey: tenantConfig.apiKey || tenantConfig.api_key,
|
|
77
94
|
baseURL: tenantConfig.baseURL || tenantConfig.base_url || void 0,
|
|
@@ -160,39 +177,70 @@ var DefaultConfigProvider = class extends BaseConfigProvider {
|
|
|
160
177
|
|
|
161
178
|
// src/llm/config-manager.js
|
|
162
179
|
var MODEL_CONFIGS = {
|
|
180
|
+
// NOTE: these must be OpenAI *API* model IDs. ChatGPT product names such as
|
|
181
|
+
// "GPT-5.5 Instant" / "GPT-5.5 Thinking" are not valid API models and return 404.
|
|
163
182
|
openai: {
|
|
164
|
-
default: "gpt-5.
|
|
165
|
-
edge: "gpt-5.
|
|
166
|
-
fast: "gpt-5.
|
|
167
|
-
cost: "gpt-5.
|
|
168
|
-
free: "gpt-5.
|
|
183
|
+
default: "gpt-5.6-luna",
|
|
184
|
+
edge: "gpt-5.6-sol",
|
|
185
|
+
fast: "gpt-5.6-luna",
|
|
186
|
+
cost: "gpt-5.6-luna",
|
|
187
|
+
free: "gpt-5.6-luna"
|
|
169
188
|
},
|
|
189
|
+
// Gemini Developer API (ai.google.dev). There is no "gemini-3.5-pro"; the Pro tier is gemini-3.1-pro-preview.
|
|
170
190
|
gemini: {
|
|
171
|
-
default: "gemini-3.
|
|
172
|
-
edge: "gemini-3.
|
|
173
|
-
fast: "gemini-3.
|
|
174
|
-
cost: "gemini-3.5-flash",
|
|
175
|
-
free: "gemini-3.5-flash",
|
|
191
|
+
default: "gemini-3.8-flash",
|
|
192
|
+
edge: "gemini-3.1-pro-preview",
|
|
193
|
+
fast: "gemini-3.8-flash",
|
|
194
|
+
cost: "gemini-3.5-flash-lite",
|
|
195
|
+
free: "gemini-3.5-flash-lite",
|
|
176
196
|
video: "veo",
|
|
177
|
-
image: "gemini-3
|
|
197
|
+
image: "gemini-3-pro-image"
|
|
178
198
|
},
|
|
199
|
+
// Vertex AI / Gemini Enterprise Agent Platform
|
|
179
200
|
vertex: {
|
|
180
|
-
default: "gemini-3.
|
|
181
|
-
edge: "gemini-3.
|
|
182
|
-
fast: "gemini-3.
|
|
183
|
-
cost: "gemini-3.5-flash",
|
|
184
|
-
free: "gemini-3.5-flash",
|
|
201
|
+
default: "gemini-3.7-flash",
|
|
202
|
+
edge: "gemini-3.1-pro-preview",
|
|
203
|
+
fast: "gemini-3.7-flash",
|
|
204
|
+
cost: "gemini-3.5-flash-lite",
|
|
205
|
+
free: "gemini-3.5-flash-lite",
|
|
185
206
|
video: "veo",
|
|
186
|
-
image: "gemini-3.
|
|
207
|
+
image: "gemini-3.1-flash-image"
|
|
187
208
|
},
|
|
209
|
+
// Anthropic IDs are "claude-<family>-<major>-<minor>", e.g. claude-sonnet-5-5 (not claude-5.5-sonnet).
|
|
188
210
|
anthropic: {
|
|
189
|
-
default: "claude-
|
|
190
|
-
edge: "claude-
|
|
191
|
-
fast: "claude-
|
|
192
|
-
cost: "claude-
|
|
193
|
-
free: "claude-
|
|
211
|
+
default: "claude-sonnet-5-5",
|
|
212
|
+
edge: "claude-opus-5-5",
|
|
213
|
+
fast: "claude-haiku-5-5",
|
|
214
|
+
cost: "claude-haiku-5-5",
|
|
215
|
+
free: "claude-haiku-5-5"
|
|
194
216
|
}
|
|
195
217
|
};
|
|
218
|
+
var LEGACY_MODEL_ALIASES = {
|
|
219
|
+
// OpenAI: ChatGPT product names, not API model IDs
|
|
220
|
+
"gpt-5.5-instant": "gpt-5.6-luna",
|
|
221
|
+
"gpt-5.5-thinking": "gpt-5.6-sol",
|
|
222
|
+
// Gemini: never existed
|
|
223
|
+
"gemini-3.5-pro": "gemini-3.1-pro-preview",
|
|
224
|
+
"gemini-3.7-pro": "gemini-3.1-pro-preview",
|
|
225
|
+
"gemini-3.5-pro-image-preview": "gemini-3-pro-image",
|
|
226
|
+
"gemini-3.7-pro-image-preview": "gemini-3-pro-image",
|
|
227
|
+
// Anthropic: wrong segment order
|
|
228
|
+
"claude-4.5-haiku": "claude-haiku-4-5",
|
|
229
|
+
"claude-4.6-sonnet": "claude-sonnet-4-6",
|
|
230
|
+
"claude-4.8-opus": "claude-opus-4-8"
|
|
231
|
+
};
|
|
232
|
+
function normalizeModelId(model) {
|
|
233
|
+
if (typeof model !== "string") return model;
|
|
234
|
+
const trimmed = model.trim();
|
|
235
|
+
return LEGACY_MODEL_ALIASES[trimmed] || trimmed;
|
|
236
|
+
}
|
|
237
|
+
function normalizeModelMap(models = {}) {
|
|
238
|
+
const out = {};
|
|
239
|
+
for (const [tier, id] of Object.entries(models)) {
|
|
240
|
+
out[tier] = normalizeModelId(id);
|
|
241
|
+
}
|
|
242
|
+
return out;
|
|
243
|
+
}
|
|
196
244
|
var ConfigManager = class {
|
|
197
245
|
/**
|
|
198
246
|
* Set a custom configuration provider.
|
|
@@ -420,6 +468,7 @@ function extractTextAndJson(input) {
|
|
|
420
468
|
}
|
|
421
469
|
|
|
422
470
|
// src/llm/providers/openai-provider.js
|
|
471
|
+
var REASONING_MODEL_PATTERN = /^(o\d|gpt-5|gpt-6)/i;
|
|
423
472
|
var OpenAIProvider = class extends BaseLLMProvider {
|
|
424
473
|
constructor(config) {
|
|
425
474
|
super(config);
|
|
@@ -428,13 +477,12 @@ var OpenAIProvider = class extends BaseLLMProvider {
|
|
|
428
477
|
clientOptions.baseURL = config.baseURL;
|
|
429
478
|
}
|
|
430
479
|
this.client = new OpenAI(clientOptions);
|
|
431
|
-
this.models = config.models;
|
|
432
|
-
this.defaultModel =
|
|
480
|
+
this.models = normalizeModelMap(config.models);
|
|
481
|
+
this.defaultModel = this.models.default;
|
|
433
482
|
}
|
|
434
483
|
async chat(userMessage, systemPrompt = "", options = {}) {
|
|
435
484
|
const messages = [{ role: "user", content: userMessage }];
|
|
436
|
-
const
|
|
437
|
-
const effectiveModel = this._getModelForTier(tier);
|
|
485
|
+
const effectiveModel = this._resolveModel(options);
|
|
438
486
|
const effectiveMaxTokens = options.maxTokens || this.config.maxTokens;
|
|
439
487
|
const effectiveTemperature = options.temperature !== void 0 ? options.temperature : this.config.temperature;
|
|
440
488
|
const response = await this._chatCompletionWithModel(
|
|
@@ -452,22 +500,42 @@ var OpenAIProvider = class extends BaseLLMProvider {
|
|
|
452
500
|
messages,
|
|
453
501
|
systemPrompt,
|
|
454
502
|
tools,
|
|
455
|
-
this.
|
|
503
|
+
this._resolveModel(options),
|
|
456
504
|
this.config.maxTokens,
|
|
457
505
|
this.config.temperature,
|
|
458
506
|
options
|
|
459
507
|
);
|
|
460
508
|
}
|
|
509
|
+
/**
|
|
510
|
+
* Per-call model resolution: explicit options.model > options.tier > default
|
|
511
|
+
*/
|
|
512
|
+
_resolveModel(options = {}) {
|
|
513
|
+
return normalizeModelId(options.model) || this._getModelForTier(options.tier || "default");
|
|
514
|
+
}
|
|
515
|
+
_isReasoningModel(modelName) {
|
|
516
|
+
return REASONING_MODEL_PATTERN.test(modelName || "");
|
|
517
|
+
}
|
|
461
518
|
async _chatCompletionWithModel(messages, systemPrompt, tools, modelName, maxTokens, temperature, options = {}) {
|
|
462
519
|
var _a, _b, _c, _d, _e;
|
|
520
|
+
const effectiveMaxTokens = (_a = options.maxTokens) != null ? _a : maxTokens;
|
|
463
521
|
const requestPayload = {
|
|
464
522
|
model: modelName,
|
|
465
|
-
temperature: (_a = options.temperature) != null ? _a : temperature,
|
|
466
|
-
max_tokens: (_b = options.maxTokens) != null ? _b : maxTokens,
|
|
467
523
|
messages: [{ role: "system", content: systemPrompt }, ...messages],
|
|
468
524
|
tools,
|
|
469
525
|
tool_choice: tools ? "auto" : void 0
|
|
470
526
|
};
|
|
527
|
+
if (this._isReasoningModel(modelName)) {
|
|
528
|
+
requestPayload.max_completion_tokens = effectiveMaxTokens;
|
|
529
|
+
if (options.reasoningEffort) {
|
|
530
|
+
requestPayload.reasoning_effort = options.reasoningEffort;
|
|
531
|
+
}
|
|
532
|
+
if (options.reasoningEffort === "none" && options.temperature !== void 0) {
|
|
533
|
+
requestPayload.temperature = options.temperature;
|
|
534
|
+
}
|
|
535
|
+
} else {
|
|
536
|
+
requestPayload.max_tokens = effectiveMaxTokens;
|
|
537
|
+
requestPayload.temperature = (_b = options.temperature) != null ? _b : temperature;
|
|
538
|
+
}
|
|
471
539
|
if (options.responseFormat) {
|
|
472
540
|
requestPayload.response_format = this._buildResponseFormat(options);
|
|
473
541
|
}
|
|
@@ -606,8 +674,8 @@ import { GoogleGenAI } from "@google/genai";
|
|
|
606
674
|
var GoogleProvider = class extends BaseLLMProvider {
|
|
607
675
|
constructor(config) {
|
|
608
676
|
super(config);
|
|
609
|
-
this.models = config.models;
|
|
610
|
-
this.defaultModel =
|
|
677
|
+
this.models = normalizeModelMap(config.models);
|
|
678
|
+
this.defaultModel = this.models.default;
|
|
611
679
|
this._pendingOperations = /* @__PURE__ */ new Map();
|
|
612
680
|
const httpOptions = config.baseURL ? { baseUrl: config.baseURL } : void 0;
|
|
613
681
|
if (config.provider === "vertex") {
|
|
@@ -646,7 +714,7 @@ var GoogleProvider = class extends BaseLLMProvider {
|
|
|
646
714
|
async chat(userMessage, systemPrompt = "", options = {}) {
|
|
647
715
|
const messages = [{ role: "user", content: userMessage }];
|
|
648
716
|
const tier = options.tier || "default";
|
|
649
|
-
const effectiveModel = this._getModelForTier(tier);
|
|
717
|
+
const effectiveModel = normalizeModelId(options.model) || this._getModelForTier(tier);
|
|
650
718
|
const effectiveMaxTokens = options.maxTokens || this.config.maxTokens;
|
|
651
719
|
const effectiveTemperature = options.temperature !== void 0 ? options.temperature : this.config.temperature;
|
|
652
720
|
const response = await this._chatCompletionWithModel(
|
|
@@ -661,7 +729,7 @@ var GoogleProvider = class extends BaseLLMProvider {
|
|
|
661
729
|
}
|
|
662
730
|
async chatCompletion(messages, systemPrompt, tools = null, options = {}) {
|
|
663
731
|
const tier = options.tier || "default";
|
|
664
|
-
const modelName = this.models[tier] || this.defaultModel;
|
|
732
|
+
const modelName = normalizeModelId(options.model) || this.models[tier] || this.defaultModel;
|
|
665
733
|
return this._chatCompletionWithModel(
|
|
666
734
|
messages,
|
|
667
735
|
systemPrompt,
|
|
@@ -961,13 +1029,21 @@ ${msg.content}`;
|
|
|
961
1029
|
const tool = toolImplementations[toolName];
|
|
962
1030
|
const tool_call_id = `gemini-tool-call-${index}`;
|
|
963
1031
|
toolCall.id = tool_call_id;
|
|
964
|
-
|
|
1032
|
+
let toolArgs = toolCall.function.args;
|
|
1033
|
+
if (toolArgs === void 0 && toolCall.function.arguments) {
|
|
1034
|
+
try {
|
|
1035
|
+
toolArgs = typeof toolCall.function.arguments === "string" ? JSON.parse(toolCall.function.arguments) : toolCall.function.arguments;
|
|
1036
|
+
} catch (e) {
|
|
1037
|
+
toolArgs = {};
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
console.log(`[Tool Call] > ${toolName}:`, JSON.stringify(toolArgs));
|
|
965
1041
|
if (!tool) {
|
|
966
1042
|
console.error(`[Tool Error] Tool '${toolName}' not found`);
|
|
967
1043
|
return { tool_call_id, output: JSON.stringify({ error: `Tool '${toolName}' not found.` }) };
|
|
968
1044
|
}
|
|
969
1045
|
try {
|
|
970
|
-
const output = await tool(
|
|
1046
|
+
const output = await tool(toolArgs, { env, tenantId });
|
|
971
1047
|
const preview = typeof output === "string" ? output.length > 200 ? output.substring(0, 200) + "..." : output : JSON.stringify(output).substring(0, 200) + "...";
|
|
972
1048
|
console.log(`[Tool Result] < ${toolName}: ${preview}`);
|
|
973
1049
|
return { tool_call_id, output };
|
|
@@ -981,7 +1057,7 @@ ${msg.content}`;
|
|
|
981
1057
|
}
|
|
982
1058
|
async imageGeneration(prompt, systemPrompt, options = {}) {
|
|
983
1059
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
984
|
-
const modelName = options.model || this.models.image || "gemini-3-pro-image
|
|
1060
|
+
const modelName = normalizeModelId(options.model) || this.models.image || "gemini-3-pro-image";
|
|
985
1061
|
console.log(`[${this.constructor.name}] Generating image with model: ${modelName}`);
|
|
986
1062
|
const hasReferenceImages = options.images && options.images.length > 0;
|
|
987
1063
|
const generationConfig = {
|
|
@@ -1230,11 +1306,13 @@ ${prompt}` : prompt;
|
|
|
1230
1306
|
|
|
1231
1307
|
// src/llm/providers/anthropic-provider.js
|
|
1232
1308
|
import Anthropic from "@anthropic-ai/sdk";
|
|
1309
|
+
var SAMPLING_PARAMS_MODEL_PATTERN = /^claude-(3[-.]|(opus|sonnet|haiku)-4(-[0-6])?([-@]\d{8})?$)/i;
|
|
1310
|
+
var NON_STREAMING_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
1233
1311
|
var AnthropicProvider = class extends BaseLLMProvider {
|
|
1234
1312
|
constructor(config) {
|
|
1235
1313
|
super(config);
|
|
1236
|
-
this.models = config.models || {};
|
|
1237
|
-
this.defaultModel = this.models.default || "claude-
|
|
1314
|
+
this.models = normalizeModelMap(config.models || {});
|
|
1315
|
+
this.defaultModel = this.models.default || "claude-sonnet-5-5";
|
|
1238
1316
|
const clientOptions = { apiKey: config.apiKey || "" };
|
|
1239
1317
|
if (config.baseURL) {
|
|
1240
1318
|
clientOptions.baseURL = config.baseURL;
|
|
@@ -1244,8 +1322,7 @@ var AnthropicProvider = class extends BaseLLMProvider {
|
|
|
1244
1322
|
async chat(userMessage, systemPrompt = "", options = {}) {
|
|
1245
1323
|
var _a;
|
|
1246
1324
|
const messages = [{ role: "user", content: userMessage }];
|
|
1247
|
-
const
|
|
1248
|
-
const effectiveModel = this._getModelForTier(tier);
|
|
1325
|
+
const effectiveModel = this._resolveModel(options);
|
|
1249
1326
|
const effectiveMaxTokens = options.maxTokens || this.config.maxTokens || 4096;
|
|
1250
1327
|
const effectiveTemperature = options.temperature !== void 0 ? options.temperature : (_a = this.config.temperature) != null ? _a : 0.7;
|
|
1251
1328
|
const response = await this._chatCompletionWithModel(
|
|
@@ -1261,8 +1338,7 @@ var AnthropicProvider = class extends BaseLLMProvider {
|
|
|
1261
1338
|
}
|
|
1262
1339
|
async chatCompletion(messages, systemPrompt, tools = null, options = {}) {
|
|
1263
1340
|
var _a;
|
|
1264
|
-
const
|
|
1265
|
-
const effectiveModel = this._getModelForTier(tier);
|
|
1341
|
+
const effectiveModel = this._resolveModel(options);
|
|
1266
1342
|
const effectiveMaxTokens = options.maxTokens || this.config.maxTokens || 4096;
|
|
1267
1343
|
const effectiveTemperature = options.temperature !== void 0 ? options.temperature : (_a = this.config.temperature) != null ? _a : 0.7;
|
|
1268
1344
|
return this._chatCompletionWithModel(
|
|
@@ -1276,7 +1352,7 @@ var AnthropicProvider = class extends BaseLLMProvider {
|
|
|
1276
1352
|
);
|
|
1277
1353
|
}
|
|
1278
1354
|
async _chatCompletionWithModel(messages, systemPrompt, tools, modelName, maxTokens, temperature, options = {}) {
|
|
1279
|
-
var _a, _b, _c, _d;
|
|
1355
|
+
var _a, _b, _c, _d, _e;
|
|
1280
1356
|
let effectiveSystem = systemPrompt || void 0;
|
|
1281
1357
|
if (options.responseFormat) {
|
|
1282
1358
|
const formatType = typeof options.responseFormat === "string" ? options.responseFormat : options.responseFormat.type;
|
|
@@ -1296,14 +1372,18 @@ ${jsonPrompt}` : jsonPrompt;
|
|
|
1296
1372
|
const requestParams = {
|
|
1297
1373
|
model: modelName,
|
|
1298
1374
|
max_tokens: maxTokens,
|
|
1299
|
-
temperature,
|
|
1300
1375
|
messages: anthropicMessages,
|
|
1301
1376
|
...effectiveSystem ? { system: effectiveSystem } : {},
|
|
1302
1377
|
...anthropicTools ? { tools: anthropicTools } : {}
|
|
1303
1378
|
};
|
|
1379
|
+
if (this._supportsSamplingParams(modelName) && temperature !== void 0 && temperature !== null) {
|
|
1380
|
+
requestParams.temperature = temperature;
|
|
1381
|
+
}
|
|
1304
1382
|
let response;
|
|
1305
1383
|
try {
|
|
1306
|
-
response = await this.client.messages.create(requestParams
|
|
1384
|
+
response = await this.client.messages.create(requestParams, {
|
|
1385
|
+
timeout: (_a = this.config.timeout) != null ? _a : NON_STREAMING_TIMEOUT_MS
|
|
1386
|
+
});
|
|
1307
1387
|
} catch (error) {
|
|
1308
1388
|
console.error(`[AnthropicProvider] request failed (API Key: ${this._getMaskedApiKey()}):`, error);
|
|
1309
1389
|
throw error;
|
|
@@ -1336,9 +1416,9 @@ ${jsonPrompt}` : jsonPrompt;
|
|
|
1336
1416
|
_rawFinishReason: rawFinishReason,
|
|
1337
1417
|
_responseFormat: options.responseFormat,
|
|
1338
1418
|
usage: {
|
|
1339
|
-
prompt_tokens: ((
|
|
1340
|
-
completion_tokens: ((
|
|
1341
|
-
total_tokens: (((
|
|
1419
|
+
prompt_tokens: ((_b = response.usage) == null ? void 0 : _b.input_tokens) || 0,
|
|
1420
|
+
completion_tokens: ((_c = response.usage) == null ? void 0 : _c.output_tokens) || 0,
|
|
1421
|
+
total_tokens: (((_d = response.usage) == null ? void 0 : _d.input_tokens) || 0) + (((_e = response.usage) == null ? void 0 : _e.output_tokens) || 0)
|
|
1342
1422
|
},
|
|
1343
1423
|
model: modelName
|
|
1344
1424
|
};
|
|
@@ -1452,6 +1532,15 @@ ${jsonPrompt}` : jsonPrompt;
|
|
|
1452
1532
|
_getModelForTier(tier) {
|
|
1453
1533
|
return this.models[tier] || this.defaultModel;
|
|
1454
1534
|
}
|
|
1535
|
+
/**
|
|
1536
|
+
* Per-call model resolution: explicit options.model > options.tier > default
|
|
1537
|
+
*/
|
|
1538
|
+
_resolveModel(options = {}) {
|
|
1539
|
+
return normalizeModelId(options.model) || this._getModelForTier(options.tier || "default");
|
|
1540
|
+
}
|
|
1541
|
+
_supportsSamplingParams(modelName) {
|
|
1542
|
+
return SAMPLING_PARAMS_MODEL_PATTERN.test(modelName || "");
|
|
1543
|
+
}
|
|
1455
1544
|
_shouldAutoParse(options) {
|
|
1456
1545
|
if (!options.responseFormat) return false;
|
|
1457
1546
|
const formatType = typeof options.responseFormat === "string" ? options.responseFormat : options.responseFormat.type;
|
|
@@ -1558,7 +1647,7 @@ var LLMService = class {
|
|
|
1558
1647
|
return { tools: param1, options: param2 || {} };
|
|
1559
1648
|
}
|
|
1560
1649
|
if (typeof param1 === "object") {
|
|
1561
|
-
const optionsKeys = ["responseFormat", "responseSchema", "temperature", "maxTokens", "tier", "autoParse", "strictSchema", "schemaName"];
|
|
1650
|
+
const optionsKeys = ["responseFormat", "responseSchema", "temperature", "maxTokens", "tier", "model", "reasoningEffort", "autoParse", "strictSchema", "schemaName"];
|
|
1562
1651
|
const hasOptionsKeys = optionsKeys.some((key) => key in param1);
|
|
1563
1652
|
if (hasOptionsKeys) {
|
|
1564
1653
|
return { tools: null, options: param1 };
|
|
@@ -2087,6 +2176,7 @@ export {
|
|
|
2087
2176
|
FINISH_REASONS,
|
|
2088
2177
|
GoogleProvider as GeminiProvider,
|
|
2089
2178
|
GoogleProvider,
|
|
2179
|
+
LEGACY_MODEL_ALIASES,
|
|
2090
2180
|
LLMService,
|
|
2091
2181
|
LLMServiceException,
|
|
2092
2182
|
MODEL_CONFIGS,
|
|
@@ -2098,6 +2188,7 @@ export {
|
|
|
2098
2188
|
extractJsonFromResponse,
|
|
2099
2189
|
extractTextAndJson,
|
|
2100
2190
|
handleApiError,
|
|
2191
|
+
normalizeModelId,
|
|
2101
2192
|
sanitizeError
|
|
2102
2193
|
};
|
|
2103
2194
|
//# sourceMappingURL=index.js.map
|