plugin-agent-orchestrator 1.0.37 → 1.1.0
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 +50 -2
- package/dist/locale/vi-VN.json +50 -2
- package/dist/locale/zh-CN.json +50 -2
- 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/plugin.js +11 -1
- package/dist/server/resources/agent-knowledge-insights.js +273 -0
- package/dist/server/services/AgentMemoryContextService.js +57 -19
- package/dist/server/services/NativeSubAgentObserver.js +11 -3
- package/dist/server/tools/external-rag-search.js +152 -12
- package/package.json +1 -1
- 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 +50 -2
- package/src/locale/vi-VN.json +50 -2
- package/src/locale/zh-CN.json +50 -2
- 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__/native-sub-agent-observer.test.ts +89 -7
- 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/plugin.ts +3 -0
- package/src/server/resources/agent-knowledge-insights.ts +304 -0
- package/src/server/services/AgentMemoryContextService.ts +63 -19
- package/src/server/services/NativeSubAgentObserver.ts +538 -528
- package/src/server/tools/external-rag-search.ts +215 -14
- package/dist/client-v2/418.29e713f79131eece.js +0 -10
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AIEmployeesProvider } from '../components/AIEmployeesContext';
|
|
3
|
+
import { AgentBindingsTab } from '../components/AgentBindingsTab';
|
|
4
|
+
|
|
5
|
+
const AgentBindingsPage: React.FC = () => (
|
|
6
|
+
<AIEmployeesProvider>
|
|
7
|
+
<div style={{ padding: '0 24px 24px' }}>
|
|
8
|
+
<AgentBindingsTab />
|
|
9
|
+
</div>
|
|
10
|
+
</AIEmployeesProvider>
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export default AgentBindingsPage;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { KnowledgeAccessTab } from '../components/KnowledgeAccessTab';
|
|
3
|
+
|
|
4
|
+
const KnowledgeAccessPage: React.FC = () => (
|
|
5
|
+
<div style={{ padding: '0 24px 24px' }}>
|
|
6
|
+
<KnowledgeAccessTab />
|
|
7
|
+
</div>
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export default KnowledgeAccessPage;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AIEmployeesProvider } from '../components/AIEmployeesContext';
|
|
3
|
+
import { MemoryInspectorTab } from '../components/MemoryInspectorTab';
|
|
4
|
+
|
|
5
|
+
const MemoryInspectorPage: React.FC = () => (
|
|
6
|
+
<AIEmployeesProvider>
|
|
7
|
+
<div style={{ padding: '0 24px 24px' }}>
|
|
8
|
+
<MemoryInspectorTab />
|
|
9
|
+
</div>
|
|
10
|
+
</AIEmployeesProvider>
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export default MemoryInspectorPage;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { RetrievalTraceTab } from '../components/RetrievalTraceTab';
|
|
3
|
+
|
|
4
|
+
const RetrievalTracePage: React.FC = () => (
|
|
5
|
+
<div style={{ padding: '0 24px 24px' }}>
|
|
6
|
+
<RetrievalTraceTab />
|
|
7
|
+
</div>
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export default RetrievalTracePage;
|
package/src/client-v2/plugin.tsx
CHANGED
|
@@ -37,6 +37,34 @@ export class PluginAgentOrchestratorClient extends Plugin<Record<string, never>,
|
|
|
37
37
|
componentLoader: () => import('./pages/HarnessProfilesPage'),
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
+
this.pluginSettingsManager.addPageTabItem({
|
|
41
|
+
menuKey: 'ai.orchestrator',
|
|
42
|
+
key: 'agent-bindings',
|
|
43
|
+
title: this.t('Agent Bindings'),
|
|
44
|
+
componentLoader: () => import('./pages/AgentBindingsPage'),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
this.pluginSettingsManager.addPageTabItem({
|
|
48
|
+
menuKey: 'ai.orchestrator',
|
|
49
|
+
key: 'knowledge-access',
|
|
50
|
+
title: this.t('Knowledge Access'),
|
|
51
|
+
componentLoader: () => import('./pages/KnowledgeAccessPage'),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
this.pluginSettingsManager.addPageTabItem({
|
|
55
|
+
menuKey: 'ai.orchestrator',
|
|
56
|
+
key: 'retrieval-trace',
|
|
57
|
+
title: this.t('Retrieval Trace'),
|
|
58
|
+
componentLoader: () => import('./pages/RetrievalTracePage'),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
this.pluginSettingsManager.addPageTabItem({
|
|
62
|
+
menuKey: 'ai.orchestrator',
|
|
63
|
+
key: 'memory-inspector',
|
|
64
|
+
title: this.t('Memory Inspector'),
|
|
65
|
+
componentLoader: () => import('./pages/MemoryInspectorPage'),
|
|
66
|
+
});
|
|
67
|
+
|
|
40
68
|
this.pluginSettingsManager.addPageTabItem({
|
|
41
69
|
menuKey: 'ai.orchestrator',
|
|
42
70
|
key: 'skill-definitions',
|
package/src/locale/en-US.json
CHANGED
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"Edit": "Edit",
|
|
76
76
|
"Delete this profile?": "Delete this profile?",
|
|
77
77
|
"Delete": "Delete",
|
|
78
|
-
"Policy profiles control native
|
|
78
|
+
"Policy profiles control native observation, memory scopes, and tracing retention.": "Policy profiles control native observation, memory scopes, and tracing retention.",
|
|
79
79
|
"New Policy": "New Policy",
|
|
80
80
|
"Edit Policy Profile": "Edit Policy Profile",
|
|
81
81
|
"New Policy Profile": "New Policy Profile",
|
|
@@ -92,5 +92,53 @@
|
|
|
92
92
|
"Save failed: {{message}}": "Save failed: {{message}}",
|
|
93
93
|
"Policy profile deleted": "Policy profile deleted",
|
|
94
94
|
"Delete failed: {{message}}": "Delete failed: {{message}}",
|
|
95
|
-
"unknown error": "unknown error"
|
|
95
|
+
"unknown error": "unknown error",
|
|
96
|
+
"Agent Bindings": "Agent Bindings",
|
|
97
|
+
"Knowledge Access": "Knowledge Access",
|
|
98
|
+
"Retrieval Trace": "Retrieval Trace",
|
|
99
|
+
"Memory Inspector": "Memory Inspector",
|
|
100
|
+
"Policy Profile": "Policy Profile",
|
|
101
|
+
"Agent binding updated": "Agent binding updated",
|
|
102
|
+
"Agent binding created": "Agent binding created",
|
|
103
|
+
"Agent binding deleted": "Agent binding deleted",
|
|
104
|
+
"Delete this binding?": "Delete this binding?",
|
|
105
|
+
"Bind each leader/sub-agent pair to the profile that controls memory and tracing policy.": "Bind each leader/sub-agent pair to the profile that controls memory and tracing policy.",
|
|
106
|
+
"New Agent Binding": "New Agent Binding",
|
|
107
|
+
"Edit Agent Binding": "Edit Agent Binding",
|
|
108
|
+
"Leader is required": "Leader is required",
|
|
109
|
+
"Sub-agent is required": "Sub-agent is required",
|
|
110
|
+
"Policy profile is required": "Policy profile is required",
|
|
111
|
+
"Select leader": "Select leader",
|
|
112
|
+
"Select sub-agent": "Select sub-agent",
|
|
113
|
+
"Select policy profile": "Select policy profile",
|
|
114
|
+
"AI Employee": "AI Employee",
|
|
115
|
+
"Knowledge Base": "Knowledge Base",
|
|
116
|
+
"Assignment": "Assignment",
|
|
117
|
+
"Assigned": "Assigned",
|
|
118
|
+
"Not assigned": "Not assigned",
|
|
119
|
+
"Agent access": "Agent access",
|
|
120
|
+
"Allowed": "Allowed",
|
|
121
|
+
"Denied": "Denied",
|
|
122
|
+
"Reason": "Reason",
|
|
123
|
+
"Runtime user gate": "Runtime user gate",
|
|
124
|
+
"This matrix checks employee assignment and static agent policy. BASIC and SHARED user access is still evaluated when a run starts.": "This matrix checks employee assignment and static agent policy. BASIC and SHARED user access is still evaluated when a run starts.",
|
|
125
|
+
"Show all": "Show all",
|
|
126
|
+
"Show denied only": "Show denied only",
|
|
127
|
+
"Decision": "Decision",
|
|
128
|
+
"Citations": "Citations",
|
|
129
|
+
"Retrieval trace stores the decision, query, and safe source citations. It does not repeat raw RAG provider metadata.": "Retrieval trace stores the decision, query, and safe source citations. It does not repeat raw RAG provider metadata.",
|
|
130
|
+
"Retrieval detail": "Retrieval detail",
|
|
131
|
+
"Unknown source": "Unknown source",
|
|
132
|
+
"No citations were returned": "No citations were returned",
|
|
133
|
+
"Memory preview returned no data": "Memory preview returned no data",
|
|
134
|
+
"Memory preview failed": "Memory preview failed",
|
|
135
|
+
"Preview the exact memory context for a user and selected sub-agent before a run. Memory is marked as data, not executable instructions.": "Preview the exact memory context for a user and selected sub-agent before a run. Memory is marked as data, not executable instructions.",
|
|
136
|
+
"User ID": "User ID",
|
|
137
|
+
"User ID is required": "User ID is required",
|
|
138
|
+
"Build memory preview": "Build memory preview",
|
|
139
|
+
"Final memory context": "Final memory context",
|
|
140
|
+
"Character budget": "Character budget",
|
|
141
|
+
"Applied scopes": "Applied scopes",
|
|
142
|
+
"None": "None",
|
|
143
|
+
"No memory context matched this preview.": "No memory context matched this preview."
|
|
96
144
|
}
|
package/src/locale/vi-VN.json
CHANGED
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"Edit": "Sửa",
|
|
76
76
|
"Delete this profile?": "Xóa hồ sơ này?",
|
|
77
77
|
"Delete": "Xóa",
|
|
78
|
-
"Policy profiles control native
|
|
78
|
+
"Policy profiles control native observation, memory scopes, and tracing retention.": "Hồ sơ chính sách kiểm soát quan sát native, phạm vi bộ nhớ và thời gian lưu trace.",
|
|
79
79
|
"New Policy": "Chính sách mới",
|
|
80
80
|
"Edit Policy Profile": "Sửa hồ sơ chính sách",
|
|
81
81
|
"New Policy Profile": "Hồ sơ chính sách mới",
|
|
@@ -92,5 +92,53 @@
|
|
|
92
92
|
"Save failed: {{message}}": "Lưu thất bại: {{message}}",
|
|
93
93
|
"Policy profile deleted": "Đã xóa hồ sơ chính sách",
|
|
94
94
|
"Delete failed: {{message}}": "Xóa thất bại: {{message}}",
|
|
95
|
-
"unknown error": "lỗi không xác định"
|
|
95
|
+
"unknown error": "lỗi không xác định",
|
|
96
|
+
"Agent Bindings": "Liên kết Agent",
|
|
97
|
+
"Knowledge Access": "Quyền truy cập Knowledge Base",
|
|
98
|
+
"Retrieval Trace": "Dấu vết truy xuất",
|
|
99
|
+
"Memory Inspector": "Kiểm tra bộ nhớ",
|
|
100
|
+
"Policy Profile": "Hồ sơ chính sách",
|
|
101
|
+
"Agent binding updated": "Đã cập nhật liên kết agent",
|
|
102
|
+
"Agent binding created": "Đã tạo liên kết agent",
|
|
103
|
+
"Agent binding deleted": "Đã xóa liên kết agent",
|
|
104
|
+
"Delete this binding?": "Xóa liên kết này?",
|
|
105
|
+
"Bind each leader/sub-agent pair to the profile that controls memory and tracing policy.": "Liên kết từng cặp leader/agent con với hồ sơ kiểm soát bộ nhớ và truy vết.",
|
|
106
|
+
"New Agent Binding": "Liên kết agent mới",
|
|
107
|
+
"Edit Agent Binding": "Sửa liên kết agent",
|
|
108
|
+
"Leader is required": "Bắt buộc chọn leader",
|
|
109
|
+
"Sub-agent is required": "Bắt buộc chọn agent con",
|
|
110
|
+
"Policy profile is required": "Bắt buộc chọn hồ sơ chính sách",
|
|
111
|
+
"Select leader": "Chọn leader",
|
|
112
|
+
"Select sub-agent": "Chọn agent con",
|
|
113
|
+
"Select policy profile": "Chọn hồ sơ chính sách",
|
|
114
|
+
"AI Employee": "AI Employee",
|
|
115
|
+
"Knowledge Base": "Knowledge Base",
|
|
116
|
+
"Assignment": "Gán KB",
|
|
117
|
+
"Assigned": "Đã gán",
|
|
118
|
+
"Not assigned": "Chưa gán",
|
|
119
|
+
"Agent access": "Quyền của agent",
|
|
120
|
+
"Allowed": "Được phép",
|
|
121
|
+
"Denied": "Bị từ chối",
|
|
122
|
+
"Reason": "Lý do",
|
|
123
|
+
"Runtime user gate": "Điều kiện người dùng khi chạy",
|
|
124
|
+
"This matrix checks employee assignment and static agent policy. BASIC and SHARED user access is still evaluated when a run starts.": "Ma trận kiểm tra KB được gán cho nhân viên và chính sách agent tĩnh. Quyền BASIC và SHARED của người dùng vẫn được kiểm tra khi lượt chạy bắt đầu.",
|
|
125
|
+
"Show all": "Hiện tất cả",
|
|
126
|
+
"Show denied only": "Chỉ hiện bị từ chối",
|
|
127
|
+
"Decision": "Quyết định",
|
|
128
|
+
"Citations": "Nguồn trích dẫn",
|
|
129
|
+
"Retrieval trace stores the decision, query, and safe source citations. It does not repeat raw RAG provider metadata.": "Dấu vết truy xuất lưu quyết định, truy vấn và nguồn trích dẫn an toàn; không lặp lại metadata thô của nhà cung cấp RAG.",
|
|
130
|
+
"Retrieval detail": "Chi tiết truy xuất",
|
|
131
|
+
"Unknown source": "Nguồn không xác định",
|
|
132
|
+
"No citations were returned": "Không có nguồn trích dẫn được trả về",
|
|
133
|
+
"Memory preview returned no data": "Bản xem trước bộ nhớ không trả dữ liệu",
|
|
134
|
+
"Memory preview failed": "Tạo bản xem trước bộ nhớ thất bại",
|
|
135
|
+
"Preview the exact memory context for a user and selected sub-agent before a run. Memory is marked as data, not executable instructions.": "Xem trước đúng context bộ nhớ cho người dùng và agent con trước khi chạy. Bộ nhớ được đánh dấu là dữ liệu, không phải chỉ dẫn có thể thực thi.",
|
|
136
|
+
"User ID": "ID người dùng",
|
|
137
|
+
"User ID is required": "Bắt buộc nhập ID người dùng",
|
|
138
|
+
"Build memory preview": "Tạo xem trước bộ nhớ",
|
|
139
|
+
"Final memory context": "Context bộ nhớ cuối cùng",
|
|
140
|
+
"Character budget": "Ngân sách ký tự",
|
|
141
|
+
"Applied scopes": "Phạm vi đã áp dụng",
|
|
142
|
+
"None": "Không có",
|
|
143
|
+
"No memory context matched this preview.": "Không có context bộ nhớ phù hợp với bản xem trước này."
|
|
96
144
|
}
|
package/src/locale/zh-CN.json
CHANGED
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"Edit": "编辑",
|
|
76
76
|
"Delete this profile?": "删除此配置?",
|
|
77
77
|
"Delete": "删除",
|
|
78
|
-
"Policy profiles control native
|
|
78
|
+
"Policy profiles control native observation, memory scopes, and tracing retention.": "策略配置控制原生观测、记忆范围和追踪保留时间。",
|
|
79
79
|
"New Policy": "新建策略",
|
|
80
80
|
"Edit Policy Profile": "编辑策略配置",
|
|
81
81
|
"New Policy Profile": "新建策略配置",
|
|
@@ -92,5 +92,53 @@
|
|
|
92
92
|
"Save failed: {{message}}": "保存失败:{{message}}",
|
|
93
93
|
"Policy profile deleted": "策略配置已删除",
|
|
94
94
|
"Delete failed: {{message}}": "删除失败:{{message}}",
|
|
95
|
-
"unknown error": "未知错误"
|
|
95
|
+
"unknown error": "未知错误",
|
|
96
|
+
"Agent Bindings": "智能体绑定",
|
|
97
|
+
"Knowledge Access": "知识库访问",
|
|
98
|
+
"Retrieval Trace": "检索追踪",
|
|
99
|
+
"Memory Inspector": "记忆检查器",
|
|
100
|
+
"Policy Profile": "策略配置",
|
|
101
|
+
"Agent binding updated": "智能体绑定已更新",
|
|
102
|
+
"Agent binding created": "智能体绑定已创建",
|
|
103
|
+
"Agent binding deleted": "智能体绑定已删除",
|
|
104
|
+
"Delete this binding?": "删除此绑定?",
|
|
105
|
+
"Bind each leader/sub-agent pair to the profile that controls memory and tracing policy.": "将每个主控/子智能体组合绑定到控制记忆和追踪策略的配置。",
|
|
106
|
+
"New Agent Binding": "新建智能体绑定",
|
|
107
|
+
"Edit Agent Binding": "编辑智能体绑定",
|
|
108
|
+
"Leader is required": "必须选择主控",
|
|
109
|
+
"Sub-agent is required": "必须选择子智能体",
|
|
110
|
+
"Policy profile is required": "必须选择策略配置",
|
|
111
|
+
"Select leader": "选择主控",
|
|
112
|
+
"Select sub-agent": "选择子智能体",
|
|
113
|
+
"Select policy profile": "选择策略配置",
|
|
114
|
+
"AI Employee": "AI 员工",
|
|
115
|
+
"Knowledge Base": "知识库",
|
|
116
|
+
"Assignment": "分配",
|
|
117
|
+
"Assigned": "已分配",
|
|
118
|
+
"Not assigned": "未分配",
|
|
119
|
+
"Agent access": "智能体访问",
|
|
120
|
+
"Allowed": "允许",
|
|
121
|
+
"Denied": "拒绝",
|
|
122
|
+
"Reason": "原因",
|
|
123
|
+
"Runtime user gate": "运行时用户条件",
|
|
124
|
+
"This matrix checks employee assignment and static agent policy. BASIC and SHARED user access is still evaluated when a run starts.": "此矩阵检查员工分配和静态智能体策略。BASIC 和 SHARED 用户访问权限仍会在运行开始时检查。",
|
|
125
|
+
"Show all": "显示全部",
|
|
126
|
+
"Show denied only": "仅显示拒绝项",
|
|
127
|
+
"Decision": "决定",
|
|
128
|
+
"Citations": "引用来源",
|
|
129
|
+
"Retrieval trace stores the decision, query, and safe source citations. It does not repeat raw RAG provider metadata.": "检索追踪保存决定、查询和安全的来源引用,不重复保存原始 RAG 提供方元数据。",
|
|
130
|
+
"Retrieval detail": "检索详情",
|
|
131
|
+
"Unknown source": "未知来源",
|
|
132
|
+
"No citations were returned": "未返回引用来源",
|
|
133
|
+
"Memory preview returned no data": "记忆预览没有返回数据",
|
|
134
|
+
"Memory preview failed": "记忆预览失败",
|
|
135
|
+
"Preview the exact memory context for a user and selected sub-agent before a run. Memory is marked as data, not executable instructions.": "在运行前预览用户和所选子智能体的准确记忆上下文。记忆被标记为数据,而非可执行指令。",
|
|
136
|
+
"User ID": "用户 ID",
|
|
137
|
+
"User ID is required": "必须填写用户 ID",
|
|
138
|
+
"Build memory preview": "生成记忆预览",
|
|
139
|
+
"Final memory context": "最终记忆上下文",
|
|
140
|
+
"Character budget": "字符预算",
|
|
141
|
+
"Applied scopes": "已应用范围",
|
|
142
|
+
"None": "无",
|
|
143
|
+
"No memory context matched this preview.": "没有匹配此预览的记忆上下文。"
|
|
96
144
|
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { buildKnowledgeAccessMatrix, summarizeRetrievalSpan } from '../resources/agent-knowledge-insights';
|
|
3
|
+
|
|
4
|
+
describe('agent knowledge insights', () => {
|
|
5
|
+
it('explains assignment and explicit agent-policy decisions per employee and knowledge base', () => {
|
|
6
|
+
const matrix = buildKnowledgeAccessMatrix(
|
|
7
|
+
[
|
|
8
|
+
{
|
|
9
|
+
username: 'researcher',
|
|
10
|
+
knowledgeBase: { knowledgeBaseKeys: ['kb-public', 'kb-explicit'] },
|
|
11
|
+
roles: [{ name: 'research' }],
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
[
|
|
15
|
+
{ id: 'kb-public', name: 'Public docs', enabled: true, agentAccess: 'inherit', accessLevel: 'PUBLIC' },
|
|
16
|
+
{
|
|
17
|
+
id: 'kb-explicit',
|
|
18
|
+
name: 'Restricted docs',
|
|
19
|
+
enabled: true,
|
|
20
|
+
agentAccess: 'explicit',
|
|
21
|
+
allowedRoles: ['research'],
|
|
22
|
+
accessLevel: 'SHARED',
|
|
23
|
+
},
|
|
24
|
+
{ id: 'kb-unassigned', name: 'Unassigned docs', enabled: true, agentAccess: 'inherit' },
|
|
25
|
+
{ id: 'kb-disabled', name: 'Disabled docs', enabled: false, agentAccess: 'inherit' },
|
|
26
|
+
],
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
expect(matrix).toEqual(
|
|
30
|
+
expect.arrayContaining([
|
|
31
|
+
expect.objectContaining({ knowledgeBaseId: 'kb-public', access: 'allowed', assigned: true }),
|
|
32
|
+
expect.objectContaining({
|
|
33
|
+
knowledgeBaseId: 'kb-explicit',
|
|
34
|
+
access: 'allowed',
|
|
35
|
+
reason: expect.stringContaining('role'),
|
|
36
|
+
}),
|
|
37
|
+
expect.objectContaining({
|
|
38
|
+
knowledgeBaseId: 'kb-unassigned',
|
|
39
|
+
access: 'denied',
|
|
40
|
+
reason: expect.stringContaining('not assigned'),
|
|
41
|
+
}),
|
|
42
|
+
expect.objectContaining({
|
|
43
|
+
knowledgeBaseId: 'kb-disabled',
|
|
44
|
+
access: 'denied',
|
|
45
|
+
reason: expect.stringContaining('disabled'),
|
|
46
|
+
}),
|
|
47
|
+
]),
|
|
48
|
+
);
|
|
49
|
+
expect(matrix.find((row) => row.knowledgeBaseId === 'kb-explicit')?.userGate).toContain('allowed KB role');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('reads current NocoBase knowledgeBaseIds settings and removes duplicate assignments', () => {
|
|
53
|
+
const matrix = buildKnowledgeAccessMatrix(
|
|
54
|
+
[
|
|
55
|
+
{
|
|
56
|
+
username: 'current-config-agent',
|
|
57
|
+
knowledgeBase: { knowledgeBaseIds: ['kb-current', 'kb-current'] },
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
[{ id: 'kb-current', name: 'Current configuration', enabled: true, agentAccess: 'inherit' }],
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
expect(matrix).toEqual([
|
|
64
|
+
expect.objectContaining({
|
|
65
|
+
employeeUsername: 'current-config-agent',
|
|
66
|
+
knowledgeBaseId: 'kb-current',
|
|
67
|
+
assigned: true,
|
|
68
|
+
access: 'allowed',
|
|
69
|
+
}),
|
|
70
|
+
]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('returns a citation-only view of external RAG spans and never surfaces raw metadata', () => {
|
|
74
|
+
const trace = summarizeRetrievalSpan({
|
|
75
|
+
id: 42,
|
|
76
|
+
employeeUsername: 'researcher',
|
|
77
|
+
status: 'success',
|
|
78
|
+
input: { query: 'deployment' },
|
|
79
|
+
output: JSON.stringify({
|
|
80
|
+
query: 'deployment',
|
|
81
|
+
results: [
|
|
82
|
+
{
|
|
83
|
+
knowledgeBaseId: 'kb-public',
|
|
84
|
+
knowledgeBaseName: 'Public docs',
|
|
85
|
+
content: 'Use the deployment checklist before release.',
|
|
86
|
+
score: 0.98,
|
|
87
|
+
source: { id: 'document-1', filename: 'deploy.md', url: 'https://example.test/deploy.md' },
|
|
88
|
+
metadata: { apiKey: 'must-not-appear' },
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
}),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
expect(trace).toMatchObject({
|
|
95
|
+
id: 42,
|
|
96
|
+
decision: 'allowed',
|
|
97
|
+
query: 'deployment',
|
|
98
|
+
citations: [
|
|
99
|
+
{
|
|
100
|
+
knowledgeBaseId: 'kb-public',
|
|
101
|
+
filename: 'deploy.md',
|
|
102
|
+
score: 0.98,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
});
|
|
106
|
+
expect(JSON.stringify(trace)).not.toContain('must-not-appear');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('records a denial reason when the retrieval tool fails', () => {
|
|
110
|
+
const trace = summarizeRetrievalSpan({
|
|
111
|
+
status: 'error',
|
|
112
|
+
input: { query: 'private notes' },
|
|
113
|
+
error: 'Knowledge base is not assigned to this AI Employee.',
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
expect(trace).toMatchObject({
|
|
117
|
+
decision: 'denied',
|
|
118
|
+
query: 'private notes',
|
|
119
|
+
reason: 'Knowledge base is not assigned to this AI Employee.',
|
|
120
|
+
citations: [],
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createExternalRagSearchTool } from '../tools/external-rag-search';
|
|
3
|
+
|
|
4
|
+
function createToolHarness(knowledgeBase = { knowledgeBaseKeys: ['kb-allowed'] }) {
|
|
5
|
+
const searchKnowledgeBases = vi.fn(async () => [
|
|
6
|
+
{
|
|
7
|
+
id: 'segment-1',
|
|
8
|
+
content: 'Relevant deployment documentation',
|
|
9
|
+
score: 0.9,
|
|
10
|
+
metadata: {
|
|
11
|
+
documentId: 'doc-1',
|
|
12
|
+
filename: 'deployment.md',
|
|
13
|
+
apiKey: 'must-not-leak',
|
|
14
|
+
internalNotes: 'must-not-leak',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
]);
|
|
18
|
+
const repositories = {
|
|
19
|
+
aiEmployees: {
|
|
20
|
+
findOne: vi.fn(async () => ({ knowledgeBase })),
|
|
21
|
+
},
|
|
22
|
+
aiToolMessages: { findOne: vi.fn() },
|
|
23
|
+
aiConversations: { findOne: vi.fn() },
|
|
24
|
+
};
|
|
25
|
+
const plugin = { app: { log: { error: vi.fn() } } };
|
|
26
|
+
const tool = createExternalRagSearchTool(plugin);
|
|
27
|
+
const ctx = {
|
|
28
|
+
_currentAIEmployee: { username: 'researcher' },
|
|
29
|
+
app: {
|
|
30
|
+
pm: {
|
|
31
|
+
get: vi.fn((name: string) => (name === 'plugin-knowledge-base' ? { searchKnowledgeBases } : undefined)),
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
db: {
|
|
35
|
+
getRepository: vi.fn((name: keyof typeof repositories) => repositories[name]),
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return { tool, ctx, searchKnowledgeBases, repositories };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('external_rag_search', () => {
|
|
43
|
+
it('searches only knowledge bases assigned to the requesting AI Employee', async () => {
|
|
44
|
+
const { tool, ctx, searchKnowledgeBases } = createToolHarness();
|
|
45
|
+
|
|
46
|
+
const response = await tool.invoke(ctx, { query: 'deployment process' });
|
|
47
|
+
|
|
48
|
+
expect(searchKnowledgeBases).toHaveBeenCalledWith(
|
|
49
|
+
expect.objectContaining({
|
|
50
|
+
_currentAIEmployee: { username: 'researcher' },
|
|
51
|
+
state: expect.objectContaining({ currentAIEmployee: { username: 'researcher' } }),
|
|
52
|
+
}),
|
|
53
|
+
'deployment process',
|
|
54
|
+
expect.objectContaining({ knowledgeBaseIds: ['kb-allowed'], rerank: true }),
|
|
55
|
+
);
|
|
56
|
+
expect(response.status).toBe('success');
|
|
57
|
+
const content = JSON.parse(response.content) as { results: Array<{ metadata: Record<string, unknown> }> };
|
|
58
|
+
expect(content.results[0].metadata).toEqual({ documentId: 'doc-1', filename: 'deployment.md' });
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('rejects explicit knowledge base IDs that are not assigned to the AI Employee', async () => {
|
|
62
|
+
const { tool, ctx, searchKnowledgeBases } = createToolHarness();
|
|
63
|
+
|
|
64
|
+
const response = await tool.invoke(ctx, {
|
|
65
|
+
query: 'deployment process',
|
|
66
|
+
knowledgeBaseIds: ['kb-not-allowed'],
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(response).toEqual(
|
|
70
|
+
expect.objectContaining({ status: 'error', content: expect.stringContaining('not assigned to AI Employee') }),
|
|
71
|
+
);
|
|
72
|
+
expect(searchKnowledgeBases).not.toHaveBeenCalled();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('reads and de-duplicates current NocoBase knowledgeBaseIds settings', async () => {
|
|
76
|
+
const { tool, ctx, searchKnowledgeBases } = createToolHarness({
|
|
77
|
+
knowledgeBaseIds: ['kb-current', 'kb-current'],
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const response = await tool.invoke(ctx, { query: 'deployment process' });
|
|
81
|
+
|
|
82
|
+
expect(searchKnowledgeBases).toHaveBeenCalledWith(
|
|
83
|
+
expect.any(Object),
|
|
84
|
+
'deployment process',
|
|
85
|
+
expect.objectContaining({ knowledgeBaseIds: ['kb-current'] }),
|
|
86
|
+
);
|
|
87
|
+
expect(response.status).toBe('success');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('resolves the AI Employee from the tool call when runtime context has no employee', async () => {
|
|
91
|
+
const { tool, ctx, searchKnowledgeBases, repositories } = createToolHarness();
|
|
92
|
+
delete ctx._currentAIEmployee;
|
|
93
|
+
repositories.aiToolMessages.findOne.mockResolvedValue({ sessionId: 'session-1' });
|
|
94
|
+
repositories.aiConversations.findOne.mockResolvedValue({ aiEmployeeUsername: 'researcher' });
|
|
95
|
+
|
|
96
|
+
const response = await tool.invoke(ctx, { query: 'deployment process' }, { toolCallId: 'tool-call-1' });
|
|
97
|
+
|
|
98
|
+
expect(repositories.aiToolMessages.findOne).toHaveBeenCalledWith({ filter: { toolCallId: 'tool-call-1' } });
|
|
99
|
+
expect(repositories.aiConversations.findOne).toHaveBeenCalledWith({ filter: { sessionId: 'session-1' } });
|
|
100
|
+
expect(searchKnowledgeBases).toHaveBeenCalledWith(
|
|
101
|
+
expect.objectContaining({ _currentAIEmployee: { username: 'researcher' } }),
|
|
102
|
+
'deployment process',
|
|
103
|
+
expect.objectContaining({ knowledgeBaseIds: ['kb-allowed'] }),
|
|
104
|
+
);
|
|
105
|
+
expect(response.status).toBe('success');
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -2,7 +2,14 @@ import { describe, expect, it, vi } from 'vitest';
|
|
|
2
2
|
import { AgentMemoryContextService } from '../services/AgentMemoryContextService';
|
|
3
3
|
import { NativeSubAgentObserver } from '../services/NativeSubAgentObserver';
|
|
4
4
|
|
|
5
|
-
function createObserverHarness(
|
|
5
|
+
function createObserverHarness(
|
|
6
|
+
profileSettings: Record<string, unknown> | null = {},
|
|
7
|
+
options: {
|
|
8
|
+
memoryRows?: unknown[];
|
|
9
|
+
orchestratorConfig?: unknown;
|
|
10
|
+
knowledgeBasePlugin?: unknown;
|
|
11
|
+
} = {},
|
|
12
|
+
) {
|
|
6
13
|
let nextSpanId = 1;
|
|
7
14
|
const spanRepo = {
|
|
8
15
|
create: vi.fn(async ({ values }) => ({ id: nextSpanId++, ...values })),
|
|
@@ -53,7 +60,7 @@ function createObserverHarness(profileSettings: Record<string, unknown> | null =
|
|
|
53
60
|
findOne: vi.fn(async () => (profileSettings ? { settings: profileSettings } : null)),
|
|
54
61
|
},
|
|
55
62
|
agentMemoryContexts: {
|
|
56
|
-
find: vi.fn(async () => []),
|
|
63
|
+
find: vi.fn(async () => options.memoryRows ?? []),
|
|
57
64
|
},
|
|
58
65
|
aiToolMessages: {
|
|
59
66
|
findOne: vi.fn(async () => ({
|
|
@@ -70,6 +77,9 @@ function createObserverHarness(profileSettings: Record<string, unknown> | null =
|
|
|
70
77
|
: null,
|
|
71
78
|
),
|
|
72
79
|
},
|
|
80
|
+
orchestratorConfig: {
|
|
81
|
+
findOne: vi.fn(async () => options.orchestratorConfig ?? null),
|
|
82
|
+
},
|
|
73
83
|
};
|
|
74
84
|
const plugin = {
|
|
75
85
|
app: {
|
|
@@ -78,7 +88,11 @@ function createObserverHarness(profileSettings: Record<string, unknown> | null =
|
|
|
78
88
|
warn: vi.fn(),
|
|
79
89
|
},
|
|
80
90
|
pm: {
|
|
81
|
-
get: vi.fn((name) =>
|
|
91
|
+
get: vi.fn((name) => {
|
|
92
|
+
if (name === 'ai') return { subAgentsDispatcher: dispatcher };
|
|
93
|
+
if (name === 'plugin-knowledge-base') return options.knowledgeBasePlugin ?? null;
|
|
94
|
+
return null;
|
|
95
|
+
}),
|
|
82
96
|
getPlugins: vi.fn(() => new Map()),
|
|
83
97
|
},
|
|
84
98
|
},
|
|
@@ -189,7 +203,7 @@ describe('NativeSubAgentObserver', () => {
|
|
|
189
203
|
});
|
|
190
204
|
|
|
191
205
|
describe('AgentMemoryContextService', () => {
|
|
192
|
-
it('
|
|
206
|
+
it('prioritizes agent-user context before user and public memory', async () => {
|
|
193
207
|
const rows = [
|
|
194
208
|
{ scope: 'public', enabled: true, userId: null, aiEmployeeUsername: '', contentMd: 'Public fact' },
|
|
195
209
|
{ scope: 'user', enabled: true, userId: 7, aiEmployeeUsername: '', contentMd: 'User context' },
|
|
@@ -237,10 +251,78 @@ describe('AgentMemoryContextService', () => {
|
|
|
237
251
|
settings: { memoryScopes: ['public', 'user', 'agent_user'], maxMemoryContextChars: 10000 },
|
|
238
252
|
});
|
|
239
253
|
|
|
240
|
-
expect(result.appliedScopes).toEqual(['
|
|
241
|
-
expect(result.context.indexOf('
|
|
254
|
+
expect(result.appliedScopes).toEqual(['agent_user', 'user-memory', 'user', 'public']);
|
|
255
|
+
expect(result.context.indexOf('Private graph')).toBeLessThan(result.context.indexOf('<user_memory>'));
|
|
242
256
|
expect(result.context.indexOf('<user_memory>')).toBeLessThan(result.context.indexOf('User context'));
|
|
243
|
-
expect(result.context.indexOf('User context')).toBeLessThan(result.context.indexOf('
|
|
257
|
+
expect(result.context.indexOf('User context')).toBeLessThan(result.context.indexOf('Public fact'));
|
|
244
258
|
expect(result.context).not.toContain('Other private');
|
|
245
259
|
});
|
|
260
|
+
|
|
261
|
+
it('does not inject any memory when a profile explicitly selects no scopes', async () => {
|
|
262
|
+
const plugin = {
|
|
263
|
+
app: { logger: { warn: vi.fn() }, pm: { get: vi.fn() } },
|
|
264
|
+
db: {
|
|
265
|
+
getRepository: vi.fn(() => ({
|
|
266
|
+
find: vi.fn(async () => [{ scope: 'public', enabled: true, userId: null, contentMd: 'Public fact' }]),
|
|
267
|
+
})),
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
const service = new AgentMemoryContextService(plugin);
|
|
271
|
+
|
|
272
|
+
await expect(
|
|
273
|
+
service.buildContext({
|
|
274
|
+
userId: 7,
|
|
275
|
+
aiEmployeeUsername: 'sub-agent',
|
|
276
|
+
settings: { memoryScopes: [] },
|
|
277
|
+
}),
|
|
278
|
+
).resolves.toEqual({ context: '', appliedScopes: [], chars: 0 });
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('uses the leader-to-sub-agent harness tag when no explicit tag is supplied', async () => {
|
|
282
|
+
const { plugin } = createObserverHarness(null, {
|
|
283
|
+
orchestratorConfig: { harnessTag: 'safe' },
|
|
284
|
+
});
|
|
285
|
+
const profileRepo = plugin.db.getRepository('agentHarnessProfiles') as {
|
|
286
|
+
findOne: ReturnType<typeof vi.fn>;
|
|
287
|
+
};
|
|
288
|
+
profileRepo.findOne.mockImplementation(async ({ filter }: { filter: { tag: string } }) =>
|
|
289
|
+
filter.tag === 'safe' ? { settings: { maxMemoryContextChars: 1200 } } : null,
|
|
290
|
+
);
|
|
291
|
+
const service = new AgentMemoryContextService(plugin);
|
|
292
|
+
|
|
293
|
+
await expect(
|
|
294
|
+
service.resolvePolicySettings({ ctx: createTask().ctx, employee: { username: 'sub-agent' } }),
|
|
295
|
+
).resolves.toEqual(expect.objectContaining({ harnessTag: 'safe', maxMemoryContextChars: 1200 }));
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe('NativeSubAgentObserver memory injection', () => {
|
|
300
|
+
it('places reference memory before the immutable agent task', async () => {
|
|
301
|
+
const { plugin, dispatcher, originalRun } = createObserverHarness(
|
|
302
|
+
{},
|
|
303
|
+
{
|
|
304
|
+
memoryRows: [{ scope: 'public', enabled: true, userId: null, contentMd: 'Reference fact' }],
|
|
305
|
+
},
|
|
306
|
+
);
|
|
307
|
+
const observer = new NativeSubAgentObserver(plugin);
|
|
308
|
+
observer.install();
|
|
309
|
+
|
|
310
|
+
await dispatcher.run(createTask());
|
|
311
|
+
|
|
312
|
+
const question = originalRun.mock.calls[0][0].question as string;
|
|
313
|
+
expect(question).toContain('<agent_memory_context>');
|
|
314
|
+
expect(question).toContain('<agent_task>\ndo the work\n</agent_task>');
|
|
315
|
+
expect(question.indexOf('Reference fact')).toBeLessThan(question.indexOf('<agent_task>'));
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('runs the native sub-agent with its Knowledge Base request identity', async () => {
|
|
319
|
+
const runWithAgentContext = vi.fn(async (_username: string, callback: () => Promise<string>) => callback());
|
|
320
|
+
const { plugin, dispatcher } = createObserverHarness({}, { knowledgeBasePlugin: { runWithAgentContext } });
|
|
321
|
+
const observer = new NativeSubAgentObserver(plugin);
|
|
322
|
+
observer.install();
|
|
323
|
+
|
|
324
|
+
await dispatcher.run(createTask());
|
|
325
|
+
|
|
326
|
+
expect(runWithAgentContext).toHaveBeenCalledWith('sub-agent', expect.any(Function));
|
|
327
|
+
});
|
|
246
328
|
});
|