|
| 1 | +// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. ========= |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at |
| 5 | +// |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | +// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. ========= |
| 14 | + |
| 15 | +import { Button } from '@/components/ui/button'; |
| 16 | +import { TriangleAlert } from 'lucide-react'; |
| 17 | +import { useTranslation } from 'react-i18next'; |
| 18 | +import { useNavigate } from 'react-router-dom'; |
| 19 | + |
| 20 | +interface ModelErrorCardProps { |
| 21 | + content: string; |
| 22 | + errorCode?: string | null; |
| 23 | +} |
| 24 | + |
| 25 | +export function ModelErrorCard({ content, errorCode }: ModelErrorCardProps) { |
| 26 | + const { t } = useTranslation(); |
| 27 | + const navigate = useNavigate(); |
| 28 | + |
| 29 | + const description = (() => { |
| 30 | + let text: string; |
| 31 | + switch (errorCode) { |
| 32 | + case 'invalid_api_key': |
| 33 | + text = t('chat.model-error-invalid-api-key'); |
| 34 | + break; |
| 35 | + case 'model_not_found': |
| 36 | + text = t('chat.model-error-model-not-found'); |
| 37 | + break; |
| 38 | + case 'insufficient_quota': |
| 39 | + text = t('chat.model-error-quota-exceeded'); |
| 40 | + break; |
| 41 | + default: |
| 42 | + return content; |
| 43 | + } |
| 44 | + // The i18n strings end with " in" for the toast's inline link. |
| 45 | + // Strip it here since the card uses a separate button. |
| 46 | + return text.replace(/ in$/, ''); |
| 47 | + })(); |
| 48 | + |
| 49 | + return ( |
| 50 | + <div className="flex w-full items-start gap-2 rounded-xl bg-surface-warning p-4"> |
| 51 | + <TriangleAlert size={16} className="text-icon-warning" /> |
| 52 | + <div className="flex flex-col items-start gap-2"> |
| 53 | + <p className="mt-0 font-inter text-sm font-medium text-text-warning"> |
| 54 | + {description} |
| 55 | + </p> |
| 56 | + <Button |
| 57 | + variant="outline" |
| 58 | + size="sm" |
| 59 | + className="w-fit" |
| 60 | + onClick={() => navigate('/setting/models')} |
| 61 | + > |
| 62 | + {t('chat.model-error-open-settings')} |
| 63 | + </Button> |
| 64 | + </div> |
| 65 | + </div> |
| 66 | + ); |
| 67 | +} |
0 commit comments