ai-chatbot/lib/ai/runtime/clarification-interruption.ts
Your Name 5a4e9fd582
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
feat: unify agent workflow protocol
2026-03-13 16:16:09 +08:00

70 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 ||
"我先确认一下,你希望我优先处理哪一部分?"
);
}