34 lines
1.9 KiB
TypeScript
34 lines
1.9 KiB
TypeScript
import { apiRequest } from '@/lib/api'
|
|
import type { AgentDefinition, AgentDetail, AgentRunDetail, AgentRunListResponse, AgentVersion } from './types'
|
|
|
|
export const listAgents = () => apiRequest<AgentDefinition[]>('/agents')
|
|
export const createAgent = (payload: object) => apiRequest<AgentDetail>('/agents', { method: 'POST', body: JSON.stringify(payload) })
|
|
export const getAgent = (id: number) => apiRequest<AgentDetail>(`/agents/${id}`)
|
|
export const updateAgent = (id: number, payload: object) => apiRequest<AgentDetail>(`/agents/${id}`, { method: 'PATCH', body: JSON.stringify(payload) })
|
|
export const ensureAgentDraft = (id: number) => apiRequest<AgentVersion>(`/agents/${id}/draft`, { method: 'POST' })
|
|
export const updateAgentDraft = (id: number, payload: object) => apiRequest<AgentVersion>(`/agents/${id}/draft`, { method: 'PATCH', body: JSON.stringify(payload) })
|
|
export const publishAgent = (id: number) => apiRequest<AgentVersion>(`/agents/${id}/publish`, { method: 'POST' })
|
|
export const rollbackAgent = (id: number, version: number) => apiRequest<AgentDetail>(`/agents/${id}/rollback/${version}`, { method: 'POST' })
|
|
export const startAgentRun = (id: number, payload: object) => apiRequest<AgentRunDetail>(`/agents/${id}/runs`, { method: 'POST', body: JSON.stringify(payload) })
|
|
export const listAgentRuns = ({
|
|
page = 1,
|
|
pageSize = 20,
|
|
status,
|
|
agentId
|
|
}: {
|
|
page?: number
|
|
pageSize?: number
|
|
status?: string
|
|
agentId?: number
|
|
} = {}) => {
|
|
const params = new URLSearchParams({
|
|
page: String(page),
|
|
page_size: String(pageSize)
|
|
})
|
|
if (status) params.set('status', status)
|
|
if (agentId) params.set('agent_id', String(agentId))
|
|
return apiRequest<AgentRunListResponse>(`/agent-runs?${params.toString()}`)
|
|
}
|
|
export const getAgentRun = (id: string) => apiRequest<AgentRunDetail>(`/agent-runs/${id}`)
|
|
export const cancelAgentRun = (id: string) => apiRequest<AgentRunDetail>(`/agent-runs/${id}/cancel`, { method: 'POST' })
|