- Introduced handling for 'answer_limited' events from the server, allowing the UI to reflect when an assistant's answer has reached the output-token limit. - Updated the VoiceStreamService to manage limited and interrupted turns with bounded memory. - Enhanced the transcript component to display appropriate messages for limited answers, including a fallback for unavailable text. - Added styles to visually indicate limited answers in the UI. - Created unit tests for the new functionality, ensuring correct behavior for limited answers and their presentation.
54 lines
2.3 KiB
TypeScript
54 lines
2.3 KiB
TypeScript
import { ChangeDetectionStrategy, Component, input } from '@angular/core';
|
|
import { VoiceMessage, VoiceSource } from '../../../services/voice-stream/voice-stream.types';
|
|
|
|
/** Read-only transcript bubbles (user / assistant), shared by the live call view and the ended-call chat box. */
|
|
@Component({
|
|
selector: 'app-voice-transcript',
|
|
standalone: true,
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
templateUrl: './voice-transcript.component.html',
|
|
styleUrl: './voice-transcript.component.css',
|
|
})
|
|
export class VoiceTranscriptComponent {
|
|
readonly messages = input.required<VoiceMessage[]>();
|
|
|
|
/**
|
|
* Compact chip label: the excerpt's first paragraph, followed by an ellipsis when the
|
|
* chunk holds more paragraphs. The document's internal `location.section` path (e.g.
|
|
* "docx/table/1/row/1/cell/1") is document structure, not content, so it is not shown
|
|
* in the chip (it stays in the hover tooltip, along with the complete excerpt). Sources
|
|
* the server marks unavailable keep their excerpt hidden and fall back to the title.
|
|
*/
|
|
sourceLabel(source: VoiceSource): string {
|
|
if (source.available !== false) {
|
|
const excerpt = source.excerpt?.trim();
|
|
if (excerpt) {
|
|
// Paragraph breaks (single or repeated newlines) separate the excerpt into
|
|
// paragraphs; only the first one is summarized into the chip.
|
|
const paragraphs = excerpt
|
|
.split(/\r?\n+/)
|
|
.map((paragraph) => paragraph.trim())
|
|
.filter(Boolean);
|
|
const first = paragraphs[0];
|
|
if (first) return paragraphs.length > 1 ? `${first} …` : first;
|
|
}
|
|
}
|
|
return source.title || source.document_id;
|
|
}
|
|
|
|
/** Hover tooltip: document, location and the complete, untruncated excerpt. */
|
|
sourceTooltip(source: VoiceSource): string {
|
|
const parts: string[] = [];
|
|
if (source.title) parts.push(source.title);
|
|
if (source.location?.page != null) parts.push(`صفحه ${source.location.page}`);
|
|
if (source.location?.section) parts.push(source.location.section);
|
|
// Same hidden-excerpt rule as the chip label: a source the server marks unavailable
|
|
// has revoked text, so it is not surfaced here either.
|
|
if (source.available !== false) {
|
|
const excerpt = source.excerpt?.trim();
|
|
if (excerpt) parts.push(excerpt);
|
|
}
|
|
return parts.join('\n');
|
|
}
|
|
}
|