2026-05-02 03:18:47 +02:00
|
|
|
/**
|
|
|
|
|
* Agents API Client
|
|
|
|
|
*
|
|
|
|
|
* Fetches agent data from the backend API.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import api from "./client";
|
|
|
|
|
import type { AgentRole, Team } from "@/types";
|
|
|
|
|
import { isMockMode, mockAgents } from "@/lib/mock-data";
|
|
|
|
|
|
|
|
|
|
export interface AgentDefinition {
|
|
|
|
|
id: string; // slug from backend (e.g., "be-dev-1")
|
2026-06-19 09:15:01 +02:00
|
|
|
uuid: string; // stable backend UUID (assigned_to / claimed_by reference this)
|
2026-05-02 03:18:47 +02:00
|
|
|
name: string;
|
|
|
|
|
role: AgentRole | null;
|
|
|
|
|
team: Team | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface AgentApiResponse {
|
|
|
|
|
id: string; // UUID (not used for definitions)
|
|
|
|
|
name: string;
|
|
|
|
|
slug: string;
|
|
|
|
|
role: string;
|
|
|
|
|
team: string | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const agentsApi = {
|
|
|
|
|
/**
|
|
|
|
|
* Get all agents from the API
|
|
|
|
|
*/
|
|
|
|
|
getAll: async (): Promise<AgentDefinition[]> => {
|
|
|
|
|
if (isMockMode()) {
|
|
|
|
|
return mockAgents.map((a) => ({
|
|
|
|
|
id: a.slug || a.id,
|
2026-06-19 09:15:01 +02:00
|
|
|
uuid: a.id,
|
2026-05-02 03:18:47 +02:00
|
|
|
name: a.name,
|
|
|
|
|
role: a.role,
|
|
|
|
|
team: a.team,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const response = await api.get<AgentApiResponse[]>("/agents");
|
|
|
|
|
const data = response.data;
|
|
|
|
|
|
|
|
|
|
// Handle unexpected response formats
|
|
|
|
|
if (!data || !Array.isArray(data)) {
|
|
|
|
|
console.warn("Unexpected agents API response:", data);
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data.map((a) => ({
|
|
|
|
|
id: a.slug || a.id, // Use slug as ID, fallback to UUID
|
2026-06-19 09:15:01 +02:00
|
|
|
uuid: a.id, // raw backend UUID (tasks reference agents by this)
|
2026-05-02 03:18:47 +02:00
|
|
|
name: a.name || "Unknown",
|
|
|
|
|
role: (a.role as AgentRole) || null,
|
|
|
|
|
team: (a.team as Team) || null,
|
|
|
|
|
}));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a single agent by ID or slug
|
|
|
|
|
*/
|
|
|
|
|
getOne: async (idOrSlug: string): Promise<AgentDefinition> => {
|
|
|
|
|
const response = await api.get<AgentApiResponse>(`/agents/${idOrSlug}`);
|
|
|
|
|
const a = response.data;
|
|
|
|
|
return {
|
|
|
|
|
id: a.slug,
|
2026-06-19 09:15:01 +02:00
|
|
|
uuid: a.id,
|
2026-05-02 03:18:47 +02:00
|
|
|
name: a.name,
|
|
|
|
|
role: a.role as AgentRole,
|
|
|
|
|
team: a.team as Team | null,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
};
|