@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.
- package/LICENSE +661 -0
- package/README.md +30 -0
- package/lib/ai-manager.d.ts +16 -0
- package/lib/ai-manager.js +49 -0
- package/lib/document-manager/document.d.ts +8 -0
- package/lib/document-manager/document.js +9 -0
- package/lib/document-manager/id-mapper.d.ts +17 -0
- package/lib/document-manager/id-mapper.js +79 -0
- package/lib/document-manager/index.d.ts +19 -0
- package/lib/document-manager/index.js +63 -0
- package/lib/document-manager/search-index.d.ts +19 -0
- package/lib/document-manager/search-index.js +69 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +36 -0
- package/lib/loader/index.d.ts +11 -0
- package/lib/loader/index.js +34 -0
- package/lib/loader/scanner.d.ts +27 -0
- package/lib/loader/scanner.js +91 -0
- package/lib/loader/tools.d.ts +36 -0
- package/lib/loader/tools.js +151 -0
- package/lib/loader/types.d.ts +18 -0
- package/lib/loader/types.js +49 -0
- package/lib/loader/utils.d.ts +9 -0
- package/lib/loader/utils.js +51 -0
- package/lib/tools-manager/index.d.ts +23 -0
- package/lib/tools-manager/index.js +127 -0
- package/lib/tools-manager/types.d.ts +42 -0
- package/lib/tools-manager/types.js +24 -0
- package/package.json +21 -0
- package/src/__tests__/resource/ai/skills/document/tools/read.ts +23 -0
- package/src/__tests__/resource/ai/skills/document/tools/search/description.md +1 -0
- package/src/__tests__/resource/ai/skills/document/tools/search/index.ts +23 -0
- package/src/__tests__/resource/ai/tools/desc/description.md +1 -0
- package/src/__tests__/resource/ai/tools/desc/index.ts +23 -0
- package/src/__tests__/resource/ai/tools/empty.ts +9 -0
- package/src/__tests__/resource/ai/tools/group/group1.ts +23 -0
- package/src/__tests__/resource/ai/tools/group/group2.ts +23 -0
- package/src/__tests__/resource/ai/tools/group/group3/description.md +1 -0
- package/src/__tests__/resource/ai/tools/group/group3/index.ts +23 -0
- package/src/__tests__/resource/ai/tools/hallow/index.ts +23 -0
- package/src/__tests__/resource/ai/tools/ignored.ts +13 -0
- package/src/__tests__/resource/ai/tools/jsfiles/formFiller.js +61 -0
- package/src/__tests__/resource/ai/tools/jsfiles/formFiller2/index.js +61 -0
- package/src/__tests__/resource/ai/tools/print.ts +23 -0
- package/src/__tests__/tools.test.ts +133 -0
- package/src/ai-manager.ts +21 -0
- package/src/document-manager/document.ts +9 -0
- package/src/document-manager/id-mapper.ts +56 -0
- package/src/document-manager/index.ts +38 -0
- package/src/document-manager/search-index.ts +48 -0
- package/src/index.ts +13 -0
- package/src/loader/index.ts +12 -0
- package/src/loader/scanner.ts +54 -0
- package/src/loader/tools.ts +135 -0
- package/src/loader/types.ts +25 -0
- package/src/loader/utils.ts +14 -0
- package/src/tools-manager/index.ts +97 -0
- package/src/tools-manager/types.ts +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# NocoBase
|
|
2
|
+
|
|
3
|
+
<video width="100%" controls>
|
|
4
|
+
<source src="https://static-docs.nocobase.com/NocoBase0510.mp4" type="video/mp4">
|
|
5
|
+
</video>
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## What is NocoBase
|
|
9
|
+
|
|
10
|
+
NocoBase is a scalability-first, open-source no-code development platform.
|
|
11
|
+
Instead of investing years of time and millions of dollars in research and development, deploy NocoBase in a few minutes and you'll have a private, controllable, and extremely scalable no-code development platform!
|
|
12
|
+
|
|
13
|
+
Homepage:
|
|
14
|
+
https://www.nocobase.com/
|
|
15
|
+
|
|
16
|
+
Online Demo:
|
|
17
|
+
https://demo.nocobase.com/new
|
|
18
|
+
|
|
19
|
+
Documents:
|
|
20
|
+
https://docs.nocobase.com/
|
|
21
|
+
|
|
22
|
+
Commericial license & plugins:
|
|
23
|
+
https://www.nocobase.com/en/commercial
|
|
24
|
+
|
|
25
|
+
License agreement:
|
|
26
|
+
https://www.nocobase.com/en/agreement
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Contact Us:
|
|
30
|
+
hello@nocobase.com
|
|
@@ -0,0 +1,16 @@
|
|
|
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 { DocumentManager } from './document-manager';
|
|
10
|
+
import { ToolsManager } from './tools-manager';
|
|
11
|
+
export declare class AIManager {
|
|
12
|
+
protected readonly app: any;
|
|
13
|
+
documentManager: DocumentManager;
|
|
14
|
+
toolsManager: ToolsManager;
|
|
15
|
+
constructor(app: any);
|
|
16
|
+
}
|
|
@@ -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 ai_manager_exports = {};
|
|
29
|
+
__export(ai_manager_exports, {
|
|
30
|
+
AIManager: () => AIManager
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(ai_manager_exports);
|
|
33
|
+
var import_document_manager = require("./document-manager");
|
|
34
|
+
var import_tools_manager = require("./tools-manager");
|
|
35
|
+
const _AIManager = class _AIManager {
|
|
36
|
+
constructor(app) {
|
|
37
|
+
this.app = app;
|
|
38
|
+
this.documentManager = new import_document_manager.DocumentManager();
|
|
39
|
+
this.toolsManager = new import_tools_manager.DefaultToolsManager();
|
|
40
|
+
}
|
|
41
|
+
documentManager;
|
|
42
|
+
toolsManager;
|
|
43
|
+
};
|
|
44
|
+
__name(_AIManager, "AIManager");
|
|
45
|
+
let AIManager = _AIManager;
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
AIManager
|
|
49
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
*/
|
|
@@ -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,17 @@
|
|
|
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 class IdMapper {
|
|
10
|
+
private nextId;
|
|
11
|
+
private ext2num;
|
|
12
|
+
private num2ext;
|
|
13
|
+
toNumeric(id: string | number): number;
|
|
14
|
+
getNumeric(id: string | number): number | undefined;
|
|
15
|
+
toExternal(id: number): string | number;
|
|
16
|
+
remove(id: string | number): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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 id_mapper_exports = {};
|
|
29
|
+
__export(id_mapper_exports, {
|
|
30
|
+
IdMapper: () => IdMapper
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(id_mapper_exports);
|
|
33
|
+
const _IdMapper = class _IdMapper {
|
|
34
|
+
nextId = 1;
|
|
35
|
+
ext2num = /* @__PURE__ */ new Map();
|
|
36
|
+
num2ext = /* @__PURE__ */ new Map();
|
|
37
|
+
toNumeric(id) {
|
|
38
|
+
if (typeof id === "number") {
|
|
39
|
+
return id;
|
|
40
|
+
}
|
|
41
|
+
let num = this.ext2num.get(id);
|
|
42
|
+
if (!num) {
|
|
43
|
+
num = this.nextId++;
|
|
44
|
+
this.ext2num.set(id, num);
|
|
45
|
+
this.num2ext.set(num, id);
|
|
46
|
+
}
|
|
47
|
+
return num;
|
|
48
|
+
}
|
|
49
|
+
getNumeric(id) {
|
|
50
|
+
if (typeof id === "number") {
|
|
51
|
+
return id;
|
|
52
|
+
}
|
|
53
|
+
return this.ext2num.get(id);
|
|
54
|
+
}
|
|
55
|
+
toExternal(id) {
|
|
56
|
+
return this.num2ext.get(id) ?? id;
|
|
57
|
+
}
|
|
58
|
+
remove(id) {
|
|
59
|
+
if (typeof id === "number") {
|
|
60
|
+
const ext = this.num2ext.get(id);
|
|
61
|
+
if (ext) {
|
|
62
|
+
this.num2ext.delete(id);
|
|
63
|
+
this.ext2num.delete(ext);
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
const num = this.ext2num.get(id);
|
|
67
|
+
if (num) {
|
|
68
|
+
this.ext2num.delete(id);
|
|
69
|
+
this.num2ext.delete(num);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
__name(_IdMapper, "IdMapper");
|
|
75
|
+
let IdMapper = _IdMapper;
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
IdMapper
|
|
79
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { Document, DocumentOptions, IndexOptions } from 'flexsearch';
|
|
10
|
+
import { Index } from './search-index';
|
|
11
|
+
export declare class DocumentManager {
|
|
12
|
+
indexes: Map<string, Index>;
|
|
13
|
+
documents: Map<string, Document>;
|
|
14
|
+
addIndex(name: string, options?: IndexOptions): Index;
|
|
15
|
+
getIndex(name: string): Index | undefined;
|
|
16
|
+
addDocument(name: string, options?: DocumentOptions): Document<import("flexsearch").DocumentData, false, false>;
|
|
17
|
+
getDocument(name: string): Document | undefined;
|
|
18
|
+
}
|
|
19
|
+
export { Index as FlexSearchIndex } from 'flexsearch';
|
|
@@ -0,0 +1,63 @@
|
|
|
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 document_manager_exports = {};
|
|
29
|
+
__export(document_manager_exports, {
|
|
30
|
+
DocumentManager: () => DocumentManager,
|
|
31
|
+
FlexSearchIndex: () => import_flexsearch2.Index
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(document_manager_exports);
|
|
34
|
+
var import_flexsearch = require("flexsearch");
|
|
35
|
+
var import_search_index = require("./search-index");
|
|
36
|
+
var import_flexsearch2 = require("flexsearch");
|
|
37
|
+
const _DocumentManager = class _DocumentManager {
|
|
38
|
+
indexes = /* @__PURE__ */ new Map();
|
|
39
|
+
documents = /* @__PURE__ */ new Map();
|
|
40
|
+
addIndex(name, options) {
|
|
41
|
+
const index = new import_search_index.Index(options);
|
|
42
|
+
this.indexes.set(name, index);
|
|
43
|
+
return index;
|
|
44
|
+
}
|
|
45
|
+
getIndex(name) {
|
|
46
|
+
return this.indexes.get(name);
|
|
47
|
+
}
|
|
48
|
+
addDocument(name, options) {
|
|
49
|
+
const doc = new import_flexsearch.Document(options);
|
|
50
|
+
this.documents.set(name, doc);
|
|
51
|
+
return doc;
|
|
52
|
+
}
|
|
53
|
+
getDocument(name) {
|
|
54
|
+
return this.documents.get(name);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
__name(_DocumentManager, "DocumentManager");
|
|
58
|
+
let DocumentManager = _DocumentManager;
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
DocumentManager,
|
|
62
|
+
FlexSearchIndex
|
|
63
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { Index as BaseIndex, ExportHandler, IndexOptions } from 'flexsearch';
|
|
10
|
+
export declare class Index {
|
|
11
|
+
private index;
|
|
12
|
+
private ids;
|
|
13
|
+
constructor(options?: IndexOptions);
|
|
14
|
+
add(id: string | number, text: string): Promise<BaseIndex<false, false, true>>;
|
|
15
|
+
remove(id: string | number): Promise<void>;
|
|
16
|
+
search(query: string, options?: any): Promise<(string | number)[]>;
|
|
17
|
+
export(handler: ExportHandler): void;
|
|
18
|
+
import(key: string, data: string): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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 search_index_exports = {};
|
|
29
|
+
__export(search_index_exports, {
|
|
30
|
+
Index: () => Index
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(search_index_exports);
|
|
33
|
+
var import_flexsearch = require("flexsearch");
|
|
34
|
+
var import_id_mapper = require("./id-mapper");
|
|
35
|
+
const _Index = class _Index {
|
|
36
|
+
index;
|
|
37
|
+
ids = new import_id_mapper.IdMapper();
|
|
38
|
+
constructor(options) {
|
|
39
|
+
this.index = new import_flexsearch.Index(options);
|
|
40
|
+
}
|
|
41
|
+
async add(id, text) {
|
|
42
|
+
const numericId = this.ids.toNumeric(id);
|
|
43
|
+
return this.index.addAsync(numericId, text);
|
|
44
|
+
}
|
|
45
|
+
async remove(id) {
|
|
46
|
+
const numericId = this.ids.getNumeric(id);
|
|
47
|
+
if (numericId === void 0) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
await this.index.removeAsync(numericId);
|
|
51
|
+
this.ids.remove(id);
|
|
52
|
+
}
|
|
53
|
+
async search(query, options) {
|
|
54
|
+
const result = await this.index.searchAsync(query, options);
|
|
55
|
+
return result.map((id) => this.ids.toExternal(id));
|
|
56
|
+
}
|
|
57
|
+
export(handler) {
|
|
58
|
+
return this.index.export(handler);
|
|
59
|
+
}
|
|
60
|
+
import(key, data) {
|
|
61
|
+
return this.index.import(key, data);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
__name(_Index, "Index");
|
|
65
|
+
let Index = _Index;
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
Index
|
|
69
|
+
});
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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 * from './ai-manager';
|
|
10
|
+
export * from './document-manager';
|
|
11
|
+
export * from './tools-manager';
|
|
12
|
+
export * from './loader';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var src_exports = {};
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
__reExport(src_exports, require("./ai-manager"), module.exports);
|
|
27
|
+
__reExport(src_exports, require("./document-manager"), module.exports);
|
|
28
|
+
__reExport(src_exports, require("./tools-manager"), module.exports);
|
|
29
|
+
__reExport(src_exports, require("./loader"), module.exports);
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
...require("./ai-manager"),
|
|
33
|
+
...require("./document-manager"),
|
|
34
|
+
...require("./tools-manager"),
|
|
35
|
+
...require("./loader")
|
|
36
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
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 * from './types';
|
|
10
|
+
export * from './scanner';
|
|
11
|
+
export * from './tools';
|
|
@@ -0,0 +1,34 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var loader_exports = {};
|
|
25
|
+
module.exports = __toCommonJS(loader_exports);
|
|
26
|
+
__reExport(loader_exports, require("./types"), module.exports);
|
|
27
|
+
__reExport(loader_exports, require("./scanner"), module.exports);
|
|
28
|
+
__reExport(loader_exports, require("./tools"), module.exports);
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
...require("./types"),
|
|
32
|
+
...require("./scanner"),
|
|
33
|
+
...require("./tools")
|
|
34
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
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 DirectoryScannerOptions = {
|
|
10
|
+
basePath: string;
|
|
11
|
+
pattern: string[];
|
|
12
|
+
};
|
|
13
|
+
export declare class DirectoryScanner {
|
|
14
|
+
private readonly options;
|
|
15
|
+
protected readonly files: FileDescriptor[];
|
|
16
|
+
constructor(options: DirectoryScannerOptions);
|
|
17
|
+
scan(): Promise<FileDescriptor[]>;
|
|
18
|
+
}
|
|
19
|
+
export declare class FileDescriptor {
|
|
20
|
+
private readonly filePath;
|
|
21
|
+
constructor(filePath: string);
|
|
22
|
+
get name(): string;
|
|
23
|
+
get directory(): string;
|
|
24
|
+
get path(): string;
|
|
25
|
+
get extname(): string;
|
|
26
|
+
get basename(): string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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 scanner_exports = {};
|
|
39
|
+
__export(scanner_exports, {
|
|
40
|
+
DirectoryScanner: () => DirectoryScanner,
|
|
41
|
+
FileDescriptor: () => FileDescriptor
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(scanner_exports);
|
|
44
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
|
45
|
+
var import_path = __toESM(require("path"));
|
|
46
|
+
const _DirectoryScanner = class _DirectoryScanner {
|
|
47
|
+
constructor(options) {
|
|
48
|
+
this.options = options;
|
|
49
|
+
}
|
|
50
|
+
files = [];
|
|
51
|
+
async scan() {
|
|
52
|
+
const { basePath, pattern } = this.options;
|
|
53
|
+
const filePaths = await (0, import_fast_glob.default)(pattern, {
|
|
54
|
+
cwd: basePath,
|
|
55
|
+
absolute: true,
|
|
56
|
+
onlyFiles: true,
|
|
57
|
+
dot: false,
|
|
58
|
+
followSymbolicLinks: false
|
|
59
|
+
});
|
|
60
|
+
return filePaths.map((f) => new FileDescriptor(f));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
__name(_DirectoryScanner, "DirectoryScanner");
|
|
64
|
+
let DirectoryScanner = _DirectoryScanner;
|
|
65
|
+
const _FileDescriptor = class _FileDescriptor {
|
|
66
|
+
constructor(filePath) {
|
|
67
|
+
this.filePath = filePath;
|
|
68
|
+
}
|
|
69
|
+
get name() {
|
|
70
|
+
return import_path.default.parse(this.filePath).name;
|
|
71
|
+
}
|
|
72
|
+
get directory() {
|
|
73
|
+
return import_path.default.basename(import_path.default.dirname(this.filePath));
|
|
74
|
+
}
|
|
75
|
+
get path() {
|
|
76
|
+
return this.filePath;
|
|
77
|
+
}
|
|
78
|
+
get extname() {
|
|
79
|
+
return import_path.default.extname(this.filePath);
|
|
80
|
+
}
|
|
81
|
+
get basename() {
|
|
82
|
+
return import_path.default.basename(this.filePath);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
__name(_FileDescriptor, "FileDescriptor");
|
|
86
|
+
let FileDescriptor = _FileDescriptor;
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
DirectoryScanner,
|
|
90
|
+
FileDescriptor
|
|
91
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { ToolsOptions } from '../tools-manager';
|
|
10
|
+
import { DirectoryScanner, DirectoryScannerOptions, FileDescriptor } from './scanner';
|
|
11
|
+
import { AIManager } from '../ai-manager';
|
|
12
|
+
import { LoadAndRegister } from './types';
|
|
13
|
+
import { Logger } from '@nocobase/logger';
|
|
14
|
+
export type ToolsLoaderOptions = {
|
|
15
|
+
scan: DirectoryScannerOptions;
|
|
16
|
+
log?: Logger;
|
|
17
|
+
};
|
|
18
|
+
export declare class ToolsLoader extends LoadAndRegister<ToolsLoaderOptions> {
|
|
19
|
+
protected readonly ai: AIManager;
|
|
20
|
+
protected readonly options: ToolsLoaderOptions;
|
|
21
|
+
protected readonly scanner: DirectoryScanner;
|
|
22
|
+
protected files: FileDescriptor[];
|
|
23
|
+
protected toolsDescriptors: ToolsDescriptor[];
|
|
24
|
+
protected log: Logger;
|
|
25
|
+
constructor(ai: AIManager, options: ToolsLoaderOptions);
|
|
26
|
+
protected scan(): Promise<void>;
|
|
27
|
+
protected import(): Promise<void>;
|
|
28
|
+
protected register(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export type ToolsDescriptor = {
|
|
31
|
+
name: string;
|
|
32
|
+
tsFile?: FileDescriptor;
|
|
33
|
+
descFile?: FileDescriptor;
|
|
34
|
+
toolsOptions?: ToolsOptions;
|
|
35
|
+
description?: string;
|
|
36
|
+
};
|