Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(desktop): add provider selection UI

Jiang Bohan197b77e04320
diff --git a/apps/desktop/src/components/api-key-dialog.tsx b/apps/desktop/src/components/api-key-dialog.tsx
new file mode 100644
index 0000000000..672cc9a8c2
--- /dev/null
+++ b/apps/desktop/src/components/api-key-dialog.tsx
@@ -0,0 +1,121 @@
+import { useState } from 'react'
+import {
+ Dialog,
+ DialogContent,
+ DialogHeader,
+ DialogFooter,
+ DialogTitle,
+ DialogDescription,
+} from '@multica/ui/components/ui/dialog'
+import { Button } from '@multica/ui/components/ui/button'
+import { Input } from '@multica/ui/components/ui/input'
+import { Label } from '@multica/ui/components/ui/label'
+import { HugeiconsIcon } from '@hugeicons/react'
+import { Loading03Icon, Key01Icon } from '@hugeicons/core-free-icons'
+
+interface ApiKeyDialogProps {
+ open: boolean
+ onOpenChange: (open: boolean) => void
+ providerId: string
+ providerName: string
+ onSuccess?: () => void
+}
+
+export function ApiKeyDialog({
+ open,
+ onOpenChange,
+ providerId,
+ providerName,
+ onSuccess,
+}: ApiKeyDialogProps) {
+ const [apiKey, setApiKey] = useState('')
+ const [saving, setSaving] = useState(false)
+ const [error, setError] = useState<string | null>(null)
+
+ const handleSave = async () => {
+ if (!apiKey.trim()) {
+ setError('API key is required')
+ return
+ }
+
+ setSaving(true)
+ setError(null)
+
+ try {
+ const result = await window.electronAPI.provider.saveApiKey(providerId, apiKey.trim())
+ if (result.ok) {
+ setApiKey('')
+ onOpenChange(false)
+ onSuccess?.()
+ } else {
+ setError(result.error ?? 'Failed to save API key')
+ }
+ } catch (err) {
+ const message = err instanceof Error ? err.message : String(err)
+ setError(message)
+ } finally {
+ setSaving(false)
+ }
+ }
+
+ const handleClose = (isOpen: boolean) => {
+ if (!isOpen) {
+ setApiKey('')
+ setError(null)
+ }
+ onOpenChange(isOpen)
+ }
+
+ return (
+ <Dialog open={open} onOpenChange={handleClose}>
+ <DialogContent className="max-w-md">
+ <DialogHeader>
+ <DialogTitle className="flex items-center gap-2">
+ <HugeiconsIcon icon={Key01Icon} className="size-5" />
+ Configure {providerName}
+ </DialogTitle>
+ <DialogDescription>
+ Enter your API key to enable {providerName}. The key will be saved securely in your credentials file.
+ </DialogDescription>
+ </DialogHeader>
+
+ <div className="space-y-4">
+ <div className="space-y-2">
+ <Label htmlFor="api-key">API Key</Label>
+ <Input
+ id="api-key"
+ type="password"
+ value={apiKey}
+ onChange={(e) => setApiKey(e.target.value)}
+ placeholder="sk-..."
+ onKeyDown={(e) => {
+ if (e.key === 'Enter' && !saving) {
+ handleSave()
+ }
+ }}
+ />
+ {error && (
+ <p className="text-sm text-destructive">{error}</p>
+ )}
+ </div>
+
+ <p className="text-xs text-muted-foreground">
+ Your API key is stored locally in <code className="bg-muted px-1 rounded">~/.super-multica/credentials.json5</code>
+ </p>
+ </div>
+
+ <DialogFooter>
+ <Button variant="outline" onClick={() => handleClose(false)} disabled={saving}>
+ Cancel
+ </Button>
+ <Button onClick={handleSave} disabled={saving || !apiKey.trim()}>
+ {saving && <HugeiconsIcon icon={Loading03Icon} className="size-4 animate-spin mr-2" />}
+ Save
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ )
+}
+
+export default ApiKeyDialog
diff --git a/apps/desktop/src/components/oauth-dialog.tsx b/apps/desktop/src/components/oauth-dialog.tsx
new file mode 100644
index 0000000000..e6573cf0b8
--- /dev/null
+++ b/apps/desktop/src/components/oauth-dialog.tsx
@@ -0,0 +1,146 @@
+import { useState } from 'react'
+import {
+ Dialog,
+ DialogContent,
+ DialogHeader,
+ DialogFooter,
+ DialogTitle,
+ DialogDescription,
+} from '@multica/ui/components/ui/dialog'
+import { Button } from '@multica/ui/components/ui/button'
+import { HugeiconsIcon } from '@hugeicons/react'
+import { Loading03Icon, CommandLineIcon, RefreshIcon, Tick02Icon } from '@hugeicons/core-free-icons'
+
+interface OAuthDialogProps {
+ open: boolean
+ onOpenChange: (open: boolean) => void
+ providerId: string
+ providerName: string
+ loginCommand?: string
+ onSuccess?: () => void
+}
+
+export function OAuthDialog({
+ open,
+ onOpenChange,
+ providerId,
+ providerName,
+ loginCommand,
+ onSuccess,
+}: OAuthDialogProps) {
+ const [importing, setImporting] = useState(false)
+ const [error, setError] = useState<string | null>(null)
+ const [success, setSuccess] = useState(false)
+ const [expiresAt, setExpiresAt] = useState<number | null>(null)
+
+ const handleImport = async () => {
+ setImporting(true)
+ setError(null)
+ setSuccess(false)
+
+ try {
+ const result = await window.electronAPI.provider.importOAuth(providerId)
+ if (result.ok) {
+ setSuccess(true)
+ setExpiresAt(result.expiresAt ?? null)
+ // Auto-close after a short delay
+ setTimeout(() => {
+ onOpenChange(false)
+ onSuccess?.()
+ }, 1500)
+ } else {
+ setError(result.error ?? 'Failed to import credentials')
+ }
+ } catch (err) {
+ const message = err instanceof Error ? err.message : String(err)
+ setError(message)
+ } finally {
+ setImporting(false)
+ }
+ }
+
+ const handleClose = (isOpen: boolean) => {
+ if (!isOpen) {
+ setError(null)
+ setSuccess(false)
+ setExpiresAt(null)
+ }
+ onOpenChange(isOpen)
+ }
+
+ const formatExpiry = (timestamp: number) => {
+ const remaining = timestamp - Date.now()
+ if (remaining <= 0) return 'expired'
+ const hours = Math.floor(remaining / (60 * 60 * 1000))
+ const minutes = Math.floor((remaining % (60 * 60 * 1000)) / (60 * 1000))
+ if (hours > 0) return `${hours}h ${minutes}m`
+ return `${minutes}m`
+ }
+
+ return (
+ <Dialog open={open} onOpenChange={handleClose}>
+ <DialogContent className="max-w-md">
+ <DialogHeader>
+ <DialogTitle className="flex items-center gap-2">
+ <HugeiconsIcon icon={CommandLineIcon} className="size-5" />
+ Configure {providerName}
+ </DialogTitle>
+ <DialogDescription>
+ {providerName} uses OAuth authentication. Please log in via the command line first.
+ </DialogDescription>
+ </DialogHeader>
+
+ <div className="space-y-4">
+ {/* Login instructions */}
+ <div className="space-y-2">
+ <p className="text-sm text-muted-foreground">
+ 1. Open your terminal and run:
+ </p>
+ <div className="bg-muted rounded-md p-3 font-mono text-sm">
+ {loginCommand ?? `${providerId} login`}
+ </div>
+ <p className="text-sm text-muted-foreground">
+ 2. Complete the login process in your browser
+ </p>
+ <p className="text-sm text-muted-foreground">
+ 3. Click "Refresh" below to import your credentials
+ </p>
+ </div>
+
+ {/* Status messages */}
+ {error && (
+ <div className="bg-destructive/10 text-destructive rounded-md p-3 text-sm">
+ {error}
+ </div>
+ )}
+
+ {success && (
+ <div className="bg-green-500/10 text-green-600 dark:text-green-400 rounded-md p-3 text-sm flex items-center gap-2">
+ <HugeiconsIcon icon={Tick02Icon} className="size-4" />
+ <span>
+ Credentials imported successfully!
+ {expiresAt && ` (expires in ${formatExpiry(expiresAt)})`}
+ </span>
+ </div>
+ )}
+ </div>
+
+ <DialogFooter>
+ <Button variant="outline" onClick={() => handleClose(false)} disabled={importing}>
+ Cancel
+ </Button>
+ <Button onClick={handleImport} disabled={importing || success}>
+ {importing ? (
+ <HugeiconsIcon icon={Loading03Icon} className="size-4 animate-spin mr-2" />
+ ) : (
+ <HugeiconsIcon icon={RefreshIcon} className="size-4 mr-2" />
+ )}
+ Refresh
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ )
+}
+
+export default OAuthDialog
diff --git a/apps/desktop/src/hooks/use-provider.ts b/apps/desktop/src/hooks/use-provider.ts
new file mode 100644
index 0000000000..99cae5403a
--- /dev/null
+++ b/apps/desktop/src/hooks/use-provider.ts
@@ -0,0 +1,101 @@
+/**
+ * Hook for managing LLM providers in the Desktop App.
+ *
+ * Provides functionality similar to CLI `/provider` command:
+ * - List all providers with status
+ * - Get current provider/model
+ * - Switch provider/model
+ */
+import { useState, useEffect, useCallback } from 'react'
+
+// Types are defined in electron-env.d.ts and available globally
+
+interface UseProviderReturn {
+ /** All providers with their status */
+ providers: ProviderStatus[]
+ /** Only available (configured) providers */
+ availableProviders: ProviderStatus[]
+ /** Current provider and model info */
+ current: CurrentProviderInfo | null
+ /** Loading state */
+ loading: boolean
+ /** Error message if any */
+ error: string | null
+ /** Refresh provider list and current status */
+ refresh: () => Promise<void>
+ /** Switch to a different provider (and optionally model) */
+ setProvider: (providerId: string, modelId?: string) => Promise<{ ok: boolean; error?: string }>
+ /** Get metadata for a specific provider */
+ getProviderMeta: (providerId: string) => ProviderStatus | undefined
+}
+
+export function useProvider(): UseProviderReturn {
+ const [providers, setProviders] = useState<ProviderStatus[]>([])
+ const [current, setCurrent] = useState<CurrentProviderInfo | null>(null)
+ const [loading, setLoading] = useState(true)
+ const [error, setError] = useState<string | null>(null)
+
+ const refresh = useCallback(async () => {
+ setLoading(true)
+ setError(null)
+
+ try {
+ const [providerList, currentInfo] = await Promise.all([
+ window.electronAPI.provider.list(),
+ window.electronAPI.provider.current(),
+ ])
+
+ setProviders(providerList)
+ setCurrent(currentInfo)
+ } catch (err) {
+ const message = err instanceof Error ? err.message : String(err)
+ setError(message)
+ console.error('[useProvider] Failed to load providers:', message)
+ } finally {
+ setLoading(false)
+ }
+ }, [])
+
+ // Load providers on mount
+ useEffect(() => {
+ refresh()
+ }, [refresh])
+
+ const setProvider = useCallback(async (providerId: string, modelId?: string) => {
+ setError(null)
+
+ try {
+ const result = await window.electronAPI.provider.set(providerId, modelId)
+
+ if (result.ok) {
+ // Refresh to update current status
+ await refresh()
+ return { ok: true }
+ } else {
+ setError(result.error ?? 'Unknown error')
+ return { ok: false, error: result.error }
+ }
+ } catch (err) {
+ const message = err instanceof Error ? err.message : String(err)
+ setError(message)
+ return { ok: false, error: message }
+ }
+ }, [refresh])
+
+ const getProviderMeta = useCallback((providerId: string) => {
+ return providers.find((p) => p.id === providerId)
+ }, [providers])
+
+ const availableProviders = providers.filter((p) => p.available)
+
+ return {
+ providers,
+ availableProviders,
+ current,
+ loading,
+ error,
+ refresh,
+ setProvider,
+ getProviderMeta,
+ }
+}
diff --git a/apps/desktop/src/pages/home.tsx b/apps/desktop/src/pages/home.tsx
index ba2767f0ba..56396e53ba 100644
--- a/apps/desktop/src/pages/home.tsx
+++ b/apps/desktop/src/pages/home.tsx
@@ -1,4 +1,4 @@
-import { useState, useEffect } from 'react'
+import { useState, useEffect, useRef } from 'react'
import { useNavigate } from 'react-router-dom'
import { Button } from '@multica/ui/components/ui/button'
import { HugeiconsIcon } from '@hugeicons/react'
@@ -8,17 +8,52 @@ import {
Loading03Icon,
AlertCircleIcon,
Edit02Icon,
+ ArrowDown01Icon,
+ Tick02Icon,
+ Alert02Icon,
} from '@hugeicons/core-free-icons'
import { ConnectionQRCode } from '../components/qr-code'
import { DeviceList } from '../components/device-list'
import { AgentSettingsDialog } from '../components/agent-settings-dialog'
+import { ApiKeyDialog } from '../components/api-key-dialog'
+import { OAuthDialog } from '../components/oauth-dialog'
import { useHub } from '../hooks/use-hub'
+import { useProvider } from '../hooks/use-provider'
export default function HomePage() {
const navigate = useNavigate()
const { hubInfo, agents, loading, error } = useHub()
+ const { providers, current, setProvider, refresh, loading: providerLoading } = useProvider()
const [settingsOpen, setSettingsOpen] = useState(false)
const [agentName, setAgentName] = useState<string | undefined>()
+ const [providerDropdownOpen, setProviderDropdownOpen] = useState(false)
+ const [switching, setSwitching] = useState(false)
+ const [apiKeyDialogOpen, setApiKeyDialogOpen] = useState(false)
+ const [oauthDialogOpen, setOauthDialogOpen] = useState(false)
+ const [selectedProvider, setSelectedProvider] = useState<{
+ id: string
+ name: string
+ authMethod: 'api-key' | 'oauth'
+ loginCommand?: string
+ } | null>(null)
+ const dropdownRef = useRef<HTMLDivElement>(null)
+
+ // Close dropdown when clicking outside
+ useEffect(() => {
+ const handleClickOutside = (event: MouseEvent) => {
+ if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
+ setProviderDropdownOpen(false)
+ }
+ }
+
+ if (providerDropdownOpen) {
+ document.addEventListener('mousedown', handleClickOutside)
+ }
+
+ return () => {
+ document.removeEventListener('mousedown', handleClickOutside)
+ }
+ }, [providerDropdownOpen])
// Load agent profile info
useEffect(() => {
@@ -151,6 +186,92 @@ export default function HomePage() {
<p className="font-medium">{agentName || 'Unnamed Agent'}</p>
</div>
+ {/* Provider Selector */}
+ <div className="p-4 rounded-lg bg-muted/50 border border-border/50 relative" ref={dropdownRef}>
+ <p className="text-xs text-muted-foreground uppercase tracking-wider mb-2">
+ LLM Provider
+ </p>
+ <button
+ className="w-full flex items-center justify-between p-3 rounded-md bg-background border border-border hover:bg-accent/50 transition-colors disabled:opacity-50"
+ onClick={() => setProviderDropdownOpen(!providerDropdownOpen)}
+ disabled={providerLoading || switching}
+ >
+ <div className="flex items-center gap-2">
+ {current?.available ? (
+ <HugeiconsIcon icon={Tick02Icon} className="size-4 text-green-500" />
+ ) : (
+ <HugeiconsIcon icon={Alert02Icon} className="size-4 text-yellow-500" />
+ )}
+ <div className="text-left">
+ <p className="font-medium text-sm">{current?.providerName ?? current?.provider ?? 'Loading...'}</p>
+ <p className="text-xs text-muted-foreground">{current?.model ?? '-'}</p>
+ </div>
+ </div>
+ <HugeiconsIcon
+ icon={ArrowDown01Icon}
+ className={`size-4 text-muted-foreground transition-transform ${providerDropdownOpen ? 'rotate-180' : ''}`}
+ />
+ </button>
+
+ {/* Provider Dropdown - Compact Grid */}
+ {providerDropdownOpen && (
+ <div className="absolute left-0 right-0 top-full mt-1 z-10 bg-background border border-border rounded-md shadow-lg p-2">
+ <div className="grid grid-cols-3 gap-1.5">
+ {providers.map((p) => (
+ <button
+ key={p.id}
+ className={`flex items-center gap-1.5 px-2 py-1.5 rounded text-left text-xs transition-colors ${
+ p.id === current?.provider
+ ? 'bg-primary/10 border border-primary/30'
+ : 'hover:bg-accent/50 border border-transparent'
+ } ${!p.available ? 'opacity-60 hover:opacity-80' : ''}`}
+ onClick={async () => {
+ if (!p.available) {
+ // Show config dialog for unavailable providers
+ setSelectedProvider({
+ id: p.id,
+ name: p.name,
+ authMethod: p.authMethod,
+ loginCommand: p.loginCommand,
+ })
+ setProviderDropdownOpen(false)
+ if (p.authMethod === 'oauth') {
+ setOauthDialogOpen(true)
+ } else {
+ setApiKeyDialogOpen(true)
+ }
+ return
+ }
+ setSwitching(true)
+ setProviderDropdownOpen(false)
+ const result = await setProvider(p.id)
+ setSwitching(false)
+ if (!result.ok) {
+ console.error('Failed to switch provider:', result.error)
+ }
+ }}
+ disabled={switching}
+ title={`${p.name}\n${p.authMethod === 'oauth' ? 'OAuth' : 'API Key'} · ${p.defaultModel}`}
+ >
+ <span className={`size-1.5 rounded-full flex-shrink-0 ${
+ p.available ? 'bg-green-500' : 'bg-muted-foreground/50'
+ }`} />
+ <span className="truncate font-medium">
+ {p.id === 'claude-code' ? 'Claude Code' :
+ p.id === 'openai-codex' ? 'Codex' :
+ p.id === 'kimi-coding' ? 'Kimi' :
+ p.id === 'anthropic' ? 'Anthropic' :
+ p.id === 'openai' ? 'OpenAI' :
+ p.id === 'openrouter' ? 'OpenRouter' :
+ p.name.split(' ')[0]}
+ </span>
+ </button>
+ ))}
+ </div>
+ </div>
+ )}
+ </div>
+
{/* Stats Grid */}
<div className="grid grid-cols-2 gap-4">
<div className="p-4 rounded-lg bg-muted/50 border border-border/50">
@@ -167,20 +288,6 @@ export default function HomePage() {
</p>
<p className="font-medium capitalize">{connectionState}</p>
</div>
- <div className="p-4 rounded-lg bg-muted/50 border border-border/50">
- <p className="text-xs text-muted-foreground uppercase tracking-wider mb-1">
- Active Agents
- </p>
- <p className="font-medium">{hubInfo?.agentCount ?? 0}</p>
- </div>
- <div className="p-4 rounded-lg bg-muted/50 border border-border/50">
- <p className="text-xs text-muted-foreground uppercase tracking-wider mb-1">
- Primary Agent
- </p>
- <p className="font-medium text-sm font-mono truncate" title={primaryAgent?.id}>
- {primaryAgent?.id ?? 'None'}
- </p>
- </div>
</div>
</div>
</div>
@@ -194,6 +301,43 @@ export default function HomePage() {
{/* Agent Settings Dialog */}
<AgentSettingsDialog open={settingsOpen} onOpenChange={setSettingsOpen} />
+ {/* API Key Dialog */}
+ {selectedProvider && selectedProvider.authMethod === 'api-key' && (
+ <ApiKeyDialog
+ open={apiKeyDialogOpen}
+ onOpenChange={setApiKeyDialogOpen}
+ providerId={selectedProvider.id}
+ providerName={selectedProvider.name}
+ onSuccess={async () => {
+ // Refresh provider list and switch to the newly configured provider
+ await refresh()
+ const result = await setProvider(selectedProvider.id)
+ if (!result.ok) {
+ console.error('Failed to switch provider:', result.error)
+ }
+ }}
+ />
+ )}
+
+ {/* OAuth Dialog */}
+ {selectedProvider && selectedProvider.authMethod === 'oauth' && (
+ <OAuthDialog
+ open={oauthDialogOpen}
+ onOpenChange={setOauthDialogOpen}
+ providerId={selectedProvider.id}
+ providerName={selectedProvider.name}
+ loginCommand={selectedProvider.loginCommand}
+ onSuccess={async () => {
+ // Refresh provider list and switch to the newly configured provider
+ await refresh()
+ const result = await setProvider(selectedProvider.id)
+ if (!result.ok) {
+ console.error('Failed to switch provider:', result.error)
+ }
+ }}
+ />
+ )}
+
{/* Bottom: Actions */}
<div className="border-t p-4">
<div className="flex items-center justify-between">