import { Copy, CornerUpLeft, ExternalLink, Eye, EyeOff, FoldVertical, HatGlasses, Home, Loader2, Scale, UnfoldVertical, } from 'lucide-react' import { useEffect, useState } from 'react' import { siGithub } from 'simple-icons' import { DEMO_BASE_URL, DEMO_MODEL, isTestingEndpoint } from '@/agent/constants' import type { ExtConfig, LanguagePreference } from '@/agent/useAgent' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Switch } from '@/components/ui/switch' interface ConfigPanelProps { config: ExtConfig | null onSave: (config: ExtConfig) => Promise onClose: () => void } export function ConfigPanel({ config, onSave, onClose }: ConfigPanelProps) { const [baseURL, setBaseURL] = useState(config?.baseURL || DEMO_BASE_URL) const [model, setModel] = useState(config?.model || DEMO_MODEL) const [apiKey, setApiKey] = useState(config?.apiKey) const [language, setLanguage] = useState(config?.language) const [maxSteps, setMaxSteps] = useState(config?.maxSteps) const [systemInstruction, setSystemInstruction] = useState(config?.systemInstruction ?? '') const [experimentalLlmsTxt, setExperimentalLlmsTxt] = useState( config?.experimentalLlmsTxt ?? false ) const [advancedOpen, setAdvancedOpen] = useState(false) const [saving, setSaving] = useState(false) const [userAuthToken, setUserAuthToken] = useState('') const [copied, setCopied] = useState(false) const [showToken, setShowToken] = useState(false) const [showApiKey, setShowApiKey] = useState(false) useEffect(() => { setBaseURL(config?.baseURL || DEMO_BASE_URL) setModel(config?.model || DEMO_MODEL) setApiKey(config?.apiKey) setLanguage(config?.language) setMaxSteps(config?.maxSteps) setSystemInstruction(config?.systemInstruction ?? '') setExperimentalLlmsTxt(config?.experimentalLlmsTxt ?? false) }, [config]) // Poll for user auth token every second until found useEffect(() => { let interval: NodeJS.Timeout | null = null const fetchToken = async () => { const result = await chrome.storage.local.get('PageAgentExtUserAuthToken') const token = result.PageAgentExtUserAuthToken if (typeof token === 'string' && token) { setUserAuthToken(token) if (interval) { clearInterval(interval) interval = null } } } fetchToken() interval = setInterval(fetchToken, 1000) return () => { if (interval) clearInterval(interval) } }, []) const handleCopyToken = async () => { if (userAuthToken) { await navigator.clipboard.writeText(userAuthToken) setCopied(true) setTimeout(() => setCopied(false), 2000) } } const handleSave = async () => { setSaving(true) try { await onSave({ apiKey, baseURL, model, language, maxSteps: maxSteps || undefined, systemInstruction: systemInstruction || undefined, experimentalLlmsTxt, }) } finally { setSaving(false) } } return (

Settings

{/* User Auth Token Section */}

Give a website the ability to call this extension.

{/* Hub link */} Manage Page Agent Hub
setBaseURL(e.target.value)} className="text-xs h-8" />
{/* Testing API notice */} {isTestingEndpoint(baseURL) && (
You are using our testing API. By using this you agree to the{' '} Terms of Use & Privacy Policy
)}
setModel(e.target.value)} className="text-xs h-8" />
setApiKey(e.target.value)} className="text-xs h-8" />
{/* Advanced Config */} {advancedOpen && ( <>
setMaxSteps(e.target.value ? Number(e.target.value) : undefined)} className="text-xs h-8 [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none [-moz-appearance:textfield]" />