Skip to content
refs
127 lines · 4.7 KBRaw
1import { GearIcon } from "@refs/design-system/icons";
2import type { Attribution, OnlineAgent } from "@refs/backend/contract";
3import { AgentAvatar, Avatar, Button, cn } from "@refs/design-system";
4
5type AvatarSize = "xs" | "sm" | "base";
6
7export function human(name: string): Attribution {
8 return { actor: { kind: "human", id: "", name } };
9}
10
11/** Who opened a pull request: the agent, acting for its author, or the author alone. */
12export function openerOf(pull: { readonly author: { readonly name: string }; readonly agent: string | null }): Attribution {
13 return pull.agent ? { actor: { kind: "agent", id: "", name: pull.agent, runtime: pull.agent }, onBehalfOf: { id: "", name: pull.author.name } } : human(pull.author.name);
14}
15
16/** A small actor mark and name, for list rows and headers. */
17export function Opener({ by }: { by: Attribution }) {
18 return (
19 <span className="inline-flex min-w-0 items-center gap-1.5">
20 <ActorMark by={by} size="xs" />
21 <ActorName by={by} />
22 </span>
23 );
24}
25
26export function isAgent(by: Attribution): boolean {
27 return by.actor.kind === "agent" || by.onBehalfOf !== undefined;
28}
29
30/** A person is a filled blue circle; an agent is a hollow ring. */
31export function ActorMark({ by, size = "sm" }: { by: Attribution; size?: AvatarSize }) {
32 return isAgent(by) ? <AgentAvatar name={by.actor.name} size={size} /> : <Avatar name={by.actor.name} size={size} />;
33}
34
35/** "claude-code for Aman": the runtime in medium weight, the person it acts for muted. */
36export function ActorName({ by }: { by: Attribution }) {
37 return (
38 <span className="min-w-0">
39 <span className={cn("text-ink", isAgent(by) ? "font-medium" : "font-semibold")}>{by.actor.name}</span>
40 {by.onBehalfOf && <span className="font-normal text-muted"> for {by.onBehalfOf.name}</span>}
41 </span>
42 );
43}
44
45export function AgentName({ agent }: { agent: Pick<OnlineAgent, "runtime" | "onBehalfOf"> }) {
46 return (
47 <span className="min-w-0">
48 <span className="font-medium text-ink">{agent.runtime}</span>
49 <span className="font-normal text-muted"> for {agent.onBehalfOf.name}</span>
50 </span>
51 );
52}
53
54export function Who({ by }: { by: Attribution }) {
55 return (
56 <span className="inline-flex min-w-0 items-center gap-2">
57 <ActorMark by={by} />
58 <ActorName by={by} />
59 </span>
60 );
61}
62
63type MarkerTone = "human" | "agent" | "event";
64
65const MARKER: Record<MarkerTone, string> = {
66 human: "bg-accent",
67 agent: "bg-ground shadow-[inset_0_0_0_1.5px_var(--porcelain)]",
68 event: "bg-line",
69};
70
71export function toneOf(by: Attribution): MarkerTone {
72 return isAgent(by) ? "agent" : "human";
73}
74
75/** A vertical hairline; each row hangs a station mark on it. */
76export function Timeline({ children }: { children: React.ReactNode }) {
77 return (
78 <div className="relative flex min-w-0 flex-col gap-3">
79 <span aria-hidden="true" className="absolute top-3 bottom-3 left-[3px] w-px bg-hairline" />
80 {children}
81 </div>
82 );
83}
84
85export function TimelineRow({ tone, offset = "top-3.5", children, className }: { tone: MarkerTone; offset?: string; children: React.ReactNode; className?: string }) {
86 return (
87 <div className={cn("relative min-w-0 pl-6", className)}>
88 <span aria-hidden="true" className={cn("absolute left-0 size-[7px] rounded-full ring-4 ring-ground", offset, MARKER[tone])} />
89 {children}
90 </div>
91 );
92}
93
94/** An event: one quiet line on the timeline. */
95export function EventLine({ by, icon, children }: { by: Attribution; icon: React.ReactNode; children: React.ReactNode }) {
96 return (
97 <TimelineRow tone="event" offset="top-[13px]">
98 <p className="m-0 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 py-1 text-compact text-muted [&_svg]:shrink-0">
99 <span className="flex size-4 items-center justify-center text-faint">{icon}</span>
100 <ActorMark by={by} size="xs" />
101 <ActorName by={by} />
102 {children}
103 </p>
104 </TimelineRow>
105 );
106}
107
108/** A field of a page's side column: a caption, an optional control, and the value. */
109export function Field({ label, action, children }: { label: string; action?: React.ReactNode; children: React.ReactNode }) {
110 return (
111 <section className="flex flex-col gap-1.5 py-3 text-compact shadow-[inset_0_-1px_0_var(--hairline)] first:pt-0 last:shadow-none">
112 <div className="flex min-h-5 items-center justify-between gap-2">
113 <h2 className="caption m-0 text-faint">{label}</h2>
114 {action}
115 </div>
116 {children}
117 </section>
118 );
119}
120
121export function GearButton({ label }: { label: string }) {
122 return (
123 <Button variant="ghost" size="sm" shape="square" className="hit-area -my-1 -mr-1.5 size-6" aria-label={label}>
124 <GearIcon size={14} />
125 </Button>
126 );
127}