• English
  • ActivityBadge

    A character and a label showing what an agent is doing.

    SearchingSearchingSearchingSearchingReadingReadingReadingReadingWritingWritingWritingWritingWorkingWorkingWorkingWorkingUploadingThinkingThinkingListeningWaiting for you
    import { CharacterStageProvider, ActivityBadge, TOOL_ACTIVITIES } from '@aora-bot/react';
    
    export default function Demo() {
      return (
        <CharacterStageProvider>
          <div className="site-demo site-demo--column">
            {Object.keys(TOOL_ACTIVITIES).map((tool) => (
              <ActivityBadge key={tool} agent={{ id: tool }} tool={tool} />
            ))}
          </div>
        </CharacterStageProvider>
      );
    }

    One source for both halves

    The tool name picks an animation state and a label at the same time. The state comes from the engine's stateForTool() table — the same mapping the Claude Code and Cursor adapters use — so a host that already speaks the emotion protocol and a host that only has a tool name cannot disagree about what the face should show.

    activityForTool('web_search');
    // → { labelKey: 'activity.searching', state: 'searching' }

    Unknown tools fall back to a generic working state rather than rendering nothing, so a new tool degrades gracefully.

    Adding tools

    import { TOOL_ACTIVITIES } from '@aora-bot/react';
    
    TOOL_ACTIVITIES.deploy = { labelKey: 'activity.running', state: 'working' };

    Groups

    Working
    import { CharacterStageProvider, GroupActivityBadge } from '@aora-bot/react';
    
    const members = [{ id: 'ada' }, { id: 'grace' }, { id: 'alan' }];
    
    export default function Demo() {
      return (
        <CharacterStageProvider>
          <GroupActivityBadge members={members} tool="run" />
        </CharacterStageProvider>
      );
    }

    Showing every member at once turns a four-person group into a wall of characters, so the row cycles through them instead. It stays one character wide and still shows who is involved. The group badge is GROUP_BADGE_PX (24 px), against ACTIVITY_BADGE_PX (32 px) for a single badge. It moves to the next member every GROUP_CYCLE_MS (2.4 s), with a 600 ms ink transition. Use cycleMs and sizePx to change the interval and the size.

    Language

    Labels come from the locale provider, so the text follows the surrounding language without a prop.

    Searching搜索中
    import { LocaleProvider, ActivityBadge } from '@aora-bot/react';
    
    export default function Demo() {
      return (
        <div className="site-demo site-demo--column">
          <ActivityBadge agent={{ id: 'en' }} tool="search" />
          <LocaleProvider locale="zh-CN">
            <ActivityBadge agent={{ id: 'zh' }} tool="search" />
          </LocaleProvider>
        </div>
      );
    }

    Facts instead of a tool name

    activityMode="tool" is the default: the caller names a tool and both halves of the row follow. activityMode="facts" reads the shared mark commands registry instead, so a row and the roster avatar for the same agent cannot disagree about what it is doing. While the row is mounted, facts publishes { running, composing, activity } for the agent. It is compared by value, so an inline object is fine. surface says where the row is drawn. A conversation row uses chat, where composing is the whole point; on an avatar surface the same facts resolve to idle, because twenty faces flicking between two states every few hundred milliseconds is noise. The engine resolves this with characterStateForRoster(facts, surface).

    Working
    same facts, avatar surface
    import { useState } from 'react';
    import { CharacterStageProvider, ActivityBadge, AgentPortrait, useMarkCommand } from '@aora-bot/react';
    
    const agent = { id: 'nova', shape: 'hex', color: 'violet' } as const;
    
    function RosterAvatar() {
      const snapshot = useMarkCommand(agent.id, 'avatar');
      return <AgentPortrait agent={agent} state={snapshot.state} size="lg" />;
    }
    
    export default function Demo() {
      const [composing, setComposing] = useState(true);
      return (
        <CharacterStageProvider>
          <div className="site-demo site-demo--column">
            <ActivityBadge
              agent={agent}
              activityMode="facts"
              facts={{ running: true, composing, activity: 'writing' }}
              surface="chat"
            />
            <div className="site-demo">
              <RosterAvatar />
              <span className="site-demo__label">same facts, avatar surface</span>
            </div>
            <button className="site-btn" onClick={() => setComposing((c) => !c)}>
              composing: {String(composing)}
            </button>
          </div>
        </CharacterStageProvider>
      );
    }

    Label, bubble, visibility

    showLabel shows the label always, only on hover, or never — and never keeps it in the accessibility tree, because the label is the only part of the row a screen reader can use. bubble draws the label as a speech bubble rather than bare text, for a row sitting next to the character rather than under it.

    visible={false} plays the exit animation before unmounting, rather than unmounting at once. Unmounting on the same tick as the flag flips makes the row vanish instead of leave, which looks like a glitch in an otherwise continuous conversation.

    SearchingReadingWorking
    import { useState } from 'react';
    import { CharacterStageProvider, ActivityBadge } from '@aora-bot/react';
    
    export default function Demo() {
      const [visible, setVisible] = useState(true);
      return (
        <CharacterStageProvider>
          <div className="site-demo site-demo--column">
            <ActivityBadge agent={{ id: 'bubble' }} tool="search" bubble />
            <ActivityBadge agent={{ id: 'hover' }} tool="read_file" showLabel="hover" />
            <ActivityBadge agent={{ id: 'leaving' }} tool="run" visible={visible} />
            <button className="site-btn" onClick={() => setVisible((v) => !v)}>
              {visible ? 'hide the last row' : 'show it again'}
            </button>
          </div>
        </CharacterStageProvider>
      );
    }

    Poking

    onPoke is called when the character is clicked, and its presence turns the mark into a real button — without it, a click does nothing, because adding a tab stop to every row of a transcript for a flourish a screen-reader user cannot see is not worth it. A poke also goes through the shared commands, so every other mark for the agent reacts; a mirrored mark that cannot move alone hops its wrapper instead.

    Thinkingpoked 0 times
    import { useState } from 'react';
    import { CharacterStageProvider, ActivityBadge } from '@aora-bot/react';
    
    export default function Demo() {
      const [pokes, setPokes] = useState(0);
      return (
        <CharacterStageProvider>
          <div className="site-demo site-demo--column">
            <ActivityBadge
              agent={{ id: 'poke', shape: 'star', color: 'yellow' }}
              tool="think"
              onPoke={() => setPokes((n) => n + 1)}
            />
            <span className="site-demo__label">poked {pokes} times</span>
          </div>
        </CharacterStageProvider>
      );
    }

    Presence hooks

    Two hooks the component uses are exported for hosts that render their own row.

    useActivityStatus(visible, { exitMs }) returns { mounted, leaving }: mounted stays true through the exit animation and leaving marks the frames in which to apply the leaving class. The default exitMs is ACTIVITY_EXIT_MS (140 ms), and drops to zero under reduced motion. The transition is applied during render rather than in an effect, so the exit is on screen for the very frame that hides the row.

    useArrival(agentId) returns { isFirst, state }: state is 'spawning' while the arrival plays and then null, so the caller falls back to its real state. Which agents have been introduced is remembered at module level, not in context — a row that unmounts when you scroll past it and remounts when you scroll back should not arrive twice. resetSpawnEntrances() forgets every introduction, for tests and session resets.

    first appearance, here
    import { useState } from 'react';
    import { CharacterStageProvider, StagedMark, useActivityStatus, useArrival } from '@aora-bot/react';
    
    function Row({ id, visible }: { id: string; visible: boolean }) {
      const presence = useActivityStatus(visible);
      const spawn = useArrival(id);
      if (!presence.mounted) return null;
      return (
        <span className={`aora-activity${presence.leaving ? ' aora-activity--leaving' : ''}`}>
          <StagedMark shape="pebble" color="green" state={spawn.state ?? 'idle'} sizePx={28} />
          <span className="site-demo__label">
            {spawn.isFirst ? 'first appearance' : 'seen before'}, {presence.leaving ? 'leaving' : 'here'}
          </span>
        </span>
      );
    }
    
    export default function Demo() {
      const [visible, setVisible] = useState(true);
      return (
        <CharacterStageProvider>
          <div className="site-demo site-demo--column">
            <Row id="presence-demo" visible={visible} />
            <button className="site-btn" onClick={() => setVisible((v) => !v)}>
              toggle
            </button>
          </div>
        </CharacterStageProvider>
      );
    }

    Accessibility

    The label is real text, so the state of the agent is readable without seeing the animation. This is the pattern to copy whenever a character carries meaning — see accessibility.

    API

    PropTypeDefaultDescription
    agent*AgentLike——
    activityModeActivityMode'tool'Where the animation state comes from. Defaults to `tool`.
    bubblebooleanfalseDraw the label as a speech bubble rather than as bare text.
    classNamestring——
    enteringbooleanfalsePlay 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.
    factsRosterFacts—Facts to publish for this agent while the row is mounted, so every other mark for it follows along. Compared by value, not identity.
    inkCssstring—CSS colour for the mark's ink, instead of the agent's palette colour.
    lineWeightnumber—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.
    pokeLabelstring—Accessible name for the poke control.
    showLabelActivityLabelMode'always'Show the label always, only while the row is hovered, or never.
    sizePxnumberACTIVITY_BADGE_PX—
    styleCSSProperties—Applied to the row, not to the character.
    surfaceRosterSurface'chat'Surface used to derive the state from facts. A conversation row is `chat`.
    textstring—Override the label text.
    toolstring | null—Tool the agent is running. Drives both the label and the animation.
    visiblebooleantrueUnmount with the exit animation rather than instantly.

    GroupActivityBadge

    PropTypeDefaultDescription
    members*AgentLike[]——
    classNamestring——
    cycleMsnumberGROUP_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.
    lineWeightnumber—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)——
    showLabelActivityLabelMode——
    sizePxnumberGROUP_BADGE_PX—
    styleCSSProperties—Merged over the ink custom properties the rotation animates, so a host can position the cluster without losing the crossfade.
    toolstring | null——

    Next