Skip to content

Commit

Permalink
🐛 fix: fix images not go in to chat context (#4361)
Browse files Browse the repository at this point in the history
* 💡 chore: add jsdoc

* 🐛 fix: fix the image not in ai chat message

* 💡 chore: add jsdoc

* 🐛 fix: fix
  • Loading branch information
arvinxx authored Oct 13, 2024
1 parent ed7e4e3 commit f17ab49
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/features/Conversation/components/SkeletonList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const SkeletonList = memo<SkeletonListProps>(({ mobile }) => {
const { cx, styles } = useStyles();

return (
<Flexbox gap={24} padding={mobile ? 8 : 12} style={{ marginTop: 24 + (mobile ? 0 : 64) }}>
<Flexbox gap={24} padding={mobile ? 8 : 12} style={{ marginTop: 24 }}>
<Skeleton
active
avatar={{ size: mobile ? 32 : 40 }}
Expand Down
45 changes: 25 additions & 20 deletions src/store/chat/slices/aiChat/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { setNamespace } from '@/utils/storeDebug';
import { chatSelectors, topicSelectors } from '../../selectors';
import { ChatRAGAction, chatRag } from './actions/rag';

const n = setNamespace('m');
const n = setNamespace('ai');

export interface SendMessageParams {
message: string;
Expand All @@ -47,33 +47,38 @@ interface ProcessMessageParams {
}

export interface ChatAIChatAction extends ChatRAGAction {
// create
/**
* Sends a new message to the AI chat system
*/
sendMessage: (params: SendMessageParams) => Promise<void>;
/**
* regenerate message
* trace enabled
* @param id
* Regenerates a specific message in the chat
*/
regenerateMessage: (id: string) => Promise<void>;

// delete
/**
* Deletes an existing message and generates a new one in its place
*/
delAndRegenerateMessage: (id: string) => Promise<void>;
/**
* Interrupts the ongoing ai message generation process
*/
stopGenerateMessage: () => void;

// ========= ↓ Internal Method ↓ ========== //
// ========================================== //
// ========================================== //

/**
* core process of the AI message (include preprocess and postprocess)
* Executes the core processing logic for AI messages
* including preprocessing and postprocessing steps
*/
internal_coreProcessMessage: (
messages: ChatMessage[],
parentId: string,
params?: ProcessMessageParams,
) => Promise<void>;
/**
* the method to fetch the AI message
* Retrieves an AI-generated chat message from the backend service
*/
internal_fetchAIChatMessage: (
messages: ChatMessage[],
Expand All @@ -83,19 +88,20 @@ export interface ChatAIChatAction extends ChatRAGAction {
isFunctionCall: boolean;
traceId?: string;
}>;

/**
* Resends a specific message, optionally using a trace ID for tracking
*/
internal_resendMessage: (id: string, traceId?: string) => Promise<void>;

/**
* method to toggle ai message generating loading
* Toggles the loading state for AI message generation, managing the UI feedback
*/
internal_toggleChatLoading: (
loading: boolean,
id?: string,
action?: string,
) => AbortController | undefined;
/**
* method to toggle the tool calling loading state
* Controls the streaming state of tool calling processes, updating the UI accordingly
*/
internal_toggleToolCallingStreaming: (id: string, streaming: boolean[] | undefined) => void;
}
Expand Down Expand Up @@ -139,7 +145,7 @@ export const chatAiChat: StateCreator<
// if message is empty or no files, then stop
if (!message && !hasFile) return;

set({ isCreatingMessage: true }, false, 'creatingMessage/start');
set({ isCreatingMessage: true }, false, n('creatingMessage/start'));

const newMessage: CreateMessageParams = {
content: message,
Expand Down Expand Up @@ -184,10 +190,7 @@ export const chatAiChat: StateCreator<
...get().messagesMap,
[messageMapKey(activeId, topicId)]: get().messagesMap[mapKey],
};
set({ messagesMap: newMaps }, false, 'internal_copyMessages');

// get().internal_dispatchMessage({ type: 'deleteMessage', id: tempMessageId });
get().internal_toggleMessageLoading(false, tempMessageId);
set({ messagesMap: newMaps }, false, n('moveMessagesToNewTopic'));

// make the topic loading
get().internal_updateTopicLoading(topicId, true);
Expand All @@ -199,9 +202,11 @@ export const chatAiChat: StateCreator<

const id = await get().internal_createMessage(newMessage, {
tempMessageId,
skipRefresh: !onlyAddUserMessage,
skipRefresh: !onlyAddUserMessage && newMessage.fileList?.length === 0,
});

if (tempMessageId) get().internal_toggleMessageLoading(false, tempMessageId);

// switch to the new topic if create the new topic
if (!!newTopicId) {
await get().switchTopic(newTopicId, true);
Expand All @@ -228,7 +233,7 @@ export const chatAiChat: StateCreator<
ragQuery: get().internal_shouldUseRAG() ? message : undefined,
});

set({ isCreatingMessage: false }, false, 'creatingMessage/stop');
set({ isCreatingMessage: false }, false, n('creatingMessage/stop'));

const summaryTitle = async () => {
// if autoCreateTopic is false, then stop
Expand Down
1 change: 1 addition & 0 deletions src/store/chat/slices/message/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ export const chatMessage: StateCreator<

const id = await messageService.createMessage(message);
if (!context?.skipRefresh) {
internal_toggleMessageLoading(true, tempId);
await refreshMessages();
}

Expand Down
2 changes: 1 addition & 1 deletion src/store/chat/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const preventLeavingFn = (e: BeforeUnloadEvent) => {
export const toggleBooleanList = (ids: string[], id: string, loading: boolean) => {
return produce(ids, (draft) => {
if (loading) {
draft.push(id);
if (!draft.includes(id)) draft.push(id);
} else {
const index = draft.indexOf(id);

Expand Down

0 comments on commit f17ab49

Please sign in to comment.