plugin-agent-orchestrator 1.0.38 → 1.1.2

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 (192) hide show
  1. package/dist/client/index.js +1 -1
  2. package/dist/client-v2/253.9f0537713cee9e6c.js +10 -0
  3. package/dist/client-v2/418.ce8f5b2b8a229d1d.js +10 -0
  4. package/dist/client-v2/53.7c29c28043e9112d.js +10 -0
  5. package/dist/client-v2/794.9bbb8d3a61b2bdf2.js +10 -0
  6. package/dist/client-v2/993.82778b6fd6db3cb1.js +10 -0
  7. package/dist/client-v2/index.js +1 -1
  8. package/dist/externalVersion.js +6 -6
  9. package/dist/locale/en-US.json +56 -2
  10. package/dist/locale/vi-VN.json +56 -2
  11. package/dist/locale/zh-CN.json +56 -2
  12. package/dist/node_modules/ajv/.tonic_example.js +20 -0
  13. package/dist/node_modules/ajv/LICENSE +22 -0
  14. package/dist/node_modules/ajv/dist/ajv.bundle.js +7189 -0
  15. package/dist/node_modules/ajv/dist/ajv.min.js +3 -0
  16. package/dist/node_modules/ajv/lib/ajv.d.ts +397 -0
  17. package/dist/node_modules/ajv/lib/ajv.js +3 -0
  18. package/dist/node_modules/ajv/lib/cache.js +26 -0
  19. package/dist/node_modules/ajv/lib/compile/async.js +90 -0
  20. package/dist/node_modules/ajv/lib/compile/equal.js +5 -0
  21. package/dist/node_modules/ajv/lib/compile/error_classes.js +34 -0
  22. package/dist/node_modules/ajv/lib/compile/formats.js +142 -0
  23. package/dist/node_modules/ajv/lib/compile/index.js +387 -0
  24. package/dist/node_modules/ajv/lib/compile/resolve.js +270 -0
  25. package/dist/node_modules/ajv/lib/compile/rules.js +66 -0
  26. package/dist/node_modules/ajv/lib/compile/schema_obj.js +9 -0
  27. package/dist/node_modules/ajv/lib/compile/ucs2length.js +20 -0
  28. package/dist/node_modules/ajv/lib/compile/util.js +239 -0
  29. package/dist/node_modules/ajv/lib/data.js +49 -0
  30. package/dist/node_modules/ajv/lib/definition_schema.js +37 -0
  31. package/dist/node_modules/ajv/lib/dot/_limit.jst +113 -0
  32. package/dist/node_modules/ajv/lib/dot/_limitItems.jst +12 -0
  33. package/dist/node_modules/ajv/lib/dot/_limitLength.jst +12 -0
  34. package/dist/node_modules/ajv/lib/dot/_limitProperties.jst +12 -0
  35. package/dist/node_modules/ajv/lib/dot/allOf.jst +32 -0
  36. package/dist/node_modules/ajv/lib/dot/anyOf.jst +46 -0
  37. package/dist/node_modules/ajv/lib/dot/coerce.def +51 -0
  38. package/dist/node_modules/ajv/lib/dot/comment.jst +9 -0
  39. package/dist/node_modules/ajv/lib/dot/const.jst +11 -0
  40. package/dist/node_modules/ajv/lib/dot/contains.jst +55 -0
  41. package/dist/node_modules/ajv/lib/dot/custom.jst +191 -0
  42. package/dist/node_modules/ajv/lib/dot/defaults.def +47 -0
  43. package/dist/node_modules/ajv/lib/dot/definitions.def +203 -0
  44. package/dist/node_modules/ajv/lib/dot/dependencies.jst +79 -0
  45. package/dist/node_modules/ajv/lib/dot/enum.jst +30 -0
  46. package/dist/node_modules/ajv/lib/dot/errors.def +194 -0
  47. package/dist/node_modules/ajv/lib/dot/format.jst +106 -0
  48. package/dist/node_modules/ajv/lib/dot/if.jst +73 -0
  49. package/dist/node_modules/ajv/lib/dot/items.jst +98 -0
  50. package/dist/node_modules/ajv/lib/dot/missing.def +39 -0
  51. package/dist/node_modules/ajv/lib/dot/multipleOf.jst +22 -0
  52. package/dist/node_modules/ajv/lib/dot/not.jst +43 -0
  53. package/dist/node_modules/ajv/lib/dot/oneOf.jst +54 -0
  54. package/dist/node_modules/ajv/lib/dot/pattern.jst +14 -0
  55. package/dist/node_modules/ajv/lib/dot/properties.jst +245 -0
  56. package/dist/node_modules/ajv/lib/dot/propertyNames.jst +52 -0
  57. package/dist/node_modules/ajv/lib/dot/ref.jst +85 -0
  58. package/dist/node_modules/ajv/lib/dot/required.jst +108 -0
  59. package/dist/node_modules/ajv/lib/dot/uniqueItems.jst +62 -0
  60. package/dist/node_modules/ajv/lib/dot/validate.jst +276 -0
  61. package/dist/node_modules/ajv/lib/dotjs/_limit.js +163 -0
  62. package/dist/node_modules/ajv/lib/dotjs/_limitItems.js +80 -0
  63. package/dist/node_modules/ajv/lib/dotjs/_limitLength.js +85 -0
  64. package/dist/node_modules/ajv/lib/dotjs/_limitProperties.js +80 -0
  65. package/dist/node_modules/ajv/lib/dotjs/allOf.js +42 -0
  66. package/dist/node_modules/ajv/lib/dotjs/anyOf.js +73 -0
  67. package/dist/node_modules/ajv/lib/dotjs/comment.js +14 -0
  68. package/dist/node_modules/ajv/lib/dotjs/const.js +56 -0
  69. package/dist/node_modules/ajv/lib/dotjs/contains.js +81 -0
  70. package/dist/node_modules/ajv/lib/dotjs/custom.js +228 -0
  71. package/dist/node_modules/ajv/lib/dotjs/dependencies.js +168 -0
  72. package/dist/node_modules/ajv/lib/dotjs/enum.js +66 -0
  73. package/dist/node_modules/ajv/lib/dotjs/format.js +150 -0
  74. package/dist/node_modules/ajv/lib/dotjs/if.js +103 -0
  75. package/dist/node_modules/ajv/lib/dotjs/index.js +33 -0
  76. package/dist/node_modules/ajv/lib/dotjs/items.js +140 -0
  77. package/dist/node_modules/ajv/lib/dotjs/multipleOf.js +80 -0
  78. package/dist/node_modules/ajv/lib/dotjs/not.js +84 -0
  79. package/dist/node_modules/ajv/lib/dotjs/oneOf.js +73 -0
  80. package/dist/node_modules/ajv/lib/dotjs/pattern.js +75 -0
  81. package/dist/node_modules/ajv/lib/dotjs/properties.js +335 -0
  82. package/dist/node_modules/ajv/lib/dotjs/propertyNames.js +81 -0
  83. package/dist/node_modules/ajv/lib/dotjs/ref.js +124 -0
  84. package/dist/node_modules/ajv/lib/dotjs/required.js +270 -0
  85. package/dist/node_modules/ajv/lib/dotjs/uniqueItems.js +86 -0
  86. package/dist/node_modules/ajv/lib/dotjs/validate.js +482 -0
  87. package/dist/node_modules/ajv/lib/keyword.js +146 -0
  88. package/dist/node_modules/ajv/lib/refs/data.json +17 -0
  89. package/dist/node_modules/ajv/lib/refs/json-schema-draft-04.json +149 -0
  90. package/dist/node_modules/ajv/lib/refs/json-schema-draft-06.json +154 -0
  91. package/dist/node_modules/ajv/lib/refs/json-schema-draft-07.json +168 -0
  92. package/dist/node_modules/ajv/lib/refs/json-schema-secure.json +94 -0
  93. package/dist/node_modules/ajv/node_modules/json-schema-traverse/.eslintrc.yml +27 -0
  94. package/dist/node_modules/ajv/node_modules/json-schema-traverse/.travis.yml +8 -0
  95. package/dist/node_modules/ajv/node_modules/json-schema-traverse/index.js +89 -0
  96. package/dist/node_modules/ajv/node_modules/json-schema-traverse/package.json +43 -0
  97. package/dist/node_modules/ajv/node_modules/json-schema-traverse/spec/.eslintrc.yml +6 -0
  98. package/dist/node_modules/ajv/node_modules/json-schema-traverse/spec/fixtures/schema.js +125 -0
  99. package/dist/node_modules/ajv/node_modules/json-schema-traverse/spec/index.spec.js +171 -0
  100. package/dist/node_modules/ajv/package.json +1 -0
  101. package/dist/node_modules/ajv/scripts/.eslintrc.yml +3 -0
  102. package/dist/node_modules/ajv/scripts/bundle.js +61 -0
  103. package/dist/node_modules/ajv/scripts/compile-dots.js +73 -0
  104. package/dist/node_modules/ajv/scripts/info +10 -0
  105. package/dist/node_modules/ajv/scripts/prepare-tests +12 -0
  106. package/dist/node_modules/ajv/scripts/publish-built-version +32 -0
  107. package/dist/node_modules/ajv/scripts/travis-gh-pages +23 -0
  108. package/dist/server/collections/skill-definitions.js +31 -0
  109. package/dist/server/collections/skill-executions.js +19 -0
  110. package/dist/server/collections/skill-registry-installations.js +70 -0
  111. package/dist/server/migrations/20260621000000-native-policy-profile-defaults.js +0 -3
  112. package/dist/server/migrations/20260727000000-remove-unused-knowledge-scopes.js +51 -0
  113. package/dist/server/migrations/20260727010000-backfill-skill-tool-names.js +66 -0
  114. package/dist/server/plugin.js +107 -2
  115. package/dist/server/resources/agent-knowledge-insights.js +273 -0
  116. package/dist/server/services/AgentExecutionContext.js +45 -0
  117. package/dist/server/services/AgentMemoryContextService.js +57 -19
  118. package/dist/server/services/CodeValidator.js +1 -0
  119. package/dist/server/services/ExecutionSpanService.js +10 -2
  120. package/dist/server/services/InputSchemaValidator.js +83 -0
  121. package/dist/server/services/NativeSubAgentObserver.js +63 -8
  122. package/dist/server/services/SandboxRunner.js +6 -2
  123. package/dist/server/services/SkillAccessService.js +109 -0
  124. package/dist/server/services/SkillManager.js +2 -0
  125. package/dist/server/services/SkillRepositoryService.js +70 -0
  126. package/dist/server/skill-hub/actions/git-import.js +479 -216
  127. package/dist/server/skill-hub/mcp/McpController.js +8 -5
  128. package/dist/server/skill-hub/middlewares/git-import-request-method-policy.js +69 -0
  129. package/dist/server/skill-hub/plugin.js +68 -14
  130. package/dist/server/skill-hub/services/RegistrySkillInstallationService.js +249 -0
  131. package/dist/server/skill-hub/services/RegistrySkillSnapshotService.js +228 -0
  132. package/dist/server/skill-hub/tasks/SkillExecutionTask.js +15 -3
  133. package/dist/server/tools/external-rag-search.js +152 -12
  134. package/dist/server/tools/skill-execute.js +23 -2
  135. package/dist/server/utils/ctx-utils.js +2 -2
  136. package/dist/server/utils/skill-tool-name.js +73 -0
  137. package/package.json +9 -3
  138. package/src/client-v2/components/AgentBindingsTab.tsx +269 -0
  139. package/src/client-v2/components/HarnessProfilesTab.tsx +1 -2
  140. package/src/client-v2/components/KnowledgeAccessTab.tsx +116 -0
  141. package/src/client-v2/components/MemoryInspectorTab.tsx +125 -0
  142. package/src/client-v2/components/RetrievalTraceTab.tsx +162 -0
  143. package/src/client-v2/pages/AgentBindingsPage.tsx +13 -0
  144. package/src/client-v2/pages/KnowledgeAccessPage.tsx +10 -0
  145. package/src/client-v2/pages/MemoryInspectorPage.tsx +13 -0
  146. package/src/client-v2/pages/RetrievalTracePage.tsx +10 -0
  147. package/src/client-v2/plugin.tsx +28 -0
  148. package/src/locale/en-US.json +56 -2
  149. package/src/locale/vi-VN.json +56 -2
  150. package/src/locale/zh-CN.json +56 -2
  151. package/src/server/__tests__/agent-execution-context.test.ts +18 -0
  152. package/src/server/__tests__/agent-knowledge-insights.test.ts +123 -0
  153. package/src/server/__tests__/external-rag-search.test.ts +107 -0
  154. package/src/server/__tests__/input-schema-validator.test.ts +26 -0
  155. package/src/server/__tests__/native-sub-agent-observer.test.ts +141 -9
  156. package/src/server/__tests__/skill-access-service.test.ts +64 -0
  157. package/src/server/__tests__/skill-execute.test.ts +37 -0
  158. package/src/server/__tests__/skill-tool-name.test.ts +23 -0
  159. package/src/server/collections/skill-definitions.ts +31 -0
  160. package/src/server/collections/skill-executions.ts +19 -0
  161. package/src/server/collections/skill-registry-installations.ts +41 -0
  162. package/src/server/migrations/20260621000000-native-policy-profile-defaults.ts +0 -3
  163. package/src/server/migrations/20260727000000-remove-unused-knowledge-scopes.ts +25 -0
  164. package/src/server/migrations/20260727010000-backfill-skill-tool-names.ts +45 -0
  165. package/src/server/plugin.ts +107 -1
  166. package/src/server/resources/agent-knowledge-insights.ts +304 -0
  167. package/src/server/services/AgentExecutionContext.ts +23 -0
  168. package/src/server/services/AgentMemoryContextService.ts +63 -19
  169. package/src/server/services/CodeValidator.ts +1 -0
  170. package/src/server/services/ExecutionSpanService.ts +119 -110
  171. package/src/server/services/InputSchemaValidator.ts +44 -0
  172. package/src/server/services/NativeSubAgentObserver.ts +592 -528
  173. package/src/server/services/SandboxRunner.ts +6 -0
  174. package/src/server/services/SkillAccessService.ts +100 -0
  175. package/src/server/services/SkillManager.ts +2 -0
  176. package/src/server/services/SkillRepositoryService.ts +98 -2
  177. package/src/server/services/__tests__/SkillRepositoryService.test.ts +33 -0
  178. package/src/server/skill-hub/actions/__tests__/git-import.test.ts +501 -0
  179. package/src/server/skill-hub/actions/git-import.ts +682 -236
  180. package/src/server/skill-hub/mcp/McpController.ts +8 -14
  181. package/src/server/skill-hub/middlewares/git-import-request-method-policy.ts +51 -0
  182. package/src/server/skill-hub/plugin.ts +79 -13
  183. package/src/server/skill-hub/services/RegistrySkillInstallationService.ts +281 -0
  184. package/src/server/skill-hub/services/RegistrySkillSnapshotService.ts +239 -0
  185. package/src/server/skill-hub/services/__tests__/RegistrySkillInstallationService.test.ts +295 -0
  186. package/src/server/skill-hub/services/__tests__/RegistrySkillSnapshotService.test.ts +63 -0
  187. package/src/server/skill-hub/tasks/SkillExecutionTask.ts +14 -2
  188. package/src/server/tools/external-rag-search.ts +215 -14
  189. package/src/server/tools/skill-execute.ts +24 -2
  190. package/src/server/utils/ctx-utils.ts +1 -1
  191. package/src/server/utils/skill-tool-name.ts +58 -0
  192. package/dist/client-v2/418.29e713f79131eece.js +0 -10
@@ -0,0 +1,107 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { createExternalRagSearchTool } from '../tools/external-rag-search';
3
+
4
+ function createToolHarness(knowledgeBase = { knowledgeBaseKeys: ['kb-allowed'] }) {
5
+ const searchKnowledgeBases = vi.fn(async () => [
6
+ {
7
+ id: 'segment-1',
8
+ content: 'Relevant deployment documentation',
9
+ score: 0.9,
10
+ metadata: {
11
+ documentId: 'doc-1',
12
+ filename: 'deployment.md',
13
+ apiKey: 'must-not-leak',
14
+ internalNotes: 'must-not-leak',
15
+ },
16
+ },
17
+ ]);
18
+ const repositories = {
19
+ aiEmployees: {
20
+ findOne: vi.fn(async () => ({ knowledgeBase })),
21
+ },
22
+ aiToolMessages: { findOne: vi.fn() },
23
+ aiConversations: { findOne: vi.fn() },
24
+ };
25
+ const plugin = { app: { log: { error: vi.fn() } } };
26
+ const tool = createExternalRagSearchTool(plugin);
27
+ const ctx = {
28
+ _currentAIEmployee: { username: 'researcher' },
29
+ app: {
30
+ pm: {
31
+ get: vi.fn((name: string) => (name === 'plugin-knowledge-base' ? { searchKnowledgeBases } : undefined)),
32
+ },
33
+ },
34
+ db: {
35
+ getRepository: vi.fn((name: keyof typeof repositories) => repositories[name]),
36
+ },
37
+ };
38
+
39
+ return { tool, ctx, searchKnowledgeBases, repositories };
40
+ }
41
+
42
+ describe('external_rag_search', () => {
43
+ it('searches only knowledge bases assigned to the requesting AI Employee', async () => {
44
+ const { tool, ctx, searchKnowledgeBases } = createToolHarness();
45
+
46
+ const response = await tool.invoke(ctx, { query: 'deployment process' });
47
+
48
+ expect(searchKnowledgeBases).toHaveBeenCalledWith(
49
+ expect.objectContaining({
50
+ _currentAIEmployee: { username: 'researcher' },
51
+ state: expect.objectContaining({ currentAIEmployee: { username: 'researcher' } }),
52
+ }),
53
+ 'deployment process',
54
+ expect.objectContaining({ knowledgeBaseIds: ['kb-allowed'], rerank: true }),
55
+ );
56
+ expect(response.status).toBe('success');
57
+ const content = JSON.parse(response.content) as { results: Array<{ metadata: Record<string, unknown> }> };
58
+ expect(content.results[0].metadata).toEqual({ documentId: 'doc-1', filename: 'deployment.md' });
59
+ });
60
+
61
+ it('rejects explicit knowledge base IDs that are not assigned to the AI Employee', async () => {
62
+ const { tool, ctx, searchKnowledgeBases } = createToolHarness();
63
+
64
+ const response = await tool.invoke(ctx, {
65
+ query: 'deployment process',
66
+ knowledgeBaseIds: ['kb-not-allowed'],
67
+ });
68
+
69
+ expect(response).toEqual(
70
+ expect.objectContaining({ status: 'error', content: expect.stringContaining('not assigned to AI Employee') }),
71
+ );
72
+ expect(searchKnowledgeBases).not.toHaveBeenCalled();
73
+ });
74
+
75
+ it('reads and de-duplicates current NocoBase knowledgeBaseIds settings', async () => {
76
+ const { tool, ctx, searchKnowledgeBases } = createToolHarness({
77
+ knowledgeBaseIds: ['kb-current', 'kb-current'],
78
+ });
79
+
80
+ const response = await tool.invoke(ctx, { query: 'deployment process' });
81
+
82
+ expect(searchKnowledgeBases).toHaveBeenCalledWith(
83
+ expect.any(Object),
84
+ 'deployment process',
85
+ expect.objectContaining({ knowledgeBaseIds: ['kb-current'] }),
86
+ );
87
+ expect(response.status).toBe('success');
88
+ });
89
+
90
+ it('resolves the AI Employee from the tool call when runtime context has no employee', async () => {
91
+ const { tool, ctx, searchKnowledgeBases, repositories } = createToolHarness();
92
+ delete ctx._currentAIEmployee;
93
+ repositories.aiToolMessages.findOne.mockResolvedValue({ sessionId: 'session-1' });
94
+ repositories.aiConversations.findOne.mockResolvedValue({ aiEmployeeUsername: 'researcher' });
95
+
96
+ const response = await tool.invoke(ctx, { query: 'deployment process' }, { toolCallId: 'tool-call-1' });
97
+
98
+ expect(repositories.aiToolMessages.findOne).toHaveBeenCalledWith({ filter: { toolCallId: 'tool-call-1' } });
99
+ expect(repositories.aiConversations.findOne).toHaveBeenCalledWith({ filter: { sessionId: 'session-1' } });
100
+ expect(searchKnowledgeBases).toHaveBeenCalledWith(
101
+ expect.objectContaining({ _currentAIEmployee: { username: 'researcher' } }),
102
+ 'deployment process',
103
+ expect.objectContaining({ knowledgeBaseIds: ['kb-allowed'] }),
104
+ );
105
+ expect(response.status).toBe('success');
106
+ });
107
+ });
@@ -0,0 +1,26 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { validateInputSchemaDefinition, validateSkillInput } from '../services/InputSchemaValidator';
3
+
4
+ const schema = {
5
+ type: 'object',
6
+ properties: {
7
+ title: { type: 'string' },
8
+ count: { type: 'integer', minimum: 1 },
9
+ },
10
+ required: ['title'],
11
+ additionalProperties: false,
12
+ };
13
+
14
+ describe('InputSchemaValidator', () => {
15
+ it('accepts valid input', () => {
16
+ expect(() => validateSkillInput(schema, { title: 'Report', count: 2 })).not.toThrow();
17
+ });
18
+
19
+ it('rejects missing, mistyped, and unknown input fields', () => {
20
+ expect(() => validateSkillInput(schema, { count: 0, unexpected: true })).toThrow('Skill input validation failed');
21
+ });
22
+
23
+ it('rejects malformed schema definitions before execution', () => {
24
+ expect(() => validateInputSchemaDefinition('{invalid json')).toThrow('valid JSON Schema object');
25
+ });
26
+ });
@@ -1,14 +1,30 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
2
  import { AgentMemoryContextService } from '../services/AgentMemoryContextService';
3
3
  import { NativeSubAgentObserver } from '../services/NativeSubAgentObserver';
4
+ import { getAgentExecutionContext } from '../services/AgentExecutionContext';
4
5
 
5
- function createObserverHarness(profileSettings: Record<string, unknown> | null = {}) {
6
+ function createObserverHarness(
7
+ profileSettings: Record<string, unknown> | null = {},
8
+ options: {
9
+ memoryRows?: unknown[];
10
+ orchestratorConfig?: unknown;
11
+ knowledgeBasePlugin?: unknown;
12
+ toolCallResult?: unknown;
13
+ } = {},
14
+ ) {
6
15
  let nextSpanId = 1;
16
+ let observedIdentity: string | undefined;
17
+ let observedSkillSettings: unknown;
7
18
  const spanRepo = {
8
19
  create: vi.fn(async ({ values }) => ({ id: nextSpanId++, ...values })),
9
20
  update: vi.fn(async () => ({})),
10
21
  };
22
+ const skillExecutionRepo = {
23
+ update: vi.fn(async () => ({})),
24
+ };
11
25
  const originalRun = vi.fn(async (task) => {
26
+ observedIdentity = getAgentExecutionContext()?.employeeUsername;
27
+ observedSkillSettings = task.skillSettings;
12
28
  task.writer?.({
13
29
  action: 'beforeToolCall',
14
30
  body: {
@@ -33,7 +49,7 @@ function createObserverHarness(profileSettings: Record<string, unknown> | null =
33
49
  name: 'skill_hub_execute',
34
50
  messageId: 'msg-1',
35
51
  },
36
- toolCallResult: {
52
+ toolCallResult: options.toolCallResult ?? {
37
53
  status: 'success',
38
54
  content: { ok: true },
39
55
  },
@@ -49,11 +65,12 @@ function createObserverHarness(profileSettings: Record<string, unknown> | null =
49
65
  const dispatcher = { run: originalRun };
50
66
  const repos: Record<string, unknown> = {
51
67
  agentExecutionSpans: spanRepo,
68
+ skillExecutions: skillExecutionRepo,
52
69
  agentHarnessProfiles: {
53
70
  findOne: vi.fn(async () => (profileSettings ? { settings: profileSettings } : null)),
54
71
  },
55
72
  agentMemoryContexts: {
56
- find: vi.fn(async () => []),
73
+ find: vi.fn(async () => options.memoryRows ?? []),
57
74
  },
58
75
  aiToolMessages: {
59
76
  findOne: vi.fn(async () => ({
@@ -70,6 +87,9 @@ function createObserverHarness(profileSettings: Record<string, unknown> | null =
70
87
  : null,
71
88
  ),
72
89
  },
90
+ orchestratorConfig: {
91
+ findOne: vi.fn(async () => options.orchestratorConfig ?? null),
92
+ },
73
93
  };
74
94
  const plugin = {
75
95
  app: {
@@ -78,7 +98,11 @@ function createObserverHarness(profileSettings: Record<string, unknown> | null =
78
98
  warn: vi.fn(),
79
99
  },
80
100
  pm: {
81
- get: vi.fn((name) => (name === 'ai' ? { subAgentsDispatcher: dispatcher } : null)),
101
+ get: vi.fn((name) => {
102
+ if (name === 'ai') return { subAgentsDispatcher: dispatcher };
103
+ if (name === 'plugin-knowledge-base') return options.knowledgeBasePlugin ?? null;
104
+ return null;
105
+ }),
82
106
  getPlugins: vi.fn(() => new Map()),
83
107
  },
84
108
  },
@@ -87,7 +111,15 @@ function createObserverHarness(profileSettings: Record<string, unknown> | null =
87
111
  },
88
112
  };
89
113
 
90
- return { plugin, dispatcher, originalRun, spanRepo, repos };
114
+ return {
115
+ plugin,
116
+ dispatcher,
117
+ originalRun,
118
+ spanRepo,
119
+ skillExecutionRepo,
120
+ repos,
121
+ getObserved: () => ({ observedIdentity, observedSkillSettings }),
122
+ };
91
123
  }
92
124
 
93
125
  function createTask(getRepository?: (name: string) => unknown) {
@@ -109,6 +141,7 @@ function createTask(getRepository?: (name: string) => unknown) {
109
141
  },
110
142
  sessionId: 'sub-session',
111
143
  employee: { username: 'sub-agent' },
144
+ skillSettings: { tools: [{ name: 'skill_hub_leader_only' }] },
112
145
  question: 'do the work',
113
146
  };
114
147
  }
@@ -129,6 +162,37 @@ describe('NativeSubAgentObserver', () => {
129
162
  expect(spanRepo.update).toHaveBeenCalled();
130
163
  });
131
164
 
165
+ it('uses the sub-agent employee bindings instead of inheriting the leader tool filter', async () => {
166
+ const { plugin, dispatcher, getObserved } = createObserverHarness();
167
+ const observer = new NativeSubAgentObserver(plugin);
168
+ observer.install();
169
+
170
+ await dispatcher.run(createTask());
171
+
172
+ expect(getObserved()).toEqual({ observedIdentity: 'sub-agent', observedSkillSettings: undefined });
173
+ });
174
+
175
+ it('links a completed Skill Hub execution to its native tool span', async () => {
176
+ const { plugin, dispatcher, skillExecutionRepo } = createObserverHarness(
177
+ {},
178
+ {
179
+ toolCallResult: {
180
+ status: 'success',
181
+ content: JSON.stringify({ execId: 'execution-41' }),
182
+ },
183
+ },
184
+ );
185
+ const observer = new NativeSubAgentObserver(plugin);
186
+ observer.install();
187
+
188
+ await dispatcher.run(createTask());
189
+
190
+ expect(skillExecutionRepo.update).toHaveBeenCalledWith({
191
+ filterByTk: 'execution-41',
192
+ values: { orchestratorSpanId: 2 },
193
+ });
194
+ });
195
+
132
196
  it('restores the native dispatcher when uninstalled', async () => {
133
197
  const { plugin, dispatcher, originalRun } = createObserverHarness();
134
198
  const observer = new NativeSubAgentObserver(plugin);
@@ -189,7 +253,7 @@ describe('NativeSubAgentObserver', () => {
189
253
  });
190
254
 
191
255
  describe('AgentMemoryContextService', () => {
192
- it('builds context in public, user-memory, user, agent_user precedence', async () => {
256
+ it('prioritizes agent-user context before user and public memory', async () => {
193
257
  const rows = [
194
258
  { scope: 'public', enabled: true, userId: null, aiEmployeeUsername: '', contentMd: 'Public fact' },
195
259
  { scope: 'user', enabled: true, userId: 7, aiEmployeeUsername: '', contentMd: 'User context' },
@@ -237,10 +301,78 @@ describe('AgentMemoryContextService', () => {
237
301
  settings: { memoryScopes: ['public', 'user', 'agent_user'], maxMemoryContextChars: 10000 },
238
302
  });
239
303
 
240
- expect(result.appliedScopes).toEqual(['public', 'user-memory', 'user', 'agent_user']);
241
- expect(result.context.indexOf('Public fact')).toBeLessThan(result.context.indexOf('<user_memory>'));
304
+ expect(result.appliedScopes).toEqual(['agent_user', 'user-memory', 'user', 'public']);
305
+ expect(result.context.indexOf('Private graph')).toBeLessThan(result.context.indexOf('<user_memory>'));
242
306
  expect(result.context.indexOf('<user_memory>')).toBeLessThan(result.context.indexOf('User context'));
243
- expect(result.context.indexOf('User context')).toBeLessThan(result.context.indexOf('Private graph'));
307
+ expect(result.context.indexOf('User context')).toBeLessThan(result.context.indexOf('Public fact'));
244
308
  expect(result.context).not.toContain('Other private');
245
309
  });
310
+
311
+ it('does not inject any memory when a profile explicitly selects no scopes', async () => {
312
+ const plugin = {
313
+ app: { logger: { warn: vi.fn() }, pm: { get: vi.fn() } },
314
+ db: {
315
+ getRepository: vi.fn(() => ({
316
+ find: vi.fn(async () => [{ scope: 'public', enabled: true, userId: null, contentMd: 'Public fact' }]),
317
+ })),
318
+ },
319
+ };
320
+ const service = new AgentMemoryContextService(plugin);
321
+
322
+ await expect(
323
+ service.buildContext({
324
+ userId: 7,
325
+ aiEmployeeUsername: 'sub-agent',
326
+ settings: { memoryScopes: [] },
327
+ }),
328
+ ).resolves.toEqual({ context: '', appliedScopes: [], chars: 0 });
329
+ });
330
+
331
+ it('uses the leader-to-sub-agent harness tag when no explicit tag is supplied', async () => {
332
+ const { plugin } = createObserverHarness(null, {
333
+ orchestratorConfig: { harnessTag: 'safe' },
334
+ });
335
+ const profileRepo = plugin.db.getRepository('agentHarnessProfiles') as {
336
+ findOne: ReturnType<typeof vi.fn>;
337
+ };
338
+ profileRepo.findOne.mockImplementation(async ({ filter }: { filter: { tag: string } }) =>
339
+ filter.tag === 'safe' ? { settings: { maxMemoryContextChars: 1200 } } : null,
340
+ );
341
+ const service = new AgentMemoryContextService(plugin);
342
+
343
+ await expect(
344
+ service.resolvePolicySettings({ ctx: createTask().ctx, employee: { username: 'sub-agent' } }),
345
+ ).resolves.toEqual(expect.objectContaining({ harnessTag: 'safe', maxMemoryContextChars: 1200 }));
346
+ });
347
+ });
348
+
349
+ describe('NativeSubAgentObserver memory injection', () => {
350
+ it('places reference memory before the immutable agent task', async () => {
351
+ const { plugin, dispatcher, originalRun } = createObserverHarness(
352
+ {},
353
+ {
354
+ memoryRows: [{ scope: 'public', enabled: true, userId: null, contentMd: 'Reference fact' }],
355
+ },
356
+ );
357
+ const observer = new NativeSubAgentObserver(plugin);
358
+ observer.install();
359
+
360
+ await dispatcher.run(createTask());
361
+
362
+ const question = originalRun.mock.calls[0][0].question as string;
363
+ expect(question).toContain('<agent_memory_context>');
364
+ expect(question).toContain('<agent_task>\ndo the work\n</agent_task>');
365
+ expect(question.indexOf('Reference fact')).toBeLessThan(question.indexOf('<agent_task>'));
366
+ });
367
+
368
+ it('runs the native sub-agent with its Knowledge Base request identity', async () => {
369
+ const runWithAgentContext = vi.fn(async (_username: string, callback: () => Promise<string>) => callback());
370
+ const { plugin, dispatcher } = createObserverHarness({}, { knowledgeBasePlugin: { runWithAgentContext } });
371
+ const observer = new NativeSubAgentObserver(plugin);
372
+ observer.install();
373
+
374
+ await dispatcher.run(createTask());
375
+
376
+ expect(runWithAgentContext).toHaveBeenCalledWith('sub-agent', expect.any(Function));
377
+ });
246
378
  });
@@ -0,0 +1,64 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { SkillAccessService } from '../services/SkillAccessService';
3
+
4
+ function createService(employeeSettings: Record<string, unknown> | null) {
5
+ const findOne = vi.fn(async ({ filter }: { filter: { username?: string; sessionId?: string } }) => {
6
+ if (filter.username) {
7
+ return employeeSettings
8
+ ? {
9
+ username: filter.username,
10
+ skillSettings: employeeSettings,
11
+ }
12
+ : null;
13
+ }
14
+ return null;
15
+ });
16
+ const find = vi.fn(async () => []);
17
+ const service = new SkillAccessService({
18
+ db: {
19
+ getRepository: vi.fn(() => ({ findOne, find })),
20
+ },
21
+ });
22
+ return service;
23
+ }
24
+
25
+ const privateSkill = {
26
+ name: 'generate-report',
27
+ toolName: 'skill_hub_generate_report',
28
+ toolScope: 'CUSTOM',
29
+ };
30
+
31
+ describe('SkillAccessService', () => {
32
+ it('allows a skill-specific binding', async () => {
33
+ const service = createService({
34
+ tools: [{ name: 'skill_hub_generate_report', autoCall: false }],
35
+ });
36
+
37
+ await expect(service.canAgentUseSkill('reporter', privateSkill)).resolves.toBe(true);
38
+ });
39
+
40
+ it('does not treat the universal executor as permission for every skill', async () => {
41
+ const service = createService({
42
+ tools: [{ name: 'skill_hub_execute', autoCall: false }],
43
+ });
44
+
45
+ await expect(service.canAgentUseSkill('reporter', privateSkill)).resolves.toBe(false);
46
+ });
47
+
48
+ it('allows GENERAL skills without a per-agent binding', async () => {
49
+ const service = createService({ tools: [] });
50
+ await expect(service.canAgentUseSkill('reporter', { ...privateSkill, toolScope: 'GENERAL' })).resolves.toBe(true);
51
+ });
52
+
53
+ it('fails closed when execution has no AI employee context', async () => {
54
+ const service = createService({ tools: [] });
55
+ await expect(service.assertCanExecute({}, privateSkill)).rejects.toThrow('requires an AI employee context');
56
+ });
57
+
58
+ it('resolves the explicit aiEmployeeUsername action value', async () => {
59
+ const service = createService({ tools: [] });
60
+ await expect(
61
+ service.resolveAgentUsername({ action: { params: { values: { aiEmployeeUsername: 'reporter' } } } }),
62
+ ).resolves.toBe('reporter');
63
+ });
64
+ });
@@ -30,4 +30,41 @@ describe('createSkillExecuteTool', () => {
30
30
  expect(executeSkill).toHaveBeenCalledOnce();
31
31
  expect(ctx.runtime).toBeUndefined();
32
32
  });
33
+
34
+ it('lists only skills authorized for the current AI employee', async () => {
35
+ const makeSkill = (name: string) => ({
36
+ get: vi.fn((field: string) => {
37
+ const values: Record<string, unknown> = {
38
+ name,
39
+ toolName: `skill_hub_${name}`,
40
+ title: name,
41
+ description: `${name} description`,
42
+ language: 'python',
43
+ toolScope: 'CUSTOM',
44
+ storageType: 'database',
45
+ };
46
+ return values[field];
47
+ }),
48
+ });
49
+ const allowed = makeSkill('allowed');
50
+ const denied = makeSkill('denied');
51
+ const plugin = {
52
+ app: { logger: { info: vi.fn() } },
53
+ db: {
54
+ getRepository: vi.fn(() => ({
55
+ find: vi.fn(async () => [allowed, denied]),
56
+ })),
57
+ },
58
+ skillAccessService: {
59
+ filterAccessibleSkills: vi.fn(async (_ctx, skills) => skills.filter((skill) => skill === allowed)),
60
+ },
61
+ };
62
+
63
+ const tool = createSkillExecuteTool(plugin);
64
+ const result = await tool.invoke({}, { action: 'list' });
65
+ const content = JSON.parse(result.content);
66
+
67
+ expect(content.skills).toHaveLength(1);
68
+ expect(content.skills[0]).toMatchObject({ name: 'allowed', toolName: 'skill_hub_allowed' });
69
+ });
33
70
  });
@@ -0,0 +1,23 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { buildSkillToolName, getSkillToolName, normalizeSkillToolScope } from '../utils/skill-tool-name';
3
+
4
+ describe('skill tool identity', () => {
5
+ it('preserves the legacy canonical name for existing bindings', () => {
6
+ expect(buildSkillToolName('Generate-Report')).toBe('skill_hub_generate_report');
7
+ });
8
+
9
+ it('uses the persisted immutable tool name when available', () => {
10
+ expect(getSkillToolName({ name: 'renamed-skill', toolName: 'skill_hub_original_name' })).toBe(
11
+ 'skill_hub_original_name',
12
+ );
13
+ });
14
+
15
+ it('rejects names that cannot produce an AI tool identifier', () => {
16
+ expect(() => buildSkillToolName('---')).toThrow('ASCII letter or number');
17
+ });
18
+
19
+ it('normalizes unsupported scopes to CUSTOM', () => {
20
+ expect(normalizeSkillToolScope('GENERAL')).toBe('GENERAL');
21
+ expect(normalizeSkillToolScope('unknown')).toBe('CUSTOM');
22
+ });
23
+ });
@@ -16,6 +16,14 @@ export default {
16
16
  length: 100,
17
17
  unique: true,
18
18
  },
19
+ {
20
+ // Immutable tool identity used by plugin-ai bindings. Display/internal
21
+ // names may change without invalidating existing AI employee settings.
22
+ name: 'toolName',
23
+ type: 'string',
24
+ length: 140,
25
+ unique: true,
26
+ },
19
27
  {
20
28
  name: 'title',
21
29
  type: 'string',
@@ -80,6 +88,14 @@ export default {
80
88
  length: 20,
81
89
  defaultValue: 'CUSTOM',
82
90
  },
91
+ {
92
+ // Provider-owned opt-in. Background consumers such as Skill Registry
93
+ // must not turn their own server privileges into access to every skill.
94
+ name: 'registryExportEnabled',
95
+ type: 'boolean',
96
+ allowNull: false,
97
+ defaultValue: false,
98
+ },
83
99
  {
84
100
  name: 'autoCall',
85
101
  type: 'boolean',
@@ -110,6 +126,21 @@ export default {
110
126
  target: 'attachments',
111
127
  foreignKey: 'fileId',
112
128
  },
129
+ // Registry linkage is nullable so existing local skills remain fully compatible.
130
+ { name: 'registryPackageId', type: 'bigInt', allowNull: true },
131
+ { name: 'registryVersionId', type: 'bigInt', allowNull: true },
132
+ { name: 'registryChannel', type: 'string', length: 20, allowNull: true },
133
+ { name: 'sourceDigest', type: 'string', length: 71, allowNull: true },
134
+ { name: 'sourceSignature', type: 'text', allowNull: true },
135
+ {
136
+ name: 'registryInstallation',
137
+ type: 'belongsTo',
138
+ target: 'skillRegistryInstallations',
139
+ foreignKey: 'registryInstallationId',
140
+ onDelete: 'SET NULL',
141
+ },
142
+ { name: 'registryInstallStatus', type: 'string', length: 24, allowNull: true },
143
+ { name: 'registryUpdatePolicy', type: 'string', length: 20, allowNull: true },
113
144
  {
114
145
  name: 'createdAt',
115
146
  type: 'date',
@@ -77,6 +77,25 @@ export default {
77
77
  length: 100,
78
78
  allowNull: true,
79
79
  },
80
+ {
81
+ name: 'aiEmployeeUsername',
82
+ type: 'string',
83
+ length: 100,
84
+ allowNull: true,
85
+ },
86
+ {
87
+ name: 'skillToolName',
88
+ type: 'string',
89
+ length: 140,
90
+ allowNull: true,
91
+ },
92
+ {
93
+ // SHA-256 of the exact rendered source stored in executedCode.
94
+ name: 'skillDigest',
95
+ type: 'string',
96
+ length: 64,
97
+ allowNull: true,
98
+ },
80
99
  {
81
100
  name: 'orchestratorRootRunId',
82
101
  type: 'string',
@@ -0,0 +1,41 @@
1
+ import { CollectionOptions } from '@nocobase/database';
2
+
3
+ export default {
4
+ name: 'skillRegistryInstallations',
5
+ title: 'Skill Registry Installations',
6
+ fields: [
7
+ { name: 'id', type: 'bigInt', autoIncrement: true, primaryKey: true },
8
+ { name: 'registryPackageId', type: 'bigInt', allowNull: false },
9
+ { name: 'registryVersionId', type: 'bigInt', allowNull: false, unique: true },
10
+ { name: 'packageIdentity', type: 'string', length: 220, allowNull: false },
11
+ { name: 'version', type: 'string', length: 64, allowNull: false },
12
+ { name: 'channel', type: 'string', length: 20, defaultValue: 'stable' },
13
+ { name: 'artifactDigest', type: 'string', length: 71, allowNull: false },
14
+ { name: 'sourceSignature', type: 'text', allowNull: true },
15
+ { name: 'updatePolicy', type: 'string', length: 20, defaultValue: 'pinned' },
16
+ { name: 'status', type: 'string', length: 24, defaultValue: 'verifying' },
17
+ {
18
+ name: 'skillDefinition',
19
+ type: 'belongsTo',
20
+ target: 'skillDefinitions',
21
+ foreignKey: 'skillDefinitionId',
22
+ onDelete: 'RESTRICT',
23
+ },
24
+ {
25
+ name: 'previousInstallation',
26
+ type: 'belongsTo',
27
+ target: 'skillRegistryInstallations',
28
+ foreignKey: 'previousInstallationId',
29
+ onDelete: 'SET NULL',
30
+ },
31
+ { name: 'lastError', type: 'text', allowNull: true },
32
+ { name: 'installedAt', type: 'date', allowNull: true },
33
+ { name: 'installedBy', type: 'belongsTo', target: 'users', foreignKey: 'installedById' },
34
+ { name: 'createdAt', type: 'date' },
35
+ { name: 'updatedAt', type: 'date' },
36
+ ],
37
+ indexes: [
38
+ { name: 'skill_registry_installations_package_status', fields: ['registryPackageId', 'status'] },
39
+ { name: 'skill_registry_installations_skill_definition', fields: ['skillDefinitionId'] },
40
+ ],
41
+ } as CollectionOptions;
@@ -18,7 +18,6 @@ const nativePolicyProfiles: ProfileSeed[] = [
18
18
  nativeObserverEnabled: true,
19
19
  memoryInjectionEnabled: true,
20
20
  memoryScopes: ['public', 'user', 'agent_user'],
21
- knowledgeScopes: ['public', 'private'],
22
21
  maxMemoryContextChars: 6000,
23
22
  tracingRetentionDays: 30,
24
23
  },
@@ -31,7 +30,6 @@ const nativePolicyProfiles: ProfileSeed[] = [
31
30
  nativeObserverEnabled: true,
32
31
  memoryInjectionEnabled: true,
33
32
  memoryScopes: ['public', 'user', 'agent_user'],
34
- knowledgeScopes: ['public', 'private'],
35
33
  maxMemoryContextChars: 4000,
36
34
  tracingRetentionDays: 14,
37
35
  },
@@ -44,7 +42,6 @@ const nativePolicyProfiles: ProfileSeed[] = [
44
42
  nativeObserverEnabled: true,
45
43
  memoryInjectionEnabled: true,
46
44
  memoryScopes: ['public', 'user', 'agent_user'],
47
- knowledgeScopes: ['public', 'private'],
48
45
  maxMemoryContextChars: 8000,
49
46
  tracingRetentionDays: 30,
50
47
  preferFileTools: true,
@@ -0,0 +1,25 @@
1
+ import { Migration } from '@nocobase/server';
2
+
3
+ export default class RemoveUnusedKnowledgeScopes extends Migration {
4
+ on = 'afterLoad';
5
+ appVersion = '>=0.1.0';
6
+
7
+ async up() {
8
+ const repo = this.db.getRepository('agentHarnessProfiles');
9
+ const profiles = await repo.find({});
10
+
11
+ for (const profile of profiles) {
12
+ const settings = profile.get?.('settings') ?? profile.settings;
13
+ if (!settings || typeof settings !== 'object' || Array.isArray(settings) || !('knowledgeScopes' in settings)) {
14
+ continue;
15
+ }
16
+
17
+ const { knowledgeScopes: _unused, ...nextSettings } = settings as Record<string, unknown>;
18
+ await profile.update({ settings: nextSettings, updatedAt: new Date() });
19
+ }
20
+ }
21
+
22
+ async down() {
23
+ // The removed key never affected runtime behavior, so there is no data to restore.
24
+ }
25
+ }