Files
multica/packages/views/agents/components/agent-avatar-stack.tsx
Naiyuan Qing f4de0948a2 refactor(ui): unify ActorAvatar size tiers + round all avatars & cropper (MUL-4277, MUL-4184) (#5133)
* refactor(ui): converge ActorAvatar size to semantic tiers (MUL-4277)

Replace the free-form numeric `size` on ActorAvatar with a constrained
`AvatarSize` union (xs/sm/md/lg/xl/2xl) so avatar dimensions are chosen by
role instead of ad-hoc pixels. This eliminates the magic-number drift where
the same role rendered at different sizes across pages.

- Add `@multica/ui/lib/avatar-size` (AvatarSize union + AVATAR_SIZE_PX map +
  default tier).
- Base `ActorAvatar` (packages/ui) and business `ActorAvatar`/`AgentStatusDot`
  (packages/views) now take `AvatarSize`; internal font/icon math and the
  presence-dot threshold read px from the map.
- Migrate all web/desktop call sites (packages/ui + packages/views) from
  numeric sizes to tiers using the role table
  (12,14->xs 16,18,20->sm 22,24,28->md 30,32,34->lg 40,44->xl 56,64->2xl).
- Token-ise the derived consumers `AgentAvatarStack` and
  `IssueAgentActivityIndicator` (px looked up internally for overlap/+N math).

Out of scope (per plan): ui/avatar.tsx primitive, account-tab/AvatarPicker,
mobile, and component-name disambiguation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(ui): unify all avatars and the upload cropper to round (MUL-4277, MUL-4184)

main's avatar-shape decision rendered non-human actors (agent, squad,
system) and the workspace logo as rounded squares, and the upload cropper
mirrored that with a square crop window. Per the updated decision
(avatars_and_cropper_round_required), every avatar and the crop UI are now
circular; the square path is removed rather than left as dead config.

- Base ActorAvatar: always rounded-full (drop the isHuman/rounded-md split).
- avatar-crop-dialog: remove the AvatarCropShape/square path; crop window is
  always cropShape="round".
- avatar-upload-control: drop VARIANT_SHAPE; the control is always round and
  no longer threads a shape to the dialog (variant still drives the fallback).
- Strip rounded-md/rounded-none square overrides from agent/squad/member
  ActorAvatar call sites; round the read-only agent/squad static wrappers.
- WorkspaceAvatar: round the org logo so it matches the (now round) workspace
  upload/crop and the shared avatar shape.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(ui): make round avatar shape a hard invariant (MUL-4277)

Close the two remaining square squad-avatar paths flagged in review and
prevent call sites from re-squaring the avatar:

- base ActorAvatar: keep `rounded-full` as the last class in cn() so a
  call-site `className` can no longer override the circle.
- SquadHeaderAvatar: drop `className="rounded"` (was overriding the base
  circle into a small rounded square).
- SquadsPage no-avatar fallback: route through the shared ActorAvatarBase
  (`isSquad size="lg"`) instead of a hand-written rounded-md tile, so the
  fallback matches the image path — one shape source of truth.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(views): round the agent/squad avatar loading skeletons (MUL-4277)

The avatar placeholder skeletons on the agent/squad list, detail, and
profile-card loading states were still rounded squares (rounded-md/lg) from
the pre-round era, so the avatar visibly popped from square to circle on
load — inconsistent with the round avatars and with the member/inbox/issue
skeletons that already use rounded-full.

Round all five: agents-page, agent-detail-page, squads-page,
squad-detail-page, squad-profile-card.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
2026-07-10 08:31:40 +08:00

95 lines
3.2 KiB
TypeScript

"use client";
import { ActorAvatar as ActorAvatarBase } from "@multica/ui/components/common/actor-avatar";
import { AVATAR_SIZE_PX, type AvatarSize } from "@multica/ui/lib/avatar-size";
import { useActorName } from "@multica/core/workspace/hooks";
import { cn } from "@multica/ui/lib/utils";
interface AgentAvatarStackProps {
// Agent ids to render, in display order. The component does NOT dedupe —
// callers are expected to pass a unique list (`new Set(...)` upstream).
agentIds: readonly string[];
// Semantic avatar tier. Avatars overlap by ~30% so the visible spacing
// scales naturally with size. Defaults match a compact toolbar / card-corner
// density (sm / 20 px).
size?: AvatarSize;
// Maximum head count before collapsing the tail into a `+N` chip. Three
// is the plan default — beyond that the stack visually crowds.
max?: number;
// `half` drops opacity to 50%. Used by IssueAgentActivityIndicator to
// signal a queued-only state (no running task) — same heads, weakened
// visual.
opacity?: "full" | "half";
className?: string;
}
/**
* Overlapping avatar group for agents. Pure presentational — no data
* fetching, no hover handling. Wrap it in a HoverCardTrigger upstream
* (IssueAgentActivityIndicator / WorkspaceAgentWorkingChip) to surface
* per-agent detail.
*
* `agentIds` is the full input list. We render up to `max` heads; if the
* input is longer, we drop the tail and append a `+N` overflow chip styled
* to match the avatar dimensions.
*/
export function AgentAvatarStack({
agentIds,
size = "sm",
max = 3,
opacity = "full",
className,
}: AgentAvatarStackProps) {
const { getActorName, getActorInitials, getActorAvatarUrl } = useActorName();
if (agentIds.length === 0) return null;
const visible = agentIds.slice(0, max);
const overflow = agentIds.length - visible.length;
const px = AVATAR_SIZE_PX[size];
// 30% overlap reads as "stacked" without obscuring the next avatar's icon.
const overlap = Math.round(px * 0.3);
return (
<span
className={cn(
"inline-flex items-center",
opacity === "half" && "opacity-50",
className,
)}
style={{ paddingLeft: 0 }}
>
{visible.map((id, i) => (
<span
key={id}
// Each subsequent head sits negative-margin over the previous so
// the stack collapses horizontally instead of growing linearly.
style={{ marginLeft: i === 0 ? 0 : -overlap }}
className="ring-2 ring-background rounded-full inline-flex"
>
<ActorAvatarBase
name={getActorName("agent", id)}
initials={getActorInitials("agent", id)}
avatarUrl={getActorAvatarUrl("agent", id)}
isAgent
size={size}
/>
</span>
))}
{overflow > 0 && (
<span
style={{
marginLeft: -overlap,
width: px,
height: px,
fontSize: Math.max(9, Math.round(px * 0.45)),
}}
className="ring-2 ring-background rounded-full bg-muted text-muted-foreground inline-flex items-center justify-center font-medium tabular-nums"
aria-label={`${overflow} more`}
>
+{overflow}
</span>
)}
</span>
);
}