Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524<script lang="ts"> import { onMount } from 'svelte'; import { models, profiles, type Model, type Profile } from './api'; import { shortCount } from './context'; import { nextModelEffort } from './modelEffort'; import { compareRank, matchFields, searchKey, searchWords, splitSegments, type MatchRank, } from './format'; import EffortBar from './EffortBar.svelte'; import SearchCard from './SearchCard.svelte';
// Unified provider + model selector with TUI-style fuzzy search across // provider names and model ids, character match highlights, ranking within // and across profile groups, and an effort segmented bar in the footer. let { profile = $bindable(), model = $bindable(), effort = $bindable(), cyberAccess = $bindable<string | null>(null), sessionId, currentCyberAccess = null, currentProfile = null, currentModel = null, autofocus = false, onpick, oneffort, }: { profile: string | null; model: string | null; effort: string | null; cyberAccess?: string | null; sessionId?: string; currentCyberAccess?: string | null; /** The session's current provider, sorted first and tagged `current`. */ currentProfile?: string | null; /** The session's current model id, tagged `current` on `currentProfile`. */ currentModel?: string | null; autofocus?: boolean; /** Called when a model row is picked (clicked or Enter on the first/highlighted match). */ onpick?: ( profile: string, model: string, effort: string | null, cyberAccess: string | null, ) => void; /** Called when an effort pill in the footer is clicked. */ oneffort?: (effort: string) => void; } = $props();
let all = $state<Profile[]>([]); let byProfile = $state<Record<string, Model[]>>({}); let loading = $state(true); let problem = $state(''); let query = $state(''); let highlighted = $state(0); /** An arrow moved the highlight, so it is drawn with no filter too: Enter picks it. */ let keyed = $state(false); // svelte-ignore state_referenced_locally const pinFirst = currentProfile ?? profile;
onMount(() => { profiles() .then(async (found) => { const entries = await Promise.all( found.profiles.map((p) => models(p.id, sessionId).then( (items) => [p.id, items] as const, (error) => { problem = `Could not verify model access for ${p.id}: ${String((error as Error).message ?? error)}`; return [p.id, [] as Model[]] as const; }, ), ), ); const loaded = Object.fromEntries(entries); byProfile = loaded; all = found.profiles; if (!profile) { const def = found.profiles.find((p) => p.id === found.fallback) ?? found.profiles[0]; if (def) { profile = def.id; model ??= def.model ?? loaded[def.id]?.[0]?.id ?? null; effort ??= def.effort; } } else if (!model && loaded[profile]?.[0]) { model = loaded[profile][0].id; } }) .catch((error) => (problem = String((error as Error).message ?? error))) .finally(() => (loading = false)); });
/** Seed a profile's model list with its configured default + current model until /models finishes. */ function rowsOf(p: Profile): Model[] { const loaded = byProfile[p.id] ?? []; const seen = new Set(loaded.map((m) => m.id)); const seeds: Model[] = []; for (const id of [p.id === currentProfile ? currentModel : null, p.model]) { if (id && !seen.has(id)) { seen.add(id); seeds.push({ id, label: id, efforts: [], default_context_tokens: null, effective_context_tokens: null, max_context_tokens: null, max_output_tokens: null, input_modalities: [], image_edge: null, raised: false, cap_key: `${p.id}/${id}`, cache_policy: { ttl_seconds: null, source: null }, source: 'seed', observed_at: null, }); } } return [...seeds, ...loaded]; }
const orderedProfiles = $derived( [...all].sort((a, b) => { if (a.id === pinFirst && b.id !== pinFirst) return -1; if (b.id === pinFirst && a.id !== pinFirst) return 1; return a.id.localeCompare(b.id); }), );
function matchModel( words: string[], pId: string, mId: string, blue: boolean, ): { rank: MatchRank; hits: number[] } | null { const res = matchFields(words, blue ? `${mId} Daybreak Blue` : mId, pId); if (!res) return null; const whole = words.join(''); if (whole && whole === searchKey(pId + mId)) { res.rank[0] = 1; } return { ...res, hits: res.hits.filter((index) => index < mId.length) }; }
const groups = $derived.by(() => { const words = searchWords(query);
const rawGroups: { profile: Profile; best: MatchRank; scored: { profile: string; model: Model; hits: number[]; rank: MatchRank; blue: boolean; }[]; }[] = [];
for (const p of orderedProfiles) { const scored: { profile: string; model: Model; hits: number[]; rank: MatchRank; blue: boolean; }[] = []; for (const m of rowsOf(p)) { for (const blue of [ false, ...(m.cyber_access?.status === 'supported' ? [true] : []), ]) { const matched = matchModel( words, p.id, m.id, blue || m.cyber_access?.status === 'unknown', ); if (matched) scored.push({ profile: p.id, model: m, hits: matched.hits, rank: matched.rank, blue, }); } } if (!scored.length) continue; if (words.length) scored.sort((a, b) => compareRank(a.rank, b.rank)); rawGroups.push({ profile: p, best: scored[0].rank, scored }); }
if (words.length) { rawGroups.sort((a, b) => compareRank(a.best, b.best)); }
let idx = 0; return rawGroups.map((g) => ({ profile: g.profile, items: g.scored.map((s) => ({ profile: s.profile, model: s.model, hits: s.hits, blue: s.blue, flatIndex: idx++, })), })); });
const flat = $derived(groups.flatMap((g) => g.items));
$effect(() => { query; highlighted = 0; });
const activeModelRecord = $derived( (profile ? byProfile[profile]?.find((m) => m.id === model) : undefined) ?? null, ); const efforts = $derived(activeModelRecord?.efforts ?? []);
function nextEffortFor(pId: string, m: Model): string | null { // Synthetic default/current rows have no metadata, unlike catalog rows // whose empty effort list explicitly means no supported effort. const known = byProfile[pId]?.find((item) => item.id === m.id); return nextModelEffort( known ? known.efforts.map((e) => e.id) : null, effort, all.find((p) => p.id === pId)?.effort ?? null, pId === profile, ); }
function selectRow(pId: string, m: Model, blue: boolean) { const nextEff = nextEffortFor(pId, m); profile = pId; model = m.id; effort = nextEff; cyberAccess = blue ? 'daybreak_blue' : null; onpick?.(pId, m.id, nextEff, cyberAccess); }
function selectEffort(nextEff: string) { effort = nextEff; oneffort?.(nextEff); }
function keydown(event: KeyboardEvent) { if (event.key === 'ArrowDown') { if (!flat.length) return; event.preventDefault(); keyed = true; highlighted = (highlighted + 1) % flat.length; return; } if (event.key === 'ArrowUp') { if (!flat.length) return; event.preventDefault(); keyed = true; highlighted = (highlighted + flat.length - 1) % flat.length; return; } if (event.key === 'Enter' && !event.isComposing) { const target = flat[highlighted] ?? flat[0]; if (!target) return; event.preventDefault(); event.stopPropagation(); selectRow(target.profile, target.model, target.blue); } }</script>
<SearchCard bind:query placeholder="filter by model or provider…" ariaLabel="models" {autofocus} onkeydown={keydown} foot={!loading && efforts.length ? effortFoot : undefined}> {#if loading} <div class="loading" role="status"> <span class="spinner" aria-hidden="true"></span> <span>loading models…</span> </div> {:else} {#each groups as group (group.profile.id)} <div class="group-head"> <span>{group.profile.id}</span> <span class="count">{group.items.length}</span> </div> {#each group.items as item (`${item.profile}:${item.model.id}:${item.blue}`)} {@const isCurrent = currentProfile !== null ? item.profile === currentProfile && item.model.id === currentModel && item.blue === (currentCyberAccess === 'daybreak_blue') : item.profile === profile && item.model.id === model && item.blue === (cyberAccess === 'daybreak_blue')} {@const isSelected = item.profile === profile && item.model.id === model && item.blue === (cyberAccess === 'daybreak_blue')} {@const ctx = item.model.effective_context_tokens ?? item.model.default_context_tokens} <button type="button" role="option" class="row" class:selected={isSelected} class:highlighted={item.flatIndex === highlighted && (keyed || query.trim().length > 0)} aria-selected={isSelected} onpointerenter={() => (highlighted = item.flatIndex)} onclick={() => selectRow(item.profile, item.model, item.blue)} > <span class="name"> <span class="id"> {#each splitSegments(item.model.id, item.hits) as seg} {#if seg.hit}<mark>{seg.text}</mark>{:else}{seg.text}{/if} {/each} </span> <span class="tag" class:blue={item.blue} >{item.blue ? 'Daybreak Blue' : 'Standard'}</span > {#if !item.blue && item.model.cyber_access?.status === 'unknown'} <span class="tag unknown">Blue unknown</span> {/if} {#if isCurrent} <span class="tag current">current</span> {/if} </span> {#if ctx} <span class="ctx">{shortCount(ctx)}</span> {/if} {#if !item.blue && item.model.cyber_access?.status === 'unknown'} <span class="availability" >Blue access could not be verified: {item.model.cyber_access .detail ?? 'Catalog metadata is unavailable'}. Standard remains available.</span > {/if} </button> {/each} {:else} <p class="empty">no models match</p> {/each} {/if} {#if problem}<p class="problem">{problem}</p>{/if}</SearchCard>
{#snippet effortFoot()} <EffortBar efforts={efforts.map((o) => o.id)} value={effort} onpick={selectEffort} />{/snippet}
<style> .group-head { display: flex; align-items: baseline; gap: 6px; padding: 7px 10px 3px; color: color-mix(in oklab, var(--text) 65%, var(--muted)); font-size: calc(11px * var(--ui-scale)); font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; } .group-head .count { color: var(--muted); font-family: var(--mono); font-size: calc(10.5px * var(--ui-scale)); font-weight: 500; font-variant-numeric: tabular-nums; } .group-head::after { content: ''; flex: 1; align-self: center; height: 1px; background: color-mix(in oklab, var(--text) 12%, transparent); } .row { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%; padding: 6px 10px; color: var(--text); font: inherit; text-align: left; background: none; border: 0; border-radius: 8px; cursor: pointer; } .row:hover, .row.highlighted { background: var(--hover); } .row.selected { background: color-mix(in oklab, var(--accent) 15%, transparent); } .row.selected::before { content: ''; position: absolute; top: 6px; bottom: 6px; left: 2px; width: 2.5px; background: var(--accent); border-radius: 2px; } .name { display: flex; align-items: center; gap: 7px; min-width: 0; font-family: var(--mono); font-size: calc(12px * var(--ui-scale)); } .row.selected .id { font-weight: 600; } .id { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .id mark { padding: 0; color: var(--accent); font-weight: 650; background: none; } .tag { flex: none; padding: 1px 5px; font-family: var(--sans); font-size: calc(10px * var(--ui-scale)); font-weight: 600; border-radius: 4px; } .tag.unknown { color: var(--muted); background: var(--field); } .availability { grid-column: 1 / -1; color: var(--muted); font: calc(11px * var(--ui-scale))/1.4 var(--sans); white-space: normal; } .tag.blue { color: var(--accent); background: color-mix(in oklab, var(--accent) 14%, transparent); } .tag.current { color: var(--added); background: color-mix(in oklab, var(--added) 16%, transparent); } .ctx { flex: none; color: var(--muted); font-family: var(--mono); font-size: calc(11px * var(--ui-scale)); font-variant-numeric: tabular-nums; } .loading { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; height: 100%; min-height: 180px; color: var(--muted); font-size: calc(12px * var(--ui-scale)); } .spinner { width: 16px; height: 16px; border: 1.8px solid color-mix(in oklab, var(--text) 16%, transparent); border-top-color: var(--accent); border-radius: 50%; animation: spin 680ms linear infinite; } @keyframes spin { to { transform: rotate(360deg); } } .empty { margin: 0; padding: 14px 10px; color: var(--faint); font-size: calc(12px * var(--ui-scale)); text-align: center; }
.problem { margin: 0; padding: 6px 11px; color: var(--danger); font-size: calc(12px * var(--ui-scale)); }</style>