From ef1304ce5eaa21e2b2192466890f2935750ba3ed Mon Sep 17 00:00:00 2001 From: BiggerRain <15911122312@163.COM> Date: Mon, 17 Mar 2025 16:24:18 +0800 Subject: [PATCH] feat: add web pages (#277) * feat: add web pages * feat: add web page * refactor: search page * feat: add tsup build web componet * chore: update timeout time * build: build web page * build: build search chat * chore: add web page * docs: update release note --- .vscode/settings.json | 1 + docs/content.en/docs/release-notes/_index.md | 2 + package.json | 7 +- pnpm-lock.yaml | 220 ++++++++- src-tauri/src/server/websocket.rs | 2 +- src/components/Assistant/Chat.tsx | 3 + src/components/Assistant/ChatContent.tsx | 6 +- src/components/Assistant/ChatHeader.tsx | 14 +- src/components/Assistant/ConnectPrompt.tsx | 4 +- .../{Search => Assistant}/FileList.tsx | 14 +- src/components/Assistant/types.ts | 6 + src/components/Common/AutoResizeTextarea.tsx | 54 --- src/components/Common/DropdownList.tsx | 163 ------- src/components/Common/ErrorBoundary.tsx | 47 ++ src/components/Common/ErrorDisplay.tsx | 32 ++ src/components/Common/Footer.tsx | 144 ------ src/components/Common/InputBox.tsx | 312 ------------ src/components/Common/Search.tsx | 129 ----- src/components/Common/Transition.tsx | 48 -- src/components/Common/types.ts | 12 - src/components/Search/ContextMenu.tsx | 18 +- src/components/Search/DocumentList.tsx | 26 +- src/components/Search/Footer.tsx | 17 +- src/components/Search/InputBox.tsx | 68 ++- src/components/Search/InputExtra.tsx | 71 +-- src/components/Search/NoResults.tsx | 38 ++ src/components/Search/Search.tsx | 72 ++- src/components/Search/SearchPopover.tsx | 14 +- src/components/Search/SearchResults.tsx | 4 +- src/components/UpdateApp/index.tsx | 32 +- src/error-page.tsx | 27 -- src/hooks/useSettingsWindow.ts | 11 +- src/hooks/useWindowEvents.ts | 27 ++ src/locales/en/translation.json | 3 + src/locales/zh/translation.json | 3 + src/pages/chat/index.tsx | 92 +++- src/pages/error/index.tsx | 10 + src/pages/main/index.tsx | 226 ++------- src/pages/settings/index.tsx | 1 + src/pages/web/SearchChat.tsx | 345 ++++++++++++++ src/pages/web/index.tsx | 24 + src/reducers/appReducer.ts | 46 ++ src/routes/index.tsx | 4 +- src/routes/layout.tsx | 34 +- src/stores/appStore.ts | 6 +- src/stores/authStore.ts | 13 +- src/utils/platform.ts | 11 +- src/utils/platformAdapter.ts | 451 ++++++++++++++++++ tsup.config.ts | 73 +++ vite.config.ts | 14 + 50 files changed, 1703 insertions(+), 1298 deletions(-) rename src/components/{Search => Assistant}/FileList.tsx (91%) delete mode 100644 src/components/Common/AutoResizeTextarea.tsx delete mode 100644 src/components/Common/DropdownList.tsx create mode 100644 src/components/Common/ErrorBoundary.tsx create mode 100644 src/components/Common/ErrorDisplay.tsx delete mode 100644 src/components/Common/Footer.tsx delete mode 100644 src/components/Common/InputBox.tsx delete mode 100644 src/components/Common/Search.tsx delete mode 100644 src/components/Common/Transition.tsx delete mode 100644 src/components/Common/types.ts create mode 100644 src/components/Search/NoResults.tsx delete mode 100644 src/error-page.tsx create mode 100644 src/hooks/useWindowEvents.ts create mode 100644 src/pages/error/index.tsx create mode 100644 src/pages/web/SearchChat.tsx create mode 100644 src/pages/web/index.tsx create mode 100644 src/reducers/appReducer.ts create mode 100644 src/utils/platformAdapter.ts create mode 100644 tsup.config.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 1e9f20cf..2ca66c02 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,7 @@ "changelogithub", "clsx", "codegen", + "dataurl", "dtolnay", "dyld", "elif", diff --git a/docs/content.en/docs/release-notes/_index.md b/docs/content.en/docs/release-notes/_index.md index 7a00d5cb..d554ba03 100644 --- a/docs/content.en/docs/release-notes/_index.md +++ b/docs/content.en/docs/release-notes/_index.md @@ -11,6 +11,8 @@ Information about release notes of Coco Server is provided here. ### Breaking changes +- feat: add web pages components #277 + ### Features ### Bug fix diff --git a/package.json b/package.json index dc722a50..c37effad 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,11 @@ "scripts": { "dev": "vite", "build": "tsc && vite build", + "build:web": "tsc && tsup", + "publish:web": "cd dist/search-chat && npm publish", + "publish:web:beta": "cd dist/search-chat && npm publish --tag beta", + "publish:web:alpha": "cd dist/search-chat && npm publish --tag alpha", + "publish:web:rc": "cd dist/search-chat && npm publish --tag rc", "preview": "vite preview", "tauri": "tauri", "release": "release-it", @@ -63,7 +68,6 @@ "@types/node": "^22.13.10", "@types/react": "^18.3.18", "@types/react-dom": "^18.3.5", - "@types/react-i18next": "^8.1.0", "@types/react-katex": "^3.0.4", "@types/react-window": "^1.8.8", "@vitejs/plugin-react": "^4.3.4", @@ -72,6 +76,7 @@ "postcss": "^8.5.3", "release-it": "^18.1.2", "tailwindcss": "^3.4.17", + "tsup": "^8.4.0", "tsx": "^4.19.3", "typescript": "^5.8.2", "vite": "^5.4.14" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 350f2a7d..f301c0a6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -153,9 +153,6 @@ importers: '@types/react-dom': specifier: ^18.3.5 version: 18.3.5(@types/react@18.3.18) - '@types/react-i18next': - specifier: ^8.1.0 - version: 8.1.0(i18next@23.16.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@types/react-katex': specifier: ^3.0.4 version: 3.0.4 @@ -180,6 +177,9 @@ importers: tailwindcss: specifier: ^3.4.17 version: 3.4.17 + tsup: + specifier: ^8.4.0 + version: 8.4.0(jiti@1.21.7)(postcss@8.5.3)(tsx@4.19.3)(typescript@5.8.2)(yaml@2.7.0) tsx: specifier: ^4.19.3 version: 4.19.3 @@ -1286,10 +1286,6 @@ packages: peerDependencies: '@types/react': ^18.0.0 - '@types/react-i18next@8.1.0': - resolution: {integrity: sha512-d4xhcjX5b3roNMObRNMfb1HinHQlQLPo8xlDj60dnHeeAw2bBymR2cy/l1giJpHzo/ZFgSvgVUvIWr4kCrenCg==} - deprecated: This is a stub types definition. react-i18next provides its own type definitions, so you do not need this installed. - '@types/react-katex@3.0.4': resolution: {integrity: sha512-aLkykKzSKLpXI6REJ3uClao6P47HAFfR1gcHOZwDeTuALsyjgMhz+oynLV4gX0kiJVnvHrBKF/TLXqyNTpHDUg==} @@ -1425,6 +1421,16 @@ packages: resolution: {integrity: sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q==} engines: {node: '>=18'} + bundle-require@5.1.0: + resolution: {integrity: sha512-3WrrOuZiyaaZPWiEt4G3+IffISVC9HYlWueJEBWED4ZH4aIAC2PnkdnuRrR94M+w6yGWn4AglWtJtBI8YqvgoA==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + peerDependencies: + esbuild: '>=0.18' + + cac@6.7.14: + resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==} + engines: {node: '>=8'} + callsites@3.1.0: resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==} engines: {node: '>=6'} @@ -1474,6 +1480,10 @@ packages: resolution: {integrity: sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==} engines: {node: '>= 8.10.0'} + chokidar@4.0.3: + resolution: {integrity: sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==} + engines: {node: '>= 14.16.0'} + ci-info@4.2.0: resolution: {integrity: sha512-cYY9mypksY8NRqgDB1XD1RiJL338v/551niynFTGkZOO2LHuB2OmOYxDIe/ttN9AHwrqdum1360G3ald0W9kCg==} engines: {node: '>=8'} @@ -1536,6 +1546,10 @@ packages: resolution: {integrity: sha512-yk7/5PN5im4qwz0WFZW3PXnzHgPu9mX29Y8uZ3aefe2lBPC1FYttWZRcaW9fKkT0pBCJyuQ2HfbmPVaODi9jcQ==} engines: {node: '>=18'} + consola@3.4.0: + resolution: {integrity: sha512-EiPU8G6dQG0GFHNR8ljnZFki/8a+cQwEQ+7wpxdChl02Q8HXlwEZWD5lqAF8vC2sEC3Tehr8hy7vErz88LHyUA==} + engines: {node: ^14.18.0 || >=16.10.0} + convert-source-map@2.0.0: resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==} @@ -1885,6 +1899,14 @@ packages: fastq@1.19.1: resolution: {integrity: sha512-GwLTyxkCXjXbxqIhTsMI2Nui8huMPtnxg7krajPJAjnEG/iiOS7i+zCtWGZR9G0NBKbXKh6X9m9UIsYX/N6vvQ==} + fdir@6.4.3: + resolution: {integrity: sha512-PMXmW2y1hDDfTSRc9gaXIuCCRpuoz3Kaz8cUelp3smouvfT632ozg2vrT6lJsHKKOF59YLbOGfAWGUcKEfRMQw==} + peerDependencies: + picomatch: ^3 || ^4 + peerDependenciesMeta: + picomatch: + optional: true + figures@6.1.0: resolution: {integrity: sha512-d+l3qxjSesT4V7v2fh+QnmFnUWv9lSpjarhShNTgBOfA0ttejbQUAlHLitbjkoRiDulW0OPoQPYIGhIC8ohejg==} engines: {node: '>=18'} @@ -2222,6 +2244,10 @@ packages: resolution: {integrity: sha512-/imKNG4EbWNrVjoNC/1H5/9GFy+tqjGBHCaSsN+P2RnPqjsLmv6UD3Ej+Kj8nBWaRAwyk7kK5ZUc+OEatnTR3A==} hasBin: true + joycon@3.1.1: + resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} + engines: {node: '>=10'} + js-cookie@3.0.5: resolution: {integrity: sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==} engines: {node: '>=14'} @@ -2284,6 +2310,10 @@ packages: lines-and-columns@1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} + load-tsconfig@0.2.5: + resolution: {integrity: sha512-IXO6OCs9yg8tMKzfPZ1YmheJbZCiEsnBdcB03l0OcfK9prKnJb96siuHCr5Fl37/yo9DnKU+TLpxzTUspw9shg==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + local-pkg@1.1.1: resolution: {integrity: sha512-WunYko2W1NcdfAFpuLUoucsgULmgDBRkdxHxWQ7mK0cQqwPiy8E1enjuRBrhLtZkB5iScJ1XIPdhVEFK8aOLSg==} engines: {node: '>=14'} @@ -2303,6 +2333,9 @@ packages: lodash.isstring@4.0.1: resolution: {integrity: sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==} + lodash.sortby@4.7.0: + resolution: {integrity: sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==} + lodash.uniqby@4.7.0: resolution: {integrity: sha512-e/zcLx6CSbmaEgFHCA7BnoQKyCtKMxnuWrJygbwPs/AIn+IMKl66L8/s+wBUn5LRw2pZx3bUHibiV1b6aTWIww==} @@ -2699,6 +2732,10 @@ packages: resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} engines: {node: '>=8.6'} + picomatch@4.0.2: + resolution: {integrity: sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==} + engines: {node: '>=12'} + pify@2.3.0: resolution: {integrity: sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==} engines: {node: '>=0.10.0'} @@ -2743,6 +2780,24 @@ packages: ts-node: optional: true + postcss-load-config@6.0.1: + resolution: {integrity: sha512-oPtTM4oerL+UXmx+93ytZVN82RrlY/wPUV8IeDxFrzIjXOLF1pN+EmKPLbubvKHT2HC20xXsCAH2Z+CKV6Oz/g==} + engines: {node: '>= 18'} + peerDependencies: + jiti: '>=1.21.0' + postcss: '>=8.0.9' + tsx: ^4.8.1 + yaml: ^2.4.2 + peerDependenciesMeta: + jiti: + optional: true + postcss: + optional: true + tsx: + optional: true + yaml: + optional: true + postcss-nested@6.2.0: resolution: {integrity: sha512-HQbt28KulC5AJzG+cZtj9kvKB93CFCdLvog1WFLf1D+xmMvPGlBstkpTEZfK5+AN9hfJocyBFCNiqyS48bpgzQ==} engines: {node: '>=12.0'} @@ -2780,6 +2835,10 @@ packages: proxy-from-env@1.1.0: resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==} + punycode@2.3.1: + resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} + engines: {node: '>=6'} + pupa@3.1.0: resolution: {integrity: sha512-FLpr4flz5xZTSJxSeaheeMKN/EDzMdK7b8PTOC6a5PYFKTucWbdqjgqaEyH0shFiSJrVB1+Qqi4Tk19ccU6Aug==} engines: {node: '>=12.20'} @@ -2862,6 +2921,10 @@ packages: resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} engines: {node: '>=8.10.0'} + readdirp@4.1.2: + resolution: {integrity: sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==} + engines: {node: '>= 14.18.0'} + rechoir@0.6.2: resolution: {integrity: sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==} engines: {node: '>= 0.10'} @@ -2913,6 +2976,10 @@ packages: resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} engines: {node: '>=4'} + resolve-from@5.0.0: + resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} + engines: {node: '>=8'} + resolve-pkg-maps@1.0.0: resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} @@ -3021,6 +3088,10 @@ packages: resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} engines: {node: '>=0.10.0'} + source-map@0.8.0-beta.0: + resolution: {integrity: sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==} + engines: {node: '>= 8'} + space-separated-tokens@2.0.2: resolution: {integrity: sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==} @@ -3114,6 +3185,10 @@ packages: tinyexec@0.3.2: resolution: {integrity: sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA==} + tinyglobby@0.2.12: + resolution: {integrity: sha512-qkf4trmKSIiMTs/E63cxH+ojC2unam7rJ0WrauAzpT3ECNTxGRMlaXxVbfxMUC/w0LaYk6jQ4y/nGR9uBO3tww==} + engines: {node: '>=12.0.0'} + tmp@0.0.33: resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==} engines: {node: '>=0.6.0'} @@ -3122,6 +3197,13 @@ packages: resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==} engines: {node: '>=8.0'} + tr46@1.0.1: + resolution: {integrity: sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==} + + tree-kill@1.2.2: + resolution: {integrity: sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==} + hasBin: true + trim-lines@3.0.1: resolution: {integrity: sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==} @@ -3138,6 +3220,25 @@ packages: tslib@2.8.1: resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} + tsup@8.4.0: + resolution: {integrity: sha512-b+eZbPCjz10fRryaAA7C8xlIHnf8VnsaRqydheLIqwG/Mcpfk8Z5zp3HayX7GaTygkigHl5cBUs+IhcySiIexQ==} + engines: {node: '>=18'} + hasBin: true + peerDependencies: + '@microsoft/api-extractor': ^7.36.0 + '@swc/core': ^1 + postcss: ^8.4.12 + typescript: '>=4.5.0' + peerDependenciesMeta: + '@microsoft/api-extractor': + optional: true + '@swc/core': + optional: true + postcss: + optional: true + typescript: + optional: true + tsx@4.19.3: resolution: {integrity: sha512-4H8vUNGNjQ4V2EOoGw005+c+dGuPSnhpPBPHBtsZdGZBk/iJb4kguGlPWaZTZ3q5nMtFOEsY0nRDlh9PJyd6SQ==} engines: {node: '>=18.0.0'} @@ -3303,6 +3404,12 @@ packages: web-namespaces@2.0.1: resolution: {integrity: sha512-bKr1DkiNa2krS7qxNtdrtHAmzuYGFQLiQ13TsorsdT6ULTkPLKuu5+GsFpDlg6JFjUTwX2DyhMPG2be8uPrqsQ==} + webidl-conversions@4.0.2: + resolution: {integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==} + + whatwg-url@7.1.0: + resolution: {integrity: sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==} + when-exit@2.1.4: resolution: {integrity: sha512-4rnvd3A1t16PWzrBUcSDZqcAmsUIy4minDXT/CZ8F2mVDgd65i4Aalimgz1aQkRGU0iH5eT5+6Rx2TK8o443Pg==} @@ -4375,15 +4482,6 @@ snapshots: dependencies: '@types/react': 18.3.18 - '@types/react-i18next@8.1.0(i18next@23.16.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': - dependencies: - react-i18next: 15.4.1(i18next@23.16.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) - transitivePeerDependencies: - - i18next - - react - - react-dom - - react-native - '@types/react-katex@3.0.4': dependencies: '@types/react': 18.3.18 @@ -4531,6 +4629,13 @@ snapshots: dependencies: run-applescript: 7.0.0 + bundle-require@5.1.0(esbuild@0.25.1): + dependencies: + esbuild: 0.25.1 + load-tsconfig: 0.2.5 + + cac@6.7.14: {} + callsites@3.1.0: {} camelcase-css@2.0.1: {} @@ -4579,6 +4684,10 @@ snapshots: optionalDependencies: fsevents: 2.3.3 + chokidar@4.0.3: + dependencies: + readdirp: 4.1.2 + ci-info@4.2.0: {} cli-boxes@3.0.0: {} @@ -4625,6 +4734,8 @@ snapshots: graceful-fs: 4.2.11 xdg-basedir: 5.1.0 + consola@3.4.0: {} + convert-source-map@2.0.0: {} cose-base@1.0.3: @@ -5036,6 +5147,10 @@ snapshots: dependencies: reusify: 1.1.0 + fdir@6.4.3(picomatch@4.0.2): + optionalDependencies: + picomatch: 4.0.2 + figures@6.1.0: dependencies: is-unicode-supported: 2.1.0 @@ -5399,6 +5514,8 @@ snapshots: jiti@1.21.7: {} + joycon@3.1.1: {} + js-cookie@3.0.5: {} js-tokens@4.0.0: {} @@ -5445,6 +5562,8 @@ snapshots: lines-and-columns@1.2.4: {} + load-tsconfig@0.2.5: {} + local-pkg@1.1.1: dependencies: mlly: 1.7.4 @@ -5461,6 +5580,8 @@ snapshots: lodash.isstring@4.0.1: {} + lodash.sortby@4.7.0: {} + lodash.uniqby@4.7.0: {} lodash@4.17.21: {} @@ -6103,6 +6224,8 @@ snapshots: picomatch@2.3.1: {} + picomatch@4.0.2: {} + pify@2.3.0: {} pirates@4.0.6: {} @@ -6145,6 +6268,15 @@ snapshots: optionalDependencies: postcss: 8.5.3 + postcss-load-config@6.0.1(jiti@1.21.7)(postcss@8.5.3)(tsx@4.19.3)(yaml@2.7.0): + dependencies: + lilconfig: 3.1.3 + optionalDependencies: + jiti: 1.21.7 + postcss: 8.5.3 + tsx: 4.19.3 + yaml: 2.7.0 + postcss-nested@6.2.0(postcss@8.5.3): dependencies: postcss: 8.5.3 @@ -6188,6 +6320,8 @@ snapshots: proxy-from-env@1.1.0: {} + punycode@2.3.1: {} + pupa@3.1.0: dependencies: escape-goat: 4.0.0 @@ -6276,6 +6410,8 @@ snapshots: dependencies: picomatch: 2.3.1 + readdirp@4.1.2: {} + rechoir@0.6.2: dependencies: resolve: 1.22.10 @@ -6393,6 +6529,8 @@ snapshots: resolve-from@4.0.0: {} + resolve-from@5.0.0: {} + resolve-pkg-maps@1.0.0: {} resolve@1.22.10: @@ -6506,6 +6644,10 @@ snapshots: source-map@0.6.1: optional: true + source-map@0.8.0-beta.0: + dependencies: + whatwg-url: 7.1.0 + space-separated-tokens@2.0.2: {} sprintf-js@1.1.3: {} @@ -6624,6 +6766,11 @@ snapshots: tinyexec@0.3.2: {} + tinyglobby@0.2.12: + dependencies: + fdir: 6.4.3(picomatch@4.0.2) + picomatch: 4.0.2 + tmp@0.0.33: dependencies: os-tmpdir: 1.0.2 @@ -6632,6 +6779,12 @@ snapshots: dependencies: is-number: 7.0.0 + tr46@1.0.1: + dependencies: + punycode: 2.3.1 + + tree-kill@1.2.2: {} + trim-lines@3.0.1: {} trough@2.2.0: {} @@ -6642,6 +6795,33 @@ snapshots: tslib@2.8.1: {} + tsup@8.4.0(jiti@1.21.7)(postcss@8.5.3)(tsx@4.19.3)(typescript@5.8.2)(yaml@2.7.0): + dependencies: + bundle-require: 5.1.0(esbuild@0.25.1) + cac: 6.7.14 + chokidar: 4.0.3 + consola: 3.4.0 + debug: 4.4.0 + esbuild: 0.25.1 + joycon: 3.1.1 + picocolors: 1.1.1 + postcss-load-config: 6.0.1(jiti@1.21.7)(postcss@8.5.3)(tsx@4.19.3)(yaml@2.7.0) + resolve-from: 5.0.0 + rollup: 4.35.0 + source-map: 0.8.0-beta.0 + sucrase: 3.35.0 + tinyexec: 0.3.2 + tinyglobby: 0.2.12 + tree-kill: 1.2.2 + optionalDependencies: + postcss: 8.5.3 + typescript: 5.8.2 + transitivePeerDependencies: + - jiti + - supports-color + - tsx + - yaml + tsx@4.19.3: dependencies: esbuild: 0.25.1 @@ -6788,6 +6968,14 @@ snapshots: web-namespaces@2.0.1: {} + webidl-conversions@4.0.2: {} + + whatwg-url@7.1.0: + dependencies: + lodash.sortby: 4.7.0 + tr46: 1.0.1 + webidl-conversions: 4.0.2 + when-exit@2.1.4: {} which@2.0.2: diff --git a/src-tauri/src/server/websocket.rs b/src-tauri/src/server/websocket.rs index 75aa81d5..f4850e3d 100644 --- a/src-tauri/src/server/websocket.rs +++ b/src-tauri/src/server/websocket.rs @@ -128,7 +128,7 @@ pub async fn connect_to_server( msg = ws.next() => { match msg { Some(Ok(Message::Text(text))) => { - //println!("Received message: {}", text); + // println!("Received message: {}", text); let _ = app_handle_clone.emit("ws-message", text); }, Some(Err(WsError::ConnectionClosed)) => { diff --git a/src/components/Assistant/Chat.tsx b/src/components/Assistant/Chat.tsx index 1cf67316..18a62395 100644 --- a/src/components/Assistant/Chat.tsx +++ b/src/components/Assistant/Chat.tsx @@ -32,6 +32,7 @@ interface ChatAIProps { isSidebarOpen?: boolean; clearChatPage?: () => void; isChatPage?: boolean; + getFileUrl: (path: string) => string; } export interface ChatAIRef { @@ -54,6 +55,7 @@ const ChatAI = memo( isSidebarOpen = false, clearChatPage, isChatPage = false, + getFileUrl, }, ref ) => { @@ -323,6 +325,7 @@ const ChatAI = memo( errorShow={errorShow} Question={Question} handleSendMessage={(value) => handleSendMessage(value, activeChat)} + getFileUrl={getFileUrl} /> ) : ( diff --git a/src/components/Assistant/ChatContent.tsx b/src/components/Assistant/ChatContent.tsx index 88b8ee6d..73e99bff 100644 --- a/src/components/Assistant/ChatContent.tsx +++ b/src/components/Assistant/ChatContent.tsx @@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next"; import { ChatMessage } from "@/components/ChatMessage"; import { Greetings } from "./Greetings"; -import FileList from "@/components/Search/FileList"; +import FileList from "@/components/Assistant/FileList"; import { useChatScroll } from "@/hooks/useChatScroll"; import { useChatStore } from "@/stores/chatStore"; import type { Chat, IChunkData } from "./types"; @@ -22,6 +22,7 @@ interface ChatContentProps { errorShow: boolean; Question: string; handleSendMessage: (content: string, newChat?: Chat) => void; + getFileUrl: (path: string) => string; } export const ChatContent = ({ @@ -38,6 +39,7 @@ export const ChatContent = ({ errorShow, Question, handleSendMessage, + getFileUrl, }: ChatContentProps) => { const { t } = useTranslation(); @@ -143,7 +145,7 @@ export const ChatContent = ({ {uploadFiles.length > 0 && (
- +
)} diff --git a/src/components/Assistant/ChatHeader.tsx b/src/components/Assistant/ChatHeader.tsx index 6eabc9d4..53d69ad9 100644 --- a/src/components/Assistant/ChatHeader.tsx +++ b/src/components/Assistant/ChatHeader.tsx @@ -17,9 +17,6 @@ import { PopoverPanel, } from "@headlessui/react"; import { useTranslation } from "react-i18next"; -import { invoke } from "@tauri-apps/api/core"; -import { emit, listen } from "@tauri-apps/api/event"; -import { getCurrentWindow } from "@tauri-apps/api/window"; import logoImg from "@/assets/icon.svg"; import HistoryIcon from "@/icons/History"; @@ -31,6 +28,7 @@ import { useAppStore, IServer } from "@/stores/appStore"; import { useChatStore } from "@/stores/chatStore"; import type { Chat } from "./types"; import { useConnectStore } from "@/stores/connectStore"; +import platformAdapter from "@/utils/platformAdapter"; interface ChatHeaderProps { onCreateNewChat: () => void; @@ -67,7 +65,7 @@ export function ChatHeader({ const setCurrentService = useConnectStore((state) => state.setCurrentService); const fetchServers = useCallback(async (resetSelection: boolean) => { - invoke("list_coco_servers") + platformAdapter.invokeBackend("list_coco_servers") .then((res: any) => { const enabledServers = (res as IServer[]).filter( (server) => server.enabled !== false @@ -95,7 +93,7 @@ export function ChatHeader({ useEffect(() => { fetchServers(true); - const unlisten = listen("login_or_logout", (event) => { + const unlisten = platformAdapter.listenEvent("login_or_logout", (event) => { console.log("Login or Logout:", currentService, event); fetchServers(true); }); @@ -111,7 +109,7 @@ export function ChatHeader({ if (!connected) return; try { console.log("disconnect"); - await invoke("disconnect"); + await platformAdapter.invokeBackend("disconnect"); } catch (error) { console.error("Failed to disconnect:", error); } @@ -142,7 +140,7 @@ export function ChatHeader({ const togglePin = async () => { try { const newPinned = !isPinned; - await getCurrentWindow().setAlwaysOnTop(newPinned); + await platformAdapter.setAlwaysOnTop(newPinned); setIsPinned(newPinned); } catch (err) { console.error("Failed to toggle window pin state:", err); @@ -151,7 +149,7 @@ export function ChatHeader({ }; const openSettings = async () => { - emit("open_settings", "connect"); + platformAdapter.emitEvent("open_settings", "connect"); }; return ( diff --git a/src/components/Assistant/ConnectPrompt.tsx b/src/components/Assistant/ConnectPrompt.tsx index e3178741..6eb1873c 100644 --- a/src/components/Assistant/ConnectPrompt.tsx +++ b/src/components/Assistant/ConnectPrompt.tsx @@ -1,10 +1,10 @@ import { ExternalLink } from "lucide-react"; import { useTranslation } from "react-i18next"; -import { emit } from "@tauri-apps/api/event"; import LoginDark from "@/assets/images/login-dark.svg"; import LoginLight from "@/assets/images/login-light.svg"; import { useThemeStore } from "@/stores/themeStore"; +import platformAdapter from "@/utils/platformAdapter"; const ConnectPrompt = () => { const { t } = useTranslation(); @@ -13,7 +13,7 @@ const ConnectPrompt = () => { const logo = isDark ? LoginDark : LoginLight; const handleConnect = async () => { - emit("open_settings", "connect"); + platformAdapter.emitEvent("open_settings", "connect"); }; return ( diff --git a/src/components/Search/FileList.tsx b/src/components/Assistant/FileList.tsx similarity index 91% rename from src/components/Search/FileList.tsx rename to src/components/Assistant/FileList.tsx index 2b8eaf8e..b4170b40 100644 --- a/src/components/Search/FileList.tsx +++ b/src/components/Assistant/FileList.tsx @@ -1,10 +1,14 @@ -import { useChatStore } from "@/stores/chatStore"; -import { isImage } from "@/utils"; -import { convertFileSrc } from "@tauri-apps/api/core"; import { filesize } from "filesize"; import { X } from "lucide-react"; -const FileList = () => { +import { useChatStore } from "@/stores/chatStore"; +import { isImage } from "@/utils"; + +interface FileListProps { + getFileUrl: (path: string) => string; +} + +const FileList = ({ getFileUrl }: FileListProps) => { const uploadFiles = useChatStore((state) => state.uploadFiles); const setUploadFiles = useChatStore((state) => state.setUploadFiles); @@ -30,7 +34,7 @@ const FileList = () => { diff --git a/src/components/Assistant/types.ts b/src/components/Assistant/types.ts index 329eecd3..8bf46e21 100644 --- a/src/components/Assistant/types.ts +++ b/src/components/Assistant/types.ts @@ -39,3 +39,9 @@ export interface IChunkData { message_chunk: string; [key: string]: any; } + +export interface DataSource { + id: string; + name: string; + [key: string]: any; +} diff --git a/src/components/Common/AutoResizeTextarea.tsx b/src/components/Common/AutoResizeTextarea.tsx deleted file mode 100644 index 0313ee23..00000000 --- a/src/components/Common/AutoResizeTextarea.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import { useRef, useImperativeHandle, forwardRef } from "react"; - -interface AutoResizeTextareaProps { - input: string; - setInput: (value: string) => void; - handleKeyDown?: (e: React.KeyboardEvent) => void; -} - -// Forward ref to allow parent to interact with this component -const AutoResizeTextarea = forwardRef< - { reset: () => void; focus: () => void }, - AutoResizeTextareaProps ->(({ input, setInput, handleKeyDown }, ref) => { - const textareaRef = useRef(null); - - // Expose methods to the parent via ref - useImperativeHandle(ref, () => ({ - reset: () => { - setInput(""); - const textarea = textareaRef.current; - if (textarea) { - textarea.style.height = "auto"; - } - }, - focus: () => { - textareaRef.current?.focus(); - }, - })); - - return ( -