openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
94 lines (93 loc) • 2.94 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import { t as bufferToBlobPart } from "./blob-runtime-QF_Wblu0.mjs";
import { a as imageSourceUploadFileName } from "./image-assets-C4Dd3W6i.mjs";
import { t as createOpenAiCompatibleImageGenerationProvider } from "./image-generation-D00XjYzo.mjs";
import { t as LITELLM_BASE_URL } from "./onboard-D15kqau-.mjs";
import { isIP } from "node:net";
//#region extensions/litellm/image-generation-provider.ts
const DEFAULT_SIZE = "1024x1024";
const DEFAULT_LITELLM_IMAGE_MODEL = "gpt-image-2";
const LITELLM_SUPPORTED_SIZES = [
"256x256",
"512x512",
"1024x1024",
"1024x1536",
"1024x1792",
"1536x1024",
"1792x1024",
"2048x2048",
"2048x1152",
"3840x2160",
"2160x3840"
];
const LITELLM_MAX_INPUT_IMAGES = 5;
function shouldAutoAllowPrivateLitellmEndpoint(e) {
const t = URL.parse(e);
if (!t || t.protocol !== "http:" && t.protocol !== "https:") return false;
const { hostname: n } = t;
return n === "localhost" || n === "host.docker.internal" || n.endsWith(".localhost") || n === "[::1]" || isIP(n) === 4 && n.startsWith("127.");
}
function buildLitellmImageGenerationProvider() {
return createOpenAiCompatibleImageGenerationProvider({
id: "litellm",
label: "LiteLLM",
defaultModel: DEFAULT_LITELLM_IMAGE_MODEL,
models: [DEFAULT_LITELLM_IMAGE_MODEL],
capabilities: {
generate: {
maxCount: 4,
supportsSize: true,
supportsAspectRatio: false,
supportsResolution: false
},
edit: {
enabled: true,
maxCount: 4,
maxInputImages: LITELLM_MAX_INPUT_IMAGES,
supportsSize: true,
supportsAspectRatio: false,
supportsResolution: false
},
geometry: { sizes: [...LITELLM_SUPPORTED_SIZES] }
},
defaultBaseUrl: LITELLM_BASE_URL,
resolveAllowPrivateNetwork: ({ baseUrl: e }) => shouldAutoAllowPrivateLitellmEndpoint(e) ? true : void 0,
useConfiguredRequest: true,
buildGenerateRequest: ({ req: e, model: t, count: n }) => ({
kind: "json",
body: {
model: t,
prompt: e.prompt,
n,
size: e.size ?? DEFAULT_SIZE
}
}),
buildEditRequest: ({ req: e, inputImages: t, model: n, count: r }) => {
const i = new FormData();
i.set("model", n);
i.set("prompt", e.prompt);
if (r > 1) i.set("n", String(r));
i.set("size", e.size ?? DEFAULT_SIZE);
const a = t.length > 1 ? "image[]" : "image";
for (const [e, n] of t.entries()) {
const t = normalizeOptionalString(n.mimeType) ?? "image/png";
i.append(a, new Blob([bufferToBlobPart(n.buffer)], { type: t }), imageSourceUploadFileName({
image: n,
index: e
}));
}
return {
kind: "multipart",
form: i
};
},
missingApiKeyError: "LiteLLM API key missing",
failureLabels: {
generate: "LiteLLM image generation failed",
edit: "LiteLLM image edit failed"
}
});
}
//#endregion
export { buildLitellmImageGenerationProvider as t };