145 lines
4.6 KiB
TypeScript
145 lines
4.6 KiB
TypeScript
import {
|
||
buildAgentToolImageMarkdown,
|
||
buildAgentToolImagesMarkdown,
|
||
buildAgentToolVideoMarkdown,
|
||
prependImageModelBadge,
|
||
} from "@/lib/ai/runtime/agent-media-markdown";
|
||
import {
|
||
getDirectAgentToolDisplayName,
|
||
getDirectAgentToolSuccessMessage,
|
||
type DirectAgentToolCapability,
|
||
} from "@/lib/ai/runtime/direct-agent-execution";
|
||
|
||
function normalizeDirectAgentResultSentence(value: string) {
|
||
const normalized = String(value || "")
|
||
.replace(/结果如下[::]?\s*$/u, "")
|
||
.replace(/[,,。::]\s*$/u, "")
|
||
.trim();
|
||
return normalized || "已完成处理";
|
||
}
|
||
|
||
function buildDirectAgentResultCard(params: {
|
||
result: string;
|
||
mediaMarkdown?: string | null;
|
||
followUp: string;
|
||
}) {
|
||
return [
|
||
"### 执行结果",
|
||
`- ${normalizeDirectAgentResultSentence(params.result)},结果如下。`,
|
||
params.mediaMarkdown,
|
||
"### 后续操作",
|
||
`- ${params.followUp}`,
|
||
]
|
||
.filter(Boolean)
|
||
.join("\n\n");
|
||
}
|
||
|
||
function getDirectAgentFollowUpMessage(capability: DirectAgentToolCapability) {
|
||
switch (capability) {
|
||
case "remove_background":
|
||
return "如需微调边缘、替换背景或继续合成,可以直接告诉我。";
|
||
case "remove_watermark":
|
||
return "如需继续修补局部痕迹或统一画面质感,可以直接告诉我。";
|
||
case "enhance":
|
||
return "如需继续调整清晰度、色彩或细节强度,可以直接告诉我。";
|
||
case "resize":
|
||
return "如需继续改尺寸、比例或输出规格,可以直接告诉我。";
|
||
case "extend":
|
||
return "如需继续扩展画面、调整构图或补充边缘内容,可以直接告诉我。";
|
||
case "angle_variant":
|
||
return "如需继续换角度、换机位或统一系列视角,可以直接告诉我。";
|
||
case "local_edit":
|
||
case "box_cutout":
|
||
return "如需继续修改局部、替换元素或细化边缘,可以直接告诉我。";
|
||
case "generate_video":
|
||
return "如需继续调整镜头、节奏、比例或时长,可以直接告诉我。";
|
||
case "generate_image":
|
||
case "generic_edit":
|
||
default:
|
||
return "如需继续调整风格、构图、主体细节或尺寸,可以直接告诉我。";
|
||
}
|
||
}
|
||
|
||
export function buildDirectAgentAnalysisAssistantText(params: {
|
||
summary: string;
|
||
answer?: string | null;
|
||
}) {
|
||
const answer = String(params.answer || "").trim();
|
||
return prependImageModelBadge(
|
||
[
|
||
getDirectAgentToolSuccessMessage("analyze"),
|
||
`图像观察:\n${String(params.summary || "").trim()}`,
|
||
answer ? `分析结论:\n${answer}` : "",
|
||
]
|
||
.filter(Boolean)
|
||
.join("\n\n"),
|
||
getDirectAgentToolDisplayName("analyze"),
|
||
);
|
||
}
|
||
|
||
export function buildDirectAgentImageGenerationAssistantText(params: {
|
||
imageMarkdown: string;
|
||
modelDisplayName?: string | null;
|
||
}) {
|
||
return prependImageModelBadge(
|
||
buildDirectAgentResultCard({
|
||
result: getDirectAgentToolSuccessMessage("generate_image"),
|
||
mediaMarkdown: params.imageMarkdown,
|
||
followUp: getDirectAgentFollowUpMessage("generate_image"),
|
||
}),
|
||
params.modelDisplayName,
|
||
);
|
||
}
|
||
|
||
export function buildDirectAgentVideoGenerationAssistantText(params: {
|
||
videoUrl: string;
|
||
modelDisplayName?: string | null;
|
||
}) {
|
||
return prependImageModelBadge(
|
||
buildDirectAgentResultCard({
|
||
result: getDirectAgentToolSuccessMessage("generate_video"),
|
||
mediaMarkdown: buildAgentToolVideoMarkdown(params.videoUrl),
|
||
followUp: getDirectAgentFollowUpMessage("generate_video"),
|
||
}),
|
||
params.modelDisplayName,
|
||
);
|
||
}
|
||
|
||
export function buildDirectAgentImageEditAssistantText(params: {
|
||
capability: DirectAgentToolCapability;
|
||
originalUrl: string;
|
||
thumbnailUrl?: string | null;
|
||
imageSize?: string;
|
||
}) {
|
||
return prependImageModelBadge(
|
||
buildDirectAgentResultCard({
|
||
result: getDirectAgentToolSuccessMessage(params.capability),
|
||
mediaMarkdown: buildAgentToolImageMarkdown({
|
||
originalUrl: params.originalUrl,
|
||
thumbnailUrl: params.thumbnailUrl,
|
||
imageSize: params.imageSize,
|
||
}),
|
||
followUp: getDirectAgentFollowUpMessage(params.capability),
|
||
}),
|
||
getDirectAgentToolDisplayName(params.capability),
|
||
);
|
||
}
|
||
|
||
export function buildDirectAgentBatchImageEditAssistantText(params: {
|
||
capability: DirectAgentToolCapability;
|
||
results: Array<{
|
||
originalUrl: string;
|
||
thumbnailUrl?: string | null;
|
||
imageSize?: string;
|
||
}>;
|
||
}) {
|
||
return prependImageModelBadge(
|
||
buildDirectAgentResultCard({
|
||
result: getDirectAgentToolSuccessMessage(params.capability),
|
||
mediaMarkdown: buildAgentToolImagesMarkdown(params.results),
|
||
followUp: getDirectAgentFollowUpMessage(params.capability),
|
||
}),
|
||
getDirectAgentToolDisplayName(params.capability),
|
||
);
|
||
}
|