fix: report unsupported image quality before submission

This commit is contained in:
WuYongJie 2026-11-13 10:14:31 +08:00
parent 168de1db3c
commit 89a9416815
2 changed files with 12 additions and 2 deletions

View File

@ -5,7 +5,7 @@ import sharp from "sharp";
import { agentImageCircuitStore } from "@/lib/ai/runtime/agent-model-circuit-store";
import { getModelGenerationCreditCost, type DiscountableImageGenConfigLike } from "@/lib/ai/image-model-pricing";
import { agentImageFailurePolicy } from "@/lib/ai/runtime/agent-image-failover";
import { agentImageGenerationError, ImageReferenceReadTimeoutError } from "@/lib/ai/runtime/image-generation-error";
import { AgentImageGenerationError, agentImageGenerationError, ImageReferenceReadTimeoutError } from "@/lib/ai/runtime/image-generation-error";
import { getAiModelById, getEnabledAiModelsWithProvider } from "@/lib/db/queries";
import { fetchImageBufferFromUrl } from "@/lib/ai/rmbg/service";
import { createGeminiImage } from "@/lib/ai/providers/gemini-image";
@ -4950,7 +4950,7 @@ export async function generateCanvasImage(
if (!selectedModel) throw new Error("当前没有可用的备用图片模型,请稍后重试");
}
if (request.agentImageMode === "pinned" && !isCanvasImageSizeSupported(selectedModel.model.imageGenConfig as CanvasImageGenConfig | null, normalizeCanvasImageSizeValue(request.imageSize)))
throw new Error("指定的图片模型不支持所选尺寸,请调整图片尺寸");
throw new AgentImageGenerationError("指定的图片模型不支持所选清晰度,任务尚未提交。请调整清晰度后重试。", true);
const normalizedReferenceImages = Array.from(
new Set(

View File

@ -5,6 +5,16 @@ import { ImageSubmissionRejectedError, agentImageGenerationError } from "@/lib/a
import * as generationErrors from "@/lib/ai/runtime/image-generation-error";
import { serverLoader } from "../helpers/canvas-download-server-loader";
test("an unsupported pinned resolution is rejected before submission and can be corrected", async () => {
const models = [{ model: { id: "primary", modelId: "primary", isEnabled: true, supportsImageGen: true,
imageGenConfig: { supportedImageSizes: ["1K", "2K"] } }, provider: { id: "provider", type: "openai-image", isEnabled: true } }];
const h = harness({ models });
await expect(h.generate({ ...h.request, agentImageMode: "pinned", imageSize: "4K" })).rejects.toMatchObject({
confirmedNoResult: true, message: expect.stringMatching(/尚未提交.*调整清晰度后重试/),
});
expect(h.calls).toHaveLength(0);
});
test("a balance rejection skips other models on the same account but permits another account of the same provider type", async () => {
const models = ["primary", "same-account", "backup"].map(id => ({
model: { id, modelId: id, displayName: id, isEnabled: true, supportsImageGen: true, supportsVision: true, imageGenConfig: { maxImages: 1 }, capabilities: { kind: "image" } },