mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
wip: when creating a project fails, check for auth errors with the api call to feed back to the user what/why we had an issue
This commit is contained in:
1 parent
f9f72e6a50
commit
c9073bb4bd
3 files changed
+73
-7
No files matched your search
@@ -14,7 +14,7 @@ const ToastViewport = React.forwardRef<
|
||||
<ToastPrimitives.Viewport
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
|
||||
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[480px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -41,7 +41,7 @@ const toastVariants = cva(
|
||||
const Toast = React.forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
|
||||
VariantProps<typeof toastVariants>
|
||||
VariantProps<typeof toastVariants>
|
||||
>(({ className, variant, ...props }, ref) => {
|
||||
return (
|
||||
<ToastPrimitives.Root
|
||||
|
||||
@@ -256,6 +256,11 @@ const resources = {
|
||||
recentlyUsed: 'Recently Used',
|
||||
errorLoadingModels: 'Error Loading Models',
|
||||
|
||||
// API Authentication Errors
|
||||
apiAuthenticationFailed: 'API Authentication Failed',
|
||||
invalidApiKey: 'Invalid API key for {{provider}}. Please check your API key in Settings.',
|
||||
checkApiKeySettings: 'Check API Key Settings',
|
||||
|
||||
// Context and Cost
|
||||
contextUsage: 'Context usage: {{tokens}} / {{total}} tokens ({{percentage}}%)',
|
||||
totalCostSession: 'Total cost for this chat session',
|
||||
@@ -552,6 +557,11 @@ const resources = {
|
||||
recentlyUsed: 'Usados Recentemente',
|
||||
errorLoadingModels: 'Erro ao Carregar Modelos',
|
||||
|
||||
// API Authentication Errors
|
||||
apiAuthenticationFailed: 'Falha na Autenticação da API',
|
||||
invalidApiKey: 'Chave de API inválida para {{provider}}. Verifique sua chave de API nas Configurações.',
|
||||
checkApiKeySettings: 'Verificar Configurações da Chave de API',
|
||||
|
||||
// Context and Cost
|
||||
contextUsage: 'Uso de contexto: {{tokens}} / {{total}} tokens ({{percentage}}%)',
|
||||
totalCostSession: 'Custo total para esta sessão de chat',
|
||||
@@ -848,6 +858,11 @@ const resources = {
|
||||
recentlyUsed: '最近使用',
|
||||
errorLoadingModels: '加载模型时出错',
|
||||
|
||||
// API Authentication Errors
|
||||
apiAuthenticationFailed: 'API身份验证失败',
|
||||
invalidApiKey: '{{provider}}的API密钥无效。请在设置中检查您的API密钥。',
|
||||
checkApiKeySettings: '检查API密钥设置',
|
||||
|
||||
// Context and Cost
|
||||
contextUsage: '上下文使用:{{tokens}} / {{total}} 令牌 ({{percentage}}%)',
|
||||
totalCostSession: '此聊天会话的总费用',
|
||||
@@ -1144,6 +1159,11 @@ const resources = {
|
||||
recentlyUsed: 'An yi amfani da su kwanan nan',
|
||||
errorLoadingModels: 'Kuskure wajen Lodin Samfura',
|
||||
|
||||
// API Authentication Errors
|
||||
apiAuthenticationFailed: 'Gazawar Tabbatarwar API',
|
||||
invalidApiKey: 'Maɓallin API na {{provider}} ba daidai ba ne. Da fatan za a duba maɓallin API a cikin Saitunan.',
|
||||
checkApiKeySettings: 'Duba Saitunan Maɓallin API',
|
||||
|
||||
// Context and Cost
|
||||
contextUsage: 'Amfanin mahallin: {{tokens}} / {{total}} alamomi ({{percentage}}%)',
|
||||
totalCostSession: 'Jimlar farashi don wannan zaman hira',
|
||||
|
||||
+51
-5
@@ -7,15 +7,18 @@ import { useFS } from '@/hooks/useFS';
|
||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useAISettings } from '@/hooks/useAISettings';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { AppLayout } from '@/components/AppLayout';
|
||||
import { OnboardingDialog } from '@/components/OnboardingDialog';
|
||||
import { DotAI } from '@/lib/DotAI';
|
||||
import { parseProviderModel } from '@/lib/parseProviderModel';
|
||||
import type { AIMessage } from '@/lib/SessionManager';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { ModelSelector } from '@/components/ModelSelector';
|
||||
import { FileAttachment } from '@/components/ui/file-attachment';
|
||||
import { ToastAction } from '@/components/ui/toast';
|
||||
import { Plus } from 'lucide-react';
|
||||
import { useSeoMeta } from '@unhead/react';
|
||||
|
||||
@@ -30,6 +33,7 @@ export default function Index() {
|
||||
const { fs } = useFS();
|
||||
const { generateProjectId, isLoading: isGeneratingId } = useAIProjectId();
|
||||
const { settings, addRecentlyUsedModel } = useAISettings();
|
||||
const { toast } = useToast();
|
||||
const [providerModel, setProviderModel] = useState(() => {
|
||||
// Initialize with first recently used model if available, otherwise empty
|
||||
return settings.recentlyUsedModels?.[0] || '';
|
||||
@@ -41,6 +45,48 @@ export default function Index() {
|
||||
// Check if any providers are configured
|
||||
const hasProvidersConfigured = settings.providers.length > 0;
|
||||
|
||||
// Check for API key failures and show appropriate toast
|
||||
const checkForKeyFailure = (error: unknown): boolean => {
|
||||
if (!(error instanceof Error)) return false;
|
||||
|
||||
const message = error.message.toLowerCase();
|
||||
const isAuthError = (
|
||||
message.includes('401') ||
|
||||
message.includes('unauthorized') ||
|
||||
message.includes('no auth credentials') ||
|
||||
message.includes('invalid api key') ||
|
||||
message.includes('authentication failed')
|
||||
);
|
||||
|
||||
if (isAuthError) {
|
||||
// Get provider name inline
|
||||
let providerName = 'Provider';
|
||||
try {
|
||||
const { provider } = parseProviderModel(providerModel, settings.providers);
|
||||
providerName = provider.charAt(0).toUpperCase() + provider.slice(1);
|
||||
} catch {
|
||||
// Keep default 'Provider'
|
||||
}
|
||||
|
||||
toast({
|
||||
title: t('apiAuthenticationFailed'),
|
||||
description: t('invalidApiKey', { provider: providerName }),
|
||||
variant: 'destructive',
|
||||
action: (
|
||||
<ToastAction
|
||||
altText={t('checkApiKeySettings')}
|
||||
onClick={() => navigate('/settings/ai')}
|
||||
>
|
||||
{t('checkApiKeySettings')}
|
||||
</ToastAction>
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
return isAuthError;
|
||||
};
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (!providerModel && settings.recentlyUsedModels?.length) {
|
||||
setProviderModel(settings.recentlyUsedModels[0]);
|
||||
@@ -185,6 +231,7 @@ export default function Index() {
|
||||
navigate(`/project/${project.id}?${searchParams.toString()}`);
|
||||
} catch (error) {
|
||||
console.error('Failed to create project:', error);
|
||||
checkForKeyFailure(error);
|
||||
} finally {
|
||||
setIsCreating(false);
|
||||
}
|
||||
@@ -209,9 +256,8 @@ export default function Index() {
|
||||
<div className="mb-8 md:mb-12">
|
||||
{/* Chat Input Container - matching the ChatPane style */}
|
||||
<div
|
||||
className={`relative rounded-2xl border border-input bg-background shadow-sm focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 transition-all ${
|
||||
isDragOver ? 'border-primary bg-primary/5 ring-2 ring-primary/20' : ''
|
||||
}`}
|
||||
className={`relative rounded-2xl border border-input bg-background shadow-sm focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 transition-all ${isDragOver ? 'border-primary bg-primary/5 ring-2 ring-primary/20' : ''
|
||||
}`}
|
||||
onDragEnter={handleDragEnter}
|
||||
onDragOver={handleDragOver}
|
||||
onDragLeave={handleDragLeave}
|
||||
@@ -222,8 +268,8 @@ export default function Index() {
|
||||
!hasProvidersConfigured
|
||||
? t('examplePrompt')
|
||||
: !providerModel.trim()
|
||||
? t('selectModelToDescribe')
|
||||
: t('examplePrompt')
|
||||
? t('selectModelToDescribe')
|
||||
: t('examplePrompt')
|
||||
}
|
||||
value={prompt}
|
||||
onChange={handlePromptChange}
|
||||
|
||||
Reference in new issue
Block a user