• 简体中文
  • AgentHud

    仲裁器当前的读数,用一个角色加一块底盘表达。

    Nova
    import { useEffect } from 'react';
    import { AgentHud, AgentStateProvider, useAgentState } from '@aora-bot/react';
    
    function Feed() {
      const { update } = useAgentState();
      useEffect(() => {
        let remaining = 90_000;
        update({ sessionId: 'nova', state: 'thinking', tips: '正在读需求' });
        const timer = setInterval(() => {
          remaining = remaining <= 0 ? 90_000 : remaining - 5_000;
          update({
            sessionId: 'nova',
            state: remaining < 20_000 ? 'waiting' : 'working',
            tips: remaining < 20_000 ? '很快需要你的答复' : '正在跑检查',
            hud: { kind: 'timer', remainingMs: remaining, totalMs: 90_000 },
          });
        }, 1000);
        return () => clearInterval(timer);
      }, [update]);
      return null;
    }
    
    export default function Demo() {
      return (
        <AgentStateProvider>
          <Feed />
          <div className="site-demo site-demo--center">
            <AgentHud agent={{ id: 'nova', name: 'Nova' }} placement="right" />
          </div>
        </AgentStateProvider>
      );
    }

    只有一个数据源

    屏幕上的一切都来自最近的 AgentStateProvider。状态决定脸,tips 变成底盘的补充文字,hud 跟着当前胜出的会话走——所以一个会话发来的倒计时,绝不会留在另一个会话的脸上。底盘等级随状态而定:alerting 和 refusing 是 alert,waiting 和 suspicious 是 warn,happy、proud、celebrate 是 ok,其余是 info。传 level 可以覆盖。

    没有 Provider 时组件照样渲染——一个空闲角色、智能体名字、没有表盘——所以页头可以在智能体通道接通之前就先挂载。

    useAgentHud

    它背后的 hook。从 Provider 读出胜出结果的 hud,没有 Provider 或没有表盘时返回 null,于是想自己排版的宿主可以把同一份 spec 直接放到 CharacterMark 上。

    const hud = useAgentHud();
    <CharacterMark shape="hex" state={state} hud={hud} />;

    外观

    agent 提供形状、墨色、脸型和鼻子,解析方式与 AgentAvatar 相同:先看显式字段,再看 preset,最后由 id 确定性推导。face、nose、lineWeight 会覆盖智能体自己的设定,所以要一个笔画更重的线条脸 HUD,只差一个 prop。线条粗细由鼻子、嘴和表盘共用——见线条脸在各个面上。

    API

    属性类型默认值说明
    agentAgentLike—Whose face to draw. Without one the character falls back to the default blob.
    classNamestring——
    face"cute" | "eyes" | "line"——
    levelHudLevel—Override the level the state implies.
    lineWeightnumber——
    nose"slant" | "angular" | "hook" | "long" | "curve" | "bow" | null——
    placementHudPlacement'bottom'—
    sizePxnumber72—
    styleCSSProperties——
    titlestring—Heading on the plate. Defaults to the agent's name.

    接下来

    • HudPlate——表盘旁边的一个数字
    • 进度 HUD——身体在干活,外环在计数