CallAssemblyDetail.tsx
17.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
import { useEffect } from 'react';
import { Drawer, Spin, Tag, Descriptions, Divider, Empty } from 'antd';
import {
ThunderboltOutlined,
FileTextOutlined,
ApartmentOutlined,
CodeOutlined,
SwapOutlined,
CheckCircleOutlined,
CloseCircleOutlined,
ClockCircleOutlined,
SafetyOutlined,
} from '@ant-design/icons';
import { useCallRecordStore } from '../../stores/callRecordStore';
import { TEMPLATE_TYPE_OPTIONS } from '../../types';
const TEMPLATE_TYPE_MAP = Object.fromEntries(
TEMPLATE_TYPE_OPTIONS.map((opt) => [opt.value, opt.label]),
);
const CALL_STATUS_MAP: Record<string, { label: string; color: string }> = {
pending: { label: '待调度', color: 'default' },
success: { label: '成功', color: 'success' },
failed: { label: '失败', color: 'error' },
};
interface Props {
open: boolean;
callId: string | null;
onClose: () => void;
}
export default function CallAssemblyDetail({ open, callId, onClose }: Props) {
const { detail, detailLoading, getCallDetail } = useCallRecordStore();
useEffect(() => {
if (open && callId) {
getCallDetail(callId);
}
}, [open, callId, getCallDetail]);
const record = detail;
return (
<Drawer
title={
<span style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<ThunderboltOutlined style={{ color: 'var(--color-primary)' }} />
<span>调用详情</span>
{record && (
<Tag color="blue" style={{ fontSize: 11 }}>{record.model_name}</Tag>
)}
</span>
}
open={open}
onClose={onClose}
width={800}
destroyOnClose
className="call-assembly-drawer"
>
<Spin spinning={detailLoading}>
{record && (
<>
{/* 基本信息 */}
<div className="assembly-section">
<div className="assembly-section-header">
<ApartmentOutlined style={{ color: 'var(--color-primary)' }} />
<span className="assembly-section-title">基本信息</span>
</div>
<Descriptions column={2} size="small" className="assembly-descriptions">
<Descriptions.Item label="模型名称">
<span style={{ fontWeight: 500 }}>{record.model_name}</span>
</Descriptions.Item>
<Descriptions.Item label="账号">
{record.account_name || '-'}
</Descriptions.Item>
<Descriptions.Item label="供应商">
{record.provider_name || '-'}
</Descriptions.Item>
<Descriptions.Item label="业务类型">
{record.biz_type ? <Tag>{record.biz_type}</Tag> : '-'}
</Descriptions.Item>
<Descriptions.Item label="状态">
<Tag color={CALL_STATUS_MAP[record.status]?.color || 'default'}>
{CALL_STATUS_MAP[record.status]?.label || record.status}
</Tag>
</Descriptions.Item>
<Descriptions.Item label="耗时">
<code style={{ fontFamily: "'JetBrains Mono', monospace" }}>
{(record.duration_ms / 1000).toFixed(2)}s
</code>
</Descriptions.Item>
<Descriptions.Item label="Prompt Tokens">
<code style={{ fontFamily: "'JetBrains Mono', monospace" }}>
{record.prompt_tokens.toLocaleString()}
</code>
</Descriptions.Item>
<Descriptions.Item label="Completion Tokens">
<code style={{ fontFamily: "'JetBrains Mono', monospace" }}>
{record.completion_tokens.toLocaleString()}
</code>
</Descriptions.Item>
<Descriptions.Item label="总 Tokens">
<code style={{ fontFamily: "'JetBrains Mono', monospace", fontWeight: 600 }}>
{record.total_tokens.toLocaleString()}
</code>
</Descriptions.Item>
<Descriptions.Item label="调用时间">
<code style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 12 }}>
{new Date(record.called_at).toLocaleString('zh-CN')}
</code>
</Descriptions.Item>
{record.error_message && (
<Descriptions.Item label="错误信息" span={2}>
<pre style={{ color: 'var(--color-error)', margin: 0, fontSize: 12 }}>
{record.error_message}
</pre>
</Descriptions.Item>
)}
</Descriptions>
</div>
<Divider style={{ margin: '12px 0' }} />
{/* 组装过程 */}
<div className="assembly-section">
<div className="assembly-section-header">
<SwapOutlined style={{ color: 'var(--color-primary)' }} />
<span className="assembly-section-title">组装过程</span>
</div>
<div className="assembly-flow">
{/* Step 1: 提示词模板 */}
<div className="flow-step">
<div className="flow-step-number">1</div>
<div className="flow-step-content">
<div className="flow-step-title">
<FileTextOutlined />
<span>提示词模板</span>
{record.template_info ? (
<Tag color="purple" style={{ marginLeft: 8, fontSize: 10 }}>
v{record.template_info.version}
</Tag>
) : (
<Tag style={{ marginLeft: 8, fontSize: 10 }}>未关联</Tag>
)}
</div>
{record.template_info ? (
<div className="flow-step-body">
<div className="template-info-row">
<label>标题</label>
<span>{record.template_info.title}</span>
</div>
<div className="template-info-row">
<label>编码</label>
<code>{record.template_info.code}</code>
</div>
<div className="template-info-row">
<label>类型</label>
<Tag>{TEMPLATE_TYPE_MAP[record.template_info.template_type] || record.template_info.template_type}</Tag>
</div>
<div className="template-info-row">
<label>System Prompt</label>
<pre className="flow-pre">{record.template_info.system_prompt}</pre>
</div>
{record.template_info.user_prompt && (
<div className="template-info-row">
<label>User Prompt</label>
<pre className="flow-pre">{record.template_info.user_prompt}</pre>
</div>
)}
</div>
) : (
<div className="flow-step-empty">
<ClockCircleOutlined />
<span>未关联提示词模板</span>
</div>
)}
</div>
</div>
{/* Step 2: 敏感词替换 */}
<div className="flow-step">
<div className="flow-step-number">2</div>
<div className="flow-step-content">
<div className="flow-step-title">
<SafetyOutlined style={{ color: 'var(--color-success)' }} />
<span>敏感词替换</span>
{record.sensitive_replacements && record.sensitive_replacements.length > 0 ? (
<Tag color="success" style={{ fontSize: 10 }}>替换 {record.sensitive_replacements.length} 项</Tag>
) : (
<Tag style={{ fontSize: 10 }}>无需替换</Tag>
)}
</div>
{record.sensitive_replacements && record.sensitive_replacements.length > 0 ? (
<div className="flow-step-body" style={{ background: '#f6ffed', borderColor: '#b7eb8f' }}>
<table className="replacement-table">
<thead>
<tr>
<th>原始词</th>
<th>替换为</th>
</tr>
</thead>
<tbody>
{record.sensitive_replacements.map((r, i) => (
<tr key={i}>
<td>
<code className="replacement-word">{r.word}</code>
</td>
<td>
<span className="replacement-arrow">→</span>
<code className="replacement-target">{r.replacement}</code>
</td>
</tr>
))}
</tbody>
</table>
</div>
) : (
<div className="flow-step-empty" style={{ background: '#f6ffed', borderColor: '#b7eb8f', borderStyle: 'solid' }}>
<CheckCircleOutlined style={{ color: '#52c41a' }} />
<span style={{ color: '#52c41a' }}>无敏感词被替换</span>
</div>
)}
</div>
</div>
{/* Step 3: 最终请求体 */}
<div className="flow-step">
<div className="flow-step-number">3</div>
<div className="flow-step-content">
<div className="flow-step-title">
<CodeOutlined />
<span>最终请求体</span>
</div>
{record.request_body ? (
<pre className="flow-pre json">{JSON.stringify(record.request_body, null, 2)}</pre>
) : (
<div className="flow-step-empty">无请求体</div>
)}
</div>
</div>
{/* Step 4: 调用结果 */}
<div className="flow-step">
<div className="flow-step-number">4</div>
<div className="flow-step-content">
<div className="flow-step-title">
{record.status === 'success' ? (
<CheckCircleOutlined style={{ color: 'var(--color-success)' }} />
) : record.status === 'failed' ? (
<CloseCircleOutlined style={{ color: 'var(--color-error)' }} />
) : (
<ClockCircleOutlined />
)}
<span>调用结果</span>
<Tag
color={CALL_STATUS_MAP[record.status]?.color || 'default'}
style={{ marginLeft: 8 }}
>
{CALL_STATUS_MAP[record.status]?.label || record.status}
</Tag>
</div>
{record.response_body ? (
<pre className="flow-pre json">{JSON.stringify(record.response_body, null, 2)}</pre>
) : record.status === 'failed' ? (
<pre className="flow-pre" style={{ color: 'var(--color-error)' }}>
{record.error_message || '未知错误'}
</pre>
) : (
<div className="flow-step-empty">
<ClockCircleOutlined />
<span>等待响应</span>
</div>
)}
</div>
</div>
</div>
</div>
</>
)}
{!detailLoading && !record && (
<Empty description="加载失败" style={{ marginTop: 60 }} />
)}
</Spin>
<style>{`
.call-assembly-drawer .ant-drawer-body {
padding: 20px 24px;
}
.assembly-section {
margin-bottom: 4px;
}
.assembly-section-header {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 16px;
}
.assembly-section-title {
font-size: 14px;
font-weight: 600;
color: var(--color-text-primary);
}
.assembly-descriptions .ant-descriptions-item-label {
font-size: 12px;
color: var(--color-text-muted);
font-weight: 500;
white-space: nowrap;
}
.assembly-descriptions .ant-descriptions-item-content {
font-size: 13px;
}
.assembly-flow {
display: flex;
flex-direction: column;
gap: 0;
position: relative;
padding-left: 0;
}
.flow-step {
display: flex;
gap: 16px;
position: relative;
padding-bottom: 24px;
}
.flow-step:last-child {
padding-bottom: 0;
}
.flow-step-number {
width: 28px;
height: 28px;
border-radius: 50%;
background: var(--color-primary);
color: #fff;
font-size: 13px;
font-weight: 600;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
position: relative;
z-index: 1;
}
.flow-step::before {
content: '';
position: absolute;
left: 13px;
top: 28px;
bottom: 0;
width: 2px;
background: var(--color-border-light);
}
.flow-step:last-child::before {
display: none;
}
.flow-step-content {
flex: 1;
min-width: 0;
}
.flow-step-title {
display: flex;
align-items: center;
gap: 6px;
font-weight: 600;
font-size: 13px;
color: var(--color-text-primary);
margin-bottom: 10px;
}
.flow-step-body {
background: var(--color-surface-subtle);
border: 1px solid var(--color-border-light);
border-radius: 8px;
padding: 12px 16px;
}
.template-info-row {
margin-bottom: 8px;
}
.template-info-row:last-child {
margin-bottom: 0;
}
.template-info-row label {
display: block;
font-size: 11px;
color: var(--color-text-muted);
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 2px;
}
.template-info-row > span,
.template-info-row > code {
font-size: 13px;
color: var(--color-text-primary);
}
.template-info-row > code {
font-family: var(--font-utility);
background: var(--color-surface);
padding: 1px 6px;
border-radius: 3px;
border: 1px solid var(--color-border-light);
}
.flow-pre {
margin: 0;
padding: 10px 14px;
background: var(--color-surface);
border: 1px solid var(--color-border-light);
border-radius: 6px;
font-family: var(--font-utility);
font-size: 12px;
line-height: 1.6;
color: var(--color-text-primary);
white-space: pre-wrap;
word-break: break-word;
max-height: 300px;
overflow-y: auto;
}
.flow-pre.json {
max-height: 400px;
}
.flow-step-empty {
display: flex;
align-items: center;
gap: 8px;
padding: 16px;
color: var(--color-text-muted);
font-size: 13px;
background: var(--color-surface-subtle);
border: 1px dashed var(--color-border-light);
border-radius: 6px;
}
.replacement-table {
width: 100%;
border-collapse: collapse;
font-size: 13px;
}
.replacement-table th {
text-align: left;
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.5px;
color: var(--color-text-muted);
font-weight: 500;
padding-bottom: 8px;
}
.replacement-table td {
padding: 6px 0;
border-top: 1px solid #d9f7be;
}
.replacement-word {
font-family: var(--font-utility);
background: #fff1f0;
color: #cf1322;
padding: 2px 8px;
border-radius: 3px;
border: 1px solid #ffa39e;
font-size: 12px;
}
.replacement-arrow {
color: var(--color-text-muted);
margin: 0 10px;
}
.replacement-target {
font-family: var(--font-utility);
background: #f6ffed;
color: #389e0d;
padding: 2px 8px;
border-radius: 3px;
border: 1px solid #b7eb8f;
font-size: 12px;
}
`}</style>
</Drawer>
);
}