2026-02-04 14:58:14 +05:30
|
|
|
"use client";
|
|
|
|
|
|
2026-02-06 22:51:58 +00:00
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
import { useState } from "react";
|
2026-02-04 14:58:14 +05:30
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
|
2026-02-06 22:49:54 +00:00
|
|
|
import { SignInButton, SignedIn, SignedOut, useAuth } from "@/auth/clerk";
|
2026-02-04 14:58:14 +05:30
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
import { ApiError } from "@/api/mutator";
|
|
|
|
|
import {
|
|
|
|
|
type listBoardsApiV1BoardsGetResponse,
|
|
|
|
|
useListBoardsApiV1BoardsGet,
|
|
|
|
|
} from "@/api/generated/boards/boards";
|
|
|
|
|
import { useCreateAgentApiV1AgentsPost } from "@/api/generated/agents/agents";
|
|
|
|
|
import type { BoardRead } from "@/api/generated/model";
|
2026-02-04 14:58:14 +05:30
|
|
|
import { DashboardSidebar } from "@/components/organisms/DashboardSidebar";
|
|
|
|
|
import { DashboardShell } from "@/components/templates/DashboardShell";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
2026-02-05 00:44:23 +05:30
|
|
|
import SearchableSelect, {
|
|
|
|
|
type SearchableSelectOption,
|
|
|
|
|
} from "@/components/ui/searchable-select";
|
2026-02-05 02:21:38 +05:30
|
|
|
import {
|
|
|
|
|
Select,
|
|
|
|
|
SelectContent,
|
|
|
|
|
SelectItem,
|
|
|
|
|
SelectTrigger,
|
|
|
|
|
SelectValue,
|
|
|
|
|
} from "@/components/ui/select";
|
2026-02-04 23:07:22 +05:30
|
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
|
|
|
import {
|
2026-02-05 02:21:38 +05:30
|
|
|
DEFAULT_IDENTITY_PROFILE,
|
2026-02-04 23:07:22 +05:30
|
|
|
DEFAULT_SOUL_TEMPLATE,
|
|
|
|
|
} from "@/lib/agent-templates";
|
2026-02-04 14:58:14 +05:30
|
|
|
|
2026-02-05 02:21:38 +05:30
|
|
|
type IdentityProfile = {
|
|
|
|
|
role: string;
|
|
|
|
|
communication_style: string;
|
|
|
|
|
emoji: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const EMOJI_OPTIONS = [
|
|
|
|
|
{ value: ":gear:", label: "Gear", glyph: "⚙️" },
|
|
|
|
|
{ value: ":sparkles:", label: "Sparkles", glyph: "✨" },
|
|
|
|
|
{ value: ":rocket:", label: "Rocket", glyph: "🚀" },
|
|
|
|
|
{ value: ":megaphone:", label: "Megaphone", glyph: "📣" },
|
|
|
|
|
{ value: ":chart_with_upwards_trend:", label: "Growth", glyph: "📈" },
|
|
|
|
|
{ value: ":bulb:", label: "Idea", glyph: "💡" },
|
|
|
|
|
{ value: ":wrench:", label: "Builder", glyph: "🔧" },
|
|
|
|
|
{ value: ":shield:", label: "Shield", glyph: "🛡️" },
|
|
|
|
|
{ value: ":memo:", label: "Notes", glyph: "📝" },
|
|
|
|
|
{ value: ":brain:", label: "Brain", glyph: "🧠" },
|
|
|
|
|
];
|
|
|
|
|
|
2026-02-05 00:44:23 +05:30
|
|
|
const HEARTBEAT_TARGET_OPTIONS: SearchableSelectOption[] = [
|
|
|
|
|
{ value: "none", label: "None (no outbound message)" },
|
|
|
|
|
{ value: "last", label: "Last channel" },
|
|
|
|
|
];
|
|
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
const getBoardOptions = (boards: BoardRead[]): SearchableSelectOption[] =>
|
2026-02-05 00:44:23 +05:30
|
|
|
boards.map((board) => ({
|
|
|
|
|
value: board.id,
|
|
|
|
|
label: board.name,
|
|
|
|
|
}));
|
|
|
|
|
|
2026-02-05 02:21:38 +05:30
|
|
|
const normalizeIdentityProfile = (
|
|
|
|
|
profile: IdentityProfile
|
|
|
|
|
): IdentityProfile | null => {
|
|
|
|
|
const normalized: IdentityProfile = {
|
|
|
|
|
role: profile.role.trim(),
|
|
|
|
|
communication_style: profile.communication_style.trim(),
|
|
|
|
|
emoji: profile.emoji.trim(),
|
|
|
|
|
};
|
|
|
|
|
const hasValue = Object.values(normalized).some((value) => value.length > 0);
|
|
|
|
|
return hasValue ? normalized : null;
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-04 14:58:14 +05:30
|
|
|
export default function NewAgentPage() {
|
|
|
|
|
const router = useRouter();
|
2026-02-06 16:12:04 +05:30
|
|
|
const { isSignedIn } = useAuth();
|
2026-02-04 14:58:14 +05:30
|
|
|
|
|
|
|
|
const [name, setName] = useState("");
|
2026-02-04 16:04:52 +05:30
|
|
|
const [boardId, setBoardId] = useState<string>("");
|
2026-02-04 17:05:58 +05:30
|
|
|
const [heartbeatEvery, setHeartbeatEvery] = useState("10m");
|
|
|
|
|
const [heartbeatTarget, setHeartbeatTarget] = useState("none");
|
2026-02-05 02:21:38 +05:30
|
|
|
const [identityProfile, setIdentityProfile] = useState<IdentityProfile>({
|
|
|
|
|
...DEFAULT_IDENTITY_PROFILE,
|
|
|
|
|
});
|
2026-02-04 23:07:22 +05:30
|
|
|
const [soulTemplate, setSoulTemplate] = useState(DEFAULT_SOUL_TEMPLATE);
|
2026-02-04 14:58:14 +05:30
|
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
const boardsQuery = useListBoardsApiV1BoardsGet<
|
|
|
|
|
listBoardsApiV1BoardsGetResponse,
|
|
|
|
|
ApiError
|
2026-02-06 19:11:11 +05:30
|
|
|
>(undefined, {
|
2026-02-06 16:12:04 +05:30
|
|
|
query: {
|
|
|
|
|
enabled: Boolean(isSignedIn),
|
|
|
|
|
refetchOnMount: "always",
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-02-04 16:04:52 +05:30
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
const createAgentMutation = useCreateAgentApiV1AgentsPost<ApiError>({
|
|
|
|
|
mutation: {
|
|
|
|
|
onSuccess: (result) => {
|
|
|
|
|
if (result.status === 200) {
|
|
|
|
|
router.push(`/agents/${result.data.id}`);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onError: (err) => {
|
|
|
|
|
setError(err.message || "Something went wrong.");
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-06 19:11:11 +05:30
|
|
|
const boards =
|
|
|
|
|
boardsQuery.data?.status === 200 ? boardsQuery.data.data.items ?? [] : [];
|
2026-02-06 16:12:04 +05:30
|
|
|
const displayBoardId = boardId || boards[0]?.id || "";
|
|
|
|
|
const isLoading = boardsQuery.isLoading || createAgentMutation.isPending;
|
|
|
|
|
const errorMessage = error ?? boardsQuery.error?.message ?? null;
|
2026-02-04 16:04:52 +05:30
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
2026-02-04 14:58:14 +05:30
|
|
|
event.preventDefault();
|
|
|
|
|
if (!isSignedIn) return;
|
|
|
|
|
const trimmed = name.trim();
|
|
|
|
|
if (!trimmed) {
|
|
|
|
|
setError("Agent name is required.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-06 16:12:04 +05:30
|
|
|
const resolvedBoardId = displayBoardId;
|
|
|
|
|
if (!resolvedBoardId) {
|
2026-02-04 16:04:52 +05:30
|
|
|
setError("Select a board before creating an agent.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-04 14:58:14 +05:30
|
|
|
setError(null);
|
2026-02-06 16:12:04 +05:30
|
|
|
createAgentMutation.mutate({
|
|
|
|
|
data: {
|
|
|
|
|
name: trimmed,
|
|
|
|
|
board_id: resolvedBoardId,
|
|
|
|
|
heartbeat_config: {
|
|
|
|
|
every: heartbeatEvery.trim() || "10m",
|
|
|
|
|
target: heartbeatTarget,
|
2026-02-04 14:58:14 +05:30
|
|
|
},
|
2026-02-06 16:12:04 +05:30
|
|
|
identity_profile: normalizeIdentityProfile(identityProfile) as unknown as Record<
|
|
|
|
|
string,
|
|
|
|
|
unknown
|
|
|
|
|
> | null,
|
|
|
|
|
soul_template: soulTemplate.trim() || null,
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-02-04 14:58:14 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<DashboardShell>
|
|
|
|
|
<SignedOut>
|
2026-02-04 21:44:21 +05:30
|
|
|
<div className="col-span-2 flex min-h-[calc(100vh-64px)] items-center justify-center bg-slate-50 p-10 text-center">
|
|
|
|
|
<div className="rounded-xl border border-slate-200 bg-white px-8 py-6 shadow-sm">
|
|
|
|
|
<p className="text-sm text-slate-600">Sign in to create an agent.</p>
|
|
|
|
|
<SignInButton
|
|
|
|
|
mode="modal"
|
|
|
|
|
forceRedirectUrl="/agents/new"
|
|
|
|
|
signUpForceRedirectUrl="/agents/new"
|
|
|
|
|
>
|
|
|
|
|
<Button className="mt-4">Sign in</Button>
|
|
|
|
|
</SignInButton>
|
|
|
|
|
</div>
|
2026-02-04 14:58:14 +05:30
|
|
|
</div>
|
|
|
|
|
</SignedOut>
|
|
|
|
|
<SignedIn>
|
|
|
|
|
<DashboardSidebar />
|
2026-02-04 21:44:21 +05:30
|
|
|
<main className="flex-1 overflow-y-auto bg-slate-50">
|
|
|
|
|
<div className="border-b border-slate-200 bg-white px-8 py-6">
|
|
|
|
|
<div>
|
|
|
|
|
<h1 className="font-heading text-2xl font-semibold text-slate-900 tracking-tight">
|
|
|
|
|
Create agent
|
|
|
|
|
</h1>
|
|
|
|
|
<p className="mt-1 text-sm text-slate-500">
|
|
|
|
|
Agents start in provisioning until they check in.
|
|
|
|
|
</p>
|
2026-02-04 14:58:14 +05:30
|
|
|
</div>
|
2026-02-04 21:44:21 +05:30
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="p-8">
|
|
|
|
|
<form
|
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
|
className="rounded-xl border border-slate-200 bg-white p-6 shadow-sm space-y-6"
|
|
|
|
|
>
|
|
|
|
|
<div>
|
|
|
|
|
<p className="text-xs font-semibold uppercase tracking-wider text-slate-500">
|
2026-02-05 02:21:38 +05:30
|
|
|
Basic configuration
|
2026-02-04 16:04:52 +05:30
|
|
|
</p>
|
2026-02-05 02:21:38 +05:30
|
|
|
<div className="mt-4 space-y-6">
|
|
|
|
|
<div className="grid gap-6 md:grid-cols-2">
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label className="text-sm font-medium text-slate-900">
|
|
|
|
|
Agent name <span className="text-red-500">*</span>
|
|
|
|
|
</label>
|
|
|
|
|
<Input
|
|
|
|
|
value={name}
|
|
|
|
|
onChange={(event) => setName(event.target.value)}
|
|
|
|
|
placeholder="e.g. Deploy bot"
|
|
|
|
|
disabled={isLoading}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label className="text-sm font-medium text-slate-900">
|
|
|
|
|
Role
|
|
|
|
|
</label>
|
|
|
|
|
<Input
|
|
|
|
|
value={identityProfile.role}
|
|
|
|
|
onChange={(event) =>
|
|
|
|
|
setIdentityProfile((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
role: event.target.value,
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
placeholder="e.g. Founder, Social Media Manager"
|
|
|
|
|
disabled={isLoading}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-02-04 21:44:21 +05:30
|
|
|
</div>
|
2026-02-05 02:21:38 +05:30
|
|
|
<div className="grid gap-6 md:grid-cols-2">
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label className="text-sm font-medium text-slate-900">
|
|
|
|
|
Board <span className="text-red-500">*</span>
|
|
|
|
|
</label>
|
|
|
|
|
<SearchableSelect
|
|
|
|
|
ariaLabel="Select board"
|
2026-02-06 16:12:04 +05:30
|
|
|
value={displayBoardId}
|
2026-02-05 02:21:38 +05:30
|
|
|
onValueChange={setBoardId}
|
|
|
|
|
options={getBoardOptions(boards)}
|
|
|
|
|
placeholder="Select board"
|
|
|
|
|
searchPlaceholder="Search boards..."
|
|
|
|
|
emptyMessage="No matching boards."
|
|
|
|
|
triggerClassName="w-full h-11 rounded-xl border border-slate-300 bg-white px-3 py-2 text-sm font-medium text-slate-900 shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-200"
|
|
|
|
|
contentClassName="rounded-xl border border-slate-200 shadow-lg"
|
|
|
|
|
itemClassName="px-4 py-3 text-sm text-slate-700 data-[selected=true]:bg-slate-50 data-[selected=true]:text-slate-900"
|
|
|
|
|
disabled={boards.length === 0}
|
|
|
|
|
/>
|
|
|
|
|
{boards.length === 0 ? (
|
|
|
|
|
<p className="text-xs text-slate-500">
|
|
|
|
|
Create a board before adding agents.
|
|
|
|
|
</p>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label className="text-sm font-medium text-slate-900">
|
|
|
|
|
Emoji
|
|
|
|
|
</label>
|
|
|
|
|
<Select
|
|
|
|
|
value={identityProfile.emoji}
|
|
|
|
|
onValueChange={(value) =>
|
|
|
|
|
setIdentityProfile((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
emoji: value,
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
disabled={isLoading}
|
|
|
|
|
>
|
|
|
|
|
<SelectTrigger>
|
|
|
|
|
<SelectValue placeholder="Select emoji" />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
{EMOJI_OPTIONS.map((option) => (
|
|
|
|
|
<SelectItem key={option.value} value={option.value}>
|
|
|
|
|
{option.glyph} {option.label}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
2026-02-04 21:44:21 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-02-04 23:07:22 +05:30
|
|
|
<div>
|
|
|
|
|
<p className="text-xs font-semibold uppercase tracking-wider text-slate-500">
|
2026-02-05 02:21:38 +05:30
|
|
|
Personality & behavior
|
2026-02-04 23:07:22 +05:30
|
|
|
</p>
|
2026-02-05 02:21:38 +05:30
|
|
|
<div className="mt-4 space-y-6">
|
2026-02-04 23:07:22 +05:30
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label className="text-sm font-medium text-slate-900">
|
2026-02-05 02:21:38 +05:30
|
|
|
Communication style
|
2026-02-04 23:07:22 +05:30
|
|
|
</label>
|
2026-02-05 02:21:38 +05:30
|
|
|
<Input
|
|
|
|
|
value={identityProfile.communication_style}
|
|
|
|
|
onChange={(event) =>
|
|
|
|
|
setIdentityProfile((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
communication_style: event.target.value,
|
|
|
|
|
}))
|
|
|
|
|
}
|
2026-02-04 23:07:22 +05:30
|
|
|
disabled={isLoading}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label className="text-sm font-medium text-slate-900">
|
|
|
|
|
Soul template
|
|
|
|
|
</label>
|
|
|
|
|
<Textarea
|
|
|
|
|
value={soulTemplate}
|
|
|
|
|
onChange={(event) => setSoulTemplate(event.target.value)}
|
|
|
|
|
rows={10}
|
|
|
|
|
disabled={isLoading}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-02-04 21:44:21 +05:30
|
|
|
<div>
|
|
|
|
|
<p className="text-xs font-semibold uppercase tracking-wider text-slate-500">
|
2026-02-05 02:21:38 +05:30
|
|
|
Schedule & notifications
|
2026-02-04 21:44:21 +05:30
|
|
|
</p>
|
|
|
|
|
<div className="mt-4 grid gap-6 md:grid-cols-2">
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label className="text-sm font-medium text-slate-900">
|
|
|
|
|
Interval
|
|
|
|
|
</label>
|
|
|
|
|
<Input
|
|
|
|
|
value={heartbeatEvery}
|
|
|
|
|
onChange={(event) => setHeartbeatEvery(event.target.value)}
|
|
|
|
|
placeholder="e.g. 10m"
|
|
|
|
|
disabled={isLoading}
|
|
|
|
|
/>
|
|
|
|
|
<p className="text-xs text-slate-500">
|
|
|
|
|
How often this agent runs HEARTBEAT.md (10m, 30m, 2h).
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label className="text-sm font-medium text-slate-900">
|
|
|
|
|
Target
|
|
|
|
|
</label>
|
2026-02-05 00:44:23 +05:30
|
|
|
<SearchableSelect
|
|
|
|
|
ariaLabel="Select heartbeat target"
|
2026-02-04 21:44:21 +05:30
|
|
|
value={heartbeatTarget}
|
2026-02-05 00:44:23 +05:30
|
|
|
onValueChange={setHeartbeatTarget}
|
|
|
|
|
options={HEARTBEAT_TARGET_OPTIONS}
|
|
|
|
|
placeholder="Select target"
|
|
|
|
|
searchPlaceholder="Search targets..."
|
|
|
|
|
emptyMessage="No matching targets."
|
|
|
|
|
triggerClassName="w-full h-11 rounded-xl border border-slate-300 bg-white px-3 py-2 text-sm font-medium text-slate-900 shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-200"
|
|
|
|
|
contentClassName="rounded-xl border border-slate-200 shadow-lg"
|
|
|
|
|
itemClassName="px-4 py-3 text-sm text-slate-700 data-[selected=true]:bg-slate-50 data-[selected=true]:text-slate-900"
|
2026-02-04 21:44:21 +05:30
|
|
|
disabled={isLoading}
|
2026-02-05 00:44:23 +05:30
|
|
|
/>
|
2026-02-04 21:44:21 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
{errorMessage ? (
|
2026-02-04 21:44:21 +05:30
|
|
|
<div className="rounded-lg border border-slate-200 bg-white p-3 text-sm text-slate-600 shadow-sm">
|
2026-02-06 16:12:04 +05:30
|
|
|
{errorMessage}
|
2026-02-04 21:44:21 +05:30
|
|
|
</div>
|
2026-02-04 16:04:52 +05:30
|
|
|
) : null}
|
2026-02-04 21:44:21 +05:30
|
|
|
|
|
|
|
|
<div className="flex flex-wrap items-center gap-3">
|
|
|
|
|
<Button type="submit" disabled={isLoading}>
|
|
|
|
|
{isLoading ? "Creating…" : "Create agent"}
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => router.push("/agents")}
|
|
|
|
|
>
|
|
|
|
|
Back to agents
|
|
|
|
|
</Button>
|
2026-02-04 14:58:14 +05:30
|
|
|
</div>
|
2026-02-04 21:44:21 +05:30
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
2026-02-04 14:58:14 +05:30
|
|
|
</SignedIn>
|
|
|
|
|
</DashboardShell>
|
|
|
|
|
);
|
|
|
|
|
}
|