Skip to content
Merged
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
21 changes: 15 additions & 6 deletions components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { VisibilityType } from './visibility-selector';
import { useArtifactSelector } from '@/hooks/use-artifact';
import { unstable_serialize } from 'swr/infinite';
import { getChatHistoryPaginationKey } from './sidebar-history';
import { toast } from './toast';
import type { Session } from 'next-auth';
import { useSearchParams } from 'next/navigation';
import { useChatVisibility } from '@/hooks/use-chat-visibility';
Expand Down Expand Up @@ -62,8 +63,7 @@ export function Chat({

const [input, setInput] = useState<string>('');
const [usage, setUsage] = useState<AppUsage | undefined>(initialLastContext);
const [showErrorAlert, setShowErrorAlert] = useState(false);
const [errorMessage, setErrorMessage] = useState('');
const [showCreditCardAlert, setShowCreditCardAlert] = useState(false);
const [currentModelId, setCurrentModelId] = useState(initialChatModel);
const currentModelIdRef = useRef(currentModelId);

Expand Down Expand Up @@ -108,8 +108,17 @@ export function Chat({
},
onError: (error) => {
if (error instanceof ChatSDKError) {
setErrorMessage(error.message);
setShowErrorAlert(true);
// Check if it's a credit card error
if (
error.message?.includes('AI Gateway requires a valid credit card')
) {
setShowCreditCardAlert(true);
} else {
toast({
type: 'error',
description: error.message,
});
}
}
},
});
Expand Down Expand Up @@ -209,8 +218,8 @@ export function Chat({
/>

<AlertDialog
open={showErrorAlert}
onOpenChange={setShowErrorAlert}
open={showCreditCardAlert}
onOpenChange={setShowCreditCardAlert}
>
<AlertDialogContent>
<AlertDialogHeader>
Expand Down
Loading