plugin-agent-orchestrator 1.0.32 → 1.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -114
- package/dist/externalVersion.js +6 -6
- package/dist/server/collections/skill-executions.js +21 -0
- package/dist/server/plugin.js +132 -3
- package/dist/server/resources/agent-loop.js +1 -2
- package/dist/server/services/AgentLoopController.js +39 -1
- package/dist/server/services/AgentLoopService.js +3 -0
- package/dist/server/services/AgentRuntimeLifecycle.js +70 -0
- package/dist/server/services/FileManager.js +12 -0
- package/dist/server/services/NativeSubAgentObserver.js +20 -0
- package/dist/server/services/PlanningPromptService.js +95 -0
- package/dist/server/services/SandboxRunner.js +251 -56
- package/dist/server/services/TokenTracker.js +20 -0
- package/dist/server/services/WorkerEnvManager.js +76 -10
- package/dist/server/services/pythonGuardTemplate.js +105 -0
- package/dist/server/services/sandboxCapabilities.js +286 -0
- package/dist/server/skill-hub/plugin.js +98 -24
- package/dist/server/skill-hub/tasks/SkillExecutionTask.js +53 -11
- package/dist/server/utils/skill-settings.js +1 -1
- package/package.json +47 -47
- package/src/client-v2/components/AgentRunsTab.tsx +494 -494
- package/src/client-v2/components/TracingTab.tsx +432 -432
- package/src/client-v2/hooks/useApiRequest.ts +121 -121
- package/src/server/__tests__/agent-runtime-lifecycle.test.ts +46 -0
- package/src/server/__tests__/planning-prompt-service.test.ts +23 -0
- package/src/server/__tests__/skill-sandbox-worker-mode.test.ts +15 -0
- package/src/server/collections/skill-executions.ts +21 -0
- package/src/server/plugin.ts +151 -0
- package/src/server/resources/agent-loop.ts +1 -2
- package/src/server/resources/agent-monitor.ts +482 -482
- package/src/server/services/AgentLoopController.ts +50 -1
- package/src/server/services/AgentLoopService.ts +4 -0
- package/src/server/services/AgentRuntimeLifecycle.ts +64 -0
- package/src/server/services/ExecutionSpanService.ts +110 -110
- package/src/server/services/FileManager.ts +16 -1
- package/src/server/services/NativeSubAgentObserver.ts +528 -507
- package/src/server/services/PlanningPromptService.ts +72 -0
- package/src/server/services/SandboxRunner.ts +341 -74
- package/src/server/services/TokenTracker.ts +26 -0
- package/src/server/services/WorkerEnvManager.ts +95 -9
- package/src/server/services/pythonGuardTemplate.ts +87 -0
- package/src/server/services/sandboxCapabilities.ts +348 -0
- package/src/server/skill-hub/plugin.ts +106 -23
- package/src/server/skill-hub/tasks/SkillExecutionTask.ts +51 -6
- package/src/server/utils/skill-settings.ts +1 -0
|
@@ -1,432 +1,432 @@
|
|
|
1
|
-
import React, { useMemo, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Table,
|
|
4
|
-
Card,
|
|
5
|
-
Tag,
|
|
6
|
-
Typography,
|
|
7
|
-
Drawer,
|
|
8
|
-
Descriptions,
|
|
9
|
-
Alert,
|
|
10
|
-
Button,
|
|
11
|
-
Empty,
|
|
12
|
-
Space,
|
|
13
|
-
Timeline,
|
|
14
|
-
Collapse,
|
|
15
|
-
Spin,
|
|
16
|
-
Select,
|
|
17
|
-
DatePicker,
|
|
18
|
-
Form,
|
|
19
|
-
} from 'antd';
|
|
20
|
-
import { EyeOutlined, CheckCircleOutlined, CloseCircleOutlined, ReloadOutlined } from '@ant-design/icons';
|
|
21
|
-
import { useApiClient as useAPIClient, useRequest } from '../hooks/useApiRequest';
|
|
22
|
-
import { useAIEmployees } from './AIEmployeesContext';
|
|
23
|
-
|
|
24
|
-
const { Text, Paragraph } = Typography;
|
|
25
|
-
const { RangePicker } = DatePicker;
|
|
26
|
-
|
|
27
|
-
type FilterState = {
|
|
28
|
-
leader?: string;
|
|
29
|
-
subAgent?: string;
|
|
30
|
-
status?: string;
|
|
31
|
-
range?: [any, any] | null;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const TracingTab: React.FC = () => {
|
|
35
|
-
const api = useAPIClient();
|
|
36
|
-
const [selectedLog, setSelectedLog] = useState<any>(null);
|
|
37
|
-
const [detailLoading, setDetailLoading] = useState(false);
|
|
38
|
-
|
|
39
|
-
const [page, setPage] = useState(1);
|
|
40
|
-
const [pageSize, setPageSize] = useState(20);
|
|
41
|
-
const [filters, setFilters] = useState<FilterState>({});
|
|
42
|
-
|
|
43
|
-
const { employees, employeeMap } = useAIEmployees();
|
|
44
|
-
|
|
45
|
-
const requestParams = useMemo(() => {
|
|
46
|
-
const filter: any = {};
|
|
47
|
-
if (filters.leader) filter.leaderUsername = filters.leader;
|
|
48
|
-
if (filters.subAgent) filter.subAgentUsername = filters.subAgent;
|
|
49
|
-
if (filters.status) filter.status = filters.status;
|
|
50
|
-
if (filters.range && (filters.range[0] || filters.range[1])) {
|
|
51
|
-
filter.createdAt = {};
|
|
52
|
-
if (filters.range[0]) filter.createdAt.$gte = filters.range[0].toDate().toISOString();
|
|
53
|
-
if (filters.range[1]) filter.createdAt.$lte = filters.range[1].toDate().toISOString();
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
sort: ['-createdAt'],
|
|
57
|
-
page,
|
|
58
|
-
pageSize,
|
|
59
|
-
filter,
|
|
60
|
-
};
|
|
61
|
-
}, [page, pageSize, filters]);
|
|
62
|
-
|
|
63
|
-
const { data, loading, refresh } = useRequest(
|
|
64
|
-
{
|
|
65
|
-
url: 'orchestratorTracing:list',
|
|
66
|
-
params: requestParams,
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
refreshDeps: [requestParams],
|
|
70
|
-
},
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
// Server returns { data: rows, meta: { count } }; useRequest unwraps to that shape.
|
|
74
|
-
const logs = useMemo(() => {
|
|
75
|
-
const rows = (data as any)?.data;
|
|
76
|
-
return Array.isArray(rows) ? rows : [];
|
|
77
|
-
}, [data]);
|
|
78
|
-
|
|
79
|
-
const total = useMemo(() => {
|
|
80
|
-
const count = (data as any)?.meta?.count;
|
|
81
|
-
return typeof count === 'number' ? count : 0;
|
|
82
|
-
}, [data]);
|
|
83
|
-
|
|
84
|
-
const formatDuration = (ms: number) => {
|
|
85
|
-
if (!ms) return '-';
|
|
86
|
-
return ms >= 1000 ? `${(ms / 1000).toFixed(1)}s` : `${ms}ms`;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const handleOpenLog = async (record: any) => {
|
|
90
|
-
setSelectedLog(record);
|
|
91
|
-
setDetailLoading(true);
|
|
92
|
-
try {
|
|
93
|
-
const res = await api.request({
|
|
94
|
-
url: 'orchestratorTracing:get',
|
|
95
|
-
params: { filterByTk: record.id, source: record.hasUnifiedTrace ? 'span' : 'log' },
|
|
96
|
-
});
|
|
97
|
-
setSelectedLog((res as any)?.data?.data?.data || (res as any)?.data?.data || record);
|
|
98
|
-
} finally {
|
|
99
|
-
setDetailLoading(false);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const updateFilter = (patch: Partial<FilterState>) => {
|
|
104
|
-
setFilters((prev) => ({ ...prev, ...patch }));
|
|
105
|
-
setPage(1);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const resetFilters = () => {
|
|
109
|
-
setFilters({});
|
|
110
|
-
setPage(1);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const employeeOptions = useMemo(
|
|
114
|
-
() =>
|
|
115
|
-
employees.map((e) => ({
|
|
116
|
-
label: e.nickname || e.username,
|
|
117
|
-
value: e.username,
|
|
118
|
-
})),
|
|
119
|
-
[employees],
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
const hasFilters = Boolean(
|
|
123
|
-
filters.leader || filters.subAgent || filters.status || (filters.range && (filters.range[0] || filters.range[1])),
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
const columns = [
|
|
127
|
-
{
|
|
128
|
-
title: 'Time',
|
|
129
|
-
dataIndex: 'createdAt',
|
|
130
|
-
key: 'createdAt',
|
|
131
|
-
width: 170,
|
|
132
|
-
render: (v: string) => (v ? new Date(v).toLocaleString() : '-'),
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
title: 'Leader',
|
|
136
|
-
dataIndex: 'leaderUsername',
|
|
137
|
-
key: 'leaderUsername',
|
|
138
|
-
render: (username: string) => <Tag color="blue">{employeeMap.get(username) || username}</Tag>,
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
title: 'Sub-Agent',
|
|
142
|
-
dataIndex: 'subAgentUsername',
|
|
143
|
-
key: 'subAgentUsername',
|
|
144
|
-
render: (username: string) => <Tag color="green">{employeeMap.get(username) || username}</Tag>,
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
title: 'Task',
|
|
148
|
-
dataIndex: 'task',
|
|
149
|
-
key: 'task',
|
|
150
|
-
render: (task: string) => (
|
|
151
|
-
<Text ellipsis style={{ maxWidth: 280 }}>
|
|
152
|
-
{task?.substring(0, 100) || '-'}
|
|
153
|
-
</Text>
|
|
154
|
-
),
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
title: 'Status',
|
|
158
|
-
dataIndex: 'status',
|
|
159
|
-
key: 'status',
|
|
160
|
-
width: 90,
|
|
161
|
-
render: (status: string) => (
|
|
162
|
-
<Tag
|
|
163
|
-
icon={status === 'success' ? <CheckCircleOutlined /> : <CloseCircleOutlined />}
|
|
164
|
-
color={status === 'success' ? 'success' : 'error'}
|
|
165
|
-
>
|
|
166
|
-
{status}
|
|
167
|
-
</Tag>
|
|
168
|
-
),
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
title: 'Duration',
|
|
172
|
-
dataIndex: 'durationMs',
|
|
173
|
-
key: 'durationMs',
|
|
174
|
-
width: 90,
|
|
175
|
-
render: formatDuration,
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
title: 'Depth',
|
|
179
|
-
dataIndex: 'depth',
|
|
180
|
-
key: 'depth',
|
|
181
|
-
width: 60,
|
|
182
|
-
render: (v: number) => v ?? 0,
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
title: '',
|
|
186
|
-
key: 'actions',
|
|
187
|
-
width: 80,
|
|
188
|
-
render: (_: any, record: any) => (
|
|
189
|
-
<Button type="link" size="small" icon={<EyeOutlined />} onClick={() => handleOpenLog(record)}>
|
|
190
|
-
Detail
|
|
191
|
-
</Button>
|
|
192
|
-
),
|
|
193
|
-
},
|
|
194
|
-
];
|
|
195
|
-
|
|
196
|
-
return (
|
|
197
|
-
<div>
|
|
198
|
-
<Alert
|
|
199
|
-
type="info"
|
|
200
|
-
showIcon
|
|
201
|
-
style={{ marginBottom: 16 }}
|
|
202
|
-
message="Execution Tracing"
|
|
203
|
-
description={
|
|
204
|
-
<Text type="secondary">
|
|
205
|
-
View orchestration execution logs. Each row represents one sub-agent invocation, with child tool and Skill
|
|
206
|
-
Hub executions shown in the detail flow.
|
|
207
|
-
</Text>
|
|
208
|
-
}
|
|
209
|
-
/>
|
|
210
|
-
|
|
211
|
-
<Card bordered={false}>
|
|
212
|
-
<Form layout="inline" style={{ marginBottom: 16, rowGap: 8, flexWrap: 'wrap' }}>
|
|
213
|
-
<Form.Item label="Leader">
|
|
214
|
-
<Select
|
|
215
|
-
allowClear
|
|
216
|
-
placeholder="Any leader"
|
|
217
|
-
style={{ minWidth: 180 }}
|
|
218
|
-
options={employeeOptions}
|
|
219
|
-
value={filters.leader}
|
|
220
|
-
onChange={(v) => updateFilter({ leader: v })}
|
|
221
|
-
showSearch
|
|
222
|
-
optionFilterProp="label"
|
|
223
|
-
/>
|
|
224
|
-
</Form.Item>
|
|
225
|
-
<Form.Item label="Sub-Agent">
|
|
226
|
-
<Select
|
|
227
|
-
allowClear
|
|
228
|
-
placeholder="Any sub-agent"
|
|
229
|
-
style={{ minWidth: 180 }}
|
|
230
|
-
options={employeeOptions}
|
|
231
|
-
value={filters.subAgent}
|
|
232
|
-
onChange={(v) => updateFilter({ subAgent: v })}
|
|
233
|
-
showSearch
|
|
234
|
-
optionFilterProp="label"
|
|
235
|
-
/>
|
|
236
|
-
</Form.Item>
|
|
237
|
-
<Form.Item label="Status">
|
|
238
|
-
<Select
|
|
239
|
-
allowClear
|
|
240
|
-
placeholder="Any status"
|
|
241
|
-
style={{ minWidth: 140 }}
|
|
242
|
-
options={[
|
|
243
|
-
{ label: 'Success', value: 'success' },
|
|
244
|
-
{ label: 'Error', value: 'error' },
|
|
245
|
-
{ label: 'Running', value: 'running' },
|
|
246
|
-
]}
|
|
247
|
-
value={filters.status}
|
|
248
|
-
onChange={(v) => updateFilter({ status: v })}
|
|
249
|
-
/>
|
|
250
|
-
</Form.Item>
|
|
251
|
-
<Form.Item label="Time">
|
|
252
|
-
<RangePicker showTime value={filters.range as any} onChange={(v) => updateFilter({ range: v as any })} />
|
|
253
|
-
</Form.Item>
|
|
254
|
-
<Form.Item>
|
|
255
|
-
<Space>
|
|
256
|
-
<Button onClick={resetFilters} disabled={!hasFilters}>
|
|
257
|
-
Reset
|
|
258
|
-
</Button>
|
|
259
|
-
<Button icon={<ReloadOutlined />} onClick={refresh}>
|
|
260
|
-
Refresh
|
|
261
|
-
</Button>
|
|
262
|
-
</Space>
|
|
263
|
-
</Form.Item>
|
|
264
|
-
</Form>
|
|
265
|
-
|
|
266
|
-
<Table
|
|
267
|
-
rowKey="id"
|
|
268
|
-
loading={loading}
|
|
269
|
-
dataSource={logs}
|
|
270
|
-
columns={columns}
|
|
271
|
-
size="middle"
|
|
272
|
-
scroll={{ x: 'max-content' }}
|
|
273
|
-
pagination={{
|
|
274
|
-
current: page,
|
|
275
|
-
pageSize,
|
|
276
|
-
total,
|
|
277
|
-
showSizeChanger: true,
|
|
278
|
-
pageSizeOptions: [10, 20, 50, 100],
|
|
279
|
-
showTotal: (count) => `${count} execution${count === 1 ? '' : 's'}`,
|
|
280
|
-
onChange: (nextPage, nextSize) => {
|
|
281
|
-
setPage(nextPage);
|
|
282
|
-
if (nextSize && nextSize !== pageSize) setPageSize(nextSize);
|
|
283
|
-
},
|
|
284
|
-
}}
|
|
285
|
-
locale={{
|
|
286
|
-
emptyText: (
|
|
287
|
-
<Empty
|
|
288
|
-
description={hasFilters ? 'No executions match the current filters' : 'No delegation executions yet'}
|
|
289
|
-
/>
|
|
290
|
-
),
|
|
291
|
-
}}
|
|
292
|
-
/>
|
|
293
|
-
</Card>
|
|
294
|
-
|
|
295
|
-
<Drawer title="Execution Detail" width={820} onClose={() => setSelectedLog(null)} open={!!selectedLog}>
|
|
296
|
-
{selectedLog && (
|
|
297
|
-
<Spin spinning={detailLoading}>
|
|
298
|
-
<>
|
|
299
|
-
<Descriptions column={1} bordered size="small" style={{ marginBottom: 16 }}>
|
|
300
|
-
<Descriptions.Item label="Status">
|
|
301
|
-
<Tag
|
|
302
|
-
icon={selectedLog.status === 'success' ? <CheckCircleOutlined /> : <CloseCircleOutlined />}
|
|
303
|
-
color={selectedLog.status === 'success' ? 'success' : 'error'}
|
|
304
|
-
>
|
|
305
|
-
{selectedLog.status}
|
|
306
|
-
</Tag>
|
|
307
|
-
</Descriptions.Item>
|
|
308
|
-
<Descriptions.Item label="Leader">
|
|
309
|
-
<Tag color="blue">{employeeMap.get(selectedLog.leaderUsername) || selectedLog.leaderUsername}</Tag>
|
|
310
|
-
</Descriptions.Item>
|
|
311
|
-
<Descriptions.Item label="Sub-Agent">
|
|
312
|
-
<Tag color="green">
|
|
313
|
-
{employeeMap.get(selectedLog.subAgentUsername) || selectedLog.subAgentUsername}
|
|
314
|
-
</Tag>
|
|
315
|
-
</Descriptions.Item>
|
|
316
|
-
<Descriptions.Item label="Tool">
|
|
317
|
-
<Text code>{selectedLog.toolName}</Text>
|
|
318
|
-
</Descriptions.Item>
|
|
319
|
-
<Descriptions.Item label="Depth">{selectedLog.depth ?? 0}</Descriptions.Item>
|
|
320
|
-
<Descriptions.Item label="Duration">{formatDuration(selectedLog.durationMs)}</Descriptions.Item>
|
|
321
|
-
<Descriptions.Item label="Time">
|
|
322
|
-
{selectedLog.createdAt ? new Date(selectedLog.createdAt).toLocaleString() : '-'}
|
|
323
|
-
</Descriptions.Item>
|
|
324
|
-
</Descriptions>
|
|
325
|
-
|
|
326
|
-
<Card title="Task" size="small" style={{ marginBottom: 16 }}>
|
|
327
|
-
<Paragraph style={{ whiteSpace: 'pre-wrap', margin: 0, fontSize: 13 }}>
|
|
328
|
-
{selectedLog.task || 'No task description'}
|
|
329
|
-
</Paragraph>
|
|
330
|
-
</Card>
|
|
331
|
-
|
|
332
|
-
{selectedLog.context && (
|
|
333
|
-
<Card title="Context" size="small" style={{ marginBottom: 16 }}>
|
|
334
|
-
<Paragraph style={{ whiteSpace: 'pre-wrap', margin: 0, fontSize: 13 }}>
|
|
335
|
-
{selectedLog.context}
|
|
336
|
-
</Paragraph>
|
|
337
|
-
</Card>
|
|
338
|
-
)}
|
|
339
|
-
|
|
340
|
-
<Card title="Execution Flow" size="small" style={{ marginBottom: 16 }}>
|
|
341
|
-
{Array.isArray(selectedLog.trace) && selectedLog.trace.length ? (
|
|
342
|
-
<Timeline
|
|
343
|
-
items={selectedLog.trace.map((item: any, index: number) => ({
|
|
344
|
-
key: index,
|
|
345
|
-
color: item.status === 'error' ? 'red' : item.type === 'tool_call' ? 'blue' : 'green',
|
|
346
|
-
children: (
|
|
347
|
-
<div>
|
|
348
|
-
<Space direction="vertical" size={2} style={{ width: '100%' }}>
|
|
349
|
-
<Text strong>{item.title || item.type}</Text>
|
|
350
|
-
<Text type="secondary">{item.at ? new Date(item.at).toLocaleString() : ''}</Text>
|
|
351
|
-
{item.toolName && <Text code>{item.toolName}</Text>}
|
|
352
|
-
{item.skillExecutionId && (
|
|
353
|
-
<Text type="secondary">Skill execution #{item.skillExecutionId}</Text>
|
|
354
|
-
)}
|
|
355
|
-
{item.content && (
|
|
356
|
-
<Paragraph style={{ whiteSpace: 'pre-wrap', margin: 0, fontSize: 13 }}>
|
|
357
|
-
{item.content}
|
|
358
|
-
</Paragraph>
|
|
359
|
-
)}
|
|
360
|
-
{item.args && (
|
|
361
|
-
<Paragraph style={{ whiteSpace: 'pre-wrap', margin: 0, fontSize: 12 }}>
|
|
362
|
-
{JSON.stringify(item.args, null, 2)}
|
|
363
|
-
</Paragraph>
|
|
364
|
-
)}
|
|
365
|
-
</Space>
|
|
366
|
-
</div>
|
|
367
|
-
),
|
|
368
|
-
}))}
|
|
369
|
-
/>
|
|
370
|
-
) : (
|
|
371
|
-
<Empty description="No execution flow captured" />
|
|
372
|
-
)}
|
|
373
|
-
</Card>
|
|
374
|
-
|
|
375
|
-
{Array.isArray(selectedLog.messages) && selectedLog.messages.length > 0 && (
|
|
376
|
-
<Collapse
|
|
377
|
-
style={{ marginBottom: 16 }}
|
|
378
|
-
items={[
|
|
379
|
-
{
|
|
380
|
-
key: 'messages',
|
|
381
|
-
label: `Raw messages (${selectedLog.messages.length})`,
|
|
382
|
-
children: (
|
|
383
|
-
<Space direction="vertical" style={{ width: '100%' }}>
|
|
384
|
-
{selectedLog.messages.map((message: any) => (
|
|
385
|
-
<Card key={message.index} size="small" title={`${message.index + 1}. ${message.type}`}>
|
|
386
|
-
<Paragraph style={{ whiteSpace: 'pre-wrap', margin: 0, fontSize: 12 }}>
|
|
387
|
-
{message.content || JSON.stringify(message.toolCalls || message, null, 2)}
|
|
388
|
-
</Paragraph>
|
|
389
|
-
{message.toolCalls?.length > 0 && (
|
|
390
|
-
<Paragraph style={{ whiteSpace: 'pre-wrap', margin: '8px 0 0', fontSize: 12 }}>
|
|
391
|
-
{JSON.stringify(message.toolCalls, null, 2)}
|
|
392
|
-
</Paragraph>
|
|
393
|
-
)}
|
|
394
|
-
</Card>
|
|
395
|
-
))}
|
|
396
|
-
</Space>
|
|
397
|
-
),
|
|
398
|
-
},
|
|
399
|
-
]}
|
|
400
|
-
/>
|
|
401
|
-
)}
|
|
402
|
-
|
|
403
|
-
<Card
|
|
404
|
-
title="Result"
|
|
405
|
-
size="small"
|
|
406
|
-
style={{
|
|
407
|
-
marginBottom: 16,
|
|
408
|
-
borderColor: selectedLog.status === 'success' ? '#b7eb8f' : '#ffa39e',
|
|
409
|
-
}}
|
|
410
|
-
>
|
|
411
|
-
<Paragraph
|
|
412
|
-
style={{ whiteSpace: 'pre-wrap', margin: 0, fontSize: 13 }}
|
|
413
|
-
ellipsis={{ rows: 20, expandable: true }}
|
|
414
|
-
>
|
|
415
|
-
{selectedLog.result || selectedLog.error || 'No result'}
|
|
416
|
-
</Paragraph>
|
|
417
|
-
</Card>
|
|
418
|
-
|
|
419
|
-
{selectedLog.error && (
|
|
420
|
-
<Card title="Error" size="small" style={{ borderColor: '#ffa39e' }}>
|
|
421
|
-
<Paragraph type="danger" style={{ whiteSpace: 'pre-wrap', margin: 0, fontSize: 13 }}>
|
|
422
|
-
{selectedLog.error}
|
|
423
|
-
</Paragraph>
|
|
424
|
-
</Card>
|
|
425
|
-
)}
|
|
426
|
-
</>
|
|
427
|
-
</Spin>
|
|
428
|
-
)}
|
|
429
|
-
</Drawer>
|
|
430
|
-
</div>
|
|
431
|
-
);
|
|
432
|
-
};
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Table,
|
|
4
|
+
Card,
|
|
5
|
+
Tag,
|
|
6
|
+
Typography,
|
|
7
|
+
Drawer,
|
|
8
|
+
Descriptions,
|
|
9
|
+
Alert,
|
|
10
|
+
Button,
|
|
11
|
+
Empty,
|
|
12
|
+
Space,
|
|
13
|
+
Timeline,
|
|
14
|
+
Collapse,
|
|
15
|
+
Spin,
|
|
16
|
+
Select,
|
|
17
|
+
DatePicker,
|
|
18
|
+
Form,
|
|
19
|
+
} from 'antd';
|
|
20
|
+
import { EyeOutlined, CheckCircleOutlined, CloseCircleOutlined, ReloadOutlined } from '@ant-design/icons';
|
|
21
|
+
import { useApiClient as useAPIClient, useRequest } from '../hooks/useApiRequest';
|
|
22
|
+
import { useAIEmployees } from './AIEmployeesContext';
|
|
23
|
+
|
|
24
|
+
const { Text, Paragraph } = Typography;
|
|
25
|
+
const { RangePicker } = DatePicker;
|
|
26
|
+
|
|
27
|
+
type FilterState = {
|
|
28
|
+
leader?: string;
|
|
29
|
+
subAgent?: string;
|
|
30
|
+
status?: string;
|
|
31
|
+
range?: [any, any] | null;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const TracingTab: React.FC = () => {
|
|
35
|
+
const api = useAPIClient();
|
|
36
|
+
const [selectedLog, setSelectedLog] = useState<any>(null);
|
|
37
|
+
const [detailLoading, setDetailLoading] = useState(false);
|
|
38
|
+
|
|
39
|
+
const [page, setPage] = useState(1);
|
|
40
|
+
const [pageSize, setPageSize] = useState(20);
|
|
41
|
+
const [filters, setFilters] = useState<FilterState>({});
|
|
42
|
+
|
|
43
|
+
const { employees, employeeMap } = useAIEmployees();
|
|
44
|
+
|
|
45
|
+
const requestParams = useMemo(() => {
|
|
46
|
+
const filter: any = {};
|
|
47
|
+
if (filters.leader) filter.leaderUsername = filters.leader;
|
|
48
|
+
if (filters.subAgent) filter.subAgentUsername = filters.subAgent;
|
|
49
|
+
if (filters.status) filter.status = filters.status;
|
|
50
|
+
if (filters.range && (filters.range[0] || filters.range[1])) {
|
|
51
|
+
filter.createdAt = {};
|
|
52
|
+
if (filters.range[0]) filter.createdAt.$gte = filters.range[0].toDate().toISOString();
|
|
53
|
+
if (filters.range[1]) filter.createdAt.$lte = filters.range[1].toDate().toISOString();
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
sort: ['-createdAt'],
|
|
57
|
+
page,
|
|
58
|
+
pageSize,
|
|
59
|
+
filter,
|
|
60
|
+
};
|
|
61
|
+
}, [page, pageSize, filters]);
|
|
62
|
+
|
|
63
|
+
const { data, loading, refresh } = useRequest(
|
|
64
|
+
{
|
|
65
|
+
url: 'orchestratorTracing:list',
|
|
66
|
+
params: requestParams,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
refreshDeps: [requestParams],
|
|
70
|
+
},
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
// Server returns { data: rows, meta: { count } }; useRequest unwraps to that shape.
|
|
74
|
+
const logs = useMemo(() => {
|
|
75
|
+
const rows = (data as any)?.data;
|
|
76
|
+
return Array.isArray(rows) ? rows : [];
|
|
77
|
+
}, [data]);
|
|
78
|
+
|
|
79
|
+
const total = useMemo(() => {
|
|
80
|
+
const count = (data as any)?.meta?.count;
|
|
81
|
+
return typeof count === 'number' ? count : 0;
|
|
82
|
+
}, [data]);
|
|
83
|
+
|
|
84
|
+
const formatDuration = (ms: number) => {
|
|
85
|
+
if (!ms) return '-';
|
|
86
|
+
return ms >= 1000 ? `${(ms / 1000).toFixed(1)}s` : `${ms}ms`;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const handleOpenLog = async (record: any) => {
|
|
90
|
+
setSelectedLog(record);
|
|
91
|
+
setDetailLoading(true);
|
|
92
|
+
try {
|
|
93
|
+
const res = await api.request({
|
|
94
|
+
url: 'orchestratorTracing:get',
|
|
95
|
+
params: { filterByTk: record.id, source: record.hasUnifiedTrace ? 'span' : 'log' },
|
|
96
|
+
});
|
|
97
|
+
setSelectedLog((res as any)?.data?.data?.data || (res as any)?.data?.data || record);
|
|
98
|
+
} finally {
|
|
99
|
+
setDetailLoading(false);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const updateFilter = (patch: Partial<FilterState>) => {
|
|
104
|
+
setFilters((prev) => ({ ...prev, ...patch }));
|
|
105
|
+
setPage(1);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const resetFilters = () => {
|
|
109
|
+
setFilters({});
|
|
110
|
+
setPage(1);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const employeeOptions = useMemo(
|
|
114
|
+
() =>
|
|
115
|
+
employees.map((e) => ({
|
|
116
|
+
label: e.nickname || e.username,
|
|
117
|
+
value: e.username,
|
|
118
|
+
})),
|
|
119
|
+
[employees],
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const hasFilters = Boolean(
|
|
123
|
+
filters.leader || filters.subAgent || filters.status || (filters.range && (filters.range[0] || filters.range[1])),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const columns = [
|
|
127
|
+
{
|
|
128
|
+
title: 'Time',
|
|
129
|
+
dataIndex: 'createdAt',
|
|
130
|
+
key: 'createdAt',
|
|
131
|
+
width: 170,
|
|
132
|
+
render: (v: string) => (v ? new Date(v).toLocaleString() : '-'),
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
title: 'Leader',
|
|
136
|
+
dataIndex: 'leaderUsername',
|
|
137
|
+
key: 'leaderUsername',
|
|
138
|
+
render: (username: string) => <Tag color="blue">{employeeMap.get(username) || username}</Tag>,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
title: 'Sub-Agent',
|
|
142
|
+
dataIndex: 'subAgentUsername',
|
|
143
|
+
key: 'subAgentUsername',
|
|
144
|
+
render: (username: string) => <Tag color="green">{employeeMap.get(username) || username}</Tag>,
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
title: 'Task',
|
|
148
|
+
dataIndex: 'task',
|
|
149
|
+
key: 'task',
|
|
150
|
+
render: (task: string) => (
|
|
151
|
+
<Text ellipsis style={{ maxWidth: 280 }}>
|
|
152
|
+
{task?.substring(0, 100) || '-'}
|
|
153
|
+
</Text>
|
|
154
|
+
),
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
title: 'Status',
|
|
158
|
+
dataIndex: 'status',
|
|
159
|
+
key: 'status',
|
|
160
|
+
width: 90,
|
|
161
|
+
render: (status: string) => (
|
|
162
|
+
<Tag
|
|
163
|
+
icon={status === 'success' ? <CheckCircleOutlined /> : <CloseCircleOutlined />}
|
|
164
|
+
color={status === 'success' ? 'success' : 'error'}
|
|
165
|
+
>
|
|
166
|
+
{status}
|
|
167
|
+
</Tag>
|
|
168
|
+
),
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
title: 'Duration',
|
|
172
|
+
dataIndex: 'durationMs',
|
|
173
|
+
key: 'durationMs',
|
|
174
|
+
width: 90,
|
|
175
|
+
render: formatDuration,
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
title: 'Depth',
|
|
179
|
+
dataIndex: 'depth',
|
|
180
|
+
key: 'depth',
|
|
181
|
+
width: 60,
|
|
182
|
+
render: (v: number) => v ?? 0,
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
title: '',
|
|
186
|
+
key: 'actions',
|
|
187
|
+
width: 80,
|
|
188
|
+
render: (_: any, record: any) => (
|
|
189
|
+
<Button type="link" size="small" icon={<EyeOutlined />} onClick={() => handleOpenLog(record)}>
|
|
190
|
+
Detail
|
|
191
|
+
</Button>
|
|
192
|
+
),
|
|
193
|
+
},
|
|
194
|
+
];
|
|
195
|
+
|
|
196
|
+
return (
|
|
197
|
+
<div>
|
|
198
|
+
<Alert
|
|
199
|
+
type="info"
|
|
200
|
+
showIcon
|
|
201
|
+
style={{ marginBottom: 16 }}
|
|
202
|
+
message="Execution Tracing"
|
|
203
|
+
description={
|
|
204
|
+
<Text type="secondary">
|
|
205
|
+
View orchestration execution logs. Each row represents one sub-agent invocation, with child tool and Skill
|
|
206
|
+
Hub executions shown in the detail flow.
|
|
207
|
+
</Text>
|
|
208
|
+
}
|
|
209
|
+
/>
|
|
210
|
+
|
|
211
|
+
<Card bordered={false}>
|
|
212
|
+
<Form layout="inline" style={{ marginBottom: 16, rowGap: 8, flexWrap: 'wrap' }}>
|
|
213
|
+
<Form.Item label="Leader">
|
|
214
|
+
<Select
|
|
215
|
+
allowClear
|
|
216
|
+
placeholder="Any leader"
|
|
217
|
+
style={{ minWidth: 180 }}
|
|
218
|
+
options={employeeOptions}
|
|
219
|
+
value={filters.leader}
|
|
220
|
+
onChange={(v) => updateFilter({ leader: v })}
|
|
221
|
+
showSearch
|
|
222
|
+
optionFilterProp="label"
|
|
223
|
+
/>
|
|
224
|
+
</Form.Item>
|
|
225
|
+
<Form.Item label="Sub-Agent">
|
|
226
|
+
<Select
|
|
227
|
+
allowClear
|
|
228
|
+
placeholder="Any sub-agent"
|
|
229
|
+
style={{ minWidth: 180 }}
|
|
230
|
+
options={employeeOptions}
|
|
231
|
+
value={filters.subAgent}
|
|
232
|
+
onChange={(v) => updateFilter({ subAgent: v })}
|
|
233
|
+
showSearch
|
|
234
|
+
optionFilterProp="label"
|
|
235
|
+
/>
|
|
236
|
+
</Form.Item>
|
|
237
|
+
<Form.Item label="Status">
|
|
238
|
+
<Select
|
|
239
|
+
allowClear
|
|
240
|
+
placeholder="Any status"
|
|
241
|
+
style={{ minWidth: 140 }}
|
|
242
|
+
options={[
|
|
243
|
+
{ label: 'Success', value: 'success' },
|
|
244
|
+
{ label: 'Error', value: 'error' },
|
|
245
|
+
{ label: 'Running', value: 'running' },
|
|
246
|
+
]}
|
|
247
|
+
value={filters.status}
|
|
248
|
+
onChange={(v) => updateFilter({ status: v })}
|
|
249
|
+
/>
|
|
250
|
+
</Form.Item>
|
|
251
|
+
<Form.Item label="Time">
|
|
252
|
+
<RangePicker showTime value={filters.range as any} onChange={(v) => updateFilter({ range: v as any })} />
|
|
253
|
+
</Form.Item>
|
|
254
|
+
<Form.Item>
|
|
255
|
+
<Space>
|
|
256
|
+
<Button onClick={resetFilters} disabled={!hasFilters}>
|
|
257
|
+
Reset
|
|
258
|
+
</Button>
|
|
259
|
+
<Button icon={<ReloadOutlined />} onClick={refresh}>
|
|
260
|
+
Refresh
|
|
261
|
+
</Button>
|
|
262
|
+
</Space>
|
|
263
|
+
</Form.Item>
|
|
264
|
+
</Form>
|
|
265
|
+
|
|
266
|
+
<Table
|
|
267
|
+
rowKey="id"
|
|
268
|
+
loading={loading}
|
|
269
|
+
dataSource={logs}
|
|
270
|
+
columns={columns}
|
|
271
|
+
size="middle"
|
|
272
|
+
scroll={{ x: 'max-content' }}
|
|
273
|
+
pagination={{
|
|
274
|
+
current: page,
|
|
275
|
+
pageSize,
|
|
276
|
+
total,
|
|
277
|
+
showSizeChanger: true,
|
|
278
|
+
pageSizeOptions: [10, 20, 50, 100],
|
|
279
|
+
showTotal: (count) => `${count} execution${count === 1 ? '' : 's'}`,
|
|
280
|
+
onChange: (nextPage, nextSize) => {
|
|
281
|
+
setPage(nextPage);
|
|
282
|
+
if (nextSize && nextSize !== pageSize) setPageSize(nextSize);
|
|
283
|
+
},
|
|
284
|
+
}}
|
|
285
|
+
locale={{
|
|
286
|
+
emptyText: (
|
|
287
|
+
<Empty
|
|
288
|
+
description={hasFilters ? 'No executions match the current filters' : 'No delegation executions yet'}
|
|
289
|
+
/>
|
|
290
|
+
),
|
|
291
|
+
}}
|
|
292
|
+
/>
|
|
293
|
+
</Card>
|
|
294
|
+
|
|
295
|
+
<Drawer title="Execution Detail" width={820} onClose={() => setSelectedLog(null)} open={!!selectedLog}>
|
|
296
|
+
{selectedLog && (
|
|
297
|
+
<Spin spinning={detailLoading}>
|
|
298
|
+
<>
|
|
299
|
+
<Descriptions column={1} bordered size="small" style={{ marginBottom: 16 }}>
|
|
300
|
+
<Descriptions.Item label="Status">
|
|
301
|
+
<Tag
|
|
302
|
+
icon={selectedLog.status === 'success' ? <CheckCircleOutlined /> : <CloseCircleOutlined />}
|
|
303
|
+
color={selectedLog.status === 'success' ? 'success' : 'error'}
|
|
304
|
+
>
|
|
305
|
+
{selectedLog.status}
|
|
306
|
+
</Tag>
|
|
307
|
+
</Descriptions.Item>
|
|
308
|
+
<Descriptions.Item label="Leader">
|
|
309
|
+
<Tag color="blue">{employeeMap.get(selectedLog.leaderUsername) || selectedLog.leaderUsername}</Tag>
|
|
310
|
+
</Descriptions.Item>
|
|
311
|
+
<Descriptions.Item label="Sub-Agent">
|
|
312
|
+
<Tag color="green">
|
|
313
|
+
{employeeMap.get(selectedLog.subAgentUsername) || selectedLog.subAgentUsername}
|
|
314
|
+
</Tag>
|
|
315
|
+
</Descriptions.Item>
|
|
316
|
+
<Descriptions.Item label="Tool">
|
|
317
|
+
<Text code>{selectedLog.toolName}</Text>
|
|
318
|
+
</Descriptions.Item>
|
|
319
|
+
<Descriptions.Item label="Depth">{selectedLog.depth ?? 0}</Descriptions.Item>
|
|
320
|
+
<Descriptions.Item label="Duration">{formatDuration(selectedLog.durationMs)}</Descriptions.Item>
|
|
321
|
+
<Descriptions.Item label="Time">
|
|
322
|
+
{selectedLog.createdAt ? new Date(selectedLog.createdAt).toLocaleString() : '-'}
|
|
323
|
+
</Descriptions.Item>
|
|
324
|
+
</Descriptions>
|
|
325
|
+
|
|
326
|
+
<Card title="Task" size="small" style={{ marginBottom: 16 }}>
|
|
327
|
+
<Paragraph style={{ whiteSpace: 'pre-wrap', margin: 0, fontSize: 13 }}>
|
|
328
|
+
{selectedLog.task || 'No task description'}
|
|
329
|
+
</Paragraph>
|
|
330
|
+
</Card>
|
|
331
|
+
|
|
332
|
+
{selectedLog.context && (
|
|
333
|
+
<Card title="Context" size="small" style={{ marginBottom: 16 }}>
|
|
334
|
+
<Paragraph style={{ whiteSpace: 'pre-wrap', margin: 0, fontSize: 13 }}>
|
|
335
|
+
{selectedLog.context}
|
|
336
|
+
</Paragraph>
|
|
337
|
+
</Card>
|
|
338
|
+
)}
|
|
339
|
+
|
|
340
|
+
<Card title="Execution Flow" size="small" style={{ marginBottom: 16 }}>
|
|
341
|
+
{Array.isArray(selectedLog.trace) && selectedLog.trace.length ? (
|
|
342
|
+
<Timeline
|
|
343
|
+
items={selectedLog.trace.map((item: any, index: number) => ({
|
|
344
|
+
key: index,
|
|
345
|
+
color: item.status === 'error' ? 'red' : item.type === 'tool_call' ? 'blue' : 'green',
|
|
346
|
+
children: (
|
|
347
|
+
<div>
|
|
348
|
+
<Space direction="vertical" size={2} style={{ width: '100%' }}>
|
|
349
|
+
<Text strong>{item.title || item.type}</Text>
|
|
350
|
+
<Text type="secondary">{item.at ? new Date(item.at).toLocaleString() : ''}</Text>
|
|
351
|
+
{item.toolName && <Text code>{item.toolName}</Text>}
|
|
352
|
+
{item.skillExecutionId && (
|
|
353
|
+
<Text type="secondary">Skill execution #{item.skillExecutionId}</Text>
|
|
354
|
+
)}
|
|
355
|
+
{item.content && (
|
|
356
|
+
<Paragraph style={{ whiteSpace: 'pre-wrap', margin: 0, fontSize: 13 }}>
|
|
357
|
+
{item.content}
|
|
358
|
+
</Paragraph>
|
|
359
|
+
)}
|
|
360
|
+
{item.args && (
|
|
361
|
+
<Paragraph style={{ whiteSpace: 'pre-wrap', margin: 0, fontSize: 12 }}>
|
|
362
|
+
{JSON.stringify(item.args, null, 2)}
|
|
363
|
+
</Paragraph>
|
|
364
|
+
)}
|
|
365
|
+
</Space>
|
|
366
|
+
</div>
|
|
367
|
+
),
|
|
368
|
+
}))}
|
|
369
|
+
/>
|
|
370
|
+
) : (
|
|
371
|
+
<Empty description="No execution flow captured" />
|
|
372
|
+
)}
|
|
373
|
+
</Card>
|
|
374
|
+
|
|
375
|
+
{Array.isArray(selectedLog.messages) && selectedLog.messages.length > 0 && (
|
|
376
|
+
<Collapse
|
|
377
|
+
style={{ marginBottom: 16 }}
|
|
378
|
+
items={[
|
|
379
|
+
{
|
|
380
|
+
key: 'messages',
|
|
381
|
+
label: `Raw messages (${selectedLog.messages.length})`,
|
|
382
|
+
children: (
|
|
383
|
+
<Space direction="vertical" style={{ width: '100%' }}>
|
|
384
|
+
{selectedLog.messages.map((message: any) => (
|
|
385
|
+
<Card key={message.index} size="small" title={`${message.index + 1}. ${message.type}`}>
|
|
386
|
+
<Paragraph style={{ whiteSpace: 'pre-wrap', margin: 0, fontSize: 12 }}>
|
|
387
|
+
{message.content || JSON.stringify(message.toolCalls || message, null, 2)}
|
|
388
|
+
</Paragraph>
|
|
389
|
+
{message.toolCalls?.length > 0 && (
|
|
390
|
+
<Paragraph style={{ whiteSpace: 'pre-wrap', margin: '8px 0 0', fontSize: 12 }}>
|
|
391
|
+
{JSON.stringify(message.toolCalls, null, 2)}
|
|
392
|
+
</Paragraph>
|
|
393
|
+
)}
|
|
394
|
+
</Card>
|
|
395
|
+
))}
|
|
396
|
+
</Space>
|
|
397
|
+
),
|
|
398
|
+
},
|
|
399
|
+
]}
|
|
400
|
+
/>
|
|
401
|
+
)}
|
|
402
|
+
|
|
403
|
+
<Card
|
|
404
|
+
title="Result"
|
|
405
|
+
size="small"
|
|
406
|
+
style={{
|
|
407
|
+
marginBottom: 16,
|
|
408
|
+
borderColor: selectedLog.status === 'success' ? '#b7eb8f' : '#ffa39e',
|
|
409
|
+
}}
|
|
410
|
+
>
|
|
411
|
+
<Paragraph
|
|
412
|
+
style={{ whiteSpace: 'pre-wrap', margin: 0, fontSize: 13 }}
|
|
413
|
+
ellipsis={{ rows: 20, expandable: true }}
|
|
414
|
+
>
|
|
415
|
+
{selectedLog.result || selectedLog.error || 'No result'}
|
|
416
|
+
</Paragraph>
|
|
417
|
+
</Card>
|
|
418
|
+
|
|
419
|
+
{selectedLog.error && (
|
|
420
|
+
<Card title="Error" size="small" style={{ borderColor: '#ffa39e' }}>
|
|
421
|
+
<Paragraph type="danger" style={{ whiteSpace: 'pre-wrap', margin: 0, fontSize: 13 }}>
|
|
422
|
+
{selectedLog.error}
|
|
423
|
+
</Paragraph>
|
|
424
|
+
</Card>
|
|
425
|
+
)}
|
|
426
|
+
</>
|
|
427
|
+
</Spin>
|
|
428
|
+
)}
|
|
429
|
+
</Drawer>
|
|
430
|
+
</div>
|
|
431
|
+
);
|
|
432
|
+
};
|