diff --git a/apps/web/components/Contexts/AI/AIChatBotContext.tsx b/apps/web/components/Contexts/AI/AIChatBotContext.tsx index b912bd1a..dbe2e510 100644 --- a/apps/web/components/Contexts/AI/AIChatBotContext.tsx +++ b/apps/web/components/Contexts/AI/AIChatBotContext.tsx @@ -5,12 +5,18 @@ export const AIChatBotContext = createContext(null) as any; export const AIChatBotDispatchContext = createContext(null) as any; export type AIChatBotStateTypes = { - messages: AIMessage[], isModalOpen: boolean, aichat_uuid: string, isWaitingForResponse: boolean, chatInputValue: string + error: AIError +} + +type AIError = { + isError: boolean + status: number + error_message: string } function AIChatBotProvider({ children }: { children: React.ReactNode }) { @@ -20,7 +26,8 @@ function AIChatBotProvider({ children }: { children: React.ReactNode }) { isModalOpen: false, aichat_uuid: null, isWaitingForResponse: false, - chatInputValue: '' + chatInputValue: '', + error: { isError: false, status: 0, error_message: ' ' } as AIError } ); return ( @@ -60,6 +67,8 @@ function aiChatBotReducer(state: any, action: any) { return { ...state, isWaitingForResponse: false }; case 'setChatInputValue': return { ...state, chatInputValue: action.payload }; + case 'setError': + return { ...state, error: action.payload }; default: throw new Error(`Unhandled action type: ${action.type}`) diff --git a/apps/web/components/Contexts/AI/AIEditorContext.tsx b/apps/web/components/Contexts/AI/AIEditorContext.tsx index 49be94b3..efd9be04 100644 --- a/apps/web/components/Contexts/AI/AIEditorContext.tsx +++ b/apps/web/components/Contexts/AI/AIEditorContext.tsx @@ -14,6 +14,13 @@ export type AIEditorStateTypes = { chatInputValue: string, selectedTool: 'Writer' | 'ContinueWriting' | 'MakeLonger' | 'GenerateQuiz' | 'Translate' isUserInputEnabled: boolean + error: AIError +} + +type AIError = { + isError: boolean + status: number + error_message: string } function AIEditorProvider({ children }: { children: React.ReactNode }) { @@ -26,7 +33,8 @@ function AIEditorProvider({ children }: { children: React.ReactNode }) { isWaitingForResponse: false, chatInputValue: '', selectedTool: 'Writer', - isUserInputEnabled: true + isUserInputEnabled: true, + error: { isError: false, status: 0, error_message: ' ' } as AIError } ); return ( @@ -74,7 +82,9 @@ function aIEditorReducer(state: any, action: any) { return { ...state, isFeedbackModalOpen: false }; case 'setIsUserInputEnabled': return { ...state, isUserInputEnabled: action.payload }; - + case 'setError': + return { ...state, error: action.payload }; + default: throw new Error(`Unhandled action type: ${action.type}`) diff --git a/apps/web/components/Objects/Activities/AI/AIActivityAsk.tsx b/apps/web/components/Objects/Activities/AI/AIActivityAsk.tsx index 884e0435..a1fcff3d 100644 --- a/apps/web/components/Objects/Activities/AI/AIActivityAsk.tsx +++ b/apps/web/components/Objects/Activities/AI/AIActivityAsk.tsx @@ -1,6 +1,6 @@ import { useSession } from '@components/Contexts/SessionContext' import { sendActivityAIChatMessage, startActivityAIChatSession } from '@services/ai/ai'; -import { BadgeInfo, NotebookTabs } from 'lucide-react'; +import { AlertTriangle, BadgeInfo, NotebookTabs } from 'lucide-react'; import Avvvatars from 'avvvatars-react'; import { motion, AnimatePresence } from 'framer-motion'; import { FlaskConical, Keyboard, MessageCircle, MessageSquareIcon, Sparkle, Sparkles, X } from 'lucide-react' @@ -34,7 +34,7 @@ function AIActivityAsk(props: AIActivityAskProps) { return ( <> - {isButtonAvailable && ( + {isButtonAvailable && (
Place your cursor at the end of a sentence to continue writing
Select text to make longer
Translate selected text to
@@ -416,8 +432,7 @@ const AiEditorActionScreen = ({ handleOperation }: { handleOperation: any }) =>