@nocobase/plugin-ai 2.3.0-alpha.1 → 2.3.0-beta.10
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-dev/watermark-plugin.md +2 -0
- 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/rag.md +43 -13
- 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 +2 -0
- package/dist/ai/docs/nocobase/api/cli/api/resource/create.md +4 -3
- 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/file-preview/index.md +44 -3
- package/dist/ai/docs/nocobase/file-manager/stable-url.md +1 -1
- package/dist/ai/docs/nocobase/file-manager/storage/aliyun-oss.md +100 -3
- package/dist/ai/docs/nocobase/file-manager/storage/index.md +76 -26
- package/dist/ai/docs/nocobase/file-manager/storage/local.md +4 -2
- package/dist/ai/docs/nocobase/file-manager/storage/s3-pro.md +58 -7
- package/dist/ai/docs/nocobase/get-started/installation/docker-nginx.mdx +4 -1
- package/dist/ai/docs/nocobase/get-started/installation/docker.mdx +2 -0
- package/dist/ai/docs/nocobase/get-started/installation/env.md +13 -1
- package/dist/ai/docs/nocobase/nocobase-cli/production/reverse-proxy/caddy.md +28 -5
- package/dist/ai/docs/nocobase/nocobase-cli/production/reverse-proxy/nginx.md +25 -0
- package/dist/ai/docs/nocobase/ops-management/migration-manager/built-in-tables.md +1 -2
- package/dist/ai/docs/nocobase/plugin-development/build.md +10 -4
- package/dist/ai/docs/nocobase/plugin-development/client/appendix/faq.md +1 -1
- package/dist/ai/docs/nocobase/plugin-development/client/examples/custom-action.md +2 -0
- package/dist/ai/docs/nocobase/plugin-development/client/examples/custom-block.md +2 -0
- package/dist/ai/docs/nocobase/plugin-development/client/examples/custom-field.md +2 -0
- package/dist/ai/docs/nocobase/plugin-development/client/examples/fullstack-plugin.md +2 -0
- package/dist/ai/docs/nocobase/plugin-development/client/examples/settings-page.md +2 -0
- package/dist/ai/docs/nocobase/plugin-development/common/i18n.md +3 -3
- package/dist/ai/docs/nocobase/plugin-development/server/cache.md +1 -1
- package/dist/ai/docs/nocobase/plugin-development/server/collections.md +0 -6
- package/dist/ai/docs/nocobase/plugin-development/server/command.md +2 -2
- package/dist/ai/docs/nocobase/plugin-development/server/context.md +2 -2
- package/dist/ai/docs/nocobase/plugin-development/server/i18n.md +4 -4
- package/dist/ai/docs/nocobase/plugin-development/write-your-first-plugin.md +91 -43
- package/dist/ai/docs/nocobase/runjs/context/ai.md +194 -4
- package/dist/ai/docs/nocobase/security/guide.md +17 -2
- package/dist/ai/docs/nocobase/users-permissions/sync/index.md +8 -1
- package/dist/ai/docs/nocobase/users-permissions/sync/sources/dingtalk.md +138 -0
- package/dist/ai/docs/nocobase/users-permissions/sync/sources/ldap.md +87 -0
- package/dist/ai/docs/nocobase/workflow/nodes/javascript.md +21 -1
- 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/knowledge-base-retrieve.js +3 -1
- package/dist/ai/tools/loadFrontendTool.d.ts +10 -0
- package/dist/ai/tools/loadFrontendTool.js +99 -0
- package/dist/client/244.aeb24ce76c510b34.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/705.1d735e63c25f66a8.js +10 -0
- package/dist/client/index.d.ts +1 -3
- package/dist/client/index.js +8 -8
- package/dist/client-v2/244.ee9ec45eac0eb99f.js +10 -0
- package/dist/client-v2/420.a5b929a5e7f330be.js +10 -0
- package/dist/client-v2/681.6890caa389564ff7.js +10 -0
- package/dist/client-v2/705.00c101bef403fb44.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/reasoning-stream.d.ts +10 -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 -33
- 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/{ai-employees/chatbox/components/DebugPanel.d.ts → block/ai-chat-box/components/AIChatBoxCoreView.d.ts} +1 -1
- 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-providers/forms.d.ts +2 -0
- package/dist/client-v2/llm-providers/index.d.ts +1 -0
- 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 +8 -0
- package/dist/client-v2/pages/EmployeesPage.d.ts +12 -0
- package/dist/client-v2/pages/LLMServicesPage.d.ts +9 -4
- package/dist/client-v2/repositories/AIConfigRepository.d.ts +2 -0
- package/dist/client-v2/runjs/registerAIEmployeeRunJSFacade.d.ts +1 -0
- package/dist/client-v2/workflow/types.d.ts +1 -0
- package/dist/collections/ai-employees.d.ts +1 -0
- package/dist/collections/ai-employees.js +1 -0
- package/dist/common/ai-employee-validation.d.ts +17 -0
- package/dist/common/ai-employee-validation.js +67 -0
- package/dist/common/error-codes.d.ts +14 -0
- package/dist/common/error-codes.js +51 -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 +19 -17
- package/dist/locale/de-DE.json +2 -1
- package/dist/locale/en-US.json +87 -5
- package/dist/locale/es-ES.json +2 -1
- package/dist/locale/fr-FR.json +2 -1
- package/dist/locale/hu-HU.json +2 -1
- package/dist/locale/id-ID.json +2 -1
- package/dist/locale/it-IT.json +2 -1
- package/dist/locale/ja-JP.json +2 -1
- package/dist/locale/ko-KR.json +2 -1
- package/dist/locale/nl-NL.json +2 -1
- package/dist/locale/pt-BR.json +2 -1
- package/dist/locale/ru-RU.json +2 -1
- package/dist/locale/tr-TR.json +2 -1
- package/dist/locale/uk-UA.json +2 -1
- package/dist/locale/vi-VN.json +2 -1
- package/dist/locale/zh-CN.json +87 -5
- package/dist/locale/zh-TW.json +2 -1
- 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 +32 -2
- package/dist/server/ai-employees/ai-employee.js +367 -79
- package/dist/server/ai-employees/ai-knowledge-base.d.ts +21 -1
- package/dist/server/ai-employees/ai-knowledge-base.js +87 -12
- package/dist/server/ai-employees/middleware/conversation.js +28 -22
- package/dist/server/ai-employees/middleware/index.d.ts +1 -0
- package/dist/server/ai-employees/middleware/index.js +2 -0
- package/dist/server/ai-employees/middleware/tool-result-integrity.d.ts +22 -0
- package/dist/server/ai-employees/middleware/tool-result-integrity.js +211 -0
- package/dist/server/ai-employees/reasoning-stream-state.d.ts +23 -0
- package/dist/server/ai-employees/reasoning-stream-state.js +63 -0
- package/dist/server/collections/ai-conversations.js +5 -0
- package/dist/server/document-loader/constants.js +1 -1
- package/dist/server/features/knowledge-base.d.ts +2 -0
- package/dist/server/frontend-tools.d.ts +25 -0
- package/dist/server/frontend-tools.js +171 -0
- package/dist/server/llm-providers/common/reasoning.js +18 -10
- package/dist/server/llm-providers/deepseek/index.d.ts +10 -0
- package/dist/server/llm-providers/deepseek/index.js +32 -0
- package/dist/server/llm-providers/deepseek/provider.d.ts +57 -0
- package/dist/server/llm-providers/deepseek/provider.js +320 -0
- package/dist/server/llm-providers/deepseek/reasoning.d.ts +83 -0
- package/dist/server/llm-providers/deepseek/reasoning.js +285 -0
- package/dist/server/llm-providers/mistral.d.ts +1 -1
- package/dist/server/llm-providers/provider.d.ts +1 -0
- package/dist/server/llm-providers/provider.js +3 -0
- package/dist/server/llm-providers/shengsuanyun.d.ts +29 -0
- package/dist/server/llm-providers/shengsuanyun.js +114 -0
- package/dist/server/manager/ai-feature-manager.js +1 -1
- package/dist/server/manager/ai-manager.d.ts +3 -0
- package/dist/server/manager/ai-manager.js +7 -2
- package/dist/server/manager/work-context-handler.js +10 -3
- package/dist/server/migrations/20260501000000-ai-employee-knowledge-base-retrieval-strategy.d.ts +14 -0
- package/dist/server/migrations/20260501000000-ai-employee-knowledge-base-retrieval-strategy.js +49 -0
- package/dist/server/plugin.d.ts +1 -0
- package/dist/server/plugin.js +31 -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 +96 -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/ai-message.type.d.ts +4 -0
- package/dist/server/types/knowledge-base.type.d.ts +8 -3
- package/dist/server/workflow/nodes/employee/files.d.ts +1 -1
- package/dist/server/workflow/nodes/employee/files.js +48 -1
- package/dist/server/workflow/nodes/employee/index.js +7 -2
- package/dist/server/workflow/nodes/employee/types.d.ts +1 -0
- 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 +1617 -0
- package/dist/swagger/index.js +62 -0
- package/dist/swagger/llm.d.ts +563 -0
- package/dist/swagger/llm.js +255 -0
- package/dist/swagger/schemas.d.ts +757 -0
- package/dist/swagger/schemas.js +392 -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/705.1d10027ff8cfdf79.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
- package/dist/client-v2/debug-logger.d.ts +0 -52
- package/dist/server/llm-providers/deepseek.d.ts +0 -40
- package/dist/server/llm-providers/deepseek.js +0 -174
|
@@ -45,6 +45,7 @@ var import_utils = require("../utils");
|
|
|
45
45
|
var import_prompts = require("./prompts");
|
|
46
46
|
var import_lodash = __toESM(require("lodash"));
|
|
47
47
|
var import_ai_chat_conversation = require("../manager/ai-chat-conversation");
|
|
48
|
+
var import_ai_knowledge_base = require("./ai-knowledge-base");
|
|
48
49
|
var import_middleware = require("./middleware");
|
|
49
50
|
var import_ai = require("@nocobase/ai");
|
|
50
51
|
var import_checkpoints = require("./checkpoints");
|
|
@@ -56,12 +57,17 @@ var import_base = require("@langchain/core/callbacks/base");
|
|
|
56
57
|
var import_shared = require("../../ai/tools/sub-agents/shared");
|
|
57
58
|
var import_tool_call_sanitizer = require("./tool-call-sanitizer");
|
|
58
59
|
var import_attachments = require("../attachments");
|
|
60
|
+
var import_frontend_tools = require("../../common/frontend-tools");
|
|
61
|
+
var import_frontend_tools2 = require("../frontend-tools");
|
|
62
|
+
var import_reasoning_stream_state = require("./reasoning-stream-state");
|
|
63
|
+
const ABORTED_TOOL_CALL_CONTENT = "The tool call was interrupted because the conversation was aborted.";
|
|
59
64
|
class AIEmployee {
|
|
60
65
|
sessionId;
|
|
61
66
|
from = "main-agent";
|
|
62
67
|
employee;
|
|
63
68
|
aiChatConversation;
|
|
64
69
|
skillSettings;
|
|
70
|
+
userMessageCount = 0;
|
|
65
71
|
plugin;
|
|
66
72
|
db;
|
|
67
73
|
ctx;
|
|
@@ -73,6 +79,7 @@ class AIEmployee {
|
|
|
73
79
|
tools;
|
|
74
80
|
inWorkflow;
|
|
75
81
|
streamCached;
|
|
82
|
+
static conversationPersistenceQueues = /* @__PURE__ */ new WeakMap();
|
|
76
83
|
constructor({
|
|
77
84
|
ctx,
|
|
78
85
|
employee,
|
|
@@ -122,6 +129,9 @@ class AIEmployee {
|
|
|
122
129
|
areToolsEnabled() {
|
|
123
130
|
return this.chatSettings.enableTools !== false;
|
|
124
131
|
}
|
|
132
|
+
getAIEmployeeRecord() {
|
|
133
|
+
return this.employee.toJSON();
|
|
134
|
+
}
|
|
125
135
|
async getFormatMessages(userMessages) {
|
|
126
136
|
const { provider } = await this.plugin.aiManager.getLLMService({
|
|
127
137
|
...this.model
|
|
@@ -204,6 +214,7 @@ class AIEmployee {
|
|
|
204
214
|
const { provider, model, service } = await this.plugin.aiManager.getLLMService({
|
|
205
215
|
...this.model
|
|
206
216
|
});
|
|
217
|
+
this.userMessageCount = (userMessages ?? []).filter((message) => message.role === "user").length;
|
|
207
218
|
const { historyMessages, tools, resolvedTools, middleware, config, state } = await this.initSession({
|
|
208
219
|
messageId,
|
|
209
220
|
provider,
|
|
@@ -410,39 +421,52 @@ class AIEmployee {
|
|
|
410
421
|
async processChatStream(stream, options) {
|
|
411
422
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
412
423
|
const aiMessageIdMap = /* @__PURE__ */ new Map();
|
|
424
|
+
const persistedAIMessageIdMap = /* @__PURE__ */ new Map();
|
|
413
425
|
const { signal, providerName, llmService, model, provider, responseMetadata, allowEmpty = false } = options;
|
|
414
|
-
|
|
426
|
+
const reasoningState = new import_reasoning_stream_state.ReasoningStreamState();
|
|
427
|
+
const stopReasoning = async (conversation) => {
|
|
428
|
+
if (reasoningState.stop(conversation)) {
|
|
429
|
+
await this.protocol.with(conversation).stopReasoning();
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
const stopAllReasoning = async () => {
|
|
433
|
+
for (const conversation of reasoningState.drain()) {
|
|
434
|
+
await this.protocol.with(conversation).stopReasoning();
|
|
435
|
+
}
|
|
436
|
+
};
|
|
415
437
|
let gathered;
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
438
|
+
let abortFinalization;
|
|
439
|
+
signal.addEventListener(
|
|
440
|
+
"abort",
|
|
441
|
+
() => {
|
|
442
|
+
abortFinalization = (async () => {
|
|
443
|
+
try {
|
|
444
|
+
await stopAllReasoning();
|
|
445
|
+
if ((gathered == null ? void 0 : gathered.type) === "ai") {
|
|
446
|
+
await this.finalizeAbortedAIMessage({
|
|
447
|
+
aiMessage: gathered,
|
|
448
|
+
providerName,
|
|
449
|
+
provider,
|
|
450
|
+
llmService,
|
|
451
|
+
model,
|
|
452
|
+
knownMessageId: persistedAIMessageIdMap.get(gathered.id)
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
} catch (e) {
|
|
456
|
+
this.logger.error("Fail to save message after conversation abort", gathered);
|
|
457
|
+
} finally {
|
|
458
|
+
await this.aiConversationsRepo.update({
|
|
459
|
+
values: { llmActiveState: "idle", read: true },
|
|
460
|
+
filter: {
|
|
461
|
+
sessionId: this.sessionId
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
await this.streamCached.clear();
|
|
441
465
|
}
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
|
|
466
|
+
})();
|
|
467
|
+
},
|
|
468
|
+
{ once: true }
|
|
469
|
+
);
|
|
446
470
|
try {
|
|
447
471
|
const aiEmployeeConversation = {
|
|
448
472
|
sessionId: this.sessionId,
|
|
@@ -456,27 +480,27 @@ class AIEmployee {
|
|
|
456
480
|
const { currentConversation } = metadata;
|
|
457
481
|
if (chunk.type === "ai") {
|
|
458
482
|
gathered = gathered !== void 0 ? (0, import_stream.concat)(gathered, chunk) : chunk;
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
483
|
+
const reasoningContent = provider.parseReasoningContent(chunk);
|
|
484
|
+
if (reasoningContent) {
|
|
485
|
+
reasoningState.start(currentConversation);
|
|
486
|
+
await this.protocol.with(currentConversation).reasoning(reasoningContent);
|
|
487
|
+
}
|
|
488
|
+
const parsedContent = chunk.content ? provider.parseResponseChunk(chunk.content) : null;
|
|
489
|
+
if (parsedContent) {
|
|
490
|
+
await stopReasoning(currentConversation);
|
|
491
|
+
await this.protocol.with(currentConversation).content(parsedContent);
|
|
468
492
|
}
|
|
469
493
|
if ((_a = chunk.tool_call_chunks) == null ? void 0 : _a.length) {
|
|
494
|
+
await stopReasoning(currentConversation);
|
|
470
495
|
await this.protocol.with(currentConversation).toolCallChunks(chunk.tool_call_chunks);
|
|
471
496
|
}
|
|
472
497
|
const webSearch = provider.parseWebSearchAction(chunk);
|
|
473
498
|
if (webSearch == null ? void 0 : webSearch.length) {
|
|
499
|
+
await stopReasoning(currentConversation);
|
|
474
500
|
await this.protocol.with(currentConversation).webSearch(webSearch);
|
|
475
501
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
isReasoning = true;
|
|
479
|
-
await this.protocol.with(currentConversation).reasoning(reasoningContent);
|
|
502
|
+
if ((0, import_reasoning_stream_state.isReasoningFinishChunk)(chunk)) {
|
|
503
|
+
await stopReasoning(currentConversation);
|
|
480
504
|
}
|
|
481
505
|
}
|
|
482
506
|
} else if (mode === "updates") {
|
|
@@ -505,6 +529,7 @@ class AIEmployee {
|
|
|
505
529
|
if (chunks.action === "AfterAIMessageSaved") {
|
|
506
530
|
await this.streamCached.skipped();
|
|
507
531
|
aiMessageIdMap.set(currentConversation.sessionId, chunks.body.messageId);
|
|
532
|
+
persistedAIMessageIdMap.set(chunks.body.id, chunks.body.messageId);
|
|
508
533
|
const data = responseMetadata.get(chunks.body.id);
|
|
509
534
|
if (data) {
|
|
510
535
|
const savedMessage = await this.aiMessagesModel.findOne({
|
|
@@ -532,6 +557,7 @@ class AIEmployee {
|
|
|
532
557
|
}
|
|
533
558
|
}
|
|
534
559
|
} else if (chunks.action === "initToolCalls") {
|
|
560
|
+
await stopReasoning(currentConversation);
|
|
535
561
|
await this.protocol.with(currentConversation).toolCalls(chunks.body);
|
|
536
562
|
} else if (chunks.action === "beforeToolCall") {
|
|
537
563
|
const toolsMap = await this.getToolsMap();
|
|
@@ -593,12 +619,14 @@ class AIEmployee {
|
|
|
593
619
|
}
|
|
594
620
|
}
|
|
595
621
|
}
|
|
622
|
+
await stopAllReasoning();
|
|
596
623
|
if (this.protocol.statistics.sent === 0 && !signal.aborted && !allowEmpty) {
|
|
597
624
|
this.sendErrorResponse("Empty message");
|
|
598
625
|
return;
|
|
599
626
|
}
|
|
600
627
|
await this.protocol.with(aiEmployeeConversation).endStream();
|
|
601
628
|
} catch (err) {
|
|
629
|
+
await stopAllReasoning();
|
|
602
630
|
this.ctx.log.error(err);
|
|
603
631
|
if (err.name === "GraphRecursionError") {
|
|
604
632
|
this.sendSpecificError({ name: err.name, message: err.message });
|
|
@@ -606,6 +634,7 @@ class AIEmployee {
|
|
|
606
634
|
this.sendErrorResponse(provider.parseResponseError(err));
|
|
607
635
|
}
|
|
608
636
|
} finally {
|
|
637
|
+
await abortFinalization;
|
|
609
638
|
if (this.from === "main-agent") {
|
|
610
639
|
this.ctx.res.end();
|
|
611
640
|
}
|
|
@@ -687,7 +716,7 @@ Field: ${field.name}, Title: ${(_a = field.options.uiSchema) == null ? void 0 :
|
|
|
687
716
|
return message;
|
|
688
717
|
}
|
|
689
718
|
async getSystemPrompt(userMessages) {
|
|
690
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
719
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
691
720
|
if (this.systemPromptMode === "none") {
|
|
692
721
|
return "";
|
|
693
722
|
}
|
|
@@ -695,9 +724,16 @@ Field: ${field.name}, Title: ${(_a = field.options.uiSchema) == null ? void 0 :
|
|
|
695
724
|
if (this.systemPromptMode === "raw") {
|
|
696
725
|
return about;
|
|
697
726
|
}
|
|
727
|
+
const employee = this.getAIEmployeeRecord();
|
|
728
|
+
const knowledgeBaseManager = this.plugin.knowledgeBaseManager;
|
|
729
|
+
const knowledgeBaseEnabled = await knowledgeBaseManager.isEnabledKnowledgeBase(employee);
|
|
730
|
+
const roleNames = (0, import_ai_knowledge_base.getCurrentRoleNames)(this.ctx.state);
|
|
731
|
+
const hasAccessibleKnowledgeBase = knowledgeBaseEnabled ? await knowledgeBaseManager.hasAccessibleKnowledgeBase({ employee, roleNames }) : false;
|
|
732
|
+
const knowledgeBaseAccessDenied = knowledgeBaseEnabled && !hasAccessibleKnowledgeBase;
|
|
733
|
+
const knowledgeBaseOnDemand = knowledgeBaseEnabled && hasAccessibleKnowledgeBase && (0, import_ai_knowledge_base.normalizeKnowledgeBaseRetrievalStrategy)((_a = employee.knowledgeBase) == null ? void 0 : _a.retrievalStrategy) === "onDemand";
|
|
698
734
|
const userConfig = await this.db.getRepository("usersAiEmployees").findOne({
|
|
699
735
|
filter: {
|
|
700
|
-
userId: ((
|
|
736
|
+
userId: ((_b = this.ctx.auth) == null ? void 0 : _b.user.id) ?? 0,
|
|
701
737
|
aiEmployee: this.employee.username
|
|
702
738
|
}
|
|
703
739
|
});
|
|
@@ -722,17 +758,25 @@ ${workContextBackground.join("\n")}`;
|
|
|
722
758
|
${addSystemPrompt.map((it) => it.content).join("\n")}`;
|
|
723
759
|
}
|
|
724
760
|
let knowledgeBase;
|
|
725
|
-
|
|
726
|
-
const employee = this.employee.toJSON();
|
|
727
|
-
if (await knowledgeBaseManager.isEnabledKnowledgeBase(employee) && employee.knowledgeBasePrompt && (userMessages == null ? void 0 : userMessages.length)) {
|
|
761
|
+
if (knowledgeBaseEnabled && hasAccessibleKnowledgeBase && !knowledgeBaseOnDemand && (userMessages == null ? void 0 : userMessages.length)) {
|
|
728
762
|
const lastUserMessage = userMessages.filter((x) => x.role === "user").at(-1);
|
|
729
763
|
if (lastUserMessage) {
|
|
730
764
|
knowledgeBase = await knowledgeBaseManager.retrievePrompt({
|
|
731
765
|
employee,
|
|
732
|
-
query: lastUserMessage.content.content
|
|
766
|
+
query: lastUserMessage.content.content,
|
|
767
|
+
roleNames
|
|
733
768
|
});
|
|
734
769
|
}
|
|
735
770
|
}
|
|
771
|
+
const knowledgeBaseBackgroundPrompt = (0, import_ai_knowledge_base.getKnowledgeBaseBackgroundPrompt)({
|
|
772
|
+
accessDenied: knowledgeBaseAccessDenied,
|
|
773
|
+
onDemand: knowledgeBaseOnDemand,
|
|
774
|
+
preRetrieved: Boolean(knowledgeBase)
|
|
775
|
+
});
|
|
776
|
+
if (knowledgeBaseBackgroundPrompt) {
|
|
777
|
+
background = `${background}
|
|
778
|
+
${knowledgeBaseBackgroundPrompt}`;
|
|
779
|
+
}
|
|
736
780
|
const availableSkills = await this.getAvailableSkills();
|
|
737
781
|
const availableAIEmployees = await this.getAvailableAIEmployees();
|
|
738
782
|
const systemPrompt = (0, import_prompts.getSystemPrompt)({
|
|
@@ -746,8 +790,8 @@ ${addSystemPrompt.map((it) => it.content).join("\n")}`;
|
|
|
746
790
|
personal: userConfig == null ? void 0 : userConfig.prompt,
|
|
747
791
|
environment: {
|
|
748
792
|
database: this.db.sequelize.getDialect(),
|
|
749
|
-
locale: ((
|
|
750
|
-
currentDateTime: getCurrentDateTimeForPrompt((
|
|
793
|
+
locale: ((_d = (_c = this.ctx).getCurrentLocale) == null ? void 0 : _d.call(_c)) || "en-US",
|
|
794
|
+
currentDateTime: getCurrentDateTimeForPrompt((_f = (_e = this.ctx).getCurrentLocale) == null ? void 0 : _f.call(_e), getCurrentTimezone(this.ctx)),
|
|
751
795
|
timezone: getCurrentTimezone(this.ctx)
|
|
752
796
|
},
|
|
753
797
|
knowledgeBase,
|
|
@@ -755,7 +799,7 @@ ${addSystemPrompt.map((it) => it.content).join("\n")}`;
|
|
|
755
799
|
availableAIEmployees,
|
|
756
800
|
webSearch: this.webSearch
|
|
757
801
|
});
|
|
758
|
-
const { important } = ((
|
|
802
|
+
const { important } = ((_h = (_g = this.ctx.action) == null ? void 0 : _g.params) == null ? void 0 : _h.values) || {};
|
|
759
803
|
if (important === "GraphRecursionError") {
|
|
760
804
|
const importantPrompt = `<Important>You have already called tools multiple times and gathered sufficient information.
|
|
761
805
|
First, provide a summary based on the existing information. Do not call additional tools.
|
|
@@ -766,14 +810,179 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
766
810
|
}
|
|
767
811
|
}
|
|
768
812
|
// === Tool calls ===
|
|
813
|
+
async withLockedConversation(callback) {
|
|
814
|
+
const persistenceQueues = AIEmployee.conversationPersistenceQueues.get(this.db) ?? /* @__PURE__ */ new Map();
|
|
815
|
+
AIEmployee.conversationPersistenceQueues.set(this.db, persistenceQueues);
|
|
816
|
+
const previous = persistenceQueues.get(this.sessionId) ?? Promise.resolve();
|
|
817
|
+
let release;
|
|
818
|
+
const current = new Promise((resolve) => {
|
|
819
|
+
release = resolve;
|
|
820
|
+
});
|
|
821
|
+
persistenceQueues.set(this.sessionId, current);
|
|
822
|
+
await previous;
|
|
823
|
+
try {
|
|
824
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
825
|
+
try {
|
|
826
|
+
return await this.aiChatConversation.withTransaction(async (conversation, transaction) => {
|
|
827
|
+
const lockedConversation = await this.aiConversationsModel.findOne({
|
|
828
|
+
where: { sessionId: this.sessionId },
|
|
829
|
+
transaction,
|
|
830
|
+
lock: transaction.LOCK.UPDATE
|
|
831
|
+
});
|
|
832
|
+
if (!lockedConversation) {
|
|
833
|
+
throw new Error(`AI conversation ${this.sessionId} not found`);
|
|
834
|
+
}
|
|
835
|
+
return await callback(conversation, transaction);
|
|
836
|
+
});
|
|
837
|
+
} catch (error) {
|
|
838
|
+
if (!(error instanceof import_database.UniqueConstraintError) || attempt === 1) {
|
|
839
|
+
throw error;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
throw new Error(`Failed to persist AI conversation ${this.sessionId}`);
|
|
844
|
+
} finally {
|
|
845
|
+
release();
|
|
846
|
+
if (persistenceQueues.get(this.sessionId) === current) {
|
|
847
|
+
persistenceQueues.delete(this.sessionId);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
async findPersistedAIMessage(transaction, langChainMessageId, knownMessageId) {
|
|
852
|
+
var _a;
|
|
853
|
+
if (knownMessageId) {
|
|
854
|
+
const knownMessage = await this.aiMessagesModel.findOne({
|
|
855
|
+
where: { sessionId: this.sessionId, messageId: knownMessageId },
|
|
856
|
+
transaction
|
|
857
|
+
});
|
|
858
|
+
if (((_a = knownMessage == null ? void 0 : knownMessage.get("metadata")) == null ? void 0 : _a.id) === langChainMessageId) {
|
|
859
|
+
return knownMessage;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
const messages = await this.aiMessagesModel.findAll({
|
|
863
|
+
where: { sessionId: this.sessionId, role: this.employee.username },
|
|
864
|
+
order: [["messageId", "DESC"]],
|
|
865
|
+
transaction
|
|
866
|
+
});
|
|
867
|
+
return messages.find((message) => {
|
|
868
|
+
var _a2;
|
|
869
|
+
return ((_a2 = message.get("metadata")) == null ? void 0 : _a2.id) === langChainMessageId;
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
async persistAIMessageInTransaction(conversation, transaction, options) {
|
|
873
|
+
const existingMessage = await this.findPersistedAIMessage(
|
|
874
|
+
transaction,
|
|
875
|
+
options.langChainMessageId,
|
|
876
|
+
options.knownMessageId
|
|
877
|
+
);
|
|
878
|
+
if (existingMessage) {
|
|
879
|
+
const message2 = existingMessage.toJSON();
|
|
880
|
+
const initializedToolCalls2 = await this.aiToolMessagesModel.findAll({
|
|
881
|
+
where: { sessionId: this.sessionId, messageId: message2.messageId },
|
|
882
|
+
transaction
|
|
883
|
+
});
|
|
884
|
+
return { message: message2, initializedToolCalls: initializedToolCalls2, created: false };
|
|
885
|
+
}
|
|
886
|
+
const message = await conversation.addMessages(options.values);
|
|
887
|
+
const initializedToolCalls = options.toolCalls.length ? await this.initToolCall(transaction, message.messageId, options.toolCalls) : [];
|
|
888
|
+
return { message, initializedToolCalls, created: true };
|
|
889
|
+
}
|
|
890
|
+
async persistAIMessage(options) {
|
|
891
|
+
return await this.withLockedConversation(async (conversation, transaction) => {
|
|
892
|
+
return await this.persistAIMessageInTransaction(conversation, transaction, options);
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
async finalizeAbortedAIMessage({
|
|
896
|
+
aiMessage,
|
|
897
|
+
providerName,
|
|
898
|
+
provider,
|
|
899
|
+
llmService,
|
|
900
|
+
model,
|
|
901
|
+
knownMessageId
|
|
902
|
+
}) {
|
|
903
|
+
const values = (0, import_utils2.convertAIMessage)({
|
|
904
|
+
aiEmployee: this,
|
|
905
|
+
providerName,
|
|
906
|
+
provider,
|
|
907
|
+
llmService,
|
|
908
|
+
model,
|
|
909
|
+
aiMessage
|
|
910
|
+
});
|
|
911
|
+
if (!values) {
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
values.metadata = { ...values.metadata, interrupted: true };
|
|
915
|
+
const toolCalls = aiMessage.tool_calls ?? [];
|
|
916
|
+
return await this.withLockedConversation(async (conversation, transaction) => {
|
|
917
|
+
var _a;
|
|
918
|
+
const result = await this.persistAIMessageInTransaction(conversation, transaction, {
|
|
919
|
+
values,
|
|
920
|
+
langChainMessageId: aiMessage.id,
|
|
921
|
+
toolCalls,
|
|
922
|
+
knownMessageId
|
|
923
|
+
});
|
|
924
|
+
const unfinishedToolCalls = result.initializedToolCalls.map((toolCall) => toolCall.toJSON()).filter((toolCall) => toolCall.invokeStatus !== "confirmed");
|
|
925
|
+
if (!result.created && (!result.initializedToolCalls.length || unfinishedToolCalls.length) && !((_a = result.message.metadata) == null ? void 0 : _a.interrupted)) {
|
|
926
|
+
const metadata = { ...result.message.metadata, interrupted: true };
|
|
927
|
+
await this.aiMessagesModel.update(
|
|
928
|
+
{ metadata },
|
|
929
|
+
{ where: { sessionId: this.sessionId, messageId: result.message.messageId }, transaction }
|
|
930
|
+
);
|
|
931
|
+
result.message.metadata = metadata;
|
|
932
|
+
}
|
|
933
|
+
if (!unfinishedToolCalls.length) {
|
|
934
|
+
return result;
|
|
935
|
+
}
|
|
936
|
+
const persistedToolCalls = result.message.toolCalls ?? toolCalls;
|
|
937
|
+
const toolCallMap = new Map(persistedToolCalls.map((toolCall) => [toolCall.id, toolCall]));
|
|
938
|
+
const now = /* @__PURE__ */ new Date();
|
|
939
|
+
await conversation.addMessages(
|
|
940
|
+
unfinishedToolCalls.map((toolCall) => ({
|
|
941
|
+
role: "tool",
|
|
942
|
+
content: { type: "text", content: ABORTED_TOOL_CALL_CONTENT },
|
|
943
|
+
metadata: {
|
|
944
|
+
id: `aborted-tool:${aiMessage.id}:${toolCall.toolCallId}`,
|
|
945
|
+
model,
|
|
946
|
+
provider: providerName,
|
|
947
|
+
llmService,
|
|
948
|
+
messageId: result.message.messageId,
|
|
949
|
+
toolCallId: toolCall.toolCallId,
|
|
950
|
+
toolName: toolCall.toolName,
|
|
951
|
+
toolCall: toolCallMap.get(toolCall.toolCallId),
|
|
952
|
+
autoCall: toolCall.auto
|
|
953
|
+
}
|
|
954
|
+
}))
|
|
955
|
+
);
|
|
956
|
+
for (const toolCall of unfinishedToolCalls) {
|
|
957
|
+
await this.aiToolMessagesModel.update(
|
|
958
|
+
{
|
|
959
|
+
invokeStatus: "confirmed",
|
|
960
|
+
status: "error",
|
|
961
|
+
content: ABORTED_TOOL_CALL_CONTENT,
|
|
962
|
+
invokeStartTime: toolCall.invokeStartTime ?? now,
|
|
963
|
+
invokeEndTime: now
|
|
964
|
+
},
|
|
965
|
+
{
|
|
966
|
+
where: {
|
|
967
|
+
id: toolCall.id,
|
|
968
|
+
invokeStatus: { [import_database.Op.ne]: "confirmed" }
|
|
969
|
+
},
|
|
970
|
+
transaction
|
|
971
|
+
}
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
return result;
|
|
975
|
+
});
|
|
976
|
+
}
|
|
769
977
|
async initToolCall(transaction, messageId, toolCalls) {
|
|
770
978
|
const nowTime = /* @__PURE__ */ new Date();
|
|
771
979
|
const toolMap = await this.getToolsMap();
|
|
980
|
+
const currentFrontendTools = toolCalls.some((toolCall) => toolCall.name === import_frontend_tools.EXECUTE_FRONTEND_TOOL_NAME) ? await (0, import_frontend_tools2.listCurrentFrontendTools)(this.ctx, this.sessionId) : [];
|
|
772
981
|
return await this.aiToolMessagesRepo.create({
|
|
773
982
|
values: toolCalls.map((toolCall) => {
|
|
774
983
|
const toolsExisted = toolMap.has(toolCall.name);
|
|
775
984
|
const tools = toolMap.get(toolCall.name);
|
|
776
|
-
const auto = this.isAutoCall(tools);
|
|
985
|
+
const auto = toolCall.name === import_frontend_tools.EXECUTE_FRONTEND_TOOL_NAME ? toolsExisted && (0, import_frontend_tools2.shouldAutoExecuteFrontendTool)(currentFrontendTools, toolCall.args) : this.isAutoCall(tools);
|
|
777
986
|
return {
|
|
778
987
|
id: this.plugin.snowflake.generate(),
|
|
779
988
|
sessionId: this.sessionId,
|
|
@@ -917,6 +1126,39 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
917
1126
|
})).map((it) => it.toJSON());
|
|
918
1127
|
return new Map(list.map((it) => [it.toolCallId, it]));
|
|
919
1128
|
}
|
|
1129
|
+
async getToolCallResults(toolCallIds) {
|
|
1130
|
+
if (!toolCallIds.length) {
|
|
1131
|
+
return /* @__PURE__ */ new Map();
|
|
1132
|
+
}
|
|
1133
|
+
const list = (await this.aiToolMessagesModel.findAll({
|
|
1134
|
+
where: {
|
|
1135
|
+
sessionId: this.sessionId,
|
|
1136
|
+
toolCallId: {
|
|
1137
|
+
[import_database.Op.in]: toolCallIds
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
})).map((item) => item.toJSON());
|
|
1141
|
+
const invokeStatusPriority = { confirmed: 2, done: 1 };
|
|
1142
|
+
const results = /* @__PURE__ */ new Map();
|
|
1143
|
+
for (const item of list) {
|
|
1144
|
+
if (item.invokeStatus !== "confirmed" && item.invokeStatus !== "done") {
|
|
1145
|
+
continue;
|
|
1146
|
+
}
|
|
1147
|
+
const existing = results.get(item.toolCallId);
|
|
1148
|
+
if (!existing) {
|
|
1149
|
+
results.set(item.toolCallId, item);
|
|
1150
|
+
continue;
|
|
1151
|
+
}
|
|
1152
|
+
const priority = invokeStatusPriority[item.invokeStatus];
|
|
1153
|
+
const existingPriority = invokeStatusPriority[existing.invokeStatus];
|
|
1154
|
+
const updatedAt = item.updatedAt ? new Date(item.updatedAt).getTime() : 0;
|
|
1155
|
+
const existingUpdatedAt = existing.updatedAt ? new Date(existing.updatedAt).getTime() : 0;
|
|
1156
|
+
if (priority > existingPriority || priority === existingPriority && updatedAt > existingUpdatedAt) {
|
|
1157
|
+
results.set(item.toolCallId, item);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
return results;
|
|
1161
|
+
}
|
|
920
1162
|
async cancelToolCall() {
|
|
921
1163
|
var _a;
|
|
922
1164
|
let messageId;
|
|
@@ -1054,7 +1296,7 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
1054
1296
|
});
|
|
1055
1297
|
}
|
|
1056
1298
|
async formatMessages({ messages, provider }) {
|
|
1057
|
-
var _a, _b;
|
|
1299
|
+
var _a, _b, _c, _d;
|
|
1058
1300
|
const formattedMessages = [];
|
|
1059
1301
|
const workContextHandler = this.plugin.workContextHandler;
|
|
1060
1302
|
const normalizedMessages = await this.normalizeMessageAttachments(messages);
|
|
@@ -1121,26 +1363,29 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
1121
1363
|
}
|
|
1122
1364
|
if (msg.role === "tool") {
|
|
1123
1365
|
formattedMessages.push({
|
|
1366
|
+
id: (_a = msg.metadata) == null ? void 0 : _a.id,
|
|
1124
1367
|
role: "tool",
|
|
1125
1368
|
content,
|
|
1126
|
-
|
|
1369
|
+
name: (_b = msg.metadata) == null ? void 0 : _b.toolName,
|
|
1370
|
+
tool_call_id: (_c = msg.metadata) == null ? void 0 : _c.toolCallId
|
|
1127
1371
|
});
|
|
1128
1372
|
continue;
|
|
1129
1373
|
}
|
|
1374
|
+
const additionalKwargs = (0, import_tool_call_sanitizer.sanitizeAdditionalKwargsForToolCalls)((_d = msg.metadata) == null ? void 0 : _d.additional_kwargs, msg.toolCalls, {
|
|
1375
|
+
onDiscard: (info) => {
|
|
1376
|
+
var _a2;
|
|
1377
|
+
this.logger.warn("Discard malformed raw tool calls from AI message", {
|
|
1378
|
+
phase: "formatMessages",
|
|
1379
|
+
messageId: (_a2 = msg.metadata) == null ? void 0 : _a2.id,
|
|
1380
|
+
...info
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
}).additionalKwargs;
|
|
1130
1384
|
formattedMessages.push({
|
|
1131
1385
|
role: "assistant",
|
|
1132
1386
|
content,
|
|
1133
1387
|
tool_calls: msg.toolCalls,
|
|
1134
|
-
additional_kwargs:
|
|
1135
|
-
onDiscard: (info) => {
|
|
1136
|
-
var _a2;
|
|
1137
|
-
this.logger.warn("Discard malformed raw tool calls from AI message", {
|
|
1138
|
-
phase: "formatMessages",
|
|
1139
|
-
messageId: (_a2 = msg.metadata) == null ? void 0 : _a2.id,
|
|
1140
|
-
...info
|
|
1141
|
-
});
|
|
1142
|
-
}
|
|
1143
|
-
}).additionalKwargs
|
|
1388
|
+
additional_kwargs: provider.prepareStoredAssistantAdditionalKwargs(additionalKwargs)
|
|
1144
1389
|
});
|
|
1145
1390
|
}
|
|
1146
1391
|
return formattedMessages;
|
|
@@ -1185,12 +1430,32 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
1185
1430
|
}
|
|
1186
1431
|
return result;
|
|
1187
1432
|
}
|
|
1433
|
+
async getKnowledgeBaseRetrieveTool() {
|
|
1434
|
+
const employee = this.getAIEmployeeRecord();
|
|
1435
|
+
const knowledgeBaseManager = this.plugin.knowledgeBaseManager;
|
|
1436
|
+
if (!await knowledgeBaseManager.isEnabledKnowledgeBase(employee)) {
|
|
1437
|
+
return void 0;
|
|
1438
|
+
}
|
|
1439
|
+
const hasAccessibleKnowledgeBase = await knowledgeBaseManager.hasAccessibleKnowledgeBase({
|
|
1440
|
+
employee,
|
|
1441
|
+
roleNames: (0, import_ai_knowledge_base.getCurrentRoleNames)(this.ctx.state)
|
|
1442
|
+
});
|
|
1443
|
+
if (!hasAccessibleKnowledgeBase) {
|
|
1444
|
+
return void 0;
|
|
1445
|
+
}
|
|
1446
|
+
return await this.toolsManager.getTools(import_ai.SYSTEM_TOOLS.KNOWLEDGE_BASE, { ctx: this.ctx });
|
|
1447
|
+
}
|
|
1188
1448
|
async getAIEmployeeTools() {
|
|
1189
1449
|
var _a;
|
|
1190
1450
|
if (!this.areToolsEnabled()) {
|
|
1191
1451
|
return [];
|
|
1192
1452
|
}
|
|
1453
|
+
const currentFrontendTools = await (0, import_frontend_tools2.listCurrentFrontendTools)(this.ctx, this.sessionId);
|
|
1193
1454
|
const tools = await this.listTools({ scope: "GENERAL" });
|
|
1455
|
+
const getSkill = await this.toolsManager.getTools(import_ai.SYSTEM_TOOLS.GET_SKILL, { ctx: this.ctx });
|
|
1456
|
+
if (getSkill) {
|
|
1457
|
+
tools.push(getSkill);
|
|
1458
|
+
}
|
|
1194
1459
|
if (this.webSearch === true) {
|
|
1195
1460
|
const subAgentWebSearch = await this.toolsManager.getTools(import_ai.SYSTEM_TOOLS.WEB_SEARCH, { ctx: this.ctx });
|
|
1196
1461
|
tools.push(subAgentWebSearch);
|
|
@@ -1199,13 +1464,9 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
1199
1464
|
const toolMap = await this.getToolsMap();
|
|
1200
1465
|
const settingsTools = ((_a = this.employee.skillSettings) == null ? void 0 : _a.tools) ?? [];
|
|
1201
1466
|
const employeeTools = [...settingsTools, ...this.tools];
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
});
|
|
1206
|
-
if (knowledgeBaseRetrieveTool) {
|
|
1207
|
-
employeeTools.push({ name: import_ai.SYSTEM_TOOLS.KNOWLEDGE_BASE });
|
|
1208
|
-
}
|
|
1467
|
+
const knowledgeBaseRetrieveTool = await this.getKnowledgeBaseRetrieveTool();
|
|
1468
|
+
if (knowledgeBaseRetrieveTool) {
|
|
1469
|
+
employeeTools.push({ name: import_ai.SYSTEM_TOOLS.KNOWLEDGE_BASE });
|
|
1209
1470
|
}
|
|
1210
1471
|
for (const toolSetting of employeeTools) {
|
|
1211
1472
|
if (generalToolsNameSet.has(toolSetting.name)) {
|
|
@@ -1217,20 +1478,26 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
1217
1478
|
}
|
|
1218
1479
|
tools.push(tool);
|
|
1219
1480
|
}
|
|
1220
|
-
const systemTools = (0, import_ai.listSystemTools)();
|
|
1481
|
+
const systemTools = [...(0, import_ai.listSystemTools)(), import_frontend_tools.LOAD_FRONTEND_TOOL_NAME, import_frontend_tools.EXECUTE_FRONTEND_TOOL_NAME];
|
|
1221
1482
|
if (!this.skillSettings) {
|
|
1222
|
-
return tools;
|
|
1483
|
+
return (0, import_frontend_tools2.prepareToolsForFrontendConversation)(tools, currentFrontendTools);
|
|
1223
1484
|
} else if (!this.skillSettings.toolsVersion) {
|
|
1224
1485
|
const toolFilter = this.skillSettings.tools ?? [];
|
|
1225
|
-
return
|
|
1226
|
-
|
|
1486
|
+
return (0, import_frontend_tools2.prepareToolsForFrontendConversation)(
|
|
1487
|
+
tools.filter(
|
|
1488
|
+
(t) => toolFilter.length === 0 || systemTools.includes(t.definition.name) || toolFilter.includes(t.definition.name)
|
|
1489
|
+
),
|
|
1490
|
+
currentFrontendTools
|
|
1227
1491
|
);
|
|
1228
1492
|
} else {
|
|
1229
1493
|
const toolFilter = this.skillSettings.tools;
|
|
1230
1494
|
if (import_lodash.default.isArray(toolFilter)) {
|
|
1231
|
-
return
|
|
1495
|
+
return (0, import_frontend_tools2.prepareToolsForFrontendConversation)(
|
|
1496
|
+
tools.filter((t) => systemTools.includes(t.definition.name) || toolFilter.includes(t.definition.name)),
|
|
1497
|
+
currentFrontendTools
|
|
1498
|
+
);
|
|
1232
1499
|
} else {
|
|
1233
|
-
return tools;
|
|
1500
|
+
return (0, import_frontend_tools2.prepareToolsForFrontendConversation)(tools, currentFrontendTools);
|
|
1234
1501
|
}
|
|
1235
1502
|
}
|
|
1236
1503
|
}
|
|
@@ -1272,6 +1539,9 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
1272
1539
|
}
|
|
1273
1540
|
const baseTools = await this.getAIEmployeeTools();
|
|
1274
1541
|
const toolMap = await this.getToolsMap();
|
|
1542
|
+
for (const tool of baseTools) {
|
|
1543
|
+
toolMap.set(tool.definition.name, tool);
|
|
1544
|
+
}
|
|
1275
1545
|
const availableSkills = await this.getAvailableSkills();
|
|
1276
1546
|
const skillOwnedToolNames = new Set(availableSkills.flatMap((it) => it.tools ?? []));
|
|
1277
1547
|
const baseToolNames = new Set(
|
|
@@ -1350,7 +1620,22 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
1350
1620
|
(0, import_middleware.toolCallStatusMiddleware)(this),
|
|
1351
1621
|
...inWorkflow ? [(0, import_middleware.workflowHistoryMiddleware)(this, this.db)] : [],
|
|
1352
1622
|
(0, import_middleware.conversationMiddleware)(this, { providerName, provider, llmService, model, messageId, agentThread }),
|
|
1353
|
-
(0, import_middleware.toolCallSanitizerMiddleware)({ logger: this.logger })
|
|
1623
|
+
(0, import_middleware.toolCallSanitizerMiddleware)({ logger: this.logger }),
|
|
1624
|
+
(0, import_middleware.toolResultIntegrityMiddleware)({
|
|
1625
|
+
sessionId: this.sessionId,
|
|
1626
|
+
logger: this.logger,
|
|
1627
|
+
loadToolResults: async (toolCallIds) => {
|
|
1628
|
+
try {
|
|
1629
|
+
return await this.getToolCallResults(toolCallIds);
|
|
1630
|
+
} catch (error) {
|
|
1631
|
+
this.logger.warn("Failed to load persisted tool results before model call", {
|
|
1632
|
+
sessionId: this.sessionId,
|
|
1633
|
+
error
|
|
1634
|
+
});
|
|
1635
|
+
return /* @__PURE__ */ new Map();
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
})
|
|
1354
1639
|
];
|
|
1355
1640
|
}
|
|
1356
1641
|
async getCurrentThread() {
|
|
@@ -1408,6 +1693,9 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
1408
1693
|
get aiMessagesRepo() {
|
|
1409
1694
|
return this.ctx.db.getRepository("aiMessages");
|
|
1410
1695
|
}
|
|
1696
|
+
get aiConversationsModel() {
|
|
1697
|
+
return this.ctx.db.getModel("aiConversations");
|
|
1698
|
+
}
|
|
1411
1699
|
get aiMessagesModel() {
|
|
1412
1700
|
return this.ctx.db.getModel("aiMessages");
|
|
1413
1701
|
}
|