The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(studio): improve ai assistant error feedback (#41132)
Kalleby Santos9792deb109b8
diff --git a/apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsx b/apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsxindex ba25895e558..191c52a3da8 100644--- a/apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsx+++ b/apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsx@@ -2,7 +2,7 @@ import type { UIMessage as MessageType } from '@ai-sdk/react'import { useChat } from '@ai-sdk/react'import { lastAssistantMessageIsCompleteWithToolCalls } from 'ai'import { AnimatePresence, motion } from 'framer-motion'-import { Eraser, Info, Pencil, X } from 'lucide-react'+import { Eraser, Pencil, X } from 'lucide-react'import { useRouter } from 'next/router'import { useCallback, useEffect, useMemo, useRef, useState } from 'react'@@ -40,6 +40,8 @@ import {ConversationScrollButton,} from './elements/Conversation'import { Message } from './Message'+import AlertError from '../AlertError'+import { ASSISTANT_ERRORS } from './AiAssistant.constants'interface AIAssistantProps {initialMessages?: MessageType[] | undefined@@ -407,57 +409,53 @@ export const AIAssistant = ({ className }: AIAssistantProps) => {<ConversationContent className="w-full px-7 py-8 mb-10">{renderedMessages}{error && (- <div className="border rounded-md px-2 py-2 flex items-center justify-between gap-x-4">- <div className="flex items-start gap-2 text-foreground-light text-sm">- <div>- <Info size={16} className="mt-0.5" />- </div>- <div>- {isContextExceededError ? (- <p>- This conversation has become too long for the Assistant to process. Please- start a new chat to continue.- </p>- ) : (- <p>- Sorry, I'm having trouble responding right now. If the error persists- while retrying, you may try creating a new chat and try again.- </p>- )}- </div>- </div>- <div className="flex items-center gap-x-2">- {isContextExceededError ? (- <Button- type="default"- size="tiny"- onClick={() => snap.newChat()}- className="text-xs"- >- New chat- </Button>- ) : (- <>- <Button- type="default"- size="tiny"- onClick={() => regenerate()}- className="text-xs"- >- Retry- </Button>- <ButtonTooltip- type="default"- size="tiny"- onClick={handleClearMessages}- className="w-7 h-7"- icon={<Eraser />}- tooltip={{ content: { side: 'bottom', text: 'Clear messages' } }}- />- </>- )}- </div>- </div>+ <>+ <AlertError+ error={+ isContextExceededError+ ? ASSISTANT_ERRORS['context-exceeded']+ : IS_PLATFORM+ ? ASSISTANT_ERRORS['default']+ : error+ }+ showErrorPrefix={false}+ showInstructions={false}+ subject="Sorry, I'm having trouble responding right now."+ additionalActions={+ <div className="flex items-center gap-x-2 mr-auto">+ {isContextExceededError ? (+ <Button+ type="default"+ size="tiny"+ onClick={() => snap.newChat()}+ className="text-xs"+ >+ New chat+ </Button>+ ) : (+ <>+ <Button+ type="default"+ size="tiny"+ onClick={() => regenerate()}+ className="text-xs"+ >+ Retry+ </Button>+ <ButtonTooltip+ type="default"+ size="tiny"+ onClick={handleClearMessages}+ className="w-7 h-7"+ icon={<Eraser />}+ tooltip={{ content: { side: 'bottom', text: 'Clear messages' } }}+ />+ </>+ )}+ </div>+ }+ />+ </>)}{isChatLoading && (<motion.spandiff --git a/apps/studio/components/ui/AIAssistantPanel/AiAssistant.constants.ts b/apps/studio/components/ui/AIAssistantPanel/AiAssistant.constants.tsindex f23cfe3e107..8e2738acdae 100644--- a/apps/studio/components/ui/AIAssistantPanel/AiAssistant.constants.ts+++ b/apps/studio/components/ui/AIAssistantPanel/AiAssistant.constants.ts@@ -1,5 +1,15 @@import { SupportedAssistantEntities } from './AIAssistant.types'+export const ASSISTANT_ERRORS = {+ 'context-exceeded': {+ message:+ 'This conversation has become too long for the Assistant to process. Please start a new chat to continue.',+ },+ default: {+ message: 'If the error persists while retrying, you may try creating a new chat and try again.',+ },+}+export const ASSISTANT_SUPPORT_ENTITIES: {id: SupportedAssistantEntitieslabel: stringdiff --git a/apps/studio/components/ui/AlertError.tsx b/apps/studio/components/ui/AlertError.tsxindex 3e472f13f88..74c6dc7c16d 100644--- a/apps/studio/components/ui/AlertError.tsx+++ b/apps/studio/components/ui/AlertError.tsx@@ -14,6 +14,8 @@ export interface AlertErrorProps {layout?: 'vertical' | 'horizontal'className?: stringshowIcon?: boolean+ showInstructions?: boolean+ showErrorPrefix?: booleanadditionalActions?: React.ReactNode}@@ -50,6 +52,8 @@ export const AlertError = ({className,showIcon = true,layout = 'horizontal',+ showInstructions = true,+ showErrorPrefix = true,children,additionalActions,}: PropsWithChildren<AlertErrorProps>) => {@@ -79,11 +83,18 @@ export const AlertError = ({title={subject}description={<>- {error?.message && <p>Error: {formattedErrorMessage}</p>}- <p>- Try refreshing your browser. If the issue persists for more than a few minutes, please- reach out to us via support.- </p>+ {error?.message && (+ <p>+ {showErrorPrefix && 'Error: '}+ {formattedErrorMessage}+ </p>+ )}+ {showInstructions && (+ <p>+ Try refreshing your browser, but if the issue persists for more than a few minutes,+ please reach out to us via support.+ </p>+ )}{children}</>}