proxy, ui-svelte: add /sdapi/v1 endpoint support (#587)

Add proxy routes for stable-diffusion.cpp's /sdapi/v1/txt2img,
/sdapi/v1/img2img, and /sdapi/v1/loras endpoints. POST endpoints
use proxyInferenceHandler (model in JSON body), GET /loras uses
proxyGETModelHandler (model in query param).

Update the image playground with a dual-mode UI supporting both
OpenAI and SDAPI backends. In SDAPI mode, loras are fetched first
to prime the server-side cache, and all txt2img parameters are
exposed (negative prompt, steps, cfg_scale, seed, batch_size,
clip_skip, sampler, scheduler, lora selection with multipliers).

- Add 3 sdapi route registrations in proxymanager.go
- Add sdApi.ts client with generateSdImage and fetchSdLoras
- Add SDAPI types (SdApiTxt2ImgRequest, SdApiResponse, etc.)
- Add /sdapi to vite dev proxy config
- Add backend tests for sdapi routing
- Support batch image display in gallery grid

https://claude.ai/code/session_0186MGX6NXdHVBTv2KH45fqn

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Benson Wong
2026-03-19 22:08:31 +09:00
committed by GitHub
parent c3c258a55d
commit 15bd55d3a9
9 changed files with 514 additions and 32 deletions
+39
View File
@@ -0,0 +1,39 @@
import type { SdApiTxt2ImgRequest, SdApiResponse, SdApiLora } from "./types";
export async function generateSdImage(
request: SdApiTxt2ImgRequest,
signal?: AbortSignal
): Promise<SdApiResponse> {
const response = await fetch("/sdapi/v1/txt2img", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(request),
signal,
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`SDAPI error: ${response.status} - ${errorText}`);
}
return response.json();
}
export async function fetchSdLoras(
model: string,
signal?: AbortSignal
): Promise<SdApiLora[]> {
const response = await fetch(
`/sdapi/v1/loras?model=${encodeURIComponent(model)}`,
{ signal }
);
if (!response.ok) {
const errorText = await response.text();
throw new Error(`SDAPI loras error: ${response.status} - ${errorText}`);
}
return response.json();
}
+34
View File
@@ -115,6 +115,40 @@ export interface ImageGenerationResponse {
}>;
}
// SDAPI types (stable-diffusion.cpp)
export type ImageApiMode = "openai" | "sdapi";
export interface SdApiLora {
name: string;
path: string;
}
export interface SdApiLoraRef {
path: string;
multiplier: number;
}
export interface SdApiTxt2ImgRequest {
model?: string;
prompt: string;
negative_prompt?: string;
width?: number;
height?: number;
steps?: number;
cfg_scale?: number;
seed?: number;
batch_size?: number;
sampler_name?: string;
scheduler?: string;
lora?: SdApiLoraRef[];
}
export interface SdApiResponse {
images: string[];
parameters: Record<string, unknown>;
info: string;
}
export interface AudioTranscriptionRequest {
file: File;
model: string;