@nocobase/plugin-ai 2.1.0-beta.13 → 2.1.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.
Files changed (44) hide show
  1. package/dist/client/{35156dfea5f288fa.js → 204.91be8cfc54d91a59.js} +1 -1
  2. package/dist/client/ai-employees/chatbox/hooks/useChatMessageActions.d.ts +2 -0
  3. package/dist/client/index.js +3 -3
  4. package/dist/externalVersion.js +16 -16
  5. package/dist/node_modules/fast-glob/package.json +1 -1
  6. package/dist/node_modules/flexsearch/package.json +1 -1
  7. package/dist/node_modules/fs-extra/package.json +1 -1
  8. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  9. package/dist/node_modules/openai/package.json +1 -1
  10. package/dist/node_modules/zod/package.json +1 -1
  11. package/dist/server/ai-employees/ai-employee.js +5 -0
  12. package/dist/server/llm-providers/anthropic.d.ts +2 -2
  13. package/dist/server/llm-providers/anthropic.js +1 -1
  14. package/dist/server/llm-providers/dashscope.d.ts +2 -3
  15. package/dist/server/llm-providers/dashscope.js +3 -28
  16. package/dist/server/llm-providers/deepseek.d.ts +2 -3
  17. package/dist/server/llm-providers/deepseek.js +2 -31
  18. package/dist/server/llm-providers/google-genai.d.ts +3 -18
  19. package/dist/server/llm-providers/google-genai.js +9 -7
  20. package/dist/server/llm-providers/kimi/provider.d.ts +4 -4
  21. package/dist/server/llm-providers/kimi/provider.js +3 -28
  22. package/dist/server/llm-providers/provider.d.ts +11 -2
  23. package/dist/server/llm-providers/provider.js +60 -0
  24. package/dist/server/manager/ai-chat-conversation.js +6 -2
  25. package/dist/server/utils.js +3 -2
  26. package/package.json +2 -2
  27. /package/dist/client/{1a5eedf9bc8e8a4e.js → 107.64d9efa24d6b9143.js} +0 -0
  28. /package/dist/client/{9ac6d4760aecc4ba.js → 124.768c8aa5d6e6b461.js} +0 -0
  29. /package/dist/client/{031e76adc8e418c0.js → 159.d52107c7a34ce2da.js} +0 -0
  30. /package/dist/client/{5672875b55ce455d.js → 192.0419770b69678994.js} +0 -0
  31. /package/dist/client/{3a04632b58ae88ec.js → 238.9f784a7cdb751999.js} +0 -0
  32. /package/dist/client/{6f06d6017f0c35fe.js → 263.6e1dfb1cbb1964f5.js} +0 -0
  33. /package/dist/client/{154167de2cbe8144.js → 35.5ee7503d9c09daa8.js} +0 -0
  34. /package/dist/client/{05bb46e182de283c.js → 47.6bd245f2140efd24.js} +0 -0
  35. /package/dist/client/{d42de7ae09b416c1.js → 481.03b3d2306d409933.js} +0 -0
  36. /package/dist/client/{d1c1b405bbcb3d80.js → 524.954f96ec4fc2fd7a.js} +0 -0
  37. /package/dist/client/{372594b4121f3e21.js → 586.6a1510cabaa84f23.js} +0 -0
  38. /package/dist/client/{f4b27eaa2f42f3b6.js → 650.8871a07b31c307ea.js} +0 -0
  39. /package/dist/client/{c49179ef6fcbc972.js → 755.e295bbd2b2a1cc21.js} +0 -0
  40. /package/dist/client/{a28774e6b2ca1fa1.js → 772.d51f683c55e18dd4.js} +0 -0
  41. /package/dist/client/{a0a62fe07b8187c2.js → 870.84187dcb8c89b4dc.js} +0 -0
  42. /package/dist/client/{a2b9e4140138455f.js → 91.90e7098b7fbd5d00.js} +0 -0
  43. /package/dist/client/{4ef570b622fa76c4.js → 933.baab3aa75f30e020.js} +0 -0
  44. /package/dist/client/{7f65c7eb3e7c2e8e.js → 987.3aee964e7f406939.js} +0 -0
@@ -8,6 +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
12
  import { Application } from '@nocobase/server';
12
13
  import { AIChatContext } from '../types/ai-chat-conversation.type';
13
14
  import { EmbeddingsInterface } from '@langchain/core/embeddings';
@@ -15,6 +16,8 @@ import { AIMessageChunk } from '@langchain/core/messages';
15
16
  import { Context } from '@nocobase/actions';
16
17
  import '@langchain/core/utils/stream';
17
18
  import { LLMResult } from '@langchain/core/outputs';
19
+ import { CachedDocumentLoader } from '../document-loader';
20
+ import PluginAIServer from '../plugin';
18
21
  export type ParsedAttachmentResult = {
19
22
  placement: string;
20
23
  content: any;
@@ -30,7 +33,7 @@ export declare abstract class LLMProvider {
30
33
  modelOptions: Record<string, any>;
31
34
  chatModel: any;
32
35
  abstract createModel(): BaseChatModel | any;
33
- get baseURL(): any;
36
+ get baseURL(): string | null;
34
37
  constructor(opts: LLMProviderOptions);
35
38
  prepareChain(context: AIChatContext): any;
36
39
  invoke(context: AIChatContext, options?: any): Promise<any>;
@@ -48,7 +51,11 @@ export declare abstract class LLMProvider {
48
51
  role: any;
49
52
  };
50
53
  parseResponseChunk(chunk: any): string;
51
- parseAttachment(ctx: Context, attachment: any): Promise<ParsedAttachmentResult>;
54
+ parseAttachment(ctx: Context, attachment: AttachmentModel): Promise<ParsedAttachmentResult>;
55
+ protected isApiSupportedAttachment(attachment: AttachmentModel): boolean;
56
+ protected isDocumentLoaderSupportedAttachment(attachment: AttachmentModel): boolean;
57
+ protected convertToContent(ctx: Context, attachment: any): Promise<ParsedAttachmentResult>;
58
+ protected loadDocument(_ctx: Context, attachment: any): Promise<any>;
52
59
  getStructuredOutputOptions(structuredOutput: AIChatContext['structuredOutput']): any;
53
60
  testFlight(): Promise<{
54
61
  status: 'success' | 'error';
@@ -68,6 +75,8 @@ export declare abstract class LLMProvider {
68
75
  };
69
76
  parseResponseMetadata(output: LLMResult): any;
70
77
  parseResponseError(err: any): any;
78
+ protected get documentLoader(): CachedDocumentLoader;
79
+ protected get aiPlugin(): PluginAIServer;
71
80
  }
72
81
  export interface EmbeddingProviderOptions {
73
82
  app: Application;
@@ -45,6 +45,8 @@ var import_axios = __toESM(require("axios"));
45
45
  var import_utils = require("../utils");
46
46
  var import_langchain = require("langchain");
47
47
  var import_stream = require("@langchain/core/utils/stream");
48
+ var import_document_loader = require("../document-loader");
49
+ var import_node_path = __toESM(require("node:path"));
48
50
  class LLMProvider {
49
51
  app;
50
52
  serviceOptions;
@@ -126,6 +128,36 @@ class LLMProvider {
126
128
  return (0, import_utils.stripToolCallTags)(chunk);
127
129
  }
128
130
  async parseAttachment(ctx, attachment) {
131
+ if (this.isApiSupportedAttachment(attachment)) {
132
+ return await this.convertToContent(ctx, attachment);
133
+ } else if (this.isDocumentLoaderSupportedAttachment(attachment)) {
134
+ return await this.loadDocument(ctx, attachment);
135
+ } else {
136
+ const safeFilename = attachment.filename ? import_node_path.default.basename(attachment.filename) : "document";
137
+ return {
138
+ placement: "system",
139
+ content: `The user has uploaded a ${attachment.mimetype} file (filename: ${safeFilename}). Please inform the user directly that you do not support parsing image content.`
140
+ };
141
+ }
142
+ }
143
+ isApiSupportedAttachment(attachment) {
144
+ const media = ["image/"];
145
+ const pdf = ["application/pdf"];
146
+ const supportedMedia = media.some((it) => {
147
+ var _a;
148
+ return (_a = attachment == null ? void 0 : attachment.mimetype) == null ? void 0 : _a.startsWith(it);
149
+ });
150
+ const supportedPdf = pdf.some((it) => {
151
+ var _a;
152
+ return (_a = attachment == null ? void 0 : attachment.mimetype) == null ? void 0 : _a.includes(it);
153
+ });
154
+ return supportedMedia || supportedPdf;
155
+ }
156
+ isDocumentLoaderSupportedAttachment(attachment) {
157
+ const ext = import_node_path.default.extname((attachment == null ? void 0 : attachment.filename) ?? "").toLocaleLowerCase();
158
+ return import_document_loader.SUPPORTED_DOCUMENT_EXTNAMES.includes(ext);
159
+ }
160
+ async convertToContent(ctx, attachment) {
129
161
  const fileManager = this.app.pm.get("file-manager");
130
162
  const url = await fileManager.getFileURL(attachment);
131
163
  const data = await (0, import_utils.encodeFile)(ctx, decodeURIComponent(url));
@@ -153,6 +185,28 @@ class LLMProvider {
153
185
  };
154
186
  }
155
187
  }
188
+ async loadDocument(_ctx, attachment) {
189
+ const safeFilename = attachment.filename ? import_node_path.default.basename(attachment.filename) : "document";
190
+ const parsed = await this.documentLoader.load(attachment);
191
+ if (!parsed.supported) {
192
+ return {
193
+ placement: "system",
194
+ content: `File ${safeFilename} is not a supported document type for text parsing.`
195
+ };
196
+ }
197
+ if (parsed.text.length === 0) {
198
+ return {
199
+ placement: "system",
200
+ content: `The file provided by the user is an empty file, file name is "${safeFilename}"`
201
+ };
202
+ }
203
+ return {
204
+ placement: "system",
205
+ content: `<parsed_document filename="${safeFilename}">
206
+ ${parsed.text}
207
+ </parsed_document>`
208
+ };
209
+ }
156
210
  getStructuredOutputOptions(structuredOutput) {
157
211
  const { responseFormat } = this.modelOptions || {};
158
212
  const { schema, name, description, strict } = structuredOutput || {};
@@ -220,6 +274,12 @@ class LLMProvider {
220
274
  parseResponseError(err) {
221
275
  return (err == null ? void 0 : err.message) ?? "Unexpected LLM service error";
222
276
  }
277
+ get documentLoader() {
278
+ return this.aiPlugin.documentLoaders.cached;
279
+ }
280
+ get aiPlugin() {
281
+ return this.app.pm.get("ai");
282
+ }
223
283
  }
224
284
  class EmbeddingProvider {
225
285
  constructor(opts) {
@@ -137,8 +137,12 @@ class AIChatConversationImpl {
137
137
  getSystemPrompt,
138
138
  formatMessages
139
139
  } = options ?? {};
140
- const messages = userMessages ? await (formatMessages == null ? void 0 : formatMessages(userMessages)) ?? [] : void 0;
141
- const systemPrompt = await (getSystemPrompt == null ? void 0 : getSystemPrompt(userMessages)) ?? "";
140
+ let messages = userMessages ? await (formatMessages == null ? void 0 : formatMessages(userMessages)) ?? [] : void 0;
141
+ const additionSystemPrompt = messages == null ? void 0 : messages.filter((it) => it.role === "system").map((it) => it.content).join("\n");
142
+ messages = messages == null ? void 0 : messages.filter((it) => it.role !== "system");
143
+ const systemPrompt = `${await (getSystemPrompt == null ? void 0 : getSystemPrompt(userMessages ?? [])) ?? ""}
144
+
145
+ ${additionSystemPrompt}`;
142
146
  const chatContext = {
143
147
  systemPrompt,
144
148
  messages,
@@ -46,7 +46,6 @@ __export(utils_exports, {
46
46
  module.exports = __toCommonJS(utils_exports);
47
47
  var import_path = __toESM(require("path"));
48
48
  var import_fs = __toESM(require("fs"));
49
- var import_axios = __toESM(require("axios"));
50
49
  var import_utils = require("@nocobase/utils");
51
50
  function sendSSEError(ctx, error, errorName) {
52
51
  const body = typeof error === "string" ? error : error.message || "Unknown error";
@@ -103,7 +102,9 @@ async function encodeFile(ctx, url) {
103
102
  const referer = ctx.get("referer") || "";
104
103
  const ua = ctx.get("user-agent") || "";
105
104
  ctx.log.trace("llm message encode file", { url, referer, ua });
106
- const response = await import_axios.default.get(url, {
105
+ const response = await (0, import_utils.serverRequest)({
106
+ method: "get",
107
+ url,
107
108
  responseType: "arraybuffer",
108
109
  headers: {
109
110
  referer,
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.13",
9
+ "version": "2.1.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",
@@ -59,5 +59,5 @@
59
59
  "keywords": [
60
60
  "AI"
61
61
  ],
62
- "gitHead": "691716e5f4e5f8bd3859d65bc8a29b4e3c32209b"
62
+ "gitHead": "cd55c9a14596d834c30c83a82c38f1f719f7aac4"
63
63
  }