mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
refactor(settings): redesign OpenCode settings with shared collapsible sections
- Replace bordered cards with compact flat rows and maintenance sections - Add shared SettingsDisclosure for config, maintenance, and sandbox sections - Auto-scroll expanded sections into view when outside the scrollport - Make agent file editor and agent form full-height and keyboard-aware on mobile
This commit is contained in:
1 parent
295d24ced7
commit
2a4fa956b4
18 files changed
+1013
-742
No files matched your search
@@ -2,9 +2,7 @@ import { useState, useRef, useId } from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Loader2, Edit, Download, RotateCcw, FileText, ChevronDown, AlertTriangle } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { RestartServerDialog } from './RestartServerDialog'
|
||||
import { OpenCodeConfigEditor } from './OpenCodeConfigEditor'
|
||||
import { CommandsEditor } from './CommandsEditor'
|
||||
@@ -13,6 +11,7 @@ import { AgentsMdEditor } from './AgentsMdEditor'
|
||||
import { McpManager } from './McpManager'
|
||||
import { SkillsEditor } from './SkillsEditor'
|
||||
import { OpenCodeModelsEditor, type ConfigProvider } from './OpenCodeModelsEditor'
|
||||
import { scrollSectionIntoView } from '@/lib/settingsScroll'
|
||||
import { VersionSelectDialog } from './VersionSelectDialog'
|
||||
import { settingsApi } from '@/api/settings'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
@@ -54,13 +53,30 @@ interface Agent {
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
const EXPANDED_SECTION_CONTENT_CLASS = 'p-2 sm:p-4'
|
||||
type ConfigSectionKey = 'agentsMd' | 'commands' | 'agents' | 'skills' | 'mcp' | 'models' | 'hostImport'
|
||||
|
||||
const SECTION_LIST_CLASS = 'divide-y divide-border/60 border-t border-border/60'
|
||||
const SECTION_HEADER_CLASS = 'flex w-full min-w-0 items-center justify-between gap-3 py-3 text-left transition-colors hover:bg-muted/40 focus-visible:outline-2 focus-visible:outline-ring focus-visible:outline-offset-2'
|
||||
const SECTION_CONTENT_CLASS = 'pb-4'
|
||||
const SECTION_CHEVRON_CLASS = 'h-4 w-4 shrink-0 transition-transform'
|
||||
const SECTION_TITLE_CLASS = 'text-sm font-medium truncate'
|
||||
const SECTION_META_CLASS = 'text-xs text-muted-foreground'
|
||||
|
||||
const getConfigFileName = (path: string) => path.split(/[\\/]/).filter(Boolean).pop() ?? path
|
||||
|
||||
export function OpenCodeConfigManager() {
|
||||
const hostImportContentId = useId()
|
||||
const sectionIdPrefix = useId()
|
||||
const agentsMdContentId = `${sectionIdPrefix}-agents-md`
|
||||
const commandsContentId = `${sectionIdPrefix}-commands`
|
||||
const agentsContentId = `${sectionIdPrefix}-agents`
|
||||
const skillsContentId = `${sectionIdPrefix}-skills`
|
||||
const mcpContentId = `${sectionIdPrefix}-mcp`
|
||||
const modelsContentId = `${sectionIdPrefix}-models`
|
||||
const hostImportContentId = `${sectionIdPrefix}-host-import`
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
const { data: health } = useServerHealth()
|
||||
const [expandedSections, setExpandedSections] = useState<Record<string, boolean>>({
|
||||
const [expandedSections, setExpandedSections] = useState<Record<ConfigSectionKey, boolean>>({
|
||||
agentsMd: false,
|
||||
commands: false,
|
||||
agents: false,
|
||||
@@ -86,6 +102,7 @@ export function OpenCodeConfigManager() {
|
||||
const skillsRef = useRef<HTMLButtonElement>(null)
|
||||
const mcpRef = useRef<HTMLButtonElement>(null)
|
||||
const modelsRef = useRef<HTMLButtonElement>(null)
|
||||
const hostImportRef = useRef<HTMLButtonElement>(null)
|
||||
|
||||
const { data: config, isLoading } = useOpenCodeConfigFile()
|
||||
|
||||
@@ -113,13 +130,11 @@ export function OpenCodeConfigManager() {
|
||||
staleTime: 30 * 1000,
|
||||
})
|
||||
|
||||
const scrollToSection = (ref: React.RefObject<HTMLButtonElement | null>) => {
|
||||
if (ref.current) {
|
||||
ref.current.scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'nearest',
|
||||
inline: 'nearest'
|
||||
})
|
||||
const toggleSection = (section: ConfigSectionKey, ref?: React.RefObject<HTMLButtonElement | null>) => {
|
||||
const isExpanding = !expandedSections[section]
|
||||
setExpandedSections(prev => ({ ...prev, [section]: !prev[section] }))
|
||||
if (isExpanding) {
|
||||
setTimeout(() => scrollSectionIntoView(ref?.current ?? null), 0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +200,7 @@ export function OpenCodeConfigManager() {
|
||||
const canImportFromHost = Boolean(importStatus?.configSourcePath || importStatus?.stateSourcePath)
|
||||
|
||||
return (
|
||||
<div className="space-y-6 min-w-0">
|
||||
<div className="min-w-0 space-y-4">
|
||||
{health?.opencodeRestartPending && (
|
||||
<div className="flex flex-col gap-2 rounded-md border border-amber-500/40 bg-amber-500/10 p-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
@@ -216,80 +231,69 @@ export function OpenCodeConfigManager() {
|
||||
/>
|
||||
|
||||
{!config ? (
|
||||
<Card>
|
||||
<CardContent className="p-8 text-center">
|
||||
<p className="text-muted-foreground">No OpenCode configuration file found. Restart the Manager to seed one.</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<p className="py-8 text-center text-sm text-muted-foreground">
|
||||
No OpenCode configuration file found. Restart the Manager to seed one.
|
||||
</p>
|
||||
) : (
|
||||
<>
|
||||
<Card>
|
||||
<CardHeader className="pb-3">
|
||||
<CardTitle className="text-sm sm:text-base">OpenCode Configuration</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-center">
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-sm font-medium">{config.path}</p>
|
||||
<p className="truncate text-sm text-muted-foreground">Updated: {new Date(config.updatedAt).toLocaleString()}</p>
|
||||
</div>
|
||||
|
||||
{!config.isValid && (
|
||||
<Badge variant="destructive">Invalid Config</Badge>
|
||||
)}
|
||||
|
||||
<TooltipProvider delayDuration={200}>
|
||||
<div className="flex items-center gap-1 sm:gap-1.5 sm:ml-auto">
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => downloadConfig(config)}
|
||||
>
|
||||
<Download className="h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">Download</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setIsEditDialogOpen(true)}
|
||||
>
|
||||
<Edit className="h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">Edit</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="flex min-w-0 items-start gap-2">
|
||||
<FileText className="mt-0.5 h-4 w-4 shrink-0 text-blue-500" />
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-sm font-medium">{getConfigFileName(config.path)}</p>
|
||||
<details className="text-xs text-muted-foreground">
|
||||
<summary className="cursor-pointer select-none">File location and updated time</summary>
|
||||
<p className="mt-1 break-all">{config.path}</p>
|
||||
<p className="mt-1">Updated: {new Date(config.updatedAt).toLocaleString()}</p>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{!config.isValid && config.validationIssues && config.validationIssues.length > 0 && (
|
||||
<div className="rounded-lg border border-destructive/40 bg-destructive/5 p-4">
|
||||
<p className="font-medium text-destructive">This configuration has validation issues</p>
|
||||
<p className="mt-1 text-sm text-destructive/90">
|
||||
OpenCode may fail to start until these fields are corrected. Open the config editor to fix the file directly.
|
||||
</p>
|
||||
<ul className="mt-3 list-disc space-y-1 pl-5 text-sm text-destructive/90">
|
||||
{config.validationIssues.slice(0, 8).map((issue) => (
|
||||
<li key={`${issue.path}-${issue.message}`}>
|
||||
<span className="font-mono text-xs">{issue.path}</span>: {issue.message}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{config.validationIssues.length > 8 && (
|
||||
<p className="mt-2 text-xs text-destructive/80">
|
||||
Showing 8 of {config.validationIssues.length} issues. Open the config editor to review and fix the file.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{!config.isValid && (
|
||||
<Badge variant="destructive">Invalid Config</Badge>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-11 sm:h-8"
|
||||
onClick={() => setIsEditDialogOpen(true)}
|
||||
>
|
||||
<Edit className="h-3.5 w-3.5 mr-1" />
|
||||
Edit
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-11 sm:h-8"
|
||||
onClick={() => downloadConfig(config)}
|
||||
>
|
||||
<Download className="h-3.5 w-3.5 mr-1" />
|
||||
Download
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{!config.isValid && config.validationIssues && config.validationIssues.length > 0 && (
|
||||
<div className="rounded-lg border border-destructive/40 bg-destructive/5 p-4">
|
||||
<p className="font-medium text-destructive">This configuration has validation issues</p>
|
||||
<p className="mt-1 text-sm text-destructive/90">
|
||||
OpenCode may fail to start until these fields are corrected. Open the config editor to fix the file directly.
|
||||
</p>
|
||||
<ul className="mt-3 list-disc space-y-1 pl-5 text-sm text-destructive/90">
|
||||
{config.validationIssues.slice(0, 8).map((issue) => (
|
||||
<li key={`${issue.path}-${issue.message}`}>
|
||||
<span className="font-mono text-xs">{issue.path}</span>: {issue.message}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{config.validationIssues.length > 8 && (
|
||||
<p className="mt-2 text-xs text-destructive/80">
|
||||
Showing 8 of {config.validationIssues.length} issues. Open the config editor to review and fix the file.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<OpenCodeConfigEditor
|
||||
config={config}
|
||||
@@ -303,238 +307,222 @@ export function OpenCodeConfigManager() {
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className="mt-8 space-y-6">
|
||||
<div className="border-t border-border pt-6">
|
||||
<div className="bg-card border border-border rounded-lg overflow-clip min-w-0 mb-6">
|
||||
<button
|
||||
ref={agentsMdRef}
|
||||
className={cn("w-full px-4 py-3 flex items-center justify-between transition-colors min-w-0", expandedSections.agentsMd ? "bg-muted/40 hover:bg-muted/50" : "hover:bg-muted/50")}
|
||||
onClick={() => {
|
||||
const isExpanding = !expandedSections.agentsMd
|
||||
setExpandedSections(prev => ({ ...prev, agentsMd: isExpanding }))
|
||||
if (isExpanding) {
|
||||
setTimeout(() => scrollToSection(agentsMdRef), 100)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<FileText className="h-4 w-4 text-blue-500" />
|
||||
<h4 className="text-sm font-medium truncate">Global Agent Instructions (AGENTS.md)</h4>
|
||||
</div>
|
||||
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.agentsMd ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
<div className={`${expandedSections.agentsMd ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className="p-4">
|
||||
<AgentsMdEditor />
|
||||
</div>
|
||||
</div>
|
||||
<div className={cn('mt-6', SECTION_LIST_CLASS)}>
|
||||
<div>
|
||||
<button
|
||||
ref={agentsMdRef}
|
||||
type="button"
|
||||
aria-expanded={expandedSections.agentsMd}
|
||||
aria-controls={agentsMdContentId}
|
||||
className={cn(SECTION_HEADER_CLASS, 'flex-wrap sm:flex-nowrap')}
|
||||
onClick={() => toggleSection('agentsMd', agentsMdRef)}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-3">
|
||||
<FileText className="h-4 w-4 shrink-0 text-blue-500" />
|
||||
<div className="min-w-0 text-left">
|
||||
<h4 className="text-sm font-medium">Global Agent Instructions (AGENTS.md)</h4>
|
||||
<p className={SECTION_META_CLASS}>Applies across OpenCode</p>
|
||||
</div>
|
||||
|
||||
<h3 className="text-base sm:text-lg font-semibold mb-4">Configure Commands, Agents & MCP Servers</h3>
|
||||
<p className="text-sm text-muted-foreground mb-6">
|
||||
Add custom commands, agents, and MCP servers to your OpenCode configuration.
|
||||
</p>
|
||||
|
||||
{config && (
|
||||
<div className="space-y-6">
|
||||
<div className="flex flex-col gap-4 pb-4 min-w-0">
|
||||
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
|
||||
<button
|
||||
ref={commandsRef}
|
||||
className={cn("w-full px-4 py-3 flex items-center justify-between transition-colors min-w-0", expandedSections.commands ? "bg-muted/40 hover:bg-muted/50" : "hover:bg-muted/50")}
|
||||
onClick={() => {
|
||||
const isExpanding = !expandedSections.commands
|
||||
setExpandedSections(prev => ({ ...prev, commands: isExpanding }))
|
||||
|
||||
if (isExpanding) {
|
||||
setTimeout(() => scrollToSection(commandsRef), 100)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<h4 className="text-sm font-medium truncate">Commands</h4>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{Object.keys((config.content.command as Record<string, Command> | undefined) ?? {}).length + directoryCommands.length} configured
|
||||
</span>
|
||||
</div>
|
||||
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.commands ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
<div className={`${expandedSections.commands ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<CommandsEditor
|
||||
commands={(config.content.command as Record<string, Command> | undefined) ?? {}}
|
||||
directoryCommands={directoryCommands}
|
||||
onChange={(commands) => {
|
||||
updateConfigContent({
|
||||
...config.content,
|
||||
command: commands
|
||||
})
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
|
||||
<button
|
||||
ref={agentsRef}
|
||||
className={cn("w-full px-4 py-3 flex items-center justify-between transition-colors min-w-0", expandedSections.agents ? "bg-muted/40 hover:bg-muted/50" : "hover:bg-muted/50")}
|
||||
onClick={() => {
|
||||
const isExpanding = !expandedSections.agents
|
||||
setExpandedSections(prev => ({ ...prev, agents: isExpanding }))
|
||||
|
||||
if (isExpanding) {
|
||||
setTimeout(() => scrollToSection(agentsRef), 100)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<h4 className="text-sm font-medium truncate">Agents</h4>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{Object.keys((config.content.agent as Record<string, Agent> | undefined) ?? {}).length + directoryAgents.length} configured
|
||||
</span>
|
||||
</div>
|
||||
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.agents ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
<div className={`${expandedSections.agents ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<AgentsEditor
|
||||
agents={(config.content.agent as Record<string, Agent> | undefined) ?? {}}
|
||||
directoryAgents={directoryAgents}
|
||||
onChange={(agents) => {
|
||||
updateConfigContent({
|
||||
...config.content,
|
||||
agent: agents
|
||||
})
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
|
||||
<button
|
||||
ref={skillsRef}
|
||||
className={cn("w-full px-4 py-3 flex items-center justify-between transition-colors min-w-0", expandedSections.skills ? "bg-muted/40 hover:bg-muted/50" : "hover:bg-muted/50")}
|
||||
onClick={() => {
|
||||
const isExpanding = !expandedSections.skills
|
||||
setExpandedSections(prev => ({ ...prev, skills: isExpanding }))
|
||||
if (isExpanding) {
|
||||
setTimeout(() => scrollToSection(skillsRef), 100)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<h4 className="text-sm font-medium truncate">Skills</h4>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{managedSkills.length} configured
|
||||
</span>
|
||||
</div>
|
||||
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.skills ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
<div className={`${expandedSections.skills ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<SkillsEditor
|
||||
managedSkills={managedSkills}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
|
||||
<button
|
||||
ref={mcpRef}
|
||||
className={cn("w-full px-4 py-3 flex items-center justify-between transition-colors min-w-0", expandedSections.mcp ? "bg-muted/40 hover:bg-muted/50" : "hover:bg-muted/50")}
|
||||
onClick={() => {
|
||||
const isExpanding = !expandedSections.mcp
|
||||
setExpandedSections(prev => ({ ...prev, mcp: isExpanding }))
|
||||
|
||||
if (isExpanding) {
|
||||
setTimeout(() => scrollToSection(mcpRef), 100)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<h4 className="text-sm font-medium truncate">MCP Servers</h4>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{Object.keys((config.content.mcp as Record<string, unknown> | undefined) ?? {}).length} configured
|
||||
</span>
|
||||
</div>
|
||||
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.mcp ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
<div className={`${expandedSections.mcp ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<McpManager
|
||||
config={config}
|
||||
onUpdate={updateConfigContent}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
|
||||
<button
|
||||
ref={modelsRef}
|
||||
className={cn("w-full px-4 py-3 flex items-center justify-between transition-colors min-w-0", expandedSections.models ? "bg-muted/40 hover:bg-muted/50" : "hover:bg-muted/50")}
|
||||
onClick={() => {
|
||||
const isExpanding = !expandedSections.models
|
||||
setExpandedSections(prev => ({ ...prev, models: isExpanding }))
|
||||
|
||||
if (isExpanding) {
|
||||
setTimeout(() => scrollToSection(modelsRef), 100)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<h4 className="text-sm font-medium truncate">Models</h4>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{(() => {
|
||||
const provider = config.content.provider as Record<string, unknown> | undefined
|
||||
if (!provider) return 0
|
||||
return Object.values(provider).reduce<number>((acc, p) => {
|
||||
const models = (p as { models?: Record<string, unknown> })?.models
|
||||
return acc + (models ? Object.keys(models).length : 0)
|
||||
}, 0)
|
||||
})()} configured
|
||||
</span>
|
||||
</div>
|
||||
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.models ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
<div className={`${expandedSections.models ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<OpenCodeModelsEditor
|
||||
providers={(config.content.provider as Record<string, ConfigProvider> | undefined) ?? {}}
|
||||
onChange={(providers) => {
|
||||
updateConfigContent({
|
||||
...config.content,
|
||||
provider: providers
|
||||
})
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-3">
|
||||
<span className="text-xs font-medium text-blue-500">Edit AGENTS.md</span>
|
||||
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.agentsMd && 'rotate-180')} />
|
||||
</div>
|
||||
</button>
|
||||
<div
|
||||
id={agentsMdContentId}
|
||||
className={cn(SECTION_CONTENT_CLASS, expandedSections.agentsMd ? 'block' : 'hidden')}
|
||||
>
|
||||
<AgentsMdEditor />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
|
||||
<button
|
||||
className={cn("w-full px-4 py-3 flex items-center justify-between transition-colors min-w-0", expandedSections.hostImport ? "bg-muted/40 hover:bg-muted/50" : "hover:bg-muted/50")}
|
||||
aria-expanded={expandedSections.hostImport}
|
||||
aria-controls={hostImportContentId}
|
||||
onClick={() => setExpandedSections(prev => ({ ...prev, hostImport: !prev.hostImport }))}
|
||||
>
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<Download className="h-4 w-4 text-blue-500" />
|
||||
<h4 className="text-sm font-medium truncate">Existing OpenCode Host Import</h4>
|
||||
</div>
|
||||
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.hostImport ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
<div id={hostImportContentId} className={`${expandedSections.hostImport ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className={cn(EXPANDED_SECTION_CONTENT_CLASS, 'space-y-3 text-sm')}>
|
||||
{config && (
|
||||
<>
|
||||
<div>
|
||||
<button
|
||||
ref={commandsRef}
|
||||
type="button"
|
||||
aria-expanded={expandedSections.commands}
|
||||
aria-controls={commandsContentId}
|
||||
className={SECTION_HEADER_CLASS}
|
||||
onClick={() => toggleSection('commands', commandsRef)}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-3">
|
||||
<h4 className={SECTION_TITLE_CLASS}>Commands</h4>
|
||||
<span className={SECTION_META_CLASS}>
|
||||
{Object.keys((config.content.command as Record<string, Command> | undefined) ?? {}).length + directoryCommands.length} configured
|
||||
</span>
|
||||
</div>
|
||||
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.commands && 'rotate-180')} />
|
||||
</button>
|
||||
<div
|
||||
id={commandsContentId}
|
||||
className={cn(SECTION_CONTENT_CLASS, expandedSections.commands ? 'block' : 'hidden')}
|
||||
>
|
||||
<CommandsEditor
|
||||
commands={(config.content.command as Record<string, Command> | undefined) ?? {}}
|
||||
directoryCommands={directoryCommands}
|
||||
onChange={(commands) => {
|
||||
updateConfigContent({
|
||||
...config.content,
|
||||
command: commands
|
||||
})
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button
|
||||
ref={agentsRef}
|
||||
type="button"
|
||||
aria-expanded={expandedSections.agents}
|
||||
aria-controls={agentsContentId}
|
||||
className={SECTION_HEADER_CLASS}
|
||||
onClick={() => toggleSection('agents', agentsRef)}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-3">
|
||||
<h4 className={SECTION_TITLE_CLASS}>Agents</h4>
|
||||
<span className={SECTION_META_CLASS}>
|
||||
{Object.keys((config.content.agent as Record<string, Agent> | undefined) ?? {}).length + directoryAgents.length} configured
|
||||
</span>
|
||||
</div>
|
||||
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.agents && 'rotate-180')} />
|
||||
</button>
|
||||
<div
|
||||
id={agentsContentId}
|
||||
className={cn(SECTION_CONTENT_CLASS, expandedSections.agents ? 'block' : 'hidden')}
|
||||
>
|
||||
<AgentsEditor
|
||||
agents={(config.content.agent as Record<string, Agent> | undefined) ?? {}}
|
||||
directoryAgents={directoryAgents}
|
||||
onChange={(agents) => {
|
||||
updateConfigContent({
|
||||
...config.content,
|
||||
agent: agents
|
||||
})
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button
|
||||
ref={skillsRef}
|
||||
type="button"
|
||||
aria-expanded={expandedSections.skills}
|
||||
aria-controls={skillsContentId}
|
||||
className={SECTION_HEADER_CLASS}
|
||||
onClick={() => toggleSection('skills', skillsRef)}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-3">
|
||||
<h4 className={SECTION_TITLE_CLASS}>Skills</h4>
|
||||
<span className={SECTION_META_CLASS}>
|
||||
{managedSkills.length} configured
|
||||
</span>
|
||||
</div>
|
||||
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.skills && 'rotate-180')} />
|
||||
</button>
|
||||
<div
|
||||
id={skillsContentId}
|
||||
className={cn(SECTION_CONTENT_CLASS, expandedSections.skills ? 'block' : 'hidden')}
|
||||
>
|
||||
<SkillsEditor
|
||||
managedSkills={managedSkills}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button
|
||||
ref={mcpRef}
|
||||
type="button"
|
||||
aria-expanded={expandedSections.mcp}
|
||||
aria-controls={mcpContentId}
|
||||
className={SECTION_HEADER_CLASS}
|
||||
onClick={() => toggleSection('mcp', mcpRef)}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-3">
|
||||
<h4 className={SECTION_TITLE_CLASS}>MCP Servers</h4>
|
||||
<span className={SECTION_META_CLASS}>
|
||||
{Object.keys((config.content.mcp as Record<string, unknown> | undefined) ?? {}).length} configured
|
||||
</span>
|
||||
</div>
|
||||
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.mcp && 'rotate-180')} />
|
||||
</button>
|
||||
<div
|
||||
id={mcpContentId}
|
||||
className={cn(SECTION_CONTENT_CLASS, expandedSections.mcp ? 'block' : 'hidden')}
|
||||
>
|
||||
<McpManager
|
||||
config={config}
|
||||
onUpdate={updateConfigContent}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button
|
||||
ref={modelsRef}
|
||||
type="button"
|
||||
aria-expanded={expandedSections.models}
|
||||
aria-controls={modelsContentId}
|
||||
className={SECTION_HEADER_CLASS}
|
||||
onClick={() => toggleSection('models', modelsRef)}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-3">
|
||||
<h4 className={SECTION_TITLE_CLASS}>Models</h4>
|
||||
<span className={SECTION_META_CLASS}>
|
||||
{(() => {
|
||||
const provider = config.content.provider as Record<string, unknown> | undefined
|
||||
if (!provider) return 0
|
||||
return Object.values(provider).reduce<number>((acc, p) => {
|
||||
const models = (p as { models?: Record<string, unknown> })?.models
|
||||
return acc + (models ? Object.keys(models).length : 0)
|
||||
}, 0)
|
||||
})()} configured
|
||||
</span>
|
||||
</div>
|
||||
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.models && 'rotate-180')} />
|
||||
</button>
|
||||
<div
|
||||
id={modelsContentId}
|
||||
className={cn(SECTION_CONTENT_CLASS, expandedSections.models ? 'block' : 'hidden')}
|
||||
>
|
||||
<OpenCodeModelsEditor
|
||||
providers={(config.content.provider as Record<string, ConfigProvider> | undefined) ?? {}}
|
||||
onChange={(providers) => {
|
||||
updateConfigContent({
|
||||
...config.content,
|
||||
provider: providers
|
||||
})
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<button
|
||||
ref={hostImportRef}
|
||||
type="button"
|
||||
aria-expanded={expandedSections.hostImport}
|
||||
aria-controls={hostImportContentId}
|
||||
className={SECTION_HEADER_CLASS}
|
||||
onClick={() => toggleSection('hostImport', hostImportRef)}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-3">
|
||||
<Download className="h-4 w-4 shrink-0 text-blue-500" />
|
||||
<h4 className={SECTION_TITLE_CLASS}>Existing OpenCode Host Import</h4>
|
||||
</div>
|
||||
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.hostImport && 'rotate-180')} />
|
||||
</button>
|
||||
<div
|
||||
id={hostImportContentId}
|
||||
className={cn(SECTION_CONTENT_CLASS, 'space-y-3 text-sm', expandedSections.hostImport ? 'block' : 'hidden')}
|
||||
>
|
||||
<p className="text-muted-foreground">
|
||||
Import your standalone OpenCode config and session state into this workspace, then restart the server so existing chats can reconnect.
|
||||
</p>
|
||||
|
||||
Reference in new issue
Block a user