Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
Accounts: unranked engines sit apart and join at the bottom; files table scrolls inside the bubble (#242)
Oleksandr Ivanchenkocb32a03523d0
diff --git a/frontend/src/components/AccountPriority.tsx b/frontend/src/components/AccountPriority.tsxindex 3a05b30b..44fb1846 100644--- a/frontend/src/components/AccountPriority.tsx+++ b/frontend/src/components/AccountPriority.tsx@@ -10,6 +10,7 @@ import {moveAnnouncement,priorityStatus,priorityUpdates,+ splitRanked,} from '../failover';import { Profile, cardOf, profilesApi } from '../profiles';import { StatusPill } from './EngineAccounts';@@ -37,8 +38,15 @@ export const AccountPriority: React.FC<{const [focusKey, setFocusKey] = useState<string | null>(null);const listRef = useRef<HTMLOListElement>(null);- const served = useMemo(() => failoverOrder(profiles), [profiles]);- const order = pending ?? served;+ const engineOf = (p: Profile) => engines?.find((e) => e.id === cardOf(p));+ // Accounts that aren't installed or aren't signed in can't take a turn: they are listed apart, unranked+ // and not movable. A move numbers them after the ranked ones, so they join at the bottom later.+ const { ranked: servedRanked, unranked } = useMemo(+ () => splitRanked(failoverOrder(profiles), (p) => engines?.find((e) => e.id === cardOf(p)), now),+ // eslint-disable-next-line react-hooks/exhaustive-deps+ [profiles, engines],+ );+ const order = pending ?? servedRanked;// Put keyboard focus back on the button that was used, once the row has moved.useEffect(() => {@@ -49,7 +57,7 @@ export const AccountPriority: React.FC<{}, [focusKey, order]);const save = async (next: Profile[], moved: Profile, to: number) => {- const updates = priorityUpdates(next);+ const updates = priorityUpdates(next, unranked);if (updates.length === 0) return;setError(null);// Show the new order at once, with the numbers it will have, so a late reload can't flip it back.@@ -87,12 +95,11 @@ export const AccountPriority: React.FC<{{FAILOVER_CAPTION}</p>{order.length === 0 ? (- <p className="mt-2 text-zinc-500">No accounts yet. Add one below.</p>+ <p className="mt-2 text-zinc-500">{unranked.length === 0 ? 'No accounts yet. Add one below.' : 'No account is ready to use yet.'}</p>) : (<ol ref={listRef} aria-describedby="account-priority-caption" className="mt-2.5 space-y-1.5">{order.map((p, i) => {- const engine = engines?.find((e) => e.id === cardOf(p));- const status = priorityStatus(p, engine, now);+ const status = priorityStatus(p, engineOf(p), now);const dragging = dragId === p.id;const over = overId === p.id && dragId !== p.id;return (@@ -166,6 +173,30 @@ export const AccountPriority: React.FC<{})}</ol>)}+ {unranked.length > 0 && (+ <div data-unranked className="mt-3">+ <h4 id="account-unranked-title" className="text-[11px] font-medium text-zinc-400">+ Not in the order+ </h4>+ <p className="mt-0.5 text-[11px] text-zinc-500">These can't run turns until they are installed or signed in.</p>+ <ul aria-labelledby="account-unranked-title" className="mt-1.5 space-y-1.5">+ {unranked.map((p) => {+ const status = priorityStatus(p, engineOf(p), now);+ return (+ <li key={p.id} data-account={p.id} data-unranked-account className="flex items-center gap-2 rounded-lg border border-dashed border-zinc-800 bg-zinc-950/20 px-2 py-2">+ <div className="flex-1 min-w-0">+ <p className="text-zinc-300 font-medium truncate">{nameOf(p)}</p>+ <div className="mt-0.5 flex items-center gap-x-1.5 gap-y-1 flex-wrap">+ <span className="text-[11px] text-zinc-500">{engineLabel(p)}</span>+ <StatusPill tone={status.tone}>{status.label}</StatusPill>+ </div>+ </div>+ </li>+ );+ })}+ </ul>+ </div>+ )}<p role="status" aria-live="polite" className="sr-only">{announce}</p>diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsxindex b4a8cf6e..5159f9e1 100644--- a/frontend/src/components/ChatView.tsx+++ b/frontend/src/components/ChatView.tsx@@ -1153,9 +1153,12 @@ export const ChatView: React.FC<ChatViewProps> = ({{files.length > 0 && <FileTiles files={files} align={isUser ? 'end' : 'start'} />}{/* A shared-file card has no bubble, so the files block (the table or text preview) is mounted here, after the tiles. */}{filesOnly && !isUser && msg.results != null && (- <FilesPreviewOnly.Provider value={true}>- <MarkdownRenderer content="" results={msg.results} messageId={msg.id} />- </FilesPreviewOnly.Provider>+ // The column is `items-start`, so without a width cap a long cell stretches the preview past the message.+ <div className="w-full min-w-0 max-w-full">+ <FilesPreviewOnly.Provider value={true}>+ <MarkdownRenderer content="" results={msg.results} messageId={msg.id} />+ </FilesPreviewOnly.Provider>+ </div>)}{decisions.length > 0 && (diff --git a/frontend/src/components/results/Files.tsx b/frontend/src/components/results/Files.tsxindex 624450e0..a8f3a48e 100644--- a/frontend/src/components/results/Files.tsx+++ b/frontend/src/components/results/Files.tsx@@ -68,7 +68,7 @@ function humanSize(bytes: number): string {}const TablePreview: React.FC<{ columns: string[]; rows: string[][] }> = ({ columns, rows }) => (- <div className="mt-2 overflow-x-auto rounded-lg border border-zinc-800">+ <div className="mt-2 min-w-0 max-w-full overflow-x-auto rounded-lg border border-zinc-800"><table className="w-full min-w-max border-collapse text-left text-[11px]"><thead><tr className="border-b border-zinc-800 bg-zinc-900/60">@@ -147,8 +147,8 @@ export const Files: React.FC<RendererProps<FilesBlock>> = ({ block }) => {const shown = block.items.filter((i) => i.preview && i.preview.kind !== 'image');if (shown.length === 0) return null;return (- <div data-smart-result="files" data-block-id={block.id} data-preview-only="">- <ul role="list" className="mt-2 space-y-2">+ <div data-smart-result="files" data-block-id={block.id} data-preview-only="" className="min-w-0 max-w-full">+ <ul role="list" className="mt-2 min-w-0 max-w-full space-y-2">{shown.map((item) => (<li key={item.id} aria-label={`Preview of ${item.name}`} className="min-w-0"><div className="truncate text-[11px] text-zinc-500" title={item.name}>@@ -162,10 +162,10 @@ export const Files: React.FC<RendererProps<FilesBlock>> = ({ block }) => {);}return (- <div data-smart-result="files" data-block-id={block.id}>- <ul role="list" className="my-3.5 space-y-2">+ <div data-smart-result="files" data-block-id={block.id} className="min-w-0 max-w-full">+ <ul role="list" className="my-3.5 min-w-0 max-w-full space-y-2">{block.items.map((item) => (- <li key={item.id} className="rounded-xl border border-zinc-800 bg-zinc-950/70 p-3 shadow-sm">+ <li key={item.id} className="min-w-0 max-w-full rounded-xl border border-zinc-800 bg-zinc-950/70 p-3 shadow-sm"><div className="flex items-start gap-2"><FileIcon size={14} className="mt-0.5 shrink-0 text-zinc-500" aria-hidden="true" /><div className="min-w-0 flex-1">diff --git a/frontend/src/components/results/SmartResult.tsx b/frontend/src/components/results/SmartResult.tsxindex c12b4cb7..74a03304 100644--- a/frontend/src/components/results/SmartResult.tsx+++ b/frontend/src/components/results/SmartResult.tsx@@ -237,7 +237,7 @@ export const SmartResult: React.FC<SmartResultProps> = ({ raw, reply, messageId,const name = block.title ?? TYPE_LABEL[block.type];return (- <div role="group" aria-label={name} data-smart-frame={block.type} className={slot ? 'mt-3' : undefined}>+ <div role="group" aria-label={name} data-smart-frame={block.type} className={slot ? 'mt-3 min-w-0 max-w-full' : 'min-w-0 max-w-full'}>{slot && block.title && <div className="mb-1.5 text-xs font-semibold text-zinc-300">{block.title}</div>}{asText ? (textdiff --git a/frontend/src/failover.ts b/frontend/src/failover.tsindex 1e8c1431..6d6117ae 100644--- a/frontend/src/failover.ts+++ b/frontend/src/failover.ts@@ -55,6 +55,26 @@ export function priorityStatus(p: Profile, engine: EngineInfo | undefined, now =return { tone: s.tone, label: s.label === 'Needs sign-in' ? 'Signed out' : s.label };}+/** Not-installed and signed-out accounts can't take a turn, so they sit outside the ranked order. A saved+ * limit ("Out until 03:00") or "Off" is the person's or the provider's state, so those stay ranked. */+export function isRanked(p: Profile, engine: EngineInfo | undefined, now = Date.now()): boolean {+ const { label } = priorityStatus(p, engine, now);+ return label !== 'Not installed' && label !== 'Signed out';+}++/** The order split for display: the ranked list (reorderable) and the rest, each in failover order.+ * Display only: nothing here changes an account's saved priority. */+export function splitRanked(+ order: Profile[],+ engineOf: (p: Profile) => EngineInfo | undefined,+ now = Date.now(),+): { ranked: Profile[]; unranked: Profile[] } {+ const ranked: Profile[] = [];+ const unranked: Profile[] = [];+ for (const p of order) (isRanked(p, engineOf(p), now) ? ranked : unranked).push(p);+ return { ranked, unranked };+}+/** Where a drag or an arrow press puts an account: the new order, or null when nothing moves. */export function moveAccount(order: Profile[], from: number, to: number): Profile[] | null {if (from === to || from < 0 || to < 0 || from >= order.length || to >= order.length) return null;@@ -66,11 +86,13 @@ export function moveAccount(order: Profile[], from: number, to: number): Profileexport const PRIORITY_STEP = 10;-/** The priority updates that make `order` the failover order: ranks 10, 20, 30…, only for accounts- * whose number changes. Uses the existing PATCH /api/profiles/:id `priority` field (0 to 10000). */-export function priorityUpdates(order: Profile[]): Array<{ id: string; priority: number }> {+/** The priority updates that make `order` the failover order: the whole list numbered 10, 20, 30…, with+ * `rest` (the accounts outside the ranked list, in their current relative order) after it, so one that+ * becomes ready later joins at the bottom, never above what the person ordered. Only accounts whose number+ * changes are returned. Uses the existing PATCH /api/profiles/:id `priority` field (0 to 10000). */+export function priorityUpdates(order: Profile[], rest: Profile[] = []): Array<{ id: string; priority: number }> {const out: Array<{ id: string; priority: number }> = [];- order.forEach((p, i) => {+ [...order, ...rest].forEach((p, i) => {const priority = Math.min(10_000, (i + 1) * PRIORITY_STEP);if (p.priority !== priority) out.push({ id: p.id, priority });});diff --git a/frontend/tests/failover.test.mjs b/frontend/tests/failover.test.mjsindex 79caa8c7..5bc7cc28 100644--- a/frontend/tests/failover.test.mjs+++ b/frontend/tests/failover.test.mjs@@ -157,3 +157,62 @@ test('a reply with no or malformed failover meta shows no notice', () => {assert.equal(m.savedFailoverNotice(meta), null);}});++// ---- Not-installed and signed-out engines are listed apart, unranked ----++const sys = (id, eng, priority) => profile({ id, engine: eng, kind: 'system', name: 'This machine', priority });+const sysList = [sys('s-claude', 'claude', 10), sys('s-codex', 'codex', 20), sys('s-grok', 'grok', 30)];+const sysEngines = [engine('claude'), engine('codex'), engine('grok', { status: 'not_installed', ready: false })];+const engineOf = (p) => sysEngines.find((e) => e.id === p.engine);++test('a not-installed engine is not ranked, a signed-out one is not ranked, an out one still is', () => {+ const { ranked, unranked } = m.splitRanked(m.failoverOrder(sysList), engineOf, NOW);+ assert.deepEqual(ranked.map((p) => p.id), ['s-claude', 's-codex']);+ assert.deepEqual(unranked.map((p) => p.id), ['s-grok']);+ const signedOut = m.splitRanked(m.failoverOrder(list), (p) => engine(p.engine), NOW);+ assert.deepEqual(signedOut.unranked.map((p) => p.id), ['g1'], 'Grok signed out');+ assert.ok(signedOut.ranked.some((p) => p.id === 'c1'), 'Out until 03:00 stays ranked');+ const off = m.splitRanked([profile({ id: 'o', enabled: false })], () => engine('claude'), NOW);+ assert.equal(off.ranked.length, 1, 'switched off stays ranked');+});++test('a move numbers the whole order: ranked first, then the unranked ones in their current order', () => {+ // Fresh install: all three system accounts at 0, Grok not installed.+ const fresh = [sys('s-claude', 'claude', 0), sys('s-codex', 'codex', 0), sys('s-grok', 'grok', 0)];+ const { ranked, unranked } = m.splitRanked(m.failoverOrder(fresh), engineOf, NOW);+ assert.deepEqual(ranked.map((p) => p.id), ['s-claude', 's-codex']);+ const next = m.moveAccount(ranked, 0, 1);+ const updates = m.priorityUpdates(next, unranked);+ assert.deepEqual(updates, [{ id: 's-codex', priority: 10 }, { id: 's-claude', priority: 20 }, { id: 's-grok', priority: 30 }]);+ // Once Grok is installed, it sorts after both.+ const after = fresh.map((p) => ({ ...p, priority: updates.find((u) => u.id === p.id)?.priority ?? p.priority }));+ assert.deepEqual(m.failoverOrder(after).map((p) => p.id), ['s-codex', 's-claude', 's-grok']);+ // Without the unranked list, only the ranked ones are numbered.+ assert.deepEqual(m.priorityUpdates(next), [{ id: 's-codex', priority: 10 }, { id: 's-claude', priority: 20 }]);+});++test('a signed-out account between ranked ones ends up after all of them once anything moves', () => {+ const three = [profile({ id: 'a', priority: 10 }), profile({ id: 'b', engine: 'codex', priority: 20 }), profile({ id: 'c', engine: 'grok', priority: 30 })];+ const next = m.moveAccount([three[0], three[2]], 0, 1); // c, a+ const updates = m.priorityUpdates(next, [three[1]]);+ assert.deepEqual(updates, [{ id: 'c', priority: 10 }, { id: 'a', priority: 20 }, { id: 'b', priority: 30 }]);+ const after = three.map((p) => ({ ...p, priority: updates.find((u) => u.id === p.id)?.priority ?? p.priority }));+ assert.deepEqual(m.failoverOrder(after).map((p) => p.id), ['c', 'a', 'b']);+ // Only numbers that change are sent, capped at 10000.+ const many = Array.from({ length: 1100 }, (_, i) => profile({ id: `p${i}`, priority: 0 }));+ assert.equal(m.priorityUpdates(many.slice(0, 1000), many.slice(1000)).at(-1).priority, 10_000);+});++test('the list shows Grok under the ranked rows, with its status, no number and no arrows', () => {+ const html = m.renderToStaticMarkup(h(m.AccountPriority, { profiles: sysList, engines: sysEngines, onChanged: async () => {}, now: NOW }));+ assert.equal((html.match(/<ol /g) ?? []).length, 1);+ const ranked = html.slice(html.indexOf('<ol '), html.indexOf('</ol>'));+ assert.equal((ranked.match(/<li /g) ?? []).length, 2, 'two ranked rows');+ assert.doesNotMatch(ranked, /Grok|Not installed/);+ const rest = html.slice(html.indexOf('</ol>'));+ assert.match(rest, /Not in the order/);+ assert.match(rest, /Grok/);+ assert.match(rest, /Not installed/);+ assert.doesNotMatch(rest, /aria-label="Move /, 'not reorderable');+ assert.doesNotMatch(rest, /draggable/);+});diff --git a/frontend/tests/smartResultsClientFixes.test.mjs b/frontend/tests/smartResultsClientFixes.test.mjsindex 8373706d..d0bbc9c5 100644--- a/frontend/tests/smartResultsClientFixes.test.mjs+++ b/frontend/tests/smartResultsClientFixes.test.mjs@@ -142,3 +142,14 @@ test('a files block on an ordinary reply is still drawn as full cards (no previeassert.match(html, /text\/csv · 357 B/);assert.doesNotMatch(html, /data-preview-only/);});++test('a long cell cannot stretch the shared-file preview past the message (it scrolls in its wrapper)', () => {+ const card = fileCard();+ card.results.blocks[0].items[0].preview = { kind: 'table', columns: ['url'], rows: [['x'.repeat(280)]] };+ const html = m.chat(chatProps([card]));+ // The column is items-start, so the preview, its frame, list and scroll wrapper each cap at the column width.+ assert.match(html, /class="w-full min-w-0 max-w-full"/);+ assert.match(html, /data-smart-frame="files"[^>]*class="[^"]*min-w-0 max-w-full/);+ assert.match(html, /data-smart-result="files"[^>]*class="min-w-0 max-w-full"/);+ assert.match(html, /class="mt-2 min-w-0 max-w-full overflow-x-auto /);+});