@nocobase/plugin-ai 2.1.0-beta.23 → 2.1.0-beta.25

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.
Files changed (37) hide show
  1. package/dist/ai/ai-employees/dara.js +1 -0
  2. package/dist/ai/tools/sub-agents/shared.js +3 -1
  3. package/dist/client/343.6f36d97dd122c5b6.js +10 -0
  4. package/dist/client/{559.133d286a0a0a1d93.js → 559.c119db3f985a695f.js} +1 -1
  5. package/dist/client/646.afa699c92cd556f3.js +10 -0
  6. package/dist/client/ai-employees/types.d.ts +2 -0
  7. package/dist/client/components/skill-settings.d.ts +2 -0
  8. package/dist/client/index.js +3 -3
  9. package/dist/client/llm-providers/mimo/ModelSettings.d.ts +10 -0
  10. package/dist/client/llm-providers/mimo/index.d.ts +10 -0
  11. package/dist/collections/ai-employees.d.ts +7 -0
  12. package/dist/collections/ai-employees.js +13 -0
  13. package/dist/externalVersion.js +15 -15
  14. package/dist/locale/en-US.json +2 -0
  15. package/dist/locale/zh-CN.json +2 -0
  16. package/dist/node_modules/fast-glob/package.json +1 -1
  17. package/dist/node_modules/flexsearch/package.json +1 -1
  18. package/dist/node_modules/fs-extra/package.json +1 -1
  19. package/dist/node_modules/jsonrepair/package.json +1 -1
  20. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  21. package/dist/node_modules/openai/package.json +1 -1
  22. package/dist/node_modules/zod/package.json +1 -1
  23. package/dist/server/ai-employees/ai-employee.js +9 -3
  24. package/dist/server/llm-providers/common/reasoning.d.ts +0 -7
  25. package/dist/server/llm-providers/common/reasoning.js +16 -36
  26. package/dist/server/llm-providers/mimo.d.ts +37 -0
  27. package/dist/server/llm-providers/mimo.js +156 -0
  28. package/dist/server/migrations/20260428175558-update-ai-employee-category.d.ts +14 -0
  29. package/dist/server/migrations/20260428175558-update-ai-employee-category.js +55 -0
  30. package/dist/server/migrations/20260429175132-ai-employee-deprecated-orin.d.ts +14 -0
  31. package/dist/server/migrations/20260429175132-ai-employee-deprecated-orin.js +53 -0
  32. package/dist/server/plugin.js +3 -1
  33. package/dist/server/resource/aiEmployees.js +10 -1
  34. package/dist/server/workflow/nodes/employee/index.js +133 -130
  35. package/package.json +2 -2
  36. package/dist/client/343.83f7d96664e4e038.js +0 -10
  37. package/dist/client/646.cba98d80e9e6ea74.js +0 -10
@@ -0,0 +1,156 @@
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 mimo_exports = {};
38
+ __export(mimo_exports, {
39
+ MiMoProvider: () => MiMoProvider,
40
+ mimoProviderOptions: () => mimoProviderOptions
41
+ });
42
+ module.exports = __toCommonJS(mimo_exports);
43
+ var import_provider = require("./provider");
44
+ var import_ai_manager = require("../manager/ai-manager");
45
+ var import_lodash = __toESM(require("lodash"));
46
+ var import_openai = require("@langchain/openai");
47
+ var import_messages = require("@langchain/core/messages");
48
+ var import_reasoning = require("./common/reasoning");
49
+ class MiMoProvider extends import_provider.LLMProvider {
50
+ get baseURL() {
51
+ return "https://api.xiaomimimo.com/v1";
52
+ }
53
+ createModel() {
54
+ const { baseURL, apiKey } = this.serviceOptions || {};
55
+ const { responseFormat, structuredOutput } = this.modelOptions || {};
56
+ const { schema } = structuredOutput || {};
57
+ const responseFormatOptions = {
58
+ type: responseFormat ?? "text"
59
+ };
60
+ if (responseFormat === "json_schema" && schema) {
61
+ responseFormatOptions["json_schema"] = schema;
62
+ }
63
+ return new ChatMiMoCompletions({
64
+ apiKey,
65
+ ...this.modelOptions,
66
+ modelKwargs: {
67
+ response_format: responseFormatOptions
68
+ },
69
+ configuration: {
70
+ baseURL: baseURL || this.baseURL
71
+ },
72
+ verbose: true
73
+ });
74
+ }
75
+ isApiSupportedAttachment(attachment) {
76
+ const media = ["image/"];
77
+ const supportedMedia = media.some((it) => {
78
+ var _a;
79
+ return (_a = attachment == null ? void 0 : attachment.mimetype) == null ? void 0 : _a.startsWith(it);
80
+ });
81
+ return supportedMedia;
82
+ }
83
+ parseResponseMessage(message) {
84
+ var _a;
85
+ const result = super.parseResponseMessage(message);
86
+ if (["user", "tool"].includes(result == null ? void 0 : result.role)) {
87
+ return result;
88
+ }
89
+ const { metadata } = (message == null ? void 0 : message.toJSON()) ?? {};
90
+ if (!import_lodash.default.isEmpty((_a = metadata == null ? void 0 : metadata.additional_kwargs) == null ? void 0 : _a.reasoning_content)) {
91
+ result.content = {
92
+ ...result.content ?? {},
93
+ reasoning: {
94
+ status: "stop",
95
+ content: metadata == null ? void 0 : metadata.additional_kwargs.reasoning_content
96
+ }
97
+ };
98
+ }
99
+ return result;
100
+ }
101
+ parseReasoningContent(chunk) {
102
+ var _a;
103
+ if (!import_lodash.default.isEmpty((_a = chunk == null ? void 0 : chunk.additional_kwargs) == null ? void 0 : _a.reasoning_content)) {
104
+ return {
105
+ status: "streaming",
106
+ content: chunk.additional_kwargs.reasoning_content
107
+ };
108
+ }
109
+ return null;
110
+ }
111
+ builtInTools() {
112
+ var _a, _b;
113
+ if (((_b = (_a = this.modelOptions) == null ? void 0 : _a.builtIn) == null ? void 0 : _b.webSearch) === true) {
114
+ return [
115
+ {
116
+ type: "web_search",
117
+ force_search: true
118
+ }
119
+ ];
120
+ }
121
+ return [];
122
+ }
123
+ isToolConflict() {
124
+ return true;
125
+ }
126
+ }
127
+ class ChatMiMoCompletions extends import_reasoning.ReasoningChatOpenAI {
128
+ _convertCompletionsDeltaToBaseMessageChunk(delta, rawResponse, defaultRole) {
129
+ const chunk = (0, import_openai.convertCompletionsDeltaToBaseMessageChunk)({
130
+ delta,
131
+ rawResponse,
132
+ includeRawResponse: this.__includeRawResponse,
133
+ defaultRole
134
+ });
135
+ if (chunk instanceof import_messages.AIMessageChunk) {
136
+ if (delta.reasoning_content) {
137
+ chunk.additional_kwargs.reasoning_content = delta.reasoning_content;
138
+ }
139
+ }
140
+ return chunk;
141
+ }
142
+ }
143
+ const mimoProviderOptions = {
144
+ title: "MiMo",
145
+ supportWebSearch: true,
146
+ supportedModel: [import_ai_manager.SupportedModel.LLM],
147
+ models: {
148
+ [import_ai_manager.SupportedModel.LLM]: ["mimo-v2.5-pro", "mimo-v2.5"]
149
+ },
150
+ provider: MiMoProvider
151
+ };
152
+ // Annotate the CommonJS export names for ESM import in node:
153
+ 0 && (module.exports = {
154
+ MiMoProvider,
155
+ mimoProviderOptions
156
+ });
@@ -0,0 +1,14 @@
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 { Migration } from '@nocobase/server';
10
+ export default class extends Migration {
11
+ on: string;
12
+ appVersion: string;
13
+ up(): Promise<void>;
14
+ }
@@ -0,0 +1,55 @@
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 update_ai_employee_category_exports = {};
28
+ __export(update_ai_employee_category_exports, {
29
+ default: () => update_ai_employee_category_default
30
+ });
31
+ module.exports = __toCommonJS(update_ai_employee_category_exports);
32
+ var import_server = require("@nocobase/server");
33
+ class update_ai_employee_category_default extends import_server.Migration {
34
+ on = "afterSync";
35
+ // 'beforeLoad' or 'afterLoad'
36
+ appVersion = "<2.2.0";
37
+ async up() {
38
+ const repo = this.db.getRepository("aiEmployees");
39
+ if (!repo) {
40
+ return;
41
+ }
42
+ await repo.update({
43
+ values: {
44
+ category: "developer"
45
+ },
46
+ filter: {
47
+ builtIn: true,
48
+ username: {
49
+ $in: ["orin", "nathan", "dara"]
50
+ }
51
+ }
52
+ });
53
+ this.app.logger.info('Update AI employee orin, nathan, dara`s category to "developer"');
54
+ }
55
+ }
@@ -0,0 +1,14 @@
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 { Migration } from '@nocobase/server';
10
+ export default class extends Migration {
11
+ on: string;
12
+ appVersion: string;
13
+ up(): Promise<void>;
14
+ }
@@ -0,0 +1,53 @@
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_employee_deprecated_orin_exports = {};
28
+ __export(ai_employee_deprecated_orin_exports, {
29
+ default: () => ai_employee_deprecated_orin_default
30
+ });
31
+ module.exports = __toCommonJS(ai_employee_deprecated_orin_exports);
32
+ var import_server = require("@nocobase/server");
33
+ class ai_employee_deprecated_orin_default extends import_server.Migration {
34
+ on = "afterSync";
35
+ // 'beforeLoad' or 'afterLoad'
36
+ appVersion = "<2.2.0";
37
+ async up() {
38
+ const repo = this.db.getRepository("aiEmployees");
39
+ if (!repo) {
40
+ return;
41
+ }
42
+ await repo.update({
43
+ values: {
44
+ deprecated: true
45
+ },
46
+ filter: {
47
+ builtIn: true,
48
+ username: "orin"
49
+ }
50
+ });
51
+ this.app.logger.info("Update AI employee orin to deprecated");
52
+ }
53
+ }
@@ -72,6 +72,7 @@ var import_ai_coding_manager = require("./manager/ai-coding-manager");
72
72
  var import_kimi = require("./llm-providers/kimi");
73
73
  var import_document_loader = require("./document-loader");
74
74
  var import_checkpoints = require("./ai-employees/checkpoints");
75
+ var import_mimo = require("./llm-providers/mimo");
75
76
  var import_sub_agents = require("./ai-employees/sub-agents");
76
77
  var import_employee = require("./workflow/nodes/employee");
77
78
  var import_ai_knowledge_base = require("./ai-employees/ai-knowledge-base");
@@ -141,9 +142,10 @@ class PluginAIServer extends import_server.Plugin {
141
142
  this.aiManager.registerLLMProvider("anthropic", import_anthropic.anthropicProviderOptions);
142
143
  this.aiManager.registerLLMProvider("deepseek", import_deepseek.deepseekProviderOptions);
143
144
  this.aiManager.registerLLMProvider("dashscope", import_dashscope.dashscopeProviderOptions);
145
+ this.aiManager.registerLLMProvider("kimi", import_kimi.kimiProviderOptions);
146
+ this.aiManager.registerLLMProvider("mimo", import_mimo.mimoProviderOptions);
144
147
  this.aiManager.registerLLMProvider("ollama", import_ollama.ollamaProviderOptions);
145
148
  this.aiManager.registerLLMProvider("openai-completions", import_openai2.openaiCompletionsProviderOptions);
146
- this.aiManager.registerLLMProvider("kimi", import_kimi.kimiProviderOptions);
147
149
  }
148
150
  registerTools() {
149
151
  const toolsManager = this.ai.toolsManager;
@@ -49,6 +49,13 @@ const list = async (ctx, next) => {
49
49
  const { paginate } = ctx.action.params || {};
50
50
  const plugin = ctx.app.pm.get("ai");
51
51
  const builtInManager = plugin.builtInManager;
52
+ const filter = ctx.action.params.filter || {};
53
+ ctx.action.mergeParams({
54
+ filter: {
55
+ ...filter,
56
+ deprecated: false
57
+ }
58
+ });
52
59
  await import_actions.default.list(ctx, () => {
53
60
  });
54
61
  let data = ctx.body.rows;
@@ -146,7 +153,9 @@ const listByUser = async (ctx, next) => {
146
153
  prompt: (_b = (_a = row.userConfigs) == null ? void 0 : _a[0]) == null ? void 0 : _b.prompt
147
154
  },
148
155
  skillSettings,
149
- builtIn: row.builtIn
156
+ builtIn: row.builtIn,
157
+ category: row.category,
158
+ deprecated: row.deprecated
150
159
  };
151
160
  });
152
161
  await next();
@@ -49,7 +49,6 @@ __reExport(employee_exports, require("./handler"), module.exports);
49
49
  __reExport(employee_exports, require("./tools"), module.exports);
50
50
  class AIEmployeeInstruction extends import_plugin_workflow.Instruction {
51
51
  async run(node, input, processor) {
52
- var _a, _b, _c, _d, _e;
53
52
  const {
54
53
  username,
55
54
  message,
@@ -81,151 +80,155 @@ ${typeof message.system === "object" ? JSON.stringify(message.system) : message.
81
80
  upstreamId: (input == null ? void 0 : input.id) ?? null
82
81
  });
83
82
  await processor.exit();
84
- try {
85
- if (skillSettings && skillSettings.skillsVersion == null) {
86
- skillSettings.skillsVersion = 2;
87
- }
88
- if (skillSettings && skillSettings.toolsVersion == null) {
89
- skillSettings.toolsVersion = 2;
90
- }
91
- const { conversation, aiWorkflowTasks } = await this.createWorkflowTask({
92
- username,
93
- userMessage,
94
- systemMessage,
95
- skillSettings,
96
- requiresApproval,
97
- toolName,
98
- node,
99
- processor,
100
- jobId: id
101
- });
102
- let currentRoles = (_a = input == null ? void 0 : input.result) == null ? void 0 : _a.roleName;
103
- if (!currentRoles) {
104
- const defaultRole = await this.workflow.db.getRepository("rolesUsers").findOne({
83
+ const runner = async () => {
84
+ var _a, _b, _c, _d, _e;
85
+ try {
86
+ if (skillSettings && skillSettings.skillsVersion == null) {
87
+ skillSettings.skillsVersion = 2;
88
+ }
89
+ if (skillSettings && skillSettings.toolsVersion == null) {
90
+ skillSettings.toolsVersion = 2;
91
+ }
92
+ const { conversation, aiWorkflowTasks } = await this.createWorkflowTask({
93
+ username,
94
+ userMessage,
95
+ systemMessage,
96
+ skillSettings,
97
+ requiresApproval,
98
+ toolName,
99
+ node,
100
+ processor,
101
+ jobId: id
102
+ });
103
+ let currentRoles = (_a = input == null ? void 0 : input.result) == null ? void 0 : _a.roleName;
104
+ if (!currentRoles) {
105
+ const defaultRole = await this.workflow.db.getRepository("rolesUsers").findOne({
106
+ filter: {
107
+ userId: ((_c = (_b = input == null ? void 0 : input.result) == null ? void 0 : _b.user) == null ? void 0 : _c.id) ?? userId,
108
+ default: true
109
+ }
110
+ });
111
+ currentRoles = defaultRole == null ? void 0 : defaultRole.roleName;
112
+ }
113
+ const employee = await this.workflow.db.getRepository("aiEmployees").findOne({
105
114
  filter: {
106
- userId: ((_c = (_b = input == null ? void 0 : input.result) == null ? void 0 : _b.user) == null ? void 0 : _c.id) ?? userId,
107
- default: true
115
+ username
108
116
  }
109
117
  });
110
- currentRoles = defaultRole == null ? void 0 : defaultRole.roleName;
111
- }
112
- const employee = await this.workflow.db.getRepository("aiEmployees").findOne({
113
- filter: {
114
- username
115
- }
116
- });
117
- const aiEmployee = new import_ai_employee.AIEmployee({
118
- ctx: {
119
- app: this.workflow.app,
120
- db: this.workflow.app.db,
121
- log: this.workflow.app.log,
122
- logger: this.workflow.app.log,
123
- state: { currentRoles },
124
- auth: {
125
- user: {
126
- id: ((_e = (_d = input == null ? void 0 : input.result) == null ? void 0 : _d.user) == null ? void 0 : _e.id) ?? userId
127
- }
128
- },
129
- action: {
130
- params: {
131
- values: {
132
- sessionId: conversation.sessionId,
133
- model
118
+ const aiEmployee = new import_ai_employee.AIEmployee({
119
+ ctx: {
120
+ app: this.workflow.app,
121
+ db: this.workflow.app.db,
122
+ log: this.workflow.app.log,
123
+ logger: this.workflow.app.log,
124
+ state: { currentRoles },
125
+ auth: {
126
+ user: {
127
+ id: ((_e = (_d = input == null ? void 0 : input.result) == null ? void 0 : _d.user) == null ? void 0 : _e.id) ?? userId
134
128
  }
135
- }
136
- }
137
- },
138
- employee,
139
- sessionId: conversation.sessionId,
140
- systemMessage,
141
- skillSettings,
142
- webSearch,
143
- model,
144
- tools: [{ name: toolName }]
145
- });
146
- const attachmentPart = {};
147
- if (files == null ? void 0 : files.length) {
148
- const { resolveAttachments, resolveUrls } = import_files.Files.resolvers(this.workflow, attachmentPart);
149
- await resolveAttachments(files);
150
- await resolveUrls(files);
151
- }
152
- let result;
153
- let isToolInvoke = false;
154
- let retry = 0;
155
- do {
156
- const userMessages = [
157
- {
158
- role: "user",
159
- content: {
160
- type: "text",
161
- content: userMessage
162
129
  },
163
- ...attachmentPart
164
- }
165
- ];
166
- if (retry > 0) {
167
- if (retry < 2) {
168
- const firstUserMessage = await this.workflow.db.getRepository("aiConversations.messages", conversation.sessionId).findOne({
169
- filter: {
170
- role: "user"
130
+ action: {
131
+ params: {
132
+ values: {
133
+ sessionId: conversation.sessionId,
134
+ model
135
+ }
136
+ }
137
+ }
138
+ },
139
+ employee,
140
+ sessionId: conversation.sessionId,
141
+ systemMessage,
142
+ skillSettings,
143
+ webSearch,
144
+ model,
145
+ tools: [{ name: toolName }]
146
+ });
147
+ const attachmentPart = {};
148
+ if (files == null ? void 0 : files.length) {
149
+ const { resolveAttachments, resolveUrls } = import_files.Files.resolvers(this.workflow, attachmentPart);
150
+ await resolveAttachments(files);
151
+ await resolveUrls(files);
152
+ }
153
+ let result;
154
+ let isToolInvoke = false;
155
+ let retry = 0;
156
+ do {
157
+ const userMessages = [
158
+ {
159
+ role: "user",
160
+ content: {
161
+ type: "text",
162
+ content: userMessage
171
163
  },
172
- sort: ["messageId"]
173
- });
174
- const messageId = firstUserMessage == null ? void 0 : firstUserMessage.messageId;
175
- result = await aiEmployee.invoke({ messageId, userMessages });
176
- } else {
177
- result = await aiEmployee.invoke({
178
- userMessages: [
179
- {
180
- role: "user",
181
- content: {
182
- type: "text",
183
- content: `You failed to call the required tool "aiEmployeeWorkflowTaskOutput" in your previous response.
164
+ ...attachmentPart
165
+ }
166
+ ];
167
+ if (retry > 0) {
168
+ if (retry < 2) {
169
+ const firstUserMessage = await this.workflow.db.getRepository("aiConversations.messages", conversation.sessionId).findOne({
170
+ filter: {
171
+ role: "user"
172
+ },
173
+ sort: ["messageId"]
174
+ });
175
+ const messageId = firstUserMessage == null ? void 0 : firstUserMessage.messageId;
176
+ result = await aiEmployee.invoke({ messageId, userMessages });
177
+ } else {
178
+ result = await aiEmployee.invoke({
179
+ userMessages: [
180
+ {
181
+ role: "user",
182
+ content: {
183
+ type: "text",
184
+ content: `You failed to call the required tool "aiEmployeeWorkflowTaskOutput" in your previous response.
184
185
  Call "aiEmployeeWorkflowTaskOutput" now to submit the workflow outcome.
185
186
  Do not send another normal assistant response without invoking it.
186
187
  `
188
+ }
187
189
  }
188
- }
189
- ]
190
- });
190
+ ]
191
+ });
192
+ }
193
+ } else {
194
+ result = await aiEmployee.invoke({ userMessages });
191
195
  }
192
- } else {
193
- result = await aiEmployee.invoke({ userMessages });
196
+ isToolInvoke = result.messages.filter((it) => it.type === "ai").flatMap((it) => it.tool_calls).some((it) => it.name === toolName);
197
+ } while (!isToolInvoke && retry++ < 2);
198
+ if (!isToolInvoke) {
199
+ throw new Error("AI employee not do job correctly");
194
200
  }
195
- isToolInvoke = result.messages.filter((it) => it.type === "ai").flatMap((it) => it.tool_calls).some((it) => it.name === toolName);
196
- } while (!isToolInvoke && retry++ < 2);
197
- if (!isToolInvoke) {
198
- throw new Error("AI employee not do job correctly");
199
- }
200
- await this.checkApproval({ requiresApproval, conversation, aiWorkflowTasks, result, aiEmployee, toolName });
201
- } catch (e) {
202
- processor.logger.error(`ai employee invoke failed, ${e.message}`, {
203
- node: node.id,
204
- stack: e.stack,
205
- chatOptions: node.config
206
- });
207
- const job = await this.workflow.app.db.getRepository("jobs").findOne({
208
- filterByTk: id
209
- });
210
- job.set({
211
- status: import_plugin_workflow.JOB_STATUS.ERROR,
212
- result: e.message
213
- });
214
- const aiWorkflowTask = await this.workflow.db.getRepository("aiWorkflowTasks").findOne({
215
- filter: {
216
- jobId: id
217
- }
218
- });
219
- if (aiWorkflowTask) {
220
- await this.workflow.db.getRepository("aiWorkflowTasks").update({
221
- values: { status: "aborted" },
201
+ await this.checkApproval({ requiresApproval, conversation, aiWorkflowTasks, result, aiEmployee, toolName });
202
+ } catch (e) {
203
+ processor.logger.error(`ai employee invoke failed, ${e.message}`, {
204
+ node: node.id,
205
+ stack: e.stack,
206
+ chatOptions: node.config
207
+ });
208
+ const job = await this.workflow.app.db.getRepository("jobs").findOne({
209
+ filterByTk: id
210
+ });
211
+ job.set({
212
+ status: import_plugin_workflow.JOB_STATUS.ERROR,
213
+ result: e.message
214
+ });
215
+ const aiWorkflowTask = await this.workflow.db.getRepository("aiWorkflowTasks").findOne({
222
216
  filter: {
223
- id: aiWorkflowTask.id
217
+ jobId: id
224
218
  }
225
219
  });
220
+ if (aiWorkflowTask) {
221
+ await this.workflow.db.getRepository("aiWorkflowTasks").update({
222
+ values: { status: "aborted" },
223
+ filter: {
224
+ id: aiWorkflowTask.id
225
+ }
226
+ });
227
+ }
228
+ await this.workflow.resume(job);
226
229
  }
227
- await this.workflow.resume(job);
228
- }
230
+ };
231
+ runner();
229
232
  }
230
233
  resume(node, job, processor) {
231
234
  return job;
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.1.0-beta.23",
9
+ "version": "2.1.0-beta.25",
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",
@@ -61,5 +61,5 @@
61
61
  "keywords": [
62
62
  "AI"
63
63
  ],
64
- "gitHead": "bb4c0d3551bf9eff505b63756dd24a0813231f16"
64
+ "gitHead": "824f8b8200e9fe086135768934d3ef427b212446"
65
65
  }