mirror of
https://github.com/tinyhumansai/openhuman.git
synced 2026-07-27 21:08:00 +00:00
refactor: streamline message handling in Conversations component
- Reorganized imports for better clarity and consistency. - Removed unnecessary parameter from `handleSendMessageWeb` function to simplify its signature. - Updated error handling in `sendMessage` thunk to enhance readability by consolidating the dispatch call for error responses.
This commit is contained in:
@@ -21,15 +21,14 @@ import {
|
||||
import {
|
||||
chatCancel,
|
||||
chatSend,
|
||||
subscribeChatEvents,
|
||||
useRustChat,
|
||||
type ChatToolCallEvent,
|
||||
type ChatToolResultEvent,
|
||||
subscribeChatEvents,
|
||||
useRustChat,
|
||||
} from '../services/chatService';
|
||||
import { store } from '../store';
|
||||
import { useAppDispatch, useAppSelector } from '../store/hooks';
|
||||
import type { NotionPageSummary, NotionSummary, NotionUserProfile } from '../store/notionSlice';
|
||||
import { store } from '../store';
|
||||
import { BACKEND_URL } from '../utils/config';
|
||||
import {
|
||||
addInferenceResponse,
|
||||
addMessageLocal,
|
||||
@@ -46,6 +45,7 @@ import {
|
||||
setSelectedThread,
|
||||
} from '../store/threadSlice';
|
||||
import type { ThreadMessage } from '../types/thread';
|
||||
import { BACKEND_URL } from '../utils/config';
|
||||
|
||||
const MIN_PANEL_WIDTH = 200;
|
||||
const MAX_PANEL_WIDTH = 480;
|
||||
@@ -406,7 +406,6 @@ const Conversations = () => {
|
||||
const handleSendMessageWeb = async (
|
||||
sendingThreadId: string,
|
||||
trimmed: string,
|
||||
userMessage: ThreadMessage,
|
||||
historySnapshot: ThreadMessage[]
|
||||
) => {
|
||||
// Safety-net timeout: force-clear loading states if everything hangs
|
||||
@@ -729,7 +728,7 @@ const Conversations = () => {
|
||||
}
|
||||
} else {
|
||||
// ── Web fallback (existing orchestration logic) ───────────────────────
|
||||
await handleSendMessageWeb(sendingThreadId, trimmed, userMessage, historySnapshot);
|
||||
await handleSendMessageWeb(sendingThreadId, trimmed, historySnapshot);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ export const sendMessage = createAsyncThunk(
|
||||
'thread/sendMessage',
|
||||
async (
|
||||
{ threadId, message }: { threadId: string; message: string },
|
||||
{ dispatch, getState, rejectWithValue }
|
||||
{ dispatch, rejectWithValue }
|
||||
) => {
|
||||
// 1. Add user message locally immediately (optimistic update)
|
||||
const userMessage: ThreadMessage = {
|
||||
@@ -116,10 +116,7 @@ export const sendMessage = createAsyncThunk(
|
||||
} catch (error) {
|
||||
// Add an error message as an agent response so the conversation flow continues
|
||||
dispatch(
|
||||
addInferenceResponse({
|
||||
content: 'Something went wrong — please try again.',
|
||||
threadId,
|
||||
})
|
||||
addInferenceResponse({ content: 'Something went wrong — please try again.', threadId })
|
||||
);
|
||||
|
||||
const msg =
|
||||
|
||||
Reference in New Issue
Block a user