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
extract withUnlistedOption, collapse the stale-pin-select copies (#7318)
[._.]/ Adam Eivy398eceda8895
diff --git a/client/src/components/music/ArtistPicker.jsx b/client/src/components/music/ArtistPicker.jsxindex eb4636db50..699a0d125f 100644--- a/client/src/components/music/ArtistPicker.jsx+++ b/client/src/components/music/ArtistPicker.jsx@@ -11,6 +11,7 @@import { useEffect, useState } from 'react';import { Link } from 'react-router';import { listArtists } from '../../services/api';+import { withUnlistedOption } from '../../lib/withUnlistedOption';export default function ArtistPicker({ id = 'music-artist', value, name, onChange, disabled = false }) {const [artists, setArtists] = useState([]);@@ -33,7 +34,11 @@ export default function ArtistPicker({ id = 'music-artist', value, name, onChang// An artistId not in the fetched list (deleted persona) shouldn't silently// snap to "none" — surface it so the link isn't lost.- const unknownLink = value && !artists.some((a) => a.id === value);+ const artistOptions = withUnlistedOption(+ artists,+ value,+ (artistId) => ({ id: artistId, name: name || 'Linked artist (unavailable)' }),+ );return (<div>@@ -45,10 +50,9 @@ export default function ArtistPicker({ id = 'music-artist', value, name, onChangclassName="w-full px-3 py-2 bg-port-bg border border-port-border rounded text-white disabled:opacity-50"><option value="">— No artist —</option>- {artists.map((a) => (+ {artistOptions.map((a) => (<option key={a.id} value={a.id}>{a.name}</option>))}- {unknownLink ? <option value={value}>{name || 'Linked artist (unavailable)'}</option> : null}</select><p className="text-[11px] text-gray-500 mt-1">{artists.length === 0 && !loading ? (diff --git a/client/src/components/music/ArtistPicker.test.jsx b/client/src/components/music/ArtistPicker.test.jsxnew file mode 100644index 0000000000..38de253fb7--- /dev/null+++ b/client/src/components/music/ArtistPicker.test.jsx@@ -0,0 +1,53 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';+import { render, screen, fireEvent } from '@testing-library/react';+import { MemoryRouter } from 'react-router';+import ArtistPicker from './ArtistPicker';++const listArtists = vi.fn();+vi.mock('../../services/api', () => ({+ listArtists: (...args) => listArtists(...args),+}));++const renderPicker = (props) => render(+ <MemoryRouter>+ <ArtistPicker onChange={vi.fn()} {...props} />+ </MemoryRouter>,+);++beforeEach(() => {+ vi.clearAllMocks();+ listArtists.mockResolvedValue([+ { id: 'ar1', name: 'The Kestrels' },+ { id: 'ar2', name: 'Neon Static' },+ ]);+});++describe('ArtistPicker', () => {+ it('lists fetched artists and reports both the id and name on change', async () => {+ const onChange = vi.fn();+ renderPicker({ value: '', name: '', onChange });+ await screen.findByRole('option', { name: 'The Kestrels' });+ fireEvent.change(screen.getByRole('combobox'), { target: { value: 'ar2' } });+ expect(onChange).toHaveBeenCalledWith('ar2', 'Neon Static');+ });++ it('keeps a linked artist the fetched list no longer has selectable, using the stored name', async () => {+ renderPicker({ value: 'deleted-artist', name: 'Deleted Artist' });+ await screen.findByRole('option', { name: 'The Kestrels' });+ const select = screen.getByRole('combobox');+ expect(select.value).toBe('deleted-artist');+ expect(screen.getByRole('option', { name: 'Deleted Artist' })).toBeTruthy();+ });++ it('falls back to a generic label for an unlisted artist with no stored name', async () => {+ renderPicker({ value: 'deleted-artist', name: '' });+ await screen.findByRole('option', { name: 'The Kestrels' });+ expect(screen.getByRole('option', { name: 'Linked artist (unavailable)' })).toBeTruthy();+ });++ it('does not add a synthetic option once the value is a real artist', async () => {+ renderPicker({ value: 'ar1', name: 'The Kestrels' });+ await screen.findByRole('option', { name: 'The Kestrels' });+ expect(screen.getAllByRole('option', { name: 'The Kestrels' })).toHaveLength(1);+ });+});diff --git a/client/src/components/music/TracksManager.jsx b/client/src/components/music/TracksManager.jsxindex e48001a21c..218cf1182b 100644--- a/client/src/components/music/TracksManager.jsx+++ b/client/src/components/music/TracksManager.jsx@@ -22,6 +22,7 @@ import ConfirmButtonPair from '../ui/ConfirmButtonPair';import Field from '../ui/FormField';import { useConfirmDelete } from '../../hooks/useConfirmDelete';import { formatBytes, formatTimecode } from '../../utils/formatters';+import { withUnlistedOption } from '../../lib/withUnlistedOption';import ArtistPicker from './ArtistPicker';import MusicGenPanel from './MusicGenPanel';import ChiptunePanel from './ChiptunePanel';@@ -364,6 +365,15 @@ export default function TracksManager() {});};+ // A linked albumId the fetched list no longer carries (deleted album)+ // shouldn't silently snap the select to "no album" — surface it so the+ // link isn't lost.+ const albumOptions = withUnlistedOption(+ albums,+ form.albumId,+ (albumId) => ({ id: albumId, title: 'Linked album (unavailable)' }),+ );+return (<div><div className="flex items-center justify-between mb-4 flex-wrap gap-3">@@ -470,12 +480,9 @@ export default function TracksManager() {className="w-full px-3 py-2 bg-port-bg border border-port-border rounded text-white text-sm"><option value="">— Single (no album) —</option>- {albums.map((a) => (+ {albumOptions.map((a) => (<option key={a.id} value={a.id}>{a.title}</option>))}- {form.albumId && !albums.some((a) => a.id === form.albumId) ? (- <option value={form.albumId}>Linked album (unavailable)</option>- ) : null}</select></Field><Field compact label="Prompt" hint="Text/style prompt used by the on-device generators.">diff --git a/client/src/components/music/TracksManager.test.jsx b/client/src/components/music/TracksManager.test.jsxindex bcad46741b..b5ba2e7df6 100644--- a/client/src/components/music/TracksManager.test.jsx+++ b/client/src/components/music/TracksManager.test.jsx@@ -355,3 +355,32 @@ describe('<TracksManager> delete confirm + save wiring', () => {);});});++describe('<TracksManager> album picker', () => {+ beforeEach(() => {+ listAlbums.mockResolvedValue([{ id: 'album-1', title: 'Debut LP' }]);+ listMusicVideoProjects.mockResolvedValue([]);+ });+ afterEach(() => {+ cleanup();+ vi.clearAllMocks();+ });++ it('keeps a linked album the fetched list no longer has selectable, instead of painting the select blank', async () => {+ listTracks.mockResolvedValue([{ ...TRACK, albumId: 'retired-album' }]);+ renderAt('track-1');+ await screen.findByDisplayValue('Example Song');+ const select = screen.getByLabelText('Album');+ expect(select.value).toBe('retired-album');+ expect(within(select).getByRole('option', { name: 'Linked album (unavailable)' })).toBeTruthy();+ });++ it('does not add a synthetic option once the linked album is in the fetched list', async () => {+ listTracks.mockResolvedValue([{ ...TRACK, albumId: 'album-1' }]);+ renderAt('track-1');+ await screen.findByDisplayValue('Example Song');+ const select = screen.getByLabelText('Album');+ expect(select.value).toBe('album-1');+ expect(within(select).getAllByRole('option', { name: 'Debut LP' })).toHaveLength(1);+ });+});diff --git a/client/src/components/pipeline/AuthorPicker.jsx b/client/src/components/pipeline/AuthorPicker.jsxindex 08e70c15e8..be546f3e48 100644--- a/client/src/components/pipeline/AuthorPicker.jsx+++ b/client/src/components/pipeline/AuthorPicker.jsx@@ -16,6 +16,7 @@import { useEffect, useState } from 'react';import { Link } from 'react-router';import { listAuthors } from '../../services/api';+import { withUnlistedOption } from '../../lib/withUnlistedOption';export default function AuthorPicker({ id = 'series-author', value, byline, onChange, disabled = false }) {const [authors, setAuthors] = useState([]);@@ -38,7 +39,11 @@ export default function AuthorPicker({ id = 'series-author', value, byline, onCh// An authorId that isn't in the fetched list (deleted persona) shouldn't make// the select silently snap to "none" — surface it so the link isn't lost.- const unknownLink = value && !authors.some((a) => a.id === value);+ const authorOptions = withUnlistedOption(+ authors,+ value,+ (authorId) => ({ id: authorId, name: byline || 'Linked author (unavailable)' }),+ );return (<div>@@ -50,10 +55,9 @@ export default function AuthorPicker({ id = 'series-author', value, byline, onChclassName="w-full px-3 py-2 bg-port-bg border border-port-border rounded text-white disabled:opacity-50"><option value="">— No author —</option>- {authors.map((a) => (+ {authorOptions.map((a) => (<option key={a.id} value={a.id}>{a.name}</option>))}- {unknownLink ? <option value={value}>{byline || 'Linked author (unavailable)'}</option> : null}</select><p className="text-[11px] text-gray-500 mt-1">{authors.length === 0 && !loading ? (diff --git a/client/src/components/pipeline/AuthorPicker.test.jsx b/client/src/components/pipeline/AuthorPicker.test.jsxnew file mode 100644index 0000000000..bbd9e82893--- /dev/null+++ b/client/src/components/pipeline/AuthorPicker.test.jsx@@ -0,0 +1,53 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';+import { render, screen, fireEvent } from '@testing-library/react';+import { MemoryRouter } from 'react-router';+import AuthorPicker from './AuthorPicker';++const listAuthors = vi.fn();+vi.mock('../../services/api', () => ({+ listAuthors: (...args) => listAuthors(...args),+}));++const renderPicker = (props) => render(+ <MemoryRouter>+ <AuthorPicker onChange={vi.fn()} {...props} />+ </MemoryRouter>,+);++beforeEach(() => {+ vi.clearAllMocks();+ listAuthors.mockResolvedValue([+ { id: 'a1', name: 'Alice' },+ { id: 'a2', name: 'Bob' },+ ]);+});++describe('AuthorPicker', () => {+ it('lists fetched authors and reports both the id and name on change', async () => {+ const onChange = vi.fn();+ renderPicker({ value: '', byline: '', onChange });+ await screen.findByRole('option', { name: 'Alice' });+ fireEvent.change(screen.getByRole('combobox'), { target: { value: 'a2' } });+ expect(onChange).toHaveBeenCalledWith('a2', 'Bob');+ });++ it('keeps a linked author the fetched list no longer has selectable, using the stored byline', async () => {+ renderPicker({ value: 'deleted-author', byline: 'Deleted Persona' });+ await screen.findByRole('option', { name: 'Alice' });+ const select = screen.getByRole('combobox');+ expect(select.value).toBe('deleted-author');+ expect(screen.getByRole('option', { name: 'Deleted Persona' })).toBeTruthy();+ });++ it('falls back to a generic label for an unlisted author with no stored byline', async () => {+ renderPicker({ value: 'deleted-author', byline: '' });+ await screen.findByRole('option', { name: 'Alice' });+ expect(screen.getByRole('option', { name: 'Linked author (unavailable)' })).toBeTruthy();+ });++ it('does not add a synthetic option once the value is a real author', async () => {+ renderPicker({ value: 'a1', byline: 'Alice' });+ await screen.findByRole('option', { name: 'Alice' });+ expect(screen.getAllByRole('option', { name: 'Alice' })).toHaveLength(1);+ });+});diff --git a/client/src/components/settings/ImageGenTab.jsx b/client/src/components/settings/ImageGenTab.jsxindex b749af76fc..e305fc5125 100644--- a/client/src/components/settings/ImageGenTab.jsx+++ b/client/src/components/settings/ImageGenTab.jsx@@ -26,6 +26,7 @@ import {} from '../../services/api';import { deriveAvailableBackends, imageGenReadiness, isCloudCliMode, IMAGE_GEN_MODE, AGY_IMAGEGEN_DEFAULT_MODEL, AGY_IMAGEGEN_IMAGE_MODEL, CODEX_IMAGEGEN_DEFAULT_EFFORT, CODEX_IMAGEGEN_DEFAULT_MODEL, GROK_ASPECT_RATIOS, RENDER_TARGET_BACKEND_AUTO, RENDER_TARGET_OPTIONS, VIDEO_RENDER_MODES, localModelSelectOptions, modeLabel, normalizeRenderPinValue, supportsCloudModelOverride } from '../../lib/imageGenBackends';import { resolveCleanersFromConfig } from '../../lib/imageCleaners';+import { withUnlistedOption } from '../../lib/withUnlistedOption';import { useMediaJobSse } from '../../hooks/useMediaJobSse';import { useAgyModels } from '../../hooks/useAgyModels';import { useHfTokenStatus } from '../../hooks/useHfTokenStatus';@@ -418,9 +419,11 @@ export function ImageGenTab() {// the derivation above (e.g. external with a blank URL) — the server would// still route the render there, so hiding it would make the select disagree// with what the button actually does.- const testModeOptions = savedBackends.some((b) => b.id === saved.mode)- ? savedBackends- : [{ id: saved.mode, label: modeLabel(saved.mode) }, ...savedBackends];+ const testModeOptions = withUnlistedOption(+ savedBackends,+ saved.mode,+ (id) => ({ id, label: modeLabel(id) }),+ );// A pick that a later save disabled falls back to the saved default rather// than queueing a render that can only 400.const effectiveTestMode = testModeOptions.some((b) => b.id === testMode) ? testMode : saved.mode;diff --git a/client/src/components/settings/VoiceTab.jsx b/client/src/components/settings/VoiceTab.jsxindex cc98d86add..40c35dce4c 100644--- a/client/src/components/settings/VoiceTab.jsx+++ b/client/src/components/settings/VoiceTab.jsx@@ -11,6 +11,7 @@ import { playWav, webSpeechSupported } from '../../services/voiceClient';import { nanoAvailability } from '../../services/browserLlm';import { readVoiceHidden, writeVoiceHidden } from '../../services/voiceVisibility';import { formatVoiceLabel } from '../../lib/voiceLabel';+import { withUnlistedOption } from '../../lib/withUnlistedOption';import FormField from '../ui/FormField';import { useInstanceFeatures } from '../../hooks/useInstanceFeatures';@@ -289,6 +290,20 @@ export function VoiceTab() {.find((key) => cfg.tts[key] && typeof cfg.tts[key] === 'object');const activeVoice = cfg.tts[engineConfigKey || fallbackConfigKey]?.voice;const selectedEngineMetadataMissing = Boolean(engineMeta && !engineConfigKey);+ // A configured engine/voice the live registry no longer lists (retired+ // engine, deleted voice) must still render as its own option — otherwise+ // the select paints blank and a save would silently switch away from it.+ const ttsEngineOptions = withUnlistedOption(ttsEngines, engine, (id) => ({ id, label: `${id} (current)` }));+ // Voices are keyed by `name`, not `id`. `unlisted` flags the synthetic+ // entry so the render below can show the same "(current)" text the old+ // hand-rolled option used, instead of running a bare `{ name }` stand-in+ // through formatVoiceLabel's engine-specific formatters.+ const voiceOptions = withUnlistedOption(+ voices,+ activeVoice,+ (name) => ({ name, unlisted: true }),+ { key: 'name' },+ );// LLM provider/model pickers. The saved provider/model are always shown even// when missing from the registry (e.g. provider deleted, or a model not in@@ -463,10 +478,7 @@ export function VoiceTab() {onChange={(e) => patch('tts.engine', e.target.value)}className={inputCls}>- {!ttsEngines.some((item) => item.id === engine) && (- <option value={engine}>{engine} (current)</option>- )}- {ttsEngines.map((opt) => (+ {ttsEngineOptions.map((opt) => (<option key={opt.id} value={opt.id}>{opt.label || opt.id}{opt.description ? ` (${opt.description})` : ''}</option>@@ -504,11 +516,8 @@ export function VoiceTab() {}}className={`${inputCls} flex-1`}>- {activeVoice && !voices.some((v) => v.name === activeVoice) && (- <option value={activeVoice}>{activeVoice} (current)</option>- )}- {voices.map((v) => (- <option key={v.name} value={v.name}>{formatVoiceLabel(v, engine)}</option>+ {voiceOptions.map((v) => (+ <option key={v.name} value={v.name}>{v.unlisted ? `${v.name} (current)` : formatVoiceLabel(v, engine)}</option>))}</select><buttondiff --git a/client/src/components/settings/VoiceTab.test.jsx b/client/src/components/settings/VoiceTab.test.jsxindex 3aeb47c0fa..e3670fb0a4 100644--- a/client/src/components/settings/VoiceTab.test.jsx+++ b/client/src/components/settings/VoiceTab.test.jsx@@ -147,4 +147,17 @@ describe('VoiceTab TTS engine registry', () => {expect(await screen.findByRole('combobox', { name: 'TTS engine' })).toHaveValue('qwen3-tts');expect(screen.getByRole('combobox', { name: 'Voice' }).disabled).toBe(false);});++ it('keeps a linked voice the fetched catalog no longer has selectable', async () => {+ voiceApi.getVoiceConfig.mockResolvedValue({+ ...structuredClone(config),+ tts: { ...structuredClone(config.tts), qwen3: { voice: 'retired-voice' } },+ });++ render(<MemoryRouter><VoiceTab /></MemoryRouter>);++ const voiceSelect = await screen.findByRole('combobox', { name: 'Voice' });+ expect(voiceSelect).toHaveValue('retired-voice');+ expect(screen.getByRole('option', { name: 'retired-voice (current)' })).toBeTruthy();+ });});diff --git a/client/src/lib/README.md b/client/src/lib/README.mdindex 40bc633364..dd75c08f55 100644--- a/client/src/lib/README.md+++ b/client/src/lib/README.md@@ -179,6 +179,7 @@ grep -i "what you want to do" client/src/lib/README.md| `uuid.js` | `uuidv4()` — spec-valid v4 uuid that also works on **insecure origins**. Reach for this instead of `crypto.randomUUID()`, which only exists in a secure context (HTTPS / localhost) and throws `crypto.randomUUID is not a function` for the many users who reach PortOS over plain HTTP via Tailscale. Falls back to `crypto.getRandomValues` (available on insecure origins), then `Math.random`. || `webglSupport.js` | `isWebGLAvailable()` — memoized probe for a creatable WebGL/WebGL2 context. CoS 3D avatars (and similar r3f mounts) call this before `<Canvas>` so headless Chrome / no-GPU displays degrade to a hint instead of unhandled `WebGLRenderer` rejections. || `voiceLabel.js` | `formatVoiceLabel(v, engine?)` — display label for a TTS voice record. Engine-specific formatters plug into a lookup table; new engines extend that map. |+| `withUnlistedOption.js` | `withUnlistedOption(list, value, makeOption, {key = 'id'})` — keeps a stored-but-no-longer-listed pin (a retired model, a deleted persona, a stale voice/album link) selectable in a `<select>` instead of the value silently painting blank and a save dropping it: returns `list` unchanged when `value` is blank or already present under `key`, else prepends `makeOption(value)`. `key` overrides the matched field for a list keyed by something other than `id` (e.g. `'name'` for a voice list). |## Page-scoped pure helpersdiff --git a/client/src/lib/index.js b/client/src/lib/index.jsindex 6f62834c89..98aa7d3ba6 100644--- a/client/src/lib/index.js+++ b/client/src/lib/index.js@@ -213,6 +213,7 @@ export * from './universeBuilderExpand.js';export * from './videoTimelineModel.js';export * from './uuid.js';export * from './webglSupport.js';+export * from './withUnlistedOption.js';export * from './wrSceneCursor.js';export * from './writingGuide.js';export * from './qrCode.js';diff --git a/client/src/lib/withUnlistedOption.js b/client/src/lib/withUnlistedOption.jsnew file mode 100644index 0000000000..f2da86b525--- /dev/null+++ b/client/src/lib/withUnlistedOption.js@@ -0,0 +1,24 @@+/**+ * Keeps a stored-but-no-longer-listed pin selectable in a `<select>`.+ *+ * A `<select>` whose `value` matches no `<option>` renders unselected — which+ * reads as "nothing pinned" while the server is still honouring the pin, and+ * a save from that state silently drops it. Returns `list` unchanged when+ * `value` is blank or already present under `key`; otherwise prepends+ * `makeOption(value)` so the pin renders as its own option.+ *+ * `key` names the property each list item is matched on (default `'id'`) —+ * pass the field a given list actually keys on (e.g. `'name'` for a voice+ * list keyed by name rather than id).+ *+ * @param {unknown[]} list+ * @param {string|null|undefined} value+ * @param {(value: string) => unknown} makeOption+ * @param {{key?: string}} [options]+ * @returns {unknown[]}+ */+export const withUnlistedOption = (list, value, makeOption, { key = 'id' } = {}) => {+ if (!value) return list;+ if (list.some((item) => item?.[key] === value)) return list;+ return [makeOption(value), ...list];+};diff --git a/client/src/lib/withUnlistedOption.test.js b/client/src/lib/withUnlistedOption.test.jsnew file mode 100644index 0000000000..02d6d464c7--- /dev/null+++ b/client/src/lib/withUnlistedOption.test.js@@ -0,0 +1,34 @@+import { describe, it, expect } from 'vitest';+import { withUnlistedOption } from './withUnlistedOption';++describe('withUnlistedOption', () => {+ const list = [{ id: 'a', label: 'A' }, { id: 'b', label: 'B' }];++ it('returns the list unchanged when value is blank', () => {+ expect(withUnlistedOption(list, '', (id) => ({ id, label: id }))).toBe(list);+ expect(withUnlistedOption(list, null, (id) => ({ id, label: id }))).toBe(list);+ expect(withUnlistedOption(list, undefined, (id) => ({ id, label: id }))).toBe(list);+ });++ it('returns the list unchanged when value is already present', () => {+ expect(withUnlistedOption(list, 'b', (id) => ({ id, label: id }))).toBe(list);+ });++ it('prepends a synthetic option when value is missing from the list', () => {+ const result = withUnlistedOption(list, 'stale', (id) => ({ id, label: `${id} (unavailable)` }));+ expect(result).toEqual([{ id: 'stale', label: 'stale (unavailable)' }, ...list]);+ });++ it('matches on a custom key instead of the id default', () => {+ const named = [{ name: 'alpha' }, { name: 'beta' }];+ expect(withUnlistedOption(named, 'alpha', (name) => ({ name }), { key: 'name' })).toBe(named);+ expect(withUnlistedOption(named, 'gamma', (name) => ({ name }), { key: 'name' }))+ .toEqual([{ name: 'gamma' }, ...named]);+ });++ it('never mutates the input list', () => {+ const original = [...list];+ withUnlistedOption(list, 'stale', (id) => ({ id }));+ expect(list).toEqual(original);+ });+});diff --git a/client/src/utils/providerModels.js b/client/src/utils/providerModels.jsindex 768dbca600..dd03509fbf 100644--- a/client/src/utils/providerModels.js+++ b/client/src/utils/providerModels.js@@ -93,6 +93,16 @@ export const selectableModelsForProvider = (provider, models) =>* configured-default sentinel (the shipped agy `defaultModel`, which* `filterSelectableModels` exists to hide) and any typo'd/stale pin.*+ * Deliberately NOT layered on the generic `withUnlistedOption` helper+ * (client/src/lib/): that helper's contract is "present under `key`, else+ * prepend" over a list of `{id, ...}` objects, while `models` here is a flat+ * array of model-id STRINGS with no `key` to match on, the extra Antigravity+ * effort-suffix gate above narrows staleness to more than mere absence, and+ * this appends (kept last, after the real catalog) rather than prepends —+ * flipping either would change which option a picker shows first for no+ * behavioral gain. The same reasoning applies to `unlistedSelection` in+ * `resolveProviderModelOptions` below, over the Codex account catalog.+ ** CLIENT-ONLY (no server mirror) — this is a rendering concern.* @param {{id?:string, command?:string}|null|undefined} provider* @param {unknown[]} models - the already-filtered option list