plugin-agent-orchestrator 1.1.4 → 1.1.5

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.
Files changed (148) hide show
  1. package/README.md +204 -114
  2. package/dist/client/index.js +1 -1
  3. package/dist/client-v2/117.7565cff57c39318a.js +10 -0
  4. package/dist/client-v2/214.106635011859dede.js +10 -0
  5. package/dist/client-v2/418.41ed200e7d6da332.js +10 -0
  6. package/dist/client-v2/53.349fff8db80b19d4.js +10 -0
  7. package/dist/client-v2/981.e4a1f41cfc94a856.js +10 -0
  8. package/dist/client-v2/index.js +1 -1
  9. package/dist/externalVersion.js +7 -8
  10. package/dist/locale/en-US.json +226 -170
  11. package/dist/locale/vi-VN.json +226 -170
  12. package/dist/locale/zh-CN.json +226 -170
  13. package/dist/server/collections/agent-execution-spans.js +8 -0
  14. package/dist/server/collections/agent-loop-action-approvals.js +1 -0
  15. package/dist/server/collections/agent-loop-runs.js +7 -1
  16. package/dist/server/collections/agent-loop-steps.js +7 -0
  17. package/dist/server/collections/skill-executions.js +8 -0
  18. package/dist/server/plugin.js +3 -1
  19. package/dist/server/resources/agent-harness-profile.js +117 -0
  20. package/dist/server/resources/agent-knowledge-insights.js +1 -3
  21. package/dist/server/resources/agent-loop-approval.js +25 -0
  22. package/dist/server/resources/agent-loop.js +3 -1
  23. package/dist/server/services/AgentMemoryContextService.js +34 -0
  24. package/dist/server/services/HarnessCompiler.js +35 -2
  25. package/dist/server/services/HarnessProfileService.js +74 -9
  26. package/dist/server/services/HarnessSchema.js +30 -3
  27. package/dist/server/services/LoopPatternSchema.js +16 -1
  28. package/dist/server/services/LoopRunRepository.js +80 -0
  29. package/dist/server/services/LoopRunStateMachine.js +92 -3
  30. package/dist/server/services/LoopTriggerService.js +37 -0
  31. package/dist/server/services/LoopWorkerService.js +261 -23
  32. package/dist/server/services/NativeSubAgentObserver.js +165 -23
  33. package/dist/server/services/PluginAiRuntimeAdapter.js +16 -5
  34. package/dist/server/services/ToolLoopDetectionService.js +210 -0
  35. package/dist/server/services/VerificationService.js +66 -0
  36. package/dist/server/services/harness-runtime-policy.js +139 -0
  37. package/dist/server/skill-hub/plugin.js +36 -3
  38. package/dist/server/skill-hub/tasks/SkillExecutionTask.js +29 -0
  39. package/package.json +53 -53
  40. package/src/client/ApprovalsTab.tsx +2 -0
  41. package/src/client/OrchestratorSettings.tsx +11 -0
  42. package/src/client/skill-hub/components/GitSkillImport.tsx +3 -3
  43. package/src/client/skill-hub/components/SkillMetrics.tsx +15 -10
  44. package/src/client/skill-hub/index.tsx +0 -52
  45. package/src/client-v2/components/AgentRunsTab.tsx +576 -576
  46. package/src/client-v2/components/ApprovalsTab.tsx +337 -0
  47. package/src/client-v2/components/HarnessProfilesTab.tsx +385 -105
  48. package/src/client-v2/components/MemoryInspectorTab.tsx +141 -141
  49. package/src/client-v2/components/TracingTab.tsx +515 -515
  50. package/src/client-v2/hooks/useApiRequest.ts +141 -141
  51. package/src/client-v2/pages/ApprovalsPage.tsx +10 -0
  52. package/src/client-v2/plugin.tsx +6 -6
  53. package/src/client-v2/skill-hub/components/SkillMetrics.tsx +5 -2
  54. package/src/locale/en-US.json +226 -174
  55. package/src/locale/vi-VN.json +226 -174
  56. package/src/locale/zh-CN.json +226 -174
  57. package/src/server/__tests__/circuit-breaker.test.ts +248 -248
  58. package/src/server/__tests__/harness-compiler.test.ts +83 -0
  59. package/src/server/__tests__/harness-profile-service.test.ts +51 -0
  60. package/src/server/__tests__/harness-runtime-policy.test.ts +293 -0
  61. package/src/server/__tests__/harness-tool-plan.test.ts +24 -0
  62. package/src/server/__tests__/loop-approval-decision.test.ts +512 -0
  63. package/src/server/__tests__/loop-approval-expiry.test.ts +258 -0
  64. package/src/server/__tests__/loop-budget-service.test.ts +255 -255
  65. package/src/server/__tests__/loop-control-plane-backfill.test.ts +266 -266
  66. package/src/server/__tests__/loop-pattern-schema.test.ts +18 -1
  67. package/src/server/__tests__/loop-pattern-service.test.ts +148 -148
  68. package/src/server/__tests__/loop-run-state-machine.test.ts +11 -0
  69. package/src/server/__tests__/loop-trigger-service.test.ts +148 -0
  70. package/src/server/__tests__/loop-worker-claim.test.ts +341 -341
  71. package/src/server/__tests__/loop-worker-execution.test.ts +82 -1
  72. package/src/server/__tests__/native-sub-agent-observer.test.ts +288 -4
  73. package/src/server/__tests__/path-lock-service.test.ts +254 -254
  74. package/src/server/__tests__/skill-execution-task-policy.test.ts +140 -0
  75. package/src/server/__tests__/smoke.test.ts +162 -162
  76. package/src/server/__tests__/tool-loop-detection.test.ts +275 -0
  77. package/src/server/collections/agent-execution-spans.ts +8 -0
  78. package/src/server/collections/agent-harness-profile-versions.ts +26 -26
  79. package/src/server/collections/agent-harness-profiles.ts +71 -71
  80. package/src/server/collections/agent-loop-action-approvals.ts +1 -0
  81. package/src/server/collections/agent-loop-artifacts.ts +25 -25
  82. package/src/server/collections/agent-loop-circuit-states.ts +23 -23
  83. package/src/server/collections/agent-loop-control-settings.ts +21 -21
  84. package/src/server/collections/agent-loop-events.ts +98 -98
  85. package/src/server/collections/agent-loop-path-locks.ts +27 -27
  86. package/src/server/collections/agent-loop-patterns.ts +42 -42
  87. package/src/server/collections/agent-loop-runs.ts +7 -1
  88. package/src/server/collections/agent-loop-steps.ts +7 -0
  89. package/src/server/collections/agent-loop-usage-buckets.ts +22 -22
  90. package/src/server/collections/agent-loop-worktrees.ts +25 -25
  91. package/src/server/collections/skill-executions.ts +8 -0
  92. package/src/server/migrations/20260427000002-change-packages-to-text.ts +52 -52
  93. package/src/server/migrations/20260429000000-add-llm-fields.ts +47 -47
  94. package/src/server/migrations/20260429000001-fix-inputargs-json-to-text.ts +45 -45
  95. package/src/server/migrations/20260503000000-add-orchestrator-trace-fields.ts +33 -33
  96. package/src/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.ts +31 -31
  97. package/src/server/migrations/20260803010000-backfill-loop-control-plane-data.ts +293 -293
  98. package/src/server/plugin.ts +3 -1
  99. package/src/server/resources/agent-harness-profile.ts +94 -0
  100. package/src/server/resources/agent-knowledge-insights.ts +5 -3
  101. package/src/server/resources/agent-loop-approval.ts +32 -0
  102. package/src/server/resources/agent-loop-artifact.ts +56 -56
  103. package/src/server/resources/agent-loop-events-stream.ts +105 -105
  104. package/src/server/resources/agent-loop.ts +3 -1
  105. package/src/server/resources/resource-helpers.ts +33 -33
  106. package/src/server/resources/tracing.ts +266 -266
  107. package/src/server/services/AgentMemoryContextService.ts +44 -0
  108. package/src/server/services/DurableCircuitBreakerService.ts +239 -239
  109. package/src/server/services/ExecutionSpanService.ts +2 -0
  110. package/src/server/services/HarnessCompiler.ts +37 -0
  111. package/src/server/services/HarnessProfileService.ts +92 -10
  112. package/src/server/services/HarnessSchema.ts +31 -0
  113. package/src/server/services/LoopBudgetService.ts +275 -275
  114. package/src/server/services/LoopControlService.ts +124 -124
  115. package/src/server/services/LoopPatternSchema.ts +19 -1
  116. package/src/server/services/LoopPatternService.ts +143 -143
  117. package/src/server/services/LoopRunRepository.ts +99 -0
  118. package/src/server/services/LoopRunStateMachine.ts +100 -3
  119. package/src/server/services/LoopSchedulerService.ts +199 -199
  120. package/src/server/services/LoopTriggerService.ts +42 -0
  121. package/src/server/services/LoopWorkerService.ts +327 -27
  122. package/src/server/services/NativeSubAgentObserver.ts +186 -21
  123. package/src/server/services/PathLockService.ts +321 -321
  124. package/src/server/services/PluginAiRuntimeAdapter.ts +24 -7
  125. package/src/server/services/ToolLoopDetectionService.ts +213 -0
  126. package/src/server/services/VerificationSchema.ts +31 -31
  127. package/src/server/services/VerificationService.ts +81 -2
  128. package/src/server/services/harness-runtime-policy.ts +141 -0
  129. package/src/server/skill-hub/plugin.ts +41 -3
  130. package/src/server/skill-hub/services/RegistrySkillSnapshotService.ts +235 -235
  131. package/src/server/skill-hub/services/__tests__/RegistrySkillSnapshotService.test.ts +61 -61
  132. package/src/server/skill-hub/tasks/SkillExecutionTask.ts +43 -2
  133. package/src/server/utils/ensure-indexes.ts +96 -96
  134. package/src/server/utils/logging.ts +62 -62
  135. package/src/server/utils/loop-pattern-context.ts +20 -20
  136. package/dist/client-v2/214.b063f33ba044a808.js +0 -10
  137. package/dist/client-v2/373.f5d5292e53c4e832.js +0 -10
  138. package/dist/client-v2/418.58fa350f5496efd3.js +0 -10
  139. package/dist/client-v2/53.9a10455323390f14.js +0 -10
  140. package/dist/client-v2/677.a991ce0250ff5c77.js +0 -10
  141. package/dist/client-v2/925.e5925bf21ed68e7a.js +0 -10
  142. package/src/client/AIEmployeeSelect.tsx +0 -47
  143. package/src/client/AIEmployeesContext.tsx +0 -102
  144. package/src/client/RulesTab.tsx +0 -2
  145. package/src/client/TracingTab.tsx +0 -436
  146. package/src/client/skill-hub/components/ExecutionProgress.tsx +0 -51
  147. package/src/client-v2/components/RulesTab.tsx +0 -2
  148. package/src/client-v2/pages/AgentRunsPage.tsx +0 -13
@@ -1,576 +1,576 @@
1
- import React, { useMemo, useRef, useState } from 'react';
2
- import {
3
- Alert,
4
- Button,
5
- Card,
6
- Collapse,
7
- Descriptions,
8
- Drawer,
9
- Empty,
10
- Form,
11
- message,
12
- Select,
13
- Space,
14
- Spin,
15
- Table,
16
- Tag,
17
- Timeline,
18
- Typography,
19
- } from 'antd';
20
- import { CheckCircleOutlined, CloseCircleOutlined, EyeOutlined, ReloadOutlined, SyncOutlined } from '@ant-design/icons';
21
- import { useApiClient as useAPIClient, useRequest } from '../hooks/useApiRequest';
22
- import { useAIEmployees } from './AIEmployeesContext';
23
- import { useT } from '../skill-hub/locale';
24
-
25
- const { Paragraph, Text } = Typography;
26
-
27
- type FilterState = {
28
- leader?: string;
29
- subAgent?: string;
30
- status?: string;
31
- };
32
-
33
- type TraceItem = {
34
- id?: number | string;
35
- type?: string;
36
- title?: string;
37
- status?: string;
38
- toolName?: string;
39
- durationMs?: number;
40
- at?: string;
41
- content?: unknown;
42
- };
43
-
44
- type ToolMessage = {
45
- sessionId?: string;
46
- toolCallId?: string;
47
- toolName?: string;
48
- status?: string;
49
- invokeStatus?: string;
50
- content?: unknown;
51
- };
52
-
53
- type NativeMessage = {
54
- sessionId?: string;
55
- messageId?: string | number;
56
- role?: string;
57
- content?: unknown;
58
- metadata?: unknown;
59
- };
60
-
61
- type RunRecord = {
62
- id: number | string;
63
- createdAt?: string;
64
- startedAt?: string;
65
- endedAt?: string;
66
- leaderUsername?: string;
67
- subAgentUsername?: string;
68
- task?: string;
69
- status?: string;
70
- durationMs?: number;
71
- memoryContextApplied?: boolean;
72
- harnessTag?: string;
73
- parentSessionId?: string;
74
- subSessionId?: string;
75
- toolCallId?: string;
76
- input?: { question?: string };
77
- output?: unknown;
78
- error?: unknown;
79
- metadata?: unknown;
80
- trace?: TraceItem[];
81
- toolMessages?: ToolMessage[];
82
- nativeMessages?: NativeMessage[];
83
- };
84
-
85
- type ListResponse = {
86
- data?: RunRecord[];
87
- meta?: { count?: number };
88
- };
89
-
90
- type RequestError = {
91
- response?: { data?: { errors?: Array<{ message?: string }> } };
92
- message?: string;
93
- };
94
-
95
- function statusColor(status?: string) {
96
- switch (status) {
97
- case 'success':
98
- return 'success';
99
- case 'error':
100
- return 'error';
101
- case 'running':
102
- return 'processing';
103
- default:
104
- return 'default';
105
- }
106
- }
107
-
108
- function statusIcon(status?: string) {
109
- if (status === 'success') return <CheckCircleOutlined />;
110
- if (status === 'error') return <CloseCircleOutlined />;
111
- return undefined;
112
- }
113
-
114
- function StatusTag({ status }: { status?: string }) {
115
- return (
116
- <Tag color={statusColor(status)} icon={statusIcon(status)}>
117
- {status || '-'}
118
- </Tag>
119
- );
120
- }
121
-
122
- function formatDate(value?: string) {
123
- return value ? new Date(value).toLocaleString() : '-';
124
- }
125
-
126
- function formatDurationMs(value?: number) {
127
- if (!value) return '-';
128
- if (value >= 60000) return `${Math.round(value / 60000)}m`;
129
- if (value >= 1000) return `${(value / 1000).toFixed(1)}s`;
130
- return `${value}ms`;
131
- }
132
-
133
- function formatJson(value: unknown) {
134
- if (value === undefined || value === null || value === '') return '';
135
- if (typeof value === 'string') return value;
136
- try {
137
- return JSON.stringify(value, null, 2);
138
- } catch {
139
- return String(value);
140
- }
141
- }
142
-
143
- function TextBlock({ value, rows = 8 }: { value: unknown; rows?: number }) {
144
- const text = formatJson(value);
145
- if (!text) return <Text type="secondary">-</Text>;
146
- return (
147
- <Paragraph
148
- style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word', margin: 0, fontSize: 12 }}
149
- ellipsis={{ rows, expandable: true }}
150
- >
151
- {text}
152
- </Paragraph>
153
- );
154
- }
155
-
156
- export const AgentRunsTab: React.FC = () => {
157
- const api = useAPIClient();
158
- const t = useT();
159
- const { employees, employeeMap } = useAIEmployees();
160
- const [filters, setFilters] = useState<FilterState>({});
161
- const [page, setPage] = useState(1);
162
- const [pageSize, setPageSize] = useState(20);
163
- const [selectedRun, setSelectedRun] = useState<RunRecord | null>(null);
164
- const [detailLoading, setDetailLoading] = useState(false);
165
- const [syncLoading, setSyncLoading] = useState(false);
166
- // Guards the detail drawer against out-of-order responses when the user
167
- // switches rows quickly: only the newest request may commit its result.
168
- const detailRequestId = useRef(0);
169
-
170
- const requestParams = useMemo(() => {
171
- const filter: Record<string, string> = {};
172
- if (filters.leader) filter.leaderUsername = filters.leader;
173
- if (filters.subAgent) filter.subAgentUsername = filters.subAgent;
174
- if (filters.status) filter.status = filters.status;
175
- return {
176
- sort: ['-createdAt'],
177
- page,
178
- pageSize,
179
- filter,
180
- };
181
- }, [filters, page, pageSize]);
182
-
183
- const { data, loading, refresh } = useRequest<ListResponse>(
184
- {
185
- url: 'agentMonitor:list',
186
- params: requestParams,
187
- },
188
- {
189
- refreshDeps: [requestParams],
190
- },
191
- );
192
-
193
- const runs = useMemo(() => {
194
- const rows = data?.data;
195
- return Array.isArray(rows) ? rows : [];
196
- }, [data]);
197
-
198
- const total = useMemo(() => {
199
- const count = data?.meta?.count;
200
- return typeof count === 'number' ? count : 0;
201
- }, [data]);
202
-
203
- const employeeOptions = useMemo(
204
- () =>
205
- employees.map((employee) => ({
206
- label: employee.nickname || employee.username,
207
- value: employee.username,
208
- })),
209
- [employees],
210
- );
211
-
212
- const updateFilter = (patch: Partial<FilterState>) => {
213
- setFilters((prev) => ({ ...prev, ...patch }));
214
- setPage(1);
215
- };
216
-
217
- const resetFilters = () => {
218
- setFilters({});
219
- setPage(1);
220
- };
221
-
222
- const fetchDetail = async (record: RunRecord) => {
223
- const requestId = ++detailRequestId.current;
224
- setSelectedRun(record);
225
- setDetailLoading(true);
226
- try {
227
- const res = await api.request({
228
- url: 'agentMonitor:get',
229
- params: { filterByTk: record.id },
230
- });
231
- if (requestId !== detailRequestId.current) return;
232
- const payload = res as { data?: { data?: { data?: RunRecord } | RunRecord } };
233
- const detail =
234
- (payload?.data?.data as { data?: RunRecord })?.data || (payload?.data?.data as RunRecord) || record;
235
- setSelectedRun(detail);
236
- } catch (error) {
237
- if (requestId !== detailRequestId.current) return;
238
- const text =
239
- (error as RequestError)?.response?.data?.errors?.[0]?.message ||
240
- (error as RequestError)?.message ||
241
- t('Failed to load run detail');
242
- message.error(text);
243
- } finally {
244
- if (requestId === detailRequestId.current) {
245
- setDetailLoading(false);
246
- }
247
- }
248
- };
249
-
250
- const syncNativeRuns = async () => {
251
- setSyncLoading(true);
252
- try {
253
- const res = await api.request({
254
- url: 'agentMonitor:sync',
255
- method: 'post',
256
- data: { limit: 500 },
257
- });
258
- const result = (res as { data?: { data?: { created?: number } } })?.data?.data || {};
259
- message.success(t('Synced {{count}} native runs', { count: result.created || 0 }));
260
- refresh();
261
- } catch (error) {
262
- const text =
263
- (error as RequestError)?.response?.data?.errors?.[0]?.message ||
264
- (error as RequestError)?.message ||
265
- t('Sync failed');
266
- message.error(text);
267
- } finally {
268
- setSyncLoading(false);
269
- }
270
- };
271
-
272
- const hasFilters = Boolean(filters.leader || filters.subAgent || filters.status);
273
- const trace: TraceItem[] = Array.isArray(selectedRun?.trace) ? selectedRun.trace : [];
274
- const toolMessages: ToolMessage[] = Array.isArray(selectedRun?.toolMessages) ? selectedRun.toolMessages : [];
275
- const nativeMessages: NativeMessage[] = Array.isArray(selectedRun?.nativeMessages) ? selectedRun.nativeMessages : [];
276
-
277
- const columns = [
278
- {
279
- title: t('Time'),
280
- dataIndex: 'createdAt',
281
- key: 'createdAt',
282
- width: 170,
283
- render: formatDate,
284
- },
285
- {
286
- title: t('Leader'),
287
- dataIndex: 'leaderUsername',
288
- key: 'leaderUsername',
289
- width: 160,
290
- render: (username: string) => <Tag color="blue">{employeeMap.get(username) || username || '-'}</Tag>,
291
- },
292
- {
293
- title: t('Sub-Agent'),
294
- dataIndex: 'subAgentUsername',
295
- key: 'subAgentUsername',
296
- width: 160,
297
- render: (username: string) => <Tag color="green">{employeeMap.get(username) || username || '-'}</Tag>,
298
- },
299
- {
300
- title: t('Task'),
301
- dataIndex: 'task',
302
- key: 'task',
303
- render: (task: string) => (
304
- <Text ellipsis style={{ maxWidth: 360 }}>
305
- {task || '-'}
306
- </Text>
307
- ),
308
- },
309
- {
310
- title: t('Status'),
311
- dataIndex: 'status',
312
- key: 'status',
313
- width: 110,
314
- render: (status: string) => <StatusTag status={status} />,
315
- },
316
- {
317
- title: t('Duration'),
318
- dataIndex: 'durationMs',
319
- key: 'durationMs',
320
- width: 100,
321
- render: formatDurationMs,
322
- },
323
- {
324
- title: t('Context'),
325
- dataIndex: 'memoryContextApplied',
326
- key: 'memoryContextApplied',
327
- width: 100,
328
- render: (applied: boolean) => (applied ? <Tag color="purple">memory</Tag> : <Text type="secondary">-</Text>),
329
- },
330
- {
331
- title: '',
332
- key: 'actions',
333
- width: 90,
334
- render: (_: unknown, record: RunRecord) => (
335
- <Button type="link" size="small" icon={<EyeOutlined />} onClick={() => fetchDetail(record)}>
336
- {t('Detail')}
337
- </Button>
338
- ),
339
- },
340
- ];
341
-
342
- return (
343
- <div>
344
- <Alert
345
- type="info"
346
- showIcon
347
- style={{ marginBottom: 16 }}
348
- message={t('Native Agent Runs')}
349
- description={
350
- <Text type="secondary">
351
- {t(
352
- 'Native plugin-ai sub-agent dispatches captured by the orchestrator observer. Execution still runs through AIEmployee/SubAgentsDispatcher.',
353
- )}
354
- </Text>
355
- }
356
- />
357
-
358
- <Card bordered={false}>
359
- <Form layout="inline" style={{ marginBottom: 16, rowGap: 8, flexWrap: 'wrap' }}>
360
- <Form.Item label={t('Leader')}>
361
- <Select
362
- allowClear
363
- showSearch
364
- optionFilterProp="label"
365
- placeholder={t('Any leader')}
366
- style={{ minWidth: 180 }}
367
- options={employeeOptions}
368
- value={filters.leader}
369
- onChange={(value) => updateFilter({ leader: value })}
370
- />
371
- </Form.Item>
372
- <Form.Item label={t('Sub-Agent')}>
373
- <Select
374
- allowClear
375
- showSearch
376
- optionFilterProp="label"
377
- placeholder={t('Any sub-agent')}
378
- style={{ minWidth: 180 }}
379
- options={employeeOptions}
380
- value={filters.subAgent}
381
- onChange={(value) => updateFilter({ subAgent: value })}
382
- />
383
- </Form.Item>
384
- <Form.Item label={t('Status')}>
385
- <Select
386
- allowClear
387
- placeholder={t('Any status')}
388
- style={{ minWidth: 140 }}
389
- value={filters.status}
390
- onChange={(value) => updateFilter({ status: value })}
391
- options={[
392
- { label: t('Running'), value: 'running' },
393
- { label: t('Success'), value: 'success' },
394
- { label: t('Error'), value: 'error' },
395
- ]}
396
- />
397
- </Form.Item>
398
- <Form.Item>
399
- <Space>
400
- <Button onClick={resetFilters} disabled={!hasFilters}>
401
- {t('Reset')}
402
- </Button>
403
- <Button icon={<ReloadOutlined />} onClick={refresh}>
404
- {t('Refresh')}
405
- </Button>
406
- <Button icon={<SyncOutlined />} onClick={syncNativeRuns} loading={syncLoading}>
407
- {t('Sync')}
408
- </Button>
409
- </Space>
410
- </Form.Item>
411
- </Form>
412
-
413
- <Table
414
- rowKey="id"
415
- loading={loading}
416
- dataSource={runs}
417
- columns={columns}
418
- scroll={{ x: 'max-content' }}
419
- pagination={{
420
- current: page,
421
- pageSize,
422
- total,
423
- showSizeChanger: true,
424
- pageSizeOptions: [10, 20, 50, 100],
425
- showTotal: (count) => t('{{count}} runs', { count }),
426
- onChange: (nextPage, nextSize) => {
427
- setPage(nextPage);
428
- if (nextSize && nextSize !== pageSize) setPageSize(nextSize);
429
- },
430
- }}
431
- locale={{
432
- emptyText: (
433
- <Empty description={hasFilters ? t('No runs match the current filters') : t('No native runs yet')} />
434
- ),
435
- }}
436
- />
437
- </Card>
438
-
439
- <Drawer title={t('Native Run Detail')} width={960} onClose={() => setSelectedRun(null)} open={!!selectedRun}>
440
- {selectedRun && (
441
- <Spin spinning={detailLoading}>
442
- <Space direction="vertical" size={16} style={{ width: '100%' }}>
443
- <Descriptions bordered size="small" column={2}>
444
- <Descriptions.Item label={t('Status')}>
445
- <StatusTag status={selectedRun.status} />
446
- </Descriptions.Item>
447
- <Descriptions.Item label={t('Harness')}>{selectedRun.harnessTag || 'default'}</Descriptions.Item>
448
- <Descriptions.Item label={t('Leader')}>
449
- <Tag color="blue">
450
- {employeeMap.get(selectedRun.leaderUsername) || selectedRun.leaderUsername || '-'}
451
- </Tag>
452
- </Descriptions.Item>
453
- <Descriptions.Item label={t('Sub-Agent')}>
454
- <Tag color="green">
455
- {employeeMap.get(selectedRun.subAgentUsername) || selectedRun.subAgentUsername || '-'}
456
- </Tag>
457
- </Descriptions.Item>
458
- <Descriptions.Item label={t('Parent session')}>
459
- <Text code>{selectedRun.parentSessionId || '-'}</Text>
460
- </Descriptions.Item>
461
- <Descriptions.Item label={t('Sub session')}>
462
- <Text code>{selectedRun.subSessionId || '-'}</Text>
463
- </Descriptions.Item>
464
- <Descriptions.Item label={t('Tool call')}>
465
- <Text code>{selectedRun.toolCallId || '-'}</Text>
466
- </Descriptions.Item>
467
- <Descriptions.Item label={t('Duration')}>{formatDurationMs(selectedRun.durationMs)}</Descriptions.Item>
468
- <Descriptions.Item label={t('Started')}>
469
- {formatDate(selectedRun.startedAt || selectedRun.createdAt)}
470
- </Descriptions.Item>
471
- <Descriptions.Item label={t('Ended')}>{formatDate(selectedRun.endedAt)}</Descriptions.Item>
472
- </Descriptions>
473
-
474
- <Card title={t('Task')} size="small">
475
- <TextBlock value={selectedRun.task || selectedRun.input?.question} rows={6} />
476
- </Card>
477
-
478
- <Card title={t('Execution Flow')} size="small">
479
- {trace.length ? (
480
- <Timeline
481
- items={trace.map((item: TraceItem) => ({
482
- key: item.id,
483
- color: item.status === 'error' ? 'red' : item.status === 'running' ? 'blue' : 'green',
484
- children: (
485
- <Space direction="vertical" size={2} style={{ width: '100%' }}>
486
- <Space wrap>
487
- <Text strong>{item.title || item.type}</Text>
488
- <Tag>{item.type}</Tag>
489
- <StatusTag status={item.status} />
490
- {item.toolName && <Text code>{item.toolName}</Text>}
491
- {item.durationMs ? <Text type="secondary">{formatDurationMs(item.durationMs)}</Text> : null}
492
- </Space>
493
- <Text type="secondary">{formatDate(item.at)}</Text>
494
- {item.content ? <TextBlock value={item.content} rows={4} /> : null}
495
- </Space>
496
- ),
497
- }))}
498
- />
499
- ) : (
500
- <Empty description={t('No execution flow captured')} />
501
- )}
502
- </Card>
503
-
504
- <Collapse
505
- items={[
506
- {
507
- key: 'toolMessages',
508
- label: t('Native tool messages ({{count}})', { count: toolMessages.length }),
509
- children: toolMessages.length ? (
510
- <Table
511
- rowKey={(record: ToolMessage) => `${record.sessionId}:${record.toolCallId}`}
512
- size="small"
513
- pagination={false}
514
- dataSource={toolMessages}
515
- scroll={{ x: 'max-content' }}
516
- columns={[
517
- { title: t('Session'), dataIndex: 'sessionId', key: 'sessionId' },
518
- { title: t('Tool'), dataIndex: 'toolName', key: 'toolName' },
519
- {
520
- title: t('Status'),
521
- dataIndex: 'status',
522
- key: 'status',
523
- render: (value: string) => <StatusTag status={value === 'error' ? 'error' : value} />,
524
- },
525
- { title: t('Invoke'), dataIndex: 'invokeStatus', key: 'invokeStatus' },
526
- {
527
- title: t('Content'),
528
- dataIndex: 'content',
529
- key: 'content',
530
- render: (value: unknown) => <TextBlock value={value} rows={3} />,
531
- },
532
- ]}
533
- />
534
- ) : (
535
- <Empty description={t('No native tool messages')} />
536
- ),
537
- },
538
- {
539
- key: 'messages',
540
- label: t('Native messages ({{count}})', { count: nativeMessages.length }),
541
- children: nativeMessages.length ? (
542
- <Space direction="vertical" size={8} style={{ width: '100%' }}>
543
- {nativeMessages.map((item: NativeMessage) => (
544
- <Card
545
- key={`${item.sessionId}:${item.messageId}`}
546
- size="small"
547
- title={`${item.role} #${item.messageId}`}
548
- >
549
- <TextBlock value={item.content || item.metadata} rows={6} />
550
- </Card>
551
- ))}
552
- </Space>
553
- ) : (
554
- <Empty description={t('No native messages loaded')} />
555
- ),
556
- },
557
- {
558
- key: 'metadata',
559
- label: t('Monitor metadata'),
560
- children: <TextBlock value={selectedRun.metadata} rows={10} />,
561
- },
562
- ]}
563
- />
564
-
565
- {(selectedRun.output || selectedRun.error) && (
566
- <Card title={selectedRun.error ? t('Error') : t('Result')} size="small">
567
- <TextBlock value={selectedRun.error || selectedRun.output} rows={12} />
568
- </Card>
569
- )}
570
- </Space>
571
- </Spin>
572
- )}
573
- </Drawer>
574
- </div>
575
- );
576
- };
1
+ import React, { useMemo, useRef, useState } from 'react';
2
+ import {
3
+ Alert,
4
+ Button,
5
+ Card,
6
+ Collapse,
7
+ Descriptions,
8
+ Drawer,
9
+ Empty,
10
+ Form,
11
+ message,
12
+ Select,
13
+ Space,
14
+ Spin,
15
+ Table,
16
+ Tag,
17
+ Timeline,
18
+ Typography,
19
+ } from 'antd';
20
+ import { CheckCircleOutlined, CloseCircleOutlined, EyeOutlined, ReloadOutlined, SyncOutlined } from '@ant-design/icons';
21
+ import { useApiClient as useAPIClient, useRequest } from '../hooks/useApiRequest';
22
+ import { useAIEmployees } from './AIEmployeesContext';
23
+ import { useT } from '../skill-hub/locale';
24
+
25
+ const { Paragraph, Text } = Typography;
26
+
27
+ type FilterState = {
28
+ leader?: string;
29
+ subAgent?: string;
30
+ status?: string;
31
+ };
32
+
33
+ type TraceItem = {
34
+ id?: number | string;
35
+ type?: string;
36
+ title?: string;
37
+ status?: string;
38
+ toolName?: string;
39
+ durationMs?: number;
40
+ at?: string;
41
+ content?: unknown;
42
+ };
43
+
44
+ type ToolMessage = {
45
+ sessionId?: string;
46
+ toolCallId?: string;
47
+ toolName?: string;
48
+ status?: string;
49
+ invokeStatus?: string;
50
+ content?: unknown;
51
+ };
52
+
53
+ type NativeMessage = {
54
+ sessionId?: string;
55
+ messageId?: string | number;
56
+ role?: string;
57
+ content?: unknown;
58
+ metadata?: unknown;
59
+ };
60
+
61
+ type RunRecord = {
62
+ id: number | string;
63
+ createdAt?: string;
64
+ startedAt?: string;
65
+ endedAt?: string;
66
+ leaderUsername?: string;
67
+ subAgentUsername?: string;
68
+ task?: string;
69
+ status?: string;
70
+ durationMs?: number;
71
+ memoryContextApplied?: boolean;
72
+ harnessTag?: string;
73
+ parentSessionId?: string;
74
+ subSessionId?: string;
75
+ toolCallId?: string;
76
+ input?: { question?: string };
77
+ output?: unknown;
78
+ error?: unknown;
79
+ metadata?: unknown;
80
+ trace?: TraceItem[];
81
+ toolMessages?: ToolMessage[];
82
+ nativeMessages?: NativeMessage[];
83
+ };
84
+
85
+ type ListResponse = {
86
+ data?: RunRecord[];
87
+ meta?: { count?: number };
88
+ };
89
+
90
+ type RequestError = {
91
+ response?: { data?: { errors?: Array<{ message?: string }> } };
92
+ message?: string;
93
+ };
94
+
95
+ function statusColor(status?: string) {
96
+ switch (status) {
97
+ case 'success':
98
+ return 'success';
99
+ case 'error':
100
+ return 'error';
101
+ case 'running':
102
+ return 'processing';
103
+ default:
104
+ return 'default';
105
+ }
106
+ }
107
+
108
+ function statusIcon(status?: string) {
109
+ if (status === 'success') return <CheckCircleOutlined />;
110
+ if (status === 'error') return <CloseCircleOutlined />;
111
+ return undefined;
112
+ }
113
+
114
+ function StatusTag({ status }: { status?: string }) {
115
+ return (
116
+ <Tag color={statusColor(status)} icon={statusIcon(status)}>
117
+ {status || '-'}
118
+ </Tag>
119
+ );
120
+ }
121
+
122
+ function formatDate(value?: string) {
123
+ return value ? new Date(value).toLocaleString() : '-';
124
+ }
125
+
126
+ function formatDurationMs(value?: number) {
127
+ if (!value) return '-';
128
+ if (value >= 60000) return `${Math.round(value / 60000)}m`;
129
+ if (value >= 1000) return `${(value / 1000).toFixed(1)}s`;
130
+ return `${value}ms`;
131
+ }
132
+
133
+ function formatJson(value: unknown) {
134
+ if (value === undefined || value === null || value === '') return '';
135
+ if (typeof value === 'string') return value;
136
+ try {
137
+ return JSON.stringify(value, null, 2);
138
+ } catch {
139
+ return String(value);
140
+ }
141
+ }
142
+
143
+ function TextBlock({ value, rows = 8 }: { value: unknown; rows?: number }) {
144
+ const text = formatJson(value);
145
+ if (!text) return <Text type="secondary">-</Text>;
146
+ return (
147
+ <Paragraph
148
+ style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word', margin: 0, fontSize: 12 }}
149
+ ellipsis={{ rows, expandable: true }}
150
+ >
151
+ {text}
152
+ </Paragraph>
153
+ );
154
+ }
155
+
156
+ export const AgentRunsTab: React.FC = () => {
157
+ const api = useAPIClient();
158
+ const t = useT();
159
+ const { employees, employeeMap } = useAIEmployees();
160
+ const [filters, setFilters] = useState<FilterState>({});
161
+ const [page, setPage] = useState(1);
162
+ const [pageSize, setPageSize] = useState(20);
163
+ const [selectedRun, setSelectedRun] = useState<RunRecord | null>(null);
164
+ const [detailLoading, setDetailLoading] = useState(false);
165
+ const [syncLoading, setSyncLoading] = useState(false);
166
+ // Guards the detail drawer against out-of-order responses when the user
167
+ // switches rows quickly: only the newest request may commit its result.
168
+ const detailRequestId = useRef(0);
169
+
170
+ const requestParams = useMemo(() => {
171
+ const filter: Record<string, string> = {};
172
+ if (filters.leader) filter.leaderUsername = filters.leader;
173
+ if (filters.subAgent) filter.subAgentUsername = filters.subAgent;
174
+ if (filters.status) filter.status = filters.status;
175
+ return {
176
+ sort: ['-createdAt'],
177
+ page,
178
+ pageSize,
179
+ filter,
180
+ };
181
+ }, [filters, page, pageSize]);
182
+
183
+ const { data, loading, refresh } = useRequest<ListResponse>(
184
+ {
185
+ url: 'agentMonitor:list',
186
+ params: requestParams,
187
+ },
188
+ {
189
+ refreshDeps: [requestParams],
190
+ },
191
+ );
192
+
193
+ const runs = useMemo(() => {
194
+ const rows = data?.data;
195
+ return Array.isArray(rows) ? rows : [];
196
+ }, [data]);
197
+
198
+ const total = useMemo(() => {
199
+ const count = data?.meta?.count;
200
+ return typeof count === 'number' ? count : 0;
201
+ }, [data]);
202
+
203
+ const employeeOptions = useMemo(
204
+ () =>
205
+ employees.map((employee) => ({
206
+ label: employee.nickname || employee.username,
207
+ value: employee.username,
208
+ })),
209
+ [employees],
210
+ );
211
+
212
+ const updateFilter = (patch: Partial<FilterState>) => {
213
+ setFilters((prev) => ({ ...prev, ...patch }));
214
+ setPage(1);
215
+ };
216
+
217
+ const resetFilters = () => {
218
+ setFilters({});
219
+ setPage(1);
220
+ };
221
+
222
+ const fetchDetail = async (record: RunRecord) => {
223
+ const requestId = ++detailRequestId.current;
224
+ setSelectedRun(record);
225
+ setDetailLoading(true);
226
+ try {
227
+ const res = await api.request({
228
+ url: 'agentMonitor:get',
229
+ params: { filterByTk: record.id },
230
+ });
231
+ if (requestId !== detailRequestId.current) return;
232
+ const payload = res as { data?: { data?: { data?: RunRecord } | RunRecord } };
233
+ const detail =
234
+ (payload?.data?.data as { data?: RunRecord })?.data || (payload?.data?.data as RunRecord) || record;
235
+ setSelectedRun(detail);
236
+ } catch (error) {
237
+ if (requestId !== detailRequestId.current) return;
238
+ const text =
239
+ (error as RequestError)?.response?.data?.errors?.[0]?.message ||
240
+ (error as RequestError)?.message ||
241
+ t('Failed to load run detail');
242
+ message.error(text);
243
+ } finally {
244
+ if (requestId === detailRequestId.current) {
245
+ setDetailLoading(false);
246
+ }
247
+ }
248
+ };
249
+
250
+ const syncNativeRuns = async () => {
251
+ setSyncLoading(true);
252
+ try {
253
+ const res = await api.request({
254
+ url: 'agentMonitor:sync',
255
+ method: 'post',
256
+ data: { limit: 500 },
257
+ });
258
+ const result = (res as { data?: { data?: { created?: number } } })?.data?.data || {};
259
+ message.success(t('Synced {{count}} native runs', { count: result.created || 0 }));
260
+ refresh();
261
+ } catch (error) {
262
+ const text =
263
+ (error as RequestError)?.response?.data?.errors?.[0]?.message ||
264
+ (error as RequestError)?.message ||
265
+ t('Sync failed');
266
+ message.error(text);
267
+ } finally {
268
+ setSyncLoading(false);
269
+ }
270
+ };
271
+
272
+ const hasFilters = Boolean(filters.leader || filters.subAgent || filters.status);
273
+ const trace: TraceItem[] = Array.isArray(selectedRun?.trace) ? selectedRun.trace : [];
274
+ const toolMessages: ToolMessage[] = Array.isArray(selectedRun?.toolMessages) ? selectedRun.toolMessages : [];
275
+ const nativeMessages: NativeMessage[] = Array.isArray(selectedRun?.nativeMessages) ? selectedRun.nativeMessages : [];
276
+
277
+ const columns = [
278
+ {
279
+ title: t('Time'),
280
+ dataIndex: 'createdAt',
281
+ key: 'createdAt',
282
+ width: 170,
283
+ render: formatDate,
284
+ },
285
+ {
286
+ title: t('Leader'),
287
+ dataIndex: 'leaderUsername',
288
+ key: 'leaderUsername',
289
+ width: 160,
290
+ render: (username: string) => <Tag color="blue">{employeeMap.get(username) || username || '-'}</Tag>,
291
+ },
292
+ {
293
+ title: t('Sub-Agent'),
294
+ dataIndex: 'subAgentUsername',
295
+ key: 'subAgentUsername',
296
+ width: 160,
297
+ render: (username: string) => <Tag color="green">{employeeMap.get(username) || username || '-'}</Tag>,
298
+ },
299
+ {
300
+ title: t('Task'),
301
+ dataIndex: 'task',
302
+ key: 'task',
303
+ render: (task: string) => (
304
+ <Text ellipsis style={{ maxWidth: 360 }}>
305
+ {task || '-'}
306
+ </Text>
307
+ ),
308
+ },
309
+ {
310
+ title: t('Status'),
311
+ dataIndex: 'status',
312
+ key: 'status',
313
+ width: 110,
314
+ render: (status: string) => <StatusTag status={status} />,
315
+ },
316
+ {
317
+ title: t('Duration'),
318
+ dataIndex: 'durationMs',
319
+ key: 'durationMs',
320
+ width: 100,
321
+ render: formatDurationMs,
322
+ },
323
+ {
324
+ title: t('Context'),
325
+ dataIndex: 'memoryContextApplied',
326
+ key: 'memoryContextApplied',
327
+ width: 100,
328
+ render: (applied: boolean) => (applied ? <Tag color="purple">memory</Tag> : <Text type="secondary">-</Text>),
329
+ },
330
+ {
331
+ title: '',
332
+ key: 'actions',
333
+ width: 90,
334
+ render: (_: unknown, record: RunRecord) => (
335
+ <Button type="link" size="small" icon={<EyeOutlined />} onClick={() => fetchDetail(record)}>
336
+ {t('Detail')}
337
+ </Button>
338
+ ),
339
+ },
340
+ ];
341
+
342
+ return (
343
+ <div>
344
+ <Alert
345
+ type="info"
346
+ showIcon
347
+ style={{ marginBottom: 16 }}
348
+ message={t('Native Agent Runs')}
349
+ description={
350
+ <Text type="secondary">
351
+ {t(
352
+ 'Native plugin-ai sub-agent dispatches captured by the orchestrator observer. Execution still runs through AIEmployee/SubAgentsDispatcher.',
353
+ )}
354
+ </Text>
355
+ }
356
+ />
357
+
358
+ <Card bordered={false}>
359
+ <Form layout="inline" style={{ marginBottom: 16, rowGap: 8, flexWrap: 'wrap' }}>
360
+ <Form.Item label={t('Leader')}>
361
+ <Select
362
+ allowClear
363
+ showSearch
364
+ optionFilterProp="label"
365
+ placeholder={t('Any leader')}
366
+ style={{ minWidth: 180 }}
367
+ options={employeeOptions}
368
+ value={filters.leader}
369
+ onChange={(value) => updateFilter({ leader: value })}
370
+ />
371
+ </Form.Item>
372
+ <Form.Item label={t('Sub-Agent')}>
373
+ <Select
374
+ allowClear
375
+ showSearch
376
+ optionFilterProp="label"
377
+ placeholder={t('Any sub-agent')}
378
+ style={{ minWidth: 180 }}
379
+ options={employeeOptions}
380
+ value={filters.subAgent}
381
+ onChange={(value) => updateFilter({ subAgent: value })}
382
+ />
383
+ </Form.Item>
384
+ <Form.Item label={t('Status')}>
385
+ <Select
386
+ allowClear
387
+ placeholder={t('Any status')}
388
+ style={{ minWidth: 140 }}
389
+ value={filters.status}
390
+ onChange={(value) => updateFilter({ status: value })}
391
+ options={[
392
+ { label: t('Running'), value: 'running' },
393
+ { label: t('Success'), value: 'success' },
394
+ { label: t('Error'), value: 'error' },
395
+ ]}
396
+ />
397
+ </Form.Item>
398
+ <Form.Item>
399
+ <Space>
400
+ <Button onClick={resetFilters} disabled={!hasFilters}>
401
+ {t('Reset')}
402
+ </Button>
403
+ <Button icon={<ReloadOutlined />} onClick={refresh}>
404
+ {t('Refresh')}
405
+ </Button>
406
+ <Button icon={<SyncOutlined />} onClick={syncNativeRuns} loading={syncLoading}>
407
+ {t('Sync')}
408
+ </Button>
409
+ </Space>
410
+ </Form.Item>
411
+ </Form>
412
+
413
+ <Table
414
+ rowKey="id"
415
+ loading={loading}
416
+ dataSource={runs}
417
+ columns={columns}
418
+ scroll={{ x: 'max-content' }}
419
+ pagination={{
420
+ current: page,
421
+ pageSize,
422
+ total,
423
+ showSizeChanger: true,
424
+ pageSizeOptions: [10, 20, 50, 100],
425
+ showTotal: (count) => t('{{count}} runs', { count }),
426
+ onChange: (nextPage, nextSize) => {
427
+ setPage(nextPage);
428
+ if (nextSize && nextSize !== pageSize) setPageSize(nextSize);
429
+ },
430
+ }}
431
+ locale={{
432
+ emptyText: (
433
+ <Empty description={hasFilters ? t('No runs match the current filters') : t('No native runs yet')} />
434
+ ),
435
+ }}
436
+ />
437
+ </Card>
438
+
439
+ <Drawer title={t('Native Run Detail')} width={960} onClose={() => setSelectedRun(null)} open={!!selectedRun}>
440
+ {selectedRun && (
441
+ <Spin spinning={detailLoading}>
442
+ <Space direction="vertical" size={16} style={{ width: '100%' }}>
443
+ <Descriptions bordered size="small" column={2}>
444
+ <Descriptions.Item label={t('Status')}>
445
+ <StatusTag status={selectedRun.status} />
446
+ </Descriptions.Item>
447
+ <Descriptions.Item label={t('Harness')}>{selectedRun.harnessTag || 'default'}</Descriptions.Item>
448
+ <Descriptions.Item label={t('Leader')}>
449
+ <Tag color="blue">
450
+ {employeeMap.get(selectedRun.leaderUsername) || selectedRun.leaderUsername || '-'}
451
+ </Tag>
452
+ </Descriptions.Item>
453
+ <Descriptions.Item label={t('Sub-Agent')}>
454
+ <Tag color="green">
455
+ {employeeMap.get(selectedRun.subAgentUsername) || selectedRun.subAgentUsername || '-'}
456
+ </Tag>
457
+ </Descriptions.Item>
458
+ <Descriptions.Item label={t('Parent session')}>
459
+ <Text code>{selectedRun.parentSessionId || '-'}</Text>
460
+ </Descriptions.Item>
461
+ <Descriptions.Item label={t('Sub session')}>
462
+ <Text code>{selectedRun.subSessionId || '-'}</Text>
463
+ </Descriptions.Item>
464
+ <Descriptions.Item label={t('Tool call')}>
465
+ <Text code>{selectedRun.toolCallId || '-'}</Text>
466
+ </Descriptions.Item>
467
+ <Descriptions.Item label={t('Duration')}>{formatDurationMs(selectedRun.durationMs)}</Descriptions.Item>
468
+ <Descriptions.Item label={t('Started')}>
469
+ {formatDate(selectedRun.startedAt || selectedRun.createdAt)}
470
+ </Descriptions.Item>
471
+ <Descriptions.Item label={t('Ended')}>{formatDate(selectedRun.endedAt)}</Descriptions.Item>
472
+ </Descriptions>
473
+
474
+ <Card title={t('Task')} size="small">
475
+ <TextBlock value={selectedRun.task || selectedRun.input?.question} rows={6} />
476
+ </Card>
477
+
478
+ <Card title={t('Execution Flow')} size="small">
479
+ {trace.length ? (
480
+ <Timeline
481
+ items={trace.map((item: TraceItem) => ({
482
+ key: item.id,
483
+ color: item.status === 'error' ? 'red' : item.status === 'running' ? 'blue' : 'green',
484
+ children: (
485
+ <Space direction="vertical" size={2} style={{ width: '100%' }}>
486
+ <Space wrap>
487
+ <Text strong>{item.title || item.type}</Text>
488
+ <Tag>{item.type}</Tag>
489
+ <StatusTag status={item.status} />
490
+ {item.toolName && <Text code>{item.toolName}</Text>}
491
+ {item.durationMs ? <Text type="secondary">{formatDurationMs(item.durationMs)}</Text> : null}
492
+ </Space>
493
+ <Text type="secondary">{formatDate(item.at)}</Text>
494
+ {item.content ? <TextBlock value={item.content} rows={4} /> : null}
495
+ </Space>
496
+ ),
497
+ }))}
498
+ />
499
+ ) : (
500
+ <Empty description={t('No execution flow captured')} />
501
+ )}
502
+ </Card>
503
+
504
+ <Collapse
505
+ items={[
506
+ {
507
+ key: 'toolMessages',
508
+ label: t('Native tool messages ({{count}})', { count: toolMessages.length }),
509
+ children: toolMessages.length ? (
510
+ <Table
511
+ rowKey={(record: ToolMessage) => `${record.sessionId}:${record.toolCallId}`}
512
+ size="small"
513
+ pagination={false}
514
+ dataSource={toolMessages}
515
+ scroll={{ x: 'max-content' }}
516
+ columns={[
517
+ { title: t('Session'), dataIndex: 'sessionId', key: 'sessionId' },
518
+ { title: t('Tool'), dataIndex: 'toolName', key: 'toolName' },
519
+ {
520
+ title: t('Status'),
521
+ dataIndex: 'status',
522
+ key: 'status',
523
+ render: (value: string) => <StatusTag status={value === 'error' ? 'error' : value} />,
524
+ },
525
+ { title: t('Invoke'), dataIndex: 'invokeStatus', key: 'invokeStatus' },
526
+ {
527
+ title: t('Content'),
528
+ dataIndex: 'content',
529
+ key: 'content',
530
+ render: (value: unknown) => <TextBlock value={value} rows={3} />,
531
+ },
532
+ ]}
533
+ />
534
+ ) : (
535
+ <Empty description={t('No native tool messages')} />
536
+ ),
537
+ },
538
+ {
539
+ key: 'messages',
540
+ label: t('Native messages ({{count}})', { count: nativeMessages.length }),
541
+ children: nativeMessages.length ? (
542
+ <Space direction="vertical" size={8} style={{ width: '100%' }}>
543
+ {nativeMessages.map((item: NativeMessage) => (
544
+ <Card
545
+ key={`${item.sessionId}:${item.messageId}`}
546
+ size="small"
547
+ title={`${item.role} #${item.messageId}`}
548
+ >
549
+ <TextBlock value={item.content || item.metadata} rows={6} />
550
+ </Card>
551
+ ))}
552
+ </Space>
553
+ ) : (
554
+ <Empty description={t('No native messages loaded')} />
555
+ ),
556
+ },
557
+ {
558
+ key: 'metadata',
559
+ label: t('Monitor metadata'),
560
+ children: <TextBlock value={selectedRun.metadata} rows={10} />,
561
+ },
562
+ ]}
563
+ />
564
+
565
+ {(selectedRun.output || selectedRun.error) && (
566
+ <Card title={selectedRun.error ? t('Error') : t('Result')} size="small">
567
+ <TextBlock value={selectedRun.error || selectedRun.output} rows={12} />
568
+ </Card>
569
+ )}
570
+ </Space>
571
+ </Spin>
572
+ )}
573
+ </Drawer>
574
+ </div>
575
+ );
576
+ };