@nocobase/plugin-ai 2.2.0-beta.12 → 2.2.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/docs/nocobase/ai-employees/scenarios/company-background-research.md +125 -0
- package/dist/ai/docs/nocobase/building-tips/operations-dashboard.md +513 -0
- package/dist/ai/docs/nocobase/file-manager/stable-url.md +87 -0
- package/dist/ai/docs/nocobase/get-started/deployment/production.md +24 -2
- package/dist/ai/docs/nocobase/get-started/installation/docker-caddy.mdx +3 -0
- package/dist/ai/docs/nocobase/get-started/installation/docker-nginx.mdx +3 -0
- package/dist/ai/docs/nocobase/get-started/installation/docker.mdx +27 -3
- package/dist/ai/docs/nocobase/get-started/installation/env.md +33 -0
- package/dist/ai/docs/nocobase/index.md +1 -1
- package/dist/ai/docs/nocobase/multi-app/multi-app-vs-multi-portal-vs-multi-space.md +159 -0
- package/dist/ai/docs/nocobase/multi-app/multi-portal/index.md +195 -0
- package/dist/ai/docs/nocobase/nocobase-cli/production/index.md +10 -0
- package/dist/ai/docs/nocobase/nocobase-cli/production/reverse-proxy/caddy.md +15 -2
- package/dist/ai/docs/nocobase/nocobase-cli/production/reverse-proxy/index.md +1 -1
- package/dist/ai/docs/nocobase/nocobase-cli/production/reverse-proxy/nginx.md +16 -2
- package/dist/ai/docs/nocobase/tutorials/index.md +20 -1
- package/dist/client/646.051c1437c9ca4fd4.js +10 -0
- package/dist/client/index.js +3 -3
- package/dist/externalVersion.js +16 -16
- package/dist/locale/en-US.json +2 -0
- package/dist/locale/zh-CN.json +2 -0
- package/dist/node_modules/@langchain/mistralai/package.json +1 -1
- package/dist/node_modules/@langchain/xai/package.json +1 -1
- package/dist/node_modules/fs-extra/package.json +1 -1
- package/dist/node_modules/jsonrepair/package.json +1 -1
- package/dist/node_modules/just-bash/package.json +1 -1
- package/dist/node_modules/nodejs-snowflake/package.json +1 -1
- package/dist/node_modules/openai/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/ai-employees/ai-employee.d.ts +1 -0
- package/dist/server/ai-employees/ai-employee.js +30 -1
- package/dist/server/attachments.d.ts +24 -0
- package/dist/server/attachments.js +204 -0
- package/dist/server/document-loader/cached.d.ts +1 -0
- package/dist/server/document-loader/cached.js +18 -9
- package/dist/server/document-loader/loader.d.ts +0 -1
- package/dist/server/document-loader/loader.js +25 -8
- package/dist/server/document-loader/types.d.ts +7 -0
- package/dist/server/llm-providers/anthropic.d.ts +2 -1
- package/dist/server/llm-providers/anthropic.js +1 -3
- package/dist/server/llm-providers/google-genai.d.ts +1 -1
- package/dist/server/llm-providers/google-genai.js +1 -5
- package/dist/server/llm-providers/provider.d.ts +3 -2
- package/dist/server/llm-providers/provider.js +26 -3
- package/dist/server/plugin.js +14 -0
- package/dist/server/resource/aiConversations.js +44 -1
- package/dist/server/utils.d.ts +5 -2
- package/dist/server/utils.js +11 -19
- package/dist/server/workflow/nodes/employee/files.d.ts +3 -1
- package/dist/server/workflow/nodes/employee/files.js +31 -5
- package/package.json +2 -2
- package/dist/client/646.2e395a514c511084.js +0 -10
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
var __create = Object.create;
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
11
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
15
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
16
|
var __export = (target, all) => {
|
|
15
17
|
for (var name in all)
|
|
@@ -23,6 +25,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
25
|
}
|
|
24
26
|
return to;
|
|
25
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
|
+
));
|
|
26
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
37
|
var loader_exports = {};
|
|
28
38
|
__export(loader_exports, {
|
|
@@ -32,6 +42,11 @@ module.exports = __toCommonJS(loader_exports);
|
|
|
32
42
|
var import_constants = require("./constants");
|
|
33
43
|
var import_utils = require("./utils");
|
|
34
44
|
var import_ai = require("@nocobase/ai");
|
|
45
|
+
var import_node_fs = require("node:fs");
|
|
46
|
+
var import_promises = require("node:fs/promises");
|
|
47
|
+
var import_node_os = __toESM(require("node:os"));
|
|
48
|
+
var import_node_path = __toESM(require("node:path"));
|
|
49
|
+
var import_promises2 = require("node:stream/promises");
|
|
35
50
|
class DocumentLoader {
|
|
36
51
|
constructor(fileManager) {
|
|
37
52
|
this.fileManager = fileManager;
|
|
@@ -42,15 +57,17 @@ class DocumentLoader {
|
|
|
42
57
|
return [];
|
|
43
58
|
}
|
|
44
59
|
const { stream, contentType } = await this.fileManager.getFileStream(file, options);
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
const tempDir = await (0, import_promises.mkdtemp)(import_node_path.default.join(import_node_os.default.tmpdir(), "nocobase-document-loader-"));
|
|
61
|
+
const tempFilePath = import_node_path.default.join(tempDir, `source${extname}`);
|
|
62
|
+
try {
|
|
63
|
+
await (0, import_promises2.pipeline)(stream, (0, import_node_fs.createWriteStream)(tempFilePath));
|
|
64
|
+
return await (0, import_ai.loadByWorker)(extname, {
|
|
65
|
+
filePath: tempFilePath,
|
|
66
|
+
mimeType: contentType ?? file.mimetype
|
|
67
|
+
});
|
|
68
|
+
} finally {
|
|
69
|
+
await (0, import_promises.rm)(tempDir, { recursive: true, force: true });
|
|
52
70
|
}
|
|
53
|
-
return new Blob(chunks, { type: mimeType });
|
|
54
71
|
}
|
|
55
72
|
}
|
|
56
73
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -31,6 +31,13 @@ export type ParseableFile = {
|
|
|
31
31
|
storageId?: number;
|
|
32
32
|
meta?: Record<string, any>;
|
|
33
33
|
size?: number;
|
|
34
|
+
source?: {
|
|
35
|
+
dataSourceKey?: string;
|
|
36
|
+
collectionName?: string;
|
|
37
|
+
field?: string;
|
|
38
|
+
documentCache?: boolean;
|
|
39
|
+
trustworthy?: boolean;
|
|
40
|
+
};
|
|
34
41
|
};
|
|
35
42
|
export type DocumentLoaderLike = {
|
|
36
43
|
load(file: ParseableFile, options?: any): Promise<Document[]>;
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { LLMProvider, ParsedAttachmentResult } from './provider';
|
|
10
10
|
import { ChatAnthropic } from '@langchain/anthropic';
|
|
11
|
+
import type { AttachmentModel } from '@nocobase/plugin-file-manager';
|
|
11
12
|
import { Model } from '@nocobase/database';
|
|
12
13
|
import { LLMProviderMeta } from '../manager/ai-manager';
|
|
13
14
|
import { Context } from '@nocobase/actions';
|
|
@@ -36,7 +37,7 @@ export declare class AnthropicProvider extends LLMProvider {
|
|
|
36
37
|
type: string;
|
|
37
38
|
query: string;
|
|
38
39
|
}[];
|
|
39
|
-
protected convertToContent(ctx: Context, attachment:
|
|
40
|
+
protected convertToContent(ctx: Context, attachment: AttachmentModel): Promise<ParsedAttachmentResult>;
|
|
40
41
|
private setMaxTokens;
|
|
41
42
|
}
|
|
42
43
|
export declare const anthropicProviderOptions: LLMProviderMeta;
|
|
@@ -186,9 +186,7 @@ class AnthropicProvider extends import_provider.LLMProvider {
|
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
188
|
async convertToContent(ctx, attachment) {
|
|
189
|
-
const
|
|
190
|
-
const url = await fileManager.getFileURL(attachment);
|
|
191
|
-
const data = await (0, import_utils2.encodeFile)(ctx, decodeURIComponent(url));
|
|
189
|
+
const data = await this.encodeAttachment(ctx, attachment);
|
|
192
190
|
if (attachment.mimetype.startsWith("image/")) {
|
|
193
191
|
return {
|
|
194
192
|
placement: "contentBlocks",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
|
|
10
10
|
import { EmbeddingProvider, LLMProvider, ParsedAttachmentResult } from './provider';
|
|
11
11
|
import { Model } from '@nocobase/database';
|
|
12
|
-
import { AttachmentModel } from '@nocobase/plugin-file-manager';
|
|
12
|
+
import type { AttachmentModel } from '@nocobase/plugin-file-manager';
|
|
13
13
|
import { LLMProviderMeta } from '../manager/ai-manager';
|
|
14
14
|
import { EmbeddingsInterface } from '@langchain/core/embeddings';
|
|
15
15
|
import { Context } from '@nocobase/actions';
|
|
@@ -34,7 +34,6 @@ module.exports = __toCommonJS(google_genai_exports);
|
|
|
34
34
|
var import_google_genai = require("@langchain/google-genai");
|
|
35
35
|
var import_provider = require("./provider");
|
|
36
36
|
var import_utils = require("@nocobase/utils");
|
|
37
|
-
var import_utils2 = require("../utils");
|
|
38
37
|
var import_ai_manager = require("../manager/ai-manager");
|
|
39
38
|
const GOOGLE_GEN_AI_URL = "https://generativelanguage.googleapis.com";
|
|
40
39
|
class GoogleGenAIProvider extends import_provider.LLMProvider {
|
|
@@ -120,10 +119,8 @@ class GoogleGenAIProvider extends import_provider.LLMProvider {
|
|
|
120
119
|
}
|
|
121
120
|
async convertToContent(ctx, attachment) {
|
|
122
121
|
var _a;
|
|
123
|
-
const
|
|
124
|
-
const url = await fileManager.getFileURL(attachment);
|
|
122
|
+
const data = await this.encodeAttachment(ctx, attachment);
|
|
125
123
|
if ((_a = attachment.mimetype) == null ? void 0 : _a.startsWith("image/")) {
|
|
126
|
-
const data = await (0, import_utils2.encodeFile)(ctx, decodeURIComponent(url));
|
|
127
124
|
return {
|
|
128
125
|
placement: "contentBlocks",
|
|
129
126
|
content: {
|
|
@@ -134,7 +131,6 @@ class GoogleGenAIProvider extends import_provider.LLMProvider {
|
|
|
134
131
|
}
|
|
135
132
|
};
|
|
136
133
|
} else {
|
|
137
|
-
const data = await (0, import_utils2.encodeFile)(ctx, decodeURIComponent(url));
|
|
138
134
|
return {
|
|
139
135
|
placement: "contentBlocks",
|
|
140
136
|
content: {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
10
10
|
import { Model } from '@nocobase/database';
|
|
11
|
-
import { AttachmentModel } from '@nocobase/plugin-file-manager';
|
|
11
|
+
import { type AttachmentModel } from '@nocobase/plugin-file-manager';
|
|
12
12
|
import { Application } from '@nocobase/server';
|
|
13
13
|
import { AIChatContext, AIMessageInput } from '../types/ai-chat-conversation.type';
|
|
14
14
|
import { EmbeddingsInterface } from '@langchain/core/embeddings';
|
|
@@ -69,7 +69,8 @@ export declare abstract class LLMProvider {
|
|
|
69
69
|
parseAttachment(ctx: Context, attachment: AttachmentModel): Promise<ParsedAttachmentResult>;
|
|
70
70
|
protected isApiSupportedAttachment(attachment: AttachmentModel): boolean;
|
|
71
71
|
protected isDocumentLoaderSupportedAttachment(attachment: AttachmentModel): boolean;
|
|
72
|
-
protected
|
|
72
|
+
protected encodeAttachment(ctx: Context, attachment: AttachmentModel): Promise<string>;
|
|
73
|
+
protected convertToContent(ctx: Context, attachment: AttachmentModel): Promise<ParsedAttachmentResult>;
|
|
73
74
|
protected loadDocument(ctx: Context, attachment: any): Promise<any>;
|
|
74
75
|
getStructuredOutputOptions(structuredOutput: AIChatContext['structuredOutput']): any;
|
|
75
76
|
testFlight(): Promise<{
|
|
@@ -183,6 +183,15 @@ class LLMProvider {
|
|
|
183
183
|
return (0, import_utils2.stripToolCallTags)(chunk);
|
|
184
184
|
}
|
|
185
185
|
async parseAttachment(ctx, attachment) {
|
|
186
|
+
var _a;
|
|
187
|
+
const dataSourceKey = (_a = attachment == null ? void 0 : attachment.source) == null ? void 0 : _a.dataSourceKey;
|
|
188
|
+
const isExternalAttachment = Boolean(dataSourceKey && dataSourceKey !== "main");
|
|
189
|
+
if (!(attachment == null ? void 0 : attachment.storageId) && !isExternalAttachment || !(attachment == null ? void 0 : attachment.filename)) {
|
|
190
|
+
return {
|
|
191
|
+
placement: "system",
|
|
192
|
+
content: "The user provided an attachment, but it is unavailable or invalid and cannot be parsed. Do not use this attachment as evidence; tell the user the attachment is unavailable."
|
|
193
|
+
};
|
|
194
|
+
}
|
|
186
195
|
if (this.isApiSupportedAttachment(attachment)) {
|
|
187
196
|
return await this.convertToContent(ctx, attachment);
|
|
188
197
|
} else if (this.isDocumentLoaderSupportedAttachment(attachment)) {
|
|
@@ -212,10 +221,24 @@ class LLMProvider {
|
|
|
212
221
|
const ext = import_node_path.default.extname((attachment == null ? void 0 : attachment.filename) ?? "").toLocaleLowerCase();
|
|
213
222
|
return import_document_loader.SUPPORTED_DOCUMENT_EXTNAMES.includes(ext);
|
|
214
223
|
}
|
|
215
|
-
async
|
|
224
|
+
async encodeAttachment(ctx, attachment) {
|
|
216
225
|
const fileManager = this.app.pm.get("file-manager");
|
|
217
|
-
|
|
218
|
-
|
|
226
|
+
if (typeof ctx.get !== "function") {
|
|
227
|
+
const { stream: stream2 } = await fileManager.getFileStream(attachment);
|
|
228
|
+
return await (0, import_utils2.encodeReadableStream)(stream2);
|
|
229
|
+
}
|
|
230
|
+
const { stream } = await fileManager.getFileStream(attachment, {
|
|
231
|
+
requestOptions: {
|
|
232
|
+
headers: {
|
|
233
|
+
Referer: ctx.get("referer") || "",
|
|
234
|
+
"User-Agent": ctx.get("user-agent") || ""
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
return await (0, import_utils2.encodeReadableStream)(stream);
|
|
239
|
+
}
|
|
240
|
+
async convertToContent(ctx, attachment) {
|
|
241
|
+
const data = await this.encodeAttachment(ctx, attachment);
|
|
219
242
|
if (attachment.mimetype.startsWith("image/")) {
|
|
220
243
|
return {
|
|
221
244
|
placement: "contentBlocks",
|
package/dist/server/plugin.js
CHANGED
|
@@ -80,6 +80,7 @@ var import_sub_agents = require("./ai-employees/sub-agents");
|
|
|
80
80
|
var import_employee = require("./workflow/nodes/employee");
|
|
81
81
|
var import_ai_knowledge_base = require("./ai-employees/ai-knowledge-base");
|
|
82
82
|
var import_llm_stream_manager = require("./manager/llm-stream-manager");
|
|
83
|
+
var import_attachments = require("./attachments");
|
|
83
84
|
class PluginAIServer extends import_server.Plugin {
|
|
84
85
|
features = new import_ai_feature_manager.AIPluginFeatureManagerImpl();
|
|
85
86
|
aiManager = new import_ai_manager.AIManager(this);
|
|
@@ -218,6 +219,19 @@ class PluginAIServer extends import_server.Plugin {
|
|
|
218
219
|
},
|
|
219
220
|
{ before: "createMiddleware" }
|
|
220
221
|
);
|
|
222
|
+
this.app.resourceManager.use(
|
|
223
|
+
async (ctx, next) => {
|
|
224
|
+
const { resourceName, actionName } = ctx.action;
|
|
225
|
+
if (resourceName === "aiFiles" && actionName === "create") {
|
|
226
|
+
(0, import_attachments.appendAIFileAttachmentSource)(ctx.action.params.values);
|
|
227
|
+
}
|
|
228
|
+
await next();
|
|
229
|
+
if (resourceName === "aiFiles" && actionName === "create") {
|
|
230
|
+
(0, import_attachments.appendAIFileAttachmentSource)(ctx.body);
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
{ after: "createMiddleware" }
|
|
234
|
+
);
|
|
221
235
|
Object.entries(aiEmployeeActions).forEach(([name, action]) => {
|
|
222
236
|
this.app.resourceManager.registerActionHandler(`aiEmployees:${name}`, action);
|
|
223
237
|
});
|
|
@@ -103,6 +103,33 @@ const saveUserMessages = async (ctx, sessionId, messages, messageId) => {
|
|
|
103
103
|
await conversation.addMessages(userMessages);
|
|
104
104
|
});
|
|
105
105
|
};
|
|
106
|
+
function isRecord(value) {
|
|
107
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
108
|
+
}
|
|
109
|
+
function normalizeIncomingMessageAttachments(ctx, messages) {
|
|
110
|
+
for (const message of messages) {
|
|
111
|
+
if (message.attachments == null) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (!Array.isArray(message.attachments)) {
|
|
115
|
+
throw new import_utils.ResourceActionError(400, ctx.t("Invalid attachment"));
|
|
116
|
+
}
|
|
117
|
+
message.attachments = message.attachments.map((attachment) => {
|
|
118
|
+
if (!isRecord(attachment) || !isRecord(attachment.source)) {
|
|
119
|
+
throw new import_utils.ResourceActionError(400, ctx.t("Invalid attachment"));
|
|
120
|
+
}
|
|
121
|
+
const source = { ...attachment.source };
|
|
122
|
+
delete source.trustworthy;
|
|
123
|
+
if (typeof source.collectionName !== "string" || !source.collectionName) {
|
|
124
|
+
throw new import_utils.ResourceActionError(400, ctx.t("Invalid attachment"));
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
...attachment,
|
|
128
|
+
source
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
106
133
|
var aiConversations_default = {
|
|
107
134
|
name: "aiConversations",
|
|
108
135
|
middlewares: [
|
|
@@ -329,6 +356,7 @@ var aiConversations_default = {
|
|
|
329
356
|
if (!Array.isArray(messages)) {
|
|
330
357
|
throw new import_utils.ResourceActionError(400, ctx.t("messages must be an array"));
|
|
331
358
|
}
|
|
359
|
+
normalizeIncomingMessageAttachments(ctx, messages);
|
|
332
360
|
const userMessage = messages.find((message) => message.role === "user");
|
|
333
361
|
if (!userMessage) {
|
|
334
362
|
throw new import_utils.ResourceActionError(400, ctx.t("user message is required"));
|
|
@@ -633,6 +661,13 @@ var aiConversations_default = {
|
|
|
633
661
|
if (!message) {
|
|
634
662
|
ctx.throw(400);
|
|
635
663
|
}
|
|
664
|
+
const messageConversation = await plugin.aiConversationsManager.getConversation({
|
|
665
|
+
sessionId: message.sessionId,
|
|
666
|
+
userId
|
|
667
|
+
});
|
|
668
|
+
if (!messageConversation) {
|
|
669
|
+
ctx.throw(400);
|
|
670
|
+
}
|
|
636
671
|
const toolCalls = message.toolCalls;
|
|
637
672
|
if (!(toolCalls == null ? void 0 : toolCalls.length)) {
|
|
638
673
|
ctx.throw(400);
|
|
@@ -730,6 +765,14 @@ var aiConversations_default = {
|
|
|
730
765
|
sendErrorResponse(ctx, "message not found");
|
|
731
766
|
return next();
|
|
732
767
|
}
|
|
768
|
+
const messageConversation = await plugin.aiConversationsManager.getConversation({
|
|
769
|
+
sessionId: message.sessionId,
|
|
770
|
+
userId
|
|
771
|
+
});
|
|
772
|
+
if (!messageConversation) {
|
|
773
|
+
sendErrorResponse(ctx, "conversation not found");
|
|
774
|
+
return next();
|
|
775
|
+
}
|
|
733
776
|
const tools = message.toolCalls;
|
|
734
777
|
if (!(tools == null ? void 0 : tools.length)) {
|
|
735
778
|
sendErrorResponse(ctx, "No tool calls found");
|
|
@@ -746,7 +789,7 @@ var aiConversations_default = {
|
|
|
746
789
|
webSearch,
|
|
747
790
|
model: resolvedModel
|
|
748
791
|
});
|
|
749
|
-
const userDecisions = await plugin.aiConversationsManager.getUserDecisions(messageId);
|
|
792
|
+
const userDecisions = await plugin.aiConversationsManager.getUserDecisions(message.messageId);
|
|
750
793
|
await aiEmployee.stream({
|
|
751
794
|
userDecisions
|
|
752
795
|
});
|
package/dist/server/utils.d.ts
CHANGED
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
+
/// <reference types="node" />
|
|
9
10
|
import { Model } from '@nocobase/database';
|
|
10
11
|
import { Context } from '@nocobase/actions';
|
|
11
12
|
import { ToolsEntry } from '@nocobase/ai';
|
|
13
|
+
import type { Readable } from 'stream';
|
|
12
14
|
export declare function sendSSEError(ctx: Context, error: Error | string, errorName?: string): void;
|
|
13
15
|
export declare function stripToolCallTags(content: string): string | null;
|
|
14
16
|
export declare function parseResponseMessage(row: Model): {
|
|
@@ -17,8 +19,9 @@ export declare function parseResponseMessage(row: Model): {
|
|
|
17
19
|
content: any;
|
|
18
20
|
role: any;
|
|
19
21
|
};
|
|
20
|
-
export declare function encodeLocalFile(
|
|
21
|
-
export declare function encodeFile(ctx: Context, url: string): Promise<string>;
|
|
22
|
+
export declare function encodeLocalFile(_url: string): Promise<void>;
|
|
23
|
+
export declare function encodeFile(ctx: Context, url: string): Promise<string | void>;
|
|
24
|
+
export declare function encodeReadableStream(stream: Readable): Promise<string>;
|
|
22
25
|
export declare function parseVariables(ctx: Context, value: string): Promise<any>;
|
|
23
26
|
export declare const buildTool: (toolsEntry: ToolsEntry) => import("@langchain/core/dist/tools").DynamicTool<any, unknown>;
|
|
24
27
|
export declare class ResourceActionError extends Error {
|
package/dist/server/utils.js
CHANGED
|
@@ -7,11 +7,9 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
var __create = Object.create;
|
|
11
10
|
var __defProp = Object.defineProperty;
|
|
12
11
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
12
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
13
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
14
|
var __export = (target, all) => {
|
|
17
15
|
for (var name in all)
|
|
@@ -25,14 +23,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
25
23
|
}
|
|
26
24
|
return to;
|
|
27
25
|
};
|
|
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
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
27
|
var utils_exports = {};
|
|
38
28
|
__export(utils_exports, {
|
|
@@ -40,14 +30,13 @@ __export(utils_exports, {
|
|
|
40
30
|
buildTool: () => buildTool,
|
|
41
31
|
encodeFile: () => encodeFile,
|
|
42
32
|
encodeLocalFile: () => encodeLocalFile,
|
|
33
|
+
encodeReadableStream: () => encodeReadableStream,
|
|
43
34
|
parseResponseMessage: () => parseResponseMessage,
|
|
44
35
|
parseVariables: () => parseVariables,
|
|
45
36
|
sendSSEError: () => sendSSEError,
|
|
46
37
|
stripToolCallTags: () => stripToolCallTags
|
|
47
38
|
});
|
|
48
39
|
module.exports = __toCommonJS(utils_exports);
|
|
49
|
-
var import_path = __toESM(require("path"));
|
|
50
|
-
var import_fs = __toESM(require("fs"));
|
|
51
40
|
var import_utils = require("@nocobase/utils");
|
|
52
41
|
var import_langchain = require("langchain");
|
|
53
42
|
function sendSSEError(ctx, error, errorName) {
|
|
@@ -91,13 +80,8 @@ function parseResponseMessage(row) {
|
|
|
91
80
|
role
|
|
92
81
|
};
|
|
93
82
|
}
|
|
94
|
-
async function encodeLocalFile(
|
|
95
|
-
|
|
96
|
-
url = url.slice(process.env.APP_PUBLIC_PATH.length);
|
|
97
|
-
}
|
|
98
|
-
url = import_path.default.join(process.cwd(), url);
|
|
99
|
-
const data = await import_fs.default.promises.readFile(url);
|
|
100
|
-
return Buffer.from(data).toString("base64");
|
|
83
|
+
async function encodeLocalFile(_url) {
|
|
84
|
+
throw new Error("Local file path is not allowed");
|
|
101
85
|
}
|
|
102
86
|
async function encodeFile(ctx, url) {
|
|
103
87
|
if (!url.startsWith("http")) {
|
|
@@ -117,6 +101,13 @@ async function encodeFile(ctx, url) {
|
|
|
117
101
|
});
|
|
118
102
|
return Buffer.from(response.data).toString("base64");
|
|
119
103
|
}
|
|
104
|
+
async function encodeReadableStream(stream) {
|
|
105
|
+
const chunks = [];
|
|
106
|
+
for await (const chunk of stream) {
|
|
107
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
108
|
+
}
|
|
109
|
+
return Buffer.concat(chunks).toString("base64");
|
|
110
|
+
}
|
|
120
111
|
async function getUser(ctx, fields) {
|
|
121
112
|
const userFields = fields.filter((f) => f && ctx.db.getFieldByPath("users." + f));
|
|
122
113
|
if (!ctx.state.currentUser) {
|
|
@@ -193,6 +184,7 @@ class ResourceActionError extends Error {
|
|
|
193
184
|
buildTool,
|
|
194
185
|
encodeFile,
|
|
195
186
|
encodeLocalFile,
|
|
187
|
+
encodeReadableStream,
|
|
196
188
|
parseResponseMessage,
|
|
197
189
|
parseVariables,
|
|
198
190
|
sendSSEError,
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
import { AIEmployeeInstructionFiles } from './types';
|
|
10
10
|
import { Plugin } from '@nocobase/server';
|
|
11
11
|
export declare abstract class Files {
|
|
12
|
-
static resolvers(plugin: Plugin, attachmentPart:
|
|
12
|
+
static resolvers(plugin: Plugin, attachmentPart: {
|
|
13
|
+
attachments?: unknown[];
|
|
14
|
+
}): {
|
|
13
15
|
resolveAttachments: (files: AIEmployeeInstructionFiles[]) => Promise<void>;
|
|
14
16
|
resolveFileIds: (files: AIEmployeeInstructionFiles[]) => Promise<void>;
|
|
15
17
|
resolveUrls: (files: AIEmployeeInstructionFiles[]) => Promise<void>;
|
|
@@ -45,10 +45,25 @@ var import_node_path = __toESM(require("node:path"));
|
|
|
45
45
|
var import_lodash = __toESM(require("lodash"));
|
|
46
46
|
var import_axios = __toESM(require("axios"));
|
|
47
47
|
var import_utils = require("../../utils");
|
|
48
|
+
var import_attachments = require("../../../attachments");
|
|
49
|
+
function appendSource(record, source) {
|
|
50
|
+
if (!record || typeof record !== "object" || Array.isArray(record)) {
|
|
51
|
+
return record;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
...record,
|
|
55
|
+
source
|
|
56
|
+
};
|
|
57
|
+
}
|
|
48
58
|
class Files {
|
|
49
59
|
static resolvers(plugin, attachmentPart) {
|
|
50
60
|
const resolveAttachments = async (files) => {
|
|
51
|
-
const attachments = files.filter((it) => it.type === "attachments").flatMap((it) => import_lodash.default.isArray(it.value) ? it.value : [it.value])
|
|
61
|
+
const attachments = files.filter((it) => it.type === "attachments").flatMap((it) => import_lodash.default.isArray(it.value) ? it.value : [it.value]).map(
|
|
62
|
+
(attachment) => appendSource(attachment, {
|
|
63
|
+
...(0, import_attachments.getAttachmentSource)(attachment) ?? {},
|
|
64
|
+
trustworthy: true
|
|
65
|
+
})
|
|
66
|
+
);
|
|
52
67
|
if (attachments.length) {
|
|
53
68
|
attachmentPart.attachments = [...attachmentPart.attachments ?? [], ...attachments];
|
|
54
69
|
}
|
|
@@ -78,7 +93,13 @@ class Files {
|
|
|
78
93
|
}
|
|
79
94
|
attachmentPart.attachments = [
|
|
80
95
|
...attachmentPart.attachments ?? [],
|
|
81
|
-
...attachmentModels.map(
|
|
96
|
+
...attachmentModels.map(
|
|
97
|
+
(it) => appendSource(it.toJSON(), {
|
|
98
|
+
dataSourceKey: "main",
|
|
99
|
+
collectionName: collection,
|
|
100
|
+
trustworthy: true
|
|
101
|
+
})
|
|
102
|
+
)
|
|
82
103
|
];
|
|
83
104
|
}
|
|
84
105
|
}
|
|
@@ -106,14 +127,19 @@ class Files {
|
|
|
106
127
|
filePath: tempFilePath,
|
|
107
128
|
storageName,
|
|
108
129
|
values: {
|
|
109
|
-
|
|
130
|
+
title: fileIdentity.title,
|
|
110
131
|
mimetype: contentType,
|
|
111
132
|
meta: {
|
|
112
|
-
sourceUrl: url
|
|
133
|
+
sourceUrl: url,
|
|
134
|
+
originalFilename: fileIdentity.filename
|
|
113
135
|
}
|
|
114
136
|
}
|
|
115
137
|
});
|
|
116
|
-
return created.toJSON()
|
|
138
|
+
return appendSource(created.toJSON(), {
|
|
139
|
+
dataSourceKey: "main",
|
|
140
|
+
collectionName: "aiFiles",
|
|
141
|
+
trustworthy: true
|
|
142
|
+
});
|
|
117
143
|
} finally {
|
|
118
144
|
await import_promises.default.rm(tempFilePath, { force: true });
|
|
119
145
|
}
|
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.2.0-beta.
|
|
9
|
+
"version": "2.2.0-beta.14",
|
|
10
10
|
"main": "dist/server/index.js",
|
|
11
11
|
"homepage": "https://docs.nocobase.com/handbook/action-ai",
|
|
12
12
|
"homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/action-ai",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"keywords": [
|
|
67
67
|
"AI"
|
|
68
68
|
],
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "1ef021f3ce0a84469e40f181a19551a50b6f850c"
|
|
70
70
|
}
|