diff --git a/src/apps/chat/components/composer/Composer.tsx b/src/apps/chat/components/composer/Composer.tsx index 40df400f8..e64977d93 100644 --- a/src/apps/chat/components/composer/Composer.tsx +++ b/src/apps/chat/components/composer/Composer.tsx @@ -129,7 +129,7 @@ export function Composer(props: { const { assistantAbortible, systemPurposeId, tokenCount: _historyTokenCount, abortConversationTemp } = useChatStore(useShallow(state => { const conversation = state.conversations.find(_c => _c.id === props.targetConversationId); return { - assistantAbortible: conversation ? !!conversation.abortController : false, + assistantAbortible: conversation ? !!conversation._abortController : false, systemPurposeId: conversation?.systemPurposeId ?? null, tokenCount: conversation ? conversation.tokenCount : 0, abortConversationTemp: state.abortConversationTemp, diff --git a/src/apps/chat/components/layout-drawer/useChatDrawerRenderItems.tsx b/src/apps/chat/components/layout-drawer/useChatDrawerRenderItems.tsx index 64fe22548..f61d8881e 100644 --- a/src/apps/chat/components/layout-drawer/useChatDrawerRenderItems.tsx +++ b/src/apps/chat/components/layout-drawer/useChatDrawerRenderItems.tsx @@ -167,7 +167,7 @@ export function useChatDrawerRenderItems( : null, updatedAt: _c.updated || _c.created || 0, messageCount: _c.messages.length, - beingGenerated: !!_c.abortController, // FIXME: when the AbortController is moved at the message level, derive the state in the conv + beingGenerated: !!_c._abortController, // FIXME: when the AbortController is moved at the message level, derive the state in the conv systemPurposeId: _c.systemPurposeId, searchFrequency, }; diff --git a/src/common/stores/chat/chat.conversation.ts b/src/common/stores/chat/chat.conversation.ts index 9515620aa..cf65261f6 100644 --- a/src/common/stores/chat/chat.conversation.ts +++ b/src/common/stores/chat/chat.conversation.ts @@ -29,7 +29,7 @@ export interface DConversation { // Not persisted, used while in-memory, or temporarily by the UI // TODO: @deprecated - shouls not be in here - it's actually a per-message/operation thing - abortController: AbortController | null; + _abortController: AbortController | null; // future additions: // draftUserMessage?: { text: string; attachments: any[] }; @@ -61,7 +61,7 @@ export function createDConversation(systemPurposeId?: SystemPurposeId): DConvers created: Date.now(), updated: Date.now(), - abortController: null, + _abortController: null, }; } @@ -95,7 +95,7 @@ export function duplicateCConversation(conversation: DConversation, lastMessageI created: conversation.created, updated: Date.now(), - abortController: null, + _abortController: null, }; } diff --git a/src/common/stores/chat/store-chats.ts b/src/common/stores/chat/store-chats.ts index 706e44f2b..04396ad46 100644 --- a/src/common/stores/chat/store-chats.ts +++ b/src/common/stores/chat/store-chats.ts @@ -31,7 +31,7 @@ export interface ChatActions { deleteConversations: (cIds: DConversationId[], newConversationPersonaId?: SystemPurposeId) => DConversationId; // within a conversation - setAbortController: (cId: DConversationId, abortController: AbortController | null) => void; + setAbortController: (cId: DConversationId, _abortController: AbortController | null) => void; abortConversationTemp: (cId: DConversationId) => void; historyReplace: (cId: DConversationId, messages: DMessage[]) => void; historyTruncateToIncluded: (cId: DConversationId, mId: DMessageId, offset: number) => void; @@ -79,7 +79,7 @@ export const useChatStore = create()(devtools( // if there's a clash, abort the former conversation, and optionally change the ID const existing = conversations.find(_c => _c.id === conversation.id); if (existing) { - existing?.abortController?.abort(); + existing?._abortController?.abort(); if (preventClash) { conversation.id = agiUuid('chat-dconversation'); console.warn('Conversation ID clash, changing ID to', conversation.id); @@ -117,7 +117,7 @@ export const useChatStore = create()(devtools( const cIndex = conversationIds.length > 0 ? conversations.findIndex(_c => _c.id === conversationIds[0]) : -1; // abort all pending requests - conversationIds.forEach(conversationId => conversations.find(_c => _c.id === conversationId)?.abortController?.abort()); + conversationIds.forEach(conversationId => conversations.find(_c => _c.id === conversationId)?._abortController?.abort()); // remove from the list const newConversations = conversations.filter(_c => !conversationIds.includes(_c.id)); @@ -149,24 +149,24 @@ export const useChatStore = create()(devtools( ), })), - setAbortController: (conversationId: DConversationId, abortController: AbortController | null) => + setAbortController: (conversationId: DConversationId, _abortController: AbortController | null) => _get()._editConversation(conversationId, () => ({ - abortController: abortController, + _abortController: _abortController, })), abortConversationTemp: (conversationId: DConversationId) => _get()._editConversation(conversationId, conversation => { - conversation.abortController?.abort(); + conversation._abortController?.abort(); return { - abortController: null, + _abortController: null, }; }), historyReplace: (conversationId: DConversationId, newMessages: DMessage[]) => _get()._editConversation(conversationId, conversation => { - conversation.abortController?.abort(); + conversation._abortController?.abort(); return { messages: newMessages, ...(!!newMessages.length ? {} : { @@ -174,7 +174,7 @@ export const useChatStore = create()(devtools( }), tokenCount: updateMessagesTokenCounts(newMessages, false, 'historyReplace'), updated: Date.now(), - abortController: null, + _abortController: null, }; }), @@ -184,7 +184,7 @@ export const useChatStore = create()(devtools( if (messageIndex < 0 || messageIndex + 1 + offset >= conversation.messages.length) return {}; - conversation.abortController?.abort(); + conversation._abortController?.abort(); const truncatedMessages = conversation.messages.slice(0, Math.max(0, messageIndex + 1 + offset)); @@ -192,7 +192,7 @@ export const useChatStore = create()(devtools( messages: truncatedMessages, tokenCount: updateMessagesTokenCounts(truncatedMessages, false, 'historyTruncateToIncluded'), updated: Date.now(), - abortController: null, + _abortController: null, }; }), @@ -362,7 +362,8 @@ export const useChatStore = create()(devtools( partialize: (state) => ({ ...state, conversations: state.conversations.map((conversation: DConversation) => { - const { abortController, ...rest } = conversation; + // remove the converation AbortController (current data structure version) + const { _abortController, ...rest } = conversation; return rest; }), }), @@ -374,8 +375,9 @@ export const useChatStore = create()(devtools( // fixup conversations for (const conversation of (state.conversations || [])) { // re-add transient properties - conversation.abortController = null; - // fixup messages + conversation._abortController = null; + + // fixup .messages[] for (const message of conversation.messages) { // reset transient properties delete message.pendingIncomplete; diff --git a/src/modules/trade/trade.client.ts b/src/modules/trade/trade.client.ts index a30edbd36..82a21b493 100644 --- a/src/modules/trade/trade.client.ts +++ b/src/modules/trade/trade.client.ts @@ -122,7 +122,7 @@ export function createDConversationFromJsonV1(part: ExportedChatJsonV1 & { token created: part.created || Date.now(), updated: part.updated || Date.now(), // add these back - these fields are not exported - abortController: null, + _abortController: null, }); } diff --git a/src/modules/trade/trade.types.ts b/src/modules/trade/trade.types.ts index fc64b268d..4bbec742c 100644 --- a/src/modules/trade/trade.types.ts +++ b/src/modules/trade/trade.types.ts @@ -94,6 +94,6 @@ export function convertDConversation_V3_V4(conversation: (ImportDConversationV3 ...rest, messages: messages.map(convertDMessageV3_to_V4), systemPurposeId: systemPurposeId as any, - abortController: null, + _abortController: null, }; }