okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1import { useEffect , useRef , useState } from 'react' ; 2import { tr } from '../lib/i18n' ; 3import { Icon } from './ui' ; 4import { FloatingMenu } from './FloatingMenu' ; 5import { cx } from '../lib/format' ; 6import { versionNote , type CatalogVersion } from '../lib/native-catalog' ; 7import { nvfp4Version } from '../lib/native-names' ; 8import { fitOn , recommendedVersions , versionFit , versionGroups , type CacheChoice , type FitHardware , type PcPick } from '../lib/native-fit' ; 9 10/** The name a version goes by in the list: the quantization, with the maker only where the quantization alone would be ambiguous. */ 11export function versionName ( v :CatalogVersion ) :string { 12switch ( v . sourceFamily ) { 13case 'swift' :return `Swift ${ v . model } ` ; 14case 'unsloth' :return `Unsloth ${ v . model } ` ; 15case 'nvfp4' :return tr ( nvfp4Version ( v . model )?. name ?? v . model ); 16case 'coder' :return `Coder ${ v . model } ` ; 17default :return v . model ; 18} 19} 20 21/** Who made a version (Details only): the family name of the quantization, a proper name in every language. */ 22const MAKERS :Record < string , string > = { qwen :'GSQ-RCO' , coder :'GSQ-RCO' , swift :'Swift' , unsloth :'Unsloth' , gyro :'Gyro' , nvfp4 :'NVFP4' }; 23 24const gb = ( n :number ) => ` ${ Number . isInteger ( n ) ? n : n . toFixed ( 1 )} GB` ; 25const whole = ( n :number ) => ` ${ Math . round ( n )} GB` ; 26 27/** 28* Where the versions of the chosen base model are listed, each exactly once. At the top: the versions we recommend (the pick for this PC first; no "Recommended" tag since 11-02, the order says it) and the versions already downloaded (tagged "Downloaded"). Below, folded under "More 29* versions": all the others. A row is the name, small tags, a word only where one is needed ("may run slower" for a version that does 30* not fit in memory; a version that fits says nothing: see `versionFit`) and the size. The maker and the 31* memory it needs are behind "Show details" (open from the start in Expert mode). The other base models are not in this list: they 32* appear when picked at the top of the page. 33*/ 34export function VersionPicker ({ versions, selectedId, hardware, onSelect, onOwnGguf, downloaded, showRecommended= true , moreLabel, pick, cache, details :detailsOpen = false } :{ 35/** The versions of the chosen base model. */ 36versions :CatalogVersion []; 37selectedId :string ; 38hardware :FitHardware | null | undefined ; 39onSelect :( id :string ) => void ; 40onOwnGguf :() => void ; 41/** The versions already on this computer (ready to load): each gets a small "Downloaded" tag. */ 42downloaded ?:ReadonlySet < string >; 43/** False where the recommended ones are shown elsewhere (the first-run page): the menu then holds only the others. */ 44showRecommended ?:boolean ; 45/** What the button says while the selected version is one of the recommended ones shown elsewhere. */ 46moreLabel ?:string ; 47/** The engine's own pick for this PC (catalog.recommendation). */ 48pick ?:PcPick | null ; 49/** The conversation context and cache format the person chose: the fit words follow them, as the This computer card does. */ 50cache ?:CacheChoice | null ; 51/** Start with the technical detail shown (Expert mode). */ 52details ?:boolean ; 53}) { 54const trigger = useRef < HTMLButtonElement >( null ); 55const [ open , setOpen ] = useState ( false ); 56const [ details , setDetails ] = useState ( detailsOpen ); 57useEffect (() => setDetails ( detailsOpen ), [ detailsOpen ]); 58const selected = versions . find ( v => v . id === selectedId ); 59// Where the recommended ones are shown outside the menu, the menu holds only the others. 60const rows = recommendedVersions ( versions , pick ); 61const apart = new Set ( showRecommended ?[] :rows . map ( x => x . v . id )); 62const recommendedIds = rows . map ( x => x . v . id ); 63const { top, more} = versionGroups ( versions , apart , downloaded , recommendedIds ); 64const shown = selected && ! apart . has ( selected . id ) ?selected :undefined ; 65// The folded part opens by itself when it holds the chosen version or when there is nothing above it. 66const [ moreOpen , setMoreOpen ] = useState ( false ); 67const foldedOpen = moreOpen || ! top . length || more . some ( v => v . id === selectedId ); 68 69const need = ( v :CatalogVersion , technical :boolean ) => { 70const size = typeof v . fit_gb === 'number' && Number . isFinite ( v . fit_gb ) ?v . fit_gb :fitOn ( v , hardware , true , cache ). memoryGb ; // the files without the lookup table: the figure the label uses 71if ( technical ) return tr ( "{0} RAM + VRAM" , [ gb ( size )]); 72return tr ( "Needs {0} of memory" , [ whole ( size )]); 73}; 74const row = ( v :CatalogVersion ) => { 75const on = v . id === selectedId , have = !! downloaded ?. has ( v . id ); 76const state = versionFit ( v , hardware , cache ); 77const technical = [ MAKERS [ v . sourceFamily ], need ( v , true )]. filter ( Boolean ). join ( ' · ' ); 78const note = versionNote ( v . model ); 79return < button key = { v . id } role = "menuitemradio" aria-checked = { on } className = { cx ( 'version-row' , on && 'is-on' )} onClick = {() => { onSelect ( v . id ); setOpen ( false ); }}> 80< span className = "version-row__check" >{ tr ( on ?< Icon name = "check" size = { 14 }/> :null )}</ span > 81< span className = "version-row__body" > 82< span className = "version-row__title" >< strong >{ versionName ( v )}</ strong >{ tr ( have ?< span className = "version-row__tags" >< span className = "version-tag version-tag--have" >{ tr ( "Downloaded" )}</ span ></ span > :null )}</ span > 83{ tr ( state === 'ssd' ?< span className = "version-row__fit" data-fit = { state }>{ tr ( 'may run slower' )}</ span > :null )} 84{ tr ( details ?< span className = "version-row__tech" >{ technical }{ tr ( note ?<>< br />{ note }</> :null )}</ span > :null )} 85</ span > 86< span className = "version-row__size" >{ have ?gb ( v . download_gb ) :tr ( "{0} download" , [ gb ( v . download_gb )])}</ span > 87</ button >; 88}; 89// The open menu opens on the chosen version, not at the top of a long list. 90const menu = useRef < HTMLDivElement >( null ); 91useEffect (() => { if ( open ) menu . current ?. querySelector ( '.is-on' )?. scrollIntoView ({ block :'nearest' }); }, [ open ]); 92return <> 93< button ref = { trigger } type = "button" className = "version-trigger" aria-haspopup = "menu" aria-expanded = { open } aria-label = { tr ( "Model version" )} onClick = {() => setOpen ( v => ! v )}> 94< strong >{ shown ?versionName ( shown ) :tr ( moreLabel ?? "Choose a version" )}</ strong >{ tr ( shown && downloaded ?. has ( shown . id ) ?< span className = "version-tag version-tag--have" >{ tr ( "Downloaded" )}</ span > :null )} 95< span className = "version-trigger__need muted" >{ tr ( shown ?need ( shown , details ) :'' )}</ span > 96< Icon name = "chevron" size = { 14 } className = "version-trigger__chev" /> 97</ button > 98{ tr ( open ?< FloatingMenu anchor = { trigger . current } title = { tr ( "Model version" )} width = { 520 } onClose = {() => setOpen ( false )}> 99< div className = "version-menu" ref = { menu }> 100{ tr ( top . length ?< div className = "version-section" role = "group" aria-label = { tr ( "Model version" )}>{ tr ( top . map ( row ))}</ div > :null )} 101{ tr ( more . length ?< div className = "version-section" role = "group" aria-label = { tr ( "More versions" )}> 102{ tr ( top . length ?< button role = "menuitem" className = "version-more" aria-expanded = { foldedOpen } onClick = {() => setMoreOpen ( ! foldedOpen )}>< span >{ tr ( "More versions" )} < span className = "muted" >{ more . length }</ span ></ span >< Icon name = "chevron" size = { 14 } className = { cx ( 'version-more__chev' , foldedOpen && 'is-open' )}/></ button > :null )} 103{ tr ( foldedOpen ?< div className = "version-more__rows" >{ tr ( more . map ( row ))}</ div > :null )} 104</ div > :null )} 105< div className = "version-foot" > 106< button role = "menuitem" className = "version-foot__btn" onClick = {() => { setOpen ( false ); onOwnGguf (); }}>< Icon name = "folder" size = { 14 }/>{ tr ( "Use your own GGUF…" )}</ button > 107< button role = "menuitem" className = "version-foot__btn" aria-pressed = { details } onClick = {() => setDetails ( d => ! d )}>{ tr ( details ?"Hide details" :"Show details" )}</ button > 108</ div > 109</ div > 110</ FloatingMenu > :null )} 111</>; 112}