All files / web/src/api agents.ts

89.74% Statements 35/39
100% Branches 10/10
87.5% Functions 7/8
89.74% Lines 35/39

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 641x     1x                       3x 3x 1x 1x   2x 2x 1x 1x   2x 2x 1x 1x   1x 1x 1x 1x   1x 1x 1x   1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x                    
import { apiClient } from './config'
import type { StoredAgent } from '@/types/generated/StoredAgent'
import type { AgentNode } from '@/types/generated/AgentNode'
import { API_ENDPOINTS } from '@/constants'
 
export interface CreateAgentRequest {
  name: string
  agent: AgentNode
}
 
export interface UpdateAgentRequest {
  name?: string
  agent?: AgentNode
}
 
export async function listAgents(): Promise<StoredAgent[]> {
  const response = await apiClient.get<StoredAgent[]>(API_ENDPOINTS.AGENT.LIST)
  return response.data
}
 
export async function getAgent(id: string): Promise<StoredAgent> {
  const response = await apiClient.get<StoredAgent>(API_ENDPOINTS.AGENT.GET(id))
  return response.data
}
 
export async function createAgent(data: CreateAgentRequest): Promise<StoredAgent> {
  const response = await apiClient.post<StoredAgent>(API_ENDPOINTS.AGENT.CREATE, data)
  return response.data
}
 
export async function updateAgent(id: string, data: UpdateAgentRequest): Promise<StoredAgent> {
  const response = await apiClient.put<StoredAgent>(API_ENDPOINTS.AGENT.UPDATE(id), data)
  return response.data
}
 
export async function deleteAgent(id: string): Promise<void> {
  await apiClient.delete(API_ENDPOINTS.AGENT.DELETE(id))
}
 
export async function executeAgent(id: string, input: string): Promise<string> {
  const response = await apiClient.post<{ response: string }>(
    API_ENDPOINTS.AGENT.EXECUTE(id),
    { input }
  )
  return response.data.response
}
 
export async function executeAgentInline(agent: any, input: string): Promise<string> {
  const response = await apiClient.post<{ response: string }>(
    API_ENDPOINTS.AGENT.EXECUTE_INLINE,
    { agent, input }
  )
  return response.data.response
}
 
export interface ChatMessage {
  role: 'user' | 'assistant'
  content: string
}
 
export async function getChatHistory(id: string): Promise<ChatMessage[]> {
  const response = await apiClient.get<ChatMessage[]>(`/api/agents/${id}/chat-history`)
  return response.data
}