Przeglądaj źródła

fix: 调用记录页白屏 — 后端 snake_case 字段未映射到前端 camelCase

recordApi.ts 直接将后端响应 as 类型转换,未做字段映射。
添加 mapRecord 函数统一映射 doc_ref→docRef, duration_ms→duration 等,
兼容两种命名风格,避免 undefined.toLowerCase() 导致白屏。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
WangXuMing 1 tydzień temu
rodzic
commit
b18aadc714
1 zmienionych plików z 27 dodań i 2 usunięć
  1. 27 2
      frontend/src/services/recordApi.ts

+ 27 - 2
frontend/src/services/recordApi.ts

@@ -1,6 +1,25 @@
 import * as api from './api';
 import type { CallRecord, ReplayResult } from '../types';
 
+function mapRecord(raw: Record<string, unknown>): CallRecord {
+  return {
+    id: (raw.id ?? raw.record_id ?? '') as string,
+    time: (raw.time ?? raw.timestamp ?? '') as string,
+    chain: (raw.chain ?? raw.chain_id ?? '') as string,
+    docRef: (raw.doc_ref ?? raw.docRef ?? '') as string,
+    inputSummary: (raw.doc_ref ?? raw.docRef ?? '').toString().slice(0, 30) as string,
+    duration: raw.duration_ms != null ? `${raw.duration_ms}ms` : ((raw.duration ?? '') as string),
+    status: (raw.status ?? '') as CallRecord['status'],
+    model: (raw.model ?? '') as string,
+    promptVer: (raw.prompt_ver ?? raw.promptVer ?? '') as string,
+    tokens: (raw.tokens ?? 0) as number,
+    params: (raw.params ?? {}) as Record<string, string>,
+    steps: (raw.steps ?? []) as CallRecord['steps'],
+    result: (raw.result ?? '') as string,
+    isReplayed: false,
+  };
+}
+
 /** 获取调用记录列表 */
 export async function fetchCallRecords(params?: {
   page?: number;
@@ -8,12 +27,18 @@ export async function fetchCallRecords(params?: {
   status?: string;
   search?: string;
 }): Promise<{ items: CallRecord[]; total: number; page: number; page_size: number }> {
-  return (await api.fetchCallRecords(params)) as {
-    items: CallRecord[];
+  const raw = await api.fetchCallRecords(params) as {
+    items: Record<string, unknown>[];
     total: number;
     page: number;
     page_size: number;
   };
+  return {
+    items: (raw.items ?? []).map(mapRecord),
+    total: raw.total ?? 0,
+    page: raw.page ?? 1,
+    page_size: raw.page_size ?? 20,
+  };
 }
 
 /** 获取调用记录详情 */