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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505<script lang="ts"> import { untrack } from 'svelte'; import { models, type Session } from '../api'; import { effortTone } from '../context'; import EffortBar from '../EffortBar.svelte'; import { busy } from '../live.svelte'; import ModelChoice from '../ModelChoice.svelte'; import { acquireModelChoice, type ModelChoiceBinding } from './model-choice-state.svelte'; import { dismissal, fit, fitted, keepFocus } from '../popover';
// The session's model and reasoning effort in one pill; it opens a filterable // palette of all providers and models to switch the session's model or effort. // When picked while the session is busy, the choice is queued for the next // turn and applied as soon as the turn finishes. let { session, down = false, inline = false, }: { session: Session; /** Opens the pane below the chip (window title bar, phone top bar) rather than above it. */ down?: boolean; /** In the undocked model window's body: renders the model selector and effort bar directly. */ inline?: boolean; } = $props(); let open = $state(false); let profile = $state<string | null>(null); let model = $state<string | null>(null); let effort = $state<string | null>(null); // Docked and undocked pickers share one session-bound save lane. let binding = $state.raw<ModelChoiceBinding | null>(null); let popupScope: object = {}; let picker = $state<HTMLElement>(); let pane = $state<HTMLElement>(); let tipEl = $state<HTMLElement>(); let hoveredPill = $state(false);
const pickerSessionId = $derived(session.id); const queue = $derived(binding?.sessionId === pickerSessionId ? binding.lane.queue : null); const queued = $derived(queue?.pending?.choice ?? null); const problem = $derived(queue?.problem ?? ''); const shownProfile = $derived(queued ? queued.provider_profile : session.provider_profile); const shownModel = $derived(queued ? queued.model : session.model); const shownEffort = $derived(queued ? queued.effort : session.effort);
$effect(() => { const sessionId = pickerSessionId; const next = untrack(() => acquireModelChoice(sessionId, busy(session))); binding = next; untrack(() => { [profile, model, effort] = [session.provider_profile, session.model, session.effort]; popupScope = {}; open = false; }); return () => next.release(); });
$effect(() => { const current = binding; const working = busy(session); if (current?.sessionId === session.id) untrack(() => current.observe(working)); });
// Read the active profile's model catalog so the effort strip has the exact // number of effort capsules that this model actually supports. let modelEfforts = $state<{ profile: string; byModel: Map<string, string[]> } | null>(null);
$effect(() => { const prof = shownProfile; if (!prof || modelEfforts?.profile === prof) return; const controller = new AbortController(); models(prof) .then((list) => { if (controller.signal.aborted) return; modelEfforts = { profile: prof, byModel: new Map(list.map((m) => [m.id, m.efforts.map((e) => e.id)])), }; }) .catch(() => {}); return () => controller.abort(); });
const knownEfforts = $derived( (shownModel && modelEfforts?.profile === shownProfile ? modelEfforts.byModel.get(shownModel) : undefined) ?? [], );
const tier = $derived.by(() => { const tone = effortTone(shownEffort); if (!tone) return null; const known = knownEfforts.length ? knownEfforts : undefined; // Like TUI's effortSteps: 'none' and 'off' fill 0 capsules; positive tiers fill 1..steps.length. const steps = known ? known.filter((id) => id !== 'none' && id !== 'off') : null; if (steps && steps.length > 0) { const idx = shownEffort ? steps.indexOf(shownEffort) : -1; const n = tone === 'none' ? 0 : idx >= 0 ? idx + 1 : Math.min(steps.length, 2); return { n, total: steps.length, tone }; } const fallbackN = tone === 'none' ? 0 : tone === 'low' ? 1 : tone === 'medium' ? 2 : 3; const fallbackTotal = tone === 'xhigh' ? 4 : 3; return { n: tone === 'xhigh' ? 4 : fallbackN, total: fallbackTotal, tone }; });
const label = $derived( [ shownModel ?? 'model', session.fast ? 'Fast mode on' : null, shownEffort ? `effort: ${shownEffort}` : null, queued ? (problem ? 'model choice not saved' : 'queued for next turn') : null, problem || null, ] .filter(Boolean) .join(' · '), );
function show() { [profile, model, effort] = [shownProfile, shownModel, shownEffort]; popupScope = {}; open = !open; }
$effect(() => { if (!hoveredPill || open || inline) return; queueMicrotask(() => tipEl && fit(tipEl)); });
// Before the pane takes the focus, so closing it gives the chip its focus back. $effect.pre(() => { if (open) return keepFocus(); });
$effect(() => { if (!open) return; return dismissal((target) => !!pane?.contains(target) || !!target.closest('.model-chip'), () => (open = false)); });
function save(nextProfile: string | null, nextModel: string | null, nextEffort: string | null, closeAfter: boolean) { const current = binding; if (!current || current.sessionId !== session.id) return; const scope = popupScope; current.observe(busy(session)); current.choose({ provider_profile: nextProfile, model: nextModel, effort: nextEffort }, closeAfter, () => { if (binding === current && popupScope === scope) open = false; }); if (closeAfter && busy(session)) open = false; }
function retry() { const current = binding; if (!current || current.sessionId !== session.id) return; current.observe(busy(session)); current.retry(); }</script>
{#snippet fastIndicator()} {#if session.fast} <span class="fast-indicator" title="Fast mode on" aria-hidden="true"> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"> <path d="m13 2-9 12h7l-1 8 10-12h-7z" /> </svg> </span> {/if}{/snippet}
{#snippet choicePane()} {#if open} <div class="pane nowheel holds-wheel" class:down bind:this={pane} {@attach fitted(!down)} role="dialog" aria-label="model for this session" > <ModelChoice bind:profile bind:model bind:effort currentProfile={shownProfile} currentModel={shownModel} autofocus onpick={(p, m, e) => save(p, m, e, true)} oneffort={(e) => save(profile, model, e, false)} /> {#if problem}<p class="problem" role="alert">{problem}</p>{/if} {#if queued && !queue?.inflight} <p class="pending">{problem ? 'Model choice not saved.' : 'Model choice queued for the next idle turn.'} <button type="button" onclick={retry}>Retry</button></p> {/if} </div> {/if}{/snippet}
{#if inline} <div class="picker inline-model nodrag" class:open bind:this={picker} role="group"> <div class="inline-controls"> <div class="model-pick-wrap"> <button type="button" class="model-pick-row model-chip" aria-haspopup="true" aria-expanded={open} aria-label={label} onclick={show}> <span class="mp-left"> <span class="mp-name">{shownModel ?? 'model'}</span> {@render fastIndicator()} {#if shownProfile} <span class="mp-prof">{shownProfile}</span> {/if} </span> <span class="mp-chev" aria-hidden="true">▾</span> </button> {@render choicePane()} </div> {#if knownEfforts.length > 0} <EffortBar efforts={knownEfforts} value={shownEffort} onpick={(opt) => save(shownProfile, shownModel, opt, false)} /> {/if} {#if problem && !open}<p class="problem">{problem}</p>{/if} </div> </div>{:else} <span class="picker nodrag" class:open class:hovered={hoveredPill && !open} bind:this={picker} role="group" onmouseenter={() => (hoveredPill = true)} onmouseleave={() => (hoveredPill = false)} > <button type="button" class="model-chip" class:has-effort={tier !== null} aria-haspopup="true" aria-expanded={open} aria-label={label} onclick={show} > <span class="name">{shownModel ?? 'model'}</span> {@render fastIndicator()} {#if problem}<span class="error-mark" aria-hidden="true">!</span>{/if} {#if tier && tier.total > 0} <span class="effort-capsules" style:--steps={tier.total} aria-hidden="true"> {#each Array.from({ length: tier.total }, (_, i) => i + 1) as step (step)} <span class={step <= tier.n ? `lit step-${Math.min(4, Math.ceil((step / tier.total) * 4))}` : ''}></span> {/each} </span> {/if} </button> {#if !open && (problem || session.fast)} <div class="tip" class:down bind:this={tipEl} role="tooltip" > {#if session.fast}<div>Fast mode on</div>{/if} {#if problem}<div class="tip-problem">{problem}</div>{/if} </div> {/if} {@render choicePane()} </span>{/if}
<style> .picker { position: relative; display: inline-flex; min-width: 0; } .picker.hovered { z-index: 15; } .picker.open { z-index: 30; } .model-chip { position: relative; display: inline-flex; align-items: center; gap: 5px; height: 26px; max-width: 100%; padding: 0 9px; overflow: hidden; color: var(--muted); font: inherit; font-size: calc(11.5px * var(--ui-scale)); font-variant-numeric: tabular-nums; line-height: 1; white-space: nowrap; background: var(--well); border: 0; border-radius: 8px; cursor: pointer; transition: background-color 120ms ease, color 120ms ease; } .fast-indicator { display: inline-flex; flex: none; align-self: center; color: var(--accent); } .model-chip.has-effort { height: 28px; padding-bottom: 4px; } .inline-controls { display: flex; flex-direction: column; gap: 5px; padding: 6px; background: var(--well); border-radius: 10px; } .model-pick-wrap { position: relative; } .model-chip.model-pick-row { width: 100%; height: auto; justify-content: space-between; padding: 6px 8px; line-height: 1.25; background: none; border-radius: 7px; } .model-chip.model-pick-row:hover, .model-chip.model-pick-row[aria-expanded='true'] { background: var(--hover); } .mp-left { display: flex; align-items: baseline; gap: 6px; min-width: 0; } .mp-name { font-size: calc(12px * var(--ui-scale)); font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; } .mp-prof { flex: none; font-family: var(--mono); font-size: calc(10.5px * var(--ui-scale)); color: var(--muted); } .mp-chev { flex: none; color: var(--muted); font-size: calc(11px * var(--ui-scale)); }
.model-chip:hover, .model-chip[aria-expanded='true'] { color: var(--text); background: var(--field); } .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; } .error-mark { color: var(--danger); font-weight: 700; } /* Individually rounded capsules along the bottom edge of the chip, one per effort step the model supports. */ .effort-capsules { position: absolute; right: 8px; bottom: 2px; left: 8px; display: grid; grid-template-columns: repeat(var(--steps, 3), 1fr); align-items: end; gap: 4px; height: 4px; pointer-events: none; } .effort-capsules span { height: 3px; background: color-mix(in oklab, var(--text) 12%, transparent); border-radius: 999px; } .effort-capsules span.lit.step-1 { height: 2px; background: oklch(from var(--accent) 0.44 calc(c * 0.6) calc(h - 14)); } .effort-capsules span.lit.step-2 { height: 2.6px; background: oklch(from var(--accent) 0.61 calc(c * 1.05) h); } .effort-capsules span.lit.step-3 { height: 3.3px; background: oklch(from var(--accent) 0.78 calc(c * 1.45) calc(h + 14)); } .effort-capsules span.lit.step-4 { height: 4px; background: oklch(from var(--accent) 0.93 calc(c * 1.7) calc(h + 26)); box-shadow: 0 0 6px oklch(from var(--accent) 0.86 calc(c * 1.6) calc(h + 22)); } :global(:root[data-albedo-theme='light']) .effort-capsules span.lit.step-1 { background: oklch(from var(--accent) 0.76 calc(c * 0.55) calc(h - 10)); } :global(:root[data-albedo-theme='light']) .effort-capsules span.lit.step-2 { background: oklch(from var(--accent) 0.64 calc(c * 0.95) h); } :global(:root[data-albedo-theme='light']) .effort-capsules span.lit.step-3 { background: oklch(from var(--accent) 0.52 calc(c * 1.3) calc(h + 12)); } :global(:root[data-albedo-theme='light']) .effort-capsules span.lit.step-4 { background: oklch(from var(--accent) 0.42 calc(c * 1.6) calc(h + 22)); box-shadow: none; } .tip { position: absolute; bottom: calc(100% + 5px); left: 0; z-index: 15; padding: 5px 9px; color: var(--text); font-size: calc(11.5px * var(--ui-scale)); font-variant-numeric: tabular-nums; white-space: nowrap; pointer-events: auto; visibility: hidden; opacity: 0; background: var(--surface); border-radius: 8px; box-shadow: 0 8px 24px rgb(0 0 0 / 0.26), inset 0 0 0 1px color-mix(in oklab, var(--text) 10%, transparent); transition: opacity 120ms ease, visibility 120ms ease; } .tip-problem { max-width: 280px; color: var(--danger); white-space: normal; } /* Invisible hover bridge so moving the cursor from .model-chip into .tip never drops :hover. */ .tip::before { content: ''; position: absolute; right: 0; bottom: 100%; left: 0; height: 8px; } .tip.down { top: calc(100% + 5px); bottom: auto; } .tip.down::before { top: -8px; bottom: auto; } .picker:hover .tip, .model-chip:focus-visible + .tip { visibility: visible; opacity: 1; } .picker.inline-model { display: flex; flex-direction: column; gap: 8px; width: 100%; padding: 12px 14px; color: var(--text); font-size: calc(11.5px * var(--ui-scale)); font-variant-numeric: tabular-nums; } .pane { position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 20; width: min(356px, calc(100vw - 24px)); background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); } .pane.down { top: calc(100% + 6px); bottom: auto; } .pending { margin: 0; padding: 6px 12px 10px; color: var(--muted); font-size: calc(12px * var(--ui-scale)); } .pending button { color: var(--text); font: inherit; background: var(--field); border: 0; border-radius: 4px; cursor: pointer; } .problem { margin: 0; padding: 0 12px 10px; color: var(--danger); font-size: calc(11.5px * var(--ui-scale)); }</style>