Streaming Messages

StreamingMessageView renders a reply as the agent writes it: Markdown, code with syntax highlighting, tables, images and charts, typed out letter by letter, as ChatGPT does. AIConversationView shows every reply with it, and you can use it on its own in a view of yours:

StreamingMessageView(
    content: reply.text,
    isGenerating: reply.isGenerating
)

Type the reply out

While isGenerating is true, the view types out the text that's new since the last update, and follows the text as it grows. Once it's false, the view shows the full text at once. That's why a stored reply doesn't type itself out again when the user scrolls back to it.

letterInterval sets the speed of the typing, in seconds per letter. The default is 0.005, which is 5 ms.

With Stream Chat, a reply is generating while its message's generating field is true. What your backend sends covers how to set it.

Code and charts

Code blocks render with syntax highlighting and a button that copies the code. A code block whose language is chart, json, chartjs, echarts, highcharts, vega-lite or vegalite, and whose content is a chart spec, renders as a native chart instead. The view reads Chart.js, ECharts, Highcharts, Plotly heatmaps and (a subset of) Vega-Lite specs, as well as a simpler format of its own, which is handy to describe in your agent's instructions:

```chart
{
  "chart_type": "bar",
  "title": "Signups per month",
  "x_label": "Month",
  "y_label": "Users",
  "series": [
    {
      "name": "2026",
      "points": [{ "x": "Jan", "y": 120 }, { "x": "Feb", "y": 180 }, { "x": "Mar", "y": 240 }]
    }
  ]
}
```

The chart types are line, bar, area, scatter, bubble, pie, heatmap and histogram. Charts are drawn with Swift Charts, so they require iOS 16. On iOS 15, the spec renders as a code block, and on iOS 16, pie charts draw as bars.

The Markdown renderer and the code highlighting, Guille Gonzalez's Swift Markdown UI and John Sundell's Splash, are built into StreamChatAI. They don't appear among your app's packages, and your app can use its own version of Swift Markdown UI next to StreamChatAI.

Note:

Before version 5.15.0, StreamChatAI brought Splash and Swift Markdown UI in as package dependencies. If your app imports MarkdownUI or Splash itself, add those packages to your app directly when you update.

Show what the agent is doing

Before the first word of a reply arrives, the agent may spend a while thinking or calling tools. AITypingIndicatorView shows what it's doing: a text of your choice, followed by three pulsing dots:

AITypingIndicatorView(text: "Checking external sources")

An AIConversation tells you what the agent says it's doing as its activity. While the agent only thinks, AIConversationView shows "Thinking... 4s" by itself, as described in Show the agent thinking.

Appearance

The view reads its colors, fonts and icons from AIAppearance, as described in Theming:

  • Colors: codeBlockBackground, codeBlockHeaderBackground and codeBlockHeaderText for code blocks, and codeText, codeKeyword, codeString, codeType, codeCall, codeNumber, codeComment, codeProperty, codeDotAccess and codePreprocessing for the syntax highlighting.
  • Fonts: codeBlockLanguage, chartTitle and chartAnnotation.
  • Icons: codeBlockCopy.