@contentgrowth/llm-service 1.3.3 → 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.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: any;
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: any;
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: any;
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: any;
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: any;
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: any;
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: any;
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: any;
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: MODEL_CONFIGS[tenantConfig.provider],
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.5-instant",
165
- edge: "gpt-5.5-thinking",
166
- fast: "gpt-5.5-instant",
167
- cost: "gpt-5.5-instant",
168
- free: "gpt-5.5-instant"
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.5-flash",
172
- edge: "gemini-3.5-pro",
173
- fast: "gemini-3.5-flash",
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.5-pro-image-preview"
197
+ image: "gemini-3-pro-image"
178
198
  },
199
+ // Vertex AI / Gemini Enterprise Agent Platform
179
200
  vertex: {
180
- default: "gemini-3.5-flash",
181
- edge: "gemini-3.5-pro",
182
- fast: "gemini-3.5-flash",
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.5-pro-image-preview"
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-4.6-sonnet",
190
- edge: "claude-4.8-opus",
191
- fast: "claude-4.5-haiku",
192
- cost: "claude-4.5-haiku",
193
- free: "claude-4.5-haiku"
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 = config.models.default;
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 tier = options.tier || "default";
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.defaultModel,
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 = config.models.default;
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,
@@ -989,7 +1057,7 @@ ${msg.content}`;
989
1057
  }
990
1058
  async imageGeneration(prompt, systemPrompt, options = {}) {
991
1059
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
992
- const modelName = options.model || this.models.image || "gemini-3-pro-image-preview";
1060
+ const modelName = normalizeModelId(options.model) || this.models.image || "gemini-3-pro-image";
993
1061
  console.log(`[${this.constructor.name}] Generating image with model: ${modelName}`);
994
1062
  const hasReferenceImages = options.images && options.images.length > 0;
995
1063
  const generationConfig = {
@@ -1238,11 +1306,13 @@ ${prompt}` : prompt;
1238
1306
 
1239
1307
  // src/llm/providers/anthropic-provider.js
1240
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;
1241
1311
  var AnthropicProvider = class extends BaseLLMProvider {
1242
1312
  constructor(config) {
1243
1313
  super(config);
1244
- this.models = config.models || {};
1245
- this.defaultModel = this.models.default || "claude-3-5-sonnet-20241022";
1314
+ this.models = normalizeModelMap(config.models || {});
1315
+ this.defaultModel = this.models.default || "claude-sonnet-5-5";
1246
1316
  const clientOptions = { apiKey: config.apiKey || "" };
1247
1317
  if (config.baseURL) {
1248
1318
  clientOptions.baseURL = config.baseURL;
@@ -1252,8 +1322,7 @@ var AnthropicProvider = class extends BaseLLMProvider {
1252
1322
  async chat(userMessage, systemPrompt = "", options = {}) {
1253
1323
  var _a;
1254
1324
  const messages = [{ role: "user", content: userMessage }];
1255
- const tier = options.tier || "default";
1256
- const effectiveModel = this._getModelForTier(tier);
1325
+ const effectiveModel = this._resolveModel(options);
1257
1326
  const effectiveMaxTokens = options.maxTokens || this.config.maxTokens || 4096;
1258
1327
  const effectiveTemperature = options.temperature !== void 0 ? options.temperature : (_a = this.config.temperature) != null ? _a : 0.7;
1259
1328
  const response = await this._chatCompletionWithModel(
@@ -1269,8 +1338,7 @@ var AnthropicProvider = class extends BaseLLMProvider {
1269
1338
  }
1270
1339
  async chatCompletion(messages, systemPrompt, tools = null, options = {}) {
1271
1340
  var _a;
1272
- const tier = options.tier || "default";
1273
- const effectiveModel = this._getModelForTier(tier);
1341
+ const effectiveModel = this._resolveModel(options);
1274
1342
  const effectiveMaxTokens = options.maxTokens || this.config.maxTokens || 4096;
1275
1343
  const effectiveTemperature = options.temperature !== void 0 ? options.temperature : (_a = this.config.temperature) != null ? _a : 0.7;
1276
1344
  return this._chatCompletionWithModel(
@@ -1284,7 +1352,7 @@ var AnthropicProvider = class extends BaseLLMProvider {
1284
1352
  );
1285
1353
  }
1286
1354
  async _chatCompletionWithModel(messages, systemPrompt, tools, modelName, maxTokens, temperature, options = {}) {
1287
- var _a, _b, _c, _d;
1355
+ var _a, _b, _c, _d, _e;
1288
1356
  let effectiveSystem = systemPrompt || void 0;
1289
1357
  if (options.responseFormat) {
1290
1358
  const formatType = typeof options.responseFormat === "string" ? options.responseFormat : options.responseFormat.type;
@@ -1304,14 +1372,18 @@ ${jsonPrompt}` : jsonPrompt;
1304
1372
  const requestParams = {
1305
1373
  model: modelName,
1306
1374
  max_tokens: maxTokens,
1307
- temperature,
1308
1375
  messages: anthropicMessages,
1309
1376
  ...effectiveSystem ? { system: effectiveSystem } : {},
1310
1377
  ...anthropicTools ? { tools: anthropicTools } : {}
1311
1378
  };
1379
+ if (this._supportsSamplingParams(modelName) && temperature !== void 0 && temperature !== null) {
1380
+ requestParams.temperature = temperature;
1381
+ }
1312
1382
  let response;
1313
1383
  try {
1314
- 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
+ });
1315
1387
  } catch (error) {
1316
1388
  console.error(`[AnthropicProvider] request failed (API Key: ${this._getMaskedApiKey()}):`, error);
1317
1389
  throw error;
@@ -1344,9 +1416,9 @@ ${jsonPrompt}` : jsonPrompt;
1344
1416
  _rawFinishReason: rawFinishReason,
1345
1417
  _responseFormat: options.responseFormat,
1346
1418
  usage: {
1347
- prompt_tokens: ((_a = response.usage) == null ? void 0 : _a.input_tokens) || 0,
1348
- completion_tokens: ((_b = response.usage) == null ? void 0 : _b.output_tokens) || 0,
1349
- total_tokens: (((_c = response.usage) == null ? void 0 : _c.input_tokens) || 0) + (((_d = response.usage) == null ? void 0 : _d.output_tokens) || 0)
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)
1350
1422
  },
1351
1423
  model: modelName
1352
1424
  };
@@ -1460,6 +1532,15 @@ ${jsonPrompt}` : jsonPrompt;
1460
1532
  _getModelForTier(tier) {
1461
1533
  return this.models[tier] || this.defaultModel;
1462
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
+ }
1463
1544
  _shouldAutoParse(options) {
1464
1545
  if (!options.responseFormat) return false;
1465
1546
  const formatType = typeof options.responseFormat === "string" ? options.responseFormat : options.responseFormat.type;
@@ -1566,7 +1647,7 @@ var LLMService = class {
1566
1647
  return { tools: param1, options: param2 || {} };
1567
1648
  }
1568
1649
  if (typeof param1 === "object") {
1569
- const optionsKeys = ["responseFormat", "responseSchema", "temperature", "maxTokens", "tier", "autoParse", "strictSchema", "schemaName"];
1650
+ const optionsKeys = ["responseFormat", "responseSchema", "temperature", "maxTokens", "tier", "model", "reasoningEffort", "autoParse", "strictSchema", "schemaName"];
1570
1651
  const hasOptionsKeys = optionsKeys.some((key) => key in param1);
1571
1652
  if (hasOptionsKeys) {
1572
1653
  return { tools: null, options: param1 };
@@ -2095,6 +2176,7 @@ export {
2095
2176
  FINISH_REASONS,
2096
2177
  GoogleProvider as GeminiProvider,
2097
2178
  GoogleProvider,
2179
+ LEGACY_MODEL_ALIASES,
2098
2180
  LLMService,
2099
2181
  LLMServiceException,
2100
2182
  MODEL_CONFIGS,
@@ -2106,6 +2188,7 @@ export {
2106
2188
  extractJsonFromResponse,
2107
2189
  extractTextAndJson,
2108
2190
  handleApiError,
2191
+ normalizeModelId,
2109
2192
  sanitizeError
2110
2193
  };
2111
2194
  //# sourceMappingURL=index.js.map