@nocobase/plugin-ai 2.1.0-alpha.16 → 2.1.0-alpha.17

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 (58) hide show
  1. package/dist/ai/skills/business-analysis-report/SKILLS.md +13 -22
  2. package/dist/ai/{tools → skills/business-analysis-report/tools}/businessReportGenerator.js +2 -2
  3. package/dist/client/280.029428b83d62155f.js +10 -0
  4. package/dist/client/ai-employees/chatbox/hooks/useChatMessageActions.d.ts +2 -0
  5. package/dist/client/index.js +2 -2
  6. package/dist/externalVersion.js +15 -15
  7. package/dist/node_modules/fast-glob/package.json +1 -1
  8. package/dist/node_modules/flexsearch/package.json +1 -1
  9. package/dist/node_modules/fs-extra/package.json +1 -1
  10. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  11. package/dist/node_modules/openai/package.json +1 -1
  12. package/dist/node_modules/zod/package.json +1 -1
  13. package/dist/server/ai-employees/ai-conversations.js +2 -0
  14. package/dist/server/ai-employees/ai-employee.js +21 -13
  15. package/dist/server/ai-employees/middleware/skill-tools.js +16 -2
  16. package/dist/server/ai-employees/prompts.js +1 -0
  17. package/dist/server/llm-providers/anthropic.d.ts +2 -2
  18. package/dist/server/llm-providers/anthropic.js +1 -1
  19. package/dist/server/llm-providers/dashscope.d.ts +2 -3
  20. package/dist/server/llm-providers/dashscope.js +3 -28
  21. package/dist/server/llm-providers/deepseek.d.ts +2 -3
  22. package/dist/server/llm-providers/deepseek.js +2 -31
  23. package/dist/server/llm-providers/google-genai.d.ts +3 -18
  24. package/dist/server/llm-providers/google-genai.js +9 -7
  25. package/dist/server/llm-providers/kimi/provider.d.ts +4 -4
  26. package/dist/server/llm-providers/kimi/provider.js +3 -28
  27. package/dist/server/llm-providers/provider.d.ts +11 -2
  28. package/dist/server/llm-providers/provider.js +60 -0
  29. package/dist/server/manager/ai-chat-conversation.js +6 -2
  30. package/dist/server/utils.js +3 -2
  31. package/package.json +2 -2
  32. package/dist/client/8c8f0213e3b46621.js +0 -10
  33. /package/dist/ai/{tools → skills/business-analysis-report/tools}/businessReportGenerator.d.ts +0 -0
  34. /package/dist/client/{44a97eeb67ff35d9.js → 170.d98eacdc00d9d527.js} +0 -0
  35. /package/dist/client/{62bf6ed27c8de0df.js → 228.b18148eb1009d2fb.js} +0 -0
  36. /package/dist/client/{1c3ef55a6d63c9a3.js → 290.0888139e33c9b7cb.js} +0 -0
  37. /package/dist/client/{f87cff5213f94856.js → 30.4f30511a3059c422.js} +0 -0
  38. /package/dist/client/{2db4faf814179140.js → 331.d547c95410476a69.js} +0 -0
  39. /package/dist/client/{87bc4d3cb55e4006.js → 343.83f7d96664e4e038.js} +0 -0
  40. /package/dist/client/{0e94d90f0134df30.js → 406.15c09d98faa2ccf1.js} +0 -0
  41. /package/dist/client/{f944d487b7ff1f00.js → 428.e9f38da3b0d8b498.js} +0 -0
  42. /package/dist/client/{8e82080c5e8ccfb7.js → 502.2b4a51e0a8122e52.js} +0 -0
  43. /package/dist/client/{85af3d6d85eb5b2b.js → 525.33a9c8ec28be4ec4.js} +0 -0
  44. /package/dist/client/{a4948d5b70172a69.js → 559.133d286a0a0a1d93.js} +0 -0
  45. /package/dist/client/{9ac11803370a9625.js → 561.776886c5308e3c26.js} +0 -0
  46. /package/dist/client/{c83c2cae956ba914.js → 580.e75f97fb883ad042.js} +0 -0
  47. /package/dist/client/{f8c075896e8b9c0b.js → 597.aa363881a325b5c0.js} +0 -0
  48. /package/dist/client/{200ac94fc7f6e97b.js → 604.de96f3ec4d471afd.js} +0 -0
  49. /package/dist/client/{81f6436fd9322dc1.js → 614.aa766080f6b99aab.js} +0 -0
  50. /package/dist/client/{b8005a3f79084610.js → 687.224e569a99cae4bb.js} +0 -0
  51. /package/dist/client/{6a8fa308c9f51507.js → 699.57c0a1acb723202a.js} +0 -0
  52. /package/dist/client/{c065565ccbb41f99.js → 711.266b8f1c520d467a.js} +0 -0
  53. /package/dist/client/{5af11e24bcb39ac4.js → 758.a9741e81911e53c3.js} +0 -0
  54. /package/dist/client/{f8a32cc1ac47cf6b.js → 768.973ce32e15099a48.js} +0 -0
  55. /package/dist/client/{5d5c118d11e91913.js → 792.ae8ad1fcae9fd974.js} +0 -0
  56. /package/dist/client/{8169eb2b48edf6c7.js → 820.6a26239ea96c075a.js} +0 -0
  57. /package/dist/client/{55d67b74f02b8d74.js → 832.0cf69e3f43c320b2.js} +0 -0
  58. /package/dist/client/{748fbb87c1013c6e.js → 927.ff5cd05b14901ae6.js} +0 -0
@@ -46,20 +46,20 @@ var import_provider = require("./provider");
46
46
  var import_axios = __toESM(require("axios"));
47
47
  var import_utils = require("../utils");
48
48
  var import_ai_manager = require("../manager/ai-manager");
49
- const GOOGLE_GEN_AI_URL = "https://generativelanguage.googleapis.com/v1beta/";
49
+ const GOOGLE_GEN_AI_URL = "https://generativelanguage.googleapis.com";
50
50
  class GoogleGenAIProvider extends import_provider.LLMProvider {
51
51
  get baseURL() {
52
52
  return GOOGLE_GEN_AI_URL;
53
53
  }
54
54
  createModel() {
55
- const { apiKey } = this.serviceOptions || {};
55
+ const { apiKey, baseURL } = this.serviceOptions || {};
56
56
  const { model, responseFormat } = this.modelOptions || {};
57
57
  return new import_google_genai.ChatGoogleGenerativeAI({
58
58
  apiKey,
59
59
  ...this.modelOptions,
60
60
  model,
61
61
  json: responseFormat === "json",
62
- verbose: true
62
+ baseUrl: baseURL ?? this.baseURL
63
63
  });
64
64
  }
65
65
  async listModels() {
@@ -77,7 +77,7 @@ class GoogleGenAIProvider extends import_provider.LLMProvider {
77
77
  baseURL = baseURL.slice(0, -1);
78
78
  }
79
79
  try {
80
- const res = await import_axios.default.get(`${baseURL}/models?key=${apiKey}`);
80
+ const res = await import_axios.default.get(`${baseURL}/v1beta/models?key=${apiKey}`);
81
81
  return {
82
82
  models: (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.models.map((model) => ({
83
83
  id: model.name
@@ -123,11 +123,12 @@ class GoogleGenAIProvider extends import_provider.LLMProvider {
123
123
  role
124
124
  };
125
125
  }
126
- async parseAttachment(ctx, attachment) {
126
+ async convertToContent(ctx, attachment) {
127
+ var _a;
127
128
  const fileManager = this.app.pm.get("file-manager");
128
129
  const url = await fileManager.getFileURL(attachment);
129
- const data = await (0, import_utils.encodeFile)(ctx, decodeURIComponent(url));
130
- if (attachment.mimetype.startsWith("image/")) {
130
+ if ((_a = attachment.mimetype) == null ? void 0 : _a.startsWith("image/")) {
131
+ const data = await (0, import_utils.encodeFile)(ctx, decodeURIComponent(url));
131
132
  return {
132
133
  placement: "contentBlocks",
133
134
  content: {
@@ -138,6 +139,7 @@ class GoogleGenAIProvider extends import_provider.LLMProvider {
138
139
  }
139
140
  };
140
141
  } else {
142
+ const data = await (0, import_utils.encodeFile)(ctx, decodeURIComponent(url));
141
143
  return {
142
144
  placement: "contentBlocks",
143
145
  content: {
@@ -7,11 +7,12 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  import { AIMessageChunk } from '@langchain/core/messages';
10
- import { Context } from '@nocobase/actions';
11
10
  import { Model } from '@nocobase/database';
12
11
  import { LLMProvider } from '../provider';
13
12
  import { LLMProviderMeta } from '../../manager/ai-manager';
13
+ import { CachedDocumentLoader } from '../../document-loader';
14
14
  import { ReasoningChatOpenAI } from '../common/reasoning';
15
+ import { AttachmentModel } from '@nocobase/plugin-file-manager';
15
16
  export declare class KimiProvider extends LLMProvider {
16
17
  chatModel: ReasoningChatOpenAI;
17
18
  private _documentLoader;
@@ -27,8 +28,7 @@ export declare class KimiProvider extends LLMProvider {
27
28
  status: string;
28
29
  content: string;
29
30
  };
30
- parseAttachment(ctx: Context, attachment: any): Promise<any>;
31
- private get aiPlugin();
32
- private get documentLoader();
31
+ protected isApiSupportedAttachment(attachment: AttachmentModel): boolean;
32
+ protected get documentLoader(): CachedDocumentLoader;
33
33
  }
34
34
  export declare const kimiProviderOptions: LLMProviderMeta;
@@ -40,7 +40,6 @@ __export(provider_exports, {
40
40
  kimiProviderOptions: () => kimiProviderOptions
41
41
  });
42
42
  module.exports = __toCommonJS(provider_exports);
43
- var import_node_path = __toESM(require("node:path"));
44
43
  var import_lodash = __toESM(require("lodash"));
45
44
  var import_provider = require("../provider");
46
45
  var import_ai_manager = require("../../manager/ai-manager");
@@ -101,33 +100,9 @@ class KimiProvider extends import_provider.LLMProvider {
101
100
  }
102
101
  return null;
103
102
  }
104
- async parseAttachment(ctx, attachment) {
105
- if (!(attachment == null ? void 0 : attachment.mimetype) || attachment.mimetype.startsWith("image/")) {
106
- return super.parseAttachment(ctx, attachment);
107
- }
108
- const parsed = await this.documentLoader.load(attachment);
109
- const safeFilename = attachment.filename ? import_node_path.default.basename(attachment.filename) : "document";
110
- if (!parsed.supported) {
111
- return {
112
- placement: "system",
113
- content: `File ${safeFilename} is not a supported document type for text parsing.`
114
- };
115
- }
116
- if (parsed.text.length === 0) {
117
- return {
118
- placement: "system",
119
- content: `The file provided by the user is an empty file, file name is "${safeFilename}"`
120
- };
121
- }
122
- return {
123
- placement: "system",
124
- content: `<parsed_document filename="${safeFilename}">
125
- ${parsed.text}
126
- </parsed_document>`
127
- };
128
- }
129
- get aiPlugin() {
130
- return this.app.pm.get("ai");
103
+ isApiSupportedAttachment(attachment) {
104
+ var _a;
105
+ return ((_a = attachment.mimetype) == null ? void 0 : _a.startsWith("image/")) ?? false;
131
106
  }
132
107
  get documentLoader() {
133
108
  var _a, _b;
@@ -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>;
@@ -49,7 +52,11 @@ export declare abstract class LLMProvider {
49
52
  role: any;
50
53
  };
51
54
  parseResponseChunk(chunk: any): string;
52
- parseAttachment(ctx: Context, attachment: any): Promise<ParsedAttachmentResult>;
55
+ parseAttachment(ctx: Context, attachment: AttachmentModel): Promise<ParsedAttachmentResult>;
56
+ protected isApiSupportedAttachment(attachment: AttachmentModel): boolean;
57
+ protected isDocumentLoaderSupportedAttachment(attachment: AttachmentModel): boolean;
58
+ protected convertToContent(ctx: Context, attachment: any): Promise<ParsedAttachmentResult>;
59
+ protected loadDocument(_ctx: Context, attachment: any): Promise<any>;
53
60
  getStructuredOutputOptions(structuredOutput: AIChatContext['structuredOutput']): any;
54
61
  testFlight(): Promise<{
55
62
  status: 'success' | 'error';
@@ -69,6 +76,8 @@ export declare abstract class LLMProvider {
69
76
  };
70
77
  parseResponseMetadata(output: LLMResult): any;
71
78
  parseResponseError(err: any): any;
79
+ protected get documentLoader(): CachedDocumentLoader;
80
+ protected get aiPlugin(): PluginAIServer;
72
81
  }
73
82
  export interface EmbeddingProviderOptions {
74
83
  app: Application;
@@ -43,6 +43,8 @@ module.exports = __toCommonJS(provider_exports);
43
43
  var import_axios = __toESM(require("axios"));
44
44
  var import_utils = require("../utils");
45
45
  var import_stream = require("@langchain/core/utils/stream");
46
+ var import_document_loader = require("../document-loader");
47
+ var import_node_path = __toESM(require("node:path"));
46
48
  class LLMProvider {
47
49
  app;
48
50
  serviceOptions;
@@ -124,6 +126,36 @@ class LLMProvider {
124
126
  return (0, import_utils.stripToolCallTags)(chunk);
125
127
  }
126
128
  async parseAttachment(ctx, attachment) {
129
+ if (this.isApiSupportedAttachment(attachment)) {
130
+ return await this.convertToContent(ctx, attachment);
131
+ } else if (this.isDocumentLoaderSupportedAttachment(attachment)) {
132
+ return await this.loadDocument(ctx, attachment);
133
+ } else {
134
+ const safeFilename = attachment.filename ? import_node_path.default.basename(attachment.filename) : "document";
135
+ return {
136
+ placement: "system",
137
+ content: `The user has uploaded a ${attachment.mimetype} file (filename: ${safeFilename}). Please inform the user directly that you do not support parsing image content.`
138
+ };
139
+ }
140
+ }
141
+ isApiSupportedAttachment(attachment) {
142
+ const media = ["image/"];
143
+ const pdf = ["application/pdf"];
144
+ const supportedMedia = media.some((it) => {
145
+ var _a;
146
+ return (_a = attachment == null ? void 0 : attachment.mimetype) == null ? void 0 : _a.startsWith(it);
147
+ });
148
+ const supportedPdf = pdf.some((it) => {
149
+ var _a;
150
+ return (_a = attachment == null ? void 0 : attachment.mimetype) == null ? void 0 : _a.includes(it);
151
+ });
152
+ return supportedMedia || supportedPdf;
153
+ }
154
+ isDocumentLoaderSupportedAttachment(attachment) {
155
+ const ext = import_node_path.default.extname((attachment == null ? void 0 : attachment.filename) ?? "").toLocaleLowerCase();
156
+ return import_document_loader.SUPPORTED_DOCUMENT_EXTNAMES.includes(ext);
157
+ }
158
+ async convertToContent(ctx, attachment) {
127
159
  const fileManager = this.app.pm.get("file-manager");
128
160
  const url = await fileManager.getFileURL(attachment);
129
161
  const data = await (0, import_utils.encodeFile)(ctx, decodeURIComponent(url));
@@ -151,6 +183,28 @@ class LLMProvider {
151
183
  };
152
184
  }
153
185
  }
186
+ async loadDocument(_ctx, attachment) {
187
+ const safeFilename = attachment.filename ? import_node_path.default.basename(attachment.filename) : "document";
188
+ const parsed = await this.documentLoader.load(attachment);
189
+ if (!parsed.supported) {
190
+ return {
191
+ placement: "system",
192
+ content: `File ${safeFilename} is not a supported document type for text parsing.`
193
+ };
194
+ }
195
+ if (parsed.text.length === 0) {
196
+ return {
197
+ placement: "system",
198
+ content: `The file provided by the user is an empty file, file name is "${safeFilename}"`
199
+ };
200
+ }
201
+ return {
202
+ placement: "system",
203
+ content: `<parsed_document filename="${safeFilename}">
204
+ ${parsed.text}
205
+ </parsed_document>`
206
+ };
207
+ }
154
208
  getStructuredOutputOptions(structuredOutput) {
155
209
  const { responseFormat } = this.modelOptions || {};
156
210
  const { schema, name, description, strict } = structuredOutput || {};
@@ -218,6 +272,12 @@ class LLMProvider {
218
272
  parseResponseError(err) {
219
273
  return (err == null ? void 0 : err.message) ?? "Unexpected LLM service error";
220
274
  }
275
+ get documentLoader() {
276
+ return this.aiPlugin.documentLoaders.cached;
277
+ }
278
+ get aiPlugin() {
279
+ return this.app.pm.get("ai");
280
+ }
221
281
  }
222
282
  class EmbeddingProvider {
223
283
  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,
@@ -47,7 +47,6 @@ __export(utils_exports, {
47
47
  module.exports = __toCommonJS(utils_exports);
48
48
  var import_path = __toESM(require("path"));
49
49
  var import_fs = __toESM(require("fs"));
50
- var import_axios = __toESM(require("axios"));
51
50
  var import_utils = require("@nocobase/utils");
52
51
  var import_langchain = require("langchain");
53
52
  function sendSSEError(ctx, error, errorName) {
@@ -106,7 +105,9 @@ async function encodeFile(ctx, url) {
106
105
  const referer = ctx.get("referer") || "";
107
106
  const ua = ctx.get("user-agent") || "";
108
107
  ctx.log.trace("llm message encode file", { url, referer, ua });
109
- const response = await import_axios.default.get(url, {
108
+ const response = await (0, import_utils.serverRequest)({
109
+ method: "get",
110
+ url,
110
111
  responseType: "arraybuffer",
111
112
  headers: {
112
113
  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-alpha.16",
9
+ "version": "2.1.0-alpha.17",
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": "14cf3dbdb9f0a9669602de4ad21a9464fa27c105"
64
+ "gitHead": "586cb00f56557e66168b9720d0e0193a1b752067"
65
65
  }
@@ -1,10 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- "use strict";(self.webpackChunk_nocobase_plugin_ai=self.webpackChunk_nocobase_plugin_ai||[]).push([["280"],{779:function(e,t,r){r.d(t,{MT:function(){return j},UV:function(){return O},Y_:function(){return N},cZ:function(){return x},e4:function(){return S},wP:function(){return k}});var n=r(9155),o=r.n(n),a=r(3342),i=r(9557),c=r(9597),s=r(7916),l=r(1210),u=r(9256),p=r(1465),d=r(5897);function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function h(e,t,r,n,o,a,i){try{var c=e[a](i),s=c.value}catch(e){r(e);return}c.done?t(s):Promise.resolve(s).then(n,o)}function m(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function i(e){h(a,n,o,i,c,"next",e)}function c(e){h(a,n,o,i,c,"throw",e)}i(void 0)})}}function b(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}function y(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}),e}function g(e){return e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function v(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),c=Object.defineProperty;return c(i,"next",{value:s(0)}),c(i,"throw",{value:s(1)}),c(i,"return",{value:s(2)}),"function"==typeof Symbol&&c(i,Symbol.iterator,{value:function(){return this}}),i;function s(c){return function(s){var l=[c,s];if(r)throw TypeError("Generator is already executing.");for(;i&&(i=0,l[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&l[0]?n.return:l[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,l[1])).done)return o;switch(n=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return a.label++,{value:l[1],done:!1};case 5:a.label++,n=l[1],l=[0];continue;case 7:l=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){a=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){a.label=l[1];break}if(6===l[0]&&a.label<o[1]){a.label=o[1],o=l;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(l);break}o[2]&&a.ops.pop(),a.trys.pop();continue}l=t.call(e,a)}catch(e){l=[6,e],n=0}finally{r=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}function w(e){return!!e&&(void 0===e?"undefined":g(e))==="object"&&"object"===g(e.options)}function x(e){return e?y(b({},e),{markdown:e.markdown,charts:function(e){if(Array.isArray(e))return e.filter(w);if("string"!=typeof e)return[];var t=e.trim();if(!t)return[];try{var r=JSON.parse(t);return Array.isArray(r)?r.filter(w):[]}catch(e){return[]}}(e.charts)}):{}}function S(e){var t=x(e);return(t.fileName||t.title||"business-analysis-report").replace(/[\\/:*?"<>|]+/g,"-").trim()}function k(e,t){var r,n,o,i=x(e),c=["# ".concat(i.title)],s=function(e,t){var r=function(e){if(null==e||""===e)return null;if(null!=(t=Date)&&"u">typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t)return Number.isNaN(e.getTime())?null:e;if("number"==typeof e)return U(e);var t,r=e.trim();if(!r)return null;if(/^\d+$/.test(r))return U(Number(r));var n=new Date(r);return Number.isNaN(n.getTime())?null:n}(e);if(!r)return null;var n=F(t)||"en-US";try{return new Intl.DateTimeFormat(n,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).format(r)}catch(e){return console.error("Failed to format business report generatedAt:",e),r.toLocaleString()}}(i.generatedAt,null==t?void 0:t.locale);return s&&c.push("_".concat(a.i18n.t("Generated at"),": ").concat(s,"_")),i.summary&&c.push("> ".concat(i.summary)),(null==(o=i.markdown)?void 0:o.trim())&&c.push((r=i.markdown.trim(),n=i.charts||[],r&&n.length?r.replace(/\{\{\s*chart\s*:\s*(\d+)\s*\}\}/gi,function(e,t){var r,o,a,i=Number(t)-1,c=n[i];return c?(r=c,o=i,a=["## ".concat(r.title||"Chart ".concat(o+1))],r.summary&&a.push(r.summary),a.push("<echarts>".concat(JSON.stringify(r.options,null,2),"</echarts>")),a.join("\n\n")):e}):r)),(function(e,t){if(!t.length)return[];for(var r,n=new Set,o=/\{\{\s*chart\s*:\s*(\d+)\s*\}\}/gi,a=e||"";r=o.exec(a);){var i=Number(r[1])-1;i>=0&&i<t.length&&n.add(i)}return t.filter(function(e,t){return!n.has(t)})})(i.markdown,i.charts||[]).forEach(function(e,t){c.push("## ".concat(e.title||"Chart ".concat(t+1))),e.summary&&c.push(e.summary),c.push("<echarts>".concat(JSON.stringify(e.options,null,2),"</echarts>"))}),c.filter(Boolean).join("\n\n")}function O(e,t){return m(function(){var r,n,a,h,w,x,S,O,j,N,U,M;return v(this,function(C){var I,L,R,E,T,D,H,_,z,J;switch(C.label){case 0:return I=k(e,{locale:null==t?void 0:t.locale}),L=[],R=0,n=(r={body:(0,d.renderToStaticMarkup)(o().createElement(c.oz,{components:{echarts:function(e){var t=e.children,r=Array.isArray(t)?t.join(""):String(null!=t?t:""),n="report-chart-".concat(R++),a=function(e){try{var t=JSON.parse(e);if(t&&(void 0===t?"undefined":g(t))==="object")return t}catch(e){console.error("Failed to parse business report chart options:",e)}return null}(r);return a&&L.push({id:n,options:a}),o().createElement("div",{id:n,className:"report-chart"})}},rehypePlugins:[l.A,[u.A,y(b({},p.j),{tagNames:((function(e){if(Array.isArray(e))return f(e)})(E=p.j.tagNames)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(E)||function(e){if(e){if("string"==typeof e)return f(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return f(e,void 0)}}(E)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).concat(["echarts"])})]],remarkPlugins:[s.A]},I)),charts:L}).body,a=r.charts,h=(null==t?void 0:t.printMode)===!0,x=(D=w=(T=F(null==t?void 0:t.locale))||"en-US").startsWith("zh")?'"PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", "WenQuanYi Micro Hei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif':D.startsWith("ja")?'"Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", "Noto Sans CJK JP", "Source Han Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif':D.startsWith("ko")?'"Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans CJK KR", "Source Han Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif':'"Inter", "Segoe UI", "Helvetica Neue", Arial, "Noto Sans", -apple-system, BlinkMacSystemFont, sans-serif',S=h?"#ffffff":"#f5f7fb",O=h?"max-width: 190mm; margin: 0 auto; padding: 0;":"max-width: 960px; margin: 0 auto; padding: 32px 24px 64px;",j=h?"background: #fff; border: 0; border-radius: 0; padding: 0; box-shadow: none; width: 100%;":"background: #fff; border: 1px solid #d0d5dd; border-radius: 20px; padding: 40px 48px; box-shadow: 0 18px 50px rgba(15, 23, 42, 0.08);",[4,(H=a,_={chartHeight:N=h?320:360,fontFamily:x,printMode:h},m(function(){var e,t,r,n,o,a,c,s,l,u,p,d;return v(this,function(f){var h,m,g;switch(f.label){case 0:if("u"<typeof document||!H.length)return[2,new Map];e=new Map,(t=document.createElement("div")).style.position="fixed",t.style.left="-100000px",t.style.top="0",t.style.width="".concat(_.printMode?718:960,"px"),t.style.pointerEvents="none",t.style.opacity="0",t.style.zIndex="-1",document.body.appendChild(t),f.label=1;case 1:f.trys.push([1,,15,16]),r=!0,n=!1,o=void 0,f.label=2;case 2:f.trys.push([2,12,13,14]),a=H[Symbol.iterator](),f.label=3;case 3:if(r=(c=a.next()).done)return[3,11];s=c.value,(l=document.createElement("div")).style.width=t.style.width,l.style.height="".concat(_.chartHeight,"px"),t.appendChild(l),f.label=4;case 4:return f.trys.push([4,8,9,10]),(p=i.init(l,"default",{renderer:"canvas"})).setOption(y(b({},(m=y(b({},h=s.options),{animation:!1,toolbox:{show:!1}}),h.grid&&(m.grid=Array.isArray(h.grid)?h.grid.map(function(e){return b({containLabel:!0},e)}):b({containLabel:!0},h.grid)),m)),{textStyle:y(b({},(null==(u=s.options)?void 0:u.textStyle)||{}),{fontFamily:_.fontFamily})}),!0),p.resize({width:l.clientWidth||parseInt(t.style.width,10),height:_.chartHeight,silent:!0}),[4,A()];case 5:return f.sent(),[4,A()];case 6:return f.sent(),[4,(g=p,new Promise(function(e){var t=!1,r=function(){t||(t=!0,g.off("finished",r),e())};g.on("finished",r),window.setTimeout(r,400)}))];case 7:return f.sent(),e.set(s.id,p.getDataURL({type:"png",pixelRatio:3,backgroundColor:"#ffffff",excludeComponents:["toolbox"]})),p.dispose(),[3,10];case 8:return console.error("Failed to render business report chart image:",f.sent()),[3,10];case 9:return l.remove(),[7];case 10:return r=!0,[3,3];case 11:return[3,14];case 12:return d=f.sent(),n=!0,o=d,[3,14];case 13:try{r||null==a.return||a.return()}finally{if(n)throw o}return[7];case 14:return[3,16];case 15:return t.remove(),[7];case 16:return[2,e]}})})())];case 1:return U=C.sent(),z=n,J=U,M=z.replace(/<div id="([^"]+)" class="report-chart"><\/div>/g,function(e,t){var r=J.get(t);return r?'<img class="report-chart-image" src="'.concat(r,'" alt="" />'):e}),[2,'<!DOCTYPE html>\n<html lang="'.concat(P(w),'">\n <head>\n <meta charset="UTF-8" />\n <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n <title>').concat(P(e.title),"</title>\n <style>\n * { box-sizing: border-box; }\n html { -webkit-print-color-adjust: exact; print-color-adjust: exact; }\n html, body { font-family: ").concat(x,"; }\n body { margin: 0; color: #1f2937; background: ").concat(S,"; }\n .report-shell { ").concat(O," }\n .report-paper { ").concat(j," }\n h1, h2, h3 { color: #101828; }\n h1 { margin-top: 0; font-size: 32px; }\n h2, h3 { break-after: avoid-page; }\n p, li { line-height: 1.7; }\n blockquote { margin: 16px 0; padding: 12px 16px; border-left: 4px solid #0f766e; background: #f0fdfa; color: #667085; }\n pre, blockquote, table, .report-chart { break-inside: avoid; page-break-inside: avoid; }\n table { width: 100%; border-collapse: collapse; }\n th, td { border: 1px solid #d0d5dd; padding: 10px 12px; text-align: left; }\n .report-chart { width: 100%; min-height: ").concat(N,"px; height: ").concat(N,"px; margin: 24px 0 32px; border: 1px solid #d0d5dd; border-radius: ").concat(16*!h,"px; overflow: hidden; background: #fff; }\n .report-chart-image { display: block; width: 100%; height: auto; border: 1px solid #d0d5dd; background: #fff; margin: 24px 0 32px; break-inside: avoid; page-break-inside: avoid; }\n .report-paper > *:first-child { margin-top: 0; }\n .report-paper > *:last-child { margin-bottom: 0; }\n img, svg, canvas { max-width: 100%; }\n svg, svg text, svg tspan, canvas { font-family: ").concat(x,'; }\n @page { size: A4; margin: 12mm; }\n @media print {\n body { background: #fff; }\n .report-shell { max-width: 100%; padding: 0; margin: 0; }\n .report-paper { border: 0; border-radius: 0; box-shadow: none; padding: 0; width: 100%; }\n .report-chart { margin: 16px 0 24px; height: 320px; min-height: 320px; }\n .report-chart-image { margin: 16px 0 24px; }\n }\n </style>\n </head>\n <body>\n <div class="report-shell">\n <article class="report-paper">').concat(M,"</article>\n </div>\n ").concat((null==t?void 0:t.autoPrint)?"<script>\n window.addEventListener('load', async () => {\n if (document.fonts?.ready) {\n try {\n await document.fonts.ready;\n } catch (error) {\n console.error('Failed to wait for fonts before printing:', error);\n }\n }\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n window.print();\n });\n });\n });\n <\/script>":"","\n </body>\n</html>")]}})})()}function j(e,t,r){var n=new Blob([t],{type:r}),o=URL.createObjectURL(n),a=document.createElement("a");a.href=o,a.download=e,a.click(),URL.revokeObjectURL(o)}function N(e,t){return m(function(){var r,n;return v(this,function(o){switch(o.label){case 0:if("u"<typeof window)return[2,!1];return[4,O(e,{autoPrint:!0,printMode:!0,locale:null==t?void 0:t.locale})];case 1:if(r=new Blob([o.sent()],{type:"text/html;charset=utf-8"}),n=URL.createObjectURL(r),!window.open(n,"_blank","noopener,noreferrer"))return URL.revokeObjectURL(n),[2,!1];return window.setTimeout(function(){URL.revokeObjectURL(n)},6e4),[2,!0]}})})()}function A(){return new Promise(function(e){return requestAnimationFrame(function(){return e()})})}function P(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function U(e){if(!Number.isFinite(e))return null;var t=new Date(e<1e12?1e3*e:e);return Number.isNaN(t.getTime())?null:t}function F(e){if(!e)return null;var t=e.trim().replace(/_/g,"-");if(!t||!/^[a-z]{2,3}(-[a-z0-9]{2,8})*$/i.test(t))return null;try{return Intl.DateTimeFormat.supportedLocalesOf([t])[0]||t}catch(e){return t}}}}]);