@nocobase/plugin-ai 2.3.0-alpha.1 → 3.0.0-alpha.2
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/dist/ai/docs/nocobase/ai-employees/block/ai-chat-box.md +133 -0
- package/dist/ai/docs/nocobase/ai-employees/knowledge-base/knowledge-base/documents.md +1 -1
- package/dist/ai/docs/nocobase/ai-employees/knowledge-base/knowledge-base/index.md +11 -7
- package/dist/ai/docs/nocobase/ai-employees/knowledge-base/knowledge-base/settings.md +12 -8
- package/dist/ai/docs/nocobase/ai-employees/knowledge-base/vector-database.md +3 -3
- package/dist/ai/docs/nocobase/ai-employees/workflow/nodes/knowledge/create-document.md +1 -1
- package/dist/ai/docs/nocobase/api/app/env.md +3 -1
- package/dist/ai/docs/nocobase/api/cli/index.md +14 -2
- package/dist/ai/docs/nocobase/api/cli/portal/config.md +44 -0
- package/dist/ai/docs/nocobase/api/cli/portal/create.md +48 -0
- package/dist/ai/docs/nocobase/api/cli/portal/deploy.md +39 -0
- package/dist/ai/docs/nocobase/api/cli/portal/destroy.md +41 -0
- package/dist/ai/docs/nocobase/api/cli/portal/dev.md +39 -0
- package/dist/ai/docs/nocobase/api/cli/portal/index.md +136 -0
- package/dist/ai/docs/nocobase/api/cli/portal/info.md +41 -0
- package/dist/ai/docs/nocobase/api/cli/portal/list.md +40 -0
- package/dist/ai/docs/nocobase/api/cli/portal/pull.md +43 -0
- package/dist/ai/docs/nocobase/api/cli/portal/push.md +41 -0
- package/dist/ai/docs/nocobase/building-tips/ai-fill-js-block-form.md +1092 -0
- package/dist/ai/docs/nocobase/data-sources/calendar/calendar-collection.md +100 -3
- package/dist/ai/docs/nocobase/data-sources/collection-comment/index.md +92 -39
- package/dist/ai/docs/nocobase/data-sources/collection-sql/index.md +150 -29
- package/dist/ai/docs/nocobase/data-sources/collection-tree/index.md +93 -5
- package/dist/ai/docs/nocobase/data-sources/collection-view/index.md +226 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/advanced/china-region.md +122 -5
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/advanced/collection-select.md +105 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/advanced/json.md +102 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/advanced/nano-id.md +104 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/advanced/snowflake-id.md +108 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/advanced/sort.md +3 -19
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/advanced/uuid.md +104 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/associations/index.md +44 -8
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/basic/color.md +102 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/basic/email.md +104 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/basic/icon.md +102 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/basic/input.md +112 -8
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/basic/integer.md +103 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/basic/number.md +103 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/basic/password.md +102 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/basic/percent.md +104 -5
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/basic/phone.md +104 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/basic/textarea.md +99 -8
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/basic/url.md +103 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/choices/checkbox-group.md +105 -3
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/choices/checkbox.md +102 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/choices/china-region.md +108 -5
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/choices/multiple-select.md +103 -5
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/choices/radio-group.md +106 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/choices/select.md +103 -5
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/datetime/date.md +102 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/datetime/datetime-without-tz.md +103 -5
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/datetime/datetime.md +103 -5
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/datetime/index.md +53 -47
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/datetime/time.md +102 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/datetime/unix-timestamp.md +103 -5
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/geometric/circle.md +102 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/geometric/line.md +103 -5
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/geometric/point.md +102 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/geometric/polygon.md +102 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/index.md +62 -16
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/media/markdown.md +104 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/media/rich-text.md +105 -5
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/system-info/created-at.md +105 -5
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/system-info/created-by.md +103 -5
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/system-info/space.md +100 -6
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/system-info/table-oid.md +102 -4
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/system-info/updated-at.md +104 -5
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/system-info/updated-by.md +104 -6
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection-fields/validation.md +68 -58
- package/dist/ai/docs/nocobase/data-sources/data-modeling/collection.md +32 -13
- package/dist/ai/docs/nocobase/data-sources/data-modeling/index.md +41 -33
- package/dist/ai/docs/nocobase/data-sources/data-source-external-mariadb/index.md +114 -6
- package/dist/ai/docs/nocobase/data-sources/data-source-external-mssql/index.md +117 -6
- package/dist/ai/docs/nocobase/data-sources/data-source-external-mysql/index.md +103 -6
- package/dist/ai/docs/nocobase/data-sources/data-source-external-nocobase/index.md +75 -73
- package/dist/ai/docs/nocobase/data-sources/data-source-external-oracle/index.md +129 -11
- package/dist/ai/docs/nocobase/data-sources/data-source-external-postgres/index.md +110 -6
- package/dist/ai/docs/nocobase/data-sources/data-source-kingbase/index.md +75 -49
- package/dist/ai/docs/nocobase/data-sources/data-source-main/general-collection.md +116 -15
- package/dist/ai/docs/nocobase/data-sources/data-source-main/index.md +92 -62
- package/dist/ai/docs/nocobase/data-sources/data-source-main/inheritance-collection.md +97 -10
- package/dist/ai/docs/nocobase/data-sources/data-source-manager/external-database.md +97 -58
- package/dist/ai/docs/nocobase/data-sources/data-source-manager/index.md +32 -24
- package/dist/ai/docs/nocobase/data-sources/data-source-rest-api/index.md +115 -153
- package/dist/ai/docs/nocobase/data-sources/external/clickhouse.md +124 -0
- package/dist/ai/docs/nocobase/data-sources/external/doris.md +130 -0
- package/dist/ai/docs/nocobase/data-sources/external/index.md +140 -0
- package/dist/ai/docs/nocobase/data-sources/external/kingbase.md +129 -0
- package/dist/ai/docs/nocobase/data-sources/external/mariadb.md +126 -0
- package/dist/ai/docs/nocobase/data-sources/external/mssql.md +129 -0
- package/dist/ai/docs/nocobase/data-sources/external/mysql.md +115 -0
- package/dist/ai/docs/nocobase/data-sources/external/nocobase.md +159 -0
- package/dist/ai/docs/nocobase/data-sources/external/oceanbase.md +126 -0
- package/dist/ai/docs/nocobase/data-sources/external/oracle.md +158 -0
- package/dist/ai/docs/nocobase/data-sources/external/postgresql.md +122 -0
- package/dist/ai/docs/nocobase/data-sources/external/rest-api.md +245 -0
- package/dist/ai/docs/nocobase/data-sources/field-attachment-url/index.md +100 -12
- package/dist/ai/docs/nocobase/data-sources/field-encryption/index.md +48 -47
- package/dist/ai/docs/nocobase/data-sources/field-formula/index.md +99 -5
- package/dist/ai/docs/nocobase/data-sources/field-markdown-vditor/index.md +105 -5
- package/dist/ai/docs/nocobase/data-sources/field-sequence/index.md +102 -5
- package/dist/ai/docs/nocobase/data-sources/field-signature/index.md +18 -16
- package/dist/ai/docs/nocobase/data-sources/field-sort/index.md +76 -73
- package/dist/ai/docs/nocobase/data-sources/file-manager/field-attachment.md +101 -7
- package/dist/ai/docs/nocobase/data-sources/file-manager/file-collection.md +101 -14
- package/dist/ai/docs/nocobase/data-sources/index.md +49 -33
- package/dist/ai/docs/nocobase/data-sources/main/index.md +130 -0
- package/dist/ai/docs/nocobase/data-sources/main/kingbase.md +147 -0
- package/dist/ai/docs/nocobase/data-sources/main/mariadb.md +59 -0
- package/dist/ai/docs/nocobase/data-sources/main/mysql.md +59 -0
- package/dist/ai/docs/nocobase/data-sources/main/oceanbase.md +62 -0
- package/dist/ai/docs/nocobase/data-sources/main/postgresql.md +61 -0
- package/dist/ai/docs/nocobase/file-manager/storage/index.md +66 -26
- package/dist/ai/docs/nocobase/file-manager/storage/s3-pro.md +58 -7
- package/dist/ai/docs/nocobase/get-started/installation/env.md +2 -2
- package/dist/ai/docs/nocobase/ops-management/migration-manager/built-in-tables.md +1 -2
- package/dist/ai/docs/nocobase/runjs/context/ai.md +194 -4
- package/dist/ai/tools/executeFrontendTool.d.ts +10 -0
- package/dist/ai/tools/executeFrontendTool.js +86 -0
- package/dist/ai/tools/getSkill.js +1 -1
- package/dist/ai/tools/loadFrontendTool.d.ts +10 -0
- package/dist/ai/tools/loadFrontendTool.js +99 -0
- package/dist/client/244.8631eb5cf3f05e21.js +10 -0
- package/dist/client/{525.203778500aca5d05.js → 525.94dd4136c1361477.js} +1 -1
- package/dist/client/681.6ffbc9329b9ac242.js +10 -0
- package/dist/{client-v2/705.1d10027ff8cfdf79.js → client/705.19b642db34de438a.js} +1 -1
- package/dist/client/index.d.ts +1 -3
- package/dist/client/index.js +8 -8
- package/dist/client-v2/244.c428e645ecb94414.js +10 -0
- package/dist/client-v2/420.b2aedb1ff71fca0e.js +10 -0
- package/dist/client-v2/681.6890caa389564ff7.js +10 -0
- package/dist/client-v2/705.8dc34d43f02f322c.js +10 -0
- package/dist/client-v2/ai-employees/AIEmployeeShortcut.d.ts +2 -0
- package/dist/client-v2/ai-employees/AddContextButton.d.ts +2 -0
- package/dist/client-v2/ai-employees/chatbox/components/AIEmployeeSwitcher.d.ts +1 -0
- package/dist/client-v2/ai-employees/chatbox/components/ChatBoxUnreadBadge.d.ts +17 -0
- package/dist/client-v2/ai-employees/chatbox/components/Conversations.d.ts +9 -1
- package/dist/client-v2/ai-employees/chatbox/components/MessageRenderers.d.ts +1 -1
- package/dist/client-v2/ai-employees/chatbox/components/Messages.d.ts +5 -1
- package/dist/client-v2/ai-employees/chatbox/components/ModelSwitcher.d.ts +4 -0
- package/dist/client-v2/ai-employees/chatbox/components/Sender.d.ts +33 -1
- package/dist/client-v2/ai-employees/chatbox/components/index.d.ts +1 -0
- package/dist/client-v2/ai-employees/chatbox/hooks/useChat.d.ts +8 -5
- package/dist/client-v2/ai-employees/chatbox/hooks/useChatBoxActions.d.ts +3 -2
- package/dist/client-v2/ai-employees/chatbox/hooks/useChatBoxEffect.d.ts +2 -1
- package/dist/client-v2/ai-employees/chatbox/hooks/useChatConversationActions.d.ts +3 -2
- package/dist/client-v2/ai-employees/chatbox/hooks/useChatMessageActions.d.ts +4 -2
- package/dist/client-v2/ai-employees/chatbox/hooks/useToolCallActions.d.ts +3 -1
- package/dist/client-v2/ai-employees/chatbox/hooks/useUploadFiles.d.ts +13 -3
- package/dist/client-v2/ai-employees/chatbox/hooks/useWorkflowTasks.d.ts +3 -2
- package/dist/client-v2/ai-employees/chatbox/index.d.ts +17 -0
- package/dist/client-v2/ai-employees/chatbox/roles.d.ts +2 -153
- package/dist/client-v2/ai-employees/chatbox/stores/chat-box.d.ts +46 -31
- package/dist/client-v2/ai-employees/chatbox/stores/chat-conversations.d.ts +7 -7
- package/dist/client-v2/ai-employees/chatbox/stores/chat-messages.d.ts +23 -18
- package/dist/client-v2/ai-employees/chatbox/stores/chat-sender.d.ts +43 -0
- package/dist/client-v2/ai-employees/chatbox/stores/chat-tool-call.d.ts +6 -5
- package/dist/client-v2/ai-employees/chatbox/stores/chat-tools.d.ts +11 -5
- package/dist/client-v2/ai-employees/chatbox/stores/mounted-chat-boxes.d.ts +20 -0
- package/dist/client-v2/ai-employees/chatbox/stores/runtime.d.ts +43 -0
- package/dist/client-v2/ai-employees/chatbox/stores/workflow-tasks.d.ts +22 -10
- package/dist/client-v2/ai-employees/chatbox/upload.d.ts +19 -0
- package/dist/client-v2/ai-employees/chatbox/utils.d.ts +28 -4
- package/dist/client-v2/ai-employees/frontend-tools.d.ts +11 -0
- package/dist/client-v2/ai-employees/tools/SuggestionsOptionsCard.d.ts +1 -1
- package/dist/client-v2/ai-employees/tools/WorkflowTaskOutputCard.d.ts +1 -1
- package/dist/client-v2/ai-employees/types.d.ts +30 -0
- package/dist/client-v2/block/ai-chat-box/AIChatBoxBlockModel.d.ts +21 -0
- package/dist/client-v2/block/ai-chat-box/AIChatBoxCoreModel.d.ts +13 -0
- package/dist/client-v2/block/ai-chat-box/components/AIChatBoxCoreView.d.ts +10 -0
- package/dist/client-v2/block/ai-chat-box/components/AIChatBoxView.d.ts +12 -0
- package/dist/client-v2/block/ai-chat-box/index.d.ts +14 -0
- package/dist/client-v2/block/ai-chat-box/settings.d.ts +12 -0
- package/dist/client-v2/block/ai-chat-box/sub-models.d.ts +26 -0
- package/dist/client-v2/block/ai-chat-box/types.d.ts +38 -0
- package/dist/client-v2/block/ai-chat-box/utils.d.ts +26 -0
- package/dist/client-v2/index.d.ts +3 -5
- package/dist/client-v2/index.js +3 -3
- package/dist/client-v2/llm-services/model-select.d.ts +33 -0
- package/dist/client-v2/llm-services/utils.d.ts +1 -0
- package/dist/client-v2/manager/ai-manager.d.ts +10 -3
- package/dist/client-v2/manager/frontend-tool-registry.d.ts +30 -0
- package/dist/client-v2/models/ai-employees/AIEmployeeActionModel.d.ts +4 -1
- package/dist/client-v2/models/ai-employees/AIEmployeeShortcutModel.d.ts +5 -0
- package/dist/client-v2/pages/EmployeesPage.d.ts +2 -0
- package/dist/client-v2/runjs/registerAIEmployeeRunJSFacade.d.ts +1 -0
- package/dist/common/ai-employee-validation.d.ts +15 -0
- package/dist/common/ai-employee-validation.js +61 -0
- package/dist/common/error-codes.d.ts +13 -0
- package/dist/common/error-codes.js +48 -0
- package/dist/common/frontend-tools.d.ts +26 -0
- package/dist/common/frontend-tools.js +57 -0
- package/dist/common/llm-service-models.d.ts +16 -0
- package/dist/common/llm-service-models.js +84 -0
- package/dist/externalVersion.js +16 -16
- package/dist/locale/en-US.json +67 -0
- package/dist/locale/zh-CN.json +67 -0
- package/dist/node_modules/@langchain/mistralai/package.json +1 -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 +4 -1
- package/dist/server/ai-employees/ai-conversations.js +2 -0
- package/dist/server/ai-employees/ai-employee.d.ts +2 -1
- package/dist/server/ai-employees/ai-employee.js +26 -7
- package/dist/server/ai-employees/middleware/conversation.js +9 -2
- package/dist/server/collections/ai-conversations.js +5 -0
- package/dist/server/document-loader/constants.js +1 -1
- package/dist/server/frontend-tools.d.ts +25 -0
- package/dist/server/frontend-tools.js +171 -0
- package/dist/server/manager/work-context-handler.js +10 -3
- package/dist/server/plugin.d.ts +1 -0
- package/dist/server/plugin.js +25 -0
- package/dist/server/resource/aiConversations.d.ts +2 -0
- package/dist/server/resource/aiConversations.js +33 -3
- package/dist/server/resource/aiEmployees.d.ts +2 -0
- package/dist/server/resource/aiEmployees.js +62 -0
- package/dist/server/resource/aiWorkflowTasks.js +9 -1
- package/dist/server/resource/llmServices.d.ts +11 -0
- package/dist/server/resource/llmServices.js +85 -0
- package/dist/server/types/knowledge-base.type.d.ts +6 -2
- package/dist/swagger/common.d.ts +143 -0
- package/dist/swagger/common.js +144 -0
- package/dist/swagger/employees.d.ts +301 -0
- package/dist/swagger/employees.js +131 -0
- package/dist/swagger/index.d.ts +1588 -0
- package/dist/swagger/index.js +62 -0
- package/dist/swagger/llm.d.ts +555 -0
- package/dist/swagger/llm.js +247 -0
- package/dist/swagger/schemas.d.ts +736 -0
- package/dist/swagger/schemas.js +381 -0
- package/package.json +2 -2
- package/dist/ai/docs/nocobase/ai-employees/knowledge-base/vector-store.md +0 -24
- package/dist/ai/docs/nocobase/data-sources/development/index.md +0 -6
- package/dist/client/372.40eb52905e3f3049.js +0 -10
- package/dist/client/681.399948c18d753667.js +0 -10
- package/dist/client/705.380279da896021fb.js +0 -10
- package/dist/client-v2/372.8cc3fde09c9bec77.js +0 -10
- package/dist/client-v2/406.341be51205c674e0.js +0 -10
- package/dist/client-v2/681.082f4f1c7b841983.js +0 -10
- package/dist/client-v2/ai-employees/chatbox/stores/create-selectors.d.ts +0 -46
- package/dist/client-v2/ai-employees/chatbox/utils/normalizeTriggerTaskOptions.d.ts +0 -19
|
@@ -98,8 +98,9 @@ const conversationMiddleware = (aiEmployee, options) => {
|
|
|
98
98
|
})
|
|
99
99
|
}),
|
|
100
100
|
beforeAgent: async (state) => {
|
|
101
|
-
const
|
|
102
|
-
const
|
|
101
|
+
const humanMessages = state.messages.filter((x) => x.type === "human");
|
|
102
|
+
const currentHumanMessageIndex = humanMessages.length;
|
|
103
|
+
const userMessages = (aiEmployee.userMessageCount ? humanMessages.slice(-aiEmployee.userMessageCount) : []).map((x) => x).map(convertHumanMessage);
|
|
103
104
|
await aiEmployee.aiChatConversation.withTransaction(async (conversation, transaction) => {
|
|
104
105
|
if (agentThread) {
|
|
105
106
|
await aiEmployee.updateThread(transaction, agentThread);
|
|
@@ -111,6 +112,12 @@ const conversationMiddleware = (aiEmployee, options) => {
|
|
|
111
112
|
await conversation.addMessages(userMessages);
|
|
112
113
|
}
|
|
113
114
|
});
|
|
115
|
+
return {
|
|
116
|
+
lastMessageIndex: {
|
|
117
|
+
...state.lastMessageIndex,
|
|
118
|
+
lastHumanMessageIndex: currentHumanMessageIndex
|
|
119
|
+
}
|
|
120
|
+
};
|
|
114
121
|
},
|
|
115
122
|
afterAgent: async () => {
|
|
116
123
|
aiEmployee.removeAbortController();
|
|
@@ -33,12 +33,12 @@ module.exports = __toCommonJS(constants_exports);
|
|
|
33
33
|
const DOCUMENT_PARSE_META_KEY = "documentParse";
|
|
34
34
|
const SUPPORTED_DOCUMENT_EXTNAMES = [
|
|
35
35
|
".pdf",
|
|
36
|
-
".ppt",
|
|
37
36
|
".pptx",
|
|
38
37
|
".doc",
|
|
39
38
|
".docx",
|
|
40
39
|
".xls",
|
|
41
40
|
".xlsx",
|
|
41
|
+
".xlsm",
|
|
42
42
|
".txt",
|
|
43
43
|
".md",
|
|
44
44
|
".json",
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import type { Context } from '@nocobase/actions';
|
|
10
|
+
import { type FrontendToolManifest } from '../common/frontend-tools';
|
|
11
|
+
import type { WorkContext } from './types/ai-message.type';
|
|
12
|
+
export declare const extractFrontendToolManifests: (workContext: WorkContext[]) => FrontendToolManifest[];
|
|
13
|
+
export declare const listCurrentFrontendTools: (ctx: Context, sessionId?: string) => Promise<FrontendToolManifest[]>;
|
|
14
|
+
export declare const findCurrentFrontendTool: (ctx: Context, toolId: string, sessionId?: string) => Promise<FrontendToolManifest | undefined>;
|
|
15
|
+
export declare const shouldAutoExecuteFrontendTool: (tools: FrontendToolManifest[], args: unknown) => boolean;
|
|
16
|
+
export declare const prepareToolsForFrontendConversation: <T extends {
|
|
17
|
+
definition: {
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
}>(tools: T[], frontendTools: FrontendToolManifest[]) => T[];
|
|
22
|
+
export declare const readFrontendToolResult: (ctx: Context, toolCallId: string) => {
|
|
23
|
+
provided: true;
|
|
24
|
+
value: unknown;
|
|
25
|
+
} | undefined;
|
|
@@ -0,0 +1,171 @@
|
|
|
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 frontend_tools_exports = {};
|
|
28
|
+
__export(frontend_tools_exports, {
|
|
29
|
+
extractFrontendToolManifests: () => extractFrontendToolManifests,
|
|
30
|
+
findCurrentFrontendTool: () => findCurrentFrontendTool,
|
|
31
|
+
listCurrentFrontendTools: () => listCurrentFrontendTools,
|
|
32
|
+
prepareToolsForFrontendConversation: () => prepareToolsForFrontendConversation,
|
|
33
|
+
readFrontendToolResult: () => readFrontendToolResult,
|
|
34
|
+
shouldAutoExecuteFrontendTool: () => shouldAutoExecuteFrontendTool
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(frontend_tools_exports);
|
|
37
|
+
var import_zod = require("zod");
|
|
38
|
+
var import_frontend_tools = require("../common/frontend-tools");
|
|
39
|
+
const isRecord = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
40
|
+
const isMessageLike = (value) => !!value && typeof value === "object";
|
|
41
|
+
const normalizeFrontendToolManifests = (value) => {
|
|
42
|
+
if (!Array.isArray(value)) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
const manifests = /* @__PURE__ */ new Map();
|
|
46
|
+
for (const manifest of value) {
|
|
47
|
+
if ((0, import_frontend_tools.isFrontendToolManifest)(manifest) && manifest.id === `${manifest.blockUid}:${manifest.name}`) {
|
|
48
|
+
manifests.set(manifest.id, manifest);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return Array.from(manifests.values());
|
|
52
|
+
};
|
|
53
|
+
const extractFrontendToolManifests = (workContext) => {
|
|
54
|
+
const manifests = /* @__PURE__ */ new Map();
|
|
55
|
+
for (const item of workContext) {
|
|
56
|
+
const frontendTools = Array.isArray(item == null ? void 0 : item.frontendTools) ? item.frontendTools : [];
|
|
57
|
+
for (const frontendTool of frontendTools) {
|
|
58
|
+
if ((0, import_frontend_tools.isFrontendToolManifest)(frontendTool) && frontendTool.blockUid === item.uid && frontendTool.id === `${item.uid}:${frontendTool.name}`) {
|
|
59
|
+
manifests.set(frontendTool.id, frontendTool);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return Array.from(manifests.values());
|
|
64
|
+
};
|
|
65
|
+
const findRequestFrontendTools = (ctx) => {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
const values = (_b = (_a = ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.values;
|
|
68
|
+
const messages = Array.isArray(values == null ? void 0 : values.messages) ? values.messages.filter(isMessageLike) : [];
|
|
69
|
+
for (const message of messages) {
|
|
70
|
+
if (message.role !== "user") {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const frontendTools = extractFrontendToolManifests(Array.isArray(message.workContext) ? message.workContext : []);
|
|
74
|
+
if (frontendTools.length) {
|
|
75
|
+
return frontendTools;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return [];
|
|
79
|
+
};
|
|
80
|
+
const listCurrentFrontendTools = async (ctx, sessionId) => {
|
|
81
|
+
var _a, _b, _c;
|
|
82
|
+
const requestSessionId = (_c = (_b = (_a = ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.values) == null ? void 0 : _c.sessionId;
|
|
83
|
+
const currentSessionId = sessionId ?? (typeof requestSessionId === "string" ? requestSessionId : "");
|
|
84
|
+
if (!currentSessionId) {
|
|
85
|
+
return findRequestFrontendTools(ctx);
|
|
86
|
+
}
|
|
87
|
+
const conversationRepository = ctx.db.getRepository("aiConversations");
|
|
88
|
+
const conversation = await conversationRepository.findOne({
|
|
89
|
+
filter: {
|
|
90
|
+
sessionId: currentSessionId
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const options = conversation == null ? void 0 : conversation.options;
|
|
94
|
+
const boundTools = normalizeFrontendToolManifests(isRecord(options) ? options.frontendTools : void 0);
|
|
95
|
+
if (boundTools.length) {
|
|
96
|
+
return boundTools;
|
|
97
|
+
}
|
|
98
|
+
const frontendTools = findRequestFrontendTools(ctx);
|
|
99
|
+
if (!frontendTools.length || !conversation) {
|
|
100
|
+
return frontendTools;
|
|
101
|
+
}
|
|
102
|
+
await conversationRepository.update({
|
|
103
|
+
filter: {
|
|
104
|
+
sessionId: currentSessionId
|
|
105
|
+
},
|
|
106
|
+
values: {
|
|
107
|
+
options: {
|
|
108
|
+
...isRecord(options) ? options : {},
|
|
109
|
+
frontendTools
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
return frontendTools;
|
|
114
|
+
};
|
|
115
|
+
const findCurrentFrontendTool = async (ctx, toolId, sessionId) => {
|
|
116
|
+
const tools = await listCurrentFrontendTools(ctx, sessionId);
|
|
117
|
+
return tools.find((tool) => tool.id === toolId);
|
|
118
|
+
};
|
|
119
|
+
const shouldAutoExecuteFrontendTool = (tools, args) => {
|
|
120
|
+
var _a;
|
|
121
|
+
if (!isRecord(args) || typeof args.toolId !== "string") {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return ((_a = tools.find((tool) => tool.id === args.toolId)) == null ? void 0 : _a.permission) === "ALLOW";
|
|
125
|
+
};
|
|
126
|
+
const prepareToolsForFrontendConversation = (tools, frontendTools) => {
|
|
127
|
+
if (!frontendTools.length) {
|
|
128
|
+
return tools.filter(
|
|
129
|
+
(tool) => tool.definition.name !== import_frontend_tools.LOAD_FRONTEND_TOOL_NAME && tool.definition.name !== import_frontend_tools.EXECUTE_FRONTEND_TOOL_NAME
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
const catalog = frontendTools.map(({ id, name, title, description }) => ({ id, name, title, description }));
|
|
133
|
+
const toolIds = frontendTools.map((tool) => tool.id);
|
|
134
|
+
const toolIdSchema = import_zod.z.enum(toolIds).describe(`Use an exact tool id from this catalog: ${JSON.stringify(catalog)}`);
|
|
135
|
+
return tools.map((tool) => {
|
|
136
|
+
if (tool.definition.name !== import_frontend_tools.LOAD_FRONTEND_TOOL_NAME && tool.definition.name !== import_frontend_tools.EXECUTE_FRONTEND_TOOL_NAME) {
|
|
137
|
+
return tool;
|
|
138
|
+
}
|
|
139
|
+
const isLoader = tool.definition.name === import_frontend_tools.LOAD_FRONTEND_TOOL_NAME;
|
|
140
|
+
return {
|
|
141
|
+
...tool,
|
|
142
|
+
definition: {
|
|
143
|
+
...tool.definition,
|
|
144
|
+
description: `${tool.definition.description}
|
|
145
|
+
|
|
146
|
+
frontendToolCatalog: ${JSON.stringify(catalog)}`,
|
|
147
|
+
schema: isLoader ? import_zod.z.object({ toolId: toolIdSchema }) : import_zod.z.object({
|
|
148
|
+
toolId: toolIdSchema,
|
|
149
|
+
args: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).default({})
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
const readFrontendToolResult = (ctx, toolCallId) => {
|
|
156
|
+
var _a, _b, _c;
|
|
157
|
+
const toolCallResults = (_c = (_b = (_a = ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.values) == null ? void 0 : _c.toolCallResults;
|
|
158
|
+
const result = Array.isArray(toolCallResults) ? toolCallResults.find(
|
|
159
|
+
(item) => isRecord(item) && item.id === toolCallId && "result" in item
|
|
160
|
+
) : void 0;
|
|
161
|
+
return result ? { provided: true, value: result.result } : void 0;
|
|
162
|
+
};
|
|
163
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
164
|
+
0 && (module.exports = {
|
|
165
|
+
extractFrontendToolManifests,
|
|
166
|
+
findCurrentFrontendTool,
|
|
167
|
+
listCurrentFrontendTools,
|
|
168
|
+
prepareToolsForFrontendConversation,
|
|
169
|
+
readFrontendToolResult,
|
|
170
|
+
shouldAutoExecuteFrontendTool
|
|
171
|
+
});
|
|
@@ -41,6 +41,7 @@ __export(work_context_handler_exports, {
|
|
|
41
41
|
module.exports = __toCommonJS(work_context_handler_exports);
|
|
42
42
|
var import_utils = require("@nocobase/utils");
|
|
43
43
|
var import_lodash = __toESM(require("lodash"));
|
|
44
|
+
const MODEL_EXCLUDED_FIELDS = /* @__PURE__ */ new Set(["frontendTools"]);
|
|
44
45
|
const createWorkContextHandler = (plugin) => new WorkContextHandlerImpl(plugin);
|
|
45
46
|
class WorkContextHandlerImpl {
|
|
46
47
|
constructor(plugin) {
|
|
@@ -82,11 +83,17 @@ class WorkContextHandlerImpl {
|
|
|
82
83
|
if (!contextItem) {
|
|
83
84
|
return "";
|
|
84
85
|
}
|
|
85
|
-
const
|
|
86
|
+
const modelContext = this.excludeInternalFields(contextItem);
|
|
87
|
+
const { resolve } = this.strategies.get(modelContext.type) ?? {};
|
|
86
88
|
if (resolve) {
|
|
87
|
-
return await resolve(ctx,
|
|
89
|
+
return await resolve(ctx, modelContext);
|
|
88
90
|
}
|
|
89
|
-
return await ((_b = (_a = this.defaultStrategy).resolve) == null ? void 0 : _b.call(_a, ctx,
|
|
91
|
+
return await ((_b = (_a = this.defaultStrategy).resolve) == null ? void 0 : _b.call(_a, ctx, modelContext));
|
|
92
|
+
}
|
|
93
|
+
excludeInternalFields(contextItem) {
|
|
94
|
+
return Object.fromEntries(
|
|
95
|
+
Object.entries(contextItem).filter(([field]) => !MODEL_EXCLUDED_FIELDS.has(field))
|
|
96
|
+
);
|
|
90
97
|
}
|
|
91
98
|
}
|
|
92
99
|
const Stringify = (_plugin) => async (_ctx, contextItem) => {
|
package/dist/server/plugin.d.ts
CHANGED
|
@@ -62,6 +62,7 @@ export declare class PluginAIServer extends Plugin {
|
|
|
62
62
|
get repositories(): {
|
|
63
63
|
aiContextDatasources: import("@nocobase/database").Repository<any, any>;
|
|
64
64
|
};
|
|
65
|
+
private registerAIFileAccessAuthorizer;
|
|
65
66
|
get fileManager(): PluginFileManagerServer;
|
|
66
67
|
private repository;
|
|
67
68
|
}
|
package/dist/server/plugin.js
CHANGED
|
@@ -56,6 +56,7 @@ var import_ai_employees_manager = require("./ai-employees/ai-employees-manager")
|
|
|
56
56
|
var import_ai_conversations = require("./ai-employees/ai-conversations");
|
|
57
57
|
var import_snowflake = __toESM(require("./snowflake"));
|
|
58
58
|
var aiEmployeeActions = __toESM(require("./resource/aiEmployees"));
|
|
59
|
+
var llmServiceActions = __toESM(require("./resource/llmServices"));
|
|
59
60
|
var import_google_genai = require("./llm-providers/google-genai");
|
|
60
61
|
var import_ai_employee = require("./workflow/triggers/ai-employee");
|
|
61
62
|
var import_tools = require("./tools");
|
|
@@ -169,6 +170,7 @@ class PluginAIServer extends import_server.Plugin {
|
|
|
169
170
|
this.defineResources();
|
|
170
171
|
this.registerMcpClientEvents();
|
|
171
172
|
this.setPermissions();
|
|
173
|
+
this.registerAIFileAccessAuthorizer();
|
|
172
174
|
this.registerWorkflow();
|
|
173
175
|
this.registerWorkContextResolveStrategy();
|
|
174
176
|
(0, import_employee.registerAIEmployeeTaskNotification)(this);
|
|
@@ -235,6 +237,9 @@ class PluginAIServer extends import_server.Plugin {
|
|
|
235
237
|
Object.entries(aiEmployeeActions).forEach(([name, action]) => {
|
|
236
238
|
this.app.resourceManager.registerActionHandler(`aiEmployees:${name}`, action);
|
|
237
239
|
});
|
|
240
|
+
Object.entries(llmServiceActions).forEach(([name, action]) => {
|
|
241
|
+
this.app.resourceManager.registerActionHandler(`llmServices:${name}`, action);
|
|
242
|
+
});
|
|
238
243
|
}
|
|
239
244
|
registerMcpClientEvents() {
|
|
240
245
|
this.db.on("aiMcpClients.afterCreate", (model, { transaction } = {}) => {
|
|
@@ -370,6 +375,26 @@ class PluginAIServer extends import_server.Plugin {
|
|
|
370
375
|
aiContextDatasources: this.repository("aiContextDatasources")
|
|
371
376
|
};
|
|
372
377
|
}
|
|
378
|
+
registerAIFileAccessAuthorizer() {
|
|
379
|
+
this.fileManager.registerFileAccessAuthorizer({
|
|
380
|
+
name: "ai-files",
|
|
381
|
+
authorize: async (ctx, params) => {
|
|
382
|
+
var _a;
|
|
383
|
+
const currentUserId = (_a = ctx.state.currentUser) == null ? void 0 : _a.id;
|
|
384
|
+
if (params.dataSourceKey !== "main" || params.collectionName !== "aiFiles" || !currentUserId) {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
const file = await ctx.db.getRepository("aiFiles").findOne({
|
|
388
|
+
filter: {
|
|
389
|
+
id: params.id,
|
|
390
|
+
createdById: currentUserId
|
|
391
|
+
},
|
|
392
|
+
fields: ["id"]
|
|
393
|
+
});
|
|
394
|
+
return Boolean(file);
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
}
|
|
373
398
|
get fileManager() {
|
|
374
399
|
return this.app.pm.get("file-manager");
|
|
375
400
|
}
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { Context, Next } from '@nocobase/actions';
|
|
10
|
+
import { Model } from '@nocobase/database';
|
|
11
|
+
export declare function isAIEmployeeEnabled(employee: Model | null | undefined): boolean;
|
|
10
12
|
declare function loginInCheck(ctx: Context, next: Next): Promise<never>;
|
|
11
13
|
declare const _default: {
|
|
12
14
|
name: string;
|
|
@@ -36,7 +36,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
37
|
var aiConversations_exports = {};
|
|
38
38
|
__export(aiConversations_exports, {
|
|
39
|
-
default: () => aiConversations_default
|
|
39
|
+
default: () => aiConversations_default,
|
|
40
|
+
isAIEmployeeEnabled: () => isAIEmployeeEnabled
|
|
40
41
|
});
|
|
41
42
|
module.exports = __toCommonJS(aiConversations_exports);
|
|
42
43
|
var import_actions = __toESM(require("@nocobase/actions"));
|
|
@@ -44,6 +45,8 @@ var import_database = require("@nocobase/database");
|
|
|
44
45
|
var import_utils = require("../utils");
|
|
45
46
|
var import_ai_employee = require("../ai-employees/ai-employee");
|
|
46
47
|
var import_ai_chat_conversation = require("../manager/ai-chat-conversation");
|
|
48
|
+
var import_frontend_tools = require("../../common/frontend-tools");
|
|
49
|
+
var import_frontend_tools2 = require("../frontend-tools");
|
|
47
50
|
async function getAIEmployee(ctx, username) {
|
|
48
51
|
var _a;
|
|
49
52
|
const filter = {
|
|
@@ -57,6 +60,10 @@ async function getAIEmployee(ctx, username) {
|
|
|
57
60
|
});
|
|
58
61
|
return employee;
|
|
59
62
|
}
|
|
63
|
+
function isAIEmployeeEnabled(employee) {
|
|
64
|
+
var _a;
|
|
65
|
+
return ((_a = employee == null ? void 0 : employee.get) == null ? void 0 : _a.call(employee, "enabled")) !== false;
|
|
66
|
+
}
|
|
60
67
|
function setupSSEHeaders(ctx) {
|
|
61
68
|
ctx.set({
|
|
62
69
|
"Content-Type": "text/event-stream",
|
|
@@ -142,12 +149,14 @@ var aiConversations_default = {
|
|
|
142
149
|
var _a;
|
|
143
150
|
const userId = (_a = ctx.auth) == null ? void 0 : _a.user.id;
|
|
144
151
|
const filter = ctx.action.params.filter || {};
|
|
152
|
+
const scope = ctx.action.params.scope;
|
|
145
153
|
ctx.action.mergeParams({
|
|
146
154
|
filter: {
|
|
147
155
|
...filter,
|
|
148
156
|
userId,
|
|
149
157
|
from: filter.from ?? "main-agent",
|
|
150
|
-
category: "chat"
|
|
158
|
+
category: "chat",
|
|
159
|
+
...typeof scope === "string" && scope ? { scope } : {}
|
|
151
160
|
}
|
|
152
161
|
});
|
|
153
162
|
return import_actions.default.list(ctx, next);
|
|
@@ -197,15 +206,20 @@ var aiConversations_default = {
|
|
|
197
206
|
var _a;
|
|
198
207
|
const plugin = ctx.app.pm.get("ai");
|
|
199
208
|
const userId = (_a = ctx.auth) == null ? void 0 : _a.user.id;
|
|
200
|
-
const { aiEmployee, systemMessage, skillSettings, conversationSettings, modelSettings } = ctx.action.params.values || {};
|
|
209
|
+
const { aiEmployee, systemMessage, skillSettings, conversationSettings, modelSettings, scope } = ctx.action.params.values || {};
|
|
210
|
+
const normalizedScope = typeof scope === "string" ? scope : void 0;
|
|
201
211
|
const employee = await getAIEmployee(ctx, aiEmployee.username);
|
|
202
212
|
if (!employee) {
|
|
203
213
|
ctx.throw(400, "AI employee not found");
|
|
204
214
|
}
|
|
215
|
+
if (!isAIEmployeeEnabled(employee)) {
|
|
216
|
+
ctx.throw(400, "AI employee is disabled");
|
|
217
|
+
}
|
|
205
218
|
try {
|
|
206
219
|
ctx.body = await plugin.aiConversationsManager.create({
|
|
207
220
|
userId,
|
|
208
221
|
aiEmployee,
|
|
222
|
+
scope: normalizedScope,
|
|
209
223
|
options: {
|
|
210
224
|
systemMessage,
|
|
211
225
|
skillSettings,
|
|
@@ -672,6 +686,17 @@ var aiConversations_default = {
|
|
|
672
686
|
if (!(toolCalls == null ? void 0 : toolCalls.length)) {
|
|
673
687
|
ctx.throw(400);
|
|
674
688
|
}
|
|
689
|
+
const selectedToolCall = toolCalls.find((toolCall2) => toolCall2.id === toolCallId);
|
|
690
|
+
if (!selectedToolCall) {
|
|
691
|
+
ctx.throw(400);
|
|
692
|
+
}
|
|
693
|
+
if (selectedToolCall.name === import_frontend_tools.EXECUTE_FRONTEND_TOOL_NAME) {
|
|
694
|
+
const toolId = isRecord(selectedToolCall.args) ? selectedToolCall.args.toolId : void 0;
|
|
695
|
+
const frontendTool = typeof toolId === "string" ? await (0, import_frontend_tools2.findCurrentFrontendTool)(ctx, toolId, message.sessionId) : void 0;
|
|
696
|
+
if (!frontendTool) {
|
|
697
|
+
ctx.throw(400, ctx.t("Frontend tool is unavailable"));
|
|
698
|
+
}
|
|
699
|
+
}
|
|
675
700
|
const aiToolMessagesModel = ctx.db.getModel("aiToolMessages");
|
|
676
701
|
const toolCall = await aiToolMessagesModel.findOne({
|
|
677
702
|
where: { sessionId: message.sessionId, messageId: message.messageId, toolCallId }
|
|
@@ -715,6 +740,7 @@ var aiConversations_default = {
|
|
|
715
740
|
toolCall2.auto = toolMessage == null ? void 0 : toolMessage.auto;
|
|
716
741
|
toolCall2.status = toolMessage == null ? void 0 : toolMessage.status;
|
|
717
742
|
toolCall2.content = toolMessage == null ? void 0 : toolMessage.content;
|
|
743
|
+
toolCall2.userDecision = toolMessage == null ? void 0 : toolMessage.userDecision;
|
|
718
744
|
toolCall2.execution = tools == null ? void 0 : tools.execution;
|
|
719
745
|
toolCall2.willInterrupt = (tools == null ? void 0 : tools.execution) === "frontend" || (toolMessage == null ? void 0 : toolMessage.auto) === false;
|
|
720
746
|
toolCall2.defaultPermission = tools == null ? void 0 : tools.defaultPermission;
|
|
@@ -801,3 +827,7 @@ var aiConversations_default = {
|
|
|
801
827
|
}
|
|
802
828
|
}
|
|
803
829
|
};
|
|
830
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
831
|
+
0 && (module.exports = {
|
|
832
|
+
isAIEmployeeEnabled
|
|
833
|
+
});
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { Context, Next } from '@nocobase/actions';
|
|
10
|
+
export declare const create: (ctx: Context, next: Next) => Promise<void>;
|
|
11
|
+
export declare const update: (ctx: Context, next: Next) => Promise<void>;
|
|
10
12
|
export declare const list: (ctx: Context, next: Next) => Promise<void>;
|
|
11
13
|
export declare const listByUser: (ctx: Context, next: Next) => Promise<any>;
|
|
12
14
|
export declare const updateUserPrompt: (ctx: Context, next: Next) => Promise<any>;
|
|
@@ -36,16 +36,76 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
37
|
var aiEmployees_exports = {};
|
|
38
38
|
__export(aiEmployees_exports, {
|
|
39
|
+
create: () => create,
|
|
39
40
|
getTemplates: () => getTemplates,
|
|
40
41
|
list: () => list,
|
|
41
42
|
listByUser: () => listByUser,
|
|
43
|
+
update: () => update,
|
|
42
44
|
updateUserPrompt: () => updateUserPrompt
|
|
43
45
|
});
|
|
44
46
|
module.exports = __toCommonJS(aiEmployees_exports);
|
|
45
47
|
var import_actions = __toESM(require("@nocobase/actions"));
|
|
48
|
+
var import_database = require("@nocobase/database");
|
|
46
49
|
var templates = __toESM(require("../ai-employees/templates"));
|
|
47
50
|
var import_lodash = __toESM(require("lodash"));
|
|
48
51
|
var import_ai_feature_manager = require("../manager/ai-feature-manager");
|
|
52
|
+
var import_error_codes = require("../../common/error-codes");
|
|
53
|
+
var import_ai_employee_validation = require("../../common/ai-employee-validation");
|
|
54
|
+
const isUniqueConstraintError = (error) => error instanceof import_database.UniqueConstraintError || typeof error === "object" && error !== null && "name" in error && error.name === "SequelizeUniqueConstraintError";
|
|
55
|
+
const throwUsernameConflict = (ctx) => ctx.throw(409, {
|
|
56
|
+
code: import_error_codes.AI_EMPLOYEE_USERNAME_CONFLICT,
|
|
57
|
+
message: ctx.t("Username already exists")
|
|
58
|
+
});
|
|
59
|
+
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
60
|
+
const validateAndNormalizeProfileValues = (ctx) => {
|
|
61
|
+
const values = ctx.action.params.values;
|
|
62
|
+
if (!isRecord(values)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if ("username" in values) {
|
|
66
|
+
if (typeof values.username !== "string" || !(0, import_ai_employee_validation.isValidAIEmployeeUsername)(values.username)) {
|
|
67
|
+
ctx.throw(400, {
|
|
68
|
+
code: import_error_codes.AI_EMPLOYEE_USERNAME_INVALID,
|
|
69
|
+
message: ctx.t("Use 1-64 letters, numbers, underscores, or hyphens.")
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
values.username = (0, import_ai_employee_validation.normalizeAIEmployeeName)(values.username);
|
|
73
|
+
}
|
|
74
|
+
if ("nickname" in values) {
|
|
75
|
+
if (typeof values.nickname !== "string" || !(0, import_ai_employee_validation.isValidAIEmployeeNickname)(values.nickname)) {
|
|
76
|
+
ctx.throw(400, {
|
|
77
|
+
code: import_error_codes.AI_EMPLOYEE_NICKNAME_INVALID,
|
|
78
|
+
message: ctx.t("Use 1-64 letters, numbers, spaces, or . _ - ' ( ) & \xB7.")
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
values.nickname = (0, import_ai_employee_validation.normalizeAIEmployeeName)(values.nickname);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const create = async (ctx, next) => {
|
|
85
|
+
var _a;
|
|
86
|
+
validateAndNormalizeProfileValues(ctx);
|
|
87
|
+
const username = (_a = ctx.action.params.values) == null ? void 0 : _a.username;
|
|
88
|
+
if (typeof username === "string") {
|
|
89
|
+
const existingEmployee = await ctx.db.getRepository("aiEmployees").findOne({
|
|
90
|
+
filter: { username }
|
|
91
|
+
});
|
|
92
|
+
if (existingEmployee) {
|
|
93
|
+
throwUsernameConflict(ctx);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
await import_actions.default.create(ctx, next);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (isUniqueConstraintError(error)) {
|
|
100
|
+
throwUsernameConflict(ctx);
|
|
101
|
+
}
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const update = async (ctx, next) => {
|
|
106
|
+
validateAndNormalizeProfileValues(ctx);
|
|
107
|
+
await import_actions.default.update(ctx, next);
|
|
108
|
+
};
|
|
49
109
|
const list = async (ctx, next) => {
|
|
50
110
|
var _a, _b;
|
|
51
111
|
const { paginate } = ctx.action.params || {};
|
|
@@ -227,8 +287,10 @@ const getTemplates = async (ctx, next) => {
|
|
|
227
287
|
};
|
|
228
288
|
// Annotate the CommonJS export names for ESM import in node:
|
|
229
289
|
0 && (module.exports = {
|
|
290
|
+
create,
|
|
230
291
|
getTemplates,
|
|
231
292
|
list,
|
|
232
293
|
listByUser,
|
|
294
|
+
update,
|
|
233
295
|
updateUserPrompt
|
|
234
296
|
});
|
|
@@ -129,7 +129,7 @@ const aiWorkflowTasks = {
|
|
|
129
129
|
await next();
|
|
130
130
|
},
|
|
131
131
|
getBySession: async (ctx, next) => {
|
|
132
|
-
var _a, _b, _c, _d, _e;
|
|
132
|
+
var _a, _b, _c, _d, _e, _f;
|
|
133
133
|
const userId = (_a = ctx.auth) == null ? void 0 : _a.user.id;
|
|
134
134
|
if (!userId) {
|
|
135
135
|
return ctx.throw(403);
|
|
@@ -158,12 +158,20 @@ const aiWorkflowTasks = {
|
|
|
158
158
|
id: task.nodeId
|
|
159
159
|
}
|
|
160
160
|
});
|
|
161
|
+
const conversation = await ctx.db.getRepository("aiConversations").findOne({
|
|
162
|
+
filter: {
|
|
163
|
+
sessionId
|
|
164
|
+
},
|
|
165
|
+
appends: ["aiEmployee"]
|
|
166
|
+
});
|
|
167
|
+
const aiEmployee = conversation == null ? void 0 : conversation.aiEmployee;
|
|
161
168
|
const readonly = task.status !== "pending_approval" || task.acceptedUserId !== userId;
|
|
162
169
|
ctx.body = {
|
|
163
170
|
...((_c = task == null ? void 0 : task.toJSON) == null ? void 0 : _c.call(task)) ?? task,
|
|
164
171
|
read: (usersAiWorkflowTasks == null ? void 0 : usersAiWorkflowTasks.read) ?? true,
|
|
165
172
|
config: (node == null ? void 0 : node.config) ?? null,
|
|
166
173
|
structuredOutputSchema: ((_e = (_d = node == null ? void 0 : node.config) == null ? void 0 : _d.structuredOutput) == null ? void 0 : _e.schema) ?? null,
|
|
174
|
+
aiEmployee: ((_f = aiEmployee == null ? void 0 : aiEmployee.toJSON) == null ? void 0 : _f.call(aiEmployee)) ?? aiEmployee ?? null,
|
|
167
175
|
readonly
|
|
168
176
|
};
|
|
169
177
|
await next();
|
|
@@ -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
|
+
import { Context, Next } from '@nocobase/actions';
|
|
10
|
+
export declare const create: (ctx: Context, next: Next) => Promise<void>;
|
|
11
|
+
export declare const update: (ctx: Context, next: Next) => Promise<void>;
|