deep-roon-mcp 0.5.0 → 0.5.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.
@@ -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.1";
15530
15542
  }
15531
15543
  });
15532
15544
 
@@ -49482,10 +49494,23 @@ 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) {
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
+ });
49512
+ const picked = (cutoff === null ? all.events : all.events.filter((e) => at(e) < cutoff)).slice(skip, skip + n);
49513
+ const out = { ...all, events: picked };
49489
49514
  const keys = [...new Set(out.events.map((e) => e.roonTrackId).filter((k) => !!k))].slice(0, 100);
49490
49515
  const byKey = /* @__PURE__ */ new Map();
49491
49516
  if (keys.length) {
@@ -49493,8 +49518,11 @@ async function history(limit3) {
49493
49518
  for (const t of tracks2) if (t) byKey.set(String(field2(t, "TrackId")), t);
49494
49519
  }
49495
49520
  closeSoon("after the history");
49521
+ const oldest = all.events.length ? localTime(at(all.events[all.events.length - 1])) : null;
49496
49522
  return {
49497
49523
  total: out.total ?? null,
49524
+ // When the budget ran out before the asked plays: how far back it got (a smaller offset or a later `before` helps).
49525
+ 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
49526
  plays: out.events.map((e) => {
49499
49527
  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
49528
  const t = e.roonTrackId ? byKey.get(e.roonTrackId) : void 0;
@@ -49514,26 +49542,40 @@ __name(history, "history");
49514
49542
  async function top(what, limit3, since) {
49515
49543
  return withCore(async (first) => {
49516
49544
  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
49545
  const from = since ? Date.parse(since) : null;
49546
+ const out = await exportPlayHistory(c, {
49547
+ limit: Number.MAX_SAFE_INTEGER,
49548
+ pageSize: PAGE,
49549
+ timeoutMs: 15e3,
49550
+ deadline: Date.now() + BUDGET_MS,
49551
+ minDate: from === null ? void 0 : new Date(from)
49552
+ });
49553
+ closeSoon("after the history");
49520
49554
  const count = /* @__PURE__ */ new Map();
49521
49555
  let counted = 0, earliest = null;
49522
49556
  for (const e of out.events) {
49523
- const at = Date.parse(e.playedAt);
49524
- if (from && at < from) continue;
49557
+ const at2 = Date.parse(e.playedAt);
49558
+ if (from && at2 < from) continue;
49525
49559
  if (typeof e.completionPct === "number" && e.completionPct < 50) continue;
49526
49560
  counted += 1;
49527
- if (earliest === null || at < earliest) earliest = at;
49561
+ if (earliest === null || at2 < earliest) earliest = at2;
49528
49562
  const artist = clean(e.artist);
49529
49563
  const key = what === "artists" ? artist : what === "tracks" ? `${e.title}\0${artist}` : `${e.album ?? "?"}\0${artist}`;
49530
49564
  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
49565
  r.plays += 1;
49532
- if (at > r.last) r.last = at;
49566
+ if (at2 > r.last) r.last = at2;
49533
49567
  count.set(key, r);
49534
49568
  }
49535
49569
  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 };
49570
+ const reachedAll = out.complete !== false;
49571
+ return {
49572
+ what,
49573
+ plays_counted: counted,
49574
+ plays_in_roon: out.total ?? null,
49575
+ from: earliest ? localTime(earliest) : null,
49576
+ 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.`,
49577
+ rows
49578
+ };
49537
49579
  });
49538
49580
  }
49539
49581
  __name(top, "top");
@@ -49784,8 +49826,8 @@ async function playTracks(keys, zoneName, how) {
49784
49826
  const br = new BinaryReader(Uint8Array.from(rr.payload));
49785
49827
  br.integer();
49786
49828
  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);
49829
+ const at2 = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
49830
+ queued = Math.max(0, total - at2);
49789
49831
  }
49790
49832
  }
49791
49833
  return {
@@ -49903,10 +49945,10 @@ __name(queueRow, "queueRow");
49903
49945
  async function queueItemAt(c, zoneName, n) {
49904
49946
  const { z: z2, q } = queueOf(c, zoneName);
49905
49947
  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 };
49948
+ const at2 = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
49949
+ const oid = refs[at2 + n - 1];
49950
+ 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");
49951
+ return { z: z2, q, oid, refs, at: at2 };
49910
49952
  }
49911
49953
  __name(queueItemAt, "queueItemAt");
49912
49954
  async function queueJump(zoneName, n) {
@@ -49923,22 +49965,22 @@ async function queueRemove(zoneName, ns) {
49923
49965
  return withCore(async (c) => {
49924
49966
  const { z: z2, q } = queueOf(c, zoneName);
49925
49967
  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);
49968
+ const at2 = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
49969
+ const oids = [...new Set(ns)].map((n) => refs[at2 + n - 1]).filter((o) => o !== void 0);
49928
49970
  if (!oids.length) throw new RoonError("No such items in the queue", "invalid");
49929
49971
  c.remoting.callMethodNoReply(q.oid, formatMethodSignature("Queue", "RemoveItems", [{ type: "IEnumerable<TransportItem>", name: "items" }]), buildArgs([Arg.collection(oids.map((o) => buildArgs([Arg.ref(o)])))]));
49930
49972
  log(`queue_remove: ${z2.name} \u2212 ${oids.length} item(s)`);
49931
49973
  await wait(300);
49932
49974
  const after = await queueItems(c, q);
49933
- return { ok: true, zone: z2.name, removed: oids.length, left: Math.max(0, after.length - at) };
49975
+ return { ok: true, zone: z2.name, removed: oids.length, left: Math.max(0, after.length - at2) };
49934
49976
  });
49935
49977
  }
49936
49978
  __name(queueRemove, "queueRemove");
49937
49979
  var INSERTION = { before: 3, after: 2 };
49938
49980
  async function queueMove(zoneName, n, to, where) {
49939
49981
  return withCore(async (c) => {
49940
- const { z: z2, q, oid, refs, at } = await queueItemAt(c, zoneName, n);
49941
- const rel = refs[at + to - 1];
49982
+ const { z: z2, q, oid, refs, at: at2 } = await queueItemAt(c, zoneName, n);
49983
+ const rel = refs[at2 + to - 1];
49942
49984
  if (rel === void 0 || to === n) throw new RoonError(`The queue of ${z2.name} has no item ${to} to move next to`, "invalid");
49943
49985
  const point = INSERTION[where];
49944
49986
  const res = await c.call(
@@ -49952,7 +49994,7 @@ async function queueMove(zoneName, n, to, where) {
49952
49994
  log(`queue_move: ${z2.name} item ${n} \u2192 ${where} ${to} (point ${point})`);
49953
49995
  await wait(300);
49954
49996
  const after = await queueItems(c, q);
49955
- const now = after.indexOf(oid) - at + 1;
49997
+ const now = after.indexOf(oid) - at2 + 1;
49956
49998
  return { ok: true, zone: z2.name, moved: n, now_at: now > 0 ? now : void 0 };
49957
49999
  });
49958
50000
  }
@@ -49961,11 +50003,11 @@ async function queue2(zoneName, limit3) {
49961
50003
  return withCore(async (c) => {
49962
50004
  const { z: z2, q } = queueOf(c, zoneName);
49963
50005
  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));
50006
+ const at2 = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
50007
+ const view = refs.slice(at2, at2 + Math.min(Math.max(1, limit3), 200));
49966
50008
  const end = Date.now() + 2500;
49967
50009
  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) })) };
50010
+ 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
50011
  });
49970
50012
  }
49971
50013
  __name(queue2, "queue");
@@ -49977,8 +50019,8 @@ async function queueClear(zoneName, everything) {
49977
50019
  return { ok: true, zone: z2.name, removed: "everything" };
49978
50020
  }
49979
50021
  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);
50022
+ const at2 = Math.max(0, field2(c.graph.getObject(q.oid), "CurrentItemIndex") ?? 0);
50023
+ const after = refs.slice(at2 + 1);
49982
50024
  if (after.length) c.remoting.callMethodNoReply(
49983
50025
  q.oid,
49984
50026
  "Sooloos.Broker.Api.Queue::RemoveItems(System.Collections.Generic.IEnumerable<Sooloos.Broker.Api.TransportItem>)",
@@ -50568,10 +50610,10 @@ function registerReadTools(server, internal = true) {
50568
50610
  }, ({ category, genre, limit: n }) => run(() => radio(category, genre, n ?? 40)));
50569
50611
  reg("roon_history", {
50570
50612
  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) },
50613
+ 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: `before` (YYYY-MM-DD) gives the plays before that date (e.g. "what did I play in March 2019": before 2019-04-01), `offset` skips the newest ones. For "most played" questions use roon_top instead of counting this.',
50614
+ inputSchema: { limit: limit(300, 30), offset: external_exports.number().int().min(0).optional(), before: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe("Only plays before this date (YYYY-MM-DD).") },
50573
50615
  annotations: READ
50574
- }, ({ limit: n }) => run(() => history(n ?? 30)));
50616
+ }, ({ limit: n, offset: offset2, before }) => run(() => history(n ?? 30, offset2 ?? 0, before)));
50575
50617
  reg("roon_top", {
50576
50618
  title: "Most played",
50577
50619
  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.',
@@ -51164,8 +51206,8 @@ async function listenLater(includePlayed) {
51164
51206
  const rows = list.map((it) => {
51165
51207
  const o = obj(c, thing(it));
51166
51208
  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;
51209
+ const at2 = dotnetDate(field2(it, "Timestamp"));
51210
+ if (at2) r.added = at2;
51169
51211
  return r;
51170
51212
  }).filter((r) => includePlayed || r.state === "waiting").sort((a, b) => String(b.added ?? "").localeCompare(String(a.added ?? ""))).map((r) => ({ ...r, added: localTime(r.added) }));
51171
51213
  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.1",
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>",