mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
- image/embed/tts/search base URLs derive from media.*Config.baseUrl / searchViaChat.endpoint (single source); handlers read PROVIDER_MEDIA. - ~18 hardcoded endpoints moved: bfl/fal/stability/runway/hf/gemini/ cloudflare/recraft/sdwebui/comfyui/nanobanana image, voyage embed, gemini/openrouter tts, chatSearch endpoints. - Byte-identical: PROVIDERS 62 + alias 90 baselines, image buildUrl outputs. Co-authored-by: Cursor <cursoragent@cursor.com>
45 lines
1.7 KiB
JavaScript
45 lines
1.7 KiB
JavaScript
// Black Forest Labs (FLUX) — async submit + polling_url
|
|
import { sleep, nowSec, POLL_INTERVAL_MS, POLL_TIMEOUT_MS } from "./_base.js";
|
|
import { PROVIDER_MEDIA } from "../../providers/index.js";
|
|
|
|
const BASE_URL = PROVIDER_MEDIA["black-forest-labs"]?.imageConfig?.baseUrl;
|
|
|
|
export default {
|
|
async: true,
|
|
buildUrl: (model) => `${BASE_URL}/${model}`,
|
|
buildHeaders: (creds) => {
|
|
const key = creds?.apiKey || creds?.accessToken;
|
|
return { "Content-Type": "application/json", "x-key": key };
|
|
},
|
|
buildBody: (_model, body) => {
|
|
const req = { prompt: body.prompt };
|
|
if (body.size) {
|
|
const [w, h] = body.size.split("x").map(Number);
|
|
if (w) req.width = w;
|
|
if (h) req.height = h;
|
|
}
|
|
if (body.image) req.image_prompt = body.image;
|
|
return req;
|
|
},
|
|
async parseResponse(response, { headers }) {
|
|
const data = await response.json();
|
|
const pollingUrl = data.polling_url;
|
|
if (!pollingUrl) throw new Error("BFL: no polling_url returned");
|
|
const deadline = Date.now() + POLL_TIMEOUT_MS;
|
|
while (Date.now() < deadline) {
|
|
await sleep(POLL_INTERVAL_MS);
|
|
const r = await fetch(pollingUrl, { headers: { "x-key": headers["x-key"], "Accept": "application/json" } });
|
|
if (!r.ok) throw new Error(`BFL status ${r.status}`);
|
|
const s = await r.json();
|
|
if (s.status === "Ready") return s;
|
|
if (s.status === "Error" || s.status === "Failed") throw new Error(s.error || "BFL generation failed");
|
|
}
|
|
throw new Error("BFL polling timeout");
|
|
},
|
|
normalize: (responseBody) => {
|
|
const sample = responseBody.result?.sample;
|
|
if (sample) return { created: nowSec(), data: [{ url: sample }] };
|
|
return { created: nowSec(), data: [] };
|
|
},
|
|
};
|