Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: keep Voice Studio auditions and design ahead of the library on phones (#11055)
Adam Eivyf9577a37fad5
diff --git a/client/src/pages/VoiceStudio.jsx b/client/src/pages/VoiceStudio.jsxindex 4542bca9fb..0194190247 100644--- a/client/src/pages/VoiceStudio.jsx+++ b/client/src/pages/VoiceStudio.jsx@@ -2,6 +2,8 @@ import { useCallback, useState } from 'react';import { Link, useNavigate, useParams, useSearchParams } from 'react-router';import { AudioLines, Plus, Loader2, ArrowLeft, Check } from 'lucide-react';import PageHeader from '../components/PageHeader';+import Drawer from '../components/Drawer';+import useContainerWidth from '../hooks/useContainerWidth';import { usePagedCollection } from '../hooks/usePagedCollection';import InfiniteScrollFooter from '../components/ui/InfiniteScrollFooter';import { useSocketResource } from '../hooks/useSocketResource';@@ -89,6 +91,9 @@ function VoiceAssignment({ profile, universeId, character, onAssigned }) {export default function VoiceStudio() {const { profileId } = useParams();const navigate = useNavigate();+ const [containerRef, containerWidth] = useContainerWidth();+ const [libraryOpen, setLibraryOpen] = useState(false);+ const compactLibrary = Boolean(profileId) && containerWidth < 760;const [params, setParams] = useSearchParams();const universeId = params.get('universeId') || '';const characterId = params.get('characterId') || '';@@ -127,6 +132,23 @@ export default function VoiceStudio() {if (key === 'universeId') next.delete('characterId');setParams(next);};+ const libraryPane = (+ <section aria-label="Voice library" className="min-w-0 rounded border border-port-border p-3 space-y-2 @[760px]:col-start-1 @[760px]:row-start-1">+ {library.loading && <p role="status">Loading voice library…</p>}+ <h2 className="font-semibold">Library <span className="text-gray-500">({formatCount(library.total ?? profiles.length)})</span></h2>+ {!library.loading && !library.error && !profiles.length && <p className="text-sm text-gray-400">No voices yet. Create a voice, listen to the preview, then assign it to a character.</p>}+ {profiles.map(profile => <Link key={profile.id} to={`/voices/${encodeURIComponent(profile.id)}${context}`} onClick={() => {+ setLibraryOpen(false);+ containerRef.current?.scrollTo({ top: 0 });+ }}+ aria-current={profile.id === profileId ? 'page' : undefined}+ className={`block rounded border p-3 break-words ${profile.id === profileId ? 'border-port-accent bg-port-accent/10' : 'border-port-border hover:border-port-accent/50'}`}>+ <span className="block text-sm font-medium">{profile.label || profile.voiceId}</span>+ <span className="text-xs text-gray-500">{profile.engine} · {profile.library ? 'Library voice' : 'Character snapshot'}</span>+ </Link>)}+ <InfiniteScrollFooter hasMore={library.hasMore} loading={library.loading} error={library.error} onLoadMore={library.loadMore} autoLoad={false} label="Load more voices" />+ </section>+ );return (<div className="flex h-full min-h-0 flex-col"><PageHeader@@ -135,10 +157,32 @@ export default function VoiceStudio() {subtitle="Create voices once, audition them, and cast characters across your universes and stories."actions={<Link to={`/voices/new?${newVoiceParams}`} className={buttonClass}><Plus size={16} /> Create voice</Link>}/>- <div className="@container min-w-0 flex-1 min-h-0 overflow-auto p-4">- <div className="space-y-4">+ <div ref={containerRef} className="@container min-w-0 flex-1 min-h-0 overflow-auto p-4">+ <div className="flex flex-col gap-4">{engine.error && <p role="alert" className="text-port-error">{engine.error.message} <button onClick={engine.refetch} className="underline">Retry</button></p>}- {library.loading && <p role="status">Loading voice library…</p>}+ <div className="order-first grid grid-cols-1 @[760px]:order-last @[760px]:grid-cols-[minmax(15rem,1fr)_minmax(0,2fr)] gap-4">+ {!profileId && libraryPane}+ <section aria-label="Voice workspace" className="min-w-0 rounded border border-port-border p-4 @[760px]:col-start-2 @[760px]:row-start-1">+ {compactLibrary && <button type="button" className={`${buttonClass} mb-3`} aria-haspopup="dialog" aria-expanded={libraryOpen} onClick={() => setLibraryOpen(true)}>Choose voice</button>}+ {detailId && detail.error ? <p role="alert">Voice not found or unavailable. Select another voice from the library.</p> : detailId && detail.loading ? <p>Loading voice…</p> : profileId === 'new' ? ((universeId && universe.loading) || (detailId && detail.loading) ? <p>Loading voice direction…</p> :+ <VoiceDesignForm key={`${universeId}:${characterId}:${variation?.id || ""}`} character={character} source={variation} ready={status?.ready && !status.busy && status.state !== 'running'} onCreated={profile => {+ putProfile(profile); navigate(`/voices/${profile.id}${context}`);+ }} />) : selected ? <div className="space-y-4">+ <h2 className="text-lg font-semibold break-words">{selected.label || selected.voiceId}</h2>+ {selected.sourceAssets?.[0] && <div className="space-y-2">+ <audio controls preload="none" aria-label="Voice preview" className="w-full" src={audioUrl(`voice-profiles/${selected.id}/source/${selected.sourceAssets[0].filename}`)}><track kind="captions" /></audio>+ <p className="text-sm break-words">{selected.sourceAssets[0].transcript}</p>+ </div>}+ {!selected.sourceAssets?.length && <p className="text-sm text-gray-400">This legacy profile has no saved reference preview.</p>}+ <p className="text-sm text-gray-400 whitespace-pre-wrap break-words">{selected.inference?.instructions || 'Preset voice'}</p>+ <p className="text-xs text-gray-500">Seed {selected.inference?.seed} · Pitch {selected.inference?.pitchSemitones || 0} semitones · Preview pace {selected.inference?.rate || 1}×</p>+ <Link className="inline-flex text-sm text-port-accent" to={`/voices/new?${new URLSearchParams({ ...Object.fromEntries(params), from: selected.id })}`}>Adjust this voice as a new candidate</Link>+ <VoiceAssignment key={`${selected.id}:${universeId}:${characterId}`} profile={selected} universeId={universeId} character={character} onAssigned={putProfile} />+ </div> : profileId && !library.loading && !library.error ? <p role="alert">Voice not found. Select another voice from the library.</p> :+ <p className="text-sm text-gray-400">Select a voice to listen and assign, or create a new character voice.</p>}+ </section>+ {profileId && !compactLibrary && libraryPane}+ </div>{status && <section aria-label="Voice engine" className="rounded border border-port-border p-3 flex flex-wrap items-center gap-3"><div className="flex-1 min-w-0 text-sm"><strong>AuK-Flash</strong> · {status.state === 'running' ? status.stage : status.busy ? 'Rendering voice…' : status.ready ? 'Ready on this Mac' : 'Setup required'}@@ -164,39 +208,11 @@ export default function VoiceStudio() {{universeId && !universe.loading && characterId && !character && <p role="alert">This character is no longer available. Choose another character.</p>}{universeId && <Link className="inline-flex items-center gap-1 text-sm text-port-accent" to={`/universes/${encodeURIComponent(universeId)}?tab=cast`}><ArrowLeft size={14} /> Back to universe cast</Link>}</section>- <div className="grid grid-cols-1 @[760px]:grid-cols-[minmax(15rem,1fr)_minmax(0,2fr)] gap-4">- <section aria-label="Voice library" className="min-w-0 rounded border border-port-border p-3 space-y-2">- <h2 className="font-semibold">Library <span className="text-gray-500">({formatCount(library.total ?? profiles.length)})</span></h2>- {!library.loading && !library.error && !profiles.length && <p className="text-sm text-gray-400">No voices yet. Create a voice, listen to the preview, then assign it to a character.</p>}- {profiles.map(profile => <Link key={profile.id} to={`/voices/${encodeURIComponent(profile.id)}${context}`}- aria-current={profile.id === profileId ? 'page' : undefined}- className={`block rounded border p-3 break-words ${profile.id === profileId ? 'border-port-accent bg-port-accent/10' : 'border-port-border hover:border-port-accent/50'}`}>- <span className="block text-sm font-medium">{profile.label || profile.voiceId}</span>- <span className="text-xs text-gray-500">{profile.engine} · {profile.library ? 'Library voice' : 'Character snapshot'}</span>- </Link>)}- <InfiniteScrollFooter hasMore={library.hasMore} loading={library.loading} error={library.error} onLoadMore={library.loadMore} autoLoad={false} label="Load more voices" />- </section>- <section className="min-w-0 rounded border border-port-border p-4">- {detailId && detail.error ? <p role="alert">Voice not found or unavailable. Select another voice from the library.</p> : detailId && detail.loading ? <p>Loading voice…</p> : profileId === 'new' ? ((universeId && universe.loading) || (detailId && detail.loading) ? <p>Loading voice direction…</p> :- <VoiceDesignForm key={`${universeId}:${characterId}:${variation?.id || ""}`} character={character} source={variation} ready={status?.ready && !status.busy && status.state !== 'running'} onCreated={profile => {- putProfile(profile); navigate(`/voices/${profile.id}${context}`);- }} />) : selected ? <div className="space-y-4">- <h2 className="text-lg font-semibold break-words">{selected.label || selected.voiceId}</h2>- <p className="text-sm text-gray-400 whitespace-pre-wrap break-words">{selected.inference?.instructions || 'Preset voice'}</p>- {selected.sourceAssets?.[0] && <div className="space-y-2">- <p className="text-sm">{selected.sourceAssets[0].transcript}</p>- <audio controls preload="none" aria-label="Voice preview" className="w-full" src={audioUrl(`voice-profiles/${selected.id}/source/${selected.sourceAssets[0].filename}`)}><track kind="captions" /></audio>- </div>}- {!selected.sourceAssets?.length && <p className="text-sm text-gray-400">This legacy profile has no saved reference preview.</p>}- <p className="text-xs text-gray-500">Seed {selected.inference?.seed} · Pitch {selected.inference?.pitchSemitones || 0} semitones · Preview pace {selected.inference?.rate || 1}×</p>- <Link className="inline-flex text-sm text-port-accent" to={`/voices/new?${new URLSearchParams({ ...Object.fromEntries(params), from: selected.id })}`}>Adjust this voice as a new candidate</Link>- <VoiceAssignment key={`${selected.id}:${universeId}:${characterId}`} profile={selected} universeId={universeId} character={character} onAssigned={putProfile} />- </div> : profileId && !library.loading && !library.error ? <p role="alert">Voice not found. Select another voice from the library.</p> :- <p className="text-sm text-gray-400">Select a voice to listen and assign, or create a new character voice.</p>}- </section>- </div></div></div>+ <Drawer open={compactLibrary && libraryOpen} onClose={() => setLibraryOpen(false)} title="Choose voice" closeLabel="Close voice library">+ {libraryPane}+ </Drawer></div>);}diff --git a/client/src/pages/VoiceStudio.test.jsx b/client/src/pages/VoiceStudio.test.jsxindex 7d7d56ff87..55bc982532 100644--- a/client/src/pages/VoiceStudio.test.jsx+++ b/client/src/pages/VoiceStudio.test.jsx@@ -1,7 +1,9 @@import { beforeEach, describe, expect, it, vi } from 'vitest';-import { render, screen, fireEvent, waitFor } from '@testing-library/react';-import { MemoryRouter, Routes, Route } from 'react-router';+import { render, screen, fireEvent, waitFor, within } from '@testing-library/react';+import { MemoryRouter, Routes, Route, useNavigate, useLocation } from 'react-router';import VoiceStudio from './VoiceStudio';+import useContainerWidth from '../hooks/useContainerWidth';+vi.mock('../hooks/useContainerWidth', () => ({ default: vi.fn(() => [{ current: null }, 390]) }));import * as api from '../services/apiVoice';import { getUniverse } from '../services/apiUniverseBuilder';vi.mock('../services/socket', () => ({ default: { on: vi.fn(), off: vi.fn(), emit: vi.fn() } }));@@ -13,11 +15,18 @@ vi.mock('../services/apiUniverseBuilder', () => ({ listUniverseNames: vi.fn().movi.mock('../components/ui/Toast', () => ({ default: { error: vi.fn() } }));const profile = { id: 'voice-1', label: 'Example voice', library: true, engine: 'auk', approval: { status: 'approved' },sourceAssets: [{ filename: 'reference.wav', transcript: 'Hello there.' }], inference: { seed: 42, instructions: 'Warm alto' } };-const open = path => render(<MemoryRouter initialEntries={[path]}><Routes>+function HistoryControls() {+ const navigate = useNavigate();+ const location = useLocation();+ return <><output aria-label="Current URL">{location.pathname}{location.search}</output>+ <button onClick={() => navigate(-1)}>Back</button><button onClick={() => navigate(1)}>Forward</button></>;+}+const open = path => render(<MemoryRouter initialEntries={[path]}><HistoryControls /><Routes><Route path="/voices" element={<VoiceStudio />} /><Route path="/voices/:profileId" element={<VoiceStudio />} /></Routes></MemoryRouter>);beforeEach(() => {vi.clearAllMocks();+ useContainerWidth.mockReturnValue([{ current: null }, 390]);api.listStudioVoices.mockResolvedValue({ items: [profile], total: 1, nextCursor: null });api.getStudioVoice.mockResolvedValue({ profile });api.getVoiceStudioStatus.mockResolvedValue({ supported: true, ready: true, state: 'idle' });@@ -60,4 +69,64 @@ describe('Voice Studio', () => {expect(await screen.findByRole('alert')).toHaveTextContent('Voice not found');expect(screen.queryByLabelText('Voice preview')).not.toBeInTheDocument();});+ it('chooses a voice from compact navigation, retaining pagination, URL context and history without side effects', async () => {+ const voices = Array.from({ length: 30 }, (_, i) => ({ ...profile, id: `voice-${i}`, label: `Long voice name ${i} with detailed character direction` }));+ api.listStudioVoices.mockResolvedValueOnce({ items: voices, total: 31, nextCursor: 'next-page' })+ .mockResolvedValue({ items: [{ ...profile, id: 'voice-last', label: 'Last voice' }], total: 31, nextCursor: null });+ api.getStudioVoice.mockImplementation(async id => ({ profile: { ...profile, id } }));+ open('/voices/new?universeId=u1&characterId=c1');+ expect(await screen.findByLabelText('Voice name')).toHaveValue('Example Character voice');+ expect(screen.queryByRole('region', { name: 'Voice library' })).not.toBeInTheDocument();+ fireEvent.click(screen.getByRole('button', { name: 'Choose voice' }));+ const drawer = screen.getByRole('dialog', { name: 'Choose voice' });+ expect(await within(drawer).findAllByRole('link')).toHaveLength(30);+ fireEvent.click(within(drawer).getByRole('button', { name: 'Load more voices' }));+ const lastVoice = await within(drawer).findByRole('link', { name: /Last voice/ });+ expect(api.listStudioVoices).toHaveBeenLastCalledWith({ cursor: 'next-page', limit: 30 }, expect.objectContaining({ silent: true }));+ fireEvent.click(lastVoice);+ expect(await screen.findByLabelText('Voice preview')).toHaveAttribute('src', '/data/voice-profiles/voice-last/source/reference.wav');+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();+ expect(screen.getByLabelText('Current URL')).toHaveTextContent('/voices/voice-last?universeId=u1&characterId=c1');+ expect(screen.getByRole('button', { name: 'Use for Example Character' })).toBeEnabled();+ fireEvent.click(screen.getByRole('button', { name: 'Back' }));+ expect(await screen.findByLabelText('Voice name')).toHaveValue('Example Character voice');+ fireEvent.click(screen.getByRole('button', { name: 'Forward' }));+ expect(await screen.findByLabelText('Voice preview')).toBeInTheDocument();+ fireEvent.click(screen.getByRole('button', { name: 'Choose voice' }));+ expect(within(screen.getByRole('dialog')).getAllByRole('link')).toHaveLength(31);+ fireEvent.click(screen.getByRole('button', { name: 'Close voice library' }));+ expect(screen.getByRole('button', { name: 'Choose voice' })).toHaveAttribute('aria-expanded', 'false');+ expect(api.setupVoiceStudio).not.toHaveBeenCalled();+ expect(api.designStudioVoice).not.toHaveBeenCalled();+ expect(api.assignStudioVoice).not.toHaveBeenCalled();+ });+ it('keeps the library alongside the work in wide containers and switches without losing form edits', async () => {+ useContainerWidth.mockReturnValue([{ current: null }, 1000]);+ const view = open('/voices/new');+ const name = await screen.findByLabelText('Voice name');+ fireEvent.change(name, { target: { value: 'Unsaved direction' } });+ expect(await screen.findByRole('region', { name: 'Voice library' })).toBeInTheDocument();+ expect(screen.queryByRole('button', { name: 'Choose voice' })).not.toBeInTheDocument();+ useContainerWidth.mockReturnValue([{ current: null }, 320]);+ view.rerender(<MemoryRouter initialEntries={['/voices/new']}><HistoryControls /><Routes>+ <Route path="/voices/:profileId" element={<VoiceStudio />} />+ </Routes></MemoryRouter>);+ expect(screen.getByLabelText('Voice name')).toHaveValue('Unsaved direction');+ expect(screen.queryByRole('region', { name: 'Voice library' })).not.toBeInTheDocument();+ fireEvent.click(screen.getByRole('button', { name: 'Choose voice' }));+ expect(screen.getByRole('dialog', { name: 'Choose voice' })).toBeInTheDocument();+ });+ it.each(['loading', 'empty', 'error'])('keeps an audition accessible with a %s library', async state => {+ if (state === 'loading') api.listStudioVoices.mockReturnValue(new Promise(() => {}));+ if (state === 'empty') api.listStudioVoices.mockResolvedValue({ items: [], total: 0, nextCursor: null });+ if (state === 'error') api.listStudioVoices.mockRejectedValue(new Error('Library unavailable'));+ open('/voices/voice-1');+ expect(await screen.findByLabelText('Voice preview')).toBeInTheDocument();+ fireEvent.click(screen.getByRole('button', { name: 'Choose voice' }));+ const drawer = within(screen.getByRole('dialog'));+ if (state === 'loading') expect(drawer.getByText('Loading voice library…')).toBeInTheDocument();+ if (state === 'empty') expect(drawer.getByText(/No voices yet/)).toBeInTheDocument();+ if (state === 'error') expect(await drawer.findByRole('button', { name: 'Retry loading' })).toBeEnabled();+ });+});