UNPKG

@withpica/mcp-server

Version:

MCP Server for withPICA — enables AI assistants to interact with your withPICA music catalog

208 lines (191 loc) • 7.82 kB
// Copyright (c) 2025-2026 Withpica Ltd. All rights reserved. /** * pica_split_sheet_card MCP App card — who has signed a song's split sheet * (ADR-152 amendment 2026-11-11, slice 2b). * * Shows each person on the latest split sheet with their share and state. * Two actions: * - "open it on pica": opens the work's documents page on PICA * (app.openLink), where a person with a share signs it ("sign your * line"). Signing itself is only ever done there, signed in. The card * can't tell whether the viewer has a share, so it doesn't say "sign" * (e1, 11-12). * - "send again" on one person's row: shows "email <name> their link * again?" and waits for a yes, then calls pica_split_sheet_remind for * that one person and shows the answer. Nothing is sent without that * yes, and the yes covers only the person it named. * "refresh" re-reads pica_split_sheet_card. * * DOM API only — never innerHTML. */ import { buildAppHtml } from "./shared.js"; const SPLIT_BODY = ` <div class="stack gap-6"> <header> <h1 class="heading heading-lg">who has signed</h1> <p class="text-secondary" id="sp-sub">reading this work&hellip;</p> </header> <div id="sp-people" class="card-flat stack" style="padding: 12px 16px; display: none;"></div> <div id="sp-confirm" class="card-flat" style="display: none; padding: 16px 20px;"> <p class="text-primary" id="sp-confirm-text"></p> <div class="row gap-4" style="margin-top: 12px;"> <button class="btn-copper" id="sp-send">send</button> <button class="btn-ghost" id="sp-cancel">cancel</button> </div> </div> <p class="text-secondary" id="sp-result" style="display: none;"></p> <div class="row gap-4" style="flex-wrap: wrap;"> <button class="btn-copper" id="sp-open">open it on pica</button> <button class="btn-ghost" id="sp-refresh">refresh</button> </div> <a id="sp-link" class="text-tertiary" style="font-size: 12px; display: none;" target="_blank" rel="noopener"></a> </div> `; const SPLIT_JS = ` var spState = { work_id: null, sign_url: null, sheet: null, people: [], sending: false }; // The send the user is saying yes to: exactly the one person named in the // "email X their link again?" box, fixed when it opens. A refresh or a new // result closes the box, so a changed list has to be shown again first. var spPending = null; function spStateWords(p) { if (p.state === "signed") return "signed"; if (p.state === "declined") return "said no"; if (p.state === "expired") return "link expired"; var base = p.state === "sent" ? "sent \\u00B7 not signed yet" : "not sent yet"; return p.has_email ? base : base + " \\u00B7 no email on record"; } function spRender() { var box = document.getElementById("sp-people"); while (box.firstChild) box.removeChild(box.firstChild); var signed = 0; spState.people.forEach(function (p) { if (p.state === "signed") signed++; var row = document.createElement("div"); row.className = "row between"; row.style.marginTop = "8px"; row.style.gap = "8px"; var name = document.createElement("span"); name.className = "text-primary"; name.textContent = p.share != null ? p.name + " \\u00B7 " + p.share + "%" : p.name; var right = document.createElement("span"); right.className = "row gap-4"; var st = document.createElement("span"); st.className = p.state === "signed" ? "text-accent" : "text-secondary"; st.style.fontSize = "13px"; st.textContent = spStateWords(p); right.appendChild(st); if (p.can_send) { var b = document.createElement("button"); b.className = "btn-ghost"; b.textContent = p.state === "sent" ? "send again" : "send"; b.setAttribute("data-signature", p.signature_id); b.addEventListener("click", function () { spStartSend(p); }); right.appendChild(b); } row.appendChild(name); row.appendChild(right); box.appendChild(row); }); box.style.display = spState.people.length > 0 ? "block" : "none"; document.getElementById("sp-sub").textContent = !spState.sheet ? "this work has no split sheet yet" : spState.people.length === 0 ? "nobody on this split sheet yet" : signed + " of " + spState.people.length + " signed"; var link = document.getElementById("sp-link"); if (spState.sign_url) { link.href = spState.sign_url; link.textContent = spState.sign_url; } } function spShowLink() { var link = document.getElementById("sp-link"); if (spState.sign_url) link.style.display = "block"; } function spOpen() { if (!spState.sign_url) return; if (app && typeof app.openLink === "function") { app.openLink({ url: spState.sign_url }).catch(spShowLink); } else { spShowLink(); } } function spCloseSend() { spPending = null; document.getElementById("sp-confirm").style.display = "none"; } function spStartSend(p) { if (!spState.work_id || !spState.sheet || !p.can_send) return; spPending = { work_id: spState.work_id, split_sheet_id: spState.sheet.split_sheet_id, signature_id: p.signature_id, name: p.name, }; document.getElementById("sp-confirm-text").textContent = p.state === "sent" ? "email " + p.name + " their signing link again?" : "email " + p.name + " their signing link?"; document.getElementById("sp-confirm").style.display = "block"; } function spOutcomeWords(o) { if (o === "sent") return "sent"; if (o === "held") return "waiting for approval before it's sent"; if (o === "no_email") return "no email on record"; if (o === "reminded_recently") return "emailed in the last day, not sent again"; if (o === "too_many") return "too many emails sent this hour \\u00B7 try again later"; return "couldn't send \\u00B7 try again, or open it on pica"; } function spResultOutcome(r) { if (!r || r.isError) return null; var s = r.structuredContent; if (s && typeof s === "object" && s.outcome) return s.outcome; return null; } function spSend() { if (spState.sending || !spPending || !app || typeof app.callServerTool !== "function") return; var p = spPending; spState.sending = true; spCloseSend(); var out = document.getElementById("sp-result"); out.style.display = "block"; out.textContent = "sending\\u2026"; app.callServerTool({ name: "pica_split_sheet_remind", arguments: { work_id: p.work_id, split_sheet_id: p.split_sheet_id, signature_id: p.signature_id, }, }).then(function (r) { out.textContent = p.name + ": " + spOutcomeWords(spResultOutcome(r)); }).catch(function () { out.textContent = p.name + ": couldn't send \\u00B7 try again, or open it on pica"; }).then(function () { spState.sending = false; spRefresh(); }); } function spApply(data) { if (!data || !Array.isArray(data.people)) return; spCloseSend(); spState.work_id = data.work_id || spState.work_id; spState.sign_url = data.sign_url || spState.sign_url; spState.sheet = data.sheet || null; spState.people = data.people; spRender(); } function spRefresh() { if (!spState.work_id || !app || typeof app.callServerTool !== "function") return; app.callServerTool({ name: "pica_split_sheet_card", arguments: { work_id: spState.work_id } }) .then(function (r) { if (r && r.structuredContent) spApply(r.structuredContent); }) .catch(function () {}); } document.getElementById("sp-open").addEventListener("click", spOpen); document.getElementById("sp-send").addEventListener("click", spSend); document.getElementById("sp-cancel").addEventListener("click", spCloseSend); document.getElementById("sp-refresh").addEventListener("click", spRefresh); window.onPicaToolResult = spApply; `; export const SPLIT_HTML = buildAppHtml("pica — split sheet", SPLIT_BODY, SPLIT_JS); //# sourceMappingURL=split.js.map