@nocobase/ai 2.1.0-beta.2 → 2.1.0-beta.20
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 +201 -661
- package/README.md +79 -10
- package/lib/ai-employee-manager/index.d.ts +29 -0
- package/lib/ai-employee-manager/index.js +167 -0
- package/lib/ai-employee-manager/types.d.ts +56 -0
- package/lib/ai-employee-manager/types.js +24 -0
- package/lib/ai-manager.d.ts +8 -0
- package/lib/ai-manager.js +12 -0
- package/lib/document-loader/index.d.ts +10 -0
- package/lib/document-loader/index.js +90 -0
- package/lib/document-loader/loader.worker.d.ts +9 -0
- package/lib/document-loader/loader.worker.js +83 -0
- package/lib/document-loader/vendor/langchain/document_loaders/fs/text.d.ts +20 -0
- package/lib/document-loader/vendor/langchain/document_loaders/fs/text.js +99 -0
- package/lib/document-loader/xlsx.d.ts +10 -0
- package/lib/document-loader/xlsx.js +100 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +11 -1
- package/lib/loader/employee.d.ts +37 -0
- package/lib/loader/employee.js +207 -0
- package/lib/loader/index.d.ts +3 -0
- package/lib/loader/index.js +7 -1
- package/lib/loader/mcp.d.ts +35 -0
- package/lib/loader/mcp.js +108 -0
- package/lib/loader/skills.d.ts +43 -0
- package/lib/loader/skills.js +138 -0
- package/lib/loader/tools.d.ts +1 -0
- package/lib/loader/tools.js +4 -3
- package/lib/mcp-manager/index.d.ts +43 -0
- package/lib/mcp-manager/index.js +341 -0
- package/lib/mcp-manager/types.d.ts +61 -0
- package/lib/mcp-manager/types.js +24 -0
- package/lib/mcp-tools-manager.d.ts +43 -0
- package/lib/mcp-tools-manager.js +77 -0
- package/lib/skills-manager/index.d.ts +29 -0
- package/lib/skills-manager/index.js +169 -0
- package/lib/skills-manager/types.d.ts +33 -0
- package/lib/skills-manager/types.js +24 -0
- package/lib/tools-manager/index.d.ts +2 -1
- package/lib/tools-manager/index.js +17 -7
- package/lib/tools-manager/types.d.ts +12 -4
- package/package.json +27 -7
- package/src/__tests__/ai-employees.test.ts +108 -0
- package/src/__tests__/mcp.test.ts +105 -0
- package/src/__tests__/resource/ai/ai-employees/index-employee/index.ts +16 -0
- package/src/__tests__/resource/ai/ai-employees/index-employee/prompt.md +1 -0
- package/src/__tests__/resource/ai/ai-employees/named-file-employee.ts +16 -0
- package/src/__tests__/resource/ai/ai-employees/with-skills/index.ts +16 -0
- package/src/__tests__/resource/ai/ai-employees/with-skills/skills/analysis/SKILLS.md +6 -0
- package/src/__tests__/resource/ai/ai-employees/with-skills-merge/index.ts +17 -0
- package/src/__tests__/resource/ai/ai-employees/with-skills-merge/skills/discovered-skill/SKILLS.md +6 -0
- package/src/__tests__/resource/ai/ai-employees/with-tools/index.ts +16 -0
- package/src/__tests__/resource/ai/ai-employees/with-tools/tools/discoveredTool.ts +23 -0
- package/src/__tests__/resource/ai/ai-employees/with-tools-merge/index.ts +16 -0
- package/src/__tests__/resource/ai/ai-employees/with-tools-merge/tools/discoveredTool.ts +23 -0
- package/src/__tests__/resource/ai/mcp/weather.ts +25 -0
- package/src/__tests__/resource/ai/skills/data-modeling/SKILLS.md +24 -0
- package/src/__tests__/resource/ai/skills/data-modeling/tools/read.ts +23 -0
- package/src/__tests__/resource/ai/skills/data-modeling/tools/search/description.md +1 -0
- package/src/__tests__/resource/ai/skills/data-modeling/tools/search/index.ts +23 -0
- package/src/__tests__/resource/ai/skills/document/tools/read.ts +1 -1
- package/src/__tests__/resource/ai/skills/document/tools/search/index.ts +1 -1
- package/src/__tests__/resource/ai/tools/desc/index.ts +1 -1
- package/src/__tests__/resource/ai/tools/group/group1.ts +1 -1
- package/src/__tests__/resource/ai/tools/group/group2.ts +1 -1
- package/src/__tests__/resource/ai/tools/group/group3/index.ts +1 -1
- package/src/__tests__/resource/ai/tools/hallow/index.ts +1 -1
- package/src/__tests__/resource/ai/tools/print.ts +1 -1
- package/src/__tests__/skills.test.ts +55 -0
- package/src/__tests__/tools.test.ts +5 -3
- package/src/ai-employee-manager/index.ts +148 -0
- package/src/ai-employee-manager/types.ts +63 -0
- package/src/ai-manager.ts +12 -0
- package/src/document-loader/index.ts +57 -0
- package/src/document-loader/loader.worker.ts +100 -0
- package/src/document-loader/vendor/langchain/document_loaders/fs/text.ts +72 -0
- package/src/document-loader/xlsx.ts +82 -0
- package/src/index.ts +5 -0
- package/src/loader/employee.ts +194 -0
- package/src/loader/index.ts +3 -0
- package/src/loader/mcp.ts +101 -0
- package/src/loader/skills.ts +129 -0
- package/src/loader/tools.ts +3 -2
- package/src/mcp-manager/index.ts +364 -0
- package/src/mcp-manager/types.ts +68 -0
- package/src/mcp-tools-manager.ts +90 -0
- package/src/skills-manager/index.ts +148 -0
- package/src/skills-manager/types.ts +38 -0
- package/src/tools-manager/index.ts +18 -7
- package/src/tools-manager/types.ts +13 -4
package/README.md
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
# NocoBase
|
|
2
2
|
|
|
3
3
|
<video width="100%" controls>
|
|
4
|
-
|
|
4
|
+
<source src="https://github.com/user-attachments/assets/4d11a87b-00e2-48f3-9bf7-389d21072d13" type="video/mp4">
|
|
5
5
|
</video>
|
|
6
6
|
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://trendshift.io/repositories/4112" target="_blank"><img src="https://trendshift.io/api/badge/repositories/4112" alt="nocobase%2Fnocobase | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
|
9
|
+
<a href="https://www.producthunt.com/posts/nocobase?embed=true&utm_source=badge-top-post-topic-badge&utm_medium=badge&utm_souce=badge-nocobase" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/top-post-topic-badge.svg?post_id=456520&theme=light&period=weekly&topic_id=267" alt="NocoBase - Scalability-first, open-source no-code platform | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
|
|
10
|
+
</p>
|
|
7
11
|
|
|
8
12
|
## What is NocoBase
|
|
9
13
|
|
|
10
|
-
NocoBase is
|
|
11
|
-
|
|
14
|
+
NocoBase is the most extensible AI-powered no-code platform.
|
|
15
|
+
Total control. Infinite extensibility. AI collaboration.
|
|
16
|
+
Enable your team to adapt quickly and cut costs dramatically.
|
|
17
|
+
No years of development. No millions wasted.
|
|
18
|
+
Deploy NocoBase in minutes — and take control of everything.
|
|
12
19
|
|
|
13
20
|
Homepage:
|
|
14
|
-
https://www.nocobase.com/
|
|
21
|
+
https://www.nocobase.com/
|
|
15
22
|
|
|
16
23
|
Online Demo:
|
|
17
24
|
https://demo.nocobase.com/new
|
|
@@ -19,12 +26,74 @@ https://demo.nocobase.com/new
|
|
|
19
26
|
Documents:
|
|
20
27
|
https://docs.nocobase.com/
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
https://
|
|
29
|
+
Forum:
|
|
30
|
+
https://forum.nocobase.com/
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
https://www.nocobase.com/en/
|
|
32
|
+
Use Cases:
|
|
33
|
+
https://www.nocobase.com/en/blog/tags/customer-stories
|
|
27
34
|
|
|
35
|
+
## Release Notes
|
|
28
36
|
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
Our [blog](https://www.nocobase.com/en/blog/timeline) is regularly updated with release notes and provides a weekly summary.
|
|
38
|
+
|
|
39
|
+
## Distinctive features
|
|
40
|
+
|
|
41
|
+
### 1. Data model-driven, not form/table–driven
|
|
42
|
+
|
|
43
|
+
Instead of being constrained by forms or tables, NocoBase adopts a data model–driven approach, separating data structure from user interface to unlock unlimited possibilities.
|
|
44
|
+
|
|
45
|
+
- UI and data structure are fully decoupled
|
|
46
|
+
- Multiple blocks and actions can be created for the same table or record in any quantity or form
|
|
47
|
+
- Supports the main database, external databases, and third-party APIs as data sources
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
### 2. AI employees, integrated into your business systems
|
|
52
|
+
Unlike standalone AI demos, NocoBase allows you to embed AI capabilities seamlessly into your interfaces, workflows, and data context, making AI truly useful in real business scenarios.
|
|
53
|
+
|
|
54
|
+
- Define AI employees for roles such as translator, analyst, researcher, or assistant
|
|
55
|
+
- Seamless AI–human collaboration in interfaces and workflows
|
|
56
|
+
- Ensure AI usage is secure, transparent, and customizable for your business needs
|
|
57
|
+
|
|
58
|
+

|
|
59
|
+
|
|
60
|
+
### 3. What you see is what you get, incredibly easy to use
|
|
61
|
+
|
|
62
|
+
While enabling the development of complex business systems, NocoBase keeps the experience simple and intuitive.
|
|
63
|
+
|
|
64
|
+
- One-click switch between usage mode and configuration mode
|
|
65
|
+
- Pages serve as a canvas to arrange blocks and actions, similar to Notion
|
|
66
|
+
- Configuration mode is designed for ordinary users, not just programmers
|
|
67
|
+
|
|
68
|
+

|
|
69
|
+
|
|
70
|
+
### 4. Everything is a plugin, designed for extension
|
|
71
|
+
Adding more no-code features will never cover every business case. NocoBase is built for extension through its plugin-based microkernel architecture.
|
|
72
|
+
|
|
73
|
+
- All functionalities are plugins, similar to WordPress
|
|
74
|
+
- Plugins are ready to use upon installation
|
|
75
|
+
- Pages, blocks, actions, APIs, and data sources can all be extended through custom plugins
|
|
76
|
+
|
|
77
|
+

|
|
78
|
+
|
|
79
|
+
## Installation
|
|
80
|
+
|
|
81
|
+
NocoBase supports three installation methods:
|
|
82
|
+
|
|
83
|
+
- <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/docker-compose">Installing With Docker (👍Recommended)</a>
|
|
84
|
+
|
|
85
|
+
Suitable for no-code scenarios, no code to write. When upgrading, just download the latest image and reboot.
|
|
86
|
+
|
|
87
|
+
- <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/create-nocobase-app">Installing from create-nocobase-app CLI</a>
|
|
88
|
+
|
|
89
|
+
The business code of the project is completely independent and supports low-code development.
|
|
90
|
+
|
|
91
|
+
- <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/git-clone">Installing from Git source code</a>
|
|
92
|
+
|
|
93
|
+
If you want to experience the latest unreleased version, or want to participate in the contribution, you need to make changes and debug on the source code, it is recommended to choose this installation method, which requires a high level of development skills, and if the code has been updated, you can git pull the latest code.
|
|
94
|
+
|
|
95
|
+
## How NocoBase works
|
|
96
|
+
|
|
97
|
+
<video width="100%" controls>
|
|
98
|
+
<source src="https://github.com/user-attachments/assets/8d183b44-9bb5-4792-b08f-bc08fe8dfaaf" type="video/mp4">
|
|
99
|
+
</video>
|
|
@@ -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 { AIEmployeeEntry, AIEmployeeFilter, AIEmployeeManager, AIEmployeeOptions } from './types';
|
|
10
|
+
export declare class DefaultAIEmployeeManager implements AIEmployeeManager {
|
|
11
|
+
private readonly app;
|
|
12
|
+
private readonly employees;
|
|
13
|
+
private readonly provideCollectionManager;
|
|
14
|
+
private mode;
|
|
15
|
+
constructor(app: any);
|
|
16
|
+
init(): Promise<void>;
|
|
17
|
+
getEmployee(username: string): Promise<AIEmployeeEntry>;
|
|
18
|
+
listEmployees(filter?: AIEmployeeFilter): Promise<AIEmployeeEntry[]>;
|
|
19
|
+
registerEmployee(options: AIEmployeeOptions): Promise<void>;
|
|
20
|
+
persistence(): Promise<void>;
|
|
21
|
+
private registerEmployeeInMemory;
|
|
22
|
+
private registerEmployeeInDatabase;
|
|
23
|
+
private get aiEmployeesCollection();
|
|
24
|
+
private get aiEmployeesModel();
|
|
25
|
+
private get sequelize();
|
|
26
|
+
private get collectionManager();
|
|
27
|
+
}
|
|
28
|
+
export declare function defineAIEmployee(options: AIEmployeeOptions): AIEmployeeOptions;
|
|
29
|
+
export * from './types';
|
|
@@ -0,0 +1,167 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var ai_employee_manager_exports = {};
|
|
30
|
+
__export(ai_employee_manager_exports, {
|
|
31
|
+
DefaultAIEmployeeManager: () => DefaultAIEmployeeManager,
|
|
32
|
+
defineAIEmployee: () => defineAIEmployee
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(ai_employee_manager_exports);
|
|
35
|
+
var import_database = require("@nocobase/database");
|
|
36
|
+
var import_utils = require("@nocobase/utils");
|
|
37
|
+
__reExport(ai_employee_manager_exports, require("./types"), module.exports);
|
|
38
|
+
const DEFAULT_KNOWLEDGE_BASE = {
|
|
39
|
+
topK: 3,
|
|
40
|
+
score: "0.6",
|
|
41
|
+
knowledgeBaseIds: []
|
|
42
|
+
};
|
|
43
|
+
const DEFAULT_KNOWLEDGE_BASE_PROMPT = "From knowledge base:\n{knowledgeBaseData}\nanswer user's question using this information.";
|
|
44
|
+
const _DefaultAIEmployeeManager = class _DefaultAIEmployeeManager {
|
|
45
|
+
constructor(app) {
|
|
46
|
+
this.app = app;
|
|
47
|
+
this.provideCollectionManager = () => app.mainDataSource;
|
|
48
|
+
}
|
|
49
|
+
employees = new import_utils.Registry();
|
|
50
|
+
provideCollectionManager;
|
|
51
|
+
mode = "memory";
|
|
52
|
+
async init() {
|
|
53
|
+
if (this.mode === "memory") {
|
|
54
|
+
await this.persistence();
|
|
55
|
+
this.mode = "database";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async getEmployee(username) {
|
|
59
|
+
var _a;
|
|
60
|
+
return (_a = await this.aiEmployeesModel.findOne({ where: { username } })) == null ? void 0 : _a.toJSON();
|
|
61
|
+
}
|
|
62
|
+
async listEmployees(filter = {}) {
|
|
63
|
+
const where = {};
|
|
64
|
+
if (filter.builtIn != null) {
|
|
65
|
+
where["builtIn"] = filter.builtIn;
|
|
66
|
+
}
|
|
67
|
+
if (filter.username) {
|
|
68
|
+
where["username"] = {
|
|
69
|
+
[import_database.Op.substring]: filter.username
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return (await this.aiEmployeesModel.findAll({ where })).map((it) => it.toJSON());
|
|
73
|
+
}
|
|
74
|
+
async registerEmployee(options) {
|
|
75
|
+
if (this.mode === "memory") {
|
|
76
|
+
return this.registerEmployeeInMemory(options);
|
|
77
|
+
}
|
|
78
|
+
return this.registerEmployeeInDatabase(options);
|
|
79
|
+
}
|
|
80
|
+
async persistence() {
|
|
81
|
+
const employees = [...this.employees.getValues()];
|
|
82
|
+
for (const employee of employees) {
|
|
83
|
+
await this.registerEmployeeInDatabase(employee);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
registerEmployeeInMemory(options) {
|
|
87
|
+
this.employees.register(options.username, options);
|
|
88
|
+
}
|
|
89
|
+
async registerEmployeeInDatabase(options) {
|
|
90
|
+
const employee = options;
|
|
91
|
+
await this.sequelize.transaction(async (transaction) => {
|
|
92
|
+
const existed = await this.aiEmployeesModel.findOne({ where: { username: employee.username }, transaction });
|
|
93
|
+
if (!existed) {
|
|
94
|
+
await this.aiEmployeesModel.create(
|
|
95
|
+
{
|
|
96
|
+
username: employee.username,
|
|
97
|
+
nickname: employee.nickname,
|
|
98
|
+
position: employee.position,
|
|
99
|
+
avatar: employee.avatar,
|
|
100
|
+
bio: employee.bio,
|
|
101
|
+
greeting: employee.greeting,
|
|
102
|
+
about: null,
|
|
103
|
+
defaultPrompt: employee.systemPrompt,
|
|
104
|
+
skillSettings: {
|
|
105
|
+
skills: employee.skills,
|
|
106
|
+
tools: employee.tools
|
|
107
|
+
},
|
|
108
|
+
enableKnowledgeBase: false,
|
|
109
|
+
knowledgeBase: DEFAULT_KNOWLEDGE_BASE,
|
|
110
|
+
knowledgeBasePrompt: DEFAULT_KNOWLEDGE_BASE_PROMPT,
|
|
111
|
+
enabled: true,
|
|
112
|
+
builtIn: true,
|
|
113
|
+
sort: employee.sort
|
|
114
|
+
},
|
|
115
|
+
{ transaction }
|
|
116
|
+
);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const current = existed.toJSON();
|
|
120
|
+
let { tools } = (current == null ? void 0 : current.skillSettings) ?? { tools: [] };
|
|
121
|
+
tools = (tools == null ? void 0 : tools.length) ? tools.filter((s) => {
|
|
122
|
+
var _a;
|
|
123
|
+
return (_a = s.name) == null ? void 0 : _a.startsWith("workflowCaller-");
|
|
124
|
+
}) : [];
|
|
125
|
+
const mergedTools = /* @__PURE__ */ new Set([...tools, ...employee.tools]);
|
|
126
|
+
const values = {
|
|
127
|
+
nickname: employee.nickname ?? current.nickname,
|
|
128
|
+
position: employee.position ?? current.position,
|
|
129
|
+
avatar: employee.avatar ?? current.avatar,
|
|
130
|
+
bio: employee.bio ?? current.bio,
|
|
131
|
+
greeting: employee.greeting ?? current.greeting,
|
|
132
|
+
defaultPrompt: employee.systemPrompt,
|
|
133
|
+
skillSettings: {
|
|
134
|
+
skills: [...employee.skills],
|
|
135
|
+
tools: [...mergedTools]
|
|
136
|
+
},
|
|
137
|
+
sort: employee.sort
|
|
138
|
+
};
|
|
139
|
+
await existed.update(values, { transaction });
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
get aiEmployeesCollection() {
|
|
143
|
+
return this.collectionManager.getCollection("aiEmployees");
|
|
144
|
+
}
|
|
145
|
+
get aiEmployeesModel() {
|
|
146
|
+
var _a;
|
|
147
|
+
return (_a = this.aiEmployeesCollection) == null ? void 0 : _a.model;
|
|
148
|
+
}
|
|
149
|
+
get sequelize() {
|
|
150
|
+
return this.collectionManager.db.sequelize;
|
|
151
|
+
}
|
|
152
|
+
get collectionManager() {
|
|
153
|
+
return this.provideCollectionManager().collectionManager;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
__name(_DefaultAIEmployeeManager, "DefaultAIEmployeeManager");
|
|
157
|
+
let DefaultAIEmployeeManager = _DefaultAIEmployeeManager;
|
|
158
|
+
function defineAIEmployee(options) {
|
|
159
|
+
return options;
|
|
160
|
+
}
|
|
161
|
+
__name(defineAIEmployee, "defineAIEmployee");
|
|
162
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
163
|
+
0 && (module.exports = {
|
|
164
|
+
DefaultAIEmployeeManager,
|
|
165
|
+
defineAIEmployee,
|
|
166
|
+
...require("./types")
|
|
167
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
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 AIEmployeeLocalizedProfile = {
|
|
10
|
+
avatar?: string;
|
|
11
|
+
nickname?: string;
|
|
12
|
+
position?: string;
|
|
13
|
+
bio?: string;
|
|
14
|
+
greeting?: string;
|
|
15
|
+
about?: string;
|
|
16
|
+
};
|
|
17
|
+
export type AIEmployeeKnowledgeBase = {
|
|
18
|
+
topK: number;
|
|
19
|
+
score: string;
|
|
20
|
+
knowledgeBaseIds: string[];
|
|
21
|
+
};
|
|
22
|
+
export type AIEmployeeToolSetting = {
|
|
23
|
+
name: string;
|
|
24
|
+
autoCall?: boolean;
|
|
25
|
+
};
|
|
26
|
+
export type AIEmployeeOptions = {
|
|
27
|
+
username: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
skills?: string[];
|
|
30
|
+
tools?: AIEmployeeToolSetting[];
|
|
31
|
+
avatar?: string;
|
|
32
|
+
nickname?: string;
|
|
33
|
+
position?: string;
|
|
34
|
+
bio?: string;
|
|
35
|
+
greeting?: string;
|
|
36
|
+
systemPrompt?: string | null;
|
|
37
|
+
sort?: number;
|
|
38
|
+
};
|
|
39
|
+
export type AIEmployeeEntry = Omit<AIEmployeeOptions, 'skills' | 'tools' | 'systemPrompt'> & {
|
|
40
|
+
about?: string;
|
|
41
|
+
defaultPrompt?: string;
|
|
42
|
+
skillSettings: {
|
|
43
|
+
skills: string[];
|
|
44
|
+
tools: AIEmployeeToolSetting[];
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export type AIEmployeeFilter = {
|
|
48
|
+
builtIn?: boolean;
|
|
49
|
+
username?: string;
|
|
50
|
+
};
|
|
51
|
+
export interface AIEmployeeManager {
|
|
52
|
+
init(): Promise<void>;
|
|
53
|
+
getEmployee(username: string): Promise<AIEmployeeEntry>;
|
|
54
|
+
listEmployees(filter?: AIEmployeeFilter): Promise<AIEmployeeEntry[]>;
|
|
55
|
+
registerEmployee(options: AIEmployeeOptions): Promise<void>;
|
|
56
|
+
}
|
|
@@ -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/lib/ai-manager.d.ts
CHANGED
|
@@ -8,9 +8,17 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { DocumentManager } from './document-manager';
|
|
10
10
|
import { ToolsManager } from './tools-manager';
|
|
11
|
+
import { SkillsManager } from './skills-manager';
|
|
12
|
+
import { AIEmployeeManager } from './ai-employee-manager';
|
|
13
|
+
import { MCPManager } from './mcp-manager';
|
|
14
|
+
import { McpToolsManager } from './mcp-tools-manager';
|
|
11
15
|
export declare class AIManager {
|
|
12
16
|
protected readonly app: any;
|
|
13
17
|
documentManager: DocumentManager;
|
|
14
18
|
toolsManager: ToolsManager;
|
|
19
|
+
skillsManager: SkillsManager;
|
|
20
|
+
employeeManager: AIEmployeeManager;
|
|
21
|
+
mcpManager: MCPManager;
|
|
22
|
+
mcpToolsManager: McpToolsManager;
|
|
15
23
|
constructor(app: any);
|
|
16
24
|
}
|
package/lib/ai-manager.js
CHANGED
|
@@ -32,14 +32,26 @@ __export(ai_manager_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(ai_manager_exports);
|
|
33
33
|
var import_document_manager = require("./document-manager");
|
|
34
34
|
var import_tools_manager = require("./tools-manager");
|
|
35
|
+
var import_skills_manager = require("./skills-manager");
|
|
36
|
+
var import_ai_employee_manager = require("./ai-employee-manager");
|
|
37
|
+
var import_mcp_manager = require("./mcp-manager");
|
|
38
|
+
var import_mcp_tools_manager = require("./mcp-tools-manager");
|
|
35
39
|
const _AIManager = class _AIManager {
|
|
36
40
|
constructor(app) {
|
|
37
41
|
this.app = app;
|
|
38
42
|
this.documentManager = new import_document_manager.DocumentManager();
|
|
39
43
|
this.toolsManager = new import_tools_manager.DefaultToolsManager();
|
|
44
|
+
this.skillsManager = new import_skills_manager.DefaultSkillsManager(app);
|
|
45
|
+
this.employeeManager = new import_ai_employee_manager.DefaultAIEmployeeManager(app);
|
|
46
|
+
this.mcpManager = new import_mcp_manager.DefaultMCPManager(app);
|
|
47
|
+
this.mcpToolsManager = new import_mcp_tools_manager.McpToolsManager();
|
|
40
48
|
}
|
|
41
49
|
documentManager;
|
|
42
50
|
toolsManager;
|
|
51
|
+
skillsManager;
|
|
52
|
+
employeeManager;
|
|
53
|
+
mcpManager;
|
|
54
|
+
mcpToolsManager;
|
|
43
55
|
};
|
|
44
56
|
__name(_AIManager, "AIManager");
|
|
45
57
|
let AIManager = _AIManager;
|
|
@@ -0,0 +1,10 @@
|
|
|
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 } from '@langchain/core/documents';
|
|
10
|
+
export declare const loadByWorker: (extname: string, blob: Blob) => Promise<Document[]>;
|
|
@@ -0,0 +1,90 @@
|
|
|
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 document_loader_exports = {};
|
|
39
|
+
__export(document_loader_exports, {
|
|
40
|
+
loadByWorker: () => loadByWorker
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(document_loader_exports);
|
|
43
|
+
var import_node_worker_threads = require("node:worker_threads");
|
|
44
|
+
var import_node_path = __toESM(require("node:path"));
|
|
45
|
+
const loadByWorker = /* @__PURE__ */ __name(async (extname, blob) => {
|
|
46
|
+
const buffer = Buffer.from(await blob.arrayBuffer());
|
|
47
|
+
const isTsRuntime = __filename.endsWith(".ts");
|
|
48
|
+
const workerPath = import_node_path.default.join(__dirname, `loader.worker.${isTsRuntime ? "ts" : "js"}`);
|
|
49
|
+
const worker = new import_node_worker_threads.Worker(workerPath, {
|
|
50
|
+
execArgv: isTsRuntime ? ["--require", "tsx/cjs"] : void 0
|
|
51
|
+
});
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
let settled = false;
|
|
54
|
+
const close = /* @__PURE__ */ __name((error, result) => {
|
|
55
|
+
if (settled) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
settled = true;
|
|
59
|
+
if (error) {
|
|
60
|
+
reject(error);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
resolve(result || []);
|
|
64
|
+
}, "close");
|
|
65
|
+
worker.once("message", (payload) => {
|
|
66
|
+
if (payload == null ? void 0 : payload.error) {
|
|
67
|
+
close(new Error(payload.error));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
close(void 0, (payload == null ? void 0 : payload.documents) || []);
|
|
71
|
+
});
|
|
72
|
+
worker.once("error", (error) => close(error));
|
|
73
|
+
worker.once("exit", (code) => {
|
|
74
|
+
if (!settled && code !== 0) {
|
|
75
|
+
close(new Error(`Document loader worker exited with code ${code}`));
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
worker.postMessage({
|
|
79
|
+
extname,
|
|
80
|
+
mimeType: blob.type,
|
|
81
|
+
buffer: Uint8Array.from(buffer)
|
|
82
|
+
});
|
|
83
|
+
}).finally(() => {
|
|
84
|
+
worker.terminate().catch(() => void 0);
|
|
85
|
+
});
|
|
86
|
+
}, "loadByWorker");
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
loadByWorker
|
|
90
|
+
});
|
|
@@ -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 {};
|
|
@@ -0,0 +1,83 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
var import_pdf = require("@langchain/community/document_loaders/fs/pdf");
|
|
13
|
+
var import_pptx = require("@langchain/community/document_loaders/fs/pptx");
|
|
14
|
+
var import_docx = require("@langchain/community/document_loaders/fs/docx");
|
|
15
|
+
var import_node_worker_threads = require("node:worker_threads");
|
|
16
|
+
var import_text = require("./vendor/langchain/document_loaders/fs/text");
|
|
17
|
+
var import_csv = require("@langchain/community/document_loaders/fs/csv");
|
|
18
|
+
var import_xlsx = require("./xlsx");
|
|
19
|
+
var _a;
|
|
20
|
+
const loadPdf = /* @__PURE__ */ __name(async (blob) => {
|
|
21
|
+
const loader = new import_pdf.PDFLoader(blob);
|
|
22
|
+
return loader.load();
|
|
23
|
+
}, "loadPdf");
|
|
24
|
+
const loadDoc = /* @__PURE__ */ __name(async (blob, type) => {
|
|
25
|
+
const loader = new import_docx.DocxLoader(blob, { type });
|
|
26
|
+
return loader.load();
|
|
27
|
+
}, "loadDoc");
|
|
28
|
+
const loadPpt = /* @__PURE__ */ __name(async (blob) => {
|
|
29
|
+
const loader = new import_pptx.PPTXLoader(blob);
|
|
30
|
+
return loader.load();
|
|
31
|
+
}, "loadPpt");
|
|
32
|
+
const loadTxt = /* @__PURE__ */ __name(async (blob) => {
|
|
33
|
+
const loader = new import_text.TextLoader(blob);
|
|
34
|
+
return loader.load();
|
|
35
|
+
}, "loadTxt");
|
|
36
|
+
const loadCsv = /* @__PURE__ */ __name(async (blob) => {
|
|
37
|
+
const loader = new import_csv.CSVLoader(blob);
|
|
38
|
+
return loader.load();
|
|
39
|
+
}, "loadCsv");
|
|
40
|
+
const loadByExtname = /* @__PURE__ */ __name(async (payload) => {
|
|
41
|
+
const blob = new Blob([Buffer.from(payload.buffer)], { type: payload.mimeType ?? "application/octet-stream" });
|
|
42
|
+
switch (payload.extname) {
|
|
43
|
+
case ".pdf":
|
|
44
|
+
return loadPdf(blob);
|
|
45
|
+
case ".ppt":
|
|
46
|
+
case ".pptx":
|
|
47
|
+
return loadPpt(blob);
|
|
48
|
+
case ".doc":
|
|
49
|
+
return loadDoc(blob, "doc");
|
|
50
|
+
case ".docx":
|
|
51
|
+
return loadDoc(blob, "docx");
|
|
52
|
+
case ".csv":
|
|
53
|
+
return loadCsv(blob);
|
|
54
|
+
case ".xls":
|
|
55
|
+
case ".xlsx":
|
|
56
|
+
return (0, import_xlsx.loadXlsx)(blob);
|
|
57
|
+
case ".json":
|
|
58
|
+
case ".md":
|
|
59
|
+
case ".txt":
|
|
60
|
+
return loadTxt(blob);
|
|
61
|
+
default:
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
}, "loadByExtname");
|
|
65
|
+
(_a = import_node_worker_threads.parentPort) == null ? void 0 : _a.on("message", async (payload) => {
|
|
66
|
+
var _a2, _b;
|
|
67
|
+
try {
|
|
68
|
+
const documents = await loadByExtname(payload);
|
|
69
|
+
const response = {
|
|
70
|
+
documents: documents.map((doc) => ({
|
|
71
|
+
pageContent: doc.pageContent,
|
|
72
|
+
metadata: doc.metadata,
|
|
73
|
+
id: doc.id
|
|
74
|
+
}))
|
|
75
|
+
};
|
|
76
|
+
(_a2 = import_node_worker_threads.parentPort) == null ? void 0 : _a2.postMessage(response);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
const response = {
|
|
79
|
+
error: String((error == null ? void 0 : error.stack) || error)
|
|
80
|
+
};
|
|
81
|
+
(_b = import_node_worker_threads.parentPort) == null ? void 0 : _b.postMessage(response);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
/// <reference types="node" />
|
|
10
|
+
import { Document } from '@langchain/core/documents';
|
|
11
|
+
import { BaseDocumentLoader } from '@langchain/core/document_loaders/base';
|
|
12
|
+
export declare class TextLoader extends BaseDocumentLoader {
|
|
13
|
+
private filePathOrBlob;
|
|
14
|
+
constructor(filePathOrBlob: any);
|
|
15
|
+
parse(raw: any): Promise<any[]>;
|
|
16
|
+
load(): Promise<Document<any>[]>;
|
|
17
|
+
static imports(): Promise<{
|
|
18
|
+
readFile: typeof import("fs/promises").readFile;
|
|
19
|
+
}>;
|
|
20
|
+
}
|