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
@@ -3,6 +3,7 @@ import type {
|
||||
AdminChannelRecord,
|
||||
AdminIoTDevice,
|
||||
AdminLlmConfig,
|
||||
AdminLlmProvider,
|
||||
AdminObservabilityMetrics,
|
||||
AdminPluginRecord,
|
||||
AdminRagHit,
|
||||
@@ -10,12 +11,21 @@ import type {
|
||||
AdminTraceSpan,
|
||||
AdminUserRecord,
|
||||
ApiErrorShape,
|
||||
ApiKeyIssueResult,
|
||||
AuditRecord,
|
||||
AutomationCreateResult,
|
||||
AutomationRunResult,
|
||||
ChannelTestResult,
|
||||
ChatSyncResult,
|
||||
LlmTestRequest,
|
||||
LlmTestResult,
|
||||
LoginResult,
|
||||
MemoryRecord,
|
||||
MemorySearchRequest,
|
||||
MemorySearchResult,
|
||||
Mode,
|
||||
PersonaRecord,
|
||||
PersonaUpsertRequest,
|
||||
Role,
|
||||
SessionRecord,
|
||||
} from "./types";
|
||||
@@ -273,6 +283,137 @@ export function adminDeleteRag(id: string): Promise<{ id: string }> {
|
||||
});
|
||||
}
|
||||
|
||||
/* --- Admin write endpoints (owner-only, audited; real store or honest 501). --- */
|
||||
|
||||
/** POST /api/v1/admin/personas — registers a persona (persisted to YAML + registry). */
|
||||
export function adminCreatePersona(req: PersonaUpsertRequest): Promise<PersonaRecord> {
|
||||
return request<PersonaRecord>("/admin/personas", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(req),
|
||||
});
|
||||
}
|
||||
/** PUT /api/v1/admin/personas/{id} — edits an existing persona. */
|
||||
export function adminUpdatePersona(id: string, req: PersonaUpsertRequest): Promise<PersonaRecord> {
|
||||
return request<PersonaRecord>(`/admin/personas/${encodeURIComponent(id)}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(req),
|
||||
});
|
||||
}
|
||||
/** POST /api/v1/admin/users — add user/role. No persistent user store yet, so the
|
||||
* backend answers honestly with a 501 ("M10"). */
|
||||
export function adminCreateUser(req: { username: string; role: string }): Promise<AdminUserRecord> {
|
||||
return request<AdminUserRecord>("/admin/users", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(req),
|
||||
});
|
||||
}
|
||||
/** POST /api/v1/admin/users/apikey — mints a key; the plaintext comes back once. */
|
||||
export function adminIssueApiKey(role: string): Promise<ApiKeyIssueResult> {
|
||||
return request<ApiKeyIssueResult>("/admin/users/apikey", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ role }),
|
||||
});
|
||||
}
|
||||
/** DELETE /api/v1/admin/users/apikey/{id} — revokes a key by masked id. */
|
||||
export function adminRevokeApiKey(id: string): Promise<{ id: string; revoked: boolean }> {
|
||||
return request<{ id: string; revoked: boolean }>(`/admin/users/apikey/${encodeURIComponent(id)}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
/** POST /api/v1/admin/iot/{id}/control — sends a control instruction to a device. */
|
||||
export function adminIoTControl(id: string, action: string, params?: Record<string, unknown>): Promise<AdminIoTDevice> {
|
||||
return request<AdminIoTDevice>(`/admin/iot/${encodeURIComponent(id)}/control`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ action, params }),
|
||||
});
|
||||
}
|
||||
/** POST /api/v1/admin/iot/scenarios — honest 501 (no scenario store yet). */
|
||||
export function adminIoTScenario(req: { name: string }): Promise<{ name: string }> {
|
||||
return request<{ name: string }>("/admin/iot/scenarios", { method: "POST", body: JSON.stringify(req) });
|
||||
}
|
||||
/** POST /api/v1/admin/iot/rules — honest 501 (no IoT rule store yet). */
|
||||
export function adminIoTRule(req: { name: string; expression: string }): Promise<{ name: string }> {
|
||||
return request<{ name: string }>("/admin/iot/rules", { method: "POST", body: JSON.stringify(req) });
|
||||
}
|
||||
/** POST /api/v1/admin/automations — registers a real cron/event automation. */
|
||||
export function adminCreateAutomation(req: {
|
||||
name: string;
|
||||
kind: string;
|
||||
expression: string;
|
||||
}): Promise<AutomationCreateResult> {
|
||||
return request<AutomationCreateResult>("/admin/automations", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(req),
|
||||
});
|
||||
}
|
||||
/** POST /api/v1/admin/automations/{id}/run — manually triggers a rule. */
|
||||
export function adminRunAutomation(id: string): Promise<AutomationRunResult> {
|
||||
return request<AutomationRunResult>(`/admin/automations/${encodeURIComponent(id)}/run`, { method: "POST" });
|
||||
}
|
||||
/** DELETE /api/v1/admin/automations/{id} — removes a rule (cron or event). */
|
||||
export function adminDeleteAutomation(id: string): Promise<{ id: string; deleted: boolean }> {
|
||||
return request<{ id: string; deleted: boolean }>(`/admin/automations/${encodeURIComponent(id)}`, { method: "DELETE" });
|
||||
}
|
||||
/** POST /api/v1/admin/llm — records a provider for the process lifetime (temporary). */
|
||||
export function adminAddLlmProvider(req: {
|
||||
id?: string;
|
||||
name: string;
|
||||
baseUrl?: string;
|
||||
model: string;
|
||||
multimodal?: boolean;
|
||||
fallback?: string;
|
||||
}): Promise<{ provider: AdminLlmProvider; temporary: boolean }> {
|
||||
return request<{ provider: AdminLlmProvider; temporary: boolean }>("/admin/llm", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(req),
|
||||
});
|
||||
}
|
||||
/** POST /api/v1/admin/llm/test — performs a real model call and reports the result. */
|
||||
export function adminTestLlm(req: LlmTestRequest): Promise<LlmTestResult> {
|
||||
return request<LlmTestResult>("/admin/llm/test", { method: "POST", body: JSON.stringify(req) });
|
||||
}
|
||||
/** POST /api/v1/admin/channels/open — connects a registered channel adapter. */
|
||||
export function adminChannelOpen(name: string): Promise<{ name: string; connected: boolean }> {
|
||||
return request<{ name: string; connected: boolean }>("/admin/channels/open", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ name }),
|
||||
});
|
||||
}
|
||||
/** POST /api/v1/admin/channels/close — disconnects a registered channel adapter. */
|
||||
export function adminChannelClose(name: string): Promise<{ name: string; connected: boolean }> {
|
||||
return request<{ name: string; connected: boolean }>("/admin/channels/close", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ name }),
|
||||
});
|
||||
}
|
||||
/** POST /api/v1/admin/channels/test — structural identity test (actor × whitelist). */
|
||||
export function adminChannelTest(req: {
|
||||
platform: string;
|
||||
accountId: string;
|
||||
isGroup: boolean;
|
||||
}): Promise<ChannelTestResult> {
|
||||
return request<ChannelTestResult>("/admin/channels/test", { method: "POST", body: JSON.stringify(req) });
|
||||
}
|
||||
/** POST /api/v1/admin/plugins/install — honest 501 (needs a plugin source). */
|
||||
export function adminPluginInstall(req: { name: string; kind: string; description: string }): Promise<AdminPluginRecord> {
|
||||
return request<AdminPluginRecord>("/admin/plugins/install", { method: "POST", body: JSON.stringify(req) });
|
||||
}
|
||||
/** POST /api/v1/admin/plugins/uninstall — removes a capability from the registry. */
|
||||
export function adminPluginUninstall(req: { name: string }): Promise<{ name: string; uninstalled: boolean }> {
|
||||
return request<{ name: string; uninstalled: boolean }>("/admin/plugins/uninstall", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(req),
|
||||
});
|
||||
}
|
||||
/** POST /api/v1/admin/memories/search — real retrieval over the memory store. */
|
||||
export function adminMemorySearch(req: MemorySearchRequest): Promise<MemorySearchResult> {
|
||||
return request<MemorySearchResult>("/admin/memories/search", { method: "POST", body: JSON.stringify(req) });
|
||||
}
|
||||
/** GET /api/v1/admin/sessions/{id}/export — exports a session as JSON. */
|
||||
export function adminExportSession(id: string): Promise<{ session: SessionRecord }> {
|
||||
return request<{ session: SessionRecord }>(`/admin/sessions/${encodeURIComponent(id)}/export`);
|
||||
}
|
||||
|
||||
/** GET /api/v1/admin/observability/metrics — gateway request metrics. */
|
||||
export function adminObservabilityMetrics(): Promise<AdminObservabilityMetrics> {
|
||||
return request<AdminObservabilityMetrics>("/admin/observability/metrics");
|
||||
|
||||
@@ -40,6 +40,23 @@ export interface ToolUsed {
|
||||
at: number;
|
||||
}
|
||||
|
||||
/** 唤醒式能力三态(design/14 §1):静息·温柔陪伴 / 唤醒·办事 / 全能·复杂任务。 */
|
||||
export type AwakenState = "quiet" | "awake" | "full";
|
||||
|
||||
/** capacity_awaken 下行事件 payload(design/14 §5):状态切换 + 本轮点亮的工具。
|
||||
* `tool` 可能是工具名字符串,也可能是含 `name` 的对象,解析层统一为字符串。 */
|
||||
export interface AwakenPayload {
|
||||
fromState?: AwakenState;
|
||||
toState?: AwakenState;
|
||||
tool?: string | { name: string };
|
||||
}
|
||||
|
||||
/** session_busy / session_pending 下行事件 payload(design/15 §5):她是否在忙 + 挂起消息数。 */
|
||||
export interface SessionStatePayload {
|
||||
busy?: boolean;
|
||||
pendingCount?: number;
|
||||
}
|
||||
|
||||
export interface ChatMessage {
|
||||
id: string;
|
||||
role: "user" | "assistant" | "system";
|
||||
@@ -153,7 +170,8 @@ export interface ChatSyncResult {
|
||||
* thinking.start/delta/end, tool_call.start/delta/end, tool_execution.update
|
||||
* (design/04 §1.1), plus the legacy stream_chunk / stream_end / thinking / mood /
|
||||
* tool_used / subagent_event / graph_update / reminder / device_update / auth /
|
||||
* error / task_output.
|
||||
* error / task_output, and the capacity/session events from design/14 §5 + 15 §5:
|
||||
* capacity_awaken (状态切换+点亮工具), session_busy / session_pending (她是否在忙+挂起消息数).
|
||||
*/
|
||||
export interface WsDownEvent {
|
||||
type: string;
|
||||
@@ -333,3 +351,112 @@ export interface OwnerAccount {
|
||||
platform: string;
|
||||
accountId: string;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
* Admin write payloads / results (POST/PUT/DELETE /api/v1/admin/*).
|
||||
* The backend persists to a real store or answers honestly with a 501 / clear
|
||||
* error — never a fabricated success.
|
||||
* -------------------------------------------------------------------------*/
|
||||
|
||||
/** POST/PUT /api/v1/admin/personas body. id required on create, path on update. */
|
||||
export interface PersonaUpsertRequest {
|
||||
id?: string;
|
||||
name: string;
|
||||
characterRef?: string;
|
||||
role: string;
|
||||
systemPrompt?: string;
|
||||
personality?: string;
|
||||
speechStyle?: string;
|
||||
catchphrase?: string;
|
||||
background?: string;
|
||||
values?: string[];
|
||||
modes?: string[];
|
||||
mode?: string;
|
||||
memoryNamespace?: string;
|
||||
}
|
||||
|
||||
/** POST /api/v1/admin/users/apikey — the plaintext key is returned exactly once. */
|
||||
export interface ApiKeyIssueResult {
|
||||
id: string;
|
||||
key: string;
|
||||
role: string;
|
||||
}
|
||||
|
||||
/** POST /api/v1/admin/automations result. */
|
||||
export interface AutomationCreateResult {
|
||||
id: string;
|
||||
name: string;
|
||||
kind: string;
|
||||
}
|
||||
|
||||
/** POST /api/v1/admin/automations/{id}/run result. */
|
||||
export interface AutomationRunResult {
|
||||
id: string;
|
||||
output: unknown;
|
||||
}
|
||||
|
||||
/** POST /api/v1/admin/llm body. */
|
||||
export interface LlmProviderRequest {
|
||||
id?: string;
|
||||
name: string;
|
||||
baseUrl?: string;
|
||||
model: string;
|
||||
multimodal?: boolean;
|
||||
fallback?: string;
|
||||
}
|
||||
|
||||
/** POST /api/v1/admin/llm/test body. */
|
||||
export interface LlmTestRequest {
|
||||
provider?: string;
|
||||
baseUrl: string;
|
||||
apiKey?: string;
|
||||
model: string;
|
||||
prompt?: string;
|
||||
}
|
||||
|
||||
/** POST /api/v1/admin/llm/test result. */
|
||||
export interface LlmTestResult {
|
||||
ok: boolean;
|
||||
provider: string;
|
||||
model: string;
|
||||
reply: string;
|
||||
tokens: number;
|
||||
}
|
||||
|
||||
/** POST /api/v1/admin/channels/test result (structural identity verdict). */
|
||||
export interface ChannelTestResult {
|
||||
role: string;
|
||||
owner: boolean;
|
||||
isGroup: boolean;
|
||||
env: string;
|
||||
verdict: string;
|
||||
}
|
||||
|
||||
/** POST /api/v1/admin/iot/{id}/control body (params keys depend on device type). */
|
||||
export interface IoTControlRequest {
|
||||
action: string;
|
||||
params?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/** POST /api/v1/admin/memories/search body. */
|
||||
export interface MemorySearchRequest {
|
||||
query: string;
|
||||
personaId?: string;
|
||||
topK?: number;
|
||||
}
|
||||
|
||||
/** One memory retrieval hit. */
|
||||
export interface MemorySearchHit {
|
||||
id: string;
|
||||
scope: string;
|
||||
text: string;
|
||||
score: number;
|
||||
}
|
||||
|
||||
/** POST /api/v1/admin/memories/search result. */
|
||||
export interface MemorySearchResult {
|
||||
query: string;
|
||||
personaId: string;
|
||||
semantic: boolean;
|
||||
hits: MemorySearchHit[];
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useAppStore } from "../store/useAppStore";
|
||||
import { useModeStore } from "../store/useModeStore";
|
||||
import { getAuthToken } from "./api";
|
||||
import { MODES, type AgentInfo, type FlowGraph, type Mode, type ToolUsed, type WsUpEvent } from "./types";
|
||||
import { MODES, type AgentInfo, type AwakenState, type FlowGraph, type Mode, type ToolUsed, type WsUpEvent } from "./types";
|
||||
import { now, uid } from "./util";
|
||||
|
||||
/**
|
||||
@@ -78,6 +78,15 @@ function parseTool(v: unknown): ToolUsed | null {
|
||||
};
|
||||
}
|
||||
|
||||
/** Normalize a capacity_awaken `tool` field into a tool-name string. The backend
|
||||
* may send a bare name or a `{name}` object; both reduce to the name. */
|
||||
function parseAwakenTool(v: unknown): string | undefined {
|
||||
if (typeof v === "string") return v || undefined;
|
||||
const r = toRecord(v);
|
||||
if (r && typeof r.name === "string" && r.name) return r.name;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Build a tool card from a tool_call.* payload. Unlike the legacy tool_used
|
||||
* frame these carry `id` (provider block id) rather than a guaranteed `name`,
|
||||
* so we label the card by id when no name is present. */
|
||||
@@ -158,6 +167,10 @@ function dispatch(ev: { type: string; data: unknown }): void {
|
||||
}
|
||||
case "stream_end": {
|
||||
s.endStream();
|
||||
// The assistant reply stopped streaming, so the immediate turn is over:
|
||||
// close the busy/pending window so the badge does not stick. If the backend
|
||||
// keeps a task/subagent running it re-emits session_busy (design/15 §5).
|
||||
s.setSessionBusy(false, 0);
|
||||
if (r && typeof r.stopReason === "string") {
|
||||
s.setContext({ lastAgentMode: s.context.lastAgentMode });
|
||||
}
|
||||
@@ -293,6 +306,27 @@ function dispatch(ev: { type: string; data: unknown }): void {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "capacity_awaken": {
|
||||
// design/14 §5 — 能力点亮:静息 → 唤醒 → 全能 + 本轮点亮工具。前端据此更新唤醒徽标/唤醒路径。
|
||||
const fromState =
|
||||
typeof r?.fromState === "string"
|
||||
? (r.fromState as AwakenState)
|
||||
: undefined;
|
||||
const toState =
|
||||
(typeof r?.toState === "string" ? (r.toState as AwakenState) : undefined) ??
|
||||
"quiet";
|
||||
s.setAwaken(fromState, toState, parseAwakenTool(r?.tool));
|
||||
break;
|
||||
}
|
||||
case "session_busy":
|
||||
case "session_pending": {
|
||||
// design/15 §5 — 她忙/有挂起消息时的轻状态(不阻塞输入框)。两者同构:都是 {busy, pendingCount}。
|
||||
const busy = typeof r?.busy === "boolean" ? r.busy : true;
|
||||
const pendingCount =
|
||||
typeof r?.pendingCount === "number" ? r.pendingCount : s.pendingCount;
|
||||
s.setSessionBusy(busy, pendingCount);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// Unknown future event: keep it in the context log so no frame is lost.
|
||||
const text = typeof ev.data === "string" ? ev.data : JSON.stringify(ev.data);
|
||||
|
||||
Reference in new issue
Block a user