-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnormalizers.test.ts
More file actions
899 lines (776 loc) · 33.3 KB
/
Copy pathnormalizers.test.ts
File metadata and controls
899 lines (776 loc) · 33.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
import { describe, it, expect } from 'vitest'
import {
defaultModelNormalizer,
defaultResponseExtractor,
normalizeTextModel,
normalizeImageModel,
normalizeVideoModel,
normalizeInpaintModel,
normalizeEmbeddingModel,
normalizeTtsModel,
normalizeAsrModel,
normalizeUpscaleModel,
inferTypeFromId,
MODEL_ID_TYPE_PATTERNS,
} from './index'
import { toNum, extractBaseFields, toBool, toStr } from './index'
// ─── Helpers ────────────────────────────────────────────────────────────────
/** Minimal raw model object — just an id */
const raw = (id: string, extra: Record<string, unknown> = {}): Record<string, unknown> => ({
id,
...extra,
})
/** Venice-style raw model with model_spec */
const veniceRaw = (
id: string,
type: string,
specOverrides: Record<string, unknown> = {},
topOverrides: Record<string, unknown> = {},
): Record<string, unknown> => ({
id,
type,
model_spec: {
name: `${id}-display`,
description: `Description for ${id}`,
...specOverrides,
},
...topOverrides,
})
// ═══════════════════════════════════════════════════════════════════════════
// toNum
// ═══════════════════════════════════════════════════════════════════════════
describe('toNum', () => {
it('converts a number', () => {
expect(toNum(42)).toBe(42)
})
it('converts a numeric string', () => {
expect(toNum('42')).toBe(42)
})
it('returns undefined for null', () => {
expect(toNum(null)).toBeUndefined()
})
it('returns undefined for undefined', () => {
expect(toNum(undefined)).toBeUndefined()
})
it('returns undefined for empty string', () => {
expect(toNum('')).toBeUndefined()
})
it('returns undefined for non-numeric string', () => {
expect(toNum('abc')).toBeUndefined()
})
it('returns undefined for NaN', () => {
expect(toNum(NaN)).toBeUndefined()
})
it('converts zero', () => {
expect(toNum(0)).toBe(0)
})
it('converts negative numbers', () => {
expect(toNum(-5)).toBe(-5)
})
it('converts float strings', () => {
expect(toNum('3.14')).toBeCloseTo(3.14)
})
})
// ═══════════════════════════════════════════════════════════════════════════
// toBool — strict boolean coercion
// ═══════════════════════════════════════════════════════════════════════════
describe('toBool', () => {
it('passes through actual booleans', () => {
expect(toBool(true)).toBe(true)
expect(toBool(false)).toBe(false)
})
it('returns undefined for null / undefined', () => {
expect(toBool(null)).toBeUndefined()
expect(toBool(undefined)).toBeUndefined()
})
it('returns undefined for non-boolean values (no coercion)', () => {
// Strict: don't coerce truthy/falsy — callers want "yes this is a boolean".
expect(toBool(0)).toBeUndefined()
expect(toBool(1)).toBeUndefined()
expect(toBool('true')).toBeUndefined()
expect(toBool('')).toBeUndefined()
expect(toBool({})).toBeUndefined()
expect(toBool({ enabled: true })).toBeUndefined()
expect(toBool([])).toBeUndefined()
})
})
// ═══════════════════════════════════════════════════════════════════════════
// toStr — strict string coercion
// ═══════════════════════════════════════════════════════════════════════════
describe('toStr', () => {
it('passes through actual strings', () => {
expect(toStr('hello')).toBe('hello')
expect(toStr('')).toBe('')
})
it('returns undefined for null / undefined', () => {
expect(toStr(null)).toBeUndefined()
expect(toStr(undefined)).toBeUndefined()
})
it('returns undefined for non-string values (no coercion)', () => {
expect(toStr(42)).toBeUndefined()
expect(toStr(true)).toBeUndefined()
expect(toStr({})).toBeUndefined()
expect(toStr([])).toBeUndefined()
})
})
// ═══════════════════════════════════════════════════════════════════════════
// defaultResponseExtractor
// ═══════════════════════════════════════════════════════════════════════════
describe('defaultResponseExtractor', () => {
it('returns top-level array as-is', () => {
const arr = [{ id: 'a' }, { id: 'b' }]
expect(defaultResponseExtractor(arr)).toBe(arr)
})
it('extracts { data: [...] }', () => {
const data = [{ id: 'c' }]
expect(defaultResponseExtractor({ data })).toBe(data)
})
it('extracts { models: [...] }', () => {
const models = [{ id: 'd' }]
expect(defaultResponseExtractor({ models })).toBe(models)
})
it('returns [] for unrecognized shape', () => {
expect(defaultResponseExtractor({ results: [1, 2, 3] })).toEqual([])
})
})
// ═══════════════════════════════════════════════════════════════════════════
// extractBaseFields
// ═══════════════════════════════════════════════════════════════════════════
describe('extractBaseFields', () => {
it('extracts id from raw.id', () => {
const result = extractBaseFields({ id: 'gpt-4o' })
expect(result.id).toBe('gpt-4o')
})
it('falls back to raw.model_id', () => {
const result = extractBaseFields({ model_id: 'claude-3' })
expect(result.id).toBe('claude-3')
})
it('throws when id is missing', () => {
expect(() => extractBaseFields({})).toThrow('Model missing required id field')
})
it('extracts name from spec.name (Venice)', () => {
const result = extractBaseFields({ id: 'x', model_spec: { name: 'Venice Name' } })
expect(result.name).toBe('Venice Name')
})
it('falls back to raw.name', () => {
const result = extractBaseFields({ id: 'x', name: 'Raw Name' })
expect(result.name).toBe('Raw Name')
})
it('falls back to id for name', () => {
const result = extractBaseFields({ id: 'fallback-id' })
expect(result.name).toBe('fallback-id')
})
it('extracts provider from slash-separated id', () => {
const result = extractBaseFields({ id: 'anthropic/claude-3' })
expect(result.provider).toBe('anthropic')
})
it('falls back to owned_by for provider', () => {
const result = extractBaseFields({ id: 'gpt-4o', owned_by: 'openai' })
expect(result.provider).toBe('openai')
})
it('defaults provider to "Unknown" when nothing available', () => {
const result = extractBaseFields({ id: 'gpt-4o' })
expect(result.provider).toBe('Unknown')
})
it('extracts Venice-specific fields from model_spec', () => {
const result = extractBaseFields({
id: 'venice-model',
model_spec: {
betaModel: true,
privacy: 'private',
offline: false,
modelSource: 'huggingface',
traits: ['fast', 'cheap'],
deprecation: { date: '2025-12-31' },
},
})
expect(result.betaModel).toBe(true)
expect(result.privacy).toBe('private')
expect(result.offline).toBe(false)
expect(result.modelSource).toBe('huggingface')
expect(result.traits).toEqual(['fast', 'cheap'])
expect(result.deprecation).toEqual({ date: '2025-12-31' })
})
it('always sets is_favorite to false', () => {
const result = extractBaseFields({ id: 'x' })
expect(result.is_favorite).toBe(false)
})
it('ignores any is_favorite value sent by the API (client-side overlay only)', () => {
// If an API response somehow includes is_favorite, the normalizer must
// discard it — favorites are a client-side overlay managed via localStorage.
const result = extractBaseFields({ id: 'x', is_favorite: true } as Record<string, unknown>)
expect(result.is_favorite).toBe(false)
})
it('slash-in-id wins over owned_by for provider (intentional OpenRouter behavior)', () => {
// Pinning current behavior: when an id contains "/", the leading segment is
// used regardless of owned_by. This is how OpenRouter's provider attribution
// works. Any future change to prefer owned_by must update this test.
const result = extractBaseFields({ id: 'anthropic/claude-3', owned_by: 'openrouter' })
expect(result.provider).toBe('anthropic')
})
it('rejects non-string privacy values (strict guard, not coerced)', () => {
const result = extractBaseFields({
id: 'x',
model_spec: { privacy: 'public' as unknown as 'private' },
})
expect(result.privacy).toBeUndefined()
})
it('rejects malformed deprecation shapes (missing string date)', () => {
const result = extractBaseFields({
id: 'x',
model_spec: { deprecation: { date: 12345 as unknown as string } },
})
expect(result.deprecation).toBeUndefined()
})
})
// ═══════════════════════════════════════════════════════════════════════════
// inferTypeFromId
// ═══════════════════════════════════════════════════════════════════════════
describe('inferTypeFromId', () => {
it('infers "embedding" from text-embedding-ada-002', () => {
expect(inferTypeFromId('text-embedding-ada-002')).toBe('embedding')
})
it('infers "embedding" from text-embedding-3-small', () => {
expect(inferTypeFromId('text-embedding-3-small')).toBe('embedding')
})
it('infers "image" from dall-e-3', () => {
expect(inferTypeFromId('dall-e-3')).toBe('image')
})
it('infers "image" from stable-diffusion-xl', () => {
expect(inferTypeFromId('stable-diffusion-xl')).toBe('image')
})
it('infers "image" from flux-dev', () => {
expect(inferTypeFromId('flux-dev')).toBe('image')
})
it('infers "tts" from tts-1', () => {
expect(inferTypeFromId('tts-1')).toBe('tts')
})
it('infers "tts" from tts-1-hd', () => {
expect(inferTypeFromId('tts-1-hd')).toBe('tts')
})
it('infers "asr" from whisper-1', () => {
expect(inferTypeFromId('whisper-1')).toBe('asr')
})
it('infers "video" from sora-v1', () => {
expect(inferTypeFromId('sora-v1')).toBe('video')
})
it('infers "video" from wan-2.1-14b', () => {
expect(inferTypeFromId('wan-2.1-14b')).toBe('video')
})
it('infers "inpaint" from inpaint-model', () => {
expect(inferTypeFromId('inpaint-model')).toBe('inpaint')
})
it('infers "upscale" from esrgan-4x', () => {
expect(inferTypeFromId('esrgan-4x')).toBe('upscale')
})
it('does NOT match "vision" as "video"', () => {
expect(inferTypeFromId('gpt-4-vision-preview')).toBeUndefined()
})
it('returns undefined for gpt-4o (unknown)', () => {
expect(inferTypeFromId('gpt-4o')).toBeUndefined()
})
it('returns undefined for my-custom-model', () => {
expect(inferTypeFromId('my-custom-model')).toBeUndefined()
})
it('returns undefined for claude-3.5-sonnet', () => {
expect(inferTypeFromId('claude-3.5-sonnet')).toBeUndefined()
})
it('MODEL_ID_TYPE_PATTERNS is exported and non-empty', () => {
expect(MODEL_ID_TYPE_PATTERNS.length).toBeGreaterThan(0)
})
})
// ═══════════════════════════════════════════════════════════════════════════
// defaultModelNormalizer — dispatching
// ═══════════════════════════════════════════════════════════════════════════
describe('defaultModelNormalizer', () => {
it('Venice text model → TextModel', () => {
const result = defaultModelNormalizer(veniceRaw('llama-3.1', 'text'))
expect(result.type).toBe('text')
expect(result.id).toBe('llama-3.1')
})
it('Venice image model → ImageModel', () => {
const result = defaultModelNormalizer(veniceRaw('flux-dev', 'image'))
expect(result.type).toBe('image')
})
it('Venice video model → VideoModel', () => {
const result = defaultModelNormalizer(veniceRaw('wan-2.1', 'video'))
expect(result.type).toBe('video')
})
it('no type + embedding id → EmbeddingModel via heuristic', () => {
const result = defaultModelNormalizer(raw('text-embedding-ada-002'))
expect(result.type).toBe('embedding')
})
it('no type + dall-e-3 id → ImageModel via heuristic', () => {
const result = defaultModelNormalizer(raw('dall-e-3'))
expect(result.type).toBe('image')
})
it('no type + tts-1 id → TtsModel via heuristic', () => {
const result = defaultModelNormalizer(raw('tts-1'))
expect(result.type).toBe('tts')
})
it('no type + whisper-1 id → AsrModel via heuristic', () => {
const result = defaultModelNormalizer(raw('whisper-1'))
expect(result.type).toBe('asr')
})
it('no type + unknown id → TextModel (fallback)', () => {
const result = defaultModelNormalizer(raw('gpt-4o'))
expect(result.type).toBe('text')
})
it('invalid type "banana" → falls through to heuristic/text', () => {
const result = defaultModelNormalizer({ id: 'gpt-4o', type: 'banana' })
expect(result.type).toBe('text')
})
it('type: "embedding" → EmbeddingModel', () => {
const result = defaultModelNormalizer({ id: 'custom-embed', type: 'embedding' })
expect(result.type).toBe('embedding')
})
it('type: "tts" → TtsModel', () => {
const result = defaultModelNormalizer({ id: 'custom-tts', type: 'tts' })
expect(result.type).toBe('tts')
})
it('type: "asr" → AsrModel', () => {
const result = defaultModelNormalizer({ id: 'custom-asr', type: 'asr' })
expect(result.type).toBe('asr')
})
it('type: "upscale" → UpscaleModel', () => {
const result = defaultModelNormalizer({ id: 'my-upscaler', type: 'upscale' })
expect(result.type).toBe('upscale')
})
it('type: "inpaint" → InpaintModel', () => {
const result = defaultModelNormalizer({ id: 'my-inpainter', type: 'inpaint' })
expect(result.type).toBe('inpaint')
})
})
// ═══════════════════════════════════════════════════════════════════════════
// normalizeTextModel
// ═══════════════════════════════════════════════════════════════════════════
describe('normalizeTextModel', () => {
it('full Venice text model with model_spec', () => {
const result = normalizeTextModel({
id: 'llama-3.3-70b',
type: 'text',
model_spec: {
name: 'Llama 3.3 70B',
description: 'Meta model',
availableContextTokens: 131072,
pricing: {
input: { usd: 0.36, diem: 0.36 },
output: { usd: 0.54, diem: 0.54 },
},
capabilities: {
optimizedForCode: false,
supportsVision: true,
supportsReasoning: false,
supportsFunctionCalling: true,
},
constraints: {
temperature: { default: 0.7 },
top_p: { default: 0.9 },
},
},
})
expect(result.type).toBe('text')
expect(result.id).toBe('llama-3.3-70b')
expect(result.name).toBe('Llama 3.3 70B')
expect(result.context_length).toBe(131072)
// Venice pricing: per-million → per-token
expect(result.pricing.prompt).toBeCloseTo(0.36 / 1_000_000)
expect(result.pricing.completion).toBeCloseTo(0.54 / 1_000_000)
expect(result.capabilities?.supportsVision).toBe(true)
expect(result.capabilities?.supportsFunctionCalling).toBe(true)
expect(result.constraints?.temperature).toEqual({ default: 0.7 })
})
it('OpenRouter pricing (per-token) used as-is', () => {
const result = normalizeTextModel({
id: 'openrouter/gpt-4o',
pricing: { prompt: 0.000005, completion: 0.000015 },
})
expect(result.pricing.prompt).toBe(0.000005)
expect(result.pricing.completion).toBe(0.000015)
})
it('metadata.pricing fallback', () => {
const result = normalizeTextModel({
id: 'meta-model',
metadata: { pricing: { prompt: 0.00001, completion: 0.00002 } },
})
expect(result.pricing.prompt).toBe(0.00001)
expect(result.pricing.completion).toBe(0.00002)
})
it('cost fallback', () => {
const result = normalizeTextModel({
id: 'cost-model',
cost: { prompt: 0.00003, completion: 0.00006 },
})
expect(result.pricing.prompt).toBe(0.00003)
expect(result.pricing.completion).toBe(0.00006)
})
it('context_length from context_length field', () => {
const result = normalizeTextModel({ id: 'x', context_length: 8192 })
expect(result.context_length).toBe(8192)
})
it('context_length from context_window field', () => {
const result = normalizeTextModel({ id: 'x', context_window: 4096 })
expect(result.context_length).toBe(4096)
})
it('context_length from spec.availableContextTokens', () => {
const result = normalizeTextModel({
id: 'x',
model_spec: { availableContextTokens: 131072 },
})
expect(result.context_length).toBe(131072)
})
it('missing pricing → empty pricing object', () => {
const result = normalizeTextModel({ id: 'x' })
expect(result.pricing.prompt).toBeUndefined()
expect(result.pricing.completion).toBeUndefined()
})
it('missing everything except id → valid TextModel with defaults', () => {
const result = normalizeTextModel({ id: 'bare-model' })
expect(result.type).toBe('text')
expect(result.id).toBe('bare-model')
expect(result.context_length).toBeUndefined()
expect(result.capabilities).toBeUndefined()
expect(result.constraints).toBeUndefined()
expect(result.is_favorite).toBe(false)
})
it('context_length is undefined when no source resolves (distinct from an actual zero)', () => {
// Previously defaulted to 0, which was indistinguishable from a model with
// genuinely zero context. undefined now signals "unknown".
expect(normalizeTextModel({ id: 'x' }).context_length).toBeUndefined()
expect(normalizeTextModel({ id: 'x', context_length: 0 }).context_length).toBe(0)
})
it('cache pricing from Venice spec', () => {
const result = normalizeTextModel({
id: 'cache-model',
model_spec: {
pricing: {
input: { usd: 1.0 },
output: { usd: 2.0 },
cache_input: { usd: 0.5 },
cache_write: { usd: 0.75 },
},
},
})
expect(result.pricing.cache_input).toBeCloseTo(0.5 / 1_000_000)
expect(result.pricing.cache_write).toBeCloseTo(0.75 / 1_000_000)
})
it('extracts Venice supportsMultipleImages capability', () => {
const result = normalizeTextModel(
veniceRaw('x', 'text', {
capabilities: { supportsMultipleImages: false, supportsVision: true },
}),
)
expect(result.capabilities?.supportsMultipleImages).toBe(false)
expect(result.capabilities?.supportsVision).toBe(true)
})
it('rejects non-boolean capability values instead of unsafe-casting them', () => {
// If a provider returns `{ supportsVision: { enabled: true } }` instead of
// a plain boolean, we must not surface it as `true`. The strict toBool
// guard returns undefined and the rendering layer treats that as "absent".
const result = normalizeTextModel({
id: 'weird-shape',
model_spec: {
capabilities: {
supportsVision: { enabled: true },
optimizedForCode: 1,
quantization: { type: 'fp8' },
supportsReasoning: true,
},
},
})
expect(result.capabilities?.supportsVision).toBeUndefined()
expect(result.capabilities?.optimizedForCode).toBeUndefined()
expect(result.capabilities?.quantization).toBeUndefined()
// Actual booleans still pass through
expect(result.capabilities?.supportsReasoning).toBe(true)
})
it('reads OpenRouter cache pricing (input_cache_read / input_cache_write)', () => {
// OpenRouter's /models uses `input_cache_read` and `input_cache_write`,
// not `cache_input`/`cache_write`. Both field conventions must resolve.
const result = normalizeTextModel({
id: 'anthropic/claude-sonnet-4.6',
pricing: {
prompt: '0.000003',
completion: '0.000015',
input_cache_read: '0.0000003',
input_cache_write: '0.00000375',
},
})
expect(result.pricing.cache_input).toBeCloseTo(3e-7)
expect(result.pricing.cache_write).toBeCloseTo(3.75e-6)
})
})
// ═══════════════════════════════════════════════════════════════════════════
// normalizeImageModel
// ═══════════════════════════════════════════════════════════════════════════
describe('normalizeImageModel', () => {
it('full Venice image model', () => {
const result = normalizeImageModel({
id: 'flux-dev',
type: 'image',
model_spec: {
name: 'Flux Dev',
pricing: {
generation: { usd: 0.04 },
upscale: {
'2x': { usd: 0.02 },
'4x': { usd: 0.06 },
},
},
constraints: {
promptCharacterLimit: 1000,
steps: { default: 30, max: 50 },
widthHeightDivisor: 8,
aspectRatios: ['1:1', '16:9'],
defaultAspectRatio: '1:1',
},
supportsWebSearch: true,
},
})
expect(result.type).toBe('image')
expect(result.pricing.generation).toBe(0.04)
expect(result.pricing.upscale_2x).toBe(0.02)
expect(result.pricing.upscale_4x).toBe(0.06)
expect(result.constraints?.steps).toEqual({ default: 30, max: 50 })
expect(result.constraints?.widthHeightDivisor).toBe(8)
expect(result.supportsWebSearch).toBe(true)
})
it('resolution-based pricing normalization', () => {
const result = normalizeImageModel({
id: 'nano-banana',
model_spec: {
pricing: {
resolutions: {
'1K': { usd: 0.18, diem: 0.18 },
'2K': { usd: 0.24, diem: 0.24 },
},
},
},
})
expect(result.pricing.resolutions).toEqual({ '1K': 0.18, '2K': 0.24 })
})
it('supportsWebSearch from spec, not constraints', () => {
const result = normalizeImageModel({
id: 'img',
model_spec: {
supportsWebSearch: false,
},
})
expect(result.supportsWebSearch).toBe(false)
})
it('missing constraints → undefined', () => {
const result = normalizeImageModel({ id: 'img' })
expect(result.constraints).toBeUndefined()
})
it('missing pricing → undefined fields', () => {
const result = normalizeImageModel({ id: 'img' })
expect(result.pricing.generation).toBeUndefined()
expect(result.pricing.upscale_2x).toBeUndefined()
expect(result.pricing.upscale_4x).toBeUndefined()
})
it('aspect ratios and steps extraction', () => {
const result = normalizeImageModel({
id: 'img',
model_spec: {
constraints: {
aspectRatios: ['1:1', '4:3', '16:9'],
steps: { default: 20, max: 40 },
},
},
})
expect(result.constraints?.aspectRatios).toEqual(['1:1', '4:3', '16:9'])
expect(result.constraints?.steps).toEqual({ default: 20, max: 40 })
})
})
// ═══════════════════════════════════════════════════════════════════════════
// normalizeVideoModel
// ═══════════════════════════════════════════════════════════════════════════
describe('normalizeVideoModel', () => {
it('full Venice video model', () => {
const result = normalizeVideoModel({
id: 'wan-2.1-14b',
type: 'video',
model_spec: {
name: 'Wan 2.1 14B',
deprecation: { date: '2026-06-01' },
constraints: {
model_type: 'text-to-video',
aspect_ratios: ['16:9', '9:16'],
resolutions: ['720p', '1080p'],
durations: ['5', '10'],
audio: false,
audio_configurable: true,
},
model_sets: ['standard', 'premium'],
},
})
expect(result.type).toBe('video')
expect(result.constraints?.model_type).toBe('text-to-video')
expect(result.constraints?.aspect_ratios).toEqual(['16:9', '9:16'])
expect(result.constraints?.durations).toEqual(['5', '10'])
expect(result.constraints?.audio).toBe(false)
expect(result.model_sets).toEqual(['standard', 'premium'])
expect(result.deprecation).toEqual({ date: '2026-06-01' })
})
it('no pricing property on VideoModel', () => {
const result = normalizeVideoModel({ id: 'vid' })
expect((result as unknown as Record<string, unknown>).pricing).toBeUndefined()
})
it('missing constraints → undefined', () => {
const result = normalizeVideoModel({ id: 'vid' })
expect(result.constraints).toBeUndefined()
})
it('model_sets from top-level raw fallback', () => {
const result = normalizeVideoModel({ id: 'vid', model_sets: ['basic'] })
expect(result.model_sets).toEqual(['basic'])
})
it('audio and video input constraints', () => {
const result = normalizeVideoModel({
id: 'vid',
model_spec: {
constraints: {
audio_input: true,
video_input: true,
},
},
})
expect(result.constraints?.audio_input).toBe(true)
expect(result.constraints?.video_input).toBe(true)
})
})
// ═══════════════════════════════════════════════════════════════════════════
// normalizeEmbeddingModel
// ═══════════════════════════════════════════════════════════════════════════
describe('normalizeEmbeddingModel', () => {
it('Venice embedding with input and output pricing', () => {
const result = normalizeEmbeddingModel({
id: 'text-embedding-ada-002',
model_spec: {
pricing: {
input: { usd: 0.1 },
output: { usd: 0.1 },
},
},
})
expect(result.type).toBe('embedding')
expect(result.pricing.input).toBeCloseTo(0.1 / 1_000_000)
expect(result.pricing.output).toBeCloseTo(0.1 / 1_000_000)
})
it('missing pricing → undefined fields', () => {
const result = normalizeEmbeddingModel({ id: 'embed' })
expect(result.pricing.input).toBeUndefined()
expect(result.pricing.output).toBeUndefined()
})
it('base fields are correct', () => {
const result = normalizeEmbeddingModel({ id: 'openai/embed-v3', name: 'Embed V3' })
expect(result.id).toBe('openai/embed-v3')
expect(result.provider).toBe('openai')
expect(result.name).toBe('Embed V3')
})
})
// ═══════════════════════════════════════════════════════════════════════════
// normalizeTtsModel
// ═══════════════════════════════════════════════════════════════════════════
describe('normalizeTtsModel', () => {
it('Venice TTS with pricing and voices', () => {
const result = normalizeTtsModel({
id: 'tts-1',
model_spec: {
pricing: { input: { usd: 15.0 } },
voices: ['alloy', 'echo', 'fable'],
},
})
expect(result.type).toBe('tts')
expect(result.pricing.input).toBeCloseTo(15.0 / 1_000_000)
expect(result.voices).toEqual(['alloy', 'echo', 'fable'])
})
it('missing voices → undefined', () => {
const result = normalizeTtsModel({ id: 'tts-1' })
expect(result.voices).toBeUndefined()
})
it('per-million conversion for pricing', () => {
const result = normalizeTtsModel({
id: 'tts-hd',
model_spec: { pricing: { input: { usd: 30.0 } } },
})
expect(result.pricing.input).toBeCloseTo(30.0 / 1_000_000)
})
})
// ═══════════════════════════════════════════════════════════════════════════
// normalizeAsrModel
// ═══════════════════════════════════════════════════════════════════════════
describe('normalizeAsrModel', () => {
it('Venice ASR with per_audio_second pricing', () => {
const result = normalizeAsrModel({
id: 'whisper-1',
model_spec: {
pricing: {
per_audio_second: { usd: 0.006 },
},
},
})
expect(result.type).toBe('asr')
expect(result.pricing.per_audio_second).toBe(0.006)
})
it('missing pricing → undefined', () => {
const result = normalizeAsrModel({ id: 'whisper-1' })
expect(result.pricing.per_audio_second).toBeUndefined()
})
it('base fields correct', () => {
const result = normalizeAsrModel({ id: 'whisper-1', owned_by: 'openai' })
expect(result.id).toBe('whisper-1')
expect(result.provider).toBe('openai')
expect(result.is_favorite).toBe(false)
})
})
// ═══════════════════════════════════════════════════════════════════════════
// normalizeInpaintModel
// ═══════════════════════════════════════════════════════════════════════════
describe('normalizeInpaintModel', () => {
it('full inpaint model', () => {
const result = normalizeInpaintModel({
id: 'inpaint-v1',
model_spec: {
pricing: { generation: { usd: 0.05 } },
constraints: {
aspectRatios: ['1:1', '4:3'],
combineImages: true,
},
},
})
expect(result.type).toBe('inpaint')
expect(result.pricing.generation).toBe(0.05)
expect(result.constraints?.aspectRatios).toEqual(['1:1', '4:3'])
expect(result.constraints?.combineImages).toBe(true)
})
it('missing constraints → undefined', () => {
const result = normalizeInpaintModel({ id: 'inpaint' })
expect(result.constraints).toBeUndefined()
})
it('missing pricing → undefined generation', () => {
const result = normalizeInpaintModel({ id: 'inpaint' })
expect(result.pricing.generation).toBeUndefined()
})
})
// ═══════════════════════════════════════════════════════════════════════════
// normalizeUpscaleModel
// ═══════════════════════════════════════════════════════════════════════════
describe('normalizeUpscaleModel', () => {
it('full upscale model', () => {
const result = normalizeUpscaleModel({
id: 'esrgan-4x',
model_spec: {
pricing: { generation: { usd: 0.08 } },
},
})
expect(result.type).toBe('upscale')
expect(result.pricing.generation).toBe(0.08)
})
it('missing everything except id → valid UpscaleModel', () => {
const result = normalizeUpscaleModel({ id: 'upscale-bare' })
expect(result.type).toBe('upscale')
expect(result.id).toBe('upscale-bare')
expect(result.pricing.generation).toBeUndefined()
expect(result.is_favorite).toBe(false)
})
})