mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-04 22:02:16 +02:00
Merge remote-tracking branch 'upstream/dev' into fix/documents
This commit is contained in:
commit
0fdd194d92
60 changed files with 5086 additions and 248 deletions
83
surfsense_web/lib/apis/image-gen-config-api.service.ts
Normal file
83
surfsense_web/lib/apis/image-gen-config-api.service.ts
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
import {
|
||||
type CreateImageGenConfigRequest,
|
||||
createImageGenConfigRequest,
|
||||
createImageGenConfigResponse,
|
||||
type UpdateImageGenConfigRequest,
|
||||
updateImageGenConfigRequest,
|
||||
updateImageGenConfigResponse,
|
||||
deleteImageGenConfigResponse,
|
||||
getImageGenConfigsResponse,
|
||||
getGlobalImageGenConfigsResponse,
|
||||
} 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}`);
|
||||
}
|
||||
return baseApiService.post(
|
||||
`/api/v1/image-generation-configs`,
|
||||
createImageGenConfigResponse,
|
||||
{ body: parsed.data }
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
|
@ -34,6 +34,11 @@ export const cacheKeys = {
|
|||
defaultInstructions: () => ["new-llm-configs", "default-instructions"] as const,
|
||||
global: () => ["new-llm-configs", "global"] as const,
|
||||
},
|
||||
imageGenConfigs: {
|
||||
all: (searchSpaceId: number) => ["image-gen-configs", searchSpaceId] as const,
|
||||
byId: (configId: number) => ["image-gen-configs", "detail", configId] as const,
|
||||
global: () => ["image-gen-configs", "global"] as const,
|
||||
},
|
||||
auth: {
|
||||
user: ["auth", "user"] as const,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue