llm-strings 1.1.1 → 1.1.2
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 +673 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/normalize.cjs +353 -4
- package/dist/normalize.cjs.map +1 -1
- package/dist/normalize.d.ts +2 -2
- package/dist/parse.cjs +60 -7
- package/dist/parse.cjs.map +1 -1
- package/dist/providers.cjs +414 -35
- package/dist/providers.cjs.map +1 -1
- package/dist/providers.d.ts +2 -2
- package/dist/validate.cjs +663 -6
- package/dist/validate.cjs.map +1 -1
- package/package.json +4 -3
- package/dist/chunk-MGWGNZDJ.cjs +0 -116
- package/dist/chunk-MGWGNZDJ.cjs.map +0 -1
- package/dist/chunk-N6NVBE43.cjs +0 -37
- package/dist/chunk-N6NVBE43.cjs.map +0 -1
- package/dist/chunk-NSCBY4VD.cjs +0 -370
- package/dist/chunk-NSCBY4VD.cjs.map +0 -1
- package/dist/chunk-RSUXM42X.cjs +0 -180
- package/dist/chunk-RSUXM42X.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,18 +1,679 @@
|
|
|
1
|
-
"use strict";
|
|
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);
|
|
2
19
|
|
|
3
|
-
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
build: () => build,
|
|
24
|
+
normalize: () => normalize,
|
|
25
|
+
parse: () => parse,
|
|
26
|
+
validate: () => validate
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
4
29
|
|
|
30
|
+
// src/parse.ts
|
|
31
|
+
function parse(connectionString) {
|
|
32
|
+
const url = new URL(connectionString);
|
|
33
|
+
if (url.protocol !== "llm:") {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Invalid scheme: expected "llm://", got "${url.protocol}//"`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
const host = url.hostname;
|
|
39
|
+
const model = url.pathname.replace(/^\//, "");
|
|
40
|
+
const label = url.username || void 0;
|
|
41
|
+
const apiKey = url.password || void 0;
|
|
42
|
+
const params = {};
|
|
43
|
+
for (const [key, value] of url.searchParams) {
|
|
44
|
+
params[key] = value;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
raw: connectionString,
|
|
48
|
+
host,
|
|
49
|
+
model,
|
|
50
|
+
label,
|
|
51
|
+
apiKey,
|
|
52
|
+
params
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function build(config) {
|
|
56
|
+
const auth = config.label || config.apiKey ? `${config.label ?? ""}${config.apiKey ? `:${config.apiKey}` : ""}@` : "";
|
|
57
|
+
const query = new URLSearchParams(config.params).toString();
|
|
58
|
+
const qs = query ? `?${query}` : "";
|
|
59
|
+
return `llm://${auth}${config.host}/${config.model}${qs}`;
|
|
60
|
+
}
|
|
5
61
|
|
|
6
|
-
|
|
62
|
+
// src/provider-core.ts
|
|
63
|
+
function detectProvider(host) {
|
|
64
|
+
if (host.includes("openrouter")) return "openrouter";
|
|
65
|
+
if (host.includes("gateway.ai.vercel")) return "vercel";
|
|
66
|
+
if (host.includes("amazonaws") || host.includes("bedrock")) return "bedrock";
|
|
67
|
+
if (host.includes("openai")) return "openai";
|
|
68
|
+
if (host.includes("anthropic") || host.includes("claude")) return "anthropic";
|
|
69
|
+
if (host.includes("googleapis") || host.includes("google")) return "google";
|
|
70
|
+
if (host.includes("mistral")) return "mistral";
|
|
71
|
+
if (host.includes("cohere")) return "cohere";
|
|
72
|
+
return void 0;
|
|
73
|
+
}
|
|
74
|
+
var ALIASES = {
|
|
75
|
+
// temperature
|
|
76
|
+
temp: "temperature",
|
|
77
|
+
// max_tokens
|
|
78
|
+
max: "max_tokens",
|
|
79
|
+
max_out: "max_tokens",
|
|
80
|
+
max_output: "max_tokens",
|
|
81
|
+
max_output_tokens: "max_tokens",
|
|
82
|
+
max_completion_tokens: "max_tokens",
|
|
83
|
+
maxOutputTokens: "max_tokens",
|
|
84
|
+
maxTokens: "max_tokens",
|
|
85
|
+
// top_p
|
|
86
|
+
topp: "top_p",
|
|
87
|
+
topP: "top_p",
|
|
88
|
+
nucleus: "top_p",
|
|
89
|
+
// top_k
|
|
90
|
+
topk: "top_k",
|
|
91
|
+
topK: "top_k",
|
|
92
|
+
// frequency_penalty
|
|
93
|
+
freq: "frequency_penalty",
|
|
94
|
+
freq_penalty: "frequency_penalty",
|
|
95
|
+
frequencyPenalty: "frequency_penalty",
|
|
96
|
+
repetition_penalty: "frequency_penalty",
|
|
97
|
+
// presence_penalty
|
|
98
|
+
pres: "presence_penalty",
|
|
99
|
+
pres_penalty: "presence_penalty",
|
|
100
|
+
presencePenalty: "presence_penalty",
|
|
101
|
+
// stop
|
|
102
|
+
stop_sequences: "stop",
|
|
103
|
+
stopSequences: "stop",
|
|
104
|
+
stop_sequence: "stop",
|
|
105
|
+
// seed
|
|
106
|
+
random_seed: "seed",
|
|
107
|
+
randomSeed: "seed",
|
|
108
|
+
// n (completions count)
|
|
109
|
+
candidateCount: "n",
|
|
110
|
+
candidate_count: "n",
|
|
111
|
+
num_completions: "n",
|
|
112
|
+
// effort / reasoning
|
|
113
|
+
reasoning_effort: "effort",
|
|
114
|
+
reasoning: "effort",
|
|
115
|
+
// cache
|
|
116
|
+
cache_control: "cache",
|
|
117
|
+
cacheControl: "cache",
|
|
118
|
+
cachePoint: "cache",
|
|
119
|
+
cache_point: "cache"
|
|
120
|
+
};
|
|
121
|
+
var PROVIDER_PARAMS = {
|
|
122
|
+
openai: {
|
|
123
|
+
temperature: "temperature",
|
|
124
|
+
max_tokens: "max_tokens",
|
|
125
|
+
top_p: "top_p",
|
|
126
|
+
frequency_penalty: "frequency_penalty",
|
|
127
|
+
presence_penalty: "presence_penalty",
|
|
128
|
+
stop: "stop",
|
|
129
|
+
n: "n",
|
|
130
|
+
seed: "seed",
|
|
131
|
+
stream: "stream",
|
|
132
|
+
effort: "reasoning_effort"
|
|
133
|
+
},
|
|
134
|
+
anthropic: {
|
|
135
|
+
temperature: "temperature",
|
|
136
|
+
max_tokens: "max_tokens",
|
|
137
|
+
top_p: "top_p",
|
|
138
|
+
top_k: "top_k",
|
|
139
|
+
stop: "stop_sequences",
|
|
140
|
+
stream: "stream",
|
|
141
|
+
effort: "effort",
|
|
142
|
+
cache: "cache_control",
|
|
143
|
+
cache_ttl: "cache_ttl"
|
|
144
|
+
},
|
|
145
|
+
google: {
|
|
146
|
+
temperature: "temperature",
|
|
147
|
+
max_tokens: "maxOutputTokens",
|
|
148
|
+
top_p: "topP",
|
|
149
|
+
top_k: "topK",
|
|
150
|
+
frequency_penalty: "frequencyPenalty",
|
|
151
|
+
presence_penalty: "presencePenalty",
|
|
152
|
+
stop: "stopSequences",
|
|
153
|
+
n: "candidateCount",
|
|
154
|
+
stream: "stream",
|
|
155
|
+
seed: "seed",
|
|
156
|
+
responseMimeType: "responseMimeType",
|
|
157
|
+
responseSchema: "responseSchema"
|
|
158
|
+
},
|
|
159
|
+
mistral: {
|
|
160
|
+
temperature: "temperature",
|
|
161
|
+
max_tokens: "max_tokens",
|
|
162
|
+
top_p: "top_p",
|
|
163
|
+
frequency_penalty: "frequency_penalty",
|
|
164
|
+
presence_penalty: "presence_penalty",
|
|
165
|
+
stop: "stop",
|
|
166
|
+
n: "n",
|
|
167
|
+
seed: "random_seed",
|
|
168
|
+
stream: "stream",
|
|
169
|
+
safe_prompt: "safe_prompt",
|
|
170
|
+
min_tokens: "min_tokens"
|
|
171
|
+
},
|
|
172
|
+
cohere: {
|
|
173
|
+
temperature: "temperature",
|
|
174
|
+
max_tokens: "max_tokens",
|
|
175
|
+
top_p: "p",
|
|
176
|
+
top_k: "k",
|
|
177
|
+
frequency_penalty: "frequency_penalty",
|
|
178
|
+
presence_penalty: "presence_penalty",
|
|
179
|
+
stop: "stop_sequences",
|
|
180
|
+
stream: "stream",
|
|
181
|
+
seed: "seed"
|
|
182
|
+
},
|
|
183
|
+
bedrock: {
|
|
184
|
+
// Bedrock Converse API uses camelCase
|
|
185
|
+
temperature: "temperature",
|
|
186
|
+
max_tokens: "maxTokens",
|
|
187
|
+
top_p: "topP",
|
|
188
|
+
top_k: "topK",
|
|
189
|
+
// Claude models via additionalModelRequestFields
|
|
190
|
+
stop: "stopSequences",
|
|
191
|
+
stream: "stream",
|
|
192
|
+
cache: "cache_control",
|
|
193
|
+
cache_ttl: "cache_ttl"
|
|
194
|
+
},
|
|
195
|
+
openrouter: {
|
|
196
|
+
// OpenAI-compatible API with extra routing params
|
|
197
|
+
temperature: "temperature",
|
|
198
|
+
max_tokens: "max_tokens",
|
|
199
|
+
top_p: "top_p",
|
|
200
|
+
top_k: "top_k",
|
|
201
|
+
frequency_penalty: "frequency_penalty",
|
|
202
|
+
presence_penalty: "presence_penalty",
|
|
203
|
+
stop: "stop",
|
|
204
|
+
n: "n",
|
|
205
|
+
seed: "seed",
|
|
206
|
+
stream: "stream",
|
|
207
|
+
effort: "reasoning_effort"
|
|
208
|
+
},
|
|
209
|
+
vercel: {
|
|
210
|
+
// OpenAI-compatible gateway
|
|
211
|
+
temperature: "temperature",
|
|
212
|
+
max_tokens: "max_tokens",
|
|
213
|
+
top_p: "top_p",
|
|
214
|
+
top_k: "top_k",
|
|
215
|
+
frequency_penalty: "frequency_penalty",
|
|
216
|
+
presence_penalty: "presence_penalty",
|
|
217
|
+
stop: "stop",
|
|
218
|
+
n: "n",
|
|
219
|
+
seed: "seed",
|
|
220
|
+
stream: "stream",
|
|
221
|
+
effort: "reasoning_effort"
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
var PARAM_SPECS = {
|
|
225
|
+
openai: {
|
|
226
|
+
temperature: { type: "number", min: 0, max: 2, default: 0.7, description: "Controls randomness" },
|
|
227
|
+
max_tokens: { type: "number", min: 1, default: 4096, description: "Maximum output tokens" },
|
|
228
|
+
top_p: { type: "number", min: 0, max: 1, default: 1, description: "Nucleus sampling" },
|
|
229
|
+
frequency_penalty: { type: "number", min: -2, max: 2, default: 0, description: "Penalize frequent tokens" },
|
|
230
|
+
presence_penalty: { type: "number", min: -2, max: 2, default: 0, description: "Penalize repeated topics" },
|
|
231
|
+
stop: { type: "string", description: "Stop sequences" },
|
|
232
|
+
n: { type: "number", min: 1, default: 1, description: "Completions count" },
|
|
233
|
+
seed: { type: "number", description: "Random seed" },
|
|
234
|
+
stream: { type: "boolean", default: false, description: "Stream response" },
|
|
235
|
+
reasoning_effort: {
|
|
236
|
+
type: "string",
|
|
237
|
+
values: ["none", "minimal", "low", "medium", "high", "xhigh"],
|
|
238
|
+
default: "medium",
|
|
239
|
+
description: "Reasoning effort"
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
anthropic: {
|
|
243
|
+
temperature: { type: "number", min: 0, max: 1, default: 0.7, description: "Controls randomness" },
|
|
244
|
+
max_tokens: { type: "number", min: 1, default: 4096, description: "Maximum output tokens" },
|
|
245
|
+
top_p: { type: "number", min: 0, max: 1, default: 1, description: "Nucleus sampling" },
|
|
246
|
+
top_k: { type: "number", min: 0, default: 40, description: "Top-K sampling" },
|
|
247
|
+
stop_sequences: { type: "string", description: "Stop sequences" },
|
|
248
|
+
stream: { type: "boolean", default: false, description: "Stream response" },
|
|
249
|
+
effort: { type: "string", values: ["low", "medium", "high", "max"], default: "medium", description: "Thinking effort" },
|
|
250
|
+
cache_control: { type: "string", values: ["ephemeral"], default: "ephemeral", description: "Cache control" },
|
|
251
|
+
cache_ttl: { type: "string", values: ["5m", "1h"], default: "5m", description: "Cache TTL" }
|
|
252
|
+
},
|
|
253
|
+
google: {
|
|
254
|
+
temperature: { type: "number", min: 0, max: 2, default: 0.7, description: "Controls randomness" },
|
|
255
|
+
maxOutputTokens: { type: "number", min: 1, default: 4096, description: "Maximum output tokens" },
|
|
256
|
+
topP: { type: "number", min: 0, max: 1, default: 1, description: "Nucleus sampling" },
|
|
257
|
+
topK: { type: "number", min: 0, default: 40, description: "Top-K sampling" },
|
|
258
|
+
frequencyPenalty: { type: "number", min: -2, max: 2, default: 0, description: "Penalize frequent tokens" },
|
|
259
|
+
presencePenalty: { type: "number", min: -2, max: 2, default: 0, description: "Penalize repeated topics" },
|
|
260
|
+
stopSequences: { type: "string", description: "Stop sequences" },
|
|
261
|
+
candidateCount: { type: "number", min: 1, default: 1, description: "Candidate count" },
|
|
262
|
+
stream: { type: "boolean", default: false, description: "Stream response" },
|
|
263
|
+
seed: { type: "number", description: "Random seed" },
|
|
264
|
+
responseMimeType: { type: "string", description: "Response MIME type" },
|
|
265
|
+
responseSchema: { type: "string", description: "Response schema" }
|
|
266
|
+
},
|
|
267
|
+
mistral: {
|
|
268
|
+
temperature: { type: "number", min: 0, max: 1, default: 0.7, description: "Controls randomness" },
|
|
269
|
+
max_tokens: { type: "number", min: 1, default: 4096, description: "Maximum output tokens" },
|
|
270
|
+
top_p: { type: "number", min: 0, max: 1, default: 1, description: "Nucleus sampling" },
|
|
271
|
+
frequency_penalty: { type: "number", min: -2, max: 2, default: 0, description: "Penalize frequent tokens" },
|
|
272
|
+
presence_penalty: { type: "number", min: -2, max: 2, default: 0, description: "Penalize repeated topics" },
|
|
273
|
+
stop: { type: "string", description: "Stop sequences" },
|
|
274
|
+
n: { type: "number", min: 1, default: 1, description: "Completions count" },
|
|
275
|
+
random_seed: { type: "number", description: "Random seed" },
|
|
276
|
+
stream: { type: "boolean", default: false, description: "Stream response" },
|
|
277
|
+
safe_prompt: { type: "boolean", default: false, description: "Enable safe prompt" },
|
|
278
|
+
min_tokens: { type: "number", min: 0, default: 0, description: "Minimum tokens" }
|
|
279
|
+
},
|
|
280
|
+
cohere: {
|
|
281
|
+
temperature: { type: "number", min: 0, max: 1, default: 0.7, description: "Controls randomness" },
|
|
282
|
+
max_tokens: { type: "number", min: 1, default: 4096, description: "Maximum output tokens" },
|
|
283
|
+
p: { type: "number", min: 0, max: 1, default: 1, description: "Nucleus sampling (p)" },
|
|
284
|
+
k: { type: "number", min: 0, max: 500, default: 40, description: "Top-K sampling (k)" },
|
|
285
|
+
frequency_penalty: { type: "number", min: 0, max: 1, default: 0, description: "Penalize frequent tokens" },
|
|
286
|
+
presence_penalty: { type: "number", min: 0, max: 1, default: 0, description: "Penalize repeated topics" },
|
|
287
|
+
stop_sequences: { type: "string", description: "Stop sequences" },
|
|
288
|
+
stream: { type: "boolean", default: false, description: "Stream response" },
|
|
289
|
+
seed: { type: "number", description: "Random seed" }
|
|
290
|
+
},
|
|
291
|
+
bedrock: {
|
|
292
|
+
// Converse API inferenceConfig params
|
|
293
|
+
temperature: { type: "number", min: 0, max: 1, default: 0.7, description: "Controls randomness" },
|
|
294
|
+
maxTokens: { type: "number", min: 1, default: 4096, description: "Maximum output tokens" },
|
|
295
|
+
topP: { type: "number", min: 0, max: 1, default: 1, description: "Nucleus sampling" },
|
|
296
|
+
topK: { type: "number", min: 0, default: 40, description: "Top-K sampling" },
|
|
297
|
+
stopSequences: { type: "string", description: "Stop sequences" },
|
|
298
|
+
stream: { type: "boolean", default: false, description: "Stream response" },
|
|
299
|
+
cache_control: { type: "string", values: ["ephemeral"], default: "ephemeral", description: "Cache control" },
|
|
300
|
+
cache_ttl: { type: "string", values: ["5m", "1h"], default: "5m", description: "Cache TTL" }
|
|
301
|
+
},
|
|
302
|
+
openrouter: {
|
|
303
|
+
// Loose validation — proxies to many providers with varying ranges
|
|
304
|
+
temperature: { type: "number", min: 0, max: 2, default: 0.7, description: "Controls randomness" },
|
|
305
|
+
max_tokens: { type: "number", min: 1, default: 4096, description: "Maximum output tokens" },
|
|
306
|
+
top_p: { type: "number", min: 0, max: 1, default: 1, description: "Nucleus sampling" },
|
|
307
|
+
top_k: { type: "number", min: 0, default: 40, description: "Top-K sampling" },
|
|
308
|
+
frequency_penalty: { type: "number", min: -2, max: 2, default: 0, description: "Penalize frequent tokens" },
|
|
309
|
+
presence_penalty: { type: "number", min: -2, max: 2, default: 0, description: "Penalize repeated topics" },
|
|
310
|
+
stop: { type: "string", description: "Stop sequences" },
|
|
311
|
+
n: { type: "number", min: 1, default: 1, description: "Completions count" },
|
|
312
|
+
seed: { type: "number", description: "Random seed" },
|
|
313
|
+
stream: { type: "boolean", default: false, description: "Stream response" },
|
|
314
|
+
reasoning_effort: {
|
|
315
|
+
type: "string",
|
|
316
|
+
values: ["none", "minimal", "low", "medium", "high", "xhigh"],
|
|
317
|
+
default: "medium",
|
|
318
|
+
description: "Reasoning effort"
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
vercel: {
|
|
322
|
+
// Loose validation — proxies to many providers with varying ranges
|
|
323
|
+
temperature: { type: "number", min: 0, max: 2, default: 0.7, description: "Controls randomness" },
|
|
324
|
+
max_tokens: { type: "number", min: 1, default: 4096, description: "Maximum output tokens" },
|
|
325
|
+
top_p: { type: "number", min: 0, max: 1, default: 1, description: "Nucleus sampling" },
|
|
326
|
+
top_k: { type: "number", min: 0, default: 40, description: "Top-K sampling" },
|
|
327
|
+
frequency_penalty: { type: "number", min: -2, max: 2, default: 0, description: "Penalize frequent tokens" },
|
|
328
|
+
presence_penalty: { type: "number", min: -2, max: 2, default: 0, description: "Penalize repeated topics" },
|
|
329
|
+
stop: { type: "string", description: "Stop sequences" },
|
|
330
|
+
n: { type: "number", min: 1, default: 1, description: "Completions count" },
|
|
331
|
+
seed: { type: "number", description: "Random seed" },
|
|
332
|
+
stream: { type: "boolean", default: false, description: "Stream response" },
|
|
333
|
+
reasoning_effort: {
|
|
334
|
+
type: "string",
|
|
335
|
+
values: ["none", "minimal", "low", "medium", "high", "xhigh"],
|
|
336
|
+
default: "medium",
|
|
337
|
+
description: "Reasoning effort"
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
function isReasoningModel(model) {
|
|
342
|
+
const name = model.includes("/") ? model.split("/").pop() : model;
|
|
343
|
+
return /^o[134]/.test(name);
|
|
344
|
+
}
|
|
345
|
+
function canHostOpenAIModels(provider) {
|
|
346
|
+
return provider === "openai" || provider === "openrouter" || provider === "vercel";
|
|
347
|
+
}
|
|
348
|
+
function isGatewayProvider(provider) {
|
|
349
|
+
return provider === "openrouter" || provider === "vercel";
|
|
350
|
+
}
|
|
351
|
+
function detectGatewaySubProvider(model) {
|
|
352
|
+
const slash = model.indexOf("/");
|
|
353
|
+
if (slash < 1) return void 0;
|
|
354
|
+
const prefix = model.slice(0, slash);
|
|
355
|
+
const direct = ["openai", "anthropic", "google", "mistral", "cohere"];
|
|
356
|
+
return direct.find((p) => p === prefix);
|
|
357
|
+
}
|
|
358
|
+
var REASONING_MODEL_UNSUPPORTED = /* @__PURE__ */ new Set([
|
|
359
|
+
"temperature",
|
|
360
|
+
"top_p",
|
|
361
|
+
"frequency_penalty",
|
|
362
|
+
"presence_penalty",
|
|
363
|
+
"n"
|
|
364
|
+
]);
|
|
365
|
+
function detectBedrockModelFamily(model) {
|
|
366
|
+
const parts = model.split(".");
|
|
367
|
+
let prefix = parts[0];
|
|
368
|
+
if (["us", "eu", "apac", "global"].includes(prefix) && parts.length > 1) {
|
|
369
|
+
prefix = parts[1];
|
|
370
|
+
}
|
|
371
|
+
const families = [
|
|
372
|
+
"anthropic",
|
|
373
|
+
"meta",
|
|
374
|
+
"amazon",
|
|
375
|
+
"mistral",
|
|
376
|
+
"cohere",
|
|
377
|
+
"ai21"
|
|
378
|
+
];
|
|
379
|
+
return families.find((f) => prefix === f);
|
|
380
|
+
}
|
|
381
|
+
function bedrockSupportsCaching(model) {
|
|
382
|
+
const family = detectBedrockModelFamily(model);
|
|
383
|
+
if (family === "anthropic") return true;
|
|
384
|
+
if (family === "amazon" && model.includes("nova")) return true;
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
var CACHE_VALUES = {
|
|
388
|
+
openai: void 0,
|
|
389
|
+
// OpenAI auto-caches; no explicit param
|
|
390
|
+
anthropic: "ephemeral",
|
|
391
|
+
google: void 0,
|
|
392
|
+
// Google uses explicit caching API, not a param
|
|
393
|
+
mistral: void 0,
|
|
394
|
+
cohere: void 0,
|
|
395
|
+
bedrock: "ephemeral",
|
|
396
|
+
// Supported for Claude models on Bedrock
|
|
397
|
+
openrouter: void 0,
|
|
398
|
+
// Depends on underlying provider
|
|
399
|
+
vercel: void 0
|
|
400
|
+
// Depends on underlying provider
|
|
401
|
+
};
|
|
402
|
+
var CACHE_TTLS = {
|
|
403
|
+
openai: void 0,
|
|
404
|
+
anthropic: ["5m", "1h"],
|
|
405
|
+
google: void 0,
|
|
406
|
+
mistral: void 0,
|
|
407
|
+
cohere: void 0,
|
|
408
|
+
bedrock: ["5m", "1h"],
|
|
409
|
+
// Claude on Bedrock uses same TTLs as direct Anthropic
|
|
410
|
+
openrouter: void 0,
|
|
411
|
+
vercel: void 0
|
|
412
|
+
};
|
|
413
|
+
var DURATION_RE = /^\d+[mh]$/;
|
|
7
414
|
|
|
415
|
+
// src/normalize.ts
|
|
416
|
+
function normalize(config, options = {}) {
|
|
417
|
+
const provider = detectProvider(config.host);
|
|
418
|
+
const subProvider = provider && isGatewayProvider(provider) ? detectGatewaySubProvider(config.model) : void 0;
|
|
419
|
+
const changes = [];
|
|
420
|
+
const params = {};
|
|
421
|
+
for (const [rawKey, value] of Object.entries(config.params)) {
|
|
422
|
+
let key = rawKey;
|
|
423
|
+
if (ALIASES[key]) {
|
|
424
|
+
const canonical = ALIASES[key];
|
|
425
|
+
if (options.verbose) {
|
|
426
|
+
changes.push({
|
|
427
|
+
from: key,
|
|
428
|
+
to: canonical,
|
|
429
|
+
value,
|
|
430
|
+
reason: `alias: "${key}" \u2192 "${canonical}"`
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
key = canonical;
|
|
434
|
+
}
|
|
435
|
+
if (key === "cache" && provider) {
|
|
436
|
+
let cacheValue = CACHE_VALUES[provider];
|
|
437
|
+
if (provider === "bedrock" && !bedrockSupportsCaching(config.model)) {
|
|
438
|
+
cacheValue = void 0;
|
|
439
|
+
}
|
|
440
|
+
if (!cacheValue) {
|
|
441
|
+
if (options.verbose) {
|
|
442
|
+
changes.push({
|
|
443
|
+
from: "cache",
|
|
444
|
+
to: "(dropped)",
|
|
445
|
+
value,
|
|
446
|
+
reason: `${provider} does not use a cache param for this model (caching is automatic or unsupported)`
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
const isBool = value === "true" || value === "1" || value === "yes";
|
|
452
|
+
const isDuration = DURATION_RE.test(value);
|
|
453
|
+
if (isBool || isDuration) {
|
|
454
|
+
const providerKey = PROVIDER_PARAMS[provider]?.["cache"] ?? "cache";
|
|
455
|
+
if (options.verbose) {
|
|
456
|
+
changes.push({
|
|
457
|
+
from: "cache",
|
|
458
|
+
to: providerKey,
|
|
459
|
+
value: cacheValue,
|
|
460
|
+
reason: `cache=${value} \u2192 ${providerKey}=${cacheValue} for ${provider}`
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
params[providerKey] = cacheValue;
|
|
464
|
+
if (isDuration && CACHE_TTLS[provider]) {
|
|
465
|
+
if (options.verbose) {
|
|
466
|
+
changes.push({
|
|
467
|
+
from: "cache",
|
|
468
|
+
to: "cache_ttl",
|
|
469
|
+
value,
|
|
470
|
+
reason: `cache=${value} \u2192 cache_ttl=${value} for ${provider}`
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
params["cache_ttl"] = value;
|
|
474
|
+
}
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
if (provider && PROVIDER_PARAMS[provider]) {
|
|
479
|
+
const providerKey = PROVIDER_PARAMS[provider][key];
|
|
480
|
+
if (providerKey && providerKey !== key) {
|
|
481
|
+
if (options.verbose) {
|
|
482
|
+
changes.push({
|
|
483
|
+
from: key,
|
|
484
|
+
to: providerKey,
|
|
485
|
+
value,
|
|
486
|
+
reason: `${provider} uses "${providerKey}" instead of "${key}"`
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
key = providerKey;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (provider && canHostOpenAIModels(provider) && isReasoningModel(config.model) && key === "max_tokens") {
|
|
493
|
+
if (options.verbose) {
|
|
494
|
+
changes.push({
|
|
495
|
+
from: "max_tokens",
|
|
496
|
+
to: "max_completion_tokens",
|
|
497
|
+
value,
|
|
498
|
+
reason: "OpenAI reasoning models use max_completion_tokens instead of max_tokens"
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
key = "max_completion_tokens";
|
|
502
|
+
}
|
|
503
|
+
params[key] = value;
|
|
504
|
+
}
|
|
505
|
+
return {
|
|
506
|
+
config: { ...config, params },
|
|
507
|
+
provider,
|
|
508
|
+
subProvider,
|
|
509
|
+
changes
|
|
510
|
+
};
|
|
511
|
+
}
|
|
8
512
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
513
|
+
// src/validate.ts
|
|
514
|
+
function buildReverseParamMap(provider) {
|
|
515
|
+
const map = {};
|
|
516
|
+
for (const [canonical, specific] of Object.entries(
|
|
517
|
+
PROVIDER_PARAMS[provider]
|
|
518
|
+
)) {
|
|
519
|
+
map[specific] = canonical;
|
|
520
|
+
}
|
|
521
|
+
return map;
|
|
522
|
+
}
|
|
523
|
+
function lookupSubProviderSpec(gatewayParamName, gatewayReverseMap, subProvider) {
|
|
524
|
+
const canonical = gatewayReverseMap[gatewayParamName] ?? gatewayParamName;
|
|
525
|
+
const subProviderKey = PROVIDER_PARAMS[subProvider]?.[canonical];
|
|
526
|
+
if (!subProviderKey) return { spec: void 0, canonical };
|
|
527
|
+
return { spec: PARAM_SPECS[subProvider]?.[subProviderKey], canonical };
|
|
528
|
+
}
|
|
529
|
+
function buildSubProviderKnownParams(gateway, subProvider) {
|
|
530
|
+
const known = /* @__PURE__ */ new Set();
|
|
531
|
+
const subProviderCanonicals = new Set(
|
|
532
|
+
Object.keys(PROVIDER_PARAMS[subProvider])
|
|
533
|
+
);
|
|
534
|
+
for (const [canonical, gatewaySpecific] of Object.entries(
|
|
535
|
+
PROVIDER_PARAMS[gateway]
|
|
536
|
+
)) {
|
|
537
|
+
if (subProviderCanonicals.has(canonical)) {
|
|
538
|
+
known.add(gatewaySpecific);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return known;
|
|
542
|
+
}
|
|
543
|
+
function validate(connectionString, options = {}) {
|
|
544
|
+
const parsed = parse(connectionString);
|
|
545
|
+
const { config, provider, subProvider } = normalize(parsed);
|
|
546
|
+
const issues = [];
|
|
547
|
+
if (!provider) {
|
|
548
|
+
issues.push({
|
|
549
|
+
param: "host",
|
|
550
|
+
value: config.host,
|
|
551
|
+
message: `Unknown provider for host "${config.host}". Validation skipped.`,
|
|
552
|
+
severity: options.strict ? "error" : "warning"
|
|
553
|
+
});
|
|
554
|
+
return issues;
|
|
555
|
+
}
|
|
556
|
+
const effectiveProvider = subProvider ?? provider;
|
|
557
|
+
const specs = PARAM_SPECS[effectiveProvider];
|
|
558
|
+
const gatewayReverseMap = subProvider ? buildReverseParamMap(provider) : void 0;
|
|
559
|
+
const knownParams = subProvider ? buildSubProviderKnownParams(provider, subProvider) : new Set(Object.values(PROVIDER_PARAMS[provider]));
|
|
560
|
+
for (const [key, value] of Object.entries(config.params)) {
|
|
561
|
+
if (canHostOpenAIModels(provider) && isReasoningModel(config.model) && REASONING_MODEL_UNSUPPORTED.has(key)) {
|
|
562
|
+
issues.push({
|
|
563
|
+
param: key,
|
|
564
|
+
value,
|
|
565
|
+
message: `"${key}" is not supported by OpenAI reasoning model "${config.model}". Use "reasoning_effort" instead of temperature for controlling output.`,
|
|
566
|
+
severity: "error"
|
|
567
|
+
});
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
if (provider === "bedrock") {
|
|
571
|
+
const family = detectBedrockModelFamily(config.model);
|
|
572
|
+
if (key === "topK" && family && family !== "anthropic" && family !== "cohere" && family !== "mistral") {
|
|
573
|
+
issues.push({
|
|
574
|
+
param: key,
|
|
575
|
+
value,
|
|
576
|
+
message: `"topK" is not supported by ${family} models on Bedrock.`,
|
|
577
|
+
severity: "error"
|
|
578
|
+
});
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
if (key === "cache_control" && !bedrockSupportsCaching(config.model)) {
|
|
582
|
+
issues.push({
|
|
583
|
+
param: key,
|
|
584
|
+
value,
|
|
585
|
+
message: `Prompt caching is only supported for Anthropic Claude and Amazon Nova models on Bedrock, not ${family ?? "unknown"} models.`,
|
|
586
|
+
severity: "error"
|
|
587
|
+
});
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
if (!knownParams.has(key) && !specs[key]) {
|
|
592
|
+
issues.push({
|
|
593
|
+
param: key,
|
|
594
|
+
value,
|
|
595
|
+
message: `Unknown param "${key}" for ${effectiveProvider}.`,
|
|
596
|
+
severity: options.strict ? "error" : "warning"
|
|
597
|
+
});
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
let spec = specs[key];
|
|
601
|
+
if (subProvider && gatewayReverseMap && !spec) {
|
|
602
|
+
const result = lookupSubProviderSpec(
|
|
603
|
+
key,
|
|
604
|
+
gatewayReverseMap,
|
|
605
|
+
subProvider
|
|
606
|
+
);
|
|
607
|
+
spec = result.spec;
|
|
608
|
+
}
|
|
609
|
+
if (!spec) continue;
|
|
610
|
+
if ((effectiveProvider === "anthropic" || provider === "bedrock" && detectBedrockModelFamily(config.model) === "anthropic") && (key === "temperature" || key === "top_p" || key === "topP")) {
|
|
611
|
+
const otherKey = key === "temperature" ? provider === "bedrock" ? "topP" : "top_p" : "temperature";
|
|
612
|
+
if (key === "temperature" && config.params[otherKey] !== void 0) {
|
|
613
|
+
issues.push({
|
|
614
|
+
param: key,
|
|
615
|
+
value,
|
|
616
|
+
message: `Cannot specify both "temperature" and "${otherKey}" for Anthropic models.`,
|
|
617
|
+
severity: "error"
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
if (spec.type === "number") {
|
|
622
|
+
const num = Number(value);
|
|
623
|
+
if (isNaN(num)) {
|
|
624
|
+
issues.push({
|
|
625
|
+
param: key,
|
|
626
|
+
value,
|
|
627
|
+
message: `"${key}" should be a number, got "${value}".`,
|
|
628
|
+
severity: "error"
|
|
629
|
+
});
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
if (spec.min !== void 0 && num < spec.min) {
|
|
633
|
+
issues.push({
|
|
634
|
+
param: key,
|
|
635
|
+
value,
|
|
636
|
+
message: `"${key}" must be >= ${spec.min}, got ${num}.`,
|
|
637
|
+
severity: "error"
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
if (spec.max !== void 0 && num > spec.max) {
|
|
641
|
+
issues.push({
|
|
642
|
+
param: key,
|
|
643
|
+
value,
|
|
644
|
+
message: `"${key}" must be <= ${spec.max}, got ${num}.`,
|
|
645
|
+
severity: "error"
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
if (spec.type === "boolean") {
|
|
650
|
+
if (!["true", "false", "0", "1"].includes(value)) {
|
|
651
|
+
issues.push({
|
|
652
|
+
param: key,
|
|
653
|
+
value,
|
|
654
|
+
message: `"${key}" should be a boolean (true/false), got "${value}".`,
|
|
655
|
+
severity: "error"
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
if (spec.type === "string" && spec.values) {
|
|
660
|
+
if (!spec.values.includes(value)) {
|
|
661
|
+
issues.push({
|
|
662
|
+
param: key,
|
|
663
|
+
value,
|
|
664
|
+
message: `"${key}" must be one of [${spec.values.join(", ")}], got "${value}".`,
|
|
665
|
+
severity: "error"
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return issues;
|
|
671
|
+
}
|
|
672
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
673
|
+
0 && (module.exports = {
|
|
674
|
+
build,
|
|
675
|
+
normalize,
|
|
676
|
+
parse,
|
|
677
|
+
validate
|
|
678
|
+
});
|
|
18
679
|
//# sourceMappingURL=index.cjs.map
|