From a7fcab2256ff27fd931f93e22ee93c56b34aba5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E5=BA=86=E6=89=8D=E4=B8=A8=E9=9D=99=E8=A7=85?= Date: Sat, 6 Apr 2024 13:27:51 +0800 Subject: [PATCH] Fix chatdoc create issue (#18) --- ...-ec588933-f4e9-4a98-9ca9-dd050877a5cc.json | 7 +++++ src/store/chat/actions.ts | 4 +-- src/store/chatdoc/actions.ts | 26 +++++++++++++------ src/store/chatdoc/mutations.ts | 4 +-- src/store/midjourney/actions.ts | 2 +- 5 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 change/@acedatacloud-hub-ec588933-f4e9-4a98-9ca9-dd050877a5cc.json diff --git a/change/@acedatacloud-hub-ec588933-f4e9-4a98-9ca9-dd050877a5cc.json b/change/@acedatacloud-hub-ec588933-f4e9-4a98-9ca9-dd050877a5cc.json new file mode 100644 index 00000000..917d6a83 --- /dev/null +++ b/change/@acedatacloud-hub-ec588933-f4e9-4a98-9ca9-dd050877a5cc.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "fix chatdoc create issue", + "packageName": "@acedatacloud/hub", + "email": "cqc@cuiqingcai.com", + "dependentChangeType": "patch" +} diff --git a/src/store/chat/actions.ts b/src/store/chat/actions.ts index f675c3d0..d63a2272 100644 --- a/src/store/chat/actions.ts +++ b/src/store/chat/actions.ts @@ -32,11 +32,11 @@ export const setConversations = async ({ commit }: any, payload: IChatConversati export const setConversation = async ({ commit, state }: any, payload: IChatConversation): Promise => { log(setConversation, 'set conversation', payload); const conversations = state.conversations; - const index = conversations.findIndex((conversation: IChatConversation) => conversation.id === payload.id); + const index = conversations?.findIndex((conversation: IChatConversation) => conversation.id === payload.id); if (index > -1) { conversations[index] = payload; } else { - conversations.unshift(payload); + conversations?.unshift(payload); } commit('setConversations', conversations); log(setConversation, 'set conversation success', conversations); diff --git a/src/store/chatdoc/actions.ts b/src/store/chatdoc/actions.ts index 4357ce1e..12929f52 100644 --- a/src/store/chatdoc/actions.ts +++ b/src/store/chatdoc/actions.ts @@ -29,16 +29,26 @@ export const setRepository = async ({ commit }: any, payload: { repository: ICha export const getApplication = async ({ commit, - rootState + rootState, + state }: ActionContext): Promise => { - log(getApplication, 'start to get application for chat'); - const { data: applications } = await applicationOperator.getAll({ - user_id: rootState.user.id, - service_id: CHATDOC_SERVICE_ID + return new Promise(async (resolve, reject) => { + state.status.getApplication = Status.Request; + applicationOperator + .getAll({ + user_id: rootState?.user?.id, + service_id: CHATDOC_SERVICE_ID + }) + .then((response) => { + state.status.getApplication = Status.Success; + commit('setApplication', response.data.items[0]); + resolve(response.data.items[0]); + }) + .catch((error) => { + state.status.getApplication = Status.Error; + reject(error); + }); }); - log(getApplication, 'get application for chat success', applications); - commit('setApplication', applications?.items?.[0]); - return applications.items?.[0]; }; export const resetAll = ({ commit }: ActionContext): void => { diff --git a/src/store/chatdoc/mutations.ts b/src/store/chatdoc/mutations.ts index 27a83521..4089de58 100644 --- a/src/store/chatdoc/mutations.ts +++ b/src/store/chatdoc/mutations.ts @@ -17,10 +17,10 @@ export const setApplication = (state: IChatdocState, payload: IApplication): voi export const setRepositories = (state: IChatdocState, payload: IChatdocRepository[]): void => { const currentRepositories = state.repositories; - if (currentRepositories) { + if (currentRepositories && payload) { // merge current repositories into payload payload.forEach((repository: IChatdocRepository) => { - const index = currentRepositories.findIndex((item: IChatdocRepository) => item.id === repository.id); + const index = currentRepositories?.findIndex((item: IChatdocRepository) => item.id === repository.id); if (index !== -1) { payload[index] = { ...currentRepositories[index], diff --git a/src/store/midjourney/actions.ts b/src/store/midjourney/actions.ts index dddf408f..5ea38e50 100644 --- a/src/store/midjourney/actions.ts +++ b/src/store/midjourney/actions.ts @@ -38,7 +38,7 @@ export const getApplication = async ({ state.status.getApplication = Status.Request; applicationOperator .getAll({ - user_id: rootState.user.id, + user_id: rootState?.user?.id, service_id: MIDJOURNEY_SERVICE_ID }) .then((response) => {