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.
- package/dist/externalVersion.js +6 -6
- package/dist/locale/en-US.json +7 -1
- package/dist/locale/vi-VN.json +7 -1
- package/dist/locale/zh-CN.json +7 -1
- 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/20260727010000-backfill-skill-tool-names.js +66 -0
- package/dist/server/plugin.js +96 -1
- package/dist/server/services/AgentExecutionContext.js +45 -0
- 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 +55 -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/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/locale/en-US.json +7 -1
- package/src/locale/vi-VN.json +7 -1
- package/src/locale/zh-CN.json +7 -1
- package/src/server/__tests__/agent-execution-context.test.ts +18 -0
- package/src/server/__tests__/input-schema-validator.test.ts +26 -0
- package/src/server/__tests__/native-sub-agent-observer.test.ts +52 -2
- 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/20260727010000-backfill-skill-tool-names.ts +45 -0
- package/src/server/plugin.ts +104 -1
- package/src/server/services/AgentExecutionContext.ts +23 -0
- 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 +64 -10
- 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/skill-execute.ts +24 -2
- package/src/server/utils/ctx-utils.ts +1 -1
- package/src/server/utils/skill-tool-name.ts +58 -0
|
@@ -0,0 +1,228 @@
|
|
|
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 RegistrySkillSnapshotService_exports = {};
|
|
28
|
+
__export(RegistrySkillSnapshotService_exports, {
|
|
29
|
+
REGISTRY_EXPORT_LIMIT_EXCEEDED: () => REGISTRY_EXPORT_LIMIT_EXCEEDED,
|
|
30
|
+
REGISTRY_EXPORT_NOT_GRANTED: () => REGISTRY_EXPORT_NOT_GRANTED,
|
|
31
|
+
RegistryExportLimitError: () => RegistryExportLimitError,
|
|
32
|
+
RegistryExportNotGrantedError: () => RegistryExportNotGrantedError,
|
|
33
|
+
RegistrySkillSnapshotService: () => RegistrySkillSnapshotService
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(RegistrySkillSnapshotService_exports);
|
|
36
|
+
var import_crypto = require("crypto");
|
|
37
|
+
function positiveLimit(value2, fallback, maximum) {
|
|
38
|
+
const parsed = Number(value2);
|
|
39
|
+
return Number.isSafeInteger(parsed) && parsed > 0 && parsed <= maximum ? parsed : fallback;
|
|
40
|
+
}
|
|
41
|
+
const MAX_REGISTRY_SKILL_SNAPSHOTS = positiveLimit(
|
|
42
|
+
process.env.SKILL_REGISTRY_MAX_SOURCE_ITEMS,
|
|
43
|
+
1e3,
|
|
44
|
+
1e4
|
|
45
|
+
);
|
|
46
|
+
const MAX_REGISTRY_TEXT_BYTES = 10 * 1024 * 1024;
|
|
47
|
+
const registryExportFilter = {
|
|
48
|
+
registryPackageId: null,
|
|
49
|
+
registryVersionId: null,
|
|
50
|
+
registryInstallationId: null,
|
|
51
|
+
registryInstallStatus: null,
|
|
52
|
+
registryExportEnabled: true
|
|
53
|
+
};
|
|
54
|
+
const REGISTRY_EXPORT_NOT_GRANTED = "REGISTRY_EXPORT_NOT_GRANTED";
|
|
55
|
+
const REGISTRY_EXPORT_LIMIT_EXCEEDED = "REGISTRY_EXPORT_LIMIT_EXCEEDED";
|
|
56
|
+
class RegistryExportNotGrantedError extends Error {
|
|
57
|
+
code = REGISTRY_EXPORT_NOT_GRANTED;
|
|
58
|
+
constructor() {
|
|
59
|
+
super("Registry export is not enabled for this Skill Hub definition.");
|
|
60
|
+
this.name = "RegistryExportNotGrantedError";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
class RegistryExportLimitError extends Error {
|
|
64
|
+
code = REGISTRY_EXPORT_LIMIT_EXCEEDED;
|
|
65
|
+
constructor(message) {
|
|
66
|
+
super(message);
|
|
67
|
+
this.name = "RegistryExportLimitError";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function value(model, attribute) {
|
|
71
|
+
return model.get(attribute);
|
|
72
|
+
}
|
|
73
|
+
function text(model, attribute, fallback = "") {
|
|
74
|
+
const raw = value(model, attribute);
|
|
75
|
+
return typeof raw === "string" ? raw : raw === null || raw === void 0 ? fallback : String(raw);
|
|
76
|
+
}
|
|
77
|
+
function parseJson(raw, fallback) {
|
|
78
|
+
if (raw === null || typeof raw === "string" || typeof raw === "boolean") {
|
|
79
|
+
if (typeof raw !== "string") {
|
|
80
|
+
return raw;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
return JSON.parse(raw);
|
|
84
|
+
} catch {
|
|
85
|
+
return fallback;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (typeof raw === "number" && Number.isFinite(raw)) {
|
|
89
|
+
return raw;
|
|
90
|
+
}
|
|
91
|
+
if (Array.isArray(raw) || typeof raw === "object" && raw !== null) {
|
|
92
|
+
return raw;
|
|
93
|
+
}
|
|
94
|
+
return fallback;
|
|
95
|
+
}
|
|
96
|
+
function stableJson(value2) {
|
|
97
|
+
if (value2 === null || typeof value2 === "string" || typeof value2 === "boolean" || typeof value2 === "number") {
|
|
98
|
+
return JSON.stringify(value2);
|
|
99
|
+
}
|
|
100
|
+
if (Array.isArray(value2)) {
|
|
101
|
+
return `[${value2.map(stableJson).join(",")}]`;
|
|
102
|
+
}
|
|
103
|
+
return `{${Object.keys(value2).sort().map((key) => `${JSON.stringify(key)}:${stableJson(value2[key])}`).join(",")}}`;
|
|
104
|
+
}
|
|
105
|
+
function digest(value2) {
|
|
106
|
+
return `sha256:${(0, import_crypto.createHash)("sha256").update(stableJson(value2)).digest("hex")}`;
|
|
107
|
+
}
|
|
108
|
+
function asPortableSnapshot(model) {
|
|
109
|
+
const id = text(model, "id");
|
|
110
|
+
const name = text(model, "name");
|
|
111
|
+
const storageType = text(model, "storageType", "database");
|
|
112
|
+
const codeTemplate = text(model, "codeTemplate");
|
|
113
|
+
const language = text(model, "language", "python") === "node" ? "node" : "python";
|
|
114
|
+
const inputSchema = parseJson(value(model, "inputSchema"), { type: "object", properties: {} });
|
|
115
|
+
const dependencies = parseJson(value(model, "packages"), []);
|
|
116
|
+
const instructions = text(model, "instructions");
|
|
117
|
+
if (Buffer.byteLength(codeTemplate, "utf8") > MAX_REGISTRY_TEXT_BYTES || Buffer.byteLength(instructions, "utf8") > MAX_REGISTRY_TEXT_BYTES) {
|
|
118
|
+
throw new RegistryExportLimitError("Skill Hub definition exceeds the registry source-file limit.");
|
|
119
|
+
}
|
|
120
|
+
const revisionInput = {
|
|
121
|
+
id,
|
|
122
|
+
name,
|
|
123
|
+
storageType,
|
|
124
|
+
codeTemplate,
|
|
125
|
+
language,
|
|
126
|
+
inputSchema,
|
|
127
|
+
dependencies,
|
|
128
|
+
instructions,
|
|
129
|
+
title: text(model, "title"),
|
|
130
|
+
description: text(model, "description")
|
|
131
|
+
};
|
|
132
|
+
if (storageType === "plugin") {
|
|
133
|
+
return {
|
|
134
|
+
id,
|
|
135
|
+
name,
|
|
136
|
+
title: text(model, "title", name),
|
|
137
|
+
description: text(model, "description"),
|
|
138
|
+
language,
|
|
139
|
+
inputSchema,
|
|
140
|
+
instructions,
|
|
141
|
+
files: [],
|
|
142
|
+
portable: false,
|
|
143
|
+
reason: "Plugin-backed skills require an explicit portable export bundle.",
|
|
144
|
+
revision: digest(revisionInput),
|
|
145
|
+
dependencies
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (!codeTemplate.trim()) {
|
|
149
|
+
return {
|
|
150
|
+
id,
|
|
151
|
+
name,
|
|
152
|
+
title: text(model, "title", name),
|
|
153
|
+
description: text(model, "description"),
|
|
154
|
+
language,
|
|
155
|
+
inputSchema,
|
|
156
|
+
instructions,
|
|
157
|
+
files: [],
|
|
158
|
+
portable: false,
|
|
159
|
+
reason: "Skill has no inline code bundle to export.",
|
|
160
|
+
revision: digest(revisionInput),
|
|
161
|
+
dependencies
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const entrypoint = language === "node" ? "src/index.js" : "src/index.py";
|
|
165
|
+
const skillMarkdown = [
|
|
166
|
+
"---",
|
|
167
|
+
`name: ${name}`,
|
|
168
|
+
`title: ${text(model, "title", name)}`,
|
|
169
|
+
`description: ${text(model, "description").replace(/\r?\n/g, " ")}`,
|
|
170
|
+
`language: ${language}`,
|
|
171
|
+
"---",
|
|
172
|
+
"",
|
|
173
|
+
instructions
|
|
174
|
+
].join("\n");
|
|
175
|
+
return {
|
|
176
|
+
id,
|
|
177
|
+
name,
|
|
178
|
+
title: text(model, "title", name),
|
|
179
|
+
description: text(model, "description"),
|
|
180
|
+
language,
|
|
181
|
+
inputSchema,
|
|
182
|
+
instructions,
|
|
183
|
+
files: [
|
|
184
|
+
{ path: "SKILL.md", content: Buffer.from(skillMarkdown, "utf8") },
|
|
185
|
+
{ path: entrypoint, content: Buffer.from(codeTemplate, "utf8") }
|
|
186
|
+
],
|
|
187
|
+
portable: true,
|
|
188
|
+
revision: digest(revisionInput),
|
|
189
|
+
dependencies
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
class RegistrySkillSnapshotService {
|
|
193
|
+
constructor(database) {
|
|
194
|
+
this.database = database;
|
|
195
|
+
}
|
|
196
|
+
async listSkillSnapshots() {
|
|
197
|
+
const definitions = await this.database.getRepository("skillDefinitions").find({
|
|
198
|
+
fields: ["id"],
|
|
199
|
+
filter: registryExportFilter,
|
|
200
|
+
sort: ["id"],
|
|
201
|
+
limit: MAX_REGISTRY_SKILL_SNAPSHOTS + 1
|
|
202
|
+
});
|
|
203
|
+
if (definitions.length > MAX_REGISTRY_SKILL_SNAPSHOTS) {
|
|
204
|
+
throw new RegistryExportLimitError("Skill Hub registry export exceeds the configured source-item limit.");
|
|
205
|
+
}
|
|
206
|
+
return definitions.map((definition) => ({ id: String(definition.get("id")) }));
|
|
207
|
+
}
|
|
208
|
+
async getSkillSnapshot(skillDefinitionId) {
|
|
209
|
+
const definition = await this.database.getRepository("skillDefinitions").findOne({
|
|
210
|
+
filter: {
|
|
211
|
+
id: skillDefinitionId,
|
|
212
|
+
...registryExportFilter
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
if (!definition) {
|
|
216
|
+
throw new RegistryExportNotGrantedError();
|
|
217
|
+
}
|
|
218
|
+
return asPortableSnapshot(definition);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
222
|
+
0 && (module.exports = {
|
|
223
|
+
REGISTRY_EXPORT_LIMIT_EXCEEDED,
|
|
224
|
+
REGISTRY_EXPORT_NOT_GRANTED,
|
|
225
|
+
RegistryExportLimitError,
|
|
226
|
+
RegistryExportNotGrantedError,
|
|
227
|
+
RegistrySkillSnapshotService
|
|
228
|
+
});
|
|
@@ -32,6 +32,8 @@ module.exports = __toCommonJS(SkillExecutionTask_exports);
|
|
|
32
32
|
var import_fs = require("fs");
|
|
33
33
|
var import_path = require("path");
|
|
34
34
|
var import_CodeValidator = require("../../services/CodeValidator");
|
|
35
|
+
var import_crypto = require("crypto");
|
|
36
|
+
var import_skill_tool_name = require("../../utils/skill-tool-name");
|
|
35
37
|
var import_json_fields = require("../utils/json-fields");
|
|
36
38
|
class TaskAbortController {
|
|
37
39
|
listeners = [];
|
|
@@ -162,7 +164,8 @@ class SkillExecutionTask {
|
|
|
162
164
|
skillDir = workDir;
|
|
163
165
|
}
|
|
164
166
|
const code = this.renderTemplate(rawCodeTemplate, inputArgs, execId, skillDir);
|
|
165
|
-
|
|
167
|
+
const skillDigest = (0, import_crypto.createHash)("sha256").update(code, "utf8").digest("hex");
|
|
168
|
+
if (!await this.updateIfOwned(execId, workerId, { executedCode: code, skillDigest })) {
|
|
166
169
|
abortController.abort();
|
|
167
170
|
return;
|
|
168
171
|
}
|
|
@@ -236,6 +239,7 @@ class SkillExecutionTask {
|
|
|
236
239
|
timeoutSeconds: timeoutSeconds || 60,
|
|
237
240
|
maxOutputSizeMb: maxOutputSizeMb || 50,
|
|
238
241
|
skillDir,
|
|
242
|
+
inputArgs,
|
|
239
243
|
signal: abortController.signal,
|
|
240
244
|
packageWhitelist,
|
|
241
245
|
onProgress: (progress) => {
|
|
@@ -325,6 +329,10 @@ class SkillExecutionTask {
|
|
|
325
329
|
}
|
|
326
330
|
code = code.replaceAll("{{outputDir}}", this.fileManager.getOutputDir(execId).replace(/\\/g, "/"));
|
|
327
331
|
code = code.replaceAll("{{skillDir}}", (skillDir || "").replace(/\\/g, "/"));
|
|
332
|
+
code = code.replaceAll(
|
|
333
|
+
"{{inputFile}}",
|
|
334
|
+
(0, import_path.resolve)(this.fileManager.getExecDir(execId), "input.json").replace(/\\/g, "/")
|
|
335
|
+
);
|
|
328
336
|
return code;
|
|
329
337
|
}
|
|
330
338
|
async installGeneratedSkillIfRequested(execId) {
|
|
@@ -370,7 +378,8 @@ class SkillExecutionTask {
|
|
|
370
378
|
execId: verifyExecId,
|
|
371
379
|
timeoutSeconds: Math.min(Number(skill.timeoutSeconds || 60), 30),
|
|
372
380
|
maxOutputSizeMb: Math.min(Number(skill.maxOutputSizeMb || 50), 10),
|
|
373
|
-
skillDir: packageDir
|
|
381
|
+
skillDir: packageDir,
|
|
382
|
+
inputArgs: manifest.testInput
|
|
374
383
|
});
|
|
375
384
|
if (!verifyResult.success) {
|
|
376
385
|
throw new Error(
|
|
@@ -392,6 +401,7 @@ class SkillExecutionTask {
|
|
|
392
401
|
});
|
|
393
402
|
const values = {
|
|
394
403
|
name,
|
|
404
|
+
toolName: (0, import_skill_tool_name.buildSkillToolName)(name),
|
|
395
405
|
title: skill.title || name,
|
|
396
406
|
description: skill.description || "",
|
|
397
407
|
instructions: skill.instructions || "",
|
|
@@ -416,9 +426,11 @@ class SkillExecutionTask {
|
|
|
416
426
|
if (manifest.overwrite === false) {
|
|
417
427
|
throw new Error(`Skill "${name}" already exists and overwrite=false.`);
|
|
418
428
|
}
|
|
419
|
-
|
|
429
|
+
const { toolName: _stableToolName, ...updateValues } = values;
|
|
430
|
+
await repo.update({ filter: { name }, values: updateValues });
|
|
420
431
|
return `[skill-hub] Updated generated skill "${name}" in Skill Hub.`;
|
|
421
432
|
}
|
|
433
|
+
await (0, import_skill_tool_name.assertSkillToolNameAvailable)(this.app.db, values.toolName);
|
|
422
434
|
await repo.create({ values });
|
|
423
435
|
return `[skill-hub] Installed generated skill "${name}" in Skill Hub.`;
|
|
424
436
|
}
|
|
@@ -30,6 +30,7 @@ __export(skill_execute_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(skill_execute_exports);
|
|
32
32
|
var import_json_fields = require("../skill-hub/utils/json-fields");
|
|
33
|
+
var import_skill_tool_name = require("../utils/skill-tool-name");
|
|
33
34
|
function normalizeRuntime(runtime) {
|
|
34
35
|
if (!runtime) return void 0;
|
|
35
36
|
if (typeof runtime === "string") {
|
|
@@ -90,10 +91,22 @@ IMPORTANT: If the skill returns file download URLs, you MUST format them as clic
|
|
|
90
91
|
if (args.action === "list") {
|
|
91
92
|
const skills = await plugin.db.getRepository("skillDefinitions").find({
|
|
92
93
|
filter: { enabled: true },
|
|
93
|
-
fields: [
|
|
94
|
+
fields: [
|
|
95
|
+
"name",
|
|
96
|
+
"toolName",
|
|
97
|
+
"title",
|
|
98
|
+
"description",
|
|
99
|
+
"language",
|
|
100
|
+
"inputSchema",
|
|
101
|
+
"instructions",
|
|
102
|
+
"storageType",
|
|
103
|
+
"toolScope"
|
|
104
|
+
]
|
|
94
105
|
});
|
|
95
|
-
const
|
|
106
|
+
const accessibleSkills = await plugin.skillAccessService.filterAccessibleSkills(ctx, skills);
|
|
107
|
+
const skillList = accessibleSkills.map((s) => ({
|
|
96
108
|
name: s.get("name"),
|
|
109
|
+
toolName: (0, import_skill_tool_name.getSkillToolName)(s),
|
|
97
110
|
title: s.get("title"),
|
|
98
111
|
description: s.get("description"),
|
|
99
112
|
language: s.get("language"),
|
|
@@ -119,11 +132,19 @@ IMPORTANT: If the skill returns file download URLs, you MUST format them as clic
|
|
|
119
132
|
content: `Skill "${args.skillName}" not found or disabled`
|
|
120
133
|
};
|
|
121
134
|
}
|
|
135
|
+
const accessible = await plugin.skillAccessService.filterAccessibleSkills(ctx, [skill]);
|
|
136
|
+
if (accessible.length === 0) {
|
|
137
|
+
return {
|
|
138
|
+
status: "error",
|
|
139
|
+
content: `Skill "${args.skillName}" is not available to this AI employee`
|
|
140
|
+
};
|
|
141
|
+
}
|
|
122
142
|
const instructions = typeof plugin.getSkillInstructions === "function" ? await plugin.getSkillInstructions(skill) : skill.get("instructions");
|
|
123
143
|
return {
|
|
124
144
|
status: "success",
|
|
125
145
|
content: JSON.stringify({
|
|
126
146
|
name: skill.get("name"),
|
|
147
|
+
toolName: (0, import_skill_tool_name.getSkillToolName)(skill),
|
|
127
148
|
title: skill.get("title"),
|
|
128
149
|
description: skill.get("description"),
|
|
129
150
|
language: skill.get("language"),
|
|
@@ -81,8 +81,8 @@ function currentUserId(ctx) {
|
|
|
81
81
|
return ((_b = (_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id) || ((_d = (_c = ctx == null ? void 0 : ctx.auth) == null ? void 0 : _c.user) == null ? void 0 : _d.id);
|
|
82
82
|
}
|
|
83
83
|
function isAdminUser(ctx) {
|
|
84
|
-
var _a, _b, _c, _d;
|
|
85
|
-
const roles = ((_b = (_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.roles) || ((_d = (_c = ctx == null ? void 0 : ctx.auth) == null ? void 0 : _c.user) == null ? void 0 : _d.roles);
|
|
84
|
+
var _a, _b, _c, _d, _e;
|
|
85
|
+
const roles = ((_b = (_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.roles) || ((_d = (_c = ctx == null ? void 0 : ctx.auth) == null ? void 0 : _c.user) == null ? void 0 : _d.roles) || ((_e = ctx == null ? void 0 : ctx.state) == null ? void 0 : _e.currentRoles);
|
|
86
86
|
if (!Array.isArray(roles)) return false;
|
|
87
87
|
return roles.some((r) => {
|
|
88
88
|
const name = typeof r === "string" ? r : r == null ? void 0 : r.name;
|
|
@@ -0,0 +1,73 @@
|
|
|
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 skill_tool_name_exports = {};
|
|
28
|
+
__export(skill_tool_name_exports, {
|
|
29
|
+
assertSkillToolNameAvailable: () => assertSkillToolNameAvailable,
|
|
30
|
+
buildSkillToolName: () => buildSkillToolName,
|
|
31
|
+
getSkillToolName: () => getSkillToolName,
|
|
32
|
+
normalizeSkillToolScope: () => normalizeSkillToolScope,
|
|
33
|
+
readRecordValue: () => readRecordValue
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(skill_tool_name_exports);
|
|
36
|
+
function readRecordValue(record, key) {
|
|
37
|
+
const value = record;
|
|
38
|
+
return typeof (value == null ? void 0 : value.get) === "function" ? value.get(key) : value == null ? void 0 : value[key];
|
|
39
|
+
}
|
|
40
|
+
function buildSkillToolName(skillName) {
|
|
41
|
+
const normalized = String(skillName || "").trim().toLowerCase().replace(/[^a-z0-9_]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
|
|
42
|
+
if (!normalized) {
|
|
43
|
+
throw new Error("Skill name must contain at least one ASCII letter or number.");
|
|
44
|
+
}
|
|
45
|
+
return `skill_hub_${normalized}`;
|
|
46
|
+
}
|
|
47
|
+
function getSkillToolName(skill) {
|
|
48
|
+
const persisted = readRecordValue(skill, "toolName");
|
|
49
|
+
if (typeof persisted === "string" && persisted.trim()) {
|
|
50
|
+
return persisted.trim();
|
|
51
|
+
}
|
|
52
|
+
return buildSkillToolName(String(readRecordValue(skill, "name") || ""));
|
|
53
|
+
}
|
|
54
|
+
function normalizeSkillToolScope(value) {
|
|
55
|
+
return value === "GENERAL" || value === "SPECIFIED" || value === "CUSTOM" ? value : "CUSTOM";
|
|
56
|
+
}
|
|
57
|
+
async function assertSkillToolNameAvailable(db, toolName, excludeId) {
|
|
58
|
+
const existing = await db.getRepository("skillDefinitions").findOne({
|
|
59
|
+
filter: { toolName }
|
|
60
|
+
});
|
|
61
|
+
if (!existing) return;
|
|
62
|
+
const existingId = readRecordValue(existing, "id");
|
|
63
|
+
if (excludeId != null && String(existingId) === String(excludeId)) return;
|
|
64
|
+
throw new Error(`Skill tool name "${toolName}" is already registered.`);
|
|
65
|
+
}
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
assertSkillToolNameAvailable,
|
|
69
|
+
buildSkillToolName,
|
|
70
|
+
getSkillToolName,
|
|
71
|
+
normalizeSkillToolScope,
|
|
72
|
+
readRecordValue
|
|
73
|
+
});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "代理协调器",
|
|
5
5
|
"displayName.vi-VN": "Điều phối Agent",
|
|
6
6
|
"description": "Native AI Employee sub-agent monitoring, policy, and memory context layer for NocoBase plugin-ai.",
|
|
7
|
-
"version": "1.1.
|
|
7
|
+
"version": "1.1.2",
|
|
8
8
|
"license": "Apache-2.0",
|
|
9
9
|
"main": "dist/server/index.js",
|
|
10
10
|
"keywords": [
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"adm-zip": "^0.5.10",
|
|
35
|
-
"
|
|
35
|
+
"ajv": "^6.12.6",
|
|
36
36
|
"zod": "^3.23.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
@@ -42,6 +42,12 @@
|
|
|
42
42
|
"@nocobase/ai": "2.x",
|
|
43
43
|
"@nocobase/plugin-ai": "2.x",
|
|
44
44
|
"@nocobase/client-v2": "2.x",
|
|
45
|
-
"@nocobase/flow-engine": "2.x"
|
|
45
|
+
"@nocobase/flow-engine": "2.x",
|
|
46
|
+
"plugin-git-manager": "^2.0.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"plugin-git-manager": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
46
52
|
}
|
|
47
53
|
}
|
package/src/locale/en-US.json
CHANGED
|
@@ -140,5 +140,11 @@
|
|
|
140
140
|
"Character budget": "Character budget",
|
|
141
141
|
"Applied scopes": "Applied scopes",
|
|
142
142
|
"None": "None",
|
|
143
|
-
"No memory context matched this preview.": "No memory context matched this preview."
|
|
143
|
+
"No memory context matched this preview.": "No memory context matched this preview.",
|
|
144
|
+
"This Skill Hub Git import action does not allow the request method.": "This Skill Hub Git import action does not allow the request method.",
|
|
145
|
+
"skills[] must contain non-empty string keys": "skills[] must contain non-empty string keys",
|
|
146
|
+
"Selected skills are not listed in the explicit skills.json manifest: {{skills}}": "Selected skills are not listed in the explicit skills.json manifest: {{skills}}",
|
|
147
|
+
"Git skill contains more than {{count}} supplemental Markdown files.": "Git skill contains more than {{count}} supplemental Markdown files.",
|
|
148
|
+
"Git skill contains a supplemental Markdown file with an invalid size.": "Git skill contains a supplemental Markdown file with an invalid size.",
|
|
149
|
+
"Git skill supplemental Markdown exceeds {{maxBytes}} bytes.": "Git skill supplemental Markdown exceeds {{maxBytes}} bytes."
|
|
144
150
|
}
|
package/src/locale/vi-VN.json
CHANGED
|
@@ -140,5 +140,11 @@
|
|
|
140
140
|
"Character budget": "Ngân sách ký tự",
|
|
141
141
|
"Applied scopes": "Phạm vi đã áp dụng",
|
|
142
142
|
"None": "Không có",
|
|
143
|
-
"No memory context matched this preview.": "Không có context bộ nhớ phù hợp với bản xem trước này."
|
|
143
|
+
"No memory context matched this preview.": "Không có context bộ nhớ phù hợp với bản xem trước này.",
|
|
144
|
+
"This Skill Hub Git import action does not allow the request method.": "Thao tác nhập Git của Skill Hub không cho phép phương thức yêu cầu này.",
|
|
145
|
+
"skills[] must contain non-empty string keys": "skills[] chỉ được chứa các khóa chuỗi không rỗng.",
|
|
146
|
+
"Selected skills are not listed in the explicit skills.json manifest: {{skills}}": "Các skill được chọn không có trong manifest skills.json tường minh: {{skills}}",
|
|
147
|
+
"Git skill contains more than {{count}} supplemental Markdown files.": "Skill Git chứa hơn {{count}} tệp Markdown bổ sung.",
|
|
148
|
+
"Git skill contains a supplemental Markdown file with an invalid size.": "Skill Git có một tệp Markdown bổ sung với kích thước không hợp lệ.",
|
|
149
|
+
"Git skill supplemental Markdown exceeds {{maxBytes}} bytes.": "Markdown bổ sung của skill Git vượt quá {{maxBytes}} byte."
|
|
144
150
|
}
|
package/src/locale/zh-CN.json
CHANGED
|
@@ -140,5 +140,11 @@
|
|
|
140
140
|
"Character budget": "字符预算",
|
|
141
141
|
"Applied scopes": "已应用范围",
|
|
142
142
|
"None": "无",
|
|
143
|
-
"No memory context matched this preview.": "没有匹配此预览的记忆上下文。"
|
|
143
|
+
"No memory context matched this preview.": "没有匹配此预览的记忆上下文。",
|
|
144
|
+
"This Skill Hub Git import action does not allow the request method.": "此 Skill Hub Git 导入操作不允许该请求方法。",
|
|
145
|
+
"skills[] must contain non-empty string keys": "skills[] 必须只包含非空字符串键。",
|
|
146
|
+
"Selected skills are not listed in the explicit skills.json manifest: {{skills}}": "所选技能不在显式 skills.json 清单中:{{skills}}",
|
|
147
|
+
"Git skill contains more than {{count}} supplemental Markdown files.": "Git 技能包含超过 {{count}} 个补充 Markdown 文件。",
|
|
148
|
+
"Git skill contains a supplemental Markdown file with an invalid size.": "Git 技能包含大小无效的补充 Markdown 文件。",
|
|
149
|
+
"Git skill supplemental Markdown exceeds {{maxBytes}} bytes.": "Git 技能的补充 Markdown 超过 {{maxBytes}} 字节。"
|
|
144
150
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { getAgentExecutionContext, runWithAgentExecutionContext } from '../services/AgentExecutionContext';
|
|
3
|
+
|
|
4
|
+
describe('AgentExecutionContext', () => {
|
|
5
|
+
it('keeps concurrent agent identities isolated across async work', async () => {
|
|
6
|
+
const readIdentity = (employeeUsername: string, delay: number) =>
|
|
7
|
+
runWithAgentExecutionContext({ employeeUsername }, async () => {
|
|
8
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
9
|
+
return getAgentExecutionContext()?.employeeUsername;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
await expect(Promise.all([readIdentity('ocr-agent', 5), readIdentity('report-agent', 1)])).resolves.toEqual([
|
|
13
|
+
'ocr-agent',
|
|
14
|
+
'report-agent',
|
|
15
|
+
]);
|
|
16
|
+
expect(getAgentExecutionContext()).toBeUndefined();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { validateInputSchemaDefinition, validateSkillInput } from '../services/InputSchemaValidator';
|
|
3
|
+
|
|
4
|
+
const schema = {
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
title: { type: 'string' },
|
|
8
|
+
count: { type: 'integer', minimum: 1 },
|
|
9
|
+
},
|
|
10
|
+
required: ['title'],
|
|
11
|
+
additionalProperties: false,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
describe('InputSchemaValidator', () => {
|
|
15
|
+
it('accepts valid input', () => {
|
|
16
|
+
expect(() => validateSkillInput(schema, { title: 'Report', count: 2 })).not.toThrow();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('rejects missing, mistyped, and unknown input fields', () => {
|
|
20
|
+
expect(() => validateSkillInput(schema, { count: 0, unexpected: true })).toThrow('Skill input validation failed');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('rejects malformed schema definitions before execution', () => {
|
|
24
|
+
expect(() => validateInputSchemaDefinition('{invalid json')).toThrow('valid JSON Schema object');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import { AgentMemoryContextService } from '../services/AgentMemoryContextService';
|
|
3
3
|
import { NativeSubAgentObserver } from '../services/NativeSubAgentObserver';
|
|
4
|
+
import { getAgentExecutionContext } from '../services/AgentExecutionContext';
|
|
4
5
|
|
|
5
6
|
function createObserverHarness(
|
|
6
7
|
profileSettings: Record<string, unknown> | null = {},
|
|
@@ -8,14 +9,22 @@ function createObserverHarness(
|
|
|
8
9
|
memoryRows?: unknown[];
|
|
9
10
|
orchestratorConfig?: unknown;
|
|
10
11
|
knowledgeBasePlugin?: unknown;
|
|
12
|
+
toolCallResult?: unknown;
|
|
11
13
|
} = {},
|
|
12
14
|
) {
|
|
13
15
|
let nextSpanId = 1;
|
|
16
|
+
let observedIdentity: string | undefined;
|
|
17
|
+
let observedSkillSettings: unknown;
|
|
14
18
|
const spanRepo = {
|
|
15
19
|
create: vi.fn(async ({ values }) => ({ id: nextSpanId++, ...values })),
|
|
16
20
|
update: vi.fn(async () => ({})),
|
|
17
21
|
};
|
|
22
|
+
const skillExecutionRepo = {
|
|
23
|
+
update: vi.fn(async () => ({})),
|
|
24
|
+
};
|
|
18
25
|
const originalRun = vi.fn(async (task) => {
|
|
26
|
+
observedIdentity = getAgentExecutionContext()?.employeeUsername;
|
|
27
|
+
observedSkillSettings = task.skillSettings;
|
|
19
28
|
task.writer?.({
|
|
20
29
|
action: 'beforeToolCall',
|
|
21
30
|
body: {
|
|
@@ -40,7 +49,7 @@ function createObserverHarness(
|
|
|
40
49
|
name: 'skill_hub_execute',
|
|
41
50
|
messageId: 'msg-1',
|
|
42
51
|
},
|
|
43
|
-
toolCallResult: {
|
|
52
|
+
toolCallResult: options.toolCallResult ?? {
|
|
44
53
|
status: 'success',
|
|
45
54
|
content: { ok: true },
|
|
46
55
|
},
|
|
@@ -56,6 +65,7 @@ function createObserverHarness(
|
|
|
56
65
|
const dispatcher = { run: originalRun };
|
|
57
66
|
const repos: Record<string, unknown> = {
|
|
58
67
|
agentExecutionSpans: spanRepo,
|
|
68
|
+
skillExecutions: skillExecutionRepo,
|
|
59
69
|
agentHarnessProfiles: {
|
|
60
70
|
findOne: vi.fn(async () => (profileSettings ? { settings: profileSettings } : null)),
|
|
61
71
|
},
|
|
@@ -101,7 +111,15 @@ function createObserverHarness(
|
|
|
101
111
|
},
|
|
102
112
|
};
|
|
103
113
|
|
|
104
|
-
return {
|
|
114
|
+
return {
|
|
115
|
+
plugin,
|
|
116
|
+
dispatcher,
|
|
117
|
+
originalRun,
|
|
118
|
+
spanRepo,
|
|
119
|
+
skillExecutionRepo,
|
|
120
|
+
repos,
|
|
121
|
+
getObserved: () => ({ observedIdentity, observedSkillSettings }),
|
|
122
|
+
};
|
|
105
123
|
}
|
|
106
124
|
|
|
107
125
|
function createTask(getRepository?: (name: string) => unknown) {
|
|
@@ -123,6 +141,7 @@ function createTask(getRepository?: (name: string) => unknown) {
|
|
|
123
141
|
},
|
|
124
142
|
sessionId: 'sub-session',
|
|
125
143
|
employee: { username: 'sub-agent' },
|
|
144
|
+
skillSettings: { tools: [{ name: 'skill_hub_leader_only' }] },
|
|
126
145
|
question: 'do the work',
|
|
127
146
|
};
|
|
128
147
|
}
|
|
@@ -143,6 +162,37 @@ describe('NativeSubAgentObserver', () => {
|
|
|
143
162
|
expect(spanRepo.update).toHaveBeenCalled();
|
|
144
163
|
});
|
|
145
164
|
|
|
165
|
+
it('uses the sub-agent employee bindings instead of inheriting the leader tool filter', async () => {
|
|
166
|
+
const { plugin, dispatcher, getObserved } = createObserverHarness();
|
|
167
|
+
const observer = new NativeSubAgentObserver(plugin);
|
|
168
|
+
observer.install();
|
|
169
|
+
|
|
170
|
+
await dispatcher.run(createTask());
|
|
171
|
+
|
|
172
|
+
expect(getObserved()).toEqual({ observedIdentity: 'sub-agent', observedSkillSettings: undefined });
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('links a completed Skill Hub execution to its native tool span', async () => {
|
|
176
|
+
const { plugin, dispatcher, skillExecutionRepo } = createObserverHarness(
|
|
177
|
+
{},
|
|
178
|
+
{
|
|
179
|
+
toolCallResult: {
|
|
180
|
+
status: 'success',
|
|
181
|
+
content: JSON.stringify({ execId: 'execution-41' }),
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
);
|
|
185
|
+
const observer = new NativeSubAgentObserver(plugin);
|
|
186
|
+
observer.install();
|
|
187
|
+
|
|
188
|
+
await dispatcher.run(createTask());
|
|
189
|
+
|
|
190
|
+
expect(skillExecutionRepo.update).toHaveBeenCalledWith({
|
|
191
|
+
filterByTk: 'execution-41',
|
|
192
|
+
values: { orchestratorSpanId: 2 },
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
146
196
|
it('restores the native dispatcher when uninstalled', async () => {
|
|
147
197
|
const { plugin, dispatcher, originalRun } = createObserverHarness();
|
|
148
198
|
const observer = new NativeSubAgentObserver(plugin);
|