mirror of
https://github.com/block/buzz.git
synced 2026-11-29 04:32:08 +00:00
Signed-off-by: Taylor Ho <taylorkmho@gmail.com> Co-authored-by: npub1223z34hd7vtwc6qj4s7flsxkj644nlre2nthu7lrrmkumhu3xddsrx9r6w <52a228d6edf316ec6812ac3c9fc0d696ab59fc7954d77e7be31eedcddf91335b@sprout-oss.stage.blox.sqprod.co>
41 lines
840 B
TypeScript
41 lines
840 B
TypeScript
import type {
|
|
AgentActivityDescriptor,
|
|
TranscriptItem,
|
|
} from "./agentSessionTypes";
|
|
import { getToolString } from "./agentSessionUtils";
|
|
|
|
type ToolItem = Extract<TranscriptItem, { type: "tool" }>;
|
|
|
|
export type ImageToolContent = {
|
|
src: string;
|
|
title: string | null;
|
|
};
|
|
|
|
export function buildImageContent(
|
|
item: ToolItem,
|
|
descriptor: AgentActivityDescriptor,
|
|
): ImageToolContent | null {
|
|
if (descriptor.renderClass !== "image") {
|
|
return null;
|
|
}
|
|
|
|
const source = getToolString(item.args, ["source"]);
|
|
if (!source) {
|
|
return null;
|
|
}
|
|
|
|
const trimmed = source.trim();
|
|
if (
|
|
!trimmed.startsWith("data:image/") &&
|
|
!trimmed.startsWith("http://") &&
|
|
!trimmed.startsWith("https://")
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
src: trimmed,
|
|
title: descriptor.preview ?? descriptor.object ?? null,
|
|
};
|
|
}
|