ai/ai-chat/ai-chat-tool-call-group.component.ts
Renders consecutive calls of the same tool as one collapsible row. Expanding it lists the calls with their status and the start of their input; each call can be expanded to show its full input and its output.
| changeDetection | ChangeDetectionStrategy.OnPush |
||||||||||||||||||||||||||
| selector | c8y-ai-chat-tool-call-group |
||||||||||||||||||||||||||
| imports |
C8yTranslatePipe
CollapseModule
|
||||||||||||||||||||||||||
| templateVariables |
|
||||||||||||||||||||||||||
| templateUrl | ./ai-chat-tool-call-group.component.html |
C8yTranslatePipe
IconDirective
CollapseModule
AiChatCodeBlockComponent
NgComponentOutlet
ListGroupComponent
ListItemComponent
ListItemIconComponent
ListItemCollapseComponent
@let _parts = parts();
@let toolName = _parts[0].toolName;
@let regionId = 'tool-call-group-' + _parts[0].toolCallId;
@let expandable = isExpandable();
@let isGroupExpanded = expandable && expanded();
@let failed = failedCount();
@let groupLabel = 'Tool calls: {{toolName}}' | translate: { toolName: displayName() };
@let callCountLabel =
'{{count}} calls`number of calls of one AI tool`' | translate: { count: _parts.length };
@let failedCountLabel =
'{{count}} failed`number of failed calls of one AI tool`' | translate: { count: failed };
@let runningLabel = 'Running`status of an AI tool call`' | translate;
@let failedLabel = 'Failed`status of an AI tool call`' | translate;
@let completedLabel = 'Completed`status of an AI tool call`' | translate;
<fieldset
class="c8y-fieldset p-b-4 ai-tool-call__fieldset"
[attr.aria-label]="groupLabel"
data-cy="ai-tool-call-group"
>
<button
class="btn-clean ai-tool-call__btn"
[attr.aria-expanded]="expandable ? isGroupExpanded : null"
[attr.aria-controls]="expandable ? regionId : null"
type="button"
[attr.data-cy]="'tool-call-group-' + toolName"
[disabled]="!expandable || null"
(click)="expanded.set(!isGroupExpanded)"
>
@if (isExecuting()) {
<i
class="icon-spin icon-16 text-primary m-r-4"
c8yIcon="spinner"
aria-hidden="true"
></i>
} @else {
<i
class="icon-16 m-r-4"
[class.text-danger]="failed > 0"
[class.text-success]="failed === 0"
[c8yIcon]="failed > 0 ? 'exclamation-circle' : 'check'"
aria-hidden="true"
data-cy="tool-call-group-status"
></i>
}
@if (expandable) {
<i
class="m-r-4"
[c8yIcon]="isGroupExpanded ? 'expand-arrow' : 'forward'"
aria-hidden="true"
></i>
}
<span class="small">{{ label() | translate }}</span>
<!-- Screen readers get the count from the text below -->
<span
class="tag tag--default b-r-pill a-s-center m-l-4"
aria-hidden="true"
data-cy="tool-call-group-count"
>×{{ _parts.length }}</span
>
<span class="sr-only">{{ callCountLabel }}</span>
<!-- Visible, since the label reads like a success even when calls failed -->
@if (failed > 0) {
<span
class="tag tag--danger b-r-pill a-s-center m-l-4"
data-cy="tool-call-group-failed"
>{{ failedCountLabel }}</span
>
}
</button>
@if (expandable) {
<div
class="collapse"
[attr.aria-label]="groupLabel"
role="region"
[collapse]="!isGroupExpanded"
[id]="regionId"
[isAnimated]="true"
>
<c8y-list-group
class="m-t-8 separator-top ai-tool-call__group-list"
role="list"
>
@for (call of calls(); track call.part.toolCallId) {
<!-- A click anywhere on the row toggles the output; the chevron button does so by keyboard -->
<c8y-li
[class.interact]="call.canExpand"
role="listitem"
[dense]="true"
(click)="call.canExpand && li.toggleCollapsed()"
data-cy="tool-call-group-item"
#li
>
<c8y-li-icon>
<!-- The number of the call, with its status at the top right, like the alarm icons -->
<span class="ai-tool-call__call-number">
{{ $index + 1 }}
@if (call.isExecuting) {
<i
class="icon-spin text-primary"
c8yIcon="spinner"
aria-hidden="true"
></i>
} @else if (call.part.error) {
<i
class="text-danger"
[c8yIcon]="'exclamation-circle'"
aria-hidden="true"
></i>
} @else {
<i
class="text-success"
[c8yIcon]="'ok'"
aria-hidden="true"
></i>
}
</span>
</c8y-li-icon>
<div class="d-flex a-i-start gap-8 min-width-0">
<!-- The status is also shown by the icon, so it is only visible when there is no input to show -->
@let status =
call.isExecuting ? runningLabel : call.part.error ? failedLabel : completedLabel;
<span
class="small"
[class.sr-only]="call.showsRawData"
>{{ status }}</span
>
<!-- The output is shown below the input in the same column, so that both line up -->
<div class="d-col flex-grow min-width-0">
@if (call.showsRawData) {
<!-- Limited in height until the call is expanded. A click on the full input is left to
selecting its text instead of collapsing the call. -->
<c8y-ai-chat-code-block
[class.ai-tool-call__input--clamped]="li.collapsed"
[value]="call.part.input"
[label]="'Tool input' | translate"
data-cy="tool-call-group-item-input"
(click)="li.collapsed || $event.stopPropagation()"
></c8y-ai-chat-code-block>
}
@if (call.canExpand) {
<div
[collapse]="li.collapsed"
[isAnimated]="true"
(click)="$event.stopPropagation()"
>
<div class="p-t-8">
@if (call.detailsComponent) {
<ng-container
[ngComponentOutlet]="call.detailsComponent"
[ngComponentOutletInputs]="{ tool: call.part }"
></ng-container>
} @else {
<c8y-ai-chat-code-block
[value]="call.part.output"
[label]="'Tool output' | translate"
data-cy="tool-call-group-item-output"
></c8y-ai-chat-code-block>
}
</div>
</div>
}
</div>
</div>
@if (call.canExpand) {
<!-- Left empty: it only gives the row its expand button and expanded state -->
<c8y-li-collapse></c8y-li-collapse>
}
</c8y-li>
}
</c8y-list-group>
</div>
}
</fieldset>