| 1 | import { app } from "../lib/bridge"; |
| 2 | import { useI18n } from "../lib/i18n"; |
| 3 | import { useToast } from "../lib/toast"; |
| 4 | import type { TabMeta } from "../lib/types"; |
| 5 | import { useAppNavigationStore } from "../store/appNavigation"; |
| 6 | import "./AuthenticationRecoveryActions.css"; |
| 7 | |
| 8 | const COPY = { |
| 9 | en: { |
| 10 | missing: "This model connection needs an API key.", |
| 11 | rejected: "The provider rejected this connection's credential.", |
| 12 | unavailable: "Reasonix could not read the credential store.", |
| 13 | configure: "Configure credential", |
| 14 | retry: "Retry once", |
| 15 | authorized: "One authentication retry is ready. Send your message when ready.", |
| 16 | }, |
| 17 | zh: { |
| 18 | missing: "当前模型连接需要 API Key。", |
| 19 | rejected: "Provider 拒绝了当前连接的凭据。", |
| 20 | unavailable: "Reasonix 无法读取凭据存储。", |
| 21 | configure: "配置凭据", |
| 22 | retry: "重试一次", |
| 23 | authorized: "已允许一次认证重试,可以重新发送消息。", |
| 24 | }, |
| 25 | "zh-TW": { |
| 26 | missing: "目前模型連線需要 API Key。", |
| 27 | rejected: "Provider 拒絕了目前連線的憑據。", |
| 28 | unavailable: "Reasonix 無法讀取憑據儲存。", |
| 29 | configure: "設定憑據", |
| 30 | retry: "重試一次", |
| 31 | authorized: "已允許一次認證重試,可以重新傳送訊息。", |
| 32 | }, |
| 33 | } as const; |
| 34 | |
| 35 | export function AuthenticationRecoveryActions({ |
| 36 | authentication, |
| 37 | tabId, |
| 38 | }: { |
| 39 | authentication: NonNullable<TabMeta["authentication"]>; |
| 40 | tabId?: string; |
| 41 | }) { |
| 42 | const { locale } = useI18n(); |
| 43 | const copy = COPY[locale]; |
| 44 | const { showToast } = useToast(); |
| 45 | return <> |
| 46 | <span className="composer-toolbar-send__hint">{ |
| 47 | authentication.status === "authentication_rejected" ? copy.rejected |
| 48 | : authentication.status === "credential_store_unavailable" ? copy.unavailable |
| 49 | : copy.missing |
| 50 | }</span> |
| 51 | {authentication.providerName && <button type="button" className="composer-toolbar-send__configure" onClick={() => { |
| 52 | useAppNavigationStore.getState().setSettingsFocus((current) => ({ |
| 53 | target: "model-access", |
| 54 | providerName: authentication.providerName, |
| 55 | sourceTabId: tabId, |
| 56 | requestId: (current?.requestId ?? 0) + 1, |
| 57 | })); |
| 58 | useAppNavigationStore.getState().setSettingsTarget("models"); |
| 59 | }}>{copy.configure}</button>} |
| 60 | {authentication.status === "authentication_rejected" && <button type="button" className="composer-toolbar-send__configure" onClick={() => void (async () => { |
| 61 | try { |
| 62 | await app.RetryAuthenticationForTab(tabId ?? ""); |
| 63 | showToast(copy.authorized, "info"); |
| 64 | } catch (error) { |
| 65 | showToast(String(error), "warn"); |
| 66 | } |
| 67 | })()}>{copy.retry}</button>} |
| 68 | </>; |
| 69 | } |
| 70 |