@nocobase/plugin-ai 2.1.0-beta.30 → 2.1.0-beta.32
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/client-v2.d.ts +1 -0
- package/client-v2.js +1 -0
- package/dist/ai/docs/nocobase/ai/index.md +1 -1
- package/dist/ai/docs/nocobase/ai-employees/built-in/atlas.md +24 -0
- package/dist/ai/docs/nocobase/ai-employees/built-in/dara.md +22 -0
- package/dist/ai/docs/nocobase/ai-employees/built-in/dex.md +32 -0
- package/dist/ai/docs/nocobase/ai-employees/built-in/ellis.md +22 -0
- package/dist/ai/docs/nocobase/ai-employees/built-in/index.md +25 -0
- package/dist/ai/docs/nocobase/ai-employees/built-in/lexi.md +26 -0
- package/dist/ai/docs/nocobase/ai-employees/built-in/lina.md +142 -0
- package/dist/ai/docs/nocobase/ai-employees/built-in/nathan.md +36 -0
- package/dist/ai/docs/nocobase/ai-employees/built-in/vera.md +22 -0
- package/dist/ai/docs/nocobase/ai-employees/built-in/viz.md +25 -0
- package/dist/ai/docs/nocobase/ai-employees/features/built-in-employee.md +1 -29
- package/dist/ai/docs/nocobase/ai-employees/features/collaborate.md +17 -7
- package/dist/ai/docs/nocobase/ai-employees/features/enable-ai-employee.md +4 -4
- package/dist/ai/docs/nocobase/ai-employees/features/model-settings.md +87 -0
- package/dist/ai/docs/nocobase/ai-employees/index.md +1 -1
- package/dist/ai/docs/nocobase/ai-employees/scenarios/localization-hy-mt.md +241 -0
- package/dist/ai/docs/nocobase/ai-employees/workflow/nodes/employee/configuration.md +1 -1
- package/dist/ai/docs/nocobase/interface-builder/actions/types/js-action.md +1 -1
- package/dist/ai/docs/nocobase/interface-builder/actions/types/js-item.md +1 -1
- package/dist/ai/docs/nocobase/interface-builder/blocks/other-blocks/js-block.md +1 -1
- package/dist/ai/docs/nocobase/interface-builder/fields/specific/js-column.md +1 -1
- package/dist/ai/docs/nocobase/interface-builder/fields/specific/js-field.md +1 -1
- package/dist/ai/docs/nocobase/interface-builder/fields/specific/js-item.md +1 -1
- package/dist/ai/docs/nocobase/security/guide.md +13 -1
- package/dist/ai/docs/nocobase/system-management/localization/index.md +25 -1
- package/dist/client/462.1708385b148779cd.js +10 -0
- package/dist/client/{559.39872901b9053629.js → 559.585f80c3bcea0bed.js} +1 -1
- package/dist/client/646.b0ed728921b007d4.js +10 -0
- package/dist/client/{927.ac9ee9a8c1cb4f1d.js → 927.d95c74ebb8fd51c9.js} +1 -1
- package/dist/client/ai-employees/admin/ModelSettings.d.ts +10 -0
- package/dist/client/ai-employees/admin/hooks.d.ts +1 -1
- package/dist/client/ai-employees/avatars.d.ts +9 -783
- package/dist/client/ai-employees/chatbox/model.d.ts +6 -3
- package/dist/client/ai-employees/types.d.ts +23 -0
- package/dist/client/features/vector-database-provider.d.ts +1 -1
- package/dist/client/index.js +4 -4
- package/dist/client/llm-services/component/EnabledModelsSelect.d.ts +1 -14
- package/dist/client-v2/ai-employees/AIEmployeeShortcut.d.ts +21 -0
- package/dist/client-v2/ai-employees/ProfileCard.d.ts +17 -0
- package/dist/client-v2/ai-employees/avatars.d.ts +783 -0
- package/dist/client-v2/ai-employees/types.d.ts +20 -0
- package/dist/client-v2/index.d.ts +17 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/client-v2/llm-services/model-label.d.ts +22 -0
- package/dist/collections/ai-employees.d.ts +2 -1
- package/dist/collections/ai-employees.js +1 -1
- package/dist/externalVersion.js +17 -17
- package/dist/locale/en-US.json +15 -1
- package/dist/locale/zh-CN.json +15 -1
- package/dist/node_modules/@langchain/xai/package.json +1 -1
- package/dist/node_modules/fs-extra/package.json +1 -1
- package/dist/node_modules/jsonrepair/package.json +1 -1
- package/dist/node_modules/just-bash/package.json +1 -1
- package/dist/node_modules/nodejs-snowflake/package.json +1 -1
- package/dist/node_modules/openai/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/ai-employees/ai-conversations.d.ts +1 -0
- package/dist/server/ai-employees/ai-conversations.js +4 -1
- package/dist/server/ai-employees/ai-employee.d.ts +15 -1
- package/dist/server/ai-employees/ai-employee.js +140 -9
- package/dist/server/ai-employees/ai-employees-manager.d.ts +4 -0
- package/dist/server/ai-employees/ai-employees-manager.js +41 -0
- package/dist/server/ai-employees/ai-knowledge-base.js +7 -7
- package/dist/server/ai-employees/middleware/conversation.d.ts +1 -0
- package/dist/server/ai-employees/middleware/conversation.js +4 -2
- package/dist/server/ai-employees/sub-agents/dispatcher.js +2 -4
- package/dist/server/ai-employees/utils.d.ts +6 -3
- package/dist/server/ai-employees/utils.js +7 -1
- package/dist/server/features/knowledge-base.d.ts +3 -2
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +3 -0
- package/dist/server/llm-providers/common/reasoning.d.ts +2 -0
- package/dist/server/llm-providers/common/reasoning.js +15 -2
- package/dist/server/llm-providers/dashscope.d.ts +2 -1
- package/dist/server/llm-providers/dashscope.js +39 -0
- package/dist/server/llm-providers/deepseek.js +2 -0
- package/dist/server/llm-providers/provider.d.ts +15 -1
- package/dist/server/llm-providers/provider.js +21 -2
- package/dist/server/manager/ai-chat-conversation.js +3 -4
- package/dist/server/manager/ai-manager.d.ts +17 -0
- package/dist/server/manager/ai-manager.js +65 -0
- package/dist/server/migrations/20260407170416-ai-employee-knowledge-base-add-key.d.ts +14 -0
- package/dist/server/migrations/20260407170416-ai-employee-knowledge-base-add-key.js +61 -0
- package/dist/server/resource/ai.js +1 -41
- package/dist/server/resource/aiConversations.js +12 -8
- package/dist/server/resource/aiEmployees.js +32 -1
- package/dist/server/types/knowledge-base.type.d.ts +3 -2
- package/dist/server/workflow/nodes/employee/index.js +4 -2
- package/package.json +2 -2
- package/dist/client/343.6f36d97dd122c5b6.js +0 -10
- package/dist/client/646.5860101cb28c8272.js +0 -10
package/dist/server/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export { LLMProvider, LLMProviderOptions } from './llm-providers/provider';
|
|
|
11
11
|
export { LLMProviderMeta } from './manager/ai-manager';
|
|
12
12
|
export { ToolOptions } from './manager/tool-manager';
|
|
13
13
|
export { DocumentLoader } from './document-loader';
|
|
14
|
+
export { AIEmployee } from './ai-employees/ai-employee';
|
|
15
|
+
export type { AIEmployeeOptions, ModelRef } from './ai-employees/ai-employee';
|
|
14
16
|
export type { ParsedDocumentResult, ParseableFile, DocumentParseMeta } from './document-loader';
|
|
15
17
|
export type * from './features';
|
|
16
18
|
export type * from './types';
|
package/dist/server/index.js
CHANGED
|
@@ -36,6 +36,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
37
|
var server_exports = {};
|
|
38
38
|
__export(server_exports, {
|
|
39
|
+
AIEmployee: () => import_ai_employee.AIEmployee,
|
|
39
40
|
DocumentLoader: () => import_document_loader.DocumentLoader,
|
|
40
41
|
LLMProvider: () => import_provider.LLMProvider,
|
|
41
42
|
LLMProviderMeta: () => import_ai_manager.LLMProviderMeta,
|
|
@@ -49,8 +50,10 @@ var import_provider = require("./llm-providers/provider");
|
|
|
49
50
|
var import_ai_manager = require("./manager/ai-manager");
|
|
50
51
|
var import_tool_manager = require("./manager/tool-manager");
|
|
51
52
|
var import_document_loader = require("./document-loader");
|
|
53
|
+
var import_ai_employee = require("./ai-employees/ai-employee");
|
|
52
54
|
// Annotate the CommonJS export names for ESM import in node:
|
|
53
55
|
0 && (module.exports = {
|
|
56
|
+
AIEmployee,
|
|
54
57
|
DocumentLoader,
|
|
55
58
|
LLMProvider,
|
|
56
59
|
LLMProviderMeta,
|
|
@@ -10,8 +10,10 @@ import { BaseMessage } from '@langchain/core/messages';
|
|
|
10
10
|
import { ChatOpenAICompletions } from '@langchain/openai';
|
|
11
11
|
import type OpenAI from 'openai';
|
|
12
12
|
export declare const REASONING_MAP_KEY = "__nb_reasoning_map";
|
|
13
|
+
export declare const MODEL_KWARGS_KEY = "__nb_model_kwargs";
|
|
13
14
|
export declare const collectReasoningMap: (messages: BaseMessage[]) => Map<string, string>;
|
|
14
15
|
export declare const patchRequestMessagesReasoning: (request: any, reasoningMap?: Map<string, string>) => void;
|
|
16
|
+
export declare const patchRequestModelKwargs: (request: any, modelKwargs?: Record<string, any>) => void;
|
|
15
17
|
export declare class ReasoningChatOpenAI extends ChatOpenAICompletions {
|
|
16
18
|
_generate(messages: BaseMessage[], options: any, runManager?: any): Promise<import("@langchain/core/dist/outputs").ChatResult>;
|
|
17
19
|
_streamResponseChunks(messages: BaseMessage[], options: any, runManager?: any): AsyncGenerator<import("@langchain/core/dist/outputs").ChatGenerationChunk, void, unknown>;
|
|
@@ -26,15 +26,18 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
26
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
27
|
var reasoning_exports = {};
|
|
28
28
|
__export(reasoning_exports, {
|
|
29
|
+
MODEL_KWARGS_KEY: () => MODEL_KWARGS_KEY,
|
|
29
30
|
REASONING_MAP_KEY: () => REASONING_MAP_KEY,
|
|
30
31
|
ReasoningChatOpenAI: () => ReasoningChatOpenAI,
|
|
31
32
|
collectReasoningMap: () => collectReasoningMap,
|
|
32
|
-
patchRequestMessagesReasoning: () => patchRequestMessagesReasoning
|
|
33
|
+
patchRequestMessagesReasoning: () => patchRequestMessagesReasoning,
|
|
34
|
+
patchRequestModelKwargs: () => patchRequestModelKwargs
|
|
33
35
|
});
|
|
34
36
|
module.exports = __toCommonJS(reasoning_exports);
|
|
35
37
|
var import_messages = require("@langchain/core/messages");
|
|
36
38
|
var import_openai = require("@langchain/openai");
|
|
37
39
|
const REASONING_MAP_KEY = "__nb_reasoning_map";
|
|
40
|
+
const MODEL_KWARGS_KEY = "__nb_model_kwargs";
|
|
38
41
|
const collectReasoningMap = (messages) => {
|
|
39
42
|
var _a;
|
|
40
43
|
const reasoningMap = /* @__PURE__ */ new Map();
|
|
@@ -69,6 +72,12 @@ const patchRequestMessagesReasoning = (request, reasoningMap) => {
|
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
74
|
};
|
|
75
|
+
const patchRequestModelKwargs = (request, modelKwargs) => {
|
|
76
|
+
if (!modelKwargs || typeof modelKwargs !== "object") {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
Object.assign(request, modelKwargs);
|
|
80
|
+
};
|
|
72
81
|
class ReasoningChatOpenAI extends import_openai.ChatOpenAICompletions {
|
|
73
82
|
async _generate(messages, options, runManager) {
|
|
74
83
|
const reasoningMap = collectReasoningMap(messages);
|
|
@@ -108,7 +117,9 @@ class ReasoningChatOpenAI extends import_openai.ChatOpenAICompletions {
|
|
|
108
117
|
}
|
|
109
118
|
async completionWithRetry(request, requestOptions) {
|
|
110
119
|
const reasoningMap = requestOptions == null ? void 0 : requestOptions[REASONING_MAP_KEY];
|
|
120
|
+
const modelKwargs = requestOptions == null ? void 0 : requestOptions[MODEL_KWARGS_KEY];
|
|
111
121
|
patchRequestMessagesReasoning(request, reasoningMap);
|
|
122
|
+
patchRequestModelKwargs(request, modelKwargs);
|
|
112
123
|
if (request.stream) {
|
|
113
124
|
return super.completionWithRetry(request, requestOptions);
|
|
114
125
|
}
|
|
@@ -117,8 +128,10 @@ class ReasoningChatOpenAI extends import_openai.ChatOpenAICompletions {
|
|
|
117
128
|
}
|
|
118
129
|
// Annotate the CommonJS export names for ESM import in node:
|
|
119
130
|
0 && (module.exports = {
|
|
131
|
+
MODEL_KWARGS_KEY,
|
|
120
132
|
REASONING_MAP_KEY,
|
|
121
133
|
ReasoningChatOpenAI,
|
|
122
134
|
collectReasoningMap,
|
|
123
|
-
patchRequestMessagesReasoning
|
|
135
|
+
patchRequestMessagesReasoning,
|
|
136
|
+
patchRequestModelKwargs
|
|
124
137
|
});
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { AIMessageChunk } from '@langchain/core/messages';
|
|
10
|
-
import { EmbeddingProvider, LLMProvider } from './provider';
|
|
10
|
+
import { EmbeddingProvider, LLMModelRequestBuilder, LLMProvider } from './provider';
|
|
11
11
|
import { EmbeddingsInterface } from '@langchain/core/embeddings';
|
|
12
12
|
import { SupportedModel } from '../manager/ai-manager';
|
|
13
13
|
import { Model } from '@nocobase/database';
|
|
@@ -19,6 +19,7 @@ export declare class DashscopeProvider extends LLMProvider {
|
|
|
19
19
|
createModel(): ReasoningChatOpenAI;
|
|
20
20
|
isToolConflict(): boolean;
|
|
21
21
|
resolveTools(toolDefinitions: any[]): any[];
|
|
22
|
+
protected getModelRequestBuilder(model?: string): LLMModelRequestBuilder | null;
|
|
22
23
|
parseResponseMessage(message: Model): {
|
|
23
24
|
key: any;
|
|
24
25
|
createdAt: any;
|
|
@@ -41,6 +41,7 @@ __export(dashscope_exports, {
|
|
|
41
41
|
dashscopeProviderOptions: () => dashscopeProviderOptions
|
|
42
42
|
});
|
|
43
43
|
module.exports = __toCommonJS(dashscope_exports);
|
|
44
|
+
var import_messages = require("@langchain/core/messages");
|
|
44
45
|
var import_openai = require("@langchain/openai");
|
|
45
46
|
var import_provider = require("./provider");
|
|
46
47
|
var import_ai_manager = require("../manager/ai-manager");
|
|
@@ -94,6 +95,44 @@ class DashscopeProvider extends import_provider.LLMProvider {
|
|
|
94
95
|
return toolDefinitions;
|
|
95
96
|
}
|
|
96
97
|
}
|
|
98
|
+
getModelRequestBuilder(model) {
|
|
99
|
+
if (!/^qwen-mt-/i.test(model || "")) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
return ({ context, options }) => {
|
|
103
|
+
var _a, _b;
|
|
104
|
+
const { sourceText, sourceLang, targetLang, terms } = (options == null ? void 0 : options.modelRequestParams) || {};
|
|
105
|
+
if (!sourceText || !sourceLang || !targetLang) {
|
|
106
|
+
return {
|
|
107
|
+
context,
|
|
108
|
+
options
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
(_b = this.app.logger) == null ? void 0 : _b.debug("Dashscope Qwen-MT model request builder matched", {
|
|
112
|
+
model: (_a = this.modelOptions) == null ? void 0 : _a.model,
|
|
113
|
+
sourceTextLength: (sourceText == null ? void 0 : sourceText.length) ?? 0,
|
|
114
|
+
sourceLang,
|
|
115
|
+
targetLang,
|
|
116
|
+
terms: Array.isArray(terms) ? terms.length : 0
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
context: {
|
|
120
|
+
messages: [new import_messages.HumanMessage(sourceText)]
|
|
121
|
+
},
|
|
122
|
+
options: {
|
|
123
|
+
...options,
|
|
124
|
+
modelKwargs: {
|
|
125
|
+
...(options == null ? void 0 : options.modelKwargs) || {},
|
|
126
|
+
translation_options: {
|
|
127
|
+
source_lang: sourceLang,
|
|
128
|
+
target_lang: targetLang,
|
|
129
|
+
...Array.isArray(terms) && terms.length ? { terms } : {}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
}
|
|
97
136
|
parseResponseMessage(message) {
|
|
98
137
|
var _a;
|
|
99
138
|
const result = super.parseResponseMessage(message);
|
|
@@ -64,7 +64,9 @@ class ReasoningDeepSeek extends import_deepseek.ChatDeepSeek {
|
|
|
64
64
|
}
|
|
65
65
|
async completionWithRetry(request, requestOptions) {
|
|
66
66
|
const reasoningMap = requestOptions == null ? void 0 : requestOptions[import_reasoning.REASONING_MAP_KEY];
|
|
67
|
+
const modelKwargs = requestOptions == null ? void 0 : requestOptions[import_reasoning.MODEL_KWARGS_KEY];
|
|
67
68
|
(0, import_reasoning.patchRequestMessagesReasoning)(request, reasoningMap);
|
|
69
|
+
(0, import_reasoning.patchRequestModelKwargs)(request, modelKwargs);
|
|
68
70
|
if (request.stream) {
|
|
69
71
|
return super.completionWithRetry(request, requestOptions);
|
|
70
72
|
}
|
|
@@ -22,6 +22,19 @@ export type ParsedAttachmentResult = {
|
|
|
22
22
|
placement: string;
|
|
23
23
|
content: any;
|
|
24
24
|
};
|
|
25
|
+
export type LLMProviderInvokeOptions = {
|
|
26
|
+
modelKwargs?: Record<string, any>;
|
|
27
|
+
modelRequestParams?: Record<string, any>;
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
};
|
|
30
|
+
export type LLMModelRequestBuilderResult = {
|
|
31
|
+
context: AIChatContext;
|
|
32
|
+
options?: LLMProviderInvokeOptions;
|
|
33
|
+
};
|
|
34
|
+
export type LLMModelRequestBuilder = (input: {
|
|
35
|
+
context: AIChatContext;
|
|
36
|
+
options?: LLMProviderInvokeOptions;
|
|
37
|
+
}) => LLMModelRequestBuilderResult;
|
|
25
38
|
export interface LLMProviderOptions {
|
|
26
39
|
app: Application;
|
|
27
40
|
serviceOptions?: Record<string, any>;
|
|
@@ -35,8 +48,9 @@ export declare abstract class LLMProvider {
|
|
|
35
48
|
abstract createModel(): BaseChatModel | any;
|
|
36
49
|
get baseURL(): string | null;
|
|
37
50
|
constructor(opts: LLMProviderOptions);
|
|
51
|
+
protected getModelRequestBuilder(_model?: string): LLMModelRequestBuilder | null;
|
|
38
52
|
prepareChain(context: AIChatContext): any;
|
|
39
|
-
invoke(context: AIChatContext, options?:
|
|
53
|
+
invoke(context: AIChatContext, options?: LLMProviderInvokeOptions): Promise<any>;
|
|
40
54
|
stream(context: AIChatContext, options?: any): Promise<any>;
|
|
41
55
|
listModels(): Promise<{
|
|
42
56
|
models?: {
|
|
@@ -45,6 +45,7 @@ var import_utils = require("../utils");
|
|
|
45
45
|
var import_stream = require("@langchain/core/utils/stream");
|
|
46
46
|
var import_document_loader = require("../document-loader");
|
|
47
47
|
var import_node_path = __toESM(require("node:path"));
|
|
48
|
+
var import_reasoning = require("./common/reasoning");
|
|
48
49
|
class LLMProvider {
|
|
49
50
|
app;
|
|
50
51
|
serviceOptions;
|
|
@@ -62,6 +63,9 @@ class LLMProvider {
|
|
|
62
63
|
this.chatModel = this.createModel();
|
|
63
64
|
}
|
|
64
65
|
}
|
|
66
|
+
getModelRequestBuilder(_model) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
65
69
|
prepareChain(context) {
|
|
66
70
|
var _a, _b, _c, _d;
|
|
67
71
|
let chain = this.chatModel;
|
|
@@ -84,8 +88,23 @@ class LLMProvider {
|
|
|
84
88
|
return chain;
|
|
85
89
|
}
|
|
86
90
|
async invoke(context, options) {
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
var _a;
|
|
92
|
+
const builder = this.getModelRequestBuilder((_a = this.modelOptions) == null ? void 0 : _a.model);
|
|
93
|
+
const request = (builder == null ? void 0 : builder({ context, options })) || { context, options };
|
|
94
|
+
const chain = this.prepareChain(request.context);
|
|
95
|
+
const { modelKwargs, modelRequestParams, options: requestOptions, ...restOptions } = request.options || {};
|
|
96
|
+
const invokeOptions = modelKwargs ? {
|
|
97
|
+
...restOptions,
|
|
98
|
+
[import_reasoning.MODEL_KWARGS_KEY]: modelKwargs,
|
|
99
|
+
options: {
|
|
100
|
+
...requestOptions || {},
|
|
101
|
+
[import_reasoning.MODEL_KWARGS_KEY]: modelKwargs
|
|
102
|
+
}
|
|
103
|
+
} : {
|
|
104
|
+
...restOptions,
|
|
105
|
+
...requestOptions ? { options: requestOptions } : {}
|
|
106
|
+
};
|
|
107
|
+
return chain.invoke(request.context.messages, invokeOptions);
|
|
89
108
|
}
|
|
90
109
|
async stream(context, options) {
|
|
91
110
|
const chain = this.prepareChain(context);
|
|
@@ -138,11 +138,10 @@ class AIChatConversationImpl {
|
|
|
138
138
|
formatMessages
|
|
139
139
|
} = options ?? {};
|
|
140
140
|
let messages = userMessages ? await (formatMessages == null ? void 0 : formatMessages(userMessages)) ?? [] : void 0;
|
|
141
|
-
const additionSystemPrompt = messages == null ? void 0 : messages.filter((it) => it.role === "system").map((it) => it.content).join("\n");
|
|
141
|
+
const additionSystemPrompt = messages == null ? void 0 : messages.filter((it) => it.role === "system").map((it) => it.content).filter(Boolean).join("\n");
|
|
142
142
|
messages = messages == null ? void 0 : messages.filter((it) => it.role !== "system");
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
${additionSystemPrompt}`;
|
|
143
|
+
const baseSystemPrompt = await (getSystemPrompt == null ? void 0 : getSystemPrompt(userMessages ?? []));
|
|
144
|
+
const systemPrompt = [baseSystemPrompt, additionSystemPrompt].filter(Boolean).join("\n\n") || void 0;
|
|
146
145
|
const chatContext = {
|
|
147
146
|
systemPrompt,
|
|
148
147
|
messages,
|
|
@@ -26,6 +26,19 @@ export type LLMModelOptions = {
|
|
|
26
26
|
model: string;
|
|
27
27
|
webSearch?: boolean;
|
|
28
28
|
};
|
|
29
|
+
export type EnabledLLMModel = {
|
|
30
|
+
label: string;
|
|
31
|
+
value: string;
|
|
32
|
+
};
|
|
33
|
+
export type EnabledLLMService = {
|
|
34
|
+
llmService: string;
|
|
35
|
+
llmServiceTitle: string;
|
|
36
|
+
provider: string;
|
|
37
|
+
providerTitle?: string;
|
|
38
|
+
enabledModels: EnabledLLMModel[];
|
|
39
|
+
supportWebSearch: boolean;
|
|
40
|
+
isToolConflict: boolean;
|
|
41
|
+
};
|
|
29
42
|
export declare class AIManager {
|
|
30
43
|
protected plugin: PluginAIServer;
|
|
31
44
|
llmProviders: Map<string, LLMProviderMeta>;
|
|
@@ -39,6 +52,10 @@ export declare class AIManager {
|
|
|
39
52
|
supportWebSearch: boolean;
|
|
40
53
|
}[];
|
|
41
54
|
getSupportedProvider(model: SupportedModel): string[];
|
|
55
|
+
listAllEnabledModels(): Promise<EnabledLLMService[]>;
|
|
56
|
+
resolveModel(model?: LLMModelOptions | null): Promise<LLMModelOptions>;
|
|
57
|
+
private toEnabledLLMService;
|
|
58
|
+
private getEnabledModels;
|
|
42
59
|
getLLMService(options: LLMModelOptions): Promise<{
|
|
43
60
|
provider: LLMProvider;
|
|
44
61
|
model: string;
|
|
@@ -31,6 +31,7 @@ __export(ai_manager_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(ai_manager_exports);
|
|
33
33
|
var import_tool_manager = require("./tool-manager");
|
|
34
|
+
var import_recommended_models = require("../../common/recommended-models");
|
|
34
35
|
var SupportedModel = /* @__PURE__ */ ((SupportedModel2) => {
|
|
35
36
|
SupportedModel2["LLM"] = "LLM";
|
|
36
37
|
SupportedModel2["EMBEDDING"] = "EMBEDDING";
|
|
@@ -57,6 +58,70 @@ class AIManager {
|
|
|
57
58
|
getSupportedProvider(model) {
|
|
58
59
|
return Array.from(this.llmProviders.entries()).filter(([_2, { supportedModel }]) => supportedModel && supportedModel.includes(model)).map(([name]) => name);
|
|
59
60
|
}
|
|
61
|
+
async listAllEnabledModels() {
|
|
62
|
+
const services = await this.plugin.db.getRepository("llmServices").find({ sort: "sort" });
|
|
63
|
+
return services.filter((service) => service.enabled !== false).map((service) => this.toEnabledLLMService(service)).filter(Boolean);
|
|
64
|
+
}
|
|
65
|
+
async resolveModel(model) {
|
|
66
|
+
var _a;
|
|
67
|
+
if ((model == null ? void 0 : model.llmService) && (model == null ? void 0 : model.model)) {
|
|
68
|
+
return model;
|
|
69
|
+
}
|
|
70
|
+
const services = await this.listAllEnabledModels();
|
|
71
|
+
const service = services.find((service2) => service2.enabledModels.length);
|
|
72
|
+
const firstModel = (_a = service == null ? void 0 : service.enabledModels[0]) == null ? void 0 : _a.value;
|
|
73
|
+
if ((service == null ? void 0 : service.llmService) && firstModel) {
|
|
74
|
+
return {
|
|
75
|
+
llmService: service.llmService,
|
|
76
|
+
model: firstModel
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
throw new Error("LLM service not configured");
|
|
80
|
+
}
|
|
81
|
+
toEnabledLLMService(service) {
|
|
82
|
+
var _a, _b, _c;
|
|
83
|
+
const provider = ((_a = service.get) == null ? void 0 : _a.call(service, "provider")) || service.provider;
|
|
84
|
+
const providerMeta = this.llmProviders.get(provider);
|
|
85
|
+
if (!providerMeta) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const enabledModels = this.getEnabledModels(service);
|
|
89
|
+
if (!enabledModels.length) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const Provider = providerMeta.provider;
|
|
93
|
+
const providerClient = new Provider({ app: this.plugin.app });
|
|
94
|
+
return {
|
|
95
|
+
llmService: ((_b = service.get) == null ? void 0 : _b.call(service, "name")) || service.name,
|
|
96
|
+
llmServiceTitle: ((_c = service.get) == null ? void 0 : _c.call(service, "title")) || service.title,
|
|
97
|
+
provider,
|
|
98
|
+
providerTitle: providerMeta.title,
|
|
99
|
+
enabledModels,
|
|
100
|
+
supportWebSearch: providerMeta.supportWebSearch ?? false,
|
|
101
|
+
isToolConflict: providerClient.isToolConflict()
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
getEnabledModels(service) {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
const provider = ((_a = service.get) == null ? void 0 : _a.call(service, "provider")) || service.provider;
|
|
107
|
+
const raw = ((_b = service.get) == null ? void 0 : _b.call(service, "enabledModels")) || service.enabledModels;
|
|
108
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw) && raw.mode) {
|
|
109
|
+
if (raw.mode === "recommended") {
|
|
110
|
+
return (0, import_recommended_models.getRecommendedModels)(provider);
|
|
111
|
+
}
|
|
112
|
+
return (raw.models || []).filter((model) => model.value).map((model) => ({
|
|
113
|
+
label: model.label || model.value,
|
|
114
|
+
value: model.value
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
if (Array.isArray(raw)) {
|
|
118
|
+
if (!raw.length) {
|
|
119
|
+
return (0, import_recommended_models.getRecommendedModels)(provider);
|
|
120
|
+
}
|
|
121
|
+
return raw.map((id) => ({ label: id, value: id }));
|
|
122
|
+
}
|
|
123
|
+
return (0, import_recommended_models.getRecommendedModels)(provider);
|
|
124
|
+
}
|
|
60
125
|
async getLLMService(options) {
|
|
61
126
|
const { llmService, model, webSearch } = options ?? {};
|
|
62
127
|
if (!llmService || !model) {
|
|
@@ -0,0 +1,14 @@
|
|
|
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 { Migration } from '@nocobase/server';
|
|
10
|
+
export default class extends Migration {
|
|
11
|
+
on: string;
|
|
12
|
+
appVersion: string;
|
|
13
|
+
up(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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 __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var ai_employee_knowledge_base_add_key_exports = {};
|
|
28
|
+
__export(ai_employee_knowledge_base_add_key_exports, {
|
|
29
|
+
default: () => ai_employee_knowledge_base_add_key_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(ai_employee_knowledge_base_add_key_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
class ai_employee_knowledge_base_add_key_default extends import_server.Migration {
|
|
34
|
+
on = "afterSync";
|
|
35
|
+
// 'beforeLoad' or 'afterLoad'
|
|
36
|
+
appVersion = "<2.1.0";
|
|
37
|
+
async up() {
|
|
38
|
+
var _a, _b, _c, _d;
|
|
39
|
+
const aiEmployeesRepo = this.app.db.getRepository("aiEmployees");
|
|
40
|
+
const aiEmployeeList = await aiEmployeesRepo.find();
|
|
41
|
+
for (const item of aiEmployeeList) {
|
|
42
|
+
if (!((_b = (_a = item.knowledgeBase) == null ? void 0 : _a.knowledgeBaseIds) == null ? void 0 : _b.length)) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if ((_d = (_c = item.knowledgeBase) == null ? void 0 : _c.knowledgeBaseKeys) == null ? void 0 : _d.length) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
await aiEmployeesRepo.update({
|
|
49
|
+
values: {
|
|
50
|
+
knowledgeBase: {
|
|
51
|
+
...item.knowledgeBase,
|
|
52
|
+
knowledgeBaseKeys: item.knowledgeBase.knowledgeBaseIds.map((it) => String(it))
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
filter: {
|
|
56
|
+
username: item.username
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -40,7 +40,6 @@ __export(ai_exports, {
|
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(ai_exports);
|
|
42
42
|
var import_lodash = __toESM(require("lodash"));
|
|
43
|
-
var import_recommended_models = require("../../common/recommended-models");
|
|
44
43
|
const aiResource = {
|
|
45
44
|
name: "ai",
|
|
46
45
|
actions: {
|
|
@@ -157,46 +156,7 @@ const aiResource = {
|
|
|
157
156
|
},
|
|
158
157
|
listAllEnabledModels: async (ctx, next) => {
|
|
159
158
|
const plugin = ctx.app.pm.get("ai");
|
|
160
|
-
|
|
161
|
-
const llmServices = services.filter((service) => service.enabled !== false).map((service) => {
|
|
162
|
-
const raw = service.enabledModels;
|
|
163
|
-
let enabledModels;
|
|
164
|
-
if (raw && typeof raw === "object" && !Array.isArray(raw) && raw.mode) {
|
|
165
|
-
if (raw.mode === "recommended") {
|
|
166
|
-
enabledModels = (0, import_recommended_models.getRecommendedModels)(service.provider);
|
|
167
|
-
} else {
|
|
168
|
-
enabledModels = (raw.models || []).filter((m) => m.value).map((m) => ({
|
|
169
|
-
label: m.label || m.value,
|
|
170
|
-
value: m.value
|
|
171
|
-
}));
|
|
172
|
-
}
|
|
173
|
-
} else if (Array.isArray(raw)) {
|
|
174
|
-
if (raw.length === 0) {
|
|
175
|
-
enabledModels = (0, import_recommended_models.getRecommendedModels)(service.provider);
|
|
176
|
-
} else {
|
|
177
|
-
enabledModels = raw.map((id) => ({ label: id, value: id }));
|
|
178
|
-
}
|
|
179
|
-
} else {
|
|
180
|
-
enabledModels = (0, import_recommended_models.getRecommendedModels)(service.provider);
|
|
181
|
-
}
|
|
182
|
-
if (enabledModels.length === 0) {
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
const providerMeta = plugin.aiManager.llmProviders.get(service.provider);
|
|
186
|
-
const P = providerMeta.provider;
|
|
187
|
-
const p = new P({ app: ctx.app });
|
|
188
|
-
const isToolConflict = p.isToolConflict();
|
|
189
|
-
return {
|
|
190
|
-
llmService: service.name,
|
|
191
|
-
llmServiceTitle: service.title,
|
|
192
|
-
provider: service.provider,
|
|
193
|
-
providerTitle: providerMeta == null ? void 0 : providerMeta.title,
|
|
194
|
-
enabledModels,
|
|
195
|
-
supportWebSearch: (providerMeta == null ? void 0 : providerMeta.supportWebSearch) ?? false,
|
|
196
|
-
isToolConflict
|
|
197
|
-
};
|
|
198
|
-
}).filter(Boolean);
|
|
199
|
-
ctx.body = llmServices;
|
|
159
|
+
ctx.body = await plugin.aiManager.listAllEnabledModels();
|
|
200
160
|
await next();
|
|
201
161
|
}
|
|
202
162
|
}
|
|
@@ -168,7 +168,7 @@ var aiConversations_default = {
|
|
|
168
168
|
if (!userId) {
|
|
169
169
|
return ctx.throw(403);
|
|
170
170
|
}
|
|
171
|
-
const { aiEmployee, systemMessage, skillSettings, conversationSettings } = ctx.action.params.values || {};
|
|
171
|
+
const { aiEmployee, systemMessage, skillSettings, conversationSettings, modelSettings } = ctx.action.params.values || {};
|
|
172
172
|
const employee = await getAIEmployee(ctx, aiEmployee.username);
|
|
173
173
|
if (!employee) {
|
|
174
174
|
ctx.throw(400, "AI employee not found");
|
|
@@ -180,7 +180,8 @@ var aiConversations_default = {
|
|
|
180
180
|
options: {
|
|
181
181
|
systemMessage,
|
|
182
182
|
skillSettings,
|
|
183
|
-
conversationSettings
|
|
183
|
+
conversationSettings,
|
|
184
|
+
modelSettings
|
|
184
185
|
}
|
|
185
186
|
});
|
|
186
187
|
} catch (error) {
|
|
@@ -214,15 +215,15 @@ var aiConversations_default = {
|
|
|
214
215
|
if (!sessionId) {
|
|
215
216
|
return ctx.throw(400, "invalid sessionId");
|
|
216
217
|
}
|
|
217
|
-
const { systemMessage, skillSettings, conversationSettings } = ctx.action.params.values || {};
|
|
218
|
-
if (!systemMessage && !skillSettings && !conversationSettings) {
|
|
218
|
+
const { systemMessage, skillSettings, conversationSettings, modelSettings } = ctx.action.params.values || {};
|
|
219
|
+
if (!systemMessage && !skillSettings && !conversationSettings && !modelSettings) {
|
|
219
220
|
return ctx.throw(400, "invalid options");
|
|
220
221
|
}
|
|
221
222
|
try {
|
|
222
223
|
ctx.body = await plugin.aiConversationsManager.update({
|
|
223
224
|
userId,
|
|
224
225
|
sessionId,
|
|
225
|
-
options: { systemMessage, skillSettings, conversationSettings }
|
|
226
|
+
options: { systemMessage, skillSettings, conversationSettings, modelSettings }
|
|
226
227
|
});
|
|
227
228
|
} catch (error) {
|
|
228
229
|
if (error.message === "invalid sessionId") {
|
|
@@ -394,6 +395,7 @@ var aiConversations_default = {
|
|
|
394
395
|
return next();
|
|
395
396
|
}
|
|
396
397
|
const legacy = conversation.thread === 0;
|
|
398
|
+
const resolvedModel = await plugin.aiEmployeesManager.resolveModel(employee, model);
|
|
397
399
|
const aiEmployee = new import_ai_employee.AIEmployee({
|
|
398
400
|
ctx,
|
|
399
401
|
employee,
|
|
@@ -402,7 +404,7 @@ var aiConversations_default = {
|
|
|
402
404
|
skillSettings: (_c = conversation.options) == null ? void 0 : _c.skillSettings,
|
|
403
405
|
tools: (_d = conversation.options) == null ? void 0 : _d.tools,
|
|
404
406
|
webSearch,
|
|
405
|
-
model,
|
|
407
|
+
model: resolvedModel,
|
|
406
408
|
legacy
|
|
407
409
|
});
|
|
408
410
|
if (!editingMessageId) {
|
|
@@ -580,6 +582,7 @@ var aiConversations_default = {
|
|
|
580
582
|
sendErrorResponse(ctx, "AI employee not found");
|
|
581
583
|
return next();
|
|
582
584
|
}
|
|
585
|
+
const resolvedModel = await plugin.aiEmployeesManager.resolveModel(employee, model);
|
|
583
586
|
const aiEmployee = new import_ai_employee.AIEmployee({
|
|
584
587
|
ctx,
|
|
585
588
|
employee,
|
|
@@ -588,7 +591,7 @@ var aiConversations_default = {
|
|
|
588
591
|
skillSettings: (_c = conversation.options) == null ? void 0 : _c.skillSettings,
|
|
589
592
|
tools: (_d = conversation.options) == null ? void 0 : _d.tools,
|
|
590
593
|
webSearch,
|
|
591
|
-
model
|
|
594
|
+
model: resolvedModel
|
|
592
595
|
});
|
|
593
596
|
await aiEmployee.stream({ messageId, userMessages: resendMessages.length ? resendMessages : void 0 });
|
|
594
597
|
} catch (err) {
|
|
@@ -728,6 +731,7 @@ var aiConversations_default = {
|
|
|
728
731
|
sendErrorResponse(ctx, "No tool calls found");
|
|
729
732
|
return next();
|
|
730
733
|
}
|
|
734
|
+
const resolvedModel = await plugin.aiEmployeesManager.resolveModel(employee, model);
|
|
731
735
|
const aiEmployee = new import_ai_employee.AIEmployee({
|
|
732
736
|
ctx,
|
|
733
737
|
employee,
|
|
@@ -736,7 +740,7 @@ var aiConversations_default = {
|
|
|
736
740
|
skillSettings: (_c = conversation.options) == null ? void 0 : _c.skillSettings,
|
|
737
741
|
tools: (_d = conversation.options) == null ? void 0 : _d.tools,
|
|
738
742
|
webSearch,
|
|
739
|
-
model
|
|
743
|
+
model: resolvedModel
|
|
740
744
|
});
|
|
741
745
|
const userDecisions = await plugin.aiConversationsManager.getUserDecisions(messageId);
|
|
742
746
|
await aiEmployee.stream({
|
|
@@ -45,7 +45,9 @@ module.exports = __toCommonJS(aiEmployees_exports);
|
|
|
45
45
|
var import_actions = __toESM(require("@nocobase/actions"));
|
|
46
46
|
var templates = __toESM(require("../ai-employees/templates"));
|
|
47
47
|
var import_lodash = __toESM(require("lodash"));
|
|
48
|
+
var import_ai_feature_manager = require("../manager/ai-feature-manager");
|
|
48
49
|
const list = async (ctx, next) => {
|
|
50
|
+
var _a, _b;
|
|
49
51
|
const { paginate } = ctx.action.params || {};
|
|
50
52
|
const plugin = ctx.app.pm.get("ai");
|
|
51
53
|
const builtInManager = plugin.builtInManager;
|
|
@@ -58,9 +60,36 @@ const list = async (ctx, next) => {
|
|
|
58
60
|
});
|
|
59
61
|
await import_actions.default.list(ctx, () => {
|
|
60
62
|
});
|
|
61
|
-
let data
|
|
63
|
+
let data;
|
|
62
64
|
if (paginate === "false" || paginate === false) {
|
|
65
|
+
ctx.body = ctx.body.map((it) => it.toJSON());
|
|
63
66
|
data = ctx.body;
|
|
67
|
+
} else {
|
|
68
|
+
ctx.body.rows = ctx.body.rows.map((it) => it.toJSON());
|
|
69
|
+
data = ctx.body.rows;
|
|
70
|
+
}
|
|
71
|
+
const featureEnabled = plugin.features.isFeaturesEnabled(Object.values(import_ai_feature_manager.EEFeatures));
|
|
72
|
+
if (featureEnabled) {
|
|
73
|
+
const knowledgeBaseKeys = import_lodash.default.uniq(
|
|
74
|
+
data.map((it) => {
|
|
75
|
+
var _a2;
|
|
76
|
+
return ((_a2 = it.knowledgeBase) == null ? void 0 : _a2.knowledgeBaseKeys) ?? [];
|
|
77
|
+
}).flatMap((it) => it)
|
|
78
|
+
);
|
|
79
|
+
const knowledgeBaseList = await plugin.features.knowledgeBase.getKnowledgeBase(knowledgeBaseKeys);
|
|
80
|
+
const existedKnowledgeBaseKeys = (knowledgeBaseList == null ? void 0 : knowledgeBaseList.map((it) => it.key)) ?? [];
|
|
81
|
+
for (const row of data) {
|
|
82
|
+
row.missingKnowledgeBaseKeys = [];
|
|
83
|
+
if (!((_b = (_a = row.knowledgeBase) == null ? void 0 : _a.knowledgeBaseKeys) == null ? void 0 : _b.length)) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
for (const k of row.knowledgeBase.knowledgeBaseKeys) {
|
|
87
|
+
if (existedKnowledgeBaseKeys.includes(k)) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
row.missingKnowledgeBaseKeys.push(k);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
64
93
|
}
|
|
65
94
|
data.forEach((row) => {
|
|
66
95
|
if (row.builtIn) {
|
|
@@ -153,6 +182,8 @@ const listByUser = async (ctx, next) => {
|
|
|
153
182
|
prompt: (_b = (_a = row.userConfigs) == null ? void 0 : _a[0]) == null ? void 0 : _b.prompt
|
|
154
183
|
},
|
|
155
184
|
skillSettings,
|
|
185
|
+
chatSettings: row.chatSettings,
|
|
186
|
+
modelSettings: row.modelSettings,
|
|
156
187
|
builtIn: row.builtIn,
|
|
157
188
|
category: row.category,
|
|
158
189
|
deprecated: row.deprecated
|