2025-05-28 12:26:47 -07:00
|
|
|
import type { Message } from "@langchain/langgraph-sdk";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extracts a string summary from a message's content, supporting multimodal (text, image, file, etc.).
|
|
|
|
|
* - If text is present, returns the joined text.
|
|
|
|
|
* - If not, returns a label for the first non-text modality (e.g., 'Image', 'Other').
|
|
|
|
|
* - If unknown, returns 'Multimodal message'.
|
|
|
|
|
*/
|
|
|
|
|
export function getContentString(content: Message["content"]): string {
|
2025-05-28 13:25:30 -07:00
|
|
|
if (typeof content === "string" || !content) return content;
|
2025-05-28 12:26:47 -07:00
|
|
|
const texts = content
|
|
|
|
|
.filter((c): c is { type: "text"; text: string } => c.type === "text")
|
|
|
|
|
.map((c) => c.text);
|
|
|
|
|
return texts.join(" ");
|
|
|
|
|
}
|