Skip to content
24 linesCodeBlameRaw
1/**
2 * What the agent template pages read: the templates and the workspace's
3 * agents, to say which started from each. Each part that does not answer
4 * comes back null, and the page says so.
5 */
6import type { AgentTemplate, User } from "@g1t/contracts";
7
8import type { StartedAgent } from "./agent-templates";
9import { workspaceAgents } from "./services.server";
10
11export async function loadTemplates(
12 slug: string,
13 viewer: User,
14): Promise<{ templates: AgentTemplate[] | null; agents: StartedAgent[] | null; members_create_agents: boolean }> {
15 const [templates, agents, policy] = await Promise.all([
16 workspaceAgents.templates().catch(() => null),
17 workspaceAgents
18 .list(slug, viewer)
19 .then((result) => (result.ok ? result.value.map(({ id, handle, display_name, template, archived_at }) => ({ id, handle, display_name, template, archived_at })) : null))
20 .catch(() => null),
21 workspaceAgents.policy(slug, viewer).catch(() => null),
22 ]);
23 return { templates, agents, members_create_agents: policy?.ok ? policy.value.members_create_agents : true };
24}