Refactor useAgentChat hook and remove agentChatContextState
- Simplified useAgentChat hook by removing the agentChatContextState and related context handling. - Deleted agentChatContextState file to streamline state management in the AI chat module.
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
|
||||
import { useAgentChatContextOrThrow } from '@/ai/hooks/useAgentChatContextOrThrow';
|
||||
import {
|
||||
type AIChatObjectMetadataAndRecordContext,
|
||||
agentChatContextState,
|
||||
} from '@/ai/states/agentChatContextState';
|
||||
import { agentChatSelectedFilesState } from '@/ai/states/agentChatSelectedFilesState';
|
||||
import { currentAIChatThreadState } from '@/ai/states/currentAIChatThreadState';
|
||||
import { useChat } from '@ai-sdk/react';
|
||||
@@ -15,10 +11,6 @@ export const useAgentChat = (agentId: string) => {
|
||||
|
||||
const agentChatSelectedFiles = useRecoilValue(agentChatSelectedFilesState);
|
||||
|
||||
const [agentChatContext, setAgentChatContext] = useRecoilState(
|
||||
agentChatContextState,
|
||||
);
|
||||
|
||||
const currentAIChatThread = useRecoilValue(currentAIChatThreadState);
|
||||
|
||||
const [agentChatInput, setAgentChatInput] =
|
||||
@@ -38,18 +30,10 @@ export const useAgentChat = (agentId: string) => {
|
||||
isStreaming ||
|
||||
agentChatSelectedFiles.length > 0;
|
||||
|
||||
const handleSetContext = async (
|
||||
items: Array<AIChatObjectMetadataAndRecordContext>,
|
||||
) => {
|
||||
setAgentChatContext(items);
|
||||
};
|
||||
|
||||
return {
|
||||
handleInputChange: (value: string) => setAgentChatInput(value),
|
||||
messages,
|
||||
input: agentChatInput,
|
||||
context: agentChatContext,
|
||||
handleSetContext,
|
||||
isLoading,
|
||||
scrollWrapperId,
|
||||
isStreaming,
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import { atom } from 'recoil';
|
||||
|
||||
export type AIChatObjectMetadataAndRecordContext = {
|
||||
type: 'objectMetadataId' | 'recordId';
|
||||
id: string;
|
||||
};
|
||||
|
||||
export const agentChatContextState = atom<
|
||||
Array<AIChatObjectMetadataAndRecordContext>
|
||||
>({
|
||||
key: 'ai/agentChatContextState',
|
||||
default: [],
|
||||
});
|
||||
Reference in New Issue
Block a user