Skip to content
87 linesCodeBlameRaw
1/**
2 * Agent templates: the starting points g1t provides for a new agent, by
3 * department, with the agents in the workspace that started from each. A
4 * template isn't installed: an owner starts an agent from one and
5 * configures it, and the agent is the workspace's own from then on.
6 */
7import { ArrowLeft, Plus } from "lucide-react";
8import { Link, data } from "react-router";
9
10import type { Route } from "./+types/templates";
11import { TemplateCard } from "../../../components/agent-templates";
12import { EmptyState } from "../../../components/ui";
13import { byDepartment, startPath, templateListings } from "../../../lib/agent-templates";
14import { loadTemplates } from "../../../lib/agent-templates.server";
15import { page } from "../../../lib/meta";
16import { requireUser, roleIn } from "../../../lib/session.server";
17
18export function meta({ params, ...args }: Route.MetaArgs) {
19 return page(args, { title: `Agent templates · ${params.owner} · g1t` });
20}
21
22export async function loader({ params, context, request }: Route.LoaderArgs) {
23 const viewer = requireUser(context, request);
24 const slug = params.owner.toLowerCase();
25 const role = roleIn(viewer, slug);
26 if (!role) throw data(null, { status: 404 });
27 return { slug, owner: role === "owner", ...(await loadTemplates(slug, viewer)) };
28}
29
30export default function AgentTemplates({ loaderData }: Route.ComponentProps) {
31 const { slug, owner, templates, agents } = loaderData;
32 const listings = templateListings(templates ?? [], agents);
33 return (
34 <div className="pb-4">
35 <Link to={`/${slug}/-/agents`} className="inline-flex items-center gap-1.5 text-sm text-muted hover:text-fg">
36 <ArrowLeft size={14} />
37 Agents
38 </Link>
39 <header className="mt-4 mb-8 flex flex-wrap items-end justify-between gap-4">
40 <div className="min-w-0 grow basis-lg">
41 <h1 className="text-2xl font-semibold tracking-tight">Templates</h1>
42 <p className="mt-1.5 max-w-2xl text-sm text-muted">
43 Starting points for a new agent, each a role with responsibilities, helpers, a voice, model limits and instructions. Start an agent from one and make it yours: its name, instructions, voice, models and budget are all
44 yours to change, then and later. A template is never updated under an agent started from it.
45 </p>
46 </div>
47 {owner && (
48 <Link to={`/${slug}/-/agents/new`} className="inline-flex h-9 shrink-0 items-center gap-1.5 rounded-md bg-fg px-4 text-sm font-medium text-bg hover:bg-fg-hover">
49 <Plus size={15} />
50 New agent
51 </Link>
52 )}
53 </header>
54 {templates == null ? (
55 <EmptyState title="Templates can't be shown right now">The agents service didn't answer. Reload in a minute.</EmptyState>
56 ) : (
57 <div className="space-y-10">
58 {/* One grid in department order: most departments have a single template. */}
59 <div className="grid gap-3 sm:grid-cols-2 xl:grid-cols-3">
60 {byDepartment(listings)
61 .flatMap(([, list]) => list)
62 .map((listing) => (
63 <TemplateCard key={listing.template.id} listing={listing} slug={slug} owner={owner} />
64 ))}
65 </div>
66 {owner && (
67 <section aria-label="Your own">
68 <h2 className="mb-3 text-xs font-semibold tracking-wide text-faint uppercase">Your own</h2>
69 <Link
70 to={startPath(slug, "blank")}
71 className="flex max-w-md items-center gap-3 rounded-xl border border-dashed border-line-strong p-4 text-sm transition-colors hover:border-fg/40 hover:bg-raised/40"
72 >
73 <span className="flex size-11 shrink-0 items-center justify-center rounded-lg bg-raised text-muted">
74 <Plus size={18} />
75 </span>
76 <span className="min-w-0">
77 <span className="block font-medium">Start from nothing</span>
78 <span className="block text-xs text-muted">Give it a name, a title, a team and what it is responsible for.</span>
79 </span>
80 </Link>
81 </section>
82 )}
83 </div>
84 )}
85 </div>
86 );
87}