mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Add settings dialogs and improve settings UI components
This commit is contained in:
1 parent
32b847c7b2
commit
c0c18a5bde
10 files changed
+1050
-1094
No files matched your search
@@ -5,6 +5,7 @@ import { Label } from '@/components/ui/label'
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { settingsApi } from '@/api/settings'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
|
||||
@@ -126,7 +127,7 @@ onSuccess: async () => {
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleClose}>
|
||||
<DialogContent className="max-w-2xl bg-card border-border">
|
||||
<DialogContent className="w-full max-w-3xl bg-card border-border">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Add MCP Server</DialogTitle>
|
||||
<DialogDescription>
|
||||
@@ -134,8 +135,8 @@ onSuccess: async () => {
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4 py-4">
|
||||
<div className="space-y-2">
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label htmlFor="serverId">Server ID</Label>
|
||||
<Input
|
||||
id="serverId"
|
||||
@@ -149,7 +150,7 @@ onSuccess: async () => {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div>
|
||||
<Label htmlFor="serverType">Server Type</Label>
|
||||
<Select value={serverType} onValueChange={(value: 'local' | 'remote') => setServerType(value)}>
|
||||
<SelectTrigger className="bg-background border-border">
|
||||
@@ -163,7 +164,7 @@ onSuccess: async () => {
|
||||
</div>
|
||||
|
||||
{serverType === 'local' ? (
|
||||
<div className="space-y-2">
|
||||
<div>
|
||||
<Label htmlFor="command">Command</Label>
|
||||
<Input
|
||||
id="command"
|
||||
@@ -177,7 +178,7 @@ onSuccess: async () => {
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
<div>
|
||||
<Label htmlFor="url">Server URL</Label>
|
||||
<Input
|
||||
id="url"
|
||||
@@ -193,16 +194,17 @@ onSuccess: async () => {
|
||||
)}
|
||||
|
||||
{serverType === 'local' && (
|
||||
<div className="space-y-2">
|
||||
<div>
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>Environment Variables</Label>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className='h-6'
|
||||
onClick={handleAddEnvironmentVar}
|
||||
>
|
||||
Add Variable
|
||||
+
|
||||
</Button>
|
||||
</div>
|
||||
{environment.map((env, index) => (
|
||||
@@ -237,7 +239,7 @@ onSuccess: async () => {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<div>
|
||||
<Label htmlFor="timeout">Timeout (ms)</Label>
|
||||
<Input
|
||||
id="timeout"
|
||||
@@ -252,12 +254,10 @@ onSuccess: async () => {
|
||||
</div>
|
||||
|
||||
<div className="flex items-center space-x-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
<Switch
|
||||
id="enabled"
|
||||
checked={enabled}
|
||||
onChange={(e) => setEnabled(e.target.checked)}
|
||||
className="rounded"
|
||||
onCheckedChange={setEnabled}
|
||||
/>
|
||||
<Label htmlFor="enabled">Enable server on startup</Label>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,480 @@
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { z } from 'zod'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
|
||||
const agentFormSchema = z.object({
|
||||
name: z.string().min(1, 'Agent name is required').regex(/^[a-z0-9-]+$/, 'Must be lowercase letters, numbers, and hyphens only'),
|
||||
description: z.string().optional(),
|
||||
prompt: z.string().min(1, 'Prompt is required'),
|
||||
mode: z.enum(['subagent', 'primary', 'all']),
|
||||
temperature: z.number().min(0).max(2),
|
||||
topP: z.number().min(0).max(1),
|
||||
modelId: z.string().optional(),
|
||||
providerId: z.string().optional(),
|
||||
write: z.boolean(),
|
||||
edit: z.boolean(),
|
||||
bash: z.boolean(),
|
||||
webfetch: z.boolean(),
|
||||
editPermission: z.enum(['ask', 'allow', 'deny']),
|
||||
bashPermission: z.enum(['ask', 'allow', 'deny']),
|
||||
webfetchPermission: z.enum(['ask', 'allow', 'deny']),
|
||||
disable: z.boolean()
|
||||
})
|
||||
|
||||
type AgentFormValues = z.infer<typeof agentFormSchema>
|
||||
|
||||
interface Agent {
|
||||
prompt?: string
|
||||
description?: string
|
||||
mode?: 'subagent' | 'primary' | 'all'
|
||||
temperature?: number
|
||||
topP?: number
|
||||
model?: {
|
||||
modelID: string
|
||||
providerID: string
|
||||
}
|
||||
tools?: Record<string, boolean>
|
||||
permission?: {
|
||||
edit?: 'ask' | 'allow' | 'deny'
|
||||
bash?: 'ask' | 'allow' | 'deny' | Record<string, 'ask' | 'allow' | 'deny'>
|
||||
webfetch?: 'ask' | 'allow' | 'deny'
|
||||
}
|
||||
disable?: boolean
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
interface AgentDialogProps {
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
onSubmit: (name: string, agent: Agent) => void
|
||||
editingAgent?: { name: string; agent: Agent } | null
|
||||
}
|
||||
|
||||
export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: AgentDialogProps) {
|
||||
const form = useForm<AgentFormValues>({
|
||||
resolver: zodResolver(agentFormSchema),
|
||||
defaultValues: {
|
||||
name: editingAgent?.name || '',
|
||||
description: editingAgent?.agent.description || '',
|
||||
prompt: editingAgent?.agent.prompt || '',
|
||||
mode: editingAgent?.agent.mode || 'subagent',
|
||||
temperature: editingAgent?.agent.temperature ?? 0.7,
|
||||
topP: editingAgent?.agent.topP ?? 1,
|
||||
modelId: editingAgent?.agent.model?.modelID || '',
|
||||
providerId: editingAgent?.agent.model?.providerID || '',
|
||||
write: editingAgent?.agent.tools?.write ?? true,
|
||||
edit: editingAgent?.agent.tools?.edit ?? true,
|
||||
bash: editingAgent?.agent.tools?.bash ?? true,
|
||||
webfetch: editingAgent?.agent.tools?.webfetch ?? true,
|
||||
editPermission: editingAgent?.agent.permission?.edit ?? 'allow',
|
||||
bashPermission: typeof editingAgent?.agent.permission?.bash === 'string' ? editingAgent.agent.permission.bash : 'allow',
|
||||
webfetchPermission: editingAgent?.agent.permission?.webfetch ?? 'allow',
|
||||
disable: editingAgent?.agent.disable ?? false
|
||||
}
|
||||
})
|
||||
|
||||
const handleSubmit = (values: AgentFormValues) => {
|
||||
const agent: Agent = {
|
||||
prompt: values.prompt,
|
||||
description: values.description || undefined,
|
||||
mode: values.mode,
|
||||
temperature: values.temperature,
|
||||
topP: values.topP,
|
||||
disable: values.disable,
|
||||
tools: {
|
||||
write: values.write,
|
||||
edit: values.edit,
|
||||
bash: values.bash,
|
||||
webfetch: values.webfetch
|
||||
},
|
||||
permission: {
|
||||
edit: values.editPermission,
|
||||
bash: values.bashPermission,
|
||||
webfetch: values.webfetchPermission
|
||||
}
|
||||
}
|
||||
|
||||
if (values.modelId || values.providerId) {
|
||||
agent.model = {
|
||||
modelID: values.modelId || '',
|
||||
providerID: values.providerId || ''
|
||||
}
|
||||
}
|
||||
|
||||
onSubmit(values.name, agent)
|
||||
form.reset()
|
||||
onOpenChange(false)
|
||||
}
|
||||
|
||||
const handleOpenChange = (isOpen: boolean) => {
|
||||
if (!isOpen) {
|
||||
form.reset()
|
||||
}
|
||||
onOpenChange(isOpen)
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||
<DialogContent className="max-w-2xl max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{editingAgent ? 'Edit Agent' : 'Create Agent'}</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(handleSubmit)} className="space-y-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="name"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Agent Name</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
placeholder="my-agent"
|
||||
disabled={!!editingAgent}
|
||||
className={editingAgent ? 'bg-muted' : ''}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormDescription>
|
||||
Use lowercase letters, numbers, and hyphens only
|
||||
</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="description"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Description</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea
|
||||
{...field}
|
||||
placeholder="Brief description of what the agent does"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="prompt"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Prompt</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea
|
||||
{...field}
|
||||
placeholder="The system prompt that defines the agent's behavior and role"
|
||||
rows={6}
|
||||
className="font-mono text-sm"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="mode"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Mode</FormLabel>
|
||||
<Select onValueChange={field.onChange} defaultValue={field.value}>
|
||||
<FormControl>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select mode" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
<SelectItem value="subagent">Subagent</SelectItem>
|
||||
<SelectItem value="primary">Primary</SelectItem>
|
||||
<SelectItem value="all">All</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="temperature"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Temperature</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
type="number"
|
||||
min="0"
|
||||
max="2"
|
||||
step="0.1"
|
||||
onChange={(e) => field.onChange(parseFloat(e.target.value))}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="topP"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Top P</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
type="number"
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.1"
|
||||
onChange={(e) => field.onChange(parseFloat(e.target.value))}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="text-sm font-medium">Model Configuration</div>
|
||||
<div className="flex flex-col sm:grid grid-cols-2 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="modelId"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Model ID</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
placeholder="claude-3-5-sonnet-20241022"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="providerId"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Provider ID</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
placeholder="anthropic"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="text-sm font-medium">Tools Configuration</div>
|
||||
<div className="grid grid-cols-2 gap-2 text-sm">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="write"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-center space-x-2 space-y-0">
|
||||
<FormControl>
|
||||
<Switch
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormLabel className="font-normal">Write</FormLabel>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="edit"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-center space-x-2 space-y-0">
|
||||
<FormControl>
|
||||
<Switch
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormLabel className="font-normal">Edit</FormLabel>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="bash"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-center space-x-2 space-y-0">
|
||||
<FormControl>
|
||||
<Switch
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormLabel className="font-normal">Bash</FormLabel>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="webfetch"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-center space-x-2 space-y-0">
|
||||
<FormControl>
|
||||
<Switch
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormLabel className="font-normal">Web Fetch</FormLabel>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="text-sm font-medium">Permissions</div>
|
||||
<div className="grid grid-cols-3 gap-2 text-sm">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="editPermission"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel className="text-xs">Edit</FormLabel>
|
||||
<Select onValueChange={field.onChange} defaultValue={field.value}>
|
||||
<FormControl>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
<SelectItem value="ask">Ask</SelectItem>
|
||||
<SelectItem value="allow">Allow</SelectItem>
|
||||
<SelectItem value="deny">Deny</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="bashPermission"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel className="text-xs">Bash</FormLabel>
|
||||
<Select onValueChange={field.onChange} defaultValue={field.value}>
|
||||
<FormControl>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
<SelectItem value="ask">Ask</SelectItem>
|
||||
<SelectItem value="allow">Allow</SelectItem>
|
||||
<SelectItem value="deny">Deny</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="webfetchPermission"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel className="text-xs">Web Fetch</FormLabel>
|
||||
<Select onValueChange={field.onChange} defaultValue={field.value}>
|
||||
<FormControl>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
<SelectItem value="ask">Ask</SelectItem>
|
||||
<SelectItem value="allow">Allow</SelectItem>
|
||||
<SelectItem value="deny">Deny</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="disable"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-4">
|
||||
<div className="space-y-0.5">
|
||||
<FormLabel className="text-base">Disable agent</FormLabel>
|
||||
<FormDescription>
|
||||
Prevent this agent from being used
|
||||
</FormDescription>
|
||||
</div>
|
||||
<FormControl>
|
||||
<Switch
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => handleOpenChange(false)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={!form.formState.isValid}
|
||||
>
|
||||
{editingAgent ? 'Update' : 'Create'}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -2,12 +2,8 @@ import { useState } from 'react'
|
||||
import { Plus, Trash2, Edit } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { Dialog, DialogTrigger } from '@/components/ui/dialog'
|
||||
import { AgentDialog } from './AgentDialog'
|
||||
|
||||
interface Agent {
|
||||
prompt?: string
|
||||
@@ -37,58 +33,22 @@ interface AgentsEditorProps {
|
||||
export function AgentsEditor({ agents, onChange }: AgentsEditorProps) {
|
||||
const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false)
|
||||
const [editingAgent, setEditingAgent] = useState<{ name: string; agent: Agent } | null>(null)
|
||||
const [newAgentName, setNewAgentName] = useState('')
|
||||
const [newAgent, setNewAgent] = useState<Agent>({
|
||||
prompt: '',
|
||||
description: '',
|
||||
mode: 'subagent',
|
||||
temperature: 0.7,
|
||||
topP: 1,
|
||||
disable: false,
|
||||
tools: {},
|
||||
permission: {}
|
||||
})
|
||||
|
||||
const createAgent = () => {
|
||||
if (!newAgentName.trim()) return
|
||||
|
||||
const updatedAgents = {
|
||||
...agents,
|
||||
[newAgentName]: {
|
||||
prompt: newAgent.prompt || undefined,
|
||||
description: newAgent.description || undefined,
|
||||
mode: newAgent.mode,
|
||||
temperature: newAgent.temperature,
|
||||
topP: newAgent.topP,
|
||||
disable: newAgent.disable
|
||||
const handleAgentSubmit = (name: string, agent: Agent) => {
|
||||
if (editingAgent) {
|
||||
const updatedAgents = { ...agents }
|
||||
delete updatedAgents[editingAgent.name]
|
||||
updatedAgents[name] = agent
|
||||
onChange(updatedAgents)
|
||||
setEditingAgent(null)
|
||||
} else {
|
||||
const updatedAgents = {
|
||||
...agents,
|
||||
[name]: agent
|
||||
}
|
||||
onChange(updatedAgents)
|
||||
setIsCreateDialogOpen(false)
|
||||
}
|
||||
|
||||
onChange(updatedAgents)
|
||||
setNewAgentName('')
|
||||
setNewAgent({
|
||||
prompt: '',
|
||||
description: '',
|
||||
mode: 'subagent',
|
||||
temperature: 0.7,
|
||||
topP: 1,
|
||||
disable: false,
|
||||
tools: {},
|
||||
permission: {}
|
||||
})
|
||||
setIsCreateDialogOpen(false)
|
||||
}
|
||||
|
||||
const updateAgent = () => {
|
||||
if (!editingAgent) return
|
||||
|
||||
const updatedAgents = { ...agents }
|
||||
delete updatedAgents[editingAgent.name]
|
||||
|
||||
updatedAgents[editingAgent.name] = editingAgent.agent
|
||||
|
||||
onChange(updatedAgents)
|
||||
setEditingAgent(null)
|
||||
}
|
||||
|
||||
const deleteAgent = (name: string) => {
|
||||
@@ -107,269 +67,21 @@ export function AgentsEditor({ agents, onChange }: AgentsEditorProps) {
|
||||
<h3 className="text-lg font-semibold">Agents</h3>
|
||||
<Dialog open={isCreateDialogOpen} onOpenChange={setIsCreateDialogOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Add Agent
|
||||
<Button className='mr-1 h-6'>
|
||||
<Plus className="h-4 w-4" />
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Create Agent</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div className='space-y-1'>
|
||||
<Label htmlFor="agent-name">Agent Name</Label>
|
||||
<Input
|
||||
id="agent-name"
|
||||
value={newAgentName}
|
||||
onChange={(e) => setNewAgentName(e.target.value)}
|
||||
placeholder="my-agent"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="agent-description">Description</Label>
|
||||
<Input
|
||||
id="agent-description"
|
||||
value={newAgent.description}
|
||||
onChange={(e) => setNewAgent({ ...newAgent, description: e.target.value })}
|
||||
placeholder="Brief description of what the agent does"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="agent-prompt">Prompt</Label>
|
||||
<Textarea
|
||||
id="agent-prompt"
|
||||
value={newAgent.prompt}
|
||||
onChange={(e) => setNewAgent({ ...newAgent, prompt: e.target.value })}
|
||||
placeholder="The system prompt that defines the agent's behavior and role"
|
||||
rows={6}
|
||||
className="font-mono text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="agent-mode">Mode</Label>
|
||||
<Select
|
||||
value={newAgent.mode}
|
||||
onValueChange={(value: 'subagent' | 'primary' | 'all') =>
|
||||
setNewAgent({ ...newAgent, mode: value })
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="subagent">Subagent</SelectItem>
|
||||
<SelectItem value="primary">Primary</SelectItem>
|
||||
<SelectItem value="all">All</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="agent-temperature">Temperature</Label>
|
||||
<Input
|
||||
id="agent-temperature"
|
||||
type="number"
|
||||
min="0"
|
||||
max="2"
|
||||
step="0.1"
|
||||
value={newAgent.temperature}
|
||||
onChange={(e) => setNewAgent({ ...newAgent, temperature: parseFloat(e.target.value) })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="agent-top-p">Top P</Label>
|
||||
<Input
|
||||
id="agent-top-p"
|
||||
type="number"
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.1"
|
||||
value={newAgent.topP}
|
||||
onChange={(e) => setNewAgent({ ...newAgent, topP: parseFloat(e.target.value) })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>Model Configuration</Label>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label htmlFor="agent-model-id">Model ID</Label>
|
||||
<Input
|
||||
id="agent-model-id"
|
||||
value={newAgent.model?.modelID || ''}
|
||||
onChange={(e) => setNewAgent({
|
||||
...newAgent,
|
||||
model: { ...newAgent.model, modelID: e.target.value, providerID: newAgent.model?.providerID || '' }
|
||||
})}
|
||||
placeholder="claude-3-5-sonnet-20241022"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="agent-provider-id">Provider ID</Label>
|
||||
<Input
|
||||
id="agent-provider-id"
|
||||
value={newAgent.model?.providerID || ''}
|
||||
onChange={(e) => setNewAgent({
|
||||
...newAgent,
|
||||
model: { ...newAgent.model, providerID: e.target.value, modelID: newAgent.model?.modelID || '' }
|
||||
})}
|
||||
placeholder="anthropic"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>Tools Configuration</Label>
|
||||
<div className="grid grid-cols-2 gap-2 text-sm">
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
id="tool-write"
|
||||
checked={newAgent.tools?.write ?? true}
|
||||
onCheckedChange={(checked) => setNewAgent({
|
||||
...newAgent,
|
||||
tools: { ...newAgent.tools, write: checked }
|
||||
})}
|
||||
/>
|
||||
<Label htmlFor="tool-write">Write</Label>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
id="tool-edit"
|
||||
checked={newAgent.tools?.edit ?? true}
|
||||
onCheckedChange={(checked) => setNewAgent({
|
||||
...newAgent,
|
||||
tools: { ...newAgent.tools, edit: checked }
|
||||
})}
|
||||
/>
|
||||
<Label htmlFor="tool-edit">Edit</Label>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
id="tool-bash"
|
||||
checked={newAgent.tools?.bash ?? true}
|
||||
onCheckedChange={(checked) => setNewAgent({
|
||||
...newAgent,
|
||||
tools: { ...newAgent.tools, bash: checked }
|
||||
})}
|
||||
/>
|
||||
<Label htmlFor="tool-bash">Bash</Label>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
id="tool-webfetch"
|
||||
checked={newAgent.tools?.webfetch ?? true}
|
||||
onCheckedChange={(checked) => setNewAgent({
|
||||
...newAgent,
|
||||
tools: { ...newAgent.tools, webfetch: checked }
|
||||
})}
|
||||
/>
|
||||
<Label htmlFor="tool-webfetch">Web Fetch</Label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>Permissions</Label>
|
||||
<div className="grid grid-cols-3 gap-2 text-sm">
|
||||
<div>
|
||||
<Label className="text-xs">Edit</Label>
|
||||
<Select
|
||||
value={newAgent.permission?.edit ?? 'allow'}
|
||||
onValueChange={(value: 'ask' | 'allow' | 'deny') =>
|
||||
setNewAgent({
|
||||
...newAgent,
|
||||
permission: { ...newAgent.permission, edit: value }
|
||||
})
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="ask">Ask</SelectItem>
|
||||
<SelectItem value="allow">Allow</SelectItem>
|
||||
<SelectItem value="deny">Deny</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs">Bash</Label>
|
||||
<Select
|
||||
value={typeof newAgent.permission?.bash === 'string' ? newAgent.permission.bash : 'allow'}
|
||||
onValueChange={(value: 'ask' | 'allow' | 'deny') =>
|
||||
setNewAgent({
|
||||
...newAgent,
|
||||
permission: { ...newAgent.permission, bash: value }
|
||||
})
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="ask">Ask</SelectItem>
|
||||
<SelectItem value="allow">Allow</SelectItem>
|
||||
<SelectItem value="deny">Deny</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs">Web Fetch</Label>
|
||||
<Select
|
||||
value={newAgent.permission?.webfetch ?? 'allow'}
|
||||
onValueChange={(value: 'ask' | 'allow' | 'deny') =>
|
||||
setNewAgent({
|
||||
...newAgent,
|
||||
permission: { ...newAgent.permission, webfetch: value }
|
||||
})
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="ask">Ask</SelectItem>
|
||||
<SelectItem value="allow">Allow</SelectItem>
|
||||
<SelectItem value="deny">Deny</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
id="agent-disable"
|
||||
checked={newAgent.disable}
|
||||
onCheckedChange={(checked) => setNewAgent({ ...newAgent, disable: checked })}
|
||||
/>
|
||||
<Label htmlFor="agent-disable">Disable agent</Label>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="outline" onClick={() => setIsCreateDialogOpen(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={createAgent} disabled={!newAgentName.trim()}>
|
||||
Create
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<AgentDialog
|
||||
open={isCreateDialogOpen}
|
||||
onOpenChange={setIsCreateDialogOpen}
|
||||
onSubmit={handleAgentSubmit}
|
||||
/>
|
||||
</Dialog>
|
||||
</div>
|
||||
|
||||
{Object.keys(agents).length === 0 ? (
|
||||
<Card>
|
||||
<CardContent className="p-8 text-center">
|
||||
<CardContent className="p-2 sm:p-8 text-center">
|
||||
<p className="text-muted-foreground">No agents configured. Add your first agent to get started.</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -399,20 +111,20 @@ export function AgentsEditor({ agents, onChange }: AgentsEditorProps) {
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<CardContent className='p-2'>
|
||||
<div className="space-y-2">
|
||||
{agent.description && (
|
||||
<p className="text-sm text-muted-foreground">{agent.description}</p>
|
||||
)}
|
||||
<div className="text-xs text-muted-foreground space-y-1">
|
||||
<p>Mode: {agent.mode}</p>
|
||||
{agent.temperature !== undefined && <p>Temperature: {agent.temperature}</p>}
|
||||
{agent.topP !== undefined && <p>Top P: {agent.topP}</p>}
|
||||
{agent.model?.modelID && <p>Model: {agent.model.providerID}/{agent.model.modelID}</p>}
|
||||
{agent.disable && <p>Status: Disabled</p>}
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground space-y-1">
|
||||
<p>Mode: {agent.mode}</p>
|
||||
{agent.temperature !== undefined && <p>Temperature: {agent.temperature}</p>}
|
||||
{agent.topP !== undefined && <p>Top P: {agent.topP}</p>}
|
||||
{agent.model?.modelID && <p>Model: {agent.model.providerID}/{agent.model.modelID}</p>}
|
||||
{agent.disable && <p>Status: Disabled</p>}
|
||||
</div>
|
||||
{agent.prompt && (
|
||||
<div className="mt-2 p-2 bg-muted rounded text-xs font-mono max-h-20 overflow-y-auto">
|
||||
<div className="mt-2 bg-muted rounded text-xs font-mono overflow-y-auto p-1 rounded-lg">
|
||||
{agent.prompt}
|
||||
</div>
|
||||
)}
|
||||
@@ -423,295 +135,12 @@ export function AgentsEditor({ agents, onChange }: AgentsEditorProps) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Edit Dialog */}
|
||||
<Dialog open={!!editingAgent} onOpenChange={() => setEditingAgent(null)}>
|
||||
<DialogContent className="max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Edit Agent</DialogTitle>
|
||||
</DialogHeader>
|
||||
{editingAgent && (
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="edit-agent-name">Agent Name</Label>
|
||||
<Input
|
||||
id="edit-agent-name"
|
||||
value={editingAgent.name}
|
||||
disabled
|
||||
className="bg-muted"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="edit-agent-description">Description</Label>
|
||||
<Input
|
||||
id="edit-agent-description"
|
||||
value={editingAgent.agent.description || ''}
|
||||
onChange={(e) => setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: { ...editingAgent.agent, description: e.target.value }
|
||||
})}
|
||||
placeholder="Brief description of what the agent does"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="edit-agent-prompt">Prompt</Label>
|
||||
<Textarea
|
||||
id="edit-agent-prompt"
|
||||
value={editingAgent.agent.prompt || ''}
|
||||
onChange={(e) => setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: { ...editingAgent.agent, prompt: e.target.value }
|
||||
})}
|
||||
placeholder="The system prompt that defines the agent's behavior and role"
|
||||
rows={6}
|
||||
className="font-mono text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
<div className='space-y-1'>
|
||||
<Label htmlFor="edit-agent-mode">Mode</Label>
|
||||
<Select
|
||||
value={editingAgent.agent.mode || 'subagent'}
|
||||
onValueChange={(value: 'subagent' | 'primary' | 'all') =>
|
||||
setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: { ...editingAgent.agent, mode: value }
|
||||
})
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="subagent">Subagent</SelectItem>
|
||||
<SelectItem value="primary">Primary</SelectItem>
|
||||
<SelectItem value="all">All</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="edit-agent-temperature">Temperature</Label>
|
||||
<Input
|
||||
id="edit-agent-temperature"
|
||||
type="number"
|
||||
min="0"
|
||||
max="2"
|
||||
step="0.1"
|
||||
value={editingAgent.agent.temperature ?? 0.7}
|
||||
onChange={(e) => setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: { ...editingAgent.agent, temperature: parseFloat(e.target.value) }
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="edit-agent-top-p">Top P</Label>
|
||||
<Input
|
||||
id="edit-agent-top-p"
|
||||
type="number"
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.1"
|
||||
value={editingAgent.agent.topP ?? 1}
|
||||
onChange={(e) => setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: { ...editingAgent.agent, topP: parseFloat(e.target.value) }
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>Model Configuration</Label>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label htmlFor="edit-agent-model-id">Model ID</Label>
|
||||
<Input
|
||||
id="edit-agent-model-id"
|
||||
value={editingAgent.agent.model?.modelID || ''}
|
||||
onChange={(e) => setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: {
|
||||
...editingAgent.agent,
|
||||
model: {
|
||||
...editingAgent.agent.model,
|
||||
modelID: e.target.value,
|
||||
providerID: editingAgent.agent.model?.providerID || ''
|
||||
}
|
||||
}
|
||||
})}
|
||||
placeholder="claude-3-5-sonnet-20241022"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="edit-agent-provider-id">Provider ID</Label>
|
||||
<Input
|
||||
id="edit-agent-provider-id"
|
||||
value={editingAgent.agent.model?.providerID || ''}
|
||||
onChange={(e) => setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: {
|
||||
...editingAgent.agent,
|
||||
model: {
|
||||
...editingAgent.agent.model,
|
||||
providerID: e.target.value,
|
||||
modelID: editingAgent.agent.model?.modelID || ''
|
||||
}
|
||||
}
|
||||
})}
|
||||
placeholder="anthropic"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>Tools Configuration</Label>
|
||||
<div className="grid grid-cols-2 gap-2 text-sm">
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
id="edit-tool-write"
|
||||
checked={editingAgent.agent.tools?.write ?? true}
|
||||
onCheckedChange={(checked) => setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: { ...editingAgent.agent, tools: { ...editingAgent.agent.tools, write: checked } }
|
||||
})}
|
||||
/>
|
||||
<Label htmlFor="edit-tool-write">Write</Label>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
id="edit-tool-edit"
|
||||
checked={editingAgent.agent.tools?.edit ?? true}
|
||||
onCheckedChange={(checked) => setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: { ...editingAgent.agent, tools: { ...editingAgent.agent.tools, edit: checked } }
|
||||
})}
|
||||
/>
|
||||
<Label htmlFor="edit-tool-edit">Edit</Label>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
id="edit-tool-bash"
|
||||
checked={editingAgent.agent.tools?.bash ?? true}
|
||||
onCheckedChange={(checked) => setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: { ...editingAgent.agent, tools: { ...editingAgent.agent.tools, bash: checked } }
|
||||
})}
|
||||
/>
|
||||
<Label htmlFor="edit-tool-bash">Bash</Label>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
id="edit-tool-webfetch"
|
||||
checked={editingAgent.agent.tools?.webfetch ?? true}
|
||||
onCheckedChange={(checked) => setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: { ...editingAgent.agent, tools: { ...editingAgent.agent.tools, webfetch: checked } }
|
||||
})}
|
||||
/>
|
||||
<Label htmlFor="edit-tool-webfetch">Web Fetch</Label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>Permissions</Label>
|
||||
<div className="grid grid-cols-3 gap-2 text-sm">
|
||||
<div>
|
||||
<Label className="text-xs">Edit</Label>
|
||||
<Select
|
||||
value={editingAgent.agent.permission?.edit ?? 'allow'}
|
||||
onValueChange={(value: 'ask' | 'allow' | 'deny') =>
|
||||
setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: { ...editingAgent.agent, permission: { ...editingAgent.agent.permission, edit: value } }
|
||||
})
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="ask">Ask</SelectItem>
|
||||
<SelectItem value="allow">Allow</SelectItem>
|
||||
<SelectItem value="deny">Deny</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs">Bash</Label>
|
||||
<Select
|
||||
value={typeof editingAgent.agent.permission?.bash === 'string' ? editingAgent.agent.permission.bash : 'allow'}
|
||||
onValueChange={(value: 'ask' | 'allow' | 'deny') =>
|
||||
setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: { ...editingAgent.agent, permission: { ...editingAgent.agent.permission, bash: value } }
|
||||
})
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="ask">Ask</SelectItem>
|
||||
<SelectItem value="allow">Allow</SelectItem>
|
||||
<SelectItem value="deny">Deny</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs">Web Fetch</Label>
|
||||
<Select
|
||||
value={editingAgent.agent.permission?.webfetch ?? 'allow'}
|
||||
onValueChange={(value: 'ask' | 'allow' | 'deny') =>
|
||||
setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: { ...editingAgent.agent, permission: { ...editingAgent.agent.permission, webfetch: value } }
|
||||
})
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="ask">Ask</SelectItem>
|
||||
<SelectItem value="allow">Allow</SelectItem>
|
||||
<SelectItem value="deny">Deny</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
id="edit-agent-disable"
|
||||
checked={editingAgent.agent.disable || false}
|
||||
onCheckedChange={(checked) => setEditingAgent({
|
||||
...editingAgent,
|
||||
agent: { ...editingAgent.agent, disable: checked }
|
||||
})}
|
||||
/>
|
||||
<Label htmlFor="edit-agent-disable">Disable agent</Label>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="outline" onClick={() => setEditingAgent(null)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={updateAgent}>
|
||||
Update
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<AgentDialog
|
||||
open={!!editingAgent}
|
||||
onOpenChange={() => setEditingAgent(null)}
|
||||
onSubmit={handleAgentSubmit}
|
||||
editingAgent={editingAgent}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormDescription,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from "@/components/ui/form";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
|
||||
const commandFormSchema = z.object({
|
||||
name: z
|
||||
.string()
|
||||
.min(1, "Command name is required")
|
||||
.regex(
|
||||
/^[a-z0-9-]+$/,
|
||||
"Must be lowercase letters, numbers, and hyphens only",
|
||||
),
|
||||
template: z.string().min(1, "Template is required"),
|
||||
description: z.string().optional(),
|
||||
agent: z.string().optional(),
|
||||
model: z.string().optional(),
|
||||
subtask: z.boolean(),
|
||||
topP: z.number().min(0).max(1).optional(),
|
||||
});
|
||||
|
||||
type CommandFormValues = z.infer<typeof commandFormSchema>;
|
||||
|
||||
interface Command {
|
||||
template: string;
|
||||
description?: string;
|
||||
agent?: string;
|
||||
model?: string;
|
||||
subtask?: boolean;
|
||||
topP?: number;
|
||||
}
|
||||
|
||||
interface CommandDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onSubmit: (name: string, command: Command) => void;
|
||||
editingCommand?: { name: string; command: Command } | null;
|
||||
}
|
||||
|
||||
export function CommandDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
onSubmit,
|
||||
editingCommand,
|
||||
}: CommandDialogProps) {
|
||||
const form = useForm<CommandFormValues>({
|
||||
resolver: zodResolver(commandFormSchema),
|
||||
defaultValues: {
|
||||
name: editingCommand?.name || "",
|
||||
template: editingCommand?.command.template || "",
|
||||
description: editingCommand?.command.description || "",
|
||||
agent: editingCommand?.command.agent || "",
|
||||
model: editingCommand?.command.model || "",
|
||||
subtask: editingCommand?.command.subtask || false,
|
||||
topP: editingCommand?.command.topP ?? 1,
|
||||
},
|
||||
});
|
||||
|
||||
const handleSubmit = (values: CommandFormValues) => {
|
||||
const command: Command = {
|
||||
template: values.template,
|
||||
description: values.description || undefined,
|
||||
agent: values.agent || undefined,
|
||||
model: values.model || undefined,
|
||||
subtask: values.subtask || undefined,
|
||||
topP: values.topP || undefined,
|
||||
};
|
||||
|
||||
onSubmit(values.name, command);
|
||||
form.reset();
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
const handleOpenChange = (isOpen: boolean) => {
|
||||
if (!isOpen) {
|
||||
form.reset();
|
||||
}
|
||||
onOpenChange(isOpen);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||
<DialogContent className="w-full max-w-3xl max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{editingCommand ? "Edit Command" : "Create Command"}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<Form {...form}>
|
||||
<form
|
||||
onSubmit={form.handleSubmit(handleSubmit)}
|
||||
className="space-y-4"
|
||||
>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="name"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Command Name</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
placeholder="my-command"
|
||||
disabled={!!editingCommand}
|
||||
className={editingCommand ? "bg-muted" : ""}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormDescription>
|
||||
Use lowercase letters, numbers, and hyphens only
|
||||
</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="description"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Description</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea
|
||||
{...field}
|
||||
placeholder="Brief description of what the command does"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="template"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Template</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea
|
||||
{...field}
|
||||
placeholder="The prompt template that will be sent to the LLM. Use $ARGUMENTS or $1, $2, etc. for parameters."
|
||||
rows={8}
|
||||
className="font-mono text-sm"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormDescription>
|
||||
Use $ARGUMENTS for all arguments or $1, $2, etc. for
|
||||
specific parameters
|
||||
</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<div className="flex flex-wrap sm:grid grid-cols-3 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="agent"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Agent (optional)</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} placeholder="build" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="topP"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Top P (optional)</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
type="number"
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.1"
|
||||
onChange={(e) =>
|
||||
field.onChange(parseFloat(e.target.value))
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="model"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Model (optional)</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
placeholder="anthropic/claude-3-5-sonnet-20241022"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="subtask"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-4">
|
||||
<div className="space-y-0.5">
|
||||
<FormLabel className="text-base">Run as subtask</FormLabel>
|
||||
<FormDescription>
|
||||
Execute this command as a separate subtask
|
||||
</FormDescription>
|
||||
</div>
|
||||
<FormControl>
|
||||
<Switch
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => handleOpenChange(false)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" disabled={!form.formState.isValid}>
|
||||
{editingCommand ? "Update" : "Create"}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,8 @@ import { useState } from 'react'
|
||||
import { Plus, Trash2, Edit } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Dialog, DialogTrigger } from '@/components/ui/dialog'
|
||||
import { CommandDialog } from './CommandDialog'
|
||||
|
||||
interface Command {
|
||||
template: string
|
||||
@@ -25,61 +22,21 @@ interface CommandsEditorProps {
|
||||
export function CommandsEditor({ commands, onChange }: CommandsEditorProps) {
|
||||
const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false)
|
||||
const [editingCommand, setEditingCommand] = useState<{ name: string; command: Command } | null>(null)
|
||||
const [newCommandName, setNewCommandName] = useState('')
|
||||
const [newCommand, setNewCommand] = useState<Command>({
|
||||
template: '',
|
||||
description: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false,
|
||||
topP: 1
|
||||
})
|
||||
|
||||
const createCommand = () => {
|
||||
if (!newCommandName.trim() || !newCommand.template.trim()) return
|
||||
|
||||
const updatedCommands = {
|
||||
...commands,
|
||||
[newCommandName]: {
|
||||
template: newCommand.template,
|
||||
description: newCommand.description,
|
||||
agent: newCommand.agent || undefined,
|
||||
model: newCommand.model || undefined,
|
||||
subtask: newCommand.subtask || undefined,
|
||||
topP: newCommand.topP || undefined
|
||||
const handleCommandSubmit = (name: string, command: Command) => {
|
||||
if (editingCommand) {
|
||||
const updatedCommands = { ...commands }
|
||||
delete updatedCommands[editingCommand.name]
|
||||
updatedCommands[name] = command
|
||||
onChange(updatedCommands)
|
||||
setEditingCommand(null)
|
||||
} else {
|
||||
const updatedCommands = {
|
||||
...commands,
|
||||
[name]: command
|
||||
}
|
||||
onChange(updatedCommands)
|
||||
}
|
||||
|
||||
onChange(updatedCommands)
|
||||
setNewCommandName('')
|
||||
setNewCommand({
|
||||
template: '',
|
||||
description: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false,
|
||||
topP: 1
|
||||
})
|
||||
setIsCreateDialogOpen(false)
|
||||
}
|
||||
|
||||
const updateCommand = () => {
|
||||
if (!editingCommand) return
|
||||
|
||||
const updatedCommands = { ...commands }
|
||||
delete updatedCommands[editingCommand.name]
|
||||
|
||||
updatedCommands[editingCommand.name] = {
|
||||
template: editingCommand.command.template,
|
||||
description: editingCommand.command.description,
|
||||
agent: editingCommand.command.agent || undefined,
|
||||
model: editingCommand.command.model || undefined,
|
||||
subtask: editingCommand.command.subtask || undefined,
|
||||
topP: editingCommand.command.topP || undefined
|
||||
}
|
||||
|
||||
onChange(updatedCommands)
|
||||
setEditingCommand(null)
|
||||
}
|
||||
|
||||
const deleteCommand = (name: string) => {
|
||||
@@ -98,108 +55,22 @@ export function CommandsEditor({ commands, onChange }: CommandsEditorProps) {
|
||||
<h3 className="text-lg font-semibold">Commands</h3>
|
||||
<Dialog open={isCreateDialogOpen} onOpenChange={setIsCreateDialogOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Add Command
|
||||
<Button className='mr-1 h-6'>
|
||||
<Plus className="h-4 w-4" />
|
||||
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Create Command</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label htmlFor="command-name">Command Name</Label>
|
||||
<Input
|
||||
id="command-name"
|
||||
value={newCommandName}
|
||||
onChange={(e) => setNewCommandName(e.target.value)}
|
||||
placeholder="my-command"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="command-description">Description</Label>
|
||||
<Input
|
||||
id="command-description"
|
||||
value={newCommand.description}
|
||||
onChange={(e) => setNewCommand({ ...newCommand, description: e.target.value })}
|
||||
placeholder="Brief description of what the command does"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="command-template">Template</Label>
|
||||
<Textarea
|
||||
id="command-template"
|
||||
value={newCommand.template}
|
||||
onChange={(e) => setNewCommand({ ...newCommand, template: e.target.value })}
|
||||
placeholder="The prompt template that will be sent to the LLM. Use $ARGUMENTS or $1, $2, etc. for parameters."
|
||||
rows={8}
|
||||
className="font-mono text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
<div>
|
||||
<Label htmlFor="command-agent">Agent (optional)</Label>
|
||||
<Input
|
||||
id="command-agent"
|
||||
value={newCommand.agent}
|
||||
onChange={(e) => setNewCommand({ ...newCommand, agent: e.target.value })}
|
||||
placeholder="build"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="command-model">Model (optional)</Label>
|
||||
<Input
|
||||
id="command-model"
|
||||
value={newCommand.model}
|
||||
onChange={(e) => setNewCommand({ ...newCommand, model: e.target.value })}
|
||||
placeholder="anthropic/claude-3-5-sonnet-20241022"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="command-top-p">Top P (optional)</Label>
|
||||
<Input
|
||||
id="command-top-p"
|
||||
type="number"
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.1"
|
||||
value={newCommand.topP}
|
||||
onChange={(e) => setNewCommand({ ...newCommand, topP: parseFloat(e.target.value) })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
id="command-subtask"
|
||||
checked={newCommand.subtask}
|
||||
onCheckedChange={(checked) => setNewCommand({ ...newCommand, subtask: checked })}
|
||||
/>
|
||||
<Label htmlFor="command-subtask">Run as subtask</Label>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="outline" onClick={() => setIsCreateDialogOpen(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={createCommand} disabled={!newCommandName.trim() || !newCommand.template.trim()}>
|
||||
Create
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<CommandDialog
|
||||
open={isCreateDialogOpen}
|
||||
onOpenChange={setIsCreateDialogOpen}
|
||||
onSubmit={handleCommandSubmit}
|
||||
/>
|
||||
</Dialog>
|
||||
</div>
|
||||
|
||||
{Object.keys(commands).length === 0 ? (
|
||||
<Card>
|
||||
<CardContent className="p-8 text-center">
|
||||
<CardContent className="p-2 sm:p-8 text-center">
|
||||
<p className="text-muted-foreground">No commands configured. Add your first command to get started.</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -229,7 +100,7 @@ export function CommandsEditor({ commands, onChange }: CommandsEditorProps) {
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<CardContent className='p-2'>
|
||||
<div className="space-y-2">
|
||||
{command.description && (
|
||||
<p className="text-sm text-muted-foreground">{command.description}</p>
|
||||
@@ -240,7 +111,7 @@ export function CommandsEditor({ commands, onChange }: CommandsEditorProps) {
|
||||
{command.topP !== undefined && <p>Top P: {command.topP}</p>}
|
||||
{command.subtask && <p>Subtask: Yes</p>}
|
||||
</div>
|
||||
<div className="mt-2 p-2 bg-muted rounded text-xs font-mono max-h-20 overflow-y-auto">
|
||||
<div className="mt-2 bg-muted rounded text-xs font-mono overflow-y-auto p-1 rounded-lg">
|
||||
{command.template}
|
||||
</div>
|
||||
</div>
|
||||
@@ -250,120 +121,12 @@ export function CommandsEditor({ commands, onChange }: CommandsEditorProps) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Edit Dialog */}
|
||||
<Dialog open={!!editingCommand} onOpenChange={() => setEditingCommand(null)}>
|
||||
<DialogContent className="max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Edit Command</DialogTitle>
|
||||
</DialogHeader>
|
||||
{editingCommand && (
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label htmlFor="edit-command-name">Command Name</Label>
|
||||
<Input
|
||||
id="edit-command-name"
|
||||
value={editingCommand.name}
|
||||
disabled
|
||||
className="bg-muted"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="edit-command-description">Description</Label>
|
||||
<Input
|
||||
id="edit-command-description"
|
||||
value={editingCommand.command.description || ''}
|
||||
onChange={(e) => setEditingCommand({
|
||||
...editingCommand,
|
||||
command: { ...editingCommand.command, description: e.target.value }
|
||||
})}
|
||||
placeholder="Brief description of what the command does"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="edit-command-template">Template</Label>
|
||||
<Textarea
|
||||
id="edit-command-template"
|
||||
value={editingCommand.command.template}
|
||||
onChange={(e) => setEditingCommand({
|
||||
...editingCommand,
|
||||
command: { ...editingCommand.command, template: e.target.value }
|
||||
})}
|
||||
placeholder="The prompt template that will be sent to the LLM. Use $ARGUMENTS or $1, $2, etc. for parameters."
|
||||
rows={8}
|
||||
className="font-mono text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
<div>
|
||||
<Label htmlFor="edit-command-agent">Agent (optional)</Label>
|
||||
<Input
|
||||
id="edit-command-agent"
|
||||
value={editingCommand.command.agent || ''}
|
||||
onChange={(e) => setEditingCommand({
|
||||
...editingCommand,
|
||||
command: { ...editingCommand.command, agent: e.target.value }
|
||||
})}
|
||||
placeholder="build"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="edit-command-model">Model (optional)</Label>
|
||||
<Input
|
||||
id="edit-command-model"
|
||||
value={editingCommand.command.model || ''}
|
||||
onChange={(e) => setEditingCommand({
|
||||
...editingCommand,
|
||||
command: { ...editingCommand.command, model: e.target.value }
|
||||
})}
|
||||
placeholder="anthropic/claude-3-5-sonnet-20241022"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="edit-command-top-p">Top P (optional)</Label>
|
||||
<Input
|
||||
id="edit-command-top-p"
|
||||
type="number"
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.1"
|
||||
value={editingCommand.command.topP ?? 1}
|
||||
onChange={(e) => setEditingCommand({
|
||||
...editingCommand,
|
||||
command: { ...editingCommand.command, topP: parseFloat(e.target.value) }
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
id="edit-command-subtask"
|
||||
checked={editingCommand.command.subtask || false}
|
||||
onCheckedChange={(checked) => setEditingCommand({
|
||||
...editingCommand,
|
||||
command: { ...editingCommand.command, subtask: checked }
|
||||
})}
|
||||
/>
|
||||
<Label htmlFor="edit-command-subtask">Run as subtask</Label>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="outline" onClick={() => setEditingCommand(null)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={updateCommand}>
|
||||
Update
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<CommandDialog
|
||||
open={!!editingCommand}
|
||||
onOpenChange={() => setEditingCommand(null)}
|
||||
onSubmit={handleCommandSubmit}
|
||||
editingCommand={editingCommand}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
import { useState, useRef } from 'react'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
|
||||
interface CreateConfigDialogProps {
|
||||
isOpen: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
onCreate: (name: string, content: string, isDefault: boolean) => Promise<void>
|
||||
isUpdating: boolean
|
||||
children?: React.ReactNode
|
||||
}
|
||||
|
||||
export function CreateConfigDialog({ isOpen, onOpenChange, onCreate, isUpdating, children }: CreateConfigDialogProps) {
|
||||
const [name, setName] = useState('')
|
||||
const [content, setContent] = useState('')
|
||||
const [isDefault, setIsDefault] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
const [errorLine, setErrorLine] = useState<number | null>(null)
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null)
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!name.trim() || !content.trim()) return
|
||||
|
||||
try {
|
||||
await onCreate(name.trim(), content.trim(), isDefault)
|
||||
setName('')
|
||||
setContent('')
|
||||
setIsDefault(false)
|
||||
setError('')
|
||||
setErrorLine(null)
|
||||
} catch (error) {
|
||||
if (error instanceof SyntaxError) {
|
||||
const match = error.message.match(/line (\d+)/i)
|
||||
const line = match ? parseInt(match[1]) : null
|
||||
setErrorLine(line)
|
||||
setError(`JSON Error: ${error.message}`)
|
||||
if (line && textareaRef.current) {
|
||||
highlightErrorLine(textareaRef.current, line)
|
||||
}
|
||||
} else if (error instanceof Error) {
|
||||
setError(error.message)
|
||||
setErrorLine(null)
|
||||
} else {
|
||||
setError('Failed to create configuration')
|
||||
setErrorLine(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleFileUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = event.target.files?.[0]
|
||||
if (!file) return
|
||||
|
||||
const reader = new FileReader()
|
||||
reader.onload = (e) => {
|
||||
const fileContent = e.target?.result as string
|
||||
try {
|
||||
JSON.parse(fileContent)
|
||||
setContent(fileContent)
|
||||
setName(file.name.replace('.json', '').replace('.jsonc', ''))
|
||||
} catch {
|
||||
window.alert('Invalid JSON file')
|
||||
}
|
||||
}
|
||||
reader.readAsText(file)
|
||||
}
|
||||
|
||||
const highlightErrorLine = (textarea: HTMLTextAreaElement, line: number) => {
|
||||
const lines = textarea.value.split('\n')
|
||||
if (line > lines.length) return
|
||||
|
||||
let charIndex = 0
|
||||
for (let i = 0; i < line - 1; i++) {
|
||||
charIndex += lines[i].length + 1
|
||||
}
|
||||
|
||||
textarea.focus()
|
||||
textarea.setSelectionRange(charIndex, charIndex + lines[line - 1].length)
|
||||
}
|
||||
|
||||
const handleContentChange = (value: string) => {
|
||||
setContent(value)
|
||||
setError('')
|
||||
setErrorLine(null)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{children}
|
||||
<Dialog open={isOpen} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Create OpenCode Config</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label htmlFor="config-name">Config Name</Label>
|
||||
<Input
|
||||
id="config-name"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder="my-config"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="config-upload">Upload JSON File</Label>
|
||||
<Input
|
||||
id="config-upload"
|
||||
type="file"
|
||||
accept=".json,.jsonc"
|
||||
onChange={handleFileUpload}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="config-content">Config Content (JSON)</Label>
|
||||
<Textarea
|
||||
id="config-content"
|
||||
ref={textareaRef}
|
||||
value={content}
|
||||
onChange={(e) => handleContentChange(e.target.value)}
|
||||
placeholder='{"$schema": "https://opencode.ai/config.json", "theme": "dark"}'
|
||||
rows={20}
|
||||
className="font-mono text-sm"
|
||||
/>
|
||||
{error && (
|
||||
<p className="text-sm text-red-500 mt-2">
|
||||
{error}
|
||||
{errorLine && (
|
||||
<span className="ml-2 text-xs">(Line {errorLine})</span>
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
id="config-default"
|
||||
checked={isDefault}
|
||||
onCheckedChange={setIsDefault}
|
||||
/>
|
||||
<Label htmlFor="config-default">Set as default configuration</Label>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
disabled={isUpdating || !name.trim() || !content.trim()}
|
||||
>
|
||||
{isUpdating && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
|
||||
Create
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -157,9 +157,9 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
|
||||
</div>
|
||||
<Dialog open={isAddDialogOpen} onOpenChange={setIsAddDialogOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Add Server
|
||||
<Button className='mr-1 h-6'>
|
||||
<Plus className="h-4 w-4" />
|
||||
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<AddMcpServerDialog
|
||||
@@ -172,16 +172,16 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
|
||||
|
||||
{Object.keys(mcpServers).length === 0 ? (
|
||||
<Card>
|
||||
<CardContent className="p-8 text-center">
|
||||
<CardContent className="p-2 sm:p-8 text-center">
|
||||
<p className="text-muted-foreground">No MCP servers configured. Add your first server to get started.</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : (
|
||||
<div className="grid gap-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{Object.entries(mcpServers).map(([serverId, serverConfig]) => (
|
||||
<Card key={serverId}>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex items-center gap-2">
|
||||
{serverConfig.type === 'local' ? (
|
||||
@@ -217,7 +217,7 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<CardContent className='p-2'>
|
||||
<div className="text-sm text-muted-foreground space-y-1">
|
||||
<p>{getServerDescription(serverConfig)}</p>
|
||||
{serverConfig.timeout && (
|
||||
@@ -245,4 +245,4 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import { useState, useEffect } from 'react'
|
||||
import { Loader2, Plus, Trash2, Edit, Star, StarOff, Download, RotateCcw } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { DialogTrigger } from '@/components/ui/dialog'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { DeleteDialog } from '@/components/ui/delete-dialog'
|
||||
import { CreateConfigDialog } from './CreateConfigDialog'
|
||||
import { OpenCodeConfigEditor } from './OpenCodeConfigEditor'
|
||||
import { CommandsEditor } from './CommandsEditor'
|
||||
import { AgentsEditor } from './AgentsEditor'
|
||||
@@ -37,16 +35,9 @@ export function OpenCodeConfigManager() {
|
||||
agents: false,
|
||||
mcp: false,
|
||||
})
|
||||
const [newConfigName, setNewConfigName] = useState('')
|
||||
const [newConfigContent, setNewConfigContent] = useState('')
|
||||
const [newConfigIsDefault, setNewConfigIsDefault] = useState(false)
|
||||
|
||||
const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false)
|
||||
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false)
|
||||
const [deleteConfirmConfig, setDeleteConfirmConfig] = useState<OpenCodeConfig | null>(null)
|
||||
const [createError, setCreateError] = useState('')
|
||||
const [createErrorLine, setCreateErrorLine] = useState<number | null>(null)
|
||||
const createTextareaRef = useRef<HTMLTextAreaElement>(null)
|
||||
|
||||
const restartServerMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
@@ -106,48 +97,28 @@ export function OpenCodeConfigManager() {
|
||||
}
|
||||
}, [configs, selectedConfig])
|
||||
|
||||
const createConfig = async () => {
|
||||
if (!newConfigName.trim() || !newConfigContent.trim()) return
|
||||
|
||||
const createConfig = async (name: string, content: string, isDefault: boolean) => {
|
||||
try {
|
||||
setIsUpdating(true)
|
||||
setCreateError('')
|
||||
const content = JSON.parse(newConfigContent)
|
||||
const parsedContent = JSON.parse(content)
|
||||
|
||||
const forbiddenFields = ['id', 'createdAt', 'updatedAt']
|
||||
const foundForbidden = forbiddenFields.filter(field => field in content)
|
||||
const foundForbidden = forbiddenFields.filter(field => field in parsedContent)
|
||||
if (foundForbidden.length > 0) {
|
||||
throw new Error(`Invalid fields found: ${foundForbidden.join(', ')}. These fields are managed automatically.`)
|
||||
}
|
||||
|
||||
await settingsApi.createOpenCodeConfig({
|
||||
name: newConfigName.trim(),
|
||||
content,
|
||||
isDefault: newConfigIsDefault,
|
||||
name: name.trim(),
|
||||
content: parsedContent,
|
||||
isDefault,
|
||||
})
|
||||
|
||||
setNewConfigName('')
|
||||
setNewConfigContent('')
|
||||
setNewConfigIsDefault(false)
|
||||
setIsCreateDialogOpen(false)
|
||||
fetchConfigs()
|
||||
} catch (error) {
|
||||
if (error instanceof SyntaxError) {
|
||||
const match = error.message.match(/line (\d+)/i)
|
||||
const line = match ? parseInt(match[1]) : null
|
||||
setCreateErrorLine(line)
|
||||
setCreateError(`JSON Error: ${error.message}`)
|
||||
if (line && createTextareaRef.current) {
|
||||
highlightErrorLine(createTextareaRef.current, line)
|
||||
}
|
||||
} else if (error instanceof Error) {
|
||||
setCreateError(error.message)
|
||||
setCreateErrorLine(null)
|
||||
} else {
|
||||
setCreateError('Failed to create configuration')
|
||||
setCreateErrorLine(null)
|
||||
}
|
||||
console.error('Failed to create config:', error)
|
||||
throw error
|
||||
} finally {
|
||||
setIsUpdating(false)
|
||||
}
|
||||
@@ -180,23 +151,7 @@ export function OpenCodeConfigManager() {
|
||||
}
|
||||
}
|
||||
|
||||
const uploadConfig = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = event.target.files?.[0]
|
||||
if (!file) return
|
||||
|
||||
const reader = new FileReader()
|
||||
reader.onload = (e) => {
|
||||
const content = e.target?.result as string
|
||||
try {
|
||||
JSON.parse(content)
|
||||
setNewConfigContent(content)
|
||||
setNewConfigName(file.name.replace('.json', '').replace('.jsonc', ''))
|
||||
} catch {
|
||||
window.alert('Invalid JSON file')
|
||||
}
|
||||
}
|
||||
reader.readAsText(file)
|
||||
}
|
||||
|
||||
|
||||
const downloadConfig = (config: OpenCodeConfig) => {
|
||||
const blob = new Blob([JSON.stringify(config.content, null, 2)], { type: 'application/json' })
|
||||
@@ -208,18 +163,7 @@ export function OpenCodeConfigManager() {
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
const highlightErrorLine = (textarea: HTMLTextAreaElement, line: number) => {
|
||||
const lines = textarea.value.split('\n')
|
||||
if (line > lines.length) return
|
||||
|
||||
let charIndex = 0
|
||||
for (let i = 0; i < line - 1; i++) {
|
||||
charIndex += lines[i].length + 1
|
||||
}
|
||||
|
||||
textarea.focus()
|
||||
textarea.setSelectionRange(charIndex, charIndex + lines[line - 1].length)
|
||||
}
|
||||
|
||||
|
||||
const startEdit = (config: OpenCodeConfig) => {
|
||||
setEditingConfig(config)
|
||||
@@ -237,8 +181,7 @@ export function OpenCodeConfigManager() {
|
||||
return (
|
||||
<div className="space-y-6 overflow-y-auto">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-lg font-semibold text-foreground">OpenCode Configurations</h2>
|
||||
<div className="flex gap-2">
|
||||
<div className="flex gap-2 ">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => restartServerMutation.mutate()}
|
||||
@@ -251,84 +194,19 @@ export function OpenCodeConfigManager() {
|
||||
)}
|
||||
Restart Server
|
||||
</Button>
|
||||
<Dialog open={isCreateDialogOpen} onOpenChange={setIsCreateDialogOpen}>
|
||||
<CreateConfigDialog
|
||||
isOpen={isCreateDialogOpen}
|
||||
onOpenChange={setIsCreateDialogOpen}
|
||||
onCreate={createConfig}
|
||||
isUpdating={isUpdating}
|
||||
>
|
||||
<DialogTrigger asChild>
|
||||
<Button>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
New Config
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Create OpenCode Config</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label htmlFor="config-name">Config Name</Label>
|
||||
<Input
|
||||
id="config-name"
|
||||
value={newConfigName}
|
||||
onChange={(e) => setNewConfigName(e.target.value)}
|
||||
placeholder="my-config"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="config-upload">Upload JSON File</Label>
|
||||
<Input
|
||||
id="config-upload"
|
||||
type="file"
|
||||
accept=".json,.jsonc"
|
||||
onChange={uploadConfig}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="config-content">Config Content (JSON)</Label>
|
||||
<Textarea
|
||||
id="config-content"
|
||||
ref={createTextareaRef}
|
||||
value={newConfigContent}
|
||||
onChange={(e) => {
|
||||
setNewConfigContent(e.target.value)
|
||||
setCreateError('')
|
||||
setCreateErrorLine(null)
|
||||
}}
|
||||
placeholder='{"$schema": "https://opencode.ai/config.json", "theme": "dark"}'
|
||||
rows={20}
|
||||
className="font-mono text-sm"
|
||||
/>
|
||||
{createError && (
|
||||
<p className="text-sm text-red-500 mt-2">
|
||||
{createError}
|
||||
{createErrorLine && (
|
||||
<span className="ml-2 text-xs">(Line {createErrorLine})</span>
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
id="config-default"
|
||||
checked={newConfigIsDefault}
|
||||
onCheckedChange={setNewConfigIsDefault}
|
||||
/>
|
||||
<Label htmlFor="config-default">Set as default configuration</Label>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="outline" onClick={() => setIsCreateDialogOpen(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={createConfig} disabled={isUpdating || !newConfigName.trim() || !newConfigContent.trim()}>
|
||||
{isUpdating && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
|
||||
Create
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</CreateConfigDialog>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -339,7 +217,7 @@ export function OpenCodeConfigManager() {
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : (
|
||||
<div className="grid gap-4">
|
||||
<div className="flex flex-col gap-4 md:grid md:grid-cols-2 lg:grid-cols">
|
||||
{configs.map((config) => (
|
||||
<Card key={config.id}>
|
||||
<CardHeader className="pb-3">
|
||||
@@ -392,9 +270,9 @@ export function OpenCodeConfigManager() {
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-sm text-muted-foreground">
|
||||
<p>Updated: {new Date(config.updatedAt).toLocaleString()}</p>
|
||||
<p>Created: {new Date(config.createdAt).toLocaleString()}</p>
|
||||
<div className="text-sm text-muted-foreground break-words">
|
||||
<p className="truncate">Updated: {new Date(config.updatedAt).toLocaleString()}</p>
|
||||
<p className="truncate">Created: {new Date(config.createdAt).toLocaleString()}</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -447,16 +325,16 @@ export function OpenCodeConfigManager() {
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-4 pb-20">
|
||||
<div className="flex flex-col gap-4 pb-20 min-w-0">
|
||||
{selectedConfig ? (
|
||||
<>
|
||||
<div className="bg-card border border-border rounded-lg overflow-hidden">
|
||||
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
|
||||
<button
|
||||
className="w-full px-4 py-3 flex items-center justify-between hover:bg-muted/50 transition-colors"
|
||||
className="w-full px-4 py-3 flex items-center justify-between hover:bg-muted/50 transition-colors min-w-0"
|
||||
onClick={() => setExpandedSections(prev => ({ ...prev, commands: !prev.commands }))}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<h4 className="text-sm font-medium">Commands</h4>
|
||||
<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(selectedConfig.content.command as Record<string, any> || {}).length} configured
|
||||
</span>
|
||||
@@ -464,7 +342,7 @@ export function OpenCodeConfigManager() {
|
||||
<Edit className={`h-4 w-4 transition-transform ${expandedSections.commands ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
<div className={`${expandedSections.commands ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className="p-4 max-h-[50vh] overflow-y-auto">
|
||||
<div className="p-1 sm:p-4 max-h-[50vh] overflow-y-auto">
|
||||
<CommandsEditor
|
||||
commands={(selectedConfig.content.command as Record<string, any>) || {}}
|
||||
onChange={(commands) => {
|
||||
@@ -479,13 +357,13 @@ export function OpenCodeConfigManager() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-lg overflow-hidden">
|
||||
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
|
||||
<button
|
||||
className="w-full px-4 py-3 flex items-center justify-between hover:bg-muted/50 transition-colors"
|
||||
className="w-full px-4 py-3 flex items-center justify-between hover:bg-muted/50 transition-colors min-w-0"
|
||||
onClick={() => setExpandedSections(prev => ({ ...prev, agents: !prev.agents }))}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<h4 className="text-sm font-medium">Agents</h4>
|
||||
<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(selectedConfig.content.agent as Record<string, any> || {}).length} configured
|
||||
</span>
|
||||
@@ -508,13 +386,13 @@ export function OpenCodeConfigManager() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-lg overflow-hidden">
|
||||
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
|
||||
<button
|
||||
className="w-full px-4 py-3 flex items-center justify-between hover:bg-muted/50 transition-colors"
|
||||
className="w-full px-4 py-3 flex items-center justify-between hover:bg-muted/50 transition-colors min-w-0"
|
||||
onClick={() => setExpandedSections(prev => ({ ...prev, mcp: !prev.mcp }))}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<h4 className="text-sm font-medium">MCP Servers</h4>
|
||||
<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((selectedConfig.content.mcp as Record<string, any>) || {}).length} configured
|
||||
</span>
|
||||
|
||||
@@ -38,37 +38,6 @@ const handleRestartServer = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// Debug function to emulate toasts - remove in production
|
||||
if (typeof window !== 'undefined') {
|
||||
(window as any).testToasts = {
|
||||
updateAvailable: () => {
|
||||
showToast.info(`OpenCode v1.2.3 is available`, {
|
||||
description: 'A new version is ready to install.',
|
||||
action: {
|
||||
label: 'Restart to Update',
|
||||
onClick: handleRestartServer
|
||||
},
|
||||
duration: 10000,
|
||||
})
|
||||
},
|
||||
updated: () => {
|
||||
showToast.success(`OpenCode updated to v1.2.3`, {
|
||||
description: 'The server has been successfully upgraded.',
|
||||
duration: 5000,
|
||||
})
|
||||
},
|
||||
restartTest: () => {
|
||||
handleRestartServer()
|
||||
},
|
||||
basic: () => {
|
||||
showToast.info('This is a basic info toast')
|
||||
showToast.success('This is a success toast')
|
||||
showToast.warning('This is a warning toast')
|
||||
showToast.error('This is an error toast')
|
||||
}
|
||||
}
|
||||
console.log('🍞 Toast test functions available: window.testToasts.updateAvailable(), window.testToasts.updated(), window.testToasts.restartTest(), window.testToasts.basic()')
|
||||
}
|
||||
|
||||
export const useSSE = (opcodeUrl: string | null | undefined, directory?: string) => {
|
||||
const client = useOpenCodeClient(opcodeUrl, directory)
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
--color-card: #141414;
|
||||
--color-card-hover: #1a1a1a;
|
||||
--color-border: #2a2a2a;
|
||||
--color-primary: #1e40af;
|
||||
--color-primary-hover: #1e3a8a;
|
||||
--color-primary: #1d4ed8;
|
||||
--color-primary-hover: #1e40af;
|
||||
--color-primary-foreground: #fafafa;
|
||||
--color-muted-foreground: #d4d4d8;
|
||||
--color-accent: #27272a;
|
||||
@@ -26,8 +26,8 @@
|
||||
--color-card: #f9fafb;
|
||||
--color-card-hover: #f3f4f6;
|
||||
--color-border: #e5e7eb;
|
||||
--color-primary: #2563eb;
|
||||
--color-primary-hover: #1d4ed8;
|
||||
--color-primary: #1d4ed8;
|
||||
--color-primary-hover: #1e40af;
|
||||
--color-primary-foreground: #ffffff;
|
||||
--color-muted-foreground: #6b7280;
|
||||
--color-accent: #f3f4f6;
|
||||
|
||||
Reference in new issue
Block a user