okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0b3299a01
main
1/** Locate catalog weights in a Strata folder or directly inside an existing GGUF folder. */ 2import { closeSync , existsSync , openSync , readSync , realpathSync , statSync } from 'node:fs' ; 3import { isAbsolute , join , relative } from 'node:path' ; 4 5export function matchesGGUF ( file , bytes , directory ) { 6let fd ; 7try { 8if ( ! existsSync ( file )) return false ; 9const path = relative ( realpathSync ( directory ), realpathSync ( file )); 10if ( path . startsWith ( '..' ) || isAbsolute ( path )) return false ; 11const stat = statSync ( file ); 12if ( ! stat . isFile () || stat . size !== bytes ) return false ; 13fd = openSync ( file , 'r' ); 14const magic = Buffer . alloc ( 4 ); readSync ( fd , magic , 0 , 4 , 0 ); 15return magic . toString () === 'GGUF' ; 16} catch { return false ; } 17finally { if ( fd !== undefined ) closeSync ( fd ); } 18} 19 20export function locateModelFile ( directory , model ) { 21const nested = join ( directory , model . id , model . source . file ); 22if ( matchesGGUF ( nested , model . source . bytes , directory )) return nested ; 23const flat = join ( directory , model . source . file ); 24// The design catalog deliberately has ambiguous filenames across model families. 25if ( ! model . designOnly && matchesGGUF ( flat , model . source . bytes , directory )) return flat ; 26return null ; 27}