Awakened_RiShre / src /components /SettingsModal.tsx
usrrootkali's picture
Update src/components/SettingsModal.tsx
c1f8e4f verified
Raw History Blame Contribute Delete
9.91 kB
import React, { useState } from 'react';
import {
Settings,
X,
Key,
ShieldCheck,
CheckCircle2,
AlertCircle,
ExternalLink,
Sparkles,
} from 'lucide-react';
import { logRealConsoleApiError } from '../utils/apiLogger';
interface SettingsModalProps {
isOpen: boolean;
onClose: () => void;
hfToken: string;
onSaveToken: (token: string) => void;
temperature: number;
onSetTemperature: (temp: number) => void;
}
export const SettingsModal: React.FC<SettingsModalProps> = ({
isOpen,
onClose,
hfToken,
onSaveToken,
temperature,
onSetTemperature,
}) => {
const [tokenInput, setTokenInput] = useState(hfToken);
const [testStatus, setTestStatus] = useState<'idle' | 'testing' | 'success' | 'error'>('idle');
const [testMessage, setTestMessage] = useState('');
if (!isOpen) return null;
const handleSave = () => {
onSaveToken(tokenInput.trim());
onClose();
};
const handleTestToken = async () => {
if (!tokenInput.trim()) {
setTestStatus('error');
setTestMessage('Please enter a Hugging Face token first.');
return;
}
setTestStatus('testing');
setTestMessage('Connecting to Hugging Face API...');
try {
const res = await fetch('https://huggingface.co/api/whoami-v2', {
headers: {
Authorization: `Bearer ${tokenInput.trim()}`,
},
});
if (res.ok) {
const data = await res.json();
setTestStatus('success');
setTestMessage(`Authenticated successfully as @${data.name || data.fullname || 'user'}!`);
} else {
const errBody = await res.text().catch(() => '');
logRealConsoleApiError({
topic: 'Hugging Face Token Authentication Error',
endpoint: 'https://huggingface.co/api/whoami-v2',
status: res.status,
statusText: res.statusText,
message: `Authentication failed with status ${res.status} (${res.statusText || 'Unauthorized'})`,
rawResponse: errBody,
});
setTestStatus('error');
setTestMessage(`HF authentication failed (${res.status}). Verify your token permissions.`);
}
} catch (e: any) {
logRealConsoleApiError({
topic: 'Hugging Face Token Validation Network Failure',
endpoint: 'https://huggingface.co/api/whoami-v2',
message: e.message || 'Network request failed or CORS blocked.',
error: e,
});
setTestStatus('error');
setTestMessage(`Connection error: ${e.message || 'Network request failed'}`);
}
};
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-md p-4 animate-in fade-in">
<div className="w-full max-w-lg bg-[#0c061a] border border-purple-500/30 rounded-3xl shadow-[0_0_60px_rgba(168,85,247,0.25)] overflow-hidden flex flex-col">
{/* Modal Header */}
<div className="px-6 py-4 bg-[#120826]/90 border-b border-purple-500/25 flex items-center justify-between">
<div className="flex items-center gap-2.5">
<div className="w-6 h-6 rounded-lg bg-gradient-to-tr from-purple-600 to-fuchsia-500 flex items-center justify-center shadow-[0_0_10px_rgba(168,85,247,0.4)]">
<Settings className="w-3.5 h-3.5 text-white" />
</div>
<h2 className="text-sm font-bold text-white tracking-wide">Platform & API Configuration</h2>
</div>
<button
onClick={onClose}
aria-label="Close"
className="p-1 rounded-lg text-purple-300 hover:text-white transition-colors cursor-pointer"
>
<X className="w-4 h-4" />
</button>
</div>
{/* Modal Body */}
<div className="p-6 space-y-6 overflow-y-auto max-h-[75vh]">
{/* RiShre Awakened Model Identity Card */}
<div className="p-4 rounded-2xl bg-gradient-to-r from-purple-950/60 via-[#180933]/70 to-[#1e0a3d]/60 border border-purple-500/30 flex items-center justify-between shadow-lg">
<div className="flex items-center gap-3">
<div className="w-9 h-9 rounded-xl bg-gradient-to-tr from-purple-600 via-fuchsia-600 to-pink-500 flex items-center justify-center shadow-[0_0_15px_rgba(168,85,247,0.4)]">
<Sparkles className="w-5 h-5 text-white" />
</div>
<div>
<h4 className="text-xs font-bold text-white">RiShre Awakened</h4>
<p className="text-[11px] text-purple-300/80">Flagship Unified Agent & Vibe Coding Engine</p>
</div>
</div>
<span className="text-[10px] font-mono px-2.5 py-1 rounded-full bg-purple-900/50 text-fuchsia-300 border border-purple-400/40">
ACTIVATED
</span>
</div>
{/* Hugging Face Token Section */}
<div className="space-y-3">
<div className="flex items-center justify-between">
<label className="text-xs font-bold text-purple-200 flex items-center gap-1.5 font-mono">
<Key className="w-3.5 h-3.5 text-fuchsia-400" />
<span>Hugging Face Access Token</span>
</label>
<a
href="https://huggingface.co/settings/tokens"
target="_blank"
rel="noreferrer"
className="text-[11px] text-fuchsia-400 hover:underline flex items-center gap-1"
>
<span>Get Token</span>
<ExternalLink className="w-3 h-3" />
</a>
</div>
<div className="flex gap-2">
<input
type="password"
placeholder="hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
value={tokenInput}
onChange={(e) => {
setTokenInput(e.target.value);
setTestStatus('idle');
}}
className="flex-1 bg-[#120826] border border-purple-500/30 rounded-xl px-3.5 py-2 text-xs text-white focus:outline-none focus:border-purple-400 font-mono shadow-inner"
/>
<button
type="button"
onClick={handleTestToken}
disabled={testStatus === 'testing'}
className="px-3.5 py-2 rounded-xl bg-[#1b0c38] hover:bg-[#281254] text-xs font-semibold text-purple-200 hover:text-white transition-colors cursor-pointer border border-purple-500/30"
>
{testStatus === 'testing' ? 'Testing...' : 'Test Token'}
</button>
</div>
{testStatus === 'success' && (
<div className="flex items-center gap-2 p-2.5 rounded-xl bg-emerald-950/40 border border-emerald-500/40 text-emerald-300 text-xs font-mono">
<CheckCircle2 className="w-4 h-4 shrink-0 text-emerald-400" />
<span>{testMessage}</span>
</div>
)}
{testStatus === 'error' && (
<div className="flex items-center gap-2 p-2.5 rounded-xl bg-rose-950/40 border border-rose-500/40 text-rose-300 text-xs font-mono">
<AlertCircle className="w-4 h-4 shrink-0 text-rose-400" />
<span>{testMessage}</span>
</div>
)}
{/* Static Security Notice */}
<div className="p-3.5 rounded-2xl bg-purple-950/30 border border-purple-500/25 text-purple-200 text-xs space-y-1.5 leading-relaxed">
<div className="flex items-center gap-1.5 font-bold text-fuchsia-300">
<ShieldCheck className="w-4 h-4" />
<span>Client-Side Static Security Guarantee</span>
</div>
<p className="text-[11px] text-purple-300/80">
Because RiShre runs as a static client application on Hugging Face Spaces without an intermediary server, your API token is stored exclusively in your browser&apos;s <code>localStorage</code>. It is sent only directly to Hugging Face API endpoints over encrypted HTTPS.
</p>
</div>
</div>
{/* Temperature Slider */}
<div className="space-y-2">
<div className="flex justify-between text-xs">
<span className="font-bold text-purple-200">Creativity / Temperature</span>
<span className="font-mono text-fuchsia-400">{temperature.toFixed(2)}</span>
</div>
<input
type="range"
min="0.1"
max="1.0"
step="0.05"
value={temperature}
onChange={(e) => onSetTemperature(parseFloat(e.target.value))}
className="w-full accent-purple-500 cursor-pointer"
/>
<div className="flex justify-between text-[10px] text-purple-400/70 font-mono">
<span>Precise & Analytical (0.2)</span>
<span>Balanced Vibe (0.7)</span>
<span>Visionary & Creative (1.0)</span>
</div>
</div>
</div>
{/* Modal Footer */}
<div className="px-6 py-4 bg-[#0a0517] border-t border-purple-500/25 flex justify-end gap-2">
<button
type="button"
onClick={onClose}
className="px-4 py-2 rounded-xl text-xs font-medium text-purple-300 hover:text-white transition-colors cursor-pointer"
>
Cancel
</button>
<button
type="button"
onClick={handleSave}
className="px-5 py-2 rounded-xl bg-gradient-to-r from-purple-600 via-fuchsia-600 to-pink-500 hover:from-purple-500 hover:to-pink-500 text-white font-bold text-xs uppercase tracking-wider transition-all shadow-[0_0_20px_rgba(168,85,247,0.4)] cursor-pointer active:scale-95"
>
Save Settings
</button>
</div>
</div>
</div>
);
};