a.sourceEntityType === "agent" && a.sourceEntityId === agent.id && a.kind === "agent_hire",
+ ) ?? null;
+
+ if (hireApproval?.state === "pending") return { agent, stage: "pending_approval", approval: hireApproval };
+ if (hireApproval?.state === "declined") return { agent, stage: "rejected", approval: hireApproval };
+ if (agent.lifecycle === "active") return { agent, stage: "active", approval: hireApproval };
+ return { agent, stage: "approved", approval: hireApproval };
+}
+
+export function HiringPipeline({ agents, approvals }: { agents: AgentRecord[]; approvals: ApprovalRecord[] }) {
+ const entries = agents.map((a) => resolveStage(a, approvals));
+
+ return (
+
+ Hiring pipeline
+
+ {STAGES.map((stage) => {
+ const stageEntries = entries.filter((e) => e.stage === stage.id);
+ return (
+
+
+
+ {stage.label}
+ {stageEntries.length}
+
+
+ {stageEntries.map((entry) => (
+
+
+
+
+
{entry.agent.name}
+
{entry.agent.role} ยท {entry.agent.department}
+
+
+ {entry.approval && (
+
+ {formatRelative(entry.approval.createdAt)}
+
+ )}
+
+ ))}
+
+
+ );
+ })}
+
+
+ );
+}