MCPcopy
hub / github.com/nukeop/nuclear / initDiscoveryService

Function initDiscoveryService

packages/player/src/services/discoveryService.ts:14–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12const RECOMMENDATION_LIMIT = 5;
13
14export const initDiscoveryService = () => {
15 return eventBus.on('trackStarted', async () => {
16 const isEnabled = useSettingsStore
17 .getState()
18 .getValue('core.playback.discovery');
19 const activeDiscoveryId = providersHost.getActive('discovery');
20 if (!isEnabled || !providersHost.get(activeDiscoveryId, 'discovery')) {
21 return;
22 }
23
24 const { items, currentIndex } = useQueueStore.getState();
25 const isLastTrack = currentIndex >= items.length - 1;
26 if (!isLastTrack) {
27 return;
28 }
29
30 const variety =
31 (useSettingsStore
32 .getState()
33 .getValue('core.playback.discoveryVariety') as number) ?? 0.5;
34
35 const contextTracks: Track[] = items
36 .slice(-CONTEXT_SIZE)
37 .map((item) => item.track);
38
39 try {
40 const recommendations = await discoveryHost.getRecommendations(
41 contextTracks,
42 { variety, limit: RECOMMENDATION_LIMIT },
43 );
44
45 if (recommendations.length > 0) {
46 useQueueStore.getState().addToQueue(recommendations);
47 }
48 } catch (error) {
49 reportError('discovery', {
50 userMessage: i18n.t('discovery:recommendationError'),
51 error,
52 });
53 }
54 });
55};

Callers 2

initPlayerAppFunction · 0.90
discovery.test.tsxFile · 0.90

Calls 6

reportErrorFunction · 0.90
onMethod · 0.80
getStateMethod · 0.80
getRecommendationsMethod · 0.80
addToQueueMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected