Files
multica/packages/views/common/task-transcript/transcript-button.tsx
Naiyuan Qing ec4b8e9c1a feat(agent-status): redesign agent runtime status as two orthogonal dimensions
Splits the conflated 5-state agent presence into two independent axes:

- AgentAvailability (3-state): online / unstable / offline — drives the
  dot indicator everywhere a dot appears. Pure runtime reachability;
  never sticky-red because of a past task outcome.

- LastTaskState (5-state): running / completed / failed / cancelled /
  idle — surfaced as text + icon on focused surfaces (hover card,
  agent detail page, agents list, runtime detail). Never colours the dot.

Major changes:

* Domain layer: AgentPresence union → AgentAvailability + LastTaskState.
  derive-presence split into deriveAgentAvailability + deriveLastTaskState
  + deriveAgentPresenceDetail orchestrator. Tests reorganised into three
  groups (availability invariants, last-task invariants, composition).

* Visual config: presenceConfig (5 entries) → availabilityConfig (3) +
  taskStateConfig (5). availabilityOrder + lastTaskOrder for filter chips.

* Workspace-level presence prefetch: new useWorkspacePresencePrefetch
  hook + WorkspacePresencePrefetch mount component, wired into
  DashboardLayout (web) and WorkspaceRouteLayout (desktop). Hover cards
  render synchronously with no skeleton flash on first hover.

* ActorAvatar hover: flipped default — disableHoverCard removed,
  enableHoverCard added (default false). Opt-in at ~14 decision-moment
  surfaces; pickers / decoration sub-chips stay plain. Status dot
  decoupled (showStatusDot prop) so picker rows can show presence
  without nesting popovers.

* Hover cards: AgentProfileCard simplified — availability dot only,
  Detail link top-right (logs live on the detail page). New
  MemberProfileCard mirrors the structure: name + role + email +
  top-2 owned agents (sorted by 30d run count) with click-through to
  agent detail.

* Agents list: split Status into two columns — availability (3-color
  dot + label) and Last run (task icon + label, optional running
  counts). Two independent filter chip groups (Status + Last run);
  combination acts as intersection ("online + failed" finds broken-
  but-alive agents).

* Other UI surfaces (issue list/board/detail, comments, autopilots,
  projects, runtimes, mention autocomplete, subscribers picker)
  updated to the new dot semantics; status dot now strictly 3-color.

Server changes accompany the client redesign — workspace-wide
agent-task-snapshot endpoint, runtime usage queries, etc. — to feed
the derive layer with the data it needs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 18:54:00 +08:00

113 lines
3.2 KiB
TypeScript

"use client";
import { useCallback, useState } from "react";
import { Loader2, ScrollText } from "lucide-react";
import { cn } from "@multica/ui/lib/utils";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@multica/ui/components/ui/tooltip";
import { api } from "@multica/core/api";
import type { AgentTask } from "@multica/core/types/agent";
import { AgentTranscriptDialog } from "./agent-transcript-dialog";
import { buildTimeline, type TimelineItem } from "./build-timeline";
interface TranscriptButtonProps {
task: AgentTask;
agentName: string;
/**
* Pre-loaded timeline. When provided the button skips the fetch and opens
* the dialog immediately — used by the live card where `items` already
* accumulate via WS. Omit for terminal tasks; the button will fetch via
* `api.listTaskMessages` on the first click and cache the result.
*/
items?: TimelineItem[];
isLive?: boolean;
className?: string;
title?: string;
}
/**
* Compact icon-button that opens the full transcript dialog. Used on any
* surface that lists agent tasks (issue activity card, agent detail
* activity tab). Owns its own dialog state and lazy-load — the parent
* just drops it in.
*/
export function TranscriptButton({
task,
agentName,
items: providedItems,
isLive = false,
className,
title = "View transcript",
}: TranscriptButtonProps) {
const [open, setOpen] = useState(false);
const [loading, setLoading] = useState(false);
const [loadedItems, setLoadedItems] = useState<TimelineItem[] | null>(null);
// Live mode: parent owns the timeline, we just render it.
// Lazy mode: we fetch once and cache.
const items = providedItems ?? loadedItems ?? [];
const handleClick = useCallback(
(e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
if (providedItems !== undefined || loadedItems !== null) {
setOpen(true);
return;
}
setLoading(true);
api
.listTaskMessages(task.id)
.then((msgs) => {
setLoadedItems(buildTimeline(msgs));
setOpen(true);
})
.catch((err) => {
console.error(err);
setLoadedItems([]);
setOpen(true);
})
.finally(() => setLoading(false));
},
[providedItems, loadedItems, task.id],
);
return (
<>
<Tooltip>
<TooltipTrigger
render={<button type="button" />}
onClick={handleClick}
disabled={loading}
aria-label={title}
className={cn(
"flex items-center justify-center rounded p-1 text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors disabled:opacity-50",
className,
)}
>
{loading ? (
<Loader2 className="h-3.5 w-3.5 animate-spin" />
) : (
<ScrollText className="h-3.5 w-3.5" />
)}
</TooltipTrigger>
<TooltipContent>{title}</TooltipContent>
</Tooltip>
{open && (
<AgentTranscriptDialog
open={open}
onOpenChange={setOpen}
task={task}
items={items}
agentName={agentName}
isLive={isLive}
/>
)}
</>
);
}