ActivityBadge
用角色加标签显示智能体正在做什么。
状态和标签出自同一来源
工具名同时决定动画状态和标签。状态取自引擎的 stateForTool() 映射表,Claude Code 和 Cursor 适配器用的也是这张表。因此,不论宿主是已经接入情绪协议,还是只知道工具名,脸上显示的内容都是一致的。
遇到未知工具时,会回退到通用的工作状态,而不是什么都不渲染,所以新增的工具不会出现空白。
添加工具
群组
同时显示每个成员,四人的群组就会变成一堵角色墙。所以这一行改为轮播:宽度始终只有一个角色,又能看出有哪些成员参与。群组徽标为 GROUP_BADGE_PX(24 px),单个徽标为 ACTIVITY_BADGE_PX(32 px);每隔 GROUP_CYCLE_MS(2.4 秒)切换到下一位成员,墨色的过渡时长为 600 ms。轮播间隔和徽标尺寸可以分别用 cycleMs 和 sizePx 修改。
语言
标签由语言 Provider提供,文字会跟随上下文的语言,不需要额外传 prop。
用事实而不是工具名
activityMode="tool" 是默认值:由调用方给出工具名,状态和标签都跟着工具名走。activityMode="facts" 则读取共享的角色指令注册表,这样同一个智能体的对话行和名册头像,对它在做什么就不会出现分歧。这一行挂载期间,facts 会为该智能体发布 { running, composing, activity }(按值比较,所以直接传内联对象也可以)。surface 说明这一行画在哪里:对话行用 chat,这里“正在撰写”正是要表现的重点;同样的事实在 avatar 上会解析为 idle,因为二十张脸每隔几百毫秒就在两个状态之间闪动,只会造成干扰。解析由引擎的 characterStateForRoster(facts, surface) 完成。
标签、气泡、可见性
showLabel 控制标签的显示方式:always 常显,hover 仅在悬停时显示,never 不显示。即使是 never,标签仍保留在无障碍树中,因为标签是屏幕阅读器唯一能读到的内容。bubble 把标签画成对话气泡,而不是纯文字,适合标签在角色旁边而不是下方的布局。
visible={false} 会先播放退场动画再卸载,而不是立刻卸载。如果在标志位翻转的同一时刻卸载,这一行会直接消失而不是退场,在连续的对话中看起来像故障。
戳一下
点击角色时会调用 onPoke;传了 onPoke,角色才会渲染成真正的按钮。没有它时,点击不会有任何效果:为了一个屏幕阅读器用户看不到的小动画,给对话记录的每一行都加一个 Tab 停靠点,并不值得。戳一下也会通过共享指令发出,所以该智能体的其他角色都会有反应;无法单独动作的镜像角色,则由外层容器代为跳一下。
在场 hook
组件内部用到的两个 Hook 也对外导出,供自己绘制对话行的宿主使用。
useActivityStatus(visible, { exitMs }) 返回 { mounted, leaving }:mounted 在退场动画期间保持为 true,leaving 标出应当加上离场类名的那几帧。exitMs 默认为 ACTIVITY_EXIT_MS(140 ms),在“减少动态效果”模式下为 0。状态切换在渲染期间完成,而不是放在 effect 里,所以隐藏该行的那一帧,退场动画就已经显示在屏幕上。
useArrival(agentId) 返回 { isFirst, state }:登场动画播放期间,state 为 'spawning',之后为 null,调用方此时应改用实际状态。哪些智能体已经登场,记录在模块级别而不是 context 中:滚动离开时卸载、滚回来时重新挂载的行,不应该再登场一次。resetSpawnEntrances() 会清除所有登场记录,用于测试和会话重置。
无障碍
标签是真正的文字,所以即使看不到动画,也能读出智能体的状态。凡是角色要传达信息的地方,都建议照这个做法处理,详见无障碍。
API
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
agent* | AgentLike | — | — |
activityMode | ActivityMode | 'tool' | Where the animation state comes from. Defaults to `tool`. |
bubble | boolean | false | Draw the label as a speech bubble rather than as bare text. |
className | string | — | — |
entering | boolean | false | Play the arrival animation. |
face | "symbol" | "capsule" | "cute" | "eyes" | "line" | "brow" | "glossy" | "sparkle" | "button" | "shades" | "droopy" | "bigmouth" | "pie" | "screen" | "teardrop" | "specs" | — | Face style, overriding what the agent identity resolves to. |
facts | RosterFacts | — | Facts to publish for this agent while the row is mounted, so every other mark for it follows along. Compared by value, not identity. |
inkCss | string | — | CSS colour for the mark's ink, instead of the agent's palette colour. |
lineWeight | number | — | Stroke width multiplier for the character. |
nose | "slant" | "angular" | "hook" | "long" | "curve" | "bow" | null | — | Nose, overriding the identity. `null` draws no nose. |
onPoke | ((agent: AgentLike) => void) | — | Called when the character is clicked. Its presence also makes the mark a real button. |
pokeLabel | string | — | Accessible name for the poke control. |
showLabel | ActivityLabelMode | 'always' | Show the label always, only while the row is hovered, or never. |
sizePx | number | ACTIVITY_BADGE_PX | — |
style | CSSProperties | — | Applied to the row, not to the character. |
surface | RosterSurface | 'chat' | Surface used to derive the state from facts. A conversation row is `chat`. |
text | string | — | Override the label text. |
tool | string | null | — | Tool the agent is running. Drives both the label and the animation. |
visible | boolean | true | Unmount with the exit animation rather than instantly. |
GroupActivityBadge
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
members* | AgentLike[] | — | — |
className | string | — | — |
cycleMs | number | GROUP_CYCLE_MS | — |
face | "symbol" | "capsule" | "cute" | "eyes" | "line" | "brow" | "glossy" | "sparkle" | "button" | "shades" | "droopy" | "bigmouth" | "pie" | "screen" | "teardrop" | "specs" | — | Face style for whichever member is showing, overriding their identity. |
lineWeight | number | — | Stroke width multiplier for the character. |
nose | "slant" | "angular" | "hook" | "long" | "curve" | "bow" | null | — | Nose for whichever member is showing. `null` draws no nose. |
onPoke | ((agent: AgentLike) => void) | — | — |
showLabel | ActivityLabelMode | — | — |
sizePx | number | GROUP_BADGE_PX | — |
style | CSSProperties | — | Merged over the ink custom properties the rotation animates, so a host can position the cluster without losing the crossfade. |
tool | string | null | — | — |
接下来
- ActivityLine——滚动切换的活动动词
- 对话流——带脸的状态行