refactor: 重构message模块 (#2561)

* feat: Implement Redux-based message management with enhanced state handling

- Add new Redux slice for managing messages with advanced state control
- Introduce topic-specific message queues using p-queue for request management
- Refactor message sending, loading, and updating logic
- Improve error handling and state synchronization with database
- Add selectors for efficient message retrieval and state access

* feat: Implement streaming message handling in Redux store

- Add stream message support in messages slice
- Create MessageStream component for rendering streaming messages
- Update Inputbar and Suggestions components to use new Redux message sending logic
- Refactor message sending flow to use stream message management
- Improve error handling and message state management

* feat:添加StreamMessage,优化数据流展示,减少大面积rerender

* refactor: Simplify messages state management and initialization

- Refactor messages slice to use flat message array instead of separate user/assistant messages
- Add initializeMessagesState thunk to load messages from database on app startup
- Update message-related reducers to work with flat message array
- Modify MessageStream and related components to use new state structure
- Improve type safety and reduce complexity in messages state management

*  feat: add Model Context Protocol (MCP) support (#2809)

*  feat: add Model Context Protocol (MCP) server configuration (main)

- Added `@modelcontextprotocol/sdk` dependency for MCP integration.
- Introduced MCP server configuration UI in settings with add, edit, delete, and activation functionalities.
- Created `useMCPServers` hook to manage MCP server state and actions.
- Added i18n support for MCP settings with translation keys.
- Integrated MCP settings into the application's settings navigation and routing.
- Implemented Redux state management for MCP servers.
- Updated `yarn.lock` with new dependencies and their resolutions.

* 🌟 feat: implement mcp service and integrate with ipc handlers

- Added `MCPService` class to manage Model Context Protocol servers.
- Implemented various handlers in `ipc.ts` for managing MCP servers including listing, adding, updating, deleting, and activating/deactivating servers.
- Integrated MCP related types into existing type declarations for consistency across the application.
- Updated `preload` to expose new MCP related APIs to the renderer process.
- Enhanced `MCPSettings` component to interact directly with the new MCP service for adding, updating, deleting servers and setting their active states.
- Introduced selectors in the MCP Redux slice for fetching active and all servers from the store.
- Moved MCP types to a centralized location in `@renderer/types` for reuse across different parts of the application.

* feat: enhance MCPService initialization to prevent recursive calls and improve error handling

* feat: enhance MCP integration by adding MCPTool type and updating related methods

* feat: implement streaming support for tool calls in OpenAIProvider and enhance message processing

* refactor: Improve message handling and type safety in message components

- Update Message, MessageGroup, MessageStream, and MessageMenubar to require Topic prop
- Modify message sending and resending logic in MessageMenubar
- Remove commented-out code and simplify message state management
- Enhance type safety by explicitly defining prop types

* fix: finish_reason undefined

* refactor: Streamline message resending and state management

- Introduce `resendMessage` thunk for more robust message resending logic
- Update `sendMessage` to support resending existing messages
- Remove deprecated `onEditMessage` callback from MessageMenubar
- Simplify message state updates using Redux actions
- Improve type safety and reduce complexity in message handling

* refactor: Optimize message resending and event handling

- Remove deprecated `APPEND_MESSAGE` event and related callbacks
- Update `resendMessage` thunk to support mentioning new models
- Modify message state synchronization in database
- Simplify dependency arrays and remove unused event listeners
- Add migration step for initializing messages state

* refactor: Enhance message translation and suggestions handling

- Update MessageMenubar to use stream message actions for translation
- Modify Suggestions component to optimize suggestion fetching
- Remove deprecated event listeners and simplify component logic
- Memoize MessageMenubar and Suggestions components for performance
- Trigger AI auto-rename on message completion in messages slice

* refactor: Optimize message streaming with throttled updates

- Introduce throttled message update mechanism using lodash
- Improve performance by limiting Redux state updates during streaming
- Create a separate handler for response message updates
- Enhance message synchronization with database
- Prevent unnecessary re-renders and reduce computational overhead

* fix: Remove unnecessary await in message dispatch

Removes the `await` keyword from the message dispatch in Inputbar, which was causing an unnecessary async operation. Also adds a missing closing brace in the migration configuration file.

* fix: Update Redux persist configuration for messages slice

Modify store configuration to exclude 'messages' slice from persistence and remove unnecessary migration step for message state initialization

* feat: Enhance message streaming and multi-model support

- Refactor Redux messages slice to support multiple stream messages per topic
- Update MessageStream and messages slice to handle message streaming with message-specific IDs
- Implement support for multi-model message generation
- Modify queue concurrency to improve parallel message processing
- Update message selection and streaming logic to be more flexible and robust

* feat: Implement file upload handling in message sending

- Add FileManager service integration for file uploads in Inputbar
- Modify sendMessage action to use uploaded file references
- Update messages slice to conditionally dispatch messages during resend

*  feat(MCP): add support for enabling/disabling MCPServers per message (#2989)

*  feat: add MCP servers in chat input

- Introduce MCPToolsButton component for managing MCP servers
- Add new icon for MCP server tools in iconfont.css
- Update Inputbar to include MCP tools functionality
- Add toggle functionality for enabling/disabling MCP servers
- Implement styled dropdown menu for server selection
- Add necessary type imports and useState for MCP server management

*  feat: add support for enabling/disabling MCPServers per message (main)

- Added `enabledMCPs` property to the `Message` type to track enabled MCPServers.
- Modified `MCPToolsButton` to enable all active MCPServers by default using a new `enableAll` state.
- Introduced `filterMCPTools` utility to filter tools based on enabled MCPServers.
- Updated `AnthropicProvider`, `GeminiProvider`, and `OpenAIProvider` to filter tools using `filterMCPTools`.
- Enhanced `Inputbar` to include `enabledMCPs` in the message payload when set.

*  feat(MCP): add enabledMCPs parameter to sendMessage action

- Update sendMessage action type to include optional enabledMCPs parameter
- Import MCPServer type for type safety
- Modify action signature to support passing enabled MCP servers per message

---------

Co-authored-by: lizhixuan <zhixuan.li@banosuperapp.com>
Co-authored-by: lizhixuan <zhixuanli219643@sohu-inc.com>
Co-authored-by: LiuVaayne <10231735+vaayne@users.noreply.github.com>
Co-authored-by: kangfenmao <kangfenmao@qq.com>
This commit is contained in:
MyPrototypeWhat
2025-03-08 01:41:05 +08:00
committed by GitHub
parent eec2ac668b
commit 1dfd7103e8
19 changed files with 1144 additions and 614 deletions
+87 -61
View File
@@ -2933,11 +2933,11 @@ __metadata:
linkType: hard
"@types/ws@npm:^8.5.4":
version: 8.5.14
resolution: "@types/ws@npm:8.5.14"
version: 8.18.0
resolution: "@types/ws@npm:8.18.0"
dependencies:
"@types/node": "npm:*"
checksum: 10c0/be88a0b6252f939cb83340bd1b4d450287f752c19271195cd97564fd94047259a9bb8c31c585a61b69d8a1b069a99df9dd804db0132d3359c54d3890c501416a
checksum: 10c0/a56d2e0d1da7411a1f3548ce02b51a50cbe9e23f025677d03df48f87e4a3c72e1342fbf1d12e487d7eafa8dc670c605152b61bbf9165891ec0e9694b0d3ea8d4
languageName: node
linkType: hard
@@ -3184,6 +3184,7 @@ __metadata:
mime: "npm:^4.0.4"
officeparser: "npm:^4.1.1"
openai: "patch:openai@npm%3A4.77.3#~/.yarn/patches/openai-npm-4.77.3-59c6d42e7a.patch"
p-queue: "npm:^8.1.0"
prettier: "npm:^3.2.4"
react: "npm:^18.2.0"
react-dom: "npm:^18.2.0"
@@ -3262,11 +3263,11 @@ __metadata:
linkType: hard
"acorn@npm:^8.9.0":
version: 8.14.0
resolution: "acorn@npm:8.14.0"
version: 8.14.1
resolution: "acorn@npm:8.14.1"
bin:
acorn: bin/acorn
checksum: 10c0/6d4ee461a7734b2f48836ee0fbb752903606e576cc100eb49340295129ca0b452f3ba91ddd4424a1d4406a98adfb2ebb6bd0ff4c49d7a0930c10e462719bbfd7
checksum: 10c0/dbd36c1ed1d2fa3550140000371fcf721578095b18777b85a79df231ca093b08edc6858d75d6e48c73e431c174dcf9214edbd7e6fa5911b93bd8abfa54e47123
languageName: node
linkType: hard
@@ -3420,8 +3421,8 @@ __metadata:
linkType: hard
"antd@npm:^5.22.5":
version: 5.24.2
resolution: "antd@npm:5.24.2"
version: 5.24.3
resolution: "antd@npm:5.24.3"
dependencies:
"@ant-design/colors": "npm:^7.2.0"
"@ant-design/cssinjs": "npm:^1.23.0"
@@ -3438,7 +3439,7 @@ __metadata:
classnames: "npm:^2.5.1"
copy-to-clipboard: "npm:^3.3.3"
dayjs: "npm:^1.11.11"
rc-cascader: "npm:~3.33.0"
rc-cascader: "npm:~3.33.1"
rc-checkbox: "npm:~3.5.0"
rc-collapse: "npm:~3.9.0"
rc-dialog: "npm:~9.6.0"
@@ -3446,14 +3447,14 @@ __metadata:
rc-dropdown: "npm:~4.2.1"
rc-field-form: "npm:~2.7.0"
rc-image: "npm:~7.11.0"
rc-input: "npm:~1.7.2"
rc-input: "npm:~1.7.3"
rc-input-number: "npm:~9.4.0"
rc-mentions: "npm:~2.19.1"
rc-menu: "npm:~9.16.1"
rc-motion: "npm:^2.9.5"
rc-notification: "npm:~5.6.3"
rc-pagination: "npm:~5.1.0"
rc-picker: "npm:~4.11.2"
rc-picker: "npm:~4.11.3"
rc-progress: "npm:~4.0.0"
rc-rate: "npm:~2.13.1"
rc-resize-observer: "npm:^1.4.3"
@@ -3466,7 +3467,7 @@ __metadata:
rc-tabs: "npm:~15.5.1"
rc-textarea: "npm:~1.9.0"
rc-tooltip: "npm:~6.4.0"
rc-tree: "npm:~5.13.0"
rc-tree: "npm:~5.13.1"
rc-tree-select: "npm:~5.27.0"
rc-upload: "npm:~4.8.1"
rc-util: "npm:^5.44.4"
@@ -3475,7 +3476,7 @@ __metadata:
peerDependencies:
react: ">=16.9.0"
react-dom: ">=16.9.0"
checksum: 10c0/a6772136b828ef73925af633dee66b7580bad736eac20c713d1991e457aae3879d1a826ca06cc40f824238da0ad1a9745dbde6acbd801aec589deaeef04846fe
checksum: 10c0/bbd1dcc4cce3bebecebde135014352156d57c8979b1ad8cb8cf873e8919454292a812f6d2e8995673b82f3cb46a2cdd14ea7b2190193bd5127380c1091ce472a
languageName: node
linkType: hard
@@ -4926,15 +4927,6 @@ __metadata:
languageName: node
linkType: hard
"debug@npm:2.6.9, debug@npm:^2.6.9":
version: 2.6.9
resolution: "debug@npm:2.6.9"
dependencies:
ms: "npm:2.0.0"
checksum: 10c0/121908fb839f7801180b69a7e218a40b5a0b718813b886b7d6bdb82001b931c938e2941d1e4450f33a1b1df1da653f5f7a0440c197f29fbf8a6e9d45ff6ef589
languageName: node
linkType: hard
"debug@npm:4, debug@npm:^4.0.0, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.3, debug@npm:^4.3.4, debug@npm:^4.3.5, debug@npm:^4.4.0":
version: 4.4.0
resolution: "debug@npm:4.4.0"
@@ -4959,6 +4951,15 @@ __metadata:
languageName: node
linkType: hard
"debug@npm:^2.6.9":
version: 2.6.9
resolution: "debug@npm:2.6.9"
dependencies:
ms: "npm:2.0.0"
checksum: 10c0/121908fb839f7801180b69a7e218a40b5a0b718813b886b7d6bdb82001b931c938e2941d1e4450f33a1b1df1da653f5f7a0440c197f29fbf8a6e9d45ff6ef589
languageName: node
linkType: hard
"debug@npm:^3.1.0, debug@npm:^3.2.6":
version: 3.2.7
resolution: "debug@npm:3.2.7"
@@ -5533,9 +5534,9 @@ __metadata:
linkType: hard
"electron-log@npm:^5.1.5":
version: 5.3.1
resolution: "electron-log@npm:5.3.1"
checksum: 10c0/051157400b36f4ad51c52ae30a6c37d0c1525dc582312dc4043723d0e52aa11a95c28ee1421a0067f11ad641624e1163850e24d1c8cec47ba31aaf905953100f
version: 5.3.2
resolution: "electron-log@npm:5.3.2"
checksum: 10c0/8cfcd6eb6ab2dff010941f9a39793a411646dc0462991632d2427fc9a45f22b00ec758996629f8c203612d99cb01713c08c72d2b0454603d13386f433f5b755b
languageName: node
linkType: hard
@@ -5565,9 +5566,9 @@ __metadata:
linkType: hard
"electron-to-chromium@npm:^1.5.73":
version: 1.5.112
resolution: "electron-to-chromium@npm:1.5.112"
checksum: 10c0/fc597268d6d3d7458b55141c436802a6c51078855f021823cdb380b80ad1a69e1c2899fdfc9cffa501d47feb3791ea6a75893fe802a608c7845e979a48f5ac25
version: 1.5.113
resolution: "electron-to-chromium@npm:1.5.113"
checksum: 10c0/837fe2fd26adbc4f3ad8e758d14067a14f636f9c2923b5ded8adb93426bbe3fdc83b48ddf9f2cf03be31b5becb0c31144db19c823b696fd52a7bc4583f4bde00
languageName: node
linkType: hard
@@ -5681,13 +5682,6 @@ __metadata:
languageName: node
linkType: hard
"encodeurl@npm:~1.0.2":
version: 1.0.2
resolution: "encodeurl@npm:1.0.2"
checksum: 10c0/f6c2387379a9e7c1156c1c3d4f9cb7bb11cf16dd4c1682e1f6746512564b053df5781029b6061296832b59fb22f459dbe250386d217c2f6e203601abb2ee0bec
languageName: node
linkType: hard
"encoding@npm:^0.1.12, encoding@npm:^0.1.13":
version: 0.1.13
resolution: "encoding@npm:0.1.13"
@@ -6260,6 +6254,13 @@ __metadata:
languageName: node
linkType: hard
"eventemitter3@npm:^5.0.1":
version: 5.0.1
resolution: "eventemitter3@npm:5.0.1"
checksum: 10c0/4ba5c00c506e6c786b4d6262cfbce90ddc14c10d4667e5c83ae993c9de88aa856033994dd2b35b83e8dc1170e224e66a319fa80adc4c32adcd2379bbc75da814
languageName: node
linkType: hard
"events@npm:^3.3.0":
version: 3.3.0
resolution: "events@npm:3.3.0"
@@ -6602,17 +6603,16 @@ __metadata:
linkType: hard
"finalhandler@npm:^2.0.0":
version: 2.0.0
resolution: "finalhandler@npm:2.0.0"
version: 2.1.0
resolution: "finalhandler@npm:2.1.0"
dependencies:
debug: "npm:2.6.9"
encodeurl: "npm:~1.0.2"
escape-html: "npm:~1.0.3"
on-finished: "npm:2.4.1"
parseurl: "npm:~1.3.3"
statuses: "npm:2.0.1"
unpipe: "npm:~1.0.0"
checksum: 10c0/ca6f69d69797eebc900d7627bde4bb7d38417112911eb11ce4e40011195b6ad1a09413ad082da9bb64da789a4ecfffdd0e6a5ea1ccb4147062224c3050f134ea
debug: "npm:^4.4.0"
encodeurl: "npm:^2.0.0"
escape-html: "npm:^1.0.3"
on-finished: "npm:^2.4.1"
parseurl: "npm:^1.3.3"
statuses: "npm:^2.0.1"
checksum: 10c0/da0bbca6d03873472ee890564eb2183f4ed377f25f3628a0fc9d16dac40bed7b150a0d82ebb77356e4c6d97d2796ad2dba22948b951dddee2c8768b0d1b9fb1f
languageName: node
linkType: hard
@@ -7478,8 +7478,8 @@ __metadata:
linkType: hard
"hast-util-to-jsx-runtime@npm:^2.0.0":
version: 2.3.5
resolution: "hast-util-to-jsx-runtime@npm:2.3.5"
version: 2.3.6
resolution: "hast-util-to-jsx-runtime@npm:2.3.6"
dependencies:
"@types/estree": "npm:^1.0.0"
"@types/hast": "npm:^3.0.0"
@@ -7493,10 +7493,10 @@ __metadata:
mdast-util-mdxjs-esm: "npm:^2.0.0"
property-information: "npm:^7.0.0"
space-separated-tokens: "npm:^2.0.0"
style-to-object: "npm:^1.0.0"
style-to-js: "npm:^1.0.0"
unist-util-position: "npm:^5.0.0"
vfile-message: "npm:^4.0.0"
checksum: 10c0/9db65b2b417cdaad1f1cc619b613abd8d1fa7196f5979ce54bd1dc8a937613f11fecb8b7a43425342cf36fd085b0fed89daadcce43bed8762786a4cdc21a1df8
checksum: 10c0/27297e02848fe37ef219be04a26ce708d17278a175a807689e94a821dcffc88aa506d62c3a85beed1f9a8544f7211bdcbcde0528b7b456a57c2e342c3fd11056
languageName: node
linkType: hard
@@ -10979,6 +10979,16 @@ __metadata:
languageName: node
linkType: hard
"p-queue@npm:^8.1.0":
version: 8.1.0
resolution: "p-queue@npm:8.1.0"
dependencies:
eventemitter3: "npm:^5.0.1"
p-timeout: "npm:^6.1.2"
checksum: 10c0/6bdea170840546769c29682fed212745c951933476761ed3a981967fab624c7c0120dff79bd99a1ac8b650b420719a245813e944af4b8ee77d4dd78adbf5fe75
languageName: node
linkType: hard
"p-retry@npm:4":
version: 4.6.2
resolution: "p-retry@npm:4.6.2"
@@ -11005,6 +11015,13 @@ __metadata:
languageName: node
linkType: hard
"p-timeout@npm:^6.1.2":
version: 6.1.4
resolution: "p-timeout@npm:6.1.4"
checksum: 10c0/019edad1c649ab07552aa456e40ce7575c4b8ae863191477f02ac8d283ac8c66cedef0ca93422735130477a051dfe952ba717641673fd3599befdd13f63bcc33
languageName: node
linkType: hard
"p-try@npm:^2.0.0":
version: 2.2.0
resolution: "p-try@npm:2.2.0"
@@ -11691,7 +11708,7 @@ __metadata:
languageName: node
linkType: hard
"rc-cascader@npm:~3.33.0":
"rc-cascader@npm:~3.33.1":
version: 3.33.1
resolution: "rc-cascader@npm:3.33.1"
dependencies:
@@ -11830,7 +11847,7 @@ __metadata:
languageName: node
linkType: hard
"rc-input@npm:~1.7.1, rc-input@npm:~1.7.2":
"rc-input@npm:~1.7.1, rc-input@npm:~1.7.3":
version: 1.7.3
resolution: "rc-input@npm:1.7.3"
dependencies:
@@ -11937,7 +11954,7 @@ __metadata:
languageName: node
linkType: hard
"rc-picker@npm:~4.11.2":
"rc-picker@npm:~4.11.3":
version: 4.11.3
resolution: "rc-picker@npm:4.11.3"
dependencies:
@@ -12086,8 +12103,8 @@ __metadata:
linkType: hard
"rc-table@npm:~7.50.3":
version: 7.50.3
resolution: "rc-table@npm:7.50.3"
version: 7.50.4
resolution: "rc-table@npm:7.50.4"
dependencies:
"@babel/runtime": "npm:^7.10.1"
"@rc-component/context": "npm:^1.4.0"
@@ -12098,7 +12115,7 @@ __metadata:
peerDependencies:
react: ">=16.9.0"
react-dom: ">=16.9.0"
checksum: 10c0/61fee18289063d33e135f87e7d325c4ab319db6a452bc7151b13c9bfdcedc9a280a543fe06dea05cd41814c47dfc0c5b3ade876f7e6c286714a8276a53f7125b
checksum: 10c0/ab5eb3db00bc31470d7dd5946c1a919247742703a3278ea2d9a33e719a08e170ca80977e615084c7cfcb54508a9c3da2449409cce16fc1d7ec1ea67596c30d79
languageName: node
linkType: hard
@@ -12167,7 +12184,7 @@ __metadata:
languageName: node
linkType: hard
"rc-tree@npm:~5.13.0":
"rc-tree@npm:~5.13.0, rc-tree@npm:~5.13.1":
version: 5.13.1
resolution: "rc-tree@npm:5.13.1"
dependencies:
@@ -12211,8 +12228,8 @@ __metadata:
linkType: hard
"rc-virtual-list@npm:^3.14.2, rc-virtual-list@npm:^3.5.1, rc-virtual-list@npm:^3.5.2":
version: 3.18.3
resolution: "rc-virtual-list@npm:3.18.3"
version: 3.18.4
resolution: "rc-virtual-list@npm:3.18.4"
dependencies:
"@babel/runtime": "npm:^7.20.0"
classnames: "npm:^2.2.6"
@@ -12221,7 +12238,7 @@ __metadata:
peerDependencies:
react: ">=16.9.0"
react-dom: ">=16.9.0"
checksum: 10c0/773b18d9594d78b4f08182caec3043fef6c1b1871db91e05294b62a65e309e2d0ee50ca699a1b237af1ac0b1b1c9cc25d62f47bae30d4a0c0dcab0ddc4d5bb8d
checksum: 10c0/2566e98418b8072af4591488e028a1e8433d2a190716f47134ee63a506afec9cf472f8a8d3dda55bf2e82ccf1215d324abd280892db4fbf5999fc30184068f62
languageName: node
linkType: hard
@@ -13961,7 +13978,16 @@ __metadata:
languageName: node
linkType: hard
"style-to-object@npm:^1.0.0":
"style-to-js@npm:^1.0.0":
version: 1.1.16
resolution: "style-to-js@npm:1.1.16"
dependencies:
style-to-object: "npm:1.0.8"
checksum: 10c0/578a4dff804539ec7e64d3cc8d327540befb9ad30e3cd0b6b0392f93f793f3a028f90084a9aaff088bffb87818fa2c6c153f0df576f61f9ab0b0938b582bcac7
languageName: node
linkType: hard
"style-to-object@npm:1.0.8":
version: 1.0.8
resolution: "style-to-object@npm:1.0.8"
dependencies:
@@ -14737,7 +14763,7 @@ __metadata:
languageName: node
linkType: hard
"unpipe@npm:1.0.0, unpipe@npm:~1.0.0":
"unpipe@npm:1.0.0":
version: 1.0.0
resolution: "unpipe@npm:1.0.0"
checksum: 10c0/193400255bd48968e5c5383730344fbb4fa114cdedfab26e329e50dd2d81b134244bb8a72c6ac1b10ab0281a58b363d06405632c9d49ca9dfd5e90cbd7d0f32c