import { api, ApiError } from "./client"; import type { AgentSkillEntry } from "./skillRegistry"; export type SkillGroupRow = { id: string; name: string; description: string | null; isBuiltin: number; createdAt: number; updatedAt: number; }; export type GroupMemberRow = { groupId: string; skillId: string; addedAt: number; }; export type AssignResult = { installed: string[]; skipped: string[]; pendingPlugin: string[]; }; export type GroupExport = { version: "1"; group: { id: string; name: string; description: string | null; members: string[]; parents: string[]; }; }; export const skillGroupsApi = { listGroups: () => api.get("/skill-registry/groups"), getGroup: (groupId: string) => api.get(`/skill-registry/groups/${groupId}`), createGroup: (input: { name: string; description?: string }) => api.post("/skill-registry/groups", input), updateGroup: (groupId: string, patch: { name?: string; description?: string }) => api.patch(`/skill-registry/groups/${groupId}`, patch), deleteGroup: (groupId: string) => api.delete(`/skill-registry/groups/${groupId}`), listMembers: (groupId: string) => api.get(`/skill-registry/groups/${groupId}/members`), addMember: (groupId: string, skillId: string) => api.post<{ ok: boolean }>(`/skill-registry/groups/${groupId}/members`, { skillId }), removeMember: (groupId: string, skillId: string) => api.delete(`/skill-registry/groups/${groupId}/members/${skillId}`), exportGroup: (groupId: string) => api.get(`/skill-registry/groups/${groupId}/export`), importGroup: (data: GroupExport) => api.post("/skill-registry/groups/import", data), listAgentGroups: (agentId: string) => api.get(`/skill-registry/agents/${agentId}/groups`), assignGroup: (agentId: string, groupId: string) => api.post(`/skill-registry/agents/${agentId}/groups`, { groupId, }), removeGroup: async (agentId: string, groupId: string): Promise => { const res = await fetch(`/api/skill-registry/agents/${agentId}/groups/${groupId}`, { method: "DELETE", credentials: "include", }); if (!res.ok && res.status !== 204) { const errorBody = await res.json().catch(() => null); throw new ApiError( (errorBody as { error?: string } | null)?.error ?? `Request failed: ${res.status}`, res.status, errorBody, ); } }, listAgentSkills: (agentId: string) => api.get(`/skill-registry/agents/${agentId}/skills`), };