feat: add local auth billing and usage management
This commit is contained in:
1 parent
f642b5e71f
commit
196fdde83f
119 files changed
+15695
-2650
No files matched your search
@@ -2,12 +2,13 @@ import type { EnabledImageCapability, GenerationStatus } from "@/lib/types";
|
||||
|
||||
export type ImageCreationEngine = "jimeng" | "evolink" | "bailian";
|
||||
|
||||
export const EVOLINK_PLATFORM_RESOLUTION = "1K" as const;
|
||||
|
||||
export type EvolinkImageSettings = {
|
||||
apiKey?: string;
|
||||
baseUrl: string;
|
||||
model: string;
|
||||
quality?: string;
|
||||
resolution?: string;
|
||||
};
|
||||
|
||||
export type EvolinkImageConfig = EvolinkImageSettings & {
|
||||
@@ -33,11 +34,9 @@ export function getSelectedImageEngine(): ImageCreationEngine {
|
||||
}
|
||||
|
||||
export function getEffectiveImageEngine(capability: EnabledImageCapability, override?: unknown): ImageCreationEngine {
|
||||
if (capability === "image.upscale") return "jimeng";
|
||||
const overrideEngine = normalizeImageEngine(override);
|
||||
if (overrideEngine) return overrideEngine;
|
||||
if (capability === "image.generate") return selectedEngineFrom(process.env.IMAGE_GENERATE_ENGINE);
|
||||
if (capability === "image.inpaint") return selectedEngineFrom(process.env.IMAGE_INPAINT_ENGINE);
|
||||
return getSelectedImageEngine();
|
||||
}
|
||||
|
||||
@@ -62,8 +61,7 @@ export function getEvolinkImageSettings(): EvolinkImageSettings {
|
||||
apiKey: process.env.EVOLINK_API_KEY?.trim() || undefined,
|
||||
baseUrl: (process.env.EVOLINK_BASE_URL || "https://api.evolink.ai").replace(/\/+$/, ""),
|
||||
model: process.env.EVOLINK_IMAGE_MODEL || "gpt-image-2",
|
||||
quality: cleanOptional(process.env.EVOLINK_IMAGE_QUALITY),
|
||||
resolution: cleanOptional(process.env.EVOLINK_IMAGE_RESOLUTION || "2K")
|
||||
quality: cleanOptional(process.env.EVOLINK_IMAGE_QUALITY)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -85,33 +83,20 @@ export function buildEvolinkImagePayload(
|
||||
input: Record<string, unknown>,
|
||||
settings = getEvolinkImageSettings()
|
||||
): Record<string, unknown> {
|
||||
if (capability === "image.upscale") {
|
||||
throw new Error("EvoLink image engine does not support upscale in this integration.");
|
||||
}
|
||||
|
||||
const prompt = String(input.prompt || "").trim();
|
||||
const imageUrls = asStringArray(input.imageUrls);
|
||||
const payload: Record<string, unknown> = {
|
||||
model: settings.model,
|
||||
prompt: prompt || (capability === "image.inpaint" ? "删除" : ""),
|
||||
prompt,
|
||||
n: 1
|
||||
};
|
||||
|
||||
if (!payload.prompt) throw new Error("Prompt is required for image generation.");
|
||||
const quality = cleanOptional(typeof input.quality === "string" ? input.quality : undefined) || settings.quality;
|
||||
if (quality) payload.quality = quality;
|
||||
if (settings.resolution) payload.resolution = settings.resolution;
|
||||
payload.resolution = EVOLINK_PLATFORM_RESOLUTION;
|
||||
assignSize(payload, input);
|
||||
|
||||
if (capability === "image.inpaint") {
|
||||
if (imageUrls.length !== 2) {
|
||||
throw new Error("EvoLink inpainting requires original image and mask URLs.");
|
||||
}
|
||||
payload.image_urls = [imageUrls[0]];
|
||||
payload.mask_url = imageUrls[1];
|
||||
return payload;
|
||||
}
|
||||
|
||||
if (imageUrls.length) payload.image_urls = imageUrls;
|
||||
return payload;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user