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:
@@ -65,6 +65,8 @@ describe('VoiceStreamService (backend handoff contract)', () => {
|
||||
let controls: PlaybackProgressMessage[];
|
||||
let transportMock: TransportMock;
|
||||
let engineStop: ReturnType<typeof vi.fn>;
|
||||
let engineFlush: Mock;
|
||||
let engineClear: Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
sessionStorage.clear();
|
||||
@@ -72,6 +74,8 @@ describe('VoiceStreamService (backend handoff contract)', () => {
|
||||
transportHandlers = null;
|
||||
controls = [];
|
||||
engineStop = vi.fn();
|
||||
engineFlush = vi.fn();
|
||||
engineClear = vi.fn();
|
||||
|
||||
api = {
|
||||
me: vi.fn().mockResolvedValue(ME),
|
||||
@@ -113,8 +117,8 @@ describe('VoiceStreamService (backend handoff contract)', () => {
|
||||
stop: engineStop,
|
||||
setMuted: vi.fn(),
|
||||
enqueuePlayback: vi.fn(),
|
||||
clearPlayback: vi.fn(),
|
||||
flushPlayback: vi.fn(),
|
||||
clearPlayback: engineClear,
|
||||
flushPlayback: engineFlush,
|
||||
inputLevel: () => 0,
|
||||
outputLevel: () => 0,
|
||||
},
|
||||
@@ -310,6 +314,38 @@ describe('VoiceStreamService (backend handoff contract)', () => {
|
||||
expect(api.closeVoiceSession).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('drains on audio_ended so the ref reaches its true final progress (not solely on transcript)', async () => {
|
||||
await startConnected();
|
||||
transportHandlers?.onEvent({ type: 'audio_started', audio_ref: 'aud-1' });
|
||||
|
||||
// A `completed` transcript that arrives BEFORE audio_ended must NOT flush the queue: the
|
||||
// audio is still streaming, so finalizing the tail now would be premature.
|
||||
transportHandlers?.onEvent({
|
||||
type: 'transcript',
|
||||
turn_ref: 'turn-1',
|
||||
role: 'assistant',
|
||||
text: '…',
|
||||
status: 'completed',
|
||||
});
|
||||
expect(engineFlush).not.toHaveBeenCalled();
|
||||
|
||||
// audio_ended (generation complete) drives the drain: the worklet emits the deferred
|
||||
// tail and plays out, so playback progress retires the whole ref before the backend's
|
||||
// stall timeout — this is the fix for the premature LIVE_BUFFER_OVERFLOW termination.
|
||||
transportHandlers?.onEvent({ type: 'audio_ended', audio_ref: 'aud-1' });
|
||||
expect(engineFlush).toHaveBeenCalledTimes(1);
|
||||
|
||||
// Once generation is done, a late/second completed transcript re-flushes idempotently.
|
||||
transportHandlers?.onEvent({
|
||||
type: 'transcript',
|
||||
turn_ref: 'turn-1',
|
||||
role: 'assistant',
|
||||
text: '…',
|
||||
status: 'completed',
|
||||
});
|
||||
expect(engineFlush).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('requires a fresh conversation after CONTEXT_REVOKED and drops the old attempt', async () => {
|
||||
await startConnected();
|
||||
const ended = firstEndedError();
|
||||
@@ -371,6 +407,51 @@ describe('VoiceStreamService (backend handoff contract)', () => {
|
||||
expect(assistant?.final).toBe(true);
|
||||
});
|
||||
|
||||
it('orders a user request above its AI response even when the assistant transcript arrives first', async () => {
|
||||
await startConnected();
|
||||
|
||||
// The server streams assistant partials before the user transcript for the same turn.
|
||||
transportHandlers?.onEvent({ type: 'transcript', turn_ref: 'turn-1', role: 'assistant', text: 'پاسخ فارسی', status: 'partial' });
|
||||
transportHandlers?.onEvent({ type: 'transcript', turn_ref: 'turn-1', role: 'user', text: 'سلام', status: 'completed' });
|
||||
|
||||
const list = service.messages();
|
||||
const userIndex = list.findIndex((m) => m.id === 'turn-1:user');
|
||||
const assistantIndex = list.findIndex((m) => m.id === 'turn-1:assistant');
|
||||
expect(userIndex).toBeGreaterThanOrEqual(0);
|
||||
expect(assistantIndex).toBeGreaterThan(userIndex);
|
||||
});
|
||||
|
||||
it('keeps user→assistant order and stable turn order across turns', async () => {
|
||||
await startConnected();
|
||||
|
||||
transportHandlers?.onEvent({ type: 'transcript', turn_ref: 't1', role: 'user', text: 'سوال ۱', status: 'completed' });
|
||||
transportHandlers?.onEvent({ type: 'transcript', turn_ref: 't1', role: 'assistant', text: 'پاسخ ۱', status: 'completed' });
|
||||
// turn 2's assistant lands before its user transcript
|
||||
transportHandlers?.onEvent({ type: 'transcript', turn_ref: 't2', role: 'assistant', text: 'پاسخ ۲', status: 'partial' });
|
||||
transportHandlers?.onEvent({ type: 'transcript', turn_ref: 't2', role: 'user', text: 'سوال ۲', status: 'completed' });
|
||||
|
||||
expect(service.messages().map((m) => m.id)).toEqual([
|
||||
't1:user',
|
||||
't1:assistant',
|
||||
't2:user',
|
||||
't2:assistant',
|
||||
]);
|
||||
});
|
||||
|
||||
it('keeps the user request above a sources-only assistant bubble of the same turn', async () => {
|
||||
await startConnected();
|
||||
|
||||
// A `sources` frame can create the assistant bubble before the user transcript arrives.
|
||||
transportHandlers?.onEvent({
|
||||
type: 'sources',
|
||||
turn_ref: 't1',
|
||||
sources: [{ source_ref: 's1', document_id: 'd1', chunk_id: 'c1', title: 'سند', excerpt: 'بند' }],
|
||||
});
|
||||
transportHandlers?.onEvent({ type: 'transcript', turn_ref: 't1', role: 'user', text: 'سلام', status: 'completed' });
|
||||
|
||||
expect(service.messages().map((m) => m.id)).toEqual(['t1:user', 't1:assistant']);
|
||||
});
|
||||
|
||||
it('closes the reservation (V04) when the call ends on user request', async () => {
|
||||
await startConnected();
|
||||
await service.close();
|
||||
|
||||
Reference in New Issue
Block a user