Template
16 lines
474 B
TypeScript
16 lines
474 B
TypeScript
import type { UIMessage } from "ai";
|
|
|
|
type MessagePart = UIMessage["parts"][number];
|
|
type ReasoningPart = Extract<MessagePart, { type: "reasoning" }>;
|
|
|
|
export function getTextContent(parts: MessagePart[]): string {
|
|
return parts
|
|
.filter((p) => p.type === "text")
|
|
.map((p) => p.text || "")
|
|
.join("");
|
|
}
|
|
|
|
export function getReasoningPart(parts: MessagePart[]): ReasoningPart | undefined {
|
|
return parts.find((p): p is ReasoningPart => p.type === "reasoning");
|
|
}
|