Something went wrong. Try again.
small gleam coding and (not yet) persistent agent daemon with a detachable cli forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364<script lang="ts"> import { arrangeQueue, clearQueue, dropQueued, moveQueuedFirst, type QueueCollection, type QueueItem, } from '../api'; import type { Transcript } from '../transcript.svelte'; let { sessionId, transcript }: { sessionId: string; transcript: Transcript } = $props(); const items = $derived(transcript.queue); const total = $derived(transcript.queueTotal); let failed = $state(''); const error = $derived(failed || transcript.queueError || ''); let dragging = $state<string | null>(null); let busy = $state<string | null>(null); async function act( id: string, action: () => Promise<QueueCollection>, dropped: string[] = [], ) { busy = id; try { transcript.applyQueue(await action(), dropped); failed = ''; } catch (cause) { failed = (cause as Error).message; void transcript.refreshQueue(); } finally { busy = null; } } function delivery(item: QueueItem) { return { steer: 'next step', wait: 'after this turn', alone: 'own turn', next_turn: 'with next turn', attach: 'attached now', }[item.delivery]; } function attached(item: QueueItem) { const images = item.images.length; return [ ...(images ? [`${images} image${images === 1 ? '' : 's'}`] : []), ...item.files.map((file) => file.name), ].join(', '); } function preview(item: QueueItem) { const text = item.text.trim().replace(/\s+/g, ' '); return ( text || (item.images.length || item.files.length ? 'attachments' : 'empty input') ); } async function clear() { if (!confirm(`clear ${total} waiting ${total === 1 ? 'item' : 'items'}?`)) return; const ids = items.map((item) => item.id); await act('all', () => clearQueue(sessionId), ids); } async function unsend(id: string) { busy = id; try { await transcript.unsend(id); failed = ''; } catch (cause) { failed = (cause as Error).message; } finally { busy = null; } } async function reorder(target: string) { if (!dragging || dragging === target) return; const ids = items.map((item) => item.id); const from = ids.indexOf(dragging), to = ids.indexOf(target); ids.splice(from, 1); ids.splice(to, 0, dragging); await act('order', () => arrangeQueue(sessionId, ids)); dragging = null; }</script>
{#if items.length || error} <section class="queue" aria-label="waiting inputs"> <header> <span class="title">waiting <span class="count">{total}</span></span> {#if total > 1}<button class="clear" disabled={busy !== null} onclick={clear}>clear all</button >{/if} </header> {#if error}<p class="error">couldn't update the queue · {error}</p>{/if} {#if items.length} <ol> {#each items as item, index (item.id)} <li draggable="true" class:dragging={dragging === item.id} class:busy={busy === item.id} class:editing={transcript.editing?.id === item.id} ondragstart={() => (dragging = item.id)} ondragover={(event) => event.preventDefault()} ondrop={() => reorder(item.id)} ondragend={() => (dragging = null)} > <span class="from">{item.from || item.source}</span> {#if transcript.own(item.id)}<button class="preview own" title={item.text} disabled={busy !== null || transcript.editing !== null} onclick={() => transcript.beginEdit(item.id)} >{preview(item)}{#if item.text_truncated}…{/if}</button >{:else}<span class="preview" title={item.text} >{preview(item)}{#if item.text_truncated}…{/if}</span >{/if} {#if item.images.length || item.files.length}<span class="attached" title={attached(item)}>{attached(item)}</span >{/if} <span class="delivery" >{transcript.editing?.id === item.id ? 'editing' : delivery(item)}</span > <span class="actions"> {#if transcript.own(item.id)}<button aria-label="edit" title="edit" disabled={busy !== null || transcript.editing !== null} onclick={() => transcript.beginEdit(item.id)} ><svg viewBox="0 0 16 16" width="12" height="12" aria-hidden="true" ><path d="M10.6 3.4a1.5 1.5 0 0 1 2.1 2.1l-6.9 6.9-2.8.7.7-2.8z" stroke="currentColor" stroke-width="1.5" fill="none" stroke-linejoin="round" /></svg ></button >{/if} <button class:first={index === 0} aria-label="move to the front" title="move to the front" disabled={busy !== null || index === 0} onclick={() => act(item.id, () => moveQueuedFirst(sessionId, item.id))} ><svg viewBox="0 0 16 16" width="12" height="12" aria-hidden="true" ><path d="M8 13V3.5M4 7l4-4 4 4" stroke="currentColor" stroke-width="1.6" fill="none" stroke-linecap="round" stroke-linejoin="round" /></svg ></button ><button class="drop" aria-label={transcript.own(item.id) ? 'take back into the composer' : 'drop'} title={transcript.own(item.id) ? 'take back into the composer' : 'drop'} disabled={busy !== null} onclick={() => transcript.own(item.id) ? unsend(item.id) : act(item.id, () => dropQueued(sessionId, item.id), [ item.id, ])} ><svg viewBox="0 0 16 16" width="11" height="11" aria-hidden="true" ><path d="M4.5 4.5l7 7M11.5 4.5l-7 7" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" /></svg ></button > </span> {#if item.last_error}<span class="failure" >couldn't deliver: {item.last_error}</span >{/if} </li> {/each} </ol> {/if} </section>{/if}
<style> .queue { flex: none; margin: 0 10px 6px; padding: 6px 4px 4px; color: var(--text); border-top: 1px solid var(--border); font-size: calc(12px * var(--canvas-scale)); } header { display: flex; align-items: baseline; justify-content: space-between; padding: 0 6px 3px; color: var(--muted); } .count { margin-left: 3px; font-variant-numeric: tabular-nums; } button { display: inline-grid; place-items: center; padding: 3px 5px; color: var(--muted); font: inherit; background: transparent; border: 0; border-radius: 5px; cursor: pointer; } button:hover:not(:disabled) { color: var(--text); background: var(--hover); } button:disabled { opacity: 0.45; cursor: wait; } .clear:hover:not(:disabled), .drop:hover:not(:disabled) { color: var(--danger); } li.editing { background: var(--hover); } li.editing .delivery { color: var(--accent); } ol { display: grid; max-height: min(30vh, 220px); margin: 0; padding: 0; overflow-y: auto; list-style: none; } li { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; min-width: 0; padding: 3px 4px 3px 6px; border-radius: 6px; cursor: grab; } li:hover { background: var(--hover); } li.dragging, li.busy { opacity: 0.45; } .from { flex: none; max-width: 30%; overflow: hidden; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; } .preview { flex: 1 1 0; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .preview.own { display: block; padding: 0; color: inherit; text-align: left; cursor: text; } .preview.own:hover:not(:disabled) { background: transparent; } .preview.own:disabled { opacity: 1; cursor: default; } .attached, .delivery { flex: none; color: var(--muted); white-space: nowrap; } .attached { max-width: 25%; overflow: hidden; text-overflow: ellipsis; } .actions { display: flex; flex: none; } .first { visibility: hidden; } .failure, .error { color: var(--danger); } .failure { flex-basis: 100%; padding-left: 2px; } .error { margin: 0 6px 4px; } @media (hover: hover) { .actions { opacity: 0; } li:hover .actions, li:focus-within .actions { opacity: 1; } } @media (max-width: 600px) { .queue { margin: 0 8px 4px; font-size: 13px; } .delivery { display: none; } button { padding: 6px 7px; } }</style>