import { prefs } from './prefs.svelte'; export function modelName(model: { id: string; label?: string | null; }): string { if (prefs.modelNames === 'ids' || !model.label) return model.id; return nameCase(model.label); } export function effortName(level: string): string { if (prefs.modelNames === 'ids') return level; if (level === 'xhigh') return nameCase('Extra high'); return nameCase(level.charAt(0).toUpperCase() + level.slice(1)); } /** Words around names, like "Provider default", take the case the names do. */ export function nameCase(text: string): string { return prefs.modelNames === 'names' ? text : text.toLowerCase(); } export function profileOverride( level: string | null | undefined, ): string | null { return level && level !== 'inherit' && level !== 'default' ? level : null; } /** Only real levels; retain a provider-default row when its level is unknown. */ export function effortChoices( levels: readonly string[], current: string | null, modelDefault?: string | null, profile?: string | null, ): string[] { const defaultLevel = effectiveEffort( current === 'default' ? 'default' : 'inherit', modelDefault, profile, ); const choices = [...levels]; if (defaultLevel && !choices.includes(defaultLevel)) choices.push(defaultLevel); if (!defaultLevel) choices.unshift('inherit'); if ( current && current !== 'inherit' && current !== 'default' && !choices.includes(current) ) choices.push(current); return choices; } export function choiceForLevel( level: string, current: string | null, modelDefault?: string | null, profile?: string | null, ): string { const mode = current === 'default' ? 'default' : 'inherit'; return level === 'inherit' || level === effectiveEffort(mode, modelDefault, profile) ? mode : level; } /** * The choice a model row starts from: the carried one, unless the model lacks * the level it resolves to, which the daemon refuses. Then medium when the * model has it, else the model default. */ export function startingEffort( choice: string | null, efforts: readonly string[], modelDefault?: string | null, defaultSource?: string | null, profile?: string | null, ): string | null { const effective = effectiveEffort(choice, modelDefault, profile); const adapterDefault = defaultSource === 'albedo' && (choice === 'default' || (choice === 'inherit' && !profileOverride(profile))); if (!effective || efforts.includes(effective) || adapterDefault) return choice; return efforts.includes('medium') ? 'medium' : 'default'; } export function effectiveEffort( choice: string | null, modelDefault: string | null | undefined, profile: string | null | undefined, ): string | null { if (choice === null) return null; if (choice === 'inherit') return profileOverride(profile) ?? modelDefault ?? null; return choice === 'default' ? (modelDefault ?? null) : choice; }