From 3f7add5c10be5485567e2462754c145e94c19d78 Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Sat, 20 Dec 2025 23:17:18 -0500 Subject: [PATCH] fix(ui): deduplicate API key and restore add variable input - Add ANTHROPIC_AUTH_TOKEN to openRouterManagedKeys set - Change collapsible section from "All Environment Variables" to "Additional Variables" - Only show non-managed env vars in the collapsible section - Restore "Add Environment Variable" input at bottom of OpenRouter view --- .../profiles/editor/friendly-ui-section.tsx | 201 ++++++++++-------- 1 file changed, 107 insertions(+), 94 deletions(-) diff --git a/ui/src/components/profiles/editor/friendly-ui-section.tsx b/ui/src/components/profiles/editor/friendly-ui-section.tsx index 109a3231..a591a730 100644 --- a/ui/src/components/profiles/editor/friendly-ui-section.tsx +++ b/ui/src/components/profiles/editor/friendly-ui-section.tsx @@ -13,7 +13,9 @@ import { OpenRouterModelPicker } from '@/components/profiles/openrouter-model-pi import { ModelTierMapping, type TierMapping } from '@/components/profiles/model-tier-mapping'; import { Label } from '@/components/ui/label'; import { MaskedInput } from '@/components/ui/masked-input'; -import { ChevronRight, Settings2 } from 'lucide-react'; +import { Input } from '@/components/ui/input'; +import { Button } from '@/components/ui/button'; +import { ChevronRight, Settings2, Plus } from 'lucide-react'; import { isOpenRouterProfile, extractTierMapping, applyTierMapping } from './utils'; import { toast } from 'sonner'; import { cn } from '@/lib/utils'; @@ -98,19 +100,19 @@ export function FriendlyUISection({ // State for collapsible sections const [showAllEnvVars, setShowAllEnvVars] = useState(false); - // For OpenRouter: filter out model-related env vars from the main display - // These are managed by the model picker and tier mapping + // For OpenRouter: keys managed by dedicated UI sections const openRouterManagedKeys = new Set([ 'ANTHROPIC_MODEL', 'ANTHROPIC_DEFAULT_OPUS_MODEL', 'ANTHROPIC_DEFAULT_SONNET_MODEL', 'ANTHROPIC_DEFAULT_HAIKU_MODEL', + 'ANTHROPIC_AUTH_TOKEN', // Managed by API Key section ]); - // Count of hidden env vars for OpenRouter profiles - const hiddenEnvVarCount = isOpenRouter - ? Object.keys(currentEnv).filter((k) => openRouterManagedKeys.has(k)).length - : 0; + // Get non-managed env vars for display in "Additional Variables" + const unmanagedEnvVars = Object.entries(currentEnv).filter( + ([key]) => !openRouterManagedKeys.has(key) + ); return (
@@ -133,97 +135,108 @@ export function FriendlyUISection({ > {/* OpenRouter Streamlined View */} {isOpenRouter ? ( -
-
- {/* Model Selection - Primary Focus */} -
- - -
- - {/* Model Tier Mapping - Collapsible */} - - - {/* API Key - Simplified */} -
- - onEnvValueChange('ANTHROPIC_AUTH_TOKEN', e.target.value)} - placeholder="sk-or-v1-..." - className="font-mono text-sm" - /> -

- Get your API key from{' '} - - openrouter.ai/keys - -

-
- - {/* Advanced: All Environment Variables */} - - - +
+
+ {/* Model Selection - Primary Focus */} +
+ + - - All Environment Variables - - ({Object.keys(currentEnv).length} vars - {hiddenEnvVarCount > 0 && `, ${hiddenEnvVarCount} managed by picker`}) - - - -
- {Object.entries(currentEnv).map(([key, value]) => ( -
- - {key === 'ANTHROPIC_AUTH_TOKEN' ? ( - onEnvValueChange(key, e.target.value)} - className="font-mono text-xs h-8" - /> - ) : ( - onEnvValueChange(key, e.target.value)} - className="w-full font-mono text-xs h-8 px-2 rounded border bg-background" - readOnly={openRouterManagedKeys.has(key)} - /> +
+ + {/* Model Tier Mapping - Collapsible */} + + + {/* API Key */} +
+ + onEnvValueChange('ANTHROPIC_AUTH_TOKEN', e.target.value)} + placeholder="sk-or-v1-..." + className="font-mono text-sm" + /> +

+ Get your API key from{' '} + + openrouter.ai/keys + +

+
+ + {/* Additional Environment Variables (non-managed) */} + {unmanagedEnvVars.length > 0 && ( + + + + + Additional Variables + + ({unmanagedEnvVars.length}) + + + +
+ {unmanagedEnvVars.map(([key, value]) => ( +
+ + onEnvValueChange(key, e.target.value)} + className="font-mono text-xs h-8" + /> +
+ ))}
- ))} -
-
- + + + )} +
-
+ + {/* Fixed Add Variable Input at Bottom */} +
+ +
+ onNewEnvKeyChange(e.target.value.toUpperCase())} + className="font-mono text-sm h-8" + onKeyDown={(e) => e.key === 'Enter' && onAddEnvVar()} + /> + +
+
+ ) : ( /* Standard Env Editor for non-OpenRouter profiles */