/** * Navidrome MCP Server - Guest song ledger * Copyright (C) 2025 * SPDX-License-Identifier: AGPL-3.0-or-later */ import type { QueueEntry, QueueTrackMetadata, ReplaceMarks } from '../../services/playback/playback-engine.js'; import type { QueuedNames } from './jukebox-names.js'; interface LedgerEntry { /** The guest or host session that added the song from the guest page, or null for a song the admin page added. */ sessionId: string | null; /** Kept whole, so a song re-added after a replace still shows its title. */ song: QueueTrackMetadata; /** The adder's current nickname or label, which the queue shows as Added by. It stays after a sign-out. */ addedBy: string; /** The host added the song from either page. The name checks read it to tell host names from guest names, and a log line never names the host by its nickname. */ byHost: boolean; addedAt: number; started: boolean; /** Orders this record against a queue read, see `recordSequence`. */ sequence: number; } export type GuestSong = Omit; /** The replace marks read after a queue read, and the generation read before it. */ export interface ReplaceReads extends ReplaceMarks { generationBeforeRead: number; } /** * Keyed by mpv entry id, which survives a move. It lives in memory, so a web player restart forgets * it, and the labeled songs stay queued as plain songs. Only a guest page song counts toward a limit, * waits for its adder and returns after a replace. An admin page song only carries its label. */ export declare class GuestLedger { private readonly entries; private held; private restoring; private replaceGeneration; private latestGeneration; private recordCount; record(entryId: number, entry: GuestSong): void; /** Taken before a queue read, so `reconcile` leaves alone the entries recorded after that read began. */ recordSequence(): number; forget(entryId: number): void; isEmpty(): boolean; /** Admin page songs count toward no limit, so only guest page songs need the queue read on every mpv event. */ tracksGuestPageSongs(): boolean; ownerOf(entryId: number): string | null; songIdOf(entryId: number): string | null; isStarted(entryId: number): boolean; addedByOf(entryId: number): string | null; /** Null for a song the host added, so only a guest's song names its adder. */ guestLabelOf(entryId: number): string | null; isFromGuestPage(entryId: number): boolean; /** Renames the session's songs, held ones included, so a changed nickname shows on songs already queued. */ relabel(sessionId: string, addedBy: string): void; /** Held songs count, since they return to the queue still showing their name. A library play adds one Host per song, so names repeat. */ addedByNames(): QueuedNames; private everyEntry; /** * Drops the entries mpv no longer holds and starts the current entry while mpv plays, so an entry * selected paused stays unplayed. An unknown pause state starts nothing. An unplayed guest page entry * that a song replace removed is held instead, and dropped once that replace fails. Returns true on a change. */ reconcile(queue: readonly QueueEntry[], paused: boolean | null, queueReadSequence: number, marks: ReplaceReads): boolean; hasRestorable(): boolean; /** Takes the held songs whose replace completed, in their add order. */ takeRestorable(): GuestSong[]; /** Ends the rename tracking of the songs `takeRestorable` returned, once they are recorded or dropped. */ finishRestore(taken: readonly GuestSong[]): void; private isRestorable; /** A held song keeps its guest's slot until it returns to the queue or drops. */ unplayedCount(sessionId: string): number; /** The guest's queued songs that have not started, which it may remove. */ unplayedEntryIds(sessionId: string): number[]; /** The guest's songs that have not started, held ones included, in their add order. */ unplayedSongs(sessionId: string): QueueTrackMetadata[]; /** A completed replace never brings back the held songs this drops. Returns how many it dropped. */ dropHeld(sessionId: string): number; /** * Any entry after the current one waits to play, and a guest page song that never started waits wherever * it sits. The guest snapshot sends this rule, so the guest page and the duplicate check agree. */ waitingRule(queue: readonly QueueEntry[]): (queued: QueueEntry) => boolean; /** A held song also waits, since it returns to the queue. */ isWaitingInQueue(queue: readonly QueueEntry[], songId: string): boolean; } export {}; //# sourceMappingURL=guest-ledger.d.ts.map