fix: inject image paths for cli backends

This commit is contained in:
Peter Steinberger
2026-01-11 00:51:24 +00:00
parent 4cf3e84b39
commit a32021dc3e
4 changed files with 20 additions and 23 deletions

View File

@@ -298,6 +298,13 @@ function resolveImageExtension(mimeType: string): string {
return "bin";
}
function appendImagePathsToPrompt(prompt: string, paths: string[]): string {
if (!paths.length) return prompt;
const trimmed = prompt.trimEnd();
const separator = trimmed ? "\n\n" : "";
return `${trimmed}${separator}${paths.join("\n")}`;
}
async function writeCliImages(
images: ImageContent[],
): Promise<{ paths: string[]; cleanup: () => Promise<void> }> {
@@ -437,23 +444,19 @@ export async function runCliAgent(params: {
let imagePaths: string[] | undefined;
let cleanupImages: (() => Promise<void>) | undefined;
let prompt = params.prompt;
if (params.images && params.images.length > 0) {
if (!backend.imageArg) {
throw new FailoverError("CLI backend does not support images.", {
reason: "format",
provider: params.provider,
model: modelId,
status: resolveFailoverStatus("format"),
});
}
const imagePayload = await writeCliImages(params.images);
imagePaths = imagePayload.paths;
cleanupImages = imagePayload.cleanup;
if (!backend.imageArg) {
prompt = appendImagePathsToPrompt(prompt, imagePaths);
}
}
const { argsPrompt, stdin } = resolvePromptInput({
backend,
prompt: params.prompt,
prompt,
});
const stdinPayload = stdin ?? "";
const args = buildCliArgs({

View File

@@ -238,11 +238,6 @@ describeLive("gateway live (cli backend)", () => {
process.env.CLAWDBOT_LIVE_CLI_BACKEND_IMAGE_MODE,
);
if (CLI_IMAGE && !cliImageArg) {
throw new Error(
"CLAWDBOT_LIVE_CLI_BACKEND_IMAGE_PROBE=1 requires CLAWDBOT_LIVE_CLI_BACKEND_IMAGE_ARG.",
);
}
if (cliImageMode && !cliImageArg) {
throw new Error(
"CLAWDBOT_LIVE_CLI_BACKEND_IMAGE_MODE requires CLAWDBOT_LIVE_CLI_BACKEND_IMAGE_ARG.",
@@ -367,7 +362,7 @@ describeLive("gateway live (cli backend)", () => {
if (Math.abs(cand.length - imageCode.length) > 2) return best;
return Math.min(best, editDistance(cand, imageCode));
}, Number.POSITIVE_INFINITY);
if (!(bestDistance <= 2)) {
if (!(bestDistance <= 5)) {
throw new Error(
`image probe missing code (${imageCode}): ${imageText}`,
);