DebugResult.tsx
5.06 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
import { Spin, Tag, Empty, Typography, Button } from 'antd';
import {
CheckCircleOutlined,
CloseCircleOutlined,
ClockCircleOutlined,
LoadingOutlined,
ReloadOutlined,
} from '@ant-design/icons';
import type { CallResultData } from './DebugConsole';
const { Text, Paragraph } = Typography;
interface DebugResultProps {
result: CallResultData | null;
loading: boolean;
onQueryAsync?: (taskId: string) => void;
}
/** 格式化 JSON 为带缩进的字符串 */
function formatJson(data: Record<string, unknown> | null): string {
if (!data) return '';
try {
return JSON.stringify(data, null, 2);
} catch {
return String(data);
}
}
export default function DebugResult({ result, loading, onQueryAsync }: DebugResultProps) {
const renderStatusTag = () => {
if (!result) return null;
switch (result.status) {
case 'success':
return (
<Tag icon={<CheckCircleOutlined />} color="success">
调用成功
</Tag>
);
case 'error':
return (
<Tag icon={<CloseCircleOutlined />} color="error">
调用失败
</Tag>
);
case 'accepted':
return (
<Tag icon={<ClockCircleOutlined />} color="processing">
任务已提交
</Tag>
);
default:
return <Tag>{result.status}</Tag>;
}
};
// Loading state
if (loading) {
return (
<div className="debug-result-container">
<div className="debug-result-header">
<Text strong>调用结果</Text>
</div>
<div className="debug-result-body" style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: 300 }}>
<Spin indicator={<LoadingOutlined style={{ fontSize: 32 }} spin />} tip="调用中..." />
</div>
</div>
);
}
// Empty state
if (!result) {
return (
<div className="debug-result-container">
<div className="debug-result-header">
<Text strong>调用结果</Text>
</div>
<div className="debug-result-body">
<Empty description="配置左侧参数后发起调用" />
</div>
</div>
);
}
return (
<div className="debug-result-container">
<div className="debug-result-header">
<Text strong>调用结果</Text>
<div className="debug-result-meta">
{renderStatusTag()}
{result.modelName && (
<Text type="secondary" style={{ fontSize: 12 }}>
模型: {result.modelName}
</Text>
)}
</div>
</div>
<div className="debug-result-body">
{/* Async task info */}
{result.callType === 'async' && result.taskId && (
<div className="debug-log-panel">
<div className="debug-log-title">任务信息</div>
<div className="debug-log-line">
<span className="debug-log-step">Task ID</span>
<code>{result.taskId}</code>
</div>
<div className="debug-log-line">
<span className="debug-log-step">状态</span>
<span>
{result.status === 'accepted' ? '等待处理...' : result.status === 'success' ? '已完成' : result.status}
</span>
</div>
{onQueryAsync && (
<div style={{ marginTop: 8 }}>
<Button
size="small"
icon={<ReloadOutlined />}
onClick={() => onQueryAsync(result.taskId!)}
loading={loading}
>
查询结果
</Button>
</div>
)}
</div>
)}
{/* Response Content (from by-template) */}
{result.responseContent && (
<div className="debug-json-panel">
<div className="debug-json-title">响应内容</div>
<pre className="debug-json-content">
<code>{result.responseContent}</code>
</pre>
</div>
)}
{/* Response Body (from orchestrate) */}
{result.responseBody && (
<div className="debug-json-panel">
<div className="debug-json-title">响应 Body</div>
<pre className="debug-json-content">
<code>{formatJson(result.responseBody)}</code>
</pre>
</div>
)}
{/* Error message */}
{result.errorMessage && (
<div className="debug-log-panel" style={{ borderColor: '#ffccc7' }}>
<div className="debug-log-title" style={{ color: '#f43f5e' }}>错误信息</div>
<Paragraph style={{ color: '#f43f5e', marginBottom: 0 }}>
{result.errorMessage}
</Paragraph>
</div>
)}
{/* Execution Log */}
{result.executionLog && (
<div className="debug-log-panel">
<div className="debug-log-title">执行日志</div>
<pre className="debug-log-content">
<code>{result.executionLog}</code>
</pre>
</div>
)}
</div>
</div>
);
}