feat: 唤醒式架构批次——capacity/L4/会话编排/管理面板写CRUD/前端集成(77-81)
【capacity 唤醒式核心(77)】internal/runtime/capacity:(Decider L1启发式+L2上下文+人格覆盖→三态静息/唤醒/全能→允许工具集+capacity_awaken事件)。loop 外围允许集过滤(不硬阻断=能力≠边界红线)。config 加 Capacity(Enabled/MinConfidence/ToolSets)。wire buildCapacity 接入 loop。 【L4 记忆驱动意图(80)】recall.go:从记忆召回用户习惯(搞一下xx=办事)→唤醒L1/L2漏掉/升置信;群聊陌生人不读owner习惯(隔离红线);RecordIntent闭环(判定写回记忆越用越准);默认保守静息。 【会话消息编排(78)】gateway/session_orchestrator.go:每会话(模式/pending有界5/tail上下文尾巴20);Submit非阻塞(idle立即/busy入队ack/满拒绝);完成回调按序续接(tail+新消息合并增量注入非全量重放);Interrupt中断;REST 202/409+WS session_busy/pending_ack事件;不重造任务引擎复用loop。 【前端集成(79)】ws.ts 加 capacity_awaken/session_busy/pending_ack 解析;store 加 awakenState/sessionBusy;TopBar/ChatShell 加唤醒态徽标+忙态提示(不阻塞输入框);状态组件 status.tsx;Miuix风格。 【管理面板写CRUD(81)】20个写端点(POST/PUT/DELETE /admin/*,owner+审计落库):personas(真持久化YAML)/users apikey(签发掩码+撤销)/iot控制(真下发)/automations(建/触发/删)/llm(test真调用+临时)/channels(connect/close/身份测试actor白名单)/plugins(卸载)/memories(search真检索)/sessions(export)。无存储如实501不伪造。拆4文件满足≤500红线。前端9模块接真写。 【wire收口】buildCapacity接入loop+OnCapacity事件;server.go newOrchestrator接hub。 实机验证:iot ac.living control 200 真实改变 on:true;observability/metrics 200、health ok;全仓 build/vet/test 47包绿+前端tsc/vite。
This commit is contained in:
1 parent
e0a543cc37
commit
6dbb4a2e18
51 files changed
+5395
-287
No files matched your search
@@ -5,6 +5,7 @@ import { applyTheme, readTheme, type ThemeMode } from "../lib/theme";
|
||||
import type { Mode, WsStatus } from "../lib/types";
|
||||
import { Tag } from "./primitives";
|
||||
import { Icon, type IconName } from "./Icon";
|
||||
import { AwakenBadge } from "./status";
|
||||
|
||||
const MODE_LABEL: Record<Mode, string> = {
|
||||
chat: "对话", code: "代码", home: "家居", work: "工作", docs: "知识库",
|
||||
@@ -56,6 +57,8 @@ export function TopBar(): React.ReactNode {
|
||||
|
||||
{mood ? <Tag tone="accent">心情 · {mood}</Tag> : null}
|
||||
|
||||
<AwakenBadge />
|
||||
|
||||
<Tag tone={meta.tone}>
|
||||
<span className={`inline-block h-1.5 w-1.5 rounded-full ${wsStatus === "connected" ? "bg-[var(--mu-ok)]" : "mu-blink"}`} />
|
||||
{meta.label}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useState } from "react";
|
||||
import type { ChatMessage, Mode, ToolUsed } from "../lib/types";
|
||||
import { Tag } from "./primitives";
|
||||
import { Icon, type IconName } from "./Icon";
|
||||
import { WakePath } from "./status";
|
||||
import { modeBody } from "./messages";
|
||||
|
||||
/** Collapsible inline chain-of-thought block. */
|
||||
@@ -76,12 +77,18 @@ export function ToolCard({ tool }: { tool: ToolUsed }): React.ReactNode {
|
||||
* message's own `mode`: the same role renders differently under different modes,
|
||||
* and a single session may mix shapes. Falls back to `chat` when mode is absent
|
||||
* (legacy persisted messages). */
|
||||
export function MessageBubble({ message }: { message: ChatMessage }): React.ReactNode {
|
||||
export function MessageBubble({
|
||||
message,
|
||||
active = false,
|
||||
}: {
|
||||
message: ChatMessage;
|
||||
active?: boolean;
|
||||
}): React.ReactNode {
|
||||
const mode = message.mode ?? "chat";
|
||||
if (message.role === "user") {
|
||||
return <UserBubble message={message} mode={mode} />;
|
||||
}
|
||||
return <AssistantBubble message={message} mode={mode} />;
|
||||
return <AssistantBubble message={message} mode={mode} active={active} />;
|
||||
}
|
||||
|
||||
/** User-side bubble. The outer accent pill is shared; the inner content may be
|
||||
@@ -111,7 +118,15 @@ function UserBubble({ message, mode }: { message: ChatMessage; mode: Mode }): Re
|
||||
|
||||
/** Assistant-side bubble. Outer layout shared; the body renders per mode via the
|
||||
* mode-specific body (chat / code / docs / home / work / vision …). */
|
||||
function AssistantBubble({ message, mode }: { message: ChatMessage; mode: Mode }): React.ReactNode {
|
||||
function AssistantBubble({
|
||||
message,
|
||||
mode,
|
||||
active = false,
|
||||
}: {
|
||||
message: ChatMessage;
|
||||
mode: Mode;
|
||||
active?: boolean;
|
||||
}): React.ReactNode {
|
||||
return (
|
||||
<div className="mu-rise-in flex gap-3">
|
||||
<img src="/icon.svg" alt="" className="mt-1 h-7 w-7 shrink-0" />
|
||||
@@ -120,6 +135,7 @@ function AssistantBubble({ message, mode }: { message: ChatMessage; mode: Mode }
|
||||
{message.mood ? (
|
||||
<div className="mb-1 text-xs text-[var(--mu-text-lo)]">心情 · {message.mood}</div>
|
||||
) : null}
|
||||
<WakePath active={active} />
|
||||
<ThinkingBlock text={message.thinking} streaming={message.streaming} />
|
||||
{message.tools?.map((t, i) => <ToolCard key={i} tool={t} />)}
|
||||
{modeBody(mode, message)}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useAppStore } from "../store/useAppStore";
|
||||
import { Tag, type TagTone } from "./primitives";
|
||||
import { Icon, type IconName } from "./Icon";
|
||||
import type { AwakenState } from "../lib/types";
|
||||
|
||||
/**
|
||||
* Miuix 风格的状态呈现组件(用户端):唤醒式能力三态 + 会话编排 busy/pending。
|
||||
* 全部从 useAppStore 的实时状态派生,纯展示、无副作用;未收到对应 WS 事件时
|
||||
* 保持默认值(静息 / 不忙),UI 不报错。design/14 §5 + 15 §5 + 07 §3.
|
||||
*/
|
||||
|
||||
/** 三态排序权重:静息 → 唤醒 → 全能(用于判断「唤醒上升」)。 */
|
||||
const AWAKEN_RANK: Record<AwakenState, number> = { quiet: 0, awake: 1, full: 2 };
|
||||
const AWAKEN_ORDER: AwakenState[] = ["quiet", "awake", "full"];
|
||||
|
||||
const AWAKEN_META: Record<
|
||||
AwakenState,
|
||||
{ label: string; icon: IconName; tone: TagTone; desc: string }
|
||||
> = {
|
||||
quiet: { label: "静息", icon: "moon", tone: "neutral", desc: "温柔陪伴" },
|
||||
awake: { label: "唤醒", icon: "light", tone: "warn", desc: "办事中" },
|
||||
full: { label: "全能", icon: "gear", tone: "accent", desc: "复杂任务" },
|
||||
};
|
||||
|
||||
/** 顶部/状态栏的轻量状态徽标:显示当前唤醒态 + 最近点亮工具;唤醒上升时短暂脉动。 */
|
||||
export function AwakenBadge(): React.ReactNode {
|
||||
const state = useAppStore((s) => s.awakenState);
|
||||
const from = useAppStore((s) => s.awakenFrom);
|
||||
const tool = useAppStore((s) => s.awakenTool);
|
||||
const [pulse, setPulse] = useState(false);
|
||||
const prevRef = useRef<AwakenState>(state);
|
||||
|
||||
// 唤醒上升(从较低态升到较高态)时短暂发光一下,提示「她认真起来了」。
|
||||
useEffect(() => {
|
||||
const prev = prevRef.current;
|
||||
if (from !== null && AWAKEN_RANK[state] > AWAKEN_RANK[prev]) {
|
||||
setPulse(true);
|
||||
const t = window.setTimeout(() => setPulse(false), 1200);
|
||||
prevRef.current = state;
|
||||
return () => window.clearTimeout(t);
|
||||
}
|
||||
prevRef.current = state;
|
||||
}, [state, from]);
|
||||
|
||||
const meta = AWAKEN_META[state];
|
||||
return (
|
||||
<Tag tone={meta.tone} className={pulse ? "mu-awaken" : ""}>
|
||||
<Icon name={meta.icon} size={12} />
|
||||
{meta.label}
|
||||
{tool ? <span className="text-[var(--mu-text-lo)]">· {tool}</span> : null}
|
||||
</Tag>
|
||||
);
|
||||
}
|
||||
|
||||
/** 聊天流里的「唤醒路径」节点序列(思维导图轻量版):静息 → 唤醒 → 全能,点亮到当前态;
|
||||
* 本轮点亮的工具以 ok 标签展示。仅在活跃(正在流式)消息气泡上渲染。 */
|
||||
export function WakePath({
|
||||
active = false,
|
||||
}: {
|
||||
active?: boolean;
|
||||
}): React.ReactNode | null {
|
||||
const state = useAppStore((s) => s.awakenState);
|
||||
const from = useAppStore((s) => s.awakenFrom);
|
||||
const tool = useAppStore((s) => s.awakenTool);
|
||||
if (!active) return null;
|
||||
|
||||
const currentIdx = AWAKEN_RANK[state];
|
||||
const ascended = from !== null && AWAKEN_RANK[state] > AWAKEN_RANK[from];
|
||||
|
||||
return (
|
||||
<div className="mb-2 flex flex-wrap items-center gap-2 rounded-[var(--mu-radius-sm)] border border-[var(--mu-glass-border)] bg-[var(--mu-surface-2)]/60 px-3 py-1.5">
|
||||
<span className="text-xs text-[var(--mu-text-lo)]">唤醒路径</span>
|
||||
<div className="flex flex-wrap items-center gap-1">
|
||||
{AWAKEN_ORDER.map((key, i) => {
|
||||
const on = AWAKEN_RANK[key] <= currentIdx;
|
||||
const isCurrent = key === state;
|
||||
return (
|
||||
<span key={key} className="flex items-center gap-1">
|
||||
{i > 0 ? (
|
||||
<Icon
|
||||
name="arrow"
|
||||
size={10}
|
||||
className={on ? "text-[var(--mu-text-mid)]" : "text-[var(--mu-text-disabled)]"}
|
||||
/>
|
||||
) : null}
|
||||
<Tag
|
||||
tone={on && isCurrent ? AWAKEN_META[key].tone : "neutral"}
|
||||
className={`${on ? "" : "opacity-60"} ${on && isCurrent && ascended ? "mu-awaken" : ""}`}
|
||||
>
|
||||
<Icon name={AWAKEN_META[key].icon} size={11} />
|
||||
{AWAKEN_META[key].label}
|
||||
</Tag>
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{ascended ? (
|
||||
<span className="text-xs text-[var(--mu-accent-hi)]">她认真起来了</span>
|
||||
) : null}
|
||||
{tool ? (
|
||||
<Tag tone="ok">
|
||||
<Icon name="check" size={11} />
|
||||
点亮 · {tool}
|
||||
</Tag>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 会话编排 busy/pending 轻状态提醒(design/15 §5)。她忙时显示在聊天区顶部;
|
||||
* **不阻塞输入框**(输入框可继续打字),挂起消息数可见。 */
|
||||
export function SessionStatusHint(): React.ReactNode | null {
|
||||
const busy = useAppStore((s) => s.sessionBusy);
|
||||
const pendingCount = useAppStore((s) => s.pendingCount);
|
||||
if (!busy) return null;
|
||||
|
||||
return (
|
||||
<div className="mu-rise-in flex items-center gap-2 rounded-[var(--mu-radius)] border border-[var(--mu-glass-border)] bg-[var(--mu-surface-2)]/70 px-3 py-2 text-xs text-[var(--mu-text-lo)]">
|
||||
<Icon name="clock" size={14} className="shrink-0 text-[var(--mu-warn)]" />
|
||||
<span className="min-w-0 truncate">她正在忙,有新消息稍后回</span>
|
||||
{pendingCount > 0 ? <Tag tone="warn">{pendingCount} 条待回</Tag> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user