2a7f716386
The xAI image branch on origin/main always posts to /v1/images/generations
and hard-codes `resolution: "1k"`, contradicting two advertised contracts:
P1: generate_image schema declares `input: z.array(inputImageSchema)`
globally; resolvedImages was populated for every provider but the xAI
branch POST body only forwarded text fields. Image-edit and
multi-reference prompts silently degraded to text-only.
P2: user-supplied image_size was ignored on the xAI path even though
every other provider honors it via resolveOpenAIImageSize /
imageConfig.imageSize.
Fix:
* Add XAIImageReference and XAIImageRequestBase typed interfaces;
combine into a discriminated XAIImageRequestBody union with mutually-
exclusive image / images fields (text-only branch carries
`image?: never; images?: never`).
* Route to POST /v1/images/edits when resolvedImages.length > 0; map
1 source -> `image: {url, type}`, 2-3 sources -> `images: [{url,
type}, ...]` per docs.x.ai. Cap at 3 with a tool-level error; xAI
documents that limit.
* Reuse the existing toDataUrl(InlineImageData) helper for the `url`
field (data: URIs are accepted alongside public URLs per docs.x.ai).
`type: "image_url"` is the OpenAI-compat discriminator every official
xAI code example sends.
* Add resolveXAIResolution(image_size): map OpenAI-style pixel size to
xAI's discrete "1k" | "2k" tier. 1024x1024 -> 1k; anything wider ->
2k. Absent image_size still defaults to "1k", matching hermes-agent
DEFAULT_RESOLUTION (plugins/image_gen/xai/__init__.py:71).
* buildXAIEditPayload uses tuple destructure + explicit guard rather
than `resolvedImages[0]`, staying safe under future
noUncheckedIndexedAccess: true.
No effect on the OpenAI / OpenAI-codex / antigravity / gemini / openrouter
branches.
Op: correct
Restores: ref:feat/xai-grok-oauth@ecedf7c7e