plugin-agent-orchestrator 1.2.0 → 1.2.1

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 (220) hide show
  1. package/LICENSE +201 -0
  2. package/dist/client/{117.2e4cb0477da3db1f.js → 117.6c69b6a87751dd18.js} +1 -1
  3. package/dist/client/{253.93deb9e0192e76a5.js → 253.52f62e1bc0e9520a.js} +1 -1
  4. package/dist/client/{404.498d2d9516dd1dce.js → 404.86593f98c9768ed5.js} +1 -1
  5. package/dist/client/{627.fdd60bcc0f3a9cf6.js → 453.fa2d169576262213.js} +1 -1
  6. package/dist/client/{53.774ff07505d521fa.js → 53.567db3ae078650c6.js} +1 -1
  7. package/dist/client/{619.e342b0fa467d39ca.js → 619.01713281e5e951d3.js} +1 -1
  8. package/dist/client/652.69da1598312b3a3f.js +10 -0
  9. package/dist/client/773.648965568ff476f9.js +10 -0
  10. package/dist/client/{981.e0546ffc34afedcd.js → 981.37e7aeecdb1ef6fa.js} +1 -1
  11. package/dist/client/{993.5d04b510835ab0d2.js → 993.ac89f3852990918d.js} +1 -1
  12. package/dist/client/index.js +1 -1
  13. package/dist/client-v2/{117.ccf43ae8631f7d74.js → 117.c982d79ff68738f5.js} +1 -1
  14. package/dist/client-v2/{214.cdf76752053a8990.js → 214.94c4257bf2838577.js} +1 -1
  15. package/dist/client-v2/{253.1198df22f5baf304.js → 253.8e19956d2a44dfb8.js} +1 -1
  16. package/dist/client-v2/{264.78887ff88f969467.js → 264.80e8e358c8c6c2e5.js} +1 -1
  17. package/dist/client-v2/{404.9ba964c28a151c81.js → 404.ab032b79c95dab6f.js} +1 -1
  18. package/dist/client-v2/{41.b28cf7a675a603d1.js → 41.cd5610fcf7446127.js} +1 -1
  19. package/dist/client-v2/{627.e16f4a0dd596c3e6.js → 453.42c6d70628d56cc2.js} +1 -1
  20. package/dist/client-v2/{53.282081f97e4308c6.js → 53.37c08089a648f89a.js} +1 -1
  21. package/dist/client-v2/{619.8c03913873785fb6.js → 619.6e9618550101e819.js} +1 -1
  22. package/dist/client-v2/652.eeba4e0c38367321.js +10 -0
  23. package/dist/client-v2/{70.9166ed70906d041f.js → 70.332698e53eb59677.js} +1 -1
  24. package/dist/client-v2/773.4de2ba5acb07318c.js +10 -0
  25. package/dist/client-v2/981.76060f466e6f7c11.js +10 -0
  26. package/dist/client-v2/{993.ca5b28f1e2b4c1ef.js → 993.f8cdb5172566ce75.js} +1 -1
  27. package/dist/client-v2/index.js +1 -1
  28. package/dist/externalVersion.js +4 -1
  29. package/dist/locale/en-US.json +80 -1
  30. package/dist/locale/vi-VN.json +5 -1
  31. package/dist/locale/zh-CN.json +80 -1
  32. package/dist/node_modules/acorn/LICENSE +21 -0
  33. package/dist/node_modules/acorn/bin/acorn +4 -0
  34. package/dist/node_modules/acorn/dist/acorn.d.mts +857 -0
  35. package/dist/node_modules/acorn/dist/acorn.d.ts +857 -0
  36. package/dist/node_modules/acorn/dist/acorn.js +1 -0
  37. package/dist/node_modules/acorn/dist/bin.js +90 -0
  38. package/dist/node_modules/acorn/package.json +1 -0
  39. package/dist/node_modules/acorn-walk/LICENSE +21 -0
  40. package/dist/node_modules/acorn-walk/dist/walk.d.mts +177 -0
  41. package/dist/node_modules/acorn-walk/dist/walk.d.ts +177 -0
  42. package/dist/node_modules/acorn-walk/dist/walk.js +1 -0
  43. package/dist/node_modules/acorn-walk/node_modules/.bin/acorn +15 -0
  44. package/dist/node_modules/acorn-walk/node_modules/.bin/acorn.cmd +7 -0
  45. package/dist/node_modules/acorn-walk/node_modules/acorn/bin/acorn +4 -0
  46. package/dist/node_modules/acorn-walk/node_modules/acorn/dist/acorn.d.mts +866 -0
  47. package/dist/node_modules/acorn-walk/node_modules/acorn/dist/acorn.d.ts +866 -0
  48. package/dist/node_modules/acorn-walk/node_modules/acorn/dist/acorn.js +6174 -0
  49. package/dist/node_modules/acorn-walk/node_modules/acorn/dist/bin.js +90 -0
  50. package/dist/node_modules/acorn-walk/node_modules/acorn/package.json +50 -0
  51. package/dist/node_modules/acorn-walk/package.json +1 -0
  52. package/dist/node_modules/adm-zip/package.json +1 -1
  53. package/dist/node_modules/ajv/package.json +1 -1
  54. package/dist/node_modules/zod/package.json +1 -1
  55. package/dist/server/collections/agent-auto-approval-checkpoints.js +47 -0
  56. package/dist/server/collections/agent-execution-spans.js +3 -3
  57. package/dist/server/collections/agent-hierarchy-invocations.js +59 -0
  58. package/dist/server/collections/agent-routing-graph-locks.js +40 -0
  59. package/dist/server/collections/agent-session-auto-approvals.js +45 -0
  60. package/dist/server/collections/orchestrator-config.js +17 -0
  61. package/dist/server/migrations/20261119000000-widen-native-employee-identifiers.js +59 -0
  62. package/dist/server/plugin.js +55 -0
  63. package/dist/server/resources/agent-auto-approval.js +80 -0
  64. package/dist/server/resources/hierarchical-routing.js +60 -0
  65. package/dist/server/services/AutoApprovalCheckpoint.js +133 -0
  66. package/dist/server/services/CodeValidator.js +8 -4
  67. package/dist/server/services/GovernanceAdmission.js +60 -0
  68. package/dist/server/services/HarnessCompiler.js +3 -0
  69. package/dist/server/services/HarnessSchema.js +13 -1
  70. package/dist/server/services/HierarchicalAgentRuntime.js +925 -0
  71. package/dist/server/services/HierarchyEnrollmentGuard.js +216 -0
  72. package/dist/server/services/HierarchyInvocationJournal.js +157 -0
  73. package/dist/server/services/HierarchyRequestCancellation.js +150 -0
  74. package/dist/server/services/LoopRunRepository.js +1 -1
  75. package/dist/server/services/LoopRunStateMachine.js +2 -2
  76. package/dist/server/services/LoopWorkerService.js +7 -7
  77. package/dist/server/services/PluginAiRuntimeAdapter.js +107 -9
  78. package/dist/server/services/RoutingBindingRepository.js +156 -0
  79. package/dist/server/services/RoutingBindingValidation.js +161 -0
  80. package/dist/server/services/SandboxRunner.js +19 -0
  81. package/dist/server/services/SessionAutoApproval.js +173 -0
  82. package/dist/server/services/VerificationService.js +2 -2
  83. package/dist/server/skill-hub/plugin.js +17 -0
  84. package/dist/server/skill-hub/services/RegistrySkillInstallationService.js +2 -2
  85. package/dist/server/skill-hub/services/registry-node-package.js +191 -0
  86. package/dist/server/skill-hub/tasks/SkillExecutionTask.js +21 -6
  87. package/dist/server/tools/skill-execute.js +1 -0
  88. package/dist/server/utils/ensure-indexes.js +1 -0
  89. package/package.json +5 -2
  90. package/src/client/SkillPages.tsx +1 -8
  91. package/src/client/__tests__/embedded-settings.test.tsx +1 -8
  92. package/src/client/plugin.tsx +3 -8
  93. package/src/client/skill-hub/tools/InteractionSchemasProvider.tsx +21 -6
  94. package/src/client/skill-hub/tools/SkillHubCard.tsx +22 -16
  95. package/src/client/skill-hub/tools/__tests__/skill-hub-card.test.tsx +255 -0
  96. package/src/client/skill-hub/tools/registerSkillLoopCards.ts +12 -3
  97. package/src/client-v2/__tests__/embedded-settings.test.tsx +20 -11
  98. package/src/client-v2/__tests__/hierarchical-routing-settings.test.tsx +350 -0
  99. package/src/client-v2/auto-approval/AutoApprovalBridge.tsx +513 -0
  100. package/src/client-v2/auto-approval/AutoApprovalProvider.tsx +399 -0
  101. package/src/client-v2/auto-approval/__tests__/session-auto-approval.test.tsx +1676 -0
  102. package/src/client-v2/components/AgentBindingsTab.tsx +275 -3
  103. package/src/client-v2/components/AgentRunsTab.tsx +1 -8
  104. package/src/client-v2/components/EmployeeGovernanceTab.tsx +1 -8
  105. package/src/client-v2/components/HarnessProfilesTab.tsx +4 -8
  106. package/src/client-v2/components/HarnessSettingsForm.tsx +221 -0
  107. package/src/client-v2/components/UsageGovernanceTab.tsx +1 -8
  108. package/src/client-v2/pages/AgentBindingsPage.tsx +1 -8
  109. package/src/client-v2/pages/ApprovalsPage.tsx +1 -8
  110. package/src/client-v2/pages/EmployeeGovernancePage.tsx +1 -8
  111. package/src/client-v2/pages/ExecutionHistoryPage.tsx +1 -8
  112. package/src/client-v2/pages/HarnessProfilesPage.tsx +1 -8
  113. package/src/client-v2/pages/KnowledgeAccessPage.tsx +1 -8
  114. package/src/client-v2/pages/LoopSettingsPage.tsx +1 -8
  115. package/src/client-v2/pages/MemoryInspectorPage.tsx +1 -8
  116. package/src/client-v2/pages/RetrievalTracePage.tsx +1 -8
  117. package/src/client-v2/pages/RulesPage.tsx +1 -8
  118. package/src/client-v2/pages/SkillDefinitionsPage.tsx +1 -8
  119. package/src/client-v2/pages/SkillMetricsPage.tsx +1 -8
  120. package/src/client-v2/pages/TracingPage.tsx +1 -8
  121. package/src/client-v2/pages/UsageGovernancePage.tsx +1 -8
  122. package/src/client-v2/plugin.tsx +3 -8
  123. package/src/client-v2/skill-hub/tools/__tests__/interactions.test.ts +17 -1
  124. package/src/client-v2/skill-hub/tools/interactions.ts +12 -3
  125. package/src/locale/en-US.json +80 -1
  126. package/src/locale/vi-VN.json +5 -1
  127. package/src/locale/zh-CN.json +80 -1
  128. package/src/server/__tests__/agent-governance.integration.test.ts +1 -8
  129. package/src/server/__tests__/agent-monitor-acl.integration.test.ts +1 -8
  130. package/src/server/__tests__/agent-usage-report.integration.test.ts +1 -8
  131. package/src/server/__tests__/auto-approval-checkpoint.integration.test.ts +295 -0
  132. package/src/server/__tests__/harness-capabilities.test.ts +1 -8
  133. package/src/server/__tests__/harness-compiler.test.ts +64 -0
  134. package/src/server/__tests__/harness-tool-plan.test.ts +1 -8
  135. package/src/server/__tests__/hierarchical-routing.integration.test.ts +2318 -0
  136. package/src/server/__tests__/hierarchy-invocation-journal.integration.test.ts +119 -0
  137. package/src/server/__tests__/loop-approval-decision.test.ts +59 -12
  138. package/src/server/__tests__/loop-budget-service.test.ts +1 -8
  139. package/src/server/__tests__/loop-run-repository.test.ts +1 -8
  140. package/src/server/__tests__/loop-trigger-service.test.ts +1 -8
  141. package/src/server/__tests__/loop-worker-claim.test.ts +46 -9
  142. package/src/server/__tests__/loop-worker-execution.test.ts +1 -8
  143. package/src/server/__tests__/native-agent-monitor-sync.test.ts +1 -8
  144. package/src/server/__tests__/native-hierarchy-probe.integration.test.ts +527 -0
  145. package/src/server/__tests__/native-sub-agent-observer.test.ts +1 -8
  146. package/src/server/__tests__/native-usage-attribution.integration.test.ts +1 -8
  147. package/src/server/__tests__/plugin-ai-runtime-adapter.test.ts +403 -0
  148. package/src/server/__tests__/registry-node-package.test.ts +299 -0
  149. package/src/server/__tests__/routing-binding-graph.integration.test.ts +217 -0
  150. package/src/server/__tests__/routing-binding-validation.test.ts +256 -0
  151. package/src/server/__tests__/session-auto-approval.integration.test.ts +329 -0
  152. package/src/server/__tests__/skill-execute.test.ts +11 -0
  153. package/src/server/__tests__/skill-review-guard.test.ts +171 -0
  154. package/src/server/__tests__/token-tracker.test.ts +1 -8
  155. package/src/server/__tests__/tracing-retention-policy.test.ts +1 -8
  156. package/src/server/__tests__/usage-ledger.integration.test.ts +1 -8
  157. package/src/server/collections/agent-auto-approval-checkpoints.ts +18 -0
  158. package/src/server/collections/agent-execution-spans.ts +4 -11
  159. package/src/server/collections/agent-governance-audit-events.ts +1 -8
  160. package/src/server/collections/agent-governance-policies.ts +1 -8
  161. package/src/server/collections/agent-governance-policy-versions.ts +1 -8
  162. package/src/server/collections/agent-governance-prompt-bindings.ts +1 -8
  163. package/src/server/collections/agent-hierarchy-invocations.ts +30 -0
  164. package/src/server/collections/agent-loop-runs.ts +1 -8
  165. package/src/server/collections/agent-routing-graph-locks.ts +11 -0
  166. package/src/server/collections/agent-session-auto-approvals.ts +16 -0
  167. package/src/server/collections/orchestrator-config.ts +26 -0
  168. package/src/server/migrations/20261110000000-add-usage-pricing-snapshots.ts +1 -8
  169. package/src/server/migrations/20261110010000-add-usage-department-attribution.ts +1 -8
  170. package/src/server/migrations/20261119000000-widen-native-employee-identifiers.ts +37 -0
  171. package/src/server/plugin.ts +58 -8
  172. package/src/server/resources/agent-auto-approval.ts +51 -0
  173. package/src/server/resources/agent-governance.ts +1 -8
  174. package/src/server/resources/agent-harness-profile.ts +1 -8
  175. package/src/server/resources/agent-monitor.ts +1 -8
  176. package/src/server/resources/agent-usage.ts +1 -8
  177. package/src/server/resources/hierarchical-routing.ts +39 -0
  178. package/src/server/resources/native-monitor-format.ts +1 -8
  179. package/src/server/resources/tracing.ts +1 -8
  180. package/src/server/services/AgentGovernanceService.ts +1 -8
  181. package/src/server/services/AutoApprovalCheckpoint.ts +140 -0
  182. package/src/server/services/CodeValidator.ts +23 -4
  183. package/src/server/services/DepartmentAttribution.ts +1 -8
  184. package/src/server/services/ExecutionSpanService.ts +1 -8
  185. package/src/server/services/GovernanceAdmission.ts +83 -8
  186. package/src/server/services/HarnessCapabilities.ts +1 -8
  187. package/src/server/services/HarnessCompiler.ts +12 -0
  188. package/src/server/services/HarnessSchema.ts +30 -0
  189. package/src/server/services/HierarchicalAgentRuntime.ts +1052 -0
  190. package/src/server/services/HierarchyEnrollmentGuard.ts +211 -0
  191. package/src/server/services/HierarchyInvocationJournal.ts +172 -0
  192. package/src/server/services/HierarchyRequestCancellation.ts +132 -0
  193. package/src/server/services/LoopBudgetService.ts +1 -8
  194. package/src/server/services/LoopRunRepository.ts +2 -9
  195. package/src/server/services/LoopRunStateMachine.ts +3 -10
  196. package/src/server/services/LoopTriggerService.ts +1 -8
  197. package/src/server/services/LoopWorkerService.ts +8 -19
  198. package/src/server/services/ManagedPromptProtection.ts +1 -8
  199. package/src/server/services/NativeAgentMonitorSyncService.ts +1 -8
  200. package/src/server/services/NativeSubAgentObserver.ts +1 -8
  201. package/src/server/services/NativeUsageAttribution.ts +1 -8
  202. package/src/server/services/PluginAiRuntimeAdapter.ts +140 -9
  203. package/src/server/services/RoutingBindingRepository.ts +146 -0
  204. package/src/server/services/RoutingBindingValidation.ts +161 -0
  205. package/src/server/services/SandboxRunner.ts +35 -1
  206. package/src/server/services/SessionAutoApproval.ts +167 -0
  207. package/src/server/services/TokenTracker.ts +1 -8
  208. package/src/server/services/TracingRetentionPolicy.ts +1 -8
  209. package/src/server/services/VerificationService.ts +3 -10
  210. package/src/server/skill-hub/plugin.ts +40 -0
  211. package/src/server/skill-hub/services/RegistrySkillInstallationService.ts +11 -1
  212. package/src/server/skill-hub/services/registry-node-package.ts +191 -0
  213. package/src/server/skill-hub/tasks/SkillExecutionTask.ts +34 -5
  214. package/src/server/tools/skill-execute.ts +10 -0
  215. package/src/server/utils/ensure-indexes.ts +2 -8
  216. package/dist/client/418.6f01da17774a5a25.js +0 -10
  217. package/dist/client/652.477e21bfff67bc1c.js +0 -10
  218. package/dist/client-v2/418.55b6b28cda8bb5f3.js +0 -10
  219. package/dist/client-v2/652.1a48364774d5383a.js +0 -10
  220. package/dist/client-v2/981.a81521f0296c7db8.js +0 -10
@@ -1,10 +1,23 @@
1
- import React, { useMemo, useState } from 'react';
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import React, { useMemo, useRef, useState } from 'react';
2
11
  import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons';
3
12
  import {
4
13
  Button,
14
+ Alert,
5
15
  Card,
16
+ Descriptions,
17
+ Divider,
6
18
  Drawer,
7
19
  Form,
20
+ Input,
8
21
  InputNumber,
9
22
  Popconfirm,
10
23
  Select,
@@ -28,20 +41,44 @@ type BindingRecord = {
28
41
  enabled?: boolean;
29
42
  maxDepth?: number;
30
43
  timeout?: number;
44
+ routingEnabled?: boolean;
45
+ routingRole?: 'specialist' | 'worker' | null;
46
+ routingPrompt?: string | null;
47
+ llmService?: string | null;
48
+ model?: string | null;
31
49
  };
32
50
 
33
51
  type ProfileRecord = { tag: string; title?: string; enabled?: boolean };
52
+ type ModelService = {
53
+ llmService: string;
54
+ llmServiceTitle?: string;
55
+ enabledModels: Array<{ value: string; label?: string }>;
56
+ };
57
+ type RoutingPreview = {
58
+ username: string;
59
+ role: 'specialist' | 'worker';
60
+ model: { llmService: string; model: string };
61
+ fallback: boolean;
62
+ profile: { tag: string; version: number };
63
+ specialist?: {
64
+ username: string;
65
+ model: { llmService: string; model: string };
66
+ fallback: boolean;
67
+ profile: { tag: string; version: number };
68
+ };
69
+ };
34
70
 
35
71
  type BindingForm = Omit<BindingRecord, 'id'>;
36
72
 
37
73
  function rowsFromResponse<T>(value: unknown): T[] {
74
+ if (Array.isArray(value)) return value as T[];
38
75
  const response = value as { data?: unknown } | undefined;
39
76
  return Array.isArray(response?.data) ? (response.data as T[]) : [];
40
77
  }
41
78
 
42
79
  function errorText(error: unknown): string {
43
80
  const response = error as { response?: { data?: { errors?: Array<{ message?: string }> } }; message?: string };
44
- return response.response?.data?.errors?.[0]?.message || response.message || 'Unknown error';
81
+ return response?.response?.data?.errors?.[0]?.message || response?.message || 'Unknown error';
45
82
  }
46
83
 
47
84
  export const AgentBindingsTab: React.FC = () => {
@@ -49,8 +86,15 @@ export const AgentBindingsTab: React.FC = () => {
49
86
  const t = useT();
50
87
  const { employeeMap } = useAIEmployees();
51
88
  const [form] = Form.useForm<BindingForm>();
89
+ const routingEnabled = Form.useWatch('routingEnabled', form);
90
+ const llmService = Form.useWatch('llmService', form);
52
91
  const [drawerOpen, setDrawerOpen] = useState(false);
53
92
  const [editing, setEditing] = useState<BindingRecord | null>(null);
93
+ const [previewSessionId, setPreviewSessionId] = useState('');
94
+ const [preview, setPreview] = useState<RoutingPreview | null>(null);
95
+ const [previewLoading, setPreviewLoading] = useState(false);
96
+ const [previewError, setPreviewError] = useState('');
97
+ const previewRequest = useRef(0);
54
98
 
55
99
  const bindingsRequest = useRequest({
56
100
  url: 'orchestratorConfig:list',
@@ -60,9 +104,12 @@ export const AgentBindingsTab: React.FC = () => {
60
104
  url: 'agentHarnessProfiles:list',
61
105
  params: { sort: ['tag'], pageSize: 100 },
62
106
  });
107
+ const modelsRequest = useRequest({ url: 'ai:listAllEnabledModels' });
63
108
 
64
109
  const bindings = useMemo(() => rowsFromResponse<BindingRecord>(bindingsRequest.data), [bindingsRequest.data]);
65
110
  const profiles = useMemo(() => rowsFromResponse<ProfileRecord>(profilesRequest.data), [profilesRequest.data]);
111
+ const services = useMemo(() => rowsFromResponse<ModelService>(modelsRequest.data), [modelsRequest.data]);
112
+ const selectedService = services.find((service) => service.llmService === llmService);
66
113
  const profileOptions = useMemo(
67
114
  () =>
68
115
  profiles
@@ -78,21 +125,58 @@ export const AgentBindingsTab: React.FC = () => {
78
125
  setDrawerOpen(false);
79
126
  setEditing(null);
80
127
  form.resetFields();
128
+ setPreview(null);
129
+ setPreviewError('');
130
+ previewRequest.current += 1;
131
+ setPreviewLoading(false);
132
+ setPreviewSessionId('');
81
133
  };
82
134
 
83
135
  const openDrawer = (binding?: BindingRecord) => {
84
136
  setEditing(binding || null);
137
+ form.resetFields();
138
+ setPreview(null);
139
+ setPreviewError('');
140
+ previewRequest.current += 1;
141
+ setPreviewLoading(false);
142
+ setPreviewSessionId('');
85
143
  form.setFieldsValue(
86
144
  binding || {
87
145
  enabled: true,
88
146
  harnessTag: 'default',
89
147
  maxDepth: 1,
90
148
  timeout: 120000,
149
+ routingEnabled: false,
91
150
  },
92
151
  );
93
152
  setDrawerOpen(true);
94
153
  };
95
154
 
155
+ const previewBinding = async () => {
156
+ if (!editing || !previewSessionId.trim()) return;
157
+ setPreviewLoading(true);
158
+ setPreview(null);
159
+ setPreviewError('');
160
+ const requestId = ++previewRequest.current;
161
+ try {
162
+ const response = await api.request({
163
+ url: 'agentHierarchy:preview',
164
+ method: 'post',
165
+ data: {
166
+ sessionId: previewSessionId.trim(),
167
+ username: editing.subAgentUsername,
168
+ ...(editing.routingRole === 'worker' ? { specialistUsername: editing.leaderUsername } : {}),
169
+ },
170
+ });
171
+ const result = response?.data as { data?: { data?: RoutingPreview } } | undefined;
172
+ if (previewRequest.current === requestId) setPreview(result?.data?.data || null);
173
+ } catch (error) {
174
+ if (previewRequest.current === requestId) setPreviewError(t(errorText(error)));
175
+ } finally {
176
+ if (previewRequest.current === requestId) setPreviewLoading(false);
177
+ }
178
+ };
179
+
96
180
  const saveBinding = async (values: BindingForm) => {
97
181
  const payload = {
98
182
  ...values,
@@ -100,6 +184,15 @@ export const AgentBindingsTab: React.FC = () => {
100
184
  subAgentUsername: values.subAgentUsername?.trim(),
101
185
  harnessTag: values.harnessTag || 'default',
102
186
  enabled: values.enabled !== false,
187
+ routingEnabled: values.routingEnabled === true,
188
+ ...(values.routingEnabled
189
+ ? {
190
+ routingRole: values.routingRole,
191
+ routingPrompt: values.routingPrompt?.trim() || null,
192
+ llmService: values.llmService || null,
193
+ model: values.model || null,
194
+ }
195
+ : {}),
103
196
  };
104
197
  try {
105
198
  if (editing) {
@@ -155,6 +248,17 @@ export const AgentBindingsTab: React.FC = () => {
155
248
  render: (tag: string) => <Tag color="purple">{tag || 'default'}</Tag>,
156
249
  },
157
250
  { title: t('Max Delegation Depth'), dataIndex: 'maxDepth', key: 'maxDepth', width: 140 },
251
+ {
252
+ title: t('Hierarchical routing'),
253
+ dataIndex: 'routingRole',
254
+ key: 'routingRole',
255
+ render: (role: BindingRecord['routingRole'], binding: BindingRecord) =>
256
+ binding.routingEnabled ? (
257
+ <Tag color="blue">{role === 'specialist' ? t('Specialist') : role === 'worker' ? t('Worker') : '-'}</Tag>
258
+ ) : (
259
+ <Tag>{t('Disabled')}</Tag>
260
+ ),
261
+ },
158
262
  {
159
263
  title: t('Enabled'),
160
264
  dataIndex: 'enabled',
@@ -201,7 +305,7 @@ export const AgentBindingsTab: React.FC = () => {
201
305
  <Space direction="vertical" size={16} style={{ width: '100%' }}>
202
306
  <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 16 }}>
203
307
  <Typography.Text type="secondary">
204
- {t('Bind each leader/sub-agent pair to the profile that controls memory and tracing policy.')}
308
+ {t('Bind employees to profiles and opt in to hierarchical delegation.')}
205
309
  </Typography.Text>
206
310
  <Button type="primary" icon={<PlusOutlined />} onClick={() => openDrawer()}>
207
311
  {t('New Agent Binding')}
@@ -259,10 +363,178 @@ export const AgentBindingsTab: React.FC = () => {
259
363
  <Form.Item label={t('Timeout (ms)')} name="timeout">
260
364
  <InputNumber min={1000} max={600000} step={1000} style={{ width: '100%' }} />
261
365
  </Form.Item>
366
+ <Form.Item
367
+ label={t('Enable hierarchical routing')}
368
+ name="routingEnabled"
369
+ valuePropName="checked"
370
+ extra={t('Applies to delegation through the hierarchical routing tool.')}
371
+ >
372
+ <Switch aria-label={t('Enable hierarchical routing')} />
373
+ </Form.Item>
374
+ {routingEnabled && (
375
+ <>
376
+ <Form.Item
377
+ label={t('Target role')}
378
+ name="routingRole"
379
+ rules={[{ required: true, message: t('Choose a routing role for the target employee.') }]}
380
+ >
381
+ <Select
382
+ options={[
383
+ { value: 'specialist', label: t('Specialist') },
384
+ { value: 'worker', label: t('Worker') },
385
+ ]}
386
+ />
387
+ </Form.Item>
388
+ <Form.Item
389
+ label={t('When to delegate')}
390
+ name="routingPrompt"
391
+ extra={t('Describe the tasks this employee is suited to handle.')}
392
+ >
393
+ <Input.TextArea maxLength={4000} showCount rows={3} />
394
+ </Form.Item>
395
+ <Form.Item
396
+ label={t('LLM service override')}
397
+ name="llmService"
398
+ dependencies={['model']}
399
+ extra={t('Leave both model fields empty to use the target employee model.')}
400
+ rules={[
401
+ ({ getFieldValue }) => ({
402
+ validator(_, value) {
403
+ return Boolean(value) === Boolean(getFieldValue('model'))
404
+ ? Promise.resolve()
405
+ : Promise.reject(new Error(t('Select both an LLM service and a model, or leave both empty.')));
406
+ },
407
+ }),
408
+ ]}
409
+ >
410
+ <Select
411
+ allowClear
412
+ showSearch
413
+ optionFilterProp="label"
414
+ loading={modelsRequest.loading}
415
+ options={services.map((service) => ({
416
+ value: service.llmService,
417
+ label: service.llmServiceTitle || service.llmService,
418
+ }))}
419
+ onChange={() => form.setFieldValue('model', undefined)}
420
+ />
421
+ </Form.Item>
422
+ <Form.Item
423
+ label={t('Model override')}
424
+ name="model"
425
+ dependencies={['llmService']}
426
+ rules={[
427
+ ({ getFieldValue }) => ({
428
+ validator(_, value) {
429
+ return Boolean(value) === Boolean(getFieldValue('llmService'))
430
+ ? Promise.resolve()
431
+ : Promise.reject(new Error(t('Select both an LLM service and a model, or leave both empty.')));
432
+ },
433
+ }),
434
+ ]}
435
+ >
436
+ <Select
437
+ allowClear
438
+ showSearch
439
+ optionFilterProp="label"
440
+ loading={modelsRequest.loading}
441
+ disabled={!llmService}
442
+ options={(selectedService?.enabledModels || []).map((model) => ({
443
+ value: model.value,
444
+ label: model.label || model.value,
445
+ }))}
446
+ />
447
+ </Form.Item>
448
+ {modelsRequest.error && (
449
+ <Typography.Text type="danger">{t('Unable to load enabled models.')}</Typography.Text>
450
+ )}
451
+ </>
452
+ )}
262
453
  <Form.Item label={t('Enabled')} name="enabled" valuePropName="checked">
263
454
  <Switch />
264
455
  </Form.Item>
265
456
  </Form>
457
+ {editing?.routingEnabled && (editing.routingRole === 'specialist' || editing.routingRole === 'worker') && (
458
+ <>
459
+ <Divider orientation="left">{t('Preview effective routing')}</Divider>
460
+ <Typography.Paragraph type="secondary">
461
+ {t('Preview uses the saved binding, published profile and a conversation owned by your user.')}
462
+ </Typography.Paragraph>
463
+ {editing.routingRole === 'worker' && (
464
+ <>
465
+ <Typography.Paragraph type="secondary">
466
+ {t('The conversation must belong to an orchestrator bound to this worker’s specialist.')}
467
+ </Typography.Paragraph>
468
+ <Typography.Paragraph type="secondary">
469
+ {t('Preview does not check worker tools that depend on a child session.')}
470
+ </Typography.Paragraph>
471
+ </>
472
+ )}
473
+ <Input
474
+ value={previewSessionId}
475
+ onChange={(event) => {
476
+ setPreviewSessionId(event.target.value);
477
+ setPreview(null);
478
+ setPreviewError('');
479
+ previewRequest.current += 1;
480
+ setPreviewLoading(false);
481
+ }}
482
+ aria-label={t('Conversation ID')}
483
+ placeholder={t('Conversation ID')}
484
+ />
485
+ <Button
486
+ style={{ marginTop: 12 }}
487
+ loading={previewLoading}
488
+ disabled={!previewSessionId.trim()}
489
+ onClick={previewBinding}
490
+ >
491
+ {t('Preview effective routing')}
492
+ </Button>
493
+ {previewError && (
494
+ <Alert
495
+ type="error"
496
+ showIcon
497
+ style={{ marginTop: 12 }}
498
+ message={t('Preview failed: {{message}}', { message: previewError })}
499
+ />
500
+ )}
501
+ {preview && (
502
+ <>
503
+ {preview.specialist && (
504
+ <Descriptions title={t('Specialist')} size="small" column={1} style={{ marginTop: 12 }}>
505
+ <Descriptions.Item label={t('Sub-Agent')}>{preview.specialist.username}</Descriptions.Item>
506
+ <Descriptions.Item label={t('Policy Profile')}>
507
+ {preview.specialist.profile.tag} v{preview.specialist.profile.version}
508
+ </Descriptions.Item>
509
+ <Descriptions.Item label={t('Effective model')}>
510
+ {preview.specialist.model.llmService} / {preview.specialist.model.model}
511
+ </Descriptions.Item>
512
+ <Descriptions.Item label={t('Fallback model selected')}>
513
+ {preview.specialist.fallback ? t('Yes') : t('No')}
514
+ </Descriptions.Item>
515
+ </Descriptions>
516
+ )}
517
+ <Descriptions
518
+ title={preview.specialist ? t('Worker') : undefined}
519
+ size="small"
520
+ column={1}
521
+ style={{ marginTop: 12 }}
522
+ >
523
+ <Descriptions.Item label={t('Sub-Agent')}>{preview.username}</Descriptions.Item>
524
+ <Descriptions.Item label={t('Policy Profile')}>
525
+ {preview.profile.tag} v{preview.profile.version}
526
+ </Descriptions.Item>
527
+ <Descriptions.Item label={t('Effective model')}>
528
+ {preview.model.llmService} / {preview.model.model}
529
+ </Descriptions.Item>
530
+ <Descriptions.Item label={t('Fallback model selected')}>
531
+ {preview.fallback ? t('Yes') : t('No')}
532
+ </Descriptions.Item>
533
+ </Descriptions>
534
+ </>
535
+ )}
536
+ </>
537
+ )}
266
538
  </Drawer>
267
539
  </Card>
268
540
  );
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import React, { useMemo, useRef, useState } from 'react';
11
4
  import {
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import React, { useMemo, useState } from 'react';
11
4
  import {
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import React from 'react';
11
4
  import {
@@ -27,6 +20,7 @@ import {
27
20
  import { CheckOutlined, DeleteOutlined, EditOutlined, PlusOutlined, SaveOutlined } from '@ant-design/icons';
28
21
  import { useApiClient as useAPIClient, useRequest } from '../hooks/useApiRequest';
29
22
  import { useT } from '../skill-hub/locale';
23
+ import { HarnessSettingsForm } from './HarnessSettingsForm';
30
24
 
31
25
  const { Text } = Typography;
32
26
 
@@ -664,6 +658,8 @@ export const HarnessProfilesTab: React.FC = () => {
664
658
  <Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
665
659
  {t('Saving updates the open draft (or creates one). Publishing makes the draft the active version.')}
666
660
  </Text>
661
+ <HarnessSettingsForm value={settingsText} onChange={setSettingsText} />
662
+ <Text>{t('Advanced settings JSON')}</Text>
667
663
  <Input.TextArea
668
664
  aria-label={t('Settings JSON')}
669
665
  rows={12}
@@ -0,0 +1,221 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import React from 'react';
11
+ import { Button, Cascader, Form, InputNumber, Select, Space, Typography } from 'antd';
12
+ import { useT } from '../skill-hub/locale';
13
+ import { useRequest } from '../hooks/useApiRequest';
14
+
15
+ type JsonRecord = Record<string, unknown>;
16
+
17
+ function objectValue(value: unknown): JsonRecord {
18
+ return value && typeof value === 'object' && !Array.isArray(value) ? (value as JsonRecord) : {};
19
+ }
20
+
21
+ function stringList(value: unknown): string[] {
22
+ return Array.isArray(value) ? value.filter((item): item is string => typeof item === 'string') : [];
23
+ }
24
+
25
+ export function HarnessSettingsForm({ value, onChange }: { value: string; onChange: (value: string) => void }) {
26
+ const t = useT();
27
+ const modelsRequest = useRequest({ url: 'ai:listAllEnabledModels' });
28
+ let parsed: JsonRecord;
29
+ try {
30
+ const input: unknown = JSON.parse(value || '{}');
31
+ if (!input || typeof input !== 'object' || Array.isArray(input)) return null;
32
+ parsed = input as JsonRecord;
33
+ } catch {
34
+ return null;
35
+ }
36
+
37
+ const tools = objectValue(parsed.tools);
38
+ const effects = objectValue(tools.effects);
39
+ const limits = objectValue(parsed.limits);
40
+ const routing = objectValue(parsed.routing);
41
+ const models = objectValue(routing.models);
42
+ const primary = objectValue(models.primary);
43
+ const fallback = Array.isArray(models.fallback) ? models.fallback.map(objectValue) : [];
44
+ const rawServices = Array.isArray(modelsRequest.data) ? modelsRequest.data : objectValue(modelsRequest.data).data;
45
+ const services = Array.isArray(rawServices) ? rawServices.map(objectValue) : [];
46
+ const modelOptions = services
47
+ .filter((service) => typeof service.llmService === 'string')
48
+ .map((service) => ({
49
+ value: String(service.llmService),
50
+ label: String(service.llmServiceTitle || service.llmService),
51
+ children: (Array.isArray(service.enabledModels) ? service.enabledModels.map(objectValue) : [])
52
+ .filter((model) => typeof model.value === 'string')
53
+ .map((model) => ({ value: String(model.value), label: String(model.label || model.value) })),
54
+ }));
55
+ const modelPair = (item: JsonRecord) =>
56
+ typeof item.llmService === 'string' && typeof item.model === 'string' ? [item.llmService, item.model] : undefined;
57
+ const setModels = (newValues: JsonRecord) => {
58
+ onChange(JSON.stringify({ ...parsed, routing: { ...routing, models: { ...models, ...newValues } } }, null, 2));
59
+ };
60
+ const setValue = (section: string, field: string, newValue: unknown) => {
61
+ const next = {
62
+ ...parsed,
63
+ [section]: { ...objectValue(parsed[section]), [field]: newValue },
64
+ };
65
+ onChange(JSON.stringify(next, null, 2));
66
+ };
67
+
68
+ return (
69
+ <Form layout="vertical">
70
+ <Typography.Text type="secondary">
71
+ {t('These settings apply only where the capability matrix shows support.')}
72
+ </Typography.Text>
73
+ <Form.Item
74
+ label={t('Profile model')}
75
+ extra={t('A binding model override takes precedence. An empty profile model uses the employee model.')}
76
+ >
77
+ <Cascader
78
+ allowClear
79
+ options={modelOptions}
80
+ loading={modelsRequest.loading}
81
+ value={modelPair(primary)}
82
+ onChange={(selection) => {
83
+ const pair = Array.isArray(selection) ? selection : [];
84
+ setModels({
85
+ primary:
86
+ typeof pair[0] === 'string' && typeof pair[1] === 'string'
87
+ ? { llmService: pair[0], model: pair[1] }
88
+ : null,
89
+ });
90
+ }}
91
+ aria-label={t('Profile model')}
92
+ />
93
+ </Form.Item>
94
+ <Form.Item
95
+ label={t('Fallback models')}
96
+ extra={t('Checked in order before execution when a configured model is unavailable.')}
97
+ >
98
+ <Cascader
99
+ multiple
100
+ allowClear
101
+ options={modelOptions}
102
+ loading={modelsRequest.loading}
103
+ value={fallback.map(modelPair).filter((pair): pair is string[] => Boolean(pair))}
104
+ onChange={(selection) => {
105
+ const pairs = Array.isArray(selection) ? selection : [];
106
+ setModels({
107
+ fallback: pairs
108
+ .filter(
109
+ (pair): pair is [string, string] =>
110
+ Array.isArray(pair) && typeof pair[0] === 'string' && typeof pair[1] === 'string',
111
+ )
112
+ .map(([llmService, model]) => ({ llmService, model })),
113
+ });
114
+ }}
115
+ aria-label={t('Fallback models')}
116
+ />
117
+ </Form.Item>
118
+ {fallback.length > 1 && (
119
+ <Space direction="vertical" style={{ width: '100%', marginBottom: 16 }}>
120
+ {fallback.map((model, index) => {
121
+ const label = modelPair(model)?.join(' / ') || '-';
122
+ const move = (offset: number) => {
123
+ const reordered = [...fallback];
124
+ const target = index + offset;
125
+ [reordered[index], reordered[target]] = [reordered[target], reordered[index]];
126
+ setModels({ fallback: reordered });
127
+ };
128
+ return (
129
+ <Space key={`${label}-${index}`}>
130
+ <Typography.Text>{label}</Typography.Text>
131
+ <Button
132
+ size="small"
133
+ disabled={index === 0}
134
+ aria-label={t('Move {{model}} up', { model: label })}
135
+ onClick={() => move(-1)}
136
+ >
137
+ {t('Move up')}
138
+ </Button>
139
+ <Button
140
+ size="small"
141
+ disabled={index === fallback.length - 1}
142
+ aria-label={t('Move {{model}} down', { model: label })}
143
+ onClick={() => move(1)}
144
+ >
145
+ {t('Move down')}
146
+ </Button>
147
+ </Space>
148
+ );
149
+ })}
150
+ </Space>
151
+ )}
152
+ {modelsRequest.error && <Typography.Text type="danger">{t('Unable to load enabled models.')}</Typography.Text>}
153
+ <Form.Item label={t('Allowed tools')}>
154
+ <Select
155
+ mode="tags"
156
+ value={stringList(tools.allow)}
157
+ onChange={(names: string[]) => setValue('tools', 'allow', names)}
158
+ aria-label={t('Allowed tools')}
159
+ />
160
+ </Form.Item>
161
+ <Form.Item
162
+ label={t('Read-only tools')}
163
+ extra={t('Classify a tool as read-only only after verifying its behavior and permissions.')}
164
+ >
165
+ <Select
166
+ mode="tags"
167
+ value={Object.entries(effects)
168
+ .filter(([, effect]) => effect === 'read')
169
+ .map(([name]) => name)}
170
+ onChange={(names: string[]) => {
171
+ const remaining = Object.fromEntries(Object.entries(effects).filter(([, effect]) => effect !== 'read'));
172
+ setValue('tools', 'effects', {
173
+ ...remaining,
174
+ ...Object.fromEntries(names.map((name) => [name, 'read'])),
175
+ });
176
+ }}
177
+ aria-label={t('Read-only tools')}
178
+ />
179
+ </Form.Item>
180
+ <Form.Item label={t('Tools requiring approval')}>
181
+ <Select
182
+ mode="tags"
183
+ value={stringList(tools.ask)}
184
+ onChange={(names: string[]) => setValue('tools', 'ask', names)}
185
+ aria-label={t('Tools requiring approval')}
186
+ />
187
+ </Form.Item>
188
+ <Form.Item label={t('Denied tools')}>
189
+ <Select
190
+ mode="tags"
191
+ value={stringList(tools.deny)}
192
+ onChange={(names: string[]) => setValue('tools', 'deny', names)}
193
+ aria-label={t('Denied tools')}
194
+ />
195
+ </Form.Item>
196
+ <Form.Item
197
+ label={t('Maximum tool calls')}
198
+ extra={t('Hierarchical chat does not yet support this limit and rejects profiles that set it.')}
199
+ >
200
+ <InputNumber
201
+ min={0}
202
+ precision={0}
203
+ style={{ width: '100%' }}
204
+ value={typeof limits.maxToolCalls === 'number' ? limits.maxToolCalls : null}
205
+ onChange={(next) => setValue('limits', 'maxToolCalls', next)}
206
+ aria-label={t('Maximum tool calls')}
207
+ />
208
+ </Form.Item>
209
+ <Form.Item label={t('Timeout (ms)')}>
210
+ <InputNumber
211
+ min={1}
212
+ precision={0}
213
+ style={{ width: '100%' }}
214
+ value={typeof limits.timeoutMs === 'number' ? limits.timeoutMs : null}
215
+ onChange={(next) => setValue('limits', 'timeoutMs', next)}
216
+ aria-label={t('Timeout (ms)')}
217
+ />
218
+ </Form.Item>
219
+ </Form>
220
+ );
221
+ }
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import React, { useMemo, useState } from 'react';
11
4
  import { Alert, Button, Card, DatePicker, Form, Input, Select, Space, Switch, Table, Tag, Typography } from 'antd';
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import React from 'react';
11
4
  import { AIEmployeesProvider } from '../components/AIEmployeesContext';