// THE WATCH OF A LIBRARY'S TOPICS (lane x-trending-2): the scan that turns a // watched topic (lib/xTrending/watch.ts) into reads. // // Armed by the editor's instrumentation BELOW the idle gate // (ARCHILYZER_IDLE_BOOT arms nothing, and armXTrendingWatch refuses an idle // boot itself), not on the e2e test server — a tick is a request to X. Once // armed, a scan runs every CHECK_MS on an unref'd timer of its own (NOT the // sync heartbeat, which can be switched off), and: // // - a watch past its end time ENDS, with a sentence; // - ONE SCAN STARTS AT MOST ONE READ, across every library: the watch // longest overdue. A tick is the same single `read-x-trending` job a // person starts, on X's queue (one job at a time, X's gap between jobs); // a missed window is one catch-up tick, never several; // - no tick is started while a trending read, a reparse or a capture of // ANY library is queued or running: the libraries share one stream of // ticks (the cap on watched topics is per library); // - three reads of a watched topic in a row that did not end "read" PAUSE // its watch ("failing") until a person switches it on again; // - WHEN X WOULD REFUSE THE READ the watches PAUSE instead of queueing jobs // to be refused: X's cookie jar is past its limit ("jar": X's jar-age // alert goes up, on the dashboard and /cookies, and /review lists the // paused watches), the X alert is up, X is cooling down after a rate // limit, or there is no connected profile. The pause ends at the first // scan that finds the reason gone; // - a topic with several trending pages reads ONE page per tick, in turn; // - a page X no longer has is not read again, and a topic with no page // left ENDS its watch with a sentence (noteXTrendingWatchRead, called at // the end of every read of a library). // // THE JAR IS NEVER REFRESHED HERE. A refresh is a person's press on /cookies // (jobs/networkGuard.ts): a watch runs only while the jar is fresh, so it // does not cover a night nobody presses Refresh in. // // After a read into a watched topic, its NEW posts get their media at once // (xTrendingWatchFollowUp says which posts one capture job takes). import path from "node:path"; import type { Paths } from "../lib/paths"; import { isIdleBoot } from "../lib/idleBoot"; import { jitterMs } from "../lib/jitter"; import { noteXJarStale } from "../lib/serviceCookies-server"; import { ageText, xSessionReport } from "../jobs/networkGuard"; import { getSettings } from "../lib/settings"; import { isXTrendingChannel } from "../lib/xTrending/config"; import { readXTrendingMembership, readXTrendingTopics, xTrendingCaptureSummary, type XTrendingTopic, } from "../lib/xTrending/store"; import { mutateXTrendingWatches, X_TRENDING_WATCH_MAX_FAILURES, pausedWatchRows, readXTrendingWatches, watchIsLive, type PausedWatchRow, type XTrendingWatch, type XTrendingWatchPauseReason, } from "../lib/xTrending/watch"; import { listChannelConfigs } from "./channels"; import { xTrendingHeld } from "./readXTrending"; export const X_TRENDING_WATCH_CHECK_MS = 60_000; // One capture after a tick takes at most this many posts. export const X_TRENDING_WATCH_CAPTURE_MAX = 80; export type WatchRefusal = { reason: XTrendingWatchPauseReason; sentence: string }; // `tabs`: the one tab the watch reads, when it does not read both. export type WatchTick = { slug: string; topic: string; url: string; trendId: string; tabs?: Array<"top" | "latest"> }; export type WatchScanDeps = { paths: Paths; now?: () => number; log?: (line: string) => void; // The libraries (default: every channel carrying the marker). libraries?: () => Promise; // A trending read, a reparse or a capture of ANY library is queued or // running (review 1 M3): the libraries share one stream of ticks, so two // libraries never have two reads waiting on X's queue behind each other. busy: () => boolean; // Why X would refuse a read now, or null (default: watchRefusal below). refusal?: (slug: string) => Promise; // One read, enqueued (the editor's readXTrendingAction). enqueue: (tick: WatchTick) => Promise<{ ok: true; jobId: string } | { ok: false; error: string }>; noteJarStale?: (line: string, slug: string) => Promise; // The stretch added to an interval (never a shortening). jitter?: (ms: number) => number; }; export type WatchScanResult = { libraries: number; // Watches switched on and not ended, after this scan. live: number; enqueued?: WatchTick & { jobId: string }; refused?: WatchTick & { error: string }; paused: Array<{ slug: string; topic: string; reason: XTrendingWatchPauseReason }>; resumed: Array<{ slug: string; topic: string }>; ended: Array<{ slug: string; topic: string; sentence: string }>; }; const hhmm = (ms: number) => new Date(ms).toISOString().slice(0, 16).replace("T", " "); // The age a watch asks of X's exported jar when the setting says nothing // usable (0 turns the fresh-jar rule off for a person's jobs — never for a // watch). export const WATCH_MAX_JAR_AGE_MINUTES = 60; export type WatchRefusalDeps = { report?: typeof xSessionReport; // Whether settings.json can be read at all. settingsReadable?: () => boolean; held?: (paths: Paths, now: number) => Promise; // False: the job asked about does not count against X's job cap (a // library's media-only capture, lib/xJobRule.ts xJobCounts — review 2, // ruling R-a), so the cap does not hold it. Every other rule here does. counts?: boolean; }; function settingsCanBeRead(): boolean { try { getSettings(); return true; } catch { return false; } } // WHY X WOULD REFUSE A READ NOW — read from disk, never from X: the X alert, // the connected profile, the jar's age, X's cooldown or hold. // // THE WATCH HAS ITS OWN JAR RULE, STRICTER THAN THE GUARD'S (review 1 M1). The // fresh-jar rule a person's job meets (jobs/networkGuard.ts) lets a job // through when the login comes from the browser (its age cannot be read), // when `social.x.maxCookieAgeMinutes` is 0, and when settings cannot be read. // Those are a person's choices about a job a person started. A watch starts // jobs with nobody there, so none of them applies to it: WHATEVER THE SOURCE // AND THE SETTING, a watch ticks only when the profile's exported jar was // written between 0 and the limit ago (the setting when it is above 0, else // 60 minutes) — an age that cannot be read, or is negative (a clock set // back), refuses — and never when settings cannot be read. export async function watchRefusal(paths: Paths, slug: string, now: number, deps: WatchRefusalDeps = {}): Promise { // A watch's job is a read or a library's capture: a browse job of X's sitting. const report = await (deps.report ?? xSessionReport)({ paths, channelSlug: slug, now, sittingKind: "browse", ...(deps.counts === false ? { counts: false } : {}), }); if (!report.hasProfile) { return { reason: "no-profile", sentence: "There is no connected X profile to read a trending page with: connect an X account on /cookies.", }; } if (report.alert) { return { reason: "alert", sentence: report.reason ?? "X's cookie alert is up." }; } if (!(deps.settingsReadable ?? settingsCanBeRead)()) { return { reason: "jar", sentence: "settings.json cannot be read, so the limit on X's cookie age is not known: a watch does not tick without it." }; } const limit = report.maxAgeMinutes > 0 ? report.maxAgeMinutes : WATCH_MAX_JAR_AGE_MINUTES; const written = report.cookiesUpdatedAt ? Date.parse(report.cookiesUpdatedAt) : NaN; // Not the report's `ageMinutes`: that one never goes below zero. const ageMinutes = Number.isFinite(written) ? (now - written) / 60_000 : null; if (ageMinutes === null || !report.hasCookies) { return { reason: "jar", sentence: "No X cookie jar has been exported from the connected profile: press Refresh cookies (or Connect X account) on /cookies." }; } if (!report.looksAuthenticated) { return { reason: "jar", sentence: "The X cookie jar holds no login (no auth_token): press Connect X account on /cookies." }; } if (ageMinutes < 0) { return { reason: "jar", sentence: "X's cookie jar is dated in the future (the clock was set back?): press Refresh cookies on /cookies." }; } if (ageMinutes > limit) { return { reason: "jar", sentence: `X cookies were last refreshed ${ageText(now - written)} ago (limit ${limit} min for a watch): press Refresh cookies (or Connect X account) on /cookies.`, }; } // X'S JOB CAP IS REACHED (lib/xJobRule.ts): like a cooldown — the tick is // skipped, the watch waits, and it goes on by itself once the cap has room. // Not the jar's fault and not a failed read. if (deps.counts !== false && !report.allowed && report.cap.reached && report.alert === null && /^X's job (cap|count)/.test(report.reason ?? "")) { return { reason: "cooldown", sentence: report.reason ?? "X's job cap is reached." }; } // X'S SITTING (lib/xSitting.ts) used up or of the other kind, X cooling down // after a 429, or the account marked suspended: the tick is skipped and the // watch waits — the sitting's ends at the next Refresh, the cooldown's at // its time. Not the jar's fault. if (!report.allowed && (report.refusedBy === "sitting" || report.refusedBy === "cooldown" || report.refusedBy === "suspended")) { return { reason: "cooldown", sentence: report.reason ?? "X is held." }; } // Whatever else the guard would refuse a person's job for. if (!report.allowed) return { reason: "jar", sentence: report.reason ?? "X's cookie jar is past its limit." }; const held = await (deps.held ?? xTrendingHeld)(paths, now); return held ? { reason: "cooldown", sentence: held } : null; } // THE LIVE WATCHES OF A LIBRARY, PAUSED for a refusal met outside the scan (a // watch's job at its start). A watch paused for failing keeps that pause. // Answers how many it paused. export async function pauseXTrendingWatches(channelRoot: string, refusal: WatchRefusal, now: number): Promise { const at = new Date(now).toISOString(); return mutateXTrendingWatches(channelRoot, (watches) => { let n = 0; for (const w of Object.values(watches)) { if (!watchIsLive(w) || w.paused?.reason === "failing" || w.paused?.reason === refusal.reason) continue; w.paused = { reason: refusal.reason, since: at, sentence: refusal.sentence }; n++; } return { write: n > 0, result: n }; }); } // A WATCH'S JOB, AT ITS START (review 2 N1) — its tick's read, and the capture // that follows a read into a watched topic. The scan asks the watch's jar rule // when it queues a tick, but a job starts when its turn on X's queue comes: a // tick queued on a 58-minute jar behind another X job starts on a 78-minute // one, and the guard every X job meets at its start lets that through when // the cookie-age setting is 0 or the login comes from the browser. So the // watch's own rule is asked AGAIN here, at the moment the job would touch X. // A refusal pauses the library's watches (as the scan would have) and is // answered; the caller then starts nothing. export async function refuseWatchJob(paths: Paths, slug: string, now: number = Date.now(), deps: WatchRefusalDeps = {}): Promise { const refusal = await watchRefusal(paths, slug, now, deps); if (refusal) await pauseXTrendingWatches(path.join(paths.channelsDir, slug), refusal, now).catch(() => 0); return refusal; } export const WATCH_JAR_NOTE = "A watch runs only while X's cookie jar is fresh: it resumes at the first scan after Refresh cookies on /cookies."; async function defaultLibraries(paths: Paths): Promise { return (await listChannelConfigs(paths)).filter((c) => isXTrendingChannel(c.config)).map((c) => c.slug); } type Due = { slug: string; root: string; topic: XTrendingTopic; watch: XTrendingWatch; dueAt: number }; // ONE SCAN. Never throws for one library's sake: a library whose files // cannot be read is skipped and said. export async function scanXTrendingWatches(deps: WatchScanDeps): Promise { const now = (deps.now ?? Date.now)(); const at = new Date(now).toISOString(); const log = deps.log ?? (() => {}); const out: WatchScanResult = { libraries: 0, live: 0, paused: [], resumed: [], ended: [] }; const slugs = await (deps.libraries ?? (() => defaultLibraries(deps.paths)))(); out.libraries = slugs.length; const due: Due[] = []; for (const slug of slugs) { const root = path.join(deps.paths.channelsDir, slug); try { if (!Object.values(await readXTrendingWatches(root)).some(watchIsLive)) continue; const topics = new Map((await readXTrendingTopics(root)).map((t) => [t.id, t])); // 1. End what is past its end time (or whose topic is no more). await mutateXTrendingWatches(root, (watches) => { let write = false; for (const [id, w] of Object.entries(watches)) { if (!watchIsLive(w)) continue; const title = topics.get(id)?.title; const sentence = !title ? `The watch ended: this library no longer has the topic "${id}".` : now >= Date.parse(w.until) ? `The watch of "${title}" ended at its end time (${hhmm(Date.parse(w.until))} UTC), after ${w.ticks} tick${w.ticks === 1 ? "" : "s"}.` : null; if (!sentence) continue; w.on = false; delete w.paused; w.ended = { at, reason: title ? "until" : "off", sentence }; out.ended.push({ slug, topic: id, sentence }); write = true; } return { write, result: null }; }); // 2. Would X refuse a read? Then the live watches pause; else they resume. const refusal = await (deps.refusal ?? ((s) => watchRefusal(deps.paths, s, now)))(slug); const watches = await mutateXTrendingWatches(root, (all) => { let write = false; for (const [id, w] of Object.entries(all)) { if (!watchIsLive(w)) continue; // Paused for failing: only a person ends that (review 1 S1). if (w.paused?.reason === "failing") continue; if (refusal) { // BY THE REASON ONLY (review 1 S4): the sentence carries the // jar's age in minutes, and a watch.json rewritten every scan for // it is churn. The sentence is the one the pause began with. if (w.paused?.reason !== refusal.reason) { out.paused.push({ slug, topic: id, reason: refusal.reason }); w.paused = { reason: refusal.reason, since: at, sentence: refusal.sentence }; write = true; } } else if (w.paused && w.paused.reason !== "refused") { // A read that was refused at its enqueue stays paused until one is taken. delete w.paused; out.resumed.push({ slug, topic: id }); write = true; } } return { write, result: all }; }); for (const p of out.paused.filter((p) => p.slug === slug)) { log(`x-trending watch: ${slug}/${p.topic}: paused (${p.reason}): ${refusal?.sentence ?? ""}`); } for (const r of out.resumed.filter((r) => r.slug === slug)) log(`x-trending watch: ${slug}/${r.topic}: resumed`); const live = Object.entries(watches).filter(([, w]) => watchIsLive(w)); out.live += live.length; if (refusal) { // The alert is raised when the watches GO stale, not at every scan // after (review 1 S4): a banner the operator dismissed stays dismissed. const went = out.paused.filter((p) => p.slug === slug && p.reason === "jar").length; if (refusal.reason === "jar" && went > 0) { const line = `${live.length} watched topic${live.length === 1 ? "" : "s"} of ${slug} paused: ${refusal.sentence} ${WATCH_JAR_NOTE}`; await (deps.noteJarStale ?? ((l, s) => noteXJarStale(deps.paths, { line: l, channel: s }, now)))(line, slug).catch(() => {}); } continue; } // 3. What is due. for (const [id, w] of live) { const topic = topics.get(id); if (!topic || w.paused?.reason === "failing") continue; const dueAt = w.nextTickAt ? Date.parse(w.nextTickAt) : Date.parse(w.startedAt); if (dueAt <= now) due.push({ slug, root, topic, watch: w, dueAt }); } } catch (err) { log(`x-trending watch: ${slug}: the scan could not read this library: ${(err as Error).message}`); } } // Nothing is started while a trending job of any library waits its turn. if (due.length === 0 || deps.busy()) return out; // The longest overdue, and only it. due.sort((a, b) => a.dueAt - b.dueAt || a.slug.localeCompare(b.slug) || a.topic.id.localeCompare(b.topic.id)); const pick = due[0]; const pages = pick.topic.sources.filter((s) => !pick.watch.goneSources.includes(s.trendId)); if (pages.length === 0) { const sentence = goneSentence(pick.topic.title); await mutateXTrendingWatches(pick.root, (watches) => { const w = watches[pick.topic.id]; if (!watchIsLive(w)) return { write: false, result: null }; w.on = false; delete w.paused; w.ended = { at, reason: "gone", sentence }; return { write: true, result: null }; }); out.ended.push({ slug: pick.slug, topic: pick.topic.id, sentence }); out.live--; return out; } const page = pages[pick.watch.nextSource % pages.length]; const tick: WatchTick = { slug: pick.slug, topic: pick.topic.id, url: page.url, trendId: page.trendId, ...(pick.watch.tabs ? { tabs: pick.watch.tabs } : {}) }; const interval = pick.watch.intervalMinutes * 60_000; const started = await deps.enqueue(tick).catch((err) => ({ ok: false as const, error: (err as Error).message })); await mutateXTrendingWatches(pick.root, (watches) => { const w = watches[pick.topic.id]; if (!watchIsLive(w)) return { write: false, result: null }; if (started.ok) { w.lastTickAt = at; w.lastJobId = started.jobId; // Stretched, never shortened. w.nextTickAt = new Date(now + interval + Math.max(0, (deps.jitter ?? ((ms) => jitterMs(ms) - ms))(interval))).toISOString(); w.ticks++; w.nextSource = (w.nextSource + 1) % 1_000_000; // ONLY THE PAUSE THIS ENQUEUE RESOLVES (review 2 N5): a read that was // refused before is taken now. The file is read again under the lock // here, and a pause set meanwhile for another reason — "failing", by a // read that ended while this one was being queued — is not this scan's // to erase. if (w.paused?.reason === "refused") delete w.paused; } else { // Not asked again every minute: the next try is an interval away. w.nextTickAt = new Date(now + interval).toISOString(); if (w.paused?.reason !== "failing") { w.paused = { reason: "refused", since: w.paused?.reason === "refused" ? w.paused.since : at, sentence: started.error }; } } return { write: true, result: null }; }); if (started.ok) { out.enqueued = { ...tick, jobId: started.jobId }; log(`x-trending watch: ${tick.slug}/${tick.topic}: tick → job ${started.jobId} (${tick.url})`); } else { out.refused = { ...tick, error: started.error }; out.paused.push({ slug: tick.slug, topic: tick.topic, reason: "refused" }); log(`x-trending watch: ${tick.slug}/${tick.topic}: not ticked: ${started.error}`); } return out; } const goneSentence = (title: string) => `X no longer has the trending page of "${title}" (trending pages expire): the watch ended.`; // THE END OF A READ, told to the watch (every read of a library, a person's // too): // - a page X answered "gone" for is not read again; when the topic has no // page left, its watch ends with a sentence; // - a read that ended "read" clears the count of failures; // - any other end (a rate limit, a 403, a login wall, a page that would not // load, nothing recognised) is a failure, and the third in a row PAUSES // the watch, "failing", until a person switches it on again (review 1 // S1). A 429's 15-minute cooldown is recorded by the read as before. // Answers the sentence of what it did to a watch, or null. export async function noteXTrendingWatchRead( channelRoot: string, read: { trendId: string; outcome: string; now?: number; sentence?: string }, ): Promise { if (read.outcome === "probe") return null; const topics = await readXTrendingTopics(channelRoot); const at = new Date(read.now ?? Date.now()).toISOString(); return mutateXTrendingWatches(channelRoot, (watches) => { let write = false; let sentence: string | null = null; for (const topic of topics) { const w = watches[topic.id]; if (!watchIsLive(w) || !topic.sources.some((s) => s.trendId === read.trendId)) continue; if (read.outcome === "read") { if (w.failures !== 0) { w.failures = 0; write = true; } continue; } if (read.outcome === "gone") { if (!w.goneSources.includes(read.trendId)) w.goneSources.push(read.trendId); write = true; if (topic.sources.every((s) => w.goneSources.includes(s.trendId))) { sentence = goneSentence(topic.title); w.on = false; delete w.paused; w.ended = { at, reason: "gone", sentence }; } continue; } w.failures++; write = true; if (w.failures >= X_TRENDING_WATCH_MAX_FAILURES && w.paused?.reason !== "failing") { sentence = `The last ${w.failures} reads of "${topic.title}" failed (the last: ${read.outcome}` + `${read.sentence ? ` — ${read.sentence}` : ""}): its watch is paused until the operator switches it on again ` + `(Watch on its page, or watch-trending {"topic": "${topic.id}", "on": true}).`; w.paused = { reason: "failing", since: at, sentence }; } } return { write, result: sentence }; }); } export type WatchFollowUp = { ids: string[]; shots: boolean; fresh: number; owed: number; uncaptured: number }; // WHAT ONE CAPTURE TAKES AFTER A READ INTO A WATCHED TOPIC: the read's new // posts (their media at once; a screenshot too when the topic says so), then // the topic's posts a capture left OWED to a later one (the job's budget, X's // cooldown), then its posts with media that were never captured at all — // never one whose capture failed, and never one owed until it is kept. // Null when the topic is not watched or there is nothing to take. export async function xTrendingWatchFollowUp( channelRoot: string, o: { topic: string; newIds: ReadonlyArray }, ): Promise { const watch = (await readXTrendingWatches(channelRoot))[o.topic]; if (!watchIsLive(watch)) return null; const membership = await readXTrendingMembership(channelRoot); // Media only: a post with none is not captured (nothing to fetch, no page). const fresh = o.newIds.filter((id) => membership[id]?.topic === o.topic && (watch.shots || (membership[id]?.media?.count ?? 0) > 0)); const ids = fresh.slice(0, X_TRENDING_WATCH_CAPTURE_MAX); let owed = 0; const taken = new Set(ids); // Then what is owed to a later capture; then (review 1 S7) the topic's // posts with media that have NO capture record at all — the new posts of an // earlier tick whose capture was refused before it was a job (a stale jar, // the cooldown), which nothing would otherwise ask for again. const never: string[] = []; for (const [id, m] of Object.entries(membership)) { if (m.topic !== o.topic || taken.has(id)) continue; const capture = await xTrendingCaptureSummary(channelRoot, id); if (capture?.mediaOwed === "next") { if (ids.length < X_TRENDING_WATCH_CAPTURE_MAX) { ids.push(id); owed++; } } else if (!capture && (m.media?.count ?? 0) > 0) never.push(id); } let uncaptured = 0; for (const id of never) { if (ids.length >= X_TRENDING_WATCH_CAPTURE_MAX) break; ids.push(id); uncaptured++; } return ids.length > 0 ? { ids, shots: watch.shots, fresh: ids.length - owed - uncaptured, owed, uncaptured } : null; } // The watches that are paused now, across every library — /review's section. export async function pausedXTrendingWatches(paths: Paths): Promise { const libraries = []; for (const slug of await defaultLibraries(paths)) { const root = path.join(paths.channelsDir, slug); const watches = await readXTrendingWatches(root); if (!Object.values(watches).some((w) => watchIsLive(w) && w.paused)) continue; libraries.push({ slug, watches, topics: await readXTrendingTopics(root) }); } return pausedWatchRows(libraries); } // ─── arming (the editor's instrumentation, below the idle gate) ─── type Armed = { deps: WatchScanDeps; timer: ReturnType | null; scanning: Promise | null }; declare global { // eslint-disable-next-line no-var var __yttXTrendingWatch__: Armed | undefined; } // One scan at a time: a second caller shares the one going. Null when unarmed. export function xTrendingWatchTick(): Promise | null { const a = globalThis.__yttXTrendingWatch__; if (!a) return null; if (!a.scanning) { a.scanning = scanXTrendingWatches(a.deps).finally(() => { a.scanning = null; }); } return a.scanning; } // ONE SCAN AT A TIME, ARMED OR NOT (review 1 S6): `watch-trending {"tick": // true}` goes through the armed scan's own in-flight promise when the timer // is armed, and through this one when it is not (the e2e test server) — two // asks at once are one scan, never two reads. declare global { // eslint-disable-next-line no-var var __yttXTrendingWatchScan__: Promise | null | undefined; } export function runXTrendingWatchScan(deps: () => WatchScanDeps): Promise { const armed = xTrendingWatchTick(); if (armed) return armed; if (!globalThis.__yttXTrendingWatchScan__) { globalThis.__yttXTrendingWatchScan__ = scanXTrendingWatches(deps()).finally(() => { globalThis.__yttXTrendingWatchScan__ = null; }); } return globalThis.__yttXTrendingWatchScan__; } // Arm the scan: every `everyMs` (default CHECK_MS). Refused (false) on an idle // boot. Idempotent: a second call only replaces the deps. export function armXTrendingWatch( deps: WatchScanDeps, opts: { env?: Record; everyMs?: number } = {}, ): boolean { if (isIdleBoot(opts.env ?? process.env)) return false; const armed = globalThis.__yttXTrendingWatch__; if (armed) { armed.deps = deps; return true; } const state: Armed = { deps, timer: null, scanning: null }; globalThis.__yttXTrendingWatch__ = state; const every = opts.everyMs ?? X_TRENDING_WATCH_CHECK_MS; if (every > 0) { state.timer = setInterval(() => { void xTrendingWatchTick()?.catch((e) => state.deps.log?.(`x-trending watch: the scan failed: ${(e as Error).message}`)); }, every); state.timer.unref?.(); } return true; } export function disarmXTrendingWatch(): void { const a = globalThis.__yttXTrendingWatch__; if (a?.timer) clearInterval(a.timer); globalThis.__yttXTrendingWatch__ = undefined; } export function isXTrendingWatchArmed(): boolean { return globalThis.__yttXTrendingWatch__ !== undefined; }