File size: 2,544 Bytes
fb43301
af1bee9
 
 
fb43301
af1bee9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import './coworkers.css';
import { Link } from 'react-router-dom';
import { useRuns } from '../api/hooks';
import { useAuth } from '../auth/AuthContext';
import { COWORKERS, coworkerState, type Coworker, type CoworkerState } from '../domain/coworkers';
import { CoworkerAvatar } from './CoworkerAvatar';

const STATE: Record<CoworkerState, { words: string; tone: string }> = {
  working: { words: 'Working', tone: 'blue' },
  waiting: { words: 'Waiting for you', tone: 'orange' },
  available: { words: 'Available', tone: 'neutral' },
};

/** One AI coworker: face, name, role, what it does, and what it is doing now. Opens the Agent team page (admins), or,

 * when `onOpen` is given (on that page), selects the coworker there; for everyone else it is a plain card. */
export function CoworkerCard({ c, state, onOpen, pressed, linked = true }: { c: Coworker; state: CoworkerState; onOpen?: () => void; pressed?: boolean; linked?: boolean }) {
  const s = STATE[state];
  const body = (
    <>

      <span className="cw-card-head pw-hatch-diag" aria-hidden />

      <span className="pw-status cw-card-state" data-variant="outline" data-tone={s.tone}>{s.words}</span>

      <CoworkerAvatar name={c.name} size={52} working={state === 'working'} />

      <span className="cw-card-name">{c.name}</span>

      <span className="cw-card-role">{c.role}</span>

      <span className="cw-card-job">{c.job}</span>

    </>
  );
  if (!onOpen && !linked) return <div className="cw-card" data-state={state} data-static data-testid={`coworker-${c.key}`}>{body}</div>;
  return onOpen
    ? <button type="button" className="cw-card" data-state={state} aria-pressed={pressed} onClick={onOpen} data-testid={`coworker-${c.key}`}>{body}</button>
    : <Link to="/agents" className="cw-card" data-state={state} data-testid={`coworker-${c.key}`}>{body}</Link>;
}

/** The whole AI team with live states (from the latest test runs). */
export function CoworkerGrid({ selected, onOpen, label = 'Your AI team' }: { selected?: string; onOpen?: (c: Coworker) => void; label?: string }) {
  const runs = useRuns(40, 0);
  const { can } = useAuth();
  const items = runs.data?.items ?? [];
  return (
    <div className="cw-grid" role="region" aria-label={label} tabIndex={0}>

      {COWORKERS.map((c) => (

        <CoworkerCard key={c.key} c={c} state={coworkerState(c, items)} pressed={onOpen ? selected === c.key : undefined} onOpen={onOpen ? () => onOpen(c) : undefined} linked={can('admin')} />

      ))}

    </div>
  );
}