| import type { |
| ActivateProfileResponse, |
| ProfileDetailResponse, |
| ProfileListResponse, |
| ProfileMutationResponse, |
| SaveProfileRequest, |
| } from "@openhands/typescript-client"; |
| import { getActiveBackend } from "../backend-registry/active-store"; |
| import type { Backend } from "../backend-registry/types"; |
| import { callCloudProxy } from "./proxy"; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| const SETTINGS_PROFILES_PATH = "/api/v1/settings/profiles"; |
|
|
| |
| |
| |
| |
| function cloudProfilesTarget(): { backend: Backend; base: string } { |
| const { backend, orgId } = getActiveBackend(); |
| if (backend.kind !== "cloud") { |
| throw new Error("Cloud profiles call requires a cloud backend."); |
| } |
| return { |
| backend, |
| base: orgId |
| ? `/api/organizations/${encodeURIComponent(orgId)}/profiles` |
| : SETTINGS_PROFILES_PATH, |
| }; |
| } |
|
|
| export async function fetchCloudProfiles(): Promise<ProfileListResponse> { |
| const { backend, base } = cloudProfilesTarget(); |
| return callCloudProxy<ProfileListResponse>({ |
| backend, |
| method: "GET", |
| path: base, |
| }); |
| } |
|
|
| export async function fetchCloudProfile( |
| name: string, |
| ): Promise<ProfileDetailResponse> { |
| const { backend, base } = cloudProfilesTarget(); |
| |
| |
| |
| const result = await callCloudProxy<{ |
| name: string; |
| config?: Record<string, unknown>; |
| llm?: Record<string, unknown>; |
| api_key_set?: boolean; |
| }>({ |
| backend, |
| method: "GET", |
| path: `${base}/${encodeURIComponent(name)}`, |
| }); |
| return { |
| name: result.name, |
| config: result.config ?? result.llm ?? {}, |
| api_key_set: result.api_key_set ?? false, |
| }; |
| } |
|
|
| export async function saveCloudProfile( |
| name: string, |
| request: SaveProfileRequest, |
| ): Promise<ProfileMutationResponse> { |
| const { backend, base } = cloudProfilesTarget(); |
| return callCloudProxy<ProfileMutationResponse>({ |
| backend, |
| method: "POST", |
| path: `${base}/${encodeURIComponent(name)}`, |
| body: request, |
| }); |
| } |
|
|
| export async function deleteCloudProfile( |
| name: string, |
| ): Promise<ProfileMutationResponse> { |
| const { backend, base } = cloudProfilesTarget(); |
| return callCloudProxy<ProfileMutationResponse>({ |
| backend, |
| method: "DELETE", |
| path: `${base}/${encodeURIComponent(name)}`, |
| }); |
| } |
|
|
| export async function renameCloudProfile( |
| name: string, |
| newName: string, |
| ): Promise<ProfileMutationResponse> { |
| const { backend, base } = cloudProfilesTarget(); |
| return callCloudProxy<ProfileMutationResponse>({ |
| backend, |
| method: "POST", |
| path: `${base}/${encodeURIComponent(name)}/rename`, |
| body: { new_name: newName }, |
| }); |
| } |
|
|
| export async function activateCloudProfile( |
| name: string, |
| ): Promise<ActivateProfileResponse> { |
| const { backend, base } = cloudProfilesTarget(); |
| |
| |
| |
| |
| const result = await callCloudProxy<{ |
| name: string; |
| message: string; |
| model?: string | null; |
| llm?: Record<string, unknown> | null; |
| }>({ |
| backend, |
| method: "POST", |
| path: `${base}/${encodeURIComponent(name)}/activate`, |
| body: {}, |
| }); |
| return { |
| name: result.name, |
| message: result.message, |
| llm_applied: result.model != null || result.llm != null, |
| }; |
| } |
|
|