@nocobase/plugin-ai 2.1.0-alpha.13 → 2.1.0-alpha.15
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/ai-employees/atlas/index.d.ts +10 -0
- package/dist/ai/ai-employees/atlas/index.js +56 -0
- package/dist/ai/ai-employees/atlas/prompt.md +84 -0
- package/dist/ai/ai-employees/vera.js +1 -1
- package/dist/ai/skills/business-analysis-report/SKILLS.md +84 -0
- package/dist/ai/tools/businessReportGenerator.d.ts +10 -0
- package/dist/ai/tools/businessReportGenerator.js +83 -0
- package/dist/ai/tools/chartGenerator.js +1 -0
- package/dist/ai/tools/getSkill.js +1 -1
- package/dist/ai/tools/sub-agents/dispatch-sub-agent-task.d.ts +10 -0
- package/dist/ai/tools/sub-agents/dispatch-sub-agent-task.js +108 -0
- package/dist/ai/tools/sub-agents/get-ai-employee.d.ts +10 -0
- package/dist/ai/tools/sub-agents/get-ai-employee.js +67 -0
- package/dist/ai/tools/sub-agents/list-ai-employees.d.ts +10 -0
- package/dist/ai/tools/sub-agents/list-ai-employees.js +64 -0
- package/dist/ai/tools/sub-agents/shared.d.ts +33 -0
- package/dist/ai/tools/sub-agents/shared.js +169 -0
- package/dist/ai/tools/subAgentWebSearch.d.ts +10 -0
- package/dist/ai/tools/subAgentWebSearch.js +103 -0
- package/dist/ai/tools/suggestions.js +2 -2
- package/dist/client/0e94d90f0134df30.js +10 -0
- package/dist/client/{4f9117811ffc7ab3.js → 1c3ef55a6d63c9a3.js} +1 -1
- package/dist/client/55d67b74f02b8d74.js +10 -0
- package/dist/client/{6dc8c9b641452067.js → 5d5c118d11e91913.js} +1 -1
- package/dist/client/748fbb87c1013c6e.js +10 -0
- package/dist/client/8e82080c5e8ccfb7.js +10 -0
- package/dist/client/a8d6d81fb88f1a8e.js +10 -0
- package/dist/client/ai-employees/built-in/utils.d.ts +1 -0
- package/dist/client/ai-employees/business-report/tools/index.d.ts +10 -0
- package/dist/client/ai-employees/business-report/ui/BusinessReportCard.d.ts +12 -0
- package/dist/client/ai-employees/business-report/ui/BusinessReportModal.d.ts +17 -0
- package/dist/client/ai-employees/business-report/ui/report-utils.d.ts +36 -0
- package/dist/client/ai-employees/chatbox/AIEmployeeSwitch.d.ts +0 -1
- package/dist/client/ai-employees/chatbox/hooks/useChatBoxActions.d.ts +5 -3
- package/dist/client/ai-employees/chatbox/markdown/ECharts.d.ts +1 -2
- package/dist/client/ai-employees/chatbox/markdown/Markdown.d.ts +1 -1
- package/dist/client/ai-employees/chatbox/roles.d.ts +1 -0
- package/dist/client/ai-employees/chatbox/stores/chat-messages.d.ts +8 -0
- package/dist/client/ai-employees/chatbox/utils.d.ts +15 -1
- package/dist/client/ai-employees/sub-agents/tools/index.d.ts +10 -0
- package/dist/client/ai-employees/sub-agents/ui/SubAgentDispatchCard.d.ts +21 -0
- package/dist/client/ai-employees/types.d.ts +19 -0
- package/dist/client/c065565ccbb41f99.js +10 -0
- package/dist/client/d5e9663991c30eed.js +10 -0
- package/dist/client/f87cff5213f94856.js +10 -0
- package/dist/client/f8c075896e8b9c0b.js +10 -0
- package/dist/client/fd4e5dcaf24052c1.js +10 -0
- package/dist/client/index.js +7 -7
- package/dist/client/manager/ai-manager.d.ts +4 -23
- package/dist/externalVersion.js +17 -15
- package/dist/locale/en-US.json +30 -1
- package/dist/locale/zh-CN.json +30 -1
- package/dist/node_modules/fast-glob/package.json +1 -1
- package/dist/node_modules/flexsearch/package.json +1 -1
- package/dist/node_modules/fs-extra/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-conversations.d.ts +64 -0
- package/dist/server/ai-employees/ai-conversations.js +285 -0
- package/dist/server/ai-employees/ai-employee.d.ts +88 -14
- package/dist/server/ai-employees/ai-employee.js +335 -200
- package/dist/server/ai-employees/middleware/conversation.d.ts +2 -0
- package/dist/server/ai-employees/middleware/conversation.js +38 -5
- package/dist/server/ai-employees/middleware/tools.js +37 -10
- package/dist/server/ai-employees/prompts.d.ts +11 -1
- package/dist/server/ai-employees/prompts.js +29 -2
- package/dist/server/ai-employees/sub-agents/dispatcher.d.ts +36 -0
- package/dist/server/ai-employees/sub-agents/dispatcher.js +225 -0
- package/dist/server/ai-employees/sub-agents/index.d.ts +9 -0
- package/dist/server/ai-employees/sub-agents/index.js +36 -0
- package/dist/server/ai-employees/utils.js +1 -1
- package/dist/server/collections/ai-conversations.js +6 -0
- package/dist/server/llm-providers/anthropic.d.ts +1 -0
- package/dist/server/llm-providers/anthropic.js +2 -1
- package/dist/server/llm-providers/dashscope.d.ts +3 -0
- package/dist/server/llm-providers/dashscope.js +13 -1
- package/dist/server/llm-providers/deepseek.d.ts +1 -0
- package/dist/server/llm-providers/deepseek.js +5 -2
- package/dist/server/llm-providers/google-genai.d.ts +1 -0
- package/dist/server/llm-providers/google-genai.js +2 -1
- package/dist/server/llm-providers/kimi/provider.d.ts +1 -0
- package/dist/server/llm-providers/openai/responses.d.ts +1 -0
- package/dist/server/llm-providers/openai/responses.js +2 -1
- package/dist/server/llm-providers/provider.d.ts +1 -10
- package/dist/server/llm-providers/provider.js +3 -34
- package/dist/server/manager/ai-manager.d.ts +10 -0
- package/dist/server/manager/ai-manager.js +32 -0
- package/dist/server/migrations/20260319000000-add-ai-conversations-from.d.ts +14 -0
- package/dist/server/migrations/20260319000000-add-ai-conversations-from.js +63 -0
- package/dist/server/plugin.d.ts +4 -0
- package/dist/server/plugin.js +4 -0
- package/dist/server/resource/aiConversations.d.ts +3 -3
- package/dist/server/resource/aiConversations.js +125 -159
- package/dist/server/types/ai-chat-conversation.type.d.ts +8 -2
- package/dist/server/types/ai-message.type.d.ts +7 -0
- package/dist/server/utils.d.ts +3 -0
- package/dist/server/utils.js +28 -1
- package/package.json +4 -2
- package/dist/client/27539a4356faebb1.js +0 -10
- package/dist/client/39492c2121f4c722.js +0 -10
- package/dist/client/53190ab4290ef9d5.js +0 -10
- package/dist/client/9c00efb8eb0b4d69.js +0 -10
- package/dist/client/d4e2ed9fa44a82b2.js +0 -10
|
@@ -0,0 +1,285 @@
|
|
|
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_conversations_exports = {};
|
|
28
|
+
__export(ai_conversations_exports, {
|
|
29
|
+
AIConversationsManager: () => AIConversationsManager
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(ai_conversations_exports);
|
|
32
|
+
var import_database = require("@nocobase/database");
|
|
33
|
+
var import_utils = require("../utils");
|
|
34
|
+
class AIConversationsManager {
|
|
35
|
+
constructor(plugin) {
|
|
36
|
+
this.plugin = plugin;
|
|
37
|
+
}
|
|
38
|
+
async create({ userId, aiEmployee, title, options = {}, from = "main-agent" }) {
|
|
39
|
+
return await this.aiConversationsRepo.create({
|
|
40
|
+
values: {
|
|
41
|
+
userId,
|
|
42
|
+
title,
|
|
43
|
+
aiEmployee,
|
|
44
|
+
options,
|
|
45
|
+
thread: 1,
|
|
46
|
+
from
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async update({ userId, sessionId, title, options: inputOptions }) {
|
|
51
|
+
const conversation = await this.aiConversationsRepo.findOne({
|
|
52
|
+
filter: {
|
|
53
|
+
sessionId,
|
|
54
|
+
userId
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
if (!conversation) {
|
|
58
|
+
throw new Error("invalid sessionId");
|
|
59
|
+
}
|
|
60
|
+
const { systemMessage, skillSettings, conversationSettings } = inputOptions ?? {};
|
|
61
|
+
const options = conversation.options ?? {};
|
|
62
|
+
if (systemMessage) {
|
|
63
|
+
options["systemMessage"] = systemMessage;
|
|
64
|
+
}
|
|
65
|
+
if (skillSettings) {
|
|
66
|
+
options["skillSettings"] = skillSettings;
|
|
67
|
+
}
|
|
68
|
+
if (conversationSettings) {
|
|
69
|
+
options["conversationSettings"] = conversationSettings;
|
|
70
|
+
}
|
|
71
|
+
const values = { options };
|
|
72
|
+
if (title) {
|
|
73
|
+
values.title = title;
|
|
74
|
+
}
|
|
75
|
+
return await this.aiConversationsRepo.update({
|
|
76
|
+
filter: {
|
|
77
|
+
userId,
|
|
78
|
+
sessionId
|
|
79
|
+
},
|
|
80
|
+
values
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async getMessages({
|
|
84
|
+
userId,
|
|
85
|
+
sessionId,
|
|
86
|
+
cursor,
|
|
87
|
+
paginate = true
|
|
88
|
+
}) {
|
|
89
|
+
const conversation = await this.aiConversationsRepo.findOne({
|
|
90
|
+
filter: {
|
|
91
|
+
sessionId,
|
|
92
|
+
userId
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
if (!conversation) {
|
|
96
|
+
throw new Error("invalid sessionId");
|
|
97
|
+
}
|
|
98
|
+
const pageSize = 10;
|
|
99
|
+
const maxLimit = 200;
|
|
100
|
+
const messageRepository = this.plugin.db.getRepository("aiConversations.messages", sessionId);
|
|
101
|
+
const filter = {
|
|
102
|
+
role: {
|
|
103
|
+
$notIn: ["tool"]
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
if (paginate && cursor) {
|
|
107
|
+
filter["messageId"] = {
|
|
108
|
+
$lt: cursor
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const rows = await messageRepository.find({
|
|
112
|
+
sort: ["-messageId"],
|
|
113
|
+
limit: paginate ? pageSize + 1 : maxLimit,
|
|
114
|
+
filter
|
|
115
|
+
});
|
|
116
|
+
const hasMore = paginate && rows.length > pageSize;
|
|
117
|
+
const data = hasMore ? rows.slice(0, -1) : rows;
|
|
118
|
+
const newCursor = data.length ? data[data.length - 1].messageId : null;
|
|
119
|
+
const subAgentConversations = data.filter((row) => {
|
|
120
|
+
var _a, _b;
|
|
121
|
+
return ((_b = (_a = row.metadata) == null ? void 0 : _a.subAgentConversations) == null ? void 0 : _b.length) ?? 0 > 0;
|
|
122
|
+
}).flatMap((row) => row.metadata.subAgentConversations);
|
|
123
|
+
const subAgentConversationSessionIds = [...new Set(subAgentConversations.map((item) => item.sessionId))];
|
|
124
|
+
const subAgentConversationMessages = subAgentConversationSessionIds.length ? await this.aiMessagesRepo.find({
|
|
125
|
+
sort: ["messageId"],
|
|
126
|
+
filter: {
|
|
127
|
+
sessionId: {
|
|
128
|
+
$in: subAgentConversationSessionIds
|
|
129
|
+
},
|
|
130
|
+
role: {
|
|
131
|
+
$notIn: ["tool"]
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}) : [];
|
|
135
|
+
const subAgentConversationMessageMap = /* @__PURE__ */ new Map();
|
|
136
|
+
const toolCallIds = [
|
|
137
|
+
...data.filter((row) => {
|
|
138
|
+
var _a;
|
|
139
|
+
return ((_a = row == null ? void 0 : row.toolCalls) == null ? void 0 : _a.length) ?? 0 > 0;
|
|
140
|
+
}).flatMap((row) => row.toolCalls).map((toolCall) => toolCall.id),
|
|
141
|
+
...subAgentConversationMessages.filter((row) => {
|
|
142
|
+
var _a;
|
|
143
|
+
return ((_a = row == null ? void 0 : row.toolCalls) == null ? void 0 : _a.length) ?? 0 > 0;
|
|
144
|
+
}).flatMap((row) => row.toolCalls).map((toolCall) => toolCall.id)
|
|
145
|
+
];
|
|
146
|
+
const toolMessages = await this.aiToolMessagesRepo.find({
|
|
147
|
+
filter: {
|
|
148
|
+
toolCallId: {
|
|
149
|
+
$in: toolCallIds
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
const toolMessageKey = (messageId, toolCallId) => `${messageId}:${toolCallId}`;
|
|
154
|
+
const toolMessageMap = new Map(
|
|
155
|
+
toolMessages.map((toolMessage) => [
|
|
156
|
+
toolMessageKey(toolMessage.messageId, toolMessage.toolCallId),
|
|
157
|
+
toolMessage
|
|
158
|
+
])
|
|
159
|
+
);
|
|
160
|
+
const toolsList = await this.plugin.aiManager.toolManager.listTools();
|
|
161
|
+
const toolsMap = new Map(
|
|
162
|
+
toolsList.map((group) => group.tools).flat().map((tool) => [tool.name, tool])
|
|
163
|
+
);
|
|
164
|
+
const parseMessageRow = (row) => {
|
|
165
|
+
var _a, _b;
|
|
166
|
+
if (((_a = row == null ? void 0 : row.toolCalls) == null ? void 0 : _a.length) ?? 0 > 0) {
|
|
167
|
+
for (const toolCall of row.toolCalls) {
|
|
168
|
+
const tool = toolsMap.get(toolCall.name);
|
|
169
|
+
const toolMessage = toolMessageMap.get(toolMessageKey(row.messageId, toolCall.id));
|
|
170
|
+
toolCall.invokeStatus = toolMessage == null ? void 0 : toolMessage.invokeStatus;
|
|
171
|
+
toolCall.auto = toolMessage == null ? void 0 : toolMessage.auto;
|
|
172
|
+
toolCall.status = toolMessage == null ? void 0 : toolMessage.status;
|
|
173
|
+
toolCall.content = toolMessage == null ? void 0 : toolMessage.content;
|
|
174
|
+
toolCall.execution = tool == null ? void 0 : tool.execution;
|
|
175
|
+
toolCall.willInterrupt = (tool == null ? void 0 : tool.execution) === "frontend" || (toolMessage == null ? void 0 : toolMessage.auto) === false;
|
|
176
|
+
toolCall.defaultPermission = tool == null ? void 0 : tool.defaultPermission;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const providerOptions = this.plugin.aiManager.llmProviders.get((_b = row.metadata) == null ? void 0 : _b.provider);
|
|
180
|
+
if (!providerOptions) {
|
|
181
|
+
return (0, import_utils.parseResponseMessage)(row);
|
|
182
|
+
}
|
|
183
|
+
const Provider = providerOptions.provider;
|
|
184
|
+
const provider = new Provider({
|
|
185
|
+
app: this.plugin.app
|
|
186
|
+
});
|
|
187
|
+
return provider.parseResponseMessage(row);
|
|
188
|
+
};
|
|
189
|
+
for (const row of subAgentConversationMessages) {
|
|
190
|
+
const sessionMessages = subAgentConversationMessageMap.get(row.sessionId) ?? [];
|
|
191
|
+
sessionMessages.push(parseMessageRow(row));
|
|
192
|
+
sessionMessages.forEach((it) => it.content.from = "sub-agent");
|
|
193
|
+
subAgentConversationMessageMap.set(row.sessionId, sessionMessages);
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
rows: data.map((row) => {
|
|
197
|
+
var _a;
|
|
198
|
+
const parsedRow = parseMessageRow(row);
|
|
199
|
+
const subAgentConversationItems = ((_a = row.metadata) == null ? void 0 : _a.subAgentConversations) ?? [];
|
|
200
|
+
if (subAgentConversationItems.length) {
|
|
201
|
+
parsedRow.content.subAgentConversations = subAgentConversationItems.map((item) => ({
|
|
202
|
+
sessionId: item.sessionId,
|
|
203
|
+
toolCallId: item.toolCallId,
|
|
204
|
+
status: item.status,
|
|
205
|
+
messages: subAgentConversationMessageMap.get(item.sessionId) ?? []
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
parsedRow.content.from = "main-agent";
|
|
209
|
+
return parsedRow;
|
|
210
|
+
}),
|
|
211
|
+
...paginate && {
|
|
212
|
+
hasMore,
|
|
213
|
+
cursor: newCursor
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
async getUserDecisions(messageId) {
|
|
218
|
+
var _a;
|
|
219
|
+
const allInterruptedToolCall = await this.aiToolMessagesRepo.find({
|
|
220
|
+
filter: {
|
|
221
|
+
messageId,
|
|
222
|
+
interruptActionOrder: { [import_database.Op.not]: null }
|
|
223
|
+
},
|
|
224
|
+
order: [["interruptActionOrder", "ASC"]]
|
|
225
|
+
});
|
|
226
|
+
if (!allInterruptedToolCall.every((t) => t.invokeStatus === "waiting")) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
const message = await this.aiMessagesRepo.findOne({
|
|
230
|
+
filter: {
|
|
231
|
+
messageId
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
const interruptId = (_a = message == null ? void 0 : message.get("metadata")) == null ? void 0 : _a.interruptId;
|
|
235
|
+
return {
|
|
236
|
+
interruptId,
|
|
237
|
+
decisions: allInterruptedToolCall.map((item) => item.userDecision)
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
async resolveSubAgentConversation(sessionId, toolCallId) {
|
|
241
|
+
var _a, _b;
|
|
242
|
+
if (!sessionId || !toolCallId) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
const toolMessage = await this.aiToolMessagesRepo.findOne({
|
|
246
|
+
filter: {
|
|
247
|
+
sessionId,
|
|
248
|
+
toolCallId
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
if (!toolMessage) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
const aiMessage = await this.aiMessagesRepo.findOne({
|
|
255
|
+
filter: {
|
|
256
|
+
sessionId,
|
|
257
|
+
messageId: toolMessage.messageId
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
if (!aiMessage) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
if (!((_b = (_a = aiMessage.metadata) == null ? void 0 : _a.subAgentConversations) == null ? void 0 : _b.length)) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
const subAgentConversation = aiMessage.metadata.subAgentConversations.find((it) => it.toolCallId == toolCallId);
|
|
267
|
+
if (!subAgentConversation) {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
return subAgentConversation;
|
|
271
|
+
}
|
|
272
|
+
get aiConversationsRepo() {
|
|
273
|
+
return this.plugin.db.getRepository("aiConversations");
|
|
274
|
+
}
|
|
275
|
+
get aiMessagesRepo() {
|
|
276
|
+
return this.plugin.db.getRepository("aiMessages");
|
|
277
|
+
}
|
|
278
|
+
get aiToolMessagesRepo() {
|
|
279
|
+
return this.plugin.db.getRepository("aiToolMessages");
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
283
|
+
0 && (module.exports = {
|
|
284
|
+
AIConversationsManager
|
|
285
|
+
});
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { Model, Transaction } from '@nocobase/database';
|
|
10
10
|
import { LLMProvider } from '../llm-providers/provider';
|
|
11
|
-
import { AIChatContext, AIChatConversation, AIMessageInput, UserDecision } from '../types';
|
|
11
|
+
import { AIChatContext, AIChatConversation, AIMessageInput, AIToolCall, UserDecision } from '../types';
|
|
12
12
|
import { DocumentSegmentedWithScore } from '../features';
|
|
13
13
|
import { KnowledgeBaseGroup } from '../types';
|
|
14
14
|
import { ToolsEntry } from '@nocobase/ai';
|
|
@@ -18,38 +18,59 @@ export interface ModelRef {
|
|
|
18
18
|
llmService: string;
|
|
19
19
|
model: string;
|
|
20
20
|
}
|
|
21
|
+
export interface AIEmployeeOptions {
|
|
22
|
+
ctx: Context;
|
|
23
|
+
employee: Model;
|
|
24
|
+
sessionId: string;
|
|
25
|
+
systemMessage?: string;
|
|
26
|
+
skillSettings?: Record<string, any>;
|
|
27
|
+
webSearch?: boolean;
|
|
28
|
+
model?: ModelRef;
|
|
29
|
+
legacy?: boolean;
|
|
30
|
+
from?: 'main-agent' | 'sub-agent';
|
|
31
|
+
}
|
|
21
32
|
export declare class AIEmployee {
|
|
33
|
+
sessionId: string;
|
|
34
|
+
from: string;
|
|
22
35
|
employee: Model;
|
|
23
36
|
aiChatConversation: AIChatConversation;
|
|
24
37
|
skillSettings?: Record<string, any>;
|
|
25
38
|
private plugin;
|
|
26
39
|
private db;
|
|
27
|
-
private sessionId;
|
|
28
40
|
private ctx;
|
|
29
41
|
private systemMessage;
|
|
42
|
+
private protocol;
|
|
30
43
|
private webSearch?;
|
|
31
44
|
private model?;
|
|
32
45
|
private legacy?;
|
|
33
|
-
|
|
34
|
-
|
|
46
|
+
constructor({ ctx, employee, sessionId, systemMessage, skillSettings, webSearch, model, legacy, from, }: AIEmployeeOptions);
|
|
47
|
+
getFormatMessages(userMessages: AIMessageInput[]): Promise<{
|
|
48
|
+
role: "user" | "assistant" | "tool" | "system";
|
|
49
|
+
content: any;
|
|
50
|
+
tool_call_id?: string;
|
|
51
|
+
tool_calls?: AIToolCall[];
|
|
52
|
+
}[]>;
|
|
35
53
|
private buildState;
|
|
36
54
|
private initSession;
|
|
37
55
|
private buildChatContext;
|
|
38
56
|
stream({ messageId, userMessages, userDecisions, }: {
|
|
39
57
|
messageId?: string;
|
|
40
58
|
userMessages?: AIMessageInput[];
|
|
41
|
-
userDecisions?:
|
|
59
|
+
userDecisions?: {
|
|
60
|
+
interruptId?: string;
|
|
61
|
+
decisions: UserDecision[];
|
|
62
|
+
};
|
|
42
63
|
}): Promise<boolean>;
|
|
43
|
-
invoke({ messageId, userMessages, userDecisions, }: {
|
|
64
|
+
invoke({ messageId, userMessages, userDecisions, writer, context, }: {
|
|
44
65
|
messageId?: string;
|
|
45
66
|
userMessages?: AIMessageInput[];
|
|
46
|
-
userDecisions?:
|
|
67
|
+
userDecisions?: {
|
|
68
|
+
interruptId?: string;
|
|
69
|
+
decisions: UserDecision[];
|
|
70
|
+
};
|
|
71
|
+
writer?: (chunk: any) => void;
|
|
72
|
+
context?: any;
|
|
47
73
|
}): Promise<any>;
|
|
48
|
-
getLLMService(): Promise<{
|
|
49
|
-
provider: LLMProvider;
|
|
50
|
-
model: string;
|
|
51
|
-
service: any;
|
|
52
|
-
}>;
|
|
53
74
|
createAgent({ provider, systemPrompt, tools, middleware, }: {
|
|
54
75
|
provider: LLMProvider;
|
|
55
76
|
systemPrompt?: string;
|
|
@@ -93,7 +114,7 @@ export declare class AIEmployee {
|
|
|
93
114
|
name: string;
|
|
94
115
|
args: any;
|
|
95
116
|
}[]): Promise<Model<AIToolMessage>[]>;
|
|
96
|
-
updateToolCallInterrupted(messageId: string, toolCallId: string, interruptAction: {
|
|
117
|
+
updateToolCallInterrupted(sessionId: string, messageId: string, toolCallId: string, interruptId: string, interruptAction: {
|
|
97
118
|
order: number;
|
|
98
119
|
description?: string;
|
|
99
120
|
allowed_decisions?: string[];
|
|
@@ -103,7 +124,6 @@ export declare class AIEmployee {
|
|
|
103
124
|
confirmToolCall(transaction: Transaction, messageId: string, toolCallIds: string[]): Promise<number>;
|
|
104
125
|
getToolCallResult(messageId: string, toolCallId: string): Promise<AIToolMessage>;
|
|
105
126
|
getToolCallResultMap(messageId: string, toolCallIds: string[]): Promise<Map<string, AIToolMessage>>;
|
|
106
|
-
getUserDecisions(messageId: string): Promise<UserDecision[]>;
|
|
107
127
|
cancelToolCall(): Promise<any>;
|
|
108
128
|
get logger(): any;
|
|
109
129
|
sendErrorResponse(errorMessage: string): void;
|
|
@@ -127,11 +147,13 @@ export declare class AIEmployee {
|
|
|
127
147
|
private getAgentTools;
|
|
128
148
|
getLoadedSkillNames(): Promise<string[]>;
|
|
129
149
|
getActivatedSkillToolNames(): Promise<Set<string>>;
|
|
150
|
+
private getAvailableAIEmployees;
|
|
130
151
|
private getMiddleware;
|
|
131
152
|
private getCurrentThread;
|
|
132
153
|
private forkCurrentThread;
|
|
133
154
|
getToolsMap(): Promise<Map<string, import("@nocobase/ai").ToolsOptions>>;
|
|
134
155
|
private listTools;
|
|
156
|
+
private withRunMetadata;
|
|
135
157
|
private get toolsManager();
|
|
136
158
|
private get aiConversationsRepo();
|
|
137
159
|
private get aiMessagesRepo();
|
|
@@ -140,3 +162,55 @@ export declare class AIEmployee {
|
|
|
140
162
|
private get aiToolMessagesModel();
|
|
141
163
|
private get aiFilesModel();
|
|
142
164
|
}
|
|
165
|
+
export declare class ChatStreamProtocol {
|
|
166
|
+
private readonly streamConsumer;
|
|
167
|
+
private _statistics;
|
|
168
|
+
constructor(streamConsumer: StreamConsumer);
|
|
169
|
+
static fromContext(ctx: Context): ChatStreamProtocol;
|
|
170
|
+
with(conversation: {
|
|
171
|
+
sessionId: string;
|
|
172
|
+
from: string;
|
|
173
|
+
username: string;
|
|
174
|
+
}): {
|
|
175
|
+
startStream: () => void;
|
|
176
|
+
endStream: () => void;
|
|
177
|
+
subAgentCompleted: () => void;
|
|
178
|
+
newMessage: (content?: unknown) => void;
|
|
179
|
+
content: (content: string) => void;
|
|
180
|
+
webSearch: (content: {
|
|
181
|
+
type: string;
|
|
182
|
+
query: string;
|
|
183
|
+
}[]) => void;
|
|
184
|
+
reasoning: (content: {
|
|
185
|
+
status: string;
|
|
186
|
+
content: string;
|
|
187
|
+
}) => void;
|
|
188
|
+
stopReasoning: () => void;
|
|
189
|
+
toolCallChunks: (content: unknown) => void;
|
|
190
|
+
toolCalls: (content: unknown) => void;
|
|
191
|
+
toolCallStatus: ({ toolCall, invokeStatus, status, invokeStartTime, invokeEndTime, content, interruptAction, }: {
|
|
192
|
+
toolCall: {
|
|
193
|
+
messageId: string;
|
|
194
|
+
id: string;
|
|
195
|
+
name: string;
|
|
196
|
+
willInterrupt: boolean;
|
|
197
|
+
};
|
|
198
|
+
invokeStatus: string;
|
|
199
|
+
status?: string;
|
|
200
|
+
invokeStartTime?: string | Date | null;
|
|
201
|
+
invokeEndTime?: string | Date | null;
|
|
202
|
+
content?: unknown;
|
|
203
|
+
interruptAction?: {
|
|
204
|
+
order: number;
|
|
205
|
+
description: string;
|
|
206
|
+
allowedDecisions: string[];
|
|
207
|
+
};
|
|
208
|
+
}) => void;
|
|
209
|
+
};
|
|
210
|
+
get statistics(): {
|
|
211
|
+
sent: number;
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
export type StreamConsumer = {
|
|
215
|
+
write: (chunk: any) => void;
|
|
216
|
+
};
|