@nocobase/plugin-ai 2.1.0-beta.15 → 2.1.0-beta.16
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/ai-employees/atlas/index.d.ts +10 -0
- package/dist/{server/ai-employees/built-in/ai-coding/prompt.js → ai/ai-employees/atlas/index.js} +29 -20
- package/dist/ai/ai-employees/atlas/prompt.md +84 -0
- package/dist/ai/ai-employees/dara.d.ts +10 -0
- package/dist/{server/ai-employees/built-in/data-visualization/prompt.js → ai/ai-employees/dara.js} +21 -13
- package/dist/ai/ai-employees/dex.d.ts +10 -0
- package/dist/{server/ai-employees/built-in/data-organizer/prompt.js → ai/ai-employees/dex.js} +15 -7
- package/dist/ai/ai-employees/ellis.d.ts +10 -0
- package/dist/{server/ai-employees/built-in/email-assistant/prompt.js → ai/ai-employees/ellis.js} +19 -11
- package/dist/ai/ai-employees/lexi.d.ts +10 -0
- package/dist/{server/ai-employees/built-in/translator/prompt.js → ai/ai-employees/lexi.js} +15 -7
- package/dist/ai/ai-employees/vera.d.ts +10 -0
- package/dist/{server/ai-employees/built-in/research-analyst/prompt.js → ai/ai-employees/vera.js} +16 -8
- package/dist/ai/ai-employees/viz.d.ts +10 -0
- package/dist/{server/ai-employees/built-in/insights-analyst/prompt.js → ai/ai-employees/viz.js} +15 -7
- package/dist/ai/skills/business-analysis-report/SKILLS.md +88 -0
- package/dist/{server/ai-employees/built-in/ai-coding/prompt.d.ts → ai/skills/business-analysis-report/tools/businessReportGenerator.d.ts} +1 -3
- package/dist/ai/skills/business-analysis-report/tools/businessReportGenerator.js +98 -0
- package/dist/ai/skills/document-search/SKILLS.md +69 -0
- package/dist/ai/tools/chartGenerator.js +15 -3
- package/dist/ai/tools/formFiller.js +13 -2
- package/dist/{server/ai-employees/built-in/data-modeling/prompt.d.ts → ai/tools/getSkill.d.ts} +1 -3
- package/dist/{server/ai-employees/built-in/data-modeling/index.js → ai/tools/getSkill.js} +39 -32
- package/dist/{server/ai-employees/built-in/data-organizer/prompt.d.ts → ai/tools/knowledge-base-retrieve.d.ts} +1 -3
- package/dist/ai/tools/knowledge-base-retrieve.js +94 -0
- package/dist/{server/ai-employees/built-in/data-visualization/prompt.d.ts → ai/tools/sub-agents/dispatch-sub-agent-task.d.ts} +1 -3
- package/dist/ai/tools/sub-agents/dispatch-sub-agent-task.js +108 -0
- package/dist/ai/tools/sub-agents/get-ai-employee.d.ts +10 -0
- package/dist/{server/ai-employees/built-in/translator/profile.js → ai/tools/sub-agents/get-ai-employee.js} +28 -21
- package/dist/ai/tools/sub-agents/list-ai-employees.d.ts +10 -0
- package/dist/{server/ai-employees/built-in/email-assistant/profile.js → ai/tools/sub-agents/list-ai-employees.js} +25 -21
- package/dist/ai/tools/sub-agents/shared.d.ts +33 -0
- package/dist/ai/tools/sub-agents/shared.js +169 -0
- package/dist/ai/tools/suggestions.js +15 -4
- package/dist/client/170.d98eacdc00d9d527.js +10 -0
- package/dist/client/228.b18148eb1009d2fb.js +10 -0
- package/dist/client/280.029428b83d62155f.js +10 -0
- package/dist/client/290.0888139e33c9b7cb.js +10 -0
- package/dist/client/{524.954f96ec4fc2fd7a.js → 331.d547c95410476a69.js} +1 -1
- package/dist/client/343.83f7d96664e4e038.js +10 -0
- package/dist/client/406.15c09d98faa2ccf1.js +10 -0
- package/dist/client/428.e9f38da3b0d8b498.js +10 -0
- package/dist/client/486.77c26e2e7f8daf28.js +10 -0
- package/dist/client/502.2b4a51e0a8122e52.js +10 -0
- package/dist/client/525.33a9c8ec28be4ec4.js +10 -0
- package/dist/client/559.133d286a0a0a1d93.js +10 -0
- package/dist/client/{91.90e7098b7fbd5d00.js → 561.776886c5308e3c26.js} +1 -1
- package/dist/client/580.e75f97fb883ad042.js +10 -0
- package/dist/client/597.aa363881a325b5c0.js +10 -0
- package/dist/client/604.de96f3ec4d471afd.js +10 -0
- package/dist/client/614.aa766080f6b99aab.js +10 -0
- package/dist/client/646.ef9d7c2ea8641044.js +10 -0
- package/dist/client/687.224e569a99cae4bb.js +10 -0
- package/dist/client/699.57c0a1acb723202a.js +10 -0
- package/dist/client/711.266b8f1c520d467a.js +10 -0
- package/dist/client/758.a9741e81911e53c3.js +10 -0
- package/dist/client/768.973ce32e15099a48.js +10 -0
- package/dist/client/792.ae8ad1fcae9fd974.js +10 -0
- package/dist/client/820.6a26239ea96c075a.js +10 -0
- package/dist/client/832.0cf69e3f43c320b2.js +10 -0
- package/dist/client/927.ff5cd05b14901ae6.js +10 -0
- package/dist/client/ai-employees/admin/SkillSettings.d.ts +7 -5
- package/dist/client/ai-employees/admin/ToolsSettings.d.ts +17 -0
- package/dist/client/ai-employees/admin/mcp/MCPSettings.d.ts +10 -0
- package/dist/client/ai-employees/admin/mcp/MCPToolsList.d.ts +19 -0
- package/dist/client/ai-employees/admin/mcp/context.d.ts +15 -0
- package/dist/client/ai-employees/admin/mcp/schemas.d.ts +1286 -0
- package/dist/client/ai-employees/built-in/utils.d.ts +1 -0
- package/dist/client/ai-employees/business-report/tools/index.d.ts +10 -0
- package/dist/client/ai-employees/business-report/ui/BusinessReportCard.d.ts +12 -0
- package/dist/client/ai-employees/business-report/ui/BusinessReportModal.d.ts +17 -0
- package/dist/client/ai-employees/business-report/ui/report-utils.d.ts +38 -0
- package/dist/client/ai-employees/chatbox/AIEmployeeSwitch.d.ts +3 -2
- package/dist/client/ai-employees/chatbox/HintMessageHeader.d.ts +10 -0
- package/dist/client/ai-employees/chatbox/ModelSwitcher.d.ts +3 -1
- package/dist/client/ai-employees/chatbox/SearchSwitch.d.ts +3 -1
- package/dist/client/ai-employees/chatbox/Upload.d.ts +3 -1
- package/dist/client/ai-employees/chatbox/conversations/ConversationsList.d.ts +27 -0
- package/dist/client/ai-employees/chatbox/conversations/WorkflowTasksList.d.ts +31 -0
- package/dist/client/ai-employees/chatbox/conversations/common.d.ts +43 -0
- package/dist/client/ai-employees/chatbox/conversations/index.d.ts +9 -0
- package/dist/client/ai-employees/chatbox/hooks/useChatBoxActions.d.ts +5 -3
- package/dist/client/ai-employees/chatbox/hooks/useWorkflowTasks.d.ts +24 -0
- package/dist/client/ai-employees/chatbox/markdown/ECharts.d.ts +1 -2
- package/dist/client/ai-employees/chatbox/markdown/Markdown.d.ts +1 -1
- package/dist/client/ai-employees/chatbox/roles.d.ts +1 -0
- package/dist/client/ai-employees/chatbox/stores/chat-box.d.ts +8 -0
- package/dist/client/ai-employees/chatbox/stores/chat-conversations.d.ts +4 -0
- package/dist/client/ai-employees/chatbox/stores/chat-messages.d.ts +8 -0
- package/dist/client/ai-employees/chatbox/stores/workflow-tasks.d.ts +41 -0
- package/dist/client/ai-employees/chatbox/utils.d.ts +17 -7
- package/dist/client/ai-employees/sub-agents/tools/index.d.ts +10 -0
- package/dist/client/ai-employees/sub-agents/ui/SubAgentDispatchCard.d.ts +21 -0
- package/dist/client/ai-employees/types.d.ts +24 -4
- package/dist/{server/ai-employees/built-in/ai-coding/document/example/js-filter → client/ai-employees/workflow-tasks/tools}/index.d.ts +2 -7
- package/dist/client/ai-employees/workflow-tasks/ui/WorkflowTaskOutputCard.d.ts +11 -0
- package/dist/client/components/ListCollapse.d.ts +28 -0
- package/dist/client/index.js +7 -7
- package/dist/client/manager/ai-manager.d.ts +4 -23
- package/dist/client/repositories/AIConfigRepository.d.ts +11 -3
- package/dist/client/workflow/nodes/employee/components/AIEmployeeSelect.d.ts +10 -0
- package/dist/client/workflow/nodes/employee/components/assigness.d.ts +11 -0
- package/dist/client/workflow/nodes/employee/components/file-inputs.d.ts +10 -0
- package/dist/client/workflow/nodes/employee/components/message-inputs.d.ts +12 -0
- package/dist/client/workflow/nodes/employee/components/model-options.d.ts +10 -0
- package/dist/client/workflow/nodes/employee/components/skill-settings.d.ts +10 -0
- package/dist/client/workflow/nodes/employee/components/structured-output.d.ts +10 -0
- package/dist/client/workflow/nodes/employee/components/users-select.d.ts +15 -0
- package/dist/client/workflow/nodes/employee/components/web-search-options.d.ts +10 -0
- package/dist/client/workflow/nodes/employee/configuration.d.ts +12 -0
- package/dist/client/workflow/nodes/employee/flow-models/feedback.d.ts +13 -0
- package/dist/client/workflow/nodes/employee/flow-models/task.d.ts +13 -0
- package/dist/client/workflow/nodes/employee/index.d.ts +7 -31
- package/dist/collections/ai-employees.js +2 -1
- package/dist/collections/ai-mcp-clients.d.ts +51 -0
- package/dist/collections/ai-mcp-clients.js +111 -0
- package/dist/externalVersion.js +17 -15
- package/dist/locale/en-US.json +136 -8
- package/dist/locale/zh-CN.json +138 -9
- package/dist/node_modules/fast-glob/out/index.js +8 -8
- package/dist/node_modules/fast-glob/package.json +1 -1
- package/dist/node_modules/flexsearch/dist/flexsearch.bundle.min.js +2 -2
- package/dist/node_modules/flexsearch/package.json +1 -1
- package/dist/node_modules/fs-extra/lib/index.js +1 -1
- package/dist/node_modules/fs-extra/package.json +1 -1
- package/dist/node_modules/nodejs-snowflake/nodejs_snowflake.js +1 -1
- package/dist/node_modules/nodejs-snowflake/package.json +1 -1
- package/dist/node_modules/openai/index.js +1 -1
- package/dist/node_modules/openai/package.json +1 -1
- package/dist/node_modules/zod/index.cjs +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/ai-employees/ai-conversations.d.ts +70 -0
- package/dist/server/ai-employees/ai-conversations.js +325 -0
- package/dist/server/ai-employees/ai-employee.d.ts +100 -19
- package/dist/server/ai-employees/ai-employee.js +484 -261
- package/dist/server/ai-employees/ai-knowledge-base.d.ts +28 -0
- package/dist/server/ai-employees/ai-knowledge-base.js +167 -0
- package/dist/server/ai-employees/middleware/conversation.d.ts +2 -0
- package/dist/server/ai-employees/middleware/conversation.js +38 -5
- package/dist/server/ai-employees/middleware/index.d.ts +2 -0
- package/dist/server/ai-employees/middleware/index.js +5 -1
- package/dist/server/ai-employees/middleware/skill-tools.d.ts +12 -0
- package/dist/server/ai-employees/middleware/skill-tools.js +88 -0
- package/dist/server/ai-employees/middleware/tools.js +37 -10
- package/dist/server/ai-employees/middleware/workflow-history.d.ts +22 -0
- package/dist/server/ai-employees/middleware/workflow-history.js +173 -0
- package/dist/server/ai-employees/prompts.d.ts +16 -1
- package/dist/server/ai-employees/prompts.js +37 -1
- package/dist/server/ai-employees/sub-agents/dispatcher.d.ts +36 -0
- package/dist/server/ai-employees/sub-agents/dispatcher.js +225 -0
- package/dist/server/ai-employees/sub-agents/index.d.ts +9 -0
- package/dist/server/{migrations/20250923221107-setup-build-in.js → ai-employees/sub-agents/index.js} +9 -13
- package/dist/server/ai-employees/templates/form-assistant.d.ts +2 -2
- package/dist/server/ai-employees/templates/form-assistant.js +2 -2
- package/dist/server/ai-employees/utils.js +2 -2
- package/dist/server/collections/ai-conversations.js +18 -0
- package/dist/server/{ai-employees/built-in/ai-coding/document/example/js-column/js_columns_for_contacts_en.d.ts → collections/ai-mcp-clients.d.ts} +1 -4
- package/dist/server/{ai-employees/built-in/nocobase-assistant/index.js → collections/ai-mcp-clients.js} +12 -13
- package/dist/server/{ai-employees/built-in/ai-coding/document/basic/flow-resource.d.ts → collections/ai-skills.d.ts} +1 -4
- package/dist/server/{ai-employees/built-in/email-assistant/index.js → collections/ai-skills.js} +46 -23
- package/dist/server/{ai-employees/built-in/ai-coding/document/example/js-column/js_columns_for_opportunities_en.d.ts → collections/ai-workflow-tasks.d.ts} +1 -4
- package/dist/server/collections/ai-workflow-tasks.js +112 -0
- package/dist/server/{ai-employees/built-in/ai-coding/document/example/js-column/js_columns_for_accounts_en.d.ts → collections/users-ai-workflow-tasks.d.ts} +1 -4
- package/dist/server/collections/users-ai-workflow-tasks.js +44 -0
- package/dist/server/llm-providers/anthropic.d.ts +1 -0
- package/dist/server/llm-providers/anthropic.js +2 -1
- package/dist/server/llm-providers/dashscope.d.ts +1 -0
- package/dist/server/llm-providers/deepseek.d.ts +1 -0
- package/dist/server/llm-providers/google-genai.d.ts +1 -0
- package/dist/server/llm-providers/google-genai.js +2 -1
- package/dist/server/llm-providers/kimi/provider.d.ts +1 -0
- package/dist/server/llm-providers/openai/responses.d.ts +1 -0
- package/dist/server/llm-providers/openai/responses.js +2 -1
- package/dist/server/llm-providers/provider.d.ts +1 -10
- package/dist/server/llm-providers/provider.js +3 -34
- package/dist/server/manager/ai-coding-manager.d.ts +1 -2
- package/dist/server/manager/ai-coding-manager.js +0 -41
- package/dist/server/manager/ai-context-datasource-manager.js +30 -1
- package/dist/server/manager/built-in-manager.d.ts +2 -4
- package/dist/server/manager/built-in-manager.js +8 -117
- package/dist/server/migrations/20260306000001-migrate-skill-settings-tools.js +68 -0
- package/dist/server/migrations/20260319000000-add-ai-conversations-from.d.ts +14 -0
- package/dist/server/migrations/20260319000000-add-ai-conversations-from.js +63 -0
- package/dist/server/plugin.d.ts +6 -1
- package/dist/server/plugin.js +31 -8
- package/dist/server/resource/aiConversations.js +112 -188
- package/dist/server/resource/aiEmployees.js +5 -7
- package/dist/server/resource/aiMcpClients.d.ts +11 -0
- package/dist/server/resource/aiMcpClients.js +78 -0
- package/dist/server/{ai-employees/built-in/ai-coding/document/example/js-column/index.d.ts → resource/aiSkills.d.ts} +3 -7
- package/dist/server/resource/aiSkills.js +71 -0
- package/dist/server/resource/aiTools.js +4 -6
- package/dist/server/resource/aiWorkflowTasks.d.ts +12 -0
- package/dist/server/resource/aiWorkflowTasks.js +290 -0
- package/dist/server/tools/docs.js +4 -3
- package/dist/server/tools/workflow-caller.js +1 -0
- package/dist/server/types/ai-chat-conversation.type.d.ts +8 -2
- package/dist/server/types/ai-message.type.d.ts +7 -0
- package/dist/server/utils.d.ts +3 -0
- package/dist/server/utils.js +28 -3
- package/dist/server/workflow/nodes/employee/files.d.ts +16 -0
- package/dist/server/workflow/nodes/employee/files.js +125 -0
- package/dist/server/workflow/nodes/employee/handler.d.ts +11 -0
- package/dist/server/workflow/nodes/employee/handler.js +107 -0
- package/dist/server/workflow/nodes/employee/index.d.ts +17 -0
- package/dist/server/workflow/nodes/employee/index.js +391 -0
- package/dist/server/workflow/nodes/employee/tools.d.ts +12 -0
- package/dist/server/workflow/nodes/employee/tools.js +133 -0
- package/dist/server/workflow/nodes/employee/types.d.ts +35 -0
- package/dist/server/workflow/nodes/employee/types.js +24 -0
- package/dist/server/workflow/utils.d.ts +14 -0
- package/dist/server/workflow/utils.js +111 -0
- package/package.json +4 -2
- package/dist/client/107.64d9efa24d6b9143.js +0 -10
- package/dist/client/124.768c8aa5d6e6b461.js +0 -10
- package/dist/client/159.d52107c7a34ce2da.js +0 -10
- package/dist/client/192.0419770b69678994.js +0 -10
- package/dist/client/204.91be8cfc54d91a59.js +0 -10
- package/dist/client/238.9f784a7cdb751999.js +0 -10
- package/dist/client/263.6e1dfb1cbb1964f5.js +0 -10
- package/dist/client/35.5ee7503d9c09daa8.js +0 -10
- package/dist/client/47.6bd245f2140efd24.js +0 -10
- package/dist/client/481.03b3d2306d409933.js +0 -10
- package/dist/client/586.6a1510cabaa84f23.js +0 -10
- package/dist/client/650.8871a07b31c307ea.js +0 -10
- package/dist/client/755.e295bbd2b2a1cc21.js +0 -10
- package/dist/client/772.d51f683c55e18dd4.js +0 -10
- package/dist/client/870.84187dcb8c89b4dc.js +0 -10
- package/dist/client/933.baab3aa75f30e020.js +0 -10
- package/dist/client/987.3aee964e7f406939.js +0 -10
- package/dist/server/ai-employees/built-in/ai-coding/document/basic/flow-resource.js +0 -256
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-column/index.js +0 -48
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-column/js_columns_for_accounts_en.js +0 -452
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-column/js_columns_for_contacts_en.js +0 -363
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-column/js_columns_for_opportunities_en.js +0 -270
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-column/js_columns_for_quotations_en.d.ts +0 -13
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-column/js_columns_for_quotations_en.js +0 -219
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-column/js_columns_for_tickets_en.d.ts +0 -13
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-column/js_columns_for_tickets_en.js +0 -409
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-filter/accounts_filter_ant_style.d.ts +0 -13
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-filter/accounts_filter_ant_style.js +0 -324
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-filter/contacts_filter_ant_style.d.ts +0 -13
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-filter/contacts_filter_ant_style.js +0 -309
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-filter/index.js +0 -50
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-filter/leads_filter_ant_style.d.ts +0 -13
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-filter/leads_filter_ant_style.js +0 -345
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-filter/opportunities_filter_ant_style.d.ts +0 -13
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-filter/opportunities_filter_ant_style.js +0 -381
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-filter/product_categories_ant_style.d.ts +0 -13
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-filter/product_categories_ant_style.js +0 -545
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-filter/tickets_filter_ant_style.d.ts +0 -13
- package/dist/server/ai-employees/built-in/ai-coding/document/example/js-filter/tickets_filter_ant_style.js +0 -346
- package/dist/server/ai-employees/built-in/ai-coding/document/js-action.d.ts +0 -13
- package/dist/server/ai-employees/built-in/ai-coding/document/js-action.js +0 -102
- package/dist/server/ai-employees/built-in/ai-coding/document/js-block.d.ts +0 -13
- package/dist/server/ai-employees/built-in/ai-coding/document/js-block.js +0 -314
- package/dist/server/ai-employees/built-in/ai-coding/document/js-column.d.ts +0 -13
- package/dist/server/ai-employees/built-in/ai-coding/document/js-column.js +0 -113
- package/dist/server/ai-employees/built-in/ai-coding/document/js-field.d.ts +0 -13
- package/dist/server/ai-employees/built-in/ai-coding/document/js-field.js +0 -498
- package/dist/server/ai-employees/built-in/ai-coding/document/js-item.d.ts +0 -13
- package/dist/server/ai-employees/built-in/ai-coding/document/js-item.js +0 -184
- package/dist/server/ai-employees/built-in/ai-coding/index.d.ts +0 -37
- package/dist/server/ai-employees/built-in/ai-coding/index.js +0 -99
- package/dist/server/ai-employees/built-in/ai-coding/profile.d.ts +0 -27
- package/dist/server/ai-employees/built-in/ai-coding/profile.js +0 -60
- package/dist/server/ai-employees/built-in/ai-coding/prompt_en.md +0 -110
- package/dist/server/ai-employees/built-in/data-modeling/index.d.ts +0 -37
- package/dist/server/ai-employees/built-in/data-modeling/profile.d.ts +0 -27
- package/dist/server/ai-employees/built-in/data-modeling/profile.js +0 -60
- package/dist/server/ai-employees/built-in/data-modeling/prompt.js +0 -283
- package/dist/server/ai-employees/built-in/data-organizer/index.d.ts +0 -37
- package/dist/server/ai-employees/built-in/data-organizer/index.js +0 -63
- package/dist/server/ai-employees/built-in/data-organizer/profile.d.ts +0 -27
- package/dist/server/ai-employees/built-in/data-organizer/profile.js +0 -60
- package/dist/server/ai-employees/built-in/data-visualization/index.d.ts +0 -37
- package/dist/server/ai-employees/built-in/data-visualization/index.js +0 -58
- package/dist/server/ai-employees/built-in/data-visualization/profile.d.ts +0 -27
- package/dist/server/ai-employees/built-in/data-visualization/profile.js +0 -60
- package/dist/server/ai-employees/built-in/email-assistant/index.d.ts +0 -34
- package/dist/server/ai-employees/built-in/email-assistant/profile.d.ts +0 -27
- package/dist/server/ai-employees/built-in/email-assistant/prompt.d.ts +0 -12
- package/dist/server/ai-employees/built-in/insights-analyst/index.d.ts +0 -37
- package/dist/server/ai-employees/built-in/insights-analyst/index.js +0 -63
- package/dist/server/ai-employees/built-in/insights-analyst/profile.d.ts +0 -27
- package/dist/server/ai-employees/built-in/insights-analyst/profile.js +0 -60
- package/dist/server/ai-employees/built-in/insights-analyst/prompt.d.ts +0 -12
- package/dist/server/ai-employees/built-in/nocobase-assistant/index.d.ts +0 -34
- package/dist/server/ai-employees/built-in/nocobase-assistant/profile.d.ts +0 -27
- package/dist/server/ai-employees/built-in/nocobase-assistant/profile.js +0 -60
- package/dist/server/ai-employees/built-in/nocobase-assistant/prompt.d.ts +0 -12
- package/dist/server/ai-employees/built-in/nocobase-assistant/prompt.js +0 -52
- package/dist/server/ai-employees/built-in/research-analyst/index.d.ts +0 -37
- package/dist/server/ai-employees/built-in/research-analyst/index.js +0 -63
- package/dist/server/ai-employees/built-in/research-analyst/profile.d.ts +0 -27
- package/dist/server/ai-employees/built-in/research-analyst/profile.js +0 -60
- package/dist/server/ai-employees/built-in/research-analyst/prompt.d.ts +0 -12
- package/dist/server/ai-employees/built-in/translator/index.d.ts +0 -37
- package/dist/server/ai-employees/built-in/translator/index.js +0 -67
- package/dist/server/ai-employees/built-in/translator/profile.d.ts +0 -27
- package/dist/server/ai-employees/built-in/translator/prompt.d.ts +0 -12
- /package/dist/client/ai-employees/chatbox/{Conversations.d.ts → conversations/Conversations.d.ts} +0 -0
- /package/dist/server/migrations/{20250923221107-setup-build-in.d.ts → 20260306000001-migrate-skill-settings-tools.d.ts} +0 -0
|
@@ -36,17 +36,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
37
|
var ai_employee_exports = {};
|
|
38
38
|
__export(ai_employee_exports, {
|
|
39
|
-
AIEmployee: () => AIEmployee
|
|
39
|
+
AIEmployee: () => AIEmployee,
|
|
40
|
+
ChatStreamProtocol: () => ChatStreamProtocol
|
|
40
41
|
});
|
|
41
42
|
module.exports = __toCommonJS(ai_employee_exports);
|
|
42
43
|
var import_database = require("@nocobase/database");
|
|
43
|
-
var import_provider = require("../llm-providers/provider");
|
|
44
44
|
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_feature_manager = require("../manager/ai-feature-manager");
|
|
49
|
-
var import_prompts2 = require("@langchain/core/prompts");
|
|
50
48
|
var import_middleware = require("./middleware");
|
|
51
49
|
var import_checkpoints = require("./checkpoints");
|
|
52
50
|
var import_langchain = require("langchain");
|
|
@@ -54,20 +52,35 @@ var import_langgraph = require("@langchain/langgraph");
|
|
|
54
52
|
var import_stream = require("@langchain/core/utils/stream");
|
|
55
53
|
var import_utils2 = require("./utils");
|
|
56
54
|
var import_base = require("@langchain/core/callbacks/base");
|
|
55
|
+
var import_shared = require("../../ai/tools/sub-agents/shared");
|
|
57
56
|
class AIEmployee {
|
|
57
|
+
sessionId;
|
|
58
|
+
from = "main-agent";
|
|
58
59
|
employee;
|
|
59
60
|
aiChatConversation;
|
|
60
61
|
skillSettings;
|
|
61
62
|
plugin;
|
|
62
63
|
db;
|
|
63
|
-
sessionId;
|
|
64
64
|
ctx;
|
|
65
65
|
systemMessage;
|
|
66
|
+
protocol;
|
|
66
67
|
webSearch;
|
|
67
68
|
model;
|
|
68
69
|
legacy;
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
tools;
|
|
71
|
+
inWorkflow;
|
|
72
|
+
constructor({
|
|
73
|
+
ctx,
|
|
74
|
+
employee,
|
|
75
|
+
sessionId,
|
|
76
|
+
systemMessage,
|
|
77
|
+
skillSettings,
|
|
78
|
+
webSearch,
|
|
79
|
+
model,
|
|
80
|
+
legacy,
|
|
81
|
+
from = "main-agent",
|
|
82
|
+
tools = []
|
|
83
|
+
}) {
|
|
71
84
|
this.employee = employee;
|
|
72
85
|
this.ctx = ctx;
|
|
73
86
|
this.plugin = ctx.app.pm.get("ai");
|
|
@@ -78,11 +91,30 @@ class AIEmployee {
|
|
|
78
91
|
this.skillSettings = skillSettings;
|
|
79
92
|
this.model = model;
|
|
80
93
|
this.legacy = legacy;
|
|
81
|
-
|
|
94
|
+
this.from = from;
|
|
95
|
+
this.tools = tools;
|
|
82
96
|
const builtInManager = this.plugin.builtInManager;
|
|
83
|
-
builtInManager.setupBuiltInInfo(
|
|
97
|
+
builtInManager.setupBuiltInInfo(ctx, this.employee);
|
|
84
98
|
this.webSearch = webSearch;
|
|
85
|
-
this.protocol = ChatStreamProtocol.
|
|
99
|
+
this.protocol = ChatStreamProtocol.fromContext(ctx);
|
|
100
|
+
}
|
|
101
|
+
async getFormatMessages(userMessages) {
|
|
102
|
+
const { provider } = await this.plugin.aiManager.getLLMService({
|
|
103
|
+
...this.model
|
|
104
|
+
});
|
|
105
|
+
const { messages } = await this.aiChatConversation.getChatContext({
|
|
106
|
+
userMessages,
|
|
107
|
+
formatMessages: (messages2) => this.formatMessages({ messages: messages2, provider })
|
|
108
|
+
});
|
|
109
|
+
return messages;
|
|
110
|
+
}
|
|
111
|
+
async isInWorkflow() {
|
|
112
|
+
if (this.inWorkflow !== void 0) {
|
|
113
|
+
return this.inWorkflow;
|
|
114
|
+
}
|
|
115
|
+
const conversation = await this.aiConversationsRepo.findByTargetKey(this.sessionId);
|
|
116
|
+
this.inWorkflow = (conversation == null ? void 0 : conversation.category) === "task";
|
|
117
|
+
return this.inWorkflow;
|
|
86
118
|
}
|
|
87
119
|
// === Chat flow ===
|
|
88
120
|
buildState(messages) {
|
|
@@ -96,12 +128,14 @@ class AIEmployee {
|
|
|
96
128
|
};
|
|
97
129
|
}
|
|
98
130
|
async initSession({ messageId, provider, model, providerName }) {
|
|
99
|
-
const tools = await this.
|
|
131
|
+
const { tools, baseToolNames } = await this.getAgentTools();
|
|
132
|
+
const resolvedTools = provider.resolveTools(tools.map(import_utils.buildTool));
|
|
100
133
|
if (!messageId && this.legacy !== true) {
|
|
101
134
|
return {
|
|
102
135
|
historyMessages: [],
|
|
103
136
|
tools,
|
|
104
|
-
|
|
137
|
+
resolvedTools,
|
|
138
|
+
middleware: await this.getMiddleware({ tools, baseToolNames, model, providerName }),
|
|
105
139
|
config: void 0,
|
|
106
140
|
state: void 0
|
|
107
141
|
};
|
|
@@ -113,8 +147,10 @@ class AIEmployee {
|
|
|
113
147
|
return {
|
|
114
148
|
historyMessages,
|
|
115
149
|
tools,
|
|
116
|
-
|
|
150
|
+
resolvedTools,
|
|
151
|
+
middleware: await this.getMiddleware({
|
|
117
152
|
tools,
|
|
153
|
+
baseToolNames,
|
|
118
154
|
model,
|
|
119
155
|
providerName,
|
|
120
156
|
messageId,
|
|
@@ -136,7 +172,7 @@ class AIEmployee {
|
|
|
136
172
|
const { provider, model, service } = await this.plugin.aiManager.getLLMService({
|
|
137
173
|
...this.model
|
|
138
174
|
});
|
|
139
|
-
const { historyMessages, tools, middleware, config, state } = await this.initSession({
|
|
175
|
+
const { historyMessages, tools, resolvedTools, middleware, config, state } = await this.initSession({
|
|
140
176
|
messageId,
|
|
141
177
|
provider,
|
|
142
178
|
model,
|
|
@@ -145,7 +181,7 @@ class AIEmployee {
|
|
|
145
181
|
const chatContext = await this.aiChatConversation.getChatContext({
|
|
146
182
|
userMessages: [...historyMessages, ...userMessages ?? []],
|
|
147
183
|
userDecisions,
|
|
148
|
-
tools,
|
|
184
|
+
tools: resolvedTools,
|
|
149
185
|
middleware,
|
|
150
186
|
getSystemPrompt: (userMessages2) => this.getSystemPrompt(userMessages2),
|
|
151
187
|
formatMessages: (messages) => this.formatMessages({ messages, provider })
|
|
@@ -157,6 +193,12 @@ class AIEmployee {
|
|
|
157
193
|
userMessages = [],
|
|
158
194
|
userDecisions
|
|
159
195
|
}) {
|
|
196
|
+
await this.aiConversationsRepo.update({
|
|
197
|
+
values: { llmActiveState: "streaming" },
|
|
198
|
+
filter: {
|
|
199
|
+
sessionId: this.sessionId
|
|
200
|
+
}
|
|
201
|
+
});
|
|
160
202
|
try {
|
|
161
203
|
const { providerName, model, provider, chatContext, config, state } = await this.buildChatContext({
|
|
162
204
|
messageId,
|
|
@@ -183,13 +225,29 @@ class AIEmployee {
|
|
|
183
225
|
this.ctx.log.error(err);
|
|
184
226
|
this.sendErrorResponse(err.message || "Chat error warning");
|
|
185
227
|
return false;
|
|
228
|
+
} finally {
|
|
229
|
+
await this.aiConversationsRepo.update({
|
|
230
|
+
values: { llmActiveState: "idle" },
|
|
231
|
+
filter: {
|
|
232
|
+
sessionId: this.sessionId
|
|
233
|
+
}
|
|
234
|
+
});
|
|
186
235
|
}
|
|
187
236
|
}
|
|
188
237
|
async invoke({
|
|
189
238
|
messageId,
|
|
190
239
|
userMessages = [],
|
|
191
|
-
userDecisions
|
|
240
|
+
userDecisions,
|
|
241
|
+
writer,
|
|
242
|
+
context
|
|
192
243
|
}) {
|
|
244
|
+
var _a;
|
|
245
|
+
await this.aiConversationsRepo.update({
|
|
246
|
+
values: { llmActiveState: "invoking" },
|
|
247
|
+
filter: {
|
|
248
|
+
sessionId: this.sessionId
|
|
249
|
+
}
|
|
250
|
+
});
|
|
193
251
|
try {
|
|
194
252
|
const { provider, chatContext, config, state } = await this.buildChatContext({
|
|
195
253
|
messageId,
|
|
@@ -198,15 +256,28 @@ class AIEmployee {
|
|
|
198
256
|
});
|
|
199
257
|
const { threadId } = await this.getCurrentThread();
|
|
200
258
|
const invokeConfig = {
|
|
201
|
-
|
|
202
|
-
context: { ctx: this.ctx },
|
|
259
|
+
context: { ctx: this.ctx, decisions: chatContext.decisions, ...context },
|
|
203
260
|
recursionLimit: 100,
|
|
261
|
+
configurable: this.from === "main-agent" ? { thread_id: threadId } : void 0,
|
|
262
|
+
writer,
|
|
204
263
|
...config
|
|
205
264
|
};
|
|
206
|
-
|
|
265
|
+
const invokeResult = await this.agentInvoke(provider, chatContext, invokeConfig, state);
|
|
266
|
+
await this.handleInterruptedToolCalls((_a = invokeResult == null ? void 0 : invokeResult.__interrupt__) == null ? void 0 : _a[0], () => invokeResult == null ? void 0 : invokeResult.messageId);
|
|
267
|
+
return invokeResult;
|
|
207
268
|
} catch (err) {
|
|
269
|
+
if (err.name === "GraphInterrupt") {
|
|
270
|
+
throw err;
|
|
271
|
+
}
|
|
208
272
|
this.ctx.log.error(err);
|
|
209
273
|
throw err;
|
|
274
|
+
} finally {
|
|
275
|
+
await this.aiConversationsRepo.update({
|
|
276
|
+
values: { llmActiveState: "idle" },
|
|
277
|
+
filter: {
|
|
278
|
+
sessionId: this.sessionId
|
|
279
|
+
}
|
|
280
|
+
});
|
|
210
281
|
}
|
|
211
282
|
}
|
|
212
283
|
// === Agent wiring & execution ===
|
|
@@ -217,17 +288,24 @@ class AIEmployee {
|
|
|
217
288
|
middleware
|
|
218
289
|
}) {
|
|
219
290
|
const model = provider.createModel();
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
291
|
+
const allTools = tools ?? [];
|
|
292
|
+
if (this.from === "main-agent") {
|
|
293
|
+
const checkpointer = new import_checkpoints.SequelizeCollectionSaver(() => this.ctx.app.mainDataSource);
|
|
294
|
+
return (0, import_langchain.createAgent)({ model, tools: allTools, middleware, systemPrompt, checkpointer });
|
|
295
|
+
} else {
|
|
296
|
+
return (0, import_langchain.createAgent)({ model, tools: allTools, middleware, systemPrompt });
|
|
297
|
+
}
|
|
224
298
|
}
|
|
225
299
|
getAgentInput(context, state) {
|
|
226
|
-
var _a;
|
|
227
|
-
if ((_a = context.decisions) == null ? void 0 : _a.length) {
|
|
300
|
+
var _a, _b;
|
|
301
|
+
if ((_b = (_a = context.decisions) == null ? void 0 : _a.decisions) == null ? void 0 : _b.length) {
|
|
228
302
|
return new import_langgraph.Command({
|
|
229
|
-
resume: {
|
|
230
|
-
decisions:
|
|
303
|
+
resume: context.decisions.interruptId ? {
|
|
304
|
+
[context.decisions.interruptId]: {
|
|
305
|
+
decisions: context.decisions.decisions
|
|
306
|
+
}
|
|
307
|
+
} : {
|
|
308
|
+
decisions: context.decisions.decisions
|
|
231
309
|
}
|
|
232
310
|
});
|
|
233
311
|
}
|
|
@@ -240,13 +318,16 @@ class AIEmployee {
|
|
|
240
318
|
const { systemPrompt, tools, middleware } = context;
|
|
241
319
|
const agent = await this.createAgent({ provider, systemPrompt, tools, middleware });
|
|
242
320
|
const input = this.getAgentInput(context, state);
|
|
243
|
-
|
|
321
|
+
if (this.from === "sub-agent") {
|
|
322
|
+
delete config.configurable;
|
|
323
|
+
}
|
|
324
|
+
return agent.stream(input, this.withRunMetadata(config));
|
|
244
325
|
}
|
|
245
326
|
async agentInvoke(provider, context, config, state) {
|
|
246
327
|
const { systemPrompt, tools, middleware } = context;
|
|
247
328
|
const agent = await this.createAgent({ provider, systemPrompt, tools, middleware });
|
|
248
329
|
const input = this.getAgentInput(context, state);
|
|
249
|
-
return agent.invoke(input, config);
|
|
330
|
+
return agent.invoke(input, this.withRunMetadata(config));
|
|
250
331
|
}
|
|
251
332
|
async prepareChatStream({
|
|
252
333
|
chatContext,
|
|
@@ -264,8 +345,8 @@ class AIEmployee {
|
|
|
264
345
|
{
|
|
265
346
|
signal,
|
|
266
347
|
streamMode: ["updates", "messages", "custom"],
|
|
267
|
-
configurable: { thread_id: threadId },
|
|
268
|
-
context: { ctx: this.ctx },
|
|
348
|
+
configurable: this.from === "main-agent" ? { thread_id: threadId } : void 0,
|
|
349
|
+
context: { ctx: this.ctx, decisions: chatContext.decisions },
|
|
269
350
|
recursionLimit: 100,
|
|
270
351
|
...config
|
|
271
352
|
},
|
|
@@ -278,8 +359,8 @@ class AIEmployee {
|
|
|
278
359
|
}
|
|
279
360
|
}
|
|
280
361
|
async processChatStream(stream, options) {
|
|
281
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
282
|
-
|
|
362
|
+
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;
|
|
363
|
+
const aiMessageIdMap = /* @__PURE__ */ new Map();
|
|
283
364
|
const { signal, providerName, model, provider, responseMetadata, allowEmpty = false } = options;
|
|
284
365
|
let isReasoning = false;
|
|
285
366
|
let gathered;
|
|
@@ -297,9 +378,6 @@ class AIEmployee {
|
|
|
297
378
|
}
|
|
298
379
|
await this.aiChatConversation.withTransaction(async (conversation, transaction) => {
|
|
299
380
|
const result = await conversation.addMessages(values);
|
|
300
|
-
if (toolCalls == null ? void 0 : toolCalls.length) {
|
|
301
|
-
await this.initToolCall(transaction, result.messageId, toolCalls);
|
|
302
|
-
}
|
|
303
381
|
});
|
|
304
382
|
}
|
|
305
383
|
} catch (e) {
|
|
@@ -307,60 +385,66 @@ class AIEmployee {
|
|
|
307
385
|
}
|
|
308
386
|
});
|
|
309
387
|
try {
|
|
310
|
-
|
|
388
|
+
const aiEmployeeConversation = {
|
|
389
|
+
sessionId: this.sessionId,
|
|
390
|
+
from: this.from,
|
|
391
|
+
username: this.employee.username
|
|
392
|
+
};
|
|
393
|
+
this.protocol.with(aiEmployeeConversation).startStream();
|
|
311
394
|
for await (const [mode, chunks] of stream) {
|
|
312
395
|
if (mode === "messages") {
|
|
313
|
-
const [chunk] = chunks;
|
|
396
|
+
const [chunk, metadata] = chunks;
|
|
397
|
+
const { currentConversation } = metadata;
|
|
314
398
|
if (chunk.type === "ai") {
|
|
315
399
|
gathered = gathered !== void 0 ? (0, import_stream.concat)(gathered, chunk) : chunk;
|
|
316
400
|
if (chunk.content) {
|
|
317
401
|
if (isReasoning) {
|
|
318
402
|
isReasoning = false;
|
|
319
|
-
this.protocol.stopReasoning();
|
|
403
|
+
this.protocol.with(currentConversation).stopReasoning();
|
|
320
404
|
}
|
|
321
405
|
const parsedContent = provider.parseResponseChunk(chunk.content);
|
|
322
406
|
if (parsedContent) {
|
|
323
|
-
this.protocol.content(parsedContent);
|
|
407
|
+
this.protocol.with(currentConversation).content(parsedContent);
|
|
324
408
|
}
|
|
325
409
|
}
|
|
326
410
|
if ((_a = chunk.tool_call_chunks) == null ? void 0 : _a.length) {
|
|
327
|
-
this.protocol.toolCallChunks(chunk.tool_call_chunks);
|
|
411
|
+
this.protocol.with(currentConversation).toolCallChunks(chunk.tool_call_chunks);
|
|
328
412
|
}
|
|
329
413
|
const webSearch = provider.parseWebSearchAction(chunk);
|
|
330
414
|
if (webSearch == null ? void 0 : webSearch.length) {
|
|
331
|
-
this.protocol.webSearch(webSearch);
|
|
415
|
+
this.protocol.with(currentConversation).webSearch(webSearch);
|
|
332
416
|
}
|
|
333
417
|
const reasoningContent = provider.parseReasoningContent(chunk);
|
|
334
418
|
if (reasoningContent) {
|
|
335
419
|
isReasoning = true;
|
|
336
|
-
this.protocol.reasoning(reasoningContent);
|
|
420
|
+
this.protocol.with(currentConversation).reasoning(reasoningContent);
|
|
337
421
|
}
|
|
338
422
|
}
|
|
339
423
|
} else if (mode === "updates") {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
await this.updateToolCallInterrupted(toolCall.messageId, toolCall.id, interruptAction);
|
|
349
|
-
this.protocol.toolCallStatus({
|
|
424
|
+
const interrupt = (_b = chunks == null ? void 0 : chunks.__interrupt__) == null ? void 0 : _b[0];
|
|
425
|
+
if (interrupt) {
|
|
426
|
+
const toolsMap = await this.getToolsMap();
|
|
427
|
+
await this.handleInterruptedToolCalls(
|
|
428
|
+
interrupt,
|
|
429
|
+
(sessionId) => aiMessageIdMap.get(sessionId),
|
|
430
|
+
({ messageId, interruptAction, toolCall, currentConversation }) => {
|
|
431
|
+
this.protocol.with(currentConversation).toolCallStatus({
|
|
350
432
|
toolCall: {
|
|
351
|
-
messageId
|
|
433
|
+
messageId,
|
|
352
434
|
id: toolCall.id,
|
|
353
435
|
name: toolCall.name,
|
|
354
|
-
willInterrupt: toolCall.
|
|
436
|
+
willInterrupt: this.shouldInterruptToolCall(toolsMap.get(toolCall.name))
|
|
355
437
|
},
|
|
356
438
|
invokeStatus: "interrupted",
|
|
357
439
|
interruptAction
|
|
358
440
|
});
|
|
359
441
|
}
|
|
360
|
-
|
|
442
|
+
);
|
|
361
443
|
}
|
|
362
444
|
} else if (mode === "custom") {
|
|
445
|
+
const { currentConversation } = chunks;
|
|
363
446
|
if (chunks.action === "AfterAIMessageSaved") {
|
|
447
|
+
aiMessageIdMap.set(currentConversation.sessionId, chunks.body.messageId);
|
|
364
448
|
const data = responseMetadata.get(chunks.body.id);
|
|
365
449
|
if (data) {
|
|
366
450
|
const savedMessage = await this.aiMessagesModel.findOne({
|
|
@@ -388,12 +472,11 @@ class AIEmployee {
|
|
|
388
472
|
}
|
|
389
473
|
}
|
|
390
474
|
} else if (chunks.action === "initToolCalls") {
|
|
391
|
-
toolCalls
|
|
392
|
-
this.protocol.toolCalls(chunks.body);
|
|
475
|
+
this.protocol.with(currentConversation).toolCalls(chunks.body);
|
|
393
476
|
} else if (chunks.action === "beforeToolCall") {
|
|
394
477
|
const toolsMap = await this.getToolsMap();
|
|
395
478
|
const willInterrupt = this.shouldInterruptToolCall(toolsMap.get((_d = (_c = chunks.body) == null ? void 0 : _c.toolCall) == null ? void 0 : _d.name));
|
|
396
|
-
this.protocol.toolCallStatus({
|
|
479
|
+
this.protocol.with(currentConversation).toolCallStatus({
|
|
397
480
|
toolCall: {
|
|
398
481
|
messageId: (_f = (_e = chunks.body) == null ? void 0 : _e.toolCall) == null ? void 0 : _f.messageId,
|
|
399
482
|
id: (_h = (_g = chunks.body) == null ? void 0 : _g.toolCall) == null ? void 0 : _h.id,
|
|
@@ -405,7 +488,7 @@ class AIEmployee {
|
|
|
405
488
|
} else if (chunks.action === "afterToolCall") {
|
|
406
489
|
const toolsMap = await this.getToolsMap();
|
|
407
490
|
const willInterrupt = this.shouldInterruptToolCall(toolsMap.get((_l = (_k = chunks.body) == null ? void 0 : _k.toolCall) == null ? void 0 : _l.name));
|
|
408
|
-
this.protocol.toolCallStatus({
|
|
491
|
+
this.protocol.with(currentConversation).toolCallStatus({
|
|
409
492
|
toolCall: {
|
|
410
493
|
messageId: (_n = (_m = chunks.body) == null ? void 0 : _m.toolCall) == null ? void 0 : _n.messageId,
|
|
411
494
|
id: (_p = (_o = chunks.body) == null ? void 0 : _o.toolCall) == null ? void 0 : _p.id,
|
|
@@ -413,7 +496,10 @@ class AIEmployee {
|
|
|
413
496
|
willInterrupt
|
|
414
497
|
},
|
|
415
498
|
invokeStatus: "done",
|
|
416
|
-
status: (_t = (_s = chunks.body) == null ? void 0 : _s.toolCallResult) == null ? void 0 : _t.status
|
|
499
|
+
status: (_t = (_s = chunks.body) == null ? void 0 : _s.toolCallResult) == null ? void 0 : _t.status,
|
|
500
|
+
invokeStartTime: (_v = (_u = chunks.body) == null ? void 0 : _u.toolCallResult) == null ? void 0 : _v.invokeStartTime,
|
|
501
|
+
invokeEndTime: (_x = (_w = chunks.body) == null ? void 0 : _w.toolCallResult) == null ? void 0 : _x.invokeEndTime,
|
|
502
|
+
content: (_z = (_y = chunks.body) == null ? void 0 : _y.toolCallResult) == null ? void 0 : _z.content
|
|
417
503
|
});
|
|
418
504
|
} else if (chunks.action === "beforeSendToolMessage") {
|
|
419
505
|
const { messageId, messages } = chunks.body ?? {};
|
|
@@ -426,7 +512,7 @@ class AIEmployee {
|
|
|
426
512
|
for (const { metadata } of messages) {
|
|
427
513
|
const tools = toolsMap.get(metadata.toolName);
|
|
428
514
|
const toolCallResult = toolCallResultMap.get(metadata.toolCallId);
|
|
429
|
-
this.protocol.toolCallStatus({
|
|
515
|
+
this.protocol.with(currentConversation).toolCallStatus({
|
|
430
516
|
toolCall: {
|
|
431
517
|
messageId,
|
|
432
518
|
id: metadata.toolCallId,
|
|
@@ -434,11 +520,16 @@ class AIEmployee {
|
|
|
434
520
|
willInterrupt: this.shouldInterruptToolCall(tools)
|
|
435
521
|
},
|
|
436
522
|
invokeStatus: "confirmed",
|
|
437
|
-
status: toolCallResult == null ? void 0 : toolCallResult.status
|
|
523
|
+
status: toolCallResult == null ? void 0 : toolCallResult.status,
|
|
524
|
+
invokeStartTime: toolCallResult == null ? void 0 : toolCallResult.invokeStartTime,
|
|
525
|
+
invokeEndTime: toolCallResult == null ? void 0 : toolCallResult.invokeEndTime,
|
|
526
|
+
content: toolCallResult == null ? void 0 : toolCallResult.content
|
|
438
527
|
});
|
|
439
528
|
}
|
|
440
529
|
}
|
|
441
|
-
this.protocol.newMessage();
|
|
530
|
+
this.protocol.with(currentConversation).newMessage();
|
|
531
|
+
} else if (chunks.action === "afterSubAgentInvoke") {
|
|
532
|
+
this.protocol.with(currentConversation).subAgentCompleted();
|
|
442
533
|
}
|
|
443
534
|
}
|
|
444
535
|
}
|
|
@@ -446,7 +537,7 @@ class AIEmployee {
|
|
|
446
537
|
this.sendErrorResponse("Empty message");
|
|
447
538
|
return;
|
|
448
539
|
}
|
|
449
|
-
this.protocol.endStream();
|
|
540
|
+
this.protocol.with(aiEmployeeConversation).endStream();
|
|
450
541
|
} catch (err) {
|
|
451
542
|
this.ctx.log.error(err);
|
|
452
543
|
if (err.name === "GraphRecursionError") {
|
|
@@ -455,7 +546,42 @@ class AIEmployee {
|
|
|
455
546
|
this.sendErrorResponse(provider.parseResponseError(err));
|
|
456
547
|
}
|
|
457
548
|
} finally {
|
|
458
|
-
this.
|
|
549
|
+
if (this.from === "main-agent") {
|
|
550
|
+
this.ctx.res.end();
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
async handleInterruptedToolCalls(interrupt, getMessageId, onInterrupted) {
|
|
555
|
+
const interruptId = interrupt == null ? void 0 : interrupt.id;
|
|
556
|
+
const interruptActions = this.toInterruptActions(interrupt == null ? void 0 : interrupt.value);
|
|
557
|
+
if (!interruptId || !interruptActions.size) {
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
for (const interruptAction of interruptActions.values()) {
|
|
561
|
+
const currentConversation = interruptAction.currentConversation;
|
|
562
|
+
const toolCall = interruptAction.toolCall;
|
|
563
|
+
if (!currentConversation || !toolCall) {
|
|
564
|
+
this.logger.warn("currentConversation or toolCall not exist in __interrupt__", interruptAction);
|
|
565
|
+
continue;
|
|
566
|
+
}
|
|
567
|
+
const messageId = getMessageId(currentConversation.sessionId);
|
|
568
|
+
if (!messageId) {
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
await this.updateToolCallInterrupted(
|
|
572
|
+
currentConversation.sessionId,
|
|
573
|
+
messageId,
|
|
574
|
+
toolCall.id,
|
|
575
|
+
interruptId,
|
|
576
|
+
interruptAction
|
|
577
|
+
);
|
|
578
|
+
await (onInterrupted == null ? void 0 : onInterrupted({
|
|
579
|
+
messageId,
|
|
580
|
+
interruptId,
|
|
581
|
+
interruptAction,
|
|
582
|
+
toolCall,
|
|
583
|
+
currentConversation
|
|
584
|
+
}));
|
|
459
585
|
}
|
|
460
586
|
}
|
|
461
587
|
// === Prompts & knowledge base ===
|
|
@@ -501,10 +627,10 @@ Field: ${field.name}, Title: ${(_a = field.options.uiSchema) == null ? void 0 :
|
|
|
501
627
|
return message;
|
|
502
628
|
}
|
|
503
629
|
async getSystemPrompt(userMessages) {
|
|
504
|
-
var _a;
|
|
630
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
505
631
|
const userConfig = await this.db.getRepository("usersAiEmployees").findOne({
|
|
506
632
|
filter: {
|
|
507
|
-
userId: (_a = this.ctx.auth) == null ? void 0 : _a.user.id,
|
|
633
|
+
userId: ((_a = this.ctx.auth) == null ? void 0 : _a.user.id) ?? 0,
|
|
508
634
|
aiEmployee: this.employee.username
|
|
509
635
|
}
|
|
510
636
|
});
|
|
@@ -530,17 +656,19 @@ ${workContextBackground.join("\n")}`;
|
|
|
530
656
|
${addSystemPrompt.map((it) => it.content).join("\n")}`;
|
|
531
657
|
}
|
|
532
658
|
let knowledgeBase;
|
|
533
|
-
|
|
659
|
+
const { knowledgeBaseManager } = this.plugin;
|
|
660
|
+
const employee = this.employee.toJSON();
|
|
661
|
+
if (await knowledgeBaseManager.isEnabledKnowledgeBase(employee) && employee.knowledgeBasePrompt && (userMessages == null ? void 0 : userMessages.length)) {
|
|
534
662
|
const lastUserMessage = userMessages.filter((x) => x.role === "user").at(-1);
|
|
535
663
|
if (lastUserMessage) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
knowledgeBase = import_lodash.default.isEmpty(knowledgeBaseData) ? void 0 : await promptTemplate.format({
|
|
540
|
-
knowledgeBaseData
|
|
664
|
+
knowledgeBase = await knowledgeBaseManager.retrievePrompt({
|
|
665
|
+
employee,
|
|
666
|
+
query: lastUserMessage.content.content
|
|
541
667
|
});
|
|
542
668
|
}
|
|
543
669
|
}
|
|
670
|
+
const availableSkills = await this.getAvailableSkills();
|
|
671
|
+
const availableAIEmployees = await this.getAvailableAIEmployees();
|
|
544
672
|
const systemPrompt = (0, import_prompts.getSystemPrompt)({
|
|
545
673
|
aiEmployee: {
|
|
546
674
|
nickname: this.employee.nickname,
|
|
@@ -553,11 +681,15 @@ ${addSystemPrompt.map((it) => it.content).join("\n")}`;
|
|
|
553
681
|
dataSources: dataSourceMessage,
|
|
554
682
|
environment: {
|
|
555
683
|
database: this.db.sequelize.getDialect(),
|
|
556
|
-
locale: this.ctx.getCurrentLocale() || "en-US"
|
|
684
|
+
locale: ((_c = (_b = this.ctx).getCurrentLocale) == null ? void 0 : _c.call(_b)) || "en-US",
|
|
685
|
+
currentDateTime: getCurrentDateTimeForPrompt((_e = (_d = this.ctx).getCurrentLocale) == null ? void 0 : _e.call(_d), getCurrentTimezone(this.ctx)),
|
|
686
|
+
timezone: getCurrentTimezone(this.ctx)
|
|
557
687
|
},
|
|
558
|
-
knowledgeBase
|
|
688
|
+
knowledgeBase,
|
|
689
|
+
availableSkills,
|
|
690
|
+
availableAIEmployees
|
|
559
691
|
});
|
|
560
|
-
const { important } = this.ctx.action.params.values || {};
|
|
692
|
+
const { important } = ((_g = (_f = this.ctx.action) == null ? void 0 : _f.params) == null ? void 0 : _g.values) || {};
|
|
561
693
|
if (important === "GraphRecursionError") {
|
|
562
694
|
const importantPrompt = `<Important>You have already called tools multiple times and gathered sufficient information.
|
|
563
695
|
First, provide a summary based on the existing information. Do not call additional tools.
|
|
@@ -567,92 +699,6 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
567
699
|
return systemPrompt;
|
|
568
700
|
}
|
|
569
701
|
}
|
|
570
|
-
async retrieveKnowledgeBase(userMessage) {
|
|
571
|
-
const vectorStoreProvider = this.plugin.features.vectorStoreProvider;
|
|
572
|
-
let queryResult = [];
|
|
573
|
-
const queryString = userMessage.content.content;
|
|
574
|
-
if (!queryString || import_lodash.default.isEmpty(queryString)) {
|
|
575
|
-
return queryResult;
|
|
576
|
-
}
|
|
577
|
-
const { topK, score } = this.getAIEmployeeKnowledgeBaseConfig();
|
|
578
|
-
const knowledgeBaseGroup = await this.getKnowledgeBaseGroup();
|
|
579
|
-
for (const entry of knowledgeBaseGroup) {
|
|
580
|
-
const { vectorStoreConfig, knowledgeBaseType, knowledgeBaseList } = entry;
|
|
581
|
-
if (!knowledgeBaseList || import_lodash.default.isEmpty(knowledgeBaseList)) {
|
|
582
|
-
continue;
|
|
583
|
-
}
|
|
584
|
-
if (knowledgeBaseType === "LOCAL") {
|
|
585
|
-
const vectorStoreService = await vectorStoreProvider.createVectorStoreService(
|
|
586
|
-
vectorStoreConfig.vectorStoreProvider,
|
|
587
|
-
[
|
|
588
|
-
{
|
|
589
|
-
key: "vectorStoreConfigId",
|
|
590
|
-
value: vectorStoreConfig.vectorStoreConfigId
|
|
591
|
-
}
|
|
592
|
-
]
|
|
593
|
-
);
|
|
594
|
-
const knowledgeBaseOuterIds = knowledgeBaseList.map((x) => x.knowledgeBaseOuterId);
|
|
595
|
-
const result = await vectorStoreService.search(queryString, {
|
|
596
|
-
topK,
|
|
597
|
-
score,
|
|
598
|
-
filter: {
|
|
599
|
-
knowledgeBaseOuterId: { in: knowledgeBaseOuterIds }
|
|
600
|
-
}
|
|
601
|
-
});
|
|
602
|
-
queryResult = [...queryResult, ...result];
|
|
603
|
-
} else if (knowledgeBaseType === "READONLY") {
|
|
604
|
-
for (const knowledgeBase of knowledgeBaseList) {
|
|
605
|
-
const vectorStoreService = await vectorStoreProvider.createVectorStoreService(
|
|
606
|
-
vectorStoreConfig.vectorStoreProvider,
|
|
607
|
-
[
|
|
608
|
-
...knowledgeBase.vectorStoreProps,
|
|
609
|
-
{
|
|
610
|
-
key: "vectorStoreConfigId",
|
|
611
|
-
value: vectorStoreConfig.vectorStoreConfigId
|
|
612
|
-
}
|
|
613
|
-
]
|
|
614
|
-
);
|
|
615
|
-
const result = await vectorStoreService.search(queryString, {
|
|
616
|
-
topK,
|
|
617
|
-
score
|
|
618
|
-
});
|
|
619
|
-
queryResult = [...queryResult, ...result];
|
|
620
|
-
}
|
|
621
|
-
} else if (knowledgeBaseType === "EXTERNAL") {
|
|
622
|
-
for (const knowledgeBase of knowledgeBaseList) {
|
|
623
|
-
const vectorStoreService = await vectorStoreProvider.createVectorStoreService(
|
|
624
|
-
vectorStoreConfig.vectorStoreProvider,
|
|
625
|
-
knowledgeBase.vectorStoreProps
|
|
626
|
-
);
|
|
627
|
-
const result = await vectorStoreService.search(queryString, {
|
|
628
|
-
topK,
|
|
629
|
-
score
|
|
630
|
-
});
|
|
631
|
-
queryResult = [...queryResult, ...result];
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
return queryResult;
|
|
636
|
-
}
|
|
637
|
-
isEnabledKnowledgeBase() {
|
|
638
|
-
const featureEnabled = this.plugin.features.isFeaturesEnabled(Object.values(import_ai_feature_manager.EEFeatures));
|
|
639
|
-
const knowledgeBaseEnabled = this.employee.enableKnowledgeBase;
|
|
640
|
-
return featureEnabled && knowledgeBaseEnabled;
|
|
641
|
-
}
|
|
642
|
-
getAIEmployeeKnowledgeBaseConfig() {
|
|
643
|
-
const { topK, score } = this.employee.knowledgeBase ?? {};
|
|
644
|
-
return {
|
|
645
|
-
topK,
|
|
646
|
-
score
|
|
647
|
-
};
|
|
648
|
-
}
|
|
649
|
-
async getKnowledgeBaseGroup() {
|
|
650
|
-
const { knowledgeBaseIds } = this.employee.knowledgeBase ?? {};
|
|
651
|
-
if (!knowledgeBaseIds || import_lodash.default.isEmpty(knowledgeBaseIds)) {
|
|
652
|
-
return [];
|
|
653
|
-
}
|
|
654
|
-
return await this.plugin.features.knowledgeBase.getKnowledgeBaseGroup(knowledgeBaseIds);
|
|
655
|
-
}
|
|
656
702
|
// === Tool calls ===
|
|
657
703
|
async initToolCall(transaction, messageId, toolCalls) {
|
|
658
704
|
const nowTime = /* @__PURE__ */ new Date();
|
|
@@ -680,23 +726,54 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
680
726
|
transaction
|
|
681
727
|
});
|
|
682
728
|
}
|
|
683
|
-
async updateToolCallInterrupted(messageId, toolCallId, interruptAction) {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
729
|
+
async updateToolCallInterrupted(sessionId, messageId, toolCallId, interruptId, interruptAction) {
|
|
730
|
+
return await this.db.sequelize.transaction(async (transaction) => {
|
|
731
|
+
const [updated] = await this.aiToolMessagesModel.update(
|
|
732
|
+
{
|
|
733
|
+
invokeStatus: "interrupted",
|
|
734
|
+
interruptActionOrder: interruptAction.order,
|
|
735
|
+
interruptAction
|
|
736
|
+
},
|
|
737
|
+
{
|
|
738
|
+
where: {
|
|
739
|
+
sessionId,
|
|
740
|
+
messageId,
|
|
741
|
+
toolCallId,
|
|
742
|
+
invokeStatus: "init"
|
|
743
|
+
},
|
|
744
|
+
transaction
|
|
745
|
+
}
|
|
746
|
+
);
|
|
747
|
+
if (!updated) {
|
|
748
|
+
return updated;
|
|
749
|
+
}
|
|
750
|
+
const message = await this.aiMessagesModel.findOne({
|
|
691
751
|
where: {
|
|
692
|
-
sessionId: this.sessionId,
|
|
693
752
|
messageId,
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
753
|
+
sessionId
|
|
754
|
+
},
|
|
755
|
+
transaction
|
|
756
|
+
});
|
|
757
|
+
if (!message) {
|
|
758
|
+
return updated;
|
|
697
759
|
}
|
|
698
|
-
|
|
699
|
-
|
|
760
|
+
await this.aiMessagesModel.update(
|
|
761
|
+
{
|
|
762
|
+
metadata: {
|
|
763
|
+
...message.get("metadata") ?? {},
|
|
764
|
+
interruptId
|
|
765
|
+
}
|
|
766
|
+
},
|
|
767
|
+
{
|
|
768
|
+
where: {
|
|
769
|
+
messageId,
|
|
770
|
+
sessionId
|
|
771
|
+
},
|
|
772
|
+
transaction
|
|
773
|
+
}
|
|
774
|
+
);
|
|
775
|
+
return updated;
|
|
776
|
+
});
|
|
700
777
|
}
|
|
701
778
|
async updateToolCallPending(messageId, toolCallId) {
|
|
702
779
|
const [updated] = await this.aiToolMessagesModel.update(
|
|
@@ -758,7 +835,6 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
758
835
|
var _a;
|
|
759
836
|
return (_a = await this.aiToolMessagesModel.findOne({
|
|
760
837
|
where: {
|
|
761
|
-
sessionId: this.sessionId,
|
|
762
838
|
messageId,
|
|
763
839
|
toolCallId
|
|
764
840
|
}
|
|
@@ -767,7 +843,6 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
767
843
|
async getToolCallResultMap(messageId, toolCallIds) {
|
|
768
844
|
const list = (await this.aiToolMessagesModel.findAll({
|
|
769
845
|
where: {
|
|
770
|
-
sessionId: this.sessionId,
|
|
771
846
|
messageId,
|
|
772
847
|
toolCallId: {
|
|
773
848
|
[import_database.Op.in]: toolCallIds
|
|
@@ -776,19 +851,6 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
776
851
|
})).map((it) => it.toJSON());
|
|
777
852
|
return new Map(list.map((it) => [it.toolCallId, it]));
|
|
778
853
|
}
|
|
779
|
-
async getUserDecisions(messageId) {
|
|
780
|
-
const allInterruptedToolCall = await this.aiToolMessagesModel.findAll({
|
|
781
|
-
where: {
|
|
782
|
-
messageId,
|
|
783
|
-
interruptActionOrder: { [import_database.Op.not]: null }
|
|
784
|
-
},
|
|
785
|
-
order: [["interruptActionOrder", "ASC"]]
|
|
786
|
-
});
|
|
787
|
-
if (!allInterruptedToolCall.every((t) => t.invokeStatus === "waiting")) {
|
|
788
|
-
return [];
|
|
789
|
-
}
|
|
790
|
-
return allInterruptedToolCall.map((item) => item.userDecision);
|
|
791
|
-
}
|
|
792
854
|
async cancelToolCall() {
|
|
793
855
|
var _a;
|
|
794
856
|
let messageId;
|
|
@@ -803,7 +865,6 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
803
865
|
}
|
|
804
866
|
const toolMessages = (await this.aiToolMessagesModel.findAll({
|
|
805
867
|
where: {
|
|
806
|
-
sessionId: this.sessionId,
|
|
807
868
|
messageId,
|
|
808
869
|
invokeStatus: {
|
|
809
870
|
[import_database.Op.ne]: "confirmed"
|
|
@@ -895,8 +956,8 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
895
956
|
if (tools.scope !== "CUSTOM") {
|
|
896
957
|
return isAutoCall;
|
|
897
958
|
}
|
|
898
|
-
const
|
|
899
|
-
const presetTools =
|
|
959
|
+
const employeeTools = ((_a = this.employee.skillSettings) == null ? void 0 : _a.tools) ?? [];
|
|
960
|
+
const presetTools = employeeTools.find((s) => s.name === tools.definition.name);
|
|
900
961
|
return presetTools ? presetTools.autoCall : isAutoCall;
|
|
901
962
|
}
|
|
902
963
|
async formatMessages({ messages, provider }) {
|
|
@@ -1036,7 +1097,7 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
1036
1097
|
toInterruptActions(interrupt) {
|
|
1037
1098
|
var _a;
|
|
1038
1099
|
const result = /* @__PURE__ */ new Map();
|
|
1039
|
-
const { actionRequests = [], reviewConfigs = [] } = interrupt;
|
|
1100
|
+
const { actionRequests = [], reviewConfigs = [] } = interrupt ?? {};
|
|
1040
1101
|
if (!actionRequests.length) {
|
|
1041
1102
|
return result;
|
|
1042
1103
|
}
|
|
@@ -1044,10 +1105,20 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
1044
1105
|
const actionRequestsMap = new Map(actionRequests.map((x) => [x.name, x]));
|
|
1045
1106
|
const reviewConfigsMap = new Map(reviewConfigs.map((x) => [x.actionName, x]));
|
|
1046
1107
|
for (const [name, actionRequest] of actionRequestsMap.entries()) {
|
|
1108
|
+
const payload = actionRequest.description ? JSON.parse(actionRequest.description) : null;
|
|
1047
1109
|
result.set(name, {
|
|
1048
1110
|
order: order++,
|
|
1049
1111
|
description: actionRequest.description,
|
|
1050
|
-
allowedDecisions: (_a = reviewConfigsMap.get(name)) == null ? void 0 : _a.allowedDecisions
|
|
1112
|
+
allowedDecisions: (_a = reviewConfigsMap.get(name)) == null ? void 0 : _a.allowedDecisions,
|
|
1113
|
+
toolCall: {
|
|
1114
|
+
id: payload.toolCallId,
|
|
1115
|
+
name: payload.toolCallName
|
|
1116
|
+
},
|
|
1117
|
+
currentConversation: {
|
|
1118
|
+
sessionId: payload.sessionId,
|
|
1119
|
+
from: payload.from,
|
|
1120
|
+
username: payload.username
|
|
1121
|
+
}
|
|
1051
1122
|
});
|
|
1052
1123
|
}
|
|
1053
1124
|
return result;
|
|
@@ -1061,25 +1132,120 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
1061
1132
|
}
|
|
1062
1133
|
const generalToolsNameSet = new Set(tools.map((x) => x.definition.name));
|
|
1063
1134
|
const toolMap = await this.getToolsMap();
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1066
|
-
|
|
1135
|
+
const employeeTools = ((_a = this.employee.skillSettings) == null ? void 0 : _a.tools) ?? [];
|
|
1136
|
+
employeeTools.push(...this.tools);
|
|
1137
|
+
if (await this.plugin.knowledgeBaseManager.isEnabledKnowledgeBase(this.employee.toJSON())) {
|
|
1138
|
+
const knowledgeBaseRetrieveTool = await this.toolsManager.getTools("knowledge-base-retrieve");
|
|
1139
|
+
if (knowledgeBaseRetrieveTool) {
|
|
1140
|
+
employeeTools.push({ name: "knowledge-base-retrieve" });
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
for (const toolSetting of employeeTools) {
|
|
1144
|
+
if (generalToolsNameSet.has(toolSetting.name)) {
|
|
1067
1145
|
continue;
|
|
1068
1146
|
}
|
|
1069
|
-
const tool = toolMap.get(
|
|
1147
|
+
const tool = toolMap.get(toolSetting.name);
|
|
1070
1148
|
if (!tool) {
|
|
1071
1149
|
continue;
|
|
1072
1150
|
}
|
|
1073
1151
|
tools.push(tool);
|
|
1074
1152
|
}
|
|
1153
|
+
const toolFilter = ((_b = this.skillSettings) == null ? void 0 : _b.tools) ?? [];
|
|
1154
|
+
return tools.filter((t) => toolFilter.length === 0 || toolFilter.includes(t.definition.name));
|
|
1155
|
+
}
|
|
1156
|
+
async getAvailableSkills() {
|
|
1157
|
+
var _a, _b;
|
|
1158
|
+
const { skillsManager } = this.plugin.ai;
|
|
1159
|
+
const aIEmployeeTools = await this.getAIEmployeeTools();
|
|
1160
|
+
const getSkill = aIEmployeeTools.find((it) => it.definition.name === "getSkill");
|
|
1161
|
+
if (!getSkill) {
|
|
1162
|
+
return [];
|
|
1163
|
+
}
|
|
1164
|
+
const generalSkills = await skillsManager.listSkills({ scope: "GENERAL" });
|
|
1165
|
+
const specifiedSkillNames = ((_a = this.employee.skillSettings) == null ? void 0 : _a.skills) ?? [];
|
|
1166
|
+
const specifiedSkills = specifiedSkillNames.length ? await skillsManager.getSkills(specifiedSkillNames) : [];
|
|
1075
1167
|
const skillFilter = ((_b = this.skillSettings) == null ? void 0 : _b.skills) ?? [];
|
|
1076
|
-
return
|
|
1168
|
+
return import_lodash.default.uniqBy([...specifiedSkills || [], ...generalSkills || []], "name").filter(
|
|
1169
|
+
(it) => skillFilter.length === 0 || skillFilter.includes(it.name)
|
|
1170
|
+
);
|
|
1171
|
+
}
|
|
1172
|
+
async getAgentTools() {
|
|
1173
|
+
const baseTools = await this.getAIEmployeeTools();
|
|
1174
|
+
const toolMap = await this.getToolsMap();
|
|
1175
|
+
const availableSkills = await this.getAvailableSkills();
|
|
1176
|
+
const skillOwnedToolNames = new Set(availableSkills.flatMap((it) => it.tools ?? []));
|
|
1177
|
+
const baseToolNames = new Set(
|
|
1178
|
+
baseTools.map((it) => it.definition.name).filter((name) => name === "getSkill" || !skillOwnedToolNames.has(name))
|
|
1179
|
+
);
|
|
1180
|
+
return {
|
|
1181
|
+
tools: Array.from(toolMap.values()),
|
|
1182
|
+
baseToolNames
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
async getLoadedSkillNames() {
|
|
1186
|
+
const list = await this.aiToolMessagesModel.findAll({
|
|
1187
|
+
where: {
|
|
1188
|
+
sessionId: this.sessionId,
|
|
1189
|
+
toolName: "getSkill",
|
|
1190
|
+
status: "success"
|
|
1191
|
+
},
|
|
1192
|
+
order: [["id", "ASC"]]
|
|
1193
|
+
});
|
|
1194
|
+
const result = /* @__PURE__ */ new Set();
|
|
1195
|
+
for (const item of list) {
|
|
1196
|
+
const { content } = item.toJSON();
|
|
1197
|
+
if (import_lodash.default.isPlainObject(content) && typeof content["skillName"] === "string") {
|
|
1198
|
+
result.add(content["skillName"]);
|
|
1199
|
+
continue;
|
|
1200
|
+
}
|
|
1201
|
+
if (typeof content === "string") {
|
|
1202
|
+
try {
|
|
1203
|
+
const parsed = JSON.parse(content);
|
|
1204
|
+
if (import_lodash.default.isPlainObject(parsed) && typeof parsed["skillName"] === "string") {
|
|
1205
|
+
result.add(parsed["skillName"]);
|
|
1206
|
+
}
|
|
1207
|
+
} catch (e) {
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
return Array.from(result.values());
|
|
1212
|
+
}
|
|
1213
|
+
async getActivatedSkillToolNames() {
|
|
1214
|
+
const loadedSkillNames = await this.getLoadedSkillNames();
|
|
1215
|
+
if (!loadedSkillNames.length) {
|
|
1216
|
+
return /* @__PURE__ */ new Set();
|
|
1217
|
+
}
|
|
1218
|
+
const availableSkills = await this.getAvailableSkills();
|
|
1219
|
+
const loadedSkills = await this.plugin.ai.skillsManager.getSkills(loadedSkillNames);
|
|
1220
|
+
const normalizedLoadedSkills = Array.isArray(loadedSkills) ? loadedSkills : [loadedSkills];
|
|
1221
|
+
const skillsMap = new Map(
|
|
1222
|
+
[...availableSkills, ...normalizedLoadedSkills.filter(Boolean)].map((it) => [it.name, it])
|
|
1223
|
+
);
|
|
1224
|
+
const result = /* @__PURE__ */ new Set();
|
|
1225
|
+
for (const skillName of loadedSkillNames) {
|
|
1226
|
+
const target = skillsMap.get(skillName);
|
|
1227
|
+
for (const toolName of (target == null ? void 0 : target.tools) ?? []) {
|
|
1228
|
+
result.add(toolName);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
return result;
|
|
1232
|
+
}
|
|
1233
|
+
async getAvailableAIEmployees() {
|
|
1234
|
+
const availableAIEmployees = (await (0, import_shared.listAccessibleAIEmployees)(this.ctx)).map(
|
|
1235
|
+
(employee) => (0, import_shared.serializeEmployeeSummary)(this.ctx, employee)
|
|
1236
|
+
);
|
|
1237
|
+
return availableAIEmployees;
|
|
1077
1238
|
}
|
|
1078
|
-
getMiddleware(options) {
|
|
1079
|
-
const { providerName, model, tools, messageId, agentThread } = options;
|
|
1239
|
+
async getMiddleware(options) {
|
|
1240
|
+
const { providerName, model, tools, baseToolNames, messageId, agentThread } = options;
|
|
1241
|
+
const inWorkflow = await this.isInWorkflow();
|
|
1080
1242
|
return [
|
|
1243
|
+
(0, import_middleware.skillToolBindingMiddleware)(this, {
|
|
1244
|
+
baseToolNames: Array.from(baseToolNames.values())
|
|
1245
|
+
}),
|
|
1081
1246
|
(0, import_middleware.toolInteractionMiddleware)(this, tools),
|
|
1082
1247
|
(0, import_middleware.toolCallStatusMiddleware)(this),
|
|
1248
|
+
...inWorkflow ? [(0, import_middleware.workflowHistoryMiddleware)(this, this.db)] : [],
|
|
1083
1249
|
(0, import_middleware.conversationMiddleware)(this, { providerName, model, messageId, agentThread })
|
|
1084
1250
|
];
|
|
1085
1251
|
}
|
|
@@ -1105,12 +1271,27 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
1105
1271
|
throw new Error("Fail to create new agent thread");
|
|
1106
1272
|
}
|
|
1107
1273
|
async getToolsMap() {
|
|
1108
|
-
const tools = await this.listTools(
|
|
1274
|
+
const tools = await this.listTools({
|
|
1275
|
+
sessionId: this.sessionId
|
|
1276
|
+
});
|
|
1109
1277
|
return new Map(tools.map((tool) => [tool.definition.name, tool]));
|
|
1110
1278
|
}
|
|
1111
1279
|
listTools(filter) {
|
|
1112
1280
|
return this.toolsManager.listTools(filter);
|
|
1113
1281
|
}
|
|
1282
|
+
withRunMetadata(config) {
|
|
1283
|
+
return {
|
|
1284
|
+
...config,
|
|
1285
|
+
metadata: {
|
|
1286
|
+
...(config == null ? void 0 : config.metadata) ?? {},
|
|
1287
|
+
currentConversation: {
|
|
1288
|
+
sessionId: this.sessionId,
|
|
1289
|
+
from: this.from,
|
|
1290
|
+
username: this.employee.get("username")
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1114
1295
|
get toolsManager() {
|
|
1115
1296
|
return this.ctx.app.aiManager.toolsManager;
|
|
1116
1297
|
}
|
|
@@ -1133,6 +1314,33 @@ If information is missing, clearly state it in the summary.</Important>`;
|
|
|
1133
1314
|
return this.ctx.db.getModel("aiFiles");
|
|
1134
1315
|
}
|
|
1135
1316
|
}
|
|
1317
|
+
function getCurrentTimezone(ctx) {
|
|
1318
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1319
|
+
const value = ((_a = ctx.get) == null ? void 0 : _a.call(ctx, "x-timezone")) || ((_c = (_b = ctx.request) == null ? void 0 : _b.get) == null ? void 0 : _c.call(_b, "x-timezone")) || ((_e = (_d = ctx.request) == null ? void 0 : _d.header) == null ? void 0 : _e["x-timezone"]) || ((_g = (_f = ctx.req) == null ? void 0 : _f.headers) == null ? void 0 : _g["x-timezone"]) || Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1320
|
+
if (Array.isArray(value)) {
|
|
1321
|
+
return value[0];
|
|
1322
|
+
}
|
|
1323
|
+
return typeof value === "string" ? value : void 0;
|
|
1324
|
+
}
|
|
1325
|
+
function getCurrentDateTimeForPrompt(locale, timezone) {
|
|
1326
|
+
const now = /* @__PURE__ */ new Date();
|
|
1327
|
+
const normalizedLocale = locale || "en-US";
|
|
1328
|
+
try {
|
|
1329
|
+
const formatter = new Intl.DateTimeFormat(normalizedLocale, {
|
|
1330
|
+
timeZone: timezone,
|
|
1331
|
+
year: "numeric",
|
|
1332
|
+
month: "2-digit",
|
|
1333
|
+
day: "2-digit",
|
|
1334
|
+
hour: "2-digit",
|
|
1335
|
+
minute: "2-digit",
|
|
1336
|
+
second: "2-digit",
|
|
1337
|
+
hour12: false
|
|
1338
|
+
});
|
|
1339
|
+
return `${formatter.format(now)}${timezone ? ` (${timezone})` : ""}`;
|
|
1340
|
+
} catch (error) {
|
|
1341
|
+
return `${now.toISOString()}${timezone ? ` (${timezone})` : ""}`;
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1136
1344
|
class AgentThread {
|
|
1137
1345
|
constructor(_sessionId, _thread) {
|
|
1138
1346
|
this._sessionId = _sessionId;
|
|
@@ -1155,8 +1363,8 @@ class AgentThread {
|
|
|
1155
1363
|
}
|
|
1156
1364
|
}
|
|
1157
1365
|
class ChatStreamProtocol {
|
|
1158
|
-
constructor(
|
|
1159
|
-
this.
|
|
1366
|
+
constructor(streamConsumer) {
|
|
1367
|
+
this.streamConsumer = streamConsumer;
|
|
1160
1368
|
}
|
|
1161
1369
|
_statistics = {
|
|
1162
1370
|
sent: 0,
|
|
@@ -1167,71 +1375,85 @@ class ChatStreamProtocol {
|
|
|
1167
1375
|
this._statistics.sent = 0;
|
|
1168
1376
|
}
|
|
1169
1377
|
};
|
|
1170
|
-
static
|
|
1171
|
-
return new ChatStreamProtocol(ctx);
|
|
1172
|
-
}
|
|
1173
|
-
startStream() {
|
|
1174
|
-
this._statistics.reset();
|
|
1175
|
-
this.write({ type: "stream_start" });
|
|
1176
|
-
}
|
|
1177
|
-
endStream() {
|
|
1178
|
-
this.write({ type: "stream_end" });
|
|
1179
|
-
}
|
|
1180
|
-
newMessage(content) {
|
|
1181
|
-
this.write({ type: "new_message", body: content });
|
|
1182
|
-
}
|
|
1183
|
-
content(content) {
|
|
1184
|
-
this.write({ type: "content", body: content });
|
|
1185
|
-
}
|
|
1186
|
-
webSearch(content) {
|
|
1187
|
-
this.write({ type: "web_search", body: content });
|
|
1188
|
-
}
|
|
1189
|
-
reasoning(content) {
|
|
1190
|
-
this.write({ type: "reasoning", body: content });
|
|
1191
|
-
}
|
|
1192
|
-
stopReasoning() {
|
|
1193
|
-
this.write({
|
|
1194
|
-
type: "reasoning",
|
|
1195
|
-
body: {
|
|
1196
|
-
status: "stop",
|
|
1197
|
-
content: ""
|
|
1198
|
-
}
|
|
1199
|
-
});
|
|
1200
|
-
}
|
|
1201
|
-
toolCallChunks(content) {
|
|
1202
|
-
this.write({ type: "tool_call_chunks", body: content });
|
|
1203
|
-
}
|
|
1204
|
-
toolCalls(content) {
|
|
1205
|
-
this.write({ type: "tool_calls", body: content });
|
|
1378
|
+
static fromContext(ctx) {
|
|
1379
|
+
return new ChatStreamProtocol(ctx.res);
|
|
1206
1380
|
}
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1381
|
+
with(conversation) {
|
|
1382
|
+
const write = ({ type, body }) => {
|
|
1383
|
+
const { sessionId, from, username } = conversation;
|
|
1384
|
+
const data = `data: ${JSON.stringify({ sessionId, from, username, type, body })}
|
|
1385
|
+
|
|
1386
|
+
`;
|
|
1387
|
+
this.streamConsumer.write(data);
|
|
1388
|
+
this._statistics.addSent(data.length);
|
|
1389
|
+
};
|
|
1390
|
+
return {
|
|
1391
|
+
startStream: () => {
|
|
1392
|
+
this._statistics.reset();
|
|
1393
|
+
write({ type: "stream_start" });
|
|
1394
|
+
},
|
|
1395
|
+
endStream: () => {
|
|
1396
|
+
write({ type: "stream_end" });
|
|
1397
|
+
},
|
|
1398
|
+
subAgentCompleted: () => {
|
|
1399
|
+
write({ type: "sub_agent_completed" });
|
|
1400
|
+
},
|
|
1401
|
+
newMessage: (content) => {
|
|
1402
|
+
write({ type: "new_message", body: content });
|
|
1403
|
+
},
|
|
1404
|
+
content: (content) => {
|
|
1405
|
+
write({ type: "content", body: content });
|
|
1406
|
+
},
|
|
1407
|
+
webSearch: (content) => {
|
|
1408
|
+
write({ type: "web_search", body: content });
|
|
1409
|
+
},
|
|
1410
|
+
reasoning: (content) => {
|
|
1411
|
+
write({ type: "reasoning", body: content });
|
|
1412
|
+
},
|
|
1413
|
+
stopReasoning: () => {
|
|
1414
|
+
write({
|
|
1415
|
+
type: "reasoning",
|
|
1416
|
+
body: {
|
|
1417
|
+
status: "stop",
|
|
1418
|
+
content: ""
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
},
|
|
1422
|
+
toolCallChunks: (content) => {
|
|
1423
|
+
write({ type: "tool_call_chunks", body: content });
|
|
1424
|
+
},
|
|
1425
|
+
toolCalls: (content) => {
|
|
1426
|
+
write({ type: "tool_calls", body: content });
|
|
1427
|
+
},
|
|
1428
|
+
toolCallStatus: ({
|
|
1216
1429
|
toolCall,
|
|
1217
1430
|
invokeStatus,
|
|
1218
1431
|
status,
|
|
1432
|
+
invokeStartTime,
|
|
1433
|
+
invokeEndTime,
|
|
1434
|
+
content,
|
|
1219
1435
|
interruptAction
|
|
1436
|
+
}) => {
|
|
1437
|
+
write({
|
|
1438
|
+
type: "tool_call_status",
|
|
1439
|
+
body: {
|
|
1440
|
+
toolCall,
|
|
1441
|
+
invokeStatus,
|
|
1442
|
+
status,
|
|
1443
|
+
invokeStartTime,
|
|
1444
|
+
invokeEndTime,
|
|
1445
|
+
content,
|
|
1446
|
+
interruptAction
|
|
1447
|
+
}
|
|
1448
|
+
});
|
|
1220
1449
|
}
|
|
1221
|
-
}
|
|
1450
|
+
};
|
|
1222
1451
|
}
|
|
1223
1452
|
get statistics() {
|
|
1224
1453
|
return {
|
|
1225
1454
|
sent: this._statistics.sent
|
|
1226
1455
|
};
|
|
1227
1456
|
}
|
|
1228
|
-
write({ type, body }) {
|
|
1229
|
-
const data = `data: ${JSON.stringify({ type, body })}
|
|
1230
|
-
|
|
1231
|
-
`;
|
|
1232
|
-
this.ctx.res.write(data);
|
|
1233
|
-
this._statistics.addSent(data.length);
|
|
1234
|
-
}
|
|
1235
1457
|
}
|
|
1236
1458
|
class ResponseMetadataCollector extends import_base.BaseCallbackHandler {
|
|
1237
1459
|
constructor(llmProvider, responseMetadata) {
|
|
@@ -1252,5 +1474,6 @@ class ResponseMetadataCollector extends import_base.BaseCallbackHandler {
|
|
|
1252
1474
|
}
|
|
1253
1475
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1254
1476
|
0 && (module.exports = {
|
|
1255
|
-
AIEmployee
|
|
1477
|
+
AIEmployee,
|
|
1478
|
+
ChatStreamProtocol
|
|
1256
1479
|
});
|