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.
- package/dist/client/index.js +1 -1
- package/dist/client-v2/253.9f0537713cee9e6c.js +10 -0
- package/dist/client-v2/418.ce8f5b2b8a229d1d.js +10 -0
- package/dist/client-v2/53.7c29c28043e9112d.js +10 -0
- package/dist/client-v2/794.9bbb8d3a61b2bdf2.js +10 -0
- package/dist/client-v2/993.82778b6fd6db3cb1.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +6 -6
- package/dist/locale/en-US.json +56 -2
- package/dist/locale/vi-VN.json +56 -2
- package/dist/locale/zh-CN.json +56 -2
- package/dist/node_modules/ajv/.tonic_example.js +20 -0
- package/dist/node_modules/ajv/LICENSE +22 -0
- package/dist/node_modules/ajv/dist/ajv.bundle.js +7189 -0
- package/dist/node_modules/ajv/dist/ajv.min.js +3 -0
- package/dist/node_modules/ajv/lib/ajv.d.ts +397 -0
- package/dist/node_modules/ajv/lib/ajv.js +3 -0
- package/dist/node_modules/ajv/lib/cache.js +26 -0
- package/dist/node_modules/ajv/lib/compile/async.js +90 -0
- package/dist/node_modules/ajv/lib/compile/equal.js +5 -0
- package/dist/node_modules/ajv/lib/compile/error_classes.js +34 -0
- package/dist/node_modules/ajv/lib/compile/formats.js +142 -0
- package/dist/node_modules/ajv/lib/compile/index.js +387 -0
- package/dist/node_modules/ajv/lib/compile/resolve.js +270 -0
- package/dist/node_modules/ajv/lib/compile/rules.js +66 -0
- package/dist/node_modules/ajv/lib/compile/schema_obj.js +9 -0
- package/dist/node_modules/ajv/lib/compile/ucs2length.js +20 -0
- package/dist/node_modules/ajv/lib/compile/util.js +239 -0
- package/dist/node_modules/ajv/lib/data.js +49 -0
- package/dist/node_modules/ajv/lib/definition_schema.js +37 -0
- package/dist/node_modules/ajv/lib/dot/_limit.jst +113 -0
- package/dist/node_modules/ajv/lib/dot/_limitItems.jst +12 -0
- package/dist/node_modules/ajv/lib/dot/_limitLength.jst +12 -0
- package/dist/node_modules/ajv/lib/dot/_limitProperties.jst +12 -0
- package/dist/node_modules/ajv/lib/dot/allOf.jst +32 -0
- package/dist/node_modules/ajv/lib/dot/anyOf.jst +46 -0
- package/dist/node_modules/ajv/lib/dot/coerce.def +51 -0
- package/dist/node_modules/ajv/lib/dot/comment.jst +9 -0
- package/dist/node_modules/ajv/lib/dot/const.jst +11 -0
- package/dist/node_modules/ajv/lib/dot/contains.jst +55 -0
- package/dist/node_modules/ajv/lib/dot/custom.jst +191 -0
- package/dist/node_modules/ajv/lib/dot/defaults.def +47 -0
- package/dist/node_modules/ajv/lib/dot/definitions.def +203 -0
- package/dist/node_modules/ajv/lib/dot/dependencies.jst +79 -0
- package/dist/node_modules/ajv/lib/dot/enum.jst +30 -0
- package/dist/node_modules/ajv/lib/dot/errors.def +194 -0
- package/dist/node_modules/ajv/lib/dot/format.jst +106 -0
- package/dist/node_modules/ajv/lib/dot/if.jst +73 -0
- package/dist/node_modules/ajv/lib/dot/items.jst +98 -0
- package/dist/node_modules/ajv/lib/dot/missing.def +39 -0
- package/dist/node_modules/ajv/lib/dot/multipleOf.jst +22 -0
- package/dist/node_modules/ajv/lib/dot/not.jst +43 -0
- package/dist/node_modules/ajv/lib/dot/oneOf.jst +54 -0
- package/dist/node_modules/ajv/lib/dot/pattern.jst +14 -0
- package/dist/node_modules/ajv/lib/dot/properties.jst +245 -0
- package/dist/node_modules/ajv/lib/dot/propertyNames.jst +52 -0
- package/dist/node_modules/ajv/lib/dot/ref.jst +85 -0
- package/dist/node_modules/ajv/lib/dot/required.jst +108 -0
- package/dist/node_modules/ajv/lib/dot/uniqueItems.jst +62 -0
- package/dist/node_modules/ajv/lib/dot/validate.jst +276 -0
- package/dist/node_modules/ajv/lib/dotjs/_limit.js +163 -0
- package/dist/node_modules/ajv/lib/dotjs/_limitItems.js +80 -0
- package/dist/node_modules/ajv/lib/dotjs/_limitLength.js +85 -0
- package/dist/node_modules/ajv/lib/dotjs/_limitProperties.js +80 -0
- package/dist/node_modules/ajv/lib/dotjs/allOf.js +42 -0
- package/dist/node_modules/ajv/lib/dotjs/anyOf.js +73 -0
- package/dist/node_modules/ajv/lib/dotjs/comment.js +14 -0
- package/dist/node_modules/ajv/lib/dotjs/const.js +56 -0
- package/dist/node_modules/ajv/lib/dotjs/contains.js +81 -0
- package/dist/node_modules/ajv/lib/dotjs/custom.js +228 -0
- package/dist/node_modules/ajv/lib/dotjs/dependencies.js +168 -0
- package/dist/node_modules/ajv/lib/dotjs/enum.js +66 -0
- package/dist/node_modules/ajv/lib/dotjs/format.js +150 -0
- package/dist/node_modules/ajv/lib/dotjs/if.js +103 -0
- package/dist/node_modules/ajv/lib/dotjs/index.js +33 -0
- package/dist/node_modules/ajv/lib/dotjs/items.js +140 -0
- package/dist/node_modules/ajv/lib/dotjs/multipleOf.js +80 -0
- package/dist/node_modules/ajv/lib/dotjs/not.js +84 -0
- package/dist/node_modules/ajv/lib/dotjs/oneOf.js +73 -0
- package/dist/node_modules/ajv/lib/dotjs/pattern.js +75 -0
- package/dist/node_modules/ajv/lib/dotjs/properties.js +335 -0
- package/dist/node_modules/ajv/lib/dotjs/propertyNames.js +81 -0
- package/dist/node_modules/ajv/lib/dotjs/ref.js +124 -0
- package/dist/node_modules/ajv/lib/dotjs/required.js +270 -0
- package/dist/node_modules/ajv/lib/dotjs/uniqueItems.js +86 -0
- package/dist/node_modules/ajv/lib/dotjs/validate.js +482 -0
- package/dist/node_modules/ajv/lib/keyword.js +146 -0
- package/dist/node_modules/ajv/lib/refs/data.json +17 -0
- package/dist/node_modules/ajv/lib/refs/json-schema-draft-04.json +149 -0
- package/dist/node_modules/ajv/lib/refs/json-schema-draft-06.json +154 -0
- package/dist/node_modules/ajv/lib/refs/json-schema-draft-07.json +168 -0
- package/dist/node_modules/ajv/lib/refs/json-schema-secure.json +94 -0
- package/dist/node_modules/ajv/node_modules/json-schema-traverse/.eslintrc.yml +27 -0
- package/dist/node_modules/ajv/node_modules/json-schema-traverse/.travis.yml +8 -0
- package/dist/node_modules/ajv/node_modules/json-schema-traverse/index.js +89 -0
- package/dist/node_modules/ajv/node_modules/json-schema-traverse/package.json +43 -0
- package/dist/node_modules/ajv/node_modules/json-schema-traverse/spec/.eslintrc.yml +6 -0
- package/dist/node_modules/ajv/node_modules/json-schema-traverse/spec/fixtures/schema.js +125 -0
- package/dist/node_modules/ajv/node_modules/json-schema-traverse/spec/index.spec.js +171 -0
- package/dist/node_modules/ajv/package.json +1 -0
- package/dist/node_modules/ajv/scripts/.eslintrc.yml +3 -0
- package/dist/node_modules/ajv/scripts/bundle.js +61 -0
- package/dist/node_modules/ajv/scripts/compile-dots.js +73 -0
- package/dist/node_modules/ajv/scripts/info +10 -0
- package/dist/node_modules/ajv/scripts/prepare-tests +12 -0
- package/dist/node_modules/ajv/scripts/publish-built-version +32 -0
- package/dist/node_modules/ajv/scripts/travis-gh-pages +23 -0
- package/dist/server/collections/skill-definitions.js +31 -0
- package/dist/server/collections/skill-executions.js +19 -0
- package/dist/server/collections/skill-registry-installations.js +70 -0
- package/dist/server/migrations/20260621000000-native-policy-profile-defaults.js +0 -3
- package/dist/server/migrations/20260727000000-remove-unused-knowledge-scopes.js +51 -0
- package/dist/server/migrations/20260727010000-backfill-skill-tool-names.js +66 -0
- package/dist/server/plugin.js +107 -2
- package/dist/server/resources/agent-knowledge-insights.js +273 -0
- package/dist/server/services/AgentExecutionContext.js +45 -0
- package/dist/server/services/AgentMemoryContextService.js +57 -19
- package/dist/server/services/CodeValidator.js +1 -0
- package/dist/server/services/ExecutionSpanService.js +10 -2
- package/dist/server/services/InputSchemaValidator.js +83 -0
- package/dist/server/services/NativeSubAgentObserver.js +63 -8
- package/dist/server/services/SandboxRunner.js +6 -2
- package/dist/server/services/SkillAccessService.js +109 -0
- package/dist/server/services/SkillManager.js +2 -0
- package/dist/server/services/SkillRepositoryService.js +70 -0
- package/dist/server/skill-hub/actions/git-import.js +479 -216
- package/dist/server/skill-hub/mcp/McpController.js +8 -5
- package/dist/server/skill-hub/middlewares/git-import-request-method-policy.js +69 -0
- package/dist/server/skill-hub/plugin.js +68 -14
- package/dist/server/skill-hub/services/RegistrySkillInstallationService.js +249 -0
- package/dist/server/skill-hub/services/RegistrySkillSnapshotService.js +228 -0
- package/dist/server/skill-hub/tasks/SkillExecutionTask.js +15 -3
- package/dist/server/tools/external-rag-search.js +152 -12
- package/dist/server/tools/skill-execute.js +23 -2
- package/dist/server/utils/ctx-utils.js +2 -2
- package/dist/server/utils/skill-tool-name.js +73 -0
- package/package.json +9 -3
- package/src/client-v2/components/AgentBindingsTab.tsx +269 -0
- package/src/client-v2/components/HarnessProfilesTab.tsx +1 -2
- package/src/client-v2/components/KnowledgeAccessTab.tsx +116 -0
- package/src/client-v2/components/MemoryInspectorTab.tsx +125 -0
- package/src/client-v2/components/RetrievalTraceTab.tsx +162 -0
- package/src/client-v2/pages/AgentBindingsPage.tsx +13 -0
- package/src/client-v2/pages/KnowledgeAccessPage.tsx +10 -0
- package/src/client-v2/pages/MemoryInspectorPage.tsx +13 -0
- package/src/client-v2/pages/RetrievalTracePage.tsx +10 -0
- package/src/client-v2/plugin.tsx +28 -0
- package/src/locale/en-US.json +56 -2
- package/src/locale/vi-VN.json +56 -2
- package/src/locale/zh-CN.json +56 -2
- package/src/server/__tests__/agent-execution-context.test.ts +18 -0
- package/src/server/__tests__/agent-knowledge-insights.test.ts +123 -0
- package/src/server/__tests__/external-rag-search.test.ts +107 -0
- package/src/server/__tests__/input-schema-validator.test.ts +26 -0
- package/src/server/__tests__/native-sub-agent-observer.test.ts +141 -9
- package/src/server/__tests__/skill-access-service.test.ts +64 -0
- package/src/server/__tests__/skill-execute.test.ts +37 -0
- package/src/server/__tests__/skill-tool-name.test.ts +23 -0
- package/src/server/collections/skill-definitions.ts +31 -0
- package/src/server/collections/skill-executions.ts +19 -0
- package/src/server/collections/skill-registry-installations.ts +41 -0
- package/src/server/migrations/20260621000000-native-policy-profile-defaults.ts +0 -3
- package/src/server/migrations/20260727000000-remove-unused-knowledge-scopes.ts +25 -0
- package/src/server/migrations/20260727010000-backfill-skill-tool-names.ts +45 -0
- package/src/server/plugin.ts +107 -1
- package/src/server/resources/agent-knowledge-insights.ts +304 -0
- package/src/server/services/AgentExecutionContext.ts +23 -0
- package/src/server/services/AgentMemoryContextService.ts +63 -19
- package/src/server/services/CodeValidator.ts +1 -0
- package/src/server/services/ExecutionSpanService.ts +119 -110
- package/src/server/services/InputSchemaValidator.ts +44 -0
- package/src/server/services/NativeSubAgentObserver.ts +592 -528
- package/src/server/services/SandboxRunner.ts +6 -0
- package/src/server/services/SkillAccessService.ts +100 -0
- package/src/server/services/SkillManager.ts +2 -0
- package/src/server/services/SkillRepositoryService.ts +98 -2
- package/src/server/services/__tests__/SkillRepositoryService.test.ts +33 -0
- package/src/server/skill-hub/actions/__tests__/git-import.test.ts +501 -0
- package/src/server/skill-hub/actions/git-import.ts +682 -236
- package/src/server/skill-hub/mcp/McpController.ts +8 -14
- package/src/server/skill-hub/middlewares/git-import-request-method-policy.ts +51 -0
- package/src/server/skill-hub/plugin.ts +79 -13
- package/src/server/skill-hub/services/RegistrySkillInstallationService.ts +281 -0
- package/src/server/skill-hub/services/RegistrySkillSnapshotService.ts +239 -0
- package/src/server/skill-hub/services/__tests__/RegistrySkillInstallationService.test.ts +295 -0
- package/src/server/skill-hub/services/__tests__/RegistrySkillSnapshotService.test.ts +63 -0
- package/src/server/skill-hub/tasks/SkillExecutionTask.ts +14 -2
- package/src/server/tools/external-rag-search.ts +215 -14
- package/src/server/tools/skill-execute.ts +24 -2
- package/src/server/utils/ctx-utils.ts +1 -1
- package/src/server/utils/skill-tool-name.ts +58 -0
- package/dist/client-v2/418.29e713f79131eece.js +0 -10
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type PluginSkillHubServer from '../plugin';
|
|
2
2
|
import { parseJsonText } from '../utils/json-fields';
|
|
3
|
+
import { buildSkillToolName, getSkillToolName } from '../../utils/skill-tool-name';
|
|
3
4
|
|
|
4
5
|
export class McpController {
|
|
5
6
|
constructor(private plugin: PluginSkillHubServer) {}
|
|
@@ -15,11 +16,7 @@ export class McpController {
|
|
|
15
16
|
|
|
16
17
|
const tools = await Promise.all(
|
|
17
18
|
skills.map(async (skill: any) => ({
|
|
18
|
-
name: skill
|
|
19
|
-
.get('name')
|
|
20
|
-
.toLowerCase()
|
|
21
|
-
.replace(/[^a-z0-9_]/g, '_')
|
|
22
|
-
.replace(/_+/g, '_'),
|
|
19
|
+
name: getSkillToolName(skill),
|
|
23
20
|
description:
|
|
24
21
|
typeof this.plugin.getSkillDescriptionForAI === 'function'
|
|
25
22
|
? await this.plugin.getSkillDescriptionForAI(skill)
|
|
@@ -51,21 +48,18 @@ export class McpController {
|
|
|
51
48
|
filter: { enabled: true },
|
|
52
49
|
});
|
|
53
50
|
|
|
54
|
-
const skill = skills.find(
|
|
55
|
-
(s
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
.replace(/[^a-z0-9_]/g, '_')
|
|
60
|
-
.replace(/_+/g, '_') === name,
|
|
61
|
-
);
|
|
51
|
+
const skill = skills.find((s: any) => {
|
|
52
|
+
const stableName = getSkillToolName(s);
|
|
53
|
+
const legacyMcpName = buildSkillToolName(s.get('name')).replace(/^skill_hub_/, '');
|
|
54
|
+
return stableName === name || legacyMcpName === name;
|
|
55
|
+
});
|
|
62
56
|
|
|
63
57
|
if (!skill) {
|
|
64
58
|
ctx.throw(404, `Tool ${name} not found`);
|
|
65
59
|
}
|
|
66
60
|
|
|
67
61
|
try {
|
|
68
|
-
const result = await this.plugin.executeSkill(skill, args || {}, ctx);
|
|
62
|
+
const result = await this.plugin.executeSkill(skill, args || {}, ctx, { privileged: true });
|
|
69
63
|
|
|
70
64
|
let textContent = `Executed successfully.`;
|
|
71
65
|
if (result.stdout) textContent += `\nOutput:\n${result.stdout}`;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Context } from '@nocobase/actions';
|
|
2
|
+
|
|
3
|
+
type MethodContext = Context & {
|
|
4
|
+
method?: string;
|
|
5
|
+
set(name: string, value: string): void;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const GIT_IMPORT_METHODS = new Map<string, readonly string[]>([
|
|
9
|
+
['gitListSkills', ['GET', 'HEAD']],
|
|
10
|
+
['gitSyncSkills', ['POST']],
|
|
11
|
+
]);
|
|
12
|
+
const GIT_IMPORT_NAMESPACE = 'plugin-agent-orchestrator';
|
|
13
|
+
|
|
14
|
+
function translateMethodError(ctx: Context): string {
|
|
15
|
+
const key = 'This Skill Hub Git import action does not allow the request method.';
|
|
16
|
+
const translate = (ctx as unknown as { t?: unknown }).t;
|
|
17
|
+
if (typeof translate !== 'function') {
|
|
18
|
+
return key;
|
|
19
|
+
}
|
|
20
|
+
const translated = translate(key, { ns: GIT_IMPORT_NAMESPACE });
|
|
21
|
+
return typeof translated === 'string' ? translated : key;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Git imports are custom actions rather than collection CRUD. Keep their
|
|
26
|
+
* HTTP contract explicit so a mutation cannot be invoked through a read
|
|
27
|
+
* request (or vice versa).
|
|
28
|
+
*/
|
|
29
|
+
export function createGitImportRequestMethodPolicy() {
|
|
30
|
+
return async (ctx: Context, next: () => Promise<void>): Promise<void> => {
|
|
31
|
+
if (ctx.action.resourceName !== 'skillHub') {
|
|
32
|
+
await next();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const allowed = GIT_IMPORT_METHODS.get(ctx.action.actionName);
|
|
37
|
+
if (!allowed) {
|
|
38
|
+
await next();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const actionContext = ctx as MethodContext;
|
|
43
|
+
const method = String(actionContext.method || '').toUpperCase();
|
|
44
|
+
if (!allowed.includes(method)) {
|
|
45
|
+
actionContext.set('Allow', allowed.join(', '));
|
|
46
|
+
actionContext.throw(405, translateMethodError(ctx));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
await next();
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -10,12 +10,20 @@ import { createSkillExecuteTool } from '../tools/skill-execute';
|
|
|
10
10
|
import { McpController } from './mcp/McpController';
|
|
11
11
|
import { SkillRepositoryService } from '../services/SkillRepositoryService';
|
|
12
12
|
import { gitListSkills, gitSyncSkills } from './actions/git-import';
|
|
13
|
+
import { createGitImportRequestMethodPolicy } from './middlewares/git-import-request-method-policy';
|
|
13
14
|
import { parseJsonText, stringifyJsonText, parseJsonLike } from './utils/json-fields';
|
|
14
15
|
import { getOrchestratorTraceContext } from '../services/ExecutionSpanService';
|
|
15
16
|
import { tryGetAIToolsManager } from '../utils/ai-manager';
|
|
16
17
|
import type { ToolsRuntime } from '@nocobase/ai';
|
|
18
|
+
import { SkillAccessService } from '../services/SkillAccessService';
|
|
19
|
+
import { validateSkillInput } from '../services/InputSchemaValidator';
|
|
20
|
+
import { currentUserId } from '../utils/ctx-utils';
|
|
21
|
+
import { getSkillToolName, normalizeSkillToolScope, readRecordValue } from '../utils/skill-tool-name';
|
|
17
22
|
|
|
18
23
|
type ToolRuntimeInput = string | ToolsRuntime | undefined;
|
|
24
|
+
type ExecuteSkillOptions = {
|
|
25
|
+
privileged?: boolean;
|
|
26
|
+
};
|
|
19
27
|
const SKILL_TASK_POLL_INTERVAL_MS = Number.parseInt(process.env.SKILL_HUB_TASK_POLL_INTERVAL_MS || '5000', 10);
|
|
20
28
|
const SKILL_TASK_POLL_LIMIT = Number.parseInt(process.env.SKILL_HUB_TASK_POLL_LIMIT || '3', 10);
|
|
21
29
|
|
|
@@ -113,6 +121,7 @@ export class SkillHubSubFeature {
|
|
|
113
121
|
private skillTaskPolling = false;
|
|
114
122
|
private mcpController: McpController;
|
|
115
123
|
private skillRepoService: SkillRepositoryService;
|
|
124
|
+
readonly skillAccessService: SkillAccessService;
|
|
116
125
|
private rateLimiter = new RateLimiter(
|
|
117
126
|
parseInt(process.env.SKILL_HUB_RATE_LIMIT_MAX || '10', 10),
|
|
118
127
|
parseInt(process.env.SKILL_HUB_RATE_LIMIT_WINDOW_MS || '60000', 10),
|
|
@@ -129,7 +138,9 @@ export class SkillHubSubFeature {
|
|
|
129
138
|
});
|
|
130
139
|
};
|
|
131
140
|
|
|
132
|
-
constructor(private plugin: any) {
|
|
141
|
+
constructor(private plugin: any) {
|
|
142
|
+
this.skillAccessService = new SkillAccessService(plugin);
|
|
143
|
+
}
|
|
133
144
|
|
|
134
145
|
get app() {
|
|
135
146
|
return this.plugin.app;
|
|
@@ -141,6 +152,10 @@ export class SkillHubSubFeature {
|
|
|
141
152
|
return this.plugin.name;
|
|
142
153
|
}
|
|
143
154
|
|
|
155
|
+
getSkillRepositoryService(): SkillRepositoryService {
|
|
156
|
+
return this.skillRepoService;
|
|
157
|
+
}
|
|
158
|
+
|
|
144
159
|
async load() {
|
|
145
160
|
// 1. Collections and migrations are now handled by parent orchestrator plugin
|
|
146
161
|
|
|
@@ -154,6 +169,7 @@ export class SkillHubSubFeature {
|
|
|
154
169
|
this.mcpController = new McpController(this);
|
|
155
170
|
|
|
156
171
|
// 3. Register REST actions
|
|
172
|
+
(this as any).app.resourceManager.use(createGitImportRequestMethodPolicy());
|
|
157
173
|
(this as any).app.resourceManager.define({
|
|
158
174
|
name: 'skillHub',
|
|
159
175
|
actions: {
|
|
@@ -432,9 +448,17 @@ export class SkillHubSubFeature {
|
|
|
432
448
|
* Pushes progress to SSE via runtime.writer (if within AI tool context).
|
|
433
449
|
* Includes rate limiting and graceful abort propagation.
|
|
434
450
|
*/
|
|
435
|
-
async executeSkill(
|
|
451
|
+
async executeSkill(
|
|
452
|
+
skill: any,
|
|
453
|
+
inputArgs: Record<string, unknown>,
|
|
454
|
+
ctx?: any,
|
|
455
|
+
options: ExecuteSkillOptions = {},
|
|
456
|
+
): Promise<any> {
|
|
457
|
+
validateSkillInput(readRecordValue(skill, 'inputSchema'), inputArgs);
|
|
458
|
+
const aiEmployeeUsername = await this.skillAccessService.assertCanExecute(ctx, skill, options);
|
|
459
|
+
|
|
436
460
|
// ── Rate limiting ──
|
|
437
|
-
const userId = ctx
|
|
461
|
+
const userId = currentUserId(ctx);
|
|
438
462
|
if (userId) {
|
|
439
463
|
if (!this.rateLimiter.check(String(userId))) {
|
|
440
464
|
const remaining = this.rateLimiter.remaining(String(userId));
|
|
@@ -451,7 +475,9 @@ export class SkillHubSubFeature {
|
|
|
451
475
|
skillId: skill.id,
|
|
452
476
|
status: 'pending',
|
|
453
477
|
inputArgs: stringifyJsonText(inputArgs, {}),
|
|
454
|
-
sessionId: ctx?.state?.sessionId,
|
|
478
|
+
sessionId: traceContext?.sessionId || ctx?.state?.sessionId || ctx?.action?.params?.values?.sessionId,
|
|
479
|
+
aiEmployeeUsername,
|
|
480
|
+
skillToolName: getSkillToolName(skill),
|
|
455
481
|
orchestratorRootRunId: traceContext?.rootRunId,
|
|
456
482
|
orchestratorSpanId: traceContext?.spanId,
|
|
457
483
|
orchestratorParentSpanId: traceContext?.parentSpanId,
|
|
@@ -463,6 +489,13 @@ export class SkillHubSubFeature {
|
|
|
463
489
|
});
|
|
464
490
|
|
|
465
491
|
const execId = String(execution.id);
|
|
492
|
+
const linkedSpanId = await this.linkSkillExecutionToSpan(traceContext, execId);
|
|
493
|
+
if (linkedSpanId && String(linkedSpanId) !== String(traceContext?.spanId || '')) {
|
|
494
|
+
await (this as any).db.getRepository('skillExecutions').update({
|
|
495
|
+
filterByTk: execId,
|
|
496
|
+
values: { orchestratorSpanId: linkedSpanId },
|
|
497
|
+
});
|
|
498
|
+
}
|
|
466
499
|
|
|
467
500
|
(this as any).app.logger.info(
|
|
468
501
|
`[skill-hub] Queued execution ${execId}: skill=${skill.get ? skill.get('name') : skill.name}, ` +
|
|
@@ -590,6 +623,45 @@ export class SkillHubSubFeature {
|
|
|
590
623
|
};
|
|
591
624
|
}
|
|
592
625
|
|
|
626
|
+
private async linkSkillExecutionToSpan(traceContext: any, executionId: string) {
|
|
627
|
+
if (!traceContext?.rootRunId) return undefined;
|
|
628
|
+
try {
|
|
629
|
+
const repo = (this as any).db.getRepository('agentExecutionSpans');
|
|
630
|
+
if (!repo) return undefined;
|
|
631
|
+
|
|
632
|
+
let span = null;
|
|
633
|
+
if (traceContext.toolCallId) {
|
|
634
|
+
span = await repo.findOne({
|
|
635
|
+
filter: {
|
|
636
|
+
rootRunId: traceContext.rootRunId,
|
|
637
|
+
toolCallId: traceContext.toolCallId,
|
|
638
|
+
},
|
|
639
|
+
sort: ['-id'],
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
// spanId is normally the Sub-Agent root span. Only use it when there is
|
|
643
|
+
// no tool-call identity; otherwise a beforeToolCall race could turn the
|
|
644
|
+
// whole Sub-Agent run into a skill span.
|
|
645
|
+
if (!traceContext.toolCallId && traceContext.spanId) {
|
|
646
|
+
span = await repo.findOne({ filterByTk: traceContext.spanId });
|
|
647
|
+
}
|
|
648
|
+
if (!span) return undefined;
|
|
649
|
+
|
|
650
|
+
const spanId = readRecordValue(span, 'id');
|
|
651
|
+
await repo.update({
|
|
652
|
+
filterByTk: spanId,
|
|
653
|
+
values: {
|
|
654
|
+
type: 'skill',
|
|
655
|
+
skillExecutionId: executionId,
|
|
656
|
+
},
|
|
657
|
+
});
|
|
658
|
+
return spanId;
|
|
659
|
+
} catch (error) {
|
|
660
|
+
(this as any).app.logger.warn('[skill-hub] Failed to link skill execution to agent span', error);
|
|
661
|
+
return undefined;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
593
665
|
private async handleDownload(ctx: any, next: any) {
|
|
594
666
|
const { execId, filename, f } = ctx.action.params;
|
|
595
667
|
let targetFile = filename;
|
|
@@ -644,7 +716,7 @@ export class SkillHubSubFeature {
|
|
|
644
716
|
ctx.throw(404, 'Skill not found');
|
|
645
717
|
}
|
|
646
718
|
|
|
647
|
-
const result = await this.executeSkill(skill, input || {}, ctx);
|
|
719
|
+
const result = await this.executeSkill(skill, input || {}, ctx, { privileged: true });
|
|
648
720
|
ctx.body = result;
|
|
649
721
|
await next();
|
|
650
722
|
}
|
|
@@ -803,12 +875,6 @@ export class SkillHubSubFeature {
|
|
|
803
875
|
|
|
804
876
|
const tools = await Promise.all(
|
|
805
877
|
skills.map(async (skill: any) => {
|
|
806
|
-
const sanitizedToolName = skill
|
|
807
|
-
.get('name')
|
|
808
|
-
.toLowerCase()
|
|
809
|
-
.replace(/[^a-z0-9_]/g, '_')
|
|
810
|
-
.replace(/_+/g, '_')
|
|
811
|
-
.replace(/^_|_$/g, '');
|
|
812
878
|
const autoCall = !!skill.get('autoCall');
|
|
813
879
|
const loopConfig = loopConfigsBySkillId.get(this.getSkillRecordId(skill));
|
|
814
880
|
const loopInteractionSchema = this.resolveLoopInteractionSchema(loopConfig);
|
|
@@ -823,7 +889,7 @@ export class SkillHubSubFeature {
|
|
|
823
889
|
? `${baseDescription}\n\nIMPORTANT: This skill is bound to a Skill Hub human-in-the-loop review template. Pass best-effort args; the user can approve, edit, or reject them before execution.`
|
|
824
890
|
: baseDescription;
|
|
825
891
|
return {
|
|
826
|
-
scope: '
|
|
892
|
+
scope: normalizeSkillToolScope(skill.get('toolScope')),
|
|
827
893
|
execution: 'backend' as const,
|
|
828
894
|
defaultPermission: (requiresHumanReview ? 'ASK' : autoCall ? 'ALLOW' : 'ASK') as 'ALLOW' | 'ASK',
|
|
829
895
|
introduction: {
|
|
@@ -831,7 +897,7 @@ export class SkillHubSubFeature {
|
|
|
831
897
|
about: skill.get('description') || `Thực thi kỹ năng ${skill.get('title')}`,
|
|
832
898
|
},
|
|
833
899
|
definition: {
|
|
834
|
-
name:
|
|
900
|
+
name: getSkillToolName(skill),
|
|
835
901
|
description,
|
|
836
902
|
schema: parseJsonText(skill.get('inputSchema'), { type: 'object', properties: {} }),
|
|
837
903
|
},
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
|
|
3
|
+
import type { Database } from '@nocobase/database';
|
|
4
|
+
|
|
5
|
+
import type { SkillRepositoryService } from '../../services/SkillRepositoryService';
|
|
6
|
+
import { assertSkillToolNameAvailable, buildSkillToolName } from '../../utils/skill-tool-name';
|
|
7
|
+
|
|
8
|
+
export interface RegistryInstallationInput {
|
|
9
|
+
registryPackageId: string | number;
|
|
10
|
+
registryVersionId: string | number;
|
|
11
|
+
packageIdentity: string;
|
|
12
|
+
version: string;
|
|
13
|
+
channel: string;
|
|
14
|
+
artifactDigest: string;
|
|
15
|
+
sourceSignature: string | null;
|
|
16
|
+
updatePolicy: 'pinned' | 'channel';
|
|
17
|
+
runtime: 'python' | 'node';
|
|
18
|
+
codeTemplate: string;
|
|
19
|
+
entrypoint: string;
|
|
20
|
+
files: Array<{ path: string; content: Buffer }>;
|
|
21
|
+
instructions: string;
|
|
22
|
+
inputSchema: unknown;
|
|
23
|
+
dependencies: unknown;
|
|
24
|
+
installedById?: string | number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface RegistryInstallationResult {
|
|
28
|
+
installationId: string;
|
|
29
|
+
skillDefinitionId: string;
|
|
30
|
+
toolName: string;
|
|
31
|
+
status: 'installed';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface RegistryRollbackTarget {
|
|
35
|
+
registryVersionId: string;
|
|
36
|
+
updatePolicy: 'pinned' | 'channel';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface RegistryInstallationState {
|
|
40
|
+
installationId: string;
|
|
41
|
+
registryPackageId: string;
|
|
42
|
+
registryVersionId: string;
|
|
43
|
+
skillDefinitionId: string;
|
|
44
|
+
version: string;
|
|
45
|
+
updatePolicy: 'pinned' | 'channel';
|
|
46
|
+
status: string;
|
|
47
|
+
installedAt: string | null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type Model = {
|
|
51
|
+
get(attribute: string): unknown;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
function read(model: Model, attribute: string, fallback = ''): string {
|
|
55
|
+
const value = model.get(attribute);
|
|
56
|
+
return typeof value === 'string' ? value : value === null || value === undefined ? fallback : String(value);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function localSkillName(packageIdentity: string): string {
|
|
60
|
+
const normalizedIdentity = packageIdentity
|
|
61
|
+
.toLowerCase()
|
|
62
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
63
|
+
.replace(/^-+|-+$/g, '');
|
|
64
|
+
const readablePrefix = normalizedIdentity ? `registry-${normalizedIdentity}` : 'registry';
|
|
65
|
+
const suffix = createHash('sha256').update(packageIdentity).digest('hex').slice(0, 12);
|
|
66
|
+
return `${readablePrefix.slice(0, 87)}-${suffix}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function jsonText(value: unknown, fallback: unknown): string {
|
|
70
|
+
try {
|
|
71
|
+
return JSON.stringify(value ?? fallback);
|
|
72
|
+
} catch {
|
|
73
|
+
return JSON.stringify(fallback);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function executionWrapper(runtime: 'python' | 'node', entrypoint: string): string {
|
|
78
|
+
const serializedEntrypoint = JSON.stringify(entrypoint);
|
|
79
|
+
if (runtime === 'python') {
|
|
80
|
+
return [
|
|
81
|
+
'import os',
|
|
82
|
+
'import runpy',
|
|
83
|
+
`runpy.run_path(os.path.join(os.environ['SKILL_DIR'], ${serializedEntrypoint}), run_name='__main__')`,
|
|
84
|
+
'',
|
|
85
|
+
].join('\n');
|
|
86
|
+
}
|
|
87
|
+
return `require(require('path').join(process.env.SKILL_DIR, ${serializedEntrypoint}));\n`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export class RegistrySkillInstallationService {
|
|
91
|
+
constructor(
|
|
92
|
+
private readonly database: Database,
|
|
93
|
+
private readonly getSkillRepository: () => SkillRepositoryService,
|
|
94
|
+
) {}
|
|
95
|
+
|
|
96
|
+
async getRegistryInstallationStates(
|
|
97
|
+
registryVersionIds: Array<string | number>,
|
|
98
|
+
): Promise<RegistryInstallationState[]> {
|
|
99
|
+
if (registryVersionIds.length === 0) return [];
|
|
100
|
+
const installations = await this.database.getRepository('skillRegistryInstallations').find({
|
|
101
|
+
filter: { registryVersionId: { $in: registryVersionIds } },
|
|
102
|
+
sort: ['-installedAt', '-id'],
|
|
103
|
+
});
|
|
104
|
+
return installations.map((installation) => {
|
|
105
|
+
const record = installation as unknown as Model;
|
|
106
|
+
const installedAt = installation.get('installedAt');
|
|
107
|
+
return {
|
|
108
|
+
installationId: read(record, 'id'),
|
|
109
|
+
registryPackageId: read(record, 'registryPackageId'),
|
|
110
|
+
registryVersionId: read(record, 'registryVersionId'),
|
|
111
|
+
skillDefinitionId: read(record, 'skillDefinitionId'),
|
|
112
|
+
version: read(record, 'version'),
|
|
113
|
+
updatePolicy: read(record, 'updatePolicy') === 'channel' ? 'channel' : 'pinned',
|
|
114
|
+
status: read(record, 'status'),
|
|
115
|
+
installedAt: installedAt instanceof Date ? installedAt.toISOString() : installedAt ? String(installedAt) : null,
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async getRollbackTarget(installationId: string | number): Promise<RegistryRollbackTarget | null> {
|
|
121
|
+
const installations = this.database.getRepository('skillRegistryInstallations');
|
|
122
|
+
const installation = await installations.findOne({ filterByTk: installationId });
|
|
123
|
+
if (!installation || read(installation as unknown as Model, 'status') !== 'installed') {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
const previousInstallationId = read(installation as unknown as Model, 'previousInstallationId');
|
|
127
|
+
if (!previousInstallationId) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
const previous = await installations.findOne({ filterByTk: previousInstallationId });
|
|
131
|
+
if (!previous) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const registryVersionId = read(previous as unknown as Model, 'registryVersionId');
|
|
135
|
+
if (!registryVersionId) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
registryVersionId,
|
|
140
|
+
updatePolicy: read(previous as unknown as Model, 'updatePolicy') === 'channel' ? 'channel' : 'pinned',
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async installRegistryVersion(input: RegistryInstallationInput): Promise<RegistryInstallationResult> {
|
|
145
|
+
const installations = this.database.getRepository('skillRegistryInstallations');
|
|
146
|
+
const existing = await installations.findOne({ filter: { registryVersionId: input.registryVersionId } });
|
|
147
|
+
if (existing && read(existing as unknown as Model, 'status') === 'installed') {
|
|
148
|
+
const skillDefinitionId = read(existing as unknown as Model, 'skillDefinitionId');
|
|
149
|
+
const skill = await this.database.getRepository('skillDefinitions').findOne({ filterByTk: skillDefinitionId });
|
|
150
|
+
if (!skill) {
|
|
151
|
+
throw new Error('Existing registry installation has no skill definition.');
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
installationId: read(existing as unknown as Model, 'id'),
|
|
155
|
+
skillDefinitionId,
|
|
156
|
+
toolName: read(skill as unknown as Model, 'toolName'),
|
|
157
|
+
status: 'installed',
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const previous = await installations.findOne({
|
|
162
|
+
filter: { registryPackageId: input.registryPackageId, status: 'installed' },
|
|
163
|
+
sort: ['-installedAt', '-id'],
|
|
164
|
+
});
|
|
165
|
+
const skillDefinitions = this.database.getRepository('skillDefinitions');
|
|
166
|
+
const previousSkillDefinitionId = previous ? read(previous as unknown as Model, 'skillDefinitionId') : '';
|
|
167
|
+
let skill = previousSkillDefinitionId
|
|
168
|
+
? await skillDefinitions.findOne({ filterByTk: previousSkillDefinitionId })
|
|
169
|
+
: null;
|
|
170
|
+
const name = skill ? read(skill as unknown as Model, 'name') : localSkillName(input.packageIdentity);
|
|
171
|
+
if (!input.codeTemplate.trim()) {
|
|
172
|
+
throw new Error('Registry artifact entrypoint is empty.');
|
|
173
|
+
}
|
|
174
|
+
const skillRepository = this.getSkillRepository();
|
|
175
|
+
const previousPackage = skillRepository.readSkillPackageFiles(name);
|
|
176
|
+
const values = {
|
|
177
|
+
title: input.packageIdentity,
|
|
178
|
+
description: `Registry package ${input.packageIdentity}@${input.version}`,
|
|
179
|
+
instructions: input.instructions,
|
|
180
|
+
language: input.runtime,
|
|
181
|
+
codeTemplate: executionWrapper(input.runtime, input.entrypoint),
|
|
182
|
+
inputSchema: jsonText(input.inputSchema, { type: 'object', properties: {} }),
|
|
183
|
+
packages: jsonText(input.dependencies, []),
|
|
184
|
+
storageType: 'local',
|
|
185
|
+
storageUrl: `local://registry/${name}`,
|
|
186
|
+
enabled: false,
|
|
187
|
+
toolScope: 'CUSTOM',
|
|
188
|
+
autoCall: false,
|
|
189
|
+
registryPackageId: input.registryPackageId,
|
|
190
|
+
registryVersionId: input.registryVersionId,
|
|
191
|
+
registryChannel: input.channel,
|
|
192
|
+
sourceDigest: input.artifactDigest,
|
|
193
|
+
sourceSignature: input.sourceSignature,
|
|
194
|
+
registryInstallStatus: 'installed',
|
|
195
|
+
registryUpdatePolicy: input.updatePolicy,
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
if (!skill) {
|
|
199
|
+
const toolName = buildSkillToolName(name);
|
|
200
|
+
await assertSkillToolNameAvailable(this.database, toolName);
|
|
201
|
+
}
|
|
202
|
+
skillRepository.writeSkillPackage(name, input.files);
|
|
203
|
+
try {
|
|
204
|
+
return await this.database.sequelize.transaction(async (transaction) => {
|
|
205
|
+
if (!skill) {
|
|
206
|
+
const toolName = buildSkillToolName(name);
|
|
207
|
+
skill = await skillDefinitions.create({ values: { name, toolName, ...values }, transaction });
|
|
208
|
+
} else {
|
|
209
|
+
await skillDefinitions.update({
|
|
210
|
+
filterByTk: read(skill as unknown as Model, 'id'),
|
|
211
|
+
values,
|
|
212
|
+
transaction,
|
|
213
|
+
});
|
|
214
|
+
skill = await skillDefinitions.findOne({ filterByTk: read(skill as unknown as Model, 'id'), transaction });
|
|
215
|
+
}
|
|
216
|
+
if (!skill) {
|
|
217
|
+
throw new Error('Failed to materialize the registry skill definition.');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const installationValues = {
|
|
221
|
+
registryPackageId: input.registryPackageId,
|
|
222
|
+
registryVersionId: input.registryVersionId,
|
|
223
|
+
packageIdentity: input.packageIdentity,
|
|
224
|
+
version: input.version,
|
|
225
|
+
channel: input.channel,
|
|
226
|
+
artifactDigest: input.artifactDigest,
|
|
227
|
+
sourceSignature: input.sourceSignature,
|
|
228
|
+
updatePolicy: input.updatePolicy,
|
|
229
|
+
status: 'installed',
|
|
230
|
+
skillDefinitionId: read(skill as unknown as Model, 'id'),
|
|
231
|
+
previousInstallationId: previous ? read(previous as unknown as Model, 'id') : null,
|
|
232
|
+
installedAt: new Date(),
|
|
233
|
+
installedById: input.installedById || null,
|
|
234
|
+
lastError: null,
|
|
235
|
+
};
|
|
236
|
+
let installation = existing;
|
|
237
|
+
if (installation) {
|
|
238
|
+
await installations.update({
|
|
239
|
+
filterByTk: read(installation as unknown as Model, 'id'),
|
|
240
|
+
values: installationValues,
|
|
241
|
+
transaction,
|
|
242
|
+
});
|
|
243
|
+
installation = await installations.findOne({
|
|
244
|
+
filterByTk: read(installation as unknown as Model, 'id'),
|
|
245
|
+
transaction,
|
|
246
|
+
});
|
|
247
|
+
} else {
|
|
248
|
+
installation = await installations.create({ values: installationValues, transaction });
|
|
249
|
+
}
|
|
250
|
+
if (!installation) {
|
|
251
|
+
throw new Error('Failed to persist the registry installation.');
|
|
252
|
+
}
|
|
253
|
+
await skillDefinitions.update({
|
|
254
|
+
filterByTk: read(skill as unknown as Model, 'id'),
|
|
255
|
+
values: { registryInstallationId: read(installation as unknown as Model, 'id') },
|
|
256
|
+
transaction,
|
|
257
|
+
});
|
|
258
|
+
if (previous) {
|
|
259
|
+
await installations.update({
|
|
260
|
+
filterByTk: read(previous as unknown as Model, 'id'),
|
|
261
|
+
values: { status: 'rolled_back' },
|
|
262
|
+
transaction,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
installationId: read(installation as unknown as Model, 'id'),
|
|
267
|
+
skillDefinitionId: read(skill as unknown as Model, 'id'),
|
|
268
|
+
toolName: read(skill as unknown as Model, 'toolName'),
|
|
269
|
+
status: 'installed' as const,
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
} catch (error) {
|
|
273
|
+
if (previousPackage) {
|
|
274
|
+
skillRepository.writeSkillPackage(name, previousPackage);
|
|
275
|
+
} else {
|
|
276
|
+
skillRepository.removeSkillPackage(name);
|
|
277
|
+
}
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|