File size: 1,298 Bytes
9b906ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { useQuery } from "@tanstack/react-query";
import AgentProfilesService from "#/api/agent-profiles-service/agent-profiles-service.api";
import { useActiveBackend } from "#/contexts/active-backend-context";
import {
  CONFIG_CACHE_OPTIONS,
  AGENT_PROFILES_QUERY_KEYS,
  AGENT_PROFILES_RETRY_OPTIONS,
} from "./query-keys";

export { AGENT_PROFILES_QUERY_KEYS };

interface UseAgentProfilesOptions {
  enabled?: boolean;
}

/**
 * List the user's AgentProfiles (Settings → Agent profiles library). On first
 * GET of an empty store the backend lazily seeds one default profile mirroring
 * the user's prior config (#3719), so the list is never empty for an upgrading
 * user. Works on both local and cloud backends — `AgentProfilesService` routes
 * cloud calls through the cloud proxy (OpenHands #15060).
 */
export function useAgentProfiles(options: UseAgentProfilesOptions = {}) {
  const { backend, orgId } = useActiveBackend();

  return useQuery({
    // Backend identity isolates the cache across backend/org switches.
    queryKey: [...AGENT_PROFILES_QUERY_KEYS.all, backend.id, orgId],
    queryFn: AgentProfilesService.listProfiles,
    ...CONFIG_CACHE_OPTIONS,
    ...AGENT_PROFILES_RETRY_OPTIONS,
    enabled: options.enabled ?? true,
    meta: { disableToast: true },
  });
}