feat(y-log): 操作日志上报(前端直连 + 后端公开只读下发地址)

- 后端新增 y_log 公开只读配置:YLogConfig + AppConfig.y_log +
  GET /api/public/config/y-log,地址写在 config.yaml(mtime 热重载)
- 前端核心 src/core/log/:writeYLog(双门控/异步即发即忘/永不抛错/
  去ip-host/对象序列化裁剪/optResult恒0)+ 配置加载 + token1 隔离存取
- 登录(token)持久化 token1 并报登录、登出先报后清;启动预热配置
- 各 API client 成功路径埋点:敏感词/菜单/按钮/技能地址/轻应用、
  会商草稿+任务草稿+后台任务、智能体/定时任务/知识库、Word导出,
  以及问答完成钩子(ChatPage/AgentChatPage onFinish)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
AdministratorandClaude Opus 4.8 committed 2026-06-23 17:46:08 +08:00
1 parent dd942cdd60
commit d2be3b206d
26 files changed
+808 -40

No files matched your search

+127 -8
View File
@@ -1,5 +1,6 @@
import { getBackendBaseURL } from "@/core/config";
import { apiFetch } from "@/core/api";
import { OptType, writeYLog } from "@/core/log/y-log";
import type {
Agent,
@@ -58,6 +59,13 @@ export async function listAgents(params: ListAgentsParams = {}): Promise<Agent[]
);
if (!res.ok) throw new Error(`Failed to load agents: ${res.statusText}`);
const data = (await res.json()) as { agents: Agent[] };
writeYLog({
optType: OptType.search,
optDetail: "B1-CM助手-智能体列表",
url: `/api/agents${query ? `?${query}` : ""}`,
reqParam: params,
returnParam: data.agents,
});
return data.agents;
}
@@ -76,12 +84,20 @@ export async function listAgentsPaginated(
page?: number;
page_size?: number;
};
return {
const result: PaginatedAgents = {
agents: data.agents,
total: data.total ?? data.agents.length,
page: data.page ?? params.page ?? 1,
pageSize: data.page_size ?? params.pageSize ?? data.agents.length,
};
writeYLog({
optType: OptType.search,
optDetail: "B1-CM助手-智能体列表",
url: `/api/agents${query ? `?${query}` : ""}`,
reqParam: params,
returnParam: result,
});
return result;
}
export async function listAllAgentsAdmin(): Promise<Agent[]> {
@@ -91,6 +107,12 @@ export async function listAllAgentsAdmin(): Promise<Agent[]> {
throw new Error(err.detail ?? `Failed to load agents: ${res.statusText}`);
}
const data = (await res.json()) as { agents: Agent[] };
writeYLog({
optType: OptType.search,
optDetail: "B1-CM助手-智能体列表",
url: `/api/agents?admin=true`,
returnParam: data.agents,
});
return data.agents;
}
@@ -110,7 +132,15 @@ export async function createAgent(request: CreateAgentRequest): Promise<Agent> {
const err = (await res.json().catch(() => ({}))) as { detail?: string };
throw new Error(err.detail ?? `Failed to create agent: ${res.statusText}`);
}
return res.json() as Promise<Agent>;
const created = (await res.json()) as Agent;
writeYLog({
optType: OptType.create,
optDetail: "B1-CM助手-智能体-新建",
url: `/api/agents`,
reqParam: request,
returnParam: created,
});
return created;
}
export async function updateAgent(
@@ -126,7 +156,15 @@ export async function updateAgent(
const err = (await res.json().catch(() => ({}))) as { detail?: string };
throw new Error(err.detail ?? `Failed to update agent: ${res.statusText}`);
}
return res.json() as Promise<Agent>;
const updated = (await res.json()) as Agent;
writeYLog({
optType: OptType.edit,
optDetail: "B1-CM助手-智能体-修改",
url: `/api/agents/${id}`,
reqParam: { id, ...request },
returnParam: updated,
});
return updated;
}
export async function deleteAgent(id: string): Promise<void> {
@@ -134,6 +172,12 @@ export async function deleteAgent(id: string): Promise<void> {
method: "DELETE",
});
if (!res.ok) throw new Error(`Failed to delete agent: ${res.statusText}`);
writeYLog({
optType: OptType.delete,
optDetail: "B1-CM助手-智能体-删除",
url: `/api/agents/${id}`,
reqParam: { id },
});
}
export async function getAgentSelector(): Promise<AgentSelectorResponse> {
@@ -150,6 +194,12 @@ export async function favoriteAgent(id: string): Promise<void> {
const err = (await res.json().catch(() => ({}))) as { detail?: string };
throw new Error(err.detail ?? `Failed to favorite agent: ${res.statusText}`);
}
writeYLog({
optType: OptType.edit,
optDetail: "B1-CM助手-智能体-收藏",
url: `/api/agents/${id}/favorite`,
reqParam: { id },
});
}
export async function unfavoriteAgent(id: string): Promise<void> {
@@ -160,6 +210,12 @@ export async function unfavoriteAgent(id: string): Promise<void> {
const err = (await res.json().catch(() => ({}))) as { detail?: string };
throw new Error(err.detail ?? `Failed to unfavorite agent: ${res.statusText}`);
}
writeYLog({
optType: OptType.edit,
optDetail: "B1-CM助手-智能体-取消收藏",
url: `/api/agents/${id}/favorite`,
reqParam: { id },
});
}
export async function pinAgent(id: string): Promise<void> {
@@ -170,6 +226,12 @@ export async function pinAgent(id: string): Promise<void> {
const err = (await res.json().catch(() => ({}))) as { detail?: string };
throw new Error(err.detail ?? `Failed to pin agent: ${res.statusText}`);
}
writeYLog({
optType: OptType.edit,
optDetail: "B1-CM助手-智能体-置顶",
url: `/api/agents/${id}/pin`,
reqParam: { id },
});
}
export async function unpinAgent(id: string): Promise<void> {
@@ -180,6 +242,12 @@ export async function unpinAgent(id: string): Promise<void> {
const err = (await res.json().catch(() => ({}))) as { detail?: string };
throw new Error(err.detail ?? `Failed to unpin agent: ${res.statusText}`);
}
writeYLog({
optType: OptType.edit,
optDetail: "B1-CM助手-智能体-取消置顶",
url: `/api/agents/${id}/pin`,
reqParam: { id },
});
}
export async function reorderFeaturedAgents(agentIds: string[]): Promise<void> {
@@ -197,6 +265,12 @@ export async function reorderFeaturedAgents(agentIds: string[]): Promise<void> {
err.detail ?? `Failed to reorder featured agents: ${res.statusText}`,
);
}
writeYLog({
optType: OptType.edit,
optDetail: "B1-CM助手-智能体-精选排序",
url: `/api/agents/featured/order`,
reqParam: { agent_ids: agentIds },
});
}
export async function listPrivateAgents(password: string): Promise<Agent[]> {
@@ -215,6 +289,12 @@ export async function listPrivateAgents(password: string): Promise<Agent[]> {
);
}
const data = (await res.json()) as { agents: Agent[] };
writeYLog({
optType: OptType.search,
optDetail: "B1-CM助手-私有广场智能体列表",
url: `/api/agents/private-square/list`,
returnParam: data.agents,
});
return data.agents;
}
@@ -261,12 +341,20 @@ export async function listPrivateAgentsPaginated(
page?: number;
page_size?: number;
};
return {
const result: PaginatedAgents = {
agents: data.agents,
total: data.total ?? data.agents.length,
page: data.page ?? params.page ?? 1,
pageSize: data.page_size ?? params.pageSize ?? data.agents.length,
};
writeYLog({
optType: OptType.search,
optDetail: "B1-CM助手-私有广场智能体列表",
url: `/api/agents/private-square/list`,
reqParam: { ...params, password: undefined },
returnParam: result,
});
return result;
}
export async function setAgentPrivate(
@@ -287,7 +375,15 @@ export async function setAgentPrivate(
err.detail ?? `Failed to update agent privacy: ${res.statusText}`,
);
}
return res.json() as Promise<Agent>;
const updated = (await res.json()) as Agent;
writeYLog({
optType: OptType.edit,
optDetail: "B1-CM助手-智能体-设置私有",
url: `/api/agents/${id}/private`,
reqParam: { id, is_private: isPrivate },
returnParam: updated,
});
return updated;
}
export async function setAgentFeatured(
@@ -308,7 +404,15 @@ export async function setAgentFeatured(
err.detail ?? `Failed to set featured: ${res.statusText}`,
);
}
return res.json() as Promise<Agent>;
const updated = (await res.json()) as Agent;
writeYLog({
optType: OptType.edit,
optDetail: "B1-CM助手-智能体-设置精选",
url: `/api/agents/${id}/featured`,
reqParam: { id, order },
returnParam: updated,
});
return updated;
}
export interface AgentSkillsSyncRemoval {
@@ -333,7 +437,14 @@ export async function adminSyncAgentSkills(): Promise<AgentSkillsSyncResult> {
const err = (await res.json().catch(() => ({}))) as { detail?: string };
throw new Error(err.detail ?? `Failed to sync agent skills: ${res.statusText}`);
}
return res.json() as Promise<AgentSkillsSyncResult>;
const result = (await res.json()) as AgentSkillsSyncResult;
writeYLog({
optType: OptType.edit,
optDetail: "B1-CM助手-智能体-同步技能",
url: `/api/agents/admin/sync-skills`,
returnParam: result,
});
return result;
}
export interface KnowledgeIngestAttempt {
@@ -371,7 +482,15 @@ export async function publishArtifactToKnowledge(request: {
const err = (await res.json().catch(() => ({}))) as { detail?: string };
throw new Error(err.detail ?? `发布入库失败: ${res.statusText}`);
}
return res.json() as Promise<KnowledgeIngestPublishResult>;
const result = (await res.json()) as KnowledgeIngestPublishResult;
writeYLog({
optType: OptType.export,
optDetail: "B1-CM助手-智能体-产物发布入库",
url: `/api/knowledge-ingest/publish`,
reqParam: request,
returnParam: result,
});
return result;
}
export async function checkAgentName(