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,70 @@
|
|
|
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_registry_installations_exports = {};
|
|
28
|
+
__export(skill_registry_installations_exports, {
|
|
29
|
+
default: () => skill_registry_installations_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(skill_registry_installations_exports);
|
|
32
|
+
var skill_registry_installations_default = {
|
|
33
|
+
name: "skillRegistryInstallations",
|
|
34
|
+
title: "Skill Registry Installations",
|
|
35
|
+
fields: [
|
|
36
|
+
{ name: "id", type: "bigInt", autoIncrement: true, primaryKey: true },
|
|
37
|
+
{ name: "registryPackageId", type: "bigInt", allowNull: false },
|
|
38
|
+
{ name: "registryVersionId", type: "bigInt", allowNull: false, unique: true },
|
|
39
|
+
{ name: "packageIdentity", type: "string", length: 220, allowNull: false },
|
|
40
|
+
{ name: "version", type: "string", length: 64, allowNull: false },
|
|
41
|
+
{ name: "channel", type: "string", length: 20, defaultValue: "stable" },
|
|
42
|
+
{ name: "artifactDigest", type: "string", length: 71, allowNull: false },
|
|
43
|
+
{ name: "sourceSignature", type: "text", allowNull: true },
|
|
44
|
+
{ name: "updatePolicy", type: "string", length: 20, defaultValue: "pinned" },
|
|
45
|
+
{ name: "status", type: "string", length: 24, defaultValue: "verifying" },
|
|
46
|
+
{
|
|
47
|
+
name: "skillDefinition",
|
|
48
|
+
type: "belongsTo",
|
|
49
|
+
target: "skillDefinitions",
|
|
50
|
+
foreignKey: "skillDefinitionId",
|
|
51
|
+
onDelete: "RESTRICT"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "previousInstallation",
|
|
55
|
+
type: "belongsTo",
|
|
56
|
+
target: "skillRegistryInstallations",
|
|
57
|
+
foreignKey: "previousInstallationId",
|
|
58
|
+
onDelete: "SET NULL"
|
|
59
|
+
},
|
|
60
|
+
{ name: "lastError", type: "text", allowNull: true },
|
|
61
|
+
{ name: "installedAt", type: "date", allowNull: true },
|
|
62
|
+
{ name: "installedBy", type: "belongsTo", target: "users", foreignKey: "installedById" },
|
|
63
|
+
{ name: "createdAt", type: "date" },
|
|
64
|
+
{ name: "updatedAt", type: "date" }
|
|
65
|
+
],
|
|
66
|
+
indexes: [
|
|
67
|
+
{ name: "skill_registry_installations_package_status", fields: ["registryPackageId", "status"] },
|
|
68
|
+
{ name: "skill_registry_installations_skill_definition", fields: ["skillDefinitionId"] }
|
|
69
|
+
]
|
|
70
|
+
};
|
|
@@ -41,7 +41,6 @@ const nativePolicyProfiles = [
|
|
|
41
41
|
nativeObserverEnabled: true,
|
|
42
42
|
memoryInjectionEnabled: true,
|
|
43
43
|
memoryScopes: ["public", "user", "agent_user"],
|
|
44
|
-
knowledgeScopes: ["public", "private"],
|
|
45
44
|
maxMemoryContextChars: 6e3,
|
|
46
45
|
tracingRetentionDays: 30
|
|
47
46
|
}
|
|
@@ -54,7 +53,6 @@ const nativePolicyProfiles = [
|
|
|
54
53
|
nativeObserverEnabled: true,
|
|
55
54
|
memoryInjectionEnabled: true,
|
|
56
55
|
memoryScopes: ["public", "user", "agent_user"],
|
|
57
|
-
knowledgeScopes: ["public", "private"],
|
|
58
56
|
maxMemoryContextChars: 4e3,
|
|
59
57
|
tracingRetentionDays: 14
|
|
60
58
|
}
|
|
@@ -67,7 +65,6 @@ const nativePolicyProfiles = [
|
|
|
67
65
|
nativeObserverEnabled: true,
|
|
68
66
|
memoryInjectionEnabled: true,
|
|
69
67
|
memoryScopes: ["public", "user", "agent_user"],
|
|
70
|
-
knowledgeScopes: ["public", "private"],
|
|
71
68
|
maxMemoryContextChars: 8e3,
|
|
72
69
|
tracingRetentionDays: 30,
|
|
73
70
|
preferFileTools: true
|
|
@@ -0,0 +1,51 @@
|
|
|
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 remove_unused_knowledge_scopes_exports = {};
|
|
28
|
+
__export(remove_unused_knowledge_scopes_exports, {
|
|
29
|
+
default: () => RemoveUnusedKnowledgeScopes
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(remove_unused_knowledge_scopes_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
class RemoveUnusedKnowledgeScopes extends import_server.Migration {
|
|
34
|
+
on = "afterLoad";
|
|
35
|
+
appVersion = ">=0.1.0";
|
|
36
|
+
async up() {
|
|
37
|
+
var _a;
|
|
38
|
+
const repo = this.db.getRepository("agentHarnessProfiles");
|
|
39
|
+
const profiles = await repo.find({});
|
|
40
|
+
for (const profile of profiles) {
|
|
41
|
+
const settings = ((_a = profile.get) == null ? void 0 : _a.call(profile, "settings")) ?? profile.settings;
|
|
42
|
+
if (!settings || typeof settings !== "object" || Array.isArray(settings) || !("knowledgeScopes" in settings)) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const { knowledgeScopes: _unused, ...nextSettings } = settings;
|
|
46
|
+
await profile.update({ settings: nextSettings, updatedAt: /* @__PURE__ */ new Date() });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async down() {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 backfill_skill_tool_names_exports = {};
|
|
28
|
+
__export(backfill_skill_tool_names_exports, {
|
|
29
|
+
default: () => BackfillSkillToolNames
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(backfill_skill_tool_names_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
var import_skill_tool_name = require("../utils/skill-tool-name");
|
|
34
|
+
class BackfillSkillToolNames extends import_server.Migration {
|
|
35
|
+
on = "afterLoad";
|
|
36
|
+
appVersion = ">=0.1.0";
|
|
37
|
+
async up() {
|
|
38
|
+
const repo = this.db.getRepository("skillDefinitions");
|
|
39
|
+
if (!repo) return;
|
|
40
|
+
const skills = await repo.find({ sort: ["id"] });
|
|
41
|
+
const used = /* @__PURE__ */ new Set();
|
|
42
|
+
for (const skill of skills) {
|
|
43
|
+
const current = (0, import_skill_tool_name.readRecordValue)(skill, "toolName");
|
|
44
|
+
if (typeof current === "string" && current.trim()) {
|
|
45
|
+
used.add(current.trim());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
for (const skill of skills) {
|
|
49
|
+
const current = (0, import_skill_tool_name.readRecordValue)(skill, "toolName");
|
|
50
|
+
if (typeof current === "string" && current.trim()) continue;
|
|
51
|
+
const id = (0, import_skill_tool_name.readRecordValue)(skill, "id");
|
|
52
|
+
const baseName = (0, import_skill_tool_name.buildSkillToolName)(String((0, import_skill_tool_name.readRecordValue)(skill, "name") || ""));
|
|
53
|
+
let toolName = baseName;
|
|
54
|
+
if (used.has(toolName)) {
|
|
55
|
+
toolName = `${baseName}_${id}`;
|
|
56
|
+
}
|
|
57
|
+
await repo.update({
|
|
58
|
+
filterByTk: id,
|
|
59
|
+
values: { toolName }
|
|
60
|
+
});
|
|
61
|
+
used.add(toolName);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async down() {
|
|
65
|
+
}
|
|
66
|
+
}
|
package/dist/server/plugin.js
CHANGED
|
@@ -46,14 +46,19 @@ var import_external_rag_search = require("./tools/external-rag-search");
|
|
|
46
46
|
var import_tracing = require("./resources/tracing");
|
|
47
47
|
var import_agent_monitor = require("./resources/agent-monitor");
|
|
48
48
|
var import_agent_loop = require("./resources/agent-loop");
|
|
49
|
+
var import_agent_knowledge_insights = require("./resources/agent-knowledge-insights");
|
|
49
50
|
var import_plugin = __toESM(require("./skill-hub/plugin"));
|
|
50
51
|
var import_NativeSubAgentObserver = require("./services/NativeSubAgentObserver");
|
|
52
|
+
var import_RegistrySkillSnapshotService = require("./skill-hub/services/RegistrySkillSnapshotService");
|
|
53
|
+
var import_RegistrySkillInstallationService = require("./skill-hub/services/RegistrySkillInstallationService");
|
|
51
54
|
var import_AgentLoopService = require("./services/AgentLoopService");
|
|
52
55
|
var import_agent_loop2 = require("./tools/agent-loop");
|
|
53
56
|
var import_PlanningPromptService = require("./services/PlanningPromptService");
|
|
54
57
|
var import_ctx_utils = require("./utils/ctx-utils");
|
|
55
58
|
var import_ai_manager = require("./utils/ai-manager");
|
|
56
59
|
var import_AgentRuntimeLifecycle = require("./services/AgentRuntimeLifecycle");
|
|
60
|
+
var import_InputSchemaValidator = require("./services/InputSchemaValidator");
|
|
61
|
+
var import_skill_tool_name = require("./utils/skill-tool-name");
|
|
57
62
|
function normalizeOptionalString(value) {
|
|
58
63
|
return typeof value === "string" ? value.trim() : "";
|
|
59
64
|
}
|
|
@@ -61,6 +66,30 @@ function readModelValue(record, key) {
|
|
|
61
66
|
const model = record;
|
|
62
67
|
return typeof (model == null ? void 0 : model.get) === "function" ? model.get(key) : model == null ? void 0 : model[key];
|
|
63
68
|
}
|
|
69
|
+
const PRIVATE_SKILL_FIELDS = ["codeTemplate", "instructions", "storageUrl", "packages", "fileId"];
|
|
70
|
+
function redactSkillRecord(record) {
|
|
71
|
+
var _a;
|
|
72
|
+
if (!record || typeof record !== "object") return record;
|
|
73
|
+
const source = ((_a = record.toJSON) == null ? void 0 : _a.call(record)) || record;
|
|
74
|
+
const result = { ...source };
|
|
75
|
+
for (const field of PRIVATE_SKILL_FIELDS) {
|
|
76
|
+
delete result[field];
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
function redactSkillResponse(body) {
|
|
81
|
+
if (Array.isArray(body)) return body.map(redactSkillRecord);
|
|
82
|
+
if (!body || typeof body !== "object") return body;
|
|
83
|
+
const value = body;
|
|
84
|
+
if (Array.isArray(value.rows)) return { ...value, rows: value.rows.map(redactSkillRecord) };
|
|
85
|
+
if (Object.prototype.hasOwnProperty.call(value, "data")) {
|
|
86
|
+
return {
|
|
87
|
+
...value,
|
|
88
|
+
data: Array.isArray(value.data) ? value.data.map(redactSkillRecord) : redactSkillRecord(value.data)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return redactSkillRecord(value);
|
|
92
|
+
}
|
|
64
93
|
function buildAgentMemoryContextKey(values) {
|
|
65
94
|
const userPart = values.scope === "public" ? "public" : String(values.userId || "");
|
|
66
95
|
const agentPart = values.aiEmployeeUsername || "*";
|
|
@@ -152,6 +181,8 @@ async function resolveTracingRetentionDays(plugin) {
|
|
|
152
181
|
}
|
|
153
182
|
class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
154
183
|
skillHub;
|
|
184
|
+
registrySkillSnapshotService;
|
|
185
|
+
registrySkillInstallationService;
|
|
155
186
|
nativeObserver;
|
|
156
187
|
agentRuntimeLifecycle;
|
|
157
188
|
installNativeObserver = () => {
|
|
@@ -160,6 +191,11 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
160
191
|
};
|
|
161
192
|
async afterAdd() {
|
|
162
193
|
this.skillHub = new import_plugin.default(this);
|
|
194
|
+
this.registrySkillSnapshotService = new import_RegistrySkillSnapshotService.RegistrySkillSnapshotService(this.db);
|
|
195
|
+
this.registrySkillInstallationService = new import_RegistrySkillInstallationService.RegistrySkillInstallationService(
|
|
196
|
+
this.db,
|
|
197
|
+
() => this.skillHub.getSkillRepositoryService()
|
|
198
|
+
);
|
|
163
199
|
this.nativeObserver = new import_NativeSubAgentObserver.NativeSubAgentObserver(this);
|
|
164
200
|
this.agentRuntimeLifecycle = new import_AgentRuntimeLifecycle.AgentRuntimeLifecycle((hookType, name, error) => {
|
|
165
201
|
this.app.logger.warn(`[AgentOrchestrator] ${hookType} hook "${name}" failed; continuing agent execution.`, {
|
|
@@ -185,6 +221,7 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
185
221
|
"orchestratorConfig:*",
|
|
186
222
|
"orchestratorTracing:*",
|
|
187
223
|
"agentMonitor:*",
|
|
224
|
+
"agentKnowledgeInsights:*",
|
|
188
225
|
"agentMemoryContexts:*",
|
|
189
226
|
"agentLoopRuns:*",
|
|
190
227
|
"agentLoopSteps:*",
|
|
@@ -204,7 +241,6 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
204
241
|
this.app.acl.allow("skillLoopConfigs", "get", "loggedIn");
|
|
205
242
|
this.app.acl.allow("skillExecutions", "list", "loggedIn");
|
|
206
243
|
this.app.acl.allow("skillExecutions", "get", "loggedIn");
|
|
207
|
-
this.app.acl.allow("skillHub", "test", "loggedIn");
|
|
208
244
|
this.app.acl.allow("skillHub", "download", "loggedIn");
|
|
209
245
|
this.app.acl.allow("skillHub", "listTemplates", "loggedIn");
|
|
210
246
|
this.app.acl.allow("agentMonitor", ["list", "get"], "loggedIn");
|
|
@@ -223,6 +259,67 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
223
259
|
},
|
|
224
260
|
{ tag: "orchestrator-skill-executions-scope", after: "acl" }
|
|
225
261
|
);
|
|
262
|
+
this.app.resourceManager.use(
|
|
263
|
+
async (ctx, next) => {
|
|
264
|
+
var _a2, _b2, _c2, _d2, _e, _f;
|
|
265
|
+
const { resourceName, actionName } = ctx.action || {};
|
|
266
|
+
if (resourceName !== "skillDefinitions") {
|
|
267
|
+
await next();
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const values = ((_b2 = (_a2 = ctx.action) == null ? void 0 : _a2.params) == null ? void 0 : _b2.values) || {};
|
|
271
|
+
if (actionName === "create" || actionName === "update") {
|
|
272
|
+
try {
|
|
273
|
+
if (Object.prototype.hasOwnProperty.call(values, "inputSchema")) {
|
|
274
|
+
(0, import_InputSchemaValidator.validateInputSchemaDefinition)(values.inputSchema);
|
|
275
|
+
}
|
|
276
|
+
if (actionName === "create") {
|
|
277
|
+
const toolName = (0, import_skill_tool_name.buildSkillToolName)(values.name);
|
|
278
|
+
await (0, import_skill_tool_name.assertSkillToolNameAvailable)(ctx.db, toolName);
|
|
279
|
+
values.toolName = toolName;
|
|
280
|
+
} else {
|
|
281
|
+
const existing = await ctx.db.getRepository("skillDefinitions").findOne({
|
|
282
|
+
filterByTk: (_d2 = (_c2 = ctx.action) == null ? void 0 : _c2.params) == null ? void 0 : _d2.filterByTk
|
|
283
|
+
});
|
|
284
|
+
if (existing) {
|
|
285
|
+
const stableToolName = (0, import_skill_tool_name.getSkillToolName)(existing);
|
|
286
|
+
if (values.toolName && values.toolName !== stableToolName) {
|
|
287
|
+
ctx.throw(400, "toolName is immutable after a skill is created.");
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
values.toolName = stableToolName;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
} catch (error) {
|
|
294
|
+
ctx.throw(400, error instanceof Error ? error.message : String(error));
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (actionName === "destroy") {
|
|
299
|
+
const existing = await ctx.db.getRepository("skillDefinitions").findOne({
|
|
300
|
+
filterByTk: (_f = (_e = ctx.action) == null ? void 0 : _e.params) == null ? void 0 : _f.filterByTk
|
|
301
|
+
});
|
|
302
|
+
if (existing) {
|
|
303
|
+
const toolName = (0, import_skill_tool_name.getSkillToolName)(existing);
|
|
304
|
+
const agentUsernames = await this.skillHub.skillAccessService.findAgentUsernamesUsingTool(toolName);
|
|
305
|
+
if (agentUsernames.length > 0) {
|
|
306
|
+
ctx.throw(
|
|
307
|
+
409,
|
|
308
|
+
`Skill tool "${toolName}" is still bound to AI employees: ${agentUsernames.join(
|
|
309
|
+
", "
|
|
310
|
+
)}. Disable or unbind it before deletion.`
|
|
311
|
+
);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
await next();
|
|
317
|
+
if ((actionName === "list" || actionName === "get") && !(0, import_ctx_utils.isAdminUser)(ctx)) {
|
|
318
|
+
ctx.body = redactSkillResponse(ctx.body);
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
{ tag: "orchestrator-skill-definition-policy", after: "acl" }
|
|
322
|
+
);
|
|
226
323
|
this.app.resourceManager.use(
|
|
227
324
|
async (ctx, next) => {
|
|
228
325
|
const { resourceName, actionName } = ctx.action || {};
|
|
@@ -263,13 +360,20 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
263
360
|
const runtimeContext = (_b2 = ctx.state) == null ? void 0 : _b2.agentRuntimeContext;
|
|
264
361
|
try {
|
|
265
362
|
await next();
|
|
266
|
-
} finally {
|
|
267
363
|
if (runtimeContext) {
|
|
268
364
|
await this.agentRuntimeLifecycle.runAfterHooks(runtimeContext, {
|
|
269
365
|
succeeded: ctx.status < 400,
|
|
270
366
|
value: ctx.body
|
|
271
367
|
});
|
|
272
368
|
}
|
|
369
|
+
} catch (error) {
|
|
370
|
+
if (runtimeContext) {
|
|
371
|
+
await this.agentRuntimeLifecycle.runAfterHooks(runtimeContext, {
|
|
372
|
+
succeeded: false,
|
|
373
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
throw error;
|
|
273
377
|
}
|
|
274
378
|
},
|
|
275
379
|
{ tag: "orchestrator-planning-prompt", after: "acl" }
|
|
@@ -280,6 +384,7 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
280
384
|
toolsManager.registerTools((0, import_agent_loop2.createAgentLoopTools)(this, agentLoopService));
|
|
281
385
|
(0, import_agent_loop.registerAgentLoopResource)(this, agentLoopService);
|
|
282
386
|
(0, import_agent_monitor.registerAgentMonitorResource)(this);
|
|
387
|
+
(0, import_agent_knowledge_insights.registerAgentKnowledgeInsightsResource)(this);
|
|
283
388
|
this.installNativeObserver();
|
|
284
389
|
(_b = (_a = this.app).on) == null ? void 0 : _b.call(_a, "afterStart", this.installNativeObserver);
|
|
285
390
|
(_d = (_c = this.app).on) == null ? void 0 : _d.call(_c, "afterStart", this.recoverAfterCrash);
|
|
@@ -0,0 +1,273 @@
|
|
|
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 agent_knowledge_insights_exports = {};
|
|
28
|
+
__export(agent_knowledge_insights_exports, {
|
|
29
|
+
buildKnowledgeAccessMatrix: () => buildKnowledgeAccessMatrix,
|
|
30
|
+
registerAgentKnowledgeInsightsResource: () => registerAgentKnowledgeInsightsResource,
|
|
31
|
+
summarizeRetrievalSpan: () => summarizeRetrievalSpan
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(agent_knowledge_insights_exports);
|
|
34
|
+
var import_AgentMemoryContextService = require("../services/AgentMemoryContextService");
|
|
35
|
+
var import_ctx_utils = require("../utils/ctx-utils");
|
|
36
|
+
function asPlainRecord(value) {
|
|
37
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
38
|
+
const model = value;
|
|
39
|
+
const plain = typeof model.toJSON === "function" ? model.toJSON() : value;
|
|
40
|
+
return plain && typeof plain === "object" && !Array.isArray(plain) ? plain : {};
|
|
41
|
+
}
|
|
42
|
+
function text(value) {
|
|
43
|
+
return typeof value === "string" ? value.trim() : value == null ? "" : String(value).trim();
|
|
44
|
+
}
|
|
45
|
+
function strings(value) {
|
|
46
|
+
return Array.isArray(value) ? Array.from(new Set(value.map(text).filter(Boolean))) : [];
|
|
47
|
+
}
|
|
48
|
+
function record(value) {
|
|
49
|
+
if (typeof value === "string" && value.trim()) {
|
|
50
|
+
try {
|
|
51
|
+
return asPlainRecord(JSON.parse(value));
|
|
52
|
+
} catch {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return asPlainRecord(value);
|
|
57
|
+
}
|
|
58
|
+
function employeeRoles(employee) {
|
|
59
|
+
return Array.isArray(employee.roles) ? employee.roles.map((role) => {
|
|
60
|
+
const roleRecord = asPlainRecord(role);
|
|
61
|
+
return text(typeof role === "string" ? role : roleRecord.name);
|
|
62
|
+
}).filter(Boolean) : [];
|
|
63
|
+
}
|
|
64
|
+
function assignedKnowledgeBaseIds(employee) {
|
|
65
|
+
const settings = record(employee.knowledgeBase);
|
|
66
|
+
const legacyIds = strings(settings.knowledgeBaseKeys);
|
|
67
|
+
return legacyIds.length ? legacyIds : strings(settings.knowledgeBaseIds);
|
|
68
|
+
}
|
|
69
|
+
function accessLevelDescription(knowledgeBase) {
|
|
70
|
+
const level = text(knowledgeBase.accessLevel) || "PUBLIC";
|
|
71
|
+
if (level === "BASIC") return "The triggering user must be the KB owner.";
|
|
72
|
+
if (level === "SHARED") return "The triggering user must have an allowed KB role.";
|
|
73
|
+
return "No additional triggering-user gate (public KB).";
|
|
74
|
+
}
|
|
75
|
+
function buildKnowledgeAccessMatrix(employees, knowledgeBases) {
|
|
76
|
+
const rows = [];
|
|
77
|
+
const normalizedKnowledgeBases = knowledgeBases.map(asPlainRecord).filter((item) => text(item.id));
|
|
78
|
+
for (const rawEmployee of employees) {
|
|
79
|
+
const employee = asPlainRecord(rawEmployee);
|
|
80
|
+
const username = text(employee.username);
|
|
81
|
+
if (!username) continue;
|
|
82
|
+
const roles = employeeRoles(employee);
|
|
83
|
+
const assignedIds = assignedKnowledgeBaseIds(employee);
|
|
84
|
+
for (const knowledgeBase of normalizedKnowledgeBases) {
|
|
85
|
+
const id = text(knowledgeBase.id);
|
|
86
|
+
const assigned = assignedIds.includes(id);
|
|
87
|
+
const enabled = knowledgeBase.enabled !== false;
|
|
88
|
+
const agentAccess = text(knowledgeBase.agentAccess) || "inherit";
|
|
89
|
+
const allowedAgents = strings(knowledgeBase.allowedAgents);
|
|
90
|
+
const allowedRoles = strings(knowledgeBase.allowedRoles);
|
|
91
|
+
const explicitGrant = allowedAgents.includes(username) || roles.some((role) => allowedRoles.includes(role));
|
|
92
|
+
let access = "allowed";
|
|
93
|
+
let reason = "Assigned to the AI Employee; agent policy inherits user access.";
|
|
94
|
+
if (!enabled) {
|
|
95
|
+
access = "denied";
|
|
96
|
+
reason = "Knowledge base is disabled.";
|
|
97
|
+
} else if (!assigned) {
|
|
98
|
+
access = "denied";
|
|
99
|
+
reason = "Knowledge base is not assigned to this AI Employee.";
|
|
100
|
+
} else if (agentAccess === "none") {
|
|
101
|
+
access = "denied";
|
|
102
|
+
reason = "Knowledge base policy denies all AI Employee access.";
|
|
103
|
+
} else if (agentAccess === "explicit" && !explicitGrant) {
|
|
104
|
+
access = "denied";
|
|
105
|
+
reason = "Explicit agent policy has no matching employee username or role.";
|
|
106
|
+
} else if (agentAccess === "explicit") {
|
|
107
|
+
reason = allowedAgents.includes(username) ? "Explicit agent policy grants this AI Employee username." : "Explicit agent policy grants one of this AI Employee roles.";
|
|
108
|
+
}
|
|
109
|
+
rows.push({
|
|
110
|
+
key: `${username}:${id}`,
|
|
111
|
+
employeeUsername: username,
|
|
112
|
+
employeeRoles: roles,
|
|
113
|
+
knowledgeBaseId: id,
|
|
114
|
+
knowledgeBaseName: text(knowledgeBase.name) || id,
|
|
115
|
+
knowledgeBaseType: text(knowledgeBase.type) || "LOCAL",
|
|
116
|
+
assigned,
|
|
117
|
+
enabled,
|
|
118
|
+
access,
|
|
119
|
+
reason,
|
|
120
|
+
userGate: accessLevelDescription(knowledgeBase)
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return rows;
|
|
125
|
+
}
|
|
126
|
+
function parseJson(value) {
|
|
127
|
+
if (typeof value !== "string" || !value.trim()) return asPlainRecord(value);
|
|
128
|
+
try {
|
|
129
|
+
return asPlainRecord(JSON.parse(value));
|
|
130
|
+
} catch {
|
|
131
|
+
return {};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function numeric(value) {
|
|
135
|
+
const result = Number(value);
|
|
136
|
+
return Number.isFinite(result) ? result : void 0;
|
|
137
|
+
}
|
|
138
|
+
function citationFromResult(value) {
|
|
139
|
+
const result = asPlainRecord(value);
|
|
140
|
+
const source = asPlainRecord(result.source);
|
|
141
|
+
return {
|
|
142
|
+
knowledgeBaseId: text(result.knowledgeBaseId) || void 0,
|
|
143
|
+
knowledgeBaseName: text(result.knowledgeBaseName) || void 0,
|
|
144
|
+
sourceId: text(source.id) || void 0,
|
|
145
|
+
filename: text(source.filename) || void 0,
|
|
146
|
+
url: text(source.url) || void 0,
|
|
147
|
+
collection: text(source.collection) || void 0,
|
|
148
|
+
recordId: text(source.recordId) || void 0,
|
|
149
|
+
excerpt: text(result.content) ? (0, import_ctx_utils.trimText)(text(result.content), 500) : void 0,
|
|
150
|
+
score: numeric(result.score)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function summarizeRetrievalSpan(rawSpan) {
|
|
154
|
+
const span = asPlainRecord(rawSpan);
|
|
155
|
+
const input = record(span.input);
|
|
156
|
+
const output = parseJson(span.output);
|
|
157
|
+
const results = Array.isArray(output.results) ? output.results.map(citationFromResult) : [];
|
|
158
|
+
const outputError = text(output.error);
|
|
159
|
+
const error = text(span.error) || outputError;
|
|
160
|
+
const denied = text(span.status) === "error";
|
|
161
|
+
return {
|
|
162
|
+
id: span.id,
|
|
163
|
+
createdAt: span.createdAt || span.startedAt,
|
|
164
|
+
employeeUsername: text(span.employeeUsername),
|
|
165
|
+
leaderUsername: text(span.leaderUsername),
|
|
166
|
+
userId: span.userId,
|
|
167
|
+
query: text(input.query) || text(output.query),
|
|
168
|
+
decision: denied ? "denied" : "allowed",
|
|
169
|
+
reason: denied ? error || "The tool returned an error without a reason." : `${results.length} citation(s) returned.`,
|
|
170
|
+
citations: results
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function ensureAdmin(ctx) {
|
|
174
|
+
if ((0, import_ctx_utils.isAdminUser)(ctx)) return true;
|
|
175
|
+
ctx.throw(403, "Administrator role is required to view Agent and Knowledge Base diagnostics.");
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
function paramsValues(ctx) {
|
|
179
|
+
var _a, _b;
|
|
180
|
+
return record((_b = (_a = ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.values);
|
|
181
|
+
}
|
|
182
|
+
function registerAgentKnowledgeInsightsResource(plugin) {
|
|
183
|
+
const memoryService = new import_AgentMemoryContextService.AgentMemoryContextService(plugin);
|
|
184
|
+
plugin.app.resource({
|
|
185
|
+
name: "agentKnowledgeInsights",
|
|
186
|
+
actions: {
|
|
187
|
+
async accessMatrix(ctx, next) {
|
|
188
|
+
if (!ensureAdmin(ctx)) return;
|
|
189
|
+
const employees = await ctx.db.getRepository("aiEmployees").find({
|
|
190
|
+
sort: ["username"],
|
|
191
|
+
appends: ["roles"]
|
|
192
|
+
});
|
|
193
|
+
const knowledgeBases = await ctx.db.getRepository("aiKnowledgeBases").find({
|
|
194
|
+
sort: ["name"]
|
|
195
|
+
});
|
|
196
|
+
ctx.body = { data: buildKnowledgeAccessMatrix(employees, knowledgeBases) };
|
|
197
|
+
await next();
|
|
198
|
+
},
|
|
199
|
+
async retrievalTrace(ctx, next) {
|
|
200
|
+
if (!ensureAdmin(ctx)) return;
|
|
201
|
+
const values = paramsValues(ctx);
|
|
202
|
+
const page = Math.max(Number(values.page || ctx.action.params.page || 1), 1);
|
|
203
|
+
const pageSize = Math.min(Math.max(Number(values.pageSize || ctx.action.params.pageSize || 20), 1), 100);
|
|
204
|
+
const filter = { toolName: "external_rag_search" };
|
|
205
|
+
const employeeUsername = text(values.employeeUsername || ctx.action.params.employeeUsername);
|
|
206
|
+
if (employeeUsername) filter.employeeUsername = employeeUsername;
|
|
207
|
+
const [spans, count] = await ctx.db.getRepository("agentExecutionSpans").findAndCount({
|
|
208
|
+
filter,
|
|
209
|
+
sort: ["-createdAt"],
|
|
210
|
+
offset: (page - 1) * pageSize,
|
|
211
|
+
limit: pageSize
|
|
212
|
+
});
|
|
213
|
+
ctx.body = {
|
|
214
|
+
data: spans.map(summarizeRetrievalSpan),
|
|
215
|
+
meta: { count, page, pageSize, totalPage: Math.ceil(count / pageSize) }
|
|
216
|
+
};
|
|
217
|
+
await next();
|
|
218
|
+
},
|
|
219
|
+
async memoryPreview(ctx, next) {
|
|
220
|
+
if (!ensureAdmin(ctx)) return;
|
|
221
|
+
const values = paramsValues(ctx);
|
|
222
|
+
const employeeUsername = text(values.employeeUsername);
|
|
223
|
+
const leaderUsername = text(values.leaderUsername);
|
|
224
|
+
const harnessTag = text(values.harnessTag);
|
|
225
|
+
const userId = text(values.userId) || String((0, import_ctx_utils.currentUserId)(ctx) || "");
|
|
226
|
+
if (!userId) {
|
|
227
|
+
ctx.throw(400, "userId is required to preview memory context.");
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const employee = employeeUsername ? await ctx.db.getRepository("aiEmployees").findOne({ filter: { username: employeeUsername } }) : void 0;
|
|
231
|
+
if (employeeUsername && !employee) {
|
|
232
|
+
ctx.throw(404, `AI Employee "${employeeUsername}" was not found.`);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const settings = await memoryService.resolvePolicySettings({
|
|
236
|
+
ctx: {
|
|
237
|
+
action: {
|
|
238
|
+
params: {
|
|
239
|
+
values: {
|
|
240
|
+
aiEmployeeUsername: leaderUsername,
|
|
241
|
+
harnessTag
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
employee
|
|
247
|
+
});
|
|
248
|
+
const preview = await memoryService.buildContext({
|
|
249
|
+
userId,
|
|
250
|
+
aiEmployeeUsername: employeeUsername || void 0,
|
|
251
|
+
settings
|
|
252
|
+
});
|
|
253
|
+
const maxChars = Number(settings.maxMemoryContextChars || settings.maxContextChars || 6e3);
|
|
254
|
+
ctx.body = {
|
|
255
|
+
data: {
|
|
256
|
+
...preview,
|
|
257
|
+
userId,
|
|
258
|
+
employeeUsername: employeeUsername || void 0,
|
|
259
|
+
harnessTag: settings.harnessTag || harnessTag || "default",
|
|
260
|
+
maxChars: Number.isFinite(maxChars) ? Math.min(Math.max(maxChars, 500), 2e4) : 6e3
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
await next();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
269
|
+
0 && (module.exports = {
|
|
270
|
+
buildKnowledgeAccessMatrix,
|
|
271
|
+
registerAgentKnowledgeInsightsResource,
|
|
272
|
+
summarizeRetrievalSpan
|
|
273
|
+
});
|