Custom Chat recipe

Source: 08_CustomChat/ · a drop-in replacement for the workspace's default chat experience.

How it looks

A custom header with a topic selector, example chips, a transcript, and per-message thumbs-up/down commands. The recipe sends each message to the workspace's assistant with the chosen topic attached; the runnable Tesserae preview below echoes a canned reply so you can try it here.

What it teaches

  • Building a chat page from the workspace's ChatView and a ChatViewConfiguration.
  • A custom header with a topic selector beside the assistant picker.
  • Fixed example prompts on the empty chat (WelcomePrompts).
  • Passing what the page knows (the topic) to the model with every turn, through PostMessage and ReplaceMessage.
  • Per-message commands (thumbs up / thumbs down) on the assistant's replies.

The same view replaces the product's assistant page when it is set as settings.AssistantView in App.cs.

Code shape

var configuration = new ChatViewConfiguration
{
    Title                  = "Recipe Chat",
    WelcomeTitle           = "Ask about the support cases",
    ChatBoxPlaceholderText = "Ask a question about a product or a case",
    WelcomePrompts         = new[] { "Summarise the most recent support cases for cameras.", /* ... */ },
    Category               = "recipes",   // this page's history lists only the chats it started

    CustomHeader    = BuildHeader,
    PostMessage     = PostMessageAsync,
    ReplaceMessage  = ReplaceMessageAsync,
    MessageCommands = BuildMessageCommands,
};

_chatView = new ChatView(configuration, state);

Other hooks on ChatViewConfiguration:

Property Use when
NewChat You decide which assistant a new chat uses.
ReplaceMessage What Edit and Regenerate call. Override it whenever you override PostMessage, or those two run without what PostMessage adds.
ListToolsAndAgents The composer should offer a curated set of tools and agents.
ListChats You filter the chat history yourself.
CustomExamples The empty chat needs more than a list of prompts.

Settings on the chat view itself

Beyond the hooks, ChatViewConfiguration carries settings that decide how the surface behaves for everyone using it — a property of the surface, not a switch the reader has to find:

Setting Effect
MaxMessageCharacters Caps how long a single message may be. The composer stops taking text at the limit and shows a "used / max" counter next to the send button once more than half the budget is spent; below that the counter is collapsed, so an ordinary message never carries a number. Zero (the default) means no limit and no counter.
Skills The skills every turn on this surface carries. Leave it null and the view says nothing about skills, so the run falls back to the ones configured on the chat's assistant template. An empty array is a choice, not silence — it carries no skills at all.
GroupedToolsThreshold How long a run of consecutive tool calls has to be before the transcript collapses it into one "Used N tools" summary. The default of 2 groups every run of more than one call; raise it to leave short runs as individual calls, and set it past any run a turn can produce (int.MaxValue) to never group at all. A lone call is never a group, so anything below 2 behaves as 2.
GroupedToolsDisplay How that summary presents itself: a pill opening a modal (the default), a pill expanding in place, or already expanded in place. Only affects the persisted transcript — a streaming reply always shows its calls inline and expanded.
DisableMessageQueueing By default, sending while the assistant is still replying holds the message as the chat's next turn rather than interrupting the reply. Set this to make the composer's trigger stop the reply instead.
ParseAs Which entity-linking parse the composer applies.
DisableNextStepSuggestions Turns off the follow-up pills described in What a reply can render as. By default a trailing next-steps fence in an assistant message is stripped from the rendered Markdown and shown as clickable pills on the last message; set this and the fence is still stripped, but nothing is rendered from it.
WelcomeTitle / WelcomePrompts The heading and the grid of starter prompts on an empty chat. A prompt is a plain string; clicking one sends it.
DisableWelcomePrompts Drops that grid without replacing it — for a surface whose empty state asks the reader something of its own through CustomHeader, where a row of generic "try this" prompts only competes with the question. Setting CustomExamples replaces the grid outright and does not need this.
ReadOnly Renders the transcript without a composer. Anything that continues the conversation is gone with it, the follow-up pills included.

What a reply can render as

A reply is Markdown, and the chat view renders it as Markdown. Four shapes are more than that, and every one of them is something the assistant writes — a fenced block, or a tool call — not a feature the view switches on. They work on any surface built on ChatView, a custom chat included.

The assistant writes The chat view renders Built-in skill
A fence tagged markdown, more than four line breaks long A Canvas — a button above a folded preview of the source, opening a side pane with a Preview / Markdown dropdown and a Download as Word button. The reader can edit the source in the pane and watch it re-render. chat-render-document
A fence tagged slides A deck in place of the source — carousel, dots, an N / M counter — plus a Slides button that opens it full size, where Download as PowerPoint sits. chat-render-slides
A trailing fence tagged next-steps, one suggestion per line, each a short pill title and the message to send separated by a vertical bar Up to four clickable pills on the last message of a live chat, each labelled with its title and sending its message verbatim as the user's next message. chat-render-next-steps
A call to ask-user-question / ask-user-multiple-choice One answerable card above the composer, gathering every pending question of the turn. Answering resumes the run. chat-render-questionnaire

Two more code-block behaviours sit beside these: a fence tagged html gets a fully sandboxed live preview next to its source (unless the workspace enables paranoid message rendering), and a fence in any other language over four line breaks gets a button that opens it in a code editor.

The four skills in the right-hand column are what teach an assistant to produce these. Add the skill to the assistant template rather than restating its rules in a system prompt — the skill is versioned with the product, a pasted copy is not.

Turning a reply into a downloadable file

The Canvas and the deck are the two shapes that become a file, and both go through the same call: POST /api/chatai/render-markdown, which runs the Markdown through the same renderer workspace code reaches as scope.ChatAI.RenderMarkdown(...).

Fence OutputType File
markdown FilesType.Documents .docx
slides FilesType.Slides .pptx

Four things are worth knowing before you build on it:

  • The file is named after the document's own title — the first # heading of the Markdown, for a deck the first slide's title. A reply with no heading falls back to Export.docx / Export.pptx. The title is text the assistant wrote, so it is stripped of characters no file name may carry and capped at 80 characters.
  • Nothing is stored. The rendered file is streamed straight back to the browser.
  • The Markdown comes from the canvas, not from the transcript, because the reader may have edited it in the pane before pressing Download. The chat UID travels with the request and is checked against the caller's own chats, so the endpoint cannot be used as a general-purpose converter.
  • Only Documents and Slides render. Any other FilesType is a 400, not a 500 out of the converter.

A deck splits on a line of three or more dashes (---), not on # headings. Nothing else splits it, so a --- used as a horizontal rule inside a slide silently starts a new one.

Suggested follow-up questions

The pills are the one shape that writes back into the composer, so they are worth spelling out. The assistant ends its reply with:

Uptime held at 99.94% for the quarter, against a 99.9% target. Both incidents
were configuration, not capacity.

```next-steps
The two incidents|Walk me through both incidents in detail, with their timelines
Closest calls|Which services came closest to breaching the 99.9% target this quarter?
Draft the summary|Draft the uptime summary for the quarterly review
```

The fence never renders as text — not even half-written, since the streaming path strips an unterminated fence too — and each line becomes a button under the last assistant message.

A line carries two things separated by a |: the title, which is the pill's label, and the message, which is what clicking sends as the next user message. The message is also the pill's tooltip, so the reader can read it in full before committing to it.

  • The split is on the first |. Everything after it is the message, so the message itself may contain more of them.
  • A line with no | is both halves — label and message — which is how the block worked before titles existed. Use it when the message is already short enough to read as a button.
  • A half-written line falls back to the side that has text. Title| and |Message both render one pill rather than an empty one.
  • Only the last such block in a message is read, and text after it survives into the reply, so nothing belongs after it.
  • One suggestion per line. A leading -, * or • is tolerated and stripped.
  • At most four lines are shown. A line whose message is shorter than three characters or 200 characters or longer is dropped. Plain text only — the title renders as a button label, so Markdown, code spans and links survive in neither half.
  • The message is sent verbatim, so write it in the user's voice and make it self-contained: "Show me the failed runs from last week", never "I could show you the failed runs" or "and the other ones?". Keep the title to two to four words, and never let it say something the message does not.
  • Never put anything the reader needs in the block. The pills only appear on the last message of a live chat, they are gone from a read-only transcript, and a view can switch them off with DisableNextStepSuggestions.

Passing context with a turn

What the model should know about the page, here the topic, goes in uiContext, not in the message. The model reads it; the transcript shows only what the user typed.

private Task<UID128> PostMessageAsync(ChatViewConfiguration.PostMessageRequest request)
    => Mosaik.API.ChatAI.PostMessage(
        chatUID:           request.ActiveChat.UID,
        message:           request.Message,
        useTools:          request.ActiveTools,
        useAgents:         request.ActiveAgents,
        useSkills:         request.ActiveSkills,
        attachments:       request.AttachmentUIDs,
        uiContext:         "[UI context]\nThe user scoped this conversation to the topic: " + _topic.Value + ".",
        cancellationToken: request.CancellationToken);

ReplaceMessageAsync makes the same call through Mosaik.API.ChatAI.ReplaceMessage, with request.MessageUID. To answer from an endpoint of your own instead of the workspace's assistant, call it in PostMessage with Mosaik.API.Endpoints.CallAsync<T>(...) and return the UID of the message it wrote.

See also