@nocobase/plugin-ai 2.4.0-alpha.2 → 2.4.0-alpha.4
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/ai/docs/nocobase/ops-management/migration-manager/built-in-tables.md +0 -1
- package/dist/client/{244.276308c9b2090ec2.js → 244.12a92ac906b07849.js} +1 -1
- package/dist/client/index.js +3 -3
- package/dist/client-v2/{244.e85b8d4659ca66c0.js → 244.a0c8684f23fa5fa9.js} +1 -1
- package/dist/client-v2/index.js +1 -1
- package/dist/common/ai-employee-validation.d.ts +2 -0
- package/dist/common/ai-employee-validation.js +6 -0
- package/dist/common/error-codes.d.ts +1 -0
- package/dist/common/error-codes.js +3 -0
- package/dist/externalVersion.js +15 -15
- package/dist/locale/de-DE.json +0 -11
- package/dist/locale/en-US.json +3 -12
- package/dist/locale/es-ES.json +0 -11
- package/dist/locale/fr-FR.json +0 -11
- package/dist/locale/hu-HU.json +0 -11
- package/dist/locale/id-ID.json +0 -11
- package/dist/locale/it-IT.json +0 -11
- package/dist/locale/ja-JP.json +0 -11
- package/dist/locale/ko-KR.json +0 -11
- package/dist/locale/nl-NL.json +0 -11
- package/dist/locale/pt-BR.json +0 -11
- package/dist/locale/ru-RU.json +0 -11
- package/dist/locale/tr-TR.json +0 -11
- package/dist/locale/uk-UA.json +0 -11
- package/dist/locale/vi-VN.json +0 -11
- package/dist/locale/zh-CN.json +3 -12
- package/dist/locale/zh-TW.json +0 -11
- package/dist/node_modules/@langchain/mistralai/package.json +1 -1
- package/dist/node_modules/@langchain/xai/package.json +1 -1
- package/dist/node_modules/fs-extra/package.json +1 -1
- package/dist/node_modules/jsonrepair/package.json +1 -1
- package/dist/node_modules/just-bash/package.json +1 -1
- package/dist/node_modules/nodejs-snowflake/package.json +1 -1
- package/dist/node_modules/openai/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/ai-employees/ai-employee.d.ts +28 -1
- package/dist/server/ai-employees/ai-employee.js +257 -34
- package/dist/server/ai-employees/ai-knowledge-base.js +11 -4
- package/dist/server/ai-employees/middleware/conversation.js +19 -20
- package/dist/server/ai-employees/middleware/index.d.ts +1 -0
- package/dist/server/ai-employees/middleware/index.js +2 -0
- package/dist/server/ai-employees/middleware/tool-result-integrity.d.ts +22 -0
- package/dist/server/ai-employees/middleware/tool-result-integrity.js +211 -0
- package/dist/server/manager/ai-context-datasource-manager.d.ts +10 -12
- package/dist/server/manager/ai-context-datasource-manager.js +0 -3
- package/dist/server/plugin.d.ts +0 -4
- package/dist/server/plugin.js +1 -14
- package/dist/server/resource/aiEmployees.js +26 -0
- package/package.json +2 -2
- package/dist/client-v2/ai-employees/context/datasource.d.ts +0 -10
- package/dist/client-v2/ai-employees/datasource/DatasourceSelector.d.ts +0 -21
- package/dist/client-v2/pages/DatasourceSettingsPage.d.ts +0 -62
- package/dist/collections/ai-context-datasource.d.ts +0 -25
- package/dist/collections/ai-context-datasource.js +0 -89
- package/dist/server/collections/ai-context-datasource.d.ts +0 -10
- package/dist/server/collections/ai-context-datasource.js +0 -44
- package/dist/server/resource/aiContextDatasources.d.ts +0 -10
- package/dist/server/resource/aiContextDatasources.js +0 -45
|
@@ -0,0 +1,211 @@
|
|
|
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 tool_result_integrity_exports = {};
|
|
28
|
+
__export(tool_result_integrity_exports, {
|
|
29
|
+
isToolCallHistoryValid: () => isToolCallHistoryValid,
|
|
30
|
+
normalizeToolCallHistory: () => normalizeToolCallHistory,
|
|
31
|
+
toolResultIntegrityMiddleware: () => toolResultIntegrityMiddleware
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(tool_result_integrity_exports);
|
|
34
|
+
var import_messages = require("@langchain/core/messages");
|
|
35
|
+
var import_langchain = require("langchain");
|
|
36
|
+
const SYNTHETIC_TOOL_RESULT_ERROR = "Tool execution was interrupted before a result was recorded.";
|
|
37
|
+
const getValidToolCalls = (message) => (message.tool_calls ?? []).filter((toolCall) => typeof toolCall.id === "string" && toolCall.id.length > 0);
|
|
38
|
+
const isToolCallHistoryValid = (messages) => {
|
|
39
|
+
for (let index = 0; index < messages.length; index++) {
|
|
40
|
+
const message = messages[index];
|
|
41
|
+
if (import_messages.ToolMessage.isInstance(message)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (!import_messages.AIMessage.isInstance(message)) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const toolCalls = getValidToolCalls(message);
|
|
48
|
+
if (!toolCalls.length) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const expectedToolCallIds = new Set(toolCalls.map((toolCall) => toolCall.id));
|
|
52
|
+
const seenToolResultIds = /* @__PURE__ */ new Set();
|
|
53
|
+
for (let resultIndex = 0; resultIndex < toolCalls.length; resultIndex++) {
|
|
54
|
+
index++;
|
|
55
|
+
if (index >= messages.length) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const result = messages[index];
|
|
59
|
+
if (!import_messages.ToolMessage.isInstance(result) || !expectedToolCallIds.has(result.tool_call_id) || seenToolResultIds.has(result.tool_call_id)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
seenToolResultIds.add(result.tool_call_id);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
};
|
|
67
|
+
const serializeToolResultContent = (content) => {
|
|
68
|
+
if (typeof content === "string") {
|
|
69
|
+
return content;
|
|
70
|
+
}
|
|
71
|
+
return JSON.stringify(content ?? null);
|
|
72
|
+
};
|
|
73
|
+
const createSyntheticToolResult = (sessionId, toolCall) => new import_messages.ToolMessage({
|
|
74
|
+
id: `synthetic-tool-result:${sessionId}:${toolCall.id}`,
|
|
75
|
+
tool_call_id: toolCall.id,
|
|
76
|
+
name: toolCall.name,
|
|
77
|
+
status: "error",
|
|
78
|
+
content: JSON.stringify({
|
|
79
|
+
status: "error",
|
|
80
|
+
error: SYNTHETIC_TOOL_RESULT_ERROR
|
|
81
|
+
})
|
|
82
|
+
});
|
|
83
|
+
const createRestoredToolResult = (sessionId, toolCall, persisted) => {
|
|
84
|
+
if (!persisted || persisted.invokeStatus !== "confirmed" && persisted.invokeStatus !== "done") {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
return new import_messages.ToolMessage({
|
|
89
|
+
id: `restored-tool-result:${sessionId}:${toolCall.id}`,
|
|
90
|
+
tool_call_id: toolCall.id,
|
|
91
|
+
name: toolCall.name,
|
|
92
|
+
status: persisted.status === "error" ? "error" : "success",
|
|
93
|
+
content: serializeToolResultContent(persisted.content)
|
|
94
|
+
});
|
|
95
|
+
} catch {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const countMisplacedResults = (messages) => {
|
|
100
|
+
let misplacedResultCount = 0;
|
|
101
|
+
for (let index = 0; index < messages.length; index++) {
|
|
102
|
+
const message = messages[index];
|
|
103
|
+
if (!import_messages.AIMessage.isInstance(message)) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const toolCalls = getValidToolCalls(message);
|
|
107
|
+
if (!toolCalls.length) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const expectedToolCallIds = new Set(toolCalls.map((toolCall) => toolCall.id));
|
|
111
|
+
const contiguousResultIds = /* @__PURE__ */ new Set();
|
|
112
|
+
for (let offset = 1; offset <= toolCalls.length; offset++) {
|
|
113
|
+
const result = messages[index + offset];
|
|
114
|
+
if (!import_messages.ToolMessage.isInstance(result)) {
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
if (expectedToolCallIds.has(result.tool_call_id)) {
|
|
118
|
+
contiguousResultIds.add(result.tool_call_id);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
misplacedResultCount += expectedToolCallIds.size - contiguousResultIds.size;
|
|
122
|
+
}
|
|
123
|
+
return misplacedResultCount;
|
|
124
|
+
};
|
|
125
|
+
const normalizeToolCallHistory = async (messages, options) => {
|
|
126
|
+
var _a;
|
|
127
|
+
const toolResultsByCallId = /* @__PURE__ */ new Map();
|
|
128
|
+
const referencedToolCallIds = /* @__PURE__ */ new Set();
|
|
129
|
+
let toolCallCount = 0;
|
|
130
|
+
let toolResultCount = 0;
|
|
131
|
+
for (const message of messages) {
|
|
132
|
+
if (import_messages.AIMessage.isInstance(message)) {
|
|
133
|
+
for (const toolCall of getValidToolCalls(message)) {
|
|
134
|
+
toolCallCount++;
|
|
135
|
+
referencedToolCallIds.add(toolCall.id);
|
|
136
|
+
}
|
|
137
|
+
} else if (import_messages.ToolMessage.isInstance(message)) {
|
|
138
|
+
toolResultCount++;
|
|
139
|
+
if (message.tool_call_id) {
|
|
140
|
+
const results = toolResultsByCallId.get(message.tool_call_id) ?? [];
|
|
141
|
+
results.push(message);
|
|
142
|
+
toolResultsByCallId.set(message.tool_call_id, results);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const missingToolCallIds = Array.from(referencedToolCallIds).filter((id) => !toolResultsByCallId.has(id));
|
|
147
|
+
const persistedResults = missingToolCallIds.length ? await options.loadToolResults(missingToolCallIds) : /* @__PURE__ */ new Map();
|
|
148
|
+
const normalized = [];
|
|
149
|
+
const nextToolResultIndexByCallId = /* @__PURE__ */ new Map();
|
|
150
|
+
let restoredResultCount = 0;
|
|
151
|
+
let syntheticResultCount = 0;
|
|
152
|
+
let consumedExistingResultCount = 0;
|
|
153
|
+
for (const message of messages) {
|
|
154
|
+
if (import_messages.ToolMessage.isInstance(message)) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
normalized.push(message);
|
|
158
|
+
if (!import_messages.AIMessage.isInstance(message)) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
for (const toolCall of getValidToolCalls(message)) {
|
|
162
|
+
const existingResults = toolResultsByCallId.get(toolCall.id);
|
|
163
|
+
const existingResultIndex = nextToolResultIndexByCallId.get(toolCall.id) ?? 0;
|
|
164
|
+
const existingResult = existingResults == null ? void 0 : existingResults[existingResultIndex];
|
|
165
|
+
if (existingResult) {
|
|
166
|
+
nextToolResultIndexByCallId.set(toolCall.id, existingResultIndex + 1);
|
|
167
|
+
normalized.push(existingResult);
|
|
168
|
+
consumedExistingResultCount++;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const restoredResult = createRestoredToolResult(options.sessionId, toolCall, persistedResults.get(toolCall.id));
|
|
172
|
+
if (restoredResult) {
|
|
173
|
+
normalized.push(restoredResult);
|
|
174
|
+
restoredResultCount++;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
normalized.push(createSyntheticToolResult(options.sessionId, toolCall));
|
|
178
|
+
syntheticResultCount++;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const stats = {
|
|
182
|
+
messageCount: messages.length,
|
|
183
|
+
toolCallCount,
|
|
184
|
+
missingResultCount: missingToolCallIds.length,
|
|
185
|
+
misplacedResultCount: countMisplacedResults(messages),
|
|
186
|
+
orphanResultCount: toolResultCount - consumedExistingResultCount,
|
|
187
|
+
restoredResultCount,
|
|
188
|
+
syntheticResultCount
|
|
189
|
+
};
|
|
190
|
+
(_a = options.logger) == null ? void 0 : _a.warn("Normalize invalid tool call history before model call", {
|
|
191
|
+
sessionId: options.sessionId,
|
|
192
|
+
...stats
|
|
193
|
+
});
|
|
194
|
+
return normalized;
|
|
195
|
+
};
|
|
196
|
+
const toolResultIntegrityMiddleware = (options) => (0, import_langchain.createMiddleware)({
|
|
197
|
+
name: "ToolResultIntegrityMiddleware",
|
|
198
|
+
wrapModelCall: async (request, handler) => {
|
|
199
|
+
if (isToolCallHistoryValid(request.messages)) {
|
|
200
|
+
return handler(request);
|
|
201
|
+
}
|
|
202
|
+
request.messages = await normalizeToolCallHistory(request.messages, options);
|
|
203
|
+
return handler(request);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
207
|
+
0 && (module.exports = {
|
|
208
|
+
isToolCallHistoryValid,
|
|
209
|
+
normalizeToolCallHistory,
|
|
210
|
+
toolResultIntegrityMiddleware
|
|
211
|
+
});
|
|
@@ -7,26 +7,28 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { QueryObject } from '@nocobase/utils';
|
|
10
|
-
import { AIContextDatasource } from '../../collections/ai-context-datasource';
|
|
11
10
|
import PluginAIServer from '../plugin';
|
|
12
11
|
import { WorkContextResolveStrategy } from '../types';
|
|
13
12
|
import { Context } from '@nocobase/actions';
|
|
14
13
|
export declare class AIContextDatasourceManager {
|
|
15
14
|
protected plugin: PluginAIServer;
|
|
16
15
|
constructor(plugin: PluginAIServer);
|
|
17
|
-
|
|
18
|
-
query(ctx: Context, options: InnerQueryOptions): Promise<QueryResult | null>;
|
|
16
|
+
query(ctx: Context, options: DatasourceQueryOptions): Promise<QueryResult | null>;
|
|
19
17
|
provideWorkContextResolveStrategy(): WorkContextResolveStrategy;
|
|
20
18
|
private innerQuery;
|
|
21
19
|
}
|
|
22
|
-
export type
|
|
20
|
+
export type DatasourceQueryOptions = {
|
|
21
|
+
datasource: string;
|
|
22
|
+
collectionName: string;
|
|
23
|
+
fields?: string[];
|
|
24
|
+
appends?: string[];
|
|
25
|
+
filter?: QueryObject | null;
|
|
26
|
+
sort?: string[];
|
|
27
|
+
limit: number;
|
|
23
28
|
offset?: number;
|
|
24
29
|
};
|
|
25
|
-
export type QueryOptions = {
|
|
26
|
-
id: string;
|
|
27
|
-
};
|
|
28
30
|
export type QueryResult = {
|
|
29
|
-
options:
|
|
31
|
+
options: DatasourceQueryOptions;
|
|
30
32
|
total: number;
|
|
31
33
|
records: {
|
|
32
34
|
name: string;
|
|
@@ -34,7 +36,3 @@ export type QueryResult = {
|
|
|
34
36
|
value: unknown;
|
|
35
37
|
}[][];
|
|
36
38
|
};
|
|
37
|
-
type InnerQueryOptions = Omit<PreviewOptions, 'filter'> & {
|
|
38
|
-
filter: QueryObject;
|
|
39
|
-
};
|
|
40
|
-
export {};
|
|
@@ -92,9 +92,6 @@ class AIContextDatasourceManager {
|
|
|
92
92
|
constructor(plugin) {
|
|
93
93
|
this.plugin = plugin;
|
|
94
94
|
}
|
|
95
|
-
async preview(ctx, options) {
|
|
96
|
-
return await this.innerQuery(ctx, { ...options, filter: options.filter ? (0, import_utils.transformFilter)(options.filter) : null });
|
|
97
|
-
}
|
|
98
95
|
async query(ctx, options) {
|
|
99
96
|
return await this.innerQuery(ctx, { ...options, filter: options.filter });
|
|
100
97
|
}
|
package/dist/server/plugin.d.ts
CHANGED
|
@@ -59,11 +59,7 @@ export declare class PluginAIServer extends Plugin {
|
|
|
59
59
|
afterEnable(): Promise<void>;
|
|
60
60
|
afterDisable(): Promise<void>;
|
|
61
61
|
remove(): Promise<void>;
|
|
62
|
-
get repositories(): {
|
|
63
|
-
aiContextDatasources: import("@nocobase/database").Repository<any, any>;
|
|
64
|
-
};
|
|
65
62
|
private registerAIFileAccessAuthorizer;
|
|
66
63
|
get fileManager(): PluginFileManagerServer;
|
|
67
|
-
private repository;
|
|
68
64
|
}
|
|
69
65
|
export default PluginAIServer;
|
package/dist/server/plugin.js
CHANGED
|
@@ -66,7 +66,6 @@ var import_dashscope = require("./llm-providers/dashscope");
|
|
|
66
66
|
var import_ollama = require("./llm-providers/ollama");
|
|
67
67
|
var import_built_in_manager = require("./manager/built-in-manager");
|
|
68
68
|
var import_ai_context_datasource_manager = require("./manager/ai-context-datasource-manager");
|
|
69
|
-
var import_aiContextDatasources = require("./resource/aiContextDatasources");
|
|
70
69
|
var import_aiMcpClients = __toESM(require("./resource/aiMcpClients"));
|
|
71
70
|
var import_work_context_handler = require("./manager/work-context-handler");
|
|
72
71
|
var import_ai_coding_manager = require("./manager/ai-coding-manager");
|
|
@@ -212,7 +211,6 @@ class PluginAIServer extends import_server.Plugin {
|
|
|
212
211
|
this.app.resourceManager.define(import_aiTools.default);
|
|
213
212
|
this.app.resourceManager.define(import_aiSkills.default);
|
|
214
213
|
this.app.resourceManager.define(import_aiSettings.default);
|
|
215
|
-
this.app.resourceManager.define(import_aiContextDatasources.aiContextDatasources);
|
|
216
214
|
this.app.resourceManager.define(import_aiMcpClients.default);
|
|
217
215
|
this.app.resourceManager.use(
|
|
218
216
|
async (ctx, next) => {
|
|
@@ -287,7 +285,7 @@ class PluginAIServer extends import_server.Plugin {
|
|
|
287
285
|
});
|
|
288
286
|
this.app.acl.registerSnippet({
|
|
289
287
|
name: `pm.${this.name}.ai-employees`,
|
|
290
|
-
actions: ["aiEmployees:*", "aiTools:*", "aiSkills:*", "roles.aiEmployees:*"
|
|
288
|
+
actions: ["aiEmployees:*", "aiTools:*", "aiSkills:*", "roles.aiEmployees:*"]
|
|
291
289
|
});
|
|
292
290
|
this.app.acl.registerSnippet({
|
|
293
291
|
name: `pm.${this.name}.ai-settings`,
|
|
@@ -295,9 +293,6 @@ class PluginAIServer extends import_server.Plugin {
|
|
|
295
293
|
});
|
|
296
294
|
this.app.acl.allow("aiConversations", "*", "loggedIn");
|
|
297
295
|
this.app.acl.allow("aiWorkflowTasks", "*", "loggedIn");
|
|
298
|
-
this.app.acl.allow("aiContextDatasources", "get", "loggedIn");
|
|
299
|
-
this.app.acl.allow("aiContextDatasources", "list", "loggedIn");
|
|
300
|
-
this.app.acl.allow("aiContextDatasources", "preview", "loggedIn");
|
|
301
296
|
this.app.acl.allow("aiFiles", "create", "loggedIn");
|
|
302
297
|
this.app.acl.allow("aiSettings", "publicGet", "loggedIn");
|
|
303
298
|
this.app.acl.allow("ai", "listAllEnabledModels", "loggedIn");
|
|
@@ -376,11 +371,6 @@ class PluginAIServer extends import_server.Plugin {
|
|
|
376
371
|
}
|
|
377
372
|
async remove() {
|
|
378
373
|
}
|
|
379
|
-
get repositories() {
|
|
380
|
-
return {
|
|
381
|
-
aiContextDatasources: this.repository("aiContextDatasources")
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
374
|
registerAIFileAccessAuthorizer() {
|
|
385
375
|
this.fileManager.registerFileAccessAuthorizer({
|
|
386
376
|
name: "ai-files",
|
|
@@ -404,9 +394,6 @@ class PluginAIServer extends import_server.Plugin {
|
|
|
404
394
|
get fileManager() {
|
|
405
395
|
return this.app.pm.get("file-manager");
|
|
406
396
|
}
|
|
407
|
-
repository(collectionName) {
|
|
408
|
-
return this.app.db.getRepository(collectionName);
|
|
409
|
-
}
|
|
410
397
|
}
|
|
411
398
|
var plugin_default = PluginAIServer;
|
|
412
399
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -88,10 +88,30 @@ const setDefaultKnowledgeBaseRetrievalStrategy = (ctx) => {
|
|
|
88
88
|
values.knowledgeBase = (0, import_ai_knowledge_base.withDefaultKnowledgeBaseRetrievalStrategy)(values.knowledgeBase);
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
|
+
const readEmployeeValue = (employee, key) => typeof (employee == null ? void 0 : employee.get) === "function" ? employee.get(key) : employee == null ? void 0 : employee[key];
|
|
92
|
+
const validateKnowledgeBasePrompt = (ctx, employee) => {
|
|
93
|
+
const values = ctx.action.params.values;
|
|
94
|
+
if (!isRecord(values)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const enableKnowledgeBase = typeof values.enableKnowledgeBase === "boolean" ? values.enableKnowledgeBase : readEmployeeValue(employee, "enableKnowledgeBase") === true;
|
|
98
|
+
const knowledgeBasePrompt = "knowledgeBasePrompt" in values ? values.knowledgeBasePrompt : readEmployeeValue(employee, "knowledgeBasePrompt");
|
|
99
|
+
if (enableKnowledgeBase && !(0, import_ai_employee_validation.hasKnowledgeBaseDataPlaceholder)(knowledgeBasePrompt)) {
|
|
100
|
+
ctx.throw(400, {
|
|
101
|
+
code: import_error_codes.AI_EMPLOYEE_KNOWLEDGE_BASE_PROMPT_INVALID,
|
|
102
|
+
message: ctx.t("The Knowledge Base Prompt must include {knowledgeBaseData} before you can save it."),
|
|
103
|
+
data: { field: "knowledgeBasePrompt" }
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const hasKnowledgeBaseConfigurationChanges = (values) => isRecord(values) && ["enableKnowledgeBase", "knowledgeBase", "knowledgeBasePrompt"].some(
|
|
108
|
+
(key) => Object.prototype.hasOwnProperty.call(values, key)
|
|
109
|
+
);
|
|
91
110
|
const create = async (ctx, next) => {
|
|
92
111
|
var _a;
|
|
93
112
|
validateAndNormalizeProfileValues(ctx);
|
|
94
113
|
setDefaultKnowledgeBaseRetrievalStrategy(ctx);
|
|
114
|
+
validateKnowledgeBasePrompt(ctx);
|
|
95
115
|
const username = (_a = ctx.action.params.values) == null ? void 0 : _a.username;
|
|
96
116
|
if (typeof username === "string") {
|
|
97
117
|
const existingEmployee = await ctx.db.getRepository("aiEmployees").findOne({
|
|
@@ -112,6 +132,12 @@ const create = async (ctx, next) => {
|
|
|
112
132
|
};
|
|
113
133
|
const update = async (ctx, next) => {
|
|
114
134
|
validateAndNormalizeProfileValues(ctx);
|
|
135
|
+
if (hasKnowledgeBaseConfigurationChanges(ctx.action.params.values)) {
|
|
136
|
+
const employee = await ctx.db.getRepository("aiEmployees").findOne({
|
|
137
|
+
filterByTk: ctx.action.params.filterByTk
|
|
138
|
+
});
|
|
139
|
+
validateKnowledgeBasePrompt(ctx, employee);
|
|
140
|
+
}
|
|
115
141
|
await import_actions.default.update(ctx, next);
|
|
116
142
|
};
|
|
117
143
|
const list = async (ctx, next) => {
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"description": "Create AI employees with diverse skills to collaborate with humans, build systems, and handle business operations.",
|
|
7
7
|
"description.ru-RU": "Поддержка интеграции с AI-сервисами: предоставляются AI-узлы для рабочих процессов, расширяя возможности бизнес-обработки.",
|
|
8
8
|
"description.zh-CN": "创建各种技能的 AI 员工,与人类协同,搭建系统,处理业务。",
|
|
9
|
-
"version": "2.4.0-alpha.
|
|
9
|
+
"version": "2.4.0-alpha.4",
|
|
10
10
|
"main": "dist/server/index.js",
|
|
11
11
|
"homepage": "https://docs.nocobase.com/handbook/action-ai",
|
|
12
12
|
"homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/action-ai",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"keywords": [
|
|
67
67
|
"AI"
|
|
68
68
|
],
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "527910882037ce1558ee6b0ef748208b8d6996bb"
|
|
70
70
|
}
|
|
@@ -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
|
-
import type { WorkContextOptions } from '../types';
|
|
10
|
-
export declare const DatasourceContext: WorkContextOptions;
|
|
@@ -1,21 +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
|
-
import React from 'react';
|
|
10
|
-
import type { ContextItem } from '../types';
|
|
11
|
-
export type DatasourceSelectorProps = {
|
|
12
|
-
contextItems?: ContextItem[];
|
|
13
|
-
onAdd: (item: Omit<ContextItem, 'type'>) => void;
|
|
14
|
-
onRemove: (uid: string) => void;
|
|
15
|
-
onClose?: () => void;
|
|
16
|
-
};
|
|
17
|
-
export declare const getCheckedDatasourceIds: (contextItems?: ContextItem[]) => string[];
|
|
18
|
-
export declare const addCheckedDatasourceId: (checkedIds: Set<string>, uid: string) => Set<string>;
|
|
19
|
-
export declare const removeCheckedDatasourceId: (checkedIds: Set<string>, uid: string) => Set<string>;
|
|
20
|
-
export declare const DatasourceSelector: React.FC<DatasourceSelectorProps>;
|
|
21
|
-
export default DatasourceSelector;
|
|
@@ -1,62 +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
|
-
import React from 'react';
|
|
10
|
-
import type { APIClient } from '@nocobase/client-v2';
|
|
11
|
-
type APIClientLike = Pick<APIClient, 'resource'>;
|
|
12
|
-
type FilterValue = Record<string, unknown>;
|
|
13
|
-
type SortValue = string[];
|
|
14
|
-
export type AIContextDatasourceRecord = {
|
|
15
|
-
id: number | string;
|
|
16
|
-
title: string;
|
|
17
|
-
description?: string;
|
|
18
|
-
datasource: string;
|
|
19
|
-
collectionName: string;
|
|
20
|
-
fields?: string[];
|
|
21
|
-
filter?: FilterValue;
|
|
22
|
-
sort?: SortValue;
|
|
23
|
-
limit: number;
|
|
24
|
-
enabled: boolean;
|
|
25
|
-
createdAt?: string;
|
|
26
|
-
};
|
|
27
|
-
export type DatasourceFormValues = Omit<AIContextDatasourceRecord, 'id' | 'datasource' | 'collectionName'> & {
|
|
28
|
-
id?: number | string;
|
|
29
|
-
collection?: string[];
|
|
30
|
-
filterText?: string;
|
|
31
|
-
sortText?: string;
|
|
32
|
-
datasource?: string;
|
|
33
|
-
collectionName?: string;
|
|
34
|
-
};
|
|
35
|
-
type DatasourceListResult = {
|
|
36
|
-
data: AIContextDatasourceRecord[];
|
|
37
|
-
total?: number;
|
|
38
|
-
};
|
|
39
|
-
export type PreviewResult = {
|
|
40
|
-
options?: {
|
|
41
|
-
datasource?: string;
|
|
42
|
-
collectionName?: string;
|
|
43
|
-
fields?: string[];
|
|
44
|
-
};
|
|
45
|
-
records?: Array<Array<{
|
|
46
|
-
name: string;
|
|
47
|
-
value: unknown;
|
|
48
|
-
}>>;
|
|
49
|
-
};
|
|
50
|
-
export declare const normalizeDatasourceValues: (values: DatasourceFormValues) => Omit<AIContextDatasourceRecord, 'id'>;
|
|
51
|
-
export declare const toDatasourceFormValues: (record: AIContextDatasourceRecord) => DatasourceFormValues;
|
|
52
|
-
export declare function listContextDatasources(apiClient: APIClientLike, params?: {
|
|
53
|
-
page?: number;
|
|
54
|
-
pageSize?: number;
|
|
55
|
-
}): Promise<DatasourceListResult>;
|
|
56
|
-
export declare function createContextDatasource(apiClient: APIClientLike, values: DatasourceFormValues): Promise<void>;
|
|
57
|
-
export declare function updateContextDatasource(apiClient: APIClientLike, id: string | number, values: DatasourceFormValues): Promise<void>;
|
|
58
|
-
export declare function deleteContextDatasource(apiClient: APIClientLike, id: string | number): Promise<void>;
|
|
59
|
-
export declare function updateContextDatasourceEnabled(apiClient: APIClientLike, id: string | number, enabled: boolean): Promise<void>;
|
|
60
|
-
export declare function previewContextDatasource(apiClient: APIClientLike, values: DatasourceFormValues): Promise<PreviewResult>;
|
|
61
|
-
export declare const DatasourceSettingsPage: React.FC;
|
|
62
|
-
export default DatasourceSettingsPage;
|
|
@@ -1,25 +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
|
-
import type { CollectionOptions, Fields, Sort } from '@nocobase/database';
|
|
10
|
-
import type { FilterGroupType } from '@nocobase/utils';
|
|
11
|
-
declare const _default: CollectionOptions;
|
|
12
|
-
export default _default;
|
|
13
|
-
export type AIContextDatasource = {
|
|
14
|
-
id: string;
|
|
15
|
-
title: string;
|
|
16
|
-
description: string;
|
|
17
|
-
datasource: string;
|
|
18
|
-
collectionName: string;
|
|
19
|
-
fields?: Fields;
|
|
20
|
-
appends?: string[];
|
|
21
|
-
filter?: FilterGroupType;
|
|
22
|
-
sort?: Sort[];
|
|
23
|
-
limit: number;
|
|
24
|
-
enabled: boolean;
|
|
25
|
-
};
|
|
@@ -1,89 +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
|
-
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 ai_context_datasource_exports = {};
|
|
28
|
-
__export(ai_context_datasource_exports, {
|
|
29
|
-
default: () => ai_context_datasource_default
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(ai_context_datasource_exports);
|
|
32
|
-
var ai_context_datasource_default = {
|
|
33
|
-
name: "aiContextDatasources",
|
|
34
|
-
dataCategory: "business",
|
|
35
|
-
migrationRules: ["schema-only"],
|
|
36
|
-
fields: [
|
|
37
|
-
{
|
|
38
|
-
name: "title",
|
|
39
|
-
type: "string",
|
|
40
|
-
length: 64,
|
|
41
|
-
allowNull: false
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: "description",
|
|
45
|
-
length: 512,
|
|
46
|
-
type: "string",
|
|
47
|
-
allowNull: false
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
name: "datasource",
|
|
51
|
-
length: 128,
|
|
52
|
-
type: "string",
|
|
53
|
-
allowNull: false
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: "collectionName",
|
|
57
|
-
length: 128,
|
|
58
|
-
type: "string",
|
|
59
|
-
allowNull: false
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: "fields",
|
|
63
|
-
type: "jsonb",
|
|
64
|
-
allowNull: true
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: "filter",
|
|
68
|
-
type: "jsonb",
|
|
69
|
-
allowNull: true
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
name: "sort",
|
|
73
|
-
type: "jsonb",
|
|
74
|
-
allowNull: true
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
name: "limit",
|
|
78
|
-
type: "integer",
|
|
79
|
-
allowNull: false,
|
|
80
|
-
defaultValue: 1e3
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
name: "enabled",
|
|
84
|
-
type: "boolean",
|
|
85
|
-
allowNull: false,
|
|
86
|
-
defaultValue: true
|
|
87
|
-
}
|
|
88
|
-
]
|
|
89
|
-
};
|
|
@@ -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
|
-
declare const _default: import("@nocobase/database").CollectionOptions;
|
|
10
|
-
export default _default;
|
|
@@ -1,44 +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
|
-
var __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __export = (target, all) => {
|
|
17
|
-
for (var name in all)
|
|
18
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
-
};
|
|
20
|
-
var __copyProps = (to, from, except, desc) => {
|
|
21
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
-
for (let key of __getOwnPropNames(from))
|
|
23
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
-
}
|
|
26
|
-
return to;
|
|
27
|
-
};
|
|
28
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
-
mod
|
|
35
|
-
));
|
|
36
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
-
var ai_context_datasource_exports = {};
|
|
38
|
-
__export(ai_context_datasource_exports, {
|
|
39
|
-
default: () => ai_context_datasource_default
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(ai_context_datasource_exports);
|
|
42
|
-
var import_database = require("@nocobase/database");
|
|
43
|
-
var import_ai_context_datasource = __toESM(require("../../collections/ai-context-datasource"));
|
|
44
|
-
var ai_context_datasource_default = (0, import_database.defineCollection)(import_ai_context_datasource.default);
|
|
@@ -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
|
-
import { ResourceOptions } from '@nocobase/resourcer';
|
|
10
|
-
export declare const aiContextDatasources: ResourceOptions;
|