- 新增 V1 记忆系统(memory.json)支持:提取结果强制中文、历史字段修复为增量累积日志 - 用户设置页面:V1 模式下新增 agent 选择器,可查看各 agent 的私有记忆 - 管理员记忆页面:区分 V1/V2 渲染,V1 支持完整 CRUD(用户画像/历史摘要/事实记录) - 后端新增 V1 记忆 CRUD API(sections/facts),前端同步添加对应 hooks 和 API 调用 - 新建专家页面:标记 bootstrap 线程类型,跳过记忆保存,侧边栏过滤该类线程 - 输入框工具栏新增「记忆」开关:关闭时 V1/V2 均不注入,开启时按 config.yaml 版本正常注入 - 修复 agent 目录不存在时的 FileNotFoundError,回退至默认配置 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
140 lines
4.0 KiB
TypeScript
140 lines
4.0 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
|
|
import {
|
|
addAdminMemoryEntry,
|
|
addAdminV1Fact,
|
|
deleteAdminMemoryEntry,
|
|
deleteAdminV1Fact,
|
|
getUserMemory,
|
|
listUserThreadMessages,
|
|
listUserThreads,
|
|
replaceAdminMemoryEntry,
|
|
updateAdminV1Fact,
|
|
updateAdminV1Section,
|
|
} from "./api";
|
|
|
|
/** Threads owned by a given user. Disabled until a user is picked. */
|
|
export function useUserThreads(userId: string | null) {
|
|
return useQuery({
|
|
queryKey: ["admin-activity", "threads", userId],
|
|
queryFn: () => listUserThreads(userId!),
|
|
enabled: !!userId,
|
|
});
|
|
}
|
|
|
|
/** Messages of a given thread. Disabled until a thread is picked. */
|
|
export function useUserThreadMessages(
|
|
userId: string | null,
|
|
threadId: string | null,
|
|
) {
|
|
return useQuery({
|
|
queryKey: ["admin-activity", "messages", userId, threadId],
|
|
queryFn: () => listUserThreadMessages(userId!, threadId!),
|
|
enabled: !!userId && !!threadId,
|
|
});
|
|
}
|
|
|
|
/** All memory buckets of a given user. Disabled until a user is picked. */
|
|
export function useUserMemory(userId: string | null) {
|
|
return useQuery({
|
|
queryKey: ["admin-activity", "memory", userId],
|
|
queryFn: () => getUserMemory(userId!),
|
|
enabled: !!userId,
|
|
});
|
|
}
|
|
|
|
function useMemoryInvalidate(userId: string) {
|
|
const qc = useQueryClient();
|
|
return () => qc.invalidateQueries({ queryKey: ["admin-activity", "memory", userId] });
|
|
}
|
|
|
|
export function useAdminAddMemoryEntry(userId: string) {
|
|
const invalidate = useMemoryInvalidate(userId);
|
|
return useMutation({
|
|
mutationFn: ({ content, agent }: { content: string; agent: string | null }) =>
|
|
addAdminMemoryEntry(userId, content, agent),
|
|
onSuccess: invalidate,
|
|
});
|
|
}
|
|
|
|
export function useAdminReplaceMemoryEntry(userId: string) {
|
|
const invalidate = useMemoryInvalidate(userId);
|
|
return useMutation({
|
|
mutationFn: ({ oldText, content, agent }: { oldText: string; content: string; agent: string | null }) =>
|
|
replaceAdminMemoryEntry(userId, oldText, content, agent),
|
|
onSuccess: invalidate,
|
|
});
|
|
}
|
|
|
|
export function useAdminDeleteMemoryEntry(userId: string) {
|
|
const invalidate = useMemoryInvalidate(userId);
|
|
return useMutation({
|
|
mutationFn: ({ oldText, agent }: { oldText: string; agent: string | null }) =>
|
|
deleteAdminMemoryEntry(userId, oldText, agent),
|
|
onSuccess: invalidate,
|
|
});
|
|
}
|
|
|
|
// ── V1 CRUD hooks ──────────────────────────────────────────────────────────
|
|
|
|
export function useAdminUpdateV1Section(userId: string) {
|
|
const invalidate = useMemoryInvalidate(userId);
|
|
return useMutation({
|
|
mutationFn: ({
|
|
sectionType,
|
|
field,
|
|
summary,
|
|
agent,
|
|
}: {
|
|
sectionType: "user" | "history";
|
|
field: string;
|
|
summary: string;
|
|
agent: string | null;
|
|
}) => updateAdminV1Section(userId, sectionType, field, summary, agent),
|
|
onSuccess: invalidate,
|
|
});
|
|
}
|
|
|
|
export function useAdminAddV1Fact(userId: string) {
|
|
const invalidate = useMemoryInvalidate(userId);
|
|
return useMutation({
|
|
mutationFn: ({
|
|
content,
|
|
category,
|
|
confidence,
|
|
agent,
|
|
}: {
|
|
content: string;
|
|
category: string;
|
|
confidence: number;
|
|
agent: string | null;
|
|
}) => addAdminV1Fact(userId, content, category, confidence, agent),
|
|
onSuccess: invalidate,
|
|
});
|
|
}
|
|
|
|
export function useAdminUpdateV1Fact(userId: string) {
|
|
const invalidate = useMemoryInvalidate(userId);
|
|
return useMutation({
|
|
mutationFn: ({
|
|
factId,
|
|
updates,
|
|
agent,
|
|
}: {
|
|
factId: string;
|
|
updates: { content?: string; category?: string; confidence?: number };
|
|
agent: string | null;
|
|
}) => updateAdminV1Fact(userId, factId, updates, agent),
|
|
onSuccess: invalidate,
|
|
});
|
|
}
|
|
|
|
export function useAdminDeleteV1Fact(userId: string) {
|
|
const invalidate = useMemoryInvalidate(userId);
|
|
return useMutation({
|
|
mutationFn: ({ factId, agent }: { factId: string; agent: string | null }) =>
|
|
deleteAdminV1Fact(userId, factId, agent),
|
|
onSuccess: invalidate,
|
|
});
|
|
}
|