mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-03 22:41:39 +00:00
* fix(fal): route grok-imagine and nano-banana-2-lite edits to correct endpoints
The fal image-generation provider appends '/image-to-image' to any model
that isn't 'openai/gpt-image-*' or 'fal-ai/nano-banana-*' when reference
images are supplied. That's wrong for two models fal serves:
- `xai/grok-imagine-image`: fal 404s on '/image-to-image'. The real edit
endpoint is '/quality/edit'. The endpoint also expects lowercase
resolution values ('1k'/'2k' only) and a distinct aspect_ratio enum.
- `google/nano-banana-2-lite`: fal 404s on '/image-to-image'. The real
edit endpoint is '/edit'. The endpoint does not accept a 'resolution'
parameter.
Add schema entries for both models so ensureFalModelPath and
applyFalImageGeometry pick the right suffix and body shape. Introduce
resolution allowlist support ('resolutions: readonly string[]') and
lowercase transform ('resolutionCase: "lower"') on the schema; existing
schemas keep their behaviour (nb2 still forwards uppercase resolution
unchanged; flux/gpt-image/nb2/krea untouched). Refactor
ensureFalModelPath to consult schema.appendEditPath instead of hardcoded
prefix checks so future models only need a schema entry.
Tested:
- Existing 49 fal unit tests still pass; added 9 new tests covering the
two new endpoints and their guard conditions (32 -> 34 tests in the
image-generation-provider suite).
- Live fal.ai calls confirm both endpoints return 200 with real
reference images; the buggy old URLs still return 404.
* fix(fal): preserve standard edit routing
* fix(image): apply inferred resolution per model
* fix(image): preserve provider reference limits
* fix(image): resolve reference limits per model
* fix(fal): preserve nano banana family limits
* test(ios): stub generated file list helper
---------
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
145 lines
4.3 KiB
TypeScript
145 lines
4.3 KiB
TypeScript
/** Shared image-generation request, provider, capability, and result contracts. */
|
|
import type { MediaNormalizationEntry } from "../../packages/media-generation-core/src/normalization.js";
|
|
import type { AuthProfileStore } from "../agents/auth-profiles/types.js";
|
|
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import type { SsrFPolicy } from "../infra/net/ssrf.js";
|
|
|
|
/** Binary image asset returned by an image-generation provider. */
|
|
export type GeneratedImageAsset = {
|
|
buffer: Buffer;
|
|
mimeType: string;
|
|
fileName?: string;
|
|
revisedPrompt?: string;
|
|
metadata?: Record<string, unknown>;
|
|
};
|
|
|
|
export type ImageGenerationResolution = "1K" | "2K" | "4K";
|
|
|
|
export type ImageGenerationQuality = "low" | "medium" | "high" | "auto";
|
|
|
|
export type ImageGenerationOutputFormat = "png" | "jpeg" | "webp";
|
|
|
|
export type ImageGenerationBackground = "transparent" | "opaque" | "auto";
|
|
|
|
export type ImageGenerationOpenAIBackground = ImageGenerationBackground;
|
|
|
|
export type ImageGenerationOpenAIModeration = "low" | "auto";
|
|
|
|
export type ImageGenerationOpenAIOptions = {
|
|
background?: ImageGenerationOpenAIBackground;
|
|
moderation?: ImageGenerationOpenAIModeration;
|
|
outputCompression?: number;
|
|
user?: string;
|
|
};
|
|
|
|
export type ImageGenerationProviderOptions = Record<string, unknown> & {
|
|
openai?: ImageGenerationOpenAIOptions;
|
|
};
|
|
|
|
type ImageGenerationIgnoredOverrideKey =
|
|
| "size"
|
|
| "aspectRatio"
|
|
| "resolution"
|
|
| "quality"
|
|
| "outputFormat"
|
|
| "background";
|
|
|
|
export type ImageGenerationIgnoredOverride = {
|
|
key: ImageGenerationIgnoredOverrideKey;
|
|
value: string;
|
|
};
|
|
|
|
export type ImageGenerationSourceImage = {
|
|
buffer: Buffer;
|
|
mimeType: string;
|
|
fileName?: string;
|
|
metadata?: Record<string, unknown>;
|
|
};
|
|
|
|
export type ImageGenerationProviderConfiguredContext = {
|
|
cfg?: OpenClawConfig;
|
|
agentDir?: string;
|
|
};
|
|
|
|
/** Runtime request passed to an image-generation provider implementation. */
|
|
export type ImageGenerationRequest = {
|
|
provider: string;
|
|
model: string;
|
|
prompt: string;
|
|
cfg: OpenClawConfig;
|
|
agentDir?: string;
|
|
authStore?: AuthProfileStore;
|
|
timeoutMs?: number;
|
|
count?: number;
|
|
size?: string;
|
|
aspectRatio?: string;
|
|
resolution?: ImageGenerationResolution;
|
|
quality?: ImageGenerationQuality;
|
|
outputFormat?: ImageGenerationOutputFormat;
|
|
background?: ImageGenerationBackground;
|
|
inputImages?: ImageGenerationSourceImage[];
|
|
providerOptions?: ImageGenerationProviderOptions;
|
|
ssrfPolicy?: SsrFPolicy;
|
|
};
|
|
|
|
export type ImageGenerationResult = {
|
|
images: GeneratedImageAsset[];
|
|
model?: string;
|
|
metadata?: Record<string, unknown>;
|
|
};
|
|
|
|
type ImageGenerationModeCapabilities = {
|
|
maxCount?: number;
|
|
supportsSize?: boolean;
|
|
supportsAspectRatio?: boolean;
|
|
supportsResolution?: boolean;
|
|
};
|
|
|
|
type ImageGenerationEditCapabilities = ImageGenerationModeCapabilities & {
|
|
enabled: boolean;
|
|
maxInputImages?: number;
|
|
maxInputImagesByModel?: Readonly<Record<string, number>>;
|
|
maxInputImagesByModelPrefix?: Readonly<Record<string, number>>;
|
|
};
|
|
|
|
type ImageGenerationGeometryCapabilities = {
|
|
sizes?: string[];
|
|
sizesByModel?: Record<string, string[]>;
|
|
aspectRatios?: string[];
|
|
aspectRatiosByModel?: Record<string, string[]>;
|
|
resolutions?: ImageGenerationResolution[];
|
|
resolutionsByModel?: Record<string, ImageGenerationResolution[]>;
|
|
};
|
|
|
|
type ImageGenerationOutputCapabilities = {
|
|
qualities?: ImageGenerationQuality[];
|
|
formats?: ImageGenerationOutputFormat[];
|
|
backgrounds?: ImageGenerationBackground[];
|
|
};
|
|
|
|
export type ImageGenerationNormalization = {
|
|
size?: MediaNormalizationEntry<string>;
|
|
aspectRatio?: MediaNormalizationEntry<string>;
|
|
resolution?: MediaNormalizationEntry<ImageGenerationResolution>;
|
|
};
|
|
|
|
export type ImageGenerationProviderCapabilities = {
|
|
generate: ImageGenerationModeCapabilities;
|
|
edit: ImageGenerationEditCapabilities;
|
|
geometry?: ImageGenerationGeometryCapabilities;
|
|
output?: ImageGenerationOutputCapabilities;
|
|
};
|
|
|
|
export type ImageGenerationProvider = {
|
|
id: string;
|
|
aliases?: string[];
|
|
label?: string;
|
|
defaultModel?: string;
|
|
/** Default provider operation timeout in milliseconds when caller/config omit timeoutMs. */
|
|
defaultTimeoutMs?: number;
|
|
models?: string[];
|
|
capabilities: ImageGenerationProviderCapabilities;
|
|
isConfigured?: (ctx: ImageGenerationProviderConfiguredContext) => boolean;
|
|
generateImage: (req: ImageGenerationRequest) => Promise<ImageGenerationResult>;
|
|
};
|