EnergyVenom's picture
Tidy the web app: pages by area, CSS in load order, web/README.md (b2a039d)
fb43301 verified
Raw History Blame Contribute Delete
1.91 kB
import { COWORKERS, type Coworker } from '../domain/coworkers';
import type { ChatResult } from './api';
/** Who an answer comes from: a coworker of the AI team, the built-in coordinator ("Astra"), or Hermes. */
export type Speaker =
| { kind: 'coworker'; name: string; role: string }
| { kind: 'patchwise'; name: 'Astra'; role: string }
| { kind: 'hermes'; name: 'Hermes'; role: string };
const byLead = (lead: string): Coworker | undefined => COWORKERS.find((c) => c.lead === lead);
/** The answering tool (backend coworker/chat/tools.py) to the coworker whose work it describes. */
const TOOL_LEAD: Record<string, string> = {
readiness: 'scout', patch_changes: 'scout', list_pods: 'scout',
scenario: 'test_generator', approve_scenarios: 'test_generator',
run_status: 'executor', list_runs: 'executor',
failures: 'triage',
};
/** Answer cards point at the same coworkers when the tool is not known (an answer restored from history has none). */
const CARD_LEAD: Record<string, string> = { readiness: 'scout', changes: 'scout', pods: 'scout', scenario: 'test_generator', run: 'executor', runs: 'executor', failures: 'triage' };
const PATCHWISE: Speaker = { kind: 'patchwise', name: 'Astra', role: 'Coordinator' };
/** Pick the speaker for an answer: Hermes when Hermes answered; actions that start or change runs, help and anything
* unknown are the coordinator; otherwise the coworker behind the tool or the first card. */
export function speakerFor(m: { by?: 'hermes' | 'builtin'; tool?: string | null; result?: ChatResult }): Speaker {
if (m.by === 'hermes') return { kind: 'hermes', name: 'Hermes', role: 'Assistant' };
const lead = (m.tool && TOOL_LEAD[m.tool]) || (m.result?.cards[0] && CARD_LEAD[m.result.cards[0].type]);
const c = lead ? byLead(lead) : undefined;
return c ? { kind: 'coworker', name: c.name, role: c.role } : PATCHWISE;
}