plugin-agent-orchestrator 1.0.27 → 1.0.32

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 (110) hide show
  1. package/README.md +9 -7
  2. package/dist/client/index.js +1 -1
  3. package/dist/client-v2/{214.723affb37c13bf7a.js → 214.79650a549273f163.js} +1 -1
  4. package/dist/client-v2/264.718a107e43fc163c.js +10 -0
  5. package/dist/client-v2/373.f5d5292e53c4e832.js +10 -0
  6. package/dist/client-v2/{41.1805b2edfaa4afe2.js → 41.ba6e080cc0488143.js} +1 -1
  7. package/dist/client-v2/418.29e713f79131eece.js +10 -0
  8. package/dist/client-v2/619.bd3c5698b40705c3.js +10 -0
  9. package/dist/client-v2/677.a991ce0250ff5c77.js +10 -0
  10. package/dist/client-v2/{70.a15d7fcec7c41768.js → 70.bda9518881c05360.js} +1 -1
  11. package/dist/client-v2/925.f5370de8f6632d65.js +10 -0
  12. package/dist/client-v2/index.js +1 -1
  13. package/dist/externalVersion.js +7 -10
  14. package/dist/locale/en-US.json +94 -25
  15. package/dist/locale/vi-VN.json +94 -25
  16. package/dist/locale/zh-CN.json +94 -25
  17. package/dist/server/collections/agent-execution-spans.js +37 -0
  18. package/dist/server/collections/agent-harness-profiles.js +2 -2
  19. package/dist/server/collections/agent-memory-contexts.js +125 -0
  20. package/dist/server/collections/orchestrator-logs.js +2 -2
  21. package/dist/server/migrations/20260425000000-add-interaction-schema.js +3 -1
  22. package/dist/server/migrations/20260427000000-change-packages-to-text.js +3 -1
  23. package/dist/server/migrations/20260427000001-change-other-json-to-text.js +6 -2
  24. package/dist/server/migrations/20260524001000-add-plan-approval-and-harness-profiles.js +21 -19
  25. package/dist/server/migrations/20260621000000-native-policy-profile-defaults.js +193 -0
  26. package/dist/server/plugin.js +128 -74
  27. package/dist/server/resources/agent-monitor.js +454 -0
  28. package/dist/server/services/AgentHarness.js +24 -499
  29. package/dist/server/services/AgentMemoryContextService.js +216 -0
  30. package/dist/server/services/ExecutionSpanService.js +2 -2
  31. package/dist/server/services/NativeSubAgentObserver.js +413 -0
  32. package/dist/server/skill-hub/mcp/McpController.js +16 -5
  33. package/dist/server/skill-hub/plugin.js +81 -5
  34. package/dist/server/skill-hub/tasks/SkillExecutionTask.js +9 -3
  35. package/dist/server/tools/delegate-task.js +11 -589
  36. package/dist/server/utils/skill-settings.js +18 -1
  37. package/package.json +47 -49
  38. package/src/client/AIEmployeesContext.tsx +5 -18
  39. package/src/client/AgentRunsTab.tsx +2 -771
  40. package/src/client/HarnessProfilesTab.tsx +2 -257
  41. package/src/client/OrchestratorSettings.tsx +97 -106
  42. package/src/client/RulesTab.tsx +2 -788
  43. package/src/client/plugin.tsx +0 -2
  44. package/src/client/skill-hub/components/ExecutionHistory.tsx +200 -202
  45. package/src/client/skill-hub/components/ExecutionProgress.tsx +51 -55
  46. package/src/client/skill-hub/components/LoopSettings.tsx +331 -331
  47. package/src/client/skill-hub/components/SkillEditor.tsx +43 -39
  48. package/src/client/skill-hub/components/SkillManager.tsx +194 -181
  49. package/src/client/skill-hub/components/SkillTestPanel.tsx +141 -145
  50. package/src/client/skill-hub/locale.ts +16 -16
  51. package/src/client/skill-hub/tools/SkillHubCard.tsx +104 -109
  52. package/src/client/skill-hub/tools/loopTemplates.ts +52 -52
  53. package/src/client/skill-hub/utils/jsonFields.ts +7 -3
  54. package/src/client-v2/components/AIEmployeesContext.tsx +3 -16
  55. package/src/client-v2/components/AgentRunsTab.tsx +182 -455
  56. package/src/client-v2/components/HarnessProfilesTab.tsx +34 -31
  57. package/src/client-v2/components/RulesTab.tsx +2 -782
  58. package/src/client-v2/components/TracingTab.tsx +1 -1
  59. package/src/client-v2/hooks/useApiRequest.ts +8 -1
  60. package/src/client-v2/pages/RulesPage.tsx +2 -2
  61. package/src/client-v2/plugin.tsx +3 -3
  62. package/src/locale/en-US.json +94 -25
  63. package/src/locale/vi-VN.json +94 -25
  64. package/src/locale/zh-CN.json +94 -25
  65. package/src/server/__tests__/native-sub-agent-observer.test.ts +246 -0
  66. package/src/server/__tests__/skill-settings.test.ts +6 -6
  67. package/src/server/__tests__/smoke.test.ts +1 -0
  68. package/src/server/collections/agent-execution-spans.ts +37 -0
  69. package/src/server/collections/agent-harness-profiles.ts +59 -59
  70. package/src/server/collections/agent-loop-events.ts +71 -71
  71. package/src/server/collections/agent-loop-steps.ts +144 -144
  72. package/src/server/collections/agent-memory-contexts.ts +95 -0
  73. package/src/server/collections/orchestrator-logs.ts +4 -4
  74. package/src/server/collections/skill-definitions.ts +111 -111
  75. package/src/server/collections/skill-executions.ts +106 -106
  76. package/src/server/collections/skill-loop-configs.ts +65 -65
  77. package/src/server/migrations/20260423000000-add-progress-fields.ts +14 -14
  78. package/src/server/migrations/20260425000000-add-interaction-schema.ts +3 -1
  79. package/src/server/migrations/20260427000000-change-packages-to-text.ts +4 -2
  80. package/src/server/migrations/20260427000001-change-other-json-to-text.ts +9 -5
  81. package/src/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.ts +30 -30
  82. package/src/server/migrations/20260524001000-add-plan-approval-and-harness-profiles.ts +145 -142
  83. package/src/server/migrations/20260615000000-normalize-ai-employee-tool-bindings.ts +2 -2
  84. package/src/server/migrations/20260621000000-native-policy-profile-defaults.ts +193 -0
  85. package/src/server/plugin.ts +151 -94
  86. package/src/server/resources/agent-monitor.ts +482 -0
  87. package/src/server/services/AgentHarness.ts +38 -623
  88. package/src/server/services/AgentMemoryContextService.ts +256 -0
  89. package/src/server/services/AgentPlanValidator.ts +73 -73
  90. package/src/server/services/ExecutionSpanService.ts +6 -2
  91. package/src/server/services/FileManager.ts +144 -144
  92. package/src/server/services/NativeSubAgentObserver.ts +507 -0
  93. package/src/server/services/SkillManager.ts +583 -583
  94. package/src/server/services/SkillRepositoryService.ts +5 -7
  95. package/src/server/services/TokenTracker.ts +3 -3
  96. package/src/server/services/WorkerEnvManager.ts +1 -2
  97. package/src/server/skill-hub/actions/git-import.ts +5 -7
  98. package/src/server/skill-hub/mcp/McpController.ts +41 -14
  99. package/src/server/skill-hub/plugin.ts +89 -6
  100. package/src/server/skill-hub/tasks/SkillExecutionTask.ts +470 -460
  101. package/src/server/skill-hub/utils/json-fields.ts +1 -1
  102. package/src/server/tools/delegate-task.ts +13 -847
  103. package/src/server/utils/skill-settings.ts +24 -6
  104. package/dist/client-v2/264.0533912e6c5ea2d7.js +0 -10
  105. package/dist/client-v2/418.5ae055abf141820e.js +0 -10
  106. package/dist/client-v2/619.d99d3c9e61c99064.js +0 -10
  107. package/dist/client-v2/892.72db4161511c8a16.js +0 -10
  108. package/dist/client-v2/926.87f660b670d85bcc.js +0 -10
  109. package/src/client/tools/PlanApprovalCard.tsx +0 -176
  110. package/src/client/tools/registerOrchestratorCards.ts +0 -17
@@ -1,331 +1,331 @@
1
- import React, { useCallback, useEffect, useMemo, useState } from 'react';
2
- import {
3
- Button,
4
- Card,
5
- Form,
6
- Input,
7
- List,
8
- message,
9
- Modal,
10
- Popconfirm,
11
- Select,
12
- Space,
13
- Switch,
14
- Tag,
15
- Tooltip,
16
- Typography,
17
- } from 'antd';
18
- import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons';
19
- import { useApp } from '@nocobase/client-v2';
20
- import { useT } from '../locale';
21
- import { formatJsonText, parseJsonText, stringifyJsonText } from '../utils/jsonFields';
22
- import { getLoopTemplate, LOOP_TEMPLATES } from '../tools/loopTemplates';
23
- import { registerSkillLoopCards } from '../tools/registerSkillLoopCards';
24
-
25
- const { TextArea } = Input;
26
-
27
- const extractList = (data: any) => {
28
- const value = data?.data?.data ?? data?.data ?? data ?? [];
29
- return Array.isArray(value) ? value : [];
30
- };
31
-
32
- export const LoopSettings: React.FC = () => {
33
- const app = useApp();
34
- const api = app.apiClient;
35
- const t = useT();
36
- const [form] = Form.useForm();
37
- const [skills, setSkills] = useState<any[]>([]);
38
- const [configs, setConfigs] = useState<any[]>([]);
39
- const [loading, setLoading] = useState(false);
40
- const [editorVisible, setEditorVisible] = useState(false);
41
- const [editingConfig, setEditingConfig] = useState<any>(null);
42
-
43
- const skillsById = useMemo(() => new Map(skills.map((skill) => [String(skill.id), skill])), [skills]);
44
-
45
- const fetchData = useCallback(async () => {
46
- setLoading(true);
47
- try {
48
- const [skillsResponse, configsResponse] = await Promise.all([
49
- api.request({
50
- url: 'skillDefinitions:list',
51
- params: {
52
- filter: { enabled: true },
53
- fields: ['id', 'name', 'title', 'language', 'autoCall'],
54
- pageSize: 500,
55
- },
56
- }),
57
- api.request({
58
- url: 'skillLoopConfigs:list',
59
- params: {
60
- fields: ['id', 'skillId', 'enabled', 'title', 'templateKey', 'prompt', 'schema', 'config', 'updatedAt'],
61
- sort: ['-updatedAt'],
62
- pageSize: 500,
63
- },
64
- }),
65
- ]);
66
- setSkills(extractList(skillsResponse.data));
67
- setConfigs(extractList(configsResponse.data));
68
- } catch {
69
- message.error(t('Failed to load skill review settings'));
70
- } finally {
71
- setLoading(false);
72
- }
73
- }, [api, t]);
74
-
75
- useEffect(() => {
76
- fetchData();
77
- }, [fetchData]);
78
-
79
- const openCreate = () => {
80
- const template = getLoopTemplate('confirm');
81
- setEditingConfig(null);
82
- form.resetFields();
83
- form.setFieldsValue({
84
- enabled: true,
85
- templateKey: template.key,
86
- prompt: template.schema.prompt,
87
- schema: formatJsonText(template.schema),
88
- config: '',
89
- });
90
- setEditorVisible(true);
91
- };
92
-
93
- const openEdit = (record: any) => {
94
- const template = getLoopTemplate(record.templateKey);
95
- setEditingConfig(record);
96
- form.setFieldsValue({
97
- ...record,
98
- templateKey: record.templateKey || template.key,
99
- prompt: record.prompt || template.schema.prompt,
100
- schema: formatJsonText(record.schema || template.schema),
101
- config: formatJsonText(record.config, null),
102
- });
103
- setEditorVisible(true);
104
- };
105
-
106
- const closeEditor = () => {
107
- setEditorVisible(false);
108
- setEditingConfig(null);
109
- form.resetFields();
110
- };
111
-
112
- const notifyLoopSettingsChanged = useCallback(async () => {
113
- await registerSkillLoopCards(app);
114
- window.dispatchEvent(new Event('skill-hub-loop-settings-changed'));
115
- }, [app]);
116
-
117
- const handleTemplateChange = (templateKey: string) => {
118
- const template = getLoopTemplate(templateKey);
119
- form.setFieldsValue({
120
- prompt: template.schema.prompt,
121
- schema: formatJsonText(template.schema),
122
- });
123
- };
124
-
125
- const handleSave = async () => {
126
- try {
127
- const values = await form.validateFields();
128
- const schema = parseJsonText<any>(values.schema, undefined);
129
- if (!schema || typeof schema !== 'object') {
130
- message.error(t('Invalid JSON in Review Schema'));
131
- return;
132
- }
133
-
134
- const config = parseJsonText<any>(values.config, undefined);
135
- if (values.config && config === undefined) {
136
- message.error(t('Invalid JSON in Review Config'));
137
- return;
138
- }
139
-
140
- const schemaWithPrompt = {
141
- ...schema,
142
- prompt: values.prompt || schema.prompt,
143
- };
144
- const data = {
145
- ...values,
146
- schema: stringifyJsonText(schemaWithPrompt),
147
- config: values.config ? stringifyJsonText(config) : null,
148
- };
149
-
150
- if (editingConfig) {
151
- await api.request({
152
- url: 'skillLoopConfigs:update',
153
- method: 'POST',
154
- params: { filterByTk: editingConfig.id },
155
- data,
156
- });
157
- } else {
158
- await api.request({
159
- url: 'skillLoopConfigs:create',
160
- method: 'POST',
161
- data,
162
- });
163
- }
164
-
165
- message.success(t(editingConfig ? 'Skill review setting updated' : 'Skill review setting created'));
166
- closeEditor();
167
- fetchData();
168
- void notifyLoopSettingsChanged();
169
- } catch (err: any) {
170
- if (err?.errorFields) return;
171
- message.error(t('Failed to save skill review setting'));
172
- }
173
- };
174
-
175
- const handleDelete = async (id: number) => {
176
- try {
177
- await api.request({ url: 'skillLoopConfigs:destroy', method: 'POST', params: { filterByTk: id } });
178
- message.success(t('Deleted'));
179
- fetchData();
180
- void notifyLoopSettingsChanged();
181
- } catch {
182
- message.error(t('Failed to delete'));
183
- }
184
- };
185
-
186
- const handleToggleEnabled = async (record: any) => {
187
- try {
188
- await api.request({
189
- url: 'skillLoopConfigs:update',
190
- method: 'POST',
191
- params: { filterByTk: record.id },
192
- data: { enabled: !record.enabled },
193
- });
194
- fetchData();
195
- void notifyLoopSettingsChanged();
196
- } catch {
197
- message.error(t('Failed to update'));
198
- }
199
- };
200
-
201
- return (
202
- <Card
203
- title={t('Skill Review Settings')}
204
- extra={
205
- <Button type="primary" icon={<PlusOutlined />} onClick={openCreate}>
206
- {t('New Review')}
207
- </Button>
208
- }
209
- >
210
- <List
211
- loading={loading}
212
- dataSource={configs}
213
- grid={{ gutter: 16, xs: 1, sm: 2, md: 3, lg: 3, xl: 4, xxl: 4 }}
214
- renderItem={(config) => {
215
- const skill = skillsById.get(String(config.skillId));
216
- const template = getLoopTemplate(config.templateKey);
217
- return (
218
- <List.Item>
219
- <Card
220
- size="small"
221
- title={
222
- <Typography.Text ellipsis>
223
- {config.title || skill?.title || skill?.name || t('Unknown skill')}
224
- </Typography.Text>
225
- }
226
- extra={
227
- <Tag color={config.enabled ? 'green' : 'default'}>
228
- {config.enabled ? t('Enabled') : t('Disabled')}
229
- </Tag>
230
- }
231
- actions={[
232
- <Tooltip key="edit" title={t('Edit')}>
233
- <EditOutlined onClick={() => openEdit(config)} />
234
- </Tooltip>,
235
- <Popconfirm key="delete" title={t('Delete?')} onConfirm={() => handleDelete(config.id)}>
236
- <Tooltip title={t('Delete')}>
237
- <DeleteOutlined style={{ color: 'red' }} />
238
- </Tooltip>
239
- </Popconfirm>,
240
- ]}
241
- style={{ boxShadow: '0 2px 8px rgba(0,0,0,0.05)', borderRadius: 8 }}
242
- >
243
- <Space direction="vertical" size={8} style={{ width: '100%' }}>
244
- <Typography.Text type="secondary" style={{ fontSize: 13 }}>
245
- {skill?.name || `skillId=${config.skillId}`}
246
- </Typography.Text>
247
- <Tag color="blue" style={{ width: 'fit-content' }}>
248
- {template.title}
249
- </Tag>
250
- <Typography.Paragraph
251
- type="secondary"
252
- ellipsis={{ rows: 2 }}
253
- style={{ minHeight: 44, marginBottom: 0, fontSize: 13 }}
254
- >
255
- {config.prompt || template.schema.prompt}
256
- </Typography.Paragraph>
257
- <Space size={4}>
258
- <Switch checked={config.enabled} onChange={() => handleToggleEnabled(config)} size="small" />
259
- <span style={{ fontSize: 12 }}>{config.enabled ? t('Enabled') : t('Disabled')}</span>
260
- </Space>
261
- </Space>
262
- </Card>
263
- </List.Item>
264
- );
265
- }}
266
- />
267
-
268
- <Modal
269
- open={editorVisible}
270
- title={editingConfig ? t('Edit Skill Review Setting') : t('New Skill Review Setting')}
271
- onCancel={closeEditor}
272
- onOk={handleSave}
273
- width={760}
274
- destroyOnClose
275
- >
276
- <Form form={form} layout="vertical">
277
- <Form.Item name="enabled" valuePropName="checked" label={t('Enabled')}>
278
- <Switch />
279
- </Form.Item>
280
-
281
- <Form.Item name="skillId" label={t('Skill')} rules={[{ required: true }]}>
282
- <Select
283
- showSearch
284
- optionFilterProp="label"
285
- placeholder={t('Select a skill')}
286
- options={skills.map((skill) => ({
287
- value: skill.id,
288
- label: `${skill.title || skill.name} (${skill.name})`,
289
- }))}
290
- />
291
- </Form.Item>
292
-
293
- <Form.Item name="title" label={t('Title')}>
294
- <Input placeholder={t('Optional display title')} />
295
- </Form.Item>
296
-
297
- <Form.Item name="templateKey" label={t('Review Template')} rules={[{ required: true }]}>
298
- <Select onChange={handleTemplateChange}>
299
- {LOOP_TEMPLATES.map((template) => (
300
- <Select.Option key={template.key} value={template.key}>
301
- {template.title} - {template.description}
302
- </Select.Option>
303
- ))}
304
- </Select>
305
- </Form.Item>
306
-
307
- <Form.Item name="prompt" label={t('Prompt')} rules={[{ required: true }]}>
308
- <TextArea rows={3} />
309
- </Form.Item>
310
-
311
- <Form.Item
312
- name="schema"
313
- label={t('Review Schema (JSON)')}
314
- rules={[{ required: true }]}
315
- extra={t('Standard interaction schema. Supported types: confirm, form, select.')}
316
- >
317
- <TextArea rows={10} style={{ fontFamily: 'monospace', fontSize: 13 }} />
318
- </Form.Item>
319
-
320
- <Form.Item name="config" label={t('Review Config (optional JSON)')}>
321
- <TextArea
322
- rows={4}
323
- style={{ fontFamily: 'monospace', fontSize: 13 }}
324
- placeholder={'{\n "maxRetries": 1\n}'}
325
- />
326
- </Form.Item>
327
- </Form>
328
- </Modal>
329
- </Card>
330
- );
331
- };
1
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
2
+ import {
3
+ Button,
4
+ Card,
5
+ Form,
6
+ Input,
7
+ List,
8
+ message,
9
+ Modal,
10
+ Popconfirm,
11
+ Select,
12
+ Space,
13
+ Switch,
14
+ Tag,
15
+ Tooltip,
16
+ Typography,
17
+ } from 'antd';
18
+ import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons';
19
+ import { useApp } from '@nocobase/client-v2';
20
+ import { useT } from '../locale';
21
+ import { formatJsonText, parseJsonText, stringifyJsonText } from '../utils/jsonFields';
22
+ import { getLoopTemplate, LOOP_TEMPLATES } from '../tools/loopTemplates';
23
+ import { registerSkillLoopCards } from '../tools/registerSkillLoopCards';
24
+
25
+ const { TextArea } = Input;
26
+
27
+ const extractList = (data: any) => {
28
+ const value = data?.data?.data ?? data?.data ?? data ?? [];
29
+ return Array.isArray(value) ? value : [];
30
+ };
31
+
32
+ export const LoopSettings: React.FC = () => {
33
+ const app = useApp();
34
+ const api = app.apiClient;
35
+ const t = useT();
36
+ const [form] = Form.useForm();
37
+ const [skills, setSkills] = useState<any[]>([]);
38
+ const [configs, setConfigs] = useState<any[]>([]);
39
+ const [loading, setLoading] = useState(false);
40
+ const [editorVisible, setEditorVisible] = useState(false);
41
+ const [editingConfig, setEditingConfig] = useState<any>(null);
42
+
43
+ const skillsById = useMemo(() => new Map(skills.map((skill) => [String(skill.id), skill])), [skills]);
44
+
45
+ const fetchData = useCallback(async () => {
46
+ setLoading(true);
47
+ try {
48
+ const [skillsResponse, configsResponse] = await Promise.all([
49
+ api.request({
50
+ url: 'skillDefinitions:list',
51
+ params: {
52
+ filter: { enabled: true },
53
+ fields: ['id', 'name', 'title', 'language', 'autoCall'],
54
+ pageSize: 500,
55
+ },
56
+ }),
57
+ api.request({
58
+ url: 'skillLoopConfigs:list',
59
+ params: {
60
+ fields: ['id', 'skillId', 'enabled', 'title', 'templateKey', 'prompt', 'schema', 'config', 'updatedAt'],
61
+ sort: ['-updatedAt'],
62
+ pageSize: 500,
63
+ },
64
+ }),
65
+ ]);
66
+ setSkills(extractList(skillsResponse.data));
67
+ setConfigs(extractList(configsResponse.data));
68
+ } catch {
69
+ message.error(t('Failed to load skill review settings'));
70
+ } finally {
71
+ setLoading(false);
72
+ }
73
+ }, [api, t]);
74
+
75
+ useEffect(() => {
76
+ fetchData();
77
+ }, [fetchData]);
78
+
79
+ const openCreate = () => {
80
+ const template = getLoopTemplate('confirm');
81
+ setEditingConfig(null);
82
+ form.resetFields();
83
+ form.setFieldsValue({
84
+ enabled: true,
85
+ templateKey: template.key,
86
+ prompt: template.schema.prompt,
87
+ schema: formatJsonText(template.schema),
88
+ config: '',
89
+ });
90
+ setEditorVisible(true);
91
+ };
92
+
93
+ const openEdit = (record: any) => {
94
+ const template = getLoopTemplate(record.templateKey);
95
+ setEditingConfig(record);
96
+ form.setFieldsValue({
97
+ ...record,
98
+ templateKey: record.templateKey || template.key,
99
+ prompt: record.prompt || template.schema.prompt,
100
+ schema: formatJsonText(record.schema || template.schema),
101
+ config: formatJsonText(record.config, null),
102
+ });
103
+ setEditorVisible(true);
104
+ };
105
+
106
+ const closeEditor = () => {
107
+ setEditorVisible(false);
108
+ setEditingConfig(null);
109
+ form.resetFields();
110
+ };
111
+
112
+ const notifyLoopSettingsChanged = useCallback(async () => {
113
+ await registerSkillLoopCards(app);
114
+ window.dispatchEvent(new Event('skill-hub-loop-settings-changed'));
115
+ }, [app]);
116
+
117
+ const handleTemplateChange = (templateKey: string) => {
118
+ const template = getLoopTemplate(templateKey);
119
+ form.setFieldsValue({
120
+ prompt: template.schema.prompt,
121
+ schema: formatJsonText(template.schema),
122
+ });
123
+ };
124
+
125
+ const handleSave = async () => {
126
+ try {
127
+ const values = await form.validateFields();
128
+ const schema = parseJsonText<any>(values.schema, undefined);
129
+ if (!schema || typeof schema !== 'object') {
130
+ message.error(t('Invalid JSON in Review Schema'));
131
+ return;
132
+ }
133
+
134
+ const config = parseJsonText<any>(values.config, undefined);
135
+ if (values.config && config === undefined) {
136
+ message.error(t('Invalid JSON in Review Config'));
137
+ return;
138
+ }
139
+
140
+ const schemaWithPrompt = {
141
+ ...schema,
142
+ prompt: values.prompt || schema.prompt,
143
+ };
144
+ const data = {
145
+ ...values,
146
+ schema: stringifyJsonText(schemaWithPrompt),
147
+ config: values.config ? stringifyJsonText(config) : null,
148
+ };
149
+
150
+ if (editingConfig) {
151
+ await api.request({
152
+ url: 'skillLoopConfigs:update',
153
+ method: 'POST',
154
+ params: { filterByTk: editingConfig.id },
155
+ data,
156
+ });
157
+ } else {
158
+ await api.request({
159
+ url: 'skillLoopConfigs:create',
160
+ method: 'POST',
161
+ data,
162
+ });
163
+ }
164
+
165
+ message.success(t(editingConfig ? 'Skill review setting updated' : 'Skill review setting created'));
166
+ closeEditor();
167
+ fetchData();
168
+ void notifyLoopSettingsChanged();
169
+ } catch (err: any) {
170
+ if (err?.errorFields) return;
171
+ message.error(t('Failed to save skill review setting'));
172
+ }
173
+ };
174
+
175
+ const handleDelete = async (id: number) => {
176
+ try {
177
+ await api.request({ url: 'skillLoopConfigs:destroy', method: 'POST', params: { filterByTk: id } });
178
+ message.success(t('Deleted'));
179
+ fetchData();
180
+ void notifyLoopSettingsChanged();
181
+ } catch {
182
+ message.error(t('Failed to delete'));
183
+ }
184
+ };
185
+
186
+ const handleToggleEnabled = async (record: any) => {
187
+ try {
188
+ await api.request({
189
+ url: 'skillLoopConfigs:update',
190
+ method: 'POST',
191
+ params: { filterByTk: record.id },
192
+ data: { enabled: !record.enabled },
193
+ });
194
+ fetchData();
195
+ void notifyLoopSettingsChanged();
196
+ } catch {
197
+ message.error(t('Failed to update'));
198
+ }
199
+ };
200
+
201
+ return (
202
+ <Card
203
+ title={t('Skill Review Settings')}
204
+ extra={
205
+ <Button type="primary" icon={<PlusOutlined />} onClick={openCreate}>
206
+ {t('New Review')}
207
+ </Button>
208
+ }
209
+ >
210
+ <List
211
+ loading={loading}
212
+ dataSource={configs}
213
+ grid={{ gutter: 16, xs: 1, sm: 2, md: 3, lg: 3, xl: 4, xxl: 4 }}
214
+ renderItem={(config) => {
215
+ const skill = skillsById.get(String(config.skillId));
216
+ const template = getLoopTemplate(config.templateKey);
217
+ return (
218
+ <List.Item>
219
+ <Card
220
+ size="small"
221
+ title={
222
+ <Typography.Text ellipsis>
223
+ {config.title || skill?.title || skill?.name || t('Unknown skill')}
224
+ </Typography.Text>
225
+ }
226
+ extra={
227
+ <Tag color={config.enabled ? 'green' : 'default'}>
228
+ {config.enabled ? t('Enabled') : t('Disabled')}
229
+ </Tag>
230
+ }
231
+ actions={[
232
+ <Tooltip key="edit" title={t('Edit')}>
233
+ <EditOutlined onClick={() => openEdit(config)} />
234
+ </Tooltip>,
235
+ <Popconfirm key="delete" title={t('Delete?')} onConfirm={() => handleDelete(config.id)}>
236
+ <Tooltip title={t('Delete')}>
237
+ <DeleteOutlined style={{ color: 'red' }} />
238
+ </Tooltip>
239
+ </Popconfirm>,
240
+ ]}
241
+ style={{ boxShadow: '0 2px 8px rgba(0,0,0,0.05)', borderRadius: 8 }}
242
+ >
243
+ <Space direction="vertical" size={8} style={{ width: '100%' }}>
244
+ <Typography.Text type="secondary" style={{ fontSize: 13 }}>
245
+ {skill?.name || `skillId=${config.skillId}`}
246
+ </Typography.Text>
247
+ <Tag color="blue" style={{ width: 'fit-content' }}>
248
+ {template.title}
249
+ </Tag>
250
+ <Typography.Paragraph
251
+ type="secondary"
252
+ ellipsis={{ rows: 2 }}
253
+ style={{ minHeight: 44, marginBottom: 0, fontSize: 13 }}
254
+ >
255
+ {config.prompt || template.schema.prompt}
256
+ </Typography.Paragraph>
257
+ <Space size={4}>
258
+ <Switch checked={config.enabled} onChange={() => handleToggleEnabled(config)} size="small" />
259
+ <span style={{ fontSize: 12 }}>{config.enabled ? t('Enabled') : t('Disabled')}</span>
260
+ </Space>
261
+ </Space>
262
+ </Card>
263
+ </List.Item>
264
+ );
265
+ }}
266
+ />
267
+
268
+ <Modal
269
+ open={editorVisible}
270
+ title={editingConfig ? t('Edit Skill Review Setting') : t('New Skill Review Setting')}
271
+ onCancel={closeEditor}
272
+ onOk={handleSave}
273
+ width={760}
274
+ destroyOnClose
275
+ >
276
+ <Form form={form} layout="vertical">
277
+ <Form.Item name="enabled" valuePropName="checked" label={t('Enabled')}>
278
+ <Switch />
279
+ </Form.Item>
280
+
281
+ <Form.Item name="skillId" label={t('Skill')} rules={[{ required: true }]}>
282
+ <Select
283
+ showSearch
284
+ optionFilterProp="label"
285
+ placeholder={t('Select a skill')}
286
+ options={skills.map((skill) => ({
287
+ value: skill.id,
288
+ label: `${skill.title || skill.name} (${skill.name})`,
289
+ }))}
290
+ />
291
+ </Form.Item>
292
+
293
+ <Form.Item name="title" label={t('Title')}>
294
+ <Input placeholder={t('Optional display title')} />
295
+ </Form.Item>
296
+
297
+ <Form.Item name="templateKey" label={t('Review Template')} rules={[{ required: true }]}>
298
+ <Select onChange={handleTemplateChange}>
299
+ {LOOP_TEMPLATES.map((template) => (
300
+ <Select.Option key={template.key} value={template.key}>
301
+ {template.title} - {template.description}
302
+ </Select.Option>
303
+ ))}
304
+ </Select>
305
+ </Form.Item>
306
+
307
+ <Form.Item name="prompt" label={t('Prompt')} rules={[{ required: true }]}>
308
+ <TextArea rows={3} />
309
+ </Form.Item>
310
+
311
+ <Form.Item
312
+ name="schema"
313
+ label={t('Review Schema (JSON)')}
314
+ rules={[{ required: true }]}
315
+ extra={t('Standard interaction schema. Supported types: confirm, form, select.')}
316
+ >
317
+ <TextArea rows={10} style={{ fontFamily: 'monospace', fontSize: 13 }} />
318
+ </Form.Item>
319
+
320
+ <Form.Item name="config" label={t('Review Config (optional JSON)')}>
321
+ <TextArea
322
+ rows={4}
323
+ style={{ fontFamily: 'monospace', fontSize: 13 }}
324
+ placeholder={'{\n "maxRetries": 1\n}'}
325
+ />
326
+ </Form.Item>
327
+ </Form>
328
+ </Modal>
329
+ </Card>
330
+ );
331
+ };