plugin-agent-orchestrator 1.1.0 → 1.1.3

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 +549 -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
@@ -30,6 +30,7 @@ __export(McpController_exports, {
30
30
  });
31
31
  module.exports = __toCommonJS(McpController_exports);
32
32
  var import_json_fields = require("../utils/json-fields");
33
+ var import_skill_tool_name = require("../../utils/skill-tool-name");
33
34
  class McpController {
34
35
  constructor(plugin) {
35
36
  this.plugin = plugin;
@@ -44,7 +45,7 @@ class McpController {
44
45
  });
45
46
  const tools = await Promise.all(
46
47
  skills.map(async (skill) => ({
47
- name: skill.get("name").toLowerCase().replace(/[^a-z0-9_]/g, "_").replace(/_+/g, "_"),
48
+ name: (0, import_skill_tool_name.getSkillToolName)(skill),
48
49
  description: typeof this.plugin.getSkillDescriptionForAI === "function" ? await this.plugin.getSkillDescriptionForAI(skill) : skill.get("description"),
49
50
  inputSchema: (0, import_json_fields.parseJsonText)(skill.get("inputSchema"), null)
50
51
  }))
@@ -67,14 +68,16 @@ class McpController {
67
68
  const skills = await this.plugin.db.getRepository("skillDefinitions").find({
68
69
  filter: { enabled: true }
69
70
  });
70
- const skill = skills.find(
71
- (s) => s.get("name").toLowerCase().replace(/[^a-z0-9_]/g, "_").replace(/_+/g, "_") === name
72
- );
71
+ const skill = skills.find((s) => {
72
+ const stableName = (0, import_skill_tool_name.getSkillToolName)(s);
73
+ const legacyMcpName = (0, import_skill_tool_name.buildSkillToolName)(s.get("name")).replace(/^skill_hub_/, "");
74
+ return stableName === name || legacyMcpName === name;
75
+ });
73
76
  if (!skill) {
74
77
  ctx.throw(404, `Tool ${name} not found`);
75
78
  }
76
79
  try {
77
- const result = await this.plugin.executeSkill(skill, args || {}, ctx);
80
+ const result = await this.plugin.executeSkill(skill, args || {}, ctx, { privileged: true });
78
81
  let textContent = `Executed successfully.`;
79
82
  if (result.stdout) textContent += `
80
83
  Output:
@@ -0,0 +1,69 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var git_import_request_method_policy_exports = {};
28
+ __export(git_import_request_method_policy_exports, {
29
+ createGitImportRequestMethodPolicy: () => createGitImportRequestMethodPolicy
30
+ });
31
+ module.exports = __toCommonJS(git_import_request_method_policy_exports);
32
+ const GIT_IMPORT_METHODS = /* @__PURE__ */ new Map([
33
+ ["gitListSkills", ["GET", "HEAD"]],
34
+ ["gitSyncSkills", ["POST"]]
35
+ ]);
36
+ const GIT_IMPORT_NAMESPACE = "plugin-agent-orchestrator";
37
+ function translateMethodError(ctx) {
38
+ const key = "This Skill Hub Git import action does not allow the request method.";
39
+ const translate = ctx.t;
40
+ if (typeof translate !== "function") {
41
+ return key;
42
+ }
43
+ const translated = translate(key, { ns: GIT_IMPORT_NAMESPACE });
44
+ return typeof translated === "string" ? translated : key;
45
+ }
46
+ function createGitImportRequestMethodPolicy() {
47
+ return async (ctx, next) => {
48
+ if (ctx.action.resourceName !== "skillHub") {
49
+ await next();
50
+ return;
51
+ }
52
+ const allowed = GIT_IMPORT_METHODS.get(ctx.action.actionName);
53
+ if (!allowed) {
54
+ await next();
55
+ return;
56
+ }
57
+ const actionContext = ctx;
58
+ const method = String(actionContext.method || "").toUpperCase();
59
+ if (!allowed.includes(method)) {
60
+ actionContext.set("Allow", allowed.join(", "));
61
+ actionContext.throw(405, translateMethodError(ctx));
62
+ }
63
+ await next();
64
+ };
65
+ }
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ createGitImportRequestMethodPolicy
69
+ });
@@ -53,9 +53,14 @@ var import_skill_execute = require("../tools/skill-execute");
53
53
  var import_McpController = require("./mcp/McpController");
54
54
  var import_SkillRepositoryService = require("../services/SkillRepositoryService");
55
55
  var import_git_import = require("./actions/git-import");
56
+ var import_git_import_request_method_policy = require("./middlewares/git-import-request-method-policy");
56
57
  var import_json_fields = require("./utils/json-fields");
57
58
  var import_ExecutionSpanService = require("../services/ExecutionSpanService");
58
59
  var import_ai_manager = require("../utils/ai-manager");
60
+ var import_SkillAccessService = require("../services/SkillAccessService");
61
+ var import_InputSchemaValidator = require("../services/InputSchemaValidator");
62
+ var import_ctx_utils = require("../utils/ctx-utils");
63
+ var import_skill_tool_name = require("../utils/skill-tool-name");
59
64
  const SKILL_TASK_POLL_INTERVAL_MS = Number.parseInt(process.env.SKILL_HUB_TASK_POLL_INTERVAL_MS || "5000", 10);
60
65
  const SKILL_TASK_POLL_LIMIT = Number.parseInt(process.env.SKILL_HUB_TASK_POLL_LIMIT || "3", 10);
61
66
  function positiveInteger(value, fallback) {
@@ -127,6 +132,7 @@ class RateLimiter {
127
132
  class SkillHubSubFeature {
128
133
  constructor(plugin) {
129
134
  this.plugin = plugin;
135
+ this.skillAccessService = new import_SkillAccessService.SkillAccessService(plugin);
130
136
  }
131
137
  sandboxRunner;
132
138
  fileManager;
@@ -141,6 +147,7 @@ class SkillHubSubFeature {
141
147
  skillTaskPolling = false;
142
148
  mcpController;
143
149
  skillRepoService;
150
+ skillAccessService;
144
151
  rateLimiter = new RateLimiter(
145
152
  parseInt(process.env.SKILL_HUB_RATE_LIMIT_MAX || "10", 10),
146
153
  parseInt(process.env.SKILL_HUB_RATE_LIMIT_WINDOW_MS || "60000", 10)
@@ -165,6 +172,9 @@ class SkillHubSubFeature {
165
172
  get name() {
166
173
  return this.plugin.name;
167
174
  }
175
+ getSkillRepositoryService() {
176
+ return this.skillRepoService;
177
+ }
168
178
  async load() {
169
179
  const storagePath = (0, import_path.resolve)(process.cwd(), "storage", "plugin-skill-hub");
170
180
  this.fileManager = new import_FileManager.FileManager(storagePath);
@@ -173,6 +183,7 @@ class SkillHubSubFeature {
173
183
  this.workerEnvManager = new import_WorkerEnvManager.WorkerEnvManager(this.app, this.db, storagePath);
174
184
  this.skillRepoService = new import_SkillRepositoryService.SkillRepositoryService(storagePath);
175
185
  this.mcpController = new import_McpController.McpController(this);
186
+ this.app.resourceManager.use((0, import_git_import_request_method_policy.createGitImportRequestMethodPolicy)());
176
187
  this.app.resourceManager.define({
177
188
  name: "skillHub",
178
189
  actions: {
@@ -420,9 +431,11 @@ class SkillHubSubFeature {
420
431
  * Pushes progress to SSE via runtime.writer (if within AI tool context).
421
432
  * Includes rate limiting and graceful abort propagation.
422
433
  */
423
- async executeSkill(skill, inputArgs, ctx) {
424
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
425
- const userId = (_b = (_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id;
434
+ async executeSkill(skill, inputArgs, ctx, options = {}) {
435
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
436
+ (0, import_InputSchemaValidator.validateSkillInput)((0, import_skill_tool_name.readRecordValue)(skill, "inputSchema"), inputArgs);
437
+ const aiEmployeeUsername = await this.skillAccessService.assertCanExecute(ctx, skill, options);
438
+ const userId = (0, import_ctx_utils.currentUserId)(ctx);
426
439
  if (userId) {
427
440
  if (!this.rateLimiter.check(String(userId))) {
428
441
  const remaining = this.rateLimiter.remaining(String(userId));
@@ -437,17 +450,26 @@ class SkillHubSubFeature {
437
450
  skillId: skill.id,
438
451
  status: "pending",
439
452
  inputArgs: (0, import_json_fields.stringifyJsonText)(inputArgs, {}),
440
- sessionId: (_c = ctx == null ? void 0 : ctx.state) == null ? void 0 : _c.sessionId,
453
+ sessionId: (traceContext == null ? void 0 : traceContext.sessionId) || ((_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.sessionId) || ((_d = (_c = (_b = ctx == null ? void 0 : ctx.action) == null ? void 0 : _b.params) == null ? void 0 : _c.values) == null ? void 0 : _d.sessionId),
454
+ aiEmployeeUsername,
455
+ skillToolName: (0, import_skill_tool_name.getSkillToolName)(skill),
441
456
  orchestratorRootRunId: traceContext == null ? void 0 : traceContext.rootRunId,
442
457
  orchestratorSpanId: traceContext == null ? void 0 : traceContext.spanId,
443
458
  orchestratorParentSpanId: traceContext == null ? void 0 : traceContext.parentSpanId,
444
459
  orchestratorToolCallId: traceContext == null ? void 0 : traceContext.toolCallId,
445
460
  agentLoopRunId: traceContext == null ? void 0 : traceContext.agentLoopRunId,
446
461
  agentLoopStepId: traceContext == null ? void 0 : traceContext.agentLoopStepId,
447
- triggeredById: (_e = (_d = ctx == null ? void 0 : ctx.state) == null ? void 0 : _d.currentUser) == null ? void 0 : _e.id
462
+ triggeredById: (_f = (_e = ctx == null ? void 0 : ctx.state) == null ? void 0 : _e.currentUser) == null ? void 0 : _f.id
448
463
  }
449
464
  });
450
465
  const execId = String(execution.id);
466
+ const linkedSpanId = await this.linkSkillExecutionToSpan(traceContext, execId);
467
+ if (linkedSpanId && String(linkedSpanId) !== String((traceContext == null ? void 0 : traceContext.spanId) || "")) {
468
+ await this.db.getRepository("skillExecutions").update({
469
+ filterByTk: execId,
470
+ values: { orchestratorSpanId: linkedSpanId }
471
+ });
472
+ }
451
473
  this.app.logger.info(
452
474
  `[skill-hub] Queued execution ${execId}: skill=${skill.get ? skill.get("name") : skill.name}, user=${userId || "system"}`
453
475
  );
@@ -473,7 +495,7 @@ class SkillHubSubFeature {
473
495
  resolvePromise = resolve2;
474
496
  rejectPromise = reject;
475
497
  });
476
- const timeoutMs = ((skill.timeoutSeconds || ((_f = skill.get) == null ? void 0 : _f.call(skill, "timeoutSeconds")) || 60) + 15) * 1e3;
498
+ const timeoutMs = ((skill.timeoutSeconds || ((_g = skill.get) == null ? void 0 : _g.call(skill, "timeoutSeconds")) || 60) + 15) * 1e3;
477
499
  const timeout = setTimeout(() => {
478
500
  clearInterval(poll);
479
501
  rejectPromise(new Error(`Skill execution timeout after ${skill.timeoutSeconds || 60}s`));
@@ -496,7 +518,7 @@ class SkillHubSubFeature {
496
518
  } catch {
497
519
  }
498
520
  }, 2e3);
499
- (_g = poll.unref) == null ? void 0 : _g.call(poll);
521
+ (_h = poll.unref) == null ? void 0 : _h.call(poll);
500
522
  const doneCallback = async (data) => {
501
523
  clearTimeout(timeout);
502
524
  clearInterval(poll);
@@ -506,9 +528,9 @@ class SkillHubSubFeature {
506
528
  cleanups.push({ channel: progressChannel, callback: progressCallback });
507
529
  await this.app.pubSubManager.subscribe(doneChannel, doneCallback);
508
530
  cleanups.push({ channel: doneChannel, callback: doneCallback });
509
- if (((_h = ctx == null ? void 0 : ctx.req) == null ? void 0 : _h.signal) || (ctx == null ? void 0 : ctx.signal)) {
510
- const signal = ((_i = ctx.req) == null ? void 0 : _i.signal) || ctx.signal;
511
- (_j = signal.addEventListener) == null ? void 0 : _j.call(signal, "abort", () => {
531
+ if (((_i = ctx == null ? void 0 : ctx.req) == null ? void 0 : _i.signal) || (ctx == null ? void 0 : ctx.signal)) {
532
+ const signal = ((_j = ctx.req) == null ? void 0 : _j.signal) || ctx.signal;
533
+ (_k = signal.addEventListener) == null ? void 0 : _k.call(signal, "abort", () => {
512
534
  clearTimeout(timeout);
513
535
  this.app.pubSubManager.publish(abortChannel, { reason: "user_cancel" }).catch(() => {
514
536
  });
@@ -545,6 +567,39 @@ class SkillHubSubFeature {
545
567
  agentLoopStepId: traceContext == null ? void 0 : traceContext.agentLoopStepId
546
568
  };
547
569
  }
570
+ async linkSkillExecutionToSpan(traceContext, executionId) {
571
+ if (!(traceContext == null ? void 0 : traceContext.rootRunId)) return void 0;
572
+ try {
573
+ const repo = this.db.getRepository("agentExecutionSpans");
574
+ if (!repo) return void 0;
575
+ let span = null;
576
+ if (traceContext.toolCallId) {
577
+ span = await repo.findOne({
578
+ filter: {
579
+ rootRunId: traceContext.rootRunId,
580
+ toolCallId: traceContext.toolCallId
581
+ },
582
+ sort: ["-id"]
583
+ });
584
+ }
585
+ if (!traceContext.toolCallId && traceContext.spanId) {
586
+ span = await repo.findOne({ filterByTk: traceContext.spanId });
587
+ }
588
+ if (!span) return void 0;
589
+ const spanId = (0, import_skill_tool_name.readRecordValue)(span, "id");
590
+ await repo.update({
591
+ filterByTk: spanId,
592
+ values: {
593
+ type: "skill",
594
+ skillExecutionId: executionId
595
+ }
596
+ });
597
+ return spanId;
598
+ } catch (error) {
599
+ this.app.logger.warn("[skill-hub] Failed to link skill execution to agent span", error);
600
+ return void 0;
601
+ }
602
+ }
548
603
  async handleDownload(ctx, next) {
549
604
  var _a, _b;
550
605
  const { execId, filename, f } = ctx.action.params;
@@ -589,7 +644,7 @@ class SkillHubSubFeature {
589
644
  if (!skill) {
590
645
  ctx.throw(404, "Skill not found");
591
646
  }
592
- const result = await this.executeSkill(skill, input || {}, ctx);
647
+ const result = await this.executeSkill(skill, input || {}, ctx, { privileged: true });
593
648
  ctx.body = result;
594
649
  await next();
595
650
  }
@@ -720,7 +775,6 @@ class SkillHubSubFeature {
720
775
  );
721
776
  const tools = await Promise.all(
722
777
  skills.map(async (skill) => {
723
- const sanitizedToolName = skill.get("name").toLowerCase().replace(/[^a-z0-9_]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
724
778
  const autoCall = !!skill.get("autoCall");
725
779
  const loopConfig = loopConfigsBySkillId.get(this.getSkillRecordId(skill));
726
780
  const loopInteractionSchema = this.resolveLoopInteractionSchema(loopConfig);
@@ -736,7 +790,7 @@ Language: ${skill.get(
736
790
 
737
791
  IMPORTANT: 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.` : baseDescription;
738
792
  return {
739
- scope: "CUSTOM",
793
+ scope: (0, import_skill_tool_name.normalizeSkillToolScope)(skill.get("toolScope")),
740
794
  execution: "backend",
741
795
  defaultPermission: requiresHumanReview ? "ASK" : autoCall ? "ALLOW" : "ASK",
742
796
  introduction: {
@@ -744,7 +798,7 @@ IMPORTANT: This skill is bound to a Skill Hub human-in-the-loop review template.
744
798
  about: skill.get("description") || `Th\u1EF1c thi k\u1EF9 n\u0103ng ${skill.get("title")}`
745
799
  },
746
800
  definition: {
747
- name: `skill_hub_${sanitizedToolName}`,
801
+ name: (0, import_skill_tool_name.getSkillToolName)(skill),
748
802
  description,
749
803
  schema: (0, import_json_fields.parseJsonText)(skill.get("inputSchema"), { type: "object", properties: {} })
750
804
  },
@@ -0,0 +1,249 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var RegistrySkillInstallationService_exports = {};
28
+ __export(RegistrySkillInstallationService_exports, {
29
+ RegistrySkillInstallationService: () => RegistrySkillInstallationService
30
+ });
31
+ module.exports = __toCommonJS(RegistrySkillInstallationService_exports);
32
+ var import_crypto = require("crypto");
33
+ var import_skill_tool_name = require("../../utils/skill-tool-name");
34
+ function read(model, attribute, fallback = "") {
35
+ const value = model.get(attribute);
36
+ return typeof value === "string" ? value : value === null || value === void 0 ? fallback : String(value);
37
+ }
38
+ function localSkillName(packageIdentity) {
39
+ const normalizedIdentity = packageIdentity.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
40
+ const readablePrefix = normalizedIdentity ? `registry-${normalizedIdentity}` : "registry";
41
+ const suffix = (0, import_crypto.createHash)("sha256").update(packageIdentity).digest("hex").slice(0, 12);
42
+ return `${readablePrefix.slice(0, 87)}-${suffix}`;
43
+ }
44
+ function jsonText(value, fallback) {
45
+ try {
46
+ return JSON.stringify(value ?? fallback);
47
+ } catch {
48
+ return JSON.stringify(fallback);
49
+ }
50
+ }
51
+ function executionWrapper(runtime, entrypoint) {
52
+ const serializedEntrypoint = JSON.stringify(entrypoint);
53
+ if (runtime === "python") {
54
+ return [
55
+ "import os",
56
+ "import runpy",
57
+ `runpy.run_path(os.path.join(os.environ['SKILL_DIR'], ${serializedEntrypoint}), run_name='__main__')`,
58
+ ""
59
+ ].join("\n");
60
+ }
61
+ return `require(require('path').join(process.env.SKILL_DIR, ${serializedEntrypoint}));
62
+ `;
63
+ }
64
+ class RegistrySkillInstallationService {
65
+ constructor(database, getSkillRepository) {
66
+ this.database = database;
67
+ this.getSkillRepository = getSkillRepository;
68
+ }
69
+ async getRegistryInstallationStates(registryVersionIds) {
70
+ if (registryVersionIds.length === 0) return [];
71
+ const installations = await this.database.getRepository("skillRegistryInstallations").find({
72
+ filter: { registryVersionId: { $in: registryVersionIds } },
73
+ sort: ["-installedAt", "-id"]
74
+ });
75
+ return installations.map((installation) => {
76
+ const record = installation;
77
+ const installedAt = installation.get("installedAt");
78
+ return {
79
+ installationId: read(record, "id"),
80
+ registryPackageId: read(record, "registryPackageId"),
81
+ registryVersionId: read(record, "registryVersionId"),
82
+ skillDefinitionId: read(record, "skillDefinitionId"),
83
+ version: read(record, "version"),
84
+ updatePolicy: read(record, "updatePolicy") === "channel" ? "channel" : "pinned",
85
+ status: read(record, "status"),
86
+ installedAt: installedAt instanceof Date ? installedAt.toISOString() : installedAt ? String(installedAt) : null
87
+ };
88
+ });
89
+ }
90
+ async getRollbackTarget(installationId) {
91
+ const installations = this.database.getRepository("skillRegistryInstallations");
92
+ const installation = await installations.findOne({ filterByTk: installationId });
93
+ if (!installation || read(installation, "status") !== "installed") {
94
+ return null;
95
+ }
96
+ const previousInstallationId = read(installation, "previousInstallationId");
97
+ if (!previousInstallationId) {
98
+ return null;
99
+ }
100
+ const previous = await installations.findOne({ filterByTk: previousInstallationId });
101
+ if (!previous) {
102
+ return null;
103
+ }
104
+ const registryVersionId = read(previous, "registryVersionId");
105
+ if (!registryVersionId) {
106
+ return null;
107
+ }
108
+ return {
109
+ registryVersionId,
110
+ updatePolicy: read(previous, "updatePolicy") === "channel" ? "channel" : "pinned"
111
+ };
112
+ }
113
+ async installRegistryVersion(input) {
114
+ const installations = this.database.getRepository("skillRegistryInstallations");
115
+ const existing = await installations.findOne({ filter: { registryVersionId: input.registryVersionId } });
116
+ if (existing && read(existing, "status") === "installed") {
117
+ const skillDefinitionId = read(existing, "skillDefinitionId");
118
+ const skill2 = await this.database.getRepository("skillDefinitions").findOne({ filterByTk: skillDefinitionId });
119
+ if (!skill2) {
120
+ throw new Error("Existing registry installation has no skill definition.");
121
+ }
122
+ return {
123
+ installationId: read(existing, "id"),
124
+ skillDefinitionId,
125
+ toolName: read(skill2, "toolName"),
126
+ status: "installed"
127
+ };
128
+ }
129
+ const previous = await installations.findOne({
130
+ filter: { registryPackageId: input.registryPackageId, status: "installed" },
131
+ sort: ["-installedAt", "-id"]
132
+ });
133
+ const skillDefinitions = this.database.getRepository("skillDefinitions");
134
+ const previousSkillDefinitionId = previous ? read(previous, "skillDefinitionId") : "";
135
+ let skill = previousSkillDefinitionId ? await skillDefinitions.findOne({ filterByTk: previousSkillDefinitionId }) : null;
136
+ const name = skill ? read(skill, "name") : localSkillName(input.packageIdentity);
137
+ if (!input.codeTemplate.trim()) {
138
+ throw new Error("Registry artifact entrypoint is empty.");
139
+ }
140
+ const skillRepository = this.getSkillRepository();
141
+ const previousPackage = skillRepository.readSkillPackageFiles(name);
142
+ const values = {
143
+ title: input.packageIdentity,
144
+ description: `Registry package ${input.packageIdentity}@${input.version}`,
145
+ instructions: input.instructions,
146
+ language: input.runtime,
147
+ codeTemplate: executionWrapper(input.runtime, input.entrypoint),
148
+ inputSchema: jsonText(input.inputSchema, { type: "object", properties: {} }),
149
+ packages: jsonText(input.dependencies, []),
150
+ storageType: "local",
151
+ storageUrl: `local://registry/${name}`,
152
+ enabled: false,
153
+ toolScope: "CUSTOM",
154
+ autoCall: false,
155
+ registryPackageId: input.registryPackageId,
156
+ registryVersionId: input.registryVersionId,
157
+ registryChannel: input.channel,
158
+ sourceDigest: input.artifactDigest,
159
+ sourceSignature: input.sourceSignature,
160
+ registryInstallStatus: "installed",
161
+ registryUpdatePolicy: input.updatePolicy
162
+ };
163
+ if (!skill) {
164
+ const toolName = (0, import_skill_tool_name.buildSkillToolName)(name);
165
+ await (0, import_skill_tool_name.assertSkillToolNameAvailable)(this.database, toolName);
166
+ }
167
+ skillRepository.writeSkillPackage(name, input.files);
168
+ try {
169
+ return await this.database.sequelize.transaction(async (transaction) => {
170
+ if (!skill) {
171
+ const toolName = (0, import_skill_tool_name.buildSkillToolName)(name);
172
+ skill = await skillDefinitions.create({ values: { name, toolName, ...values }, transaction });
173
+ } else {
174
+ await skillDefinitions.update({
175
+ filterByTk: read(skill, "id"),
176
+ values,
177
+ transaction
178
+ });
179
+ skill = await skillDefinitions.findOne({ filterByTk: read(skill, "id"), transaction });
180
+ }
181
+ if (!skill) {
182
+ throw new Error("Failed to materialize the registry skill definition.");
183
+ }
184
+ const installationValues = {
185
+ registryPackageId: input.registryPackageId,
186
+ registryVersionId: input.registryVersionId,
187
+ packageIdentity: input.packageIdentity,
188
+ version: input.version,
189
+ channel: input.channel,
190
+ artifactDigest: input.artifactDigest,
191
+ sourceSignature: input.sourceSignature,
192
+ updatePolicy: input.updatePolicy,
193
+ status: "installed",
194
+ skillDefinitionId: read(skill, "id"),
195
+ previousInstallationId: previous ? read(previous, "id") : null,
196
+ installedAt: /* @__PURE__ */ new Date(),
197
+ installedById: input.installedById || null,
198
+ lastError: null
199
+ };
200
+ let installation = existing;
201
+ if (installation) {
202
+ await installations.update({
203
+ filterByTk: read(installation, "id"),
204
+ values: installationValues,
205
+ transaction
206
+ });
207
+ installation = await installations.findOne({
208
+ filterByTk: read(installation, "id"),
209
+ transaction
210
+ });
211
+ } else {
212
+ installation = await installations.create({ values: installationValues, transaction });
213
+ }
214
+ if (!installation) {
215
+ throw new Error("Failed to persist the registry installation.");
216
+ }
217
+ await skillDefinitions.update({
218
+ filterByTk: read(skill, "id"),
219
+ values: { registryInstallationId: read(installation, "id") },
220
+ transaction
221
+ });
222
+ if (previous) {
223
+ await installations.update({
224
+ filterByTk: read(previous, "id"),
225
+ values: { status: "rolled_back" },
226
+ transaction
227
+ });
228
+ }
229
+ return {
230
+ installationId: read(installation, "id"),
231
+ skillDefinitionId: read(skill, "id"),
232
+ toolName: read(skill, "toolName"),
233
+ status: "installed"
234
+ };
235
+ });
236
+ } catch (error) {
237
+ if (previousPackage) {
238
+ skillRepository.writeSkillPackage(name, previousPackage);
239
+ } else {
240
+ skillRepository.removeSkillPackage(name);
241
+ }
242
+ throw error;
243
+ }
244
+ }
245
+ }
246
+ // Annotate the CommonJS export names for ESM import in node:
247
+ 0 && (module.exports = {
248
+ RegistrySkillInstallationService
249
+ });