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:
1 parent
320f2ef814
commit
df9c59e21c
35 files changed
+1569
-224
No files matched your search
@@ -93,9 +93,17 @@ export async function createScheduledTask(data: {
|
||||
}
|
||||
|
||||
export async function listScheduledTaskRuns(taskId: string) {
|
||||
return parseResponse<ScheduledTaskRun[]>(
|
||||
const result = await parseResponse<ScheduledTaskRun[]>(
|
||||
await apiFetch(`${baseUrl()}/${encodeURIComponent(taskId)}/runs`),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.search,
|
||||
optDetail: "B1-CM助手-定时任务-运行记录列表",
|
||||
url: `${baseUrl()}/${encodeURIComponent(taskId)}/runs`,
|
||||
reqParam: { taskId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getScheduledTaskRun(runId: string) {
|
||||
@@ -113,18 +121,34 @@ export async function getScheduledTaskRun(runId: string) {
|
||||
}
|
||||
|
||||
export async function deleteScheduledTaskRun(runId: string) {
|
||||
return parseResponse<{ success: boolean }>(
|
||||
const result = await parseResponse<{ success: boolean }>(
|
||||
await apiFetch(`${baseUrl()}/runs/${encodeURIComponent(runId)}`, {
|
||||
method: "DELETE",
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.delete,
|
||||
optDetail: "B1-CM助手-定时任务-删除运行记录",
|
||||
url: `${baseUrl()}/runs/${encodeURIComponent(runId)}`,
|
||||
reqParam: { runId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Agent messages for a run's underlying agent run — used to inspect a stuck/running run. */
|
||||
export async function getScheduledTaskRunMessages(runId: string) {
|
||||
return parseResponse<ScheduledTaskRunMessagesResponse>(
|
||||
const result = await parseResponse<ScheduledTaskRunMessagesResponse>(
|
||||
await apiFetch(`${baseUrl()}/runs/${encodeURIComponent(runId)}/messages`),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.view,
|
||||
optDetail: "B1-CM助手-定时任务-运行消息",
|
||||
url: `${baseUrl()}/runs/${encodeURIComponent(runId)}/messages`,
|
||||
reqParam: { runId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export function scheduledTaskRunDownloadUrl(runId: string) {
|
||||
@@ -136,9 +160,17 @@ export function scheduledTaskRunFileDownloadUrl(runId: string, fileIndex: number
|
||||
}
|
||||
|
||||
export async function getScheduledTaskRunFileContent(runId: string, fileIndex: number) {
|
||||
return parseResponse<ScheduledTaskResultFileContent>(
|
||||
const result = await parseResponse<ScheduledTaskResultFileContent>(
|
||||
await apiFetch(`${baseUrl()}/runs/${encodeURIComponent(runId)}/files/${fileIndex}`),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.view,
|
||||
optDetail: "B1-CM助手-定时任务-运行文件查看",
|
||||
url: `${baseUrl()}/runs/${encodeURIComponent(runId)}/files/${fileIndex}`,
|
||||
reqParam: { runId, fileIndex },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function updateScheduledTaskRunFile(
|
||||
@@ -146,13 +178,21 @@ export async function updateScheduledTaskRunFile(
|
||||
fileIndex: number,
|
||||
content: string,
|
||||
) {
|
||||
return parseResponse<ScheduledTaskRunFileUpdateResponse>(
|
||||
const result = await parseResponse<ScheduledTaskRunFileUpdateResponse>(
|
||||
await apiFetch(`${baseUrl()}/runs/${encodeURIComponent(runId)}/files/${fileIndex}`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ content }),
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.edit,
|
||||
optDetail: "B1-CM助手-定时任务-运行文件编辑",
|
||||
url: `${baseUrl()}/runs/${encodeURIComponent(runId)}/files/${fileIndex}`,
|
||||
reqParam: { runId, fileIndex },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
function filenameFromContentDisposition(header: string | null): string | null {
|
||||
@@ -212,6 +252,12 @@ export async function downloadScheduledTaskRun(runId: string) {
|
||||
await apiFetch(scheduledTaskRunDownloadUrl(runId)),
|
||||
"scheduled-task-result.zip",
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.export,
|
||||
optDetail: "B1-CM助手-定时任务-下载运行结果",
|
||||
url: scheduledTaskRunDownloadUrl(runId),
|
||||
reqParam: { runId },
|
||||
});
|
||||
}
|
||||
|
||||
export async function downloadScheduledTaskRunFile(runId: string, fileIndex: number) {
|
||||
@@ -219,24 +265,45 @@ export async function downloadScheduledTaskRunFile(runId: string, fileIndex: num
|
||||
await apiFetch(scheduledTaskRunFileDownloadUrl(runId, fileIndex)),
|
||||
"scheduled-task-file",
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.export,
|
||||
optDetail: "B1-CM助手-定时任务-下载运行文件",
|
||||
url: scheduledTaskRunFileDownloadUrl(runId, fileIndex),
|
||||
reqParam: { runId, fileIndex },
|
||||
});
|
||||
}
|
||||
|
||||
export async function getScheduledTaskDeliveryProfile() {
|
||||
return parseResponse<ScheduledTaskDeliveryProfile>(
|
||||
const result = await parseResponse<ScheduledTaskDeliveryProfile>(
|
||||
await apiFetch(`${baseUrl()}/delivery-profile`),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.view,
|
||||
optDetail: "B1-CM助手-定时任务-投递配置查看",
|
||||
url: `${baseUrl()}/delivery-profile`,
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function updateScheduledTaskDeliveryProfile(data: {
|
||||
element_user_id?: string | null;
|
||||
}) {
|
||||
return parseResponse<ScheduledTaskDeliveryProfile>(
|
||||
const result = await parseResponse<ScheduledTaskDeliveryProfile>(
|
||||
await apiFetch(`${baseUrl()}/delivery-profile`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(data),
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.edit,
|
||||
optDetail: "B1-CM助手-定时任务-投递配置修改",
|
||||
url: `${baseUrl()}/delivery-profile`,
|
||||
reqParam: data,
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function updateScheduledTask(
|
||||
@@ -339,53 +406,101 @@ export async function listPublishedScheduledTasks(params: { limit?: number; offs
|
||||
if (params.limit != null) query.set("limit", String(params.limit));
|
||||
if (params.offset != null) query.set("offset", String(params.offset));
|
||||
const suffix = query.toString();
|
||||
return parseResponse<PublishedScheduledTask[]>(
|
||||
const result = await parseResponse<PublishedScheduledTask[]>(
|
||||
await apiFetch(`${baseUrl()}/published${suffix ? `?${suffix}` : ""}`),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.search,
|
||||
optDetail: "B1-CM助手-定时任务-已发布列表",
|
||||
url: `${baseUrl()}/published${suffix ? `?${suffix}` : ""}`,
|
||||
reqParam: params,
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function publishScheduledTask(taskId: string) {
|
||||
return parseResponse<ScheduledTask>(
|
||||
const result = await parseResponse<ScheduledTask>(
|
||||
await apiFetch(`${baseUrl()}/${encodeURIComponent(taskId)}/publish`, {
|
||||
method: "POST",
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.export,
|
||||
optDetail: "B1-CM助手-定时任务-发布",
|
||||
url: `${baseUrl()}/${encodeURIComponent(taskId)}/publish`,
|
||||
reqParam: { taskId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function unpublishScheduledTask(taskId: string) {
|
||||
return parseResponse<ScheduledTask>(
|
||||
const result = await parseResponse<ScheduledTask>(
|
||||
await apiFetch(`${baseUrl()}/${encodeURIComponent(taskId)}/unpublish`, {
|
||||
method: "POST",
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.other,
|
||||
optDetail: "B1-CM助手-定时任务-取消发布",
|
||||
url: `${baseUrl()}/${encodeURIComponent(taskId)}/unpublish`,
|
||||
reqParam: { taskId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function subscribeScheduledTask(taskId: string, notifyElement: boolean) {
|
||||
return parseResponse<ScheduledTaskSubscription>(
|
||||
const result = await parseResponse<ScheduledTaskSubscription>(
|
||||
await apiFetch(`${baseUrl()}/${encodeURIComponent(taskId)}/subscribe`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ notify_element: notifyElement }),
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.create,
|
||||
optDetail: "B1-CM助手-定时任务-订阅",
|
||||
url: `${baseUrl()}/${encodeURIComponent(taskId)}/subscribe`,
|
||||
reqParam: { taskId, notify_element: notifyElement },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function updateScheduledTaskSubscription(taskId: string, notifyElement: boolean) {
|
||||
return parseResponse<ScheduledTaskSubscription>(
|
||||
const result = await parseResponse<ScheduledTaskSubscription>(
|
||||
await apiFetch(`${baseUrl()}/${encodeURIComponent(taskId)}/subscribe`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ notify_element: notifyElement }),
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.edit,
|
||||
optDetail: "B1-CM助手-定时任务-订阅修改",
|
||||
url: `${baseUrl()}/${encodeURIComponent(taskId)}/subscribe`,
|
||||
reqParam: { taskId, notify_element: notifyElement },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function unsubscribeScheduledTask(taskId: string) {
|
||||
return parseResponse<{ success: boolean }>(
|
||||
const result = await parseResponse<{ success: boolean }>(
|
||||
await apiFetch(`${baseUrl()}/${encodeURIComponent(taskId)}/subscribe`, {
|
||||
method: "DELETE",
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.delete,
|
||||
optDetail: "B1-CM助手-定时任务-取消订阅",
|
||||
url: `${baseUrl()}/${encodeURIComponent(taskId)}/subscribe`,
|
||||
reqParam: { taskId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
// --- Admin (cross-user management) ---
|
||||
@@ -395,16 +510,32 @@ export async function listAllScheduledTasks(search?: string) {
|
||||
const qs = new URLSearchParams();
|
||||
if (search) qs.set("search", search);
|
||||
const query = qs.toString();
|
||||
return parseResponse<ScheduledTask[]>(
|
||||
const result = await parseResponse<ScheduledTask[]>(
|
||||
await apiFetch(`${baseUrl()}/admin/all${query ? `?${query}` : ""}`),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.search,
|
||||
optDetail: "B1-CM助手-定时任务-全部任务列表",
|
||||
url: `${baseUrl()}/admin/all${query ? `?${query}` : ""}`,
|
||||
reqParam: { search },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/** List runs for any task regardless of owner. Admin-only endpoint. */
|
||||
export async function adminListScheduledTaskRuns(taskId: string) {
|
||||
return parseResponse<ScheduledTaskRun[]>(
|
||||
const result = await parseResponse<ScheduledTaskRun[]>(
|
||||
await apiFetch(`${baseUrl()}/admin/${encodeURIComponent(taskId)}/runs`),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.search,
|
||||
optDetail: "B1-CM助手-定时任务-运行记录列表",
|
||||
url: `${baseUrl()}/admin/${encodeURIComponent(taskId)}/runs`,
|
||||
reqParam: { taskId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Update any task regardless of owner. Admin-only endpoint. */
|
||||
@@ -421,52 +552,99 @@ export async function adminUpdateScheduledTask(
|
||||
require_markdown: boolean;
|
||||
}>,
|
||||
) {
|
||||
return parseResponse<ScheduledTask>(
|
||||
const result = await parseResponse<ScheduledTask>(
|
||||
await apiFetch(`${baseUrl()}/admin/${encodeURIComponent(taskId)}`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(data),
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.edit,
|
||||
optDetail: "B1-CM助手-定时任务-修改",
|
||||
url: `${baseUrl()}/admin/${encodeURIComponent(taskId)}`,
|
||||
reqParam: { taskId, data },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Delete any task regardless of owner. Admin-only endpoint. */
|
||||
export async function adminDeleteScheduledTask(taskId: string) {
|
||||
return parseResponse<{ success: boolean }>(
|
||||
const result = await parseResponse<{ success: boolean }>(
|
||||
await apiFetch(`${baseUrl()}/admin/${encodeURIComponent(taskId)}`, {
|
||||
method: "DELETE",
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.delete,
|
||||
optDetail: "B1-CM助手-定时任务-删除",
|
||||
url: `${baseUrl()}/admin/${encodeURIComponent(taskId)}`,
|
||||
reqParam: { taskId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Trigger an immediate run of any task regardless of owner. Admin-only. */
|
||||
export async function adminTriggerScheduledTask(taskId: string) {
|
||||
return parseResponse<{ success: boolean; task: ScheduledTask }>(
|
||||
const result = await parseResponse<{ success: boolean; task: ScheduledTask }>(
|
||||
await apiFetch(`${baseUrl()}/admin/${encodeURIComponent(taskId)}/trigger`, {
|
||||
method: "POST",
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.other,
|
||||
optDetail: "B1-CM助手-定时任务-手动运行",
|
||||
url: `${baseUrl()}/admin/${encodeURIComponent(taskId)}/trigger`,
|
||||
reqParam: { taskId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
// --- HTML page tasks ---
|
||||
|
||||
/** Fetch the generated HTML document for an ``html_page`` run. */
|
||||
export async function getScheduledTaskRunHtml(runId: string) {
|
||||
return parseResponse<ScheduledTaskRunHtml>(
|
||||
const result = await parseResponse<ScheduledTaskRunHtml>(
|
||||
await apiFetch(`${baseUrl()}/runs/${encodeURIComponent(runId)}/html`),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.view,
|
||||
optDetail: "B1-CM助手-定时任务-运行HTML查看",
|
||||
url: `${baseUrl()}/runs/${encodeURIComponent(runId)}/html`,
|
||||
reqParam: { runId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
const favoritesUrl = () => `${getBackendBaseURL()}/api/html-page-favorites`;
|
||||
|
||||
export async function listHtmlPageFavorites() {
|
||||
return parseResponse<HtmlPageFavorite[]>(await apiFetch(favoritesUrl()));
|
||||
const result = await parseResponse<HtmlPageFavorite[]>(await apiFetch(favoritesUrl()));
|
||||
writeYLog({
|
||||
optType: OptType.search,
|
||||
optDetail: "B1-CM助手-HTML收藏-列表",
|
||||
url: `/api/html-page-favorites`,
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getHtmlPageFavorite(favoriteId: string) {
|
||||
return parseResponse<HtmlPageFavorite>(
|
||||
const result = await parseResponse<HtmlPageFavorite>(
|
||||
await apiFetch(`${favoritesUrl()}/${encodeURIComponent(favoriteId)}`),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.view,
|
||||
optDetail: "B1-CM助手-HTML收藏-查看",
|
||||
url: `/api/html-page-favorites/${encodeURIComponent(favoriteId)}`,
|
||||
reqParam: { favoriteId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function createHtmlPageFavorite(data: {
|
||||
@@ -475,19 +653,35 @@ export async function createHtmlPageFavorite(data: {
|
||||
description?: string | null;
|
||||
tags?: string[];
|
||||
}) {
|
||||
return parseResponse<HtmlPageFavorite>(
|
||||
const result = await parseResponse<HtmlPageFavorite>(
|
||||
await apiFetch(favoritesUrl(), {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(data),
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.create,
|
||||
optDetail: "B1-CM助手-HTML收藏-新建",
|
||||
url: `/api/html-page-favorites`,
|
||||
reqParam: data,
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function deleteHtmlPageFavorite(favoriteId: string) {
|
||||
return parseResponse<{ success: boolean }>(
|
||||
const result = await parseResponse<{ success: boolean }>(
|
||||
await apiFetch(`${favoritesUrl()}/${encodeURIComponent(favoriteId)}`, {
|
||||
method: "DELETE",
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.delete,
|
||||
optDetail: "B1-CM助手-HTML收藏-删除",
|
||||
url: `/api/html-page-favorites/${encodeURIComponent(favoriteId)}`,
|
||||
reqParam: { favoriteId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user