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
|
@@ -2,6 +2,56 @@ import { z } from 'zod';
|
|
|
2
2
|
|
|
3
3
|
const TOOL_NAME = 'external_rag_search';
|
|
4
4
|
const MAX_CONTENT_LENGTH = 4000;
|
|
5
|
+
const MAX_METADATA_VALUE_LENGTH = 500;
|
|
6
|
+
const METADATA_FIELDS = [
|
|
7
|
+
'id',
|
|
8
|
+
'title',
|
|
9
|
+
'filename',
|
|
10
|
+
'fileName',
|
|
11
|
+
'name',
|
|
12
|
+
'source',
|
|
13
|
+
'url',
|
|
14
|
+
'fileUrl',
|
|
15
|
+
'sourceUrl',
|
|
16
|
+
'collection',
|
|
17
|
+
'collectionName',
|
|
18
|
+
'recordId',
|
|
19
|
+
'rowId',
|
|
20
|
+
'documentId',
|
|
21
|
+
'docId',
|
|
22
|
+
'fileId',
|
|
23
|
+
'page',
|
|
24
|
+
'pageNumber',
|
|
25
|
+
'chunkIndex',
|
|
26
|
+
] as const;
|
|
27
|
+
|
|
28
|
+
type RecordLike = Record<string, unknown>;
|
|
29
|
+
|
|
30
|
+
type Repository = {
|
|
31
|
+
findOne?: (options: RecordLike) => Promise<unknown>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type ToolContext = {
|
|
35
|
+
app?: {
|
|
36
|
+
pm?: {
|
|
37
|
+
get?: (name: string) => unknown;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
db?: {
|
|
41
|
+
getRepository?: (name: string) => Repository | undefined;
|
|
42
|
+
};
|
|
43
|
+
state?: RecordLike;
|
|
44
|
+
_currentAIEmployee?: unknown;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type ToolRuntime = {
|
|
48
|
+
toolCallId?: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type ResolvedAgent = {
|
|
52
|
+
username: string;
|
|
53
|
+
knowledgeBaseIds: string[];
|
|
54
|
+
};
|
|
5
55
|
|
|
6
56
|
function truncate(value: unknown, max = MAX_CONTENT_LENGTH) {
|
|
7
57
|
const text = typeof value === 'string' ? value : value == null ? '' : String(value);
|
|
@@ -20,10 +70,41 @@ function firstString(...values: unknown[]) {
|
|
|
20
70
|
return undefined;
|
|
21
71
|
}
|
|
22
72
|
|
|
23
|
-
function
|
|
24
|
-
|
|
73
|
+
function toRecord(value: unknown): RecordLike {
|
|
74
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? (value as RecordLike) : {};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function readModelValue(record: unknown, key: string): unknown {
|
|
78
|
+
const model = record as { get?: (name: string) => unknown; [key: string]: unknown };
|
|
79
|
+
return typeof model?.get === 'function' ? model.get(key) : model?.[key];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function toPlain(record: unknown): RecordLike {
|
|
83
|
+
const model = record as { toJSON?: () => unknown };
|
|
84
|
+
return toRecord(typeof model?.toJSON === 'function' ? model.toJSON() : record);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function sanitizeMetadata(value: unknown): RecordLike {
|
|
88
|
+
const metadata = toRecord(value);
|
|
89
|
+
return Object.fromEntries(
|
|
90
|
+
METADATA_FIELDS.flatMap((key) => {
|
|
91
|
+
const field = metadata[key];
|
|
92
|
+
if (typeof field === 'string') {
|
|
93
|
+
return [[key, truncate(field, MAX_METADATA_VALUE_LENGTH)]];
|
|
94
|
+
}
|
|
95
|
+
if (typeof field === 'number' || typeof field === 'boolean') {
|
|
96
|
+
return [[key, field]];
|
|
97
|
+
}
|
|
98
|
+
return [];
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function normalizeResult(result: unknown) {
|
|
104
|
+
const record = toRecord(result);
|
|
105
|
+
const metadata = sanitizeMetadata(record.metadata);
|
|
25
106
|
const sourceId = firstString(
|
|
26
|
-
|
|
107
|
+
record.id,
|
|
27
108
|
metadata.id,
|
|
28
109
|
metadata.sourceId,
|
|
29
110
|
metadata.documentId,
|
|
@@ -34,10 +115,10 @@ function normalizeResult(result: any) {
|
|
|
34
115
|
const filename = firstString(metadata.filename, metadata.fileName, metadata.name, metadata.title, metadata.source);
|
|
35
116
|
|
|
36
117
|
return {
|
|
37
|
-
content: truncate(
|
|
38
|
-
score: Number(
|
|
39
|
-
knowledgeBaseId:
|
|
40
|
-
knowledgeBaseName:
|
|
118
|
+
content: truncate(record.content),
|
|
119
|
+
score: Number(record.rerankScore ?? record.score ?? record.vectorScore ?? 0),
|
|
120
|
+
knowledgeBaseId: record.knowledgeBaseId,
|
|
121
|
+
knowledgeBaseName: record.knowledgeBaseName,
|
|
41
122
|
source: {
|
|
42
123
|
id: sourceId,
|
|
43
124
|
filename,
|
|
@@ -49,6 +130,87 @@ function normalizeResult(result: any) {
|
|
|
49
130
|
};
|
|
50
131
|
}
|
|
51
132
|
|
|
133
|
+
function getContextAgentUsername(ctx: ToolContext): string | undefined {
|
|
134
|
+
const direct = ctx._currentAIEmployee ?? ctx.state?.currentAIEmployee;
|
|
135
|
+
if (typeof direct === 'string' && direct.trim()) {
|
|
136
|
+
return direct.trim();
|
|
137
|
+
}
|
|
138
|
+
const employee = toRecord(direct);
|
|
139
|
+
return firstString(employee.username, employee.name);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function resolveAgentFromToolCall(ctx: ToolContext, runtime?: ToolRuntime): Promise<string | undefined> {
|
|
143
|
+
const direct = getContextAgentUsername(ctx);
|
|
144
|
+
if (direct) {
|
|
145
|
+
return direct;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const toolCallId = runtime?.toolCallId;
|
|
149
|
+
if (!toolCallId) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const toolMessage = await ctx.db?.getRepository?.('aiToolMessages')?.findOne?.({
|
|
154
|
+
filter: { toolCallId },
|
|
155
|
+
});
|
|
156
|
+
const sessionId = firstString(readModelValue(toolMessage, 'sessionId'));
|
|
157
|
+
if (!sessionId) {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const conversation = await ctx.db?.getRepository?.('aiConversations')?.findOne?.({
|
|
162
|
+
filter: { sessionId },
|
|
163
|
+
});
|
|
164
|
+
return firstString(readModelValue(conversation, 'aiEmployeeUsername'));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function readKnowledgeBaseIds(employee: unknown): string[] {
|
|
168
|
+
const settings = toRecord(readModelValue(employee, 'knowledgeBase'));
|
|
169
|
+
// NocoBase currently persists this setting as `knowledgeBaseIds`; early
|
|
170
|
+
// orchestrator configurations used `knowledgeBaseKeys`. Prefer the legacy
|
|
171
|
+
// value when it is populated, but fall back to the current field so either
|
|
172
|
+
// configuration can enforce the same retrieval boundary.
|
|
173
|
+
const legacyIds = settings.knowledgeBaseKeys;
|
|
174
|
+
const ids = Array.isArray(legacyIds) && legacyIds.length ? legacyIds : settings.knowledgeBaseIds;
|
|
175
|
+
return Array.isArray(ids)
|
|
176
|
+
? Array.from(
|
|
177
|
+
new Set(
|
|
178
|
+
ids.filter((id): id is string | number => typeof id === 'string' || typeof id === 'number').map(String),
|
|
179
|
+
),
|
|
180
|
+
)
|
|
181
|
+
: [];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async function resolveAgent(ctx: ToolContext, runtime?: ToolRuntime): Promise<ResolvedAgent | undefined> {
|
|
185
|
+
const username = await resolveAgentFromToolCall(ctx, runtime);
|
|
186
|
+
if (!username) {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const employee = await ctx.db?.getRepository?.('aiEmployees')?.findOne?.({
|
|
191
|
+
filter: { username },
|
|
192
|
+
});
|
|
193
|
+
if (!employee) {
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
username,
|
|
199
|
+
knowledgeBaseIds: readKnowledgeBaseIds(employee),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function withAgentIdentity(ctx: ToolContext, username: string): ToolContext {
|
|
204
|
+
const scoped = Object.create(ctx) as ToolContext;
|
|
205
|
+
const employee = { username };
|
|
206
|
+
scoped._currentAIEmployee = employee;
|
|
207
|
+
scoped.state = {
|
|
208
|
+
...(ctx.state ?? {}),
|
|
209
|
+
currentAIEmployee: employee,
|
|
210
|
+
};
|
|
211
|
+
return scoped;
|
|
212
|
+
}
|
|
213
|
+
|
|
52
214
|
export function createExternalRagSearchTool(plugin: any) {
|
|
53
215
|
return {
|
|
54
216
|
scope: 'CUSTOM' as const,
|
|
@@ -85,15 +247,54 @@ The search may be served by an external RAG service. Results include content plu
|
|
|
85
247
|
},
|
|
86
248
|
|
|
87
249
|
invoke: async (
|
|
88
|
-
ctx:
|
|
250
|
+
ctx: ToolContext,
|
|
89
251
|
args: { query?: string; knowledgeBaseIds?: string[]; topK?: number; scoreThreshold?: number },
|
|
252
|
+
runtime?: ToolRuntime,
|
|
90
253
|
) => {
|
|
91
254
|
const query = typeof args?.query === 'string' ? args.query.trim() : '';
|
|
92
255
|
if (!query) {
|
|
93
256
|
return { status: 'error' as const, content: 'Missing required field: query.' };
|
|
94
257
|
}
|
|
95
258
|
|
|
96
|
-
const
|
|
259
|
+
const agent = await resolveAgent(ctx, runtime);
|
|
260
|
+
if (!agent) {
|
|
261
|
+
return {
|
|
262
|
+
status: 'error' as const,
|
|
263
|
+
content: 'Unable to determine the requesting AI Employee. Knowledge base search is denied.',
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
if (!agent.knowledgeBaseIds.length) {
|
|
267
|
+
return {
|
|
268
|
+
status: 'error' as const,
|
|
269
|
+
content: `AI Employee "${agent.username}" has no assigned knowledge bases.`,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const requestedIds = Array.isArray(args.knowledgeBaseIds) ? args.knowledgeBaseIds.map(String) : undefined;
|
|
274
|
+
const unauthorizedIds = requestedIds?.filter((id) => !agent.knowledgeBaseIds.includes(id)) ?? [];
|
|
275
|
+
if (unauthorizedIds.length) {
|
|
276
|
+
return {
|
|
277
|
+
status: 'error' as const,
|
|
278
|
+
content: `Knowledge base IDs are not assigned to AI Employee "${agent.username}": ${unauthorizedIds.join(
|
|
279
|
+
', ',
|
|
280
|
+
)}.`,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const kbPlugin = ctx.app?.pm?.get?.('plugin-knowledge-base') as
|
|
285
|
+
| {
|
|
286
|
+
searchKnowledgeBases?: (
|
|
287
|
+
requestContext: ToolContext,
|
|
288
|
+
searchQuery: string,
|
|
289
|
+
options: {
|
|
290
|
+
knowledgeBaseIds: string[];
|
|
291
|
+
topK?: number;
|
|
292
|
+
scoreThreshold?: number;
|
|
293
|
+
rerank: boolean;
|
|
294
|
+
},
|
|
295
|
+
) => Promise<unknown[]>;
|
|
296
|
+
}
|
|
297
|
+
| undefined;
|
|
97
298
|
if (!kbPlugin?.searchKnowledgeBases) {
|
|
98
299
|
return {
|
|
99
300
|
status: 'error' as const,
|
|
@@ -102,8 +303,8 @@ The search may be served by an external RAG service. Results include content plu
|
|
|
102
303
|
}
|
|
103
304
|
|
|
104
305
|
try {
|
|
105
|
-
const results = await kbPlugin.searchKnowledgeBases(ctx, query, {
|
|
106
|
-
knowledgeBaseIds:
|
|
306
|
+
const results = await kbPlugin.searchKnowledgeBases(withAgentIdentity(ctx, agent.username), query, {
|
|
307
|
+
knowledgeBaseIds: requestedIds ?? agent.knowledgeBaseIds,
|
|
107
308
|
topK: args.topK,
|
|
108
309
|
scoreThreshold: args.scoreThreshold,
|
|
109
310
|
rerank: true,
|
|
@@ -113,14 +314,14 @@ The search may be served by an external RAG service. Results include content plu
|
|
|
113
314
|
status: 'success' as const,
|
|
114
315
|
content: JSON.stringify({
|
|
115
316
|
query,
|
|
116
|
-
results:
|
|
317
|
+
results: results.map(normalizeResult),
|
|
117
318
|
}),
|
|
118
319
|
};
|
|
119
|
-
} catch (error:
|
|
320
|
+
} catch (error: unknown) {
|
|
120
321
|
plugin.app.log?.error?.('[AgentOrchestrator] external_rag_search failed', error);
|
|
121
322
|
return {
|
|
122
323
|
status: 'error' as const,
|
|
123
|
-
content: `External RAG search failed: ${error
|
|
324
|
+
content: `External RAG search failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
124
325
|
};
|
|
125
326
|
}
|
|
126
327
|
},
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
"use strict";(self.webpackChunkplugin_agent_orchestrator_client_v2=self.webpackChunkplugin_agent_orchestrator_client_v2||[]).push([["418"],{393:function(e,t,r){r.r(t),r.d(t,{default:function(){return g}});var n=r(155),a=r.n(n),l=r(59),o=r(375),i=r(608),u=r(603);function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function s(e,t,r,n,a,l,o){try{var i=e[l](o),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,a)}function f(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var l=e.apply(t,r);function o(e){s(l,n,a,o,i,"next",e)}function i(e){s(l,n,a,o,i,"throw",e)}o(void 0)})}}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,a=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var l=[],o=!0,i=!1;try{for(a=a.call(e);!(o=(r=a.next()).done)&&(l.push(r.value),!t||l.length!==t);o=!0);}catch(e){i=!0,n=e}finally{try{o||null==a.return||a.return()}finally{if(i)throw n}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return c(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return c(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(e,t){var r,n,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(l=0)),l;)try{if(r=1,n&&(a=2&c[0]?n.return:c[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,c[1])).done)return a;switch(n=0,a&&(c=[2&c[0],a.value]),c[0]){case 0:case 1:a=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,n=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(a=(a=l.trys).length>0&&a[a.length-1])&&(6===c[0]||2===c[0])){l=0;continue}if(3===c[0]&&(!a||c[1]>a[0]&&c[1]<a[3])){l.label=c[1];break}if(6===c[0]&&l.label<a[1]){l.label=a[1],a=c;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(c);break}a[2]&&l.ops.pop(),l.trys.pop();continue}c=t.call(e,l)}catch(e){c=[6,e],n=0}finally{r=a=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var m=l.Typography.Text,y=function(e){var t=String(e||"").trim();return t?JSON.parse(t):{}},b=function(){var e=(0,i.R)(),t=(0,u.k)(),r=p(a().useState(!1),2),n=r[0],c=r[1],s=p(a().useState(null),2),b=s[0],g=s[1],v=p(l.Form.useForm(),1)[0],h=(0,i.b)({url:"agentHarnessProfiles:list",params:{sort:["tag"],pageSize:100}}),w=h.data,O=h.loading,S=h.refresh,E=a().useMemo(function(){var e=null==w?void 0:w.data;return Array.isArray(e)?e:[]},[w]),k=function(e){var t,r;g(e||null),v.resetFields(),v.setFieldsValue(e?(t=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({},e),r=r={settingsText:JSON.stringify(e.settings||{},null,2)},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}),t):{tag:"",title:"",description:"",enabled:!0,settingsText:JSON.stringify({nativeObserverEnabled:!0,memoryInjectionEnabled:!0,memoryScopes:["public","user","agent_user"],knowledgeScopes:["public","private"],maxMemoryContextChars:6e3,tracingRetentionDays:30},null,2)}),c(!0)},P=function(){c(!1),g(null)},j=[{title:t("Tag"),dataIndex:"tag",key:"tag",width:140,render:function(e){return a().createElement(l.Tag,{color:"blue"},e)}},{title:t("Title"),dataIndex:"title",key:"title",render:function(e,t){return e||t.tag}},{title:t("Enabled"),dataIndex:"enabled",key:"enabled",width:90,render:function(t,r){return a().createElement(l.Switch,{size:"small",checked:!1!==t,onChange:function(t){return f(function(){return d(this,function(n){switch(n.label){case 0:return[4,e.request({url:"agentHarnessProfiles:update",method:"put",params:{filterByTk:r.id},data:{enabled:t}})];case 1:return n.sent(),S(),[2]}})})()}})}},{title:t("Settings"),key:"settings",render:function(e,t){return a().createElement(l.Space,{size:4,wrap:!0},Object.entries(t.settings||{}).slice(0,5).map(function(e){var t=p(e,2),r=t[0],n=t[1];return a().createElement(l.Tag,{key:r},r,": ",String(n))}))}},{title:t("Actions"),key:"actions",width:150,render:function(r,n){return a().createElement(l.Space,null,a().createElement(l.Button,{type:"link",size:"small",icon:a().createElement(o.EditOutlined,null),onClick:function(){return k(n)}},t("Edit")),a().createElement(l.Popconfirm,{title:t("Delete this profile?"),onConfirm:function(){var r;return r=n.id,f(function(){var n;return d(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),[4,e.request({url:"agentHarnessProfiles:destroy",method:"delete",params:{filterByTk:r}})];case 1:return a.sent(),l.message.success(t("Policy profile deleted")),S(),[3,3];case 2:return n=a.sent(),l.message.error(t("Delete failed: {{message}}",{message:(null==n?void 0:n.message)||t("unknown error")})),[3,3];case 3:return[2]}})})()}},a().createElement(l.Button,{type:"link",size:"small",danger:!0,icon:a().createElement(o.DeleteOutlined,null)},t("Delete"))))}}];return a().createElement("div",null,a().createElement(l.Card,{bordered:!1},a().createElement(l.Space,{direction:"vertical",size:16,style:{width:"100%"}},a().createElement("div",{style:{display:"flex",justifyContent:"space-between",gap:16}},a().createElement(m,{type:"secondary"},t("Policy profiles control native observer, tracing retention, and memory/knowledge scopes.")),a().createElement(l.Button,{type:"primary",icon:a().createElement(o.PlusOutlined,null),onClick:function(){return k()}},t("New Policy"))),a().createElement(l.Table,{rowKey:"id",loading:O,dataSource:E,columns:j,pagination:!1,scroll:{x:"max-content"}}))),a().createElement(l.Drawer,{title:b?t("Edit Policy Profile"):t("New Policy Profile"),width:560,open:n,onClose:P,extra:a().createElement(l.Space,null,a().createElement(l.Button,{onClick:P},t("Cancel")),a().createElement(l.Button,{type:"primary",onClick:function(){return v.submit()}},t("Save")))},a().createElement(l.Form,{form:v,layout:"vertical",onFinish:function(r){return f(function(){var n,a,o,i,u,c,s,f;return d(this,function(p){switch(p.label){case 0:try{n=y(r.settingsText)}catch(e){return l.message.error(t("Settings JSON is invalid: {{message}}",{message:(null==e?void 0:e.message)||e})),[2]}a={tag:String(r.tag||"").trim(),title:r.title,description:r.description,enabled:!1!==r.enabled,settings:n},p.label=1;case 1:if(p.trys.push([1,6,,7]),!b)return[3,3];return[4,e.request({url:"agentHarnessProfiles:update",method:"put",params:{filterByTk:b.id},data:a})];case 2:return p.sent(),l.message.success(t("Policy profile updated")),[3,5];case 3:return[4,e.request({url:"agentHarnessProfiles:create",method:"post",data:a})];case 4:p.sent(),l.message.success(t("Policy profile created")),p.label=5;case 5:return P(),S(),[3,7];case 6:return f=(null==(o=p.sent())||null==(s=o.response)||null==(c=s.data)||null==(u=c.errors)||null==(i=u[0])?void 0:i.message)||(null==o?void 0:o.message)||"unknown error",l.message.error(t("Save failed: {{message}}",{message:f})),[3,7];case 7:return[2]}})})()}},a().createElement(l.Form.Item,{name:"tag",label:t("Tag"),rules:[{required:!0,message:t("Tag is required")}]},a().createElement(l.Input,{placeholder:t("default"),disabled:(null==b?void 0:b.tag)==="default"})),a().createElement(l.Form.Item,{name:"title",label:t("Title")},a().createElement(l.Input,null)),a().createElement(l.Form.Item,{name:"description",label:t("Description")},a().createElement(l.Input.TextArea,{rows:3})),a().createElement(l.Form.Item,{name:"settingsText",label:t("Settings JSON"),rules:[{required:!0,message:t("Settings JSON is required")}]},a().createElement(l.Input.TextArea,{rows:12,spellCheck:!1})),a().createElement(l.Form.Item,{name:"enabled",label:t("Enabled"),valuePropName:"checked"},a().createElement(l.Switch,null)))))},g=function(){return a().createElement("div",{style:{padding:"0 24px 24px"}},a().createElement(b,null))}},608:function(e,t,r){r.d(t,{R:function(){return c},b:function(){return s}});var n=r(485),a=r(155);function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function o(e,t,r,n,a,l,o){try{var i=e[l](o),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,a)}function i(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,a=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var l=[],o=!0,i=!1;try{for(a=a.call(e);!(o=(r=a.next()).done)&&(l.push(r.value),!t||l.length!==t);o=!0);}catch(e){i=!0,n=e}finally{try{o||null==a.return||a.return()}finally{if(i)throw n}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return l(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return l(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e){return e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function c(){return(0,n.useApp)().apiClient}function s(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=c(),n=t.manual,l=void 0!==n&&n,s=t.refreshDeps,f=t.onSuccess,p=t.onError,d=i((0,a.useState)(void 0),2),m=d[0],y=d[1],b=i((0,a.useState)(!l),2),g=b[0],v=b[1],h=i((0,a.useState)(void 0),2),w=h[0],O=h[1],S=(0,a.useRef)(e);S.current=e;var E=(0,a.useRef)(f);E.current=f;var k=(0,a.useRef)(p);k.current=p;var P=(0,a.useCallback)(function(e){var t;return(t=function(){var t,n,a,l,o,i,c;return function(e,t){var r,n,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(l=0)),l;)try{if(r=1,n&&(a=2&c[0]?n.return:c[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,c[1])).done)return a;switch(n=0,a&&(c=[2&c[0],a.value]),c[0]){case 0:case 1:a=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,n=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(a=(a=l.trys).length>0&&a[a.length-1])&&(6===c[0]||2===c[0])){l=0;continue}if(3===c[0]&&(!a||c[1]>a[0]&&c[1]<a[3])){l.label=c[1];break}if(6===c[0]&&l.label<a[1]){l.label=a[1],a=c;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(c);break}a[2]&&l.ops.pop(),l.trys.pop();continue}c=t.call(e,l)}catch(e){c=[6,e],n=0}finally{r=a=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(s){switch(s.label){case 0:t=S.current,v(!0),O(void 0),s.label=1;case 1:if(s.trys.push([1,6,7,8]),"function"!=typeof t)return[3,3];return[4,t()];case 2:return a=s.sent(),[3,5];case 3:return[4,r.request({url:t.url,method:t.method||"get",params:function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({},t.params||{},e||{}),data:t.data})];case 4:a=(o=null==(l=s.sent())?void 0:l.data)&&(void 0===o?"undefined":u(o))==="object"&&o.data&&"object"===u(o.data)&&"data"in o.data?o.data:o,s.label=5;case 5:return y(a),null==(n=E.current)||n.call(E,a),[2,a];case 6:return O(i=s.sent()),null==(c=k.current)||c.call(k,i),[2,void 0];case 7:return v(!1),[7];case 8:return[2]}})},function(){var e=this,r=arguments;return new Promise(function(n,a){var l=t.apply(e,r);function i(e){o(l,n,a,i,u,"next",e)}function u(e){o(l,n,a,i,u,"throw",e)}i(void 0)})})()},[r]),j=(0,a.useCallback)(function(){P()},[P]);return(0,a.useEffect)(function(){l||P()},void 0===s?[]:s),{data:m,loading:g,error:w,refresh:j,run:P}}},603:function(e,t,r){r.d(t,{k:function(){return l}});var n=r(485),a=r(155);function l(){var e=(0,n.useApp)();return(0,a.useCallback)(function(t,r){return e.i18n.t(t,function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({ns:["plugin-agent-orchestrator","client"]},r))},[e.i18n])}}}]);
|