# Conflicts:
#	frontend-web/src/roundtable-planning/hooks/useStep3Dashboard.ts
This commit is contained in:
fengxiangdebaozi committed 2026-06-18 15:18:41 +08:00
commit b04b830039
20 files changed
+1396 -271

No files matched your search

@@ -0,0 +1,68 @@
/**
* 大屏绘制智能体「独立页面」会话持久化 —— 按外部 taskId 存取(后端不按 user 分权)。
*
* 一个 taskId 一条会话:聊天记录(transcript)+ 最新结构化数据(reportJson)。
* 后端 `/api/dashboard-sessions/by-task/{taskId}`(GET 取 / PUT upsert)。
* 详见后端 `app/gateway/routers/dashboard_sessions.py`。
*/
import { apiFetch } from "@/core/api/fetch-client";
import { getBackendBaseURL } from "@/core/config";
export interface DashboardSession {
taskId: string;
/** 聊天记录(大屏绘制智能体对话气泡数组;形状与 Step2Dialogue 一致,宽松存取)。 */
transcript: unknown[] | null;
/** 最新结构化数据(report-json 字符串);可被 parseReportJson 解析则视为「有效结果」。 */
reportJson: string | null;
updatedAt: string | null;
}
interface ServerDashboardSession {
task_id: string;
transcript: unknown[] | null;
report_json: string | null;
created_at?: string | null;
updated_at?: string | null;
}
const BASE = () => `${getBackendBaseURL()}/api/dashboard-sessions`;
function toClient(s: ServerDashboardSession): DashboardSession {
return {
taskId: s.task_id,
transcript: Array.isArray(s.transcript) ? s.transcript : null,
reportJson: s.report_json ?? null,
updatedAt: s.updated_at ?? null,
};
}
/** 取该 taskId 的会话;无(404)返回 null。 */
export async function getDashboardSessionByTask(taskId: string): Promise<DashboardSession | null> {
const res = await apiFetch(`${BASE()}/by-task/${encodeURIComponent(taskId)}`, { method: "GET" });
if (res.status === 404) return null;
if (!res.ok) {
const text = await res.text().catch(() => "");
throw new Error(`get dashboard session failed (${res.status}): ${text}`);
}
return toClient((await res.json()) as ServerDashboardSession);
}
/** upsert 该 taskId 的会话(只传需要更新的字段)。 */
export async function putDashboardSessionByTask(
taskId: string,
patch: { transcript?: unknown[]; reportJson?: string | null },
): Promise<DashboardSession | null> {
const body: Record<string, unknown> = {};
if (patch.transcript !== undefined) body.transcript = patch.transcript;
if (patch.reportJson !== undefined) body.report_json = patch.reportJson;
const res = await apiFetch(`${BASE()}/by-task/${encodeURIComponent(taskId)}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
if (!res.ok) {
const text = await res.text().catch(() => "");
throw new Error(`put dashboard session failed (${res.status}): ${text}`);
}
return toClient((await res.json()) as ServerDashboardSession);
}