修复Agent输出设置不再臆造未设置参数
This commit is contained in:
parent
31e4ca6407
commit
b7a9c30e70
@ -247,6 +247,46 @@ function mergeImageParamsWithAgentRecommendation(params: {
|
|||||||
return Object.keys(merged).length > 0 ? merged : undefined;
|
return Object.keys(merged).length > 0 ? merged : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sanitizeAgentOutputSettingsSection(params: {
|
||||||
|
message?: string;
|
||||||
|
userImageParams?: PostRequestBody["imageParams"];
|
||||||
|
hasUserCustomImageParams: boolean;
|
||||||
|
}): string | undefined {
|
||||||
|
const { message, userImageParams, hasUserCustomImageParams } = params;
|
||||||
|
if (!message?.trim()) return message;
|
||||||
|
|
||||||
|
const outputSectionRegex = /###\s*输出设置[\s\S]*?(?=\n###\s*|$)/;
|
||||||
|
if (!outputSectionRegex.test(message)) return message;
|
||||||
|
|
||||||
|
if (!hasUserCustomImageParams) {
|
||||||
|
return message.replace(
|
||||||
|
outputSectionRegex,
|
||||||
|
"### 输出设置\n- 参数:按用户面板当前设置执行(未自动改写)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const lines: string[] = [];
|
||||||
|
const aspectRatio =
|
||||||
|
typeof userImageParams?.aspectRatio === "string" ? userImageParams.aspectRatio.trim() : "";
|
||||||
|
const imageSize =
|
||||||
|
typeof userImageParams?.imageSize === "string" ? userImageParams.imageSize.trim() : "";
|
||||||
|
const imageCount =
|
||||||
|
typeof userImageParams?.imageCount === "number" ? userImageParams.imageCount : undefined;
|
||||||
|
|
||||||
|
if (aspectRatio && aspectRatio !== "auto") {
|
||||||
|
lines.push(`- 宽高比:${aspectRatio}(来自用户面板设置)`);
|
||||||
|
}
|
||||||
|
if (imageSize && imageSize.toUpperCase() !== "2K") {
|
||||||
|
lines.push(`- 清晰度档位:${imageSize.toUpperCase()}(来自用户面板设置)`);
|
||||||
|
}
|
||||||
|
if (typeof imageCount === "number" && Number.isFinite(imageCount) && imageCount !== 1) {
|
||||||
|
lines.push(`- 出图数量:${Math.max(1, Math.round(imageCount))} 张(来自用户面板设置)`);
|
||||||
|
}
|
||||||
|
lines.push("- 其余参数:保持用户面板当前设置");
|
||||||
|
|
||||||
|
return message.replace(outputSectionRegex, `### 输出设置\n${lines.join("\n")}`);
|
||||||
|
}
|
||||||
|
|
||||||
function guessImageMediaType(url: string): string {
|
function guessImageMediaType(url: string): string {
|
||||||
const cleanUrl = url.split("?")[0]?.toLowerCase() || "";
|
const cleanUrl = url.split("?")[0]?.toLowerCase() || "";
|
||||||
if (cleanUrl.endsWith(".jpg") || cleanUrl.endsWith(".jpeg")) return "image/jpeg";
|
if (cleanUrl.endsWith(".jpg") || cleanUrl.endsWith(".jpeg")) return "image/jpeg";
|
||||||
@ -1286,6 +1326,14 @@ export async function POST(request: Request) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shouldRunAgentConversation && smartAutoFriendlyMessage) {
|
||||||
|
smartAutoFriendlyMessage = sanitizeAgentOutputSettingsSection({
|
||||||
|
message: smartAutoFriendlyMessage,
|
||||||
|
userImageParams: requestBody.imageParams,
|
||||||
|
hasUserCustomImageParams,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
|
|
||||||
if (!session?.user) {
|
if (!session?.user) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user