Skip to content

An open-source, faster Devin alternative

TypeScript

feat(web): see/edit an agent (click name → detail + edit dialog)

Igor Zalutski5974cd724d1a
diff --git a/web/src/api/client.ts b/web/src/api/client.ts
index 74702289..4ec5bad3 100644
--- a/web/src/api/client.ts
+++ b/web/src/api/client.ts
@@ -378,9 +378,11 @@ export const createAgent = (body: {
S.AgentSchema,
)
+// PATCH bumps revision; name is immutable (create idempotency key). `key`
+// rotates the model credential.
export const updateAgent = (
id: string,
- body: Partial<{ name: string; prompt: string; model: string }>,
+ body: Partial<{ prompt: string; model: string; key: string }>,
) =>
apiFetch(
`/v3/agents/${id}`,
diff --git a/web/src/pages/Agents.tsx b/web/src/pages/Agents.tsx
index 5615b02a..1c8e93a3 100644
--- a/web/src/pages/Agents.tsx
+++ b/web/src/pages/Agents.tsx
@@ -2,7 +2,7 @@ import { useState } from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { Bot, Plus } from 'lucide-react'
import { notifyError } from '@/lib/errors'
-import { getAgents, createAgent, type Agent } from '@/api/client'
+import { getAgents, createAgent, updateAgent, type Agent } from '@/api/client'
import { PageHeader } from '@/components/page-header'
import { Panel } from '@/components/panel'
import { Button } from '@/components/ui/button'
@@ -58,12 +58,48 @@ export default function Agents() {
onError: (e) => notifyError("Couldn't create the agent.", e),
})
+ // See / edit an agent. name is immutable (PATCH covers model/prompt/key); the
+ // current prompt isn't returned (write-only), so editing it is a replace.
+ const [editing, setEditing] = useState<Agent | null>(null)
+ const [editModel, setEditModel] = useState('')
+ const [editPrompt, setEditPrompt] = useState('')
+ const [editKey, setEditKey] = useState('')
+
+ const openEdit = (a: Agent) => {
+ setEditing(a)
+ setEditModel(a.model)
+ setEditPrompt('')
+ setEditKey('')
+ }
+
+ const updateMutation = useMutation({
+ mutationFn: () => {
+ if (!editing) throw new Error('no agent selected')
+ const body: { model?: string; prompt?: string; key?: string } = {}
+ if (editModel.trim() && editModel.trim() !== editing.model)
+ body.model = editModel.trim()
+ if (editPrompt.trim()) body.prompt = editPrompt.trim()
+ if (editKey.trim()) body.key = editKey.trim()
+ return updateAgent(editing.id, body)
+ },
+ onSuccess: () => {
+ void queryClient.invalidateQueries({ queryKey: ['agents'] })
+ setEditing(null)
+ },
+ onError: (e) => notifyError("Couldn't update the agent.", e),
+ })
+
const columns: Column<Agent>[] = [
{
key: 'name',
header: 'Name',
cell: (a) => (
- <span className="text-foreground font-medium">{a.name}</span>
+ <button
+ onClick={() => openEdit(a)}
+ className="text-foreground font-medium underline-offset-4 hover:underline"
+ >
+ {a.name}
+ </button>
),
},
{
@@ -229,6 +265,92 @@ export default function Agents() {
</form>
</DialogContent>
</Dialog>
+
+ <Dialog
+ open={editing !== null}
+ onOpenChange={(open) => !open && setEditing(null)}
+ >
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>{editing?.name}</DialogTitle>
+ <DialogDescription>
+ Edit the model, prompt, or credential. Changes bump the agent's
+ revision; the name is fixed.
+ </DialogDescription>
+ </DialogHeader>
+ {editing ? (
+ <form
+ className="space-y-4"
+ onSubmit={(e) => {
+ e.preventDefault()
+ updateMutation.mutate()
+ }}
+ >
+ <div className="bg-panel-2 text-muted-foreground grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5 rounded-md border p-3 text-xs">
+ <span>Agent ID</span>
+ <span className="text-foreground font-mono">{editing.id}</span>
+ <span>Runtime</span>
+ <span className="text-foreground capitalize">
+ {editing.runtime}
+ </span>
+ <span>Revision</span>
+ <span className="text-foreground font-mono">
+ {editing.revision ?? 1}
+ </span>
+ <span>Credential</span>
+ <span className="text-foreground">
+ {editing.credential_id ? 'Set' : 'None'}
+ </span>
+ </div>
+ <Field label="Model" htmlFor="edit-model">
+ <Input
+ id="edit-model"
+ value={editModel}
+ onChange={(e) => setEditModel(e.target.value)}
+ />
+ </Field>
+ <Field
+ label="New prompt"
+ htmlFor="edit-prompt"
+ description="Leave blank to keep the current prompt (it isn't shown)."
+ >
+ <Textarea
+ id="edit-prompt"
+ value={editPrompt}
+ onChange={(e) => setEditPrompt(e.target.value)}
+ placeholder="Replace the system prompt…"
+ className="min-h-24"
+ />
+ </Field>
+ <Field
+ label="Rotate Anthropic API key"
+ htmlFor="edit-key"
+ description="Leave blank to keep the current credential."
+ >
+ <Input
+ id="edit-key"
+ type="password"
+ value={editKey}
+ onChange={(e) => setEditKey(e.target.value)}
+ placeholder="sk-ant-…"
+ />
+ </Field>
+ <DialogFooter className="mt-2">
+ <Button
+ type="button"
+ variant="ghost"
+ onClick={() => setEditing(null)}
+ >
+ Cancel
+ </Button>
+ <Button type="submit" disabled={updateMutation.isPending}>
+ {updateMutation.isPending ? 'Saving…' : 'Save changes'}
+ </Button>
+ </DialogFooter>
+ </form>
+ ) : null}
+ </DialogContent>
+ </Dialog>
</div>
)
}