okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
31030b170
main
1import { tr } from '../lib/i18n' ; 2import { useState } from 'react' ; 3import { Btn , Dialog , ErrorNotice } from './ui' ; 4import { nativeAction , nativeState , refreshNative , useNative , type NativeJob } from '../lib/native' ; 5import { catalogVersionLabel , nativeCatalogModels } from '../lib/native-catalog' ; 6import { sizeGb } from '../lib/format' ; 7 8/** Delete a downloaded (native) model: its own files and run config. What another installed model still uses stays. A loaded model 9* is unloaded first by the host. Same dialog and words as deleting a version of the managed library. */ 10export function NativeDeleteDialog ({ id, onClose} :{ id :string | null ; onClose :() => void }) { 11const native = useNative (); 12const [ pending , setPending ] = useState ( false ), [ error , setError ] = useState ( '' ); 13const entry = native ?. installed ?. models . find ( m => m . model === id ); 14const label = (() => { const sizes = nativeCatalogModels ( native ?. catalog ?. families ?? []). flatMap ( f => f . sizes ); const v = sizes . find ( s => s . id === id ); return v ?` ${ catalogVersionLabel ( v )} · ${ v . model } ` :entry ?. model_name ?? id ?? '' ; })(); 15const running = !! native ?. instances . some ( i => i . model === id ); 16const busy = !! native ?. jobs . some ( j => j . state === 'running' ); 17const size = entry ?. diskGb ?? 0 , gb = entry ?. removableGb ?? size ; 18// Files in the person's own folder (an adopted GGUF) stay where they are: only the entry is removed. 19const keepsFiles = entry ?. removableGb === 0 && size > 0 ; 20function close () { if ( ! pending ) { onClose (); setError ( '' ); } } 21async function remove () { 22setPending ( true ); 23setError ( '' ); 24try { 25const job = await nativeAction < NativeJob >( 'operations' , { kind :'remove' , args :{ model :id } }); 26for ( let i = 0 ; i < 600 ; i ++ ) { 27await new Promise ( r => setTimeout ( r , 500 )); 28await refreshNative ( true ). catch (() => undefined ); 29const current = nativeState ()?. jobs . find ( j => j . id === job . id ); 30if ( current && current . state !== 'running' ) { 31if ( current . state === 'error' ) throw new Error ( current . error ?? 'Could not delete this version.' ); 32break ; 33} 34} 35onClose (); 36} 37catch ( e ) { setError ( e instanceof Error ?e . message :String ( e )); } 38finally { setPending ( false ); } 39} 40return < Dialog open = { !! id } compact title = { tr ( "Delete this version?" )} onClose = { close } actions = {<>< Btn disabled = { pending } onClick = { close }>{ tr ( "Keep version" )}</ Btn >< Btn variant = "danger" disabled = { pending || busy || ! entry } onClick = {() => void remove ()}>{ tr ( pending ?'Working…' :'Delete version' )}</ Btn ></>}> 41< p >{ tr ( label )}{ tr ( size ?` · ${ sizeGb ( size )} ` :'' )}</ p > 42{ tr ( ! entry ?< p className = "small muted" >{ tr ( "This version is no longer downloaded." )}</ p > :< p className = "small muted storage-delete-note" >{ keepsFiles ?tr ( 'These files are in your own folder, so they stay there. Only the entry in Strata is removed.' ) :tr ( 'Remove {0} GB of downloaded files. You can download this version again.' , [ gb ?gb . toFixed ( 1 ) :'0' ])}{ tr ( running ?' ' :'' )}{ tr ( running ?( keepsFiles ?'The running model will be unloaded.' :'The running model will be unloaded and its files deleted.' ) :'' )}</ p >)} 43{ tr ( error ?< ErrorNotice message = { error }/> :null )} 44</ Dialog >; 45}