@@ -290,23 +290,16 @@ const normalize = Effect.fnUntraced(function* (
290290 return [
291291 { ...base , variants } ,
292292 ...tiers . flatMap ( ( tier ) => {
293- const mode = modes . find ( ( [ key , options ] ) => ( options . service_tier ?? key ) === tier )
294- // A mode for the tier keeps its ID, so a saved session asks for the same tier, unless another model already
295- // has that ID. Otherwise "priority" is the tier people know as fast.
296- const name =
297- mode && ! ids . has ( Model . ID . make ( `${ source . model . id } -${ mode [ 0 ] } ` ) )
298- ? mode [ 0 ]
299- : tier === "priority" && ! tiers . includes ( "fast" )
300- ? "fast"
301- : tier
293+ // "priority" is the tier people know as fast.
294+ const name = tier === "priority" && ! tiers . includes ( "fast" ) ? "fast" : tier
302295 const speedID = Model . ID . make ( `${ source . model . id } -${ name } ` )
303- // A mode's ID stays with the tier it asks for, even when another tier has that name.
304- if ( ids . has ( speedID ) || ( ! mode && modes . some ( ( [ key ] ) => key === name ) ) ) return [ ]
296+ if ( ids . has ( speedID ) ) return [ ]
297+ // Until every tier has a multiplier, a mode for the tier may still carry its price.
298+ const mode = modes . find ( ( [ key , options ] ) => ( options . service_tier ?? key ) === tier ) ?. [ 1 ]
305299 return [
306300 modelInfo ( providerID , { packageName, baseURL } , speedID , source , {
307301 ...speed ( name , tier ) ,
308- // Until every tier has a multiplier, a mode for the tier may still carry its price.
309- cost : modeCost ( source . model , baseCost , tier , { cost : mode ?. [ 1 ] . cost } ) ,
302+ cost : modeCost ( source . model , baseCost , tier , { cost : mode ?. cost } ) ,
310303 request : tierRequest ( source . route . protocol , tier ) ,
311304 } ) ,
312305 ]
@@ -502,7 +495,7 @@ function modeCost(model: SourceModel, base: Model.Info["cost"], name: string, mo
502495 if ( mode . cost ) return [ cost ( mode . cost ) [ 0 ] , ...baseTiers ]
503496 const tier = mode . service_tier ?? name
504497 // A tier's multiplier may only hold for some dates (an introductory price); the one for today is used.
505- const today = utcDay ( )
498+ const today = new Date ( ) . toISOString ( ) . slice ( 0 , 10 )
506499 const factor = model . cost ?. multipliers ?. find ( ( multiplier ) => {
507500 if ( ! Object . keys ( multiplier . when ) . every ( ( key ) => key === "service_tier" || key === "date" ) ) return false
508501 if ( Option . getOrUndefined ( decodeServiceTier ( multiplier . when . service_tier ) ) ?. equals !== tier ) return false
@@ -557,11 +550,6 @@ function tierPrices(source: SourceCost | undefined, base: Model.Info["cost"][num
557550 }
558551}
559552
560- // Prices are dated by the UTC day, so normalized models are only good until it changes.
561- function utcDay ( ) {
562- return new Date ( ) . toISOString ( ) . slice ( 0 , 10 )
563- }
564-
565553const decodeServiceTier = Schema . decodeUnknownOption ( Schema . Struct ( { equals : Schema . optional ( Schema . String ) } ) )
566554// ISO dates (YYYY-MM-DD), which compare as strings.
567555const decodeDate = Schema . decodeUnknownOption (
@@ -701,19 +689,18 @@ export const decodeSnapshot = (text: string, recommended = false, speeds = false
701689// packages/core/src/models-dev/snapshot.txt and refreshed via
702690// `bun run script/update-models-snapshot.ts`. Release builds bundle the live
703691// catalog in its place when it can be fetched. Decoded and normalized once per
704- // flag value per isolate and day : the snapshot is a multi-MB module-level constant and one isolate can
692+ // flag value per isolate: the snapshot is a multi-MB module-level constant and one isolate can
705693// host many runtimes (Cloudflare colocates Durable Object instances), so
706694// per-runtime decoding would multiply the cost.
707- const bundledCache = new Map < string , { readonly day : string ; readonly snapshot : readonly Snapshot [ ] } > ( )
695+ const bundledCache = new Map < string , readonly Snapshot [ ] > ( )
708696const bundledSnapshot = ( recommended : boolean , speeds : boolean ) =>
709697 Effect . suspend ( ( ) => {
710698 const key = `${ recommended } :${ speeds } `
711- const day = utcDay ( )
712699 const cached = bundledCache . get ( key )
713- return cached ?. day === day
714- ? Effect . succeed ( cached . snapshot )
700+ return cached
701+ ? Effect . succeed ( cached )
715702 : decodeSnapshot ( snapshotText , recommended , speeds ) . pipe (
716- Effect . tap ( ( snapshot ) => Effect . sync ( ( ) => bundledCache . set ( key , { day , snapshot } ) ) ) ,
703+ Effect . tap ( ( snapshot ) => Effect . sync ( ( ) => bundledCache . set ( key , snapshot ) ) ) ,
717704 )
718705 } )
719706
@@ -859,13 +846,6 @@ export const layer = (options?: Options) =>
859846 ( [ recommended , speeds ] ) => Effect . cachedInvalidateWithTTL ( populate ( recommended , speeds ) , Duration . infinity ) ,
860847 )
861848 const get = ( recommended = false , speeds = false ) => caches [ Number ( recommended ) * 2 + Number ( speeds ) ] [ 0 ]
862- // The UTC day the cached models were priced for.
863- const priced = { day : utcDay ( ) }
864- const invalidate = Effect . gen ( function * ( ) {
865- priced . day = utcDay ( )
866- yield * Effect . forEach ( caches , ( [ , invalidate ] ) => invalidate , { discard : true } )
867- yield * bus . publish ( ModelsDev . Event . Refreshed , { } , { global : true } )
868- } )
869849
870850 const refresh = Effect . fn ( "ModelsDev.refresh" ) ( function * ( force = false ) {
871851 yield * lock
@@ -887,15 +867,14 @@ export const layer = (options?: Options) =>
887867 if ( ! response ) return
888868 yield * decodeCatalog ( response . text )
889869 yield * writeCache ( response . text , response . etag , digest )
890- yield * invalidate
870+ yield * Effect . forEach ( caches , ( [ , invalidate ] ) => invalidate , { discard : true } )
871+ yield * bus . publish ( ModelsDev . Event . Refreshed , { } , { global : true } )
891872 } ) ,
892873 )
893874 . pipe (
894875 Effect . tapCause ( ( cause ) => Effect . logError ( "Failed to fetch models.dev" , { cause : cause } ) ) ,
895876 Effect . ignore ,
896877 )
897- // An unchanged or unreachable catalog can still hold a price that started or ended today.
898- if ( priced . day !== utcDay ( ) ) yield * invalidate
899878 } )
900879
901880 if ( fetch && ! process . argv . includes ( "--get-yargs-completions" ) ) {
0 commit comments