Adds assistants.
This commit is contained in:
@@ -76,6 +76,17 @@ class ApiClient {
|
||||
streamUrl(path: string): string {
|
||||
return `${this.baseUrl}${path}`
|
||||
}
|
||||
|
||||
// Build a ws(s):// URL for a WebSocket endpoint. Handles both the cross-origin
|
||||
// base (https://castle-api.<domain>) and the same-origin "/api" base.
|
||||
wsUrl(path: string): string {
|
||||
const absolute = this.baseUrl.startsWith("http")
|
||||
? `${this.baseUrl}${path}`
|
||||
: `${window.location.origin}${this.baseUrl}${path}`
|
||||
const url = new URL(absolute)
|
||||
url.protocol = url.protocol === "https:" ? "wss:" : "ws:"
|
||||
return url.toString()
|
||||
}
|
||||
}
|
||||
|
||||
export const apiClient = new ApiClient()
|
||||
|
||||
@@ -17,6 +17,9 @@ import type {
|
||||
MeshStatus,
|
||||
NodeSummary,
|
||||
NodeDetail,
|
||||
AgentInfo,
|
||||
AgentSessionInfo,
|
||||
AgentHistoryEntry,
|
||||
} from "@/types"
|
||||
|
||||
// Compat hook for the /deployments/{name} unified detail endpoint
|
||||
@@ -208,6 +211,39 @@ export function useMeshStatus() {
|
||||
})
|
||||
}
|
||||
|
||||
export function useAgents() {
|
||||
return useQuery({
|
||||
queryKey: ["agents"],
|
||||
queryFn: () => apiClient.get<AgentInfo[]>("/agents"),
|
||||
staleTime: Infinity,
|
||||
})
|
||||
}
|
||||
|
||||
export function useAgentSessions() {
|
||||
return useQuery({
|
||||
queryKey: ["agent-sessions"],
|
||||
queryFn: () => apiClient.get<AgentSessionInfo[]>("/agents/sessions"),
|
||||
refetchInterval: 5_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function useAgentHistory(enabled: boolean) {
|
||||
return useQuery({
|
||||
queryKey: ["agent-history"],
|
||||
queryFn: () => apiClient.get<AgentHistoryEntry[]>("/agents/history"),
|
||||
enabled,
|
||||
staleTime: 10_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function useDeleteAgentSession() {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => apiClient.delete(`/agents/sessions/${id}`),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ["agent-sessions"] }),
|
||||
})
|
||||
}
|
||||
|
||||
export function useEventStream() {
|
||||
const qc = useQueryClient()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user