feat: implement answer-limited state handling in voice stream service
- 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.
This commit is contained in:
@@ -12,11 +12,42 @@ import { VoiceMessage, VoiceSource } from '../../../services/voice-stream/voice-
|
||||
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);
|
||||
return parts.length ? `${source.title} — ${parts.join('، ')}` : source.title;
|
||||
// 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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user