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,109 @@
|
|
|
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 SkillAccessService_exports = {};
|
|
28
|
+
__export(SkillAccessService_exports, {
|
|
29
|
+
SkillAccessService: () => SkillAccessService
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(SkillAccessService_exports);
|
|
32
|
+
var import_AgentExecutionContext = require("./AgentExecutionContext");
|
|
33
|
+
var import_ctx_utils = require("../utils/ctx-utils");
|
|
34
|
+
var import_skill_tool_name = require("../utils/skill-tool-name");
|
|
35
|
+
function bindingName(binding) {
|
|
36
|
+
if (typeof binding === "string") return binding.trim();
|
|
37
|
+
return typeof (binding == null ? void 0 : binding.name) === "string" ? binding.name.trim() : "";
|
|
38
|
+
}
|
|
39
|
+
class SkillAccessService {
|
|
40
|
+
constructor(plugin) {
|
|
41
|
+
this.plugin = plugin;
|
|
42
|
+
}
|
|
43
|
+
async resolveAgentUsername(ctx) {
|
|
44
|
+
var _a, _b, _c, _d, _e, _f;
|
|
45
|
+
const executionIdentity = (0, import_AgentExecutionContext.getAgentExecutionContext)();
|
|
46
|
+
if (executionIdentity == null ? void 0 : executionIdentity.employeeUsername) return executionIdentity.employeeUsername;
|
|
47
|
+
const values = (0, import_ctx_utils.valuesFromCtx)(ctx);
|
|
48
|
+
const direct = (0, import_ctx_utils.normalizeEmployeeUsername)(
|
|
49
|
+
(ctx == null ? void 0 : ctx._currentAIEmployee) || ((_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.currentAIEmployee) || ((_c = (_b = ctx == null ? void 0 : ctx.runtime) == null ? void 0 : _b.context) == null ? void 0 : _c.currentAIEmployee) || values.aiEmployee || values.aiEmployeeUsername
|
|
50
|
+
);
|
|
51
|
+
if (direct) return direct;
|
|
52
|
+
const sessionId = (executionIdentity == null ? void 0 : executionIdentity.sessionId) || values.sessionId || ((_e = (_d = ctx == null ? void 0 : ctx.action) == null ? void 0 : _d.params) == null ? void 0 : _e.sessionId) || ((_f = ctx == null ? void 0 : ctx.state) == null ? void 0 : _f.sessionId);
|
|
53
|
+
if (!sessionId) return void 0;
|
|
54
|
+
try {
|
|
55
|
+
const conversation = await this.plugin.db.getRepository("aiConversations").findOne({
|
|
56
|
+
filter: { sessionId }
|
|
57
|
+
});
|
|
58
|
+
return (0, import_ctx_utils.normalizeEmployeeUsername)((0, import_skill_tool_name.readRecordValue)(conversation, "aiEmployeeUsername")) || (0, import_ctx_utils.normalizeEmployeeUsername)((0, import_skill_tool_name.readRecordValue)(conversation, "aiEmployee")) || void 0;
|
|
59
|
+
} catch {
|
|
60
|
+
return void 0;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async canAgentUseSkill(agentUsername, skill) {
|
|
64
|
+
if ((0, import_skill_tool_name.normalizeSkillToolScope)((0, import_skill_tool_name.readRecordValue)(skill, "toolScope")) === "GENERAL") return true;
|
|
65
|
+
const employee = await this.plugin.db.getRepository("aiEmployees").findOne({
|
|
66
|
+
filter: { username: agentUsername }
|
|
67
|
+
});
|
|
68
|
+
if (!employee) return false;
|
|
69
|
+
const skillSettings = (0, import_ctx_utils.asObject)((0, import_skill_tool_name.readRecordValue)(employee, "skillSettings"));
|
|
70
|
+
const tools = Array.isArray(skillSettings.tools) ? skillSettings.tools : [];
|
|
71
|
+
const targetToolName = (0, import_skill_tool_name.getSkillToolName)(skill);
|
|
72
|
+
return tools.some((binding) => bindingName(binding) === targetToolName);
|
|
73
|
+
}
|
|
74
|
+
async assertCanExecute(ctx, skill, options = {}) {
|
|
75
|
+
if (options.privileged) return this.resolveAgentUsername(ctx);
|
|
76
|
+
if ((0, import_ctx_utils.isAdminUser)(ctx)) return this.resolveAgentUsername(ctx);
|
|
77
|
+
const agentUsername = await this.resolveAgentUsername(ctx);
|
|
78
|
+
if (!agentUsername) {
|
|
79
|
+
throw new Error("Skill execution requires an AI employee context.");
|
|
80
|
+
}
|
|
81
|
+
if (!await this.canAgentUseSkill(agentUsername, skill)) {
|
|
82
|
+
throw new Error(`AI employee "${agentUsername}" is not bound to skill tool "${(0, import_skill_tool_name.getSkillToolName)(skill)}".`);
|
|
83
|
+
}
|
|
84
|
+
return agentUsername;
|
|
85
|
+
}
|
|
86
|
+
async filterAccessibleSkills(ctx, skills) {
|
|
87
|
+
if ((0, import_ctx_utils.isAdminUser)(ctx)) return skills;
|
|
88
|
+
const agentUsername = await this.resolveAgentUsername(ctx);
|
|
89
|
+
if (!agentUsername) return [];
|
|
90
|
+
const checks = await Promise.all(skills.map((skill) => this.canAgentUseSkill(agentUsername, skill)));
|
|
91
|
+
return skills.filter((_skill, index) => checks[index]);
|
|
92
|
+
}
|
|
93
|
+
async findAgentUsernamesUsingTool(toolName) {
|
|
94
|
+
const employees = await this.plugin.db.getRepository("aiEmployees").find({});
|
|
95
|
+
const usernames = [];
|
|
96
|
+
for (const employee of employees || []) {
|
|
97
|
+
const settings = (0, import_ctx_utils.asObject)((0, import_skill_tool_name.readRecordValue)(employee, "skillSettings"));
|
|
98
|
+
const tools = Array.isArray(settings.tools) ? settings.tools : [];
|
|
99
|
+
if (!tools.some((binding) => bindingName(binding) === toolName)) continue;
|
|
100
|
+
const username = (0, import_ctx_utils.normalizeEmployeeUsername)((0, import_skill_tool_name.readRecordValue)(employee, "username"));
|
|
101
|
+
if (username) usernames.push(username);
|
|
102
|
+
}
|
|
103
|
+
return usernames;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
SkillAccessService
|
|
109
|
+
});
|
|
@@ -30,6 +30,7 @@ __export(SkillManager_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(SkillManager_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
|
class SkillManager {
|
|
34
35
|
constructor(db) {
|
|
35
36
|
this.db = db;
|
|
@@ -232,6 +233,7 @@ class SkillManager {
|
|
|
232
233
|
await repo.create({
|
|
233
234
|
values: {
|
|
234
235
|
...seed,
|
|
236
|
+
toolName: (0, import_skill_tool_name.buildSkillToolName)(seed.name),
|
|
235
237
|
inputSchema: (0, import_json_fields.stringifyJsonText)(seed.inputSchema),
|
|
236
238
|
packages: (0, import_json_fields.stringifyJsonText)(seed.packages, [])
|
|
237
239
|
}
|
|
@@ -68,6 +68,37 @@ class SkillRepositoryService {
|
|
|
68
68
|
getSkillPath(skillName) {
|
|
69
69
|
return (0, import_path.resolve)(this.baseDir, skillName);
|
|
70
70
|
}
|
|
71
|
+
readSkillPackageFiles(skillName) {
|
|
72
|
+
const targetDir = this.getSkillPath(skillName);
|
|
73
|
+
if (!(0, import_fs.existsSync)(targetDir)) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
const files = [];
|
|
77
|
+
const collect = (directory) => {
|
|
78
|
+
for (const item of (0, import_fs.readdirSync)(directory)) {
|
|
79
|
+
const fullPath = (0, import_path.resolve)(directory, item);
|
|
80
|
+
const stat = (0, import_fs.statSync)(fullPath);
|
|
81
|
+
if (stat.isDirectory()) {
|
|
82
|
+
collect(fullPath);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (!stat.isFile()) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const relativePath = (0, import_path.relative)(targetDir, fullPath).replace(/\\/g, "/");
|
|
89
|
+
files.push({ path: relativePath, content: (0, import_fs.readFileSync)(fullPath) });
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
collect(targetDir);
|
|
93
|
+
return files;
|
|
94
|
+
}
|
|
95
|
+
removeSkillPackage(skillName) {
|
|
96
|
+
const targetDir = this.getSkillPath(skillName);
|
|
97
|
+
if (!targetDir.startsWith(`${this.baseDir}${import_path.sep}`)) {
|
|
98
|
+
throw new Error(`Invalid skill package name: ${skillName}`);
|
|
99
|
+
}
|
|
100
|
+
(0, import_fs.rmSync)(targetDir, { recursive: true, force: true });
|
|
101
|
+
}
|
|
71
102
|
getSkillCode(skillName) {
|
|
72
103
|
const dir = this.getSkillPath(skillName);
|
|
73
104
|
if (!(0, import_fs.existsSync)(dir)) return null;
|
|
@@ -77,6 +108,45 @@ class SkillRepositoryService {
|
|
|
77
108
|
const srcDir = this.getSkillPath(skillName);
|
|
78
109
|
this.copyDirectoryTo(srcDir, destDir);
|
|
79
110
|
}
|
|
111
|
+
writeSkillPackage(skillName, files) {
|
|
112
|
+
const targetDir = this.getSkillPath(skillName);
|
|
113
|
+
const temporaryDir = `${targetDir}.next-${Date.now()}`;
|
|
114
|
+
const backupDir = `${targetDir}.previous-${Date.now()}`;
|
|
115
|
+
const filePaths = /* @__PURE__ */ new Set();
|
|
116
|
+
(0, import_fs.rmSync)(temporaryDir, { recursive: true, force: true });
|
|
117
|
+
(0, import_fs.mkdirSync)(temporaryDir, { recursive: true });
|
|
118
|
+
try {
|
|
119
|
+
for (const file of files) {
|
|
120
|
+
const path = file.path.replace(/\\/g, "/");
|
|
121
|
+
if (!path || path.includes("\0") || path.startsWith("/") || path.split("/").some((part) => !part || part === "." || part === "..") || filePaths.has(path)) {
|
|
122
|
+
throw new Error(`Invalid skill package path: ${file.path}`);
|
|
123
|
+
}
|
|
124
|
+
filePaths.add(path);
|
|
125
|
+
const outputPath = (0, import_path.resolve)(temporaryDir, path);
|
|
126
|
+
if (!outputPath.startsWith(`${temporaryDir}${import_path.sep}`)) {
|
|
127
|
+
throw new Error(`Skill package path is outside its package root: ${file.path}`);
|
|
128
|
+
}
|
|
129
|
+
(0, import_fs.mkdirSync)((0, import_path.dirname)(outputPath), { recursive: true });
|
|
130
|
+
(0, import_fs.writeFileSync)(outputPath, file.content);
|
|
131
|
+
}
|
|
132
|
+
if ((0, import_fs.existsSync)(targetDir)) {
|
|
133
|
+
(0, import_fs.rmSync)(backupDir, { recursive: true, force: true });
|
|
134
|
+
(0, import_fs.renameSync)(targetDir, backupDir);
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
(0, import_fs.renameSync)(temporaryDir, targetDir);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
if ((0, import_fs.existsSync)(backupDir)) {
|
|
140
|
+
(0, import_fs.renameSync)(backupDir, targetDir);
|
|
141
|
+
}
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
(0, import_fs.rmSync)(backupDir, { recursive: true, force: true });
|
|
145
|
+
} catch (error) {
|
|
146
|
+
(0, import_fs.rmSync)(temporaryDir, { recursive: true, force: true });
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
80
150
|
readSkillPackage(packageDir) {
|
|
81
151
|
const rootDir = (0, import_path.resolve)(packageDir);
|
|
82
152
|
if (!(0, import_fs.existsSync)(rootDir)) {
|