@doitian/dsh-music 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -724
- package/cordis.patch.yml +12 -8
- package/lib/dj.js +239 -47
- package/lib/index.js +53 -5
- package/lib/panel.html +351 -167
- package/lib/router.js +49 -2
- package/lib/session.js +96 -9
- package/lib/state.js +60 -10
- package/package.json +1 -1
package/cordis.patch.yml
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
# apiPrefix route prefix (default `music`) — keep it `music` unless
|
|
10
10
|
# you also rebuild the browser half.
|
|
11
11
|
# dataDir where session.json lives (default $DSH_HOME/music).
|
|
12
|
-
# audioLevel exhigh (320 kbps, default)
|
|
12
|
+
# audioLevel exhigh (320 kbps, default); also standard, higher,
|
|
13
|
+
# lossless, hires, jymaster, dolby, sky, jyeffect.
|
|
13
14
|
# requestTimeoutMs NetEase request deadline (default 15000).
|
|
14
15
|
# dj.provider model route for the AI DJ's model tier, e.g. opencode-go.
|
|
15
16
|
# dj.model exact model id, e.g. deepseek-v4.1-flash.
|
|
@@ -23,14 +24,17 @@
|
|
|
23
24
|
# conversation.
|
|
24
25
|
#
|
|
25
26
|
# Route resolution, highest first: the player's picker -> `dj.provider`/`dj.model`
|
|
26
|
-
# -> the
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
27
|
+
# -> the session's default model (`agent-default-model`, which is why "use my
|
|
28
|
+
# session model" needs no configuration) -> discovery, whose first row is
|
|
29
|
+
# arbitrary. Only the choice of model is shared with the session: the DJ is not
|
|
30
|
+
# an agent and starts none. It makes stateless leaf calls — one to curate each
|
|
31
|
+
# plan, and one to rewrite a mood brief into search terms the first time that
|
|
32
|
+
# brief is seen — so there is no session to rotate or dispose.
|
|
30
33
|
#
|
|
31
|
-
#
|
|
32
|
-
# similar songs,
|
|
33
|
-
#
|
|
34
|
+
# With no model route at all the DJ still works: it scores its candidates —
|
|
35
|
+
# similar songs, personal FM, rested likes, the daily recommendations, the
|
|
36
|
+
# charts and any mood brief — by brief match, artist affinity, and the
|
|
37
|
+
# listener's likes, dislikes and skips.
|
|
34
38
|
- insert:
|
|
35
39
|
- id: music
|
|
36
40
|
name: '@doitian/dsh-music'
|
package/lib/dj.js
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
import { createHash, randomUUID } from 'node:crypto';
|
|
33
33
|
|
|
34
34
|
import { Pacer, TtlCache, sampleInOrder } from './cache.js';
|
|
35
|
+
import { isHeard } from './session.js';
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* Render a model-tier failure so its stable code survives.
|
|
@@ -63,8 +64,29 @@ const MAX_SEEDS = 4;
|
|
|
63
64
|
/** How far back in the history a seed may come from, so seeds stay current. */
|
|
64
65
|
const SEED_HISTORY = 20;
|
|
65
66
|
|
|
66
|
-
/**
|
|
67
|
-
const
|
|
67
|
+
/** Seeds taken from what was played; the rest come from likes. */
|
|
68
|
+
const HISTORY_SEEDS = 2;
|
|
69
|
+
|
|
70
|
+
/** "More like this" boosts that seed similarity, ahead of the regular seeds. */
|
|
71
|
+
const BOOST_SEEDS = 2;
|
|
72
|
+
|
|
73
|
+
/** Songs like a "more" boost queued straight after the current one. */
|
|
74
|
+
const BOOST_NEXT = 3;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* A boost weighs as much as the mood brief: both are the listener saying what
|
|
78
|
+
* they want now, and a boost would be no use if a favourite artist outranked it.
|
|
79
|
+
*/
|
|
80
|
+
const BOOST_WEIGHT = 3.0;
|
|
81
|
+
|
|
82
|
+
/** The newest likes whose artists inform the taste picture. */
|
|
83
|
+
const LIKED_TASTE = 200;
|
|
84
|
+
|
|
85
|
+
/** A liked track's artist outweighs a play of it: a like is a deliberate act. */
|
|
86
|
+
const LIKED_ARTIST_WEIGHT = 2;
|
|
87
|
+
|
|
88
|
+
/** Track details per lookup; one oversized id list is a request NetEase may refuse. */
|
|
89
|
+
const DETAIL_BATCH = 50;
|
|
68
90
|
|
|
69
91
|
/** A liked track played more recently than this is not offered back yet. */
|
|
70
92
|
const LIKED_REST_MS = 3 * 24 * 60 * 60 * 1000;
|
|
@@ -80,7 +102,14 @@ const ORIGINS = ['prompt', 'liked', 'fm', 'similar', 'daily', 'new', 'chart'];
|
|
|
80
102
|
* no single one can crowd discovery out of the pool; without a brief they sum
|
|
81
103
|
* to 48, and a brief adds up to 23 that match it.
|
|
82
104
|
*/
|
|
83
|
-
const QUOTA = { promptPlaylists: 15, promptSongs: 8, similar: 14, daily: 8, new: 6, chart: 8 };
|
|
105
|
+
const QUOTA = { promptPlaylists: 15, promptSongs: 8, similar: 14, liked: 6, daily: 8, new: 6, chart: 8 };
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Signed in, the account's own signals — the daily list, likes, FM — know the
|
|
109
|
+
* listener; the charts and the new-song feed only know the market. They keep a
|
|
110
|
+
* few slots for discovery and give the rest to the personal sources.
|
|
111
|
+
*/
|
|
112
|
+
const SIGNED_IN_QUOTA = { ...QUOTA, liked: 9, daily: 12, new: 3, chart: 4 };
|
|
84
113
|
|
|
85
114
|
const HOUR = 60 * 60 * 1000;
|
|
86
115
|
|
|
@@ -131,6 +160,14 @@ const SKIPS_TO_REPORT_ARTIST = 2;
|
|
|
131
160
|
/** Prefix for the minted curation identity, so logs and health read clearly. */
|
|
132
161
|
const SESSION_ID_PREFIX = 'music-dj-';
|
|
133
162
|
|
|
163
|
+
/** One line of the brief naming the boosts in one direction, or nothing. */
|
|
164
|
+
function boostLine(boosts, direction, heading) {
|
|
165
|
+
const named = (boosts ?? [])
|
|
166
|
+
.filter((boost) => boost.direction === direction)
|
|
167
|
+
.map((boost) => `${boost.name} — ${(boost.artists ?? []).join('/')}`);
|
|
168
|
+
return named.length ? `${heading}: ${named.join('; ')}` : '';
|
|
169
|
+
}
|
|
170
|
+
|
|
134
171
|
/**
|
|
135
172
|
* The provider-visible identity of the DJ's curation conversation.
|
|
136
173
|
*
|
|
@@ -366,23 +403,31 @@ export class AiDj {
|
|
|
366
403
|
|
|
367
404
|
/**
|
|
368
405
|
* The tracks similarity expands from: what is playing and what was recently
|
|
369
|
-
* heard through,
|
|
406
|
+
* heard through, and random likes — each filling in when the other is thin.
|
|
370
407
|
*
|
|
371
408
|
* A rejected track never seeds. The ✕ records a dislike and then moves on, so
|
|
372
409
|
* seeding from the raw history would make the very next plan fetch more of
|
|
373
410
|
* exactly what was just turned down.
|
|
374
411
|
*/
|
|
375
412
|
#seeds(digest) {
|
|
376
|
-
const
|
|
413
|
+
const usable = (id) => id && this.store.taste(id) !== 'disliked' && !digest.skipCounts.has(id);
|
|
414
|
+
const heard = [
|
|
415
|
+
this.player.current()?.id,
|
|
416
|
+
...this.store.state.history.slice(0, SEED_HISTORY).filter(isHeard).map((entry) => entry.id),
|
|
417
|
+
].filter(usable);
|
|
418
|
+
const liked = sampleInOrder(this.store.feedback.likes.filter(usable), MAX_SEEDS);
|
|
377
419
|
const seeds = [];
|
|
378
|
-
const
|
|
379
|
-
|
|
420
|
+
const take = (ids, limit) => {
|
|
421
|
+
for (const id of ids) {
|
|
422
|
+
if (seeds.length >= limit) return;
|
|
423
|
+
if (!seeds.includes(id)) seeds.push(id);
|
|
424
|
+
}
|
|
380
425
|
};
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
426
|
+
// Half from what is playing and was heard, half from likes: seeding only
|
|
427
|
+
// from plays lets the DJ's own picks decide what it picks next.
|
|
428
|
+
take(heard, HISTORY_SEEDS);
|
|
429
|
+
take(liked, MAX_SEEDS);
|
|
430
|
+
take(heard, MAX_SEEDS);
|
|
386
431
|
return seeds;
|
|
387
432
|
}
|
|
388
433
|
|
|
@@ -397,7 +442,7 @@ export class AiDj {
|
|
|
397
442
|
this.store.state.history.filter((entry) => (entry.at ?? 0) > restedSince).map((entry) => entry.id),
|
|
398
443
|
);
|
|
399
444
|
const ids = this.store.feedback.likes.filter((id) => !excluded.has(id) && !heardRecently.has(id));
|
|
400
|
-
return sampleInOrder(ids,
|
|
445
|
+
return sampleInOrder(ids, this.#quota().liked);
|
|
401
446
|
}
|
|
402
447
|
|
|
403
448
|
/**
|
|
@@ -417,7 +462,17 @@ export class AiDj {
|
|
|
417
462
|
...[...digest.skipCounts].filter(([, skips]) => skips >= SKIPS_TO_EXCLUDE).map(([id]) => id),
|
|
418
463
|
]);
|
|
419
464
|
const brief = prompt.trim();
|
|
420
|
-
const
|
|
465
|
+
const boosts = this.store.activeBoosts();
|
|
466
|
+
const fewer = new Set(boosts.filter((boost) => boost.direction === 'less').map((boost) => boost.id));
|
|
467
|
+
for (const id of fewer) excluded.add(id);
|
|
468
|
+
// A "more" boost seeds first, and its similar songs are kept whole; a
|
|
469
|
+
// "less" one never seeds.
|
|
470
|
+
const boostSeeds = boosts
|
|
471
|
+
.filter((boost) => boost.direction === 'more')
|
|
472
|
+
.map((boost) => boost.id)
|
|
473
|
+
.slice(0, BOOST_SEEDS);
|
|
474
|
+
const seeds = [...boostSeeds, ...this.#seeds(digest).filter((id) => !boostSeeds.includes(id) && !fewer.has(id))];
|
|
475
|
+
const nearBoosts = this.#nearBoosts(boosts);
|
|
421
476
|
// Every source is fetched at once and fails alone; the pool is then
|
|
422
477
|
// assembled in priority order, so a track two sources share is claimed by
|
|
423
478
|
// the one that ranks it higher, however the requests happened to finish.
|
|
@@ -427,19 +482,24 @@ export class AiDj {
|
|
|
427
482
|
prompt: brief ? settled(briefing.then((result) => result.tracks)) : [],
|
|
428
483
|
liked: settled(this.#tracksByIds(this.#likedSample(excluded))),
|
|
429
484
|
fm: settled(this.#fmTracks()),
|
|
430
|
-
similar: settled(this.#similarTracks(seeds, excluded)),
|
|
431
|
-
daily: settled(this.#feedTracks(`daily:${this.#account()}`, TTL.daily, () => this.api.recommendSongs(30),
|
|
432
|
-
new: settled(this.#feedTracks('new', TTL.new, () => this.api.personalizedNewsongs(30),
|
|
485
|
+
similar: settled(this.#similarTracks(seeds, excluded, boostSeeds.length + 1, boosts)),
|
|
486
|
+
daily: settled(this.#feedTracks(`daily:${this.#account()}`, TTL.daily, () => this.api.recommendSongs(30), this.#quota().daily, excluded)),
|
|
487
|
+
new: settled(this.#feedTracks('new', TTL.new, () => this.api.personalizedNewsongs(30), this.#quota().new, excluded)),
|
|
433
488
|
chart: settled(this.#chartTracks(excluded)),
|
|
434
489
|
};
|
|
435
490
|
|
|
491
|
+
// The newest likes, for the taste picture; cached per track, so only new
|
|
492
|
+
// likes cost a lookup after the first plan.
|
|
493
|
+
const likedTaste = this.#tracksByIds(this.store.feedback.likes.slice(0, LIKED_TASTE)).catch(() => []);
|
|
494
|
+
|
|
495
|
+
const near = await nearBoosts;
|
|
436
496
|
const pool = [];
|
|
437
497
|
const seen = new Set();
|
|
438
498
|
for (const origin of ORIGINS) {
|
|
439
499
|
for (const track of await sources[origin]) {
|
|
440
500
|
if (!track?.id || seen.has(track.id) || excluded.has(track.id)) continue;
|
|
441
501
|
seen.add(track.id);
|
|
442
|
-
pool.push({ ...track, origin });
|
|
502
|
+
pool.push({ ...track, origin, ...this.#boostTag(track, near) });
|
|
443
503
|
}
|
|
444
504
|
}
|
|
445
505
|
const trimmed = pool.slice(0, MAX_POOL);
|
|
@@ -447,7 +507,109 @@ export class AiDj {
|
|
|
447
507
|
const covered = trimmed.some((track) => !track.picUrl)
|
|
448
508
|
? await this.pacer.run(() => this.api.withCovers(trimmed)).catch(() => trimmed)
|
|
449
509
|
: trimmed;
|
|
450
|
-
return {
|
|
510
|
+
return {
|
|
511
|
+
pool: covered,
|
|
512
|
+
digest: { ...this.#withLikes(digest, await likedTaste), boosts },
|
|
513
|
+
terms: briefing ? (await briefing).terms : [],
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// ---------------------------------------------------------------- boosts
|
|
518
|
+
|
|
519
|
+
/** A track's similar songs, cached for a day like every similarity list. */
|
|
520
|
+
#similarOf(id) {
|
|
521
|
+
return this.cache
|
|
522
|
+
.get(`similar:${id}`, TTL.similar, () => this.pacer.run(() => this.api.simiSongs(id, { limit: 20 })))
|
|
523
|
+
.catch(() => []);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* What "like this track" means for a boost: its similar songs, or — for a
|
|
528
|
+
* track NetEase has none for, such as 晴天 — its first artist's songs, so a
|
|
529
|
+
* boost is never silently a no-op.
|
|
530
|
+
*/
|
|
531
|
+
async #neighboursOf(boost) {
|
|
532
|
+
const similar = await this.#similarOf(boost.id);
|
|
533
|
+
const artist = boost.artists?.[0];
|
|
534
|
+
if (similar.length > 0 || !artist || !this.api.searchSongs) return similar;
|
|
535
|
+
const songs = await this.cache
|
|
536
|
+
.get(`artist:${artist}`, TTL.similar, () =>
|
|
537
|
+
this.pacer.run(() => this.api.searchSongs(artist, { limit: 20 }).then((result) => result.tracks)),
|
|
538
|
+
)
|
|
539
|
+
.catch(() => []);
|
|
540
|
+
return songs.filter((track) => track.id !== boost.id && (track.artists ?? []).includes(artist));
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* What each boost reaches: its similar songs, and its artists.
|
|
545
|
+
* @returns {Promise<{more: {ids: Set<number>, artists: Set<string>}, less: {ids: Set<number>, artists: Set<string>}}>}
|
|
546
|
+
*/
|
|
547
|
+
async #nearBoosts(boosts) {
|
|
548
|
+
const near = { more: { ids: new Set(), artists: new Set() }, less: { ids: new Set(), artists: new Set() } };
|
|
549
|
+
await Promise.all(
|
|
550
|
+
boosts.map(async (boost) => {
|
|
551
|
+
const reach = near[boost.direction];
|
|
552
|
+
if (!reach) return;
|
|
553
|
+
for (const artist of boost.artists ?? []) reach.artists.add(artist);
|
|
554
|
+
for (const track of await this.#neighboursOf(boost)) reach.ids.add(track.id);
|
|
555
|
+
}),
|
|
556
|
+
);
|
|
557
|
+
return near;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Whether a candidate is near a boost. "Less" wins a tie: steering away is
|
|
562
|
+
* the stronger ask, and a song near both is the one the listener is unsure of.
|
|
563
|
+
*/
|
|
564
|
+
#boostTag(track, near) {
|
|
565
|
+
const touches = (reach) =>
|
|
566
|
+
reach.ids.has(track.id) || (track.artists ?? []).some((artist) => reach.artists.has(artist));
|
|
567
|
+
if (touches(near.less)) return { boost: 'less' };
|
|
568
|
+
if (touches(near.more)) return { boost: 'more' };
|
|
569
|
+
return {};
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Make a fresh boost felt now rather than a batch or two later.
|
|
574
|
+
*
|
|
575
|
+
* "More" queues a few songs like it straight after the current one; "less"
|
|
576
|
+
* takes the DJ's own upcoming picks that are like it out of the queue — never
|
|
577
|
+
* a track the listener queued, and never the one playing. Both only while the
|
|
578
|
+
* DJ is on: with it off, the queue is the listener's alone.
|
|
579
|
+
*
|
|
580
|
+
* @param {{id: number, artists?: string[]}} track
|
|
581
|
+
* @param {'more'|'less'|'none'} direction
|
|
582
|
+
* @returns {Promise<{queued: number, removed: number}>}
|
|
583
|
+
*/
|
|
584
|
+
async applyBoost(track, direction) {
|
|
585
|
+
const effect = { queued: 0, removed: 0 };
|
|
586
|
+
if (!this.player.dj.enabled || !track?.id) return effect;
|
|
587
|
+
const similar = await this.#neighboursOf(track);
|
|
588
|
+
if (direction === 'more') {
|
|
589
|
+
const digest = this.store.tasteDigest();
|
|
590
|
+
const blocked = new Set([...digest.dislikedIds, ...digest.recentIds, ...this.player.queue.map((entry) => entry.id)]);
|
|
591
|
+
const next = sampleInOrder(similar.filter((entry) => entry?.id && !blocked.has(entry.id)), BOOST_NEXT);
|
|
592
|
+
if (next.length === 0) return effect;
|
|
593
|
+
const covered = next.some((entry) => !entry.picUrl)
|
|
594
|
+
? await this.pacer.run(() => this.api.withCovers(next)).catch(() => next)
|
|
595
|
+
: next;
|
|
596
|
+
effect.queued = this.player.insertNext(covered, { source: 'heuristic', queuedBy: 'dj' }).added;
|
|
597
|
+
} else if (direction === 'less') {
|
|
598
|
+
const near = new Set(similar.map((entry) => entry.id));
|
|
599
|
+
const artists = new Set(track.artists ?? []);
|
|
600
|
+
for (let index = this.player.queue.length - 1; index > this.player.index; index -= 1) {
|
|
601
|
+
const entry = this.player.queue[index];
|
|
602
|
+
if (entry.queuedBy !== 'dj') continue;
|
|
603
|
+
if (near.has(entry.id) || (entry.artists ?? []).some((artist) => artists.has(artist))) {
|
|
604
|
+
this.player.remove(index);
|
|
605
|
+
effect.removed += 1;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
if (effect.queued || effect.removed) {
|
|
610
|
+
this.logger?.info?.(`[music] boost ${direction} on ${track.id}: queued ${effect.queued}, removed ${effect.removed}`);
|
|
611
|
+
}
|
|
612
|
+
return effect;
|
|
451
613
|
}
|
|
452
614
|
|
|
453
615
|
/**
|
|
@@ -465,14 +627,42 @@ export class AiDj {
|
|
|
465
627
|
async #tracksByIds(ids) {
|
|
466
628
|
if (ids.length === 0 || !this.api.songDetail) return [];
|
|
467
629
|
const missing = ids.filter((id) => this.cache.peek(`track:${id}`) === undefined);
|
|
468
|
-
|
|
469
|
-
|
|
630
|
+
for (let offset = 0; offset < missing.length; offset += DETAIL_BATCH) {
|
|
631
|
+
const batch = missing.slice(offset, offset + DETAIL_BATCH);
|
|
632
|
+
for (const track of await this.pacer.run(() => this.api.songDetail(batch))) {
|
|
470
633
|
if (track?.id) this.cache.set(`track:${track.id}`, track, TTL.track);
|
|
471
634
|
}
|
|
472
635
|
}
|
|
473
636
|
return ids.map((id) => this.cache.peek(`track:${id}`)).filter(Boolean);
|
|
474
637
|
}
|
|
475
638
|
|
|
639
|
+
/** The pool's quotas: personal sources take over once there is an account. */
|
|
640
|
+
#quota() {
|
|
641
|
+
return this.api.authenticated ? SIGNED_IN_QUOTA : QUOTA;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Fold the account's likes into the taste picture.
|
|
646
|
+
*
|
|
647
|
+
* The history only knows what played through this plugin, and much of that
|
|
648
|
+
* the DJ chose itself; the likes are what the listener chose, anywhere. So
|
|
649
|
+
* a liked track's artists count toward the favourites — twice what a play
|
|
650
|
+
* counts — and the model is shown liked songs by name, not only the few that
|
|
651
|
+
* happen to be in the history.
|
|
652
|
+
*/
|
|
653
|
+
#withLikes(digest, liked) {
|
|
654
|
+
if (liked.length === 0) return digest;
|
|
655
|
+
const scores = this.store.heardArtists();
|
|
656
|
+
for (const track of liked) {
|
|
657
|
+
for (const artist of track.artists ?? []) scores.set(artist, (scores.get(artist) ?? 0) + LIKED_ARTIST_WEIGHT);
|
|
658
|
+
}
|
|
659
|
+
return {
|
|
660
|
+
...digest,
|
|
661
|
+
topArtists: [...scores].sort((a, b) => b[1] - a[1]).slice(0, 8).map(([artist]) => artist),
|
|
662
|
+
liked: sampleInOrder(liked, 15).map((track) => `${track.name} — ${(track.artists ?? []).join('/')}`),
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
|
|
476
666
|
/** A cached list, sampled down to its quota of eligible tracks. */
|
|
477
667
|
async #feedTracks(key, ttlMs, load, quota, excluded) {
|
|
478
668
|
const tracks = await this.cache.get(key, ttlMs, () => this.pacer.run(load));
|
|
@@ -487,21 +677,21 @@ export class AiDj {
|
|
|
487
677
|
}
|
|
488
678
|
|
|
489
679
|
/**
|
|
490
|
-
* Similar tracks for each seed. Every eligible track of the
|
|
491
|
-
* one playing — is kept, and the other seeds
|
|
680
|
+
* Similar tracks for each seed. Every eligible track of the leading seeds —
|
|
681
|
+
* the boosted ones, then the one playing — is kept, and the other seeds
|
|
682
|
+
* share what is left of the quota.
|
|
492
683
|
*/
|
|
493
|
-
async #similarTracks(seeds, excluded) {
|
|
684
|
+
async #similarTracks(seeds, excluded, leading = 1, boosts = []) {
|
|
494
685
|
const lists = await Promise.all(
|
|
495
|
-
seeds.map((seed) =>
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
),
|
|
686
|
+
seeds.map((seed) => {
|
|
687
|
+
const boost = boosts.find((entry) => entry.id === seed);
|
|
688
|
+
return boost ? this.#neighboursOf(boost) : this.#similarOf(seed);
|
|
689
|
+
}),
|
|
500
690
|
);
|
|
501
691
|
const eligible = (tracks) => (tracks ?? []).filter((track) => track?.id && !excluded.has(track.id));
|
|
502
|
-
const
|
|
503
|
-
const lead =
|
|
504
|
-
return [...lead, ...sampleInOrder(
|
|
692
|
+
const eligibleLists = lists.map(eligible);
|
|
693
|
+
const lead = eligibleLists.slice(0, leading).flat().slice(0, this.#quota().similar);
|
|
694
|
+
return [...lead, ...sampleInOrder(eligibleLists.slice(leading).flat(), this.#quota().similar - lead.length)];
|
|
505
695
|
}
|
|
506
696
|
|
|
507
697
|
/**
|
|
@@ -543,7 +733,7 @@ export class AiDj {
|
|
|
543
733
|
*/
|
|
544
734
|
async #chartTracks(excluded) {
|
|
545
735
|
const charts = await Promise.all(CHARTS.map((id) => this.#playlist(id, TTL.chart).catch(() => null)));
|
|
546
|
-
return this.#samplePlaylists(charts.filter(Boolean),
|
|
736
|
+
return this.#samplePlaylists(charts.filter(Boolean), this.#quota().chart, excluded);
|
|
547
737
|
}
|
|
548
738
|
|
|
549
739
|
/**
|
|
@@ -559,7 +749,7 @@ export class AiDj {
|
|
|
559
749
|
`songs:${terms[0]}`,
|
|
560
750
|
TTL.search,
|
|
561
751
|
() => this.api.searchSongs(terms[0], { limit: 30 }).then((result) => result.tracks),
|
|
562
|
-
|
|
752
|
+
this.#quota().promptSongs,
|
|
563
753
|
excluded,
|
|
564
754
|
).catch(() => []);
|
|
565
755
|
const playlists = (async () => {
|
|
@@ -586,7 +776,7 @@ export class AiDj {
|
|
|
586
776
|
}
|
|
587
777
|
const ids = [...chosen.keys()].slice(0, BRIEF_PLAYLISTS);
|
|
588
778
|
const loaded = await Promise.all(ids.map((id) => this.#playlist(id, TTL.playlist).catch(() => null)));
|
|
589
|
-
return this.#samplePlaylists(loaded.filter(Boolean),
|
|
779
|
+
return this.#samplePlaylists(loaded.filter(Boolean), this.#quota().promptPlaylists, excluded);
|
|
590
780
|
})().catch(() => []);
|
|
591
781
|
// Playlist tracks first: they are the stronger match for a mood.
|
|
592
782
|
return { tracks: [...(await playlists), ...(await songs)], terms };
|
|
@@ -721,10 +911,10 @@ export class AiDj {
|
|
|
721
911
|
* Decide which provider route to call.
|
|
722
912
|
*
|
|
723
913
|
* An explicit pin always wins. Otherwise the deployment's own model selection
|
|
724
|
-
* is inherited — `agent-default-model`,
|
|
725
|
-
*
|
|
726
|
-
*
|
|
727
|
-
*
|
|
914
|
+
* is inherited — `agent-default-model`, the same choice the composer picker
|
|
915
|
+
* writes and new conversations start on — so the session model and the DJ's
|
|
916
|
+
* model are two separable decisions that agree by default. Only the choice
|
|
917
|
+
* is inherited; the call itself stays a leaf call. Only when neither exists does discovery run.
|
|
728
918
|
*
|
|
729
919
|
* Discovery is a convenience, not a recommendation: the catalogue's first
|
|
730
920
|
* entry is arbitrary, so pinning both fields is the only way to know which
|
|
@@ -777,7 +967,8 @@ export class AiDj {
|
|
|
777
967
|
const label = (track) => `${track.name} — ${(track.artists ?? []).join('/')}`;
|
|
778
968
|
const catalogue = pool
|
|
779
969
|
.map((track, index) =>
|
|
780
|
-
`${index}. ${label(track)}${track.album ? ` (${track.album})` : ''}${track.origin === 'liked' ? ' [liked]' : ''}`
|
|
970
|
+
`${index}. ${label(track)}${track.album ? ` (${track.album})` : ''}${track.origin === 'liked' ? ' [liked]' : ''}` +
|
|
971
|
+
(track.boost === 'more' ? ' [more]' : track.boost === 'less' ? ' [fewer]' : ''))
|
|
781
972
|
.join('\n');
|
|
782
973
|
const current = this.player.current();
|
|
783
974
|
const upNext = follows ? this.player.remaining().slice(-5) : [];
|
|
@@ -795,6 +986,8 @@ export class AiDj {
|
|
|
795
986
|
digest.topArtists.length ? `Favourite artists: ${digest.topArtists.join(', ')}` : '',
|
|
796
987
|
digest.liked.length ? `Liked: ${digest.liked.join('; ')}` : '',
|
|
797
988
|
digest.disliked.length ? `Disliked (never pick): ${digest.disliked.join('; ')}` : '',
|
|
989
|
+
boostLine(digest.boosts, 'more', 'Right now, more like'),
|
|
990
|
+
boostLine(digest.boosts, 'less', 'Right now, fewer like'),
|
|
798
991
|
digest.skipped.length ? `Skipped early (steer away from these): ${digest.skipped.join('; ')}` : '',
|
|
799
992
|
skippedArtists.length ? `Often skipped artists (skips): ${skippedArtists.join(', ')}` : '',
|
|
800
993
|
'',
|
|
@@ -820,6 +1013,7 @@ export class AiDj {
|
|
|
820
1013
|
'Favour artists the listener likes and the requested mood; keep variety — never place two tracks by the same artist back to back; ' +
|
|
821
1014
|
'avoid anything listed as recently played or disliked, and pick less of what the listener skips. ' +
|
|
822
1015
|
'Candidates marked [liked] are the listener\'s own likes, not heard for a while: mix one in when it fits, but do not fill the set with them. ' +
|
|
1016
|
+
'For the next while the listener asked for more or fewer songs like a few tracks: favour candidates marked [more], and avoid those marked [fewer] unless nothing else fits. ' +
|
|
823
1017
|
'Reply with JSON only, no prose, no code fence: ' +
|
|
824
1018
|
'{"vibe":"<one short line describing the set>","picks":[{"index":<candidate index>,"why":"<max 8 words>"}]}',
|
|
825
1019
|
},
|
|
@@ -922,11 +1116,7 @@ export class AiDj {
|
|
|
922
1116
|
#rank({ pool, digest, count, follows }) {
|
|
923
1117
|
const favourites = new Set(digest.topArtists);
|
|
924
1118
|
const currentArtists = new Set(this.player.current()?.artists ?? []);
|
|
925
|
-
const playedArtists =
|
|
926
|
-
for (const entry of this.store.state.history.slice(0, 60)) {
|
|
927
|
-
if (entry.skipped) continue;
|
|
928
|
-
for (const artist of entry.artists ?? []) playedArtists.set(artist, (playedArtists.get(artist) ?? 0) + 1);
|
|
929
|
-
}
|
|
1119
|
+
const playedArtists = this.store.heardArtists(60);
|
|
930
1120
|
|
|
931
1121
|
const scored = pool.map((track) => {
|
|
932
1122
|
let score = Math.random() * 0.8;
|
|
@@ -935,6 +1125,8 @@ export class AiDj {
|
|
|
935
1125
|
// FM is personalised, similarity is not; a like is a known good song,
|
|
936
1126
|
// weighted lightly so the set stays a discovery rather than a replay.
|
|
937
1127
|
if (track.origin === 'prompt') score += 3.0;
|
|
1128
|
+
if (track.boost === 'more') score += BOOST_WEIGHT;
|
|
1129
|
+
else if (track.boost === 'less') score -= BOOST_WEIGHT;
|
|
938
1130
|
else if (track.origin === 'fm') score += 1.0;
|
|
939
1131
|
else if (track.origin === 'similar') score += 0.6;
|
|
940
1132
|
else if (track.origin === 'liked') score += 0.5;
|
|
@@ -1037,7 +1229,7 @@ export class AiDj {
|
|
|
1037
1229
|
// `play: false` preserves whatever the listener chose, so a top-up while
|
|
1038
1230
|
// paused does not start playback, while a queue refilled after the last
|
|
1039
1231
|
// track ended still resumes because `playing` was already true.
|
|
1040
|
-
this.player.append(plan.tracks, { source: plan.source, play: false });
|
|
1232
|
+
this.player.append(plan.tracks, { source: plan.source, play: false, queuedBy: 'dj' });
|
|
1041
1233
|
this.player.dj = {
|
|
1042
1234
|
...this.player.dj,
|
|
1043
1235
|
busy: false,
|
|
@@ -1076,7 +1268,7 @@ export class AiDj {
|
|
|
1076
1268
|
// The batch replaces the queue, so nothing precedes its first track.
|
|
1077
1269
|
const plan = await this.plan({ prompt: prompt ?? this.store.settings.djPrompt ?? '', count, follows: null });
|
|
1078
1270
|
if (plan.tracks.length > 0) {
|
|
1079
|
-
this.player.setQueue(plan.tracks, { startIndex: 0, play: true, source: plan.source });
|
|
1271
|
+
this.player.setQueue(plan.tracks, { startIndex: 0, play: true, source: plan.source, queuedBy: 'dj' });
|
|
1080
1272
|
this.player.dj.lastPlanAt = Date.now();
|
|
1081
1273
|
this.player.dj.lastPlan = {
|
|
1082
1274
|
source: plan.source,
|
package/lib/index.js
CHANGED
|
@@ -149,8 +149,9 @@ export function apply(ctx, config = {}) {
|
|
|
149
149
|
* The deployment's default model selection: the route a freshly created agent
|
|
150
150
|
* starts on, and the same choice the composer/command model picker writes.
|
|
151
151
|
*
|
|
152
|
-
* This is the seam that makes the
|
|
153
|
-
* separate decisions
|
|
152
|
+
* This is the seam that makes the session's model and the DJ's model two
|
|
153
|
+
* separate decisions; only the choice is shared, since the DJ calls its model
|
|
154
|
+
* directly rather than through an agent. `agent-default-model` owns the first; `dj.provider` /
|
|
154
155
|
* `dj.model` owns the second; and the DJ follows the session model when the
|
|
155
156
|
* plugin pins nothing, instead of picking an arbitrary first route.
|
|
156
157
|
*/
|
|
@@ -224,13 +225,17 @@ export function apply(ctx, config = {}) {
|
|
|
224
225
|
.catch((error) => logger.warn(`[music] account check failed: ${error.message}`));
|
|
225
226
|
|
|
226
227
|
// ---------------------------------------------------------- history + DJ
|
|
228
|
+
// The one place a play is recorded: whenever the current track changes, by
|
|
229
|
+
// whatever path. Recording it again where the queue is set counted every
|
|
230
|
+
// played track twice, and an appended one as a play of the current track.
|
|
227
231
|
let lastRecorded = null;
|
|
228
232
|
player.subscribe(() => {
|
|
229
233
|
const current = player.current();
|
|
230
234
|
if (!current || current.id === lastRecorded) return;
|
|
231
235
|
lastRecorded = current.id;
|
|
232
|
-
store.recordPlay(current);
|
|
236
|
+
store.recordPlay(current, { tentative: current.queuedBy === 'dj' });
|
|
233
237
|
});
|
|
238
|
+
player.onHeard = (track) => store.confirmPlay(track.id);
|
|
234
239
|
|
|
235
240
|
// A periodic sweep catches the cases the track-end hook misses: a paused
|
|
236
241
|
// panel, a failed track, or a DJ that was switched on with a short queue.
|
|
@@ -391,7 +396,6 @@ export function apply(ctx, config = {}) {
|
|
|
391
396
|
if (mode === 'append') player.append(tracks, { source: 'agent' });
|
|
392
397
|
else if (mode === 'next') player.insertNext(tracks, { source: 'agent' });
|
|
393
398
|
else player.setQueue(tracks, { startIndex: 0, play: true, source: 'agent' });
|
|
394
|
-
store.recordPlay(player.current() ?? tracks[0]);
|
|
395
399
|
|
|
396
400
|
const summary = player.summary();
|
|
397
401
|
return {
|
|
@@ -513,7 +517,9 @@ export function apply(ctx, config = {}) {
|
|
|
513
517
|
'Run or configure the continuous AI DJ for the user\'s NetEase Cloud Music panel. ' +
|
|
514
518
|
'With `enabled: true` the DJ keeps the queue stocked: it gathers candidates from similar songs, personal FM, ' +
|
|
515
519
|
'liked songs not heard lately, the daily recommendations, the charts and any mood brief, then either asks the model to choose or scores them by the ' +
|
|
516
|
-
'listener\'s liked artists,
|
|
520
|
+
'listener\'s liked artists and their likes, dislikes and skips. Pass `prompt` for a mood or vibe, and `replan` to refill now. ' +
|
|
521
|
+
'Pass `boost` to steer it for a while — `more` or `less` songs like a track (the playing one by default) for an hour, ' +
|
|
522
|
+
'or `none` to clear — when the listener wants more or fewer like a song without a lasting like or dislike.',
|
|
517
523
|
parameters: {
|
|
518
524
|
type: 'object',
|
|
519
525
|
additionalProperties: false,
|
|
@@ -526,6 +532,13 @@ export function apply(ctx, config = {}) {
|
|
|
526
532
|
description: 'How many tracks to plan (1-25; default 8 for `start`, the player\'s batch size for `replan`).',
|
|
527
533
|
},
|
|
528
534
|
start: { type: 'boolean', description: 'Replace the queue with a freshly planned batch (a full DJ session).' },
|
|
535
|
+
boost: {
|
|
536
|
+
type: 'string',
|
|
537
|
+
enum: ['more', 'less', 'none'],
|
|
538
|
+
description: 'Temporarily steer the DJ toward (`more`) or away from (`less`) songs like a track, or clear its boost (`none`).',
|
|
539
|
+
},
|
|
540
|
+
boostTrackId: { type: 'integer', description: 'The track to boost; defaults to the one playing.' },
|
|
541
|
+
boostMinutes: { type: 'integer', description: 'How long the boost lasts, 5-720 minutes (default 60).' },
|
|
529
542
|
},
|
|
530
543
|
},
|
|
531
544
|
render: (_args, value) => [
|
|
@@ -536,6 +549,15 @@ export function apply(ctx, config = {}) {
|
|
|
536
549
|
(value.modelError ? `Model tier unavailable: ${value.modelError}. ` : '') +
|
|
537
550
|
(value.vibe ? `Vibe: ${value.vibe}. ` : '') +
|
|
538
551
|
(value.searchedAs.length ? `Brief searched as: ${value.searchedAs.join('; ')}. ` : '') +
|
|
552
|
+
(value.boostError ? `Boost not applied: ${value.boostError}. ` : '') +
|
|
553
|
+
(value.boosted
|
|
554
|
+
? `Boost: ${value.boosted.direction === 'more' ? 'more' : 'fewer'} songs like ${value.boosted.name} for ` +
|
|
555
|
+
`${value.boosted.minutes} min${value.boosted.queued ? `, ${value.boosted.queued} queued next` : ''}` +
|
|
556
|
+
`${value.boosted.removed ? `, ${value.boosted.removed} removed from the queue` : ''}. `
|
|
557
|
+
: '') +
|
|
558
|
+
(value.boosts.length
|
|
559
|
+
? `Active boosts: ${value.boosts.map((boost) => `${boost.direction} like ${boost.name} (${boost.minutesLeft} min left)`).join('; ')}. `
|
|
560
|
+
: '') +
|
|
539
561
|
(value.names.length
|
|
540
562
|
? `Queued ${value.added} track(s):\n${value.names.map((entry, index) => `${index + 1}. ${entry}`).join('\n')}`
|
|
541
563
|
: value.note || 'No new tracks were queued.') +
|
|
@@ -547,6 +569,24 @@ export function apply(ctx, config = {}) {
|
|
|
547
569
|
const prompt = args.prompt === undefined ? undefined : String(args.prompt);
|
|
548
570
|
if (enabled !== undefined || prompt !== undefined) dj.setEnabled(enabled ?? player.dj.enabled, { prompt });
|
|
549
571
|
|
|
572
|
+
let boosted = null;
|
|
573
|
+
let boostError = null;
|
|
574
|
+
if (args.boost !== undefined) {
|
|
575
|
+
const trackId = args.boostTrackId ?? player.current()?.id;
|
|
576
|
+
const applied = trackId === undefined
|
|
577
|
+
? { ok: false, reason: 'nothing is playing, so pass boostTrackId' }
|
|
578
|
+
: await router.applyBoost(trackId, String(args.boost), args.boostMinutes);
|
|
579
|
+
if (!applied.ok) boostError = applied.reason;
|
|
580
|
+
else if (applied.boost) {
|
|
581
|
+
boosted = {
|
|
582
|
+
direction: applied.boost.direction,
|
|
583
|
+
name: applied.boost.name,
|
|
584
|
+
minutes: Math.round((applied.boost.until - Date.now()) / 60_000),
|
|
585
|
+
...applied.effect,
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
550
590
|
const count = Math.min(Math.max(Number(args.count) || 8, 1), 25);
|
|
551
591
|
let plan = null;
|
|
552
592
|
if (args.start) {
|
|
@@ -569,6 +609,14 @@ export function apply(ctx, config = {}) {
|
|
|
569
609
|
authenticated: api.authenticated,
|
|
570
610
|
current: summary.current,
|
|
571
611
|
remaining: summary.remaining,
|
|
612
|
+
boosted,
|
|
613
|
+
boostError,
|
|
614
|
+
boosts: store.activeBoosts().map((boost) => ({
|
|
615
|
+
id: boost.id,
|
|
616
|
+
name: boost.name,
|
|
617
|
+
direction: boost.direction,
|
|
618
|
+
minutesLeft: Math.max(Math.round((boost.until - Date.now()) / 60_000), 1),
|
|
619
|
+
})),
|
|
572
620
|
};
|
|
573
621
|
},
|
|
574
622
|
});
|