@@ -34,34 +34,44 @@ interface OpenCodeZenPricing {
3434 outputCostPerToken : number
3535}
3636
37- const OPENCODE_ZEN_MODELS : Record <
38- string ,
39- { opencodeId : string ; pricing : OpenCodeZenPricing }
40- > = {
41- [ openCodeZenModels . opencode_kimi_k2_6 ] : {
42- opencodeId : 'kimi-k2.6' ,
43- pricing : {
44- inputCostPerToken : 0.95 / 1_000_000 ,
45- cachedInputCostPerToken : 0.16 / 1_000_000 ,
46- outputCostPerToken : 4.0 / 1_000_000 ,
47- } ,
48- } ,
37+ const OPENCODE_MODEL_PREFIX = 'opencode/'
38+ const MOONSHOT_KIMI_MODEL = 'moonshotai/kimi-k2.6'
39+ const KIMI_ZEN_MODEL = 'kimi-k2.6'
40+
41+ const OPENCODE_ZEN_MODEL_ALIASES : Record < string , string > = {
42+ [ openCodeZenModels . opencode_kimi_k2_6 ] : KIMI_ZEN_MODEL ,
43+ [ MOONSHOT_KIMI_MODEL ] : KIMI_ZEN_MODEL ,
4944}
5045
51- export function isOpenCodeZenModel ( model : string ) : boolean {
52- return model in OPENCODE_ZEN_MODELS
46+ const KIMI_ZEN_PRICING : OpenCodeZenPricing = {
47+ inputCostPerToken : 0.95 / 1_000_000 ,
48+ cachedInputCostPerToken : 0.16 / 1_000_000 ,
49+ outputCostPerToken : 4.0 / 1_000_000 ,
50+ }
51+
52+ const OPENCODE_ZEN_PRICING : Record < string , OpenCodeZenPricing > = {
53+ [ KIMI_ZEN_MODEL ] : KIMI_ZEN_PRICING ,
54+ }
55+
56+ export function isOpenCodeZenModel ( model : unknown ) : model is string {
57+ if ( typeof model !== 'string' ) return false
58+ return (
59+ model . startsWith ( OPENCODE_MODEL_PREFIX ) ||
60+ model in OPENCODE_ZEN_MODEL_ALIASES
61+ )
5362}
5463
5564function getOpenCodeZenModelId ( model : string ) : string {
56- return OPENCODE_ZEN_MODELS [ model ] ?. opencodeId ?? model
65+ return (
66+ OPENCODE_ZEN_MODEL_ALIASES [ model ] ??
67+ ( model . startsWith ( OPENCODE_MODEL_PREFIX )
68+ ? model . slice ( OPENCODE_MODEL_PREFIX . length )
69+ : model )
70+ )
5771}
5872
5973function getOpenCodeZenPricing ( model : string ) : OpenCodeZenPricing {
60- const entry = OPENCODE_ZEN_MODELS [ model ]
61- if ( ! entry ) {
62- throw new Error ( `No OpenCode Zen pricing found for model: ${ model } ` )
63- }
64- return entry . pricing
74+ return OPENCODE_ZEN_PRICING [ getOpenCodeZenModelId ( model ) ] ?? KIMI_ZEN_PRICING
6575}
6676
6777type StreamState = {
0 commit comments