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) => {