MCPcopy Create free account
hub / github.com/anus-dev/ANUS / ApiKeyInput

Function ApiKeyInput

packages/cli/src/ui/components/ApiKeyInput.tsx:19–136  ·  view source on GitHub ↗
({
  onSubmit,
  onCancel,
  errorMessage,
}: ApiKeyInputProps)

Source from the content-addressed store, hash-verified

17}
18
19export function ApiKeyInput({
20 onSubmit,
21 onCancel,
22 errorMessage,
23}: ApiKeyInputProps): React.JSX.Element {
24 const [input, setInput] = useState('');
25 const [localError, setLocalError] = useState<string | null>(null);
26
27 const validateApiKey = useCallback((key: string): string | null => {
28 if (!key.trim()) {
29 return 'API key cannot be empty';
30 }
31 if (!key.startsWith('sk-or-v1-')) {
32 return 'Invalid API key format. OpenRouter API keys start with "sk-or-v1-"';
33 }
34 if (key.length < 20) {
35 return 'API key appears to be too short';
36 }
37 return null;
38 }, []);
39
40 const handleSubmit = useCallback(() => {
41 const trimmedInput = input.trim();
42 const validationError = validateApiKey(trimmedInput);
43
44 if (validationError) {
45 setLocalError(validationError);
46 return;
47 }
48
49 setLocalError(null);
50 onSubmit(trimmedInput);
51 }, [input, validateApiKey, onSubmit]);
52
53 useKeypress(
54 (key) => {
55 // Clear error on any key press except enter/escape
56 if (key.name !== 'return' && key.name !== 'escape' && localError) {
57 setLocalError(null);
58 }
59
60 if (key.name === 'return') {
61 handleSubmit();
62 return;
63 }
64
65 if (key.name === 'escape') {
66 onCancel();
67 return;
68 }
69
70 if (key.name === 'backspace' || key.name === 'delete') {
71 setInput((prev) => prev.slice(0, -1));
72 return;
73 }
74
75 // Handle ctrl+c
76 if (key.ctrl && key.name === 'c') {

Callers

nothing calls this directly

Calls 1

useKeypressFunction · 0.85

Tested by

no test coverage detected