Show turn summaries only in the transcript, not as inbox reports
This commit is contained in:
+26
-16
@@ -1,12 +1,10 @@
|
||||
import type { InboxItem, NotificationPrefs } from "./api.js";
|
||||
import type { ByreEvent, InboxItem, NotificationPrefs } from "./api.js";
|
||||
import { findTask, focusTask, state } from "./state.js";
|
||||
|
||||
function wants(p: NotificationPrefs, item: InboxItem): boolean {
|
||||
switch (item.kind) {
|
||||
case "question":
|
||||
return item.blocking ? p.blocking_questions : p.questions;
|
||||
case "report":
|
||||
return p.reports;
|
||||
case "session_error":
|
||||
return p.errors;
|
||||
case "rate_limited":
|
||||
@@ -16,26 +14,38 @@ function wants(p: NotificationPrefs, item: InboxItem): boolean {
|
||||
|
||||
function itemText(item: InboxItem): string {
|
||||
const p = item.payload;
|
||||
const text =
|
||||
item.kind === "question" ? String(p["question"] ?? "")
|
||||
: item.kind === "report" ? String(p["text"] ?? "")
|
||||
return item.kind === "question" ? String(p["question"] ?? "")
|
||||
: item.kind === "session_error" ? `Error: ${String(p["error"] ?? "")}`
|
||||
: "Rate limited";
|
||||
const line = text.trim().split("\n")[0] ?? "";
|
||||
return line.length > 200 ? `${line.slice(0, 199)}…` : line;
|
||||
}
|
||||
|
||||
export function notifyInbox(item: InboxItem): void {
|
||||
if (!("Notification" in window) || Notification.permission !== "granted" || !state.me || !wants(state.me.notification_prefs, item)) {
|
||||
return;
|
||||
}
|
||||
const title = findTask(item.task_id)?.title;
|
||||
const n = new Notification(title ? `byre · ${title}` : "byre", { body: itemText(item), tag: item.id });
|
||||
function show(taskId: string, tag: string, text: string): void {
|
||||
const line = text.trim().split("\n")[0] ?? "";
|
||||
const title = findTask(taskId)?.title;
|
||||
const n = new Notification(title ? `byre · ${title}` : "byre", { body: line.length > 200 ? `${line.slice(0, 199)}…` : line, tag });
|
||||
n.onclick = () => {
|
||||
window.focus();
|
||||
if (item.task_id) {
|
||||
focusTask(item.task_id);
|
||||
if (taskId) {
|
||||
focusTask(taskId);
|
||||
}
|
||||
n.close();
|
||||
};
|
||||
}
|
||||
|
||||
function allowed(): boolean {
|
||||
return "Notification" in window && Notification.permission === "granted" && !!state.me;
|
||||
}
|
||||
|
||||
export function notifyInbox(item: InboxItem): void {
|
||||
if (!allowed() || !wants(state.me!.notification_prefs, item)) {
|
||||
return;
|
||||
}
|
||||
show(item.task_id, item.id, itemText(item));
|
||||
}
|
||||
|
||||
export function notifyTurn(ev: ByreEvent): void {
|
||||
if (!allowed() || !state.me!.notification_prefs.reports || ev.payload["summary"] !== true || !ev.task_id) {
|
||||
return;
|
||||
}
|
||||
show(ev.task_id, `turn-${ev.seq}`, String(ev.payload["result"] ?? ""));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user