feat(y-log): 问答按 LLM 调用各记一条 + 全量补齐各 API 操作埋点

- 问答日志从「每轮 onFinish 一条」改为 useThreadStream onLangChainEvent
  监听 on_chat_model_end,每次大模型调用结束各上报一条(含子代理)
- 广覆盖各 API client 成功路径:查看(view)/查询(search)/新增(create)/
  编辑(edit)/删除(delete)/启停(enabled·disabled)/导入导出,补齐此前
  整模块零埋点与漏掉的单条详情 GET;跳过高频 typeahead/轮询/bootstrap

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 20:42:54 +08:00
1 parent 320f2ef814
commit df9c59e21c
35 files changed
+1569 -224

No files matched your search

+45 -13
View File
@@ -2,6 +2,7 @@ import type { Message } from "@langchain/langgraph-sdk";
import { apiFetch } from "@/core/api";
import { getBackendBaseURL } from "@/core/config";
import { OptType, writeYLog } from "@/core/log/y-log";
/**
* Share modes:
@@ -65,7 +66,15 @@ export async function createShare(
body: JSON.stringify({ thread_id: threadId, mode }),
});
if (!response.ok) throw await parseError(response, "创建分享失败");
return response.json() as Promise<ThreadShare>;
const result = (await response.json()) as ThreadShare;
writeYLog({
optType: OptType.create,
optDetail: "B1-CM助手-会话分享-创建分享",
url: baseUrl(),
reqParam: { thread_id: threadId, mode },
returnParam: { share_code: result.share_code, mode: result.mode },
});
return result;
}
/** List the current user's own share links. */
@@ -73,34 +82,57 @@ export async function listShares(): Promise<ThreadShare[]> {
const response = await apiFetch(baseUrl());
if (!response.ok) throw await parseError(response, "加载分享列表失败");
const json = (await response.json()) as { shares: ThreadShare[] };
writeYLog({
optType: OptType.search,
optDetail: "B1-CM助手-会话分享-查询分享列表",
url: baseUrl(),
returnParam: { count: json.shares.length },
});
return json.shares;
}
/** Revoke a share link so it can no longer be previewed or imported. */
export async function revokeShare(shareCode: string): Promise<void> {
const response = await apiFetch(`${baseUrl()}/${encodeURIComponent(shareCode)}`, {
method: "DELETE",
});
const url = `${baseUrl()}/${encodeURIComponent(shareCode)}`;
const response = await apiFetch(url, { method: "DELETE" });
if (!response.ok) throw await parseError(response, "撤销分享失败");
writeYLog({
optType: OptType.delete,
optDetail: "B1-CM助手-会话分享-撤销分享",
url,
reqParam: { shareCode },
});
}
/** Preview a share link before importing it. */
export async function previewShare(shareCode: string): Promise<SharePreview> {
const response = await apiFetch(
`${baseUrl()}/${encodeURIComponent(shareCode)}/preview`,
);
const url = `${baseUrl()}/${encodeURIComponent(shareCode)}/preview`;
const response = await apiFetch(url);
if (!response.ok) throw await parseError(response, "无法读取该分享");
return response.json() as Promise<SharePreview>;
const result = (await response.json()) as SharePreview;
writeYLog({
optType: OptType.view,
optDetail: "B1-CM助手-会话分享-预览分享",
url,
reqParam: { shareCode },
});
return result;
}
/** Import every conversation behind a share link into the current account. */
export async function importShare(shareCode: string): Promise<ImportResult> {
const response = await apiFetch(
`${baseUrl()}/${encodeURIComponent(shareCode)}/import`,
{ method: "POST" },
);
const url = `${baseUrl()}/${encodeURIComponent(shareCode)}/import`;
const response = await apiFetch(url, { method: "POST" });
if (!response.ok) throw await parseError(response, "导入失败");
return response.json() as Promise<ImportResult>;
const result = (await response.json()) as ImportResult;
writeYLog({
optType: OptType.import,
optDetail: "B1-CM助手-会话分享-导入分享",
url,
reqParam: { shareCode },
returnParam: result,
});
return result;
}
/**