Files
Psychotoxical-psysonic/src/serverCapabilities/storeView.ts
T
cucadmuh 6118b3940f feat(server): capability framework, AudioMuse sonic routing & PsyLab Connections (#1033)
* feat(server): probe AudioMuse via OpenSubsonic and add PsyLab Connections tab

Navidrome ≥0.62: detect sonicSimilarity extension for reliable plugin signal;
older servers keep the legacy getSimilarSongs probe. PsyLab gets a Connections
tab with session, endpoint, and active-server capability details.

* feat(psylab): polish Connections tab, admin role probe, and tab bar layout

Status badges and Navidrome admin/user validation in Connections; prevent
PsyLab tab row from vertically collapsing under the Logs flex layout.

* docs: add CHANGELOG and credits for PR #1032

* feat(settings): auto-enable AudioMuse on Navidrome 0.62+ with status indicator

Replace the per-server manual toggle with a probe-driven badge when
sonicSimilarity is available; pre-0.62 Navidrome keeps the legacy toggle.

* feat(server): capability framework with AudioMuse sonic routing

Add a declarative server-capability catalog (src/serverCapabilities/) that
picks a feature strategy per server generation, runs only the needed probes,
and routes API calls. AudioMuse Instant Mix now prefers the OpenSubsonic
sonicSimilarity endpoint (getSonicSimilarTracks) on Navidrome 0.62+ and
falls back to legacy getSimilarSongs.

- catalog/context/resolve: eligibility, detection, activation, call routing
- storeView: read facade over the existing per-server probe maps
- getSonicSimilarTracks API client + fetchSimilarTracksRouted router
- route Instant Mix and Lucky Mix through the resolver
- ServersTab + PsyLab Connections read the resolver (auto status vs toggle)
- tests: resolve, storeView, router

* docs: update CHANGELOG and credits for PR #1033

Renamed branch supersedes PR #1032: point changelog/credits at #1033 and
document the server-capability framework, auto-managed AudioMuse indicator,
and sonic Instant Mix routing.

* refactor(server): address PR #1033 review — idempotent probe, drop dead code

- Make scheduleInstantMixProbeForServer idempotent: skip when a definitive
  result is cached; re-probe only on force (add/edit/test server), a prior
  error, or a server version/type change (invalidated in setSubsonicServerIdentity).
  Removes the steady-state 120 s re-probe, the present→probing→present flicker,
  and the momentary legacy-fallback routing window.
- Remove now-dead identity helpers (showAudiomuseNavidromeServerSetting,
  isAudiomusePluginAutoManaged, isNavidromeSonicSimilarityEligible,
  resolveAudiomusePluginProbeUiStatus + type) and the superseded
  probeAudiomusePluginWithCredentials; the catalog is the single source of truth.
- Drop the never-emitted 'unsupported' AudiomusePluginProbeResult variant.
- Fill audiomuseStatus* keys in all 8 non-en locales.
- Tests: probe idempotency + version-change invalidation; retarget
  OpenSubsonic test to fetchOpenSubsonicExtensionsWithCredentials.
2026-06-08 23:16:29 +02:00

86 lines
2.9 KiB
TypeScript

import { useAuthStore } from '../store/authStore';
import type {
AudiomusePluginProbeResult,
InstantMixProbeResult,
} from '../utils/server/subsonicServerIdentity';
import { buildCapabilityContext } from './context';
import {
PROBE_LEGACY_INSTANT_MIX,
PROBE_OPENSUBSONIC_EXTENSIONS,
SONIC_SIMILARITY_EXTENSION,
getCapabilityDefinition,
} from './catalog';
import {
isCapabilityActive,
resolveCallChain,
resolveCapability,
} from './resolve';
import type {
CapabilityCallRoute,
ProbeOutcome,
ResolvedCapability,
} from './types';
/**
* Probe results currently live in dedicated per-server store maps. This facade
* maps them into the generic `ProbeOutcome` shape the resolver consumes, so the
* catalog/resolver/router stay storage-agnostic.
*/
function pluginProbeToOutcome(probe: AudiomusePluginProbeResult | undefined): ProbeOutcome | undefined {
switch (probe) {
case 'present': return { status: 'present', extensions: [SONIC_SIMILARITY_EXTENSION] };
case 'absent': return { status: 'present', extensions: [] };
case 'probing': return { status: 'probing' };
case 'error': return { status: 'error' };
default: return undefined;
}
}
function legacyProbeToOutcome(probe: InstantMixProbeResult | undefined): ProbeOutcome | undefined {
switch (probe) {
case 'ok': return { status: 'present' };
case 'empty':
case 'skipped': return { status: 'absent' };
case 'error': return { status: 'error' };
default: return undefined;
}
}
export function buildProbeOutcomesForServer(serverId: string): Record<string, ProbeOutcome | undefined> {
const s = useAuthStore.getState();
return {
[PROBE_OPENSUBSONIC_EXTENSIONS]: pluginProbeToOutcome(s.audiomusePluginProbeByServer[serverId]),
[PROBE_LEGACY_INSTANT_MIX]: legacyProbeToOutcome(s.instantMixProbeByServer[serverId]),
};
}
export function resolveFeatureForServer(
serverId: string,
feature: string,
): ResolvedCapability | null {
const def = getCapabilityDefinition(feature);
if (!def) return null;
const s = useAuthStore.getState();
const ctx = buildCapabilityContext(s.subsonicServerIdentityByServer[serverId]);
return resolveCapability(def, ctx, buildProbeOutcomesForServer(serverId));
}
export function isFeatureActiveForServer(serverId: string, feature: string): boolean {
const resolved = resolveFeatureForServer(serverId, feature);
if (!resolved) return false;
const userOptIn = !!useAuthStore.getState().audiomuseNavidromeByServer[serverId];
return isCapabilityActive(resolved, userOptIn);
}
export function resolveCallRoutesForServer(
serverId: string,
feature: string,
op: string,
): CapabilityCallRoute[] {
const def = getCapabilityDefinition(feature);
if (!def) return [];
const s = useAuthStore.getState();
const ctx = buildCapabilityContext(s.subsonicServerIdentityByServer[serverId]);
return resolveCallChain(def, ctx, buildProbeOutcomesForServer(serverId), op);
}