Skip to content
28 linesCodeBlameRaw
1/**
2 * What the Marketplace's pages read: the agent catalog's roles with the
3 * workspace's agents, and what the workspace has connected. Each part that
4 * does not answer comes back null, and the page says so.
5 */
6import type { AgentTemplate, User, WorkspaceAgent } from "@g1t/contracts";
7
8import type { ConnectedState } from "./connectors";
9import { connectedStates } from "./connected.server";
10import { workspaceAgents } from "./services.server";
11
12/** An agent as the Marketplace needs it: who it is and which role it was hired into. */
13export type HiredAgent = Pick<WorkspaceAgent, "id" | "handle" | "display_name" | "template" | "archived_at">;
14
15export async function loadCatalog(slug: string, viewer: User): Promise<{ templates: AgentTemplate[] | null; agents: HiredAgent[] | null }> {
16 const [templates, agents] = await Promise.all([
17 workspaceAgents.templates().catch(() => null),
18 workspaceAgents
19 .list(slug, viewer)
20 .then((result) => (result.ok ? result.value.map(({ id, handle, display_name, template, archived_at }) => ({ id, handle, display_name, template, archived_at })) : null))
21 .catch(() => null),
22 ]);
23 return { templates, agents };
24}
25
26export async function loadConnected(slug: string, viewer: User): Promise<Record<string, ConnectedState>> {
27 return connectedStates(slug, viewer);
28}