Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions frontend/__tests__/components/chat/chat-interface.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { Message } from "#/message";
import { SUGGESTIONS } from "#/utils/suggestions";
import { ChatInterface } from "#/components/features/chat/chat-interface";
import { useWsClient } from "#/context/ws-client-provider";
import { useOptimisticUserMessage } from "#/hooks/use-optimistic-user-message";
import { useOptimisticUserMessageStore } from "#/stores/optimistic-user-message-store";
import { useWSErrorMessage } from "#/hooks/use-ws-error-message";
import { useConfig } from "#/hooks/query/use-config";
import { useGetTrajectory } from "#/hooks/mutation/use-get-trajectory";
Expand All @@ -26,7 +26,7 @@ import { OpenHandsAction } from "#/types/core/actions";

// Mock the hooks
vi.mock("#/context/ws-client-provider");
vi.mock("#/hooks/use-optimistic-user-message");
vi.mock("#/stores/optimistic-user-message-store");
vi.mock("#/hooks/use-ws-error-message");
vi.mock("#/hooks/query/use-config");
vi.mock("#/hooks/mutation/use-get-trajectory");
Expand Down Expand Up @@ -109,7 +109,7 @@ describe("ChatInterface - Chat Suggestions", () => {
parsedEvents: [],
});
(
useOptimisticUserMessage as unknown as ReturnType<typeof vi.fn>
useOptimisticUserMessageStore as unknown as ReturnType<typeof vi.fn>
).mockReturnValue({
setOptimisticUserMessage: vi.fn(),
getOptimisticUserMessage: vi.fn(() => null),
Expand Down Expand Up @@ -203,7 +203,7 @@ describe("ChatInterface - Chat Suggestions", () => {

test("should hide chat suggestions when there is an optimistic user message", () => {
(
useOptimisticUserMessage as unknown as ReturnType<typeof vi.fn>
useOptimisticUserMessageStore as unknown as ReturnType<typeof vi.fn>
).mockReturnValue({
setOptimisticUserMessage: vi.fn(),
getOptimisticUserMessage: vi.fn(() => "Optimistic message"),
Expand Down Expand Up @@ -246,7 +246,7 @@ describe("ChatInterface - Empty state", () => {
parsedEvents: [],
});
(
useOptimisticUserMessage as unknown as ReturnType<typeof vi.fn>
useOptimisticUserMessageStore as unknown as ReturnType<typeof vi.fn>
).mockReturnValue({
setOptimisticUserMessage: vi.fn(),
getOptimisticUserMessage: vi.fn(() => null),
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/features/chat/chat-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useAgentStore } from "#/stores/agent-store";
import { ScrollToBottomButton } from "#/components/shared/buttons/scroll-to-bottom-button";
import { LoadingSpinner } from "#/components/shared/loading-spinner";
import { displayErrorToast } from "#/utils/custom-toast-handlers";
import { useOptimisticUserMessage } from "#/hooks/use-optimistic-user-message";
import { useOptimisticUserMessageStore } from "#/stores/optimistic-user-message-store";
import { useWSErrorMessage } from "#/hooks/use-ws-error-message";
import { ErrorMessageBanner } from "./error-message-banner";
import {
Expand All @@ -49,7 +49,7 @@ export function ChatInterface() {
const { getErrorMessage } = useWSErrorMessage();
const { send, isLoadingMessages, parsedEvents } = useWsClient();
const { setOptimisticUserMessage, getOptimisticUserMessage } =
useOptimisticUserMessage();
useOptimisticUserMessageStore();
const { t } = useTranslation();
const scrollRef = React.useRef<HTMLDivElement>(null);
const {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/features/chat/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "#/types/core/guards";
import { EventMessage } from "./event-message";
import { ChatMessage } from "./chat-message";
import { useOptimisticUserMessage } from "#/hooks/use-optimistic-user-message";
import { useOptimisticUserMessageStore } from "#/stores/optimistic-user-message-store";
import { LaunchMicroagentModal } from "./microagent/launch-microagent-modal";
import { useUserConversation } from "#/hooks/query/use-user-conversation";
import { useConversationId } from "#/hooks/use-conversation-id";
Expand Down Expand Up @@ -48,7 +48,7 @@ export const Messages: React.FC<MessagesProps> = React.memo(
isPending,
unsubscribeFromConversation,
} = useCreateConversationAndSubscribeMultiple();
const { getOptimisticUserMessage } = useOptimisticUserMessage();
const { getOptimisticUserMessage } = useOptimisticUserMessageStore();
const { conversationId } = useConversationId();
const { data: conversation } = useUserConversation(conversationId);

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/features/home/tasks/task-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SuggestedTask } from "#/utils/types";
import { useIsCreatingConversation } from "#/hooks/use-is-creating-conversation";
import { useCreateConversation } from "#/hooks/mutation/use-create-conversation";
import { TaskIssueNumber } from "./task-issue-number";
import { useOptimisticUserMessage } from "#/hooks/use-optimistic-user-message";
import { useOptimisticUserMessageStore } from "#/stores/optimistic-user-message-store";
import { cn } from "#/utils/utils";

const getTaskTypeMap = (
Expand All @@ -21,7 +21,7 @@ interface TaskCardProps {
}

export function TaskCard({ task }: TaskCardProps) {
const { setOptimisticUserMessage } = useOptimisticUserMessage();
const { setOptimisticUserMessage } = useOptimisticUserMessageStore();
const { mutate: createConversation } = useCreateConversation();
const isCreatingConversation = useIsCreatingConversation();
const { t } = useTranslation();
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/context/ws-client-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
isStatusUpdate,
isUserMessage,
} from "#/types/core/guards";
import { useOptimisticUserMessage } from "#/hooks/use-optimistic-user-message";
import { useOptimisticUserMessageStore } from "#/stores/optimistic-user-message-store";
import { useWSErrorMessage } from "#/hooks/use-ws-error-message";

export type WebSocketStatus = "CONNECTING" | "CONNECTED" | "DISCONNECTED";
Expand Down Expand Up @@ -131,7 +131,7 @@ export function WsClientProvider({
conversationId,
children,
}: React.PropsWithChildren<WsClientProviderProps>) {
const { removeOptimisticUserMessage } = useOptimisticUserMessage();
const { removeOptimisticUserMessage } = useOptimisticUserMessageStore();
const { setErrorMessage, removeErrorMessage } = useWSErrorMessage();
const queryClient = useQueryClient();
const sioRef = React.useRef<Socket | null>(null);
Expand Down
23 changes: 0 additions & 23 deletions frontend/src/hooks/use-optimistic-user-message.ts

This file was deleted.

36 changes: 36 additions & 0 deletions frontend/src/stores/optimistic-user-message-store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { create } from "zustand";

interface OptimisticUserMessageState {
optimisticUserMessage: string | null;
}

interface OptimisticUserMessageActions {
setOptimisticUserMessage: (message: string) => void;
getOptimisticUserMessage: () => string | null;
removeOptimisticUserMessage: () => void;
}

type OptimisticUserMessageStore = OptimisticUserMessageState &
OptimisticUserMessageActions;

const initialState: OptimisticUserMessageState = {
optimisticUserMessage: null,
};

export const useOptimisticUserMessageStore = create<OptimisticUserMessageStore>(
(set, get) => ({
...initialState,

setOptimisticUserMessage: (message: string) =>
set(() => ({
optimisticUserMessage: message,
})),

getOptimisticUserMessage: () => get().optimisticUserMessage,

removeOptimisticUserMessage: () =>
set(() => ({
optimisticUserMessage: null,
})),
}),
);
Loading