Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(web): add agent detail layout with navbar, sidebar, and content area

Gener2215f4f38136
diff --git a/src/web/src/app/(app)/w/[slug]/agents/[id]/layout.tsx b/src/web/src/app/(app)/w/[slug]/agents/[id]/layout.tsx
new file mode 100644
index 000000000..33ab10999
--- /dev/null
+++ b/src/web/src/app/(app)/w/[slug]/agents/[id]/layout.tsx
@@ -0,0 +1,132 @@
+"use client";
+
+import { useState, type ReactNode } from "react";
+import { useParams, useRouter } from "next/navigation";
+import { useAgentContext } from "@/contexts/agent-context";
+import { useWorkspace } from "@/contexts/workspace-context";
+import { Button } from "@/components/ui/button";
+import { ConfirmDialog } from "@/components/ui/confirm-dialog";
+import { AgentEditForm } from "@/components/agent-edit-form";
+import { AgentDetailSidebar } from "@/components/agent-detail-sidebar";
+import { cn } from "@/lib/utils";
+import { Pencil, Trash2, X } from "lucide-react";
+
+export default function AgentDetailLayout({ children }: { children: ReactNode }) {
+ const params = useParams();
+ const router = useRouter();
+ const { slug } = useWorkspace();
+ const agentId = params.id as string;
+ const { agents, runtimes, handleDeleteAgent, handleUpdateAgent } = useAgentContext();
+
+ const agent = agents.find((a) => a.id === agentId);
+ const runtime = agent ? runtimes.find((r) => r.id === agent.runtime_id) : null;
+ const isOnline = runtime?.status === "online";
+
+ const [editing, setEditing] = useState(false);
+ const [saving, setSaving] = useState(false);
+ const [agentConfirmOpen, setAgentConfirmOpen] = useState(false);
+ const [agentDeleting, setAgentDeleting] = useState(false);
+
+ return (
+ <>
+ {/* Top navbar */}
+ <div className="flex items-center justify-between border-b border-border/50 px-5 py-2.5">
+ <div className="flex items-center gap-2 min-w-0">
+ {agent && (
+ <span
+ title={isOnline ? "Runtime online" : "Runtime offline"}
+ className={cn(
+ "size-2 rounded-full shrink-0",
+ isOnline ? "bg-status-online" : "bg-status-offline"
+ )}
+ />
+ )}
+ <h1 className="text-sm font-medium truncate">{agent?.name || "Agent"}</h1>
+ {editing && <span className="text-xs text-muted-foreground">/ Settings</span>}
+ </div>
+ {agent && (
+ <div className="flex items-center gap-0.5 shrink-0">
+ {editing ? (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-xs text-muted-foreground h-7 gap-1 px-2"
+ onClick={() => setEditing(false)}
+ >
+ <X className="size-3" />
+ Cancel
+ </Button>
+ ) : (
+ <>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-xs text-muted-foreground h-7 gap-1 px-2"
+ onClick={() => setEditing(true)}
+ >
+ <Pencil className="size-3" />
+ Edit
+ </Button>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-xs text-muted-foreground h-7 px-2 hover:text-destructive"
+ onClick={() => setAgentConfirmOpen(true)}
+ >
+ <Trash2 className="size-3" />
+ Remove
+ </Button>
+ </>
+ )}
+ </div>
+ )}
+ </div>
+
+ {/* Content: edit form OR sidebar + children */}
+ {editing && agent ? (
+ <AgentEditForm
+ agent={agent}
+ runtimes={runtimes}
+ saving={saving}
+ onCancel={() => setEditing(false)}
+ onSave={async (data) => {
+ setSaving(true);
+ try {
+ const ok = await handleUpdateAgent(agent.id, data);
+ if (ok) setEditing(false);
+ return ok;
+ } finally {
+ setSaving(false);
+ }
+ }}
+ />
+ ) : (
+ <div className="flex flex-1 min-h-0">
+ <AgentDetailSidebar agentId={agentId} />
+ <div className="flex-1 min-w-0 overflow-hidden flex flex-col">{children}</div>
+ </div>
+ )}
+
+ {/* Delete agent confirmation */}
+ {agent && (
+ <ConfirmDialog
+ open={agentConfirmOpen}
+ onOpenChange={setAgentConfirmOpen}
+ title="Remove agent"
+ description={`This will permanently delete "${agent.name}" and all its conversations.`}
+ loading={agentDeleting}
+ onConfirm={async () => {
+ setAgentDeleting(true);
+ try {
+ const ok = await handleDeleteAgent(agent.id);
+ if (ok) router.push(`/w/${slug}/home`);
+ } finally {
+ setAgentDeleting(false);
+ setAgentConfirmOpen(false);
+ }
+ }}
+ />
+ )}
+ </>
+ );
+}