Merge branch 'feature/radio-receipts-hub' into unify/skills-20261112-night
# Conflicts: # orchestrator/kvb_orchestrator/hub.py # orchestrator/server.py # orchestrator/templates/page-stream.js # skills/kvb-org-radio/scripts/radio.py
This commit is contained in:
commit
5b65fb5284
25 files changed
+1433
-88
No files matched your search
@@ -281,6 +281,11 @@ input[type="datetime-local"] { padding: 3px 6px; border: 1px solid var(--line-st
|
||||
.custom { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
||||
.avatar { display: inline-grid; place-items: center; flex: none; width: 26px; height: 26px; overflow: hidden; border-radius: 50%; background: var(--sunken); border: 1px solid var(--line); }
|
||||
.avatar.big { width: 52px; height: 52px; }
|
||||
.readers { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 6px; }
|
||||
.reader { position: relative; display: inline-flex; }
|
||||
.reader .avatar { width: 22px; height: 22px; }
|
||||
.reader .ack { position: absolute; right: -4px; bottom: -3px; display: inline-grid; place-items: center; width: 13px; height: 13px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 9px; box-shadow: 0 0 0 1.5px var(--panel); }
|
||||
.readers-more { padding: 0 7px; border-radius: 999px; background: var(--neutral-soft); color: var(--muted); font-size: var(--fs-xs); font-weight: 650; line-height: 20px; cursor: default; }
|
||||
.avatar svg { display: block; width: 100%; height: 100%; }
|
||||
.linkish { padding: 0; border: 0; background: none; color: inherit; font-weight: 650; text-align: left; cursor: pointer; overflow-wrap: anywhere; }
|
||||
.linkish:hover { color: var(--accent); text-decoration: underline; }
|
||||
@@ -470,6 +475,8 @@ pre.notes { margin: 0; padding: 8px 10px; background: var(--sunken); border-radi
|
||||
|
||||
{% include "radioset.js" %}
|
||||
|
||||
{% include "receipts.js" %}
|
||||
|
||||
{% include "bubbles.js" %}
|
||||
|
||||
{% include "diffs.js" %}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function history(key) {
|
||||
const known = (people()[key] || {names: [nameOf(key)]}).names;
|
||||
const radio = state.radio.filter((row) => row.source === key || row.targets.includes(key)).map((row) => ({ts: row.ts, mine: row.from === HUMAN, who: row.from, text: row.text}));
|
||||
const sent = state.messages.filter((message) => known.includes(message.to) || message.to === "*").map((message) => ({ts: message.created_ts, mine: true, who: HUMAN, text: message.upload ? `${message.text}\n📎 ${message.upload}` : message.text, id: message.id, voice: message.voice}));
|
||||
const radio = state.radio.filter((row) => row.source === key || row.targets.includes(key)).map((row) => ({ts: row.ts, mine: row.from === HUMAN, who: row.from, text: row.text, readers: row.readers, acks: row.acks}));
|
||||
const sent = state.messages.filter((message) => known.includes(message.to) || message.to === "*").map((message) => ({ts: message.created_ts, mine: true, who: HUMAN, text: message.upload ? `${message.text}\n📎 ${message.upload}` : message.text, id: message.id, voice: message.voice, readers: message.readers, acks: message.acks}));
|
||||
const hubIds = new Set(sent.map((entry) => entry.id));
|
||||
const relayed = radio.filter((entry) => !(entry.who === HUMAN && [...hubIds].some((id) => entry.text.includes(`[kvb-orchestrator msg ${id}]`))));
|
||||
return [...relayed, ...sent].sort((a, b) => a.ts - b.ts).slice(-80);
|
||||
@@ -31,7 +31,7 @@
|
||||
h("span", {class: "muted"}, `${dash(claim.runtime)} · since ${dash(claim.since)}`)))) : h("p", {class: "muted"}, "No claims."));
|
||||
const rows = history(ui.agent);
|
||||
agentDom.history.replaceChildren(rows.length
|
||||
? h("div", {}, rows.map((row) => h("div", {class: `bubble ${row.mine ? "mine" : "theirs"}`}, h("span", {class: "muted"}, `${row.who} · `, when(row.ts)), row.text, voiceReplay(row.voice))))
|
||||
? h("div", {}, rows.map((row) => h("div", {class: `bubble ${row.mine ? "mine" : "theirs"}`}, h("span", {class: "muted"}, `${row.who} · `, when(row.ts)), row.text, voiceReplay(row.voice), readerRow(row))))
|
||||
: h("p", {class: "muted"}, "No history in the chosen time range."));
|
||||
placePopup();
|
||||
}
|
||||
|
||||
@@ -95,6 +95,14 @@
|
||||
const nameOf = (key) => (people()[key] || {now: String(key).replace(/^name:/, "")}).now;
|
||||
const agentKey = (who) => (people()[who] ? who : (Object.entries(people()).find(([, entry]) => entry.now === who || entry.names.includes(who)) || [who])[0]);
|
||||
const chairKey = () => (state.graph.nodes.find((node) => node.kind === "chair") || {id: HUMAN}).id;
|
||||
const readLabel = (reader) => Receipts.label(reader, (ts) => absolute.format(stampOf(ts)));
|
||||
const readerRow = (row) => {
|
||||
const {shown, hidden} = Receipts.strip(row);
|
||||
const avatar = (reader) => h("span", {class: "reader", "data-session": reader.session, "data-acked": String(reader.acked), role: "img", ...named(readLabel(reader))},
|
||||
face(people()[reader.session] ? reader.session : reader.name, false), reader.acked ? h("span", {class: "ack", "aria-hidden": "true"}, icon("bi-check2-all")) : null);
|
||||
const more = hidden.length ? h("span", {class: "readers-more", role: "img", ...named(`${hidden.length} more readers`, [...shown, ...hidden].map(readLabel).join("\n"))}, `+${hidden.length}`) : null;
|
||||
return shown.length ? h("div", {class: "readers", role: "group", "aria-label": `Read by ${shown.length + hidden.length}`}, shown.map(avatar), more) : null;
|
||||
};
|
||||
const stamp = (life) => [life.born ? `🐣 ${life.born}` : "", life.died ? `🪦 ${life.died}` : ""].filter(Boolean).join(" · ");
|
||||
|
||||
function toast(title, lines, good) {
|
||||
|
||||
@@ -216,13 +216,14 @@
|
||||
h("span", {class: "radio-route"}, `${row.from} → ${targetsOf(row)}`),
|
||||
h("span", {class: "radio-line", title: first}, first)),
|
||||
h("pre", {class: "radio-full"}, row.text),
|
||||
voiceReplay(message ? message.voice : null)));
|
||||
voiceReplay(message ? message.voice : null)),
|
||||
readerRow(row));
|
||||
}
|
||||
|
||||
function drawLog() {
|
||||
const dom = radioDom.log;
|
||||
const entry = radioSet.log;
|
||||
const sig = JSON.stringify([state.radio.length, state.radio.length ? state.radio[state.radio.length - 1].ts : 0, state.messages.length, entry, Math.floor(Date.now() / 60000)]);
|
||||
const sig = JSON.stringify([state.radio.length, state.radio.length ? state.radio[state.radio.length - 1].ts : 0, state.messages.length, Receipts.signature(state.radio), Receipts.signature(state.messages), entry, Math.floor(Date.now() / 60000)]);
|
||||
if (sig === dom.sig) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -133,12 +133,13 @@
|
||||
const alarm = entry.kind === "radio" && (entry.part === "mayday" || entry.part === "pan-pan");
|
||||
const renamed = entry.now && entry.now !== entry.agent ? h("span", {title: `now: ${entry.now}`}, person(entry.agent)) : person(entry.agent);
|
||||
const who = entry.agent ? [face(entry.agent, false), renamed] : entry.session ? h("strong", {title: entry.session}, entry.session.slice(0, 8)) : null;
|
||||
const headline = entry.kind === "transcript" || entry.kind === "ask" || entry.kind === "operator" ? null : h("span", {class: "headline"}, entry.title);
|
||||
const headline = entry.kind === "transcript" || entry.kind === "ask" || entry.kind === "operator" ? null : h("span", {class: "headline"}, Receipts.headline(entry));
|
||||
return h("li", {class: `entry k-${entry.kind}${entry.waiting ? " waiting" : ""}${alarm ? " alarm" : ""}`, "data-ref": item ? keyOf(item) : null, "data-item": `message:${entry.ts}/${entry.id}`, "data-to": item && item.to ? item.to : null},
|
||||
h("div", {class: "msg-meta"}, when(entry.ts), kindPill(entry), extras(entry)),
|
||||
h("div", {},
|
||||
h("div", {class: "route", "data-star-slot": ""}, who, entry.sub ? h("button", {type: "button", class: "linkish muted", on: {click: () => focusSub(entry.session, entry.sub)}}, `› Subagent ${entry.sub.slice(0, 12)}`) : null, entry.kind === "ask" ? h("strong", {}, entry.title) : null, headline),
|
||||
body(entry),
|
||||
entry.kind === "radio" ? readerRow(entry.ref) : null,
|
||||
item ? diffBlocks(item) : null,
|
||||
item ? feedbackList(keyOf(item)) : null,
|
||||
item ? h("div", {class: "line-actions"}, actionsFor(item)) : null));
|
||||
|
||||
@@ -103,7 +103,7 @@ const RadioSet = (() => {
|
||||
}
|
||||
|
||||
function sentRows(messages, human) {
|
||||
return messages.map((message) => ({ts: message.created_ts, from: human, to: message.to === "*" ? [] : [message.to], class: message.class || "post", text: message.text, voice: message.voice, sent: true}));
|
||||
return messages.map((message) => ({ts: message.created_ts, from: human, to: message.to === "*" ? [] : [message.to], class: message.class || "post", text: message.text, voice: message.voice, sent: true, readers: message.readers, acks: message.acks}));
|
||||
}
|
||||
|
||||
function tabRows(rows, tab, human, messages) {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
const Receipts = (() => {
|
||||
"use strict";
|
||||
const SHOWN = 8;
|
||||
|
||||
/**
|
||||
* @param {object} row a radio row of the state or the ref of a radio entry of the Stream, with readers and acks.
|
||||
* @returns {object} shown and hidden: every reader with acked true where its receipt exists, the first SHOWN as avatars and the rest behind "+N".
|
||||
*/
|
||||
function strip(row) {
|
||||
const acks = new Set(Array.isArray(row.acks) ? row.acks : []);
|
||||
const readers = (Array.isArray(row.readers) ? row.readers : []).map((reader) => ({...reader, acked: acks.has(reader.session)}));
|
||||
return {shown: readers.slice(0, SHOWN), hidden: readers.slice(SHOWN)};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} reader an entry of strip().
|
||||
* @param {function(number): string} format renders a read time.
|
||||
* @returns {string} the reader's name, its read time where the hub knows one, prefixed "about" where only a sighting gives it, and whether it acknowledged.
|
||||
*/
|
||||
function label(reader, format) {
|
||||
const known = reader.read !== null && reader.read !== undefined;
|
||||
const read = known ? `read ${reader.approximate ? "about " : ""}${format(reader.read)}` : "read";
|
||||
return [reader.name, read, reader.acked ? "acknowledged" : ""].filter(Boolean).join(" · ");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} entry a Stream entry.
|
||||
* @returns {string} its headline; a radio entry whose sender the route already shows names only the recipients.
|
||||
*/
|
||||
function headline(entry) {
|
||||
if (entry.kind !== "radio" || !entry.agent) {
|
||||
return entry.title;
|
||||
}
|
||||
return `→ ${entry.ref.to.length ? entry.ref.to.join(", ") : "all"}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array<object>} rows radio rows of the state.
|
||||
* @returns {string} changes whenever a reader, its read time or an ack of any row does, so a log that redraws only on change shows them on the next poll.
|
||||
*/
|
||||
function signature(rows) {
|
||||
const read = (reader) => `${reader.session}@${reader.read ?? ""}${reader.approximate ? "~" : ""}`;
|
||||
return rows.map((row) => `${(row.readers || []).map(read).join(",")}/${(row.acks || []).join(",")}`).join("|");
|
||||
}
|
||||
|
||||
return {SHOWN, strip, label, headline, signature};
|
||||
})();
|
||||
if (typeof module === "object" && module.exports) {
|
||||
module.exports = Receipts;
|
||||
}
|
||||
Reference in new issue
Block a user