@nocobase/ai 2.0.0

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/LICENSE +661 -0
  2. package/README.md +30 -0
  3. package/lib/ai-manager.d.ts +16 -0
  4. package/lib/ai-manager.js +49 -0
  5. package/lib/document-manager/document.d.ts +8 -0
  6. package/lib/document-manager/document.js +9 -0
  7. package/lib/document-manager/id-mapper.d.ts +17 -0
  8. package/lib/document-manager/id-mapper.js +79 -0
  9. package/lib/document-manager/index.d.ts +19 -0
  10. package/lib/document-manager/index.js +63 -0
  11. package/lib/document-manager/search-index.d.ts +19 -0
  12. package/lib/document-manager/search-index.js +69 -0
  13. package/lib/index.d.ts +12 -0
  14. package/lib/index.js +36 -0
  15. package/lib/loader/index.d.ts +11 -0
  16. package/lib/loader/index.js +34 -0
  17. package/lib/loader/scanner.d.ts +27 -0
  18. package/lib/loader/scanner.js +91 -0
  19. package/lib/loader/tools.d.ts +36 -0
  20. package/lib/loader/tools.js +151 -0
  21. package/lib/loader/types.d.ts +18 -0
  22. package/lib/loader/types.js +49 -0
  23. package/lib/loader/utils.d.ts +9 -0
  24. package/lib/loader/utils.js +51 -0
  25. package/lib/tools-manager/index.d.ts +23 -0
  26. package/lib/tools-manager/index.js +127 -0
  27. package/lib/tools-manager/types.d.ts +42 -0
  28. package/lib/tools-manager/types.js +24 -0
  29. package/package.json +21 -0
  30. package/src/__tests__/resource/ai/skills/document/tools/read.ts +23 -0
  31. package/src/__tests__/resource/ai/skills/document/tools/search/description.md +1 -0
  32. package/src/__tests__/resource/ai/skills/document/tools/search/index.ts +23 -0
  33. package/src/__tests__/resource/ai/tools/desc/description.md +1 -0
  34. package/src/__tests__/resource/ai/tools/desc/index.ts +23 -0
  35. package/src/__tests__/resource/ai/tools/empty.ts +9 -0
  36. package/src/__tests__/resource/ai/tools/group/group1.ts +23 -0
  37. package/src/__tests__/resource/ai/tools/group/group2.ts +23 -0
  38. package/src/__tests__/resource/ai/tools/group/group3/description.md +1 -0
  39. package/src/__tests__/resource/ai/tools/group/group3/index.ts +23 -0
  40. package/src/__tests__/resource/ai/tools/hallow/index.ts +23 -0
  41. package/src/__tests__/resource/ai/tools/ignored.ts +13 -0
  42. package/src/__tests__/resource/ai/tools/jsfiles/formFiller.js +61 -0
  43. package/src/__tests__/resource/ai/tools/jsfiles/formFiller2/index.js +61 -0
  44. package/src/__tests__/resource/ai/tools/print.ts +23 -0
  45. package/src/__tests__/tools.test.ts +133 -0
  46. package/src/ai-manager.ts +21 -0
  47. package/src/document-manager/document.ts +9 -0
  48. package/src/document-manager/id-mapper.ts +56 -0
  49. package/src/document-manager/index.ts +38 -0
  50. package/src/document-manager/search-index.ts +48 -0
  51. package/src/index.ts +13 -0
  52. package/src/loader/index.ts +12 -0
  53. package/src/loader/scanner.ts +54 -0
  54. package/src/loader/tools.ts +135 -0
  55. package/src/loader/types.ts +25 -0
  56. package/src/loader/utils.ts +14 -0
  57. package/src/tools-manager/index.ts +97 -0
  58. package/src/tools-manager/types.ts +50 -0
@@ -0,0 +1,151 @@
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var tools_exports = {};
39
+ __export(tools_exports, {
40
+ ToolsLoader: () => ToolsLoader
41
+ });
42
+ module.exports = __toCommonJS(tools_exports);
43
+ var import_utils = require("@nocobase/utils");
44
+ var import_scanner = require("./scanner");
45
+ var import_promises = require("fs/promises");
46
+ var import_lodash = __toESM(require("lodash"));
47
+ var import_fs = require("fs");
48
+ var import_types = require("./types");
49
+ var import_utils2 = require("./utils");
50
+ const _ToolsLoader = class _ToolsLoader extends import_types.LoadAndRegister {
51
+ constructor(ai, options) {
52
+ super(ai, options);
53
+ this.ai = ai;
54
+ this.options = options;
55
+ this.log = options.log;
56
+ this.scanner = new import_scanner.DirectoryScanner(this.options.scan);
57
+ }
58
+ scanner;
59
+ files = [];
60
+ toolsDescriptors = [];
61
+ log;
62
+ async scan() {
63
+ this.files = await this.scanner.scan();
64
+ }
65
+ async import() {
66
+ if (!this.files.length) {
67
+ return;
68
+ }
69
+ const grouped = /* @__PURE__ */ new Map();
70
+ for (const fd of this.files) {
71
+ const key = fd.basename === "index.ts" || fd.basename === "index.js" || fd.basename === "description.md" ? fd.directory : fd.name;
72
+ if (!grouped.has(key)) {
73
+ grouped.set(key, []);
74
+ }
75
+ grouped.get(key).push(fd);
76
+ }
77
+ this.toolsDescriptors = (await Promise.all(
78
+ Array.from(grouped.entries()).map(async ([name, fds]) => {
79
+ var _a, _b, _c;
80
+ const tsFile = fds.find((fd) => fd.extname === ".ts" || fd.extname === ".js");
81
+ const descFile = fds.find((fd) => fd.basename === "description.md");
82
+ const entry = { name, tsFile, descFile };
83
+ if (!tsFile || !(0, import_fs.existsSync)(tsFile.path)) {
84
+ (_a = this.log) == null ? void 0 : _a.error(`tools [${name}] ignored: can not find .ts file`);
85
+ return null;
86
+ }
87
+ try {
88
+ const module2 = await (0, import_utils.importModule)(tsFile.path);
89
+ if ((0, import_utils2.isNonEmptyObject)(module2)) {
90
+ entry.toolsOptions = typeof module2 === "function" ? module2() : module2;
91
+ } else {
92
+ entry.toolsOptions = void 0;
93
+ }
94
+ } catch (e) {
95
+ (_b = this.log) == null ? void 0 : _b.error(`tools [${name}] load fail: error occur when import ${tsFile.path}`, e);
96
+ return null;
97
+ }
98
+ if (descFile && (0, import_fs.existsSync)(descFile.path)) {
99
+ try {
100
+ entry.description = await (0, import_promises.readFile)(descFile.path, "utf-8");
101
+ } catch (e) {
102
+ (_c = this.log) == null ? void 0 : _c.error(
103
+ `tools [${name}] load fail: error occur when reading description.md at ${descFile.path}`,
104
+ e
105
+ );
106
+ return null;
107
+ }
108
+ }
109
+ return entry;
110
+ })
111
+ )).filter((t) => t != null);
112
+ }
113
+ async register() {
114
+ var _a, _b, _c;
115
+ if (!this.toolsDescriptors.length) {
116
+ return;
117
+ }
118
+ const { toolsManager } = this.ai;
119
+ for (const descriptor of this.toolsDescriptors) {
120
+ if (!descriptor.toolsOptions) {
121
+ (_a = this.log) == null ? void 0 : _a.warn(
122
+ `tools [${descriptor.name}] register ignored: ToolsOptions not export as default at ${descriptor.tsFile.path}`
123
+ );
124
+ continue;
125
+ }
126
+ const { name, toolsOptions, description } = descriptor;
127
+ if (await toolsManager.getTools(name)) {
128
+ (_b = this.log) == null ? void 0 : _b.warn(`tools [${descriptor.name}] register ignored: duplicate register for tools`);
129
+ continue;
130
+ }
131
+ if (toolsOptions.definition) {
132
+ toolsOptions.definition.name = name;
133
+ if (!import_lodash.default.isEmpty(description)) {
134
+ toolsOptions.definition.description = description;
135
+ }
136
+ }
137
+ try {
138
+ toolsManager.registerTools(toolsOptions);
139
+ } catch (e) {
140
+ (_c = this.log) == null ? void 0 : _c.error(`tools [${descriptor.name}] register ignored: error occur when invoke registerTools`, e);
141
+ continue;
142
+ }
143
+ }
144
+ }
145
+ };
146
+ __name(_ToolsLoader, "ToolsLoader");
147
+ let ToolsLoader = _ToolsLoader;
148
+ // Annotate the CommonJS export names for ESM import in node:
149
+ 0 && (module.exports = {
150
+ ToolsLoader
151
+ });
@@ -0,0 +1,18 @@
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 { AIManager } from '../ai-manager';
10
+ export declare abstract class LoadAndRegister<TOptions> {
11
+ protected readonly ai: AIManager;
12
+ protected readonly options: TOptions;
13
+ constructor(ai: AIManager, options: TOptions);
14
+ protected abstract scan(): Promise<void>;
15
+ protected abstract import(): Promise<void>;
16
+ protected abstract register(): Promise<void>;
17
+ load(): Promise<void>;
18
+ }
@@ -0,0 +1,49 @@
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 types_exports = {};
29
+ __export(types_exports, {
30
+ LoadAndRegister: () => LoadAndRegister
31
+ });
32
+ module.exports = __toCommonJS(types_exports);
33
+ const _LoadAndRegister = class _LoadAndRegister {
34
+ constructor(ai, options) {
35
+ this.ai = ai;
36
+ this.options = options;
37
+ }
38
+ async load() {
39
+ await this.scan();
40
+ await this.import();
41
+ await this.register();
42
+ }
43
+ };
44
+ __name(_LoadAndRegister, "LoadAndRegister");
45
+ let LoadAndRegister = _LoadAndRegister;
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ LoadAndRegister
49
+ });
@@ -0,0 +1,9 @@
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 declare function isNonEmptyObject(val: any): boolean;
@@ -0,0 +1,51 @@
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var utils_exports = {};
39
+ __export(utils_exports, {
40
+ isNonEmptyObject: () => isNonEmptyObject
41
+ });
42
+ module.exports = __toCommonJS(utils_exports);
43
+ var import_lodash = __toESM(require("lodash"));
44
+ function isNonEmptyObject(val) {
45
+ return import_lodash.default.isPlainObject(val) && !import_lodash.default.isEmpty(val);
46
+ }
47
+ __name(isNonEmptyObject, "isNonEmptyObject");
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ isNonEmptyObject
51
+ });
@@ -0,0 +1,23 @@
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 { Registry } from '@nocobase/utils';
10
+ import { DynamicToolsProvider, ToolsEntry, ToolsFilter, ToolsManager, ToolsOptions } from './types';
11
+ export declare class DefaultToolsManager implements ToolsManager {
12
+ private readonly tools;
13
+ private readonly dynamicTools;
14
+ constructor(tools?: Registry<ToolsOptions>, dynamicTools?: DynamicToolsProvider[]);
15
+ getTools(toolName: string): Promise<ToolsEntry>;
16
+ listTools(filter?: ToolsFilter): Promise<ToolsEntry[]>;
17
+ registerTools(options: ToolsOptions | ToolsOptions[]): void;
18
+ registerDynamicTools(provider: DynamicToolsProvider): void;
19
+ private getToolsList;
20
+ private syncDynamicTools;
21
+ }
22
+ export declare function defineTools(options: ToolsOptions): ToolsOptions;
23
+ export * from './types';
@@ -0,0 +1,127 @@
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 tools_manager_exports = {};
40
+ __export(tools_manager_exports, {
41
+ DefaultToolsManager: () => DefaultToolsManager,
42
+ defineTools: () => defineTools
43
+ });
44
+ module.exports = __toCommonJS(tools_manager_exports);
45
+ var import_utils = require("@nocobase/utils");
46
+ var import_lodash = __toESM(require("lodash"));
47
+ __reExport(tools_manager_exports, require("./types"), module.exports);
48
+ const _DefaultToolsManager = class _DefaultToolsManager {
49
+ constructor(tools = new import_utils.Registry(), dynamicTools = []) {
50
+ this.tools = tools;
51
+ this.dynamicTools = dynamicTools;
52
+ }
53
+ async getTools(toolName) {
54
+ const target = this.tools.get(toolName);
55
+ if (target) {
56
+ return target;
57
+ }
58
+ const dynamicTools = await this.syncDynamicTools();
59
+ return dynamicTools.find((x) => x.definition.name === toolName);
60
+ }
61
+ async listTools(filter) {
62
+ const toolsList = await this.getToolsList();
63
+ return toolsList.filter((x) => {
64
+ if (!filter) {
65
+ return true;
66
+ }
67
+ let result = true;
68
+ if (filter.scope) {
69
+ result &&= filter.scope === x.scope;
70
+ }
71
+ if (filter.defaultPermission) {
72
+ result &&= filter.defaultPermission === x.defaultPermission;
73
+ }
74
+ if (filter.silence != null && filter.silence !== void 0) {
75
+ result &&= filter.silence === x.silence;
76
+ }
77
+ return result;
78
+ });
79
+ }
80
+ registerTools(options) {
81
+ const list = import_lodash.default.isArray(options) ? options : [options];
82
+ for (const item of list) {
83
+ const toolsEntry = { ...item };
84
+ if (!toolsEntry.execution) {
85
+ toolsEntry.execution = "backend";
86
+ }
87
+ if (!toolsEntry.defaultPermission) {
88
+ toolsEntry.defaultPermission = "ASK";
89
+ }
90
+ toolsEntry.silence = toolsEntry.silence === true;
91
+ if (!toolsEntry.introduction) {
92
+ toolsEntry.introduction = {
93
+ title: toolsEntry.definition.name
94
+ };
95
+ }
96
+ this.tools.register(item.definition.name, toolsEntry);
97
+ }
98
+ }
99
+ registerDynamicTools(provider) {
100
+ this.dynamicTools.push(provider);
101
+ }
102
+ async getToolsList() {
103
+ const dynamicTools = await this.syncDynamicTools();
104
+ return [...this.tools.getValues(), ...dynamicTools];
105
+ }
106
+ async syncDynamicTools() {
107
+ if (this.dynamicTools.length === 0) {
108
+ return [];
109
+ }
110
+ const registry = new import_utils.Registry();
111
+ const ephemeral = new _DefaultToolsManager(registry);
112
+ await Promise.all(this.dynamicTools.map((register) => register(ephemeral)));
113
+ return [...registry.getValues()];
114
+ }
115
+ };
116
+ __name(_DefaultToolsManager, "DefaultToolsManager");
117
+ let DefaultToolsManager = _DefaultToolsManager;
118
+ function defineTools(options) {
119
+ return options;
120
+ }
121
+ __name(defineTools, "defineTools");
122
+ // Annotate the CommonJS export names for ESM import in node:
123
+ 0 && (module.exports = {
124
+ DefaultToolsManager,
125
+ defineTools,
126
+ ...require("./types")
127
+ });
@@ -0,0 +1,42 @@
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 type { Context } from '@nocobase/actions';
10
+ export interface ToolsManager extends ToolsRegistration {
11
+ getTools(toolName: string): Promise<ToolsEntry>;
12
+ listTools(filter?: ToolsFilter): Promise<ToolsEntry[]>;
13
+ }
14
+ export interface ToolsRegistration {
15
+ registerTools(options: ToolsOptions | ToolsOptions[]): void;
16
+ registerDynamicTools(provider: (register: ToolsRegistration) => Promise<void>): void;
17
+ }
18
+ export type ToolsOptions = {
19
+ scope: Scope;
20
+ execution?: 'frontend' | 'backend';
21
+ defaultPermission?: Permission;
22
+ silence?: boolean;
23
+ introduction?: {
24
+ title: string;
25
+ about?: string;
26
+ };
27
+ definition: {
28
+ name: string;
29
+ description: string;
30
+ schema?: any;
31
+ };
32
+ invoke: (ctx: Context, args: any, id: string) => Promise<any>;
33
+ };
34
+ export type ToolsEntry = ToolsOptions;
35
+ export type Scope = 'SPECIFIED' | 'GENERAL' | 'CUSTOM';
36
+ export type Permission = 'ASK' | 'ALLOW';
37
+ export type DynamicToolsProvider = (register: ToolsRegistration) => Promise<void>;
38
+ export type ToolsFilter = {
39
+ scope?: Scope;
40
+ defaultPermission?: Permission;
41
+ silence?: boolean;
42
+ };
@@ -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);
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@nocobase/ai",
3
+ "version": "2.0.0",
4
+ "description": "",
5
+ "license": "AGPL-3.0",
6
+ "main": "./lib/index.js",
7
+ "types": "./lib/index.d.ts",
8
+ "dependencies": {
9
+ "@nocobase/logger": "2.0.0",
10
+ "@nocobase/resourcer": "2.0.0",
11
+ "@nocobase/utils": "2.0.0",
12
+ "fast-glob": "^3.3.2",
13
+ "flexsearch": "^0.8.2"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/nocobase/nocobase.git",
18
+ "directory": "packages/ai"
19
+ },
20
+ "gitHead": "3590c0087a56f0f285a5357f43a80bdc62b11bec"
21
+ }
@@ -0,0 +1,23 @@
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
+ import { Context } from '@nocobase/actions';
11
+ import { defineTools } from '@nocobase/ai';
12
+
13
+ export default defineTools({
14
+ scope: 'SPECIFIED',
15
+ definition: {
16
+ name: 'read',
17
+ description: 'read document',
18
+ schema: null,
19
+ },
20
+ invoke: async (ctx: Context, args: any, id: string) => {
21
+ return { status: 'success' };
22
+ },
23
+ });
@@ -0,0 +1,23 @@
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
+ import { Context } from '@nocobase/actions';
11
+ import { defineTools } from '@nocobase/ai';
12
+
13
+ export default defineTools({
14
+ scope: 'SPECIFIED',
15
+ definition: {
16
+ name: 'search',
17
+ description: 'search document',
18
+ schema: null,
19
+ },
20
+ invoke: async (ctx: Context, args: any, id: string) => {
21
+ return { status: 'success' };
22
+ },
23
+ });
@@ -0,0 +1,23 @@
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
+ import { Context } from '@nocobase/actions';
11
+ import { defineTools } from '@nocobase/ai';
12
+
13
+ export default defineTools({
14
+ scope: 'GENERAL',
15
+ definition: {
16
+ name: 'desc',
17
+ description: 'tools with description.md',
18
+ schema: null,
19
+ },
20
+ invoke: async (ctx: Context, args: any, id: string) => {
21
+ return { status: 'success' };
22
+ },
23
+ });
@@ -0,0 +1,9 @@
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
+
@@ -0,0 +1,23 @@
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
+ import { Context } from '@nocobase/actions';
11
+ import { defineTools } from '@nocobase/ai';
12
+
13
+ export default defineTools({
14
+ scope: 'GENERAL',
15
+ definition: {
16
+ name: 'group1',
17
+ description: 'hallow group1',
18
+ schema: null,
19
+ },
20
+ invoke: async (ctx: Context, args: any, id: string) => {
21
+ return { status: 'success' };
22
+ },
23
+ });
@@ -0,0 +1,23 @@
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
+ import { Context } from '@nocobase/actions';
11
+ import { defineTools } from '@nocobase/ai';
12
+
13
+ export default defineTools({
14
+ scope: 'GENERAL',
15
+ definition: {
16
+ name: 'group2',
17
+ description: 'hallow group2',
18
+ schema: null,
19
+ },
20
+ invoke: async (ctx: Context, args: any, id: string) => {
21
+ return { status: 'success' };
22
+ },
23
+ });