@contractspec/lib.ai-providers 2.9.0 → 3.1.1

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.
@@ -0,0 +1,694 @@
1
+ // @bun
2
+ // src/models.ts
3
+ var DEFAULT_MODELS = {
4
+ ollama: "llama3.2",
5
+ openai: "gpt-4o",
6
+ anthropic: "claude-sonnet-4-20250514",
7
+ mistral: "mistral-large-latest",
8
+ gemini: "gemini-2.0-flash"
9
+ };
10
+ var MODELS = [
11
+ {
12
+ id: "llama3.2",
13
+ name: "Llama 3.2",
14
+ provider: "ollama",
15
+ contextWindow: 128000,
16
+ capabilities: {
17
+ vision: false,
18
+ tools: true,
19
+ reasoning: false,
20
+ streaming: true
21
+ }
22
+ },
23
+ {
24
+ id: "codellama",
25
+ name: "Code Llama",
26
+ provider: "ollama",
27
+ contextWindow: 16000,
28
+ capabilities: {
29
+ vision: false,
30
+ tools: false,
31
+ reasoning: false,
32
+ streaming: true
33
+ }
34
+ },
35
+ {
36
+ id: "deepseek-coder",
37
+ name: "DeepSeek Coder",
38
+ provider: "ollama",
39
+ contextWindow: 16000,
40
+ capabilities: {
41
+ vision: false,
42
+ tools: false,
43
+ reasoning: false,
44
+ streaming: true
45
+ }
46
+ },
47
+ {
48
+ id: "mistral",
49
+ name: "Mistral 7B",
50
+ provider: "ollama",
51
+ contextWindow: 32000,
52
+ capabilities: {
53
+ vision: false,
54
+ tools: false,
55
+ reasoning: false,
56
+ streaming: true
57
+ }
58
+ },
59
+ {
60
+ id: "gpt-4o",
61
+ name: "GPT-4o",
62
+ provider: "openai",
63
+ contextWindow: 128000,
64
+ capabilities: {
65
+ vision: true,
66
+ tools: true,
67
+ reasoning: false,
68
+ streaming: true
69
+ },
70
+ costPerMillion: { input: 2.5, output: 10 }
71
+ },
72
+ {
73
+ id: "gpt-4o-mini",
74
+ name: "GPT-4o Mini",
75
+ provider: "openai",
76
+ contextWindow: 128000,
77
+ capabilities: {
78
+ vision: true,
79
+ tools: true,
80
+ reasoning: false,
81
+ streaming: true
82
+ },
83
+ costPerMillion: { input: 0.15, output: 0.6 }
84
+ },
85
+ {
86
+ id: "o1",
87
+ name: "o1",
88
+ provider: "openai",
89
+ contextWindow: 200000,
90
+ capabilities: {
91
+ vision: true,
92
+ tools: true,
93
+ reasoning: true,
94
+ streaming: true
95
+ },
96
+ costPerMillion: { input: 15, output: 60 }
97
+ },
98
+ {
99
+ id: "o1-mini",
100
+ name: "o1 Mini",
101
+ provider: "openai",
102
+ contextWindow: 128000,
103
+ capabilities: {
104
+ vision: false,
105
+ tools: true,
106
+ reasoning: true,
107
+ streaming: true
108
+ },
109
+ costPerMillion: { input: 3, output: 12 }
110
+ },
111
+ {
112
+ id: "claude-sonnet-4-20250514",
113
+ name: "Claude Sonnet 4",
114
+ provider: "anthropic",
115
+ contextWindow: 200000,
116
+ capabilities: {
117
+ vision: true,
118
+ tools: true,
119
+ reasoning: true,
120
+ streaming: true
121
+ },
122
+ costPerMillion: { input: 3, output: 15 }
123
+ },
124
+ {
125
+ id: "claude-3-5-sonnet-20241022",
126
+ name: "Claude 3.5 Sonnet",
127
+ provider: "anthropic",
128
+ contextWindow: 200000,
129
+ capabilities: {
130
+ vision: true,
131
+ tools: true,
132
+ reasoning: false,
133
+ streaming: true
134
+ },
135
+ costPerMillion: { input: 3, output: 15 }
136
+ },
137
+ {
138
+ id: "claude-3-5-haiku-20241022",
139
+ name: "Claude 3.5 Haiku",
140
+ provider: "anthropic",
141
+ contextWindow: 200000,
142
+ capabilities: {
143
+ vision: true,
144
+ tools: true,
145
+ reasoning: false,
146
+ streaming: true
147
+ },
148
+ costPerMillion: { input: 0.8, output: 4 }
149
+ },
150
+ {
151
+ id: "mistral-large-latest",
152
+ name: "Mistral Large",
153
+ provider: "mistral",
154
+ contextWindow: 128000,
155
+ capabilities: {
156
+ vision: false,
157
+ tools: true,
158
+ reasoning: false,
159
+ streaming: true
160
+ },
161
+ costPerMillion: { input: 2, output: 6 }
162
+ },
163
+ {
164
+ id: "mistral-medium-latest",
165
+ name: "Mistral Medium",
166
+ provider: "mistral",
167
+ contextWindow: 128000,
168
+ capabilities: {
169
+ vision: false,
170
+ tools: true,
171
+ reasoning: false,
172
+ streaming: true
173
+ }
174
+ },
175
+ {
176
+ id: "codestral-latest",
177
+ name: "Codestral",
178
+ provider: "mistral",
179
+ contextWindow: 256000,
180
+ capabilities: {
181
+ vision: false,
182
+ tools: true,
183
+ reasoning: false,
184
+ streaming: true
185
+ },
186
+ costPerMillion: { input: 0.2, output: 0.6 }
187
+ },
188
+ {
189
+ id: "devstral-small-latest",
190
+ name: "Devstral Small",
191
+ provider: "mistral",
192
+ contextWindow: 128000,
193
+ capabilities: {
194
+ vision: false,
195
+ tools: true,
196
+ reasoning: true,
197
+ streaming: true
198
+ }
199
+ },
200
+ {
201
+ id: "magistral-medium-latest",
202
+ name: "Magistral Medium",
203
+ provider: "mistral",
204
+ contextWindow: 128000,
205
+ capabilities: {
206
+ vision: false,
207
+ tools: true,
208
+ reasoning: true,
209
+ streaming: true
210
+ }
211
+ },
212
+ {
213
+ id: "pixtral-large-latest",
214
+ name: "Pixtral Large",
215
+ provider: "mistral",
216
+ contextWindow: 128000,
217
+ capabilities: {
218
+ vision: true,
219
+ tools: true,
220
+ reasoning: false,
221
+ streaming: true
222
+ }
223
+ },
224
+ {
225
+ id: "mistral-small-latest",
226
+ name: "Mistral Small",
227
+ provider: "mistral",
228
+ contextWindow: 32000,
229
+ capabilities: {
230
+ vision: false,
231
+ tools: true,
232
+ reasoning: false,
233
+ streaming: true
234
+ },
235
+ costPerMillion: { input: 0.2, output: 0.6 }
236
+ },
237
+ {
238
+ id: "gemini-2.0-flash",
239
+ name: "Gemini 2.0 Flash",
240
+ provider: "gemini",
241
+ contextWindow: 1e6,
242
+ capabilities: {
243
+ vision: true,
244
+ tools: true,
245
+ reasoning: false,
246
+ streaming: true
247
+ },
248
+ costPerMillion: { input: 0.075, output: 0.3 }
249
+ },
250
+ {
251
+ id: "gemini-2.5-pro-preview-06-05",
252
+ name: "Gemini 2.5 Pro",
253
+ provider: "gemini",
254
+ contextWindow: 1e6,
255
+ capabilities: {
256
+ vision: true,
257
+ tools: true,
258
+ reasoning: true,
259
+ streaming: true
260
+ },
261
+ costPerMillion: { input: 1.25, output: 10 }
262
+ },
263
+ {
264
+ id: "gemini-2.5-flash-preview-05-20",
265
+ name: "Gemini 2.5 Flash",
266
+ provider: "gemini",
267
+ contextWindow: 1e6,
268
+ capabilities: {
269
+ vision: true,
270
+ tools: true,
271
+ reasoning: true,
272
+ streaming: true
273
+ },
274
+ costPerMillion: { input: 0.15, output: 0.6 }
275
+ }
276
+ ];
277
+ function getModelsForProvider(provider) {
278
+ return MODELS.filter((m) => m.provider === provider);
279
+ }
280
+ function getModelInfo(modelId) {
281
+ return MODELS.find((m) => m.id === modelId);
282
+ }
283
+ function getRecommendedModels(provider) {
284
+ const normalizedProvider = provider === "claude" ? "anthropic" : provider === "custom" ? "openai" : provider;
285
+ return getModelsForProvider(normalizedProvider).map((m) => m.id);
286
+ }
287
+ function getDefaultModel(provider) {
288
+ return DEFAULT_MODELS[provider];
289
+ }
290
+
291
+ // src/factory.ts
292
+ import { createAnthropic } from "@ai-sdk/anthropic";
293
+ import { createGoogleGenerativeAI } from "@ai-sdk/google";
294
+ import { createMistral } from "@ai-sdk/mistral";
295
+ import { createOpenAI } from "@ai-sdk/openai";
296
+ import { createOllama } from "ollama-ai-provider";
297
+ class BaseProvider {
298
+ name;
299
+ model;
300
+ mode;
301
+ config;
302
+ transport;
303
+ authMethod;
304
+ apiVersion;
305
+ customHeaders;
306
+ cachedModel = null;
307
+ constructor(config) {
308
+ this.name = config.provider;
309
+ this.model = config.model ?? DEFAULT_MODELS[config.provider];
310
+ this.mode = this.determineMode(config);
311
+ this.config = config;
312
+ this.transport = config.transport;
313
+ this.authMethod = config.authMethod;
314
+ this.apiVersion = config.apiVersion;
315
+ this.customHeaders = config.customHeaders;
316
+ }
317
+ getModel() {
318
+ if (!this.cachedModel) {
319
+ this.cachedModel = this.createModel();
320
+ }
321
+ return this.cachedModel;
322
+ }
323
+ async listModels() {
324
+ if (this.name === "ollama") {
325
+ return this.listOllamaModels();
326
+ }
327
+ return getModelsForProvider(this.name);
328
+ }
329
+ async validate() {
330
+ if (this.name === "ollama") {
331
+ return this.validateOllama();
332
+ }
333
+ if (this.mode === "byok" && !this.config.apiKey) {
334
+ return {
335
+ valid: false,
336
+ error: `API key required for ${this.name}`
337
+ };
338
+ }
339
+ if (this.mode === "managed" && !this.config.proxyUrl && !this.config.organizationId) {
340
+ return {
341
+ valid: false,
342
+ error: "Managed mode requires proxyUrl or organizationId"
343
+ };
344
+ }
345
+ return { valid: true };
346
+ }
347
+ determineMode(config) {
348
+ if (config.provider === "ollama")
349
+ return "local";
350
+ if (config.apiKey)
351
+ return "byok";
352
+ return "managed";
353
+ }
354
+ createModel() {
355
+ const { baseUrl, proxyUrl, apiKey } = this.config;
356
+ const headers = this.customHeaders;
357
+ if (this.name === "ollama") {
358
+ const provider = createOllama({ baseURL: baseUrl, headers });
359
+ return provider(this.model);
360
+ }
361
+ if (this.mode === "managed" && proxyUrl) {
362
+ const provider = createOpenAI({ baseURL: proxyUrl, apiKey, headers });
363
+ return provider(this.model);
364
+ }
365
+ switch (this.name) {
366
+ case "openai": {
367
+ const provider = createOpenAI({ apiKey, headers });
368
+ return provider(this.model);
369
+ }
370
+ case "anthropic": {
371
+ const provider = createAnthropic({ apiKey, headers });
372
+ return provider(this.model);
373
+ }
374
+ case "mistral": {
375
+ const provider = createMistral({ apiKey, headers });
376
+ return provider(this.model);
377
+ }
378
+ case "gemini": {
379
+ const provider = createGoogleGenerativeAI({ apiKey, headers });
380
+ return provider(this.model);
381
+ }
382
+ default:
383
+ throw new Error(`Unknown provider: ${this.name}`);
384
+ }
385
+ }
386
+ async listOllamaModels() {
387
+ try {
388
+ const baseUrl = this.config.baseUrl ?? "http://localhost:11434";
389
+ const response = await fetch(`${baseUrl}/api/tags`);
390
+ if (!response.ok) {
391
+ return getModelsForProvider("ollama");
392
+ }
393
+ const data = await response.json();
394
+ const models = data.models ?? [];
395
+ return models.map((m) => ({
396
+ id: m.name,
397
+ name: m.name,
398
+ provider: "ollama",
399
+ contextWindow: 8000,
400
+ capabilities: {
401
+ vision: false,
402
+ tools: false,
403
+ reasoning: false,
404
+ streaming: true
405
+ }
406
+ }));
407
+ } catch {
408
+ return getModelsForProvider("ollama");
409
+ }
410
+ }
411
+ async validateOllama() {
412
+ try {
413
+ const baseUrl = this.config.baseUrl ?? "http://localhost:11434";
414
+ const response = await fetch(`${baseUrl}/api/tags`);
415
+ if (!response.ok) {
416
+ return {
417
+ valid: false,
418
+ error: `Ollama server returned ${response.status}`
419
+ };
420
+ }
421
+ const data = await response.json();
422
+ const models = data.models ?? [];
423
+ const hasModel = models.some((m) => m.name === this.model);
424
+ if (!hasModel) {
425
+ return {
426
+ valid: false,
427
+ error: `Model "${this.model}" not found. Available: ${models.map((m) => m.name).join(", ")}`
428
+ };
429
+ }
430
+ return { valid: true };
431
+ } catch (error) {
432
+ const baseUrl = this.config.baseUrl ?? "http://localhost:11434";
433
+ return {
434
+ valid: false,
435
+ error: `Cannot connect to Ollama at ${baseUrl}: ${error instanceof Error ? error.message : String(error)}`
436
+ };
437
+ }
438
+ }
439
+ }
440
+ function createProvider(config) {
441
+ return new BaseProvider(config);
442
+ }
443
+ function createProviderFromEnv() {
444
+ const provider = process.env.CONTRACTSPEC_AI_PROVIDER ?? "openai";
445
+ const model = process.env.CONTRACTSPEC_AI_MODEL;
446
+ let apiKey;
447
+ switch (provider) {
448
+ case "openai":
449
+ apiKey = process.env.OPENAI_API_KEY;
450
+ break;
451
+ case "anthropic":
452
+ apiKey = process.env.ANTHROPIC_API_KEY;
453
+ break;
454
+ case "mistral":
455
+ apiKey = process.env.MISTRAL_API_KEY;
456
+ break;
457
+ case "gemini":
458
+ apiKey = process.env.GOOGLE_API_KEY ?? process.env.GEMINI_API_KEY;
459
+ break;
460
+ case "ollama":
461
+ break;
462
+ }
463
+ const transport = process.env.CONTRACTSPEC_AI_TRANSPORT;
464
+ const apiVersion = process.env.CONTRACTSPEC_AI_API_VERSION;
465
+ return createProvider({
466
+ provider,
467
+ model,
468
+ apiKey,
469
+ baseUrl: process.env.OLLAMA_BASE_URL,
470
+ proxyUrl: process.env.CONTRACTSPEC_AI_PROXY_URL,
471
+ organizationId: process.env.CONTRACTSPEC_ORG_ID,
472
+ transport,
473
+ apiVersion
474
+ });
475
+ }
476
+ function getAvailableProviders() {
477
+ const providers = [];
478
+ providers.push({
479
+ provider: "ollama",
480
+ available: true,
481
+ mode: "local",
482
+ transports: ["rest", "sdk"],
483
+ authMethods: []
484
+ });
485
+ const openaiKey = process.env.OPENAI_API_KEY;
486
+ providers.push({
487
+ provider: "openai",
488
+ available: Boolean(openaiKey) || Boolean(process.env.CONTRACTSPEC_AI_PROXY_URL),
489
+ mode: openaiKey ? "byok" : "managed",
490
+ reason: !openaiKey ? "Set OPENAI_API_KEY for BYOK mode" : undefined,
491
+ transports: ["rest", "sdk"],
492
+ authMethods: ["api-key"]
493
+ });
494
+ const anthropicKey = process.env.ANTHROPIC_API_KEY;
495
+ providers.push({
496
+ provider: "anthropic",
497
+ available: Boolean(anthropicKey) || Boolean(process.env.CONTRACTSPEC_AI_PROXY_URL),
498
+ mode: anthropicKey ? "byok" : "managed",
499
+ reason: !anthropicKey ? "Set ANTHROPIC_API_KEY for BYOK mode" : undefined,
500
+ transports: ["rest", "sdk"],
501
+ authMethods: ["api-key"]
502
+ });
503
+ const mistralKey = process.env.MISTRAL_API_KEY;
504
+ providers.push({
505
+ provider: "mistral",
506
+ available: Boolean(mistralKey) || Boolean(process.env.CONTRACTSPEC_AI_PROXY_URL),
507
+ mode: mistralKey ? "byok" : "managed",
508
+ reason: !mistralKey ? "Set MISTRAL_API_KEY for BYOK mode" : undefined,
509
+ transports: ["rest", "sdk"],
510
+ authMethods: ["api-key"]
511
+ });
512
+ const geminiKey = process.env.GOOGLE_API_KEY ?? process.env.GEMINI_API_KEY;
513
+ providers.push({
514
+ provider: "gemini",
515
+ available: Boolean(geminiKey) || Boolean(process.env.CONTRACTSPEC_AI_PROXY_URL),
516
+ mode: geminiKey ? "byok" : "managed",
517
+ reason: !geminiKey ? "Set GOOGLE_API_KEY for BYOK mode" : undefined,
518
+ transports: ["rest", "sdk"],
519
+ authMethods: ["api-key"]
520
+ });
521
+ return providers;
522
+ }
523
+
524
+ // src/selector.ts
525
+ function createModelSelector(options) {
526
+ const { store, fallbackModels, defaultConstraints } = options;
527
+ const catalog = fallbackModels ?? MODELS;
528
+ return {
529
+ async select(context) {
530
+ const merged = mergeConstraints(defaultConstraints, context.constraints);
531
+ if (context.priorities?.length) {
532
+ return selectMultiObjective(store, catalog, context.priorities, merged);
533
+ }
534
+ const dimension = context.taskDimension ?? "reasoning";
535
+ return selectByDimension(store, catalog, dimension, merged);
536
+ },
537
+ async selectAndCreate(context) {
538
+ const selection = await this.select(context);
539
+ const model = createProvider({
540
+ provider: selection.providerKey,
541
+ model: selection.modelId
542
+ }).getModel();
543
+ return { model, selection };
544
+ }
545
+ };
546
+ }
547
+ async function selectByDimension(store, catalog, dimension, constraints) {
548
+ const { rankings } = await store.listModelRankings({ dimension, limit: 50 });
549
+ const eligible = filterRankings(rankings, catalog, constraints);
550
+ const topCandidate = eligible[0];
551
+ if (topCandidate) {
552
+ const dimScore = topCandidate.dimensionScores[dimension]?.score ?? topCandidate.compositeScore;
553
+ return {
554
+ modelId: topCandidate.modelId,
555
+ providerKey: topCandidate.providerKey,
556
+ score: dimScore,
557
+ reason: `Top-ranked for "${dimension}" (score ${Math.round(dimScore)})`,
558
+ alternatives: eligible.slice(1, 4).map((r) => ({
559
+ modelId: r.modelId,
560
+ providerKey: r.providerKey,
561
+ score: r.dimensionScores[dimension]?.score ?? r.compositeScore
562
+ }))
563
+ };
564
+ }
565
+ return fallbackFromCatalog(catalog, constraints, dimension);
566
+ }
567
+ async function selectMultiObjective(store, catalog, priorities, constraints) {
568
+ const { rankings } = await store.listModelRankings({ limit: 100 });
569
+ const eligible = filterRankings(rankings, catalog, constraints);
570
+ if (eligible.length === 0) {
571
+ const primaryDim = priorities.reduce((a, b) => b.weight > a.weight ? b : a).dimension;
572
+ return fallbackFromCatalog(catalog, constraints, primaryDim);
573
+ }
574
+ const totalWeight = priorities.reduce((sum, p) => sum + p.weight, 0) || 1;
575
+ const scored = eligible.map((r) => {
576
+ let weightedScore = 0;
577
+ for (const p of priorities) {
578
+ const dimScore = r.dimensionScores[p.dimension]?.score ?? 0;
579
+ weightedScore += dimScore * (p.weight / totalWeight);
580
+ }
581
+ return { ranking: r, weightedScore };
582
+ });
583
+ scored.sort((a, b) => b.weightedScore - a.weightedScore);
584
+ const best = scored[0];
585
+ if (!best) {
586
+ const primaryDim = priorities.reduce((a, b) => b.weight > a.weight ? b : a).dimension;
587
+ return fallbackFromCatalog(catalog, constraints, primaryDim);
588
+ }
589
+ const dims = priorities.map((p) => p.dimension).join(", ");
590
+ return {
591
+ modelId: best.ranking.modelId,
592
+ providerKey: best.ranking.providerKey,
593
+ score: Math.round(best.weightedScore * 100) / 100,
594
+ reason: `Multi-objective optimum across [${dims}]`,
595
+ alternatives: scored.slice(1, 4).map((s) => ({
596
+ modelId: s.ranking.modelId,
597
+ providerKey: s.ranking.providerKey,
598
+ score: Math.round(s.weightedScore * 100) / 100
599
+ }))
600
+ };
601
+ }
602
+ function filterRankings(rankings, catalog, constraints) {
603
+ return rankings.filter((r) => {
604
+ if (constraints.allowedProviders?.length) {
605
+ if (!constraints.allowedProviders.includes(r.providerKey))
606
+ return false;
607
+ }
608
+ if (constraints.excludeModels?.length) {
609
+ if (constraints.excludeModels.includes(r.modelId))
610
+ return false;
611
+ }
612
+ const info = getModelInfo(r.modelId) ?? catalog.find((m) => m.id === r.modelId);
613
+ if (!info)
614
+ return true;
615
+ if (constraints.minContextWindow && info.contextWindow < constraints.minContextWindow) {
616
+ return false;
617
+ }
618
+ if (constraints.maxCostPerMillionInput && info.costPerMillion) {
619
+ if (info.costPerMillion.input > constraints.maxCostPerMillionInput)
620
+ return false;
621
+ }
622
+ if (constraints.maxCostPerMillionOutput && info.costPerMillion) {
623
+ if (info.costPerMillion.output > constraints.maxCostPerMillionOutput)
624
+ return false;
625
+ }
626
+ if (constraints.requiredCapabilities?.length) {
627
+ for (const cap of constraints.requiredCapabilities) {
628
+ if (!info.capabilities[cap])
629
+ return false;
630
+ }
631
+ }
632
+ return true;
633
+ });
634
+ }
635
+ function fallbackFromCatalog(catalog, constraints, dimension) {
636
+ let eligible = catalog.filter((m) => m.costPerMillion != null);
637
+ const {
638
+ allowedProviders,
639
+ excludeModels,
640
+ minContextWindow,
641
+ requiredCapabilities
642
+ } = constraints;
643
+ if (allowedProviders?.length) {
644
+ eligible = eligible.filter((m) => allowedProviders.includes(m.provider));
645
+ }
646
+ if (excludeModels?.length) {
647
+ eligible = eligible.filter((m) => !excludeModels.includes(m.id));
648
+ }
649
+ if (minContextWindow) {
650
+ eligible = eligible.filter((m) => m.contextWindow >= minContextWindow);
651
+ }
652
+ if (requiredCapabilities?.length) {
653
+ eligible = eligible.filter((m) => requiredCapabilities.every((cap) => m.capabilities[cap]));
654
+ }
655
+ if (eligible.length === 0) {
656
+ eligible = catalog.slice(0, 5);
657
+ }
658
+ eligible.sort((a, b) => {
659
+ const costA = a.costPerMillion ? (a.costPerMillion.input + a.costPerMillion.output) / 2 : 999;
660
+ const costB = b.costPerMillion ? (b.costPerMillion.input + b.costPerMillion.output) / 2 : 999;
661
+ return b.contextWindow / 1e5 - costB - (a.contextWindow / 1e5 - costA);
662
+ });
663
+ const best = eligible[0];
664
+ if (!best) {
665
+ return {
666
+ modelId: "unknown",
667
+ providerKey: "openai",
668
+ score: 0,
669
+ reason: `No eligible models found for "${dimension}"`,
670
+ alternatives: []
671
+ };
672
+ }
673
+ return {
674
+ modelId: best.id,
675
+ providerKey: best.provider,
676
+ score: 0,
677
+ reason: `Fallback from catalog (no ranking data for "${dimension}")`,
678
+ alternatives: eligible.slice(1, 4).map((m) => ({
679
+ modelId: m.id,
680
+ providerKey: m.provider,
681
+ score: 0
682
+ }))
683
+ };
684
+ }
685
+ function mergeConstraints(defaults, overrides) {
686
+ if (!defaults)
687
+ return overrides ?? {};
688
+ if (!overrides)
689
+ return defaults;
690
+ return { ...defaults, ...overrides };
691
+ }
692
+ export {
693
+ createModelSelector
694
+ };