refactor: overhaul home UI and audio playback reliability

Redesign the home page and voice stream panel into a compact dock
layout to improve the chat experience. Implement a flush mechanism in
the PCM playback worklet to handle the resampler tail, preventing
premature session termination due to phantom outstanding playback.
Fix document filter visibility in settings to ensure controls remain
accessible when no results match, and refactor transcript insertion
to maintain correct user/assistant ordering.
This commit is contained in:
PeymanHonarjoo
2026-10-10 17:47:51 +03:30
parent be17544f2d
commit 28590c6dce
16 changed files with 1092 additions and 534 deletions
@@ -16,6 +16,12 @@
min-height: 460px;
}
/* A live call replaces the composer: the call bar (rendered by the page) sits where the input was,
so the wrapper collapses instead of leaving an empty 72px box under it. */
.ai-chat-input-wrapper.stream-open {
min-height: 0;
}
/* Layers cross-fade */
.composer-layer,
.voice-layer {
@@ -57,14 +63,6 @@
transform: translateY(0) scale(1);
}
:host-context(.has-messages) {
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 10;
}
/* ---------- Chat composer ---------- */
.chat-composer {
/* The composer lays itself out RTL explicitly: Plus on the right edge, Send on the left.
@@ -128,7 +126,6 @@
}
.composer-textarea::-webkit-scrollbar-thumb {
background: var(--muted);
border: none;
border-radius: 9999px;
}
@@ -2,6 +2,7 @@
class="ai-chat-input-wrapper"
[class.voice-active]="anyVoiceActive()"
[class.dictation-active]="isVoiceMode()"
[class.stream-open]="streamOpen()"
[attr.data-voice-state]="voiceState()"
(keydown.escape)="onEscape()"
>
@@ -207,4 +208,4 @@
</div>
}
</div>
</div>
</div>
@@ -1,47 +1,52 @@
/* Host collapses its row to 0 when the call ends, so the composer never jumps when the bar is removed. */
:host {
display: block;
min-height: 0;
height: 100%;
display: grid;
grid-template-rows: 1fr;
opacity: 1;
animation: dockIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
transition:
grid-template-rows 0.35s cubic-bezier(0.22, 1, 0.36, 1),
opacity 0.3s ease,
margin 0.35s ease;
}
.stream-panel {
--footer-h: 3.5rem;
--orb-zone: 7.25rem;
--orb-gap: 0.75rem;
--reserve: calc(var(--footer-h) + var(--orb-gap) + var(--orb-zone) + var(--orb-gap));
:host(.is-ended) {
grid-template-rows: 0fr;
opacity: 0;
margin-bottom: 0 !important;
pointer-events: none;
}
position: relative;
display: flex;
flex-direction: column;
.call-dock {
direction: rtl;
box-sizing: border-box;
min-height: 0;
height: 100%;
direction: rtl;
background: transparent; /* was surface card */
border: none; /* removed card border */
border-radius: 0;
box-shadow: none; /* removed card shadow */
overflow: hidden;
background: var(--surface-bg);
border: 1px solid var(--surface-border);
border-radius: 1.25rem;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.03);
}
/* ---------- Orb layer (behind the transcript) ---------- */
.stream-orb-layer {
position: absolute;
bottom: calc(var(--footer-h) + var(--orb-gap));
left: 50%;
transform: translateX(-50%);
z-index: 1;
:host(.is-ended) .call-dock {
border-color: transparent;
box-shadow: none;
}
.dock-row {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.5rem;
transition: opacity 0.45s ease, transform 0.45s ease;
gap: 0.75rem;
padding: 0.5rem 0.75rem;
}
/* ---------- Orb ---------- */
/* The canvas is larger than the bar is tall (negative margin) so the orb and its glow are not tiny. */
.orb-container {
width: 88px;
height: 88px;
max-width: 100%;
width: 96px;
height: 96px;
margin-block: -20px;
margin-inline: -14px;
flex-shrink: 0;
display: flex;
align-items: center;
@@ -56,11 +61,11 @@
/* Shown only when WebGL is unavailable */
.orb-fallback {
width: 70%;
height: 70%;
width: 55%;
height: 55%;
border-radius: 50%;
background: radial-gradient(circle at 35% 30%, #93c5fd, #3b82f6 55%, #1e3a5f);
box-shadow: 0 0 40px rgba(59, 130, 246, 0.35);
box-shadow: 0 0 24px rgba(59, 130, 246, 0.35);
animation: fallbackPulse 2.4s ease-in-out infinite;
}
@@ -70,12 +75,14 @@
transform: scale(1);
}
50% {
transform: scale(1.06);
transform: scale(1.08);
}
}
/* ---------- Status ---------- */
.stream-status {
.dock-info {
flex: 1;
min-width: 0;
display: flex;
align-items: center;
gap: 0.5rem;
@@ -83,9 +90,12 @@
.status-text {
margin: 0;
font-size: 0.8125rem;
min-width: 0;
font-size: 0.875rem;
color: var(--text-secondary);
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.status-dot {
@@ -97,22 +107,22 @@
transition: background 0.3s ease;
}
.stream-status[data-state='LISTENING'] .status-dot {
.status-dot[data-state='LISTENING'] {
background: #22c55e;
animation: dotPulse 1.6s ease-in-out infinite;
}
.stream-status[data-state='PROCESSING'] .status-dot {
.status-dot[data-state='PROCESSING'] {
background: #818cf8;
animation: dotPulse 0.9s ease-in-out infinite;
}
.stream-status[data-state='SPEAKING'] .status-dot {
.status-dot[data-state='SPEAKING'] {
background: #a78bfa;
animation: dotPulse 0.7s ease-in-out infinite;
}
.stream-status[data-state='INTERRUPTED'] .status-dot {
.status-dot[data-state='INTERRUPTED'] {
background: #f59e0b;
}
@@ -128,56 +138,91 @@
}
}
/* ---------- Transcript (overlaid on top of the orb) ---------- */
.stream-transcript {
position: relative;
z-index: 2;
flex: 1;
min-height: 0;
width: 100%;
max-width: 680px;
margin: 0 auto;
overflow-y: auto;
/* Hide the scrollbar, keep wheel / trackpad / touch scrolling */
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* legacy Edge */
padding: 1rem 0.75rem var(--reserve);
scroll-behavior: smooth;
transition: padding-bottom 0.45s ease;
}
.stream-transcript::-webkit-scrollbar {
display: none; /* Chrome, Safari, Edge */
width: 0;
height: 0;
}
/* ---------- Retryable server error ---------- */
.stream-error {
position: absolute;
bottom: calc(var(--footer-h) + 0.5rem);
left: 50%;
transform: translateX(-50%);
z-index: 3;
/* ---------- Controls ---------- */
.dock-actions {
display: flex;
align-items: center;
gap: 0.5rem;
width: min(100% - 1.5rem, 640px);
box-sizing: border-box;
padding: 0.5rem 0.75rem;
flex-shrink: 0;
}
.dock-btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.375rem;
height: 40px;
min-width: 40px;
padding: 0 0.75rem;
border: 1px solid var(--surface-border);
border-radius: 9999px;
background: var(--surface-bg);
color: var(--text-secondary);
font-family: inherit;
font-size: 0.875rem;
cursor: pointer;
transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
user-select: none;
}
.dock-btn:hover:not(:disabled) {
background: var(--sidebar-hover);
color: var(--text-primary);
transform: scale(1.04);
}
.dock-btn:active:not(:disabled) {
transform: scale(0.96);
}
.dock-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.dock-btn:focus-visible {
outline: 2px solid var(--color-primary);
outline-offset: 2px;
}
.dock-btn.is-active {
background: rgba(239, 68, 68, 0.1);
border-color: rgba(239, 68, 68, 0.5);
color: #dc2626;
}
.dock-btn.is-end {
background: #ef4444;
border-color: #ef4444;
color: #ffffff;
}
.dock-btn.is-end:hover:not(:disabled) {
background: #dc2626;
border-color: #dc2626;
color: #ffffff;
}
/* ---------- Retryable server error (second row inside the bar) ---------- */
.dock-error {
display: flex;
align-items: center;
gap: 0.5rem;
margin: 0 0.75rem 0.5rem;
padding: 0.375rem 0.625rem;
border: 1px solid rgba(239, 68, 68, 0.45);
border-radius: 0.875rem;
border-radius: 0.75rem;
color: #dc2626;
font-size: 0.8125rem;
line-height: 1.6;
}
.stream-error span {
.dock-error span {
flex: 1;
min-width: 0;
}
.stream-error-close {
.dock-error-close {
display: inline-flex;
align-items: center;
justify-content: center;
@@ -191,112 +236,20 @@
flex-shrink: 0;
}
.stream-error-close:focus-visible {
.dock-error-close:focus-visible {
outline: 2px solid var(--color-primary);
outline-offset: 1px;
}
/* ---------- Controls ---------- */
.stream-footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
z-index: 3;
display: flex;
align-items: center;
justify-content: center;
padding-bottom: 0.25rem;
transition: opacity 0.45s ease, transform 0.45s ease;
}
.stream-actions {
display: flex;
align-items: center;
justify-content: center;
gap: 0.625rem;
flex-wrap: wrap;
}
.stream-btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
padding: 0.625rem 1.25rem;
border: 1px solid var(--surface-border);
border-radius: 9999px;
background: var(--surface-bg);
color: var(--text-secondary);
font-family: inherit;
font-size: 0.875rem;
cursor: pointer;
transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
user-select: none;
}
.stream-btn:hover:not(:disabled) {
background: var(--sidebar-hover);
color: var(--text-primary);
transform: scale(1.03);
}
.stream-btn:active:not(:disabled) {
transform: scale(0.97);
}
.stream-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.stream-btn:focus-visible {
outline: 2px solid var(--color-primary);
outline-offset: 2px;
}
.stream-btn.is-active {
background: rgba(239, 68, 68, 0.1);
border-color: rgba(239, 68, 68, 0.5);
color: #dc2626;
}
.stream-btn.is-end {
background: #ef4444;
border-color: #ef4444;
color: #ffffff;
}
.stream-btn.is-end:hover:not(:disabled) {
background: #dc2626;
border-color: #dc2626;
color: #ffffff;
}
/* ---------- Ended: orb + controls fade out, transcript stays ---------- */
/* The orb + footer reserve only exists while the call is live; collapsing it stops the
bottom padding from forcing the panel (and the chat column) taller than the viewport. */
.stream-panel.is-ended {
--reserve: 0rem;
}
.stream-panel.is-ended .stream-orb-layer {
opacity: 0;
transform: translateX(-50%) translateY(14px) scale(0.9);
pointer-events: none;
}
.stream-panel.is-ended .stream-footer {
opacity: 0;
transform: translateY(10px);
pointer-events: none;
}
/* The transcript keeps the full height of the chat column: no max-height, so it never
collapses into a short nested scroll box — scrolling stays on the full-height area. */
.stream-panel.is-ended .stream-transcript {
padding: 1rem 0.75rem;
@keyframes dockIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.sr-only {
@@ -312,31 +265,34 @@
}
@media (prefers-reduced-motion: reduce) {
:host,
.status-dot,
.orb-fallback,
.stream-btn,
.stream-orb-layer,
.stream-footer,
.stream-transcript {
.dock-btn {
animation: none !important;
transition: none !important;
scroll-behavior: auto !important;
}
}
@media (max-width: 640px) {
.stream-panel {
--footer-h: 3.25rem;
--orb-zone: 6rem;
--orb-gap: 0.5rem;
.dock-row {
gap: 0.5rem;
padding: 0.375rem 0.625rem;
}
.orb-container {
width: 68px;
height: 68px;
width: 84px;
height: 84px;
margin-block: -16px;
margin-inline: -12px;
}
.stream-btn {
padding: 0.5rem 1rem;
.dock-btn-label {
display: none;
}
}
.dock-btn.is-end {
padding: 0;
width: 40px;
}
}
@@ -1,55 +1,27 @@
<div
class="stream-panel"
class="call-dock"
role="region"
aria-label="گفتگوی صوتی"
[class.is-ended]="ended()"
[attr.data-state]="state()"
>
<div class="sr-only" role="status" aria-live="polite">{{ statusText() }}</div>
<!-- Orb layer: behind the transcript, anchored just above the controls -->
<div class="stream-orb-layer" aria-hidden="true">
<div class="orb-container" #orbContainer>
<div class="dock-row">
<div class="orb-container" #orbContainer aria-hidden="true">
@if (!orbAvailable()) {
<div class="orb-fallback"></div>
}
</div>
<div class="stream-status" [attr.data-state]="state()">
<span class="status-dot" aria-hidden="true"></span>
<p class="status-text">{{ statusText() }}</p>
<div class="dock-info" aria-hidden="true">
<span class="status-dot" [attr.data-state]="state()"></span>
<p class="status-text" [attr.title]="statusText()">{{ statusText() }}</p>
</div>
</div>
<!-- Transcript: overlaid on top of the orb, keeps streaming while the call runs -->
<div
class="stream-transcript"
#scroller
role="log"
aria-label="متن گفتگو"
aria-live="polite"
aria-relevant="additions"
>
<app-voice-transcript [messages]="messages()" />
</div>
@if (streamError(); as errorText) {
<div class="stream-error" role="alert">
<span>{{ errorText }}</span>
<button type="button" class="stream-error-close" aria-label="بستن پیام" (click)="dismissError()">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<line x1="18" x2="6" y1="6" y2="18" />
<line x1="6" x2="18" y1="6" y2="18" />
</svg>
</button>
</div>
}
<!-- Controls: fade out together with the orb when the call ends -->
<div class="stream-footer">
<div class="stream-actions">
<div class="dock-actions">
<button
type="button"
class="stream-btn"
class="dock-btn"
[class.is-active]="muted()"
[attr.aria-pressed]="muted()"
[attr.aria-label]="muteLabel()"
@@ -73,16 +45,27 @@
<line x1="12" x2="12" y1="19" y2="22" />
</svg>
}
<span>{{ muted() ? 'فعال‌سازی' : 'بی‌صدا' }}</span>
</button>
<button type="button" class="stream-btn is-end" aria-label="پایان گفتگوی صوتی" (click)="endCall()">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<button type="button" class="dock-btn is-end" aria-label="پایان گفتگوی صوتی" (click)="endCall()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<line x1="18" x2="6" y1="6" y2="18" />
<line x1="6" x2="18" y1="6" y2="18" />
</svg>
<span>پایان گفتگو</span>
<span class="dock-btn-label">پایان</span>
</button>
</div>
</div>
</div>
@if (streamError(); as errorText) {
<div class="dock-error" role="alert">
<span>{{ errorText }}</span>
<button type="button" class="dock-error-close" aria-label="بستن پیام" (click)="dismissError()">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<line x1="18" x2="6" y1="6" y2="18" />
<line x1="6" x2="18" y1="6" y2="18" />
</svg>
</button>
</div>
}
</div>
@@ -13,7 +13,6 @@ import {
import { OrbMode, VoiceOrbService } from '../../../services/voice-orb/voice-orb.service';
import { VoiceStreamService } from '../../../services/voice-stream/voice-stream.service';
import { VoiceStreamState } from '../../../services/voice-stream/voice-stream.types';
import { VoiceTranscriptComponent } from '../voice-transcript/voice-transcript.component';
const ORB_MODE: Record<VoiceStreamState, OrbMode> = {
IDLE: 'listening',
@@ -23,12 +22,16 @@ const ORB_MODE: Record<VoiceStreamState, OrbMode> = {
SPEAKING: 'speaking',
};
/** Live call view: orb behind an overlaid running transcript, mute / end controls. */
/**
* Compact call bar that sits right above the chat input while a voice call runs:
* orb + status on one side, mute / end on the other. The transcript is NOT part of it;
* the home page's transcript list renders the messages.
*/
@Component({
selector: 'app-voice-stream-panel',
standalone: true,
imports: [VoiceTranscriptComponent],
changeDetection: ChangeDetectionStrategy.OnPush,
host: { '[class.is-ended]': 'ended()' },
templateUrl: './voice-stream-panel.component.html',
styleUrl: './voice-stream-panel.component.css',
})
@@ -38,15 +41,13 @@ export class VoiceStreamPanelComponent implements AfterViewInit, OnDestroy {
readonly state = this.voice.state;
readonly connection = this.voice.connection;
readonly messages = this.voice.messages;
readonly muted = this.voice.muted;
readonly streamError = this.voice.streamError;
readonly orbAvailable = signal(true);
/** The call is over: the orb and controls fade out, the transcript stays. */
/** The call is over: the bar fades and collapses (the host drops it shortly after). */
readonly ended = computed(() => this.connection() === 'disconnected');
private readonly orbContainer = viewChild.required<ElementRef<HTMLDivElement>>('orbContainer');
private readonly scroller = viewChild<ElementRef<HTMLDivElement>>('scroller');
private orbRunning = false;
readonly statusText = computed(() => {
@@ -73,16 +74,7 @@ export class VoiceStreamPanelComponent implements AfterViewInit, OnDestroy {
constructor() {
effect(() => this.orb.setMode(ORB_MODE[this.state()]));
// Keep the newest message in view as text streams in.
effect(() => {
this.messages();
requestAnimationFrame(() => {
const el = this.scroller()?.nativeElement;
if (el) el.scrollTop = el.scrollHeight;
});
});
// The orb animates only while a call is live; it fades out (and stops) when the call ends.
// The orb animates only while a call is live.
effect(() => {
if (this.ended()) {
this.orb.stopAnimation();
@@ -120,4 +112,4 @@ export class VoiceStreamPanelComponent implements AfterViewInit, OnDestroy {
endCall(): void {
this.voice.end();
}
}
}
@@ -105,6 +105,7 @@
.transcript-empty {
margin: auto;
margin-bottom:10px;
font-size: 0.875rem;
color: var(--muted);
text-align: center;