diff --git a/web/src/api/acp.ts b/web/src/api/acp.ts new file mode 100644 index 0000000..25d6b93 --- /dev/null +++ b/web/src/api/acp.ts @@ -0,0 +1,65 @@ +import { request } from './client' + +// Admin DTO from `internal/acp/dto.go: AgentKindAdminDTO`. +export interface AgentKindAdmin { + id: string + name: string + display_name: string + description: string + binary_path: string + args: string[] + env_keys: string[] + enabled: boolean + created_by: string + created_at: string + updated_at: string +} + +// Public DTO (non-admin view) from `internal/acp/dto.go: AgentKindPublicDTO`. +export interface AgentKindPublic { + id: string + name: string + display_name: string + enabled: boolean +} + +// Type guard distinguishing admin vs public DTO based on presence of admin-only fields. +export function isAgentKindAdmin(k: AgentKindAdmin | AgentKindPublic): k is AgentKindAdmin { + return 'binary_path' in k +} + +export interface CreateAgentKindReq { + name: string + display_name: string + description?: string + binary_path: string + args?: string[] + env?: Record + enabled?: boolean +} + +export interface UpdateAgentKindReq { + display_name?: string + description?: string + binary_path?: string + args?: string[] + env?: Record + enabled?: boolean +} + +const enc = (v: string) => encodeURIComponent(v) + +export const acpApi = { + agentKinds: { + list: () => + request<(AgentKindAdmin | AgentKindPublic)[]>('/api/v1/acp/agent-kinds'), + get: (id: string) => + request(`/api/v1/acp/agent-kinds/${enc(id)}`), + create: (req: CreateAgentKindReq) => + request('/api/v1/acp/agent-kinds', { method: 'POST', body: req }), + update: (id: string, req: UpdateAgentKindReq) => + request(`/api/v1/acp/agent-kinds/${enc(id)}`, { method: 'PATCH', body: req }), + remove: (id: string) => + request(`/api/v1/acp/agent-kinds/${enc(id)}`, { method: 'DELETE' }), + }, +}