Assistant answers render as markdown
react-markdown, lazy-loaded with the first answer (37 kB gzip chunk, main bundle unchanged). No raw HTML, images dropped, links open in a new tab. The system prompt asks for lists, inline code and fenced code blocks.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { queryOptions, useQuery, useQueryClient } from "@tanstack/react-query"
|
||||
import { useRouterState } from "@tanstack/react-router"
|
||||
import { Bird, Bot, MessageCircle, Send, Square, Trash2 } from "lucide-react"
|
||||
import { useEffect, useRef, useState } from "react"
|
||||
import { lazy, Suspense, useEffect, useRef, useState } from "react"
|
||||
|
||||
import { AiService, type ChatItem } from "@/client"
|
||||
import { flowKeys } from "@/components/Flow/queries"
|
||||
@@ -23,6 +23,9 @@ import { type ChatTab, chatStore, useChat } from "./chatStore"
|
||||
import { type ChatEvent, streamTurn } from "./stream"
|
||||
import { type Action, type ControlItem, useControl } from "./useControl"
|
||||
|
||||
/** The renderer arrives with the first answer, not with the app. */
|
||||
const Markdown = lazy(() => import("./Markdown"))
|
||||
|
||||
export const aiStatusQueryOptions = () =>
|
||||
queryOptions({
|
||||
queryKey: ["ai", "status"],
|
||||
@@ -382,8 +385,14 @@ function Message({ item }: { item: Item }) {
|
||||
)
|
||||
case "assistant":
|
||||
return (
|
||||
<div className="self-start whitespace-pre-wrap break-words px-1 text-sm">
|
||||
{item.text}
|
||||
<div className="min-w-0 max-w-full self-start px-1 text-sm">
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="whitespace-pre-wrap break-words">{item.text}</div>
|
||||
}
|
||||
>
|
||||
<Markdown text={item.text} />
|
||||
</Suspense>
|
||||
</div>
|
||||
)
|
||||
case "error":
|
||||
|
||||
Reference in New Issue
Block a user