import { adminRequest } from "@/lib/admin-http"; import type { AdminRoleRow } from "@/types/api/admin-user"; import type { AgentAdminUserCreatePayload, AgentAdminUserListData, AgentAdminUserRoleSyncPayload, AgentNodeCreatePayload, AgentNodeListData, AgentNodeRow, AgentNodeUpdatePayload, AgentProfilePayload, AgentProfileRow, AgentRoleCreatePayload, AgentRoleListData, AgentTreeData, AgentDelegationGrantsData, AgentDelegationGrantSyncPayload, } from "@/types/api/admin-agent"; import type { AdminUserPermissionRow } from "@/types/api/admin-user"; const A = `/admin`; export async function getAgentTree(adminSiteId?: number): Promise { return adminRequest.get(`${A}/agent-nodes/tree`, { params: adminSiteId ? { admin_site_id: adminSiteId } : undefined, }); } export async function getAgentNodes(adminSiteId?: number): Promise { return adminRequest.get(`${A}/agent-nodes`, { params: adminSiteId ? { admin_site_id: adminSiteId } : undefined, }); } export async function postAgentNode(body: AgentNodeCreatePayload): Promise { return adminRequest.post(`${A}/agent-nodes`, body); } export async function putAgentNode( agentNodeId: number, body: AgentNodeUpdatePayload, ): Promise { return adminRequest.put(`${A}/agent-nodes/${agentNodeId}`, body); } export async function deleteAgentNode(agentNodeId: number): Promise { return adminRequest.delete(`${A}/agent-nodes/${agentNodeId}`); } export async function getAgentNodeProfile(agentNodeId: number): Promise { return adminRequest.get(`${A}/agent-nodes/${agentNodeId}/profile`); } export async function putAgentNodeProfile( agentNodeId: number, body: AgentProfilePayload, ): Promise { return adminRequest.put(`${A}/agent-nodes/${agentNodeId}/profile`, body); } export async function getAgentNodeRoles(agentNodeId: number): Promise { return adminRequest.get(`${A}/agent-nodes/${agentNodeId}/roles`); } export async function postAgentRole( agentNodeId: number, body: AgentRoleCreatePayload, ): Promise { return adminRequest.post(`${A}/agent-nodes/${agentNodeId}/roles`, body); } export async function putAgentRole( roleId: number, body: { name?: string; description?: string | null; status?: number }, ): Promise { return adminRequest.put(`${A}/agent-roles/${roleId}`, body); } export async function putAgentRolePermissions( roleId: number, permissionSlugs: string[], ): Promise { return adminRequest.put(`${A}/agent-roles/${roleId}/permissions`, { permission_slugs: permissionSlugs, }); } export async function deleteAgentRole(roleId: number): Promise<{ deleted: boolean; id: number }> { return adminRequest.delete<{ deleted: boolean; id: number }>(`${A}/agent-roles/${roleId}`); } export async function getAgentNodeAdminUsers(agentNodeId: number): Promise { return adminRequest.get(`${A}/agent-nodes/${agentNodeId}/admin-users`); } export async function postAgentAdminUser( agentNodeId: number, body: AgentAdminUserCreatePayload, ): Promise { return adminRequest.post( `${A}/agent-nodes/${agentNodeId}/admin-users`, body, ); } export async function putAgentAdminUserRoles( adminUserId: number, body: AgentAdminUserRoleSyncPayload, ): Promise { return adminRequest.put( `${A}/agent-admin-users/${adminUserId}/roles`, body, ); } export async function deleteAgentAdminUser( adminUserId: number, ): Promise<{ deleted: boolean; id: number }> { return adminRequest.delete<{ deleted: boolean; id: number }>( `${A}/agent-admin-users/${adminUserId}`, ); } export async function getAgentDelegationGrants( agentNodeId: number, ): Promise { return adminRequest.get( `${A}/agent-nodes/${agentNodeId}/delegation-grants`, ); } export async function putAgentDelegationGrants( agentNodeId: number, body: AgentDelegationGrantSyncPayload, ): Promise { return adminRequest.put( `${A}/agent-nodes/${agentNodeId}/delegation-grants`, body, ); }