opencode-magpie-plugin 0.0.0-stage → 0.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.
@@ -0,0 +1,851 @@
1
+ //#region src/model-pricing.ts
2
+ const MODEL_PRICING_ALIASES = {
3
+ "claude-opus-4-6": "claude-opus-4.6",
4
+ "claude-opus-4-7": "claude-opus-4.7",
5
+ "claude-opus-4-8": "claude-opus-4.8",
6
+ "claude-opus-5-5": "claude-opus-5.5",
7
+ "claude-opus-4.6-1m": "claude-opus-4.6",
8
+ "claude-opus-4.7-1m": "claude-opus-4.7",
9
+ "claude-opus-4.8-1m": "claude-opus-4.8",
10
+ "claude-opus-5.5-1m": "claude-opus-5.5",
11
+ "claude-sonnet-4-6": "claude-sonnet-4.6",
12
+ "claude-sonnet-4.6-1m": "claude-sonnet-4.6",
13
+ "claude-sonnet-5-1m": "claude-sonnet-5",
14
+ "deepseek-v3-2": "deepseek-v3.2",
15
+ "deepseek-v3-2-volc-ioa": "deepseek-v3.2",
16
+ "deepseek-v4-flash-external": "deepseek-v4-flash",
17
+ "deepseek-v4-flash-official": "deepseek-v4-flash",
18
+ "deepseek-v4-flash-ioa": "deepseek-v4-flash",
19
+ "deepseek-v4-flash-0731": "deepseek-v4-flash",
20
+ "deepseek-v4.1-flash": "deepseek-v4-flash",
21
+ "deepseek-v4-flash-vision-exp": "deepseek-v4-flash",
22
+ "deepseek-v4-pro-external": "deepseek-v4-pro",
23
+ "deepseek-v4-pro-official": "deepseek-v4-pro",
24
+ "deepseek-v4-pro-ioa": "deepseek-v4-pro",
25
+ "gemini-3-1-pro": "gemini-3.1-pro",
26
+ "gemini-3-5-flash": "gemini-3.5-flash",
27
+ "glm-5-1": "glm-5.1",
28
+ "glm-5-2-internal": "glm-5.2",
29
+ "glm-5-3-internal": "glm-5.3",
30
+ "glm-5-3-flash-internal": "glm-5.3-flash",
31
+ "glm-5.1-external": "glm-5.1",
32
+ "glm-5.2-external": "glm-5.2",
33
+ "glm-5-1-ioa": "glm-5.1",
34
+ "glm-5-2-ioa": "glm-5.2",
35
+ "glm-5.0-ioa": "glm-5.0",
36
+ "glm-4.6-ioa": "glm-4.6",
37
+ "glm-4.6v-ioa": "glm-4.6v",
38
+ "glm-4.7-ioa": "glm-4.7",
39
+ "glm-5-fp8-ioa": "glm-5-fp8",
40
+ "glm-5v-turbo-ioa": "glm-5v-turbo",
41
+ "glm-5-turbo-external": "glm-5-turbo",
42
+ "glm-5v-turbo": "glm-5v-turbo",
43
+ "gpt-5-4": "gpt-5.4",
44
+ "gpt-5-4-mini": "gpt-5.4-mini",
45
+ "gpt-5-4-nano": "gpt-5.4-nano",
46
+ "gpt-5-5": "gpt-5.5",
47
+ "gpt-5-6-sol": "gpt-5.6-sol",
48
+ "gpt-5-6-terra": "gpt-5.6-terra",
49
+ "gpt-5-6-luna": "gpt-5.6-luna",
50
+ "hy3-ioa": "hy-3",
51
+ hy3: "hy-3",
52
+ "hy-4-preview": "hy4-preview",
53
+ "kimi-k2.6-external": "kimi-k2.6",
54
+ "kimi-k2.6-ioa": "kimi-k2.6",
55
+ "minimax-m2.5-ioa": "minimax-m2.5",
56
+ "minimax-m2.7-ioa": "minimax-m2.7",
57
+ "minimax-m3-external": "minimax-m3",
58
+ "cursor-grok-4.5": "grok-4.5",
59
+ "cursor-grok-4.7": "grok-4.7"
60
+ };
61
+ const PROVIDER_MODEL_SUFFIXES = [
62
+ "-external",
63
+ "-internal",
64
+ "-ioa",
65
+ "-official"
66
+ ];
67
+ const CAPABILITY_SUFFIXES = ["-fast"];
68
+ const CONTEXT_SUFFIX_REGEX = /-(\d+)(k|m)$/i;
69
+ const stripContextSuffixes = (key) => key.replace(CONTEXT_SUFFIX_REGEX, "");
70
+ /**
71
+ * Cursor 的 `cursor` provider 价格由其自身账单反解得到,不是厂商 list price。
72
+ *
73
+ * Cursor 对缓存读取另有加价(Opus 实测 $0.75/M,Anthropic list 为 $0.50/M),
74
+ * 而缓存读取又占实际 token 量的 95% 以上;沿用 list price 会系统性少算。
75
+ * 这些数字是对 7.5k 条 Cursor usage event 做非负最小二乘拟合的结果,
76
+ * 复算当月账单为实际值的 99%(沿用 list price 时只有 49%)。
77
+ * 缓存读写一律取拟合值;Anthropic 系的 input/output 保留 list price,
78
+ * 因为绝大多数 prompt 都走缓存,拟合无法把 output 与 cache_write 分开。
79
+ */
80
+ const MODEL_PRICINGS = {
81
+ "claude-haiku-4.5": {
82
+ default: {
83
+ input: 1,
84
+ output: 5
85
+ },
86
+ providers: { cursor: {
87
+ input: 1,
88
+ output: 5.25,
89
+ cache: {
90
+ read: .35,
91
+ write: 1.5
92
+ }
93
+ } }
94
+ },
95
+ "claude-sonnet-4.6": {
96
+ default: {
97
+ input: 3,
98
+ output: 15
99
+ },
100
+ providers: {
101
+ boxai: {
102
+ input: 3,
103
+ output: 15,
104
+ cache: {
105
+ read: .3,
106
+ write: 3.75
107
+ }
108
+ },
109
+ cursor: {
110
+ input: 3,
111
+ output: 15.25,
112
+ cache: {
113
+ read: .55,
114
+ write: 4
115
+ }
116
+ }
117
+ }
118
+ },
119
+ "claude-sonnet-5": {
120
+ default: {
121
+ input: 3,
122
+ output: 15
123
+ },
124
+ providers: { cursor: {
125
+ input: 3,
126
+ output: 15,
127
+ cache: {
128
+ read: .45,
129
+ write: 2.75
130
+ }
131
+ } }
132
+ },
133
+ "claude-sonnet-5.5": { default: {
134
+ input: 3,
135
+ output: 15
136
+ } },
137
+ "claude-opus-4.5": { default: {
138
+ input: 5,
139
+ output: 25,
140
+ cache: {
141
+ read: .5,
142
+ write: 6.25
143
+ }
144
+ } },
145
+ "claude-opus-4.6": {
146
+ default: {
147
+ input: 5,
148
+ output: 25,
149
+ cache: {
150
+ read: .5,
151
+ write: 6.25
152
+ }
153
+ },
154
+ providers: {
155
+ boxai: {
156
+ input: 5,
157
+ output: 25,
158
+ cache: {
159
+ read: .5,
160
+ write: 6.25
161
+ }
162
+ },
163
+ cursor: {
164
+ input: 5,
165
+ output: 25,
166
+ cache: {
167
+ read: .75,
168
+ write: 6.5
169
+ }
170
+ }
171
+ }
172
+ },
173
+ "claude-opus-4.7": {
174
+ default: {
175
+ input: 5,
176
+ output: 25,
177
+ cache: {
178
+ read: .5,
179
+ write: 6.25
180
+ }
181
+ },
182
+ providers: { boxai: {
183
+ input: 5,
184
+ output: 25,
185
+ cache: {
186
+ read: .5,
187
+ write: 6.25
188
+ }
189
+ } }
190
+ },
191
+ "claude-opus-4.8": {
192
+ default: {
193
+ input: 5,
194
+ output: 25,
195
+ cache: {
196
+ read: .5,
197
+ write: 6.25
198
+ }
199
+ },
200
+ providers: {
201
+ boxai: {
202
+ input: 5,
203
+ output: 25,
204
+ cache: {
205
+ read: .5,
206
+ write: 6.25
207
+ }
208
+ },
209
+ cursor: {
210
+ input: 5,
211
+ output: 25,
212
+ cache: {
213
+ read: .77,
214
+ write: 6.59
215
+ }
216
+ }
217
+ }
218
+ },
219
+ "claude-opus-5": {
220
+ default: {
221
+ input: 5,
222
+ output: 25,
223
+ cache: {
224
+ read: .5,
225
+ write: 6.25
226
+ }
227
+ },
228
+ providers: { cursor: {
229
+ input: 5,
230
+ output: 25,
231
+ cache: {
232
+ read: .75,
233
+ write: 6.5
234
+ }
235
+ } }
236
+ },
237
+ "claude-opus-5.5": {
238
+ default: {
239
+ input: 5,
240
+ output: 25,
241
+ cache: {
242
+ read: .5,
243
+ write: 6.25
244
+ }
245
+ },
246
+ providers: { cursor: {
247
+ input: 5,
248
+ output: 25,
249
+ cache: {
250
+ read: .75,
251
+ write: 6.5
252
+ }
253
+ } }
254
+ },
255
+ "composer-2.5": {
256
+ default: {
257
+ input: 3,
258
+ output: 15
259
+ },
260
+ providers: { cursor: {
261
+ input: .66,
262
+ output: 4.5,
263
+ cache: { read: .42 }
264
+ } }
265
+ },
266
+ "composer-2.5-fast": {
267
+ default: {
268
+ input: 3,
269
+ output: 15
270
+ },
271
+ providers: { cursor: {
272
+ input: 2.73,
273
+ output: 13.23,
274
+ cache: { read: .76 }
275
+ } }
276
+ },
277
+ "deepseek-v3.2": { default: {
278
+ input: .29,
279
+ output: .43
280
+ } },
281
+ "deepseek-v4-flash": { default: {
282
+ input: .429,
283
+ output: 1.286,
284
+ cache: { read: .014 }
285
+ } },
286
+ "deepseek-v4-pro": { default: {
287
+ input: 1.286,
288
+ output: 3.857,
289
+ cache: { read: .043 }
290
+ } },
291
+ "gemini-3.1-pro": { default: {
292
+ input: 2,
293
+ output: 12
294
+ } },
295
+ "gemini-3.5-flash": {
296
+ default: {
297
+ input: 1.55,
298
+ output: 9.45
299
+ },
300
+ providers: { boxai: {
301
+ input: .15,
302
+ output: .6
303
+ } }
304
+ },
305
+ "gemini-3.6-flash": {
306
+ default: {
307
+ input: 1.5,
308
+ output: 7.5
309
+ },
310
+ providers: { cursor: {
311
+ input: 1.75,
312
+ output: 7.75,
313
+ cache: { read: .4 }
314
+ } }
315
+ },
316
+ "gemini-3.8-flash": {
317
+ default: {
318
+ input: .75,
319
+ output: 3.5,
320
+ cache: { read: .075 }
321
+ },
322
+ providers: { cursor: {
323
+ input: .75,
324
+ output: 3.5,
325
+ cache: { read: .075 }
326
+ } }
327
+ },
328
+ "gemini-4-argon": {
329
+ default: {
330
+ input: 2,
331
+ output: 10,
332
+ cache: { read: .1 }
333
+ },
334
+ providers: { cursor: {
335
+ input: 2,
336
+ output: 10,
337
+ cache: { read: .1 }
338
+ } }
339
+ },
340
+ "gemini-2.5-pro": { default: {
341
+ input: 0,
342
+ output: 0
343
+ } },
344
+ "glm-4.6": { default: {
345
+ input: 0,
346
+ output: 0
347
+ } },
348
+ "glm-4.6v": { default: {
349
+ input: 0,
350
+ output: 0
351
+ } },
352
+ "glm-4.7": { default: {
353
+ input: 0,
354
+ output: 0
355
+ } },
356
+ "glm-5.0": { default: {
357
+ input: 0,
358
+ output: 0
359
+ } },
360
+ "glm-5-fp8": { default: {
361
+ input: 1,
362
+ output: 3.2
363
+ } },
364
+ "glm-5.1": {
365
+ default: {
366
+ input: 1.4,
367
+ output: 4.4
368
+ },
369
+ providers: {
370
+ astra: {
371
+ input: 1,
372
+ output: 3.2
373
+ },
374
+ boxai: {
375
+ input: 1.4,
376
+ output: 4.4,
377
+ cache: { read: .26 }
378
+ },
379
+ kalm: {
380
+ input: 1,
381
+ output: 3.2
382
+ }
383
+ }
384
+ },
385
+ "glm-5.2": {
386
+ default: {
387
+ input: 1.4,
388
+ output: 4.4
389
+ },
390
+ providers: {
391
+ astra: {
392
+ input: 1,
393
+ output: 3.2
394
+ },
395
+ boxai: {
396
+ input: 1.4,
397
+ output: 4.4,
398
+ cache: { read: .26 }
399
+ },
400
+ kalm: {
401
+ input: 1,
402
+ output: 3.2
403
+ }
404
+ }
405
+ },
406
+ "glm-5.3": {
407
+ default: {
408
+ input: 1.4,
409
+ output: 4.4,
410
+ cache: { read: .26 }
411
+ },
412
+ providers: {
413
+ astra: {
414
+ input: 0,
415
+ output: 0
416
+ },
417
+ kalm: {
418
+ input: 0,
419
+ output: 0
420
+ },
421
+ imate: {
422
+ input: 0,
423
+ output: 0
424
+ }
425
+ }
426
+ },
427
+ "glm-5.3-flash": {
428
+ default: {
429
+ input: .15,
430
+ output: .5,
431
+ cache: { read: .03 }
432
+ },
433
+ providers: {
434
+ astra: {
435
+ input: 0,
436
+ output: 0
437
+ },
438
+ kalm: {
439
+ input: 0,
440
+ output: 0
441
+ },
442
+ imate: {
443
+ input: 0,
444
+ output: 0
445
+ }
446
+ }
447
+ },
448
+ "glm-5.3-flashx": { default: {
449
+ input: .37,
450
+ output: 1.25,
451
+ cache: { read: .075 }
452
+ } },
453
+ apex_glm5d3_w4a8_p800: {
454
+ default: {
455
+ input: 1.4,
456
+ output: 4.4,
457
+ cache: { read: .26 }
458
+ },
459
+ providers: { astra: {
460
+ input: 0,
461
+ output: 0
462
+ } }
463
+ },
464
+ "glm-5-turbo": { default: {
465
+ input: 1.2,
466
+ output: 4,
467
+ cache: { read: .24 }
468
+ } },
469
+ "glm-5v-turbo": { default: {
470
+ input: 1.2,
471
+ output: 4,
472
+ cache: { read: .24 }
473
+ } },
474
+ "grok-4.5": {
475
+ default: {
476
+ input: 3,
477
+ output: 15
478
+ },
479
+ providers: { cursor: {
480
+ input: 1.53,
481
+ output: 6.88,
482
+ cache: { read: .249 }
483
+ } }
484
+ },
485
+ "grok-4.5-fast": {
486
+ default: {
487
+ input: 3,
488
+ output: 15
489
+ },
490
+ providers: { cursor: {
491
+ input: 2.62,
492
+ output: 14.45,
493
+ cache: { read: .588 }
494
+ } }
495
+ },
496
+ "grok-4.7": {
497
+ default: {
498
+ input: 2,
499
+ output: 6,
500
+ cache: { read: .5 }
501
+ },
502
+ providers: { cursor: {
503
+ input: 2,
504
+ output: 6,
505
+ cache: { read: .5 }
506
+ } }
507
+ },
508
+ "grok-4.7-fast": {
509
+ default: {
510
+ input: 4,
511
+ output: 12,
512
+ cache: { read: 1 }
513
+ },
514
+ providers: { cursor: {
515
+ input: 4,
516
+ output: 12,
517
+ cache: { read: 1 }
518
+ } }
519
+ },
520
+ "gpt-5.6-sol": {
521
+ default: {
522
+ input: 4,
523
+ output: 20,
524
+ cache: {
525
+ read: .4,
526
+ write: 5
527
+ }
528
+ },
529
+ providers: { cursor: {
530
+ input: 5,
531
+ output: 29.07,
532
+ cache: {
533
+ read: .735,
534
+ write: 6.4
535
+ }
536
+ } }
537
+ },
538
+ "gpt-5.6-sol-fast": { default: {
539
+ input: 8,
540
+ output: 40,
541
+ cache: {
542
+ read: .8,
543
+ write: 10
544
+ }
545
+ } },
546
+ "gpt-5.6-terra": {
547
+ default: {
548
+ input: 2,
549
+ output: 12,
550
+ cache: {
551
+ read: .2,
552
+ write: 2.5
553
+ }
554
+ },
555
+ providers: { cursor: {
556
+ input: 2.5,
557
+ output: 15.25,
558
+ cache: {
559
+ read: .5,
560
+ write: 3.375
561
+ }
562
+ } }
563
+ },
564
+ "gpt-5.6-terra-fast": { default: {
565
+ input: 4,
566
+ output: 24,
567
+ cache: {
568
+ read: .4,
569
+ write: 5
570
+ }
571
+ } },
572
+ "gpt-5.6-luna": { default: {
573
+ input: .2,
574
+ output: 1.2,
575
+ cache: {
576
+ read: .02,
577
+ write: .25
578
+ }
579
+ } },
580
+ "gpt-5.6-luna-fast": { default: {
581
+ input: .4,
582
+ output: 2.4,
583
+ cache: {
584
+ read: .04,
585
+ write: .5
586
+ }
587
+ } },
588
+ "gpt-6-astra": { default: {
589
+ input: 10,
590
+ output: 50,
591
+ cache: {
592
+ read: 1,
593
+ write: 12.5
594
+ }
595
+ } },
596
+ "gpt-6-astra-fast": { default: {
597
+ input: 20,
598
+ output: 100,
599
+ cache: {
600
+ read: 2,
601
+ write: 25
602
+ }
603
+ } },
604
+ "gpt-6-sol": { default: {
605
+ input: 2,
606
+ output: 10,
607
+ cache: {
608
+ read: .2,
609
+ write: 2.5
610
+ }
611
+ } },
612
+ "gpt-6-luna": { default: {
613
+ input: .1,
614
+ output: .5,
615
+ cache: {
616
+ read: .01,
617
+ write: .125
618
+ }
619
+ } },
620
+ "gpt-5.5": {
621
+ default: {
622
+ input: 5,
623
+ output: 30,
624
+ cache: { read: .5 }
625
+ },
626
+ providers: { cursor: {
627
+ input: 3.61,
628
+ output: 13.82,
629
+ cache: { read: .795 }
630
+ } }
631
+ },
632
+ "gpt-5.5-fast": { default: {
633
+ input: 12.5,
634
+ output: 75,
635
+ cache: { read: 1.25 }
636
+ } },
637
+ "gpt-5.4": { default: {
638
+ input: 2.5,
639
+ output: 15,
640
+ cache: { read: .25 }
641
+ } },
642
+ "gpt-5.4-fast": { default: {
643
+ input: 5,
644
+ output: 30,
645
+ cache: { read: .5 }
646
+ } },
647
+ "gpt-5.4-mini": { default: {
648
+ input: .75,
649
+ output: 4.5,
650
+ cache: { read: .075 }
651
+ } },
652
+ "gpt-5.4-nano": { default: {
653
+ input: .2,
654
+ output: 1.25
655
+ } },
656
+ "gpt-5.3-codex": { default: {
657
+ input: 0,
658
+ output: 0
659
+ } },
660
+ "gpt-5.1-codex": { default: {
661
+ input: 0,
662
+ output: 0
663
+ } },
664
+ "gpt-5.1-codex-mini": { default: {
665
+ input: 0,
666
+ output: 0
667
+ } },
668
+ "hy-3": { default: {
669
+ input: .5,
670
+ output: 2
671
+ } },
672
+ "kimi-k2.5": { default: {
673
+ input: .6,
674
+ output: 3
675
+ } },
676
+ "kimi-k2-thinking": { default: {
677
+ input: 0,
678
+ output: 0
679
+ } },
680
+ "kimi-k2.6": {
681
+ default: {
682
+ input: .6,
683
+ output: 3
684
+ },
685
+ providers: { boxai: {
686
+ input: 2,
687
+ output: 8
688
+ } }
689
+ },
690
+ "kimi-k2.7": { default: {
691
+ input: .95,
692
+ output: 4
693
+ } },
694
+ "kimi-k3": { default: {
695
+ input: 3,
696
+ output: 15,
697
+ cache: { read: .3 }
698
+ } },
699
+ "kimi-k2.8-preview": { default: {
700
+ input: 1,
701
+ output: 4,
702
+ cache: { read: .25 }
703
+ } },
704
+ "minimax-m2.5": { default: {
705
+ input: .3,
706
+ output: 1.2
707
+ } },
708
+ "minimax-m2.7": { default: {
709
+ input: .3,
710
+ output: 1.2
711
+ } },
712
+ "minimax-m3": {
713
+ default: {
714
+ input: .6,
715
+ output: 2.4,
716
+ cache: { read: .12 }
717
+ },
718
+ providers: { astra: {
719
+ input: .3,
720
+ output: 1.2
721
+ } }
722
+ },
723
+ "deepseek-v4-pro-0813": { default: {
724
+ input: 0,
725
+ output: 0
726
+ } },
727
+ "hy4-preview": {
728
+ default: {
729
+ input: .834,
730
+ output: 2.501,
731
+ cache: { read: .042 }
732
+ },
733
+ providers: {
734
+ astra: {
735
+ input: 0,
736
+ output: 0
737
+ },
738
+ kalm: {
739
+ input: 0,
740
+ output: 0
741
+ },
742
+ imate: {
743
+ input: 0,
744
+ output: 0
745
+ }
746
+ }
747
+ },
748
+ "qwen3.8-27b": { default: {
749
+ input: 0,
750
+ output: 0
751
+ } },
752
+ "qwen3.8-flash-next": { default: {
753
+ input: 0,
754
+ output: 0
755
+ } },
756
+ "MiMo-V2.6-Flash-RL-astra": { default: {
757
+ input: .14,
758
+ output: .28,
759
+ cache: { read: .0028 }
760
+ } },
761
+ "MiMo-V2.6-Pro-RL-astra": { default: {
762
+ input: .435,
763
+ output: .87,
764
+ cache: { read: .0036 }
765
+ } }
766
+ };
767
+ const clonePricing = (pricing) => ({
768
+ input: pricing.input,
769
+ output: pricing.output,
770
+ ...pricing.cache ? { cache: { ...pricing.cache } } : {}
771
+ });
772
+ const stripProviderSuffixes = (key) => {
773
+ const suffix = PROVIDER_MODEL_SUFFIXES.find((candidate) => key.endsWith(candidate));
774
+ return suffix ? stripProviderSuffixes(key.slice(0, -suffix.length)) : key;
775
+ };
776
+ const normalizeVersionSeparators = (key) => key.replace(/^([a-z]+(?:-[a-z]+)*)-(\d+)-(\d+)(?=-|$)/, "$1-$2.$3");
777
+ /** Peel a trailing capability suffix so the base can be normalized on its own. */
778
+ const splitCapabilitySuffix = (key) => {
779
+ const suffix = CAPABILITY_SUFFIXES.find((candidate) => key.endsWith(candidate));
780
+ return suffix ? {
781
+ base: key.slice(0, -suffix.length),
782
+ capability: suffix
783
+ } : {
784
+ base: key,
785
+ capability: ""
786
+ };
787
+ };
788
+ const normalizeModelPricingKey = (key) => {
789
+ const withoutProviderSuffixes = stripProviderSuffixes(key);
790
+ const withoutContext = stripContextSuffixes(withoutProviderSuffixes);
791
+ const normalizedVersion = normalizeVersionSeparators(withoutContext);
792
+ return MODEL_PRICING_ALIASES[key] ?? MODEL_PRICING_ALIASES[withoutProviderSuffixes] ?? MODEL_PRICING_ALIASES[withoutContext] ?? MODEL_PRICING_ALIASES[normalizedVersion] ?? normalizedVersion;
793
+ };
794
+ const parseVersionedModelKey = (key) => {
795
+ const match = /^([a-z]+(?:-[a-z]+)*)-(\d+)(?:\.(\d+))?(?:-.+)?$/.exec(key);
796
+ if (!match) return void 0;
797
+ return {
798
+ key,
799
+ family: match[1],
800
+ isFast: key.endsWith("-fast"),
801
+ major: Number(match[2]),
802
+ minor: Number(match[3] ?? 0)
803
+ };
804
+ };
805
+ const compareModelVersions = (left, right) => left.major === right.major ? left.minor - right.minor : left.major - right.major;
806
+ const getFallbackPriority = (candidate) => candidate.key.includes("-sol") ? 1 : 0;
807
+ const findVersionFallbackKey = (key) => {
808
+ const requested = parseVersionedModelKey(key);
809
+ if (!requested) return void 0;
810
+ return Object.keys(MODEL_PRICINGS).map(parseVersionedModelKey).filter((candidate) => candidate !== void 0 && candidate.family === requested.family && candidate.isFast === requested.isFast && candidate.major === requested.major && compareModelVersions(candidate, requested) <= 0).sort((left, right) => compareModelVersions(right, left) || getFallbackPriority(right) - getFallbackPriority(left) || left.key.localeCompare(right.key))[0]?.key;
811
+ };
812
+ /**
813
+ * 将 Provider 特有模型 ID 归一化为共享价格 key。
814
+ *
815
+ * 优先级:精确 key → 显式别名 → 去 Provider 后缀 → 同家族同主版本的最近已知版本。
816
+ * 未知 SKU 不会跨主版本猜测价格。
817
+ *
818
+ * 能力后缀(`-fast`)先摘掉再归一化基础 key,否则 `<base>-<context>-fast`
819
+ * 里的 context 位于中间,既剥不掉也命不中别名,整个 SKU 会拿不到价格。
820
+ */
821
+ const resolveModelPricingKey = (key) => {
822
+ if (MODEL_PRICINGS[key]) return key;
823
+ const { base, capability } = splitCapabilitySuffix(key);
824
+ const normalizedBase = normalizeModelPricingKey(base);
825
+ const candidates = capability ? [`${normalizedBase}${capability}`, normalizedBase] : [normalizedBase];
826
+ for (const candidate of candidates) {
827
+ if (MODEL_PRICINGS[candidate]) return candidate;
828
+ const versionFallback = findVersionFallbackKey(candidate);
829
+ if (versionFallback) return versionFallback;
830
+ }
831
+ };
832
+ /**
833
+ * 获取模型的统一价格;未知模型返回 undefined,调用方保留自己的 fallback。
834
+ */
835
+ const getModelPricing = (key, provider) => {
836
+ const resolvedKey = resolveModelPricingKey(key);
837
+ const entry = resolvedKey ? MODEL_PRICINGS[resolvedKey] : void 0;
838
+ const pricing = provider ? entry?.providers?.[provider] ?? entry?.default : entry?.default;
839
+ return pricing ? clonePricing(pricing) : void 0;
840
+ };
841
+ /** 获取模型价格;用于内置模型表,缺失价格属于注册表错误。 */
842
+ const getRequiredModelPricing = (key, provider) => {
843
+ const pricing = getModelPricing(key, provider);
844
+ if (pricing) return pricing;
845
+ throw new Error(`Missing shared pricing for model: ${key}`);
846
+ };
847
+ /** 获取已注册的规范模型默认价格,返回副本以避免外部修改共享注册表。 */
848
+ const getAllModelPricings = () => Object.fromEntries(Object.entries(MODEL_PRICINGS).map(([key, entry]) => [key, clonePricing(entry.default)]));
849
+
850
+ //#endregion
851
+ export { resolveModelPricingKey as i, getModelPricing as n, getRequiredModelPricing as r, getAllModelPricings as t };