llm-strings 1.1.1 → 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.
Files changed (54) hide show
  1. package/README.md +117 -45
  2. package/dist/ai-sdk.cjs +831 -0
  3. package/dist/ai-sdk.cjs.map +1 -0
  4. package/dist/ai-sdk.d.cts +27 -0
  5. package/dist/ai-sdk.d.ts +27 -0
  6. package/dist/ai-sdk.js +465 -0
  7. package/dist/ai-sdk.js.map +1 -0
  8. package/dist/{chunk-MPIHGH6L.js → chunk-2ARD4TFU.js} +5 -4
  9. package/dist/chunk-2ARD4TFU.js.map +1 -0
  10. package/dist/{chunk-FCEV23OT.js → chunk-BCOUH7LH.js} +9 -3
  11. package/dist/chunk-BCOUH7LH.js.map +1 -0
  12. package/dist/{chunk-UYMVUTLV.js → chunk-RPXK2A7O.js} +5 -9
  13. package/dist/chunk-RPXK2A7O.js.map +1 -0
  14. package/dist/{chunk-XID353H7.js → chunk-W4NIQY7M.js} +412 -52
  15. package/dist/chunk-W4NIQY7M.js.map +1 -0
  16. package/dist/index.cjs +1032 -12
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +9 -4
  21. package/dist/normalize.cjs +370 -4
  22. package/dist/normalize.cjs.map +1 -1
  23. package/dist/normalize.d.cts +1 -1
  24. package/dist/normalize.d.ts +1 -1
  25. package/dist/normalize.js +2 -2
  26. package/dist/parse.cjs +129 -5
  27. package/dist/parse.cjs.map +1 -1
  28. package/dist/parse.d.cts +5 -1
  29. package/dist/parse.d.ts +5 -1
  30. package/dist/parse.js +2 -1
  31. package/dist/{provider-core-DinpG40u.d.ts → provider-core-BiAl8MCV.d.cts} +20 -1
  32. package/dist/{provider-core-DinpG40u.d.cts → provider-core-BiAl8MCV.d.ts} +20 -1
  33. package/dist/providers.cjs +1145 -90
  34. package/dist/providers.cjs.map +1 -1
  35. package/dist/providers.d.cts +2 -2
  36. package/dist/providers.d.ts +2 -2
  37. package/dist/providers.js +379 -60
  38. package/dist/providers.js.map +1 -1
  39. package/dist/validate.cjs +1017 -6
  40. package/dist/validate.cjs.map +1 -1
  41. package/dist/validate.js +4 -4
  42. package/package.json +13 -2
  43. package/dist/chunk-FCEV23OT.js.map +0 -1
  44. package/dist/chunk-MGWGNZDJ.cjs +0 -116
  45. package/dist/chunk-MGWGNZDJ.cjs.map +0 -1
  46. package/dist/chunk-MPIHGH6L.js.map +0 -1
  47. package/dist/chunk-N6NVBE43.cjs +0 -37
  48. package/dist/chunk-N6NVBE43.cjs.map +0 -1
  49. package/dist/chunk-NSCBY4VD.cjs +0 -370
  50. package/dist/chunk-NSCBY4VD.cjs.map +0 -1
  51. package/dist/chunk-RSUXM42X.cjs +0 -180
  52. package/dist/chunk-RSUXM42X.cjs.map +0 -1
  53. package/dist/chunk-UYMVUTLV.js.map +0 -1
  54. package/dist/chunk-XID353H7.js.map +0 -1
package/dist/validate.cjs CHANGED
@@ -1,10 +1,1021 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
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
- var _chunkRSUXM42Xcjs = require('./chunk-RSUXM42X.cjs');
4
- require('./chunk-MGWGNZDJ.cjs');
5
- require('./chunk-N6NVBE43.cjs');
6
- require('./chunk-NSCBY4VD.cjs');
20
+ // src/validate.ts
21
+ var validate_exports = {};
22
+ __export(validate_exports, {
23
+ validate: () => validate
24
+ });
25
+ module.exports = __toCommonJS(validate_exports);
7
26
 
27
+ // src/provider-core.ts
28
+ function hasOwn(object, key) {
29
+ return Object.prototype.hasOwnProperty.call(object, key);
30
+ }
31
+ var HOST_ALIASES = {
32
+ openai: "api.openai.com",
33
+ anthropic: "api.anthropic.com",
34
+ google: "generativelanguage.googleapis.com",
35
+ aistudio: "generativelanguage.googleapis.com",
36
+ mistral: "api.mistral.ai",
37
+ cohere: "api.cohere.com",
38
+ bedrock: "bedrock-runtime.us-east-1.amazonaws.com",
39
+ openrouter: "openrouter.ai",
40
+ vercel: "gateway.ai.vercel.app",
41
+ alibaba: "dashscope-intl.aliyuncs.com",
42
+ alibabacloud: "dashscope-intl.aliyuncs.com",
43
+ dashscope: "dashscope-intl.aliyuncs.com",
44
+ fireworks: "api.fireworks.ai",
45
+ fireworksai: "api.fireworks.ai",
46
+ venice: "api.venice.ai",
47
+ parasail: "api.parasail.io",
48
+ deepinfra: "api.deepinfra.com",
49
+ atlascloud: "api.atlascloud.ai",
50
+ novita: "api.novita.ai",
51
+ novitaai: "api.novita.ai",
52
+ grok: "api.x.ai",
53
+ xai: "api.x.ai",
54
+ wandb: "api.inference.wandb.ai",
55
+ weightsandbiases: "api.inference.wandb.ai",
56
+ baidu: "qianfan.baidubce.com",
57
+ qianfan: "qianfan.baidubce.com",
58
+ vertex: "aiplatform.googleapis.com",
59
+ xiaomi: "api.xiaomimimo.com",
60
+ minimax: "api.minimax.io"
61
+ };
62
+ function readProcessEnv() {
63
+ return typeof process !== "undefined" && process.env ? process.env : {};
64
+ }
65
+ function normalizeHostValue(value) {
66
+ const trimmed = value.trim();
67
+ if (!trimmed) return trimmed;
68
+ try {
69
+ if (trimmed.includes("://")) {
70
+ return new URL(trimmed).host;
71
+ }
72
+ } catch {
73
+ }
74
+ return trimmed.replace(/^\/\//, "").split("/")[0] ?? trimmed;
75
+ }
76
+ function envHostOverride(alias, env) {
77
+ const upper = alias.toUpperCase();
78
+ const override = env[`LLM_STRINGS_${upper}_HOST`] ?? env[`LLM_STRINGS_HOST_${upper}`];
79
+ return override?.trim() ? override : void 0;
80
+ }
81
+ function resolveHostAlias(host, env = readProcessEnv()) {
82
+ const normalizedHost = host.toLowerCase();
83
+ if (!hasOwn(HOST_ALIASES, normalizedHost)) {
84
+ return { host };
85
+ }
86
+ const alias = normalizedHost;
87
+ const override = envHostOverride(alias, env);
88
+ return {
89
+ host: normalizeHostValue(override ?? HOST_ALIASES[alias]),
90
+ alias
91
+ };
92
+ }
93
+ function providerFromHostAlias(alias) {
94
+ const normalizedAlias = alias.toLowerCase();
95
+ if (hasOwn(PROVIDER_PARAMS, normalizedAlias)) {
96
+ return normalizedAlias;
97
+ }
98
+ return void 0;
99
+ }
100
+ function detectProvider(host) {
101
+ host = host.toLowerCase();
102
+ if (host.includes("openrouter")) return "openrouter";
103
+ if (host.includes("gateway.ai.vercel")) return "vercel";
104
+ if (host.includes("amazonaws") || host.includes("bedrock")) return "bedrock";
105
+ if (host.includes("openai")) return "openai";
106
+ if (host.includes("anthropic") || host.includes("claude")) return "anthropic";
107
+ if (host.includes("googleapis") || host.includes("google")) return "google";
108
+ if (host.includes("mistral")) return "mistral";
109
+ if (host.includes("cohere")) return "cohere";
110
+ return void 0;
111
+ }
112
+ var ALIASES = {
113
+ // temperature
114
+ temp: "temperature",
115
+ // max_tokens
116
+ max: "max_tokens",
117
+ max_out: "max_tokens",
118
+ max_output: "max_tokens",
119
+ max_output_tokens: "max_tokens",
120
+ max_completion_tokens: "max_tokens",
121
+ maxOutputTokens: "max_tokens",
122
+ maxTokens: "max_tokens",
123
+ // top_p
124
+ topp: "top_p",
125
+ topP: "top_p",
126
+ nucleus: "top_p",
127
+ // top_k
128
+ topk: "top_k",
129
+ topK: "top_k",
130
+ // frequency_penalty
131
+ freq: "frequency_penalty",
132
+ freq_penalty: "frequency_penalty",
133
+ frequencyPenalty: "frequency_penalty",
134
+ repetition_penalty: "frequency_penalty",
135
+ // presence_penalty
136
+ pres: "presence_penalty",
137
+ pres_penalty: "presence_penalty",
138
+ presencePenalty: "presence_penalty",
139
+ // stop
140
+ stop_sequences: "stop",
141
+ stopSequences: "stop",
142
+ stop_sequence: "stop",
143
+ // seed
144
+ random_seed: "seed",
145
+ randomSeed: "seed",
146
+ // n (completions count)
147
+ candidateCount: "n",
148
+ candidate_count: "n",
149
+ num_completions: "n",
150
+ // effort / reasoning
151
+ reasoning_effort: "effort",
152
+ reasoning: "effort",
153
+ // cache
154
+ cache_control: "cache",
155
+ cacheControl: "cache",
156
+ cachePoint: "cache",
157
+ cache_point: "cache"
158
+ };
159
+ var PROVIDER_PARAMS = {
160
+ openai: {
161
+ temperature: "temperature",
162
+ max_tokens: "max_tokens",
163
+ top_p: "top_p",
164
+ frequency_penalty: "frequency_penalty",
165
+ presence_penalty: "presence_penalty",
166
+ stop: "stop",
167
+ n: "n",
168
+ seed: "seed",
169
+ stream: "stream",
170
+ effort: "reasoning_effort"
171
+ },
172
+ anthropic: {
173
+ temperature: "temperature",
174
+ max_tokens: "max_tokens",
175
+ top_p: "top_p",
176
+ top_k: "top_k",
177
+ stop: "stop_sequences",
178
+ stream: "stream",
179
+ effort: "effort",
180
+ cache: "cache_control",
181
+ cache_ttl: "cache_ttl"
182
+ },
183
+ google: {
184
+ temperature: "temperature",
185
+ max_tokens: "maxOutputTokens",
186
+ top_p: "topP",
187
+ top_k: "topK",
188
+ frequency_penalty: "frequencyPenalty",
189
+ presence_penalty: "presencePenalty",
190
+ stop: "stopSequences",
191
+ n: "candidateCount",
192
+ stream: "stream",
193
+ seed: "seed",
194
+ responseMimeType: "responseMimeType",
195
+ responseSchema: "responseSchema"
196
+ },
197
+ mistral: {
198
+ temperature: "temperature",
199
+ max_tokens: "max_tokens",
200
+ top_p: "top_p",
201
+ frequency_penalty: "frequency_penalty",
202
+ presence_penalty: "presence_penalty",
203
+ stop: "stop",
204
+ n: "n",
205
+ seed: "random_seed",
206
+ stream: "stream",
207
+ safe_prompt: "safe_prompt",
208
+ min_tokens: "min_tokens"
209
+ },
210
+ cohere: {
211
+ temperature: "temperature",
212
+ max_tokens: "max_tokens",
213
+ top_p: "p",
214
+ top_k: "k",
215
+ frequency_penalty: "frequency_penalty",
216
+ presence_penalty: "presence_penalty",
217
+ stop: "stop_sequences",
218
+ stream: "stream",
219
+ seed: "seed"
220
+ },
221
+ bedrock: {
222
+ // Bedrock Converse API uses camelCase
223
+ temperature: "temperature",
224
+ max_tokens: "maxTokens",
225
+ top_p: "topP",
226
+ top_k: "topK",
227
+ // Claude models via additionalModelRequestFields
228
+ stop: "stopSequences",
229
+ stream: "stream",
230
+ cache: "cache_control",
231
+ cache_ttl: "cache_ttl"
232
+ },
233
+ openrouter: {
234
+ // OpenAI-compatible API with extra routing params
235
+ temperature: "temperature",
236
+ max_tokens: "max_tokens",
237
+ top_p: "top_p",
238
+ top_k: "top_k",
239
+ frequency_penalty: "frequency_penalty",
240
+ presence_penalty: "presence_penalty",
241
+ stop: "stop",
242
+ n: "n",
243
+ seed: "seed",
244
+ stream: "stream",
245
+ effort: "reasoning_effort"
246
+ },
247
+ vercel: {
248
+ // OpenAI-compatible gateway
249
+ temperature: "temperature",
250
+ max_tokens: "max_tokens",
251
+ top_p: "top_p",
252
+ top_k: "top_k",
253
+ frequency_penalty: "frequency_penalty",
254
+ presence_penalty: "presence_penalty",
255
+ stop: "stop",
256
+ n: "n",
257
+ seed: "seed",
258
+ stream: "stream",
259
+ effort: "reasoning_effort"
260
+ }
261
+ };
262
+ var PARAM_SPECS = {
263
+ openai: {
264
+ temperature: {
265
+ type: "number",
266
+ min: 0,
267
+ max: 2,
268
+ default: 0.7,
269
+ description: "Controls randomness"
270
+ },
271
+ max_tokens: {
272
+ type: "number",
273
+ min: 1,
274
+ default: 4096,
275
+ description: "Maximum output tokens"
276
+ },
277
+ top_p: {
278
+ type: "number",
279
+ min: 0,
280
+ max: 1,
281
+ default: 1,
282
+ description: "Nucleus sampling"
283
+ },
284
+ frequency_penalty: {
285
+ type: "number",
286
+ min: -2,
287
+ max: 2,
288
+ default: 0,
289
+ description: "Penalize frequent tokens"
290
+ },
291
+ presence_penalty: {
292
+ type: "number",
293
+ min: -2,
294
+ max: 2,
295
+ default: 0,
296
+ description: "Penalize repeated topics"
297
+ },
298
+ stop: { type: "string", description: "Stop sequences" },
299
+ n: { type: "number", min: 1, default: 1, description: "Completions count" },
300
+ seed: { type: "number", description: "Random seed" },
301
+ stream: { type: "boolean", default: false, description: "Stream response" },
302
+ reasoning_effort: {
303
+ type: "string",
304
+ values: ["none", "minimal", "low", "medium", "high", "xhigh"],
305
+ default: "medium",
306
+ description: "Reasoning effort"
307
+ }
308
+ },
309
+ anthropic: {
310
+ temperature: {
311
+ type: "number",
312
+ min: 0,
313
+ max: 1,
314
+ default: 0.7,
315
+ description: "Controls randomness"
316
+ },
317
+ max_tokens: {
318
+ type: "number",
319
+ min: 1,
320
+ default: 4096,
321
+ description: "Maximum output tokens"
322
+ },
323
+ top_p: {
324
+ type: "number",
325
+ min: 0,
326
+ max: 1,
327
+ default: 1,
328
+ description: "Nucleus sampling"
329
+ },
330
+ top_k: {
331
+ type: "number",
332
+ min: 0,
333
+ default: 40,
334
+ description: "Top-K sampling"
335
+ },
336
+ stop_sequences: { type: "string", description: "Stop sequences" },
337
+ stream: { type: "boolean", default: false, description: "Stream response" },
338
+ effort: {
339
+ type: "string",
340
+ values: ["low", "medium", "high", "max"],
341
+ default: "medium",
342
+ description: "Thinking effort"
343
+ },
344
+ cache_control: {
345
+ type: "string",
346
+ values: ["ephemeral"],
347
+ default: "ephemeral",
348
+ description: "Cache control"
349
+ },
350
+ cache_ttl: {
351
+ type: "string",
352
+ values: ["5m", "1h"],
353
+ default: "5m",
354
+ description: "Cache TTL"
355
+ }
356
+ },
357
+ google: {
358
+ temperature: {
359
+ type: "number",
360
+ min: 0,
361
+ max: 2,
362
+ default: 0.7,
363
+ description: "Controls randomness"
364
+ },
365
+ maxOutputTokens: {
366
+ type: "number",
367
+ min: 1,
368
+ default: 4096,
369
+ description: "Maximum output tokens"
370
+ },
371
+ topP: {
372
+ type: "number",
373
+ min: 0,
374
+ max: 1,
375
+ default: 1,
376
+ description: "Nucleus sampling"
377
+ },
378
+ topK: {
379
+ type: "number",
380
+ min: 0,
381
+ default: 40,
382
+ description: "Top-K sampling"
383
+ },
384
+ frequencyPenalty: {
385
+ type: "number",
386
+ min: -2,
387
+ max: 2,
388
+ default: 0,
389
+ description: "Penalize frequent tokens"
390
+ },
391
+ presencePenalty: {
392
+ type: "number",
393
+ min: -2,
394
+ max: 2,
395
+ default: 0,
396
+ description: "Penalize repeated topics"
397
+ },
398
+ stopSequences: { type: "string", description: "Stop sequences" },
399
+ candidateCount: {
400
+ type: "number",
401
+ min: 1,
402
+ default: 1,
403
+ description: "Candidate count"
404
+ },
405
+ stream: { type: "boolean", default: false, description: "Stream response" },
406
+ seed: { type: "number", description: "Random seed" },
407
+ responseMimeType: { type: "string", description: "Response MIME type" },
408
+ responseSchema: { type: "string", description: "Response schema" }
409
+ },
410
+ mistral: {
411
+ temperature: {
412
+ type: "number",
413
+ min: 0,
414
+ max: 1,
415
+ default: 0.7,
416
+ description: "Controls randomness"
417
+ },
418
+ max_tokens: {
419
+ type: "number",
420
+ min: 1,
421
+ default: 4096,
422
+ description: "Maximum output tokens"
423
+ },
424
+ top_p: {
425
+ type: "number",
426
+ min: 0,
427
+ max: 1,
428
+ default: 1,
429
+ description: "Nucleus sampling"
430
+ },
431
+ frequency_penalty: {
432
+ type: "number",
433
+ min: -2,
434
+ max: 2,
435
+ default: 0,
436
+ description: "Penalize frequent tokens"
437
+ },
438
+ presence_penalty: {
439
+ type: "number",
440
+ min: -2,
441
+ max: 2,
442
+ default: 0,
443
+ description: "Penalize repeated topics"
444
+ },
445
+ stop: { type: "string", description: "Stop sequences" },
446
+ n: { type: "number", min: 1, default: 1, description: "Completions count" },
447
+ random_seed: { type: "number", description: "Random seed" },
448
+ stream: { type: "boolean", default: false, description: "Stream response" },
449
+ safe_prompt: {
450
+ type: "boolean",
451
+ default: false,
452
+ description: "Enable safe prompt"
453
+ },
454
+ min_tokens: {
455
+ type: "number",
456
+ min: 0,
457
+ default: 0,
458
+ description: "Minimum tokens"
459
+ }
460
+ },
461
+ cohere: {
462
+ temperature: {
463
+ type: "number",
464
+ min: 0,
465
+ max: 1,
466
+ default: 0.7,
467
+ description: "Controls randomness"
468
+ },
469
+ max_tokens: {
470
+ type: "number",
471
+ min: 1,
472
+ default: 4096,
473
+ description: "Maximum output tokens"
474
+ },
475
+ p: {
476
+ type: "number",
477
+ min: 0,
478
+ max: 1,
479
+ default: 1,
480
+ description: "Nucleus sampling (p)"
481
+ },
482
+ k: {
483
+ type: "number",
484
+ min: 0,
485
+ max: 500,
486
+ default: 40,
487
+ description: "Top-K sampling (k)"
488
+ },
489
+ frequency_penalty: {
490
+ type: "number",
491
+ min: 0,
492
+ max: 1,
493
+ default: 0,
494
+ description: "Penalize frequent tokens"
495
+ },
496
+ presence_penalty: {
497
+ type: "number",
498
+ min: 0,
499
+ max: 1,
500
+ default: 0,
501
+ description: "Penalize repeated topics"
502
+ },
503
+ stop_sequences: { type: "string", description: "Stop sequences" },
504
+ stream: { type: "boolean", default: false, description: "Stream response" },
505
+ seed: { type: "number", description: "Random seed" }
506
+ },
507
+ bedrock: {
508
+ // Converse API inferenceConfig params
509
+ temperature: {
510
+ type: "number",
511
+ min: 0,
512
+ max: 1,
513
+ default: 0.7,
514
+ description: "Controls randomness"
515
+ },
516
+ maxTokens: {
517
+ type: "number",
518
+ min: 1,
519
+ default: 4096,
520
+ description: "Maximum output tokens"
521
+ },
522
+ topP: {
523
+ type: "number",
524
+ min: 0,
525
+ max: 1,
526
+ default: 1,
527
+ description: "Nucleus sampling"
528
+ },
529
+ topK: {
530
+ type: "number",
531
+ min: 0,
532
+ default: 40,
533
+ description: "Top-K sampling"
534
+ },
535
+ stopSequences: { type: "string", description: "Stop sequences" },
536
+ stream: { type: "boolean", default: false, description: "Stream response" },
537
+ cache_control: {
538
+ type: "string",
539
+ values: ["ephemeral"],
540
+ default: "ephemeral",
541
+ description: "Cache control"
542
+ },
543
+ cache_ttl: {
544
+ type: "string",
545
+ values: ["5m", "1h"],
546
+ default: "5m",
547
+ description: "Cache TTL"
548
+ }
549
+ },
550
+ openrouter: {
551
+ // Loose validation — proxies to many providers with varying ranges
552
+ temperature: {
553
+ type: "number",
554
+ min: 0,
555
+ max: 2,
556
+ default: 0.7,
557
+ description: "Controls randomness"
558
+ },
559
+ max_tokens: {
560
+ type: "number",
561
+ min: 1,
562
+ default: 4096,
563
+ description: "Maximum output tokens"
564
+ },
565
+ top_p: {
566
+ type: "number",
567
+ min: 0,
568
+ max: 1,
569
+ default: 1,
570
+ description: "Nucleus sampling"
571
+ },
572
+ top_k: {
573
+ type: "number",
574
+ min: 0,
575
+ default: 40,
576
+ description: "Top-K sampling"
577
+ },
578
+ frequency_penalty: {
579
+ type: "number",
580
+ min: -2,
581
+ max: 2,
582
+ default: 0,
583
+ description: "Penalize frequent tokens"
584
+ },
585
+ presence_penalty: {
586
+ type: "number",
587
+ min: -2,
588
+ max: 2,
589
+ default: 0,
590
+ description: "Penalize repeated topics"
591
+ },
592
+ stop: { type: "string", description: "Stop sequences" },
593
+ n: { type: "number", min: 1, default: 1, description: "Completions count" },
594
+ seed: { type: "number", description: "Random seed" },
595
+ stream: { type: "boolean", default: false, description: "Stream response" },
596
+ reasoning_effort: {
597
+ type: "string",
598
+ values: ["none", "minimal", "low", "medium", "high", "xhigh"],
599
+ default: "medium",
600
+ description: "Reasoning effort"
601
+ }
602
+ },
603
+ vercel: {
604
+ // Loose validation — proxies to many providers with varying ranges
605
+ temperature: {
606
+ type: "number",
607
+ min: 0,
608
+ max: 2,
609
+ default: 0.7,
610
+ description: "Controls randomness"
611
+ },
612
+ max_tokens: {
613
+ type: "number",
614
+ min: 1,
615
+ default: 4096,
616
+ description: "Maximum output tokens"
617
+ },
618
+ top_p: {
619
+ type: "number",
620
+ min: 0,
621
+ max: 1,
622
+ default: 1,
623
+ description: "Nucleus sampling"
624
+ },
625
+ top_k: {
626
+ type: "number",
627
+ min: 0,
628
+ default: 40,
629
+ description: "Top-K sampling"
630
+ },
631
+ frequency_penalty: {
632
+ type: "number",
633
+ min: -2,
634
+ max: 2,
635
+ default: 0,
636
+ description: "Penalize frequent tokens"
637
+ },
638
+ presence_penalty: {
639
+ type: "number",
640
+ min: -2,
641
+ max: 2,
642
+ default: 0,
643
+ description: "Penalize repeated topics"
644
+ },
645
+ stop: { type: "string", description: "Stop sequences" },
646
+ n: { type: "number", min: 1, default: 1, description: "Completions count" },
647
+ seed: { type: "number", description: "Random seed" },
648
+ stream: { type: "boolean", default: false, description: "Stream response" },
649
+ reasoning_effort: {
650
+ type: "string",
651
+ values: ["none", "minimal", "low", "medium", "high", "xhigh"],
652
+ default: "medium",
653
+ description: "Reasoning effort"
654
+ }
655
+ }
656
+ };
657
+ function isReasoningModel(model) {
658
+ const name = model.includes("/") ? model.split("/").pop() : model;
659
+ return /^o[134]/.test(name);
660
+ }
661
+ function canHostOpenAIModels(provider) {
662
+ return provider === "openai" || provider === "openrouter" || provider === "vercel";
663
+ }
664
+ function isGatewayProvider(provider) {
665
+ return provider === "openrouter" || provider === "vercel";
666
+ }
667
+ function detectGatewaySubProvider(model) {
668
+ const slash = model.indexOf("/");
669
+ if (slash < 1) return void 0;
670
+ const prefix = model.slice(0, slash);
671
+ const direct = [
672
+ "openai",
673
+ "anthropic",
674
+ "google",
675
+ "mistral",
676
+ "cohere"
677
+ ];
678
+ return direct.find((p) => p === prefix);
679
+ }
680
+ var REASONING_MODEL_UNSUPPORTED = /* @__PURE__ */ new Set([
681
+ "temperature",
682
+ "top_p",
683
+ "frequency_penalty",
684
+ "presence_penalty",
685
+ "n"
686
+ ]);
687
+ function detectBedrockModelFamily(model) {
688
+ const parts = model.split(".");
689
+ let prefix = parts[0];
690
+ if (["us", "eu", "apac", "global"].includes(prefix) && parts.length > 1) {
691
+ prefix = parts[1];
692
+ }
693
+ const families = [
694
+ "anthropic",
695
+ "meta",
696
+ "amazon",
697
+ "mistral",
698
+ "cohere",
699
+ "ai21"
700
+ ];
701
+ return families.find((f) => prefix === f);
702
+ }
703
+ function bedrockSupportsCaching(model) {
704
+ const family = detectBedrockModelFamily(model);
705
+ if (family === "anthropic") return true;
706
+ if (family === "amazon" && model.includes("nova")) return true;
707
+ return false;
708
+ }
709
+ var CACHE_VALUES = {
710
+ openai: void 0,
711
+ // OpenAI auto-caches; no explicit param
712
+ anthropic: "ephemeral",
713
+ google: void 0,
714
+ // Google uses explicit caching API, not a param
715
+ mistral: void 0,
716
+ cohere: void 0,
717
+ bedrock: "ephemeral",
718
+ // Supported for Claude models on Bedrock
719
+ openrouter: void 0,
720
+ // Depends on underlying provider
721
+ vercel: void 0
722
+ // Depends on underlying provider
723
+ };
724
+ var CACHE_TTLS = {
725
+ openai: void 0,
726
+ anthropic: ["5m", "1h"],
727
+ google: void 0,
728
+ mistral: void 0,
729
+ cohere: void 0,
730
+ bedrock: ["5m", "1h"],
731
+ // Claude on Bedrock uses same TTLs as direct Anthropic
732
+ openrouter: void 0,
733
+ vercel: void 0
734
+ };
735
+ var DURATION_RE = /^\d+[mh]$/;
8
736
 
9
- exports.validate = _chunkRSUXM42Xcjs.validate;
737
+ // src/parse.ts
738
+ function parse(connectionString) {
739
+ const url = new URL(connectionString);
740
+ if (url.protocol !== "llm:") {
741
+ throw new Error(
742
+ `Invalid scheme: expected "llm://", got "${url.protocol}//"`
743
+ );
744
+ }
745
+ const { host, alias: hostAlias } = resolveHostAlias(url.host);
746
+ const model = url.pathname.replace(/^\//, "");
747
+ const label = url.username || void 0;
748
+ const apiKey = url.password || void 0;
749
+ const params = {};
750
+ for (const [key, value] of url.searchParams) {
751
+ params[key] = value;
752
+ }
753
+ return {
754
+ raw: connectionString,
755
+ host,
756
+ hostAlias,
757
+ model,
758
+ label,
759
+ apiKey,
760
+ params
761
+ };
762
+ }
763
+
764
+ // src/normalize.ts
765
+ function normalize(config, options = {}) {
766
+ const provider = (config.hostAlias ? providerFromHostAlias(config.hostAlias) : void 0) ?? detectProvider(config.host);
767
+ const subProvider = provider && isGatewayProvider(provider) ? detectGatewaySubProvider(config.model) : void 0;
768
+ const changes = [];
769
+ const params = {};
770
+ for (const [rawKey, value] of Object.entries(config.params)) {
771
+ let key = rawKey;
772
+ if (ALIASES[key]) {
773
+ const canonical = ALIASES[key];
774
+ if (options.verbose) {
775
+ changes.push({
776
+ from: key,
777
+ to: canonical,
778
+ value,
779
+ reason: `alias: "${key}" \u2192 "${canonical}"`
780
+ });
781
+ }
782
+ key = canonical;
783
+ }
784
+ if (key === "cache" && provider) {
785
+ let cacheValue = CACHE_VALUES[provider];
786
+ if (provider === "bedrock" && !bedrockSupportsCaching(config.model)) {
787
+ cacheValue = void 0;
788
+ }
789
+ if (!cacheValue) {
790
+ if (options.verbose) {
791
+ changes.push({
792
+ from: "cache",
793
+ to: "(dropped)",
794
+ value,
795
+ reason: `${provider} does not use a cache param for this model (caching is automatic or unsupported)`
796
+ });
797
+ }
798
+ continue;
799
+ }
800
+ const isBool = value === "true" || value === "1" || value === "yes";
801
+ const isDuration = DURATION_RE.test(value);
802
+ if (isBool || isDuration) {
803
+ const providerKey = PROVIDER_PARAMS[provider]?.["cache"] ?? "cache";
804
+ if (options.verbose) {
805
+ changes.push({
806
+ from: "cache",
807
+ to: providerKey,
808
+ value: cacheValue,
809
+ reason: `cache=${value} \u2192 ${providerKey}=${cacheValue} for ${provider}`
810
+ });
811
+ }
812
+ params[providerKey] = cacheValue;
813
+ if (isDuration && CACHE_TTLS[provider]) {
814
+ if (options.verbose) {
815
+ changes.push({
816
+ from: "cache",
817
+ to: "cache_ttl",
818
+ value,
819
+ reason: `cache=${value} \u2192 cache_ttl=${value} for ${provider}`
820
+ });
821
+ }
822
+ params["cache_ttl"] = value;
823
+ }
824
+ continue;
825
+ }
826
+ }
827
+ if (provider && PROVIDER_PARAMS[provider]) {
828
+ const providerKey = PROVIDER_PARAMS[provider][key];
829
+ if (providerKey && providerKey !== key) {
830
+ if (options.verbose) {
831
+ changes.push({
832
+ from: key,
833
+ to: providerKey,
834
+ value,
835
+ reason: `${provider} uses "${providerKey}" instead of "${key}"`
836
+ });
837
+ }
838
+ key = providerKey;
839
+ }
840
+ }
841
+ if (provider && canHostOpenAIModels(provider) && isReasoningModel(config.model) && key === "max_tokens") {
842
+ if (options.verbose) {
843
+ changes.push({
844
+ from: "max_tokens",
845
+ to: "max_completion_tokens",
846
+ value,
847
+ reason: "OpenAI reasoning models use max_completion_tokens instead of max_tokens"
848
+ });
849
+ }
850
+ key = "max_completion_tokens";
851
+ }
852
+ params[key] = value;
853
+ }
854
+ return {
855
+ config: { ...config, params },
856
+ provider,
857
+ subProvider,
858
+ changes
859
+ };
860
+ }
861
+
862
+ // src/validate.ts
863
+ function buildReverseParamMap(provider) {
864
+ const map = {};
865
+ for (const [canonical, specific] of Object.entries(
866
+ PROVIDER_PARAMS[provider]
867
+ )) {
868
+ map[specific] = canonical;
869
+ }
870
+ return map;
871
+ }
872
+ function lookupSubProviderSpec(gatewayParamName, gatewayReverseMap, subProvider) {
873
+ const canonical = gatewayReverseMap[gatewayParamName] ?? gatewayParamName;
874
+ const subProviderKey = PROVIDER_PARAMS[subProvider]?.[canonical];
875
+ if (!subProviderKey) return { spec: void 0, canonical };
876
+ return { spec: PARAM_SPECS[subProvider]?.[subProviderKey], canonical };
877
+ }
878
+ function buildSubProviderKnownParams(gateway, subProvider) {
879
+ const known = /* @__PURE__ */ new Set();
880
+ const subProviderCanonicals = new Set(
881
+ Object.keys(PROVIDER_PARAMS[subProvider])
882
+ );
883
+ for (const [canonical, gatewaySpecific] of Object.entries(
884
+ PROVIDER_PARAMS[gateway]
885
+ )) {
886
+ if (subProviderCanonicals.has(canonical)) {
887
+ known.add(gatewaySpecific);
888
+ }
889
+ }
890
+ return known;
891
+ }
892
+ function validate(connectionString, options = {}) {
893
+ const parsed = parse(connectionString);
894
+ const { config, provider, subProvider } = normalize(parsed);
895
+ const issues = [];
896
+ if (!provider) {
897
+ issues.push({
898
+ param: "host",
899
+ value: config.host,
900
+ message: `Unknown provider for host "${config.host}". Validation skipped.`,
901
+ severity: options.strict ? "error" : "warning"
902
+ });
903
+ return issues;
904
+ }
905
+ const effectiveProvider = subProvider ?? provider;
906
+ const specs = PARAM_SPECS[effectiveProvider];
907
+ const gatewayReverseMap = subProvider ? buildReverseParamMap(provider) : void 0;
908
+ const knownParams = subProvider ? buildSubProviderKnownParams(provider, subProvider) : new Set(Object.values(PROVIDER_PARAMS[provider]));
909
+ for (const [key, value] of Object.entries(config.params)) {
910
+ if (canHostOpenAIModels(provider) && isReasoningModel(config.model) && REASONING_MODEL_UNSUPPORTED.has(key)) {
911
+ issues.push({
912
+ param: key,
913
+ value,
914
+ message: `"${key}" is not supported by OpenAI reasoning model "${config.model}". Use "reasoning_effort" instead of temperature for controlling output.`,
915
+ severity: "error"
916
+ });
917
+ continue;
918
+ }
919
+ if (provider === "bedrock") {
920
+ const family = detectBedrockModelFamily(config.model);
921
+ if (key === "topK" && family && family !== "anthropic" && family !== "cohere" && family !== "mistral") {
922
+ issues.push({
923
+ param: key,
924
+ value,
925
+ message: `"topK" is not supported by ${family} models on Bedrock.`,
926
+ severity: "error"
927
+ });
928
+ continue;
929
+ }
930
+ if (key === "cache_control" && !bedrockSupportsCaching(config.model)) {
931
+ issues.push({
932
+ param: key,
933
+ value,
934
+ message: `Prompt caching is only supported for Anthropic Claude and Amazon Nova models on Bedrock, not ${family ?? "unknown"} models.`,
935
+ severity: "error"
936
+ });
937
+ continue;
938
+ }
939
+ }
940
+ if (!knownParams.has(key) && !specs[key]) {
941
+ issues.push({
942
+ param: key,
943
+ value,
944
+ message: `Unknown param "${key}" for ${effectiveProvider}.`,
945
+ severity: options.strict ? "error" : "warning"
946
+ });
947
+ continue;
948
+ }
949
+ let spec = specs[key];
950
+ if (subProvider && gatewayReverseMap && !spec) {
951
+ const result = lookupSubProviderSpec(key, gatewayReverseMap, subProvider);
952
+ spec = result.spec;
953
+ }
954
+ if (!spec) continue;
955
+ if ((effectiveProvider === "anthropic" || provider === "bedrock" && detectBedrockModelFamily(config.model) === "anthropic") && (key === "temperature" || key === "top_p" || key === "topP")) {
956
+ const otherKey = key === "temperature" ? provider === "bedrock" ? "topP" : "top_p" : "temperature";
957
+ if (key === "temperature" && config.params[otherKey] !== void 0) {
958
+ issues.push({
959
+ param: key,
960
+ value,
961
+ message: `Cannot specify both "temperature" and "${otherKey}" for Anthropic models.`,
962
+ severity: "error"
963
+ });
964
+ }
965
+ }
966
+ if (spec.type === "number") {
967
+ const num = Number(value);
968
+ if (isNaN(num)) {
969
+ issues.push({
970
+ param: key,
971
+ value,
972
+ message: `"${key}" should be a number, got "${value}".`,
973
+ severity: "error"
974
+ });
975
+ continue;
976
+ }
977
+ if (spec.min !== void 0 && num < spec.min) {
978
+ issues.push({
979
+ param: key,
980
+ value,
981
+ message: `"${key}" must be >= ${spec.min}, got ${num}.`,
982
+ severity: "error"
983
+ });
984
+ }
985
+ if (spec.max !== void 0 && num > spec.max) {
986
+ issues.push({
987
+ param: key,
988
+ value,
989
+ message: `"${key}" must be <= ${spec.max}, got ${num}.`,
990
+ severity: "error"
991
+ });
992
+ }
993
+ }
994
+ if (spec.type === "boolean") {
995
+ if (!["true", "false", "0", "1"].includes(value)) {
996
+ issues.push({
997
+ param: key,
998
+ value,
999
+ message: `"${key}" should be a boolean (true/false), got "${value}".`,
1000
+ severity: "error"
1001
+ });
1002
+ }
1003
+ }
1004
+ if (spec.type === "string" && spec.values) {
1005
+ if (!spec.values.includes(value)) {
1006
+ issues.push({
1007
+ param: key,
1008
+ value,
1009
+ message: `"${key}" must be one of [${spec.values.join(", ")}], got "${value}".`,
1010
+ severity: "error"
1011
+ });
1012
+ }
1013
+ }
1014
+ }
1015
+ return issues;
1016
+ }
1017
+ // Annotate the CommonJS export names for ESM import in node:
1018
+ 0 && (module.exports = {
1019
+ validate
1020
+ });
10
1021
  //# sourceMappingURL=validate.cjs.map