plugin-agent-orchestrator 1.0.38 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.js +1 -1
- package/dist/client-v2/253.9f0537713cee9e6c.js +10 -0
- package/dist/client-v2/418.ce8f5b2b8a229d1d.js +10 -0
- package/dist/client-v2/53.7c29c28043e9112d.js +10 -0
- package/dist/client-v2/794.9bbb8d3a61b2bdf2.js +10 -0
- package/dist/client-v2/993.82778b6fd6db3cb1.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +6 -6
- package/dist/locale/en-US.json +56 -2
- package/dist/locale/vi-VN.json +56 -2
- package/dist/locale/zh-CN.json +56 -2
- package/dist/node_modules/ajv/.tonic_example.js +20 -0
- package/dist/node_modules/ajv/LICENSE +22 -0
- package/dist/node_modules/ajv/dist/ajv.bundle.js +7189 -0
- package/dist/node_modules/ajv/dist/ajv.min.js +3 -0
- package/dist/node_modules/ajv/lib/ajv.d.ts +397 -0
- package/dist/node_modules/ajv/lib/ajv.js +3 -0
- package/dist/node_modules/ajv/lib/cache.js +26 -0
- package/dist/node_modules/ajv/lib/compile/async.js +90 -0
- package/dist/node_modules/ajv/lib/compile/equal.js +5 -0
- package/dist/node_modules/ajv/lib/compile/error_classes.js +34 -0
- package/dist/node_modules/ajv/lib/compile/formats.js +142 -0
- package/dist/node_modules/ajv/lib/compile/index.js +387 -0
- package/dist/node_modules/ajv/lib/compile/resolve.js +270 -0
- package/dist/node_modules/ajv/lib/compile/rules.js +66 -0
- package/dist/node_modules/ajv/lib/compile/schema_obj.js +9 -0
- package/dist/node_modules/ajv/lib/compile/ucs2length.js +20 -0
- package/dist/node_modules/ajv/lib/compile/util.js +239 -0
- package/dist/node_modules/ajv/lib/data.js +49 -0
- package/dist/node_modules/ajv/lib/definition_schema.js +37 -0
- package/dist/node_modules/ajv/lib/dot/_limit.jst +113 -0
- package/dist/node_modules/ajv/lib/dot/_limitItems.jst +12 -0
- package/dist/node_modules/ajv/lib/dot/_limitLength.jst +12 -0
- package/dist/node_modules/ajv/lib/dot/_limitProperties.jst +12 -0
- package/dist/node_modules/ajv/lib/dot/allOf.jst +32 -0
- package/dist/node_modules/ajv/lib/dot/anyOf.jst +46 -0
- package/dist/node_modules/ajv/lib/dot/coerce.def +51 -0
- package/dist/node_modules/ajv/lib/dot/comment.jst +9 -0
- package/dist/node_modules/ajv/lib/dot/const.jst +11 -0
- package/dist/node_modules/ajv/lib/dot/contains.jst +55 -0
- package/dist/node_modules/ajv/lib/dot/custom.jst +191 -0
- package/dist/node_modules/ajv/lib/dot/defaults.def +47 -0
- package/dist/node_modules/ajv/lib/dot/definitions.def +203 -0
- package/dist/node_modules/ajv/lib/dot/dependencies.jst +79 -0
- package/dist/node_modules/ajv/lib/dot/enum.jst +30 -0
- package/dist/node_modules/ajv/lib/dot/errors.def +194 -0
- package/dist/node_modules/ajv/lib/dot/format.jst +106 -0
- package/dist/node_modules/ajv/lib/dot/if.jst +73 -0
- package/dist/node_modules/ajv/lib/dot/items.jst +98 -0
- package/dist/node_modules/ajv/lib/dot/missing.def +39 -0
- package/dist/node_modules/ajv/lib/dot/multipleOf.jst +22 -0
- package/dist/node_modules/ajv/lib/dot/not.jst +43 -0
- package/dist/node_modules/ajv/lib/dot/oneOf.jst +54 -0
- package/dist/node_modules/ajv/lib/dot/pattern.jst +14 -0
- package/dist/node_modules/ajv/lib/dot/properties.jst +245 -0
- package/dist/node_modules/ajv/lib/dot/propertyNames.jst +52 -0
- package/dist/node_modules/ajv/lib/dot/ref.jst +85 -0
- package/dist/node_modules/ajv/lib/dot/required.jst +108 -0
- package/dist/node_modules/ajv/lib/dot/uniqueItems.jst +62 -0
- package/dist/node_modules/ajv/lib/dot/validate.jst +276 -0
- package/dist/node_modules/ajv/lib/dotjs/_limit.js +163 -0
- package/dist/node_modules/ajv/lib/dotjs/_limitItems.js +80 -0
- package/dist/node_modules/ajv/lib/dotjs/_limitLength.js +85 -0
- package/dist/node_modules/ajv/lib/dotjs/_limitProperties.js +80 -0
- package/dist/node_modules/ajv/lib/dotjs/allOf.js +42 -0
- package/dist/node_modules/ajv/lib/dotjs/anyOf.js +73 -0
- package/dist/node_modules/ajv/lib/dotjs/comment.js +14 -0
- package/dist/node_modules/ajv/lib/dotjs/const.js +56 -0
- package/dist/node_modules/ajv/lib/dotjs/contains.js +81 -0
- package/dist/node_modules/ajv/lib/dotjs/custom.js +228 -0
- package/dist/node_modules/ajv/lib/dotjs/dependencies.js +168 -0
- package/dist/node_modules/ajv/lib/dotjs/enum.js +66 -0
- package/dist/node_modules/ajv/lib/dotjs/format.js +150 -0
- package/dist/node_modules/ajv/lib/dotjs/if.js +103 -0
- package/dist/node_modules/ajv/lib/dotjs/index.js +33 -0
- package/dist/node_modules/ajv/lib/dotjs/items.js +140 -0
- package/dist/node_modules/ajv/lib/dotjs/multipleOf.js +80 -0
- package/dist/node_modules/ajv/lib/dotjs/not.js +84 -0
- package/dist/node_modules/ajv/lib/dotjs/oneOf.js +73 -0
- package/dist/node_modules/ajv/lib/dotjs/pattern.js +75 -0
- package/dist/node_modules/ajv/lib/dotjs/properties.js +335 -0
- package/dist/node_modules/ajv/lib/dotjs/propertyNames.js +81 -0
- package/dist/node_modules/ajv/lib/dotjs/ref.js +124 -0
- package/dist/node_modules/ajv/lib/dotjs/required.js +270 -0
- package/dist/node_modules/ajv/lib/dotjs/uniqueItems.js +86 -0
- package/dist/node_modules/ajv/lib/dotjs/validate.js +482 -0
- package/dist/node_modules/ajv/lib/keyword.js +146 -0
- package/dist/node_modules/ajv/lib/refs/data.json +17 -0
- package/dist/node_modules/ajv/lib/refs/json-schema-draft-04.json +149 -0
- package/dist/node_modules/ajv/lib/refs/json-schema-draft-06.json +154 -0
- package/dist/node_modules/ajv/lib/refs/json-schema-draft-07.json +168 -0
- package/dist/node_modules/ajv/lib/refs/json-schema-secure.json +94 -0
- package/dist/node_modules/ajv/node_modules/json-schema-traverse/.eslintrc.yml +27 -0
- package/dist/node_modules/ajv/node_modules/json-schema-traverse/.travis.yml +8 -0
- package/dist/node_modules/ajv/node_modules/json-schema-traverse/index.js +89 -0
- package/dist/node_modules/ajv/node_modules/json-schema-traverse/package.json +43 -0
- package/dist/node_modules/ajv/node_modules/json-schema-traverse/spec/.eslintrc.yml +6 -0
- package/dist/node_modules/ajv/node_modules/json-schema-traverse/spec/fixtures/schema.js +125 -0
- package/dist/node_modules/ajv/node_modules/json-schema-traverse/spec/index.spec.js +171 -0
- package/dist/node_modules/ajv/package.json +1 -0
- package/dist/node_modules/ajv/scripts/.eslintrc.yml +3 -0
- package/dist/node_modules/ajv/scripts/bundle.js +61 -0
- package/dist/node_modules/ajv/scripts/compile-dots.js +73 -0
- package/dist/node_modules/ajv/scripts/info +10 -0
- package/dist/node_modules/ajv/scripts/prepare-tests +12 -0
- package/dist/node_modules/ajv/scripts/publish-built-version +32 -0
- package/dist/node_modules/ajv/scripts/travis-gh-pages +23 -0
- package/dist/server/collections/skill-definitions.js +31 -0
- package/dist/server/collections/skill-executions.js +19 -0
- package/dist/server/collections/skill-registry-installations.js +70 -0
- package/dist/server/migrations/20260621000000-native-policy-profile-defaults.js +0 -3
- package/dist/server/migrations/20260727000000-remove-unused-knowledge-scopes.js +51 -0
- package/dist/server/migrations/20260727010000-backfill-skill-tool-names.js +66 -0
- package/dist/server/plugin.js +107 -2
- package/dist/server/resources/agent-knowledge-insights.js +273 -0
- package/dist/server/services/AgentExecutionContext.js +45 -0
- package/dist/server/services/AgentMemoryContextService.js +57 -19
- package/dist/server/services/CodeValidator.js +1 -0
- package/dist/server/services/ExecutionSpanService.js +10 -2
- package/dist/server/services/InputSchemaValidator.js +83 -0
- package/dist/server/services/NativeSubAgentObserver.js +63 -8
- package/dist/server/services/SandboxRunner.js +6 -2
- package/dist/server/services/SkillAccessService.js +109 -0
- package/dist/server/services/SkillManager.js +2 -0
- package/dist/server/services/SkillRepositoryService.js +70 -0
- package/dist/server/skill-hub/actions/git-import.js +479 -216
- package/dist/server/skill-hub/mcp/McpController.js +8 -5
- package/dist/server/skill-hub/middlewares/git-import-request-method-policy.js +69 -0
- package/dist/server/skill-hub/plugin.js +68 -14
- package/dist/server/skill-hub/services/RegistrySkillInstallationService.js +249 -0
- package/dist/server/skill-hub/services/RegistrySkillSnapshotService.js +228 -0
- package/dist/server/skill-hub/tasks/SkillExecutionTask.js +15 -3
- package/dist/server/tools/external-rag-search.js +152 -12
- package/dist/server/tools/skill-execute.js +23 -2
- package/dist/server/utils/ctx-utils.js +2 -2
- package/dist/server/utils/skill-tool-name.js +73 -0
- package/package.json +9 -3
- package/src/client-v2/components/AgentBindingsTab.tsx +269 -0
- package/src/client-v2/components/HarnessProfilesTab.tsx +1 -2
- package/src/client-v2/components/KnowledgeAccessTab.tsx +116 -0
- package/src/client-v2/components/MemoryInspectorTab.tsx +125 -0
- package/src/client-v2/components/RetrievalTraceTab.tsx +162 -0
- package/src/client-v2/pages/AgentBindingsPage.tsx +13 -0
- package/src/client-v2/pages/KnowledgeAccessPage.tsx +10 -0
- package/src/client-v2/pages/MemoryInspectorPage.tsx +13 -0
- package/src/client-v2/pages/RetrievalTracePage.tsx +10 -0
- package/src/client-v2/plugin.tsx +28 -0
- package/src/locale/en-US.json +56 -2
- package/src/locale/vi-VN.json +56 -2
- package/src/locale/zh-CN.json +56 -2
- package/src/server/__tests__/agent-execution-context.test.ts +18 -0
- package/src/server/__tests__/agent-knowledge-insights.test.ts +123 -0
- package/src/server/__tests__/external-rag-search.test.ts +107 -0
- package/src/server/__tests__/input-schema-validator.test.ts +26 -0
- package/src/server/__tests__/native-sub-agent-observer.test.ts +141 -9
- package/src/server/__tests__/skill-access-service.test.ts +64 -0
- package/src/server/__tests__/skill-execute.test.ts +37 -0
- package/src/server/__tests__/skill-tool-name.test.ts +23 -0
- package/src/server/collections/skill-definitions.ts +31 -0
- package/src/server/collections/skill-executions.ts +19 -0
- package/src/server/collections/skill-registry-installations.ts +41 -0
- package/src/server/migrations/20260621000000-native-policy-profile-defaults.ts +0 -3
- package/src/server/migrations/20260727000000-remove-unused-knowledge-scopes.ts +25 -0
- package/src/server/migrations/20260727010000-backfill-skill-tool-names.ts +45 -0
- package/src/server/plugin.ts +107 -1
- package/src/server/resources/agent-knowledge-insights.ts +304 -0
- package/src/server/services/AgentExecutionContext.ts +23 -0
- package/src/server/services/AgentMemoryContextService.ts +63 -19
- package/src/server/services/CodeValidator.ts +1 -0
- package/src/server/services/ExecutionSpanService.ts +119 -110
- package/src/server/services/InputSchemaValidator.ts +44 -0
- package/src/server/services/NativeSubAgentObserver.ts +592 -528
- package/src/server/services/SandboxRunner.ts +6 -0
- package/src/server/services/SkillAccessService.ts +100 -0
- package/src/server/services/SkillManager.ts +2 -0
- package/src/server/services/SkillRepositoryService.ts +98 -2
- package/src/server/services/__tests__/SkillRepositoryService.test.ts +33 -0
- package/src/server/skill-hub/actions/__tests__/git-import.test.ts +501 -0
- package/src/server/skill-hub/actions/git-import.ts +682 -236
- package/src/server/skill-hub/mcp/McpController.ts +8 -14
- package/src/server/skill-hub/middlewares/git-import-request-method-policy.ts +51 -0
- package/src/server/skill-hub/plugin.ts +79 -13
- package/src/server/skill-hub/services/RegistrySkillInstallationService.ts +281 -0
- package/src/server/skill-hub/services/RegistrySkillSnapshotService.ts +239 -0
- package/src/server/skill-hub/services/__tests__/RegistrySkillInstallationService.test.ts +295 -0
- package/src/server/skill-hub/services/__tests__/RegistrySkillSnapshotService.test.ts +63 -0
- package/src/server/skill-hub/tasks/SkillExecutionTask.ts +14 -2
- package/src/server/tools/external-rag-search.ts +215 -14
- package/src/server/tools/skill-execute.ts +24 -2
- package/src/server/utils/ctx-utils.ts +1 -1
- package/src/server/utils/skill-tool-name.ts +58 -0
- package/dist/client-v2/418.29e713f79131eece.js +0 -10
|
@@ -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
|
}
|
|
@@ -32,6 +32,28 @@ module.exports = __toCommonJS(external_rag_search_exports);
|
|
|
32
32
|
var import_zod = require("zod");
|
|
33
33
|
const TOOL_NAME = "external_rag_search";
|
|
34
34
|
const MAX_CONTENT_LENGTH = 4e3;
|
|
35
|
+
const MAX_METADATA_VALUE_LENGTH = 500;
|
|
36
|
+
const METADATA_FIELDS = [
|
|
37
|
+
"id",
|
|
38
|
+
"title",
|
|
39
|
+
"filename",
|
|
40
|
+
"fileName",
|
|
41
|
+
"name",
|
|
42
|
+
"source",
|
|
43
|
+
"url",
|
|
44
|
+
"fileUrl",
|
|
45
|
+
"sourceUrl",
|
|
46
|
+
"collection",
|
|
47
|
+
"collectionName",
|
|
48
|
+
"recordId",
|
|
49
|
+
"rowId",
|
|
50
|
+
"documentId",
|
|
51
|
+
"docId",
|
|
52
|
+
"fileId",
|
|
53
|
+
"page",
|
|
54
|
+
"pageNumber",
|
|
55
|
+
"chunkIndex"
|
|
56
|
+
];
|
|
35
57
|
function truncate(value, max = MAX_CONTENT_LENGTH) {
|
|
36
58
|
const text = typeof value === "string" ? value : value == null ? "" : String(value);
|
|
37
59
|
return text.length > max ? `${text.slice(0, max)}...` : text;
|
|
@@ -47,10 +69,37 @@ function firstString(...values) {
|
|
|
47
69
|
}
|
|
48
70
|
return void 0;
|
|
49
71
|
}
|
|
72
|
+
function toRecord(value) {
|
|
73
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
74
|
+
}
|
|
75
|
+
function readModelValue(record, key) {
|
|
76
|
+
const model = record;
|
|
77
|
+
return typeof (model == null ? void 0 : model.get) === "function" ? model.get(key) : model == null ? void 0 : model[key];
|
|
78
|
+
}
|
|
79
|
+
function toPlain(record) {
|
|
80
|
+
const model = record;
|
|
81
|
+
return toRecord(typeof (model == null ? void 0 : model.toJSON) === "function" ? model.toJSON() : record);
|
|
82
|
+
}
|
|
83
|
+
function sanitizeMetadata(value) {
|
|
84
|
+
const metadata = toRecord(value);
|
|
85
|
+
return Object.fromEntries(
|
|
86
|
+
METADATA_FIELDS.flatMap((key) => {
|
|
87
|
+
const field = metadata[key];
|
|
88
|
+
if (typeof field === "string") {
|
|
89
|
+
return [[key, truncate(field, MAX_METADATA_VALUE_LENGTH)]];
|
|
90
|
+
}
|
|
91
|
+
if (typeof field === "number" || typeof field === "boolean") {
|
|
92
|
+
return [[key, field]];
|
|
93
|
+
}
|
|
94
|
+
return [];
|
|
95
|
+
})
|
|
96
|
+
);
|
|
97
|
+
}
|
|
50
98
|
function normalizeResult(result) {
|
|
51
|
-
const
|
|
99
|
+
const record = toRecord(result);
|
|
100
|
+
const metadata = sanitizeMetadata(record.metadata);
|
|
52
101
|
const sourceId = firstString(
|
|
53
|
-
|
|
102
|
+
record.id,
|
|
54
103
|
metadata.id,
|
|
55
104
|
metadata.sourceId,
|
|
56
105
|
metadata.documentId,
|
|
@@ -60,10 +109,10 @@ function normalizeResult(result) {
|
|
|
60
109
|
);
|
|
61
110
|
const filename = firstString(metadata.filename, metadata.fileName, metadata.name, metadata.title, metadata.source);
|
|
62
111
|
return {
|
|
63
|
-
content: truncate(
|
|
64
|
-
score: Number(
|
|
65
|
-
knowledgeBaseId:
|
|
66
|
-
knowledgeBaseName:
|
|
112
|
+
content: truncate(record.content),
|
|
113
|
+
score: Number(record.rerankScore ?? record.score ?? record.vectorScore ?? 0),
|
|
114
|
+
knowledgeBaseId: record.knowledgeBaseId,
|
|
115
|
+
knowledgeBaseName: record.knowledgeBaseName,
|
|
67
116
|
source: {
|
|
68
117
|
id: sourceId,
|
|
69
118
|
filename,
|
|
@@ -74,6 +123,74 @@ function normalizeResult(result) {
|
|
|
74
123
|
metadata
|
|
75
124
|
};
|
|
76
125
|
}
|
|
126
|
+
function getContextAgentUsername(ctx) {
|
|
127
|
+
var _a;
|
|
128
|
+
const direct = ctx._currentAIEmployee ?? ((_a = ctx.state) == null ? void 0 : _a.currentAIEmployee);
|
|
129
|
+
if (typeof direct === "string" && direct.trim()) {
|
|
130
|
+
return direct.trim();
|
|
131
|
+
}
|
|
132
|
+
const employee = toRecord(direct);
|
|
133
|
+
return firstString(employee.username, employee.name);
|
|
134
|
+
}
|
|
135
|
+
async function resolveAgentFromToolCall(ctx, runtime) {
|
|
136
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
137
|
+
const direct = getContextAgentUsername(ctx);
|
|
138
|
+
if (direct) {
|
|
139
|
+
return direct;
|
|
140
|
+
}
|
|
141
|
+
const toolCallId = runtime == null ? void 0 : runtime.toolCallId;
|
|
142
|
+
if (!toolCallId) {
|
|
143
|
+
return void 0;
|
|
144
|
+
}
|
|
145
|
+
const toolMessage = await ((_d = (_c = (_b = (_a = ctx.db) == null ? void 0 : _a.getRepository) == null ? void 0 : _b.call(_a, "aiToolMessages")) == null ? void 0 : _c.findOne) == null ? void 0 : _d.call(_c, {
|
|
146
|
+
filter: { toolCallId }
|
|
147
|
+
}));
|
|
148
|
+
const sessionId = firstString(readModelValue(toolMessage, "sessionId"));
|
|
149
|
+
if (!sessionId) {
|
|
150
|
+
return void 0;
|
|
151
|
+
}
|
|
152
|
+
const conversation = await ((_h = (_g = (_f = (_e = ctx.db) == null ? void 0 : _e.getRepository) == null ? void 0 : _f.call(_e, "aiConversations")) == null ? void 0 : _g.findOne) == null ? void 0 : _h.call(_g, {
|
|
153
|
+
filter: { sessionId }
|
|
154
|
+
}));
|
|
155
|
+
return firstString(readModelValue(conversation, "aiEmployeeUsername"));
|
|
156
|
+
}
|
|
157
|
+
function readKnowledgeBaseIds(employee) {
|
|
158
|
+
const settings = toRecord(readModelValue(employee, "knowledgeBase"));
|
|
159
|
+
const legacyIds = settings.knowledgeBaseKeys;
|
|
160
|
+
const ids = Array.isArray(legacyIds) && legacyIds.length ? legacyIds : settings.knowledgeBaseIds;
|
|
161
|
+
return Array.isArray(ids) ? Array.from(
|
|
162
|
+
new Set(
|
|
163
|
+
ids.filter((id) => typeof id === "string" || typeof id === "number").map(String)
|
|
164
|
+
)
|
|
165
|
+
) : [];
|
|
166
|
+
}
|
|
167
|
+
async function resolveAgent(ctx, runtime) {
|
|
168
|
+
var _a, _b, _c, _d;
|
|
169
|
+
const username = await resolveAgentFromToolCall(ctx, runtime);
|
|
170
|
+
if (!username) {
|
|
171
|
+
return void 0;
|
|
172
|
+
}
|
|
173
|
+
const employee = await ((_d = (_c = (_b = (_a = ctx.db) == null ? void 0 : _a.getRepository) == null ? void 0 : _b.call(_a, "aiEmployees")) == null ? void 0 : _c.findOne) == null ? void 0 : _d.call(_c, {
|
|
174
|
+
filter: { username }
|
|
175
|
+
}));
|
|
176
|
+
if (!employee) {
|
|
177
|
+
return void 0;
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
username,
|
|
181
|
+
knowledgeBaseIds: readKnowledgeBaseIds(employee)
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function withAgentIdentity(ctx, username) {
|
|
185
|
+
const scoped = Object.create(ctx);
|
|
186
|
+
const employee = { username };
|
|
187
|
+
scoped._currentAIEmployee = employee;
|
|
188
|
+
scoped.state = {
|
|
189
|
+
...ctx.state ?? {},
|
|
190
|
+
currentAIEmployee: employee
|
|
191
|
+
};
|
|
192
|
+
return scoped;
|
|
193
|
+
}
|
|
77
194
|
function createExternalRagSearchTool(plugin) {
|
|
78
195
|
return {
|
|
79
196
|
scope: "CUSTOM",
|
|
@@ -97,13 +214,36 @@ The search may be served by an external RAG service. Results include content plu
|
|
|
97
214
|
scoreThreshold: import_zod.z.number().min(0).max(1).optional().describe("Minimum relevance score. Default is controlled by plugin-knowledge-base.")
|
|
98
215
|
})
|
|
99
216
|
},
|
|
100
|
-
invoke: async (ctx, args) => {
|
|
217
|
+
invoke: async (ctx, args, runtime) => {
|
|
101
218
|
var _a, _b, _c, _d, _e;
|
|
102
219
|
const query = typeof (args == null ? void 0 : args.query) === "string" ? args.query.trim() : "";
|
|
103
220
|
if (!query) {
|
|
104
221
|
return { status: "error", content: "Missing required field: query." };
|
|
105
222
|
}
|
|
106
|
-
const
|
|
223
|
+
const agent = await resolveAgent(ctx, runtime);
|
|
224
|
+
if (!agent) {
|
|
225
|
+
return {
|
|
226
|
+
status: "error",
|
|
227
|
+
content: "Unable to determine the requesting AI Employee. Knowledge base search is denied."
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
if (!agent.knowledgeBaseIds.length) {
|
|
231
|
+
return {
|
|
232
|
+
status: "error",
|
|
233
|
+
content: `AI Employee "${agent.username}" has no assigned knowledge bases.`
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
const requestedIds = Array.isArray(args.knowledgeBaseIds) ? args.knowledgeBaseIds.map(String) : void 0;
|
|
237
|
+
const unauthorizedIds = (requestedIds == null ? void 0 : requestedIds.filter((id) => !agent.knowledgeBaseIds.includes(id))) ?? [];
|
|
238
|
+
if (unauthorizedIds.length) {
|
|
239
|
+
return {
|
|
240
|
+
status: "error",
|
|
241
|
+
content: `Knowledge base IDs are not assigned to AI Employee "${agent.username}": ${unauthorizedIds.join(
|
|
242
|
+
", "
|
|
243
|
+
)}.`
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
const kbPlugin = (_c = (_b = (_a = ctx.app) == null ? void 0 : _a.pm) == null ? void 0 : _b.get) == null ? void 0 : _c.call(_b, "plugin-knowledge-base");
|
|
107
247
|
if (!(kbPlugin == null ? void 0 : kbPlugin.searchKnowledgeBases)) {
|
|
108
248
|
return {
|
|
109
249
|
status: "error",
|
|
@@ -111,8 +251,8 @@ The search may be served by an external RAG service. Results include content plu
|
|
|
111
251
|
};
|
|
112
252
|
}
|
|
113
253
|
try {
|
|
114
|
-
const results = await kbPlugin.searchKnowledgeBases(ctx, query, {
|
|
115
|
-
knowledgeBaseIds:
|
|
254
|
+
const results = await kbPlugin.searchKnowledgeBases(withAgentIdentity(ctx, agent.username), query, {
|
|
255
|
+
knowledgeBaseIds: requestedIds ?? agent.knowledgeBaseIds,
|
|
116
256
|
topK: args.topK,
|
|
117
257
|
scoreThreshold: args.scoreThreshold,
|
|
118
258
|
rerank: true
|
|
@@ -121,14 +261,14 @@ The search may be served by an external RAG service. Results include content plu
|
|
|
121
261
|
status: "success",
|
|
122
262
|
content: JSON.stringify({
|
|
123
263
|
query,
|
|
124
|
-
results:
|
|
264
|
+
results: results.map(normalizeResult)
|
|
125
265
|
})
|
|
126
266
|
};
|
|
127
267
|
} catch (error) {
|
|
128
268
|
(_e = (_d = plugin.app.log) == null ? void 0 : _d.error) == null ? void 0 : _e.call(_d, "[AgentOrchestrator] external_rag_search failed", error);
|
|
129
269
|
return {
|
|
130
270
|
status: "error",
|
|
131
|
-
content: `External RAG search failed: ${
|
|
271
|
+
content: `External RAG search failed: ${error instanceof Error ? error.message : String(error)}`
|
|
132
272
|
};
|
|
133
273
|
}
|
|
134
274
|
}
|
|
@@ -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
|
+
});
|