# AiToolResultView
## Description
BitAiToolResultView shows a tool result carried on its own (a BitAiToolResultPart) rather than on the call it answers - a conversation imported from a store that keeps each result as a message of its own: a card headed by the tool's name, with the result as it was written, as a JSON tree when it is structured, or as a compact error when it failed. A result streamed in by a transport always goes to its call and is shown by the BitAiToolCallView of that call.
## Parameters
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Classes | `BitAiToolResultViewClassStyles?` | null | Custom CSS classes for different parts of the tool result view. |
| Part | `BitAiToolResultPart` | | The result to render (required). The card is headed by its ToolName (else by the Result text of the BitAiStrings in force) and shows its Outcome: a failure as a compact BitAiErrorView, a Text as it was written, else the Value as a BitAiJsonView. |
| Styles | `BitAiToolResultViewClassStyles?` | null | Custom CSS styles for different parts of the tool result view. |
| 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. |
## 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. |
## Enums
### 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. |
## Sub Classes
### BitAiToolResultViewClassStyles Properties
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Root | `string?` | null | Custom CSS classes/styles for the root element of the BitAiToolResultView. |
| Header | `string?` | null | Custom CSS classes/styles for the header of the BitAiToolResultView. |
| Icon | `string?` | null | Custom CSS classes/styles for the tool icon of the BitAiToolResultView. |
| Title | `string?` | null | Custom CSS classes/styles for the title of the BitAiToolResultView. |
| Body | `string?` | null | Custom CSS classes/styles for the body of the BitAiToolResultView. |
| Text | `string?` | null | Custom CSS classes/styles for a textual result of the BitAiToolResultView. |
### BitAiToolResultPart Properties
A tool result carried on its own (Kind "tool-result") rather than on the BitAiToolCallPart it answers. The stream processor never adds one: it gives a result to the call of its id, holding one that arrives ahead of its call for ToolResultHoldTime and dropping one whose call never starts. An app adds one to a message it builds itself - a conversation imported from a store that keeps each result as a message of its own.
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| BitAiToolResultPart(toolCallId, outcome, partId?) | `constructor` | | Creates a result of the call identified by toolCallId; partId is generated when left out. |
| ToolCallId | `string` | | The call the result answers. |
| ToolName | `string?` | null | The tool that produced the result, when known. It heads the card. |
| Outcome | `BitAiToolOutcome` | | The result itself: its Value, Text or Error. |
| PartId | `string` | | The identifier of the part (inherited from BitAiMessagePart, like the four members below): the partId given to the constructor, else a generated one. |
| Kind | `string` | "tool-result" | The kind of the part (BitAiMessagePartKinds.ToolResult), which BitAiMessagePartView renders with this view. |
| Version | `int` | 0 | Increments on every change of the part. |
| Message | `BitAiMessage?` | null | The message the part belongs to, once it has been added to one. |
| Changed | `event Action<BitAiMessagePart>` | | Raised after a part changes - which a result part never does: its Outcome is fixed, and setting its ToolName raises nothing. The view does not listen to it, so a ToolName set afterwards is drawn with the next render of the page. |
## CSS Variables
Public CSS custom properties read off the component's root. Set one on `:root` to restyle every instance, on any ancestor to restyle the ones inside it, or on the `Style` of one instance to restyle it and every instance nested inside it, which inherits the value too - a parameter changes one alone, as does the real CSS property on its `Style` / `Styles` when that property does not inherit (`opacity`); an inherited one (`color`, `font-family`) reaches the nested instances that do not set it themselves.
| Name | Default Value | Description |
| :--- | :------------ | :---------- |
| `--bit-AiToolResultView-background` | var(--bit-clr-bg-sec) | Surface of the card. |
| `--bit-AiToolResultView-border-color` | var(--bit-clr-brd-sec) | Outline of the card, and the rule under its header. |
| `--bit-AiToolResultView-radius` | var(--bit-shp-radius-surface) | Corner radius of the card. |
| `--bit-AiToolResultView-header-color` | var(--bit-clr-fg-sec) | Text and icon of the header. |
| `--bit-AiToolResultView-body-background` | var(--bit-clr-bg-pri) | Surface of the body. |
## Examples
\n**Basic**:
```razor
```
```csharp
private readonly BitAiToolResultPart textResult = new("call_logs", BitAiToolOutcome.FromText("""
3 errors in the last hour:
12:04 payment-api Timeout after 30s calling the ledger
12:31 payment-api Timeout after 30s calling the ledger
12:58 search Index rebuild failed: out of disk space
"""))
{
ToolName = "read_logs",
};
```
\n**Structured result**:
```razor
```
```csharp
private static JsonElement Json(string json) => JsonDocument.Parse(json).RootElement;
private readonly BitAiToolResultPart jsonResult = new("call_weather", BitAiToolOutcome.Success(Json("""
{"city":"Oslo","degrees":-3,"condition":"Snow","humidity":81,"forecast":[{"day":"Tue","high":-1},{"day":"Wed","high":2}]}
""")))
{
ToolName = "get_weather",
};
private readonly BitAiToolResultPart unnamedResult = new("call_unknown", BitAiToolOutcome.Success(Json("""{"deleted":128}""")));
```
\n**Failure**:
```razor
```
```csharp
private readonly BitAiToolResultPart failedResult = new("call_deploy", BitAiToolOutcome.Failure(new BitAiError("The deployment was rejected: the branch has failing checks.")
{
Code = "checks_failed",
Kind = BitAiErrorKind.Tool,
Detail = "build (ubuntu-latest): failed\ntest (windows-latest): failed\nlint: passed",
}))
{
ToolName = "deploy",
};
```
\n**In a message**:
```razor
@foreach (var part in resultMessage.Parts)
{
}
```
```csharp
private readonly BitAiMessage resultMessage = CreateResultMessage();
private static BitAiMessage CreateResultMessage()
{
var message = new BitAiMessage(BitAiRole.Assistant);
message.AddPart(new BitAiTextPart("I checked the logs of the last hour:"));
message.AddPart(new BitAiToolResultPart("call_logs", BitAiToolOutcome.FromText("3 errors, 2 of them timeouts of payment-api.")) { ToolName = "read_logs" });
message.AddPart(new BitAiTextPart("Both timeouts come from the ledger, so that is where to look first."));
return message;
}
```
\n**Cascading parameters**:
```razor
```
```csharp
private readonly BitAiToolResultViewParams[] resultViewParams =
[
new() { Styles = new() { Root = "border-style: dashed", Title = "font-style: italic" } },
];
private static JsonElement Json(string json) => JsonDocument.Parse(json).RootElement;
private readonly BitAiToolResultPart textResult = new("call_logs", BitAiToolOutcome.FromText("""
3 errors in the last hour:
12:04 payment-api Timeout after 30s calling the ledger
12:31 payment-api Timeout after 30s calling the ledger
12:58 search Index rebuild failed: out of disk space
"""))
{
ToolName = "read_logs",
};
private readonly BitAiToolResultPart failedResult = new("call_deploy", BitAiToolOutcome.Failure(new BitAiError("The deployment was rejected: the branch has failing checks.")
{
Code = "checks_failed",
Kind = BitAiErrorKind.Tool,
Detail = "build (ubuntu-latest): failed\ntest (windows-latest): failed\nlint: passed",
}))
{
ToolName = "deploy",
};
private readonly BitAiToolResultPart jsonResult = new("call_weather", BitAiToolOutcome.Success(Json("""
{"city":"Oslo","degrees":-3,"condition":"Snow","humidity":81,"forecast":[{"day":"Tue","high":-1},{"day":"Wed","high":2}]}
""")))
{
ToolName = "get_weather",
};
```
\n**Style & Class**:
```razor
```
```csharp
private static JsonElement Json(string json) => JsonDocument.Parse(json).RootElement;
private readonly BitAiToolResultPart textResult = new("call_logs", BitAiToolOutcome.FromText("""
3 errors in the last hour:
12:04 payment-api Timeout after 30s calling the ledger
12:31 payment-api Timeout after 30s calling the ledger
12:58 search Index rebuild failed: out of disk space
"""))
{
ToolName = "read_logs",
};
private readonly BitAiToolResultPart jsonResult = new("call_weather", BitAiToolOutcome.Success(Json("""
{"city":"Oslo","degrees":-3,"condition":"Snow","humidity":81,"forecast":[{"day":"Tue","high":-1},{"day":"Wed","high":2}]}
""")))
{
ToolName = "get_weather",
};
```
\n**RTL**:
```razor
```
```csharp
private readonly BitAiToolResultPart rtlResult = new("call_weather_fa", BitAiToolOutcome.FromText("تهران: ۱۸ درجه، آفتابی\nرطوبت: ۲۰٪"))
{
ToolName = "آب و هوا",
};
private readonly BitAiToolResultPart rtlUnnamedResult = new("call_unknown_fa", BitAiToolOutcome.FromText("۱۲۸ رکورد حذف شد."));
private readonly BitAiUiOptions persianOptions = BitAiUiOptions.Default with { Strings = new PersianAiStrings() };
// The heading of a result with no ToolName, in Persian.
private sealed class PersianAiStrings : BitAiStrings
{
public override string Result => "نتیجه";
}
```