SurfSense/surfsense_web/lib/apis/image-gen-config-api.service.ts

82 lines
2.3 KiB
TypeScript
Raw Normal View History

2026-02-05 16:43:48 -08:00
import {
type CreateImageGenConfigRequest,
createImageGenConfigRequest,
createImageGenConfigResponse,
2026-02-09 16:49:11 -08:00
deleteImageGenConfigResponse,
getGlobalImageGenConfigsResponse,
getImageGenConfigsResponse,
2026-02-05 16:43:48 -08:00
type UpdateImageGenConfigRequest,
updateImageGenConfigRequest,
updateImageGenConfigResponse,
} from "@/contracts/types/new-llm-config.types";
import { ValidationError } from "../error";
import { baseApiService } from "./base-api.service";
class ImageGenConfigApiService {
/**
* Get all global image generation configs (from YAML, negative IDs)
*/
getGlobalConfigs = async () => {
return baseApiService.get(
`/api/v1/global-image-generation-configs`,
getGlobalImageGenConfigsResponse
);
};
/**
* Create a new image generation config for a search space
*/
createConfig = async (request: CreateImageGenConfigRequest) => {
const parsed = createImageGenConfigRequest.safeParse(request);
if (!parsed.success) {
const msg = parsed.error.issues.map((i) => i.message).join(", ");
throw new ValidationError(`Invalid request: ${msg}`);
}
2026-02-06 18:22:19 +05:30
return baseApiService.post(`/api/v1/image-generation-configs`, createImageGenConfigResponse, {
body: parsed.data,
});
2026-02-05 16:43:48 -08:00
};
/**
* Get image generation configs for a search space
*/
getConfigs = async (searchSpaceId: number) => {
const params = new URLSearchParams({
search_space_id: String(searchSpaceId),
}).toString();
return baseApiService.get(
`/api/v1/image-generation-configs?${params}`,
getImageGenConfigsResponse
);
};
/**
* Update an existing image generation config
*/
updateConfig = async (request: UpdateImageGenConfigRequest) => {
const parsed = updateImageGenConfigRequest.safeParse(request);
if (!parsed.success) {
const msg = parsed.error.issues.map((i) => i.message).join(", ");
throw new ValidationError(`Invalid request: ${msg}`);
}
const { id, data } = parsed.data;
return baseApiService.put(
`/api/v1/image-generation-configs/${id}`,
updateImageGenConfigResponse,
{ body: data }
);
};
/**
* Delete an image generation config
*/
deleteConfig = async (id: number) => {
return baseApiService.delete(
`/api/v1/image-generation-configs/${id}`,
deleteImageGenConfigResponse
);
};
}
export const imageGenConfigApiService = new ImageGenConfigApiService();