mirror of
https://github.com/Finesssee/ProxyPilot.git
synced 2026-11-19 02:17:46 +00:00
feat(webui): refactor dashboard with tabbed navigation and theme toggle
- Add 5-tab navigation: Engine, Auth, Routing, Memory, Logs - Add dark/light/system theme toggle with persistence - Extract 7 modular dashboard components: - EngineControl: proxy start/stop/restart controls - ProviderLogins: OAuth buttons for 6 AI providers - Integrations: CLI agent detection and configuration - ModelMappings: global model mapping CRUD - MemoryManager: session memory management - SemanticMemory: Ollama embeddings and namespaces - LogsViewer: diagnostics and log viewing - Add centralized state management with ProxyProvider context - Reduce App.tsx from 1,734 lines to 351 lines 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
3e3d0bf933
commit
7631297204
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+177
-1559
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,246 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Separator } from '@/components/ui/separator'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import {
|
||||
Play,
|
||||
Square,
|
||||
RotateCcw,
|
||||
FolderOpen,
|
||||
FileText,
|
||||
Copy,
|
||||
Activity,
|
||||
Settings,
|
||||
Shield,
|
||||
Globe,
|
||||
AlertCircle,
|
||||
} from 'lucide-react'
|
||||
import { useProxyContext } from '@/hooks/useProxyContext'
|
||||
|
||||
export function EngineControl() {
|
||||
const { status, loading, handleAction, showToast } = useProxyContext()
|
||||
const [privateOAuth, setPrivateOAuth] = useState(false)
|
||||
|
||||
const isRunning = status?.running ?? false
|
||||
|
||||
useEffect(() => {
|
||||
;(async () => {
|
||||
try {
|
||||
if (window.pp_get_oauth_private) {
|
||||
const priv = await window.pp_get_oauth_private()
|
||||
setPrivateOAuth(priv)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('OAuth private error:', e)
|
||||
}
|
||||
})()
|
||||
}, [])
|
||||
|
||||
const handlePrivateOAuthChange = async (checked: boolean) => {
|
||||
try {
|
||||
if (window.pp_set_oauth_private) {
|
||||
await window.pp_set_oauth_private(checked)
|
||||
setPrivateOAuth(checked)
|
||||
showToast('Preference saved', 'success')
|
||||
}
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="backdrop-blur-sm bg-card/60 border-border/50 shadow-xl">
|
||||
<CardHeader className="pb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-10 w-10 rounded-xl bg-primary/10 flex items-center justify-center">
|
||||
<Activity className="h-5 w-5 text-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<CardTitle className="text-lg">Engine Control</CardTitle>
|
||||
<CardDescription>Start, stop or restart the proxy</CardDescription>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-5">
|
||||
{/* Control Buttons */}
|
||||
<div className="flex gap-3">
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
className={`flex-1 gap-2 transition-all duration-200 font-semibold shadow-md ${
|
||||
isRunning
|
||||
? 'opacity-50 cursor-not-allowed'
|
||||
: 'hover:scale-[1.02] active:scale-[0.98]'
|
||||
}`}
|
||||
variant={isRunning ? 'secondary' : 'default'}
|
||||
disabled={isRunning || loading === 'start'}
|
||||
onClick={() => handleAction(window.pp_start, 'start', 'Proxy started')}
|
||||
>
|
||||
<Play className="h-4 w-4 fill-current" />
|
||||
Start
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Start the proxy server</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="destructive"
|
||||
className={`flex-1 gap-2 transition-all duration-200 shadow-md ${
|
||||
!isRunning
|
||||
? 'opacity-50 cursor-not-allowed'
|
||||
: 'hover:bg-destructive/90 hover:scale-[1.02]'
|
||||
}`}
|
||||
disabled={!isRunning || loading === 'stop'}
|
||||
onClick={() => handleAction(window.pp_stop, 'stop', 'Proxy stopped')}
|
||||
>
|
||||
<Square className="h-4 w-4 fill-current" />
|
||||
Stop
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Stop the proxy server</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
className={`flex-1 gap-2 transition-all duration-200 ${
|
||||
!isRunning
|
||||
? 'opacity-50 cursor-not-allowed'
|
||||
: 'hover:bg-secondary hover:text-secondary-foreground'
|
||||
}`}
|
||||
disabled={!isRunning || loading === 'restart'}
|
||||
onClick={() => handleAction(window.pp_restart, 'restart', 'Proxy restarted')}
|
||||
>
|
||||
<RotateCcw className="h-4 w-4" />
|
||||
Restart
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Restart the proxy server</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
{/* Status Info */}
|
||||
<div className="rounded-xl bg-muted/50 border border-border/50 p-4 space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-sm text-muted-foreground flex items-center gap-2">
|
||||
<Globe className="h-4 w-4" /> Base URL
|
||||
</span>
|
||||
<code className="text-sm font-mono text-primary bg-background/50 px-2 py-1 rounded border border-border/50">
|
||||
{status?.base_url || '—'}
|
||||
</code>
|
||||
</div>
|
||||
<Separator className="bg-border/50" />
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-sm text-muted-foreground">Port</span>
|
||||
<span className="text-sm font-mono">{status?.port || '—'}</span>
|
||||
</div>
|
||||
{status?.last_error && (
|
||||
<>
|
||||
<Separator className="bg-border/50" />
|
||||
<div className="flex items-start gap-2 text-destructive">
|
||||
<AlertCircle className="h-4 w-4 mt-0.5 flex-shrink-0" />
|
||||
<span className="text-sm break-all font-medium">{status.last_error}</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Quick Actions */}
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="gap-2 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => handleAction(window.pp_open_logs, 'logs', 'Opened logs')}
|
||||
>
|
||||
<FileText className="h-4 w-4" /> Logs
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>View log files</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="gap-2 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => handleAction(window.pp_open_auth_folder, 'auth', 'Opened auth folder')}
|
||||
>
|
||||
<FolderOpen className="h-4 w-4" /> Auth Folder
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Open authentication files folder</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="gap-2 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => handleAction(window.pp_copy_diagnostics, 'diag-copy', 'Copied to clipboard')}
|
||||
>
|
||||
<Copy className="h-4 w-4" /> Copy Diagnostics
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Copy diagnostics to clipboard</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="gap-2 text-muted-foreground hover:text-foreground"
|
||||
disabled={!isRunning}
|
||||
onClick={() => handleAction(window.pp_open_diagnostics, 'diag-open', 'Opened diagnostics')}
|
||||
>
|
||||
<Activity className="h-4 w-4" /> Diagnostics
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Open diagnostics panel</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="gap-2 text-muted-foreground hover:text-foreground"
|
||||
disabled={!isRunning}
|
||||
onClick={() => handleAction(window.pp_open_legacy_ui, 'legacy', 'Opened advanced UI')}
|
||||
>
|
||||
<Settings className="h-4 w-4" /> Advanced
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Open advanced management UI</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
{/* Private OAuth Toggle */}
|
||||
<div className="flex items-center justify-between rounded-lg bg-muted/30 border border-border/50 p-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<Shield className="h-5 w-5 text-muted-foreground" />
|
||||
<Label htmlFor="private-oauth" className="text-sm cursor-pointer">
|
||||
Open OAuth in private window
|
||||
</Label>
|
||||
</div>
|
||||
<Switch
|
||||
id="private-oauth"
|
||||
checked={privateOAuth}
|
||||
onCheckedChange={handlePrivateOAuthChange}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Terminal, Check, X } from 'lucide-react'
|
||||
import { useProxyContext } from '@/hooks/useProxyContext'
|
||||
|
||||
interface Integration {
|
||||
id: string
|
||||
name?: string
|
||||
detected: boolean
|
||||
binary_path?: string
|
||||
config_path?: string
|
||||
}
|
||||
|
||||
export function Integrations() {
|
||||
const { mgmtKey, mgmtFetch, showToast } = useProxyContext()
|
||||
const [integrations, setIntegrations] = useState<Integration[]>([])
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const fetchIntegrations = async () => {
|
||||
if (!mgmtKey) return
|
||||
setLoading(true)
|
||||
try {
|
||||
const data = await mgmtFetch('/v0/management/integrations/status')
|
||||
setIntegrations(data.integrations || [])
|
||||
} catch (e) {
|
||||
console.error('Failed to fetch integrations:', e)
|
||||
}
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
const configureIntegration = async (integrationId: string) => {
|
||||
try {
|
||||
await mgmtFetch(`/v0/management/integrations/${integrationId}/configure`, {
|
||||
method: 'POST',
|
||||
})
|
||||
await fetchIntegrations()
|
||||
showToast(`Configured ${integrationId}`, 'success')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (mgmtKey) fetchIntegrations()
|
||||
}, [mgmtKey])
|
||||
|
||||
return (
|
||||
<Card className="backdrop-blur-sm bg-card/60 border-border/50 shadow-xl">
|
||||
<CardHeader className="pb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-10 w-10 rounded-xl bg-green-500/10 flex items-center justify-center">
|
||||
<Terminal className="h-5 w-5 text-green-500" />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<CardTitle className="text-lg">CLI Agent Integrations</CardTitle>
|
||||
<CardDescription>Detected AI coding assistants</CardDescription>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => fetchIntegrations()}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? 'Loading...' : 'Refresh'}
|
||||
</Button>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||
{integrations.length === 0 && !loading && (
|
||||
<div className="col-span-full text-center text-sm text-muted-foreground py-4">
|
||||
No integrations detected. Click Refresh to scan for CLI agents.
|
||||
</div>
|
||||
)}
|
||||
{integrations.map((integration) => (
|
||||
<div
|
||||
key={integration.id}
|
||||
className="rounded-lg border border-border/50 bg-muted/30 p-4 space-y-3"
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="font-medium text-sm">{integration.name || integration.id}</span>
|
||||
{integration.detected ? (
|
||||
<Check className="h-5 w-5 text-green-500" />
|
||||
) : (
|
||||
<X className="h-5 w-5 text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
{integration.detected && (
|
||||
<>
|
||||
{integration.binary_path && (
|
||||
<div className="text-xs text-muted-foreground truncate" title={integration.binary_path}>
|
||||
<span className="font-mono">Binary:</span> {integration.binary_path}
|
||||
</div>
|
||||
)}
|
||||
{integration.config_path && (
|
||||
<div className="text-xs text-muted-foreground truncate" title={integration.config_path}>
|
||||
<span className="font-mono">Config:</span> {integration.config_path}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
disabled={!integration.detected}
|
||||
onClick={() => configureIntegration(integration.id)}
|
||||
>
|
||||
Configure
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import { useState } from 'react'
|
||||
import { useProxyContext } from '@/hooks/useProxyContext'
|
||||
import { Card, CardHeader, CardTitle, CardDescription, CardContent } from '@/components/ui/card'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Copy, FileText } from 'lucide-react'
|
||||
|
||||
export function LogsViewer() {
|
||||
const { mgmtFetch, showToast } = useProxyContext()
|
||||
const [diagnostics, setDiagnostics] = useState('')
|
||||
const [logText, setLogText] = useState('')
|
||||
const [activeLogType, setActiveLogType] = useState<'stdout' | 'stderr'>('stdout')
|
||||
|
||||
const loadDiagnostics = async () => {
|
||||
try {
|
||||
const res = await mgmtFetch('/v0/management/proxypilot/diagnostics?lines=120')
|
||||
setDiagnostics(res.text || '')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
const copyDiagnostics = async () => {
|
||||
if (!diagnostics) {
|
||||
showToast('No diagnostics to copy', 'error')
|
||||
return
|
||||
}
|
||||
try {
|
||||
await navigator.clipboard.writeText(diagnostics)
|
||||
showToast('Copied diagnostics to clipboard', 'success')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
const tailLogs = async (kind: 'stdout' | 'stderr') => {
|
||||
try {
|
||||
setActiveLogType(kind)
|
||||
const res = await mgmtFetch(`/v0/management/proxypilot/logs/tail?file=${kind}&lines=200`)
|
||||
setLogText((res.lines || []).join('\n'))
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid gap-6 lg:grid-cols-2">
|
||||
{/* Diagnostics Card */}
|
||||
<Card className="backdrop-blur-sm bg-card/60 border-border/50 shadow-xl">
|
||||
<CardHeader className="pb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-10 w-10 rounded-xl bg-blue-500/10 flex items-center justify-center">
|
||||
<FileText className="h-5 w-5 text-blue-500" />
|
||||
</div>
|
||||
<div>
|
||||
<CardTitle className="text-lg">Diagnostics</CardTitle>
|
||||
<CardDescription>Engine snapshot</CardDescription>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="flex gap-2">
|
||||
<Button size="sm" variant="outline" onClick={loadDiagnostics}>
|
||||
Load
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={copyDiagnostics}
|
||||
disabled={!diagnostics}
|
||||
className="gap-2"
|
||||
>
|
||||
<Copy className="h-4 w-4" />
|
||||
Copy
|
||||
</Button>
|
||||
</div>
|
||||
<pre className="max-h-48 overflow-auto rounded-md border border-border/50 bg-muted/30 p-2 text-xs">
|
||||
{diagnostics || 'No diagnostics loaded.'}
|
||||
</pre>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Logs Tail Card */}
|
||||
<Card className="backdrop-blur-sm bg-card/60 border-border/50 shadow-xl">
|
||||
<CardHeader className="pb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-10 w-10 rounded-xl bg-green-500/10 flex items-center justify-center">
|
||||
<FileText className="h-5 w-5 text-green-500" />
|
||||
</div>
|
||||
<div>
|
||||
<CardTitle className="text-lg">Logs (tail)</CardTitle>
|
||||
<CardDescription>Engine stdout/stderr</CardDescription>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant={activeLogType === 'stdout' ? 'default' : 'outline'}
|
||||
onClick={() => tailLogs('stdout')}
|
||||
>
|
||||
Stdout
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant={activeLogType === 'stderr' ? 'default' : 'outline'}
|
||||
onClick={() => tailLogs('stderr')}
|
||||
>
|
||||
Stderr
|
||||
</Button>
|
||||
</div>
|
||||
<pre className="max-h-48 overflow-auto rounded-md border border-border/50 bg-muted/30 p-2 text-xs">
|
||||
{logText || 'No logs loaded.'}
|
||||
</pre>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,641 @@
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Separator } from '@/components/ui/separator'
|
||||
import {
|
||||
Database,
|
||||
Download,
|
||||
Upload,
|
||||
Trash2,
|
||||
RefreshCw,
|
||||
Save,
|
||||
FileText,
|
||||
Anchor,
|
||||
ListTodo,
|
||||
Pin,
|
||||
Scissors,
|
||||
Brain,
|
||||
} from 'lucide-react'
|
||||
import { useProxyContext } from '@/hooks/useProxyContext'
|
||||
|
||||
interface MemorySession {
|
||||
key: string;
|
||||
updated_at?: string;
|
||||
summary?: string;
|
||||
pinned?: string;
|
||||
todo?: string;
|
||||
semantic_disabled?: boolean;
|
||||
}
|
||||
|
||||
interface PruneConfig {
|
||||
maxAgeDays: number;
|
||||
maxSessions: number;
|
||||
maxBytesPerSession: number;
|
||||
maxNamespaces: number;
|
||||
maxBytesPerNamespace: number;
|
||||
}
|
||||
|
||||
const downloadBlob = (blob: Blob, filename: string) => {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
export function MemoryManager() {
|
||||
const { mgmtKey, mgmtFetch, showToast } = useProxyContext()
|
||||
|
||||
// Session state
|
||||
const [memorySessions, setMemorySessions] = useState<MemorySession[]>([])
|
||||
const [memorySession, setMemorySession] = useState('')
|
||||
const [memoryDetails, setMemoryDetails] = useState<MemorySession | null>(null)
|
||||
|
||||
// Session details
|
||||
const [memorySummary, setMemorySummary] = useState('')
|
||||
const [memoryPinned, setMemoryPinned] = useState('')
|
||||
const [memoryTodo, setMemoryTodo] = useState('')
|
||||
const [memorySemanticEnabled, setMemorySemanticEnabled] = useState(true)
|
||||
|
||||
// Events and anchors
|
||||
const [memoryEvents, setMemoryEvents] = useState('')
|
||||
const [memoryAnchors, setMemoryAnchors] = useState('')
|
||||
const [memoryEventsLimit, setMemoryEventsLimit] = useState(120)
|
||||
const [memoryAnchorsLimit, setMemoryAnchorsLimit] = useState(20)
|
||||
|
||||
// Import
|
||||
const [memoryImportReplace, setMemoryImportReplace] = useState(false)
|
||||
|
||||
// Prune configuration
|
||||
const [memoryPrune, setMemoryPrune] = useState<PruneConfig>({
|
||||
maxAgeDays: 30,
|
||||
maxSessions: 200,
|
||||
maxBytesPerSession: 2000000,
|
||||
maxNamespaces: 200,
|
||||
maxBytesPerNamespace: 2000000,
|
||||
})
|
||||
|
||||
// Load sessions list
|
||||
const loadMemorySessions = useCallback(async () => {
|
||||
try {
|
||||
const res = await mgmtFetch('/v0/management/memory/sessions?limit=200')
|
||||
const sessions = res.sessions || []
|
||||
setMemorySessions(sessions)
|
||||
if (!memorySession && sessions.length > 0) {
|
||||
setMemorySession(sessions[0].key)
|
||||
}
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}, [mgmtFetch, showToast, memorySession])
|
||||
|
||||
// Load session details
|
||||
const loadMemorySessionDetails = useCallback(async () => {
|
||||
if (!memorySession) {
|
||||
setMemoryDetails(null)
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await mgmtFetch(`/v0/management/memory/session?session=${encodeURIComponent(memorySession)}`)
|
||||
const session = res.session || null
|
||||
setMemoryDetails(session)
|
||||
if (session) {
|
||||
setMemorySummary(session.summary || '')
|
||||
setMemoryPinned(session.pinned || '')
|
||||
setMemoryTodo(session.todo || '')
|
||||
setMemorySemanticEnabled(!session.semantic_disabled)
|
||||
}
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}, [memorySession, mgmtFetch, showToast])
|
||||
|
||||
// Load events
|
||||
const loadMemoryEvents = useCallback(async () => {
|
||||
if (!memorySession) {
|
||||
setMemoryEvents('Select a session.')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await mgmtFetch(`/v0/management/memory/events?session=${encodeURIComponent(memorySession)}&limit=${encodeURIComponent(memoryEventsLimit)}`)
|
||||
const events = res.events || []
|
||||
if (!Array.isArray(events) || events.length === 0) {
|
||||
setMemoryEvents('No events.')
|
||||
return
|
||||
}
|
||||
const lines = events.map((e: any) => {
|
||||
const ts = e.ts || ''
|
||||
const kind = e.kind || ''
|
||||
const role = e.role || ''
|
||||
const text = (e.text || '').toString()
|
||||
return `[${ts}][${kind}][${role}] ${text}`
|
||||
})
|
||||
setMemoryEvents(lines.join('\n\n'))
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}, [memorySession, memoryEventsLimit, mgmtFetch, showToast])
|
||||
|
||||
// Load anchors
|
||||
const loadMemoryAnchors = useCallback(async () => {
|
||||
if (!memorySession) {
|
||||
setMemoryAnchors('Select a session.')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await mgmtFetch(`/v0/management/memory/anchors?session=${encodeURIComponent(memorySession)}&limit=${encodeURIComponent(memoryAnchorsLimit)}`)
|
||||
const anchors = res.anchors || []
|
||||
if (!Array.isArray(anchors) || anchors.length === 0) {
|
||||
setMemoryAnchors('No anchors.')
|
||||
return
|
||||
}
|
||||
const lines = anchors.map((a: any) => {
|
||||
const ts = a.ts || ''
|
||||
const summary = (a.summary || '').toString()
|
||||
return `[${ts}]\n${summary}`
|
||||
})
|
||||
setMemoryAnchors(lines.join('\n\n---\n\n'))
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}, [memorySession, memoryAnchorsLimit, mgmtFetch, showToast])
|
||||
|
||||
// Save TODO
|
||||
const saveMemoryTodo = async () => {
|
||||
if (!memorySession) return
|
||||
try {
|
||||
await mgmtFetch('/v0/management/memory/todo', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ session: memorySession, value: memoryTodo }),
|
||||
})
|
||||
await loadMemorySessionDetails()
|
||||
showToast('Saved TODO', 'success')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
// Save pinned context
|
||||
const saveMemoryPinned = async () => {
|
||||
if (!memorySession) return
|
||||
try {
|
||||
await mgmtFetch('/v0/management/memory/pinned', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ session: memorySession, value: memoryPinned }),
|
||||
})
|
||||
await loadMemorySessionDetails()
|
||||
showToast('Saved pinned context', 'success')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
// Save summary
|
||||
const saveMemorySummary = async () => {
|
||||
if (!memorySession) return
|
||||
try {
|
||||
await mgmtFetch('/v0/management/memory/summary', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ session: memorySession, value: memorySummary }),
|
||||
})
|
||||
await loadMemorySessionDetails()
|
||||
showToast('Saved anchor summary', 'success')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
// Toggle semantic memory
|
||||
const toggleMemorySemantic = async (enabled: boolean) => {
|
||||
if (!memorySession) return
|
||||
try {
|
||||
await mgmtFetch('/v0/management/memory/semantic', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ session: memorySession, enabled }),
|
||||
})
|
||||
setMemorySemanticEnabled(enabled)
|
||||
await loadMemorySessionDetails()
|
||||
showToast(`Semantic ${enabled ? 'enabled' : 'disabled'}`, 'success')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
// Delete session
|
||||
const deleteMemorySession = async () => {
|
||||
if (!memorySession) return
|
||||
try {
|
||||
await mgmtFetch(`/v0/management/memory/session?session=${encodeURIComponent(memorySession)}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
setMemorySession('')
|
||||
setMemoryDetails(null)
|
||||
setMemoryEvents('')
|
||||
setMemoryAnchors('')
|
||||
await loadMemorySessions()
|
||||
showToast('Deleted session', 'success')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
// Export session
|
||||
const exportMemorySession = async () => {
|
||||
if (!memorySession || !mgmtKey) return
|
||||
try {
|
||||
const res = await fetch(`/v0/management/memory/export?session=${encodeURIComponent(memorySession)}`, {
|
||||
headers: { 'X-Management-Key': mgmtKey },
|
||||
})
|
||||
if (!res.ok) {
|
||||
const msg = await res.text()
|
||||
throw new Error(msg)
|
||||
}
|
||||
const blob = await res.blob()
|
||||
downloadBlob(blob, `proxypilot-session-${memorySession}.zip`)
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
// Export all sessions
|
||||
const exportAllMemory = async () => {
|
||||
if (!mgmtKey) return
|
||||
try {
|
||||
const res = await fetch('/v0/management/memory/export-all', {
|
||||
headers: { 'X-Management-Key': mgmtKey },
|
||||
})
|
||||
if (!res.ok) {
|
||||
const msg = await res.text()
|
||||
throw new Error(msg)
|
||||
}
|
||||
const blob = await res.blob()
|
||||
downloadBlob(blob, 'proxypilot-memory-all.zip')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
// Delete all sessions
|
||||
const deleteAllMemory = async () => {
|
||||
if (!mgmtKey) return
|
||||
if (!window.confirm('Delete all memory data? This cannot be undone.')) return
|
||||
try {
|
||||
await mgmtFetch('/v0/management/memory/delete-all?confirm=true', { method: 'POST' })
|
||||
setMemorySession('')
|
||||
setMemoryDetails(null)
|
||||
setMemoryEvents('')
|
||||
setMemoryAnchors('')
|
||||
await loadMemorySessions()
|
||||
showToast('Deleted all memory', 'success')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
// Import session
|
||||
const importMemorySession = async (file: File | null) => {
|
||||
if (!file || !memorySession || !mgmtKey) return
|
||||
try {
|
||||
const form = new FormData()
|
||||
form.append('file', file)
|
||||
const res = await fetch(`/v0/management/memory/import?session=${encodeURIComponent(memorySession)}&replace=${memoryImportReplace ? 'true' : 'false'}`, {
|
||||
method: 'POST',
|
||||
headers: { 'X-Management-Key': mgmtKey },
|
||||
body: form,
|
||||
})
|
||||
if (!res.ok) {
|
||||
const msg = await res.text()
|
||||
throw new Error(msg)
|
||||
}
|
||||
await loadMemorySessionDetails()
|
||||
showToast('Imported session', 'success')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
// Prune memory
|
||||
const pruneMemory = async () => {
|
||||
try {
|
||||
await mgmtFetch('/v0/management/memory/prune', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
max_age_days: memoryPrune.maxAgeDays,
|
||||
max_sessions: memoryPrune.maxSessions,
|
||||
max_bytes_per_session: memoryPrune.maxBytesPerSession,
|
||||
max_namespaces: memoryPrune.maxNamespaces,
|
||||
max_bytes_per_namespace: memoryPrune.maxBytesPerNamespace,
|
||||
}),
|
||||
})
|
||||
await loadMemorySessions()
|
||||
showToast('Prune completed', 'success')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
// Load sessions on mount
|
||||
useEffect(() => {
|
||||
if (mgmtKey) {
|
||||
loadMemorySessions()
|
||||
}
|
||||
}, [mgmtKey, loadMemorySessions])
|
||||
|
||||
if (!mgmtKey) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="backdrop-blur-sm bg-card/60 border-border/50 shadow-xl">
|
||||
<CardHeader className="pb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-10 w-10 rounded-xl bg-violet-500/10 flex items-center justify-center">
|
||||
<Database className="h-5 w-5 text-violet-500" />
|
||||
</div>
|
||||
<div>
|
||||
<CardTitle className="text-lg">Memory</CardTitle>
|
||||
<CardDescription>Anchors, pinned context, TODOs, and session history</CardDescription>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
{/* Action buttons */}
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button size="sm" variant="outline" onClick={loadMemorySessions} className="gap-1">
|
||||
<RefreshCw className="h-3 w-3" />
|
||||
Refresh sessions
|
||||
</Button>
|
||||
<Button size="sm" variant="outline" onClick={loadMemorySessionDetails} className="gap-1">
|
||||
<FileText className="h-3 w-3" />
|
||||
Load session
|
||||
</Button>
|
||||
<Button size="sm" variant="outline" onClick={loadMemoryEvents} className="gap-1">
|
||||
<FileText className="h-3 w-3" />
|
||||
Events
|
||||
</Button>
|
||||
<Button size="sm" variant="outline" onClick={loadMemoryAnchors} className="gap-1">
|
||||
<Anchor className="h-3 w-3" />
|
||||
Anchors
|
||||
</Button>
|
||||
<Button size="sm" variant="outline" onClick={exportMemorySession} className="gap-1">
|
||||
<Download className="h-3 w-3" />
|
||||
Export
|
||||
</Button>
|
||||
<Button size="sm" variant="outline" onClick={exportAllMemory} className="gap-1">
|
||||
<Download className="h-3 w-3" />
|
||||
Export all
|
||||
</Button>
|
||||
<Button size="sm" variant="destructive" onClick={deleteMemorySession} className="gap-1">
|
||||
<Trash2 className="h-3 w-3" />
|
||||
Delete
|
||||
</Button>
|
||||
<Button size="sm" variant="destructive" onClick={deleteAllMemory} className="gap-1">
|
||||
<Trash2 className="h-3 w-3" />
|
||||
Delete all
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Session selector and limits */}
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<select
|
||||
className="min-w-[220px] rounded-md border border-border bg-background/60 px-2 py-1 text-xs font-mono"
|
||||
value={memorySession}
|
||||
onChange={(e) => setMemorySession(e.target.value)}
|
||||
>
|
||||
{memorySessions.length === 0 && <option value="">(no sessions)</option>}
|
||||
{memorySessions.map((s) => (
|
||||
<option key={s.key} value={s.key}>
|
||||
{s.key}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="flex items-center gap-1">
|
||||
<Label htmlFor="events-limit" className="text-xs text-muted-foreground">Events:</Label>
|
||||
<input
|
||||
id="events-limit"
|
||||
type="number"
|
||||
min={10}
|
||||
max={500}
|
||||
className="w-20 rounded-md border border-border bg-background/60 px-2 py-1 text-xs"
|
||||
value={memoryEventsLimit}
|
||||
onChange={(e) => setMemoryEventsLimit(parseInt(e.target.value || '120', 10))}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<Label htmlFor="anchors-limit" className="text-xs text-muted-foreground">Anchors:</Label>
|
||||
<input
|
||||
id="anchors-limit"
|
||||
type="number"
|
||||
min={5}
|
||||
max={200}
|
||||
className="w-20 rounded-md border border-border bg-background/60 px-2 py-1 text-xs"
|
||||
value={memoryAnchorsLimit}
|
||||
onChange={(e) => setMemoryAnchorsLimit(parseInt(e.target.value || '20', 10))}
|
||||
/>
|
||||
</div>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{memoryDetails?.updated_at ? `Updated ${memoryDetails.updated_at}` : 'No session loaded.'}
|
||||
</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<Brain className="h-4 w-4 text-muted-foreground" />
|
||||
<Label htmlFor="semantic-toggle" className="text-xs text-muted-foreground cursor-pointer">
|
||||
Semantic
|
||||
</Label>
|
||||
<Switch
|
||||
id="semantic-toggle"
|
||||
checked={memorySemanticEnabled}
|
||||
disabled={!memorySession}
|
||||
onCheckedChange={toggleMemorySemantic}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Separator className="bg-border/50" />
|
||||
|
||||
{/* Session details: Summary, Pinned, TODO */}
|
||||
<div className="grid gap-4 lg:grid-cols-3">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Anchor className="h-3 w-3" />
|
||||
Anchor summary
|
||||
</div>
|
||||
<textarea
|
||||
className="h-40 w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs font-mono resize-y"
|
||||
value={memorySummary}
|
||||
onChange={(e) => setMemorySummary(e.target.value)}
|
||||
placeholder="Session anchor summary..."
|
||||
/>
|
||||
<Button size="sm" variant="outline" onClick={saveMemorySummary} className="gap-1">
|
||||
<Save className="h-3 w-3" />
|
||||
Save summary
|
||||
</Button>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Pin className="h-3 w-3" />
|
||||
Pinned context
|
||||
</div>
|
||||
<textarea
|
||||
className="h-40 w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs font-mono resize-y"
|
||||
value={memoryPinned}
|
||||
onChange={(e) => setMemoryPinned(e.target.value)}
|
||||
placeholder="Pinned context that persists across turns..."
|
||||
/>
|
||||
<Button size="sm" variant="outline" onClick={saveMemoryPinned} className="gap-1">
|
||||
<Save className="h-3 w-3" />
|
||||
Save pinned
|
||||
</Button>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<ListTodo className="h-3 w-3" />
|
||||
TODO
|
||||
</div>
|
||||
<textarea
|
||||
className="h-40 w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs font-mono resize-y"
|
||||
value={memoryTodo}
|
||||
onChange={(e) => setMemoryTodo(e.target.value)}
|
||||
placeholder="Session TODO list..."
|
||||
/>
|
||||
<Button size="sm" variant="outline" onClick={saveMemoryTodo} className="gap-1">
|
||||
<Save className="h-3 w-3" />
|
||||
Save TODO
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Separator className="bg-border/50" />
|
||||
|
||||
{/* Events and Anchors display */}
|
||||
<div className="grid gap-4 lg:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<FileText className="h-3 w-3" />
|
||||
Events
|
||||
</div>
|
||||
<pre className="max-h-56 overflow-auto rounded-md border border-border/50 bg-muted/30 p-2 text-xs whitespace-pre-wrap">
|
||||
{memoryEvents || 'No events loaded.'}
|
||||
</pre>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Anchor className="h-3 w-3" />
|
||||
Anchors
|
||||
</div>
|
||||
<pre className="max-h-56 overflow-auto rounded-md border border-border/50 bg-muted/30 p-2 text-xs whitespace-pre-wrap">
|
||||
{memoryAnchors || 'No anchors loaded.'}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Separator className="bg-border/50" />
|
||||
|
||||
{/* Import and Prune */}
|
||||
<div className="grid gap-4 lg:grid-cols-2">
|
||||
{/* Import section */}
|
||||
<div className="space-y-2 p-3 rounded-lg bg-muted/30 border border-border/50">
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Upload className="h-3 w-3" />
|
||||
Import session (zip)
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<input
|
||||
type="file"
|
||||
accept=".zip"
|
||||
className="text-xs file:mr-2 file:py-1 file:px-2 file:rounded file:border-0 file:text-xs file:bg-primary file:text-primary-foreground hover:file:bg-primary/90"
|
||||
onChange={(e) => importMemorySession(e.target.files?.[0] || null)}
|
||||
/>
|
||||
<div className="flex items-center gap-2">
|
||||
<Switch
|
||||
id="import-replace"
|
||||
checked={memoryImportReplace}
|
||||
onCheckedChange={setMemoryImportReplace}
|
||||
/>
|
||||
<Label htmlFor="import-replace" className="text-xs text-muted-foreground cursor-pointer">
|
||||
Replace existing
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Prune section */}
|
||||
<div className="space-y-2 p-3 rounded-lg bg-muted/30 border border-border/50">
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Scissors className="h-3 w-3" />
|
||||
Prune limits
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="prune-age" className="text-xs text-muted-foreground">Max age (days)</Label>
|
||||
<input
|
||||
id="prune-age"
|
||||
type="number"
|
||||
min={0}
|
||||
className="w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs"
|
||||
value={memoryPrune.maxAgeDays}
|
||||
onChange={(e) => setMemoryPrune({ ...memoryPrune, maxAgeDays: parseInt(e.target.value || '0', 10) })}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="prune-sessions" className="text-xs text-muted-foreground">Max sessions</Label>
|
||||
<input
|
||||
id="prune-sessions"
|
||||
type="number"
|
||||
min={0}
|
||||
className="w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs"
|
||||
value={memoryPrune.maxSessions}
|
||||
onChange={(e) => setMemoryPrune({ ...memoryPrune, maxSessions: parseInt(e.target.value || '0', 10) })}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="prune-namespaces" className="text-xs text-muted-foreground">Max namespaces</Label>
|
||||
<input
|
||||
id="prune-namespaces"
|
||||
type="number"
|
||||
min={0}
|
||||
className="w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs"
|
||||
value={memoryPrune.maxNamespaces}
|
||||
onChange={(e) => setMemoryPrune({ ...memoryPrune, maxNamespaces: parseInt(e.target.value || '0', 10) })}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="prune-bytes-session" className="text-xs text-muted-foreground">Max bytes/session</Label>
|
||||
<input
|
||||
id="prune-bytes-session"
|
||||
type="number"
|
||||
min={0}
|
||||
className="w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs"
|
||||
value={memoryPrune.maxBytesPerSession}
|
||||
onChange={(e) => setMemoryPrune({ ...memoryPrune, maxBytesPerSession: parseInt(e.target.value || '0', 10) })}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1 col-span-2">
|
||||
<Label htmlFor="prune-bytes-namespace" className="text-xs text-muted-foreground">Max bytes/namespace</Label>
|
||||
<input
|
||||
id="prune-bytes-namespace"
|
||||
type="number"
|
||||
min={0}
|
||||
className="w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs"
|
||||
value={memoryPrune.maxBytesPerNamespace}
|
||||
onChange={(e) => setMemoryPrune({ ...memoryPrune, maxBytesPerNamespace: parseInt(e.target.value || '0', 10) })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<Button size="sm" variant="outline" onClick={pruneMemory} className="gap-1 mt-2">
|
||||
<Scissors className="h-3 w-3" />
|
||||
Prune memory
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useProxyContext } from '@/hooks/useProxyContext'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { ArrowRight, Plus, Trash2, Pencil, Check, X } from 'lucide-react'
|
||||
|
||||
interface ModelMapping {
|
||||
from: string
|
||||
to: string
|
||||
provider: string
|
||||
}
|
||||
|
||||
export function ModelMappings() {
|
||||
const { mgmtKey, mgmtFetch, showToast } = useProxyContext()
|
||||
|
||||
const [modelMappings, setModelMappings] = useState<ModelMapping[]>([])
|
||||
const [newMapping, setNewMapping] = useState<ModelMapping>({ from: '', to: '', provider: '' })
|
||||
const [editingMapping, setEditingMapping] = useState<number | null>(null)
|
||||
const [editingMappingValues, setEditingMappingValues] = useState<ModelMapping>({ from: '', to: '', provider: '' })
|
||||
const [mappingTestInput, setMappingTestInput] = useState('')
|
||||
const [mappingTestResult, setMappingTestResult] = useState('')
|
||||
|
||||
const fetchModelMappings = async () => {
|
||||
try {
|
||||
const data = await mgmtFetch('/v0/management/model-mappings')
|
||||
setModelMappings(data.mappings || [])
|
||||
} catch (e) {
|
||||
console.error('Failed to fetch model mappings:', e)
|
||||
}
|
||||
}
|
||||
|
||||
const addModelMapping = async () => {
|
||||
if (!newMapping.from.trim() || !newMapping.to.trim()) {
|
||||
showToast('Both "from" and "to" fields are required', 'error')
|
||||
return
|
||||
}
|
||||
try {
|
||||
await mgmtFetch('/v0/management/model-mappings', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(newMapping),
|
||||
})
|
||||
setNewMapping({ from: '', to: '', provider: '' })
|
||||
await fetchModelMappings()
|
||||
showToast('Mapping added', 'success')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
const updateModelMapping = async (index: number, mapping: ModelMapping) => {
|
||||
try {
|
||||
await mgmtFetch(`/v0/management/model-mappings/${index}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(mapping),
|
||||
})
|
||||
setEditingMapping(null)
|
||||
await fetchModelMappings()
|
||||
showToast('Mapping updated', 'success')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
const deleteModelMapping = async (index: number) => {
|
||||
try {
|
||||
await mgmtFetch(`/v0/management/model-mappings/${index}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
await fetchModelMappings()
|
||||
showToast('Mapping deleted', 'success')
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
const testModelMapping = async () => {
|
||||
if (!mappingTestInput.trim()) {
|
||||
setMappingTestResult('Enter a model name to test')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const data = await mgmtFetch(`/v0/management/model-mappings/test?model=${encodeURIComponent(mappingTestInput.trim())}`)
|
||||
setMappingTestResult(JSON.stringify(data, null, 2))
|
||||
} catch (e) {
|
||||
setMappingTestResult(e instanceof Error ? e.message : String(e))
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (mgmtKey) {
|
||||
fetchModelMappings()
|
||||
}
|
||||
}, [mgmtKey])
|
||||
|
||||
if (!mgmtKey) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="backdrop-blur-sm bg-card/60 border-border/50 shadow-xl">
|
||||
<CardHeader className="pb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-10 w-10 rounded-xl bg-orange-500/10 flex items-center justify-center">
|
||||
<ArrowRight className="h-5 w-5 text-orange-500" />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<CardTitle className="text-lg">Global Model Mappings</CardTitle>
|
||||
<CardDescription>Rewrite model names before routing</CardDescription>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => fetchModelMappings().catch((e) => showToast(String(e), 'error'))}
|
||||
>
|
||||
Refresh
|
||||
</Button>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
{/* Add new mapping form */}
|
||||
<div className="flex flex-wrap items-end gap-3 p-3 rounded-lg bg-muted/30 border border-border/50">
|
||||
<div className="flex-1 min-w-[150px] space-y-1">
|
||||
<label className="text-xs text-muted-foreground">From model</label>
|
||||
<input
|
||||
type="text"
|
||||
className="w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs font-mono"
|
||||
placeholder="gpt-4"
|
||||
value={newMapping.from}
|
||||
onChange={(e) => setNewMapping({ ...newMapping, from: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1 min-w-[150px] space-y-1">
|
||||
<label className="text-xs text-muted-foreground">To model</label>
|
||||
<input
|
||||
type="text"
|
||||
className="w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs font-mono"
|
||||
placeholder="claude-3-opus"
|
||||
value={newMapping.to}
|
||||
onChange={(e) => setNewMapping({ ...newMapping, to: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1 min-w-[120px] space-y-1">
|
||||
<label className="text-xs text-muted-foreground">Provider (optional)</label>
|
||||
<input
|
||||
type="text"
|
||||
className="w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs font-mono"
|
||||
placeholder="anthropic"
|
||||
value={newMapping.provider}
|
||||
onChange={(e) => setNewMapping({ ...newMapping, provider: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="default"
|
||||
onClick={() => addModelMapping().catch((e) => showToast(String(e), 'error'))}
|
||||
className="gap-1"
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
Add
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Mappings list */}
|
||||
<div className="max-h-64 overflow-auto rounded-md border border-border/50">
|
||||
<table className="w-full text-xs">
|
||||
<thead className="bg-muted/40 sticky top-0">
|
||||
<tr>
|
||||
<th className="px-3 py-2 text-left">From</th>
|
||||
<th className="px-3 py-2 text-left"></th>
|
||||
<th className="px-3 py-2 text-left">To</th>
|
||||
<th className="px-3 py-2 text-left">Provider</th>
|
||||
<th className="px-3 py-2 text-left">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{modelMappings.length === 0 && (
|
||||
<tr>
|
||||
<td className="px-3 py-3 text-muted-foreground" colSpan={5}>
|
||||
No model mappings configured.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{modelMappings.map((mapping, index) => (
|
||||
<tr key={index} className="border-t border-border/40">
|
||||
{editingMapping === index ? (
|
||||
<>
|
||||
<td className="px-3 py-2">
|
||||
<input
|
||||
type="text"
|
||||
className="w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs font-mono"
|
||||
value={editingMappingValues.from}
|
||||
onChange={(e) => setEditingMappingValues(v => ({ ...v, from: e.target.value }))}
|
||||
/>
|
||||
</td>
|
||||
<td className="px-3 py-2 text-muted-foreground">
|
||||
<ArrowRight className="h-4 w-4" />
|
||||
</td>
|
||||
<td className="px-3 py-2">
|
||||
<input
|
||||
type="text"
|
||||
className="w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs font-mono"
|
||||
value={editingMappingValues.to}
|
||||
onChange={(e) => setEditingMappingValues(v => ({ ...v, to: e.target.value }))}
|
||||
/>
|
||||
</td>
|
||||
<td className="px-3 py-2">
|
||||
<input
|
||||
type="text"
|
||||
className="w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs font-mono"
|
||||
value={editingMappingValues.provider}
|
||||
onChange={(e) => setEditingMappingValues(v => ({ ...v, provider: e.target.value }))}
|
||||
/>
|
||||
</td>
|
||||
<td className="px-3 py-2">
|
||||
<div className="flex gap-1">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 p-0"
|
||||
onClick={() => {
|
||||
updateModelMapping(index, editingMappingValues)
|
||||
.catch((e) => showToast(String(e), 'error'))
|
||||
}}
|
||||
>
|
||||
<Check className="h-4 w-4 text-green-500" />
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 p-0"
|
||||
onClick={() => setEditingMapping(null)}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</td>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<td className="px-3 py-2 font-mono">{mapping.from}</td>
|
||||
<td className="px-3 py-2 text-muted-foreground">
|
||||
<ArrowRight className="h-4 w-4" />
|
||||
</td>
|
||||
<td className="px-3 py-2 font-mono">{mapping.to}</td>
|
||||
<td className="px-3 py-2 font-mono text-muted-foreground">
|
||||
{mapping.provider || '-'}
|
||||
</td>
|
||||
<td className="px-3 py-2">
|
||||
<div className="flex gap-1">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 p-0"
|
||||
onClick={() => {
|
||||
setEditingMapping(index)
|
||||
setEditingMappingValues({
|
||||
from: mapping.from || '',
|
||||
to: mapping.to || '',
|
||||
provider: mapping.provider || '',
|
||||
})
|
||||
}}
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 p-0 text-destructive hover:text-destructive"
|
||||
onClick={() => deleteModelMapping(index).catch((e) => showToast(String(e), 'error'))}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</td>
|
||||
</>
|
||||
)}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{/* Test mapping */}
|
||||
<div className="flex flex-wrap items-end gap-3 p-3 rounded-lg bg-muted/30 border border-border/50">
|
||||
<div className="flex-1 min-w-[200px] space-y-1">
|
||||
<label className="text-xs text-muted-foreground">Test model name</label>
|
||||
<input
|
||||
type="text"
|
||||
className="w-full rounded-md border border-border bg-background/60 px-2 py-1 text-xs font-mono"
|
||||
placeholder="Enter model to test mapping"
|
||||
value={mappingTestInput}
|
||||
onChange={(e) => setMappingTestInput(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => testModelMapping().catch((e) => showToast(String(e), 'error'))}
|
||||
>
|
||||
Test
|
||||
</Button>
|
||||
</div>
|
||||
{mappingTestResult && (
|
||||
<pre className="max-h-24 overflow-auto rounded-md border border-border/50 bg-muted/30 p-2 text-xs">
|
||||
{mappingTestResult}
|
||||
</pre>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Key, ExternalLink, Info } from 'lucide-react'
|
||||
import { useProxyContext } from '@/hooks/useProxyContext'
|
||||
|
||||
const providers = [
|
||||
{ id: 'antigravity', name: 'Antigravity', color: 'from-purple-500 to-indigo-600' },
|
||||
{ id: 'gemini-cli', name: 'Gemini CLI', color: 'from-blue-500 to-cyan-500' },
|
||||
{ id: 'codex', name: 'Codex', color: 'from-green-500 to-emerald-600' },
|
||||
{ id: 'claude', name: 'Claude', color: 'from-orange-500 to-amber-500' },
|
||||
{ id: 'qwen', name: 'Qwen', color: 'from-pink-500 to-rose-500' },
|
||||
{ id: 'iflow', name: 'iFlow', color: 'from-teal-500 to-cyan-600' },
|
||||
]
|
||||
|
||||
export function ProviderLogins() {
|
||||
const { loading, setLoading, showToast } = useProxyContext()
|
||||
|
||||
const handleOAuth = async (provider: string) => {
|
||||
setLoading(`oauth-${provider}`)
|
||||
try {
|
||||
if (window.pp_oauth) {
|
||||
await window.pp_oauth(provider)
|
||||
showToast(`Opening ${provider} login...`, 'success')
|
||||
}
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
} finally {
|
||||
setLoading(null)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="backdrop-blur-sm bg-card/60 border-border/50 shadow-xl">
|
||||
<CardHeader className="pb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-10 w-10 rounded-xl bg-purple-500/10 flex items-center justify-center">
|
||||
<Key className="h-5 w-5 text-purple-500" />
|
||||
</div>
|
||||
<div>
|
||||
<CardTitle className="text-lg">Provider Logins</CardTitle>
|
||||
<CardDescription>Authenticate with AI providers</CardDescription>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
{providers.map((provider) => (
|
||||
<Button
|
||||
key={provider.id}
|
||||
variant="outline"
|
||||
className={`relative overflow-hidden transition-all duration-300 hover:border-primary/50 group h-12 bg-background/50`}
|
||||
onClick={() => handleOAuth(provider.id)}
|
||||
disabled={loading === `oauth-${provider.id}`}
|
||||
>
|
||||
<div className={`absolute inset-0 bg-gradient-to-r ${provider.color} opacity-0 group-hover:opacity-10 transition-opacity duration-300`} />
|
||||
<span className="relative flex items-center gap-2 font-medium">
|
||||
<ExternalLink className="h-4 w-4 opacity-50 group-hover:opacity-100 transition-opacity" />
|
||||
{provider.name}
|
||||
</span>
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="flex items-start gap-3 rounded-lg bg-blue-500/5 border border-blue-500/10 p-4">
|
||||
<Info className="h-5 w-5 text-blue-500 mt-0.5 flex-shrink-0" />
|
||||
<p className="text-sm text-muted-foreground leading-relaxed">
|
||||
Click a provider to open their login flow in your browser. Authentication tokens will be saved locally for ProxyPilot to use.
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { useProxyContext } from '@/hooks/useProxyContext'
|
||||
|
||||
interface SemanticHealthData {
|
||||
status?: string
|
||||
model?: string
|
||||
version?: string
|
||||
model_present?: boolean
|
||||
latency_ms?: number
|
||||
queue?: {
|
||||
queued: number
|
||||
dropped: number
|
||||
processed: number
|
||||
failed: number
|
||||
}
|
||||
}
|
||||
|
||||
interface SemanticNamespace {
|
||||
key: string
|
||||
label?: string
|
||||
}
|
||||
|
||||
interface SemanticItem {
|
||||
ts?: string
|
||||
source?: string
|
||||
role?: string
|
||||
text?: string
|
||||
}
|
||||
|
||||
export function SemanticMemory() {
|
||||
const { mgmtKey, mgmtFetch, showToast } = useProxyContext()
|
||||
|
||||
const [semanticHealth, setSemanticHealth] = useState<SemanticHealthData | null>(null)
|
||||
const [semanticNamespaces, setSemanticNamespaces] = useState<SemanticNamespace[]>([])
|
||||
const [semanticNamespace, setSemanticNamespace] = useState('')
|
||||
const [semanticLimit, setSemanticLimit] = useState(50)
|
||||
const [semanticItems, setSemanticItems] = useState('')
|
||||
|
||||
const loadSemanticHealth = useCallback(async () => {
|
||||
try {
|
||||
const res = await mgmtFetch('/v0/management/semantic/health')
|
||||
setSemanticHealth(res)
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}, [mgmtFetch, showToast])
|
||||
|
||||
const loadSemanticNamespaces = useCallback(async () => {
|
||||
try {
|
||||
const res = await mgmtFetch('/v0/management/semantic/namespaces')
|
||||
const namespaces = res.namespaces || []
|
||||
setSemanticNamespaces(namespaces)
|
||||
if (!semanticNamespace && namespaces.length > 0) {
|
||||
setSemanticNamespace(namespaces[0].key)
|
||||
}
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}, [mgmtFetch, showToast, semanticNamespace])
|
||||
|
||||
const loadSemanticItems = useCallback(async () => {
|
||||
if (!semanticNamespace) {
|
||||
setSemanticItems('Select a namespace.')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await mgmtFetch(
|
||||
`/v0/management/semantic/items?namespace=${encodeURIComponent(semanticNamespace)}&limit=${encodeURIComponent(semanticLimit)}`
|
||||
)
|
||||
const items: SemanticItem[] = res.items || []
|
||||
if (!Array.isArray(items) || items.length === 0) {
|
||||
setSemanticItems('No items.')
|
||||
return
|
||||
}
|
||||
const lines = items.map((it) => {
|
||||
const ts = it.ts || ''
|
||||
const src = it.source || ''
|
||||
const role = it.role || ''
|
||||
const text = (it.text || '').toString()
|
||||
return `[${ts}][${src}][${role}] ${text}`
|
||||
})
|
||||
setSemanticItems(lines.join('\n\n'))
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
}
|
||||
}, [mgmtFetch, showToast, semanticNamespace, semanticLimit])
|
||||
|
||||
// Load initial data when mgmtKey is available
|
||||
useEffect(() => {
|
||||
if (mgmtKey) {
|
||||
loadSemanticHealth()
|
||||
loadSemanticNamespaces()
|
||||
}
|
||||
}, [mgmtKey, loadSemanticHealth, loadSemanticNamespaces])
|
||||
|
||||
if (!mgmtKey) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="backdrop-blur-sm bg-card/60 border-border/50 shadow-xl">
|
||||
<CardHeader className="pb-4">
|
||||
<CardTitle className="text-lg">Semantic Memory</CardTitle>
|
||||
<CardDescription>Ollama embeddings + per-repo namespaces</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{/* Health Status */}
|
||||
<div className="flex items-center gap-2">
|
||||
<Button size="sm" variant="outline" onClick={loadSemanticHealth}>
|
||||
Refresh
|
||||
</Button>
|
||||
<Badge variant={semanticHealth?.status === 'ok' ? 'default' : 'secondary'}>
|
||||
{semanticHealth?.status || 'unknown'}
|
||||
</Badge>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{semanticHealth?.model} {semanticHealth?.version ? `v${semanticHealth.version}` : ''}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{semanticHealth?.model_present === false ? 'model missing' : ''}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Queue Statistics */}
|
||||
<div className="text-xs text-muted-foreground">
|
||||
{semanticHealth?.latency_ms ? `latency ${semanticHealth.latency_ms}ms` : 'latency n/a'}
|
||||
{semanticHealth?.queue
|
||||
? ` · queue q${semanticHealth.queue.queued} d${semanticHealth.queue.dropped} p${semanticHealth.queue.processed} f${semanticHealth.queue.failed}`
|
||||
: ''}
|
||||
</div>
|
||||
|
||||
{/* Namespace Selection and Items */}
|
||||
<div className="flex items-center gap-2">
|
||||
<select
|
||||
className="min-w-[200px] rounded-md border border-border bg-background/60 px-2 py-1 text-xs font-mono"
|
||||
value={semanticNamespace}
|
||||
onChange={(e) => setSemanticNamespace(e.target.value)}
|
||||
>
|
||||
{semanticNamespaces.length === 0 && <option value="">(no namespaces)</option>}
|
||||
{semanticNamespaces.map((n) => (
|
||||
<option key={n.key} value={n.key}>
|
||||
{n.label || n.key}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<input
|
||||
type="number"
|
||||
min={10}
|
||||
max={200}
|
||||
className="w-20 rounded-md border border-border bg-background/60 px-2 py-1 text-xs"
|
||||
value={semanticLimit}
|
||||
onChange={(e) => setSemanticLimit(parseInt(e.target.value || '50', 10))}
|
||||
/>
|
||||
<Button size="sm" variant="outline" onClick={loadSemanticItems}>
|
||||
Load
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Items Display */}
|
||||
<pre className="max-h-56 overflow-auto rounded-md border border-border/50 bg-muted/30 p-2 text-xs">
|
||||
{semanticItems || 'No items loaded.'}
|
||||
</pre>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export { EngineControl } from './EngineControl'
|
||||
export { ProviderLogins } from './ProviderLogins'
|
||||
export { Integrations } from './Integrations'
|
||||
export { SemanticMemory } from './SemanticMemory'
|
||||
export { LogsViewer } from './LogsViewer'
|
||||
export { ModelMappings } from './ModelMappings'
|
||||
export { MemoryManager } from './MemoryManager'
|
||||
@@ -0,0 +1,53 @@
|
||||
import * as React from "react"
|
||||
import * as TabsPrimitive from "@radix-ui/react-tabs"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Tabs = TabsPrimitive.Root
|
||||
|
||||
const TabsList = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.List>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.List
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"inline-flex h-10 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TabsList.displayName = TabsPrimitive.List.displayName
|
||||
|
||||
const TabsTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
|
||||
|
||||
const TabsContent = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"mt-4 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TabsContent.displayName = TabsPrimitive.Content.displayName
|
||||
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent }
|
||||
@@ -0,0 +1,27 @@
|
||||
import { Moon, Sun, Monitor } from 'lucide-react'
|
||||
import { Button } from './button'
|
||||
import { useTheme } from '@/hooks/useTheme'
|
||||
|
||||
export function ThemeToggle() {
|
||||
const { theme, setTheme } = useTheme()
|
||||
|
||||
const cycleTheme = () => {
|
||||
if (theme === 'dark') setTheme('light')
|
||||
else if (theme === 'light') setTheme('system')
|
||||
else setTheme('dark')
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={cycleTheme}
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
title={`Theme: ${theme}`}
|
||||
>
|
||||
{theme === 'dark' && <Moon className="h-4 w-4" />}
|
||||
{theme === 'light' && <Sun className="h-4 w-4" />}
|
||||
{theme === 'system' && <Monitor className="h-4 w-4" />}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
import { createContext, useContext, useEffect, useState, useCallback } from 'react'
|
||||
import type { ReactNode } from 'react'
|
||||
|
||||
// Type declarations for desktop app bindings
|
||||
declare global {
|
||||
interface Window {
|
||||
pp_status?: () => Promise<ProxyStatus>;
|
||||
pp_start?: () => Promise<void>;
|
||||
pp_stop?: () => Promise<void>;
|
||||
pp_restart?: () => Promise<void>;
|
||||
pp_open_logs?: () => Promise<void>;
|
||||
pp_open_auth_folder?: () => Promise<void>;
|
||||
pp_open_legacy_ui?: () => Promise<void>;
|
||||
pp_open_diagnostics?: () => Promise<void>;
|
||||
pp_get_oauth_private?: () => Promise<boolean>;
|
||||
pp_set_oauth_private?: (enabled: boolean) => Promise<void>;
|
||||
pp_oauth?: (provider: string) => Promise<void>;
|
||||
pp_copy_diagnostics?: () => Promise<void>;
|
||||
pp_get_management_key?: () => Promise<string>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ProxyStatus {
|
||||
running: boolean;
|
||||
port: number;
|
||||
base_url: string;
|
||||
last_error: string;
|
||||
}
|
||||
|
||||
interface ProxyContextType {
|
||||
status: ProxyStatus | null;
|
||||
isDesktop: boolean;
|
||||
mgmtKey: string | null;
|
||||
loading: string | null;
|
||||
setLoading: (id: string | null) => void;
|
||||
refreshStatus: () => Promise<void>;
|
||||
showToast: (message: string, type?: 'success' | 'error') => void;
|
||||
toast: { message: string; type: 'success' | 'error' } | null;
|
||||
mgmtFetch: (path: string, opts?: RequestInit) => Promise<any>;
|
||||
handleAction: (action: (() => Promise<void>) | undefined, actionId: string, successMsg: string) => Promise<void>;
|
||||
}
|
||||
|
||||
const ProxyContext = createContext<ProxyContextType | null>(null)
|
||||
|
||||
export function useProxyContext() {
|
||||
const ctx = useContext(ProxyContext)
|
||||
if (!ctx) throw new Error('useProxyContext must be used within ProxyProvider')
|
||||
return ctx
|
||||
}
|
||||
|
||||
export function ProxyProvider({ children }: { children: ReactNode }) {
|
||||
const [status, setStatus] = useState<ProxyStatus | null>(null)
|
||||
const [mgmtKey, setMgmtKey] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState<string | null>(null)
|
||||
const [toast, setToast] = useState<{ message: string; type: 'success' | 'error' } | null>(null)
|
||||
|
||||
const isDesktop = typeof window.pp_status === 'function'
|
||||
|
||||
const showToast = useCallback((message: string, type: 'success' | 'error' = 'success') => {
|
||||
setToast({ message, type })
|
||||
setTimeout(() => setToast(null), 2500)
|
||||
}, [])
|
||||
|
||||
const refreshStatus = useCallback(async () => {
|
||||
try {
|
||||
if (window.pp_status) {
|
||||
const s = await window.pp_status()
|
||||
setStatus(s)
|
||||
} else {
|
||||
const res = await fetch('/healthz')
|
||||
if (!res.ok) {
|
||||
setStatus({ running: false, port: 0, base_url: location.origin, last_error: res.statusText })
|
||||
return
|
||||
}
|
||||
const body = await res.json().catch(() => ({}))
|
||||
setStatus({
|
||||
running: true,
|
||||
port: body.port || 0,
|
||||
base_url: location.origin,
|
||||
last_error: '',
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Status error:', e)
|
||||
}
|
||||
}, [])
|
||||
|
||||
const mgmtFetch = useCallback(async (path: string, opts: RequestInit = {}) => {
|
||||
if (!mgmtKey) throw new Error('Missing management key')
|
||||
const headers = Object.assign({}, opts.headers || {}, { 'X-Management-Key': mgmtKey })
|
||||
const res = await fetch(path, { ...opts, headers })
|
||||
const ct = (res.headers.get('content-type') || '').toLowerCase()
|
||||
const body = ct.includes('application/json') ? await res.json() : await res.text()
|
||||
if (!res.ok) {
|
||||
const msg = typeof body === 'string' ? body : body?.error ? body.error : JSON.stringify(body)
|
||||
throw new Error(`${res.status} ${res.statusText}: ${msg}`)
|
||||
}
|
||||
return body
|
||||
}, [mgmtKey])
|
||||
|
||||
const handleAction = useCallback(async (
|
||||
action: (() => Promise<void>) | undefined,
|
||||
actionId: string,
|
||||
successMsg: string
|
||||
) => {
|
||||
if (!action) return
|
||||
setLoading(actionId)
|
||||
try {
|
||||
await action()
|
||||
showToast(successMsg, 'success')
|
||||
await refreshStatus()
|
||||
} catch (e) {
|
||||
showToast(e instanceof Error ? e.message : String(e), 'error')
|
||||
} finally {
|
||||
setLoading(null)
|
||||
}
|
||||
}, [showToast, refreshStatus])
|
||||
|
||||
// Initialize on mount
|
||||
useEffect(() => {
|
||||
refreshStatus()
|
||||
const interval = setInterval(refreshStatus, 1200)
|
||||
|
||||
;(async () => {
|
||||
try {
|
||||
if (window.pp_get_management_key) {
|
||||
const key = await window.pp_get_management_key()
|
||||
setMgmtKey(key)
|
||||
} else if (!isDesktop) {
|
||||
const meta = document.querySelector('meta[name="pp-mgmt-key"]')
|
||||
setMgmtKey(meta ? meta.getAttribute('content') : null)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Management key error:', e)
|
||||
}
|
||||
})()
|
||||
|
||||
return () => clearInterval(interval)
|
||||
}, [refreshStatus, isDesktop])
|
||||
|
||||
return (
|
||||
<ProxyContext.Provider value={{
|
||||
status,
|
||||
isDesktop,
|
||||
mgmtKey,
|
||||
loading,
|
||||
setLoading,
|
||||
refreshStatus,
|
||||
showToast,
|
||||
toast,
|
||||
mgmtFetch,
|
||||
handleAction,
|
||||
}}>
|
||||
{children}
|
||||
</ProxyContext.Provider>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
type Theme = 'light' | 'dark' | 'system'
|
||||
|
||||
export function useTheme() {
|
||||
const [theme, setThemeState] = useState<Theme>(() => {
|
||||
if (typeof window === 'undefined') return 'dark'
|
||||
const stored = localStorage.getItem('pp-theme') as Theme | null
|
||||
return stored || 'dark'
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
const root = document.documentElement
|
||||
const systemDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
|
||||
const effectiveTheme = theme === 'system' ? (systemDark ? 'dark' : 'light') : theme
|
||||
|
||||
root.classList.remove('light', 'dark')
|
||||
root.classList.add(effectiveTheme)
|
||||
localStorage.setItem('pp-theme', theme)
|
||||
}, [theme])
|
||||
|
||||
// Listen for system theme changes
|
||||
useEffect(() => {
|
||||
if (theme !== 'system') return
|
||||
|
||||
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
|
||||
const handler = (e: MediaQueryListEvent) => {
|
||||
const root = document.documentElement
|
||||
root.classList.remove('light', 'dark')
|
||||
root.classList.add(e.matches ? 'dark' : 'light')
|
||||
}
|
||||
|
||||
mediaQuery.addEventListener('change', handler)
|
||||
return () => mediaQuery.removeEventListener('change', handler)
|
||||
}, [theme])
|
||||
|
||||
const setTheme = (newTheme: Theme) => {
|
||||
setThemeState(newTheme)
|
||||
}
|
||||
|
||||
return { theme, setTheme }
|
||||
}
|
||||
Reference in New Issue
Block a user