feat(radio): wire radio + similarity into the queue (A11/B6, §6.5)
"Start radio" in the track menu seeds the queue from a track; RadioController
(headless, in AppShell) tops it up via /radio/next as it drains. QueuePanel's
radio scaffolding is now live: the exploration slider drives familiar<->new and
each entry shows its reason ("why this is playing"). Adds the radio endpoints
(start/next/similar), radio context + actions on the queue slice, and the pick->
entry mapper. Degrades to metadata picks while ML is offline.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import { api } from '../index';
|
||||
import { toTrack, type RawTrack } from '../mappers';
|
||||
import type { RadioResult } from '../types';
|
||||
|
||||
// Radio + similarity (§6.5). Stateless: the client passes the seed + already-
|
||||
// queued ids and pulls more as the queue drains.
|
||||
|
||||
interface RawRadioTrack {
|
||||
track: RawTrack;
|
||||
reason: string;
|
||||
}
|
||||
interface RawRadio {
|
||||
source: string;
|
||||
tracks: RawRadioTrack[];
|
||||
}
|
||||
interface RawSimilar {
|
||||
source: string;
|
||||
tracks: RawTrack[];
|
||||
}
|
||||
|
||||
export interface RadioArgs {
|
||||
seedTrackId?: string;
|
||||
fromLikes?: boolean;
|
||||
exploration?: number;
|
||||
count?: number;
|
||||
excludeIds?: string[];
|
||||
}
|
||||
|
||||
const toBody = (a: RadioArgs) => ({
|
||||
seed_track_id: a.seedTrackId ?? null,
|
||||
from_likes: a.fromLikes ?? false,
|
||||
exploration: a.exploration ?? 0.25,
|
||||
count: a.count ?? 20,
|
||||
exclude_ids: a.excludeIds ?? [],
|
||||
});
|
||||
|
||||
const toRadio = (r: RawRadio): RadioResult => ({
|
||||
source: r.source,
|
||||
picks: r.tracks.map((x) => ({ track: toTrack(x.track), reason: x.reason })),
|
||||
});
|
||||
|
||||
export const radioApi = api.injectEndpoints({
|
||||
endpoints: (build) => ({
|
||||
startRadio: build.mutation<RadioResult, RadioArgs>({
|
||||
query: (a) => ({ url: '/radio', method: 'POST', body: toBody(a) }),
|
||||
transformResponse: (r: RawRadio) => toRadio(r),
|
||||
}),
|
||||
radioNext: build.mutation<RadioResult, RadioArgs>({
|
||||
query: (a) => ({ url: '/radio/next', method: 'POST', body: toBody(a) }),
|
||||
transformResponse: (r: RawRadio) => toRadio(r),
|
||||
}),
|
||||
getSimilarTracks: build.query<RadioResult, string>({
|
||||
query: (trackId) => `/tracks/${trackId}/similar`,
|
||||
transformResponse: (r: RawSimilar) => ({
|
||||
source: r.source,
|
||||
picks: r.tracks.map((t) => ({ track: toTrack(t), reason: 'similar' })),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
overrideExisting: false,
|
||||
});
|
||||
|
||||
export const {
|
||||
useStartRadioMutation,
|
||||
useRadioNextMutation,
|
||||
useGetSimilarTracksQuery,
|
||||
} = radioApi;
|
||||
Reference in New Issue
Block a user