open-swe/apps/web/src/components/thread/utils.ts
Brace Sproul ed9862bbbb
fix: web (#35)
* fix: web

* cr

* cr
2025-05-28 13:25:30 -07:00

15 lines
641 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" || !content) return content;
const texts = content
.filter((c): c is { type: "text"; text: string } => c.type === "text")
.map((c) => c.text);
return texts.join(" ");
}