File size: 3,087 Bytes
3d700dd | 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | import type {
AgentProfileSaveInput,
AgentProfileListResponse,
AgentProfileDetailResponse,
AgentProfileMutationResponse,
ActivateAgentProfileResponse,
} from "@openhands/typescript-client";
import { getActiveBackend } from "../backend-registry/active-store";
import type { Backend } from "../backend-registry/types";
import { callCloudProxy } from "./proxy";
/**
* Cloud transport for the Agent Profiles surface. The cloud enterprise
* app-server exposes the SAME `/api/agent-profiles` contract as the local
* agent-server (paths + response shapes mirror `agent_profiles_router.py`),
* but cloud calls authenticate with the backend's bearer token + `X-Org-Id`
* and must go through {@link callCloudProxy} — not the direct
* `AgentProfilesClient` (which speaks `X-Session-API-Key` to a local host).
*
* The org is resolved server-side from the auth session (`EFFECTIVE_ORG_ID`),
* so — unlike org LLM profiles — no `{org_id}` path segment is needed here.
*
* Mirrors the pattern in `cloud/settings-service.api.ts`. Consumed by
* `AgentProfilesService` on the cloud path.
*/
const BASE = "/api/agent-profiles";
function activeCloudBackend(): Backend {
const active = getActiveBackend().backend;
if (active.kind !== "cloud") {
throw new Error("Cloud agent-profile call requires a cloud backend.");
}
return active;
}
export async function listCloudAgentProfiles(): Promise<AgentProfileListResponse> {
return callCloudProxy<AgentProfileListResponse>({
backend: activeCloudBackend(),
method: "GET",
path: BASE,
});
}
export async function getCloudAgentProfile(
name: string,
): Promise<AgentProfileDetailResponse> {
return callCloudProxy<AgentProfileDetailResponse>({
backend: activeCloudBackend(),
method: "GET",
path: `${BASE}/${encodeURIComponent(name)}`,
});
}
export async function saveCloudAgentProfile(
name: string,
profile: AgentProfileSaveInput,
): Promise<AgentProfileMutationResponse> {
return callCloudProxy<AgentProfileMutationResponse>({
backend: activeCloudBackend(),
method: "POST",
path: `${BASE}/${encodeURIComponent(name)}`,
body: profile,
});
}
export async function deleteCloudAgentProfile(
name: string,
): Promise<AgentProfileMutationResponse> {
return callCloudProxy<AgentProfileMutationResponse>({
backend: activeCloudBackend(),
method: "DELETE",
path: `${BASE}/${encodeURIComponent(name)}`,
});
}
export async function renameCloudAgentProfile(
name: string,
newName: string,
): Promise<AgentProfileMutationResponse> {
return callCloudProxy<AgentProfileMutationResponse>({
backend: activeCloudBackend(),
method: "POST",
path: `${BASE}/${encodeURIComponent(name)}/rename`,
body: { new_name: newName },
});
}
export async function activateCloudAgentProfile(
profileId: string,
): Promise<ActivateAgentProfileResponse> {
return callCloudProxy<ActivateAgentProfileResponse>({
backend: activeCloudBackend(),
method: "POST",
path: `${BASE}/${encodeURIComponent(profileId)}/activate`,
body: {},
});
}
|