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
UI: routing line in every auto-routed channel; delete dialog reads the real usage and 409 shapes
Lin (kwant bot)9a2aeba6e587
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex d3658a0d..ce9df518 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -2385,7 +2385,6 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({title={chatTitle}subtitle={chatSubtitle}spaceName={space.name}- isGeneral={isGeneral}onBack={isPhone ? () => setPhoneView('list') : undefined}messages={viewingHistory ? historyWindow.messages : messages}viewingHistory={viewingHistory}diff --git a/frontend/src/botDelete.ts b/frontend/src/botDelete.tsindex e1552b78..544f43c3 100644--- a/frontend/src/botDelete.ts+++ b/frontend/src/botDelete.ts@@ -4,9 +4,13 @@/** What deleting a bot removes, from GET /api/kwants/:id/usage; null when the server can't say. */export interface BotUsage {conversations: number;+ /** Messages in its direct chats and threads; team-chat messages stay and aren't counted. */+ messages: number;memories: number;skills: number;routines: number;+ /** Teams and channels it leads; each passes to its next member. */+ leads: number;running: boolean;}@@ -15,7 +19,15 @@ const n = (v: unknown) => (typeof v === 'number' && Number.isFinite(v) && v >= 0export function parseUsage(raw: unknown): BotUsage | null {if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;const o = raw as Record<string, unknown>;- return { conversations: n(o.conversations), memories: n(o.memories), skills: n(o.skills), routines: n(o.routines), running: o.running === true };+ return {+ conversations: n(o.conversations),+ messages: n(o.messages),+ memories: n(o.memories),+ skills: n(o.skills),+ routines: n(o.routines),+ leads: n(o.leads),+ running: o.running === true,+ };}const count = (k: number, one: string, many: string) => `${k} ${k === 1 ? one : many}`;@@ -24,13 +36,21 @@ const count = (k: number, one: string, many: string) => `${k} ${k === 1 ? one :export function lossLines(usage: BotUsage | null): string[] {if (!usage) return ['Its conversations and threads', 'Its memory', 'Its skills', 'Its routines'];return [- count(usage.conversations, 'conversation', 'conversations'),+ usage.messages+ ? `${count(usage.conversations, 'conversation', 'conversations')} (${count(usage.messages, 'message', 'messages')})`+ : count(usage.conversations, 'conversation', 'conversations'),count(usage.memories, 'memory', 'memories'),count(usage.skills, 'skill', 'skills'),count(usage.routines, 'routine', 'routines'),];}+/** A note for teams and channels it leads, or null. */+export function leadsNote(usage: BotUsage | null): string | null {+ if (!usage?.leads) return null;+ return `It leads ${count(usage.leads, 'team or channel', 'teams or channels')}; the next member takes over as lead.`;+}+/** Why Delete is off right now, or null when it can be pressed. `busy` is the sidebar's activity line. */export function deleteBlockedReason(name: string, busy: string | null | undefined, usage: BotUsage | null): string | null {if (busy || usage?.running) return `${name} is working right now. Stop it or wait until it finishes, then delete it.`;@@ -59,13 +79,16 @@ export const botDeleteApi = {}if (res.ok || res.status === 404) return null;let msg = '';+ let code = '';try {const body = await res.json();+ code = typeof body?.error === 'string' ? body.error : '';msg = typeof body?.message === 'string' ? body.message : typeof body?.error === 'string' && body.error.includes(' ') ? body.error : '';} catch {/* not JSON */}if (msg) return msg;+ if (code === 'last_bot') return `${name} is the only bot in this space, and a space needs at least one. Add another bot first.`;if (res.status === 409) return `${name} is working right now. Stop it or wait until it finishes, then delete it.`;if (res.status === 405) return 'This server can’t delete bots yet. Update the app and try again.';return `Couldn’t delete ${name} (HTTP ${res.status}).`;diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsxindex b912550e..320958c1 100644--- a/frontend/src/components/ChatView.tsx+++ b/frontend/src/components/ChatView.tsx@@ -100,8 +100,6 @@ export interface ChatViewProps {subtitle: string;/** The open space, for "Message #general in Work" and Laya's lines. */spaceName?: string;- /** #general, where Laya picks who answers. */- isGeneral?: boolean;/** Phones: back to the list. */onBack?: () => void;messages: ChatMessage[];@@ -272,7 +270,6 @@ export const ChatView: React.FC<ChatViewProps> = ({title,subtitle,spaceName,- isGeneral,onBack,messages,streamingText,@@ -684,7 +681,8 @@ export const ChatView: React.FC<ChatViewProps> = ({const isThoughtOpen = !!openThoughts[msg.id];const ranOn = isUser ? null : ranOnLabel(msg.meta);const account = isUser ? null : ranOnAccount(msg.meta);- const routed = isUser || !isGeneral ? null : parseRoutingMeta(msg.meta);+ // Any auto-routed channel, not only #general: the server attaches `routing` wherever it picked the bot.+ const routed = isUser ? null : parseRoutingMeta(msg.meta);const displayName = isUser ? 'You' : (msg.sender_id && msg.sender_id.length > 20 ? title : msg.sender_id);return (diff --git a/frontend/src/components/DeleteBotDialog.tsx b/frontend/src/components/DeleteBotDialog.tsxindex f2206912..afee9942 100644--- a/frontend/src/components/DeleteBotDialog.tsx+++ b/frontend/src/components/DeleteBotDialog.tsx@@ -1,6 +1,6 @@import React, { useEffect, useRef, useState } from 'react';import { AlertTriangle, Download, Loader2, Trash2 } from 'lucide-react';-import { BotUsage, botDeleteApi, deleteBlockedReason, lossLines } from '../botDelete';+import { BotUsage, botDeleteApi, deleteBlockedReason, leadsNote, lossLines } from '../botDelete';import { downloadExport, trapFocusTarget } from '../imports';interface DeleteBotDialogProps {@@ -114,7 +114,9 @@ export const DeleteBotDialog: React.FC<DeleteBotDialogProps> = ({ kwant, busy, o<li key={l}>{l}</li>))}</ul>- <p className="text-[11px] text-zinc-500">Teams it’s in lose it as a member. Other bots and their chats stay.</p>+ <p className="text-[11px] text-zinc-500">+ {leadsNote(usage) ?? 'Teams it’s in lose it as a member.'} Other bots and their chats stay, and so do its team-chat messages and working folder.+ </p><div className="rounded-xl border border-zinc-800 bg-zinc-950/70 p-3 space-y-2"><p className="text-xs text-zinc-300">Want a copy first? Export saves its instructions, memory, skills and routines to a file you can import later.</p>diff --git a/frontend/tests/botCapabilities.test.mjs b/frontend/tests/botCapabilities.test.mjsindex 57063a9f..c23dc7b2 100644--- a/frontend/tests/botCapabilities.test.mjs+++ b/frontend/tests/botCapabilities.test.mjs@@ -15,7 +15,7 @@ const m = await loadBundled(`import { PreviewView } from './src/components/ImportDialog';export { builtinView } from './src/components/ModernApprovalCard';export { parseHireMeta, hireStateText, hiredBotGone, isTeamHire } from './src/botActions';- export { lossLines, parseUsage, deleteBlockedReason } from './src/botDelete';+ export { lossLines, parseUsage, deleteBlockedReason, leadsNote, botDeleteApi } from './src/botDelete';export { toolNote } from './src/imports';export { routeReasonText } from './src/routeReason';export { routingLine } from './src/spaces';@@ -192,3 +192,49 @@ test('the routing line and card use the server’s own reason when it sends one'assert.match(m.routingLine({ kwant_name: 'Probe', basis: 'keywords', matched_terms: [], reason: named.reason }, 'Trading'), /^Probe \(QA\) was named in your message\. Chosen in Trading\.$/);assert.match(m.routingLine({ kwant_name: 'Lin', reason: 'Laya picked Lin (Backend) as the best fit', candidate_count: 2 }, 'Work'), /^Laya picked Lin from 2 bots in Work$/, 'older servers keep the old line');});++// One row per routing basis, with the sentence src/router/team.rs (and routes.rs for discuss) actually sends.+const OFFLINE = 'Laya is offline, so this was a keyword match';+const ROUTES = [+ { case: 'named', basis: 'keywords', name: 'Probe', terms: ['probe'], reason: 'Probe (QA) was named in your message' },+ { case: 'keywords', basis: 'keywords', name: 'Gopher', terms: ['strategy', 'go'], reason: `Gopher (Go backend) does this kind of work: your message mentions strategy, go. ${OFFLINE}` },+ { case: 'lead-unmatched', basis: 'lead', name: 'Ada', terms: [], reason: "No one's role matched this, so it went to the channel lead, Ada (Tech Lead)" },+ { case: 'lead-multi-role', basis: 'several', name: 'Gopher', terms: ['endpoint', 'page'], reason: `This touches several roles (Gopher and Pixel), so it went to the channel lead, Gopher (Go backend), to answer or hand parts on. ${OFFLINE}` },+ { case: 'only-bot', basis: 'only', name: 'Lin', terms: [], reason: 'Lin is the only bot here that can answer' },+ { case: 'laya', basis: 'skills', name: 'Lin', terms: ['migration'], reason: 'Lin (Backend) does this kind of work: your message mentions migration; Laya picked the same bot' },+ { case: 'laya-titles', basis: 'skills', name: 'Lin', terms: [], reason: "Laya matched this to Lin's role (Backend); no words in your message named a role" },+ { case: 'discuss', basis: 'discuss', name: 'Ada', terms: [], reason: 'This needs several perspectives — starting a 4-turn team discussion led by Ada' },+];++for (const r of ROUTES) {+ test(`routing basis ${r.case}: card and line show the server’s reason`, () => {+ const sentence = /[.!?]$/.test(r.reason) ? r.reason : `${r.reason}.`;+ assert.equal(m.routeReasonText({ kwantName: r.name, basis: r.basis, matchedTerms: r.terms, reason: r.reason }), sentence);+ const line = m.routingLine({ kwant_name: r.name, basis: r.basis, matched_terms: r.terms, reason: r.reason, candidate_count: 3, fallback: r.reason.includes(OFFLINE) }, 'Trading');+ assert.equal(line, `${sentence} Chosen from 3 bots in Trading.`);+ assert.doesNotMatch(line, /^Laya picked|Picked by keywords \(Laya is offline\)/, 'no local wording over the server’s');+ });+}++test('delete dialog reads Lin’s real usage shape and both 409 codes', async () => {+ const usage = m.parseUsage({ conversations: 3, messages: 41, memories: 2, skills: 1, routines: 0, leads: 1, running: false });+ assert.deepEqual(m.lossLines(usage), ['3 conversations (41 messages)', '2 memories', '1 skill', '0 routines']);+ assert.equal(m.leadsNote(usage), 'It leads 1 team or channel; the next member takes over as lead.');+ assert.equal(m.leadsNote(m.parseUsage({ leads: 0 })), null);+ const real = globalThis.fetch;+ const reply = (status, body) => { globalThis.fetch = async () => new Response(JSON.stringify(body), { status }); };+ try {+ reply(409, { error: 'last_bot', message: 'Probe is the only bot in this space; a space needs at least one.' });+ assert.equal(await m.botDeleteApi.remove('k1', 'Probe'), 'Probe is the only bot in this space; a space needs at least one.');+ reply(409, { error: 'last_bot' });+ assert.match(await m.botDeleteApi.remove('k1', 'Probe'), /only bot in this space/);+ reply(409, { error: 'running' });+ assert.match(await m.botDeleteApi.remove('k1', 'Probe'), /working right now/);+ reply(200, { status: 'deleted', deleted: 'k1', name: 'Probe', removed: {}, kept_folder: null });+ assert.equal(await m.botDeleteApi.remove('k1', 'Probe'), null);+ reply(404, { error: 'bot not found' });+ assert.equal(await m.botDeleteApi.remove('k1', 'Probe'), null, 'already gone counts as deleted');+ } finally {+ globalThis.fetch = real;+ }+});