70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import "server-only";
|
||
|
||
function shouldReplaceClarificationLikeMessage(message?: string) {
|
||
if (!message) return true;
|
||
const normalized = message.trim();
|
||
if (!normalized) return true;
|
||
return /[??]$/.test(normalized) || /哪一张|哪个|请先确认/.test(normalized);
|
||
}
|
||
|
||
export function resolveClarificationBypass(params: {
|
||
text: string;
|
||
hasCurrentImageInput: boolean;
|
||
hasHistoryImageInput: boolean;
|
||
hasCanvasSelection: boolean;
|
||
targetResolutionMode?: string | null;
|
||
executionMode?: string;
|
||
friendlyMessage?: string;
|
||
}) {
|
||
const latestUserText = String(params.text || "").trim();
|
||
if (
|
||
!params.hasCurrentImageInput &&
|
||
!params.hasHistoryImageInput &&
|
||
latestUserText.length <= 0
|
||
) {
|
||
return {
|
||
shouldBypass: false,
|
||
nextFriendlyMessage: params.friendlyMessage,
|
||
};
|
||
}
|
||
|
||
const canForceByIntent = /改|调整|优化|换|替换|去掉|抠|重绘|增强|修|处理|按照|按|保留|统一|色差|背景|清晰|风格/.test(
|
||
latestUserText,
|
||
);
|
||
const hasForceTargetHint =
|
||
params.hasCanvasSelection ||
|
||
params.targetResolutionMode === "text_reference" ||
|
||
/第[一二三四五六七八九十\d]+张|左|右|上|下|中间|选中/.test(latestUserText);
|
||
const canForceExecution =
|
||
(params.executionMode === "edit_image" ||
|
||
params.executionMode === "generate_image" ||
|
||
params.executionMode === "generate_video") &&
|
||
canForceByIntent &&
|
||
hasForceTargetHint;
|
||
|
||
if (!canForceExecution) {
|
||
return {
|
||
shouldBypass: false,
|
||
nextFriendlyMessage: params.friendlyMessage,
|
||
};
|
||
}
|
||
|
||
return {
|
||
shouldBypass: true,
|
||
nextFriendlyMessage: shouldReplaceClarificationLikeMessage(params.friendlyMessage)
|
||
? "收到,我将按你的当前需求直接执行。"
|
||
: params.friendlyMessage,
|
||
};
|
||
}
|
||
|
||
export function resolveClarificationMessage(params: {
|
||
clarificationQuestion?: string;
|
||
friendlyMessage?: string;
|
||
}) {
|
||
return (
|
||
params.clarificationQuestion ||
|
||
params.friendlyMessage ||
|
||
"我先确认一下,你希望我优先处理哪一部分?"
|
||
);
|
||
}
|