Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(pet): leave listening as soon as voice stop is pressed (#2880)
Max3f62aaac1fd4
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.jsonindex b8de47681..05696a2e3 100644--- a/ui/src/i18n/en.json+++ b/ui/src/i18n/en.json@@ -5947,6 +5947,7 @@"voice": {"cloudRequired": "Voice input needs Avibe Cloud. You can type a message instead.","listening": "Listening…",+ "finishing": "Finishing…","open": "Voice input","stop": "Stop voice input","startFailed": "Couldn't use the microphone. Check microphone access in system settings, or type instead.",diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.jsonindex 62f440af8..1df23629e 100644--- a/ui/src/i18n/zh.json+++ b/ui/src/i18n/zh.json@@ -5947,6 +5947,7 @@"voice": {"cloudRequired": "语音输入需要 Avibe Cloud,暂时可以打字发送。","listening": "正在听…",+ "finishing": "正在整理…","open": "语音输入","stop": "停止语音输入","startFailed": "无法使用麦克风。请在系统设置里检查麦克风权限,或直接打字。",diff --git a/ui/src/pet/PetPage.test.tsx b/ui/src/pet/PetPage.test.tsxindex eb48090a8..1f786eb49 100644--- a/ui/src/pet/PetPage.test.tsx+++ b/ui/src/pet/PetPage.test.tsx@@ -1662,6 +1662,62 @@ describe('desktop mini v2 interaction contract', () => {}});+ it('leaves listening as soon as stop is pressed, before the transcript arrives', async () => {+ const done = deferred<string>();+ const finish = vi.fn();+ let preview!: (text: string) => void;+ class Dictation {+ done = done.promise;+ constructor(options: { onPreview: (text: string) => void }) { preview = options.onPreview; }+ start = async () => {};+ finish = finish;+ abort = () => {};+ }+ await withVoiceEnv(() => true, Dictation, async () => {+ mainSession('S'); render(<PetPage />); tapHotkey();+ await userEvent.click(await screen.findByLabelText('pet.voice.open'));+ expect(pose()).toBe('listening');+ await act(async () => { preview('live words'); });+ expect(screen.getByText('live words')).toBeTruthy();+ await userEvent.click(screen.getByLabelText('pet.voice.stop'));+ expect(finish).toHaveBeenCalled();+ expect(pose()).not.toBe('listening');+ expect(screen.queryByLabelText('pet.voice.stop')).toBeNull();+ expect(screen.getByLabelText('pet.voice.open').hasAttribute('disabled')).toBe(true);+ expect(screen.getByText('pet.voice.finishing')).toBeTruthy();+ expect(screen.queryByText('live words')).toBeNull();+ expect(screen.queryByRole('textbox')).toBeNull();+ await act(async () => done.resolve('cleaned words'));+ expect(await screen.findByRole('textbox')).toBeTruthy();+ expect((screen.getByRole('textbox') as HTMLTextAreaElement).value).toBe('cleaned words');+ expect(screen.queryByText('pet.voice.finishing')).toBeNull();+ });+ });++ it('cancels an in-flight finish so Escape and an epoch change do not stick on Finishing', async () => {+ const done = deferred<string>();+ const abort = vi.fn();+ class Dictation {+ done = done.promise;+ start = async () => {};+ finish = () => {};+ abort = abort;+ }+ await withVoiceEnv(() => true, Dictation, async () => {+ mainSession('S'); render(<PetPage />); tapHotkey();+ await userEvent.click(await screen.findByLabelText('pet.voice.open'));+ expect(pose()).toBe('listening');+ await userEvent.click(screen.getByLabelText('pet.voice.stop'));+ expect(screen.getByText('pet.voice.finishing')).toBeTruthy();+ await userEvent.keyboard('{Escape}');+ expect(abort).toHaveBeenCalled();+ expect(screen.queryByText('pet.voice.finishing')).toBeNull();+ expect(await screen.findByRole('textbox')).toBeTruthy();+ await act(async () => done.resolve('late cleaned words'));+ expect((screen.getByRole('textbox') as HTMLTextAreaElement).value).toBe('');+ });+ });+it('does not let a queued old animation report replace the new epochs hit regions', async () => {const frames: FrameRequestCallback[] = [];vi.stubGlobal('requestAnimationFrame', vi.fn((callback: FrameRequestCallback) => frames.push(callback)));diff --git a/ui/src/pet/PetPage.tsx b/ui/src/pet/PetPage.tsxindex a10a91b79..a128b20a4 100644--- a/ui/src/pet/PetPage.tsx+++ b/ui/src/pet/PetPage.tsx@@ -277,7 +277,7 @@ const PetSurface: React.FC = () => {if (cardsListed) { void setPanel(false); return; }if (historyOpen) { setDetailOpen(false); void setPanel(false); return; }// Typing and dictation keep the speech slot, and the draft, as they are.- if (composing || voice.listening) return;+ if (composing || voice.busy) return;if (!binding || resolvingMain || (data.messages.length === 0 && !optimisticTitle)) return;openHistory();};@@ -573,7 +573,7 @@ const PetSurface: React.FC = () => {if (intent === 'release') {hotkeyHeld.current = false;voice.stop(true);- if (!voice.listening && !composing) {+ if (!voice.busy && !composing) {void setPanel(true);petComposer.requestListen();}@@ -585,7 +585,7 @@ const PetSurface: React.FC = () => {hotkeyHeld.current = true;petComposer.requestListen();}- }, [setPanel, openCards, voice.stop, voice.listening, composing]);+ }, [setPanel, openCards, voice.stop, voice.busy, composing]);useOnSummon(onSummon);useEffect(() => {if (!listenPending || !binding || !canChat || !expanded) return;@@ -595,15 +595,15 @@ const PetSurface: React.FC = () => {else openComposer(draft);}, [listenPending, binding, canChat, expanded, voice.available, voice.start, openComposer, draft, uncertain]);useEffect(() => {- const onBlur = () => { if (!voice.listening && !draft.trim()) void setPanel(false); };+ const onBlur = () => { if (!voice.busy && !draft.trim()) void setPanel(false); };window.addEventListener('blur', onBlur);return () => window.removeEventListener('blur', onBlur);- }, [voice.listening, draft, setPanel]);+ }, [voice.busy, draft, setPanel]);useEffect(() => {const onKey = (event: KeyboardEvent) => {// Escape also dismisses an IME candidate list; that one is not ours.if (event.key !== 'Escape' || isComposingKey(event)) return;- if (voice.listening) voice.cancel();+ if (voice.busy) voice.cancel();else if (composing) closeComposer();else if (detailOpen) { setDetailOpen(false); void setPanel(false); }else void setPanel(false);@@ -701,7 +701,7 @@ const PetSurface: React.FC = () => {// The bubble is drawn: the speech slot shows it rather than the input or the// dictation marquee. Every input to the linger (time, pointer) means// something only while this holds.- const bubbleDrawn = hasBubbleContent && Boolean(binding) && !voice.listening && !(composing && canChat && !uncertain);+ const bubbleDrawn = hasBubbleContent && Boolean(binding) && !voice.busy && !(composing && canChat && !uncertain);// The reply is on screen: the bubble is drawn and its summary row is the// reply (not "thinking" while the turn still runs, nor a failure notice).// Only then does the linger spend its time.@@ -818,9 +818,10 @@ const PetSurface: React.FC = () => {<MiniDockenabled={canChat && Boolean(binding)}listening={voice.listening}+ finishing={voice.finishing}typing={composing}// Availability gates starting a capture; an active one always keeps its stop control.- showMic={voice.available || voice.listening}+ showMic={voice.available || voice.busy}onMic={() => (voice.listening ? voice.stop(true) : voice.start())}onKeyboard={() => {if (uncertain) { void setPanel(true); setDetailOpen(true); return; }@@ -834,8 +835,8 @@ const PetSurface: React.FC = () => {return (<div ref={rootRef} className="pet-mini-stage" data-pet-root data-busy={busy} data-state={state}>- <div className={clsx('pet-mini-column', voice.listening && 'is-voice-active')} style={{ '--pet-collapsed-height': `${collapsedHeight}px` } as CSSProperties}>- <div className={clsx('pet-mini-cards', voice.listening && 'is-hidden')} inert={voice.listening || undefined} aria-label={cardsExpanded ? t('pet.panel') : undefined} style={{ height: cardsListed ? (visibleCards.length > 0 ? STACK_HEIGHT : 'auto') : collapsedHeight }}>+ <div className={clsx('pet-mini-column', voice.busy && 'is-voice-active')} style={{ '--pet-collapsed-height': `${collapsedHeight}px` } as CSSProperties}>+ <div className={clsx('pet-mini-cards', voice.busy && 'is-hidden')} inert={voice.busy || undefined} aria-label={cardsExpanded ? t('pet.panel') : undefined} style={{ height: cardsListed ? (visibleCards.length > 0 ? STACK_HEIGHT : 'auto') : collapsedHeight }}><div ref={collapsedRef} key={singleCard ? 'single' : cardsExpanded ? 'expanded' : 'collapsed'} className="pet-mini-swap is-switching" onAnimationEnd={(event) => { if (event.target === event.currentTarget) event.currentTarget.classList.remove('is-switching'); }}>{visibleCards.length > 0 && (cardsFull ? (@@ -855,8 +856,8 @@ const PetSurface: React.FC = () => {)}</div></div>- <SpeechSlot open={voice.listening || composing || showReplyBubble || resolvingMain || !binding}>- {voice.listening ? <Marquee text={voice.preview} listeningLabel={t('pet.voice.listening')} /> : composing && canChat && !uncertain ? (+ <SpeechSlot open={voice.busy || composing || showReplyBubble || resolvingMain || !binding}>+ {voice.busy ? <Marquee text={voice.finishing ? '' : voice.preview} listeningLabel={t(voice.finishing ? 'pet.voice.finishing' : 'pet.voice.listening')} /> : composing && canChat && !uncertain ? (<>{voice.error && <p className="pet-mini-input-note" role="status">{t(`pet.voice.${voice.error}`)}</p>}<form className="pet-mini-input" data-pet-hit onSubmit={(event) => { event.preventDefault(); void submit(); }}>@@ -1017,6 +1018,8 @@ function usePetVoice({ enabled, epoch, draft, onOpenComposer }: { enabled: booleconst [asr, setAsr] = useState<{ epoch: PetSurfaceEpoch; enabled: boolean; available: boolean; checked: boolean; maxFileBytes?: number }>({ epoch, enabled, available: false, checked: false });const [preview, setPreview] = useState('');const [listening, setListening] = useState(false);+ // Stop has been requested; capture and cleanup still run until `done`.+ const [finishing, setFinishing] = useState(false);// A failed capture or transcription falls back to text with this note.const [error, setError] = useState<VoiceFailure | null>(null);type Capture = { dictation: ShowPageVoiceDictation; ending: boolean; cancelled: boolean };@@ -1041,15 +1044,24 @@ function usePetVoice({ enabled, epoch, draft, onOpenComposer }: { enabled: booleconst stop = useCallback((commit: boolean) => {const capture = captureRef.current;if (!capture) return;- capture.ending = true;- if (commit) capture.dictation.finish();- else {- capture.cancelled = true;- captureRef.current = null;- capture.dictation.abort();+ // A second commit is a no-op. Cancel must still abort an in-flight finish+ // (Escape, epoch change) so finishing cannot stick on the next surface.+ if (commit) {+ if (capture.ending) return;+ capture.ending = true;setListening(false);- setPreview('');+ setFinishing(true);+ capture.dictation.finish();+ return;}+ if (capture.cancelled) return;+ capture.ending = true;+ capture.cancelled = true;+ captureRef.current = null;+ capture.dictation.abort();+ setListening(false);+ setFinishing(false);+ setPreview('');}, []);const start = useCallback(() => {if (!epoch.isCurrent() || !available || captureRef.current) return;@@ -1061,11 +1073,13 @@ function usePetVoice({ enabled, epoch, draft, onOpenComposer }: { enabled: boole};captureRef.current = capture;setListening(true);+ setFinishing(false);setError(null);const settle = () => {if (captureRef.current !== capture || !epoch.isCurrent()) return false;captureRef.current = null;setListening(false);+ setFinishing(false);setPreview('');return !capture.cancelled;};@@ -1091,7 +1105,19 @@ function usePetVoice({ enabled, epoch, draft, onOpenComposer }: { enabled: booleconst clearError = useCallback(() => setError(null), []);useEffect(() => cancel, [epoch, enabled, cancel]);useEffect(() => () => setError(null), [epoch, enabled]);- return { available, cloudRequired: asrForEpoch.checked && !asrForEpoch.available, listening, preview, error, clearError, start, stop, cancel };+ return {+ available,+ cloudRequired: asrForEpoch.checked && !asrForEpoch.available,+ listening,+ finishing,+ busy: listening || finishing,+ preview,+ error,+ clearError,+ start,+ stop,+ cancel,+ };}type VoiceFailure = 'startFailed' | 'empty' | 'failed';@@ -1129,9 +1155,9 @@ const Marquee: React.FC<{ text: string; listeningLabel: string }> = ({ text, lis);};-const MiniDock: React.FC<{ enabled: boolean; listening: boolean; typing: boolean; showMic: boolean; onMic: () => void; onKeyboard: () => void; t: (key: string) => string }> = ({ enabled, listening, typing, showMic, onMic, onKeyboard, t }) => (- <div className={clsx('pet-mini-dock', (listening || typing) && 'is-active')} data-pet-hit>- {showMic && <button type="button" className={clsx(listening && 'is-listening')} onClick={onMic} aria-pressed={listening} aria-label={listening ? t('pet.voice.stop') : t('pet.voice.open')}>{listening ? <StopIcon /> : <MicIcon />}</button>}+const MiniDock: React.FC<{ enabled: boolean; listening: boolean; finishing?: boolean; typing: boolean; showMic: boolean; onMic: () => void; onKeyboard: () => void; t: (key: string) => string }> = ({ enabled, listening, finishing, typing, showMic, onMic, onKeyboard, t }) => (+ <div className={clsx('pet-mini-dock', (listening || finishing || typing) && 'is-active')} data-pet-hit>+ {showMic && <button type="button" className={clsx(listening && 'is-listening')} disabled={finishing} onClick={onMic} aria-pressed={listening} aria-label={listening ? t('pet.voice.stop') : t('pet.voice.open')}>{listening ? <StopIcon /> : <MicIcon />}</button>}{showMic && <span className="pet-mini-dock-divider" aria-hidden />}<button type="button" className={clsx(typing && 'is-typing')} disabled={!enabled} onClick={onKeyboard} aria-pressed={typing} aria-label={typing ? t('pet.keyboard.close') : t('pet.keyboard.open')}><KeyboardIcon /></button></div>