plugin-agent-orchestrator 1.1.0 → 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 (162) hide show
  1. package/dist/externalVersion.js +6 -6
  2. package/dist/locale/en-US.json +7 -1
  3. package/dist/locale/vi-VN.json +7 -1
  4. package/dist/locale/zh-CN.json +7 -1
  5. package/dist/node_modules/ajv/.tonic_example.js +20 -0
  6. package/dist/node_modules/ajv/LICENSE +22 -0
  7. package/dist/node_modules/ajv/dist/ajv.bundle.js +7189 -0
  8. package/dist/node_modules/ajv/dist/ajv.min.js +3 -0
  9. package/dist/node_modules/ajv/lib/ajv.d.ts +397 -0
  10. package/dist/node_modules/ajv/lib/ajv.js +3 -0
  11. package/dist/node_modules/ajv/lib/cache.js +26 -0
  12. package/dist/node_modules/ajv/lib/compile/async.js +90 -0
  13. package/dist/node_modules/ajv/lib/compile/equal.js +5 -0
  14. package/dist/node_modules/ajv/lib/compile/error_classes.js +34 -0
  15. package/dist/node_modules/ajv/lib/compile/formats.js +142 -0
  16. package/dist/node_modules/ajv/lib/compile/index.js +387 -0
  17. package/dist/node_modules/ajv/lib/compile/resolve.js +270 -0
  18. package/dist/node_modules/ajv/lib/compile/rules.js +66 -0
  19. package/dist/node_modules/ajv/lib/compile/schema_obj.js +9 -0
  20. package/dist/node_modules/ajv/lib/compile/ucs2length.js +20 -0
  21. package/dist/node_modules/ajv/lib/compile/util.js +239 -0
  22. package/dist/node_modules/ajv/lib/data.js +49 -0
  23. package/dist/node_modules/ajv/lib/definition_schema.js +37 -0
  24. package/dist/node_modules/ajv/lib/dot/_limit.jst +113 -0
  25. package/dist/node_modules/ajv/lib/dot/_limitItems.jst +12 -0
  26. package/dist/node_modules/ajv/lib/dot/_limitLength.jst +12 -0
  27. package/dist/node_modules/ajv/lib/dot/_limitProperties.jst +12 -0
  28. package/dist/node_modules/ajv/lib/dot/allOf.jst +32 -0
  29. package/dist/node_modules/ajv/lib/dot/anyOf.jst +46 -0
  30. package/dist/node_modules/ajv/lib/dot/coerce.def +51 -0
  31. package/dist/node_modules/ajv/lib/dot/comment.jst +9 -0
  32. package/dist/node_modules/ajv/lib/dot/const.jst +11 -0
  33. package/dist/node_modules/ajv/lib/dot/contains.jst +55 -0
  34. package/dist/node_modules/ajv/lib/dot/custom.jst +191 -0
  35. package/dist/node_modules/ajv/lib/dot/defaults.def +47 -0
  36. package/dist/node_modules/ajv/lib/dot/definitions.def +203 -0
  37. package/dist/node_modules/ajv/lib/dot/dependencies.jst +79 -0
  38. package/dist/node_modules/ajv/lib/dot/enum.jst +30 -0
  39. package/dist/node_modules/ajv/lib/dot/errors.def +194 -0
  40. package/dist/node_modules/ajv/lib/dot/format.jst +106 -0
  41. package/dist/node_modules/ajv/lib/dot/if.jst +73 -0
  42. package/dist/node_modules/ajv/lib/dot/items.jst +98 -0
  43. package/dist/node_modules/ajv/lib/dot/missing.def +39 -0
  44. package/dist/node_modules/ajv/lib/dot/multipleOf.jst +22 -0
  45. package/dist/node_modules/ajv/lib/dot/not.jst +43 -0
  46. package/dist/node_modules/ajv/lib/dot/oneOf.jst +54 -0
  47. package/dist/node_modules/ajv/lib/dot/pattern.jst +14 -0
  48. package/dist/node_modules/ajv/lib/dot/properties.jst +245 -0
  49. package/dist/node_modules/ajv/lib/dot/propertyNames.jst +52 -0
  50. package/dist/node_modules/ajv/lib/dot/ref.jst +85 -0
  51. package/dist/node_modules/ajv/lib/dot/required.jst +108 -0
  52. package/dist/node_modules/ajv/lib/dot/uniqueItems.jst +62 -0
  53. package/dist/node_modules/ajv/lib/dot/validate.jst +276 -0
  54. package/dist/node_modules/ajv/lib/dotjs/_limit.js +163 -0
  55. package/dist/node_modules/ajv/lib/dotjs/_limitItems.js +80 -0
  56. package/dist/node_modules/ajv/lib/dotjs/_limitLength.js +85 -0
  57. package/dist/node_modules/ajv/lib/dotjs/_limitProperties.js +80 -0
  58. package/dist/node_modules/ajv/lib/dotjs/allOf.js +42 -0
  59. package/dist/node_modules/ajv/lib/dotjs/anyOf.js +73 -0
  60. package/dist/node_modules/ajv/lib/dotjs/comment.js +14 -0
  61. package/dist/node_modules/ajv/lib/dotjs/const.js +56 -0
  62. package/dist/node_modules/ajv/lib/dotjs/contains.js +81 -0
  63. package/dist/node_modules/ajv/lib/dotjs/custom.js +228 -0
  64. package/dist/node_modules/ajv/lib/dotjs/dependencies.js +168 -0
  65. package/dist/node_modules/ajv/lib/dotjs/enum.js +66 -0
  66. package/dist/node_modules/ajv/lib/dotjs/format.js +150 -0
  67. package/dist/node_modules/ajv/lib/dotjs/if.js +103 -0
  68. package/dist/node_modules/ajv/lib/dotjs/index.js +33 -0
  69. package/dist/node_modules/ajv/lib/dotjs/items.js +140 -0
  70. package/dist/node_modules/ajv/lib/dotjs/multipleOf.js +80 -0
  71. package/dist/node_modules/ajv/lib/dotjs/not.js +84 -0
  72. package/dist/node_modules/ajv/lib/dotjs/oneOf.js +73 -0
  73. package/dist/node_modules/ajv/lib/dotjs/pattern.js +75 -0
  74. package/dist/node_modules/ajv/lib/dotjs/properties.js +335 -0
  75. package/dist/node_modules/ajv/lib/dotjs/propertyNames.js +81 -0
  76. package/dist/node_modules/ajv/lib/dotjs/ref.js +124 -0
  77. package/dist/node_modules/ajv/lib/dotjs/required.js +270 -0
  78. package/dist/node_modules/ajv/lib/dotjs/uniqueItems.js +86 -0
  79. package/dist/node_modules/ajv/lib/dotjs/validate.js +482 -0
  80. package/dist/node_modules/ajv/lib/keyword.js +146 -0
  81. package/dist/node_modules/ajv/lib/refs/data.json +17 -0
  82. package/dist/node_modules/ajv/lib/refs/json-schema-draft-04.json +149 -0
  83. package/dist/node_modules/ajv/lib/refs/json-schema-draft-06.json +154 -0
  84. package/dist/node_modules/ajv/lib/refs/json-schema-draft-07.json +168 -0
  85. package/dist/node_modules/ajv/lib/refs/json-schema-secure.json +94 -0
  86. package/dist/node_modules/ajv/node_modules/json-schema-traverse/.eslintrc.yml +27 -0
  87. package/dist/node_modules/ajv/node_modules/json-schema-traverse/.travis.yml +8 -0
  88. package/dist/node_modules/ajv/node_modules/json-schema-traverse/index.js +89 -0
  89. package/dist/node_modules/ajv/node_modules/json-schema-traverse/package.json +43 -0
  90. package/dist/node_modules/ajv/node_modules/json-schema-traverse/spec/.eslintrc.yml +6 -0
  91. package/dist/node_modules/ajv/node_modules/json-schema-traverse/spec/fixtures/schema.js +125 -0
  92. package/dist/node_modules/ajv/node_modules/json-schema-traverse/spec/index.spec.js +171 -0
  93. package/dist/node_modules/ajv/package.json +1 -0
  94. package/dist/node_modules/ajv/scripts/.eslintrc.yml +3 -0
  95. package/dist/node_modules/ajv/scripts/bundle.js +61 -0
  96. package/dist/node_modules/ajv/scripts/compile-dots.js +73 -0
  97. package/dist/node_modules/ajv/scripts/info +10 -0
  98. package/dist/node_modules/ajv/scripts/prepare-tests +12 -0
  99. package/dist/node_modules/ajv/scripts/publish-built-version +32 -0
  100. package/dist/node_modules/ajv/scripts/travis-gh-pages +23 -0
  101. package/dist/server/collections/skill-definitions.js +31 -0
  102. package/dist/server/collections/skill-executions.js +19 -0
  103. package/dist/server/collections/skill-registry-installations.js +70 -0
  104. package/dist/server/migrations/20260727010000-backfill-skill-tool-names.js +66 -0
  105. package/dist/server/plugin.js +96 -1
  106. package/dist/server/services/AgentExecutionContext.js +45 -0
  107. package/dist/server/services/CodeValidator.js +1 -0
  108. package/dist/server/services/ExecutionSpanService.js +10 -2
  109. package/dist/server/services/InputSchemaValidator.js +83 -0
  110. package/dist/server/services/NativeSubAgentObserver.js +55 -8
  111. package/dist/server/services/SandboxRunner.js +6 -2
  112. package/dist/server/services/SkillAccessService.js +109 -0
  113. package/dist/server/services/SkillManager.js +2 -0
  114. package/dist/server/services/SkillRepositoryService.js +70 -0
  115. package/dist/server/skill-hub/actions/git-import.js +479 -216
  116. package/dist/server/skill-hub/mcp/McpController.js +8 -5
  117. package/dist/server/skill-hub/middlewares/git-import-request-method-policy.js +69 -0
  118. package/dist/server/skill-hub/plugin.js +68 -14
  119. package/dist/server/skill-hub/services/RegistrySkillInstallationService.js +249 -0
  120. package/dist/server/skill-hub/services/RegistrySkillSnapshotService.js +228 -0
  121. package/dist/server/skill-hub/tasks/SkillExecutionTask.js +15 -3
  122. package/dist/server/tools/skill-execute.js +23 -2
  123. package/dist/server/utils/ctx-utils.js +2 -2
  124. package/dist/server/utils/skill-tool-name.js +73 -0
  125. package/package.json +9 -3
  126. package/src/locale/en-US.json +7 -1
  127. package/src/locale/vi-VN.json +7 -1
  128. package/src/locale/zh-CN.json +7 -1
  129. package/src/server/__tests__/agent-execution-context.test.ts +18 -0
  130. package/src/server/__tests__/input-schema-validator.test.ts +26 -0
  131. package/src/server/__tests__/native-sub-agent-observer.test.ts +52 -2
  132. package/src/server/__tests__/skill-access-service.test.ts +64 -0
  133. package/src/server/__tests__/skill-execute.test.ts +37 -0
  134. package/src/server/__tests__/skill-tool-name.test.ts +23 -0
  135. package/src/server/collections/skill-definitions.ts +31 -0
  136. package/src/server/collections/skill-executions.ts +19 -0
  137. package/src/server/collections/skill-registry-installations.ts +41 -0
  138. package/src/server/migrations/20260727010000-backfill-skill-tool-names.ts +45 -0
  139. package/src/server/plugin.ts +104 -1
  140. package/src/server/services/AgentExecutionContext.ts +23 -0
  141. package/src/server/services/CodeValidator.ts +1 -0
  142. package/src/server/services/ExecutionSpanService.ts +119 -110
  143. package/src/server/services/InputSchemaValidator.ts +44 -0
  144. package/src/server/services/NativeSubAgentObserver.ts +64 -10
  145. package/src/server/services/SandboxRunner.ts +6 -0
  146. package/src/server/services/SkillAccessService.ts +100 -0
  147. package/src/server/services/SkillManager.ts +2 -0
  148. package/src/server/services/SkillRepositoryService.ts +98 -2
  149. package/src/server/services/__tests__/SkillRepositoryService.test.ts +33 -0
  150. package/src/server/skill-hub/actions/__tests__/git-import.test.ts +501 -0
  151. package/src/server/skill-hub/actions/git-import.ts +682 -236
  152. package/src/server/skill-hub/mcp/McpController.ts +8 -14
  153. package/src/server/skill-hub/middlewares/git-import-request-method-policy.ts +51 -0
  154. package/src/server/skill-hub/plugin.ts +79 -13
  155. package/src/server/skill-hub/services/RegistrySkillInstallationService.ts +281 -0
  156. package/src/server/skill-hub/services/RegistrySkillSnapshotService.ts +239 -0
  157. package/src/server/skill-hub/services/__tests__/RegistrySkillInstallationService.test.ts +295 -0
  158. package/src/server/skill-hub/services/__tests__/RegistrySkillSnapshotService.test.ts +63 -0
  159. package/src/server/skill-hub/tasks/SkillExecutionTask.ts +14 -2
  160. package/src/server/tools/skill-execute.ts +24 -2
  161. package/src/server/utils/ctx-utils.ts +1 -1
  162. package/src/server/utils/skill-tool-name.ts +58 -0
@@ -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;
@@ -0,0 +1,45 @@
1
+ import { Migration } from '@nocobase/server';
2
+ import { buildSkillToolName, readRecordValue } from '../utils/skill-tool-name';
3
+
4
+ export default class BackfillSkillToolNames extends Migration {
5
+ on = 'afterLoad';
6
+ appVersion = '>=0.1.0';
7
+
8
+ async up() {
9
+ const repo = this.db.getRepository('skillDefinitions');
10
+ if (!repo) return;
11
+
12
+ const skills = await repo.find({ sort: ['id'] });
13
+ const used = new Set<string>();
14
+
15
+ for (const skill of skills) {
16
+ const current = readRecordValue(skill, 'toolName');
17
+ if (typeof current === 'string' && current.trim()) {
18
+ used.add(current.trim());
19
+ }
20
+ }
21
+
22
+ for (const skill of skills) {
23
+ const current = readRecordValue(skill, 'toolName');
24
+ if (typeof current === 'string' && current.trim()) continue;
25
+
26
+ const id = readRecordValue(skill, 'id');
27
+ const baseName = buildSkillToolName(String(readRecordValue(skill, 'name') || ''));
28
+ let toolName = baseName;
29
+ if (used.has(toolName)) {
30
+ toolName = `${baseName}_${id}`;
31
+ }
32
+
33
+ await repo.update({
34
+ filterByTk: id,
35
+ values: { toolName },
36
+ });
37
+ used.add(toolName);
38
+ }
39
+ }
40
+
41
+ async down() {
42
+ // Stable tool identities are intentionally retained on rollback so AI
43
+ // employee bindings do not become orphaned.
44
+ }
45
+ }
@@ -7,12 +7,16 @@ import { registerAgentLoopResource } from './resources/agent-loop';
7
7
  import { registerAgentKnowledgeInsightsResource } from './resources/agent-knowledge-insights';
8
8
  import SkillHubSubFeature from './skill-hub/plugin';
9
9
  import { NativeSubAgentObserver } from './services/NativeSubAgentObserver';
10
+ import { RegistrySkillSnapshotService } from './skill-hub/services/RegistrySkillSnapshotService';
11
+ import { RegistrySkillInstallationService } from './skill-hub/services/RegistrySkillInstallationService';
10
12
  import { AgentLoopService } from './services/AgentLoopService';
11
13
  import { createAgentLoopTools } from './tools/agent-loop';
12
14
  import { PlanningPromptService } from './services/PlanningPromptService';
13
15
  import { asObject, isAdminUser, currentUserId } from './utils/ctx-utils';
14
16
  import { getAIToolsManager } from './utils/ai-manager';
15
17
  import { AgentRuntimeLifecycle } from './services/AgentRuntimeLifecycle';
18
+ import { validateInputSchemaDefinition } from './services/InputSchemaValidator';
19
+ import { assertSkillToolNameAvailable, buildSkillToolName, getSkillToolName } from './utils/skill-tool-name';
16
20
 
17
21
  function normalizeOptionalString(value: unknown) {
18
22
  return typeof value === 'string' ? value.trim() : '';
@@ -23,6 +27,34 @@ function readModelValue(record: unknown, key: string) {
23
27
  return typeof model?.get === 'function' ? model.get(key) : model?.[key];
24
28
  }
25
29
 
30
+ const PRIVATE_SKILL_FIELDS = ['codeTemplate', 'instructions', 'storageUrl', 'packages', 'fileId'] as const;
31
+
32
+ function redactSkillRecord(record: unknown): unknown {
33
+ if (!record || typeof record !== 'object') return record;
34
+ const source =
35
+ (record as { toJSON?: () => Record<string, unknown> }).toJSON?.() || (record as Record<string, unknown>);
36
+ const result = { ...source };
37
+ for (const field of PRIVATE_SKILL_FIELDS) {
38
+ delete result[field];
39
+ }
40
+ return result;
41
+ }
42
+
43
+ function redactSkillResponse(body: unknown): unknown {
44
+ if (Array.isArray(body)) return body.map(redactSkillRecord);
45
+ if (!body || typeof body !== 'object') return body;
46
+
47
+ const value = body as Record<string, unknown>;
48
+ if (Array.isArray(value.rows)) return { ...value, rows: value.rows.map(redactSkillRecord) };
49
+ if (Object.prototype.hasOwnProperty.call(value, 'data')) {
50
+ return {
51
+ ...value,
52
+ data: Array.isArray(value.data) ? value.data.map(redactSkillRecord) : redactSkillRecord(value.data),
53
+ };
54
+ }
55
+ return redactSkillRecord(value);
56
+ }
57
+
26
58
  function buildAgentMemoryContextKey(values: { scope: string; userId?: unknown; aiEmployeeUsername?: string }) {
27
59
  const userPart = values.scope === 'public' ? 'public' : String(values.userId || '');
28
60
  const agentPart = values.aiEmployeeUsername || '*';
@@ -128,6 +160,8 @@ async function resolveTracingRetentionDays(plugin: { db: any; app: any }) {
128
160
 
129
161
  export class PluginAgentOrchestratorServer extends Plugin {
130
162
  skillHub: SkillHubSubFeature;
163
+ registrySkillSnapshotService: RegistrySkillSnapshotService;
164
+ registrySkillInstallationService: RegistrySkillInstallationService;
131
165
  nativeObserver: NativeSubAgentObserver;
132
166
  agentRuntimeLifecycle: AgentRuntimeLifecycle;
133
167
  private readonly installNativeObserver = () => {
@@ -136,6 +170,10 @@ export class PluginAgentOrchestratorServer extends Plugin {
136
170
 
137
171
  async afterAdd() {
138
172
  this.skillHub = new SkillHubSubFeature(this);
173
+ this.registrySkillSnapshotService = new RegistrySkillSnapshotService(this.db);
174
+ this.registrySkillInstallationService = new RegistrySkillInstallationService(this.db, () =>
175
+ this.skillHub.getSkillRepositoryService(),
176
+ );
139
177
  this.nativeObserver = new NativeSubAgentObserver(this);
140
178
  this.agentRuntimeLifecycle = new AgentRuntimeLifecycle((hookType, name, error) => {
141
179
  this.app.logger.warn(`[AgentOrchestrator] ${hookType} hook "${name}" failed; continuing agent execution.`, {
@@ -193,7 +231,6 @@ export class PluginAgentOrchestratorServer extends Plugin {
193
231
  this.app.acl.allow('skillLoopConfigs', 'get', 'loggedIn');
194
232
  this.app.acl.allow('skillExecutions', 'list', 'loggedIn');
195
233
  this.app.acl.allow('skillExecutions', 'get', 'loggedIn');
196
- this.app.acl.allow('skillHub', 'test', 'loggedIn');
197
234
  this.app.acl.allow('skillHub', 'download', 'loggedIn');
198
235
  this.app.acl.allow('skillHub', 'listTemplates', 'loggedIn');
199
236
  this.app.acl.allow('agentMonitor', ['list', 'get'], 'loggedIn');
@@ -219,6 +256,72 @@ export class PluginAgentOrchestratorServer extends Plugin {
219
256
  { tag: 'orchestrator-skill-executions-scope', after: 'acl' },
220
257
  );
221
258
 
259
+ this.app.resourceManager.use(
260
+ async (ctx, next) => {
261
+ const { resourceName, actionName } = ctx.action || {};
262
+ if (resourceName !== 'skillDefinitions') {
263
+ await next();
264
+ return;
265
+ }
266
+
267
+ const values = ctx.action?.params?.values || {};
268
+ if (actionName === 'create' || actionName === 'update') {
269
+ try {
270
+ if (Object.prototype.hasOwnProperty.call(values, 'inputSchema')) {
271
+ validateInputSchemaDefinition(values.inputSchema);
272
+ }
273
+
274
+ if (actionName === 'create') {
275
+ const toolName = buildSkillToolName(values.name);
276
+ await assertSkillToolNameAvailable(ctx.db, toolName);
277
+ values.toolName = toolName;
278
+ } else {
279
+ const existing = await ctx.db.getRepository('skillDefinitions').findOne({
280
+ filterByTk: ctx.action?.params?.filterByTk,
281
+ });
282
+ if (existing) {
283
+ const stableToolName = getSkillToolName(existing);
284
+ if (values.toolName && values.toolName !== stableToolName) {
285
+ ctx.throw(400, 'toolName is immutable after a skill is created.');
286
+ return;
287
+ }
288
+ values.toolName = stableToolName;
289
+ }
290
+ }
291
+ } catch (error) {
292
+ ctx.throw(400, error instanceof Error ? error.message : String(error));
293
+ return;
294
+ }
295
+ }
296
+
297
+ if (actionName === 'destroy') {
298
+ const existing = await ctx.db.getRepository('skillDefinitions').findOne({
299
+ filterByTk: ctx.action?.params?.filterByTk,
300
+ });
301
+ if (existing) {
302
+ const toolName = getSkillToolName(existing);
303
+ const agentUsernames = await this.skillHub.skillAccessService.findAgentUsernamesUsingTool(toolName);
304
+ if (agentUsernames.length > 0) {
305
+ ctx.throw(
306
+ 409,
307
+ `Skill tool "${toolName}" is still bound to AI employees: ${agentUsernames.join(
308
+ ', ',
309
+ )}. Disable or unbind it before deletion.`,
310
+ );
311
+ return;
312
+ }
313
+ }
314
+ }
315
+
316
+ await next();
317
+
318
+ if ((actionName === 'list' || actionName === 'get') && !isAdminUser(ctx)) {
319
+ ctx.body = redactSkillResponse(ctx.body);
320
+ }
321
+ },
322
+ { tag: 'orchestrator-skill-definition-policy', after: 'acl' },
323
+ );
324
+
222
325
  this.app.resourceManager.use(
223
326
  async (ctx, next) => {
224
327
  const { resourceName, actionName } = ctx.action || {};
@@ -0,0 +1,23 @@
1
+ import { AsyncLocalStorage } from 'async_hooks';
2
+
3
+ export type AgentExecutionIdentity = {
4
+ rootRunId?: string;
5
+ spanId?: string;
6
+ parentSpanId?: string;
7
+ toolCallId?: string;
8
+ leaderUsername?: string;
9
+ employeeUsername?: string;
10
+ sessionId?: string;
11
+ agentLoopRunId?: string;
12
+ agentLoopStepId?: string;
13
+ };
14
+
15
+ const storage = new AsyncLocalStorage<AgentExecutionIdentity>();
16
+
17
+ export function runWithAgentExecutionContext<T>(identity: AgentExecutionIdentity, callback: () => T): T {
18
+ return storage.run(identity, callback);
19
+ }
20
+
21
+ export function getAgentExecutionContext(): AgentExecutionIdentity | undefined {
22
+ return storage.getStore();
23
+ }
@@ -96,6 +96,7 @@ const PYTHON_BUILTINS = [
96
96
  'fractions',
97
97
  'random',
98
98
  'statistics',
99
+ 'runpy',
99
100
  'copy',
100
101
  'enum',
101
102
  'dataclasses',