mirror of
https://github.com/enricoros/big-AGI.git
synced 2026-05-10 21:50:14 -07:00
Conversation: rename _abortController (and don't export/import it)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ConversationsStore>()(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<ConversationsStore>()(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<ConversationsStore>()(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<ConversationsStore>()(devtools(
|
||||
}),
|
||||
tokenCount: updateMessagesTokenCounts(newMessages, false, 'historyReplace'),
|
||||
updated: Date.now(),
|
||||
abortController: null,
|
||||
_abortController: null,
|
||||
};
|
||||
}),
|
||||
|
||||
@@ -184,7 +184,7 @@ export const useChatStore = create<ConversationsStore>()(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<ConversationsStore>()(devtools(
|
||||
messages: truncatedMessages,
|
||||
tokenCount: updateMessagesTokenCounts(truncatedMessages, false, 'historyTruncateToIncluded'),
|
||||
updated: Date.now(),
|
||||
abortController: null,
|
||||
_abortController: null,
|
||||
};
|
||||
}),
|
||||
|
||||
@@ -362,7 +362,8 @@ export const useChatStore = create<ConversationsStore>()(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<ConversationsStore>()(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;
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user