308 lines
18 KiB
HTML
308 lines
18 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||
<!--
|
||
The Details drawer's "Plan usage" card (slot conv-plan-usage): a conversation's
|
||
share of its Claude plan. List-price dollars lead (display currency), the % of
|
||
the account's week and of a 5-hour window sit beside them, then the plan units
|
||
behind those percentages and the per-model / per-effort split from `byModel`
|
||
(subagents included). A row's "% wk" is its plan units at the same rate the
|
||
headline was converted with, so the rows add up to it.
|
||
|
||
Drawn from the host's live `update` snapshot (no action call): `cost`,
|
||
`planPct`, `planUnits`, `subagentPlanUnits`, `fastCalls`, `priceBook`,
|
||
`byModel`, `currency`, `usdToEur`, `lang`. Folds away (setEmpty + resize(0))
|
||
when the conversation has neither plan units nor a per-model split.
|
||
-->
|
||
<style>
|
||
* { box-sizing: border-box; }
|
||
html, body { margin: 0; padding: 0; background: transparent; }
|
||
body { font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 12px;
|
||
line-height: 1.35; color: hsl(var(--foreground)); -webkit-font-smoothing: antialiased; }
|
||
.card { border: 1px solid hsl(var(--border)); border-radius: 12px; background: hsl(var(--card)); padding: 12px; }
|
||
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
|
||
.muted { color: hsl(var(--muted-foreground)); }
|
||
.cap { font-size: 10px; text-transform: uppercase; letter-spacing: .025em; color: hsl(var(--muted-foreground)); }
|
||
.head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
|
||
.head svg { color: hsl(var(--primary)); flex: none; }
|
||
.book { margin-left: auto; font-size: 10px; }
|
||
.figs { display: flex; flex-wrap: wrap; align-items: flex-end; column-gap: 16px; row-gap: 8px; }
|
||
.big { font-size: 24px; font-weight: 600; line-height: 1; }
|
||
.mid { font-size: 16px; font-weight: 600; line-height: 1; }
|
||
.under { margin-top: 4px; font-size: 10px; }
|
||
.line { margin-top: 10px; display: flex; flex-wrap: wrap; align-items: center; column-gap: 8px; row-gap: 4px;
|
||
font-size: 11px; color: hsl(var(--muted-foreground)); }
|
||
.fg { color: hsl(var(--foreground)); }
|
||
.fast { display: inline-flex; align-items: center; gap: 2px; }
|
||
.fast svg { color: #f59e0b; }
|
||
a.link { color: inherit; text-decoration: none; cursor: pointer; }
|
||
a.link:hover { color: hsl(var(--foreground)); text-decoration: underline; }
|
||
.table { margin-top: 12px; border-top: 1px solid hsl(var(--border)); padding-top: 8px; font-size: 11px; }
|
||
.table > * + * { margin-top: 6px; }
|
||
.thead { display: flex; align-items: center; gap: 8px; }
|
||
.thead .grow { flex: 1; }
|
||
.w12 { width: 48px; text-align: right; flex: none; }
|
||
.row { min-width: 0; }
|
||
.r1 { display: flex; min-width: 0; align-items: center; gap: 6px; }
|
||
.tags { display: flex; min-width: 0; flex: 1; align-items: center; gap: 4px; flex-wrap: wrap; }
|
||
.amt { flex: none; }
|
||
.r2 { margin-top: 2px; padding-left: 4px; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||
.efforts { margin: 4px 0 0 8px; padding-left: 8px; border-left: 1px solid hsl(var(--border)); }
|
||
.efforts > * + * { margin-top: 4px; }
|
||
.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 6px; font-size: 10px;
|
||
font-weight: 500; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
|
||
.noeff { font-size: 10px; font-style: italic; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div id="root"></div>
|
||
<script>
|
||
(function () {
|
||
"use strict";
|
||
var A = window.aiAgentPlugin || {};
|
||
var root = document.getElementById("root");
|
||
var U = {};
|
||
|
||
// ── i18n (the app's own French strings) ──────────────────────────────────
|
||
var FR = {
|
||
"Plan usage": "Utilisation du forfait", "list price": "prix public", "of the week": "de la semaine",
|
||
"of a 5h window": "d'une fenêtre de 5 h", "{units} plan units": "{units} unités de forfait",
|
||
"(incl. {n} subagents)": "(dont {n} sous-agents)", "{n} fast": "{n} en mode rapide",
|
||
"rate fitted {date}": "taux ajusté le {date}", "seeded rate": "taux initial",
|
||
"By model · effort": "Par modèle · effort", "% wk": "% sem.", "no effort": "sans effort",
|
||
"{n} turn": "{n} tour", "{n} turns": "{n} tours", "prices {book}": "tarifs {book}", "B": "Md"
|
||
};
|
||
function fr() { return U.lang === "fr"; }
|
||
function loc() { return fr() ? "fr-FR" : "en-US"; }
|
||
function t(en, vars) {
|
||
var s = (fr() && FR[en]) || en;
|
||
return s.replace(/\{(\w+)\}/g, function (m, k) { return vars && vars[k] != null ? String(vars[k]) : m; });
|
||
}
|
||
function num(v) { return typeof v === "number" && isFinite(v) ? v : 0; }
|
||
function dec(v, d) { var s = v.toFixed(d); return fr() ? s.replace(".", ",") : s; }
|
||
function fmtCost(usd) {
|
||
var eur = U.currency === "EUR";
|
||
var rate = typeof U.usdToEur === "number" && U.usdToEur > 0 ? U.usdToEur : 0.92;
|
||
var v = eur ? num(usd) * rate : num(usd);
|
||
var sym = eur ? "€" : "$";
|
||
var n = !v ? "0" : v < 0.01 ? dec(v, 4) : v < 1 ? dec(v, 3) : v < 100 ? dec(v, 2) : Math.round(v).toLocaleString(loc());
|
||
return fr() ? n + " " + sym : sym + n;
|
||
}
|
||
function fmtTokens(n) {
|
||
var a = Math.abs(n);
|
||
if (a < 1000) return Math.round(n).toLocaleString(loc());
|
||
var div = a >= 1e9 ? 1e9 : a >= 1e6 ? 1e6 : 1e3;
|
||
var suf = a >= 1e9 ? t("B") : a >= 1e6 ? "M" : "K";
|
||
var v = n / div;
|
||
var s = Math.abs(v) >= 100 ? v.toFixed(0) : v.toFixed(1).replace(/\.0$/, "");
|
||
return (fr() ? s.replace(".", ",") : s) + suf;
|
||
}
|
||
function fmtPlanPct(p, digits) {
|
||
digits = digits == null ? 1 : digits;
|
||
if (p == null || !isFinite(p)) return "—";
|
||
var floor = 0.5 * Math.pow(10, -digits);
|
||
if (p > 0 && p < floor) return "<" + dec(Math.pow(10, -digits), digits) + "%";
|
||
return dec(p, digits) + "%";
|
||
}
|
||
function fmtStampDate(ts) {
|
||
if (!ts) return null;
|
||
return new Date(ts * 1000).toLocaleDateString(loc(), { day: "numeric", month: "short" });
|
||
}
|
||
function planPctTitle(p) {
|
||
var when = fmtStampDate(p.calibratedAt);
|
||
var week = fmtPlanPct(p.week, 2);
|
||
var head = p.h5 != null
|
||
? (fr() ? "≈ " + week + " de la limite hebdomadaire de ce compte · " + fmtPlanPct(p.h5, 1) + " d'une fenêtre de 5 heures"
|
||
: "≈ " + week + " of this account's weekly limit · " + fmtPlanPct(p.h5, 1) + " of a 5-hour window")
|
||
: (fr() ? "≈ " + week + " de la limite hebdomadaire de ce compte" : "≈ " + week + " of this account's weekly limit");
|
||
var tail = when ? (fr() ? "calibré le " + when : "calibrated " + when)
|
||
: (fr() ? "taux initial, pas encore ajusté" : "seeded rate, not yet fitted");
|
||
return head + " (" + tail + ")";
|
||
}
|
||
|
||
// ── DOM helpers (built node by node: model names come from transcripts) ───
|
||
function el(tag, cls, kids, attrs) {
|
||
var n = document.createElement(tag);
|
||
if (cls) n.className = cls;
|
||
if (attrs) for (var k in attrs) if (attrs[k] != null) n.setAttribute(k, attrs[k]);
|
||
(kids || []).forEach(function (c) { if (c != null) n.appendChild(typeof c === "string" ? document.createTextNode(c) : c); });
|
||
return n;
|
||
}
|
||
var NS = "http://www.w3.org/2000/svg";
|
||
function icon(shapes, size) {
|
||
var s = document.createElementNS(NS, "svg");
|
||
var a = { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor",
|
||
"stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", "aria-hidden": "true" };
|
||
for (var k in a) s.setAttribute(k, a[k]);
|
||
shapes.forEach(function (sh) {
|
||
var e = document.createElementNS(NS, sh[0]);
|
||
for (var k2 in sh[1]) e.setAttribute(k2, sh[1][k2]);
|
||
s.appendChild(e);
|
||
});
|
||
return s;
|
||
}
|
||
var I_GAUGE = [["path", { d: "M15.6 2.7a10 10 0 1 0 5.7 5.7" }], ["circle", { cx: "12", cy: "12", r: "2" }], ["path", { d: "M13.4 10.6 19 5" }]];
|
||
var I_ZAP = [["path", { d: "M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z" }]];
|
||
var I_SPARK = [["path", { d: "M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z" }]];
|
||
var I_CPU = [["rect", { width: "16", height: "16", x: "4", y: "4", rx: "2" }], ["rect", { width: "6", height: "6", x: "9", y: "9", rx: "1" }],
|
||
["path", { d: "M15 2v2M15 20v2M2 15h2M2 9h2M20 15h2M20 9h2M9 2v2M9 20v2" }]];
|
||
var I_BOT = [["path", { d: "M12 8V4H8" }], ["rect", { width: "16", height: "12", x: "4", y: "8", rx: "2" }], ["path", { d: "M2 14h2M20 14h2M15 13v2M9 13v2" }]];
|
||
var I_EFFORT = [["path", { d: "m12 14 4-4" }], ["path", { d: "M3.34 19a10 10 0 1 1 17.32 0" }]];
|
||
var I_FLAME = [["path", { d: "M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z" }]];
|
||
|
||
// ── model + effort pills (lib/models.tsx ModelTag / EffortTag) ────────────
|
||
var HUE = { violet: "139,92,246", amber: "245,158,11", rose: "244,63,94", sky: "14,165,233", teal: "20,184,166",
|
||
emerald: "16,185,129", blue: "59,130,246", slate: "100,116,139", indigo: "99,102,241", orange: "249,115,22" };
|
||
var FAMILIES = [
|
||
["fable", "rose", I_SPARK], ["opus", "violet", I_SPARK], ["sonnet", "amber", I_SPARK], ["haiku", "sky", I_SPARK],
|
||
["inkling", "teal", I_CPU], ["qwen", "teal", I_CPU], ["gpt", "emerald", I_BOT], ["gemini", "blue", I_SPARK]
|
||
];
|
||
function familyOf(id) {
|
||
var bare = String(id || "").split("/").pop();
|
||
for (var i = 0; i < FAMILIES.length; i++) {
|
||
var f = FAMILIES[i][0];
|
||
if (bare.indexOf(f + "-") === 0 || bare.indexOf(f) === 0 && /^(qwen|gpt|gemini|inkling)/.test(f) ||
|
||
String(id).indexOf("-" + f) !== -1 || bare === f) return FAMILIES[i];
|
||
}
|
||
return null;
|
||
}
|
||
function modelLabel(id) {
|
||
var f = familyOf(id);
|
||
var tail = String(id).split("/").pop();
|
||
if (f && f[0] === "qwen") { var m = tail.match(/qwen(\d+(?:\.\d+)?)/); return m ? "qwen " + m[1] : tail; }
|
||
if (!f) return String(id).indexOf("/") !== -1 ? tail : String(id).replace("claude-", "");
|
||
if (String(id).indexOf("claude-") === 0 || String(id).indexOf("claude-" + f[0]) !== -1) {
|
||
var v = (String(id).split(f[0] + "-")[1] || "").split("-")
|
||
.filter(function (p) { return /^\d+$/.test(p) && p.length !== 8; }).join(".");
|
||
return v ? f[0] + " " + v : f[0];
|
||
}
|
||
return tail.replace(/-/g, " ");
|
||
}
|
||
function pill(text, rgb, shapes, title) {
|
||
var p = el("span", "pill", [icon(shapes, 10), text], { title: title });
|
||
p.style.background = "rgba(" + rgb + ",.1)";
|
||
p.style.color = "rgb(" + rgb + ")";
|
||
return p;
|
||
}
|
||
function modelTag(id) {
|
||
var f = familyOf(id);
|
||
return f ? pill(modelLabel(id), HUE[f[1]], f[2], id) : pill(modelLabel(id), HUE.slate, I_BOT, id);
|
||
}
|
||
var EFFORTS = ["low", "medium", "high", "xhigh", "max", "none"];
|
||
var EFFORT_LOOK = { none: ["slate", I_EFFORT], minimal: ["slate", I_EFFORT], low: ["sky", I_EFFORT],
|
||
medium: ["emerald", I_EFFORT], high: ["indigo", I_EFFORT], xhigh: ["orange", I_FLAME], max: ["rose", I_FLAME],
|
||
think: ["indigo", I_EFFORT] };
|
||
function effortTag(e) {
|
||
var l = EFFORT_LOOK[e];
|
||
var tip = fr() ? "effort " + e : "ran at " + e + " effort";
|
||
if (!l) { var p = el("span", "pill muted", [icon(I_EFFORT, 10), e], { title: tip }); p.style.background = "hsl(var(--muted))"; return p; }
|
||
return pill(e, HUE[l[0]], l[1], tip);
|
||
}
|
||
function effortRank(e) { var i = EFFORTS.indexOf(e); return i === -1 ? EFFORTS.length : i; }
|
||
|
||
// ── the card ──────────────────────────────────────────────────────────────
|
||
function row(label, turns, tokens, cost, pct, strong) {
|
||
var r1 = el("div", "r1", [
|
||
el("span", "tags", label),
|
||
el("span", "amt mono " + (strong ? "fg" : "muted"), [fmtCost(cost)]),
|
||
pct != null ? el("span", "w12 mono muted", [pct]) : null
|
||
]);
|
||
var tn = turns === 1 ? t("{n} turn", { n: turns }) : t("{n} turns", { n: turns });
|
||
return el("div", "row", [r1, el("div", "r2 mono muted", [fmtTokens(num(tokens)) + " tok · " + tn])]);
|
||
}
|
||
|
||
function render() {
|
||
var units = num(U.planUnits);
|
||
var byModel = U.byModel && typeof U.byModel === "object" ? U.byModel : {};
|
||
var models = Object.keys(byModel).map(function (k) { return [k, byModel[k] || {}]; });
|
||
if (!(units > 0) && !models.length) { show(null); return; }
|
||
models.sort(function (a, b) { return num(b[1].cost) - num(a[1].cost); });
|
||
var p = U.planPct && typeof U.planPct === "object" ? U.planPct : null;
|
||
var perPct = p && p.week && units > 0 ? units / p.week : null;
|
||
var subUnits = num(U.subagentPlanUnits);
|
||
var calibrated = fmtStampDate(p && p.calibratedAt);
|
||
|
||
var head = el("div", "head", [icon(I_GAUGE, 14), el("div", "cap", [t("Plan usage")]),
|
||
U.priceBook ? el("span", "book mono muted", [t("prices {book}", { book: U.priceBook })],
|
||
{ title: fr() ? "Le barème avec lequel chaque chiffre ici a été calculé (prix public exact par version de modèle)"
|
||
: "The price book every figure here was computed with (exact list price per model version)" }) : null]);
|
||
|
||
var figs = el("div", "figs", [
|
||
el("div", null, [el("div", "big", [fmtCost(U.cost)]), el("div", "under muted", [t("list price")])]),
|
||
p && p.week != null ? el("div", null, [el("div", "mid mono", ["≈" + fmtPlanPct(p.week, 2)]),
|
||
el("div", "under muted", [t("of the week")])], { title: planPctTitle(p) }) : null,
|
||
p && p.h5 != null ? el("div", null, [el("div", "mid mono", [fmtPlanPct(p.h5)]),
|
||
el("div", "under muted", [t("of a 5h window")])], { title: planPctTitle(p) }) : null
|
||
]);
|
||
|
||
var unitsTxt = t("{units} plan units", { units: "\u0000" }).split("\u0000");
|
||
var unitSpan = el("span", null, [unitsTxt[0], el("span", "mono fg", [units.toFixed(1)]), unitsTxt[1] || "",
|
||
subUnits > 0 ? " " + t("(incl. {n} subagents)", { n: subUnits.toFixed(1) }) : null],
|
||
{ title: fr() ? "Ce que comptent les limites du forfait : les tokens au prix du modèle auquel ils sont comptés, Fable ×1,75"
|
||
: "What the plan's limits count: the tokens priced as the model they're metered as, Fable ×1.75" });
|
||
var line = el("div", "line", [unitSpan]);
|
||
if (num(U.fastCalls) > 0) {
|
||
var fastTxt = t("{n} fast", { n: "\u0000" }).split("\u0000");
|
||
line.appendChild(el("span", "fast", ["· ", icon(I_ZAP, 12), fastTxt[0], el("span", "mono fg", [String(U.fastCalls)]), fastTxt[1] || ""],
|
||
{ title: fr() ? "Appels API en mode rapide — chaque type de token facturé 2×" : "API calls in fast mode — billed 2× every token type" }));
|
||
}
|
||
if (p) {
|
||
var a = el("a", "link", [calibrated ? t("rate fitted {date}", { date: calibrated }) : t("seeded rate")],
|
||
{ href: "#", role: "link" });
|
||
a.addEventListener("click", function (e) { e.preventDefault(); if (A.navigate) A.navigate("/plugins/plan-usage/board"); });
|
||
line.appendChild(el("span", null, ["· ", a]));
|
||
}
|
||
|
||
var card = el("div", "card", [head, figs, line]);
|
||
if (models.length) {
|
||
var pctOf = function (u) { return perPct ? fmtPlanPct(num(u) / perPct, 2) : null; };
|
||
var table = el("div", "table", [el("div", "thead cap", [el("span", "grow", [t("By model · effort")]), el("span", null, ["$"]),
|
||
perPct ? el("span", "w12", [t("% wk")]) : null])]);
|
||
models.forEach(function (mm) {
|
||
var model = mm[0], m = mm[1];
|
||
var efforts = Object.keys(m.efforts || {}).map(function (k) { return [k, m.efforts[k] || {}]; })
|
||
.sort(function (a2, b2) { return effortRank(a2[0]) - effortRank(b2[0]); });
|
||
var single = efforts.length === 1 ? efforts[0][0] : null;
|
||
var wrap = el("div", null, [row([modelTag(model), single && single !== "none" ? effortTag(single) : null],
|
||
num(m.turns), m.tokens, m.cost, pctOf(m.planUnits), true)]);
|
||
if (efforts.length > 1) {
|
||
wrap.appendChild(el("div", "efforts", efforts.map(function (ee) {
|
||
var lab = ee[0] === "none"
|
||
? el("span", "noeff muted", [t("no effort")], { title: fr() ? "Tours sans --effort" : "Turns with no --effort stamp" })
|
||
: effortTag(ee[0]);
|
||
return row([lab], num(ee[1].turns), ee[1].tokens, ee[1].cost, pctOf(ee[1].planUnits), false);
|
||
})));
|
||
}
|
||
table.appendChild(wrap);
|
||
});
|
||
card.appendChild(table);
|
||
}
|
||
show(card);
|
||
}
|
||
|
||
// ── host bridge: empty / resize / live updates ────────────────────────────
|
||
var lastH = -1, empty = null;
|
||
function fit() {
|
||
var h = empty ? 0 : Math.ceil(root.getBoundingClientRect().height);
|
||
if (h !== lastH) { lastH = h; if (A.resize) A.resize(h); }
|
||
}
|
||
function show(node) {
|
||
var nowEmpty = !node;
|
||
while (root.firstChild) root.removeChild(root.firstChild);
|
||
if (node) root.appendChild(node);
|
||
if (nowEmpty !== empty) { empty = nowEmpty; if (A.setEmpty) A.setEmpty(nowEmpty); }
|
||
fit();
|
||
}
|
||
if (window.ResizeObserver) new ResizeObserver(fit).observe(root);
|
||
var got = false;
|
||
function onUpdate(u) { got = true; U = u && typeof u === "object" ? u : {}; render(); }
|
||
if (typeof A.onUpdate === "function") A.onUpdate(onUpdate);
|
||
if (!got) onUpdate((A.init && A.init.update) || {});
|
||
if (typeof A.onTheme === "function") A.onTheme(function () { render(); });
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|