- 创建智能体页面:保存后自动跳转列表页、技能列表增加搜索过滤框 - Bootstrap 模式:开放全部技能可见性,注入专属提示词(skill_list 匹配意图、禁止 skill_manage) - 管理员记忆页面:新增 AdminMemoryPage 及路由,支持查看/编辑用户记忆条目 - 内存配置与管理员用户接口同步更新 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
121 lines
3.2 KiB
TypeScript
121 lines
3.2 KiB
TypeScript
import { apiFetch } from "@/core/api";
|
|
import { getBackendBaseURL } from "@/core/config";
|
|
|
|
/** A conversation thread owned by some user (admin view). */
|
|
export interface AdminThread {
|
|
thread_id: string;
|
|
display_name: string;
|
|
status: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
}
|
|
|
|
/**
|
|
* One conversation message, as serialized from the LangGraph checkpoint —
|
|
* a LangChain message dump: ``type`` is "human" | "ai" | "tool" | "system",
|
|
* ``content`` is a string or a content-block list.
|
|
*/
|
|
export interface AdminMessage {
|
|
type?: string;
|
|
content?: unknown;
|
|
id?: string | null;
|
|
name?: string | null;
|
|
}
|
|
|
|
/** One memory bucket: the global file or a per-agent file. */
|
|
export interface AdminMemoryBucket {
|
|
name: string;
|
|
display_name?: string;
|
|
data: Record<string, unknown>;
|
|
}
|
|
|
|
export interface AdminMemoryResponse {
|
|
user_id: string;
|
|
buckets: AdminMemoryBucket[];
|
|
}
|
|
|
|
const base = () => `${getBackendBaseURL()}/api/admin/users`;
|
|
|
|
async function parse<T>(res: Response, what: string): Promise<T> {
|
|
if (!res.ok) {
|
|
const err = (await res.json().catch(() => ({}))) as { detail?: string };
|
|
throw new Error(err.detail ?? `${what} (HTTP ${res.status})`);
|
|
}
|
|
return res.json() as Promise<T>;
|
|
}
|
|
|
|
export async function listUserThreads(userId: string): Promise<AdminThread[]> {
|
|
return parse(
|
|
await apiFetch(`${base()}/${encodeURIComponent(userId)}/threads?limit=200`),
|
|
"Failed to load threads",
|
|
);
|
|
}
|
|
|
|
export async function listUserThreadMessages(
|
|
userId: string,
|
|
threadId: string,
|
|
): Promise<AdminMessage[]> {
|
|
return parse(
|
|
await apiFetch(
|
|
`${base()}/${encodeURIComponent(userId)}/threads/${encodeURIComponent(threadId)}/messages`,
|
|
),
|
|
"Failed to load messages",
|
|
);
|
|
}
|
|
|
|
export async function getUserMemory(
|
|
userId: string,
|
|
): Promise<AdminMemoryResponse> {
|
|
return parse(
|
|
await apiFetch(`${base()}/${encodeURIComponent(userId)}/memory`),
|
|
"Failed to load memory",
|
|
);
|
|
}
|
|
|
|
export async function addAdminMemoryEntry(
|
|
userId: string,
|
|
content: string,
|
|
agent: string | null,
|
|
): Promise<AdminMemoryBucket> {
|
|
return parse(
|
|
await apiFetch(`${base()}/${encodeURIComponent(userId)}/memory/entries`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ content, agent }),
|
|
}),
|
|
"Failed to add memory entry",
|
|
);
|
|
}
|
|
|
|
export async function replaceAdminMemoryEntry(
|
|
userId: string,
|
|
oldText: string,
|
|
content: string,
|
|
agent: string | null,
|
|
): Promise<AdminMemoryBucket> {
|
|
return parse(
|
|
await apiFetch(`${base()}/${encodeURIComponent(userId)}/memory/entries`, {
|
|
method: "PUT",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ old_text: oldText, content, agent }),
|
|
}),
|
|
"Failed to replace memory entry",
|
|
);
|
|
}
|
|
|
|
export async function deleteAdminMemoryEntry(
|
|
userId: string,
|
|
oldText: string,
|
|
agent: string | null,
|
|
): Promise<AdminMemoryBucket> {
|
|
const params = new URLSearchParams({ old_text: oldText });
|
|
if (agent) params.set("agent", agent);
|
|
return parse(
|
|
await apiFetch(
|
|
`${base()}/${encodeURIComponent(userId)}/memory/entries?${params}`,
|
|
{ method: "DELETE" },
|
|
),
|
|
"Failed to delete memory entry",
|
|
);
|
|
}
|