@nocobase/plugin-ai 2.0.0-alpha.55 → 2.0.0-alpha.57
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/1e2575d69d11cc58.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +11 -11
- package/dist/locale/en-US.json +8 -4
- package/dist/locale/zh-CN.json +8 -4
- package/dist/node_modules/@langchain/anthropic/package.json +1 -1
- package/dist/node_modules/@langchain/core/package.json +1 -1
- package/dist/node_modules/@langchain/deepseek/package.json +1 -1
- package/dist/node_modules/@langchain/google-genai/package.json +1 -1
- package/dist/node_modules/@langchain/ollama/package.json +1 -1
- package/dist/node_modules/@langchain/openai/package.json +1 -1
- package/dist/node_modules/nodejs-snowflake/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/node_modules/zod-to-json-schema/package.json +1 -1
- package/dist/server/ai-employees/ai-employee.d.ts +1 -1
- package/dist/server/ai-employees/ai-employee.js +10 -11
- package/dist/server/ai-employees/built-in/ai-coding/index.js +4 -0
- package/dist/server/ai-employees/built-in/ai-coding/prompt_en.md +7 -10
- package/dist/server/ai-employees/built-in/data-modeling/index.js +4 -0
- package/dist/server/ai-employees/built-in/data-organizer/index.js +4 -0
- package/dist/server/ai-employees/built-in/data-visualization/index.js +1 -0
- package/dist/server/ai-employees/built-in/data-visualization/prompt.js +3 -1
- package/dist/server/ai-employees/built-in/insights-analyst/index.js +4 -0
- package/dist/server/ai-employees/built-in/research-analyst/index.js +4 -0
- package/dist/server/ai-employees/built-in/translator/index.js +4 -0
- package/dist/server/manager/ai-chat-conversation.js +14 -6
- package/dist/server/manager/built-in-manager.js +0 -2
- package/dist/server/plugin.d.ts +5 -0
- package/dist/server/plugin.js +27 -2
- package/dist/server/resource/aiConversations.js +5 -8
- package/dist/server/tools/data-modeling.d.ts +1 -0
- package/dist/server/tools/data-modeling.js +88 -25
- package/dist/server/utils.d.ts +1 -0
- package/dist/server/utils.js +17 -0
- package/package.json +2 -2
- package/dist/client/adcb0e115e38e1a9.js +0 -10
- package/dist/server/ai-employees/built-in/form-filler/index.d.ts +0 -37
- package/dist/server/ai-employees/built-in/form-filler/index.js +0 -60
- package/dist/server/ai-employees/built-in/form-filler/profile.d.ts +0 -27
- package/dist/server/ai-employees/built-in/form-filler/profile.js +0 -60
- package/dist/server/ai-employees/built-in/form-filler/prompt.d.ts +0 -12
- package/dist/server/ai-employees/built-in/form-filler/prompt.js +0 -39
|
@@ -53,6 +53,7 @@ var data_visualization_default = {
|
|
|
53
53
|
{ name: "dataSource-dataSourceCounting", autoCall: true },
|
|
54
54
|
{ name: "dataSource-dataSourceQuery", autoCall: true },
|
|
55
55
|
// 了解数据结构
|
|
56
|
+
{ name: "dataModeling-getDataSources", autoCall: true },
|
|
56
57
|
{ name: "dataModeling-getCollectionNames", autoCall: true },
|
|
57
58
|
{ name: "dataModeling-getCollectionMetadata", autoCall: true }
|
|
58
59
|
]
|
|
@@ -37,7 +37,7 @@ Answer questions using data by fetching required information, analyzing results,
|
|
|
37
37
|
|
|
38
38
|
**YOUR PROCESS:**
|
|
39
39
|
1. Understand the user\u2019s intent and the required data.
|
|
40
|
-
2. Produce a single sql code block using safe, read-only SELECT to fetch the data. Use tools like getCollectionNames/getCollectionMetadata only to inspect schema (collections and fields).
|
|
40
|
+
2. Produce a single sql code block using safe, read-only SELECT to fetch the data. Use tools like getCollectionNames/getCollectionMetadata only to inspect schema (collections and fields).
|
|
41
41
|
3. Analyze the data to answer the question without fabricating any content.
|
|
42
42
|
4. Visualize the answer:
|
|
43
43
|
- Trends/Comparisons/Distributions: use charts (bar/line/pie/etc.)
|
|
@@ -46,6 +46,8 @@ Answer questions using data by fetching required information, analyzing results,
|
|
|
46
46
|
|
|
47
47
|
**CRITICAL RULES:**
|
|
48
48
|
- Language: Respond in the user\u2019s language: {{$nLang}}.
|
|
49
|
+
- SQL Dialect Awareness: Adjust SQL syntax based on the target data source type (e.g., use backticks \` for MySQL/MariaDB, double quotes " for PostgreSQL/SQLite). Check the "type" field in data source information (from context or tool results) before writing SQL.
|
|
50
|
+
- DataSource Specification: When writing SQL, ALWAYS add a comment on the first line specifying the data source key, e.g., \`-- dataSource: ExternalMySQL\`. If it's the main database, use \`-- dataSource: main\`.
|
|
49
51
|
- Visual-first: Prefer charts or KPI cards whenever possible.
|
|
50
52
|
- Data integrity: NEVER fabricate data; if missing, ask one focused question.
|
|
51
53
|
- SQL safety: ONLY use SELECT; never INSERT/UPDATE/DELETE.
|
|
@@ -109,10 +109,14 @@ class AIChatConversationImpl {
|
|
|
109
109
|
$lt: query.messageId
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
sort: ["messageId"],
|
|
112
|
+
const messages = await this.aiConversationMessagesRepo.find({
|
|
113
|
+
sort: ["-messageId"],
|
|
114
|
+
// 改为倒序,取最新的
|
|
115
|
+
limit: 50,
|
|
116
|
+
// 新增:最多 50 条消息
|
|
114
117
|
filter
|
|
115
118
|
});
|
|
119
|
+
return messages.reverse();
|
|
116
120
|
}
|
|
117
121
|
async lastUserMessage() {
|
|
118
122
|
const filter = {
|
|
@@ -141,15 +145,19 @@ class AIChatConversationImpl {
|
|
|
141
145
|
};
|
|
142
146
|
}
|
|
143
147
|
async formatMessages(messages, options) {
|
|
144
|
-
var _a, _b, _c
|
|
148
|
+
var _a, _b, _c;
|
|
145
149
|
const formattedMessages = [];
|
|
146
150
|
const { provider, workContextHandler } = options;
|
|
151
|
+
const truncate = (text, maxLen = 5e4) => {
|
|
152
|
+
if (!text || text.length <= maxLen) return text;
|
|
153
|
+
return text.slice(0, maxLen) + "\n...[truncated]";
|
|
154
|
+
};
|
|
147
155
|
for (const msg of messages) {
|
|
148
156
|
const attachments = msg.attachments;
|
|
149
157
|
const workContext = msg.workContext;
|
|
150
158
|
let content = (_a = msg.content) == null ? void 0 : _a.content;
|
|
151
|
-
if (
|
|
152
|
-
|
|
159
|
+
if (typeof content === "string") {
|
|
160
|
+
content = truncate(content);
|
|
153
161
|
}
|
|
154
162
|
if (msg.role === "user") {
|
|
155
163
|
if (typeof content === "string") {
|
|
@@ -182,7 +190,7 @@ class AIChatConversationImpl {
|
|
|
182
190
|
formattedMessages.push({
|
|
183
191
|
role: "tool",
|
|
184
192
|
content,
|
|
185
|
-
tool_call_id: (
|
|
193
|
+
tool_call_id: (_c = (_b = msg.metadata) == null ? void 0 : _b.toolCall) == null ? void 0 : _c.id
|
|
186
194
|
});
|
|
187
195
|
continue;
|
|
188
196
|
}
|
|
@@ -40,7 +40,6 @@ __export(built_in_manager_exports, {
|
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(built_in_manager_exports);
|
|
42
42
|
var import_data_modeling = __toESM(require("../ai-employees/built-in/data-modeling"));
|
|
43
|
-
var import_form_filler = __toESM(require("../ai-employees/built-in/form-filler"));
|
|
44
43
|
var import_ai_coding = __toESM(require("../ai-employees/built-in/ai-coding"));
|
|
45
44
|
var import_data_organizer = __toESM(require("../ai-employees/built-in/data-organizer"));
|
|
46
45
|
var import_insights_analyst = __toESM(require("../ai-employees/built-in/insights-analyst"));
|
|
@@ -63,7 +62,6 @@ class BuiltInManager {
|
|
|
63
62
|
}
|
|
64
63
|
builtInEmployees = [
|
|
65
64
|
import_data_modeling.default,
|
|
66
|
-
import_form_filler.default,
|
|
67
65
|
import_ai_coding.default,
|
|
68
66
|
import_data_organizer.default,
|
|
69
67
|
import_insights_analyst.default,
|
package/dist/server/plugin.d.ts
CHANGED
|
@@ -23,6 +23,11 @@ export declare class PluginAIServer extends Plugin {
|
|
|
23
23
|
aiCodingManager: AICodingManager;
|
|
24
24
|
workContextHandler: import("./types").WorkContextHandler;
|
|
25
25
|
snowflake: Snowflake;
|
|
26
|
+
/**
|
|
27
|
+
* Check if the AI employee is a builder/admin-only type (e.g., Nathan, Orin).
|
|
28
|
+
* These employees have powerful capabilities (coding, schema modification) and should be restricted to admins.
|
|
29
|
+
*/
|
|
30
|
+
isBuilderAI(username: string): boolean;
|
|
26
31
|
afterAdd(): Promise<void>;
|
|
27
32
|
beforeLoad(): Promise<void>;
|
|
28
33
|
load(): Promise<void>;
|
package/dist/server/plugin.js
CHANGED
|
@@ -76,6 +76,14 @@ class PluginAIServer extends import_server.Plugin {
|
|
|
76
76
|
aiCodingManager = new import_ai_coding_manager.AICodingManager(this);
|
|
77
77
|
workContextHandler = (0, import_work_context_handler.createWorkContextHandler)(this);
|
|
78
78
|
snowflake;
|
|
79
|
+
/**
|
|
80
|
+
* Check if the AI employee is a builder/admin-only type (e.g., Nathan, Orin).
|
|
81
|
+
* These employees have powerful capabilities (coding, schema modification) and should be restricted to admins.
|
|
82
|
+
*/
|
|
83
|
+
isBuilderAI(username) {
|
|
84
|
+
const BUILDER_AI_USERNAMES = ["nathan", "orin", "dara"];
|
|
85
|
+
return BUILDER_AI_USERNAMES.includes(username);
|
|
86
|
+
}
|
|
79
87
|
async afterAdd() {
|
|
80
88
|
}
|
|
81
89
|
async beforeLoad() {
|
|
@@ -147,6 +155,10 @@ class PluginAIServer extends import_server.Plugin {
|
|
|
147
155
|
groupName: dataModelingGroupName,
|
|
148
156
|
tool: import_tools.dataModelingIntentRouter
|
|
149
157
|
},
|
|
158
|
+
{
|
|
159
|
+
groupName: dataModelingGroupName,
|
|
160
|
+
tool: import_tools.getDataSources
|
|
161
|
+
},
|
|
150
162
|
{
|
|
151
163
|
groupName: dataModelingGroupName,
|
|
152
164
|
tool: import_tools.getCollectionNames
|
|
@@ -235,7 +247,16 @@ class PluginAIServer extends import_server.Plugin {
|
|
|
235
247
|
workflowSnippet.actions.push("ai:listModels");
|
|
236
248
|
}
|
|
237
249
|
this.app.db.on("roles.beforeCreate", async (instance) => {
|
|
238
|
-
instance.set("allowNewAiEmployee",
|
|
250
|
+
instance.set("allowNewAiEmployee", true);
|
|
251
|
+
});
|
|
252
|
+
this.app.db.on("roles.afterCreate", async (instance, { transaction }) => {
|
|
253
|
+
const allAiEmployees = await this.app.db.getRepository("aiEmployees").find({
|
|
254
|
+
transaction
|
|
255
|
+
});
|
|
256
|
+
const generalAiEmployees = allAiEmployees.filter((ai) => !this.isBuilderAI(ai.username));
|
|
257
|
+
if (generalAiEmployees.length > 0) {
|
|
258
|
+
await instance.addAiEmployees(generalAiEmployees, { transaction });
|
|
259
|
+
}
|
|
239
260
|
});
|
|
240
261
|
this.app.db.on("aiEmployees.afterCreate", async (instance, { transaction }) => {
|
|
241
262
|
const roles = await this.app.db.getRepository("roles").find({
|
|
@@ -244,8 +265,12 @@ class PluginAIServer extends import_server.Plugin {
|
|
|
244
265
|
},
|
|
245
266
|
transaction
|
|
246
267
|
});
|
|
268
|
+
let targetRoles = roles;
|
|
269
|
+
if (this.isBuilderAI(instance.username)) {
|
|
270
|
+
targetRoles = roles.filter((role) => role.name === "admin");
|
|
271
|
+
}
|
|
247
272
|
await this.app.db.getRepository("aiEmployees.roles", instance.username).add({
|
|
248
|
-
tk:
|
|
273
|
+
tk: targetRoles.map((role) => role.name),
|
|
249
274
|
transaction
|
|
250
275
|
});
|
|
251
276
|
});
|
|
@@ -64,10 +64,7 @@ function setupSSEHeaders(ctx) {
|
|
|
64
64
|
ctx.status = 200;
|
|
65
65
|
}
|
|
66
66
|
function sendErrorResponse(ctx, errorMessage) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
`);
|
|
70
|
-
ctx.res.end();
|
|
67
|
+
(0, import_utils.sendSSEError)(ctx, errorMessage);
|
|
71
68
|
}
|
|
72
69
|
var aiConversations_default = {
|
|
73
70
|
name: "aiConversations",
|
|
@@ -361,7 +358,7 @@ var aiConversations_default = {
|
|
|
361
358
|
await aiEmployee.processMessages(messages, editingMessageId);
|
|
362
359
|
} catch (err) {
|
|
363
360
|
ctx.log.error(err);
|
|
364
|
-
sendErrorResponse(ctx, err.message || "
|
|
361
|
+
sendErrorResponse(ctx, err.message || "Tool call error");
|
|
365
362
|
}
|
|
366
363
|
await next();
|
|
367
364
|
},
|
|
@@ -416,7 +413,7 @@ var aiConversations_default = {
|
|
|
416
413
|
await aiEmployee.resendMessages(messageId);
|
|
417
414
|
} catch (err) {
|
|
418
415
|
ctx.log.error(err);
|
|
419
|
-
sendErrorResponse(ctx, "Chat error warning");
|
|
416
|
+
sendErrorResponse(ctx, err.message || "Chat error warning");
|
|
420
417
|
}
|
|
421
418
|
await next();
|
|
422
419
|
},
|
|
@@ -513,7 +510,7 @@ var aiConversations_default = {
|
|
|
513
510
|
await aiEmployee.callTool(message.messageId, false);
|
|
514
511
|
} catch (err) {
|
|
515
512
|
ctx.log.error(err);
|
|
516
|
-
sendErrorResponse(ctx, "Tool call error");
|
|
513
|
+
sendErrorResponse(ctx, err.message || "Tool call error");
|
|
517
514
|
}
|
|
518
515
|
await next();
|
|
519
516
|
},
|
|
@@ -568,7 +565,7 @@ var aiConversations_default = {
|
|
|
568
565
|
await aiEmployee.confirmToolCall(message.messageId, toolCallIds);
|
|
569
566
|
} catch (err) {
|
|
570
567
|
ctx.log.error(err);
|
|
571
|
-
sendErrorResponse(ctx, "Tool call confirm error");
|
|
568
|
+
sendErrorResponse(ctx, err.message || "Tool call confirm error");
|
|
572
569
|
}
|
|
573
570
|
await next();
|
|
574
571
|
}
|
|
@@ -10,4 +10,5 @@ import { ToolOptions } from '../manager/tool-manager';
|
|
|
10
10
|
export declare const dataModelingIntentRouter: ToolOptions;
|
|
11
11
|
export declare const getCollectionNames: ToolOptions;
|
|
12
12
|
export declare const getCollectionMetadata: ToolOptions;
|
|
13
|
+
export declare const getDataSources: ToolOptions;
|
|
13
14
|
export declare const defineCollections: ToolOptions;
|
|
@@ -39,7 +39,8 @@ __export(data_modeling_exports, {
|
|
|
39
39
|
dataModelingIntentRouter: () => dataModelingIntentRouter,
|
|
40
40
|
defineCollections: () => defineCollections,
|
|
41
41
|
getCollectionMetadata: () => getCollectionMetadata,
|
|
42
|
-
getCollectionNames: () => getCollectionNames
|
|
42
|
+
getCollectionNames: () => getCollectionNames,
|
|
43
|
+
getDataSources: () => getDataSources
|
|
43
44
|
});
|
|
44
45
|
module.exports = __toCommonJS(data_modeling_exports);
|
|
45
46
|
var import_lodash = __toESM(require("lodash"));
|
|
@@ -158,13 +159,23 @@ const getCollectionNames = {
|
|
|
158
159
|
description: '{{t("Retrieve names and titles map of all collections")}}',
|
|
159
160
|
schema: {
|
|
160
161
|
type: "object",
|
|
161
|
-
properties: {
|
|
162
|
+
properties: {
|
|
163
|
+
dataSource: {
|
|
164
|
+
type: "string",
|
|
165
|
+
description: 'The data source name to retrieve collections from. Defaults to "main".'
|
|
166
|
+
}
|
|
167
|
+
},
|
|
162
168
|
additionalProperties: false
|
|
163
169
|
},
|
|
164
|
-
invoke: async (ctx) => {
|
|
170
|
+
invoke: async (ctx, args) => {
|
|
171
|
+
const { dataSource = "main" } = args || {};
|
|
165
172
|
let names = [];
|
|
166
173
|
try {
|
|
167
|
-
const
|
|
174
|
+
const ds = ctx.app.dataSourceManager.dataSources.get(dataSource);
|
|
175
|
+
if (!ds) {
|
|
176
|
+
throw new Error(`Data source "${dataSource}" not found`);
|
|
177
|
+
}
|
|
178
|
+
const collections = ds.collectionManager.getCollections();
|
|
168
179
|
names = collections.map((collection) => ({
|
|
169
180
|
name: collection.name,
|
|
170
181
|
title: collection.title
|
|
@@ -194,6 +205,10 @@ const getCollectionMetadata = {
|
|
|
194
205
|
schema: {
|
|
195
206
|
type: "object",
|
|
196
207
|
properties: {
|
|
208
|
+
dataSource: {
|
|
209
|
+
type: "string",
|
|
210
|
+
description: 'The data source name. Defaults to "main".'
|
|
211
|
+
},
|
|
197
212
|
collectionNames: {
|
|
198
213
|
type: "array",
|
|
199
214
|
items: {
|
|
@@ -206,36 +221,83 @@ const getCollectionMetadata = {
|
|
|
206
221
|
additionalProperties: false
|
|
207
222
|
},
|
|
208
223
|
invoke: async (ctx, args) => {
|
|
209
|
-
const { collectionNames } = args || {};
|
|
224
|
+
const { collectionNames, dataSource = "main" } = args || {};
|
|
210
225
|
if (!collectionNames || !Array.isArray(collectionNames) || collectionNames.length === 0) {
|
|
211
226
|
return {
|
|
212
227
|
status: "error",
|
|
213
228
|
content: "No collection names provided or invalid format."
|
|
214
229
|
};
|
|
215
230
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
});
|
|
220
|
-
const metadata = collections.map((collection) => {
|
|
221
|
-
const fields = collection.fields.map((field) => {
|
|
231
|
+
try {
|
|
232
|
+
const ds = ctx.app.dataSourceManager.dataSources.get(dataSource);
|
|
233
|
+
if (!ds) {
|
|
222
234
|
return {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
interface: field.interface,
|
|
226
|
-
options: field.options || {}
|
|
235
|
+
status: "error",
|
|
236
|
+
content: `Data source "${dataSource}" not found`
|
|
227
237
|
};
|
|
228
|
-
}
|
|
238
|
+
}
|
|
239
|
+
const metadata = [];
|
|
240
|
+
for (const name of collectionNames) {
|
|
241
|
+
const collection = ds.collectionManager.getCollection(name);
|
|
242
|
+
if (!collection) continue;
|
|
243
|
+
const fields = collection.getFields().map((field) => {
|
|
244
|
+
return {
|
|
245
|
+
name: field.name,
|
|
246
|
+
type: field.type,
|
|
247
|
+
interface: field.options.interface,
|
|
248
|
+
options: field.options || {}
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
metadata.push({
|
|
252
|
+
name: collection.name,
|
|
253
|
+
title: collection.title,
|
|
254
|
+
fields
|
|
255
|
+
});
|
|
256
|
+
}
|
|
229
257
|
return {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
fields
|
|
258
|
+
status: "success",
|
|
259
|
+
content: JSON.stringify(metadata)
|
|
233
260
|
};
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
261
|
+
} catch (err) {
|
|
262
|
+
return {
|
|
263
|
+
status: "error",
|
|
264
|
+
content: `Failed to retrieve metadata: ${err.message}`
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
const getDataSources = {
|
|
270
|
+
name: "getDataSources",
|
|
271
|
+
title: '{{t("Get data sources")}}',
|
|
272
|
+
description: '{{t("Retrieve list of all available data sources")}}',
|
|
273
|
+
schema: {
|
|
274
|
+
type: "object",
|
|
275
|
+
properties: {},
|
|
276
|
+
additionalProperties: false
|
|
277
|
+
},
|
|
278
|
+
invoke: async (ctx) => {
|
|
279
|
+
var _a, _b, _c;
|
|
280
|
+
try {
|
|
281
|
+
const records = await ctx.db.getRepository("dataSources").find();
|
|
282
|
+
const displayNameMap = new Map(records.map((r) => [r.get("key"), r.get("displayName")]));
|
|
283
|
+
const dataSources = [];
|
|
284
|
+
for (const [key, ds] of ctx.app.dataSourceManager.dataSources) {
|
|
285
|
+
dataSources.push({
|
|
286
|
+
key,
|
|
287
|
+
displayName: displayNameMap.get(key) || key,
|
|
288
|
+
type: ((_c = (_b = (_a = ds.collectionManager) == null ? void 0 : _a.db) == null ? void 0 : _b.sequelize) == null ? void 0 : _c.getDialect()) || "unknown"
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
return {
|
|
292
|
+
status: "success",
|
|
293
|
+
content: JSON.stringify(dataSources)
|
|
294
|
+
};
|
|
295
|
+
} catch (err) {
|
|
296
|
+
return {
|
|
297
|
+
status: "error",
|
|
298
|
+
content: `Failed to retrieve data sources: ${err.message}`
|
|
299
|
+
};
|
|
300
|
+
}
|
|
239
301
|
}
|
|
240
302
|
};
|
|
241
303
|
const defineCollections = {
|
|
@@ -383,5 +445,6 @@ const defineCollections = {
|
|
|
383
445
|
dataModelingIntentRouter,
|
|
384
446
|
defineCollections,
|
|
385
447
|
getCollectionMetadata,
|
|
386
|
-
getCollectionNames
|
|
448
|
+
getCollectionNames,
|
|
449
|
+
getDataSources
|
|
387
450
|
});
|
package/dist/server/utils.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { Model } from '@nocobase/database';
|
|
10
10
|
import { Context } from '@nocobase/actions';
|
|
11
|
+
export declare function sendSSEError(ctx: Context, error: Error | string): void;
|
|
11
12
|
export declare function stripToolCallTags(content: string): string | null;
|
|
12
13
|
export declare function parseResponseMessage(row: Model): {
|
|
13
14
|
key: any;
|
package/dist/server/utils.js
CHANGED
|
@@ -40,6 +40,7 @@ __export(utils_exports, {
|
|
|
40
40
|
encodeLocalFile: () => encodeLocalFile,
|
|
41
41
|
parseResponseMessage: () => parseResponseMessage,
|
|
42
42
|
parseVariables: () => parseVariables,
|
|
43
|
+
sendSSEError: () => sendSSEError,
|
|
43
44
|
stripToolCallTags: () => stripToolCallTags
|
|
44
45
|
});
|
|
45
46
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -47,6 +48,21 @@ var import_path = __toESM(require("path"));
|
|
|
47
48
|
var import_fs = __toESM(require("fs"));
|
|
48
49
|
var import_axios = __toESM(require("axios"));
|
|
49
50
|
var import_utils = require("@nocobase/utils");
|
|
51
|
+
function sendSSEError(ctx, error) {
|
|
52
|
+
const body = typeof error === "string" ? error : error.message || "Unknown error";
|
|
53
|
+
if (!ctx.res.headersSent) {
|
|
54
|
+
ctx.set({
|
|
55
|
+
"Content-Type": "text/event-stream",
|
|
56
|
+
"Cache-Control": "no-cache",
|
|
57
|
+
Connection: "keep-alive"
|
|
58
|
+
});
|
|
59
|
+
ctx.status = 200;
|
|
60
|
+
}
|
|
61
|
+
ctx.res.write(`data: ${JSON.stringify({ type: "error", body })}
|
|
62
|
+
|
|
63
|
+
`);
|
|
64
|
+
ctx.res.end();
|
|
65
|
+
}
|
|
50
66
|
function stripToolCallTags(content) {
|
|
51
67
|
if (typeof content !== "string") {
|
|
52
68
|
return content;
|
|
@@ -141,5 +157,6 @@ async function parseVariables(ctx, value) {
|
|
|
141
157
|
encodeLocalFile,
|
|
142
158
|
parseResponseMessage,
|
|
143
159
|
parseVariables,
|
|
160
|
+
sendSSEError,
|
|
144
161
|
stripToolCallTags
|
|
145
162
|
});
|
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.0.0-alpha.
|
|
9
|
+
"version": "2.0.0-alpha.57",
|
|
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",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"keywords": [
|
|
48
48
|
"AI"
|
|
49
49
|
],
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "b9ec8bc83fd86a9cadfc4fb2f87a4e015061b289"
|
|
51
51
|
}
|
|
@@ -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.webpackChunk_nocobase_plugin_ai=self.webpackChunk_nocobase_plugin_ai||[]).push([["862"],{7839:function(e,t,n){n.r(t),n.d(t,{Employees:function(){return ey}});var r=n(8156),o=n.n(r),a=n(2721),l=n(3772),i=n(3990),c=n(3505),s=n(7097),u=n(4582),p=function(e){var t,n=(0,l.usePlugin)(u.default).aiManager.llmProviders.get(e);return null==n||null==(t=n.components)?void 0:t.ModelSettingsForm},m=(0,c.observer)(function(){var e,t,n,r,a=(0,c.useForm)(),i=(0,l.useAPIClient)(),s=(0,l.useRequest)(function(){var e,t;return i.resource("llmServices").get({filterByTk:null==(t=a.values)||null==(e=t.modelSettings)?void 0:e.llmService}).then(function(e){var t;return null==e||null==(t=e.data)?void 0:t.data})},{ready:!!(null==(t=a.values)||null==(e=t.modelSettings)?void 0:e.llmService),refreshDeps:[null==(r=a.values)||null==(n=r.modelSettings)?void 0:n.llmService]}),u=s.data,m=s.loading,d=p(null==u?void 0:u.provider);return m?null:d?o().createElement(d,null):null},{displayName:"AIEmployeeModelOptionsForm"}),d=function(){var e=(0,i.NT)();return o().createElement(l.SchemaComponent,{scope:{t:e},components:{ModelOptions:m},schema:{type:"object",name:"modelSettings",properties:{llmService:{type:"string",title:'{{t("LLM service")}}',required:!0,"x-decorator":"FormItem","x-component":"RemoteSelect","x-component-props":{manual:!1,fieldNames:{label:"title",value:"name"},service:{resource:"llmServices",action:"list",params:{fields:["title","name"]}}}},settings:{type:"void","x-component":"ModelOptions"}}}})},f=n(9527),y=n.n(f),v=n(4964);function b(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function g(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(n=o.next()).done)&&(a.push(n.value),!t||a.length!==t);l=!0);}catch(e){i=!0,r=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return b(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return b(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 x(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function h(){var e=x(["\n border-color: "," !important;\n "]);return h=function(){return e},e}function S(){var e=x(["\n cursor: pointer;\n &:hover {\n border-color: "," !important;\n }\n "]);return S=function(){return e},e}function E(){var e=x(["\n border: 2px solid "," !important;\n "]);return E=function(){return e},e}function A(){var e=x(["\n cursor: pointer;\n &:hover {\n border: 2px solid "," !important;\n }\n "]);return A=function(){return e},e}var w=function(e){var t=e.srcs,n=e.size,r=void 0===n?"large":n,i=e.selectable,c=e.highlightItem,s=e.onClick,u=(0,l.useToken)().token,p=(0,l.useUploadStyles)(),m=(p.wrapSSR,p.hashId,p.componentCls);return null==t||t.map(function(e,t){var n=g(e,2),r=n[0],a=n[1];return o().createElement("div",{key:t,className:"".concat(m,"-list-picture-card-container ").concat(m,"-list-item-container")},o().createElement("div",{onClick:function(){return s&&s(a)},className:y()("".concat(m,"-list-item"),"".concat(m,"-list-item-done"),"".concat(m,"-list-item-list-type-picture-card"),c===a?(0,v.css)(h(),u.colorPrimary):"",i?(0,v.css)(S(),u.colorPrimary):"")},o().createElement("div",{className:"".concat(m,"-list-item-info")},o().createElement("span",{key:"thumbnail",className:"".concat(m,"-list-item-thumbnail")},o().createElement("img",{src:r,className:"".concat(m,"-list-item-image")})))))}),o().createElement(a.List,{grid:{gutter:16,column:10},itemLayout:"horizontal",dataSource:t,renderItem:function(e){var t=g(e,2),n=t[0],l=t[1];return o().createElement(a.List.Item,null,o().createElement(a.Avatar,{size:"small"===r?45:80,className:y()(c===l?(0,v.css)(E(),u.colorPrimary):"",i?(0,v.css)(A(),u.colorPrimary):""),src:n,onClick:function(){return s&&s(l)}}))}})},k=function(e){var t=e.disabled,n=(0,c.useField)(),a=Object.keys(s.n)[0],l=g(o().useState(a),2),i=l[0],u=l[1];(0,r.useEffect)(function(){n.value||n.setInitialValue(a)},[n]),(0,r.useEffect)(function(){n.value&&u(n.value)},[n.value]);var p=(0,r.useMemo)(function(){return Object.keys(s.n).map(function(e){return{seed:e,uri:(0,s.a)(e)}})},[]);return o().createElement(o().Fragment,null,o().createElement("div",{style:{marginBottom:"16px"}},o().createElement(w,{srcs:i?[[(0,s.a)(i),i]]:[]})),!0!==t?o().createElement(w,{srcs:p.map(function(e){return[e.uri,e.seed]}),size:"small",selectable:!0,highlightItem:i,onClick:function(e){return n.value=e}}):o().createElement(o().Fragment,null))},C=n(4632),P=function(e){var t=e.edit,n=(0,i.NT)(),r=(0,l.useCollectionRecordData)(),a=null==r?void 0:r.builtIn;return o().createElement(l.SchemaComponent,{scope:{t:n},components:{AvatarSelect:k,Switch:C.Switch},schema:{type:"void",properties:{username:{type:"string",title:'{{t("Username")}}',"x-decorator":"FormItem","x-component":"Input",required:!0,"x-disabled":t},nickname:{type:"string",title:'{{t("Nickname")}}',"x-disabled":a,"x-decorator":"FormItem","x-component":"Input",required:!0},enabled:{type:"boolean",title:'{{t("Enabled")}}',"x-decorator":"FormItem","x-component":"Switch",default:!0,required:!0},position:{type:"string",title:'{{t("Position")}}',"x-disabled":a,"x-decorator":"FormItem","x-component":"Input",description:n("Position description"),"x-component-props":{placeholder:n("Position placeholder")}},avatar:{type:"string",title:'{{t("Avatar")}}',"x-decorator":"FormItem","x-component":"AvatarSelect","x-component-props":{disabled:a}},bio:{type:"string",title:'{{t("Bio")}}',"x-disabled":a,"x-decorator":"FormItem","x-component":"Input.TextArea","x-component-props":{placeholder:n("Bio placeholder")}},greeting:{type:"string",title:'{{t("Greeting message")}}',"x-disabled":a,"x-decorator":"FormItem","x-component":"Input.TextArea","x-component-props":{placeholder:n("Greeting message placeholder")}}}}})};function I(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function O(){var e=I(["\n position: relative;\n "]);return O=function(){return e},e}function T(){var e=I(["\n position: absolute;\n right: 0;\n top: 0;\n z-index: 1;\n "]);return T=function(){return e},e}var j=function(e){var t=e.className,n=(0,l.useCollectionRecordData)(),r=null==n?void 0:n.builtIn,s=(0,i.NT)(),u=(0,c.useForm)(),p=(0,l.useAPIClient)(),m=(0,l.useRequest)(function(){return p.resource("aiEmployees").getBuiltInDefault({filterByTk:null==n?void 0:n.username})},{manual:!0,onSuccess:function(e){var t,n,r=null==e||null==(n=e.data)||null==(t=n.data)?void 0:t.about;"string"==typeof r&&(u.setValuesIn("about",r),a.message.success(s("Reset successfully")))}}).run;return r?o().createElement("div",{className:t},o().createElement(a.Button,{type:"link",size:"small",onClick:function(){return m()}},s("Reset to default"))):null},F=function(){var e=(0,i.NT)(),t=(0,l.useCurrentUserVariable)({maxDepth:3,noDisabled:!0}).currentUserSettings,n=(0,l.useCurrentRoleVariable)({noDisabled:!0}).currentRoleSettings,r=(0,l.useDatetimeVariable)({noDisabled:!0}).datetimeSettings;return[t,n,{key:"$nLang",value:"$nLang",label:e("Current language")},r]},B=function(){var e=(0,i.NT)();return o().createElement(a.Alert,{style:{marginBottom:16},message:e("Characterization description"),type:"info"})},N=function(){var e=(0,i.NT)(),t=F();return o().createElement(l.SchemaComponent,{scope:{t:e},components:{ResetButton:j,Description:B},schema:{type:"void",properties:{desc:{type:"void","x-component":"Description"},aboutWrap:{type:"void","x-component":"div","x-component-props":{className:(0,v.css)(O())},properties:{about:{type:"string",title:'{{t("Characterization")}}',required:!0,"x-decorator":"FormItem","x-component":"Variable.RawTextArea","x-component-props":{scope:t,placeholder:e("Characterization placeholder"),autoSize:{minRows:15}}},resetAbout:{type:"void","x-component":"ResetButton","x-component-props":{className:(0,v.css)(T())}}}}}}})},D={name:"aiEmployees",fields:[{name:"username",type:"string",primaryKey:!0},{name:"nickname",type:"string",interface:"input"},{name:"position",type:"string",interface:"input"},{name:"avatar",type:"string",interface:"image"},{name:"bio",type:"text",interface:"textarea"},{name:"about",type:"text",interface:"textarea"},{name:"greeting",type:"text",interface:"textarea"},{name:"chatSettings",type:"jsonb"},{name:"skillSettings",type:"jsonb"},{name:"modelSettings",type:"jsonb"},{name:"dataSourceSettings",type:"jsonb"},{name:"enableKnowledgeBase",type:"boolean",allowNull:!1,defaultValue:!1},{name:"knowledgeBasePrompt",type:"text"},{name:"knowledgeBase",type:"jsonb"},{name:"enabled",type:"boolean",interface:"switch",allowNull:!1,defaultValue:!0},{name:"builtIn",type:"boolean",allowNull:!1,defaultValue:!1}]},z=n(482);function R(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function M(e){return function(e){if(Array.isArray(e))return R(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||V(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function V(e,t){if(e){if("string"==typeof e)return R(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return R(e,t)}}var L=function(e){var t=e.title,n=e.description,r=e.schema,s=(0,i.NT)(),u=(0,l.useToken)().token;return o().createElement(a.Card,{size:"small",style:{minWidth:"300px",maxWidth:"400px"},title:o().createElement(o().Fragment,null,o().createElement("div",{style:{marginTop:"4px"}},c.Schema.compile(t,{t:s})),o().createElement("div",{style:{color:u.colorTextSecondary,fontSize:u.fontSizeSM,fontWeight:400,whiteSpace:"pre-wrap"}},c.Schema.compile(n,{t:s})))},o().createElement(o().Fragment,null,o().createElement("div",{style:{fontWeight:u.fontWeightStrong}},s("Parameters")),o().createElement(a.List,{itemLayout:"vertical",dataSource:Object.entries((null==r?void 0:r.properties)||{}),size:"small",renderItem:function(e){var t,n=function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(n=o.next()).done)&&(a.push(n.value),a.length!==t);l=!0);}catch(e){i=!0,r=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw r}}return a}}(e,2)||V(e,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),l=n[0],i=n[1];return o().createElement(a.List.Item,{key:l},o().createElement("div",null,o().createElement("span",{style:{fontWeight:u.fontWeightStrong}},i.title||l),o().createElement("span",{style:{color:u.colorTextSecondary,fontSize:u.fontSizeSM,marginLeft:"4px"}},i.type),(null==(t=r.required)?void 0:t.includes(l))&&o().createElement("span",{style:{color:u.colorError,fontSize:u.fontSizeSM,marginLeft:"4px"}},s("Required"))),o().createElement("div",{style:{color:u.colorTextSecondary,fontSize:u.fontSizeSM}},i.description))}})))},K=function(e){var t,n=e.name,r=e.title,s=e.description,u=e.isRoot,p=(0,i.NT)(),m=(0,l.useToken)().token,d=null==(t=(0,c.useField)().value)?void 0:t.find(function(e){return e.name===n});return o().createElement("div",{style:{minWidth:"150px",maxWidth:"300px"}},o().createElement("div",{style:{display:"flex",justifyContent:"space-between"}},o().createElement("div",null,c.Schema.compile(r,{t:p})),!u&&o().createElement("div",null,o().createElement(a.Switch,{size:"small",value:d,disabled:d}))),o().createElement("div",{style:{color:m.colorTextSecondary,fontSize:m.fontSizeSM}},c.Schema.compile(s,{t:p})))},q=function(){var e=(0,i.NT)(),t=(0,l.useToken)().token,n=(0,c.useField)(),r=(0,l.useAPIClient)(),s=(0,l.useRequest)(function(){return r.resource("aiTools").list().then(function(e){var t;return null==e||null==(t=e.data)?void 0:t.data})}),u=s.data,p=s.loading,m=function(e){var t=M(n.value||[]);t.some(function(t){return t.name===e})||t.push({name:e,autoCall:!1}),n.value=t},d=(null==u?void 0:u.map(function(e){var t,n,r={key:e.group.groupName},a={title:null!=(t=e.group.title)?t:"",description:null!=(n=e.group.description)?n:"",name:e.group.groupName,isRoot:!0};return e.tools?(r.label=o().createElement(K,a),r.children=e.tools.map(function(e){return{key:e.name,label:o().createElement(K,e),onClick:function(){return m(e.name)}}})):(r.label=o().createElement(K,a),r.onClick=function(){}),r}))||[];return o().createElement(o().Fragment,null,o().createElement("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",width:"100%",margin:"8px 0 16px 0"}},o().createElement(a.Dropdown,{menu:{items:d},placement:"bottomRight"},o().createElement(a.Button,{type:"primary",icon:o().createElement(z.PlusOutlined,null)},e("Add skill"),o().createElement(a.Tooltip,{title:e("Tools available for LLM function calling")},o().createElement(z.QuestionCircleOutlined,{style:{marginLeft:"4px"}}))))),!p&&o().createElement(a.List,{itemLayout:"vertical",bordered:!0,dataSource:n.value||[],renderItem:function(r){var l,i=(null!=(l=null==u?void 0:u.flatMap(function(e){return e.tools}))?l:[]).find(function(e){return e.name===r.name});return i?o().createElement(a.List.Item,{key:i.name,extra:o().createElement(a.Flex,{vertical:!0,justify:"end"},o().createElement(a.Space,null,o().createElement("div",{style:{fontSize:t.fontSizeSM}},e("Auto usage"),o().createElement(a.Switch,{style:{marginLeft:"4px",marginRight:"8px"},size:"small",checked:r.autoCall,onChange:function(e){var t=(n.value||[]).map(function(t){var n,o;return t.name===r.name?(n=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},t),o=o={autoCall:e},Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(o)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(o,e))}),n):t});n.value=t}})),o().createElement(a.Popover,{content:o().createElement(L,i),placement:"bottom",arrow:!1,styles:{body:{padding:0,marginRight:"8px"}}},o().createElement(z.InfoCircleOutlined,null)),o().createElement(a.Button,{icon:o().createElement(z.DeleteOutlined,null),variant:"link",color:"default",onClick:function(){var e=M(n.value||[]),t=e.findIndex(function(e){return e.name===i.name});-1!==t&&(e.splice(t,1),n.value=e)}})))},o().createElement("div",null,c.Schema.compile(i.title,{t:e})),o().createElement("div",{style:{color:t.colorTextSecondary,fontSize:t.fontSizeSM}},c.Schema.compile(i.description,{t:e}))):null}}))},W=function(){var e=(0,i.NT)();return o().createElement(l.SchemaComponent,{components:{Skills:q},schema:{type:"void",properties:{skillSettings:{type:"object",properties:{skills:{type:"array","x-component":"Skills","x-decorator":"FormItem",description:e("Auto skill description")}}}}}})},$=n(8875),U=n(8563),_=n(3972);function G(e,t,n,r,o,a,l){try{var i=e[a](l),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,o)}function H(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var a=e.apply(t,n);function l(e){G(a,r,o,l,i,"next",e)}function i(e){G(a,r,o,l,i,"throw",e)}l(void 0)})}}function Q(e,t){var n,r,o,a,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){var c=[a,i];if(n)throw TypeError("Generator is already executing.");for(;l;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,r=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){l=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){l.label=c[1];break}if(6===c[0]&&l.label<o[1]){l.label=o[1],o=c;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(c);break}o[2]&&l.ops.pop(),l.trys.pop();continue}c=t.call(e,l)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var X=function(){var e=(0,i.NT)();return{form:(0,r.useMemo)(function(){return(0,U.createForm)({initialValues:{username:"".concat((0,$.uid)()),enableKnowledgeBase:!1,knowledgeBase:{knowledgeBaseIds:[],topK:3,score:"0.6"},knowledgeBasePrompt:e("knowledge Base Prompt default")}})},[e])}},J=function(){var e=(0,l.useCollectionRecordData)();return{form:(0,r.useMemo)(function(){return(0,U.createForm)({initialValues:e})},[e])}},Y=function(){var e=(0,l.useActionContext)().setVisible,t=(0,c.useForm)();return{type:"default",onClick:function(){e(!1),t.reset()}}},Z=function(){var e=(0,l.useActionContext)().setVisible,t=a.App.useApp().message,n=(0,c.useForm)(),r=(0,l.useAPIClient)(),o=(0,l.useDataBlockRequest)().refresh,s=(0,_.S)().refresh,u=(0,i.NT)();return{type:"primary",onClick:function(){return H(function(){var a;return Q(this,function(l){switch(l.label){case 0:return[4,n.submit()];case 1:return l.sent(),a=n.values,[4,r.resource("aiEmployees").create({values:a})];case 2:return l.sent(),o(),t.success(u("Saved successfully")),e(!1),n.reset(),s(),[2]}})})()}}},ee=function(){var e=(0,l.useActionContext)().setVisible,t=a.App.useApp().message,n=(0,c.useForm)(),r=(0,l.useDataBlockResource)(),o=(0,l.useDataBlockRequest)().refresh,s=(0,_.S)().refresh,u=(0,l.useCollection)().getFilterTargetKey(),p=(0,i.NT)();return{type:"primary",onClick:function(){return H(function(){var a;return Q(this,function(l){switch(l.label){case 0:return[4,n.submit()];case 1:return l.sent(),a=n.values,[4,r.update({values:a,filterByTk:a[u]})];case 2:return l.sent(),o(),t.success(p("Saved successfully")),e(!1),n.reset(),s(),[2]}})})()}}},et=function(){var e=(0,i.NT)(),t=(0,l.useCollectionRecordData)(),n=(0,l.useDestroyActionProps)().onClick,r=null==t?void 0:t.builtIn,o=a.App.useApp().message;return{onClick:function(t,a){return H(function(){return Q(this,function(l){switch(l.label){case 0:if(r)return o.warning(e("Cannot delete built-in ai employees")),[2];return[4,n(t,a)];case 1:return l.sent(),[2]}})})()}}};function en(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var er=a.Card.Meta,eo=(0,r.createContext)(null),ea=function(){var e=(0,r.useContext)(eo).aiEmployee;return{form:(0,r.useMemo)(function(){return(0,U.createForm)({initialValues:e})},[e])}},el=function(e){var t=e.aiEmployee,n=(0,l.useToken)().token,r=(0,l.useActionContext)().setVisible;return o().createElement(a.Card,{variant:"borderless",hoverable:!0,onClick:function(){return r(!0)}},o().createElement(er,{avatar:t.avatar?o().createElement(a.Avatar,{size:40,src:(0,s.a)(t.avatar)}):null,title:t.nickname,description:o().createElement(o().Fragment,null,t.position&&o().createElement(a.Tag,{style:{marginBottom:n.marginXS}},t.position),o().createElement(a.Typography.Paragraph,{style:{height:n.fontSize*n.lineHeight*3},ellipsis:{rows:3},type:"secondary"},t.bio))}))},ei=function(){var e,t=(e=o().useState(!1),function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(n=o.next()).done)&&(a.push(n.value),a.length!==t);l=!0);}catch(e){i=!0,r=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw r}}return a}}(e,2)||function(e,t){if(e){if("string"==typeof e)return en(e,2);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return en(e,t)}}(e,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),n=t[0],r=t[1],i=(0,l.useAPIClient)(),c=(0,l.useRequest)(function(){return i.resource("aiEmployees").getTemplates().then(function(e){var t;return null==e||null==(t=e.data)?void 0:t.data})}),s=c.data;return c.loading?o().createElement(a.Spin,null):s&&s.length?o().createElement(a.Row,{gutter:[16,16]},s.map(function(e){return o().createElement(l.ActionContextProvider,{key:e.username,value:{visible:n,setVisible:r}},o().createElement(a.Col,{span:12},o().createElement(el,{aiEmployee:e})),o().createElement(eo.Provider,{value:{aiEmployee:e}},o().createElement(l.SchemaComponent,{scope:{useCancelActionProps:Y,useCreateActionProps:Z,useTemplateFormProps:ea},schema:{type:"void",name:(0,$.uid)(),"x-component":"Action.Drawer",title:'{{t("New AI employee")}}',"x-decorator":"FormV2","x-use-decorator-props":"useTemplateFormProps",properties:{form:{type:"void","x-component":"AIEmployeeForm"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{close:{title:"Cancel","x-component":"Action","x-component-props":{type:"default"},"x-use-component-props":"useCancelActionProps"},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary"},"x-use-component-props":"useCreateActionProps"}}}}}})))})):o().createElement(a.Empty,{image:a.Empty.PRESENTED_IMAGE_SIMPLE})},ec=function(){return(0,i.NT)(),o().createElement(l.SchemaComponent,{components:{Switch:C.Switch},schema:{type:"void",properties:{enableKnowledgeBase:{type:"boolean",title:'{{t("Enable Knowledge Base")}}',"x-decorator":"FormItem","x-component":"Switch"},knowledgeBasePrompt:{type:"string",title:'{{t("Knowledge Base Prompt")}}',required:!0,"x-decorator":"FormItem","x-component":"Input.TextArea","x-component-props":{autoSize:{minRows:5}},"x-reactions":[{dependencies:["enableKnowledgeBase"],fulfill:{state:{disabled:"{{$deps[0] === false}}"}}}]},knowledgeBase:{type:"object",properties:{knowledgeBaseIds:{type:"array",title:'{{t("Knowledge Base")}}',required:!0,"x-decorator":"FormItem","x-component":"RemoteSelect","x-component-props":{mode:"multiple",manual:!1,fieldNames:{label:"name",value:"id"},service:{resource:"aiKnowledgeBase",action:"list",params:{fields:["id","name"],filter:{enabled:!0}}}},"x-reactions":[{dependencies:["enableKnowledgeBase"],fulfill:{state:{disabled:"{{$deps[0] === false}}"}}}]},topK:{type:"number",title:'{{t("Top K")}}',required:!0,"x-decorator":"FormItem","x-component":"InputNumber","x-component-props":{min:1,max:100},"x-reactions":[{dependencies:["enableKnowledgeBase"],fulfill:{state:{disabled:"{{$deps[0] === false}}"}}}]},score:{type:"number",title:'{{t("Score")}}',required:!0,"x-decorator":"FormItem","x-component":"InputNumber","x-component-props":{min:0,max:1,step:.1},"x-reactions":[{dependencies:["enableKnowledgeBase"],fulfill:{state:{disabled:"{{$deps[0] === false}}"}}}]}}}}}})};function es(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function eu(e,t){if(e){if("string"==typeof e)return es(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return es(e,t)}}var ep=function(e){var t,n,c=e.edit,s=(0,i.NT)(),u=(0,l.useAPIClient)(),p=(t=(0,r.useState)(!1),function(e){if(Array.isArray(e))return e}(t)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(n=o.next()).done)&&(a.push(n.value),a.length!==t);l=!0);}catch(e){i=!0,r=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw r}}return a}}(t,2)||eu(t,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),m=p[0],f=p[1];return(0,r.useEffect)(function(){u.resource("aiSettings").isKnowledgeBaseEnabled().then(function(e){var t;f(null==e||null==(t=e.data)?void 0:t.data.enabled)}).catch(function(e){return console.error("api fail aiSettings.isKnowledgeBaseEnabled",e)})},[u]),o().createElement(a.Tabs,{items:[{key:"profile",label:s("Profile"),children:o().createElement(P,{edit:c}),forceRender:!0},{key:"persona",label:s("Characterization"),children:o().createElement(N,null),forceRender:!0},{key:"modelSettings",label:s("Model settings"),children:o().createElement(d,null),forceRender:!0},{key:"skills",label:s("Skills"),children:o().createElement(W,null)}].concat(function(e){if(Array.isArray(e))return es(e)}(n=m?[{key:"knowledgeBase",label:s("KnowledgeBase"),children:o().createElement(ec,null)}]:[])||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(n)||eu(n)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}())})},em=function(e){var t,n,r=(0,c.useField)();return r.value?o().createElement(a.Avatar,(t=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({shape:"square",size:"large"},e),n=n={src:(0,s.a)(r.value)},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}),t)):null},ed=function(e){var t=(0,c.useField)();return t.value?t.value&&o().createElement(z.CheckOutlined,{style:{color:"#52c41a"}}):null},ef=function(e){var t=(0,c.useField)();return t.value?o().createElement(a.Tag,null,t.value.model):null},ey=function(){var e=(0,i.NT)();return o().createElement(l.ExtendCollectionsProvider,{collections:[D]},o().createElement(l.SchemaComponent,{components:{AIEmployeeForm:ep,Avatar:em,Templates:ei,LLMModel:ef,Enabled:ed},scope:{t:e,useCreateFormProps:X,useEditFormProps:J,useCancelActionProps:Y,useCreateActionProps:Z,useEditActionProps:ee,useDeleteActionProps:et},schema:{type:"void",name:"ai-employees",properties:{block:{type:"void","x-component":"CardItem","x-component-props":{heightMode:"fullHeight"},"x-decorator":"TableBlockProvider","x-decorator-props":{collection:"aiEmployees",action:"list",rowKey:"username",dragSort:!0,dragSortBy:"sort"},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:20}},properties:{refresh:{title:"{{t('Refresh')}}","x-component":"Action","x-use-component-props":"useRefreshActionProps","x-component-props":{icon:"ReloadOutlined"}},add:{type:"void",title:"{{t('New AI employee')}}","x-align":"right","x-component":"Action","x-component-props":{type:"primary",icon:"PlusOutlined"},properties:{drawer:{type:"void","x-component":"Action.Drawer",title:'{{t("New AI employee")}}',"x-decorator":"FormV2","x-use-decorator-props":"useCreateFormProps",properties:{form:{type:"void","x-component":"AIEmployeeForm"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{close:{title:"Cancel","x-component":"Action","x-component-props":{type:"default"},"x-use-component-props":"useCancelActionProps"},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary"},"x-use-component-props":"useCreateActionProps"}}}}}}}}},table:{type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"username",rowSelection:{type:"checkbox"}},properties:{column0:{type:"void",title:e("Avatar"),"x-component":"TableV2.Column",properties:{avatar:{type:"string","x-component":"Avatar","x-component-props":{shape:"circle"}}}},column1:{type:"void",title:e("Username"),"x-component":"TableV2.Column",properties:{username:{type:"string","x-component":"Input","x-pattern":"readPretty"}}},column2:{type:"void",title:e("Nickname"),"x-component":"TableV2.Column",properties:{nickname:{type:"string","x-component":"Input","x-pattern":"readPretty"}}},column3:{type:"void",title:e("Position"),"x-component":"TableV2.Column",properties:{position:{type:"string","x-component":"Input","x-pattern":"readPretty"}}},column4:{type:"void",title:e("Model"),"x-component":"TableV2.Column",properties:{modelSettings:{type:"string","x-component":"LLMModel"}}},column5:{type:"void",title:e("Enabled"),"x-component":"TableV2.Column",properties:{enabled:{type:"string","x-component":"Enabled"}}},column6:{type:"void",title:'{{t("Actions")}}',"x-decorator":"TableV2.Column.ActionBar","x-component":"TableV2.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{edit:{type:"void",title:'{{t("Edit") }}',"x-action":"update","x-component":"Action.Link","x-component-props":{openMode:"drawer"},properties:{drawer:{type:"void",title:e("Edit AI employee"),"x-component":"Action.Drawer","x-decorator":"FormV2","x-use-decorator-props":"useEditFormProps",properties:{form:{type:"void","x-component":"AIEmployeeForm","x-component-props":{edit:!0}},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{close:{title:e("Cancel"),"x-component":"Action","x-use-component-props":"useCancelActionProps"},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-use-component-props":"useEditActionProps"}}}}}}},destroy:{type:"void",title:'{{ t("Delete") }}',"x-action":"destroy","x-component":"Action.Link","x-use-component-props":"useDeleteActionProps","x-component-props":{confirm:{title:"{{t('Delete AI employee')}}",content:"{{t('Are you sure you want to delete this AI employee?')}}"}}}}}}}}}}}}}}))}}}]);
|
|
@@ -1,37 +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: {
|
|
10
|
-
username: string;
|
|
11
|
-
description: string;
|
|
12
|
-
profile: {
|
|
13
|
-
'en-US': {
|
|
14
|
-
avatar: string;
|
|
15
|
-
nickname: string;
|
|
16
|
-
position: string;
|
|
17
|
-
bio: string;
|
|
18
|
-
greeting: string;
|
|
19
|
-
about: string;
|
|
20
|
-
};
|
|
21
|
-
'zh-CN': {
|
|
22
|
-
avatar: string;
|
|
23
|
-
nickname: string;
|
|
24
|
-
position: string;
|
|
25
|
-
bio: string;
|
|
26
|
-
greeting: string;
|
|
27
|
-
about: string;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
skillSettings: {
|
|
31
|
-
skills: {
|
|
32
|
-
name: string;
|
|
33
|
-
autoCall: boolean;
|
|
34
|
-
}[];
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
export default _default;
|