| 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 | */ |
| 6 | import type { AgentTemplate, User, WorkspaceAgent } from "@g1t/contracts"; |
| 7 | |
| 8 | import type { ConnectedState } from "./connectors"; |
| 9 | import { connectedStates } from "./connected.server"; |
| 10 | import { workspaceAgents } from "./services.server"; |
| 11 | |
| 12 | /** An agent as the Marketplace needs it: who it is and which role it was hired into. */ |
| 13 | export type HiredAgent = Pick<WorkspaceAgent, "id" | "handle" | "display_name" | "template" | "archived_at">; |
| 14 | |
| 15 | export 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 | |
| 26 | export async function loadConnected(slug: string, viewer: User): Promise<Record<string, ConnectedState>> { |
| 27 | return connectedStates(slug, viewer); |
| 28 | } |