mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Add executionModel feature and refactor CLI into modular commands (#150)
* Add executionModel feature and refactor CLI into modular commands - Add executionModel config option to memory plugin for specifying AI provider/model - Refactor monolithic CLI into modular commands: export, import, list, stats, cleanup - Add model selector UI with connected providers and recent models - Add showClear prop to Combobox component - Update documentation and bump version to 0.0.10 * Update execution model placeholder text * Update docs with new CLI commands and ocm-mem binary usage * Bump version to v0.9.06 * Add executionModel field to default config
This commit is contained in:
1 parent
e5b2cab9d9
commit
c15e53fb98
22 files changed
+1719
-783
No files matched your search
@@ -1,11 +1,15 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useState, useEffect, useMemo } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Combobox } from '@/components/ui/combobox'
|
||||
import type { ComboboxOption } from '@/components/ui/combobox'
|
||||
import { getProviders } from '@/api/providers'
|
||||
import { useModelStore } from '@/stores/modelStore'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { ChevronDown, ChevronRight, Save, Loader2, Database, Brain, AlertCircle, RefreshCw, Play } from 'lucide-react'
|
||||
import { ChevronDown, ChevronRight, Save, Loader2, Database, Brain, AlertCircle, RefreshCw, Play, Cpu } from 'lucide-react'
|
||||
import { getPluginConfig, updatePluginConfig, reindexMemories, testEmbeddingConfig } from '@/api/memory'
|
||||
import { FetchError } from '@/api/fetchWrapper'
|
||||
import { settingsApi } from '@/api/settings'
|
||||
@@ -41,6 +45,54 @@ export function MemoryPluginConfig({ memoryPluginEnabled, onToggle }: MemoryPlug
|
||||
enabled: memoryPluginEnabled && expanded,
|
||||
})
|
||||
|
||||
const { data: providersData } = useQuery({
|
||||
queryKey: ['providers-for-execution-model'],
|
||||
queryFn: getProviders,
|
||||
staleTime: 60000,
|
||||
enabled: memoryPluginEnabled && expanded,
|
||||
})
|
||||
|
||||
const recentModels = useModelStore((s) => s.recentModels)
|
||||
|
||||
const executionModelOptions = useMemo<ComboboxOption[]>(() => {
|
||||
if (!providersData?.providers) return []
|
||||
|
||||
const connectedProviders = providersData.providers.filter((p) => p.isConnected)
|
||||
|
||||
const recentSet = new Set<string>()
|
||||
const recentOptions: ComboboxOption[] = []
|
||||
|
||||
for (const recent of recentModels) {
|
||||
const modelValue = `${recent.providerID}/${recent.modelID}`
|
||||
const provider = connectedProviders.find((p) => p.id === recent.providerID)
|
||||
const model = provider?.models[recent.modelID]
|
||||
if (!model || !provider) continue
|
||||
recentSet.add(modelValue)
|
||||
recentOptions.push({
|
||||
value: modelValue,
|
||||
label: model.name || model.id,
|
||||
description: provider.name,
|
||||
group: 'Recent',
|
||||
})
|
||||
}
|
||||
|
||||
const providerOptions: ComboboxOption[] = []
|
||||
for (const provider of connectedProviders.sort((a, b) => a.name.localeCompare(b.name))) {
|
||||
for (const [modelId, model] of Object.entries(provider.models)) {
|
||||
const modelValue = `${provider.id}/${modelId}`
|
||||
if (recentSet.has(modelValue)) continue
|
||||
providerOptions.push({
|
||||
value: modelValue,
|
||||
label: model.name || model.id,
|
||||
description: modelId,
|
||||
group: provider.name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return [...recentOptions, ...providerOptions]
|
||||
}, [providersData, recentModels])
|
||||
|
||||
const config = data?.config
|
||||
const [localConfig, setLocalConfig] = useState<PluginConfig | null>(null)
|
||||
|
||||
@@ -66,12 +118,8 @@ export function MemoryPluginConfig({ memoryPluginEnabled, onToggle }: MemoryPlug
|
||||
const updateMutation = useMutation({
|
||||
mutationFn: updatePluginConfig,
|
||||
onSuccess: (data) => {
|
||||
showToast.success('Memory plugin configuration saved')
|
||||
queryClient.setQueryData(['memory-plugin-config'], { config: data.config })
|
||||
},
|
||||
onError: () => {
|
||||
showToast.error('Failed to save configuration')
|
||||
},
|
||||
})
|
||||
|
||||
const reindexMutation = useMutation({
|
||||
@@ -112,16 +160,20 @@ export function MemoryPluginConfig({ memoryPluginEnabled, onToggle }: MemoryPlug
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!localConfig) return
|
||||
showToast.loading('Saving configuration...', { id: 'memory-save' })
|
||||
updateMutation.mutate(localConfig, {
|
||||
onSuccess: async () => {
|
||||
showToast.loading('Restarting OpenCode server...', { id: 'memory-restart' })
|
||||
showToast.loading('Restarting OpenCode server...', { id: 'memory-save' })
|
||||
try {
|
||||
await settingsApi.restartOpenCodeServer()
|
||||
showToast.success('Configuration saved and server restarted', { id: 'memory-restart' })
|
||||
showToast.success('Configuration saved and server restarted', { id: 'memory-save' })
|
||||
} catch {
|
||||
showToast.error('Failed to restart server', { id: 'memory-restart' })
|
||||
showToast.error('Failed to restart server', { id: 'memory-save' })
|
||||
}
|
||||
},
|
||||
onError: () => {
|
||||
showToast.error('Failed to save configuration', { id: 'memory-save' })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -262,40 +314,93 @@ export function MemoryPluginConfig({ memoryPluginEnabled, onToggle }: MemoryPlug
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<RefreshCw className="h-4 w-4 text-purple-500" />
|
||||
<span className="text-sm font-medium">Reindex</span>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleReindex}
|
||||
disabled={reindexMutation.isPending}
|
||||
className="w-full justify-start"
|
||||
>
|
||||
{reindexMutation.isPending ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin mr-2" />
|
||||
) : (
|
||||
<RefreshCw className="h-4 w-4 mr-2" />
|
||||
)}
|
||||
Reindex
|
||||
</Button>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Regenerate embeddings for all memories
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4 border-t pt-4">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Database className="h-4 w-4 text-green-500" />
|
||||
<span className="text-sm font-medium">Storage</span>
|
||||
<div className="grid gap-4 md:grid-cols-2 border-t pt-4">
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Database className="h-4 w-4 text-green-500" />
|
||||
<span className="text-sm font-medium">Storage</span>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="dedupThreshold">Deduplication Threshold</Label>
|
||||
<div className="flex items-center gap-4">
|
||||
<input
|
||||
id="dedupThreshold"
|
||||
type="range"
|
||||
min="0"
|
||||
max="0.4"
|
||||
step="0.05"
|
||||
value={displayConfig.dedupThreshold ?? 0.25}
|
||||
onChange={(e) => {
|
||||
setLocalConfig({
|
||||
...displayConfig,
|
||||
dedupThreshold: parseFloat(e.target.value),
|
||||
})
|
||||
}}
|
||||
className="flex-1"
|
||||
/>
|
||||
<span className="text-sm text-muted-foreground w-12">
|
||||
{(displayConfig.dedupThreshold ?? 0.25).toFixed(2)}
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Lower values = more aggressive deduplication (0.0 - 0.4)
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="dedupThreshold">Deduplication Threshold</Label>
|
||||
<div className="flex items-center gap-4">
|
||||
<input
|
||||
id="dedupThreshold"
|
||||
type="range"
|
||||
min="0"
|
||||
max="0.4"
|
||||
step="0.05"
|
||||
value={displayConfig.dedupThreshold ?? 0.25}
|
||||
onChange={(e) => {
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Cpu className="h-4 w-4 text-orange-500" />
|
||||
<span className="text-sm font-medium">Plan Execution</span>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="executionModel">Execution Model</Label>
|
||||
<Combobox
|
||||
value={displayConfig.executionModel ?? ''}
|
||||
onChange={(value) => {
|
||||
setLocalConfig({
|
||||
...displayConfig,
|
||||
dedupThreshold: parseFloat(e.target.value),
|
||||
executionModel: value || undefined,
|
||||
})
|
||||
}}
|
||||
className="flex-1"
|
||||
options={executionModelOptions}
|
||||
placeholder="default model"
|
||||
allowCustomValue
|
||||
showClear
|
||||
/>
|
||||
<span className="text-sm text-muted-foreground w-12">
|
||||
{(displayConfig.dedupThreshold ?? 0.25).toFixed(2)}
|
||||
</span>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Model used when executing plans from the Architect. Format: provider/model. Leave empty to use the current session's model.
|
||||
</p>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Lower values = more aggressive deduplication (0.0 - 0.4)
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -306,31 +411,6 @@ export function MemoryPluginConfig({ memoryPluginEnabled, onToggle }: MemoryPlug
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-4 border-t pt-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<RefreshCw className="h-4 w-4 text-purple-500" />
|
||||
<span className="text-sm font-medium">Reindex</span>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleReindex}
|
||||
disabled={reindexMutation.isPending}
|
||||
>
|
||||
{reindexMutation.isPending ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin mr-1" />
|
||||
) : (
|
||||
<RefreshCw className="h-4 w-4 mr-1" />
|
||||
)}
|
||||
Reindex
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Regenerate embeddings for all memories. Use when changing embedding model or if embeddings are missing.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between pt-2">
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<AlertCircle className="h-3 w-3" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, useRef, useEffect, useCallback } from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { ChevronDown } from 'lucide-react'
|
||||
import { ChevronDown, X } from 'lucide-react'
|
||||
|
||||
export interface ComboboxOption {
|
||||
value: string
|
||||
@@ -17,6 +17,7 @@ interface ComboboxProps {
|
||||
disabled?: boolean
|
||||
className?: string
|
||||
allowCustomValue?: boolean
|
||||
showClear?: boolean
|
||||
}
|
||||
|
||||
export function Combobox({
|
||||
@@ -27,6 +28,7 @@ export function Combobox({
|
||||
disabled = false,
|
||||
className,
|
||||
allowCustomValue = true,
|
||||
showClear = false,
|
||||
}: ComboboxProps) {
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const [inputValue, setInputValue] = useState(() => {
|
||||
@@ -181,6 +183,22 @@ export function Combobox({
|
||||
'pr-8'
|
||||
)}
|
||||
/>
|
||||
{showClear && value && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
if (!disabled) {
|
||||
onChange('')
|
||||
setInputValue('')
|
||||
inputRef.current?.focus()
|
||||
}
|
||||
}}
|
||||
className="absolute right-7 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
|
||||
tabIndex={-1}
|
||||
>
|
||||
<X className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
@@ -189,7 +207,10 @@ export function Combobox({
|
||||
inputRef.current?.focus()
|
||||
}
|
||||
}}
|
||||
className="absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
|
||||
className={cn(
|
||||
'absolute top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground',
|
||||
showClear && value ? 'right-1' : 'right-2'
|
||||
)}
|
||||
tabIndex={-1}
|
||||
>
|
||||
<ChevronDown className={cn('h-4 w-4 transition-transform', isOpen && 'rotate-180')} />
|
||||
|
||||
Reference in new issue
Block a user