mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-01 13:13:14 +00:00
16 lines
629 B
TypeScript
16 lines
629 B
TypeScript
|
|
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 {
|
||
|
|
if (typeof content === "string") return content;
|
||
|
|
const texts = content
|
||
|
|
.filter((c): c is { type: "text"; text: string } => c.type === "text")
|
||
|
|
.map((c) => c.text);
|
||
|
|
return texts.join(" ");
|
||
|
|
}
|