@audiofool/moondog 0.3.0-beta.9 → 0.3.1
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 +100 -136
- package/package.json +9 -7
- package/scripts/moondog.mjs +47 -9
- package/src/core/apple-projection-domain-services.mjs +4 -0
- package/src/core/capability-catalog.mjs +46 -14
- package/src/core/host.mjs +30 -0
- package/src/core/library-store.mjs +82 -6
- package/src/core/listening-now.mjs +7 -2
- package/src/core/listening-profile-domain-services.mjs +4 -0
- package/src/core/moondog-application.mjs +412 -144
- package/src/i18n/messages/de.mjs +4 -3
- package/src/i18n/messages/en.mjs +4 -3
- package/src/i18n/messages/es.mjs +4 -3
- package/src/i18n/messages/fr.mjs +4 -3
- package/src/i18n/messages/it.mjs +4 -3
- package/src/i18n/messages/ja.mjs +4 -3
- package/src/i18n/messages/ko.mjs +4 -3
- package/src/i18n/messages/pt.mjs +4 -3
- package/src/i18n/messages/zh-Hant.mjs +4 -3
- package/src/i18n/messages/zh.mjs +4 -3
- package/src/i18n/screen/es.mjs +54 -7
- package/src/i18n/screen/ja.mjs +54 -7
- package/src/i18n/screen/pt.mjs +54 -7
- package/src/i18n/screen/zh.mjs +54 -7
- package/src/importers/zip-reader.mjs +61 -0
- package/src/integrations/apple-music/music-app.mjs +3 -2
- package/src/integrations/lastfm/history.mjs +2 -1
- package/src/integrations/lyrics/lrclib.mjs +1 -1
- package/src/integrations/netease/ncm-cli-player.mjs +62 -20
- package/src/integrations/open-music-similarity/artist-radio.mjs +3 -3
- package/src/integrations/playlist-links.mjs +114 -0
- package/src/integrations/public-playlists.mjs +41 -8
- package/src/integrations/spotify/account-data-history.mjs +63 -57
- package/src/integrations/spotify/authentication.mjs +2 -22
- package/src/integrations/spotify/extended-streaming-history.mjs +48 -40
- package/src/integrations/spotify/history-archive.mjs +2 -13
- package/src/integrations/spotify/service.mjs +88 -58
- package/src/integrations/spotify/web-api-client.mjs +12 -4
- package/src/integrations/user-agent.mjs +6 -0
- package/src/integrations/web/codex-web.mjs +3 -1
- package/src/integrations/web/deepseek-web.mjs +1 -1
- package/src/integrations/web/moondog-web.mjs +57 -0
- package/src/integrations/web/web-research.mjs +106 -22
- package/src/integrations/web/web-result.mjs +61 -12
- package/src/integrations/youtube-music/takeout.mjs +11 -16
- package/src/profile/history-import.mjs +3 -1
- package/src/profile/listening-history-store.mjs +55 -1
- package/src/profile/listening-profile-projection.mjs +1 -1
- package/src/profile/music-import-bundle.mjs +3 -1
- package/src/profile/music-providers.mjs +3 -0
- package/src/runtime/pi/agent-runtime.mjs +247 -148
- package/src/runtime/pi/configured-runtime.mjs +4 -1
- package/src/runtime/pi/image-input.mjs +148 -0
- package/src/runtime/pi/memory-agent-runtime.mjs +1 -1
- package/src/runtime/pi/model-roles.mjs +138 -0
- package/src/runtime/pi/model-settings.mjs +141 -6
- package/src/runtime/pi/model-transport.mjs +9 -0
- package/src/runtime/pi/moondog-model.mjs +159 -0
- package/src/runtime/pi/next-songs.mjs +71 -0
- package/src/runtime/pi/persistent-credential-store.mjs +2 -0
- package/src/runtime/pi/profile-build-runtime.mjs +1 -1
- package/src/runtime/pi/public-model-catalog.mjs +11 -4
- package/src/runtime/pi/runtime-settings.mjs +7 -3
- package/src/surfaces/cli/brand-components.mjs +3 -3
- package/src/surfaces/cli/command-completions.mjs +43 -3
- package/src/surfaces/cli/format-output.mjs +19 -7
- package/src/surfaces/cli/invite-command.mjs +65 -0
- package/src/surfaces/cli/model-roles-command.mjs +60 -0
- package/src/surfaces/cli/tui.mjs +91 -5
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
// tracks the listener kept, first in the list, never renamed or deleted. An entry keeps what names the song
|
|
8
8
|
// (title, artist, album, ISRC) and the ids each service found for it, so the same playlist plays on whichever
|
|
9
9
|
// service the listener chose, and any one service can be dropped without losing it.
|
|
10
|
+
//
|
|
11
|
+
// A playlist is made and arranged here. A service gets a copy when the listener exports it: library_exports keeps
|
|
12
|
+
// where that copy is and what it held, so the next export brings the same copy up to date instead of making another.
|
|
10
13
|
import { randomUUID } from "node:crypto";
|
|
11
14
|
import { chmod, mkdir } from "node:fs/promises";
|
|
12
15
|
import path from "node:path";
|
|
@@ -16,7 +19,7 @@ export const LIBRARY_SCHEMA_VERSION = 1;
|
|
|
16
19
|
export const SAVED_PLAYLIST_ID = "saved";
|
|
17
20
|
export const MAX_DEPTH = 4;
|
|
18
21
|
export const MAX_ENTRIES = 2000;
|
|
19
|
-
const ORIGINS = new Set(["listener", "moondog", "spotify", "apple_music", "netease", "file"]);
|
|
22
|
+
const ORIGINS = new Set(["listener", "moondog", "spotify", "apple_music", "netease", "qq_music", "file"]);
|
|
20
23
|
const ADDERS = new Set(["listener", "moondog"]);
|
|
21
24
|
|
|
22
25
|
export const resolveLibraryPath = (environment = process.env) => path.join(resolveMoondogStateDirectory(environment), "library.sqlite");
|
|
@@ -53,6 +56,16 @@ const schema = `
|
|
|
53
56
|
added_by TEXT NOT NULL,
|
|
54
57
|
added_at TEXT NOT NULL
|
|
55
58
|
) STRICT;
|
|
59
|
+
CREATE TABLE IF NOT EXISTS library_exports (
|
|
60
|
+
playlist_id TEXT NOT NULL REFERENCES library_playlists(playlist_id) ON DELETE CASCADE,
|
|
61
|
+
provider TEXT NOT NULL,
|
|
62
|
+
remote_id TEXT NOT NULL,
|
|
63
|
+
url TEXT,
|
|
64
|
+
count INTEGER NOT NULL,
|
|
65
|
+
signature TEXT,
|
|
66
|
+
exported_at TEXT NOT NULL,
|
|
67
|
+
PRIMARY KEY (playlist_id, provider)
|
|
68
|
+
) STRICT;
|
|
56
69
|
CREATE INDEX IF NOT EXISTS library_entries_by_playlist ON library_entries(playlist_id, position);
|
|
57
70
|
CREATE INDEX IF NOT EXISTS library_entries_by_made ON library_entries(made_id) WHERE made_id IS NOT NULL;
|
|
58
71
|
`;
|
|
@@ -125,6 +138,38 @@ const entryOf = (row) => ({
|
|
|
125
138
|
added_at: row.added_at,
|
|
126
139
|
});
|
|
127
140
|
|
|
141
|
+
// A word that goes on past a name is another word: @Night is not in @Nightfall. Chinese and Japanese run on without spaces, so they end it.
|
|
142
|
+
const WORD = /[\p{Script=Latin}\p{N}]/u;
|
|
143
|
+
// Saved goes by its name in each of the window's languages.
|
|
144
|
+
const SAVED_NAMES = ["Saved", "收藏", "保存済み", "저장됨", "Guardadas", "Enregistrés", "Gespeichert", "Salvas", "Salvati"];
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The playlists and folders a listener's messages name with @, newest message first. A longer name wins over one
|
|
148
|
+
* it starts with, so @Night drive is not also @Night.
|
|
149
|
+
*/
|
|
150
|
+
export function libraryMentions({ folders = [], playlists = [] } = {}, texts = [], { limit = 5 } = {}) {
|
|
151
|
+
const names = [
|
|
152
|
+
...playlists.flatMap((playlist) => (playlist.saved ? SAVED_NAMES : [playlist.name]).map((name) => ({ kind: "playlist", id: playlist.id, name }))),
|
|
153
|
+
...folders.map((folder) => ({ kind: "folder", id: folder.id, name: folder.name })),
|
|
154
|
+
].sort((a, b) => b.name.length - a.name.length);
|
|
155
|
+
const found = new Map();
|
|
156
|
+
for (const text of [...texts].reverse()) {
|
|
157
|
+
let rest = String(text ?? "").toLowerCase();
|
|
158
|
+
if (!rest.includes("@")) continue;
|
|
159
|
+
for (const { kind, id, name } of names) {
|
|
160
|
+
const wanted = `@${name.toLowerCase()}`;
|
|
161
|
+
for (let at = rest.indexOf(wanted); at >= 0; at = rest.indexOf(wanted, at + 1)) {
|
|
162
|
+
const end = at + wanted.length;
|
|
163
|
+
if ((at > 0 && WORD.test(rest[at - 1])) || (end < rest.length && WORD.test(rest[end]) && WORD.test(wanted.at(-1)))) continue;
|
|
164
|
+
if (!found.has(`${kind}:${id}`)) found.set(`${kind}:${id}`, { kind, id });
|
|
165
|
+
rest = rest.slice(0, at) + " ".repeat(wanted.length) + rest.slice(end);
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return [...found.values()].slice(0, limit);
|
|
171
|
+
}
|
|
172
|
+
|
|
128
173
|
export class LibraryStore {
|
|
129
174
|
#database;
|
|
130
175
|
#clock;
|
|
@@ -204,8 +249,9 @@ export class LibraryStore {
|
|
|
204
249
|
}
|
|
205
250
|
|
|
206
251
|
/**
|
|
207
|
-
* The tree the sidebar draws: folders, and playlists with their counts and a cover (the
|
|
208
|
-
*
|
|
252
|
+
* The tree the sidebar draws: folders, and playlists with their counts and a cover (the playlist's own from
|
|
253
|
+
* where it was imported, else the first entry's artwork or the first made track, whose cover the window draws),
|
|
254
|
+
* Saved among them.
|
|
209
255
|
*/
|
|
210
256
|
view() {
|
|
211
257
|
this.#open();
|
|
@@ -220,12 +266,13 @@ export class LibraryStore {
|
|
|
220
266
|
}
|
|
221
267
|
return null;
|
|
222
268
|
};
|
|
223
|
-
const
|
|
269
|
+
const ownCover = (row) => (row.source_json ? JSON.parse(row.source_json).cover : null);
|
|
270
|
+
const playlists = this.#database.prepare(`SELECT p.playlist_id, p.folder_id, p.name, p.origin, p.source_json, p.position, p.updated_at,
|
|
224
271
|
(SELECT COUNT(*) FROM library_entries e WHERE e.playlist_id = p.playlist_id) AS count,
|
|
225
272
|
(SELECT COUNT(*) FROM library_entries e WHERE e.playlist_id = p.playlist_id AND e.kind = 'made') AS made
|
|
226
273
|
FROM library_playlists p`).all()
|
|
227
274
|
.map((row) => ({ id: row.playlist_id, folderId: row.folder_id ?? null, name: row.name, origin: row.origin, position: row.position,
|
|
228
|
-
updatedAt: row.updated_at, count: row.count, made: row.made, cover: coverOf(row.playlist_id),
|
|
275
|
+
updatedAt: row.updated_at, count: row.count, made: row.made, cover: ownCover(row) ? { artwork_url: ownCover(row) } : coverOf(row.playlist_id),
|
|
229
276
|
...(row.playlist_id === SAVED_PLAYLIST_ID ? { saved: true } : {}) }));
|
|
230
277
|
return { folders, playlists };
|
|
231
278
|
}
|
|
@@ -236,9 +283,12 @@ export class LibraryStore {
|
|
|
236
283
|
const row = this.#database.prepare("SELECT * FROM library_playlists WHERE playlist_id = ?").get(String(id ?? ""));
|
|
237
284
|
if (!row) return null;
|
|
238
285
|
const entries = this.#database.prepare("SELECT * FROM library_entries WHERE playlist_id = ? ORDER BY position, added_at").all(row.playlist_id).map(entryOf);
|
|
286
|
+
const exports = this.#database.prepare("SELECT provider, remote_id, url, count, signature, exported_at FROM library_exports WHERE playlist_id = ? ORDER BY provider")
|
|
287
|
+
.all(row.playlist_id).map((copy) => ({ provider: copy.provider, id: copy.remote_id, url: copy.url ?? null, count: copy.count,
|
|
288
|
+
signature: copy.signature ?? null, exportedAt: copy.exported_at }));
|
|
239
289
|
return { id: row.playlist_id, folderId: row.folder_id ?? null, name: row.name, origin: row.origin,
|
|
240
290
|
...(row.source_json ? { source: JSON.parse(row.source_json) } : {}), createdAt: row.created_at, updatedAt: row.updated_at,
|
|
241
|
-
...(row.playlist_id === SAVED_PLAYLIST_ID ? { saved: true } : {}), entries };
|
|
291
|
+
...(row.playlist_id === SAVED_PLAYLIST_ID ? { saved: true } : {}), ...(exports.length ? { exports } : {}), entries };
|
|
242
292
|
}
|
|
243
293
|
|
|
244
294
|
/** Playlists whose names hold the words, best first, for the agent and the terminal. */
|
|
@@ -411,6 +461,32 @@ export class LibraryStore {
|
|
|
411
461
|
});
|
|
412
462
|
}
|
|
413
463
|
|
|
464
|
+
/** An imported playlist's own cover, found after it came in. */
|
|
465
|
+
setPlaylistCover(playlistId, cover) {
|
|
466
|
+
return this.#transaction(() => {
|
|
467
|
+
const id = cleanId(playlistId, "Playlist");
|
|
468
|
+
const row = this.#database.prepare("SELECT source_json FROM library_playlists WHERE playlist_id = ?").get(id);
|
|
469
|
+
if (!row?.source_json) return;
|
|
470
|
+
this.#database.prepare("UPDATE library_playlists SET source_json = ? WHERE playlist_id = ?").run(JSON.stringify({ ...JSON.parse(row.source_json), cover }), id);
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Keeps where a playlist's copy on a service is, after an export: the copy's id and link there, how many songs
|
|
476
|
+
* it took, and a signature of what it held, which tells a later export whether the copy was changed there.
|
|
477
|
+
*/
|
|
478
|
+
rememberExport(playlistId, { provider, id, url, count, signature } = {}) {
|
|
479
|
+
return this.#transaction(() => {
|
|
480
|
+
const playlist = cleanId(playlistId, "Playlist");
|
|
481
|
+
this.#requirePlaylist(playlist);
|
|
482
|
+
this.#database.prepare(`INSERT INTO library_exports(playlist_id, provider, remote_id, url, count, signature, exported_at) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
483
|
+
ON CONFLICT(playlist_id, provider) DO UPDATE SET remote_id = excluded.remote_id, url = excluded.url, count = excluded.count,
|
|
484
|
+
signature = excluded.signature, exported_at = excluded.exported_at`)
|
|
485
|
+
.run(playlist, cleanId(provider, "Service"), cleanId(id, "Copy"), cleanText(url, 400, "Link", { optional: true }),
|
|
486
|
+
Number.isInteger(count) && count >= 0 ? count : 0, cleanText(signature, 128, "Signature", { optional: true }), this.#now());
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
|
|
414
490
|
/** Moves entries, in their order, before another entry or to the end. */
|
|
415
491
|
moveEntries(playlistId, entryIds, beforeId = null) {
|
|
416
492
|
return this.#transaction(() => {
|
|
@@ -156,6 +156,11 @@ export function createPlayerNow() {
|
|
|
156
156
|
if (event?.type === "queue" && Array.isArray(event.tracks)) { this.queued(event.tracks); return; }
|
|
157
157
|
if (!queue) return;
|
|
158
158
|
if (event?.type === "stopped") { queue = null; return; }
|
|
159
|
+
// A song the listener took out of Up next keeps its place, so the positions the player reports still match.
|
|
160
|
+
if (event?.type === "removed") {
|
|
161
|
+
if (Number.isInteger(event.position) && event.position > queue.index + 1 && event.position <= queue.tracks.length) queue.tracks[event.position - 1].removed = true;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
159
164
|
if (Number.isInteger(event?.position) && event.position >= 1 && event.position <= queue.tracks.length) queue.index = event.position - 1;
|
|
160
165
|
if (event?.type === "playing" || event?.type === "paused" || event?.type === "loading") queue.state = event.type;
|
|
161
166
|
},
|
|
@@ -164,7 +169,7 @@ export function createPlayerNow() {
|
|
|
164
169
|
},
|
|
165
170
|
/** The song playing and every one after it, for keeping the whole queue: read() shows only ten. */
|
|
166
171
|
remaining() {
|
|
167
|
-
return queue ? queue.tracks.slice(queue.index).map((track) => ({ ...track })) : [];
|
|
172
|
+
return queue ? queue.tracks.slice(queue.index).filter((track) => !track.removed).map((track) => ({ ...track })) : [];
|
|
168
173
|
},
|
|
169
174
|
/** null when nothing is queued, or { state, song, position, count, next } with up to ten songs after it. */
|
|
170
175
|
read() {
|
|
@@ -175,7 +180,7 @@ export function createPlayerNow() {
|
|
|
175
180
|
song: { ...queue.tracks[queue.index] },
|
|
176
181
|
position: queue.index + 1,
|
|
177
182
|
count: queue.tracks.length,
|
|
178
|
-
next: queue.tracks.slice(queue.index + 1
|
|
183
|
+
next: queue.tracks.slice(queue.index + 1).filter((track) => !track.removed).slice(0, 10).map((track) => ({ ...track })),
|
|
179
184
|
};
|
|
180
185
|
},
|
|
181
186
|
};
|
|
@@ -506,6 +506,10 @@ export class ListeningProfileDomainServices {
|
|
|
506
506
|
return this.#store.recentAttention?.({ subjectId: this.#subjectId }) ?? null;
|
|
507
507
|
}
|
|
508
508
|
|
|
509
|
+
listeningDays() {
|
|
510
|
+
return this.#store.listeningDays?.({ subjectId: this.#subjectId }) ?? null;
|
|
511
|
+
}
|
|
512
|
+
|
|
509
513
|
// Moondog's suggestions ledger and the declared mix (src/profile/moondog-suggestions.mjs).
|
|
510
514
|
recordMoondogSuggestions(entries) {
|
|
511
515
|
return this.#store.recordMoondogSuggestions?.({ entries }) ?? null;
|