feat: enhance discovery, vibe sessions, and library enrichment
Typecheck / typecheck (backend) (push) Has been cancelled
Typecheck / typecheck (workers) (push) Has been cancelled

This commit is contained in:
kami
2026-08-01 14:40:48 +04:00
parent a0c9f42a89
commit 4c48d11e9d
54 changed files with 4136 additions and 521 deletions
+51
View File
@@ -0,0 +1,51 @@
import type { Track } from '../types';
import { usePlaybackStore } from '../store/usePlaybackStore';
import { useVibeStore } from '../store/useVibeStore';
import { fetchNextBatch, vibeService, type VibeBatchStatus } from './vibeService';
export const INITIAL_VIBE_BATCH_SIZE = 5;
export interface StartedVibeSession {
status: VibeBatchStatus;
tracks: Track[];
}
let startInFlight: Promise<StartedVibeSession> | null = null;
/**
* Start a V2 plan and immediately hand its first recommendations to playback.
* Keeping this in one place prevents entry points from accidentally replacing a
* generated Vibe queue with a normal browse queue.
*/
export async function startVibeSession(seed: Track): Promise<StartedVibeSession> {
if (startInFlight) return startInFlight;
startInFlight = beginVibeSession(seed);
try {
return await startInFlight;
} finally {
startInFlight = null;
}
}
async function beginVibeSession(seed: Track): Promise<StartedVibeSession> {
const { sessionId } = await vibeService.start(seed.id);
const vibe = useVibeStore.getState();
// Do not replace a working Vibe until the new session has produced a usable
// initial batch. This also keeps the page prefetcher attached to the old
// session while this request is in flight.
const result = await fetchNextBatch(INITIAL_VIBE_BATCH_SIZE, sessionId);
if (result.tracks.length === 0) return result;
vibe.setInitialBatchStatus('loading');
vibe.setActiveSession({ sessionId, seedTrackId: seed.id });
vibe.setSeedTrackId(seed.id);
vibe.setCenterTrack(seed);
vibe.setBuffer(result.tracks);
vibe.setInitialBatchStatus('idle');
const playback = usePlaybackStore.getState();
playback.setQueue(result.tracks);
playback.playTrack(result.tracks[0]);
return result;
}