plugin-agent-orchestrator 1.0.38 → 1.1.0
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/dist/client/index.js +1 -1
- package/dist/client-v2/253.9f0537713cee9e6c.js +10 -0
- package/dist/client-v2/418.ce8f5b2b8a229d1d.js +10 -0
- package/dist/client-v2/53.7c29c28043e9112d.js +10 -0
- package/dist/client-v2/794.9bbb8d3a61b2bdf2.js +10 -0
- package/dist/client-v2/993.82778b6fd6db3cb1.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +6 -6
- package/dist/locale/en-US.json +50 -2
- package/dist/locale/vi-VN.json +50 -2
- package/dist/locale/zh-CN.json +50 -2
- package/dist/server/migrations/20260621000000-native-policy-profile-defaults.js +0 -3
- package/dist/server/migrations/20260727000000-remove-unused-knowledge-scopes.js +51 -0
- package/dist/server/plugin.js +11 -1
- package/dist/server/resources/agent-knowledge-insights.js +273 -0
- package/dist/server/services/AgentMemoryContextService.js +57 -19
- package/dist/server/services/NativeSubAgentObserver.js +11 -3
- package/dist/server/tools/external-rag-search.js +152 -12
- package/package.json +1 -1
- package/src/client-v2/components/AgentBindingsTab.tsx +269 -0
- package/src/client-v2/components/HarnessProfilesTab.tsx +1 -2
- package/src/client-v2/components/KnowledgeAccessTab.tsx +116 -0
- package/src/client-v2/components/MemoryInspectorTab.tsx +125 -0
- package/src/client-v2/components/RetrievalTraceTab.tsx +162 -0
- package/src/client-v2/pages/AgentBindingsPage.tsx +13 -0
- package/src/client-v2/pages/KnowledgeAccessPage.tsx +10 -0
- package/src/client-v2/pages/MemoryInspectorPage.tsx +13 -0
- package/src/client-v2/pages/RetrievalTracePage.tsx +10 -0
- package/src/client-v2/plugin.tsx +28 -0
- package/src/locale/en-US.json +50 -2
- package/src/locale/vi-VN.json +50 -2
- package/src/locale/zh-CN.json +50 -2
- package/src/server/__tests__/agent-knowledge-insights.test.ts +123 -0
- package/src/server/__tests__/external-rag-search.test.ts +107 -0
- package/src/server/__tests__/native-sub-agent-observer.test.ts +89 -7
- package/src/server/migrations/20260621000000-native-policy-profile-defaults.ts +0 -3
- package/src/server/migrations/20260727000000-remove-unused-knowledge-scopes.ts +25 -0
- package/src/server/plugin.ts +3 -0
- package/src/server/resources/agent-knowledge-insights.ts +304 -0
- package/src/server/services/AgentMemoryContextService.ts +63 -19
- package/src/server/services/NativeSubAgentObserver.ts +538 -528
- package/src/server/tools/external-rag-search.ts +215 -14
- package/dist/client-v2/418.29e713f79131eece.js +0 -10
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
|
+
import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons';
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
Card,
|
|
6
|
+
Drawer,
|
|
7
|
+
Form,
|
|
8
|
+
InputNumber,
|
|
9
|
+
Popconfirm,
|
|
10
|
+
Select,
|
|
11
|
+
Space,
|
|
12
|
+
Switch,
|
|
13
|
+
Table,
|
|
14
|
+
Tag,
|
|
15
|
+
Typography,
|
|
16
|
+
message,
|
|
17
|
+
} from 'antd';
|
|
18
|
+
import { AIEmployeeSelect } from './AIEmployeeSelect';
|
|
19
|
+
import { useAIEmployees } from './AIEmployeesContext';
|
|
20
|
+
import { useApiClient, useRequest } from '../hooks/useApiRequest';
|
|
21
|
+
import { useT } from '../skill-hub/locale';
|
|
22
|
+
|
|
23
|
+
type BindingRecord = {
|
|
24
|
+
id: string | number;
|
|
25
|
+
leaderUsername: string;
|
|
26
|
+
subAgentUsername: string;
|
|
27
|
+
harnessTag?: string;
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
maxDepth?: number;
|
|
30
|
+
timeout?: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type ProfileRecord = { tag: string; title?: string; enabled?: boolean };
|
|
34
|
+
|
|
35
|
+
type BindingForm = Omit<BindingRecord, 'id'>;
|
|
36
|
+
|
|
37
|
+
function rowsFromResponse<T>(value: unknown): T[] {
|
|
38
|
+
const response = value as { data?: unknown } | undefined;
|
|
39
|
+
return Array.isArray(response?.data) ? (response.data as T[]) : [];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function errorText(error: unknown): string {
|
|
43
|
+
const response = error as { response?: { data?: { errors?: Array<{ message?: string }> } }; message?: string };
|
|
44
|
+
return response.response?.data?.errors?.[0]?.message || response.message || 'Unknown error';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const AgentBindingsTab: React.FC = () => {
|
|
48
|
+
const api = useApiClient();
|
|
49
|
+
const t = useT();
|
|
50
|
+
const { employeeMap } = useAIEmployees();
|
|
51
|
+
const [form] = Form.useForm<BindingForm>();
|
|
52
|
+
const [drawerOpen, setDrawerOpen] = useState(false);
|
|
53
|
+
const [editing, setEditing] = useState<BindingRecord | null>(null);
|
|
54
|
+
|
|
55
|
+
const bindingsRequest = useRequest({
|
|
56
|
+
url: 'orchestratorConfig:list',
|
|
57
|
+
params: { sort: ['leaderUsername', 'subAgentUsername'], pageSize: 200 },
|
|
58
|
+
});
|
|
59
|
+
const profilesRequest = useRequest({
|
|
60
|
+
url: 'agentHarnessProfiles:list',
|
|
61
|
+
params: { sort: ['tag'], pageSize: 100 },
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const bindings = useMemo(() => rowsFromResponse<BindingRecord>(bindingsRequest.data), [bindingsRequest.data]);
|
|
65
|
+
const profiles = useMemo(() => rowsFromResponse<ProfileRecord>(profilesRequest.data), [profilesRequest.data]);
|
|
66
|
+
const profileOptions = useMemo(
|
|
67
|
+
() =>
|
|
68
|
+
profiles
|
|
69
|
+
.filter((profile) => profile.enabled !== false)
|
|
70
|
+
.map((profile) => ({
|
|
71
|
+
label: profile.title ? `${profile.title} (${profile.tag})` : profile.tag,
|
|
72
|
+
value: profile.tag,
|
|
73
|
+
})),
|
|
74
|
+
[profiles],
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const closeDrawer = () => {
|
|
78
|
+
setDrawerOpen(false);
|
|
79
|
+
setEditing(null);
|
|
80
|
+
form.resetFields();
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const openDrawer = (binding?: BindingRecord) => {
|
|
84
|
+
setEditing(binding || null);
|
|
85
|
+
form.setFieldsValue(
|
|
86
|
+
binding || {
|
|
87
|
+
enabled: true,
|
|
88
|
+
harnessTag: 'default',
|
|
89
|
+
maxDepth: 1,
|
|
90
|
+
timeout: 120000,
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
setDrawerOpen(true);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const saveBinding = async (values: BindingForm) => {
|
|
97
|
+
const payload = {
|
|
98
|
+
...values,
|
|
99
|
+
leaderUsername: values.leaderUsername?.trim(),
|
|
100
|
+
subAgentUsername: values.subAgentUsername?.trim(),
|
|
101
|
+
harnessTag: values.harnessTag || 'default',
|
|
102
|
+
enabled: values.enabled !== false,
|
|
103
|
+
};
|
|
104
|
+
try {
|
|
105
|
+
if (editing) {
|
|
106
|
+
await api.request({
|
|
107
|
+
url: 'orchestratorConfig:update',
|
|
108
|
+
method: 'put',
|
|
109
|
+
params: { filterByTk: editing.id },
|
|
110
|
+
data: payload,
|
|
111
|
+
});
|
|
112
|
+
message.success(t('Agent binding updated'));
|
|
113
|
+
} else {
|
|
114
|
+
await api.request({ url: 'orchestratorConfig:create', method: 'post', data: payload });
|
|
115
|
+
message.success(t('Agent binding created'));
|
|
116
|
+
}
|
|
117
|
+
closeDrawer();
|
|
118
|
+
bindingsRequest.refresh();
|
|
119
|
+
} catch (error) {
|
|
120
|
+
message.error(t('Save failed: {{message}}', { message: errorText(error) }));
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const removeBinding = async (id: string | number) => {
|
|
125
|
+
try {
|
|
126
|
+
await api.request({
|
|
127
|
+
url: 'orchestratorConfig:destroy',
|
|
128
|
+
method: 'delete',
|
|
129
|
+
params: { filterByTk: id },
|
|
130
|
+
});
|
|
131
|
+
message.success(t('Agent binding deleted'));
|
|
132
|
+
bindingsRequest.refresh();
|
|
133
|
+
} catch (error) {
|
|
134
|
+
message.error(t('Delete failed: {{message}}', { message: errorText(error) }));
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const columns = [
|
|
139
|
+
{
|
|
140
|
+
title: t('Leader (Orchestrator)'),
|
|
141
|
+
dataIndex: 'leaderUsername',
|
|
142
|
+
key: 'leaderUsername',
|
|
143
|
+
render: (username: string) => <Tag color="blue">{employeeMap.get(username) || username}</Tag>,
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
title: t('Sub-Agent'),
|
|
147
|
+
dataIndex: 'subAgentUsername',
|
|
148
|
+
key: 'subAgentUsername',
|
|
149
|
+
render: (username: string) => <Tag color="green">{employeeMap.get(username) || username}</Tag>,
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
title: t('Policy Profile'),
|
|
153
|
+
dataIndex: 'harnessTag',
|
|
154
|
+
key: 'harnessTag',
|
|
155
|
+
render: (tag: string) => <Tag color="purple">{tag || 'default'}</Tag>,
|
|
156
|
+
},
|
|
157
|
+
{ title: t('Max Delegation Depth'), dataIndex: 'maxDepth', key: 'maxDepth', width: 140 },
|
|
158
|
+
{
|
|
159
|
+
title: t('Enabled'),
|
|
160
|
+
dataIndex: 'enabled',
|
|
161
|
+
key: 'enabled',
|
|
162
|
+
width: 100,
|
|
163
|
+
render: (enabled: boolean, binding: BindingRecord) => (
|
|
164
|
+
<Switch
|
|
165
|
+
size="small"
|
|
166
|
+
checked={enabled !== false}
|
|
167
|
+
aria-label={t('Enabled')}
|
|
168
|
+
onChange={async (checked) => {
|
|
169
|
+
await api.request({
|
|
170
|
+
url: 'orchestratorConfig:update',
|
|
171
|
+
method: 'put',
|
|
172
|
+
params: { filterByTk: binding.id },
|
|
173
|
+
data: { enabled: checked },
|
|
174
|
+
});
|
|
175
|
+
bindingsRequest.refresh();
|
|
176
|
+
}}
|
|
177
|
+
/>
|
|
178
|
+
),
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
title: t('Actions'),
|
|
182
|
+
key: 'actions',
|
|
183
|
+
width: 150,
|
|
184
|
+
render: (_: unknown, binding: BindingRecord) => (
|
|
185
|
+
<Space>
|
|
186
|
+
<Button type="link" size="small" icon={<EditOutlined />} onClick={() => openDrawer(binding)}>
|
|
187
|
+
{t('Edit')}
|
|
188
|
+
</Button>
|
|
189
|
+
<Popconfirm title={t('Delete this binding?')} onConfirm={() => removeBinding(binding.id)}>
|
|
190
|
+
<Button type="link" size="small" danger icon={<DeleteOutlined />}>
|
|
191
|
+
{t('Delete')}
|
|
192
|
+
</Button>
|
|
193
|
+
</Popconfirm>
|
|
194
|
+
</Space>
|
|
195
|
+
),
|
|
196
|
+
},
|
|
197
|
+
];
|
|
198
|
+
|
|
199
|
+
return (
|
|
200
|
+
<Card bordered={false}>
|
|
201
|
+
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
|
202
|
+
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 16 }}>
|
|
203
|
+
<Typography.Text type="secondary">
|
|
204
|
+
{t('Bind each leader/sub-agent pair to the profile that controls memory and tracing policy.')}
|
|
205
|
+
</Typography.Text>
|
|
206
|
+
<Button type="primary" icon={<PlusOutlined />} onClick={() => openDrawer()}>
|
|
207
|
+
{t('New Agent Binding')}
|
|
208
|
+
</Button>
|
|
209
|
+
</div>
|
|
210
|
+
<Table
|
|
211
|
+
rowKey="id"
|
|
212
|
+
dataSource={bindings}
|
|
213
|
+
loading={bindingsRequest.loading || profilesRequest.loading}
|
|
214
|
+
columns={columns}
|
|
215
|
+
pagination={false}
|
|
216
|
+
scroll={{ x: 'max-content' }}
|
|
217
|
+
/>
|
|
218
|
+
</Space>
|
|
219
|
+
|
|
220
|
+
<Drawer
|
|
221
|
+
open={drawerOpen}
|
|
222
|
+
onClose={closeDrawer}
|
|
223
|
+
width={560}
|
|
224
|
+
title={editing ? t('Edit Agent Binding') : t('New Agent Binding')}
|
|
225
|
+
extra={
|
|
226
|
+
<Space>
|
|
227
|
+
<Button onClick={closeDrawer}>{t('Cancel')}</Button>
|
|
228
|
+
<Button type="primary" onClick={() => form.submit()}>
|
|
229
|
+
{t('Save')}
|
|
230
|
+
</Button>
|
|
231
|
+
</Space>
|
|
232
|
+
}
|
|
233
|
+
>
|
|
234
|
+
<Form form={form} layout="vertical" onFinish={saveBinding}>
|
|
235
|
+
<Form.Item
|
|
236
|
+
label={t('Leader (Orchestrator)')}
|
|
237
|
+
name="leaderUsername"
|
|
238
|
+
rules={[{ required: true, message: t('Leader is required') }]}
|
|
239
|
+
>
|
|
240
|
+
<AIEmployeeSelect placeholder={t('Select leader')} />
|
|
241
|
+
</Form.Item>
|
|
242
|
+
<Form.Item
|
|
243
|
+
label={t('Sub-Agent')}
|
|
244
|
+
name="subAgentUsername"
|
|
245
|
+
rules={[{ required: true, message: t('Sub-agent is required') }]}
|
|
246
|
+
>
|
|
247
|
+
<AIEmployeeSelect placeholder={t('Select sub-agent')} />
|
|
248
|
+
</Form.Item>
|
|
249
|
+
<Form.Item
|
|
250
|
+
label={t('Policy Profile')}
|
|
251
|
+
name="harnessTag"
|
|
252
|
+
rules={[{ required: true, message: t('Policy profile is required') }]}
|
|
253
|
+
>
|
|
254
|
+
<Select options={profileOptions} placeholder={t('Select policy profile')} />
|
|
255
|
+
</Form.Item>
|
|
256
|
+
<Form.Item label={t('Max Delegation Depth')} name="maxDepth">
|
|
257
|
+
<InputNumber min={1} max={10} style={{ width: '100%' }} />
|
|
258
|
+
</Form.Item>
|
|
259
|
+
<Form.Item label={t('Timeout (ms)')} name="timeout">
|
|
260
|
+
<InputNumber min={1000} max={600000} step={1000} style={{ width: '100%' }} />
|
|
261
|
+
</Form.Item>
|
|
262
|
+
<Form.Item label={t('Enabled')} name="enabled" valuePropName="checked">
|
|
263
|
+
<Switch />
|
|
264
|
+
</Form.Item>
|
|
265
|
+
</Form>
|
|
266
|
+
</Drawer>
|
|
267
|
+
</Card>
|
|
268
|
+
);
|
|
269
|
+
};
|
|
@@ -51,7 +51,6 @@ export const HarnessProfilesTab: React.FC = () => {
|
|
|
51
51
|
nativeObserverEnabled: true,
|
|
52
52
|
memoryInjectionEnabled: true,
|
|
53
53
|
memoryScopes: ['public', 'user', 'agent_user'],
|
|
54
|
-
knowledgeScopes: ['public', 'private'],
|
|
55
54
|
maxMemoryContextChars: 6000,
|
|
56
55
|
tracingRetentionDays: 30,
|
|
57
56
|
},
|
|
@@ -199,7 +198,7 @@ export const HarnessProfilesTab: React.FC = () => {
|
|
|
199
198
|
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
|
200
199
|
<div style={{ display: 'flex', justifyContent: 'space-between', gap: 16 }}>
|
|
201
200
|
<Text type="secondary">
|
|
202
|
-
{t('Policy profiles control native
|
|
201
|
+
{t('Policy profiles control native observation, memory scopes, and tracing retention.')}
|
|
203
202
|
</Text>
|
|
204
203
|
<Button type="primary" icon={<PlusOutlined />} onClick={() => openDrawer()}>
|
|
205
204
|
{t('New Policy')}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
|
+
import { Button, Card, Space, Table, Tag, Tooltip, Typography } from 'antd';
|
|
3
|
+
import { ReloadOutlined } from '@ant-design/icons';
|
|
4
|
+
import { useRequest } from '../hooks/useApiRequest';
|
|
5
|
+
import { useT } from '../skill-hub/locale';
|
|
6
|
+
|
|
7
|
+
type AccessRow = {
|
|
8
|
+
key: string;
|
|
9
|
+
employeeUsername: string;
|
|
10
|
+
employeeRoles: string[];
|
|
11
|
+
knowledgeBaseId: string;
|
|
12
|
+
knowledgeBaseName: string;
|
|
13
|
+
knowledgeBaseType: string;
|
|
14
|
+
assigned: boolean;
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
access: 'allowed' | 'denied';
|
|
17
|
+
reason: string;
|
|
18
|
+
userGate: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function rowsFromResponse(value: unknown): AccessRow[] {
|
|
22
|
+
const body = value as { data?: unknown } | undefined;
|
|
23
|
+
return Array.isArray(body?.data) ? (body.data as AccessRow[]) : [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const KnowledgeAccessTab: React.FC = () => {
|
|
27
|
+
const t = useT();
|
|
28
|
+
const [showDeniedOnly, setShowDeniedOnly] = useState(false);
|
|
29
|
+
const request = useRequest({ url: 'agentKnowledgeInsights:accessMatrix' });
|
|
30
|
+
const rows = useMemo(() => rowsFromResponse(request.data), [request.data]);
|
|
31
|
+
const filteredRows = useMemo(
|
|
32
|
+
() => (showDeniedOnly ? rows.filter((row) => row.access === 'denied') : rows),
|
|
33
|
+
[rows, showDeniedOnly],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const columns = [
|
|
37
|
+
{ title: t('AI Employee'), dataIndex: 'employeeUsername', key: 'employeeUsername' },
|
|
38
|
+
{
|
|
39
|
+
title: t('Knowledge Base'),
|
|
40
|
+
dataIndex: 'knowledgeBaseName',
|
|
41
|
+
key: 'knowledgeBaseName',
|
|
42
|
+
render: (name: string, row: AccessRow) => (
|
|
43
|
+
<Space size={4} wrap>
|
|
44
|
+
<span>{name}</span>
|
|
45
|
+
<Tag>{row.knowledgeBaseType}</Tag>
|
|
46
|
+
</Space>
|
|
47
|
+
),
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
title: t('Assignment'),
|
|
51
|
+
dataIndex: 'assigned',
|
|
52
|
+
key: 'assigned',
|
|
53
|
+
width: 120,
|
|
54
|
+
render: (assigned: boolean) => (
|
|
55
|
+
<Tag color={assigned ? 'blue' : 'default'}>{assigned ? t('Assigned') : t('Not assigned')}</Tag>
|
|
56
|
+
),
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
title: t('Agent access'),
|
|
60
|
+
dataIndex: 'access',
|
|
61
|
+
key: 'access',
|
|
62
|
+
width: 130,
|
|
63
|
+
render: (access: AccessRow['access']) => (
|
|
64
|
+
<Tag color={access === 'allowed' ? 'success' : 'error'}>
|
|
65
|
+
{access === 'allowed' ? t('Allowed') : t('Denied')}
|
|
66
|
+
</Tag>
|
|
67
|
+
),
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
title: t('Reason'),
|
|
71
|
+
dataIndex: 'reason',
|
|
72
|
+
key: 'reason',
|
|
73
|
+
render: (reason: string) => <Typography.Text>{reason}</Typography.Text>,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
title: t('Runtime user gate'),
|
|
77
|
+
dataIndex: 'userGate',
|
|
78
|
+
key: 'userGate',
|
|
79
|
+
render: (gate: string) => (
|
|
80
|
+
<Tooltip title={gate}>
|
|
81
|
+
<Typography.Text ellipsis style={{ maxWidth: 260 }}>
|
|
82
|
+
{gate}
|
|
83
|
+
</Typography.Text>
|
|
84
|
+
</Tooltip>
|
|
85
|
+
),
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<Card bordered={false}>
|
|
91
|
+
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
|
92
|
+
<Typography.Text type="secondary">
|
|
93
|
+
{t(
|
|
94
|
+
'This matrix checks employee assignment and static agent policy. BASIC and SHARED user access is still evaluated when a run starts.',
|
|
95
|
+
)}
|
|
96
|
+
</Typography.Text>
|
|
97
|
+
<Space wrap>
|
|
98
|
+
<Button type={showDeniedOnly ? 'primary' : 'default'} onClick={() => setShowDeniedOnly((value) => !value)}>
|
|
99
|
+
{showDeniedOnly ? t('Show all') : t('Show denied only')}
|
|
100
|
+
</Button>
|
|
101
|
+
<Button icon={<ReloadOutlined />} onClick={request.refresh}>
|
|
102
|
+
{t('Refresh')}
|
|
103
|
+
</Button>
|
|
104
|
+
</Space>
|
|
105
|
+
<Table
|
|
106
|
+
rowKey="key"
|
|
107
|
+
loading={request.loading}
|
|
108
|
+
dataSource={filteredRows}
|
|
109
|
+
columns={columns}
|
|
110
|
+
scroll={{ x: 'max-content' }}
|
|
111
|
+
pagination={{ pageSize: 50, showSizeChanger: true }}
|
|
112
|
+
/>
|
|
113
|
+
</Space>
|
|
114
|
+
</Card>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
|
+
import { Button, Card, Descriptions, Form, Input, Select, Space, Typography, message } from 'antd';
|
|
3
|
+
import { useApiClient, useRequest } from '../hooks/useApiRequest';
|
|
4
|
+
import { useAIEmployees } from './AIEmployeesContext';
|
|
5
|
+
import { useT } from '../skill-hub/locale';
|
|
6
|
+
|
|
7
|
+
type ProfileRecord = { tag: string; title?: string; enabled?: boolean };
|
|
8
|
+
type Preview = {
|
|
9
|
+
context: string;
|
|
10
|
+
appliedScopes: string[];
|
|
11
|
+
chars: number;
|
|
12
|
+
maxChars: number;
|
|
13
|
+
harnessTag: string;
|
|
14
|
+
};
|
|
15
|
+
type PreviewForm = { userId: string; employeeUsername?: string; leaderUsername?: string; harnessTag?: string };
|
|
16
|
+
|
|
17
|
+
function responseRows<T>(value: unknown): T[] {
|
|
18
|
+
const response = value as { data?: unknown } | undefined;
|
|
19
|
+
return Array.isArray(response?.data) ? (response.data as T[]) : [];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function responseData<T>(value: unknown): T | undefined {
|
|
23
|
+
const response = value as { data?: { data?: T } } | undefined;
|
|
24
|
+
return response?.data?.data || (response?.data as unknown as T | undefined);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const MemoryInspectorTab: React.FC = () => {
|
|
28
|
+
const api = useApiClient();
|
|
29
|
+
const t = useT();
|
|
30
|
+
const { employees } = useAIEmployees();
|
|
31
|
+
const [form] = Form.useForm<PreviewForm>();
|
|
32
|
+
const [preview, setPreview] = useState<Preview | null>(null);
|
|
33
|
+
const [loading, setLoading] = useState(false);
|
|
34
|
+
const profilesRequest = useRequest({ url: 'agentHarnessProfiles:list', params: { pageSize: 100, sort: ['tag'] } });
|
|
35
|
+
const profiles = useMemo(() => responseRows<ProfileRecord>(profilesRequest.data), [profilesRequest.data]);
|
|
36
|
+
|
|
37
|
+
const createPreview = async (values: PreviewForm) => {
|
|
38
|
+
setLoading(true);
|
|
39
|
+
try {
|
|
40
|
+
const response = await api.request({ url: 'agentKnowledgeInsights:memoryPreview', method: 'post', data: values });
|
|
41
|
+
const data = responseData<Preview>(response.data);
|
|
42
|
+
if (!data) throw new Error(t('Memory preview returned no data'));
|
|
43
|
+
setPreview(data);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
const detail = error as { response?: { data?: { errors?: Array<{ message?: string }> } }; message?: string };
|
|
46
|
+
message.error(detail.response?.data?.errors?.[0]?.message || detail.message || t('Memory preview failed'));
|
|
47
|
+
} finally {
|
|
48
|
+
setLoading(false);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
|
54
|
+
<Card bordered={false}>
|
|
55
|
+
<Typography.Text type="secondary">
|
|
56
|
+
{t(
|
|
57
|
+
'Preview the exact memory context for a user and selected sub-agent before a run. Memory is marked as data, not executable instructions.',
|
|
58
|
+
)}
|
|
59
|
+
</Typography.Text>
|
|
60
|
+
<Form
|
|
61
|
+
form={form}
|
|
62
|
+
layout="vertical"
|
|
63
|
+
onFinish={createPreview}
|
|
64
|
+
style={{ marginTop: 16, maxWidth: 680 }}
|
|
65
|
+
initialValues={{ harnessTag: 'default' }}
|
|
66
|
+
>
|
|
67
|
+
<Form.Item label={t('User ID')} name="userId" rules={[{ required: true, message: t('User ID is required') }]}>
|
|
68
|
+
<Input inputMode="numeric" />
|
|
69
|
+
</Form.Item>
|
|
70
|
+
<Form.Item label={t('Sub-Agent')} name="employeeUsername">
|
|
71
|
+
<Select
|
|
72
|
+
allowClear
|
|
73
|
+
showSearch
|
|
74
|
+
optionFilterProp="label"
|
|
75
|
+
options={employees.map((employee) => ({
|
|
76
|
+
label: employee.nickname || employee.username,
|
|
77
|
+
value: employee.username,
|
|
78
|
+
}))}
|
|
79
|
+
/>
|
|
80
|
+
</Form.Item>
|
|
81
|
+
<Form.Item label={t('Leader (Orchestrator)')} name="leaderUsername">
|
|
82
|
+
<Select
|
|
83
|
+
allowClear
|
|
84
|
+
showSearch
|
|
85
|
+
optionFilterProp="label"
|
|
86
|
+
options={employees.map((employee) => ({
|
|
87
|
+
label: employee.nickname || employee.username,
|
|
88
|
+
value: employee.username,
|
|
89
|
+
}))}
|
|
90
|
+
/>
|
|
91
|
+
</Form.Item>
|
|
92
|
+
<Form.Item label={t('Policy Profile')} name="harnessTag">
|
|
93
|
+
<Select
|
|
94
|
+
options={profiles
|
|
95
|
+
.filter((profile) => profile.enabled !== false)
|
|
96
|
+
.map((profile) => ({
|
|
97
|
+
label: profile.title ? `${profile.title} (${profile.tag})` : profile.tag,
|
|
98
|
+
value: profile.tag,
|
|
99
|
+
}))}
|
|
100
|
+
/>
|
|
101
|
+
</Form.Item>
|
|
102
|
+
<Button type="primary" htmlType="submit" loading={loading}>
|
|
103
|
+
{t('Build memory preview')}
|
|
104
|
+
</Button>
|
|
105
|
+
</Form>
|
|
106
|
+
</Card>
|
|
107
|
+
{preview && (
|
|
108
|
+
<Card title={t('Final memory context')}>
|
|
109
|
+
<Descriptions bordered size="small" column={2} style={{ marginBottom: 16 }}>
|
|
110
|
+
<Descriptions.Item label={t('Policy Profile')}>{preview.harnessTag}</Descriptions.Item>
|
|
111
|
+
<Descriptions.Item label={t('Character budget')}>
|
|
112
|
+
{preview.chars} / {preview.maxChars}
|
|
113
|
+
</Descriptions.Item>
|
|
114
|
+
<Descriptions.Item label={t('Applied scopes')} span={2}>
|
|
115
|
+
{preview.appliedScopes.join(', ') || t('None')}
|
|
116
|
+
</Descriptions.Item>
|
|
117
|
+
</Descriptions>
|
|
118
|
+
<Typography.Paragraph style={{ margin: 0, whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
|
|
119
|
+
{preview.context || t('No memory context matched this preview.')}
|
|
120
|
+
</Typography.Paragraph>
|
|
121
|
+
</Card>
|
|
122
|
+
)}
|
|
123
|
+
</Space>
|
|
124
|
+
);
|
|
125
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
|
+
import { Button, Card, Drawer, Empty, Space, Table, Tag, Typography } from 'antd';
|
|
3
|
+
import { EyeOutlined, ReloadOutlined } from '@ant-design/icons';
|
|
4
|
+
import { useRequest } from '../hooks/useApiRequest';
|
|
5
|
+
import { useT } from '../skill-hub/locale';
|
|
6
|
+
|
|
7
|
+
type Citation = {
|
|
8
|
+
knowledgeBaseId?: string;
|
|
9
|
+
knowledgeBaseName?: string;
|
|
10
|
+
sourceId?: string;
|
|
11
|
+
filename?: string;
|
|
12
|
+
url?: string;
|
|
13
|
+
collection?: string;
|
|
14
|
+
recordId?: string;
|
|
15
|
+
excerpt?: string;
|
|
16
|
+
score?: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type RetrievalRow = {
|
|
20
|
+
id: string | number;
|
|
21
|
+
createdAt?: string;
|
|
22
|
+
employeeUsername?: string;
|
|
23
|
+
leaderUsername?: string;
|
|
24
|
+
query?: string;
|
|
25
|
+
decision: 'allowed' | 'denied';
|
|
26
|
+
reason: string;
|
|
27
|
+
citations: Citation[];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function responseRows(value: unknown): RetrievalRow[] {
|
|
31
|
+
const body = value as { data?: unknown } | undefined;
|
|
32
|
+
return Array.isArray(body?.data) ? (body.data as RetrievalRow[]) : [];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const RetrievalTraceTab: React.FC = () => {
|
|
36
|
+
const t = useT();
|
|
37
|
+
const [selected, setSelected] = useState<RetrievalRow | null>(null);
|
|
38
|
+
const request = useRequest({
|
|
39
|
+
url: 'agentKnowledgeInsights:retrievalTrace',
|
|
40
|
+
params: { page: 1, pageSize: 100 },
|
|
41
|
+
});
|
|
42
|
+
const rows = useMemo(() => responseRows(request.data), [request.data]);
|
|
43
|
+
|
|
44
|
+
const columns = [
|
|
45
|
+
{
|
|
46
|
+
title: t('Time'),
|
|
47
|
+
dataIndex: 'createdAt',
|
|
48
|
+
key: 'createdAt',
|
|
49
|
+
width: 180,
|
|
50
|
+
render: (value?: string) => (value ? new Date(value).toLocaleString() : '-'),
|
|
51
|
+
},
|
|
52
|
+
{ title: t('AI Employee'), dataIndex: 'employeeUsername', key: 'employeeUsername', width: 160 },
|
|
53
|
+
{
|
|
54
|
+
title: t('Query'),
|
|
55
|
+
dataIndex: 'query',
|
|
56
|
+
key: 'query',
|
|
57
|
+
render: (query?: string) => (
|
|
58
|
+
<Typography.Paragraph ellipsis={{ rows: 2 }} style={{ margin: 0, maxWidth: 360 }}>
|
|
59
|
+
{query || '-'}
|
|
60
|
+
</Typography.Paragraph>
|
|
61
|
+
),
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
title: t('Decision'),
|
|
65
|
+
dataIndex: 'decision',
|
|
66
|
+
key: 'decision',
|
|
67
|
+
width: 110,
|
|
68
|
+
render: (decision: RetrievalRow['decision']) => (
|
|
69
|
+
<Tag color={decision === 'allowed' ? 'success' : 'error'}>
|
|
70
|
+
{decision === 'allowed' ? t('Allowed') : t('Denied')}
|
|
71
|
+
</Tag>
|
|
72
|
+
),
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
title: t('Citations'),
|
|
76
|
+
dataIndex: 'citations',
|
|
77
|
+
key: 'citations',
|
|
78
|
+
width: 100,
|
|
79
|
+
render: (citations: Citation[]) => citations?.length || 0,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
title: t('Actions'),
|
|
83
|
+
key: 'actions',
|
|
84
|
+
width: 100,
|
|
85
|
+
render: (_: unknown, row: RetrievalRow) => (
|
|
86
|
+
<Button type="link" size="small" icon={<EyeOutlined />} onClick={() => setSelected(row)}>
|
|
87
|
+
{t('Detail')}
|
|
88
|
+
</Button>
|
|
89
|
+
),
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<Card bordered={false}>
|
|
95
|
+
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
|
96
|
+
<Typography.Text type="secondary">
|
|
97
|
+
{t(
|
|
98
|
+
'Retrieval trace stores the decision, query, and safe source citations. It does not repeat raw RAG provider metadata.',
|
|
99
|
+
)}
|
|
100
|
+
</Typography.Text>
|
|
101
|
+
<Button icon={<ReloadOutlined />} onClick={request.refresh} style={{ alignSelf: 'flex-start' }}>
|
|
102
|
+
{t('Refresh')}
|
|
103
|
+
</Button>
|
|
104
|
+
<Table
|
|
105
|
+
rowKey="id"
|
|
106
|
+
loading={request.loading}
|
|
107
|
+
dataSource={rows}
|
|
108
|
+
columns={columns}
|
|
109
|
+
scroll={{ x: 'max-content' }}
|
|
110
|
+
pagination={{ pageSize: 50, showSizeChanger: true }}
|
|
111
|
+
/>
|
|
112
|
+
</Space>
|
|
113
|
+
<Drawer title={t('Retrieval detail')} open={Boolean(selected)} onClose={() => setSelected(null)} width={760}>
|
|
114
|
+
{selected && (
|
|
115
|
+
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
|
116
|
+
<Typography.Text strong>{t('Decision')}</Typography.Text>
|
|
117
|
+
<Tag color={selected.decision === 'allowed' ? 'success' : 'error'}>{selected.decision}</Tag>
|
|
118
|
+
<Typography.Paragraph>
|
|
119
|
+
<Typography.Text strong>{t('Reason')}: </Typography.Text>
|
|
120
|
+
{selected.reason}
|
|
121
|
+
</Typography.Paragraph>
|
|
122
|
+
<Typography.Paragraph>
|
|
123
|
+
<Typography.Text strong>{t('Query')}: </Typography.Text>
|
|
124
|
+
{selected.query || '-'}
|
|
125
|
+
</Typography.Paragraph>
|
|
126
|
+
<Card title={t('Citations')} size="small">
|
|
127
|
+
{selected.citations.length ? (
|
|
128
|
+
<Space direction="vertical" size={12} style={{ width: '100%' }}>
|
|
129
|
+
{selected.citations.map((citation, index) => (
|
|
130
|
+
<Card key={`${citation.sourceId || citation.filename || index}`} size="small">
|
|
131
|
+
<Space direction="vertical" size={4} style={{ width: '100%' }}>
|
|
132
|
+
<Typography.Text strong>
|
|
133
|
+
{citation.filename || citation.sourceId || t('Unknown source')}
|
|
134
|
+
</Typography.Text>
|
|
135
|
+
<Typography.Text type="secondary">
|
|
136
|
+
{citation.knowledgeBaseName || citation.knowledgeBaseId || '-'}
|
|
137
|
+
{citation.score != null ? ` · ${citation.score.toFixed(3)}` : ''}
|
|
138
|
+
</Typography.Text>
|
|
139
|
+
{citation.url ? (
|
|
140
|
+
<Typography.Link href={citation.url} target="_blank" rel="noreferrer">
|
|
141
|
+
{citation.url}
|
|
142
|
+
</Typography.Link>
|
|
143
|
+
) : null}
|
|
144
|
+
{citation.excerpt ? (
|
|
145
|
+
<Typography.Paragraph style={{ whiteSpace: 'pre-wrap', margin: 0 }}>
|
|
146
|
+
{citation.excerpt}
|
|
147
|
+
</Typography.Paragraph>
|
|
148
|
+
) : null}
|
|
149
|
+
</Space>
|
|
150
|
+
</Card>
|
|
151
|
+
))}
|
|
152
|
+
</Space>
|
|
153
|
+
) : (
|
|
154
|
+
<Empty description={t('No citations were returned')} />
|
|
155
|
+
)}
|
|
156
|
+
</Card>
|
|
157
|
+
</Space>
|
|
158
|
+
)}
|
|
159
|
+
</Drawer>
|
|
160
|
+
</Card>
|
|
161
|
+
);
|
|
162
|
+
};
|