From 7307ad005485e21a552995d1aa1f10cf5e8a9f5c Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Thu, 7 May 2026 11:45:33 +0800 Subject: [PATCH] feat(web): acp api client (agent_kinds) --- web/src/api/acp.ts | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 web/src/api/acp.ts 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' }), + }, +}