Map `messages` to Message
Use **`isTextUIPart`** from **`ai`** so you only aggregate **`type: "text"`** segments. Skip **`system`** turns unless you surface them deliberately. Assistant messages can also include **reasoning**, **tool**, **source**, and other part types—extend this loop when you need those in the UI.
```tsx
"use client";
import { useChat } from "@ai-sdk/react";
import { DefaultChatTransport, isTextUIPart, type UIMessage } from "ai";
import {
Message,
MessageStack,
MessageContent,
MessageMarkdown,
} from "@/components/nexus-ui/message";
function textFromMessage(message: UIMessage) {
return message.parts.filter(isTextUIPart).map((p) => p.text).join("");
}
export default function ChatThread() {
const { messages } = useChat({
transport: new DefaultChatTransport({ api: "/api/chat" }),
});
return (
{messages
.filter((m) => m.role !== "system")
.map((m) => (
{textFromMessage(m)}
))}
);
}
```