Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
chore(merge): resolve page.tsx conflict — keep ImportCodexAuthModal and ApplyCodexAuthModal
diegosouzapw3227c9ffe361
diff --cc src/app/(dashboard)/dashboard/providers/[id]/page.tsxindex b9a9993e47,33c44b8397..a850433439--- a/src/app/(dashboard)/dashboard/providers/[id]/page.tsx+++ b/src/app/(dashboard)/dashboard/providers/[id]/page.tsx@@@ -1058,8 -1058,10 +1058,11 @@@ export default function ProviderDetailPnull);const [applyingCodexAuthId, setApplyingCodexAuthId] = useState<string | null>(null);+ const [applyCodexModalConnectionId, setApplyCodexModalConnectionId] = useState<string | null>(+ null+ );const [exportingCodexAuthId, setExportingCodexAuthId] = useState<string | null>(null);+ const [importCodexModalOpen, setImportCodexModalOpen] = useState(false);const [codexGlobalFastServiceTier, setCodexGlobalFastServiceTier] = useState(false);const [savingCodexGlobalFastServiceTier, setSavingCodexGlobalFastServiceTier] = useState(false);const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());@@@ -6995,273 -6985,98 +7008,371 @@@ function AddApiKeyModal();}+interface ImportCodexAuthModalProps {+ onClose: () => void;+ onSuccess: () => void;+}++function ImportCodexAuthModal({ onClose, onSuccess }: ImportCodexAuthModalProps) {+ const t = useTranslations("providers");+ const notify = useNotificationStore();+ const [tab, setTab] = useState<"upload" | "paste">("upload");+ const [pasteText, setPasteText] = useState("");+ const [parsedJson, setParsedJson] = useState<unknown>(null);+ const [parseError, setParseError] = useState<string | null>(null);+ const [detectedEmail, setDetectedEmail] = useState<string | null>(null);+ const [name, setName] = useState("");+ const [email, setEmail] = useState("");+ const [overwriteExisting, setOverwriteExisting] = useState(false);+ const [loading, setLoading] = useState(false);+ const [resultError, setResultError] = useState<string | null>(null);++ function extractEmailFromJwt(idToken: string): string | null {+ try {+ const parts = idToken.split(".");+ if (parts.length !== 3) return null;+ const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));+ return typeof payload.email === "string" ? payload.email : null;+ } catch {+ return null;+ }+ }++ function tryParseAndPreview(json: unknown) {+ setParseError(null);+ setDetectedEmail(null);+ setParsedJson(null);+ try {+ const doc = json && typeof json === "object" ? (json as Record<string, unknown>) : null;+ if (!doc || doc.auth_mode !== "chatgpt") {+ setParseError(t("codexImportInvalidShape") || "Not a valid Codex auth.json");+ return;+ }+ const tokens =+ doc.tokens && typeof doc.tokens === "object"+ ? (doc.tokens as Record<string, unknown>)+ : null;+ if (!tokens?.id_token || typeof tokens.id_token !== "string") {+ setParseError(t("codexImportInvalidShape") || "Not a valid Codex auth.json");+ return;+ }+ const detected = extractEmailFromJwt(tokens.id_token as string);+ setDetectedEmail(detected);+ if (detected && !email) setEmail(detected);+ setParsedJson(doc);+ } catch {+ setParseError(t("codexImportInvalidJson") || "Could not parse JSON");+ }+ }++ function handleFileChange(e: React.ChangeEvent<HTMLInputElement>) {+ const file = e.target.files?.[0];+ if (!file) return;+ const reader = new FileReader();+ reader.onload = (ev) => {+ const text = ev.target?.result as string;+ try {+ const json = JSON.parse(text);+ tryParseAndPreview(json);+ setParsedJson(json);+ } catch {+ setParseError(t("codexImportInvalidJson") || "Could not parse JSON");+ setParsedJson(null);+ }+ };+ reader.readAsText(file);+ }++ function handlePasteChange(text: string) {+ setPasteText(text);+ if (!text.trim()) {+ setParsedJson(null);+ setParseError(null);+ setDetectedEmail(null);+ return;+ }+ try {+ const json = JSON.parse(text);+ tryParseAndPreview(json);+ } catch {+ setParseError(t("codexImportInvalidJson") || "Could not parse JSON");+ setParsedJson(null);+ }+ }++ async function handleSubmit() {+ if (!parsedJson) return;+ setLoading(true);+ setResultError(null);+ try {+ const res = await fetch("/api/providers/codex-auth/import", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({+ source: { kind: "json", json: parsedJson },+ name: name.trim() || undefined,+ email: email.trim() || undefined,+ overwriteExisting,+ }),+ });+ const data = await res.json().catch(() => ({}));+ if (!res.ok) {+ if (data.code === "duplicate_account") {+ setResultError(+ t("codexImportDuplicate") ||+ "Account already exists — enable Replace existing to overwrite"+ );+ } else {+ setResultError(data.error || t("codexImportFailed") || "Failed to import Codex auth");+ }+ return;+ }+ notify.success(t("codexImportSuccess") || "Codex connection imported successfully");+ onSuccess();+ } catch {+ setResultError(t("codexImportFailed") || "Failed to import Codex auth");+ } finally {+ setLoading(false);+ }+ }++ const canSubmit = !!parsedJson && !parseError && !loading;++ return (+ <Modal+ isOpen+ onClose={onClose}+ title={t("codexImportModalTitle") || "Import Codex Auth"}+ maxWidth="max-w-lg"+ >+ <div className="flex flex-col gap-4">+ {/* Tabs */}+ <div className="flex border-b border-border">+ {(["upload", "paste"] as const).map((id) => (+ <button+ key={id}+ onClick={() => {+ setTab(id);+ setParsedJson(null);+ setParseError(null);+ setDetectedEmail(null);+ }}+ className={`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${+ tab === id+ ? "border-primary text-primary"+ : "border-transparent text-text-muted hover:text-text-main"+ }`}+ >+ {id === "upload"+ ? t("codexImportTabUpload") || "Upload file"+ : t("codexImportTabPaste") || "Paste JSON"}+ </button>+ ))}+ </div>++ {/* Upload tab */}+ {tab === "upload" && (+ <div className="flex flex-col gap-2">+ <label className="text-sm font-medium text-text-main">+ {t("codexImportFileLabel") || "Choose auth.json"}+ </label>+ <input+ type="file"+ accept=".json"+ onChange={handleFileChange}+ className="text-sm text-text-muted file:mr-3 file:py-1.5 file:px-3 file:rounded-lg file:border file:border-border file:text-xs file:bg-bg-subtle file:text-text-main hover:file:bg-bg-hover cursor-pointer"+ />+ <p className="text-xs text-text-muted">+ {t("codexImportFileHint") ||+ "Select the auth.json file exported from Codex or OmniRoute."}+ </p>+ </div>+ )}++ {/* Paste tab */}+ {tab === "paste" && (+ <div className="flex flex-col gap-2">+ <label className="text-sm font-medium text-text-main">+ {t("codexImportPasteLabel") || "Paste the JSON content"}+ </label>+ <textarea+ value={pasteText}+ onChange={(e) => handlePasteChange(e.target.value)}+ rows={8}+ placeholder='{ "auth_mode": "chatgpt", ... }'+ className="w-full rounded-lg border border-border bg-bg-subtle px-3 py-2 text-xs font-mono text-text-main placeholder:text-text-muted focus:outline-none focus:ring-2 focus:ring-primary/40 resize-none"+ />+ </div>+ )}++ {/* Parse error */}+ {parseError && <p className="text-sm text-red-500">{parseError}</p>}++ {/* Detected email preview */}+ {detectedEmail && !parseError && (+ <p className="text-xs text-text-muted">+ {t("codexImportDetectedEmail", { email: detectedEmail }) ||+ `Detected: ${detectedEmail}`}+ </p>+ )}++ {/* Shared fields */}+ <div className="flex flex-col gap-3">+ <div className="flex flex-col gap-1">+ <label className="text-sm font-medium text-text-main">+ {t("codexImportEmailLabel") || "Account email"}+ </label>+ <input+ type="email"+ value={email}+ onChange={(e) => setEmail(e.target.value)}+ placeholder="[email protected]"+ className="rounded-lg border border-border bg-bg-subtle px-3 py-2 text-sm text-text-main placeholder:text-text-muted focus:outline-none focus:ring-2 focus:ring-primary/40"+ />+ <p className="text-xs text-text-muted">+ {t("codexImportEmailHint") || "Auto-detected from the file; edit if needed."}+ </p>+ </div>++ <div className="flex flex-col gap-1">+ <label className="text-sm font-medium text-text-main">+ {t("codexImportNameLabel") || "Connection name (optional)"}+ </label>+ <input+ type="text"+ value={name}+ onChange={(e) => setName(e.target.value)}+ placeholder={email || "Codex (imported)"}+ className="rounded-lg border border-border bg-bg-subtle px-3 py-2 text-sm text-text-main placeholder:text-text-muted focus:outline-none focus:ring-2 focus:ring-primary/40"+ />+ </div>++ <label className="flex items-center gap-2 cursor-pointer">+ <input+ type="checkbox"+ checked={overwriteExisting}+ onChange={(e) => setOverwriteExisting(e.target.checked)}+ className="rounded border-border"+ />+ <span className="text-sm text-text-main">+ {t("codexImportOverwriteLabel") ||+ "Replace existing connection if account already exists"}+ </span>+ </label>+ </div>++ {/* Result error banner */}+ {resultError && (+ <div className="rounded-lg bg-red-500/10 border border-red-500/20 px-4 py-3 text-sm text-red-400">+ {resultError}+ </div>+ )}++ <div className="flex gap-2 pt-1">+ <Button onClick={handleSubmit} disabled={!canSubmit} loading={loading} fullWidth>+ {t("codexImportSubmit") || "Import"}+ </Button>+ <Button onClick={onClose} variant="ghost" fullWidth>+ {t("cancel")}+ </Button>++ </div>++ </div>++ </Modal>++ );++}+++ function ApplyCodexAuthModal({+ connectionId,+ inProgress,+ onConfirm,+ onClose,+ }: {+ connectionId: string | null;+ inProgress: boolean;+ onConfirm: (id: string) => Promise<void>;+ onClose: () => void;+ }) {+ const t = useTranslations("providers");+ // `key`-reset pattern: caller re-mounts the modal each open (different+ // connectionId triggers a new instance), so local confirmation state is+ // naturally fresh without any post-render bookkeeping.+ const [confirmed, setConfirmed] = useState(false);+ const isOpen = !!connectionId;++ if (!connectionId) return null;++ const title =+ typeof t.has === "function" && t.has("codexApplyModalTitle")+ ? t("codexApplyModalTitle")+ : "Apply to Local Codex";+ const targetLabel =+ typeof t.has === "function" && t.has("codexApplyTargetLabel")+ ? t("codexApplyTargetLabel")+ : "Target path";+ const backupLabel =+ typeof t.has === "function" && t.has("codexApplyBackupLabel")+ ? t("codexApplyBackupLabel")+ : "Backups";+ const warning =+ typeof t.has === "function" && t.has("codexApplyWarning")+ ? t("codexApplyWarning")+ : "This will replace the existing auth.json. Continue?";+ const confirmText =+ typeof t.has === "function" && t.has("codexApplyConfirmCheckbox")+ ? t("codexApplyConfirmCheckbox")+ : "I confirm I want to replace the existing auth.json";+ const applyText = typeof t.has === "function" && t.has("codexApply") ? t("codexApply") : "Apply";++ return (+ <Modal isOpen={isOpen} title={title} onClose={onClose}>+ <div className="flex flex-col gap-4">+ <div>+ <div className="text-xs uppercase text-text-muted mb-1">{targetLabel}</div>+ <code className="block rounded bg-sidebar px-2 py-1.5 text-xs font-mono text-text-main">+ ~/.codex/auth.json+ </code>+ <p className="mt-1 text-xs text-text-muted">+ Path is auto-detected per OS (Linux/Mac/Windows).+ </p>+ </div>+ <div>+ <div className="text-xs uppercase text-text-muted mb-1">{backupLabel}</div>+ <ul className="text-xs text-text-muted space-y-0.5 list-disc pl-4">+ <li>+ <code className="text-text-main">~/.codex/auth-<timestamp>.bak</code> — quick+ local rollback+ </li>+ <li>Centralized backup history (audit trail)</li>+ </ul>+ </div>+ <div className="rounded-lg border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-sm text-amber-200">+ <div className="flex items-start gap-2">+ <span className="material-symbols-outlined mt-0.5 text-[18px] text-amber-500">+ warning+ </span>+ <span>{warning}</span>+ </div>+ </div>+ <label className="flex items-center gap-2 text-sm text-text-muted cursor-pointer">+ <input+ type="checkbox"+ checked={confirmed}+ onChange={(e) => setConfirmed(e.target.checked)}+ className="rounded border-border"+ />+ {confirmText}+ </label>+ <div className="flex gap-2">+ <Button+ onClick={() => void onConfirm(connectionId)}+ fullWidth+ disabled={!confirmed || inProgress}+ >+ {inProgress ? t("saving") : applyText}+ </Button>+ <Button onClick={onClose} variant="ghost" fullWidth disabled={inProgress}>+ {t("cancel")}+ </Button></div></div></Modal>