llm-strings 1.1.2 → 1.2.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.
- package/README.md +117 -45
- package/dist/ai-sdk.cjs +831 -0
- package/dist/ai-sdk.cjs.map +1 -0
- package/dist/ai-sdk.d.cts +27 -0
- package/dist/ai-sdk.d.ts +27 -0
- package/dist/ai-sdk.js +465 -0
- package/dist/ai-sdk.js.map +1 -0
- package/dist/{chunk-MPIHGH6L.js → chunk-2ARD4TFU.js} +5 -4
- package/dist/chunk-2ARD4TFU.js.map +1 -0
- package/dist/{chunk-FCEV23OT.js → chunk-BCOUH7LH.js} +9 -3
- package/dist/chunk-BCOUH7LH.js.map +1 -0
- package/dist/{chunk-UYMVUTLV.js → chunk-RPXK2A7O.js} +5 -9
- package/dist/chunk-RPXK2A7O.js.map +1 -0
- package/dist/{chunk-XID353H7.js → chunk-W4NIQY7M.js} +412 -52
- package/dist/chunk-W4NIQY7M.js.map +1 -0
- package/dist/index.cjs +443 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +9 -4
- package/dist/normalize.cjs +19 -2
- package/dist/normalize.cjs.map +1 -1
- package/dist/normalize.d.cts +1 -1
- package/dist/normalize.d.ts +2 -2
- package/dist/normalize.js +2 -2
- package/dist/parse.cjs +73 -2
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.d.cts +5 -1
- package/dist/parse.d.ts +5 -1
- package/dist/parse.js +2 -1
- package/dist/{provider-core-DinpG40u.d.cts → provider-core-BiAl8MCV.d.cts} +20 -1
- package/dist/{provider-core-DinpG40u.d.ts → provider-core-BiAl8MCV.d.ts} +20 -1
- package/dist/providers.cjs +786 -110
- package/dist/providers.cjs.map +1 -1
- package/dist/providers.d.cts +2 -2
- package/dist/providers.d.ts +2 -2
- package/dist/providers.js +379 -60
- package/dist/providers.js.map +1 -1
- package/dist/validate.cjs +433 -79
- package/dist/validate.cjs.map +1 -1
- package/dist/validate.js +4 -4
- package/package.json +13 -3
- package/dist/chunk-FCEV23OT.js.map +0 -1
- package/dist/chunk-MPIHGH6L.js.map +0 -1
- package/dist/chunk-UYMVUTLV.js.map +0 -1
- package/dist/chunk-XID353H7.js.map +0 -1
package/dist/ai-sdk.cjs
ADDED
|
@@ -0,0 +1,831 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/ai-sdk.ts
|
|
21
|
+
var ai_sdk_exports = {};
|
|
22
|
+
__export(ai_sdk_exports, {
|
|
23
|
+
createAiSdkProviderOptions: () => createAiSdkProviderOptions
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(ai_sdk_exports);
|
|
26
|
+
|
|
27
|
+
// src/provider-core.ts
|
|
28
|
+
function hasOwn(object, key) {
|
|
29
|
+
return Object.prototype.hasOwnProperty.call(object, key);
|
|
30
|
+
}
|
|
31
|
+
function providerFromHostAlias(alias) {
|
|
32
|
+
const normalizedAlias = alias.toLowerCase();
|
|
33
|
+
if (hasOwn(PROVIDER_PARAMS, normalizedAlias)) {
|
|
34
|
+
return normalizedAlias;
|
|
35
|
+
}
|
|
36
|
+
return void 0;
|
|
37
|
+
}
|
|
38
|
+
function detectProvider(host) {
|
|
39
|
+
host = host.toLowerCase();
|
|
40
|
+
if (host.includes("openrouter")) return "openrouter";
|
|
41
|
+
if (host.includes("gateway.ai.vercel")) return "vercel";
|
|
42
|
+
if (host.includes("amazonaws") || host.includes("bedrock")) return "bedrock";
|
|
43
|
+
if (host.includes("openai")) return "openai";
|
|
44
|
+
if (host.includes("anthropic") || host.includes("claude")) return "anthropic";
|
|
45
|
+
if (host.includes("googleapis") || host.includes("google")) return "google";
|
|
46
|
+
if (host.includes("mistral")) return "mistral";
|
|
47
|
+
if (host.includes("cohere")) return "cohere";
|
|
48
|
+
return void 0;
|
|
49
|
+
}
|
|
50
|
+
var ALIASES = {
|
|
51
|
+
// temperature
|
|
52
|
+
temp: "temperature",
|
|
53
|
+
// max_tokens
|
|
54
|
+
max: "max_tokens",
|
|
55
|
+
max_out: "max_tokens",
|
|
56
|
+
max_output: "max_tokens",
|
|
57
|
+
max_output_tokens: "max_tokens",
|
|
58
|
+
max_completion_tokens: "max_tokens",
|
|
59
|
+
maxOutputTokens: "max_tokens",
|
|
60
|
+
maxTokens: "max_tokens",
|
|
61
|
+
// top_p
|
|
62
|
+
topp: "top_p",
|
|
63
|
+
topP: "top_p",
|
|
64
|
+
nucleus: "top_p",
|
|
65
|
+
// top_k
|
|
66
|
+
topk: "top_k",
|
|
67
|
+
topK: "top_k",
|
|
68
|
+
// frequency_penalty
|
|
69
|
+
freq: "frequency_penalty",
|
|
70
|
+
freq_penalty: "frequency_penalty",
|
|
71
|
+
frequencyPenalty: "frequency_penalty",
|
|
72
|
+
repetition_penalty: "frequency_penalty",
|
|
73
|
+
// presence_penalty
|
|
74
|
+
pres: "presence_penalty",
|
|
75
|
+
pres_penalty: "presence_penalty",
|
|
76
|
+
presencePenalty: "presence_penalty",
|
|
77
|
+
// stop
|
|
78
|
+
stop_sequences: "stop",
|
|
79
|
+
stopSequences: "stop",
|
|
80
|
+
stop_sequence: "stop",
|
|
81
|
+
// seed
|
|
82
|
+
random_seed: "seed",
|
|
83
|
+
randomSeed: "seed",
|
|
84
|
+
// n (completions count)
|
|
85
|
+
candidateCount: "n",
|
|
86
|
+
candidate_count: "n",
|
|
87
|
+
num_completions: "n",
|
|
88
|
+
// effort / reasoning
|
|
89
|
+
reasoning_effort: "effort",
|
|
90
|
+
reasoning: "effort",
|
|
91
|
+
// cache
|
|
92
|
+
cache_control: "cache",
|
|
93
|
+
cacheControl: "cache",
|
|
94
|
+
cachePoint: "cache",
|
|
95
|
+
cache_point: "cache"
|
|
96
|
+
};
|
|
97
|
+
var PROVIDER_PARAMS = {
|
|
98
|
+
openai: {
|
|
99
|
+
temperature: "temperature",
|
|
100
|
+
max_tokens: "max_tokens",
|
|
101
|
+
top_p: "top_p",
|
|
102
|
+
frequency_penalty: "frequency_penalty",
|
|
103
|
+
presence_penalty: "presence_penalty",
|
|
104
|
+
stop: "stop",
|
|
105
|
+
n: "n",
|
|
106
|
+
seed: "seed",
|
|
107
|
+
stream: "stream",
|
|
108
|
+
effort: "reasoning_effort"
|
|
109
|
+
},
|
|
110
|
+
anthropic: {
|
|
111
|
+
temperature: "temperature",
|
|
112
|
+
max_tokens: "max_tokens",
|
|
113
|
+
top_p: "top_p",
|
|
114
|
+
top_k: "top_k",
|
|
115
|
+
stop: "stop_sequences",
|
|
116
|
+
stream: "stream",
|
|
117
|
+
effort: "effort",
|
|
118
|
+
cache: "cache_control",
|
|
119
|
+
cache_ttl: "cache_ttl"
|
|
120
|
+
},
|
|
121
|
+
google: {
|
|
122
|
+
temperature: "temperature",
|
|
123
|
+
max_tokens: "maxOutputTokens",
|
|
124
|
+
top_p: "topP",
|
|
125
|
+
top_k: "topK",
|
|
126
|
+
frequency_penalty: "frequencyPenalty",
|
|
127
|
+
presence_penalty: "presencePenalty",
|
|
128
|
+
stop: "stopSequences",
|
|
129
|
+
n: "candidateCount",
|
|
130
|
+
stream: "stream",
|
|
131
|
+
seed: "seed",
|
|
132
|
+
responseMimeType: "responseMimeType",
|
|
133
|
+
responseSchema: "responseSchema"
|
|
134
|
+
},
|
|
135
|
+
mistral: {
|
|
136
|
+
temperature: "temperature",
|
|
137
|
+
max_tokens: "max_tokens",
|
|
138
|
+
top_p: "top_p",
|
|
139
|
+
frequency_penalty: "frequency_penalty",
|
|
140
|
+
presence_penalty: "presence_penalty",
|
|
141
|
+
stop: "stop",
|
|
142
|
+
n: "n",
|
|
143
|
+
seed: "random_seed",
|
|
144
|
+
stream: "stream",
|
|
145
|
+
safe_prompt: "safe_prompt",
|
|
146
|
+
min_tokens: "min_tokens"
|
|
147
|
+
},
|
|
148
|
+
cohere: {
|
|
149
|
+
temperature: "temperature",
|
|
150
|
+
max_tokens: "max_tokens",
|
|
151
|
+
top_p: "p",
|
|
152
|
+
top_k: "k",
|
|
153
|
+
frequency_penalty: "frequency_penalty",
|
|
154
|
+
presence_penalty: "presence_penalty",
|
|
155
|
+
stop: "stop_sequences",
|
|
156
|
+
stream: "stream",
|
|
157
|
+
seed: "seed"
|
|
158
|
+
},
|
|
159
|
+
bedrock: {
|
|
160
|
+
// Bedrock Converse API uses camelCase
|
|
161
|
+
temperature: "temperature",
|
|
162
|
+
max_tokens: "maxTokens",
|
|
163
|
+
top_p: "topP",
|
|
164
|
+
top_k: "topK",
|
|
165
|
+
// Claude models via additionalModelRequestFields
|
|
166
|
+
stop: "stopSequences",
|
|
167
|
+
stream: "stream",
|
|
168
|
+
cache: "cache_control",
|
|
169
|
+
cache_ttl: "cache_ttl"
|
|
170
|
+
},
|
|
171
|
+
openrouter: {
|
|
172
|
+
// OpenAI-compatible API with extra routing params
|
|
173
|
+
temperature: "temperature",
|
|
174
|
+
max_tokens: "max_tokens",
|
|
175
|
+
top_p: "top_p",
|
|
176
|
+
top_k: "top_k",
|
|
177
|
+
frequency_penalty: "frequency_penalty",
|
|
178
|
+
presence_penalty: "presence_penalty",
|
|
179
|
+
stop: "stop",
|
|
180
|
+
n: "n",
|
|
181
|
+
seed: "seed",
|
|
182
|
+
stream: "stream",
|
|
183
|
+
effort: "reasoning_effort"
|
|
184
|
+
},
|
|
185
|
+
vercel: {
|
|
186
|
+
// OpenAI-compatible gateway
|
|
187
|
+
temperature: "temperature",
|
|
188
|
+
max_tokens: "max_tokens",
|
|
189
|
+
top_p: "top_p",
|
|
190
|
+
top_k: "top_k",
|
|
191
|
+
frequency_penalty: "frequency_penalty",
|
|
192
|
+
presence_penalty: "presence_penalty",
|
|
193
|
+
stop: "stop",
|
|
194
|
+
n: "n",
|
|
195
|
+
seed: "seed",
|
|
196
|
+
stream: "stream",
|
|
197
|
+
effort: "reasoning_effort"
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
function isReasoningModel(model) {
|
|
201
|
+
const name = model.includes("/") ? model.split("/").pop() : model;
|
|
202
|
+
return /^o[134]/.test(name);
|
|
203
|
+
}
|
|
204
|
+
function canHostOpenAIModels(provider) {
|
|
205
|
+
return provider === "openai" || provider === "openrouter" || provider === "vercel";
|
|
206
|
+
}
|
|
207
|
+
function isGatewayProvider(provider) {
|
|
208
|
+
return provider === "openrouter" || provider === "vercel";
|
|
209
|
+
}
|
|
210
|
+
function detectGatewaySubProvider(model) {
|
|
211
|
+
const slash = model.indexOf("/");
|
|
212
|
+
if (slash < 1) return void 0;
|
|
213
|
+
const prefix = model.slice(0, slash);
|
|
214
|
+
const direct = [
|
|
215
|
+
"openai",
|
|
216
|
+
"anthropic",
|
|
217
|
+
"google",
|
|
218
|
+
"mistral",
|
|
219
|
+
"cohere"
|
|
220
|
+
];
|
|
221
|
+
return direct.find((p) => p === prefix);
|
|
222
|
+
}
|
|
223
|
+
function detectBedrockModelFamily(model) {
|
|
224
|
+
const parts = model.split(".");
|
|
225
|
+
let prefix = parts[0];
|
|
226
|
+
if (["us", "eu", "apac", "global"].includes(prefix) && parts.length > 1) {
|
|
227
|
+
prefix = parts[1];
|
|
228
|
+
}
|
|
229
|
+
const families = [
|
|
230
|
+
"anthropic",
|
|
231
|
+
"meta",
|
|
232
|
+
"amazon",
|
|
233
|
+
"mistral",
|
|
234
|
+
"cohere",
|
|
235
|
+
"ai21"
|
|
236
|
+
];
|
|
237
|
+
return families.find((f) => prefix === f);
|
|
238
|
+
}
|
|
239
|
+
function bedrockSupportsCaching(model) {
|
|
240
|
+
const family = detectBedrockModelFamily(model);
|
|
241
|
+
if (family === "anthropic") return true;
|
|
242
|
+
if (family === "amazon" && model.includes("nova")) return true;
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
var CACHE_VALUES = {
|
|
246
|
+
openai: void 0,
|
|
247
|
+
// OpenAI auto-caches; no explicit param
|
|
248
|
+
anthropic: "ephemeral",
|
|
249
|
+
google: void 0,
|
|
250
|
+
// Google uses explicit caching API, not a param
|
|
251
|
+
mistral: void 0,
|
|
252
|
+
cohere: void 0,
|
|
253
|
+
bedrock: "ephemeral",
|
|
254
|
+
// Supported for Claude models on Bedrock
|
|
255
|
+
openrouter: void 0,
|
|
256
|
+
// Depends on underlying provider
|
|
257
|
+
vercel: void 0
|
|
258
|
+
// Depends on underlying provider
|
|
259
|
+
};
|
|
260
|
+
var CACHE_TTLS = {
|
|
261
|
+
openai: void 0,
|
|
262
|
+
anthropic: ["5m", "1h"],
|
|
263
|
+
google: void 0,
|
|
264
|
+
mistral: void 0,
|
|
265
|
+
cohere: void 0,
|
|
266
|
+
bedrock: ["5m", "1h"],
|
|
267
|
+
// Claude on Bedrock uses same TTLs as direct Anthropic
|
|
268
|
+
openrouter: void 0,
|
|
269
|
+
vercel: void 0
|
|
270
|
+
};
|
|
271
|
+
var DURATION_RE = /^\d+[mh]$/;
|
|
272
|
+
|
|
273
|
+
// src/normalize.ts
|
|
274
|
+
function normalize(config, options = {}) {
|
|
275
|
+
const provider = (config.hostAlias ? providerFromHostAlias(config.hostAlias) : void 0) ?? detectProvider(config.host);
|
|
276
|
+
const subProvider = provider && isGatewayProvider(provider) ? detectGatewaySubProvider(config.model) : void 0;
|
|
277
|
+
const changes = [];
|
|
278
|
+
const params = {};
|
|
279
|
+
for (const [rawKey, value] of Object.entries(config.params)) {
|
|
280
|
+
let key = rawKey;
|
|
281
|
+
if (ALIASES[key]) {
|
|
282
|
+
const canonical = ALIASES[key];
|
|
283
|
+
if (options.verbose) {
|
|
284
|
+
changes.push({
|
|
285
|
+
from: key,
|
|
286
|
+
to: canonical,
|
|
287
|
+
value,
|
|
288
|
+
reason: `alias: "${key}" \u2192 "${canonical}"`
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
key = canonical;
|
|
292
|
+
}
|
|
293
|
+
if (key === "cache" && provider) {
|
|
294
|
+
let cacheValue = CACHE_VALUES[provider];
|
|
295
|
+
if (provider === "bedrock" && !bedrockSupportsCaching(config.model)) {
|
|
296
|
+
cacheValue = void 0;
|
|
297
|
+
}
|
|
298
|
+
if (!cacheValue) {
|
|
299
|
+
if (options.verbose) {
|
|
300
|
+
changes.push({
|
|
301
|
+
from: "cache",
|
|
302
|
+
to: "(dropped)",
|
|
303
|
+
value,
|
|
304
|
+
reason: `${provider} does not use a cache param for this model (caching is automatic or unsupported)`
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
const isBool = value === "true" || value === "1" || value === "yes";
|
|
310
|
+
const isDuration = DURATION_RE.test(value);
|
|
311
|
+
if (isBool || isDuration) {
|
|
312
|
+
const providerKey = PROVIDER_PARAMS[provider]?.["cache"] ?? "cache";
|
|
313
|
+
if (options.verbose) {
|
|
314
|
+
changes.push({
|
|
315
|
+
from: "cache",
|
|
316
|
+
to: providerKey,
|
|
317
|
+
value: cacheValue,
|
|
318
|
+
reason: `cache=${value} \u2192 ${providerKey}=${cacheValue} for ${provider}`
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
params[providerKey] = cacheValue;
|
|
322
|
+
if (isDuration && CACHE_TTLS[provider]) {
|
|
323
|
+
if (options.verbose) {
|
|
324
|
+
changes.push({
|
|
325
|
+
from: "cache",
|
|
326
|
+
to: "cache_ttl",
|
|
327
|
+
value,
|
|
328
|
+
reason: `cache=${value} \u2192 cache_ttl=${value} for ${provider}`
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
params["cache_ttl"] = value;
|
|
332
|
+
}
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (provider && PROVIDER_PARAMS[provider]) {
|
|
337
|
+
const providerKey = PROVIDER_PARAMS[provider][key];
|
|
338
|
+
if (providerKey && providerKey !== key) {
|
|
339
|
+
if (options.verbose) {
|
|
340
|
+
changes.push({
|
|
341
|
+
from: key,
|
|
342
|
+
to: providerKey,
|
|
343
|
+
value,
|
|
344
|
+
reason: `${provider} uses "${providerKey}" instead of "${key}"`
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
key = providerKey;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (provider && canHostOpenAIModels(provider) && isReasoningModel(config.model) && key === "max_tokens") {
|
|
351
|
+
if (options.verbose) {
|
|
352
|
+
changes.push({
|
|
353
|
+
from: "max_tokens",
|
|
354
|
+
to: "max_completion_tokens",
|
|
355
|
+
value,
|
|
356
|
+
reason: "OpenAI reasoning models use max_completion_tokens instead of max_tokens"
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
key = "max_completion_tokens";
|
|
360
|
+
}
|
|
361
|
+
params[key] = value;
|
|
362
|
+
}
|
|
363
|
+
return {
|
|
364
|
+
config: { ...config, params },
|
|
365
|
+
provider,
|
|
366
|
+
subProvider,
|
|
367
|
+
changes
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// src/ai-sdk.ts
|
|
372
|
+
var PROVIDER_OPTION_KEYS = {
|
|
373
|
+
openai: "openai",
|
|
374
|
+
anthropic: "anthropic",
|
|
375
|
+
google: "google",
|
|
376
|
+
mistral: "mistral",
|
|
377
|
+
cohere: "cohere",
|
|
378
|
+
bedrock: "bedrock",
|
|
379
|
+
openrouter: "openrouter",
|
|
380
|
+
vercel: "gateway"
|
|
381
|
+
};
|
|
382
|
+
var TRUE_VALUES = /* @__PURE__ */ new Set(["true", "1", "yes", "on"]);
|
|
383
|
+
var FALSE_VALUES = /* @__PURE__ */ new Set(["false", "0", "no", "off"]);
|
|
384
|
+
function providerOptionsKey(provider) {
|
|
385
|
+
return PROVIDER_OPTION_KEYS[provider];
|
|
386
|
+
}
|
|
387
|
+
function setProviderOption(options, provider, key, value) {
|
|
388
|
+
options[provider] ?? (options[provider] = {});
|
|
389
|
+
options[provider][key] = value;
|
|
390
|
+
}
|
|
391
|
+
function parseBoolean(value) {
|
|
392
|
+
const normalized = value.trim().toLowerCase();
|
|
393
|
+
if (TRUE_VALUES.has(normalized)) return true;
|
|
394
|
+
if (FALSE_VALUES.has(normalized)) return false;
|
|
395
|
+
return void 0;
|
|
396
|
+
}
|
|
397
|
+
function parseNumber(value) {
|
|
398
|
+
if (!value.trim()) return void 0;
|
|
399
|
+
const parsed = Number(value);
|
|
400
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
401
|
+
}
|
|
402
|
+
function parseJson(value) {
|
|
403
|
+
try {
|
|
404
|
+
return JSON.parse(value);
|
|
405
|
+
} catch {
|
|
406
|
+
return void 0;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function parseStringList(value) {
|
|
410
|
+
const json = parseJson(value);
|
|
411
|
+
if (Array.isArray(json)) {
|
|
412
|
+
return json.filter((item) => typeof item === "string");
|
|
413
|
+
}
|
|
414
|
+
return value.split(",").map((item) => item.trim()).filter(Boolean);
|
|
415
|
+
}
|
|
416
|
+
function typedValue(value) {
|
|
417
|
+
const booleanValue = parseBoolean(value);
|
|
418
|
+
if (booleanValue !== void 0) return booleanValue;
|
|
419
|
+
const numberValue = parseNumber(value);
|
|
420
|
+
if (numberValue !== void 0) return numberValue;
|
|
421
|
+
const jsonValue = parseJson(value);
|
|
422
|
+
if (jsonValue !== void 0) return jsonValue;
|
|
423
|
+
return value;
|
|
424
|
+
}
|
|
425
|
+
function mergeObjectOption(options, provider, key, value) {
|
|
426
|
+
const parsed = parseJson(value);
|
|
427
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
428
|
+
setProviderOption(options, provider, key, parsed);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
function addOpenAiOption(options, key, value) {
|
|
432
|
+
const target = "openai";
|
|
433
|
+
const mappings = {
|
|
434
|
+
reasoning_effort: "reasoningEffort",
|
|
435
|
+
max_completion_tokens: "maxCompletionTokens",
|
|
436
|
+
parallel_tool_calls: "parallelToolCalls",
|
|
437
|
+
service_tier: "serviceTier",
|
|
438
|
+
strict_json_schema: "strictJsonSchema",
|
|
439
|
+
text_verbosity: "textVerbosity",
|
|
440
|
+
prompt_cache_key: "promptCacheKey",
|
|
441
|
+
prompt_cache_retention: "promptCacheRetention",
|
|
442
|
+
safety_identifier: "safetyIdentifier",
|
|
443
|
+
system_message_mode: "systemMessageMode",
|
|
444
|
+
force_reasoning: "forceReasoning",
|
|
445
|
+
reasoning_summary: "reasoningSummary",
|
|
446
|
+
previous_response_id: "previousResponseId",
|
|
447
|
+
max_tool_calls: "maxToolCalls",
|
|
448
|
+
allowed_tools: "allowedTools"
|
|
449
|
+
};
|
|
450
|
+
const directKeys = /* @__PURE__ */ new Set([
|
|
451
|
+
"conversation",
|
|
452
|
+
"instructions",
|
|
453
|
+
"logprobs",
|
|
454
|
+
"metadata",
|
|
455
|
+
"prediction",
|
|
456
|
+
"store",
|
|
457
|
+
"truncation",
|
|
458
|
+
"user"
|
|
459
|
+
]);
|
|
460
|
+
if (!mappings[key] && !directKeys.has(key) && key !== "include") return;
|
|
461
|
+
const optionKey = mappings[key] ?? key;
|
|
462
|
+
if (key === "include") {
|
|
463
|
+
setProviderOption(options, target, optionKey, parseStringList(value));
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
if (key === "metadata" || key === "prediction" || key === "allowed_tools") {
|
|
467
|
+
mergeObjectOption(options, target, optionKey, value);
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
setProviderOption(options, target, optionKey, typedValue(value));
|
|
471
|
+
}
|
|
472
|
+
function addAnthropicOption(options, key, value) {
|
|
473
|
+
const target = "anthropic";
|
|
474
|
+
if (key === "cache_control" || key === "cacheControl") {
|
|
475
|
+
const ttl = options[target]?.cacheControl;
|
|
476
|
+
const ttlValue = ttl && typeof ttl === "object" && "ttl" in ttl ? ttl.ttl : void 0;
|
|
477
|
+
setProviderOption(options, target, "cacheControl", {
|
|
478
|
+
type: value === "ephemeral" ? "ephemeral" : value,
|
|
479
|
+
...ttlValue ? { ttl: ttlValue } : {}
|
|
480
|
+
});
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
if (key === "cache_ttl") {
|
|
484
|
+
const current = options[target]?.cacheControl;
|
|
485
|
+
setProviderOption(options, target, "cacheControl", {
|
|
486
|
+
...current && typeof current === "object" ? current : {},
|
|
487
|
+
type: "ephemeral",
|
|
488
|
+
ttl: value
|
|
489
|
+
});
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
if (key === "thinking") {
|
|
493
|
+
mergeObjectOption(options, target, "thinking", value);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (key === "thinking_budget" || key === "budget_tokens") {
|
|
497
|
+
const budgetTokens = parseNumber(value);
|
|
498
|
+
if (budgetTokens !== void 0) {
|
|
499
|
+
setProviderOption(options, target, "thinking", {
|
|
500
|
+
type: "enabled",
|
|
501
|
+
budgetTokens
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const mappings = {
|
|
507
|
+
send_reasoning: "sendReasoning",
|
|
508
|
+
structured_output_mode: "structuredOutputMode",
|
|
509
|
+
disable_parallel_tool_use: "disableParallelToolUse",
|
|
510
|
+
tool_streaming: "toolStreaming",
|
|
511
|
+
inference_geo: "inferenceGeo",
|
|
512
|
+
anthropic_beta: "anthropicBeta",
|
|
513
|
+
mcp_servers: "mcpServers",
|
|
514
|
+
task_budget: "taskBudget",
|
|
515
|
+
context_management: "contextManagement"
|
|
516
|
+
};
|
|
517
|
+
const directKeys = /* @__PURE__ */ new Set([
|
|
518
|
+
"effort",
|
|
519
|
+
"speed",
|
|
520
|
+
"sendReasoning",
|
|
521
|
+
"structuredOutputMode",
|
|
522
|
+
"disableParallelToolUse",
|
|
523
|
+
"toolStreaming",
|
|
524
|
+
"inferenceGeo",
|
|
525
|
+
"anthropicBeta",
|
|
526
|
+
"metadata",
|
|
527
|
+
"mcpServers",
|
|
528
|
+
"container",
|
|
529
|
+
"taskBudget",
|
|
530
|
+
"contextManagement"
|
|
531
|
+
]);
|
|
532
|
+
if (!mappings[key] && !directKeys.has(key)) return;
|
|
533
|
+
const optionKey = mappings[key] ?? key;
|
|
534
|
+
if (key === "anthropic_beta") {
|
|
535
|
+
setProviderOption(options, target, optionKey, parseStringList(value));
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
if (key === "metadata" || key === "mcp_servers" || key === "container" || key === "task_budget" || key === "context_management") {
|
|
539
|
+
mergeObjectOption(options, target, optionKey, value);
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
setProviderOption(options, target, optionKey, typedValue(value));
|
|
543
|
+
}
|
|
544
|
+
function addGoogleOption(options, key, value) {
|
|
545
|
+
const target = "google";
|
|
546
|
+
if (key === "thinking_budget" || key === "thinking_level" || key === "include_thoughts") {
|
|
547
|
+
const current = options[target]?.thinkingConfig;
|
|
548
|
+
const thinkingConfig = current && typeof current === "object" && !Array.isArray(current) ? { ...current } : {};
|
|
549
|
+
if (key === "thinking_budget") {
|
|
550
|
+
const parsed = parseNumber(value);
|
|
551
|
+
if (parsed !== void 0) thinkingConfig.thinkingBudget = parsed;
|
|
552
|
+
}
|
|
553
|
+
if (key === "thinking_level") thinkingConfig.thinkingLevel = value;
|
|
554
|
+
if (key === "include_thoughts") {
|
|
555
|
+
const parsed = parseBoolean(value);
|
|
556
|
+
if (parsed !== void 0) thinkingConfig.includeThoughts = parsed;
|
|
557
|
+
}
|
|
558
|
+
setProviderOption(options, target, "thinkingConfig", thinkingConfig);
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
const mappings = {
|
|
562
|
+
cached_content: "cachedContent",
|
|
563
|
+
structured_outputs: "structuredOutputs",
|
|
564
|
+
safety_settings: "safetySettings",
|
|
565
|
+
response_modalities: "responseModalities",
|
|
566
|
+
audio_timestamp: "audioTimestamp",
|
|
567
|
+
media_resolution: "mediaResolution",
|
|
568
|
+
image_config: "imageConfig",
|
|
569
|
+
retrieval_config: "retrievalConfig",
|
|
570
|
+
stream_function_call_arguments: "streamFunctionCallArguments",
|
|
571
|
+
service_tier: "serviceTier"
|
|
572
|
+
};
|
|
573
|
+
const directKeys = /* @__PURE__ */ new Set([
|
|
574
|
+
"cachedContent",
|
|
575
|
+
"structuredOutputs",
|
|
576
|
+
"safetySettings",
|
|
577
|
+
"threshold",
|
|
578
|
+
"audioTimestamp",
|
|
579
|
+
"labels",
|
|
580
|
+
"mediaResolution",
|
|
581
|
+
"imageConfig",
|
|
582
|
+
"retrievalConfig",
|
|
583
|
+
"responseModalities",
|
|
584
|
+
"streamFunctionCallArguments",
|
|
585
|
+
"serviceTier"
|
|
586
|
+
]);
|
|
587
|
+
if (!mappings[key] && !directKeys.has(key)) return;
|
|
588
|
+
const optionKey = mappings[key] ?? key;
|
|
589
|
+
if (key === "response_modalities") {
|
|
590
|
+
setProviderOption(options, target, optionKey, parseStringList(value));
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
if (key === "safety_settings" || key === "labels" || key === "image_config" || key === "retrieval_config") {
|
|
594
|
+
mergeObjectOption(options, target, optionKey, value);
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
setProviderOption(options, target, optionKey, typedValue(value));
|
|
598
|
+
}
|
|
599
|
+
function addMistralOption(options, key, value) {
|
|
600
|
+
const target = "mistral";
|
|
601
|
+
const mappings = {
|
|
602
|
+
safe_prompt: "safePrompt",
|
|
603
|
+
document_image_limit: "documentImageLimit",
|
|
604
|
+
document_page_limit: "documentPageLimit",
|
|
605
|
+
structured_outputs: "structuredOutputs",
|
|
606
|
+
strict_json_schema: "strictJsonSchema",
|
|
607
|
+
parallel_tool_calls: "parallelToolCalls",
|
|
608
|
+
reasoning_effort: "reasoningEffort"
|
|
609
|
+
};
|
|
610
|
+
const directKeys = /* @__PURE__ */ new Set([
|
|
611
|
+
"safePrompt",
|
|
612
|
+
"documentImageLimit",
|
|
613
|
+
"documentPageLimit",
|
|
614
|
+
"structuredOutputs",
|
|
615
|
+
"strictJsonSchema",
|
|
616
|
+
"parallelToolCalls",
|
|
617
|
+
"reasoningEffort"
|
|
618
|
+
]);
|
|
619
|
+
if (!mappings[key] && !directKeys.has(key)) return;
|
|
620
|
+
const optionKey = mappings[key] ?? key;
|
|
621
|
+
setProviderOption(options, target, optionKey, typedValue(value));
|
|
622
|
+
}
|
|
623
|
+
function addCohereOption(options, key, value) {
|
|
624
|
+
const target = "cohere";
|
|
625
|
+
if (key === "thinking") {
|
|
626
|
+
mergeObjectOption(options, target, "thinking", value);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
if (key === "thinking_token_budget" || key === "token_budget") {
|
|
630
|
+
const tokenBudget = parseNumber(value);
|
|
631
|
+
if (tokenBudget !== void 0) {
|
|
632
|
+
setProviderOption(options, target, "thinking", {
|
|
633
|
+
type: "enabled",
|
|
634
|
+
tokenBudget
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
if (key === "thinking_type") {
|
|
640
|
+
const current = options[target]?.thinking;
|
|
641
|
+
setProviderOption(options, target, "thinking", {
|
|
642
|
+
...current && typeof current === "object" ? current : {},
|
|
643
|
+
type: value
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
function addBedrockOption(options, key, value) {
|
|
648
|
+
const target = "bedrock";
|
|
649
|
+
if (key === "cache_control") {
|
|
650
|
+
setProviderOption(options, target, "cachePoint", {
|
|
651
|
+
type: value === "ephemeral" ? "default" : value
|
|
652
|
+
});
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
if (key === "cache_ttl") {
|
|
656
|
+
const current = options[target]?.cachePoint;
|
|
657
|
+
setProviderOption(options, target, "cachePoint", {
|
|
658
|
+
...current && typeof current === "object" ? current : {},
|
|
659
|
+
type: "default",
|
|
660
|
+
ttl: value
|
|
661
|
+
});
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
if (key === "reasoning_config") {
|
|
665
|
+
mergeObjectOption(options, target, "reasoningConfig", value);
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
if (key === "budget_tokens" || key === "reasoning_effort") {
|
|
669
|
+
const current = options[target]?.reasoningConfig;
|
|
670
|
+
const reasoningConfig = current && typeof current === "object" && !Array.isArray(current) ? { ...current } : {};
|
|
671
|
+
reasoningConfig.type = "enabled";
|
|
672
|
+
if (key === "budget_tokens") {
|
|
673
|
+
const budgetTokens = parseNumber(value);
|
|
674
|
+
if (budgetTokens !== void 0)
|
|
675
|
+
reasoningConfig.budgetTokens = budgetTokens;
|
|
676
|
+
}
|
|
677
|
+
if (key === "reasoning_effort") reasoningConfig.maxReasoningEffort = value;
|
|
678
|
+
setProviderOption(options, target, "reasoningConfig", reasoningConfig);
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
const mappings = {
|
|
682
|
+
additional_model_request_fields: "additionalModelRequestFields",
|
|
683
|
+
anthropic_beta: "anthropicBeta",
|
|
684
|
+
service_tier: "serviceTier"
|
|
685
|
+
};
|
|
686
|
+
const directKeys = /* @__PURE__ */ new Set([
|
|
687
|
+
"additionalModelRequestFields",
|
|
688
|
+
"anthropicBeta",
|
|
689
|
+
"serviceTier"
|
|
690
|
+
]);
|
|
691
|
+
if (!mappings[key] && !directKeys.has(key)) return;
|
|
692
|
+
const optionKey = mappings[key] ?? key;
|
|
693
|
+
if (key === "additional_model_request_fields") {
|
|
694
|
+
mergeObjectOption(options, target, optionKey, value);
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
if (key === "anthropic_beta") {
|
|
698
|
+
setProviderOption(options, target, optionKey, parseStringList(value));
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
setProviderOption(options, target, optionKey, typedValue(value));
|
|
702
|
+
}
|
|
703
|
+
function addGatewayOption(options, key, value) {
|
|
704
|
+
const target = "gateway";
|
|
705
|
+
const listKeys = /* @__PURE__ */ new Set(["only", "order", "tags", "models"]);
|
|
706
|
+
const objectKeys = /* @__PURE__ */ new Set(["byok", "provider_timeouts"]);
|
|
707
|
+
const mappings = {
|
|
708
|
+
zero_data_retention: "zeroDataRetention",
|
|
709
|
+
disallow_prompt_training: "disallowPromptTraining",
|
|
710
|
+
hipaa_compliant: "hipaaCompliant",
|
|
711
|
+
quota_entity_id: "quotaEntityId",
|
|
712
|
+
provider_timeouts: "providerTimeouts"
|
|
713
|
+
};
|
|
714
|
+
const directKeys = /* @__PURE__ */ new Set([
|
|
715
|
+
"sort",
|
|
716
|
+
"user",
|
|
717
|
+
"zeroDataRetention",
|
|
718
|
+
"disallowPromptTraining",
|
|
719
|
+
"hipaaCompliant",
|
|
720
|
+
"quotaEntityId",
|
|
721
|
+
"providerTimeouts"
|
|
722
|
+
]);
|
|
723
|
+
if (!mappings[key] && !directKeys.has(key) && !listKeys.has(key) && !objectKeys.has(key)) {
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
const optionKey = mappings[key] ?? key;
|
|
727
|
+
if (listKeys.has(key)) {
|
|
728
|
+
setProviderOption(options, target, optionKey, parseStringList(value));
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
if (objectKeys.has(key)) {
|
|
732
|
+
mergeObjectOption(options, target, optionKey, value);
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
setProviderOption(options, target, optionKey, typedValue(value));
|
|
736
|
+
}
|
|
737
|
+
function addOpenRouterOption(options, key, value) {
|
|
738
|
+
const target = "openrouter";
|
|
739
|
+
if (key === "models") {
|
|
740
|
+
setProviderOption(options, target, "models", parseStringList(value));
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
if (key === "reasoning") {
|
|
744
|
+
mergeObjectOption(options, target, "reasoning", value);
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
if (key === "reasoning_effort") {
|
|
748
|
+
const current = options[target]?.reasoning;
|
|
749
|
+
setProviderOption(options, target, "reasoning", {
|
|
750
|
+
...current && typeof current === "object" ? current : {},
|
|
751
|
+
effort: value
|
|
752
|
+
});
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
if (key === "reasoning_max_tokens" || key === "max_reasoning_tokens") {
|
|
756
|
+
const current = options[target]?.reasoning;
|
|
757
|
+
const maxTokens = parseNumber(value);
|
|
758
|
+
if (maxTokens !== void 0) {
|
|
759
|
+
setProviderOption(options, target, "reasoning", {
|
|
760
|
+
...current && typeof current === "object" ? current : {},
|
|
761
|
+
max_tokens: maxTokens
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
if (key === "reasoning_enabled" || key === "reasoning_exclude") {
|
|
767
|
+
const current = options[target]?.reasoning;
|
|
768
|
+
const parsed = parseBoolean(value);
|
|
769
|
+
if (parsed !== void 0) {
|
|
770
|
+
setProviderOption(options, target, "reasoning", {
|
|
771
|
+
...current && typeof current === "object" ? current : {},
|
|
772
|
+
[key === "reasoning_enabled" ? "enabled" : "exclude"]: parsed
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
if (key === "user") {
|
|
778
|
+
setProviderOption(options, target, "user", value);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
function addProviderSpecificOption(options, provider, key, value, includeGatewayOptions) {
|
|
782
|
+
if (provider === "vercel") {
|
|
783
|
+
if (includeGatewayOptions) addGatewayOption(options, key, value);
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
if (provider === "openai") addOpenAiOption(options, key, value);
|
|
787
|
+
if (provider === "anthropic") addAnthropicOption(options, key, value);
|
|
788
|
+
if (provider === "google") addGoogleOption(options, key, value);
|
|
789
|
+
if (provider === "mistral") addMistralOption(options, key, value);
|
|
790
|
+
if (provider === "cohere") addCohereOption(options, key, value);
|
|
791
|
+
if (provider === "bedrock") addBedrockOption(options, key, value);
|
|
792
|
+
if (provider === "openrouter") addOpenRouterOption(options, key, value);
|
|
793
|
+
}
|
|
794
|
+
function createAiSdkProviderOptions(configOrResult, options = {}) {
|
|
795
|
+
const normalized = "changes" in configOrResult && "subProvider" in configOrResult ? configOrResult : normalize(configOrResult, options);
|
|
796
|
+
const providerOptions = {};
|
|
797
|
+
if (!normalized.provider) {
|
|
798
|
+
return {
|
|
799
|
+
provider: normalized.provider,
|
|
800
|
+
subProvider: normalized.subProvider,
|
|
801
|
+
providerOptions
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
const includeGatewayOptions = options.includeGatewayOptions ?? normalized.provider === "vercel";
|
|
805
|
+
for (const [key, value] of Object.entries(normalized.config.params)) {
|
|
806
|
+
addProviderSpecificOption(
|
|
807
|
+
providerOptions,
|
|
808
|
+
normalized.provider,
|
|
809
|
+
key,
|
|
810
|
+
value,
|
|
811
|
+
includeGatewayOptions
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
if (normalized.provider !== "vercel" && !providerOptions[providerOptionsKey(normalized.provider)]) {
|
|
815
|
+
return {
|
|
816
|
+
provider: normalized.provider,
|
|
817
|
+
subProvider: normalized.subProvider,
|
|
818
|
+
providerOptions: {}
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
return {
|
|
822
|
+
provider: normalized.provider,
|
|
823
|
+
subProvider: normalized.subProvider,
|
|
824
|
+
providerOptions
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
828
|
+
0 && (module.exports = {
|
|
829
|
+
createAiSdkProviderOptions
|
|
830
|
+
});
|
|
831
|
+
//# sourceMappingURL=ai-sdk.cjs.map
|