deep-roon-mcp 0.5.0 → 0.5.2

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.
@@ -9914,9 +9914,16 @@ async function exportPlayHistory(client2, options) {
9914
9914
  if (client2.graph.findByType("HistoryPlay").length > 0) {
9915
9915
  throw new Error("history export requires a fresh client graph with no HistoryPlay objects");
9916
9916
  }
9917
- const criteria2 = inlineStruct(
9918
- client2.remoting.defineType("Sooloos.Broker.Api.HistoryQueryCriteria", [])
9919
- );
9917
+ const dateField = /* @__PURE__ */ __name((which, d) => ({
9918
+ name: `System.DateTime? Sooloos.Broker.Api.HistoryQueryCriteria::${which}`,
9919
+ propType: 18 /* NullableDateTime */,
9920
+ value: new BinaryWriter().boolean(true).long(BigInt(d.getTime()) * 10000n + UNIX_EPOCH_TICKS | 1n << 62n).toBuffer()
9921
+ }), "dateField");
9922
+ const dates = [
9923
+ ...options.minDate ? [dateField("MinPlayDate", options.minDate)] : [],
9924
+ ...options.maxDate ? [dateField("MaxPlayDate", options.maxDate)] : []
9925
+ ];
9926
+ const criteria2 = dates.length ? client2.structArg("Sooloos.Broker.Api.HistoryQueryCriteria", dates) : inlineStruct(client2.remoting.defineType("Sooloos.Broker.Api.HistoryQueryCriteria", []));
9920
9927
  const params = client2.structArg("Sooloos.Broker.Api.VirtualQueryParameters", [
9921
9928
  {
9922
9929
  name: "int Sooloos.Broker.Api.VirtualQueryParameters::PageSize",
@@ -9958,7 +9965,12 @@ async function exportPlayHistory(client2, options) {
9958
9965
  }
9959
9966
  return plays.size;
9960
9967
  }, "harvest");
9968
+ let complete = true;
9961
9969
  for (let page = 0; page < Math.ceil(target2 / pageSize); page++) {
9970
+ if (page > 0 && (options.deadline && Date.now() > options.deadline || options.enough && options.enough(snapshots.map((x) => x.event).filter((e) => !!e)))) {
9971
+ complete = false;
9972
+ break;
9973
+ }
9962
9974
  let acquired = false;
9963
9975
  try {
9964
9976
  const retained = await client2.remoting.callMethod(
@@ -10039,7 +10051,7 @@ async function exportPlayHistory(client2, options) {
10039
10051
  events.push(snapshot.event);
10040
10052
  if (events.length >= target2) break;
10041
10053
  }
10042
- return { total, events, skipped, duplicates };
10054
+ return { total, events, skipped, duplicates, complete };
10043
10055
  } finally {
10044
10056
  client2.remoting.callMethodNoReply(queryOid, SIG_DISPOSE, Buffer.alloc(0));
10045
10057
  }
@@ -15526,7 +15538,7 @@ var require_lib2 = __commonJS({
15526
15538
  var version2;
15527
15539
  var init_package = __esm({
15528
15540
  "package.json"() {
15529
- version2 = "0.5.0";
15541
+ version2 = "0.5.2";
15530
15542
  }
15531
15543
  });
15532
15544
 
@@ -49482,10 +49494,24 @@ init_intern();
49482
49494
  init_session();
49483
49495
  init_graph();
49484
49496
  init_library();
49485
- async function history(limit3) {
49497
+ var PAGE = 500;
49498
+ var BUDGET_MS = 45e3;
49499
+ var at = /* @__PURE__ */ __name((e) => Date.parse(e.playedAt), "at");
49500
+ async function history(limit3, offset2 = 0, before, since) {
49486
49501
  return withCore(async (first) => {
49487
49502
  const c = first.graph.findByType("HistoryPlay").length > 0 ? await fresh() : first;
49488
- const out = await exportPlayHistory(c, { limit: Math.min(Math.max(0, limit3), 500) });
49503
+ const n = Math.min(Math.max(0, limit3), 500), skip = Math.max(0, offset2);
49504
+ const cutoff = before ? Date.parse(before) : null;
49505
+ const all = await exportPlayHistory(c, {
49506
+ limit: skip + n,
49507
+ pageSize: PAGE,
49508
+ timeoutMs: 15e3,
49509
+ deadline: Date.now() + BUDGET_MS,
49510
+ maxDate: cutoff === null ? void 0 : new Date(cutoff),
49511
+ minDate: since ? new Date(Date.parse(since)) : void 0
49512
+ });
49513
+ const picked = (cutoff === null ? all.events : all.events.filter((e) => at(e) < cutoff)).slice(skip, skip + n);
49514
+ const out = { ...all, events: picked };
49489
49515
  const keys = [...new Set(out.events.map((e) => e.roonTrackId).filter((k) => !!k))].slice(0, 100);
49490
49516
  const byKey = /* @__PURE__ */ new Map();
49491
49517
  if (keys.length) {
@@ -49493,8 +49519,11 @@ async function history(limit3) {
49493
49519
  for (const t of tracks2) if (t) byKey.set(String(field2(t, "TrackId")), t);
49494
49520
  }
49495
49521
  closeSoon("after the history");
49522
+ const oldest = all.events.length ? localTime(at(all.events[all.events.length - 1])) : null;
49496
49523
  return {
49497
49524
  total: out.total ?? null,
49525
+ // When the budget ran out before the asked plays: how far back it got (a smaller offset or a later `before` helps).
49526
+ note: all.complete === false && picked.length < n ? `Roon's history is long: this reached back to ${oldest} within the time \u2014 ask with a \`before\` date to start further back.` : void 0,
49498
49527
  plays: out.events.map((e) => {
49499
49528
  const r = { at: localTime(e.playedAt), title: e.title, artist: clean(e.artist), album: e.album ?? void 0, played_pct: e.completionPct ?? void 0, track_key: e.roonTrackId ?? void 0 };
49500
49529
  const t = e.roonTrackId ? byKey.get(e.roonTrackId) : void 0;
@@ -49511,29 +49540,44 @@ async function history(limit3) {
49511
49540
  });
49512
49541
  }
49513
49542
  __name(history, "history");
49514
- async function top(what, limit3, since) {
49543
+ async function top(what, limit3, since, until) {
49515
49544
  return withCore(async (first) => {
49516
49545
  const c = first.graph.findByType("HistoryPlay").length > 0 ? await fresh() : first;
49517
- const out = await exportPlayHistory(c, { limit: 2e4, timeoutMs: 8e3 });
49518
- closeSoon("after the history");
49519
49546
  const from = since ? Date.parse(since) : null;
49547
+ const out = await exportPlayHistory(c, {
49548
+ limit: Number.MAX_SAFE_INTEGER,
49549
+ pageSize: PAGE,
49550
+ timeoutMs: 15e3,
49551
+ deadline: Date.now() + BUDGET_MS,
49552
+ minDate: from === null ? void 0 : new Date(from),
49553
+ maxDate: until ? new Date(Date.parse(until)) : void 0
49554
+ });
49555
+ closeSoon("after the history");
49520
49556
  const count = /* @__PURE__ */ new Map();
49521
49557
  let counted = 0, earliest = null;
49522
49558
  for (const e of out.events) {
49523
- const at = Date.parse(e.playedAt);
49524
- if (from && at < from) continue;
49559
+ const at2 = Date.parse(e.playedAt);
49560
+ if (from && at2 < from) continue;
49525
49561
  if (typeof e.completionPct === "number" && e.completionPct < 50) continue;
49526
49562
  counted += 1;
49527
- if (earliest === null || at < earliest) earliest = at;
49563
+ if (earliest === null || at2 < earliest) earliest = at2;
49528
49564
  const artist = clean(e.artist);
49529
49565
  const key = what === "artists" ? artist : what === "tracks" ? `${e.title}\0${artist}` : `${e.album ?? "?"}\0${artist}`;
49530
49566
  const r = count.get(key) ?? { plays: 0, last: 0, title: what === "tracks" ? e.title : void 0, album: what === "albums" ? e.album ?? void 0 : void 0, artist };
49531
49567
  r.plays += 1;
49532
- if (at > r.last) r.last = at;
49568
+ if (at2 > r.last) r.last = at2;
49533
49569
  count.set(key, r);
49534
49570
  }
49535
49571
  const rows = [...count.values()].sort((a, b) => b.plays - a.plays || b.last - a.last).slice(0, Math.min(Math.max(1, limit3), 100)).map((r) => ({ plays: r.plays, title: r.title, album: r.album, artist: r.artist, last_played: localTime(r.last) }));
49536
- return { what, plays_counted: counted, plays_in_roon: out.total ?? null, from: earliest ? localTime(earliest) : null, rows };
49572
+ const reachedAll = out.complete !== false;
49573
+ return {
49574
+ what,
49575
+ plays_counted: counted,
49576
+ plays_in_roon: out.total ?? null,
49577
+ from: earliest ? localTime(earliest) : null,
49578
+ note: reachedAll ? void 0 : `Counted back to ${earliest ? localTime(earliest) : "?"} \u2014 Roon's history goes further, but the rest didn't fit in the time. Use \`since\` for a period.`,
49579
+ rows
49580
+ };
49537
49581
  });
49538
49582
  }
49539
49583
  __name(top, "top");
@@ -49784,8 +49828,8 @@ async function playTracks(keys, zoneName, how) {
49784
49828
  const br = new BinaryReader(Uint8Array.from(rr.payload));
49785
49829
  br.integer();
49786
49830
  const total = br.flexInt();
49787
- const at = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
49788
- queued = Math.max(0, total - at);
49831
+ const at2 = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
49832
+ queued = Math.max(0, total - at2);
49789
49833
  }
49790
49834
  }
49791
49835
  return {
@@ -49903,10 +49947,10 @@ __name(queueRow, "queueRow");
49903
49947
  async function queueItemAt(c, zoneName, n) {
49904
49948
  const { z: z2, q } = queueOf(c, zoneName);
49905
49949
  const refs = await queueItems(c, q);
49906
- const at = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
49907
- const oid = refs[at + n - 1];
49908
- if (oid === void 0) throw new RoonError(`The queue of ${z2.name} has no item ${n} (${Math.max(0, refs.length - at)} from here)`, "invalid");
49909
- return { z: z2, q, oid, refs, at };
49950
+ const at2 = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
49951
+ const oid = refs[at2 + n - 1];
49952
+ if (oid === void 0) throw new RoonError(`The queue of ${z2.name} has no item ${n} (${Math.max(0, refs.length - at2)} from here)`, "invalid");
49953
+ return { z: z2, q, oid, refs, at: at2 };
49910
49954
  }
49911
49955
  __name(queueItemAt, "queueItemAt");
49912
49956
  async function queueJump(zoneName, n) {
@@ -49923,22 +49967,22 @@ async function queueRemove(zoneName, ns) {
49923
49967
  return withCore(async (c) => {
49924
49968
  const { z: z2, q } = queueOf(c, zoneName);
49925
49969
  const refs = await queueItems(c, q);
49926
- const at = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
49927
- const oids = [...new Set(ns)].map((n) => refs[at + n - 1]).filter((o) => o !== void 0);
49970
+ const at2 = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
49971
+ const oids = [...new Set(ns)].map((n) => refs[at2 + n - 1]).filter((o) => o !== void 0);
49928
49972
  if (!oids.length) throw new RoonError("No such items in the queue", "invalid");
49929
49973
  c.remoting.callMethodNoReply(q.oid, formatMethodSignature("Queue", "RemoveItems", [{ type: "IEnumerable<TransportItem>", name: "items" }]), buildArgs([Arg.collection(oids.map((o) => buildArgs([Arg.ref(o)])))]));
49930
49974
  log(`queue_remove: ${z2.name} \u2212 ${oids.length} item(s)`);
49931
49975
  await wait(300);
49932
49976
  const after = await queueItems(c, q);
49933
- return { ok: true, zone: z2.name, removed: oids.length, left: Math.max(0, after.length - at) };
49977
+ return { ok: true, zone: z2.name, removed: oids.length, left: Math.max(0, after.length - at2) };
49934
49978
  });
49935
49979
  }
49936
49980
  __name(queueRemove, "queueRemove");
49937
49981
  var INSERTION = { before: 3, after: 2 };
49938
49982
  async function queueMove(zoneName, n, to, where) {
49939
49983
  return withCore(async (c) => {
49940
- const { z: z2, q, oid, refs, at } = await queueItemAt(c, zoneName, n);
49941
- const rel = refs[at + to - 1];
49984
+ const { z: z2, q, oid, refs, at: at2 } = await queueItemAt(c, zoneName, n);
49985
+ const rel = refs[at2 + to - 1];
49942
49986
  if (rel === void 0 || to === n) throw new RoonError(`The queue of ${z2.name} has no item ${to} to move next to`, "invalid");
49943
49987
  const point = INSERTION[where];
49944
49988
  const res = await c.call(
@@ -49952,7 +49996,7 @@ async function queueMove(zoneName, n, to, where) {
49952
49996
  log(`queue_move: ${z2.name} item ${n} \u2192 ${where} ${to} (point ${point})`);
49953
49997
  await wait(300);
49954
49998
  const after = await queueItems(c, q);
49955
- const now = after.indexOf(oid) - at + 1;
49999
+ const now = after.indexOf(oid) - at2 + 1;
49956
50000
  return { ok: true, zone: z2.name, moved: n, now_at: now > 0 ? now : void 0 };
49957
50001
  });
49958
50002
  }
@@ -49961,11 +50005,11 @@ async function queue2(zoneName, limit3) {
49961
50005
  return withCore(async (c) => {
49962
50006
  const { z: z2, q } = queueOf(c, zoneName);
49963
50007
  const refs = await queueItems(c, q);
49964
- const at = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
49965
- const view = refs.slice(at, at + Math.min(Math.max(1, limit3), 200));
50008
+ const at2 = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
50009
+ const view = refs.slice(at2, at2 + Math.min(Math.max(1, limit3), 200));
49966
50010
  const end = Date.now() + 2500;
49967
50011
  while (Date.now() < end && view.some((oid) => queueRow(c, oid).title === null)) await wait(50);
49968
- return { zone: z2.name, left: Math.max(0, refs.length - at), rows: view.map((oid, i) => ({ n: i + 1, now: i === 0 || void 0, ...queueRow(c, oid) })) };
50012
+ return { zone: z2.name, left: Math.max(0, refs.length - at2), rows: view.map((oid, i) => ({ n: i + 1, now: i === 0 || void 0, ...queueRow(c, oid) })) };
49969
50013
  });
49970
50014
  }
49971
50015
  __name(queue2, "queue");
@@ -49977,8 +50021,8 @@ async function queueClear(zoneName, everything) {
49977
50021
  return { ok: true, zone: z2.name, removed: "everything" };
49978
50022
  }
49979
50023
  const refs = await queueItems(c, q);
49980
- const at = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
49981
- const after = refs.slice(at + 1);
50024
+ const at2 = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
50025
+ const after = refs.slice(at2 + 1);
49982
50026
  if (after.length) c.remoting.callMethodNoReply(
49983
50027
  q.oid,
49984
50028
  "Sooloos.Broker.Api.Queue::RemoveItems(System.Collections.Generic.IEnumerable<Sooloos.Broker.Api.TransportItem>)",
@@ -50568,16 +50612,26 @@ function registerReadTools(server, internal = true) {
50568
50612
  }, ({ category, genre, limit: n }) => run(() => radio(category, genre, n ?? 40)));
50569
50613
  reg("roon_history", {
50570
50614
  title: "Play history",
50571
- description: `What was played in Roon, newest first \u2014 Roon's own play history, with how much of each track was heard. For "most played" questions use roon_top instead of counting this.`,
50572
- inputSchema: { limit: limit(300, 30) },
50615
+ description: 'What was played in Roon, newest first \u2014 Roon\'s own play history, with how much of each track was heard. Goes back as far as Roon\'s history does \u2014 Roon filters by date itself: `since` and `before` (YYYY-MM-DD) give the plays in that window (e.g. "what did I play in March 2019": since 2019-03-01, before 2019-04-01; up to 500 per call, `offset` for the next ones). For "most played" questions use roon_top instead of counting this.',
50616
+ inputSchema: {
50617
+ limit: limit(500, 30),
50618
+ offset: external_exports.number().int().min(0).optional(),
50619
+ since: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe("Only plays from this date on (YYYY-MM-DD)."),
50620
+ before: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe("Only plays before this date (YYYY-MM-DD).")
50621
+ },
50573
50622
  annotations: READ
50574
- }, ({ limit: n }) => run(() => history(n ?? 30)));
50623
+ }, ({ limit: n, offset: offset2, since, before }) => run(() => history(n ?? 30, offset2 ?? 0, before, since)));
50575
50624
  reg("roon_top", {
50576
50625
  title: "Most played",
50577
- description: 'The most played albums, artists or tracks in Roon, counted over the WHOLE play history (a play counts when at least half the track was heard). Use this for "most listened" questions \u2014 don\'t tally roon_history yourself. `since` (YYYY-MM-DD) limits the period.',
50578
- inputSchema: { what: external_exports.enum(["albums", "artists", "tracks"]).optional(), limit: limit(100, 20), since: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe("Only plays from this date on (YYYY-MM-DD).") },
50626
+ description: 'The most played albums, artists or tracks in Roon, counted over the WHOLE play history (a play counts when at least half the track was heard). Use this for "most listened" questions \u2014 don\'t tally roon_history yourself. `since` and `until` (YYYY-MM-DD) limit the period \u2014 Roon filters by date itself, however far back: "what did I play most in March 2019" is since 2019-03-01, until 2019-04-01.',
50627
+ inputSchema: {
50628
+ what: external_exports.enum(["albums", "artists", "tracks"]).optional(),
50629
+ limit: limit(100, 20),
50630
+ since: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe("Only plays from this date on (YYYY-MM-DD)."),
50631
+ until: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe("Only plays before this date (YYYY-MM-DD).")
50632
+ },
50579
50633
  annotations: READ
50580
- }, ({ what, limit: n, since }) => run(() => top(what ?? "albums", n ?? 20, since)));
50634
+ }, ({ what, limit: n, since, until }) => run(() => top(what ?? "albums", n ?? 20, since, until)));
50581
50635
  }
50582
50636
  __name(registerReadTools, "registerReadTools");
50583
50637
 
@@ -51164,8 +51218,8 @@ async function listenLater(includePlayed) {
51164
51218
  const rows = list.map((it) => {
51165
51219
  const o = obj(c, thing(it));
51166
51220
  const r = { ...o ? resultRow(c, o) : { kind: field2(it, "DataType") ?? "?" }, state: { 1: "waiting", 2: "played" }[field2(it, "State")] ?? "none" };
51167
- const at = dotnetDate(field2(it, "Timestamp"));
51168
- if (at) r.added = at;
51221
+ const at2 = dotnetDate(field2(it, "Timestamp"));
51222
+ if (at2) r.added = at2;
51169
51223
  return r;
51170
51224
  }).filter((r) => includePlayed || r.state === "waiting").sort((a, b) => String(b.added ?? "").localeCompare(String(a.added ?? ""))).map((r) => ({ ...r, added: localTime(r.added) }));
51171
51225
  return { waiting: list.filter((it) => field2(it, "State") === 1).length, rows };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deep-roon-mcp",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "An MCP server for Roon that reaches the parts the official API doesn't: reviews, biographies, Qobuz's and TIDAL's shelves, TIDAL's playlists, your history, search across your library and the streaming services",
5
5
  "license": "Apache-2.0",
6
6
  "author": "René Bouwmeester <21277119+renebouwmeester@users.noreply.github.com>",