fix: keep multimodal agent model for detail planning
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Your Name 2026-02-21 23:34:04 +08:00
parent 7df5528056
commit c5abfaf974

View File

@ -5,11 +5,26 @@ import {
getAgentAiModelWithProvider, getAgentAiModelWithProvider,
getEnabledAiModelsWithProvider, getEnabledAiModelsWithProvider,
} from "@/lib/db/queries"; } from "@/lib/db/queries";
import { isAiModelMultimodal } from "@/lib/db/ai-model-flags";
import { getLanguageModelById } from "@/lib/ai/dynamic-provider"; import { getLanguageModelById } from "@/lib/ai/dynamic-provider";
export const runtime = "nodejs"; export const runtime = "nodejs";
export const maxDuration = 60; export const maxDuration = 60;
function supportsVisionPlanning(model: {
supportsVision?: boolean | null;
capabilities?: unknown;
defaultParams?: unknown;
}) {
return (
Boolean(model.supportsVision) ||
isAiModelMultimodal({
capabilities: model.capabilities,
defaultParams: model.defaultParams,
})
);
}
type DetailPlanRequest = { type DetailPlanRequest = {
prompt?: string; prompt?: string;
count?: number; count?: number;
@ -738,8 +753,8 @@ export async function POST(request: Request) {
let plannerConfig = preferredAgentConfig; let plannerConfig = preferredAgentConfig;
if (referenceImages.length > 0) { if (referenceImages.length > 0) {
if (!plannerConfig?.model.supportsVision) { if (!plannerConfig || !supportsVisionPlanning(plannerConfig.model)) {
plannerConfig = reasoningCompatible.find((item) => item.model.supportsVision); plannerConfig = reasoningCompatible.find((item) => supportsVisionPlanning(item.model));
} }
} }
if (!plannerConfig) { if (!plannerConfig) {
@ -750,6 +765,19 @@ export async function POST(request: Request) {
return NextResponse.json({ success: true, data: fallback }); return NextResponse.json({ success: true, data: fallback });
} }
console.log("[Canvas Detail Plan] Planner model selected:", {
id: plannerConfig.model.id,
displayName: plannerConfig.model.displayName,
modelId: plannerConfig.model.modelId,
providerType: plannerConfig.provider.type,
supportsVision: plannerConfig.model.supportsVision,
multimodalFlag: isAiModelMultimodal({
capabilities: plannerConfig.model.capabilities,
defaultParams: plannerConfig.model.defaultParams,
}),
hasReferenceImages: referenceImages.length > 0,
});
const model = await getLanguageModelById(plannerConfig.model.id); const model = await getLanguageModelById(plannerConfig.model.id);
if (!model) { if (!model) {
return NextResponse.json({ success: true, data: fallback }); return NextResponse.json({ success: true, data: fallback });
@ -776,7 +804,7 @@ export async function POST(request: Request) {
.join("\n"); .join("\n");
const imageInputs = const imageInputs =
plannerConfig.model.supportsVision && referenceImages.length > 0 supportsVisionPlanning(plannerConfig.model) && referenceImages.length > 0
? referenceImages.map((url) => ({ type: "image" as const, image: url })) ? referenceImages.map((url) => ({ type: "image" as const, image: url }))
: []; : [];