54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
export interface AgentToolImageMarkdownItem {
|
||
originalUrl: string;
|
||
thumbnailUrl?: string | null;
|
||
imageSize?: string;
|
||
}
|
||
|
||
export function prependImageModelBadge(
|
||
text: string,
|
||
modelDisplayName?: string | null,
|
||
): string {
|
||
const normalizedText = String(text || "").trim();
|
||
if (!normalizedText) return normalizedText;
|
||
|
||
const normalizedModelName = String(modelDisplayName || "").trim();
|
||
if (!normalizedModelName) return normalizedText;
|
||
|
||
if (
|
||
/^\s*[◈◇◆🔹⬡✦•·]\s*[^\n]+/im.test(normalizedText) ||
|
||
/^\s*(?:Routed to|Using model|使用模型|模型)\s*[::]/im.test(normalizedText)
|
||
) {
|
||
return normalizedText;
|
||
}
|
||
|
||
return `◈ ${normalizedModelName}\n\n${normalizedText}`;
|
||
}
|
||
|
||
export function buildAgentToolImageMarkdown(params: AgentToolImageMarkdownItem): string {
|
||
const originalUrl = String(params.originalUrl || "").trim();
|
||
const thumbnailUrl = String(params.thumbnailUrl || originalUrl).trim() || originalUrl;
|
||
const imageSize = String(params.imageSize || "2K").trim() || "2K";
|
||
return ``;
|
||
}
|
||
|
||
export function buildAgentToolImagesMarkdown(items: AgentToolImageMarkdownItem[]) {
|
||
return items
|
||
.map((item) =>
|
||
buildAgentToolImageMarkdown({
|
||
originalUrl: item.originalUrl,
|
||
thumbnailUrl: item.thumbnailUrl,
|
||
imageSize: item.imageSize,
|
||
}),
|
||
)
|
||
.join("\n");
|
||
}
|
||
|
||
export function buildAgentToolVideoMarkdown(videoUrl: string) {
|
||
const normalizedUrl = String(videoUrl || "").trim();
|
||
if (!normalizedUrl) return "";
|
||
return [
|
||
`<video src="${normalizedUrl}" controls style="max-width: 100%; border-radius: 8px;"></video>`,
|
||
`[下载视频](${normalizedUrl})`,
|
||
].join("\n\n");
|
||
}
|