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

@@ -12,6 +12,7 @@
import { apiFetch } from "@/core/api/fetch-client";
import { getBackendBaseURL } from "@/core/config";
import { OptType, writeYLog } from "@/core/log/y-log";
import type { BusinessChain, ChainSeat } from "@/roundtable-planning/lib/business-chain";
import type { SeatMode } from "@/roundtable-planning/lib/seat-mode";
@@ -154,7 +155,15 @@ export async function listChains(scope: ChainScope = "mine"): Promise<BusinessCh
const url = scope === "mine" ? BASE() : `${BASE()}?scope=${scope}`;
const res = await apiFetch(url, { method: "GET" });
const data = await readJson<{ chains: ServerChain[] }>(res, "list chains");
return (data.chains ?? []).map(toChain);
const chains = (data.chains ?? []).map(toChain);
writeYLog({
optType: OptType.search,
optDetail: "B1-CM助手-业务链条-查询",
url,
reqParam: { scope },
returnParam: { count: chains.length },
});
return chains;
}
/** 发布 / 取消发布一条链条(仅 owner 生效)。返回更新后的链条,404 返回 null。 */
@@ -167,7 +176,15 @@ export async function getChain(id: string): Promise<BusinessChain | null> {
const res = await apiFetch(`${BASE()}/${encodeURIComponent(id)}`, { method: "GET" });
if (res.status === 404) return null;
const data = await readJson<ServerChain>(res, "get chain");
return toChain(data);
const chain = toChain(data);
writeYLog({
optType: OptType.view,
optDetail: "B1-CM助手-业务链条-查看",
url: `${BASE()}/${id}`,
reqParam: { id },
returnParam: { id: chain.id, title: chain.title },
});
return chain;
}
export async function createChain(payload: ChainCreatePayload): Promise<BusinessChain> {
@@ -177,7 +194,15 @@ export async function createChain(payload: ChainCreatePayload): Promise<Business
body: JSON.stringify(fromCreate(payload)),
});
const data = await readJson<ServerChain>(res, "create chain");
return toChain(data);
const chain = toChain(data);
writeYLog({
optType: OptType.create,
optDetail: "B1-CM助手-业务链条-新建",
url: BASE(),
reqParam: { title: payload.title, seats: payload.seats?.length ?? 0 },
returnParam: { id: chain.id, title: chain.title },
});
return chain;
}
export async function updateChain(id: string, patch: ChainUpdatePayload): Promise<BusinessChain | null> {
@@ -188,7 +213,20 @@ export async function updateChain(id: string, patch: ChainUpdatePayload): Promis
});
if (res.status === 404) return null;
const data = await readJson<ServerChain>(res, "update chain");
return toChain(data);
const chain = toChain(data);
writeYLog({
optType: patch.isPublic === true ? OptType.enabled : patch.isPublic === false ? OptType.disabled : OptType.edit,
optDetail:
patch.isPublic === true
? "B1-CM助手-业务链条-发布"
: patch.isPublic === false
? "B1-CM助手-业务链条-取消发布"
: "B1-CM助手-业务链条-编辑",
url: `${BASE()}/${id}`,
reqParam: { id, ...patch },
returnParam: { id: chain.id, title: chain.title },
});
return chain;
}
export async function deleteChain(id: string): Promise<void> {
@@ -197,6 +235,12 @@ export async function deleteChain(id: string): Promise<void> {
const text = await res.text().catch(() => "");
throw new Error(`delete chain failed (${res.status}): ${text}`);
}
writeYLog({
optType: OptType.delete,
optDetail: "B1-CM助手-业务链条-删除",
url: `${BASE()}/${id}`,
reqParam: { id },
});
}
// ── 提示词优化 ───────────────────────────────────────────────────────────────
@@ -7,6 +7,7 @@
*/
import { apiFetch } from "@/core/api/fetch-client";
import { getBackendBaseURL } from "@/core/config";
import { OptType, writeYLog } from "@/core/log/y-log";
export interface DashboardSession {
taskId: string;
@@ -44,7 +45,15 @@ export async function getDashboardSessionByTask(taskId: string): Promise<Dashboa
const text = await res.text().catch(() => "");
throw new Error(`get dashboard session failed (${res.status}): ${text}`);
}
return toClient((await res.json()) as ServerDashboardSession);
const session = toClient((await res.json()) as ServerDashboardSession);
writeYLog({
optType: OptType.view,
optDetail: "B1-CM助手-大屏会话-查看",
url: `${BASE()}/by-task/${taskId}`,
reqParam: { taskId },
returnParam: { taskId: session.taskId, updatedAt: session.updatedAt },
});
return session;
}
/** upsert 该 taskId 的会话(只传需要更新的字段)。 */
@@ -64,5 +73,13 @@ export async function putDashboardSessionByTask(
const text = await res.text().catch(() => "");
throw new Error(`put dashboard session failed (${res.status}): ${text}`);
}
return toClient((await res.json()) as ServerDashboardSession);
const session = toClient((await res.json()) as ServerDashboardSession);
writeYLog({
optType: OptType.edit,
optDetail: "B1-CM助手-大屏会话-保存",
url: `${BASE()}/by-task/${taskId}`,
reqParam: { taskId, hasTranscript: patch.transcript !== undefined, hasReportJson: patch.reportJson !== undefined },
returnParam: { taskId: session.taskId, updatedAt: session.updatedAt },
});
return session;
}
@@ -337,7 +337,15 @@ export async function getDraft(id: string): Promise<DraftRecord | null> {
const res = await apiFetch(`${BASE()}/${encodeURIComponent(id)}`, { method: "GET" });
if (res.status === 404) return null;
const data = await readJson<ServerDraftFull>(res, "get draft");
return toRecord(data);
const record = toRecord(data);
writeYLog({
optType: OptType.view,
optDetail: "B1-CM助手-会商-查看草稿",
url: `${BASE()}/${id}`,
reqParam: { id },
returnParam: { id: record.id, title: record.title },
});
return record;
}
export async function createDraft(payload: DraftCreatePayload): Promise<DraftRecord> {
@@ -1,5 +1,6 @@
import { apiFetch } from "@/core/api/fetch-client";
import { getBackendBaseURL } from "@/core/config";
import { OptType, writeYLog } from "@/core/log/y-log";
import { resolveAllowMultiple } from "@/roundtable-planning/lib/clarification";
import { reportRoundtableError, stageForRoundtableAgent } from "@/roundtable-planning/api/diagnostics-report";
@@ -921,7 +922,7 @@ export async function listSessionArtifacts(
modified_at: string;
}>;
};
return {
const result = {
threadId: json.thread_id,
files: (json.files ?? []).map((f) => ({
path: f.path,
@@ -931,6 +932,14 @@ export async function listSessionArtifacts(
modifiedAt: f.modified_at,
})),
};
writeYLog({
optType: OptType.search,
optDetail: "B1-CM助手-会商产物-查询",
url: `/api/threads/${threadId}/artifacts`,
reqParam: { threadId },
returnParam: { count: result.files.length },
});
return result;
}
/**
@@ -1,5 +1,6 @@
import { apiFetch } from "@/core/api/fetch-client";
import { getBackendBaseURL } from "@/core/config";
import { OptType, writeYLog } from "@/core/log/y-log";
import type { Agent } from "@/core/agents";
import type { IntentSummary } from "./intent";
@@ -268,7 +269,15 @@ export async function listRecommendHistory(draftId: string): Promise<RecommendHi
throw new Error(`list recommend history failed (${res.status}): ${text}`);
}
const data = (await res.json()) as { history: ServerHistoryItem[] };
return (data.history ?? []).map(toHistoryItem);
const items = (data.history ?? []).map(toHistoryItem);
writeYLog({
optType: OptType.search,
optDetail: "B1-CM助手-席位推荐-查询历史",
url: `/api/roundtable-drafts/${draftId}/recommendations`,
reqParam: { draftId },
returnParam: { count: items.length },
});
return items;
}
/** Append one recommendation run to a draft's history. */
@@ -296,7 +305,15 @@ export async function saveRecommendHistory(
const text = await res.text().catch(() => "");
throw new Error(`save recommend history failed (${res.status}): ${text}`);
}
return toHistoryItem((await res.json()) as ServerHistoryItem);
const item = toHistoryItem((await res.json()) as ServerHistoryItem);
writeYLog({
optType: OptType.create,
optDetail: "B1-CM助手-席位推荐-保存历史",
url: `/api/roundtable-drafts/${draftId}/recommendations`,
reqParam: { draftId, status: payload.status, picks: payload.picks?.length ?? 0 },
returnParam: { id: item.id },
});
return item;
}
/**
@@ -189,7 +189,15 @@ export async function resumeJob(jobId: string, answer: string, taskId?: string |
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ answer }),
});
return mapJob(await readJson<Record<string, unknown>>(res, "resume job"));
const job = mapJob(await readJson<Record<string, unknown>>(res, "resume job"));
writeYLog({
optType: OptType.other,
optDetail: "B1-CM助手-会商-回答澄清续跑",
url: `${BASE()}/${jobId}/resume`,
reqParam: { jobId, taskId: taskId ?? null },
returnParam: { id: job.id, status: job.status },
});
return job;
}
/** 取消作业。`taskId` 非空 → task 共享取消(不分权)。 */
@@ -50,7 +50,15 @@ export async function getLatestTaskDraftByTask(taskId: string): Promise<DraftRec
const res = await apiFetch(`${BASE()}/by-task/${encodeURIComponent(taskId)}/latest`, { method: "GET" });
if (res.status === 404) return null;
const data = await readJson<ServerDraftFull>(res, "get latest task draft");
return toRecord(data);
const record = toRecord(data);
writeYLog({
optType: OptType.view,
optDetail: "B1-CM助手-会商任务-查看最新草稿",
url: `${BASE()}/by-task/${taskId}/latest`,
reqParam: { taskId },
returnParam: { id: record.id, title: record.title },
});
return record;
}
/** Full task draft by id (不分权). Returns null on 404. */
@@ -58,7 +66,15 @@ export async function getTaskDraft(id: string): Promise<DraftRecord | null> {
const res = await apiFetch(`${BASE()}/${encodeURIComponent(id)}`, { method: "GET" });
if (res.status === 404) return null;
const data = await readJson<ServerDraftFull>(res, "get task draft");
return toRecord(data);
const record = toRecord(data);
writeYLog({
optType: OptType.view,
optDetail: "B1-CM助手-会商任务-查看草稿",
url: `${BASE()}/${id}`,
reqParam: { id },
returnParam: { id: record.id, title: record.title },
});
return record;
}
/** Create a task draft. `payload.taskId` is required. */