mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 20:11:08 +00:00
Codex agent auth must be determined entirely by ~/.codex/auth.json or ~/.codex/config.toml. Before this change, if the user configured any OpenAI-compatible API provider in netcatty settings (for Catty agent use), useAIChatStreaming would silently hand that provider's apiKey to the Codex agent too, causing aiBridge to spawn codex-acp with authMethodId "codex-api-key" and completely override the user's ChatGPT login. The regression was introduced in PR #702 (v1.0.89) when findManagedAgent Provider started matching generic "custom" providers for Codex. Users who logged into Codex via ChatGPT and also had a netcatty-configured custom provider saw the UI flip to "API mode" on refresh and their ChatGPT session get ignored. Remove the codex branch from the agentProviderId resolver and from findManagedAgentProvider itself. Also drop the now-meaningless hasCompatibleProvider hint on the Codex settings card and its i18n copy. Claude agent behavior is unchanged. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
210 lines
7.5 KiB
TypeScript
210 lines
7.5 KiB
TypeScript
import React from "react";
|
|
import { ExternalLink, LogIn, LogOut, RefreshCw, X } from "lucide-react";
|
|
import { useI18n } from "../../../../application/i18n/I18nProvider";
|
|
import { Button } from "../../../ui/button";
|
|
import { cn } from "../../../../lib/utils";
|
|
import type { AgentPathInfo, CodexIntegrationStatus, CodexLoginSession } from "./types";
|
|
import { ProviderIconBadge } from "./ProviderIconBadge";
|
|
|
|
export const CodexConnectionCard: React.FC<{
|
|
pathInfo: AgentPathInfo | null;
|
|
isResolvingPath: boolean;
|
|
customPath: string;
|
|
onCustomPathChange: (path: string) => void;
|
|
onRecheckPath: () => void;
|
|
integration: CodexIntegrationStatus | null;
|
|
loginSession: CodexLoginSession | null;
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
onRefresh: () => void;
|
|
onConnect: () => void;
|
|
onCancel: () => void;
|
|
onOpenUrl: () => void;
|
|
onLogout: () => void;
|
|
}> = ({
|
|
pathInfo,
|
|
isResolvingPath,
|
|
customPath,
|
|
onCustomPathChange,
|
|
onRecheckPath,
|
|
integration,
|
|
loginSession,
|
|
isLoading,
|
|
error,
|
|
onRefresh,
|
|
onConnect,
|
|
onCancel,
|
|
onOpenUrl,
|
|
onLogout,
|
|
}) => {
|
|
const { t } = useI18n();
|
|
const found = pathInfo?.available;
|
|
|
|
const customConfigIncomplete = Boolean(
|
|
integration?.state === "connected_custom_config"
|
|
&& integration.customConfig
|
|
&& integration.customConfig.envKey
|
|
&& !integration.customConfig.envKeyPresent
|
|
&& !integration.customConfig.hasHardcodedApiKey,
|
|
);
|
|
|
|
const status = isResolvingPath
|
|
? t('ai.codex.detecting')
|
|
: !found
|
|
? t('ai.codex.notFound')
|
|
: loginSession?.state === "running"
|
|
? t('ai.codex.awaitingLogin')
|
|
: integration?.state === "connected_chatgpt"
|
|
? t('ai.codex.connectedChatGPT')
|
|
: integration?.state === "connected_api_key"
|
|
? t('ai.codex.connectedApiKey')
|
|
: integration?.state === "connected_custom_config"
|
|
? customConfigIncomplete
|
|
? t('ai.codex.customConfigIncomplete')
|
|
: t('ai.codex.connectedCustomConfig')
|
|
: integration?.state === "not_logged_in"
|
|
? t('ai.codex.notConnected')
|
|
: t('ai.codex.statusUnknown');
|
|
|
|
const statusClassName = isResolvingPath
|
|
? "text-muted-foreground"
|
|
: !found
|
|
? "text-amber-500"
|
|
: loginSession?.state === "running"
|
|
? "text-amber-500"
|
|
: customConfigIncomplete
|
|
? "text-amber-500"
|
|
: integration?.isConnected
|
|
? "text-emerald-500"
|
|
: "text-muted-foreground";
|
|
|
|
const outputText = loginSession?.error
|
|
? loginSession.error
|
|
: loginSession?.output?.trim()
|
|
? loginSession.output.trim()
|
|
: integration?.rawOutput?.trim()
|
|
? integration.rawOutput.trim()
|
|
: "";
|
|
|
|
return (
|
|
<div className="rounded-lg border border-border/60 bg-muted/20 p-4 space-y-3">
|
|
<div className="flex items-start justify-between gap-4">
|
|
<div className="min-w-0">
|
|
<div className="flex items-center gap-2">
|
|
<ProviderIconBadge providerId="openai" size="sm" />
|
|
<span className="text-sm font-medium">{t('ai.codex.title')}</span>
|
|
</div>
|
|
<p className="text-xs text-muted-foreground mt-2 leading-5">
|
|
{t('ai.codex.description')}
|
|
</p>
|
|
</div>
|
|
<div className={cn("text-xs font-medium shrink-0", statusClassName)}>
|
|
{status}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Path detection info */}
|
|
{found ? (
|
|
<div className="flex items-center gap-2 text-xs">
|
|
<span className="text-muted-foreground">{t('ai.codex.path')}</span>
|
|
<span className="font-mono text-foreground truncate">{pathInfo.path}</span>
|
|
{pathInfo.version && (
|
|
<>
|
|
<span className="text-muted-foreground">|</span>
|
|
<span className="text-muted-foreground">{pathInfo.version}</span>
|
|
</>
|
|
)}
|
|
</div>
|
|
) : !isResolvingPath ? (
|
|
<div className="space-y-2">
|
|
<p className="text-xs text-amber-500">
|
|
{t('ai.codex.notFoundHint')}
|
|
</p>
|
|
<div className="flex items-center gap-2">
|
|
<input
|
|
type="text"
|
|
value={customPath}
|
|
onChange={(e) => onCustomPathChange(e.target.value)}
|
|
placeholder={t('ai.codex.customPathPlaceholder')}
|
|
className="flex-1 h-8 rounded-md border border-input bg-background px-3 text-sm font-mono placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
/>
|
|
<Button variant="outline" size="sm" onClick={onRecheckPath} disabled={!customPath.trim()}>
|
|
<RefreshCw size={14} className="mr-1.5" />
|
|
{t('ai.codex.check')}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
|
|
{/* Connection & login UI -- only when codex is detected */}
|
|
{found && (
|
|
<>
|
|
<div className="border-t border-border/40 pt-3 flex items-center gap-2 flex-wrap">
|
|
{loginSession?.state === "running" ? (
|
|
<>
|
|
<Button variant="default" size="sm" onClick={onOpenUrl} disabled={!loginSession.url}>
|
|
<ExternalLink size={14} className="mr-1.5" />
|
|
{t('ai.codex.openLogin')}
|
|
</Button>
|
|
<Button variant="outline" size="sm" onClick={onCancel}>
|
|
<X size={14} className="mr-1.5" />
|
|
{t('common.cancel')}
|
|
</Button>
|
|
</>
|
|
) : integration?.state === "connected_custom_config" ? (
|
|
// Nothing to log out of; config.toml is user-owned state.
|
|
null
|
|
) : integration?.isConnected ? (
|
|
<Button variant="outline" size="sm" onClick={onLogout}>
|
|
<LogOut size={14} className="mr-1.5" />
|
|
{t('ai.codex.logout')}
|
|
</Button>
|
|
) : (
|
|
<Button variant="default" size="sm" onClick={onConnect}>
|
|
<LogIn size={14} className="mr-1.5" />
|
|
{t('ai.codex.connectChatGPT')}
|
|
</Button>
|
|
)}
|
|
|
|
<Button variant="outline" size="sm" onClick={onRefresh} disabled={isLoading}>
|
|
<RefreshCw size={14} className={cn("mr-1.5", isLoading && "animate-spin")} />
|
|
{t('ai.codex.refreshStatus')}
|
|
</Button>
|
|
</div>
|
|
|
|
{integration?.state === "connected_custom_config" && integration.customConfig && (
|
|
<>
|
|
<p className="text-xs text-emerald-500">
|
|
{t('ai.codex.customConfigHint').replace(
|
|
'{provider}',
|
|
integration.customConfig.displayName || integration.customConfig.providerName,
|
|
)}
|
|
</p>
|
|
{integration.customConfig.envKey && !integration.customConfig.envKeyPresent && !integration.customConfig.hasHardcodedApiKey && (
|
|
<p className="text-xs text-amber-500">
|
|
{t('ai.codex.customConfigMissingEnvKey').replace(
|
|
'{envKey}',
|
|
integration.customConfig.envKey,
|
|
)}
|
|
</p>
|
|
)}
|
|
</>
|
|
)}
|
|
</>
|
|
)}
|
|
|
|
{error && (
|
|
<p className="text-xs text-destructive">
|
|
{error}
|
|
</p>
|
|
)}
|
|
|
|
{found && outputText && (
|
|
<pre className="rounded-md border border-border/60 bg-background px-3 py-2 text-[11px] leading-5 text-muted-foreground whitespace-pre-wrap max-h-40 overflow-auto">
|
|
{outputText}
|
|
</pre>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|