From 3c8f38799c6baa697a4f5b5f878e0b8dfad14caa Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Wed, 3 May 2023 22:33:25 +0800 Subject: [PATCH] perf: ts type --- package.json | 1 + pnpm-lock.yaml | 429 +++++++++++++++----------------- src/service/utils/chat/index.ts | 39 ++- src/utils/chat/index.ts | 9 +- 4 files changed, 243 insertions(+), 235 deletions(-) diff --git a/package.json b/package.json index e010c98bc..2a2cd62b6 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "axios": "^1.3.3", "crypto": "^1.0.1", "dayjs": "^1.11.7", + "delay": "^5.0.0", "eventsource-parser": "^0.1.0", "formidable": "^2.1.1", "framer-motion": "^9.0.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6e464905a..c72b383b3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -28,6 +28,7 @@ specifiers: axios: ^1.3.3 crypto: ^1.0.1 dayjs: ^1.11.7 + delay: ^5.0.0 eslint: 8.34.0 eslint-config-next: 13.1.6 eventsource-parser: ^0.1.0 @@ -82,6 +83,7 @@ dependencies: axios: registry.npmmirror.com/axios/1.3.3 crypto: registry.npmmirror.com/crypto/1.0.1 dayjs: registry.npmmirror.com/dayjs/1.11.7 + delay: 5.0.0 eventsource-parser: registry.npmmirror.com/eventsource-parser/0.1.0 formidable: registry.npmmirror.com/formidable/2.1.1 framer-motion: registry.npmmirror.com/framer-motion/9.0.6_biqbaboplfbrettd7655fr4n2y @@ -136,6 +138,189 @@ devDependencies: packages: + /@aws-sdk/credential-providers/3.278.0: + resolution: {integrity: sha512-XeCyXru9+gxePvrnPbdITZLSCC5qg3C/hgdItstDEvrQh+vMw9DJvX5ztoKh987C0puwkbB6HENC04ZTh/0Buw==} + engines: {node: '>=14.0.0'} + requiresBuild: true + dependencies: + '@aws-sdk/client-cognito-identity': registry.npmmirror.com/@aws-sdk/client-cognito-identity/3.278.0 + '@aws-sdk/client-sso': registry.npmmirror.com/@aws-sdk/client-sso/3.278.0 + '@aws-sdk/client-sts': registry.npmmirror.com/@aws-sdk/client-sts/3.278.0 + '@aws-sdk/credential-provider-cognito-identity': registry.npmmirror.com/@aws-sdk/credential-provider-cognito-identity/3.278.0 + '@aws-sdk/credential-provider-env': registry.npmmirror.com/@aws-sdk/credential-provider-env/3.272.0 + '@aws-sdk/credential-provider-imds': registry.npmmirror.com/@aws-sdk/credential-provider-imds/3.272.0 + '@aws-sdk/credential-provider-ini': registry.npmmirror.com/@aws-sdk/credential-provider-ini/3.278.0 + '@aws-sdk/credential-provider-node': registry.npmmirror.com/@aws-sdk/credential-provider-node/3.278.0 + '@aws-sdk/credential-provider-process': registry.npmmirror.com/@aws-sdk/credential-provider-process/3.272.0 + '@aws-sdk/credential-provider-sso': registry.npmmirror.com/@aws-sdk/credential-provider-sso/3.278.0 + '@aws-sdk/credential-provider-web-identity': registry.npmmirror.com/@aws-sdk/credential-provider-web-identity/3.272.0 + '@aws-sdk/property-provider': registry.npmmirror.com/@aws-sdk/property-provider/3.272.0 + '@aws-sdk/shared-ini-file-loader': registry.npmmirror.com/@aws-sdk/shared-ini-file-loader/3.272.0 + '@aws-sdk/types': registry.npmmirror.com/@aws-sdk/types/3.272.0 + tslib: registry.npmmirror.com/tslib/2.5.0 + transitivePeerDependencies: + - aws-crt + dev: false + optional: true + + /@emotion/is-prop-valid/0.8.8: + resolution: {integrity: sha512-u5WtneEAr5IDG2Wv65yhunPSMLIpuKsbuOktRojfrEiEvRyC85LgPMZI63cr7NUqT8ZIGdSVg8ZKGxIug4lXcA==} + requiresBuild: true + dependencies: + '@emotion/memoize': registry.npmmirror.com/@emotion/memoize/0.7.4 + dev: false + optional: true + + /@next/swc-android-arm-eabi/13.1.6: + resolution: {integrity: sha512-F3/6Z8LH/pGlPzR1AcjPFxx35mPqjE5xZcf+IL+KgbW9tMkp7CYi1y7qKrEWU7W4AumxX/8OINnDQWLiwLasLQ==} + engines: {node: '>= 10'} + cpu: [arm] + os: [android] + requiresBuild: true + dev: false + optional: true + + /@next/swc-android-arm64/13.1.6: + resolution: {integrity: sha512-cMwQjnB8vrYkWyK/H0Rf2c2pKIH4RGjpKUDvbjVAit6SbwPDpmaijLio0LWFV3/tOnY6kvzbL62lndVA0mkYpw==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: false + optional: true + + /@next/swc-darwin-arm64/13.1.6: + resolution: {integrity: sha512-KKRQH4DDE4kONXCvFMNBZGDb499Hs+xcFAwvj+rfSUssIDrZOlyfJNy55rH5t2Qxed1e4K80KEJgsxKQN1/fyw==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /@next/swc-darwin-x64/13.1.6: + resolution: {integrity: sha512-/uOky5PaZDoaU99ohjtNcDTJ6ks/gZ5ykTQDvNZDjIoCxFe3+t06bxsTPY6tAO6uEAw5f6vVFX5H5KLwhrkZCA==} + engines: {node: '>= 10'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /@next/swc-freebsd-x64/13.1.6: + resolution: {integrity: sha512-qaEALZeV7to6weSXk3Br80wtFQ7cFTpos/q+m9XVRFggu+8Ib895XhMWdJBzew6aaOcMvYR6KQ6JmHA2/eMzWw==} + engines: {node: '>= 10'} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: false + optional: true + + /@next/swc-linux-arm-gnueabihf/13.1.6: + resolution: {integrity: sha512-OybkbC58A1wJ+JrJSOjGDvZzrVEQA4sprJejGqMwiZyLqhr9Eo8FXF0y6HL+m1CPCpPhXEHz/2xKoYsl16kNqw==} + engines: {node: '>= 10'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@next/swc-linux-arm64-gnu/13.1.6: + resolution: {integrity: sha512-yCH+yDr7/4FDuWv6+GiYrPI9kcTAO3y48UmaIbrKy8ZJpi7RehJe3vIBRUmLrLaNDH3rY1rwoHi471NvR5J5NQ==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@next/swc-linux-arm64-musl/13.1.6: + resolution: {integrity: sha512-ECagB8LGX25P9Mrmlc7Q/TQBb9rGScxHbv/kLqqIWs2fIXy6Y/EiBBiM72NTwuXUFCNrWR4sjUPSooVBJJ3ESQ==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@next/swc-linux-x64-gnu/13.1.6: + resolution: {integrity: sha512-GT5w2mruk90V/I5g6ScuueE7fqj/d8Bui2qxdw6lFxmuTgMeol5rnzAv4uAoVQgClOUO/MULilzlODg9Ib3Y4Q==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@next/swc-linux-x64-musl/13.1.6: + resolution: {integrity: sha512-keFD6KvwOPzmat4TCnlnuxJCQepPN+8j3Nw876FtULxo8005Y9Ghcl7ACcR8GoiKoddAq8gxNBrpjoxjQRHeAQ==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@next/swc-win32-arm64-msvc/13.1.6: + resolution: {integrity: sha512-OwertslIiGQluFvHyRDzBCIB07qJjqabAmINlXUYt7/sY7Q7QPE8xVi5beBxX/rxTGPIbtyIe3faBE6Z2KywhQ==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /@next/swc-win32-ia32-msvc/13.1.6: + resolution: {integrity: sha512-g8zowiuP8FxUR9zslPmlju7qYbs2XBtTLVSxVikPtUDQedhcls39uKYLvOOd1JZg0ehyhopobRoH1q+MHlIN/w==} + engines: {node: '>= 10'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /@next/swc-win32-x64-msvc/13.1.6: + resolution: {integrity: sha512-Ls2OL9hi3YlJKGNdKv8k3X/lLgc3VmLG3a/DeTkAd+lAituJp8ZHmRmm9f9SL84fT3CotlzcgbdaCDfFwFA6bA==} + engines: {node: '>= 10'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /delay/5.0.0: + resolution: {integrity: sha512-ReEBKkIfe4ya47wlPYf/gu5ib6yUG0/Aez0JQZQz94kiWtRQvZIQbTiehsnwHvLSWJnQdhVeqYue7Id1dKr0qw==} + engines: {node: '>=10'} + dev: false + + /fsevents/2.3.2: + resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==} + engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /graceful-fs/4.2.10: + resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==} + dev: false + optional: true + + /saslprep/1.0.3: + resolution: {integrity: sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==} + engines: {node: '>=6'} + requiresBuild: true + dependencies: + sparse-bitfield: registry.npmmirror.com/sparse-bitfield/3.0.3 + dev: false + optional: true + + /source-map/0.6.1: + resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} + engines: {node: '>=0.10.0'} + dev: false + optional: true + registry.npmmirror.com/@alicloud/credentials/2.2.6: resolution: {integrity: sha512-jG+msY77dHmAF3x+8VTy7fEgORyXLHmDci8t92HeipBdCHsPptDegA++GEwKgR7f6G4wvafYt+aqMZ1iligdrQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@alicloud/credentials/-/credentials-2.2.6.tgz} name: '@alicloud/credentials' @@ -641,33 +826,6 @@ packages: dev: false optional: true - registry.npmmirror.com/@aws-sdk/credential-providers/3.278.0: - resolution: {integrity: sha512-XeCyXru9+gxePvrnPbdITZLSCC5qg3C/hgdItstDEvrQh+vMw9DJvX5ztoKh987C0puwkbB6HENC04ZTh/0Buw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@aws-sdk/credential-providers/-/credential-providers-3.278.0.tgz} - name: '@aws-sdk/credential-providers' - version: 3.278.0 - engines: {node: '>=14.0.0'} - requiresBuild: true - dependencies: - '@aws-sdk/client-cognito-identity': registry.npmmirror.com/@aws-sdk/client-cognito-identity/3.278.0 - '@aws-sdk/client-sso': registry.npmmirror.com/@aws-sdk/client-sso/3.278.0 - '@aws-sdk/client-sts': registry.npmmirror.com/@aws-sdk/client-sts/3.278.0 - '@aws-sdk/credential-provider-cognito-identity': registry.npmmirror.com/@aws-sdk/credential-provider-cognito-identity/3.278.0 - '@aws-sdk/credential-provider-env': registry.npmmirror.com/@aws-sdk/credential-provider-env/3.272.0 - '@aws-sdk/credential-provider-imds': registry.npmmirror.com/@aws-sdk/credential-provider-imds/3.272.0 - '@aws-sdk/credential-provider-ini': registry.npmmirror.com/@aws-sdk/credential-provider-ini/3.278.0 - '@aws-sdk/credential-provider-node': registry.npmmirror.com/@aws-sdk/credential-provider-node/3.278.0 - '@aws-sdk/credential-provider-process': registry.npmmirror.com/@aws-sdk/credential-provider-process/3.272.0 - '@aws-sdk/credential-provider-sso': registry.npmmirror.com/@aws-sdk/credential-provider-sso/3.278.0 - '@aws-sdk/credential-provider-web-identity': registry.npmmirror.com/@aws-sdk/credential-provider-web-identity/3.272.0 - '@aws-sdk/property-provider': registry.npmmirror.com/@aws-sdk/property-provider/3.272.0 - '@aws-sdk/shared-ini-file-loader': registry.npmmirror.com/@aws-sdk/shared-ini-file-loader/3.272.0 - '@aws-sdk/types': registry.npmmirror.com/@aws-sdk/types/3.272.0 - tslib: registry.npmmirror.com/tslib/2.5.0 - transitivePeerDependencies: - - aws-crt - dev: false - optional: true - registry.npmmirror.com/@aws-sdk/fetch-http-handler/3.272.0: resolution: {integrity: sha512-1Qhm9e0RbS1Xf4CZqUbQyUMkDLd7GrsRXWIvm9b86/vgeV8/WnjO3CMue9D51nYgcyQORhYXv6uVjAYCWbUExA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@aws-sdk/fetch-http-handler/-/fetch-http-handler-3.272.0.tgz} name: '@aws-sdk/fetch-http-handler' @@ -4220,16 +4378,6 @@ packages: version: 0.9.0 dev: false - registry.npmmirror.com/@emotion/is-prop-valid/0.8.8: - resolution: {integrity: sha512-u5WtneEAr5IDG2Wv65yhunPSMLIpuKsbuOktRojfrEiEvRyC85LgPMZI63cr7NUqT8ZIGdSVg8ZKGxIug4lXcA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@emotion/is-prop-valid/-/is-prop-valid-0.8.8.tgz} - name: '@emotion/is-prop-valid' - version: 0.8.8 - requiresBuild: true - dependencies: - '@emotion/memoize': registry.npmmirror.com/@emotion/memoize/0.7.4 - dev: false - optional: true - registry.npmmirror.com/@emotion/is-prop-valid/1.2.0: resolution: {integrity: sha512-3aDpDprjM0AwaxGE09bOPkNxHpBd+kA6jty3RnaEXdweX1DF1U3VQpPYb0g1IStAuK7SVQ1cy+bNBBKp4W3Fjg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@emotion/is-prop-valid/-/is-prop-valid-1.2.0.tgz} name: '@emotion/is-prop-valid' @@ -4520,153 +4668,6 @@ packages: version: 13.1.6 dev: false - registry.npmmirror.com/@next/swc-android-arm-eabi/13.1.6: - resolution: {integrity: sha512-F3/6Z8LH/pGlPzR1AcjPFxx35mPqjE5xZcf+IL+KgbW9tMkp7CYi1y7qKrEWU7W4AumxX/8OINnDQWLiwLasLQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@next/swc-android-arm-eabi/-/swc-android-arm-eabi-13.1.6.tgz} - name: '@next/swc-android-arm-eabi' - version: 13.1.6 - engines: {node: '>= 10'} - cpu: [arm] - os: [android] - requiresBuild: true - dev: false - optional: true - - registry.npmmirror.com/@next/swc-android-arm64/13.1.6: - resolution: {integrity: sha512-cMwQjnB8vrYkWyK/H0Rf2c2pKIH4RGjpKUDvbjVAit6SbwPDpmaijLio0LWFV3/tOnY6kvzbL62lndVA0mkYpw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@next/swc-android-arm64/-/swc-android-arm64-13.1.6.tgz} - name: '@next/swc-android-arm64' - version: 13.1.6 - engines: {node: '>= 10'} - cpu: [arm64] - os: [android] - requiresBuild: true - dev: false - optional: true - - registry.npmmirror.com/@next/swc-darwin-arm64/13.1.6: - resolution: {integrity: sha512-KKRQH4DDE4kONXCvFMNBZGDb499Hs+xcFAwvj+rfSUssIDrZOlyfJNy55rH5t2Qxed1e4K80KEJgsxKQN1/fyw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.1.6.tgz} - name: '@next/swc-darwin-arm64' - version: 13.1.6 - engines: {node: '>= 10'} - cpu: [arm64] - os: [darwin] - requiresBuild: true - dev: false - optional: true - - registry.npmmirror.com/@next/swc-darwin-x64/13.1.6: - resolution: {integrity: sha512-/uOky5PaZDoaU99ohjtNcDTJ6ks/gZ5ykTQDvNZDjIoCxFe3+t06bxsTPY6tAO6uEAw5f6vVFX5H5KLwhrkZCA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@next/swc-darwin-x64/-/swc-darwin-x64-13.1.6.tgz} - name: '@next/swc-darwin-x64' - version: 13.1.6 - engines: {node: '>= 10'} - cpu: [x64] - os: [darwin] - requiresBuild: true - dev: false - optional: true - - registry.npmmirror.com/@next/swc-freebsd-x64/13.1.6: - resolution: {integrity: sha512-qaEALZeV7to6weSXk3Br80wtFQ7cFTpos/q+m9XVRFggu+8Ib895XhMWdJBzew6aaOcMvYR6KQ6JmHA2/eMzWw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@next/swc-freebsd-x64/-/swc-freebsd-x64-13.1.6.tgz} - name: '@next/swc-freebsd-x64' - version: 13.1.6 - engines: {node: '>= 10'} - cpu: [x64] - os: [freebsd] - requiresBuild: true - dev: false - optional: true - - registry.npmmirror.com/@next/swc-linux-arm-gnueabihf/13.1.6: - resolution: {integrity: sha512-OybkbC58A1wJ+JrJSOjGDvZzrVEQA4sprJejGqMwiZyLqhr9Eo8FXF0y6HL+m1CPCpPhXEHz/2xKoYsl16kNqw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@next/swc-linux-arm-gnueabihf/-/swc-linux-arm-gnueabihf-13.1.6.tgz} - name: '@next/swc-linux-arm-gnueabihf' - version: 13.1.6 - engines: {node: '>= 10'} - cpu: [arm] - os: [linux] - requiresBuild: true - dev: false - optional: true - - registry.npmmirror.com/@next/swc-linux-arm64-gnu/13.1.6: - resolution: {integrity: sha512-yCH+yDr7/4FDuWv6+GiYrPI9kcTAO3y48UmaIbrKy8ZJpi7RehJe3vIBRUmLrLaNDH3rY1rwoHi471NvR5J5NQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.1.6.tgz} - name: '@next/swc-linux-arm64-gnu' - version: 13.1.6 - engines: {node: '>= 10'} - cpu: [arm64] - os: [linux] - libc: [glibc] - requiresBuild: true - dev: false - optional: true - - registry.npmmirror.com/@next/swc-linux-arm64-musl/13.1.6: - resolution: {integrity: sha512-ECagB8LGX25P9Mrmlc7Q/TQBb9rGScxHbv/kLqqIWs2fIXy6Y/EiBBiM72NTwuXUFCNrWR4sjUPSooVBJJ3ESQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.1.6.tgz} - name: '@next/swc-linux-arm64-musl' - version: 13.1.6 - engines: {node: '>= 10'} - cpu: [arm64] - os: [linux] - libc: [musl] - requiresBuild: true - dev: false - optional: true - - registry.npmmirror.com/@next/swc-linux-x64-gnu/13.1.6: - resolution: {integrity: sha512-GT5w2mruk90V/I5g6ScuueE7fqj/d8Bui2qxdw6lFxmuTgMeol5rnzAv4uAoVQgClOUO/MULilzlODg9Ib3Y4Q==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.1.6.tgz} - name: '@next/swc-linux-x64-gnu' - version: 13.1.6 - engines: {node: '>= 10'} - cpu: [x64] - os: [linux] - libc: [glibc] - requiresBuild: true - dev: false - optional: true - - registry.npmmirror.com/@next/swc-linux-x64-musl/13.1.6: - resolution: {integrity: sha512-keFD6KvwOPzmat4TCnlnuxJCQepPN+8j3Nw876FtULxo8005Y9Ghcl7ACcR8GoiKoddAq8gxNBrpjoxjQRHeAQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.1.6.tgz} - name: '@next/swc-linux-x64-musl' - version: 13.1.6 - engines: {node: '>= 10'} - cpu: [x64] - os: [linux] - libc: [musl] - requiresBuild: true - dev: false - optional: true - - registry.npmmirror.com/@next/swc-win32-arm64-msvc/13.1.6: - resolution: {integrity: sha512-OwertslIiGQluFvHyRDzBCIB07qJjqabAmINlXUYt7/sY7Q7QPE8xVi5beBxX/rxTGPIbtyIe3faBE6Z2KywhQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.1.6.tgz} - name: '@next/swc-win32-arm64-msvc' - version: 13.1.6 - engines: {node: '>= 10'} - cpu: [arm64] - os: [win32] - requiresBuild: true - dev: false - optional: true - - registry.npmmirror.com/@next/swc-win32-ia32-msvc/13.1.6: - resolution: {integrity: sha512-g8zowiuP8FxUR9zslPmlju7qYbs2XBtTLVSxVikPtUDQedhcls39uKYLvOOd1JZg0ehyhopobRoH1q+MHlIN/w==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.1.6.tgz} - name: '@next/swc-win32-ia32-msvc' - version: 13.1.6 - engines: {node: '>= 10'} - cpu: [ia32] - os: [win32] - requiresBuild: true - dev: false - optional: true - - registry.npmmirror.com/@next/swc-win32-x64-msvc/13.1.6: - resolution: {integrity: sha512-Ls2OL9hi3YlJKGNdKv8k3X/lLgc3VmLG3a/DeTkAd+lAituJp8ZHmRmm9f9SL84fT3CotlzcgbdaCDfFwFA6bA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.1.6.tgz} - name: '@next/swc-win32-x64-msvc' - version: 13.1.6 - engines: {node: '>= 10'} - cpu: [x64] - os: [win32] - requiresBuild: true - dev: false - optional: true - registry.npmmirror.com/@nodelib/fs.scandir/2.1.5: resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz} name: '@nodelib/fs.scandir' @@ -6018,7 +6019,7 @@ packages: normalize-path: registry.npmmirror.com/normalize-path/3.0.0 readdirp: registry.npmmirror.com/readdirp/3.6.0 optionalDependencies: - fsevents: registry.npmmirror.com/fsevents/2.3.2 + fsevents: 2.3.2 dev: false registry.npmmirror.com/chownr/1.1.4: @@ -6812,7 +6813,7 @@ packages: esutils: registry.npmmirror.com/esutils/2.0.3 optionator: registry.npmmirror.com/optionator/0.8.3 optionalDependencies: - source-map: registry.npmmirror.com/source-map/0.6.1 + source-map: 0.6.1 dev: false registry.npmmirror.com/eslint-config-next/13.1.6_7kw3g6rralp5ps6mg3uyzz6azm: @@ -7399,7 +7400,7 @@ packages: react-dom: registry.npmmirror.com/react-dom/18.2.0_react@18.2.0 tslib: registry.npmmirror.com/tslib/2.5.0 optionalDependencies: - '@emotion/is-prop-valid': registry.npmmirror.com/@emotion/is-prop-valid/0.8.8 + '@emotion/is-prop-valid': 0.8.8 dev: false registry.npmmirror.com/framesync/6.1.2: @@ -7433,16 +7434,6 @@ packages: version: 1.0.0 dev: true - registry.npmmirror.com/fsevents/2.3.2: - resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/fsevents/-/fsevents-2.3.2.tgz} - name: fsevents - version: 2.3.2 - engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} - os: [darwin] - requiresBuild: true - dev: false - optional: true - registry.npmmirror.com/ftp/0.3.10: resolution: {integrity: sha512-faFVML1aBx2UoDStmLwv2Wptt4vw5x03xxX172nhA5Y5HBshW5JweqQ2W4xL4dezQTG8inJsuYcpPHHU3X5OTQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/ftp/-/ftp-0.3.10.tgz} name: ftp @@ -8442,7 +8433,7 @@ packages: name: jsonfile version: 4.0.0 optionalDependencies: - graceful-fs: registry.npmmirror.com/graceful-fs/4.2.10 + graceful-fs: 4.2.10 dev: false registry.npmmirror.com/jsonwebtoken/9.0.0: @@ -9373,8 +9364,8 @@ packages: mongodb-connection-string-url: registry.npmmirror.com/mongodb-connection-string-url/2.6.0 socks: registry.npmmirror.com/socks/2.7.1 optionalDependencies: - '@aws-sdk/credential-providers': registry.npmmirror.com/@aws-sdk/credential-providers/3.278.0 - saslprep: registry.npmmirror.com/saslprep/1.0.3 + '@aws-sdk/credential-providers': 3.278.0 + saslprep: 1.0.3 transitivePeerDependencies: - aws-crt dev: false @@ -9513,19 +9504,19 @@ packages: sass: registry.npmmirror.com/sass/1.58.3 styled-jsx: registry.npmmirror.com/styled-jsx/5.1.1_react@18.2.0 optionalDependencies: - '@next/swc-android-arm-eabi': registry.npmmirror.com/@next/swc-android-arm-eabi/13.1.6 - '@next/swc-android-arm64': registry.npmmirror.com/@next/swc-android-arm64/13.1.6 - '@next/swc-darwin-arm64': registry.npmmirror.com/@next/swc-darwin-arm64/13.1.6 - '@next/swc-darwin-x64': registry.npmmirror.com/@next/swc-darwin-x64/13.1.6 - '@next/swc-freebsd-x64': registry.npmmirror.com/@next/swc-freebsd-x64/13.1.6 - '@next/swc-linux-arm-gnueabihf': registry.npmmirror.com/@next/swc-linux-arm-gnueabihf/13.1.6 - '@next/swc-linux-arm64-gnu': registry.npmmirror.com/@next/swc-linux-arm64-gnu/13.1.6 - '@next/swc-linux-arm64-musl': registry.npmmirror.com/@next/swc-linux-arm64-musl/13.1.6 - '@next/swc-linux-x64-gnu': registry.npmmirror.com/@next/swc-linux-x64-gnu/13.1.6 - '@next/swc-linux-x64-musl': registry.npmmirror.com/@next/swc-linux-x64-musl/13.1.6 - '@next/swc-win32-arm64-msvc': registry.npmmirror.com/@next/swc-win32-arm64-msvc/13.1.6 - '@next/swc-win32-ia32-msvc': registry.npmmirror.com/@next/swc-win32-ia32-msvc/13.1.6 - '@next/swc-win32-x64-msvc': registry.npmmirror.com/@next/swc-win32-x64-msvc/13.1.6 + '@next/swc-android-arm-eabi': 13.1.6 + '@next/swc-android-arm64': 13.1.6 + '@next/swc-darwin-arm64': 13.1.6 + '@next/swc-darwin-x64': 13.1.6 + '@next/swc-freebsd-x64': 13.1.6 + '@next/swc-linux-arm-gnueabihf': 13.1.6 + '@next/swc-linux-arm64-gnu': 13.1.6 + '@next/swc-linux-arm64-musl': 13.1.6 + '@next/swc-linux-x64-gnu': 13.1.6 + '@next/swc-linux-x64-musl': 13.1.6 + '@next/swc-win32-arm64-msvc': 13.1.6 + '@next/swc-win32-ia32-msvc': 13.1.6 + '@next/swc-win32-x64-msvc': 13.1.6 transitivePeerDependencies: - '@babel/core' - babel-plugin-macros @@ -10760,17 +10751,6 @@ packages: version: 2.1.2 dev: false - registry.npmmirror.com/saslprep/1.0.3: - resolution: {integrity: sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/saslprep/-/saslprep-1.0.3.tgz} - name: saslprep - version: 1.0.3 - engines: {node: '>=6'} - requiresBuild: true - dependencies: - sparse-bitfield: registry.npmmirror.com/sparse-bitfield/3.0.3 - dev: false - optional: true - registry.npmmirror.com/sass/1.58.3: resolution: {integrity: sha512-Q7RaEtYf6BflYrQ+buPudKR26/lH+10EmO9bBqbmPh/KeLqv8bjpTNqxe71ocONqXq+jYiCbpPUmQMS+JJPk4A==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/sass/-/sass-1.58.3.tgz} name: sass @@ -11011,6 +10991,7 @@ packages: name: source-map version: 0.6.1 engines: {node: '>=0.10.0'} + dev: true registry.npmmirror.com/space-separated-tokens/1.1.5: resolution: {integrity: sha512-q/JSVd1Lptzhf5bkYm4ob4iWPjx0KiRe3sRFBNrVqbJkFaBm5vbbowy1mymoPNLRa52+oadOhJ+K49wsSeSjTA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/space-separated-tokens/-/space-separated-tokens-1.1.5.tgz} diff --git a/src/service/utils/chat/index.ts b/src/service/utils/chat/index.ts index 96c34ab1f..5da3b6497 100644 --- a/src/service/utils/chat/index.ts +++ b/src/service/utils/chat/index.ts @@ -6,20 +6,39 @@ import { OpenAiChatEnum } from '@/constants/model'; import { chatResponse, openAiStreamResponse } from './openai'; import type { NextApiResponse } from 'next'; import type { PassThrough } from 'stream'; +import delay from 'delay'; export type ChatCompletionType = { apiKey: string; temperature: number; messages: ChatItemSimpleType[]; stream: boolean; + params?: any; +}; +export type ChatCompletionResponseType = { + streamResponse: any; + responseMessages: ChatItemSimpleType[]; + responseText: string; + totalTokens: number; }; export type StreamResponseType = { stream: PassThrough; chatResponse: any; prompts: ChatItemSimpleType[]; }; +export type StreamResponseReturnType = { + responseContent: string; + totalTokens: number; + finishMessages: ChatItemSimpleType[]; +}; -export const modelServiceToolMap = { +export const modelServiceToolMap: Record< + ChatModelType, + { + chatCompletion: (data: ChatCompletionType) => Promise; + streamResponse: (data: StreamResponseType) => Promise; + } +> = { [OpenAiChatEnum.GPT35]: { chatCompletion: (data: ChatCompletionType) => chatResponse({ model: OpenAiChatEnum.GPT35, ...data }), @@ -142,16 +161,16 @@ export const resStreamResponse = async ({ prompts }); - setTimeout(() => { - // push system prompt - !stream.destroyed && - systemPrompt && - stream.push(`${SYSTEM_PROMPT_PREFIX}${systemPrompt.replace(/\n/g, '
')}`); + await delay(100); - // close stream - !stream.destroyed && stream.push(null); - stream.destroy(); - }, 100); + // push system prompt + !stream.destroyed && + systemPrompt && + stream.push(`${SYSTEM_PROMPT_PREFIX}${systemPrompt.replace(/\n/g, '
')}`); + + // close stream + !stream.destroyed && stream.push(null); + stream.destroy(); return { responseContent, totalTokens, finishMessages }; }; diff --git a/src/utils/chat/index.ts b/src/utils/chat/index.ts index 8af9aadaa..868d0b563 100644 --- a/src/utils/chat/index.ts +++ b/src/utils/chat/index.ts @@ -2,10 +2,17 @@ import { OpenAiChatEnum } from '@/constants/model'; import type { ChatModelType } from '@/constants/model'; import type { ChatItemSimpleType } from '@/types/chat'; import { countOpenAIToken, getOpenAiEncMap, adaptChatItem_openAI } from './openai'; +import { ChatCompletionRequestMessage } from 'openai'; export type CountTokenType = { messages: ChatItemSimpleType[] }; -export const modelToolMap = { +export const modelToolMap: Record< + ChatModelType, + { + countTokens: (data: CountTokenType) => number; + adaptChatMessages: (data: CountTokenType) => ChatCompletionRequestMessage[]; + } +> = { [OpenAiChatEnum.GPT35]: { countTokens: ({ messages }: CountTokenType) => countOpenAIToken({ model: OpenAiChatEnum.GPT35, messages }),