diff --git a/CHANGELOG.md b/CHANGELOG.md index fcb3845..e417a8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## v2.2.0 + +`2023-02-14` +### Feature +- 会话和上下文本地储存 +- 侧边栏本地储存 + ## v2.1.0 `2023-02-14` diff --git a/package.json b/package.json index a97f802..4f5830a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chatgpt-web", - "version": "2.1.0", + "version": "2.2.0", "private": false, "description": "ChatGPT Web", "author": "ChenZhaoYu ", @@ -23,6 +23,7 @@ }, "dependencies": { "naive-ui": "^2.34.3", + "pinia": "^2.0.30", "vue": "^3.2.47", "vue-router": "^4.1.6" }, @@ -31,10 +32,12 @@ "@commitlint/cli": "^17.4.3", "@commitlint/config-conventional": "^17.4.3", "@iconify/vue": "^4.1.0", + "@types/crypto-js": "^4.1.1", "@types/node": "^18.13.0", "@vitejs/plugin-vue": "^4.0.0", "autoprefixer": "^10.4.13", "axios": "^1.3.2", + "crypto-js": "^4.1.1", "eslint": "^8.34.0", "husky": "^8.0.3", "lint-staged": "^13.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f9fe567..5bd96a7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,15 +5,18 @@ specifiers: '@commitlint/cli': ^17.4.3 '@commitlint/config-conventional': ^17.4.3 '@iconify/vue': ^4.1.0 + '@types/crypto-js': ^4.1.1 '@types/node': ^18.13.0 '@vitejs/plugin-vue': ^4.0.0 autoprefixer: ^10.4.13 axios: ^1.3.2 + crypto-js: ^4.1.1 eslint: ^8.34.0 husky: ^8.0.3 lint-staged: ^13.1.1 naive-ui: ^2.34.3 npm-run-all: ^4.1.5 + pinia: ^2.0.30 postcss: ^8.4.21 rimraf: ^4.1.2 tailwindcss: ^3.2.6 @@ -25,6 +28,7 @@ specifiers: dependencies: naive-ui: 2.34.3_vue@3.2.47 + pinia: 2.0.30_hmuptsblhheur2tugfgucj7gc4 vue: 3.2.47 vue-router: 4.1.6_vue@3.2.47 @@ -33,10 +37,12 @@ devDependencies: '@commitlint/cli': 17.4.3 '@commitlint/config-conventional': 17.4.3 '@iconify/vue': 4.1.0_vue@3.2.47 + '@types/crypto-js': 4.1.1 '@types/node': 18.13.0 '@vitejs/plugin-vue': 4.0.0_vite@4.1.1+vue@3.2.47 autoprefixer: 10.4.13_postcss@8.4.21 axios: 1.3.2 + crypto-js: 4.1.1 eslint: 8.34.0 husky: 8.0.3 lint-staged: 13.1.1 @@ -695,6 +701,10 @@ packages: resolution: {integrity: sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==} dev: true + /@types/crypto-js/4.1.1: + resolution: {integrity: sha512-BG7fQKZ689HIoc5h+6D2Dgq1fABRa0RbBWKBd9SP/MVRVXROflpm5fhwyATX5duFmbStzyzyycPB8qUYKDH3NA==} + dev: true + /@types/json-schema/7.0.11: resolution: {integrity: sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==} dev: true @@ -1527,6 +1537,10 @@ packages: which: 2.0.2 dev: true + /crypto-js/4.1.1: + resolution: {integrity: sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==} + dev: true + /css-render/0.15.12: resolution: {integrity: sha512-eWzS66patiGkTTik+ipO9qNGZ+uNuGyTmnz6/+EJIiFg8+3yZRpnMwgFo8YdXhQRsiePzehnusrxVvugNjXzbw==} dependencies: @@ -3567,6 +3581,24 @@ packages: engines: {node: '>=4'} dev: true + /pinia/2.0.30_hmuptsblhheur2tugfgucj7gc4: + resolution: {integrity: sha512-q6DUmxWwe/mQgg+55QQjykpKC+aGeGdaJV3niminl19V08dE+LRTvSEuqi6/NLSGCKHI49KGL6tMNEOssFiMyA==} + peerDependencies: + '@vue/composition-api': ^1.4.0 + typescript: '>=4.4.4' + vue: ^2.6.14 || ^3.2.0 + peerDependenciesMeta: + '@vue/composition-api': + optional: true + typescript: + optional: true + dependencies: + '@vue/devtools-api': 6.5.0 + typescript: 4.9.5 + vue: 3.2.47 + vue-demi: 0.13.11_vue@3.2.47 + dev: false + /pluralize/8.0.0: resolution: {integrity: sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==} engines: {node: '>=4'} @@ -4284,7 +4316,6 @@ packages: resolution: {integrity: sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==} engines: {node: '>=4.2.0'} hasBin: true - dev: true /unbox-primitive/1.0.2: resolution: {integrity: sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==} @@ -4390,6 +4421,21 @@ packages: vue: 3.2.47 dev: false + /vue-demi/0.13.11_vue@3.2.47: + resolution: {integrity: sha512-IR8HoEEGM65YY3ZJYAjMlKygDQn25D5ajNFNoKh9RSDMQtlzCxtfQjdQgv9jjK+m3377SsJXY8ysq8kLCZL25A==} + engines: {node: '>=12'} + hasBin: true + requiresBuild: true + peerDependencies: + '@vue/composition-api': ^1.0.0-rc.1 + vue: ^3.0.0-0 || ^2.6.0 + peerDependenciesMeta: + '@vue/composition-api': + optional: true + dependencies: + vue: 3.2.47 + dev: false + /vue-eslint-parser/9.1.0_eslint@8.34.0: resolution: {integrity: sha512-NGn/iQy8/Wb7RrRa4aRkokyCZfOUWk19OP5HP6JEozQFX5AoS/t+Z0ZN7FY4LlmWc4FNI922V7cvX28zctN8dQ==} engines: {node: ^14.17.0 || >=16.0.0} diff --git a/src/api/index.ts b/src/api/index.ts index e0e87d6..4f997d1 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,17 +1,16 @@ +import type { GenericAbortSignal } from 'axios' import { post } from '@/utils/request' +export const controller = new AbortController() + export function fetchChatAPI( prompt: string, options?: { conversationId?: string; parentMessageId?: string }, + signal?: GenericAbortSignal, ) { return post({ url: '/chat', data: { prompt, options }, - }) -} - -export function clearConversations() { - return post({ - url: '/clear', + signal, }) } diff --git a/src/components/business/Chat/hooks/useChat.ts b/src/components/business/Chat/hooks/useChat.ts new file mode 100644 index 0000000..7e7ea5e --- /dev/null +++ b/src/components/business/Chat/hooks/useChat.ts @@ -0,0 +1,28 @@ +import { useHistoryStore } from '@/store' + +export function useChat() { + const historyStore = useHistoryStore() + + function addChat( + message: string, + args?: { reversal?: boolean; error?: boolean; options?: Chat.ChatOptions }, + uuid?: number | null, + ) { + historyStore.addChat( + { + dateTime: new Date().toLocaleString(), + message, + reversal: args?.reversal ?? false, + error: args?.error ?? false, + options: args?.options ?? undefined, + }, + uuid, + ) + } + + function clearChat() { + historyStore.clearChat() + } + + return { addChat, clearChat } +} diff --git a/src/components/business/Chat/index.vue b/src/components/business/Chat/index.vue index 279ea44..85d3e12 100644 --- a/src/components/business/Chat/index.vue +++ b/src/components/business/Chat/index.vue @@ -1,27 +1,31 @@