@nocobase/ai 2.1.0-alpha.3 → 2.1.0-alpha.31

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 (90) hide show
  1. package/LICENSE +201 -661
  2. package/README.md +79 -10
  3. package/lib/ai-employee-manager/index.d.ts +29 -0
  4. package/lib/ai-employee-manager/index.js +169 -0
  5. package/lib/ai-employee-manager/types.d.ts +57 -0
  6. package/lib/ai-employee-manager/types.js +24 -0
  7. package/lib/ai-manager.d.ts +8 -0
  8. package/lib/ai-manager.js +12 -0
  9. package/lib/document-loader/index.d.ts +10 -0
  10. package/lib/document-loader/index.js +90 -0
  11. package/lib/document-loader/loader.worker.d.ts +9 -0
  12. package/lib/document-loader/loader.worker.js +83 -0
  13. package/lib/document-loader/vendor/langchain/document_loaders/fs/text.d.ts +20 -0
  14. package/lib/document-loader/vendor/langchain/document_loaders/fs/text.js +99 -0
  15. package/lib/document-loader/xlsx.d.ts +10 -0
  16. package/lib/document-loader/xlsx.js +100 -0
  17. package/lib/index.d.ts +5 -0
  18. package/lib/index.js +11 -1
  19. package/lib/loader/employee.d.ts +37 -0
  20. package/lib/loader/employee.js +219 -0
  21. package/lib/loader/index.d.ts +3 -0
  22. package/lib/loader/index.js +7 -1
  23. package/lib/loader/mcp.d.ts +35 -0
  24. package/lib/loader/mcp.js +108 -0
  25. package/lib/loader/skills.d.ts +43 -0
  26. package/lib/loader/skills.js +138 -0
  27. package/lib/loader/tools.d.ts +1 -0
  28. package/lib/loader/tools.js +4 -3
  29. package/lib/mcp-manager/index.d.ts +43 -0
  30. package/lib/mcp-manager/index.js +341 -0
  31. package/lib/mcp-manager/types.d.ts +61 -0
  32. package/lib/mcp-manager/types.js +24 -0
  33. package/lib/mcp-tools-manager.d.ts +43 -0
  34. package/lib/mcp-tools-manager.js +77 -0
  35. package/lib/skills-manager/index.d.ts +29 -0
  36. package/lib/skills-manager/index.js +169 -0
  37. package/lib/skills-manager/types.d.ts +33 -0
  38. package/lib/skills-manager/types.js +24 -0
  39. package/lib/tools-manager/index.d.ts +8 -1
  40. package/lib/tools-manager/index.js +28 -8
  41. package/lib/tools-manager/types.d.ts +12 -4
  42. package/package.json +27 -7
  43. package/src/__tests__/ai-employees.test.ts +108 -0
  44. package/src/__tests__/mcp.test.ts +105 -0
  45. package/src/__tests__/resource/ai/ai-employees/index-employee/index.ts +16 -0
  46. package/src/__tests__/resource/ai/ai-employees/index-employee/prompt.md +1 -0
  47. package/src/__tests__/resource/ai/ai-employees/named-file-employee.ts +16 -0
  48. package/src/__tests__/resource/ai/ai-employees/with-skills/index.ts +16 -0
  49. package/src/__tests__/resource/ai/ai-employees/with-skills/skills/analysis/SKILLS.md +6 -0
  50. package/src/__tests__/resource/ai/ai-employees/with-skills-merge/index.ts +17 -0
  51. package/src/__tests__/resource/ai/ai-employees/with-skills-merge/skills/discovered-skill/SKILLS.md +6 -0
  52. package/src/__tests__/resource/ai/ai-employees/with-tools/index.ts +16 -0
  53. package/src/__tests__/resource/ai/ai-employees/with-tools/tools/discoveredTool.ts +23 -0
  54. package/src/__tests__/resource/ai/ai-employees/with-tools-merge/index.ts +16 -0
  55. package/src/__tests__/resource/ai/ai-employees/with-tools-merge/tools/discoveredTool.ts +23 -0
  56. package/src/__tests__/resource/ai/mcp/weather.ts +25 -0
  57. package/src/__tests__/resource/ai/skills/data-modeling/SKILLS.md +24 -0
  58. package/src/__tests__/resource/ai/skills/data-modeling/tools/read.ts +23 -0
  59. package/src/__tests__/resource/ai/skills/data-modeling/tools/search/description.md +1 -0
  60. package/src/__tests__/resource/ai/skills/data-modeling/tools/search/index.ts +23 -0
  61. package/src/__tests__/resource/ai/skills/document/tools/read.ts +1 -1
  62. package/src/__tests__/resource/ai/skills/document/tools/search/index.ts +1 -1
  63. package/src/__tests__/resource/ai/tools/desc/index.ts +1 -1
  64. package/src/__tests__/resource/ai/tools/group/group1.ts +1 -1
  65. package/src/__tests__/resource/ai/tools/group/group2.ts +1 -1
  66. package/src/__tests__/resource/ai/tools/group/group3/index.ts +1 -1
  67. package/src/__tests__/resource/ai/tools/hallow/index.ts +1 -1
  68. package/src/__tests__/resource/ai/tools/print.ts +1 -1
  69. package/src/__tests__/skills.test.ts +55 -0
  70. package/src/__tests__/tools.test.ts +5 -3
  71. package/src/ai-employee-manager/index.ts +150 -0
  72. package/src/ai-employee-manager/types.ts +64 -0
  73. package/src/ai-manager.ts +12 -0
  74. package/src/document-loader/index.ts +57 -0
  75. package/src/document-loader/loader.worker.ts +100 -0
  76. package/src/document-loader/vendor/langchain/document_loaders/fs/text.ts +72 -0
  77. package/src/document-loader/xlsx.ts +82 -0
  78. package/src/index.ts +5 -0
  79. package/src/loader/employee.ts +205 -0
  80. package/src/loader/index.ts +3 -0
  81. package/src/loader/mcp.ts +101 -0
  82. package/src/loader/skills.ts +129 -0
  83. package/src/loader/tools.ts +3 -2
  84. package/src/mcp-manager/index.ts +364 -0
  85. package/src/mcp-manager/types.ts +68 -0
  86. package/src/mcp-tools-manager.ts +90 -0
  87. package/src/skills-manager/index.ts +148 -0
  88. package/src/skills-manager/types.ts +38 -0
  89. package/src/tools-manager/index.ts +26 -7
  90. package/src/tools-manager/types.ts +13 -4
@@ -0,0 +1,43 @@
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
+ export type McpTool = {
10
+ name: string;
11
+ description: string;
12
+ inputSchema?: any;
13
+ resourceName?: string;
14
+ actionName?: string;
15
+ path?: string;
16
+ method?: string;
17
+ call: (args: Record<string, any>, context?: McpToolCallContext) => Promise<any>;
18
+ };
19
+ export type McpToolCallContext = {
20
+ token?: string;
21
+ headers?: Record<string, string | string[] | undefined>;
22
+ };
23
+ export type McpToolResultPostProcessorContext = {
24
+ tool: McpTool;
25
+ args: Record<string, any>;
26
+ callContext?: McpToolCallContext;
27
+ response?: {
28
+ statusCode?: number;
29
+ headers?: Record<string, any>;
30
+ body?: any;
31
+ };
32
+ };
33
+ export type McpToolResultPostProcessor = (result: any, context: McpToolResultPostProcessorContext) => any | Promise<any>;
34
+ export declare class McpToolsManager {
35
+ private tools;
36
+ private resultPostProcessors;
37
+ private getActionKey;
38
+ registerTools(tools: McpTool[]): void;
39
+ registerToolResultPostProcessor(resourceName: string, actionName: string, processor: McpToolResultPostProcessor): void;
40
+ postProcessToolResult(tool: McpTool, result: any, context: Omit<McpToolResultPostProcessorContext, 'tool'>): Promise<any>;
41
+ listTools(): McpTool[];
42
+ getTool(name: string): McpTool;
43
+ }
@@ -0,0 +1,77 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var mcp_tools_manager_exports = {};
29
+ __export(mcp_tools_manager_exports, {
30
+ McpToolsManager: () => McpToolsManager
31
+ });
32
+ module.exports = __toCommonJS(mcp_tools_manager_exports);
33
+ var import_utils = require("@nocobase/utils");
34
+ const _McpToolsManager = class _McpToolsManager {
35
+ tools = new import_utils.Registry();
36
+ resultPostProcessors = /* @__PURE__ */ new Map();
37
+ getActionKey(resourceName, actionName) {
38
+ return `${resourceName}:${actionName}`;
39
+ }
40
+ registerTools(tools) {
41
+ for (const tool of tools) {
42
+ this.tools.register(tool.name, tool);
43
+ }
44
+ }
45
+ registerToolResultPostProcessor(resourceName, actionName, processor) {
46
+ const key = this.getActionKey(resourceName, actionName);
47
+ const processors = this.resultPostProcessors.get(key) || [];
48
+ processors.push(processor);
49
+ this.resultPostProcessors.set(key, processors);
50
+ }
51
+ async postProcessToolResult(tool, result, context) {
52
+ if (!tool.resourceName || !tool.actionName) {
53
+ return result;
54
+ }
55
+ const processors = this.resultPostProcessors.get(this.getActionKey(tool.resourceName, tool.actionName)) || [];
56
+ let current = result;
57
+ for (const processor of processors) {
58
+ current = await processor(current, {
59
+ ...context,
60
+ tool
61
+ });
62
+ }
63
+ return current;
64
+ }
65
+ listTools() {
66
+ return [...this.tools.getValues()];
67
+ }
68
+ getTool(name) {
69
+ return this.tools.get(name);
70
+ }
71
+ };
72
+ __name(_McpToolsManager, "McpToolsManager");
73
+ let McpToolsManager = _McpToolsManager;
74
+ // Annotate the CommonJS export names for ESM import in node:
75
+ 0 && (module.exports = {
76
+ McpToolsManager
77
+ });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { SkillsEntry, SkillsManager, SkillsOptions, SkillsFilter } from './types';
10
+ export declare class DefaultSkillsManager implements SkillsManager {
11
+ private readonly app;
12
+ private readonly skills;
13
+ private readonly provideCollectionManager;
14
+ private mode;
15
+ constructor(app: any);
16
+ init(): Promise<void>;
17
+ getSkills(name: string[]): Promise<SkillsEntry[]>;
18
+ getSkills(name: string): Promise<SkillsEntry>;
19
+ listSkills(filter: SkillsFilter): Promise<SkillsEntry[]>;
20
+ registerSkills(options: SkillsOptions): Promise<void>;
21
+ persistence(): Promise<void>;
22
+ private registerSkillsInMemory;
23
+ registerSkillsInDatabase(options: SkillsOptions): Promise<void>;
24
+ private get aiSkillsCollection();
25
+ private get aiSkillsModel();
26
+ private get sequelize();
27
+ private get collectionManager();
28
+ }
29
+ export * from './types';
@@ -0,0 +1,169 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
30
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
+ // If the importer is in node compatibility mode or this is not an ESM
32
+ // file that has been converted to a CommonJS file using a Babel-
33
+ // compatible transform (i.e. "__esModule" has not been set), then set
34
+ // "default" to the CommonJS "module.exports" for node compatibility.
35
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
36
+ mod
37
+ ));
38
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
39
+ var skills_manager_exports = {};
40
+ __export(skills_manager_exports, {
41
+ DefaultSkillsManager: () => DefaultSkillsManager
42
+ });
43
+ module.exports = __toCommonJS(skills_manager_exports);
44
+ var import_database = require("@nocobase/database");
45
+ var import_utils = require("@nocobase/utils");
46
+ var import_lodash = __toESM(require("lodash"));
47
+ __reExport(skills_manager_exports, require("./types"), module.exports);
48
+ const _DefaultSkillsManager = class _DefaultSkillsManager {
49
+ constructor(app) {
50
+ this.app = app;
51
+ this.provideCollectionManager = () => app.mainDataSource;
52
+ }
53
+ skills = new import_utils.Registry();
54
+ provideCollectionManager;
55
+ mode = "memory";
56
+ async init() {
57
+ if (this.mode === "memory") {
58
+ await this.persistence();
59
+ this.mode = "database";
60
+ }
61
+ }
62
+ async getSkills(name) {
63
+ var _a;
64
+ if (import_lodash.default.isArray(name)) {
65
+ return (await this.aiSkillsModel.findAll({ where: { name: { [import_database.Op.in]: name } } })).map((it) => it.toJSON()).map(converterSkillsEntry);
66
+ } else {
67
+ return converterSkillsEntry((_a = await this.aiSkillsModel.findOne({ where: { name } })) == null ? void 0 : _a.toJSON());
68
+ }
69
+ }
70
+ async listSkills(filter) {
71
+ const where = {};
72
+ if (filter == null ? void 0 : filter.scope) {
73
+ where["scope"] = filter.scope;
74
+ }
75
+ if (filter == null ? void 0 : filter.name) {
76
+ where["name"] = {
77
+ [import_database.Op.substring]: filter.name
78
+ };
79
+ }
80
+ return (await this.aiSkillsModel.findAll({ where })).map((it) => it.toJSON()).map(converterSkillsEntry);
81
+ }
82
+ async registerSkills(options) {
83
+ if (this.mode === "memory") {
84
+ return this.registerSkillsInMemory(options);
85
+ }
86
+ return this.registerSkillsInDatabase(options);
87
+ }
88
+ async persistence() {
89
+ const skillsList = [...this.skills.getValues()];
90
+ for (const skill of skillsList) {
91
+ await this.registerSkillsInDatabase(skill);
92
+ }
93
+ }
94
+ registerSkillsInMemory(options) {
95
+ const skillsEntry = { ...options };
96
+ this.skills.register(options.name, skillsEntry);
97
+ }
98
+ async registerSkillsInDatabase(options) {
99
+ var _a, _b;
100
+ const title = (_a = options.introduction) == null ? void 0 : _a.title;
101
+ const about = (_b = options.introduction) == null ? void 0 : _b.about;
102
+ const from = options.from || "loader";
103
+ await this.sequelize.transaction(async (transaction) => {
104
+ const existed = await this.aiSkillsModel.findOne({ where: { name: options.name }, transaction });
105
+ if (existed) {
106
+ await this.aiSkillsModel.update(
107
+ {
108
+ scope: options.scope,
109
+ description: options.description,
110
+ content: options.content,
111
+ tools: options.tools,
112
+ title,
113
+ about,
114
+ from
115
+ },
116
+ {
117
+ where: { name: options.name },
118
+ transaction
119
+ }
120
+ );
121
+ } else {
122
+ await this.aiSkillsModel.create(
123
+ {
124
+ name: options.name,
125
+ scope: options.scope,
126
+ description: options.description,
127
+ content: options.content,
128
+ tools: options.tools,
129
+ title,
130
+ about,
131
+ from
132
+ },
133
+ {
134
+ transaction
135
+ }
136
+ );
137
+ }
138
+ });
139
+ }
140
+ get aiSkillsCollection() {
141
+ return this.collectionManager.getCollection("aiSkills");
142
+ }
143
+ get aiSkillsModel() {
144
+ var _a;
145
+ return (_a = this.aiSkillsCollection) == null ? void 0 : _a.model;
146
+ }
147
+ get sequelize() {
148
+ return this.collectionManager.db.sequelize;
149
+ }
150
+ get collectionManager() {
151
+ return this.provideCollectionManager().collectionManager;
152
+ }
153
+ };
154
+ __name(_DefaultSkillsManager, "DefaultSkillsManager");
155
+ let DefaultSkillsManager = _DefaultSkillsManager;
156
+ const converterSkillsEntry = /* @__PURE__ */ __name((model) => {
157
+ return {
158
+ ...model ?? {},
159
+ introduction: (model == null ? void 0 : model.title) ? {
160
+ title: model.title,
161
+ about: model == null ? void 0 : model.about
162
+ } : void 0
163
+ };
164
+ }, "converterSkillsEntry");
165
+ // Annotate the CommonJS export names for ESM import in node:
166
+ 0 && (module.exports = {
167
+ DefaultSkillsManager,
168
+ ...require("./types")
169
+ });
@@ -0,0 +1,33 @@
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
+ export interface SkillsManager {
10
+ init(): Promise<void>;
11
+ getSkills(name: string[]): Promise<SkillsEntry[]>;
12
+ getSkills(name: string): Promise<SkillsEntry>;
13
+ listSkills(filter?: SkillsFilter): Promise<SkillsEntry[]>;
14
+ registerSkills(options: SkillsOptions): Promise<void>;
15
+ }
16
+ export type SkillsOptions = {
17
+ scope: SkillsScope;
18
+ name: string;
19
+ description: string;
20
+ content: string;
21
+ tools?: string[];
22
+ introduction?: {
23
+ title: string;
24
+ about?: string;
25
+ };
26
+ from?: string;
27
+ };
28
+ export type SkillsEntry = SkillsOptions;
29
+ export type SkillsFilter = {
30
+ scope?: SkillsScope;
31
+ name?: string;
32
+ };
33
+ export type SkillsScope = 'SPECIFIED' | 'GENERAL' | 'CUSTOM';
@@ -0,0 +1,24 @@
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 __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var types_exports = {};
24
+ module.exports = __toCommonJS(types_exports);
@@ -12,12 +12,19 @@ export declare class DefaultToolsManager implements ToolsManager {
12
12
  private readonly tools;
13
13
  private readonly dynamicTools;
14
14
  constructor(tools?: Registry<ToolsOptions>, dynamicTools?: DynamicToolsProvider[]);
15
- getTools(toolName: string): Promise<ToolsEntry>;
15
+ getTools(toolName: string, filter?: ToolsFilter): Promise<ToolsEntry>;
16
16
  listTools(filter?: ToolsFilter): Promise<ToolsEntry[]>;
17
+ isToolsExisted(toolName: string): boolean;
17
18
  registerTools(options: ToolsOptions | ToolsOptions[]): void;
18
19
  registerDynamicTools(provider: DynamicToolsProvider): void;
19
20
  private getToolsList;
20
21
  private syncDynamicTools;
21
22
  }
22
23
  export declare function defineTools(options: ToolsOptions): ToolsOptions;
24
+ export declare const SYSTEM_TOOLS: {
25
+ WEB_SEARCH: string;
26
+ KNOWLEDGE_BASE: string;
27
+ WORK_FLOW_TASK_OUTPUT: string;
28
+ };
29
+ export declare const listSystemTools: () => string[];
23
30
  export * from './types';
@@ -39,7 +39,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
39
39
  var tools_manager_exports = {};
40
40
  __export(tools_manager_exports, {
41
41
  DefaultToolsManager: () => DefaultToolsManager,
42
- defineTools: () => defineTools
42
+ SYSTEM_TOOLS: () => SYSTEM_TOOLS,
43
+ defineTools: () => defineTools,
44
+ listSystemTools: () => listSystemTools
43
45
  });
44
46
  module.exports = __toCommonJS(tools_manager_exports);
45
47
  var import_utils = require("@nocobase/utils");
@@ -50,16 +52,16 @@ const _DefaultToolsManager = class _DefaultToolsManager {
50
52
  this.tools = tools;
51
53
  this.dynamicTools = dynamicTools;
52
54
  }
53
- async getTools(toolName) {
55
+ async getTools(toolName, filter) {
54
56
  const target = this.tools.get(toolName);
55
57
  if (target) {
56
58
  return target;
57
59
  }
58
- const dynamicTools = await this.syncDynamicTools();
60
+ const dynamicTools = await this.syncDynamicTools(filter);
59
61
  return dynamicTools.find((x) => x.definition.name === toolName);
60
62
  }
61
63
  async listTools(filter) {
62
- const toolsList = await this.getToolsList();
64
+ const toolsList = await this.getToolsList(filter);
63
65
  return toolsList.filter((x) => {
64
66
  if (!filter) {
65
67
  return true;
@@ -77,10 +79,20 @@ const _DefaultToolsManager = class _DefaultToolsManager {
77
79
  return result;
78
80
  });
79
81
  }
82
+ isToolsExisted(toolName) {
83
+ const target = this.tools.get(toolName);
84
+ if (target) {
85
+ return true;
86
+ }
87
+ return false;
88
+ }
80
89
  registerTools(options) {
81
90
  const list = import_lodash.default.isArray(options) ? options : [options];
82
91
  for (const item of list) {
83
92
  const toolsEntry = { ...item };
93
+ if (!toolsEntry.from) {
94
+ toolsEntry.from = "loader";
95
+ }
84
96
  if (!toolsEntry.execution) {
85
97
  toolsEntry.execution = "backend";
86
98
  }
@@ -99,17 +111,17 @@ const _DefaultToolsManager = class _DefaultToolsManager {
99
111
  registerDynamicTools(provider) {
100
112
  this.dynamicTools.push(provider);
101
113
  }
102
- async getToolsList() {
103
- const dynamicTools = await this.syncDynamicTools();
114
+ async getToolsList(filter) {
115
+ const dynamicTools = await this.syncDynamicTools(filter);
104
116
  return [...this.tools.getValues(), ...dynamicTools];
105
117
  }
106
- async syncDynamicTools() {
118
+ async syncDynamicTools(filter) {
107
119
  if (this.dynamicTools.length === 0) {
108
120
  return [];
109
121
  }
110
122
  const registry = new import_utils.Registry();
111
123
  const ephemeral = new _DefaultToolsManager(registry);
112
- await Promise.all(this.dynamicTools.map((register) => register(ephemeral)));
124
+ await Promise.all(this.dynamicTools.map((register) => register(ephemeral, filter)));
113
125
  return [...registry.getValues()];
114
126
  }
115
127
  };
@@ -119,9 +131,17 @@ function defineTools(options) {
119
131
  return options;
120
132
  }
121
133
  __name(defineTools, "defineTools");
134
+ const SYSTEM_TOOLS = {
135
+ WEB_SEARCH: "subAgentWebSearch",
136
+ KNOWLEDGE_BASE: "knowledge-base-retrieve",
137
+ WORK_FLOW_TASK_OUTPUT: "aiEmployeeWorkflowTaskOutput"
138
+ };
139
+ const listSystemTools = /* @__PURE__ */ __name(() => Object.values(SYSTEM_TOOLS), "listSystemTools");
122
140
  // Annotate the CommonJS export names for ESM import in node:
123
141
  0 && (module.exports = {
124
142
  DefaultToolsManager,
143
+ SYSTEM_TOOLS,
125
144
  defineTools,
145
+ listSystemTools,
126
146
  ...require("./types")
127
147
  });
@@ -8,15 +8,17 @@
8
8
  */
9
9
  import type { Context } from '@nocobase/actions';
10
10
  export interface ToolsManager extends ToolsRegistration {
11
- getTools(toolName: string): Promise<ToolsEntry>;
11
+ getTools(toolName: string, filter?: ToolsFilter): Promise<ToolsEntry>;
12
12
  listTools(filter?: ToolsFilter): Promise<ToolsEntry[]>;
13
+ isToolsExisted(toolName: string): boolean;
13
14
  }
14
15
  export interface ToolsRegistration {
15
16
  registerTools(options: ToolsOptions | ToolsOptions[]): void;
16
- registerDynamicTools(provider: (register: ToolsRegistration) => Promise<void>): void;
17
+ registerDynamicTools(provider: DynamicToolsProvider): void;
17
18
  }
18
19
  export type ToolsOptions = {
19
20
  scope: Scope;
21
+ from?: From;
20
22
  execution?: 'frontend' | 'backend';
21
23
  defaultPermission?: Permission;
22
24
  silence?: boolean;
@@ -29,14 +31,20 @@ export type ToolsOptions = {
29
31
  description: string;
30
32
  schema?: any;
31
33
  };
32
- invoke: (ctx: Context, args: any, id: string) => Promise<any>;
34
+ invoke: (ctx: Context, args: any, runtime: ToolsRuntime) => Promise<any>;
35
+ };
36
+ export type ToolsRuntime = {
37
+ toolCallId: string;
38
+ writer: (chunk: any) => void;
33
39
  };
34
40
  export type ToolsEntry = ToolsOptions;
35
41
  export type Scope = 'SPECIFIED' | 'GENERAL' | 'CUSTOM';
36
42
  export type Permission = 'ASK' | 'ALLOW';
37
- export type DynamicToolsProvider = (register: ToolsRegistration) => Promise<void>;
43
+ export type From = 'loader' | 'workflow' | 'mcp';
44
+ export type DynamicToolsProvider = (register: ToolsRegistration, filter?: ToolsFilter) => Promise<void>;
38
45
  export type ToolsFilter = {
39
46
  scope?: Scope;
40
47
  defaultPermission?: Permission;
41
48
  silence?: boolean;
49
+ sessionId?: string;
42
50
  };
package/package.json CHANGED
@@ -1,21 +1,41 @@
1
1
  {
2
2
  "name": "@nocobase/ai",
3
- "version": "2.1.0-alpha.3",
3
+ "version": "2.1.0-alpha.31",
4
4
  "description": "",
5
- "license": "AGPL-3.0",
5
+ "license": "Apache-2.0",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./lib/index.d.ts",
8
8
  "dependencies": {
9
- "@nocobase/logger": "2.1.0-alpha.3",
10
- "@nocobase/resourcer": "2.1.0-alpha.3",
11
- "@nocobase/utils": "2.1.0-alpha.3",
9
+ "@langchain/anthropic": "^1.3.17",
10
+ "@langchain/classic": "^1.0.21",
11
+ "@langchain/community": "^1.1.0",
12
+ "@langchain/core": "^1.1.24",
13
+ "@langchain/deepseek": "^1.0.11",
14
+ "@langchain/google-genai": "^2.1.18",
15
+ "@langchain/langgraph": "^1.1.4",
16
+ "@langchain/langgraph-checkpoint": "^1.0.0",
17
+ "@langchain/mcp-adapters": "^1.1.3",
18
+ "@langchain/ollama": "^1.2.2",
19
+ "@langchain/openai": "^1.2.7",
20
+ "@nocobase/data-source-manager": "2.1.0-alpha.31",
21
+ "@nocobase/logger": "2.1.0-alpha.31",
22
+ "@nocobase/resourcer": "2.1.0-alpha.31",
23
+ "@nocobase/utils": "2.1.0-alpha.31",
24
+ "d3-dsv": "2",
12
25
  "fast-glob": "^3.3.2",
13
- "flexsearch": "^0.8.2"
26
+ "flexsearch": "^0.8.2",
27
+ "gray-matter": "^4.0.3",
28
+ "langchain": "^1.2.24",
29
+ "mammoth": "^1.10.0",
30
+ "officeparser": "^5.2.0",
31
+ "pdf-parse": "^1.1.1",
32
+ "word-extractor": "^1.0.4",
33
+ "xlsx": "^0.18.5"
14
34
  },
15
35
  "repository": {
16
36
  "type": "git",
17
37
  "url": "git+https://github.com/nocobase/nocobase.git",
18
38
  "directory": "packages/ai"
19
39
  },
20
- "gitHead": "b4d7448b938c1c3be8b2299ad32c6cbe012dd4ea"
40
+ "gitHead": "e2bc6b461a9bfd336043069c3211c9c5b01ebcc3"
21
41
  }