// X'S LOGIN, WHEN X WORK WAITS (umtool redesign L4, "What needs you"): the // editor's cookie alerts (`GET /api/ops/services`, editor/app/lib/cookieAlerts.ts // over common/lib/serviceCookies.ts) carry X's jar age always, and an ALERT only // when the jar refused an X job or X jobs are queued behind it -- the rule the // editor's own banner draws by. So the Inbox shows the jar only when there is a // stale alert of X's family: one Blocking card (a MACHINE call, lib/machine.ts: // no piece's), the editor's three short lines // (how old, the one thing to do, what it refused), its action the editor's // settings, where Refresh cookies / Connect X account and Recheck are. // // Nothing here asks X anything, and nothing refreshes the jar: a refresh is a // human click in the editor. Pure: lib/inbox/xJar.ts asks the editor. export const X_JAR_STALE = "x-jar-stale"; /** * The row, or null when no X work waits (or the payload is not one). * * @param {unknown} payload the services route's answer * @param {{ href: string, now?: number }} o */ export function xJarDecision(payload, { href, now = Date.now() }) { const p = /** @type {Record | null} */ (payload && typeof payload === "object" ? payload : null); const alerts = Array.isArray(p?.alerts) ? p.alerts : []; const x = alerts.find((a) => a && a.family === "x" && a.state === "stale"); if (!x) return null; const jar = p?.x && typeof p.x === "object" ? p.x : null; const lines = [x.headline, x.fix, x.detail].map((s) => (typeof s === "string" ? s.trim() : "")).filter(Boolean); const at = Date.parse(x.raisedAt ?? x.since ?? "") || now; return { project: "editor", projectTitle: x.label ? `${x.label} login` : "X login", kind: X_JAR_STALE, target: x.service ?? "x", why: lines.length ? lines.join(" ") : "X's cookies are past their age limit — refresh them on the editor's settings", href, severity: "blocking", at, ...(jar && Number.isFinite(jar.ageMinutes) ? { ageMinutes: jar.ageMinutes } : {}), }; }