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 shows the server's own reason; team hire card marks the new team's lead
Lin (kwant bot)b6a2ab612726
diff --git a/frontend/src/botActions.ts b/frontend/src/botActions.tsindex ee4bcf5a..01e9842a 100644--- a/frontend/src/botActions.ts+++ b/frontend/src/botActions.ts@@ -249,7 +249,8 @@ export interface HireMeta {/** Every bot the proposal hires, the first being the top-level one; one entry for a single hire. */members: HireMember[];/** The team the proposal creates for them, when it makes a new one. */- new_team: { name: string } | null;+ /** `lead` is a member's name; the server makes the first member lead when it's missing. */+ new_team: { name: string; lead: string | null } | null;/** The bots made on accept, in `members` order; empty until then. */hired_kwant_ids: string[];}@@ -333,11 +334,23 @@ export function parseHireMeta(raw: unknown): HireMeta | null {const top: HireMember = { name, role: str(m.role) ?? '', model: str(m.model), tools: parseTools(m.tools), instructions: str(m.instructions) ?? '' };return listed.length ? listed : [top];})(),- new_team: m.new_team && typeof m.new_team === 'object' && str((m.new_team as Record<string, unknown>).name) ? { name: (m.new_team as Record<string, string>).name } : null,+ new_team: (() => {+ const t = m.new_team && typeof m.new_team === 'object' ? (m.new_team as Record<string, unknown>) : null;+ const teamName = t && str(t.name);+ return teamName ? { name: teamName, lead: str(t.lead)?.replace(/^@/, '') ?? null } : null;+ })(),hired_kwant_ids: strs(m.hired_kwant_ids),};}+/** Index of the member who will lead the new team, or -1 when the proposal makes no team. */+export function hireLeadIndex(h: Pick<HireMeta, 'members' | 'new_team'>): number {+ if (!h.new_team) return -1;+ const lead = h.new_team.lead?.toLowerCase();+ const i = lead ? h.members.findIndex((m) => m.name.toLowerCase() === lead) : -1;+ return i >= 0 ? i : 0;+}+/** Whether the proposal hires several bots at once (a team), rather than one. */export const isTeamHire = (h: Pick<HireMeta, 'members'>) => h.members.length > 1;diff --git a/frontend/src/components/HireCard.tsx b/frontend/src/components/HireCard.tsxindex b4eaa05c..20a258e6 100644--- a/frontend/src/components/HireCard.tsx+++ b/frontend/src/components/HireCard.tsx@@ -1,7 +1,7 @@import React, { useId, useState } from 'react';import { AlertTriangle, CheckCircle2, ChevronDown, ChevronRight, Loader2, MinusCircle, Undo2, UserPlus } from 'lucide-react';import { ModernAvatar } from './ModernAvatar';-import { HireMeta, evidenceText, hireStateText, hireView, hiredBotGone, isTeamHire, modelText } from '../botActions';+import { HireMeta, evidenceText, hireStateText, hireView, hireLeadIndex, hiredBotGone, isTeamHire, modelText } from '../botActions';export type HireDecision = 'deny' | 'accept_once' | 'always_accept' | 'undo';@@ -55,6 +55,7 @@ export const HireCard: React.FC<HireCardProps> = ({ meta, messageId, kwantName,const evidence = evidenceText(view.evidence, view.requested_by_person);const border = pending ? 'border-violet-500/40' : done ? 'border-zinc-800' : 'border-emerald-500/25';const can = (c: string) => pending && view.choices.includes(c);+ const leadIndex = hireLeadIndex(view);const team = isTeamHire(view);const toolText = (tools: HireMeta['tools']) => (tools.length ? tools.map((t) => t.name || 'Unknown tool').join(', ') : 'None');@@ -116,7 +117,12 @@ export const HireCard: React.FC<HireCardProps> = ({ meta, messageId, kwantName,<li key={`${m.name}-${i}`} className="flex items-start gap-2.5 px-3 py-2 min-w-0"><ModernAvatar role={m.role || m.name} name={m.name} size={24} kwantId={view.hired_kwant_ids[i]} /><div className="min-w-0 flex-1">- <p className={`font-medium break-words ${done ? 'text-zinc-400' : 'text-zinc-100'}`}>{m.name}</p>+ <p className={`font-medium break-words ${done ? 'text-zinc-400' : 'text-zinc-100'}`}>+ {m.name}+ {i === leadIndex && (+ <span className="ml-2 rounded-full border border-violet-500/40 bg-violet-500/10 px-1.5 py-px text-[10px] font-medium text-violet-200">Lead</span>+ )}+ </p>{m.role && <p className="text-zinc-400 break-words">{m.role}</p>}<p className="text-[11px] text-zinc-500 break-words">{modelText(m.model)} · Tools: {toolText(m.tools)}@@ -128,7 +134,9 @@ export const HireCard: React.FC<HireCardProps> = ({ meta, messageId, kwantName,<dl className="mx-4 mb-2 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 px-1 text-xs"><dt className="text-zinc-500">Team</dt><dd className="min-w-0 break-words text-zinc-200">- {view.new_team ? `New team: ${view.new_team.name}` : view.team ? view.team.name : 'No team'}+ {view.new_team+ ? `New team: ${view.new_team.name}${leadIndex >= 0 ? `, led by ${view.members[leadIndex].name}` : ''}`+ : view.team ? view.team.name : 'No team'}</dd></dl></>diff --git a/frontend/src/routeReason.ts b/frontend/src/routeReason.tsindex d5143cae..cd3cfdf7 100644--- a/frontend/src/routeReason.ts+++ b/frontend/src/routeReason.ts@@ -1,7 +1,7 @@// The line under "Sending your question to X" on Laya's routing card: why that bot, in words that// match how it was actually picked.-export type RouteBasis = 'skills' | 'lead' | 'keywords' | 'only';+export type RouteBasis = 'skills' | 'lead' | 'keywords' | 'only' | 'several' | 'discuss';export interface RouteReasonInput {kwantName?: string;@@ -11,7 +11,17 @@ export interface RouteReasonInput {matchedTerms?: string[];}+/** True when the server wrote its own sentence for this pick. Older servers say "Laya picked …" for+ * every pick, even the lead fallback, so that wording is never trusted when a basis says otherwise. */+export function serverReason(r: { reason?: string; basis?: string }): string | null {+ const reason = r.reason?.trim();+ if (!reason || !r.basis || /^laya picked\b/i.test(reason)) return null;+ return /[.!?]$/.test(reason) ? reason : `${reason}.`;+}+export function routeReasonText(r: RouteReasonInput): string | null {+ const own = serverReason(r);+ if (own) return own;const name = r.kwantName || 'the team lead';const terms = (r.matchedTerms ?? []).filter(Boolean).slice(0, 4);switch (r.basis) {diff --git a/frontend/src/spaces.ts b/frontend/src/spaces.tsindex 937696e0..324fbe4a 100644--- a/frontend/src/spaces.ts+++ b/frontend/src/spaces.ts@@ -1,6 +1,8 @@// Spaces: separate sets of bots, teams, channels and accounts. The open space rides on every// `/api` call as `?space=` (added by the fetch wrapper in auth.ts) and on the event stream.+import { serverReason } from './routeReason';+export interface SpaceCounts {bots: number;ready_accounts: number;@@ -249,7 +251,7 @@ export interface RoutingMeta {candidate_count?: number | null;fallback?: boolean;matched_terms?: string[];- /** 'lead' when no role matched and the team lead took it; see routeReason.ts. */+ /** How the bot was picked: skills, keywords, only, lead, several or discuss; see routeReason.ts. */basis?: string;}@@ -263,10 +265,12 @@ export function parseRoutingMeta(meta: string | null | undefined): RoutingMeta |}}-/** "Laya picked Lin from 6 bots in Work · matched 'migration', 'SQLite'", or the keyword-fallback line. */+/** The server's own reason when it sends one, else "Laya picked Lin from 6 bots in Work · matched 'migration', 'SQLite'", or the keyword-fallback line. */export function routingLine(r: RoutingMeta, spaceName: string): string {const n = typeof r.candidate_count === 'number' && r.candidate_count > 0 ? r.candidate_count : null;const pool = n ? `from ${n} ${n === 1 ? 'bot' : 'bots'} in ${spaceName}` : `in ${spaceName}`;+ const own = serverReason(r);+ if (own) return `${own} Chosen ${pool}.`;const matched = r.matched_terms?.length ? ` · matched ${r.matched_terms.map((t) => `'${t}'`).join(', ')}` : '';if (r.fallback) return `Picked by keywords (Laya is offline) · ${r.kwant_name} ${pool}${matched}`;if (r.basis === 'lead') return `No one’s role matched, so the team lead ${r.kwant_name} took it ${pool}`;diff --git a/frontend/tests/botCapabilities.test.mjs b/frontend/tests/botCapabilities.test.mjsindex 28d7e46e..57063a9f 100644--- a/frontend/tests/botCapabilities.test.mjs+++ b/frontend/tests/botCapabilities.test.mjs@@ -85,7 +85,7 @@ test('a team proposal lists every member with role and model, and asks once', ()const t = text(html);assert.match(t, /Backend proposes hiring a team of 3/);assert.match(t, /Engineering/);- for (const s of ['Frontend Frontend Engineer Picked automatically', 'QA QA \/ Test Engineer claude-sonnet-5-5 · Tools: Browser', 'Lead Tech Lead Picked automatically']) assert.match(t, new RegExp(s));+ for (const s of ['Frontend Lead Frontend Engineer Picked automatically', 'QA QA \/ Test Engineer claude-sonnet-5-5 · Tools: Browser', 'Lead Tech Lead Picked automatically']) assert.match(t, new RegExp(s));assert.match(t, /New team: Engineering/);assert.deepEqual(buttons(html), ['Show their instructions', 'Approve all 3', 'Always accept', 'Decline']);});@@ -168,3 +168,27 @@ test('the routing line says when the team lead took it because no role matched',assert.equal(m.routeReasonText({ basis: 'keywords', matchedTerms: ['strategy', 'go'] }), 'Picked by matching words: strategy, go.');assert.match(m.routingLine({ kwant_name: 'Ada', basis: 'lead', candidate_count: 4 }, 'Work'), /^No one’s role matched, so the team lead Ada took it from 4 bots in Work$/);});++// ---------------------------------------------------------------- shapes Lin's server sends (bot-capabilities)++test('a team proposal as the server sends it: members once, no Always accept, and the lead marked', () => {+ const html = m.hire(hireProps(hireMeta({ choices: ['deny', 'accept_once'], new_team: { name: 'Trading', lead: 'QA' } })));+ const t = text(html);+ assert.equal((t.match(/Frontend Engineer/g) ?? []).length, 1, 'the top-level bot is members[0], not an extra row');+ assert.deepEqual(buttons(html), ['Show their instructions', 'Approve all 3', 'Decline']);+ assert.match(t, /QA Lead QA \/ Test Engineer/);+ assert.match(t, /New team: Trading, led by QA/);+ assert.match(text(m.hire(hireProps(hireMeta({ new_team: { name: 'Trading', lead: null } })))), /led by Frontend/, 'no lead named: the first member leads');+});++test('the routing line and card use the server’s own reason when it sends one', () => {+ const several = { kwant_name: 'Gopher', basis: 'several', fallback: true, candidate_count: 3, matched_terms: ['endpoint', 'page'],+ reason: 'This touches several roles (Gopher and Pixel), so it went to the team lead, Gopher (Go backend), to answer or hand parts on. Laya is offline, so this was picked by keywords' };+ const line = m.routingLine(several, 'Trading');+ assert.match(line, /^This touches several roles \(Gopher and Pixel\).*picked by keywords\. Chosen from 3 bots in Trading\.$/);+ assert.doesNotMatch(line, /Laya picked/);+ const named = { kwantName: 'Probe', basis: 'keywords', matchedTerms: [], reason: 'Probe (QA) was named in your message' };+ assert.equal(m.routeReasonText(named), 'Probe (QA) was named in your message.');+ 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');+});