AI
AiTextPartView
BitAiTextPartView renders a text part of a message as Markdown through a BitAiStreamingMarkdown, with a caret while the part is still growing. Citations anchored to character offsets of the part are woven into the text as numbered markers before it is parsed, so each superscript lands mid-sentence where the claim it supports ends - and a citation whose span ends inside code is left to the source list, where a marker cannot break the code.
Notes
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
Blazor can render a component in two places:
on the server, which streams UI diffs over a circuit;
in the browser, on WebAssembly.
Pick per page with @rendermode.
Streaming
Citations
Interactive Server keeps component state on the server and streams UI diffs over a SignalR circuit. Persist what has to survive a dropped circuit with PersistentComponentState.
Cascading parameters
Blazor can render a component in two places:
on the server, which streams UI diffs over a circuit;
in the browser, on WebAssembly.
Pick per page with @rendermode.
Interactive Server keeps component state on the server and streams UI diffs over a SignalR circuit. Persist what has to survive a dropped circuit with PersistentComponentState.
Interactive Server keeps component state on the server and streams UI diffs over a SignalR circuit. Persist what has to survive a dropped circuit with PersistentComponentState.
Style & Class
RTL
بلیزر یک کامپوننت را در دو جا رندر میکند:
روی سرور، که تغییرات را از راه یک اتصال میفرستد؛
در مرورگر، روی WebAssembly.
API
Every parameter, public member, sub-class and enum this component exposes.
BitAiTextPartView parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Classes | BitAiTextPartViewClassStyles? | null | Custom CSS classes for different parts of the text part view. |
| Message | BitAiMessage | The message the part belongs to (required), whose citations the markers of the text resolve against. Only the citations anchored to this part (their PartId, or none) and whose span the text already reaches are woven in, as numbered markers placed where each span ends; a span that ends inside code gets none. | |
| OnCitationClick | EventCallback<BitAiCitation> | The callback for when the user activates an inline citation marker, with the citation it stands for. | |
| Part | BitAiTextPart | The part to render (required) - a BitAiTextPart or a BitAiMarkdownPart. Its text is rendered as Markdown, with a caret and its last block left open while the part is streaming; the citations are woven in again only when the part, its version, the message, the number of its citations or BitAiUiOptions.InlineCitations changed. The view does not subscribe to the part: it shows the part as it stands each time its parent renders it. | |
| Styles | BitAiTextPartViewClassStyles? | null | Custom CSS styles for different parts of the text part view. |
BitComponentBase parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AriaLabel | string? | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | string? | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | BitDir? | null | Gets or sets the text directionality for the component's content. |
| Disabled | bool | false | Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction. |
| ForceAnimation | bool | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| HtmlAttributes | Dictionary<string, object> | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. An attribute written on the component wins over an entry of the same name. |
| Id | string? | null | Gets or sets the unique identifier for the component's root element. |
| Style | string? | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | string? | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | BitVisibility | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
BitComponentBase public members
| Name | Type | Default value | Description |
|---|---|---|---|
| UniqueId | Guid | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | ElementReference | Gets the reference to the root HTML element associated with this component. |
BitAiTextPartViewClassStyles properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Root | string? | null | Custom CSS classes/styles for the root element of the BitAiTextPartView. |
| Markdown | BitAiStreamingMarkdownClassStyles? | null | Custom CSS classes/styles for the BitAiStreamingMarkdown the BitAiTextPartView renders its text with (and, through its own Markdown, for every part of the Markdown view inside it). |
BitAiTextPart properties
A run of text that grows as the model writes it - the body of an assistant message. new BitAiTextPart() creates an empty part that expects more text (streaming), new BitAiTextPart(text) a finished one, and new BitAiTextPart(text, partId) a part with an identifier a transport addresses it by (null text: streaming). Appending is amortised constant time, and it is safe for one writer and any number of readers. BitAiMarkdownPart is the same part marked as Markdown, for hosts that render plain text parts verbatim; BitAiReasoningPart and BitAiCodePart derive from it too, so they share every member below.
| Name | Type | Default value | Description |
|---|---|---|---|
| Text | string | The text accumulated so far. | |
| Length | int | 0 | How many characters have arrived, without materialising the string - the cheap read for hot paths such as auto-scroll checks. |
| IsEmpty | bool | Whether no text has arrived yet. | |
| IsStreaming | bool | Whether more text is expected: true for a part created without text until Complete is called. | |
| Append(string? delta) | void | Appends a delta and notifies the observers of the part (an empty delta is ignored). | |
| SetText(string text) | void | Replaces the whole text, for edits and regenerations. | |
| Complete() | void | Marks the part finished, which lets the renderers do the work they deferred while it was growing (highlighting a code block, dropping the caret). | |
| Kind | string | "text" | The part kind (BitAiMessagePartKinds.Text; "markdown" for a BitAiMarkdownPart), which picks the renderer of the part in a message. |
| PartId | string | The identifier of the part, given to the constructor or generated. An anchored citation names it in its PartId. | |
| Version | int | 0 | Increments on every change, so a renderer compares two integers rather than two texts. |
| Message | BitAiMessage? | null | The message the part belongs to, once it has been added to one (BitAiMessage.AddPart). |
| Changed | event Action<BitAiMessagePart>? | Raised after every change, on whichever thread made it; the message the part belongs to raises its own PartChanged too. |
BitVisibility enum
| Name | Value | Description |
|---|---|---|
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
BitDir enum
| Name | Value | Description |
|---|---|---|
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.