HH-598: hide unavailable AI takeover (#155)

* fix(HH-598): hide unavailable AI takeover

* fix: isolate inbox assistant availability

---------

Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
Rogee
2026-08-24 12:49:46 +08:00
committed by GitHub
co-authored by rogee
parent 907d8ea4e1
commit a7e96afef4
6 changed files with 151 additions and 16 deletions
@@ -44,6 +44,8 @@ const getStoredMessage = (conversation, message) => {
const isNewerMessage = (currentMessage, message) =>
isNewerTimestamp(currentMessage?.updated_at, message.updated_at);
let inboxAssistantRequestId = 0;
// actions
const actions = {
getConversation: async ({ commit }, conversationId) => {
@@ -56,7 +58,10 @@ const actions = {
}
},
fetchAllConversations: async ({ commit, state, dispatch }, explicitFilters) => {
fetchAllConversations: async (
{ commit, state, dispatch },
explicitFilters
) => {
commit(types.CLEAR_LIST_ERROR_STATUS);
commit(types.SET_LIST_LOADING_STATUS);
try {
@@ -574,9 +579,14 @@ const actions = {
},
getInboxCaptainAssistantById: async ({ commit }, conversationId) => {
inboxAssistantRequestId += 1;
const requestId = inboxAssistantRequestId;
commit(types.SET_INBOX_CAPTAIN_ASSISTANT, { assistant: null });
try {
const response = await ConversationApi.getInboxAssistant(conversationId);
commit(types.SET_INBOX_CAPTAIN_ASSISTANT, response.data);
if (requestId === inboxAssistantRequestId) {
commit(types.SET_INBOX_CAPTAIN_ASSISTANT, response.data);
}
} catch (error) {
// Handle error
}
@@ -1002,22 +1002,47 @@ describe('#addMentions', () => {
it('fetches inbox assistant by id', async () => {
axios.get.mockResolvedValue({
data: {
id: 1,
name: 'Assistant',
description: 'Assistant description',
},
});
await actions.getInboxCaptainAssistantById({ commit }, 1);
expect(commit.mock.calls).toEqual([
[
types.SET_INBOX_CAPTAIN_ASSISTANT,
{
assistant: {
id: 1,
name: 'Assistant',
description: 'Assistant description',
},
},
});
await actions.getInboxCaptainAssistantById({ commit }, 1);
expect(commit.mock.calls).toEqual([
[types.SET_INBOX_CAPTAIN_ASSISTANT, { assistant: null }],
[
types.SET_INBOX_CAPTAIN_ASSISTANT,
{
assistant: {
id: 1,
name: 'Assistant',
description: 'Assistant description',
},
},
],
]);
});
it('ignores an older response after switching conversations', async () => {
const resolvers = [];
axios.get.mockImplementation(
() => new Promise(resolve => resolvers.push(resolve))
);
const requestA = actions.getInboxCaptainAssistantById({ commit }, 1);
const requestB = actions.getInboxCaptainAssistantById({ commit }, 2);
resolvers[1]({ data: { assistant: null } });
await requestB;
resolvers[0]({ data: { assistant: { id: 1, name: 'Assistant A' } } });
await requestA;
expect(commit.mock.calls).toEqual([
[types.SET_INBOX_CAPTAIN_ASSISTANT, { assistant: null }],
[types.SET_INBOX_CAPTAIN_ASSISTANT, { assistant: null }],
[types.SET_INBOX_CAPTAIN_ASSISTANT, { assistant: null }],
]);
});
});
});