35 lines
917 B
TypeScript
35 lines
917 B
TypeScript
import { create } from "zustand";
|
|
import { agentApiService } from "@/modules/agent/api/agent.api.service";
|
|
import type { AgentInfo } from "@/modules/agent/types/agent.types";
|
|
|
|
interface AgentState {
|
|
agents: AgentInfo[];
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
fetchAgents: () => Promise<void>;
|
|
removeAgent: (name: string) => void;
|
|
}
|
|
|
|
export const useAgentStore = create<AgentState>()((set, get) => ({
|
|
agents: [],
|
|
isLoading: false,
|
|
error: null,
|
|
|
|
fetchAgents: async () => {
|
|
set({ isLoading: true, error: null });
|
|
try {
|
|
const agents = await agentApiService.getAgents();
|
|
set({ agents, isLoading: false });
|
|
} catch (error) {
|
|
set({
|
|
error: error instanceof Error ? error.message : "Failed to fetch agents",
|
|
isLoading: false,
|
|
});
|
|
}
|
|
},
|
|
|
|
removeAgent: (name: string) => {
|
|
set({ agents: get().agents.filter((a) => a.name !== name) });
|
|
},
|
|
}));
|