From 581db146fce053ec33a62d2a3976d3dd9f26de04 Mon Sep 17 00:00:00 2001 From: Danyang Chen Date: Thu, 19 Nov 2026 12:38:11 +0800 Subject: [PATCH] Clear a manual unread mark from the row menu and the chat header (#3114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A chat already marked unread only offered Mark as Unread again, and the conversation header had no unread entry, so the local mark could not be cleared without opening the chat. The row menus now offer Clear unread mark when `ui.unread` holds that row, the header draws one bell toggle that maps the Session id to the sidebar's row id, and clearing either one writes only the local key — completion and pending-interaction flags are untouched. Fixes #3205 Part of #3114 --- changelog.d/3114-unread-mark-menu.fixed.md | 1 + core/client.js | 36 +- core/src/client/context-menu.js | 11 +- core/src/client/header.js | 27 +- core/src/client/i18n.js | 1 + core/src/client/overlays.js | 2 +- core/src/client/styles.js | 4 + core/test/unread-mark-menu.test.js | 175 ++ docs/subsystems/core-client.md | 6 +- patches/ds-bot/0001-core-fixes.patch | 3 +- patches/ds-bot/0003-flybot-api-client.patch | 39 +- patches/ds-bot/0008-client-bundle.patch | 2030 +++++++++-------- patches/ds-bot/0012-room-membership.patch | 34 +- .../files/test/unread-mark-menu.test.js | 175 ++ 14 files changed, 1512 insertions(+), 1032 deletions(-) create mode 100644 changelog.d/3114-unread-mark-menu.fixed.md create mode 100644 core/test/unread-mark-menu.test.js create mode 100644 patches/ds-bot/files/test/unread-mark-menu.test.js diff --git a/changelog.d/3114-unread-mark-menu.fixed.md b/changelog.d/3114-unread-mark-menu.fixed.md new file mode 100644 index 000000000..4ff083ed6 --- /dev/null +++ b/changelog.d/3114-unread-mark-menu.fixed.md @@ -0,0 +1 @@ +**Clear unread mark** is now offered on a chat that is already marked unread — in its row menu and in the conversation header — so the local mark can be cleared without opening the chat, and clearing it does not acknowledge system unread ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)). diff --git a/core/client.js b/core/client.js index 01ae3d3a4..f5f7dc0f5 100644 --- a/core/client.js +++ b/core/client.js @@ -769,6 +769,7 @@ var ZH = { Pin: "置顶", Pinned: "已置顶", "Mark as Unread": "标为未读", + "Clear unread mark": "清除手动未读标记", "Group settings": "群设置", "Rename group": "重命名群聊", "Copy conversation ID": "复制对话 ID", @@ -5286,6 +5287,10 @@ body[data-bt-motion=quiet] .bt-mark[data-poke]{cursor:default} .bt-pill[aria-expanded=true] .bt-pill-go svg{transform:rotate(180deg)} .bt-pill[data-memory=updated]:is(:hover,:focus-visible,[aria-expanded=true]) .bt-pill-go{width:0;margin-left:-8px;opacity:0;filter:blur(6px);transform:translateX(-6px)} @media (prefers-reduced-motion:reduce){.bt-pill,.bt-pill-go,.bt-pill-go svg{transition:none!important}.bt-pill-go{filter:none}.bt-pill:active{transform:none}} +.bt-head-unread{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;padding:0;border:0;border-radius:50%;background:none;color:var(--bt-ink-3);cursor:pointer} +.bt-head-unread:hover{background:var(--bt-hover);color:var(--bt-ink)} +.bt-head-unread[aria-pressed=true]{color:var(--bt-accent)} +.bt-head-unread svg{width:15px;height:15px} .bt-astack{display:flex;flex-direction:column;align-items:flex-start;gap:4px;margin:0} .bt-bubble{max-width:min(80%,560px,calc(100% - 82px));background:var(--bt-bubble);color:var(--bt-ink);border-radius:18px;padding:7px 12px;font-size:var(--dsh-content-font-size,14px);line-height:calc(var(--dsh-content-font-size,14px) + 8px);box-sizing:border-box;overflow-wrap:anywhere} @@ -13161,6 +13166,24 @@ function MemoryNotice({ shown }) { (0, import_react24.createElement)("span", { className: "bt-pill-mem-in", ref: inner }, (0, import_react24.createElement)("span", { className: "bt-pill-mem-ico" }, (0, import_react24.createElement)(MemoryIcon)), label) ); } +function unreadEntryId(roster, sessionId) { + const bot = roster?.byId?.[sessionId]; + const room2 = roster?.roomsById?.[sessionId]; + return bot?.id ?? room2?.id ?? roster?.agentOf?.[sessionId] ?? sessionId; +} +function SessionUnreadToggle({ sessionId, roster, unread, actions }) { + const target = unreadEntryId(roster, sessionId); + const marked = unread?.[target] === true; + const label = marked ? t("Clear unread mark") : t("Mark as Unread"); + return (0, import_react24.createElement)("button", { + type: "button", + className: "bt-head-unread", + "aria-pressed": marked, + "aria-label": label, + title: label, + onClick: () => marked ? actions.clearUnread(target) : actions.markUnread(target) + }, (0, import_react24.createElement)(UnreadIcon)); +} function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSession, useActivity, useBusyAcks, useMemoryNews, useTurnClock, useUi, useLive, actions }) { const roster = useRoster((value) => value); const title = useSessions((list) => list.byId[sessionId]?.displayTitle ?? list.byId[sessionId]?.title ?? ""); @@ -13170,6 +13193,7 @@ function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSe }); const hiddenTurns = roster.exchangeTurns?.[sessionId]; const visit = useUi((state) => state.visits?.[sessionId]); + const unread = useUi((state) => state.unread); const opening = useTurnClock((state) => { const first = openingTurn(state[sessionId], firstTurns, hiddenTurns); return first && !unseenSince(visit, first.start) ? clockLabel(first.start) : ""; @@ -13220,7 +13244,8 @@ function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSe }), (0, import_react24.createElement)(NewMessagePills, { key: sessionId, sessionId, hiddenTurns, useSessions, useUi, useTurnClock, actions }), (0, import_react24.createElement)(ActivityIndicator, { key: `activity:${sessionId}`, sessionId, useRoster, useSessionStatus, useSession, useLive, actions }), - (0, import_react24.createElement)(BusyAckBubble, { key: `busy-ack:${sessionId}`, sessionId, useRoster, useBusyAcks, useSessionStatus, useSession, useLive }) + (0, import_react24.createElement)(BusyAckBubble, { key: `busy-ack:${sessionId}`, sessionId, useRoster, useBusyAcks, useSessionStatus, useSession, useLive }), + (0, import_react24.createElement)(SessionUnreadToggle, { sessionId, roster, unread, actions }) ); } function useTranscriptView() { @@ -20903,7 +20928,7 @@ function ProjectsPage({ roster, actions, run, call: call4 }) { // src/client/context-menu.js var import_react46 = require("react"); -function ContextMenu({ menu, roster, actions, leaving = false }) { +function ContextMenu({ menu, roster, actions, leaving = false, unread }) { useEscape(() => actions.closeMenu()); (0, import_react46.useEffect)(() => { const onDown = (event) => { @@ -20925,13 +20950,14 @@ function ContextMenu({ menu, roster, actions, leaving = false }) { const room2 = roster.roomsById[menu.id]; const entry = bot ?? room2; if (entry === void 0) return null; + const unreadItem = unread?.[menu.id] === true ? [t("Clear unread mark"), UnreadIcon, () => actions.clearUnread(menu.id)] : [t("Mark as Unread"), UnreadIcon, () => actions.markUnread(menu.id)]; const isMainBot = isMainOf(roster, menu.id); const isTile = roster.mainBotId === menu.id; const mainCount = (roster.mainBotIds ?? []).length; const locked = typeof roster?.readOnly === "string" && roster.readOnly.trim() !== ""; const groups = bot?.remote ? [ [ - [t("Mark as Unread"), UnreadIcon, () => actions.markUnread(menu.id)] + unreadItem ], [ [t("Bot settings"), GearIcon, () => actions.openSettings("bots", bot.id)] @@ -20941,7 +20967,7 @@ function ContextMenu({ menu, roster, actions, leaving = false }) { ] : [ [ isTile || locked ? null : [entry.pinned ? t("Unpin") : t("Pin"), PinIcon, () => actions.setFlags(menu.id, { pinned: !entry.pinned })], - [t("Mark as Unread"), UnreadIcon, () => actions.markUnread(menu.id)] + unreadItem ], [ // One way to edit a Bot (#385): its name is edited in Edit Bot too. @@ -22374,7 +22400,7 @@ function Overlays({ useRoster, useUi, useSessions, useSessionStatus, useActivity ui2.palette ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(CommandPalette, { key: ui2.palette.token, start: ui2.palette.query, token: ui2.palette.token, roster, actions, useSessions }), document.body) : null, ui2.exchange ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(ExchangeDialog, { pair: ui2.exchange, roster, actions }), document.body) : null, ui2.voice ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(VoiceMode, { key: ui2.voice, sessionId: ui2.voice, roster, actions, useSessions, useSessionStatus }), document.body) : null, - menu ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(ContextMenu, { key: `${menu.kind ?? ""}:${menu.id}:${menu.x}:${menu.y}`, menu, roster, actions, leaving: menuLeaving }), document.body) : null, + menu ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(ContextMenu, { key: `${menu.kind ?? ""}:${menu.id}:${menu.x}:${menu.y}`, menu, roster, actions, unread: ui2.unread, leaving: menuLeaving }), document.body) : null, settings ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(SettingsDialog, { page: settings.page, id: settings.id, roster, actions, useUpdate, leaving: settingsLeaving }), document.body) : null, remoteBotSettings ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(RemoteBotSettingsSheet, { key: remoteBotSettings, bot: roster.byId[remoteBotSettings], roster, actions, leaving: remoteLeaving }), document.body) : null, memory && roster.byId[memory] ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(MemoryDialog, { key: memory, bot: roster.byId[memory], roster, actions, leaving: memoryLeaving }), document.body) : null, diff --git a/core/src/client/context-menu.js b/core/src/client/context-menu.js index 0633a08aa..860c11208 100644 --- a/core/src/client/context-menu.js +++ b/core/src/client/context-menu.js @@ -8,7 +8,7 @@ import { useSidebarStructure } from './flybot-slots.js' import { pluginItems } from './flybot-registry.js' import { LinkIcon } from './icons.js' -export function ContextMenu({ menu, roster, actions, leaving = false }) { +export function ContextMenu({ menu, roster, actions, leaving = false, unread }) { useEscape(() => actions.closeMenu()) useEffect(() => { const onDown = (event) => { if (!(event.target instanceof Element) || !event.target.closest('.bt-menu')) actions.closeMenu() } @@ -28,6 +28,11 @@ export function ContextMenu({ menu, roster, actions, leaving = false }) { const room = roster.roomsById[menu.id] const entry = bot ?? room if (entry === undefined) return null + // The manual unread mark is a local one (#3114): a chat already marked unread offers to + // clear it, and clearing drops only that key — a completion flag stays as it is. + const unreadItem = unread?.[menu.id] === true + ? [t('Clear unread mark'), UnreadIcon, () => actions.clearUnread(menu.id)] + : [t('Mark as Unread'), UnreadIcon, () => actions.markUnread(menu.id)] const isMainBot = isMainOf(roster, menu.id) const isTile = roster.mainBotId === menu.id const mainCount = (roster.mainBotIds ?? []).length @@ -37,7 +42,7 @@ export function ContextMenu({ menu, roster, actions, leaving = false }) { const groups = bot?.remote ? [ [ - [t('Mark as Unread'), UnreadIcon, () => actions.markUnread(menu.id)], + unreadItem, ], [ [t('Bot settings'), GearIcon, () => actions.openSettings('bots', bot.id)], @@ -48,7 +53,7 @@ export function ContextMenu({ menu, roster, actions, leaving = false }) { : [ [ isTile || locked ? null : [entry.pinned ? t('Unpin') : t('Pin'), PinIcon, () => actions.setFlags(menu.id, { pinned: !entry.pinned })], - [t('Mark as Unread'), UnreadIcon, () => actions.markUnread(menu.id)], + unreadItem, ], [ // One way to edit a Bot (#385): its name is edited in Edit Bot too. diff --git a/core/src/client/header.js b/core/src/client/header.js index 4be72cec2..825421806 100644 --- a/core/src/client/header.js +++ b/core/src/client/header.js @@ -1,7 +1,7 @@ import { createElement as h, Fragment, useEffect, useLayoutEffect, useRef, useState } from 'react' import { createPortal } from 'react-dom' import { currentPart, faceRowTitle, latestMemoryChange } from './text.js' -import { ArrowUpIcon, CloseIcon, ArrowDownIcon, MemoryIcon } from './icons.js' +import { ArrowUpIcon, CloseIcon, ArrowDownIcon, MemoryIcon, UnreadIcon } from './icons.js' import { botState, BotAvatar, RoomAvatar } from './mark.js' import { clockLabel, movedOnSince, openingTurn, unseenSince } from './cells.js' import { ActivityIndicator } from './activity-row.js' @@ -46,6 +46,27 @@ function MemoryNotice({ shown }) { h('span', { className: 'bt-pill-mem-in', ref: inner }, h('span', { className: 'bt-pill-mem-ico' }, h(MemoryIcon)), label)) } +// The manual unread mark is keyed by the sidebar's row id (a Bot id, a group id or an Agent +// id) while the header holds the Session id; an unknown id is left alone (#3114). +export function unreadEntryId(roster, sessionId) { + const bot = roster?.byId?.[sessionId] + const room = roster?.roomsById?.[sessionId] + return bot?.id ?? room?.id ?? roster?.agentOf?.[sessionId] ?? sessionId +} + +// The header's local unread control: it marks this chat unread or clears that mark without +// opening it, and it never writes the host's completion or pending-interaction flags — +// those still clear only when the chat is opened. +export function SessionUnreadToggle({ sessionId, roster, unread, actions }) { + const target = unreadEntryId(roster, sessionId) + const marked = unread?.[target] === true + const label = marked ? t('Clear unread mark') : t('Mark as Unread') + return h('button', { + type: 'button', className: 'bt-head-unread', 'aria-pressed': marked, 'aria-label': label, title: label, + onClick: () => (marked ? actions.clearUnread(target) : actions.markUnread(target)), + }, h(UnreadIcon)) +} + export function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSession, useActivity, useBusyAcks, useMemoryNews, useTurnClock, useUi, useLive, actions }) { const roster = useRoster(value => value) const title = useSessions(list => list.byId[sessionId]?.displayTitle ?? list.byId[sessionId]?.title ?? '') @@ -55,6 +76,7 @@ export function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus }) const hiddenTurns = roster.exchangeTurns?.[sessionId] const visit = useUi(state => state.visits?.[sessionId]) + const unread = useUi(state => state.unread) // The opening separator is the one page effect that stays with the pill: it needs a turn, so // the shell always draws the header for it, and it reads `useTurnClock`, which the installer // in header-effects.js deliberately does not carry. @@ -106,7 +128,8 @@ export function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus }), h(NewMessagePills, { key: sessionId, sessionId, hiddenTurns, useSessions, useUi, useTurnClock, actions }), h(ActivityIndicator, { key: `activity:${sessionId}`, sessionId, useRoster, useSessionStatus, useSession, useLive, actions }), - h(BusyAckBubble, { key: `busy-ack:${sessionId}`, sessionId, useRoster, useBusyAcks, useSessionStatus, useSession, useLive })) + h(BusyAckBubble, { key: `busy-ack:${sessionId}`, sessionId, useRoster, useBusyAcks, useSessionStatus, useSession, useLive }), + h(SessionUnreadToggle, { sessionId, roster, unread, actions })) } // New-message pills. "N new messages ↓" takes Back to bottom's place when diff --git a/core/src/client/i18n.js b/core/src/client/i18n.js index acea3e19e..22bf12e40 100644 --- a/core/src/client/i18n.js +++ b/core/src/client/i18n.js @@ -711,6 +711,7 @@ const ZH = { Pin: '置顶', Pinned: '已置顶', 'Mark as Unread': '标为未读', + 'Clear unread mark': '清除手动未读标记', 'Group settings': '群设置', 'Rename group': '重命名群聊', 'Copy conversation ID': '复制对话 ID', diff --git a/core/src/client/overlays.js b/core/src/client/overlays.js index c63a85d52..ed9f8e872 100644 --- a/core/src/client/overlays.js +++ b/core/src/client/overlays.js @@ -51,7 +51,7 @@ export function Overlays({ useRoster, useUi, useSessions, useSessionStatus, useA ui.palette ? createPortal(h(CommandPalette, { key: ui.palette.token, start: ui.palette.query, token: ui.palette.token, roster, actions, useSessions }), document.body) : null, ui.exchange ? createPortal(h(ExchangeDialog, { pair: ui.exchange, roster, actions }), document.body) : null, ui.voice ? createPortal(h(VoiceMode, { key: ui.voice, sessionId: ui.voice, roster, actions, useSessions, useSessionStatus }), document.body) : null, - menu ? createPortal(h(ContextMenu, { key: `${menu.kind ?? ''}:${menu.id}:${menu.x}:${menu.y}`, menu, roster, actions, leaving: menuLeaving }), document.body) : null, + menu ? createPortal(h(ContextMenu, { key: `${menu.kind ?? ''}:${menu.id}:${menu.x}:${menu.y}`, menu, roster, actions, unread: ui.unread, leaving: menuLeaving }), document.body) : null, settings ? createPortal(h(SettingsDialog, { page: settings.page, id: settings.id, roster, actions, useUpdate, leaving: settingsLeaving }), document.body) : null, remoteBotSettings ? createPortal(h(RemoteBotSettingsSheet, { key: remoteBotSettings, bot: roster.byId[remoteBotSettings], roster, actions, leaving: remoteLeaving }), document.body) : null, memory && roster.byId[memory] ? createPortal(h(MemoryDialog, { key: memory, bot: roster.byId[memory], roster, actions, leaving: memoryLeaving }), document.body) : null, diff --git a/core/src/client/styles.js b/core/src/client/styles.js index c1c5829ec..ee527e3ef 100644 --- a/core/src/client/styles.js +++ b/core/src/client/styles.js @@ -193,6 +193,10 @@ body[data-bt-motion=quiet] .bt-mark[data-poke]{cursor:default} .bt-pill[aria-expanded=true] .bt-pill-go svg{transform:rotate(180deg)} .bt-pill[data-memory=updated]:is(:hover,:focus-visible,[aria-expanded=true]) .bt-pill-go{width:0;margin-left:-8px;opacity:0;filter:blur(6px);transform:translateX(-6px)} @media (prefers-reduced-motion:reduce){.bt-pill,.bt-pill-go,.bt-pill-go svg{transition:none!important}.bt-pill-go{filter:none}.bt-pill:active{transform:none}} +.bt-head-unread{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;padding:0;border:0;border-radius:50%;background:none;color:var(--bt-ink-3);cursor:pointer} +.bt-head-unread:hover{background:var(--bt-hover);color:var(--bt-ink)} +.bt-head-unread[aria-pressed=true]{color:var(--bt-accent)} +.bt-head-unread svg{width:15px;height:15px} .bt-astack{display:flex;flex-direction:column;align-items:flex-start;gap:4px;margin:0} .bt-bubble{max-width:min(80%,560px,calc(100% - 82px));background:var(--bt-bubble);color:var(--bt-ink);border-radius:18px;padding:7px 12px;font-size:var(--dsh-content-font-size,14px);line-height:calc(var(--dsh-content-font-size,14px) + 8px);box-sizing:border-box;overflow-wrap:anywhere} diff --git a/core/test/unread-mark-menu.test.js b/core/test/unread-mark-menu.test.js new file mode 100644 index 000000000..8b06aff2f --- /dev/null +++ b/core/test/unread-mark-menu.test.js @@ -0,0 +1,175 @@ +// The manual unread mark is a client-only key in `ui.unread` (#3110 L102, #3114): a chat +// that is already marked unread must offer to clear that mark from its row menu and from +// the conversation header, without opening the chat. Clearing it never touches the host's +// completion or pending-interaction flags — opening the chat is what acknowledges those. +import assert from 'node:assert/strict' +import { test } from 'node:test' +import { runInNewContext } from 'node:vm' +import { build } from 'esbuild' +import { indexRoster } from '../src/client/sources.js' + +// One bundle for both surfaces; the header namespace keeps a missing export an assertion, not a build error. +const { outputFiles } = await build({ + stdin: { + contents: [ + "export { ContextMenu } from './src/client/context-menu.js'", + "import * as header from './src/client/header.js'", + 'export { header }', + ].join('\n'), + resolveDir: new URL('..', import.meta.url).pathname, + }, + bundle: true, format: 'cjs', platform: 'node', write: false, logLevel: 'silent', + external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'], +}) + +// One render pass over the hook shim is enough: these components read their inputs and draw. +let pass = null +const h = (type, props, ...children) => ({ type, props: { ...props, children: children.flat(Infinity) } }) +const sandbox = { + module: { exports: {} }, exports: null, Date, Promise, console, JSON, Map, Set, + window: { addEventListener: () => {}, removeEventListener: () => {}, innerWidth: 1400, innerHeight: 900 }, + document: { body: {}, addEventListener: () => {}, removeEventListener: () => {}, querySelector: () => null }, + navigator: { language: 'en' }, localStorage: { getItem: () => null, setItem() {} }, + setTimeout, clearTimeout, + require: (name) => { + const platform = { + react: { + createElement: (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat(Infinity) }), + useState: (initial) => { + const index = pass === null ? 0 : pass.index++ + if (!pass) return [initial, () => {}] + if (!(index in pass.values)) pass.values[index] = typeof initial === 'function' ? initial() : initial + return [pass.values[index], (next) => { pass.values[index] = typeof next === 'function' ? next(pass.values[index]) : next }] + }, + useEffect: () => {}, useLayoutEffect: () => {}, + useRef: current => ({ current }), useCallback: fn => fn, useMemo: fn => fn(), useSyncExternalStore: (_subscribe, get) => get(), + Fragment: 'fragment', + Component: class { constructor(props) { this.props = props } setState() {} render() { return null } }, + }, + 'react-dom': { createPortal: element => element }, + '@deepseek-ai/dsh-client-ui-primitives': {}, + } + if (!(name in platform)) throw new Error(`no platform module ${name}`) + return platform[name] + }, +} +sandbox.exports = sandbox.module.exports +runInNewContext(outputFiles[0].text, sandbox) +const { ContextMenu, header } = sandbox.module.exports +const { SessionUnreadToggle, unreadEntryId } = header + +const renderNode = (node) => { + if (Array.isArray(node)) return node.map(renderNode) + if (node === null || typeof node !== 'object') return node + if (typeof node.type === 'function') return renderNode(node.type({ ...node.props, children: node.children })) + return { ...node, children: (node.children ?? []).map(renderNode) } +} +const draw = (element) => { + pass = { index: 0, values: [] } + try { return renderNode(element()) } finally { pass = null } +} + +const textOf = node => (node?.children ?? []).flat(Infinity).filter(child => typeof child === 'string').join('') +const menuItems = (node, found = []) => { + if (node === null || typeof node !== 'object') return found + if (node.props?.role === 'menuitem') found.push({ label: textOf(node), onClick: node.props.onClick }) + for (const child of node.children ?? []) menuItems(child, found) + return found +} + +const bots = [ + { id: 'chief', name: 'Chief', sessionId: 'chief', parts: ['chief'] }, + { id: 'writer', name: 'Writer', sessionId: 'writer', parts: ['writer'] }, + { id: 'friend', name: 'Friend', sessionId: 'friend', parts: ['friend'], remote: true }, +] +const rooms = [{ id: 'room', name: 'Launch', members: ['chief', 'writer'] }] +const agents = [{ id: 'agent1', name: 'DSH Agent', sessions: ['agent-session'] }] +const rosterOf = (extra = {}) => indexRoster({ bots, rooms, agents, mainBotId: 'chief', mainBotIds: ['chief'], ...extra }) +const WRITER = { kind: 'bot', id: 'writer', x: 10, y: 10 } + +// Only the two local unread actions may be called, so any other entry in `calls` fails the check. +const localCalls = () => { + const calls = [] + const actions = { + closeMenu: () => {}, reportError: () => {}, openSession: id => calls.push({ action: 'openSession', id }), + markUnread: id => calls.push({ action: 'markUnread', id }), + clearUnread: id => calls.push({ action: 'clearUnread', id }), + openSettings: () => calls.push({ action: 'openSettings' }), setFlags: () => calls.push({ action: 'setFlags' }), + renameBot: () => calls.push({ action: 'renameBot' }), duplicateBot: async () => { calls.push({ action: 'duplicateBot' }); return { id: 'copy' } }, + setMain: () => calls.push({ action: 'setMain' }), deleteBot: () => calls.push({ action: 'deleteBot' }), + deleteRoom: () => calls.push({ action: 'deleteRoom' }), + } + return { calls, actions } +} + +// The pin toggle is left out of the message so the line names the entries this cut reads. +const written = labels => labels.filter(label => label !== 'Pin' && label !== 'Unpin') + +test('#3114: a marked chat offers Clear unread mark in its row menu, and that clears only the local mark', () => { + const { calls, actions } = localCalls() + const marked = menuItems(draw(() => ContextMenu({ menu: WRITER, roster: rosterOf(), actions, unread: { writer: true } }))) + assert.ok( + marked.some(item => item.label === 'Clear unread mark'), + `a marked bot (writer) offers no Clear unread mark: ${written(marked.map(item => item.label)).join(', ')}`, + ) + assert.ok(!marked.some(item => item.label === 'Mark as Unread'), 'a marked bot still offers Mark as Unread') + marked.find(item => item.label === 'Clear unread mark').onClick() + assert.deepEqual(calls, [{ action: 'clearUnread', id: 'writer' }], 'clearing the row mark wrote something else') + assert.ok(!calls.some(call => call.action === 'openSession'), 'clearing the row mark opened the chat') + + const plainCalls = localCalls() + const plain = menuItems(draw(() => ContextMenu({ menu: WRITER, roster: rosterOf(), actions: plainCalls.actions, unread: {} }))) + assert.ok(plain.some(item => item.label === 'Mark as Unread'), 'an unmarked bot lost Mark as Unread') + plain.find(item => item.label === 'Mark as Unread').onClick() + assert.deepEqual(plainCalls.calls, [{ action: 'markUnread', id: 'writer' }], 'marking the row wrote something else') +}) + +test('#3114: the chat header marks and clears the chat without opening it', () => { + assert.equal(typeof SessionUnreadToggle, 'function', 'the conversation header draws no unread control') + const roster = rosterOf() + // The header holds the Session id; the mark lives under the sidebar's row id. + assert.equal(unreadEntryId(roster, 'writer'), 'writer', 'a Bot Session maps to its Bot id') + assert.equal(unreadEntryId(roster, 'room'), 'room', 'a group Session maps to its room id') + assert.equal(unreadEntryId(roster, 'agent-session'), 'agent1', 'an Agent Session maps to its Agent id') + assert.equal(unreadEntryId(roster, 'elsewhere'), 'elsewhere', 'an unknown id is left alone') + + const state = localCalls() + const buttonOf = (sessionId, unread) => { + const find = (node) => { + if (node === null || typeof node !== 'object') return null + if (node.type === 'button') return node + for (const child of node.children ?? []) { const hit = find(child); if (hit) return hit } + return null + } + return find(draw(() => h(SessionUnreadToggle, { sessionId, roster, unread, actions: state.actions }))) + } + + const unmarked = buttonOf('writer', {}) + assert.equal(unmarked.props['aria-label'], 'Mark as Unread', 'an unmarked chat offers no way to mark it') + assert.equal(unmarked.props['aria-pressed'], false, 'an unmarked chat claims to be marked') + unmarked.props.onClick() + assert.deepEqual(state.calls, [{ action: 'markUnread', id: 'writer' }], 'the header marked something else') + + state.calls.length = 0 + const marked = buttonOf('writer', { writer: true }) + assert.equal(marked.props['aria-label'], 'Clear unread mark', 'a marked chat offers no way to clear the mark') + assert.equal(marked.props['aria-pressed'], true, 'a marked chat does not say it is marked') + marked.props.onClick() + assert.deepEqual(state.calls, [{ action: 'clearUnread', id: 'writer' }], 'the header cleared something else') + + state.calls.length = 0 + buttonOf('room', { room: true }).props.onClick() + buttonOf('agent-session', { agent1: true }).props.onClick() + assert.deepEqual(state.calls, [{ action: 'clearUnread', id: 'room' }, { action: 'clearUnread', id: 'agent1' }], 'the header cleared the wrong row') + assert.ok(!state.calls.some(call => call.action === 'openSession'), 'the header opened the chat it marked') +}) + +test('#3114: the unread entry stays a local control in a read-only window and never writes through the host', () => { + const locked = rosterOf({ readOnly: 'This window holds the team read-only.' }) + const { calls, actions } = localCalls() + const items = menuItems(draw(() => ContextMenu({ menu: WRITER, roster: locked, actions, unread: {} }))) + assert.ok(items.some(item => item.label === 'Mark as Unread'), 'a read-only window dropped the local unread control') + items.find(item => item.label === 'Mark as Unread').onClick() + assert.deepEqual(calls, [{ action: 'markUnread', id: 'writer' }], 'a read-only window did not mark locally') + assert.ok(!calls.some(call => call.action !== 'markUnread'), 'a read-only window wrote through the host') +}) diff --git a/docs/subsystems/core-client.md b/docs/subsystems/core-client.md index 029ae7b0f..bd5118ac9 100644 --- a/docs/subsystems/core-client.md +++ b/docs/subsystems/core-client.md @@ -134,12 +134,12 @@ The overlay (`flybot-slots.js` `FlyBotApprovals`) is the fallback, not a second - A friend's 1:1 chat (#443): `AssistantCell` gives the reply bubbles a `bt-lead` `BotMark` from the chat record (`friendLead`; none on a `Not sent:` note). The activity row (`activity-row.js`; host `[data-chat-flow] [data-chat-running]`, nested under `conversation.chat.flow` on DSH 0.2.1+ — #1626) stays up while `awaitingReply` (`awaiting.js`, `roster.remoteAwaiting`, 10 min cap) holds. Between the send turn and the echo turn it sits in the last turn's tail, with a 1.5 s grace and `data-carry` so there is no second entrance, which keeps one row from send to reply. The social `PeerThinking` line is for face rooms only. While the row is up in a friend chat and no local tool is the newest activity, its phrase is **Waiting for their approval** (等对方批准) instead of the thinking pool (`Sorting out the details` and the rest): that wait is the other home holding the reply, and this home cannot see the card (#1087). A local tool line still wins. A friend chat shows the row for a run that started from my submission and, between runs, while `awaitingReply` holds. The friend's reply run (the echo, which has no submission) hides it at once, and only the end of my send run gets the grace. The turn-tail hiding rules in `styles.js` spare `.bt-typing` and its tail item, or the row between runs would be drawn with `display:none`. - A friend's Bot the owner hid, a remote chat marked `gone`/`hidden`, and a home-level handle (`@friend.home`, not `@bot.friend.home`) must not reappear in the sidebar, the **发给 / 和谁聊…** picker, `@` mentions, or `list_bots` friends lines (`isListedRemoteChat`). `flybot.remote.publish` skips those handles so remote-chat sync marks the persisted session gone/hidden instead of opening it again; history is kept. Handle comparison is case-insensitive (`normRemoteHandle`). - The "@" reader is shared with the host (`core/src/shared/mentions.js`, bundled into `core/client.js`). #287 added `unmatchedMentions` there (the `@` words that name nobody, used by the host for the face-room hint); `mentionSpans` and what the bubbles draw are unchanged. -- A friend's Bot settings surface is not the local editor (#160): no rename, avatar editor, model, folder, instructions, Main Bot, Hide, Duplicate, or Delete. The details gear and context menu say **Bot settings**. The menu is Mark as Unread, Bot settings, and Copy conversation ID. Per-friend **Auto-send** and **Remove this Bot** stay on that page (`flybot.bot.details`); Remove closes the overlay so a stale local editor cannot appear. The Bots settings list is local Bots only. +- A friend's Bot settings surface is not the local editor (#160): no rename, avatar editor, model, folder, instructions, Main Bot, Hide, Duplicate, or Delete. The details gear and context menu say **Bot settings**. The menu is Mark as Unread (Clear unread mark on a chat already marked), Bot settings, and Copy conversation ID. Per-friend **Auto-send** and **Remove this Bot** stay on that page (`flybot.bot.details`); Remove closes the overlay so a stale local editor cannot appear. The Bots settings list is local Bots only. - A friend's Bot details overview is that compact panel: handle plus `FlyBotDetails` (Auto-send and a muted Remove link), no Browser tab, no Usage / model / folder. Opening the gear uses `remote-bot-settings` (`RemoteBotSettingsSheet`): a bottom sheet on narrow viewports and a centered card from 520px up, with the scrim behind the dialog (`z-index` stacking like `bt-settings` / `bt-mem`) so the sheet stays clickable through enter/leave animations. The surrounding DSH settings-shell chrome (back/title) is not redesigned (#166). The sheet takes focus when it opens (`tabIndex -1`, `preventScroll`), closes on Escape from its own `onKeyDown` as well as `useEscape`, and gives focus back without scrolling; in the tree a friend's `.bt-row-wrap` (row plus gear) shrinks like a plain row (`.bt-tree-item>.bt-row-wrap`), so the gear never overflows the sidebar and focusing it cannot scroll it sideways (#274). On every wide row (own Bots too) the gear's focus and click run `keepSidebarStill`, which puts back any sideways scroll a focus left on the row's ancestors or the page, now and after the settings dialog opened (#421). The Settings nav's last entry reads **Harness settings ↗** with a tooltip saying it opens DeepSeek Harness's own settings in a separate window; FlyBot does not embed or retitle that dialog (#421). - An own Bot's settings (`BotSettingsForm`) draw the `flybot.bot.details` entries once, as a titled **Sharing** card right after **Instructions** (`FlyBotDetails` with `wrap` → `Card`), so sharing is not at the end of the page; with no entry there is no card. Bot settings and group settings both end with a **More** card (Duplicate / Delete). A write the host refuses is reported on the dialog's own line under its heading, outside the page's scrolling box: `SettingsDialog` owns the sentence `run` stores, and `.bt-settings-scroll` no longer holds it, so scrolling down to the control that was pressed cannot leave the refusal above the viewport with the switch apparently unmoved ([#2194](https://github.com/ThinkFlowLab/FlyBot/issues/2194)). A window that holds the team read-only says so in that same header: `SettingsDialog` prints the host's own sentence from `roster.readOnly` as a `role="status"` line under the heading and above the refused-write line, so the standing state comes first and the answer to one pressed control sits closest to it, and a blank or missing `readOnly` draws nothing at all (#2199). The details drawer's own Settings view is not that dialog and had no header sentence: it now reads the same window lock (`lockedWindow`, `schedules.js`) and, in a read-only window, draws the host's sentence in the form's place instead of mounting `BotSettingsForm` or `GroupSettingsForm`, so no write control the host would refuse is drawn for a Bot or a group, and a writable window keeps the form unchanged (#2387). A refused write in that view follows the same rule as the dialog (#2385): the `bt-error` line is a sibling above `bt-drawer-body bt-set-body`, not its first child, so a press at the bottom of the group page — Pin, Hide, Make admin, Remove — writes the host's refusal where the press happened instead of at the top of the box it was scrolled past. The drawer's overview view holds the same two rules: its refusal line is a sibling above `bt-drawer-body`, and in a read-only window the Bot's name is plain text with no model, permission or working-folder control beside it, above a `role="status"` line carrying the host's own sentence, so the overview offers only what the host will not refuse. Since P-547 those three cards keep their titles and their saved values as plain text as well (`ReadOnlyOverview`: the model's name and provider, the permission preset's label, the working folder's last segment with the full path as its `title`), because the window refuses the writes, not the reading — a value that vanishes with its control leaves the page saying less than the host knows; a writable window keeps every control and draws none of those values twice. Tests: `core/test/details-overview-readonly.test.js`. A group's overview follows it (#2391 left it to P-544): the name is plain text with no rename control, `Remove my Bot` is gone, and the host's one sentence sits above the reads — a shared room's approval card keeps its headline and rows and drops its decisions — while a writable window keeps every control. Tests: `core/test/details-bot-settings-readonly.test.js`, `core/test/details-drawer-refusal-line.test.js`, `core/test/details-overview-readonly.test.js`, `core/test/details-group-overview-readonly.test.js`. The composer card's `:focus-within` border is 55% ink, hover stays 30% (#406). Keyboard Tab order, checked in headless Chrome on a mock bench (#406): sidebar (Search, New…, the Bots, Connect apps, Account) → chat header pill → message box → Add, Dictate, voice → the turn stats; the `shell.overlay` layer (approval cards) comes after the main column in the DOM, and no stop focuses an invisible element. The message box comes before **+** because DSH's DOM puts the input first and FlyBot's CSS only reorders it visually. - Settings → **Projects** (`ProjectsPage` and `ProjectsList` in `settings.js`) draws the write half of the Project record: a name field, **New Project**, a **Bind to {name}** choice on every Project row and **Unbind** on every binding. In a window that holds the team read-only (`lockedWindow`, `schedules.js`) none of them is drawn, because the host refuses `project-create` and `project-bind`; **Open board**, the Project rows with their names and working folders, and the members already bound stay readable, and a writable window is unchanged. With no Project at all the read-only page says only that there is none (`No Project yet.`) instead of inviting a creation the page no longer offers, while a writable window keeps the shared `No Project yet — create one.` the Project board also uses (#2489). Tests: `core/test/project-settings-page.test.js`. - The rest of Settings follows that lock (#2474): `GeneralPage`, `MainBotsSection` and `MotionSection` in `settings.js`, `BotSettingsForm` (`bot-settings.js`), `GroupSettingsForm` (`group-settings.js`), `ConnectorsPage` (`connectors.js`), `CapabilitiesPage` (`capability-settings.js`) and `SecretsPage` (`secret-card.js`) each read the same `lockedWindow(roster)` and, in a read-only window, draw no `select`, `input`, switch or component that would render one — every one of them asked for `set-prefs`, `set-main`, `update-bot`, `update-room`, a `connector-*` write, `save-capability`/`delete-capability` or a `secret-*` write, which the host refuses with `bot/read-only`. The facts stay as text: the theme and the accent in use, the notification state, the Main Bots and the animation setting, a Bot's role, model, working folder and instructions, a group's members, admin and notice (in a face-to-face room each person's Bots are named under that person; the page states who answers and the working folder for every group, face-to-face or plain, since #2492 and #2528), each connector's own state sentence, each capability's description and each stored key's name with who may use it. Entries that only navigate stay — **New Bot**, whose form explains the lock itself since #2465, and a row that opens a Bot's or a group's page — and the standing sentence is still the dialog header's, drawn once above the page and never again inside it. A writable window is unchanged. Tests: `core/test/settings-readonly-pages.test.js`. -- Every listed Bot row in wide sidebar mode is a `bt-row-wrap`: the session `bt-row` and a sibling gear (`bt-row-settings`, hover/focus) that opens Edit Bot for an own Bot or Bot settings for a friend's (#166, #276). A manual **Mark as Unread** is a local mark cleared when that conversation is opened; one made on the chat already on screen lasts until it is left and opened again ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)). +- Every listed Bot row in wide sidebar mode is a `bt-row-wrap`: the session `bt-row` and a sibling gear (`bt-row-settings`, hover/focus) that opens Edit Bot for an own Bot or Bot settings for a friend's (#166, #276). A manual **Mark as Unread** is a local mark cleared when that conversation is opened; one made on the chat already on screen lasts until it is left and opened again ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)). A chat already marked offers **Clear unread mark** in that row’s menu and on the chat header’s bell (`SessionUnreadToggle`), which clears only that local mark — a completion or pending-interaction flag still clears only by opening the chat. - The Session header is the shell's own: FlyBot registers the Bot pill in `conversation.session.header.utilities` rather than claiming the single `conversation.session.header` slot, so the seats that header renders — the lineage title and `conversation.session.header.actions`, where `@deepseek-ai/ui-subagent` puts the subagent catalog — keep rendering (#803). The floating header style FlyBot used to draw over the Session header is gone. - What the pill does to the page is not in the pill and not in a seat of its own (#803). The shell draws `.utilities` — and the pill with it — only while its chrome shows, which a Session without a first message hides, so a side effect parked in the pill stops there: the friend's empty-chat hint, `body[data-bt-friend-chat]`, the `Message {name}` composer label, the visit ledger, `body[data-bt-room]` and the face-room `@` filter. `installHeaderEffects` (`src/client/header-effects.js`) is installed once from `apply` and keeps them on the Session in the main view. It carries no React, and each effect has its own dependency key: the sessions list answers before the roster, so a single "did the Session change" guard would drop a friend's flags on the first pass, while `beginVisit`/`endVisit` keyed on more than the Session would open a second visit for a chat that was only just opened. `test/header-effects.test.js` drives those transitions on jsdom; `test/header-slot.test.js` pins that no such effect runs in `HeaderPill` and that FlyBot claims no other header seat. - `conversation.session.header.corner` is **not** available as that seat: it is `single` and `ui-sidebar-right` already registers its right-sidebar button there with no `priority` (0), and `SlotCore.register` throws on a second registration in the same cell (`single slot "…" already has a registration at priority 0`), which would fail FlyBot's whole client plugin from `apply`. Only `--bt-first-sep` still rides the pill, because it needs a turn and so always has a header to be drawn in. @@ -241,7 +241,7 @@ The member's own chat keeps its `busyAcks[sessionId]` bubble and its visibility - Slot `flybot.settings.page` (`0003-flybot-api-client`, types in `flybot.d.ts`, #337) adds a page to the Settings list right after Connectors: `{ id, order, label, icon?, component }`. `SettingsDialog` (`settings.js`) lists `useSettingsPages()` entries under the key `plugin:` and draws the component through `SettingsPageSlot` (a failing component draws nothing, it does not close the dialog); a page whose plugin is gone opens General. `label` is an English key for the host `t()`; the component gets `{ roster, actions, call, run, t, Section, Row }` (the host translator, the Settings section card and row, so the page matches the others and reads zh from `i18n.js`). Social registers **Bot Social** (the server, see [social](social.md)). Test: `core/test/settings-page-slot.test.js`. - Slot `flybot.account.header` (`0003-flybot-api-client`) is a compact block at the top of the account menu (`FlyBotAccountHeader`); social uses it for the owner's own handle (#181). - Slot `flybot.new-chat.action` (`0003-flybot-api-client`, types in `flybot.d.ts`) is a row on the sidebar **+** new-chat menu, after New group chat. Plugins register `{ id, order, label, hint?, visible?, run }`; the picker looks `label` / `hint` up with `t()` like the neighbouring rows. A string returned from `run` is shown as a toast (`actions.notify`). Social registers Face-to-face room and Add friend; see [plugin-runtime](plugin-runtime.md) and [social](social.md). -- Sidebar **+** (`mode === 'new'`) opens a short action menu (`data-menu`, no To:/composer) until **New chat** or **New group chat**. That menu does not list individual Bots (Chief and the rest stay behind **New chat**). The Agent row in that FlyBot menu is **Add coding agent**; every row has its own mark (`ChatIcon`, `BotIcon`, `PeopleIcon`, a plugin row's `icon`, drawn through `SlotIcon` behind its own error boundary with the people mark as fallback; a function or memo/forwardRef component, `TerminalIcon`), one verb style (New … / Add …) and one short hint with no closing period (#385: *Message one of your Bots*, *Set up a Bot with its own role*, *Chat with several of your Bots*, *Meet people nearby with a 6-digit number*, *Paste an invite link or code*, *A coding session without a Bot*). A Bot's right-click menu has **Edit Bot** and no separate **Rename Bot** (the name is edited there); a `flybot.sidebar.structure` entry's `menuItems` rows follow in their own group, and the menu hands each one the window's read-only flag (`readOnly: true` only when `roster.readOnly` trims to a non-empty string), so an entry hides a write the host would refuse instead of painting its failure (#2238); a read-only window (`roster.readOnly` a non-empty string, read the same way) also draws none of the menu's own core writes — no Pin/Unpin, Duplicate, Make Main Bot, Remove Main Bot role, Hide from sidebar, Rename group, Delete or Delete group, because the host refuses every one of them with `bot/read-only` — while Edit Bot, Group settings, Mark as Unread and Copy conversation ID stay; the DSH Agent row's menu and a Session's menu read the same flag, so a read-only window draws no Pin/Unpin, Remove DSH Agent, Rename or Archive there either, because the host refuses `set-flags`, `remove-agent`, `agent-rename` and `agent-archive` for such a window, and with every row hidden the menu draws nothing at all rather than an empty box. Tests: `core/test/context-menu-readonly.test.js`, `core/test/context-menu-agent-readonly.test.js`; **Add DSH Agent** stays the DSH product string on Agent rows elsewhere (#126, #181). +- Sidebar **+** (`mode === 'new'`) opens a short action menu (`data-menu`, no To:/composer) until **New chat** or **New group chat**. That menu does not list individual Bots (Chief and the rest stay behind **New chat**). The Agent row in that FlyBot menu is **Add coding agent**; every row has its own mark (`ChatIcon`, `BotIcon`, `PeopleIcon`, a plugin row's `icon`, drawn through `SlotIcon` behind its own error boundary with the people mark as fallback; a function or memo/forwardRef component, `TerminalIcon`), one verb style (New … / Add …) and one short hint with no closing period (#385: *Message one of your Bots*, *Set up a Bot with its own role*, *Chat with several of your Bots*, *Meet people nearby with a 6-digit number*, *Paste an invite link or code*, *A coding session without a Bot*). A Bot's right-click menu has **Edit Bot** and no separate **Rename Bot** (the name is edited there); a `flybot.sidebar.structure` entry's `menuItems` rows follow in their own group, and the menu hands each one the window's read-only flag (`readOnly: true` only when `roster.readOnly` trims to a non-empty string), so an entry hides a write the host would refuse instead of painting its failure (#2238); a read-only window (`roster.readOnly` a non-empty string, read the same way) also draws none of the menu's own core writes — no Pin/Unpin, Duplicate, Make Main Bot, Remove Main Bot role, Hide from sidebar, Rename group, Delete or Delete group, because the host refuses every one of them with `bot/read-only` — while Edit Bot, Group settings, Mark as Unread (Clear unread mark on a chat already marked) and Copy conversation ID stay; the DSH Agent row's menu and a Session's menu read the same flag, so a read-only window draws no Pin/Unpin, Remove DSH Agent, Rename or Archive there either, because the host refuses `set-flags`, `remove-agent`, `agent-rename` and `agent-archive` for such a window, and with every row hidden the menu draws nothing at all rather than an empty box. Tests: `core/test/context-menu-readonly.test.js`, `core/test/context-menu-agent-readonly.test.js`; **Add DSH Agent** stays the DSH product string on Agent rows elsewhere (#126, #181). - Group bubbles, notices, and failed-reply lines never show a raw `` wrap or a developer error (`llm-deepseek: no API key`). `remoteMessageText` unwraps stored fences; `failureLabel` maps missing-key / unknown model failures to a short friendly line. Details stay in Settings → Feedback. - A closed face room's status line already says who left (#1103). `GroupReplies` (`leaveNoticeCoveredByClose` in `cells.js`) does not also draw a short leave notice for that person (`SelfB1025 left the room`, or `Coder (SelfB1025) left`). A leave while the room is still open, a leave the status line does not name, and every other notice stay. The social plugin uses the same rule when it decides whether to post the line. Test: `core/test/tool-cells.test.js`. - `GroupReplies` draws a `user` reply with `other: true` (another member's face-room line, #180) as `PersonMessage` (`cells.js`): the person's name, the person mark (`PersonMark` in `mark.js`) and a received `--bt-bubble` bubble, not a centred `bt-event` notice and not the sent `--bt-user` style; own lines keep the right-hand bubble (#229). `other` comes only from the host's person-line post (`hooks.js` `postHuman`), never from text. Another home member's line in a shared group (`UserMessageCell`, author stamped by the host) gets the same person mark and the received surface (`.bt-umsg-other .bt-ubody`). `PersonMark({ name })` draws the person's initial on a color picked from the name (`personColor`, the core default-color hash of `person:`), so one person looks the same on every home and two people are told apart; without a name it is the plain silhouette (#182). diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index 139b1723a..6e022a765 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -1289,11 +1289,12 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js 'Harness settings': 'Harness 设置', 'Back to Bots': '返回 Bot 列表', 'Close settings': '关闭设置', -@@ -324,7 +324,6 @@ const ZH = { +@@ -324,7 +324,7 @@ const ZH = { Pin: '置顶', Pinned: '已置顶', 'Mark as Unread': '标为未读', - 'Rename Bot': '重命名 Bot', ++ 'Clear unread mark': '清除手动未读标记', 'Group settings': '群设置', 'Rename group': '重命名群聊', 'Copy conversation ID': '复制对话 ID', diff --git a/patches/ds-bot/0003-flybot-api-client.patch b/patches/ds-bot/0003-flybot-api-client.patch index 358be4cb7..50b89726d 100644 --- a/patches/ds-bot/0003-flybot-api-client.patch +++ b/patches/ds-bot/0003-flybot-api-client.patch @@ -1414,7 +1414,7 @@ diff --git a/src/client/cells.js b/src/client/cells.js diff --git a/src/client/context-menu.js b/src/client/context-menu.js --- a/src/client/context-menu.js +++ b/src/client/context-menu.js -@@ -4,6 +4,9 @@ import { currentPart } from './text.js' +@@ -4,14 +4,18 @@ import { currentPart } from './text.js' import { GearIcon, PinIcon, UnreadIcon, PencilIcon, StarLineIcon, CopyIcon, HideIcon, TrashIcon, DuplicateIcon } from './icons.js' import { useEscape } from './overlay-hooks.js' import { t } from './i18n.js' @@ -1422,9 +1422,11 @@ diff --git a/src/client/context-menu.js b/src/client/context-menu.js +import { pluginItems } from './flybot-registry.js' +import { LinkIcon } from './icons.js' - export function ContextMenu({ menu, roster, actions, leaving = false }) { +-export function ContextMenu({ menu, roster, actions, leaving = false }) { ++export function ContextMenu({ menu, roster, actions, leaving = false, unread }) { useEscape(() => actions.closeMenu()) -@@ -12,6 +12,7 @@ export function ContextMenu({ menu, roster, actions, leaving = false }) { + useEffect(() => { + const onDown = (event) => { if (!(event.target instanceof Element) || !event.target.closest('.bt-menu')) actions.closeMenu() } window.addEventListener('mousedown', onDown) return () => window.removeEventListener('mousedown', onDown) }, []) @@ -1432,7 +1434,15 @@ diff --git a/src/client/context-menu.js b/src/client/context-menu.js const ref = useRef(null) const [place, setPlace] = useState({ left: menu.x, top: menu.y }) useLayoutEffect(() => { -@@ -27,28 +27,44 @@ export function ContextMenu({ menu, roster, actions, leaving = false }) { +@@ -24,31 +24,52 @@ export function ContextMenu({ menu, roster, actions, leaving = false }) { + const room = roster.roomsById[menu.id] + const entry = bot ?? room + if (entry === undefined) return null ++ // The manual unread mark is a local one (#3114): a chat already marked unread offers to ++ // clear it, and clearing drops only that key — a completion flag stays as it is. ++ const unreadItem = unread?.[menu.id] === true ++ ? [t('Clear unread mark'), UnreadIcon, () => actions.clearUnread(menu.id)] ++ : [t('Mark as Unread'), UnreadIcon, () => actions.markUnread(menu.id)] const isMainBot = isMainOf(roster, menu.id) const isTile = roster.mainBotId === menu.id const mainCount = (roster.mainBotIds ?? []).length @@ -1462,7 +1472,7 @@ diff --git a/src/client/context-menu.js b/src/client/context-menu.js + const groups = bot?.remote + ? [ + [ -+ [t('Mark as Unread'), UnreadIcon, () => actions.markUnread(menu.id)], ++ unreadItem, + ], + [ + [t('Bot settings'), GearIcon, () => actions.openSettings('bots', bot.id)], @@ -1473,7 +1483,7 @@ diff --git a/src/client/context-menu.js b/src/client/context-menu.js + : [ + [ + isTile || locked ? null : [entry.pinned ? t('Unpin') : t('Pin'), PinIcon, () => actions.setFlags(menu.id, { pinned: !entry.pinned })], -+ [t('Mark as Unread'), UnreadIcon, () => actions.markUnread(menu.id)], ++ unreadItem, + ], + [ + // One way to edit a Bot (#385): its name is edited in Edit Bot too. @@ -2756,7 +2766,7 @@ diff --git a/src/client/overlays.js b/src/client/overlays.js import { useLinger } from './motion.js' // How long a closing dialog or menu stays for its exit (see their [data-leaving] CSS). -@@ -27,17 +27,21 @@ export function Overlays({ useRoster, useUi, useSessions, useSessionStatus, useA +@@ -27,24 +27,31 @@ export function Overlays({ useRoster, useUi, useSessions, useSessionStatus, useA previous.current = current if (current) actions.followPanel?.(current) }, [current]) @@ -2780,9 +2790,11 @@ diff --git a/src/client/overlays.js b/src/client/overlays.js return h(Fragment, null, pane ? createPortal(h(BotPanel, { pane, leaving: open === null, roster, actions, useSessions, useSessionStatus, useActivity, useWork, useBrowserTabs, useBrowserPages }), document.body) : null, ui.newChat ? createPortal(h(NewChat, { key: ui.newChat, mode: ui.newChat, roster, actions }), document.body) : null, -@@ -46,5 +46,8 @@ export function Overlays({ useRoster, useUi, useSessions, useSessionStatus, useA + ui.palette ? createPortal(h(CommandPalette, { key: ui.palette.token, start: ui.palette.query, token: ui.palette.token, roster, actions, useSessions }), document.body) : null, + ui.exchange ? createPortal(h(ExchangeDialog, { pair: ui.exchange, roster, actions }), document.body) : null, ui.voice ? createPortal(h(VoiceMode, { key: ui.voice, sessionId: ui.voice, roster, actions, useSessions, useSessionStatus }), document.body) : null, - menu ? createPortal(h(ContextMenu, { key: `${menu.kind ?? ''}:${menu.id}:${menu.x}:${menu.y}`, menu, roster, actions, leaving: menuLeaving }), document.body) : null, +- menu ? createPortal(h(ContextMenu, { key: `${menu.kind ?? ''}:${menu.id}:${menu.x}:${menu.y}`, menu, roster, actions, leaving: menuLeaving }), document.body) : null, ++ menu ? createPortal(h(ContextMenu, { key: `${menu.kind ?? ''}:${menu.id}:${menu.x}:${menu.y}`, menu, roster, actions, unread: ui.unread, leaving: menuLeaving }), document.body) : null, settings ? createPortal(h(SettingsDialog, { page: settings.page, id: settings.id, roster, actions, useUpdate, leaving: settingsLeaving }), document.body) : null, - memory && roster.byId[memory] ? createPortal(h(MemoryDialog, { key: memory, bot: roster.byId[memory], actions, leaving: memoryLeaving }), document.body) : null) + remoteBotSettings ? createPortal(h(RemoteBotSettingsSheet, { key: remoteBotSettings, bot: roster.byId[remoteBotSettings], roster, actions, leaving: remoteLeaving }), document.body) : null, @@ -3806,7 +3818,14 @@ diff --git a/src/client/styles.js b/src/client/styles.js .bt-pill-mem{flex:none;display:inline-flex;width:0;margin-left:-8px;overflow:hidden;transition:${spring(SPRING_SHAPE, 'width', 'margin-left')}} .bt-pill[data-memory=updated] .bt-pill-mem{width:var(--bt-mem-w);margin-left:0;transition:${spring(SPRING_STRETCH, 'width', 'margin-left')}} .bt-pill-mem-in{flex:none;display:inline-flex;align-items:center;gap:5px;white-space:nowrap;color:var(--bt-ink-2);font-size:13px;font-weight:500;opacity:0;filter:blur(6px);transform:translateX(-8px);transition:opacity .14s ease,filter .18s ease,${spring(SPRING_SHAPE, 'transform')}} -@@ -174,8 +174,31 @@ body[data-bt-motion=quiet] .bt-mark[data-poke]{cursor:default} +@@ -171,11 +171,38 @@ body[data-bt-motion=quiet] .bt-mark[data-poke]{cursor:default} + .bt-pill[aria-expanded=true] .bt-pill-go svg{transform:rotate(180deg)} + .bt-pill[data-memory=updated]:is(:hover,:focus-visible,[aria-expanded=true]) .bt-pill-go{width:0;margin-left:-8px;opacity:0;filter:blur(6px);transform:translateX(-6px)} + @media (prefers-reduced-motion:reduce){.bt-pill,.bt-pill-go,.bt-pill-go svg{transition:none!important}.bt-pill-go{filter:none}.bt-pill:active{transform:none}} ++.bt-head-unread{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;padding:0;border:0;border-radius:50%;background:none;color:var(--bt-ink-3);cursor:pointer} ++.bt-head-unread:hover{background:var(--bt-hover);color:var(--bt-ink)} ++.bt-head-unread[aria-pressed=true]{color:var(--bt-accent)} ++.bt-head-unread svg{width:15px;height:15px} .bt-astack{display:flex;flex-direction:column;align-items:flex-start;gap:4px;margin:0} .bt-bubble{max-width:min(80%,560px,calc(100% - 82px));background:var(--bt-bubble);color:var(--bt-ink);border-radius:18px;padding:7px 12px;font-size:var(--dsh-content-font-size,14px);line-height:calc(var(--dsh-content-font-size,14px) + 8px);box-sizing:border-box;overflow-wrap:anywhere} diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index a3bd52882..55ccb27c6 100644 --- a/patches/ds-bot/0008-client-bundle.patch +++ b/patches/ds-bot/0008-client-bundle.patch @@ -553,11 +553,12 @@ diff --git a/client.js b/client.js "Harness settings": "Harness 设置", "Back to Bots": "返回 Bot 列表", "Close settings": "关闭设置", -@@ -385,7 +385,6 @@ var ZH = { +@@ -385,7 +385,7 @@ var ZH = { Pin: "置顶", Pinned: "已置顶", "Mark as Unread": "标为未读", - "Rename Bot": "重命名 Bot", ++ "Clear unread mark": "清除手动未读标记", "Group settings": "群设置", "Rename group": "重命名群聊", "Copy conversation ID": "复制对话 ID", @@ -2226,7 +2227,7 @@ diff --git a/client.js b/client.js var formatTokens = (count) => count >= 1e6 ? `${(count / 1e6).toFixed(1)}M` : count >= 1e3 ? `${(count / 1e3).toFixed(1)}K` : String(count); function usageOf(list, ids) { let input = 0; -@@ -1624,537 +1624,3130 @@ function usageOf(list, ids) { +@@ -1624,537 +1624,3134 @@ function usageOf(list, ids) { const hit = input > 0 ? Math.round(cacheRead / input * 100) : 0; return t("{tokens} tok · Cache hit {hit}%", { tokens: formatTokens(input + output), hit }); } @@ -5654,6 +5655,10 @@ diff --git a/client.js b/client.js +.bt-pill[aria-expanded=true] .bt-pill-go svg{transform:rotate(180deg)} +.bt-pill[data-memory=updated]:is(:hover,:focus-visible,[aria-expanded=true]) .bt-pill-go{width:0;margin-left:-8px;opacity:0;filter:blur(6px);transform:translateX(-6px)} +@media (prefers-reduced-motion:reduce){.bt-pill,.bt-pill-go,.bt-pill-go svg{transition:none!important}.bt-pill-go{filter:none}.bt-pill:active{transform:none}} ++.bt-head-unread{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;padding:0;border:0;border-radius:50%;background:none;color:var(--bt-ink-3);cursor:pointer} ++.bt-head-unread:hover{background:var(--bt-hover);color:var(--bt-ink)} ++.bt-head-unread[aria-pressed=true]{color:var(--bt-accent)} ++.bt-head-unread svg{width:15px;height:15px} + +.bt-astack{display:flex;flex-direction:column;align-items:flex-start;gap:4px;margin:0} +.bt-bubble{max-width:min(80%,560px,calc(100% - 82px));background:var(--bt-bubble);color:var(--bt-ink);border-radius:18px;padding:7px 12px;font-size:var(--dsh-content-font-size,14px);line-height:calc(var(--dsh-content-font-size,14px) + 8px);box-sizing:border-box;overflow-wrap:anywhere} @@ -6045,7 +6050,7 @@ diff --git a/client.js b/client.js .bt-account{flex:none;width:36px;height:36px;border:0;padding:0;background:none;border-radius:50%;cursor:pointer;display:inline-flex} .bt-account:hover .bt-you,.bt-account[aria-expanded=true] .bt-you{background:color-mix(in srgb,var(--bt-ink) 9%,var(--bt-sidebar))} /* Popover keyframes move translate and scale, which compose with a transform the popover -@@ -2488,4682 +2488,8879 @@ body[data-ds-dark-theme] .bt-theme-chip i{background:var(--da)} +@@ -2488,4682 +2488,8899 @@ body[data-ds-dark-theme] .bt-theme-chip i{background:var(--da)} @keyframes bt-rise{from{opacity:0;transform:translateY(-3px)}to{opacity:1;transform:none}} @media (prefers-reduced-motion:reduce){.bt-member,.bt-addlist{animation:none}} @@ -8629,13 +8634,6 @@ diff --git a/client.js b/client.js - ), - rows.length > 0 ? (0, import_react4.createElement)("div", { className: "bt-q-list", role: "group" }, rows) : null, - field && !raised ? (0, import_react4.createElement)( -- "div", -- { className: "bt-q-custom" }, -- (0, import_react4.createElement)("label", { className: "bt-q-field" }, field), -- !multi && canSubmit ? (0, import_react4.createElement)("button", { type: "submit", className: "bt-q-submit" }, t("Submit")) : null -- ) : null, -- foot -- ); + const parts = []; + parts.push((0, import_react12.createElement)("span", { key: "p" }, prefix)); + bots.forEach((bot, index) => { @@ -8661,13 +8659,7 @@ diff --git a/client.js b/client.js + const held = heldForm(item.text); + return held !== "" && (held === line2 || held.length >= 799 && line2.startsWith(held)); + }); - } --function SettledQuestion({ question, answer }) { -- const options = optionsOf(question); -- const prompt = question?.question ?? ""; -- const chosen = [...answer.selected ?? [], ...answer.custom ? [answer.custom] : []]; -- if (chosen.length === 0) { -- return (0, import_react4.createElement)( ++} +var HELD_SENDING_MS = 6e4; +function heldLineState(room2, { seq, botId, text: text2 } = {}, now = Date.now()) { + if (room2?.origin !== "face-to-face" || !Array.isArray(room2.heldLines)) return void 0; @@ -8685,19 +8677,16 @@ diff --git a/client.js b/client.js + if (held === "rejected") { + return (0, import_react12.createElement)( "div", -- { className: "bt-q bt-q-settled bt-q-dismissed", role: "group", "aria-label": prompt }, -- (0, import_react4.createElement)( -- "div", -- { className: "bt-q-head" }, -- (0, import_react4.createElement)("div", { className: "bt-q-text" }, (0, import_react4.createElement)("p", { className: "bt-q-title" }, prompt)), -- (0, import_react4.createElement)("span", { className: "bt-q-badge" }, t("Dismissed")) -- ) +- { className: "bt-q-custom" }, +- (0, import_react4.createElement)("label", { className: "bt-q-field" }, field), +- !multi && canSubmit ? (0, import_react4.createElement)("button", { type: "submit", className: "bt-q-submit" }, t("Submit")) : null +- ) : null, +- foot + { className: "bt-event bt-not-sent", "data-flybot": "held-not-sent", role: "status" }, + (0, import_react12.createElement)(BotMark, { bot, size: 16 }), + (0, import_react12.createElement)("span", null, t("{name} · Not sent", { name: bot.name })) - ); - } -- return (0, import_react4.createElement)( ++ ); ++ } + if (held === "held" || isHeldLine(room2, text2, bot)) return null; + const lead = (0, import_react12.createElement)( + "button", @@ -8711,54 +8700,18 @@ diff --git a/client.js b/client.js + room2?.admin === bot.id ? (0, import_react12.createElement)("span", { className: "bt-group-role" }, t("Admin")) : null + ); + return (0, import_react12.createElement)( - "div", -- { className: "bt-q bt-q-settled", role: "group", "aria-label": prompt }, -- prompt ? (0, import_react4.createElement)("div", { className: "bt-q-head" }, (0, import_react4.createElement)("div", { className: "bt-q-text" }, (0, import_react4.createElement)("p", { className: "bt-q-title" }, prompt))) : null, -- (0, import_react4.createElement)("div", { className: "bt-q-list", role: "group", "aria-label": t("Your answer") }, chosen.map((label, index) => { -- const optionIndex = options.findIndex((option) => option.label === label); -- return (0, import_react4.createElement)( -- "div", -- { key: `${label}-${index}`, className: "bt-q-opt" }, -- optionIndex >= 0 ? (0, import_react4.createElement)("span", { className: "bt-key", "aria-hidden": true }, keyLetter(optionIndex)) : null, -- (0, import_react4.createElement)("span", { className: "bt-q-body" }, (0, import_react4.createElement)("span", { className: "bt-q-label" }, label)), -- (0, import_react4.createElement)("span", { className: "bt-q-check", title: t("Selected") }, (0, import_react4.createElement)(CheckIcon)) -- ); -- })) ++ "div", + { className: "bt-group-msg" }, + name, + (0, import_react12.createElement)(Bubbles, { texts: [text2], roster, selfId: bot.id, actions, sessionId: room2?.id, msgKey, useUi, lead }) ); } --function QuestionCard({ matched }) { -- const pending = matched; -- const questions = pending.questions ?? []; -- const [index, setIndex] = (0, import_react4.useState)(0); -- const [answers, setAnswers] = (0, import_react4.useState)([]); -- const question = questions[index]; -- if (question === void 0) return null; -- const onAnswer = (answer) => { -- const next = [...answers, { id: question.id, ...answer }]; -- if (index + 1 < questions.length) { -- setAnswers(next); -- setIndex(index + 1); -- return; -- } -- pending.answer({ answers: next }); -- }; -- return (0, import_react4.createElement)(QuestionView, { key: index, question, onAnswer, onDismiss: () => pending.dismiss(), ownAnswer: true, raised: true }); --} --function PendingQuestion({ sessionId, question, actions, inline }) { -- const [answered, setAnswered] = (0, import_react4.useState)(null); -- if (answered === question.id) return null; -- const onAnswer = (answer) => { -- setAnswered(question.id); -- void actions.answerQuestion(sessionId, question.id, { selected: answer.selected ?? [], custom: answer.custom ?? "" }).catch(() => setAnswered(null)); -- }; -- const onDismiss = () => { -- setAnswered(question.id); -- void actions.dismissQuestion(sessionId); -- }; -- return (0, import_react4.createElement)( +-function SettledQuestion({ question, answer }) { +- const options = optionsOf(question); +- const prompt = question?.question ?? ""; +- const chosen = [...answer.selected ?? [], ...answer.custom ? [answer.custom] : []]; +- if (chosen.length === 0) { +- return (0, import_react4.createElement)( +function remoteSpeaker(source, roster, sessionId) { + const handle = source.remote.handle; + const member = (roster.remoteBots ?? []).find((bot2) => bot2.handle === handle); @@ -8801,7 +8754,14 @@ diff --git a/client.js b/client.js + const person = typeof source.remote.typedBy === "string" ? source.remote.typedBy : ""; + if (person) { + return (0, import_react12.createElement)( -+ "div", + "div", +- { className: "bt-q bt-q-settled bt-q-dismissed", role: "group", "aria-label": prompt }, +- (0, import_react4.createElement)( +- "div", +- { className: "bt-q-head" }, +- (0, import_react4.createElement)("div", { className: "bt-q-text" }, (0, import_react4.createElement)("p", { className: "bt-q-title" }, prompt)), +- (0, import_react4.createElement)("span", { className: "bt-q-badge" }, t("Dismissed")) +- ) + { className: "bt-group-msg bt-person-msg bt-remote-msg", "data-person": person, "data-remote": handle }, + // One short header: the person, and the Bot that carried the line only when it is known (#275). + (0, import_react12.createElement)( @@ -8812,14 +8772,25 @@ diff --git a/client.js b/client.js + ), + String(words ?? "").trim() === "" ? null : (0, import_react12.createElement)(Bubbles, { texts: [words], roster, selfId: bot.id, actions, sessionId, msgKey, useUi, lead: (0, import_react12.createElement)("span", { className: "bt-lead", title: person }, (0, import_react12.createElement)(PersonMark, { name: person })) }), + files.length ? (0, import_react12.createElement)(RemoteFiles, { files, plugin: member?.plugin ?? "social", botId: roster.byId[sessionId]?.id ?? sessionId }) : null -+ ); -+ } + ); + } +- return (0, import_react4.createElement)( + const mark = (0, import_react12.createElement)(BotMark, { bot, size: 22 }); + const lead = chatId ? (0, import_react12.createElement)("button", { type: "button", className: "bt-lead", title: handle, "aria-label": t("Open {name}'s chat", { name }), onClick: () => actions.openSession(chatId) }, mark) : (0, import_react12.createElement)("span", { className: "bt-lead", title: handle }, mark); + return (0, import_react12.createElement)( "div", -- { className: inline ? "bt-q-inline" : "bt-q-dock" }, -- (0, import_react4.createElement)(QuestionView, { key: question.id, question, onAnswer, onDismiss, ownAnswer: question.allowCustom === true, raised: !inline }) +- { className: "bt-q bt-q-settled", role: "group", "aria-label": prompt }, +- prompt ? (0, import_react4.createElement)("div", { className: "bt-q-head" }, (0, import_react4.createElement)("div", { className: "bt-q-text" }, (0, import_react4.createElement)("p", { className: "bt-q-title" }, prompt))) : null, +- (0, import_react4.createElement)("div", { className: "bt-q-list", role: "group", "aria-label": t("Your answer") }, chosen.map((label, index) => { +- const optionIndex = options.findIndex((option) => option.label === label); +- return (0, import_react4.createElement)( +- "div", +- { key: `${label}-${index}`, className: "bt-q-opt" }, +- optionIndex >= 0 ? (0, import_react4.createElement)("span", { className: "bt-key", "aria-hidden": true }, keyLetter(optionIndex)) : null, +- (0, import_react4.createElement)("span", { className: "bt-q-body" }, (0, import_react4.createElement)("span", { className: "bt-q-label" }, label)), +- (0, import_react4.createElement)("span", { className: "bt-q-check", title: t("Selected") }, (0, import_react4.createElement)(CheckIcon)) +- ); +- })) + { className: "bt-group-msg bt-remote-msg", "data-remote": handle }, + // A face room's header is the one name alone; the handle is on hover only (#457). + face ? (0, import_react12.createElement)("span", { className: "bt-group-name", style: { color: inkText(colorOf(bot)) }, title: handle }, name) : (0, import_react12.createElement)( @@ -8832,17 +8803,107 @@ diff --git a/client.js b/client.js + files.length ? (0, import_react12.createElement)(RemoteFiles, { files, plugin: member?.plugin ?? "social", botId: roster.byId[sessionId]?.id ?? sessionId }) : null ); } +-function QuestionCard({ matched }) { +- const pending = matched; +- const questions = pending.questions ?? []; +- const [index, setIndex] = (0, import_react4.useState)(0); +- const [answers, setAnswers] = (0, import_react4.useState)([]); +- const question = questions[index]; +- if (question === void 0) return null; +- const onAnswer = (answer) => { +- const next = [...answers, { id: question.id, ...answer }]; +- if (index + 1 < questions.length) { +- setAnswers(next); +- setIndex(index + 1); +- return; ++function FirstContact({ source, roster, sessionId }) { ++ const person = typeof source.remote.typedBy === "string" ? source.remote.typedBy : ""; ++ const who = person || remoteSpeaker(source, roster).name; ++ const bot = roster.byId[sessionId]?.name ?? t("your Bot"); ++ return (0, import_react12.createElement)("div", { className: "bt-event", "data-first-contact": source.remote.handle }, (0, import_react12.createElement)("span", null, t("{name} is talking to {bot} through Bot Social", { name: who, bot }))); ++} ++function GlobeMark() { ++ return (0, import_react12.createElement)( ++ "svg", ++ { width: 10, height: 10, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": true }, ++ (0, import_react12.createElement)("circle", { cx: 12, cy: 12, r: 9 }), ++ (0, import_react12.createElement)("path", { d: "M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18" }) ++ ); ++} ++function RemoteFiles({ files, plugin, botId }) { ++ const [busy, setBusy] = (0, import_react12.useState)(""); ++ const [error, setError] = (0, import_react12.useState)(""); ++ const download2 = async (file) => { ++ setBusy(file.id); ++ setError(""); ++ try { ++ const got = await call(`flybot/${plugin}/attachment`, { id: file.id, botId }); ++ const value = got?.value ?? got; ++ const bytes = Uint8Array.from(atob(value.content_base64), (c) => c.charCodeAt(0)); ++ const url = URL.createObjectURL(new Blob([bytes], { type: "application/octet-stream" })); ++ const link = Object.assign(document.createElement("a"), { href: url, download: value.name ?? file.name }); ++ link.click(); ++ setTimeout(() => URL.revokeObjectURL(url), 1e4); ++ } catch (reason) { ++ setError(String(reason?.message ?? reason)); ++ } finally { ++ setBusy(""); + } +- pending.answer({ answers: next }); + }; +- return (0, import_react4.createElement)(QuestionView, { key: index, question, onAnswer, onDismiss: () => pending.dismiss(), ownAnswer: true, raised: true }); ++ return (0, import_react12.createElement)( ++ "div", ++ { className: "bt-file-chips" }, ++ files.map((file) => (0, import_react12.createElement)( ++ "button", ++ { key: file.id, type: "button", className: "bt-file-chip", disabled: busy === file.id, title: `Download ${file.name} (untrusted file from a remote Bot)`, onClick: () => download2(file) }, ++ `📎 ${file.name} · ${fileSize(file.size)}` ++ )), ++ error ? (0, import_react12.createElement)("span", { className: "bt-file-error", role: "alert" }, error) : null ++ ); + } +-function PendingQuestion({ sessionId, question, actions, inline }) { +- const [answered, setAnswered] = (0, import_react4.useState)(null); +- if (answered === question.id) return null; +- const onAnswer = (answer) => { +- setAnswered(question.id); +- void actions.answerQuestion(sessionId, question.id, { selected: answer.selected ?? [], custom: answer.custom ?? "" }).catch(() => setAnswered(null)); +- }; +- const onDismiss = () => { +- setAnswered(question.id); +- void actions.dismissQuestion(sessionId); +- }; +- return (0, import_react4.createElement)( ++function GroupEvent({ prefix, room: room2, name, roster, actions }) { ++ return (0, import_react12.createElement)( + "div", +- { className: inline ? "bt-q-inline" : "bt-q-dock" }, +- (0, import_react4.createElement)(QuestionView, { key: question.id, question, onAnswer, onDismiss, ownAnswer: question.allowCustom === true, raised: !inline }) ++ { className: "bt-event" }, ++ (0, import_react12.createElement)("span", null, prefix), ++ room2 ? (0, import_react12.createElement)("button", { type: "button", onClick: () => actions.openSession(room2.id) }, (0, import_react12.createElement)(RoomAvatar, { room: room2, roster, size: 16 }), room2.name) : name ? (0, import_react12.createElement)("span", null, name) : null + ); + } -function QuestionDock({ sessionId, useRoster, useCards, useSession, actions }) { - const question = useRoster((value) => value.questions?.[sessionId]); - const drawn = useCards?.((state) => state[sessionId]?.[question?.callId] > 0) === true; - const loading = useSession?.(historyLoading) === true; - if (question === void 0 || question.callId && (drawn || loading)) return null; - return (0, import_react4.createElement)(PendingQuestion, { sessionId, question, actions, inline: false }); -+function FirstContact({ source, roster, sessionId }) { -+ const person = typeof source.remote.typedBy === "string" ? source.remote.typedBy : ""; -+ const who = person || remoteSpeaker(source, roster).name; -+ const bot = roster.byId[sessionId]?.name ?? t("your Bot"); -+ return (0, import_react12.createElement)("div", { className: "bt-event", "data-first-contact": source.remote.handle }, (0, import_react12.createElement)("span", null, t("{name} is talking to {bot} through Bot Social", { name: who, bot }))); ++function MemoryEvent({ sessionId, scope, result, roster, actions, findBot }) { ++ if (!/^(Saved to|Updated in|Removed from) /.test(result)) return null; ++ const self = roster.byId[sessionId]; ++ const team = /^(team|团队|共享)$/i.test(String(scope ?? "").trim()); ++ const other = team || !scope ? void 0 : findBot(scope); ++ const target = other && other.id !== self?.id ? other : self; ++ if (!target) return null; ++ const label = team ? t("Team memory updated") : target === self ? t("Memory updated") : t("Updated {name}'s memory", { name: target.name }); ++ return (0, import_react12.createElement)( ++ "div", ++ { className: "bt-event" }, ++ (0, import_react12.createElement)("button", { type: "button", title: result, onClick: () => actions.openMemory(target.id) }, (0, import_react12.createElement)(MemoryIcon), label) ++ ); } -function AnsweredCell({ node }) { - const data = node.data ?? {}; @@ -8856,13 +8917,8 @@ diff --git a/client.js b/client.js - question, - answer: answers.find((answer) => answer.id === question.id) ?? { selected: [] } - }))); -+function GlobeMark() { -+ return (0, import_react12.createElement)( -+ "svg", -+ { width: 10, height: 10, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": true }, -+ (0, import_react12.createElement)("circle", { cx: 12, cy: 12, r: 9 }), -+ (0, import_react12.createElement)("path", { d: "M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18" }) -+ ); ++function PartLine({ time }) { ++ return (0, import_react12.createElement)("div", { className: "bt-part-line", role: "separator" }, Number.isFinite(time) ? (0, import_react12.createElement)("span", null, dayLabel(time)) : null); } - -// src/client/secret-card.js @@ -8893,7 +8949,12 @@ diff --git a/client.js b/client.js - if (scope === "all") return t("All Bots"); - const names = (scope ?? []).map((id) => roster.byId[id]?.name).filter(Boolean); - return names.length === 0 ? t("No Bot") : names.join(t(" and ")); --}; ++var scrollParent = (node) => { ++ for (let at = node.parentElement; at; at = at.parentElement) { ++ if (/(auto|scroll)/.test(getComputedStyle(at).overflowY)) return at; ++ } ++ return null; + }; -var when = (time) => Number.isFinite(time) ? new Date(time).toLocaleString(dateLocale(), { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" }) : ""; -function MaskedInput({ value, onChange, onEnter, label, autoFocus = false }) { - return (0, import_react5.createElement)("input", { @@ -8917,154 +8978,6 @@ diff --git a/client.js b/client.js - if (event.key !== "Enter" || event.nativeEvent.isComposing) return; - event.preventDefault(); - onEnter?.(); -+function RemoteFiles({ files, plugin, botId }) { -+ const [busy, setBusy] = (0, import_react12.useState)(""); -+ const [error, setError] = (0, import_react12.useState)(""); -+ const download2 = async (file) => { -+ setBusy(file.id); -+ setError(""); -+ try { -+ const got = await call(`flybot/${plugin}/attachment`, { id: file.id, botId }); -+ const value = got?.value ?? got; -+ const bytes = Uint8Array.from(atob(value.content_base64), (c) => c.charCodeAt(0)); -+ const url = URL.createObjectURL(new Blob([bytes], { type: "application/octet-stream" })); -+ const link = Object.assign(document.createElement("a"), { href: url, download: value.name ?? file.name }); -+ link.click(); -+ setTimeout(() => URL.revokeObjectURL(url), 1e4); -+ } catch (reason) { -+ setError(String(reason?.message ?? reason)); -+ } finally { -+ setBusy(""); - } -- }); --} --function ScopeSwitch({ value, onChange, bot }) { -- const options = [["all", t("All Bots")], ["bot", t("Only {name}", { name: bot.name })]]; -- return (0, import_react5.createElement)( -+ }; -+ return (0, import_react12.createElement)( - "div", -- { className: "bt-secret-scope", role: "radiogroup", "aria-label": t("Who may use it") }, -- (0, import_react5.createElement)("span", { className: "bt-secret-glide", "data-at": value === "all" ? 0 : 1, "aria-hidden": true }), -- options.map(([id, text]) => (0, import_react5.createElement)("button", { -- key: id, -- type: "button", -- role: "radio", -- "aria-checked": value === id, -- className: "bt-secret-seg", -- onClick: () => onChange(id) -- }, text)) -+ { className: "bt-file-chips" }, -+ files.map((file) => (0, import_react12.createElement)( -+ "button", -+ { key: file.id, type: "button", className: "bt-file-chip", disabled: busy === file.id, title: `Download ${file.name} (untrusted file from a remote Bot)`, onClick: () => download2(file) }, -+ `📎 ${file.name} · ${fileSize(file.size)}` -+ )), -+ error ? (0, import_react12.createElement)("span", { className: "bt-file-error", role: "alert" }, error) : null - ); - } --function SecretHead({ bot, title, detail, name, onClose }) { -- return (0, import_react5.createElement)( -+function GroupEvent({ prefix, room: room2, name, roster, actions }) { -+ return (0, import_react12.createElement)( - "div", -- { className: "bt-q-head bt-secret-head" }, -- (0, import_react5.createElement)("span", { className: "bt-secret-who" }, (0, import_react5.createElement)(BotMark, { bot, size: 28 }), (0, import_react5.createElement)("span", { className: "bt-secret-lock" }, (0, import_react5.createElement)(LockIcon))), -- (0, import_react5.createElement)( -- "div", -- { className: "bt-q-text" }, -- (0, import_react5.createElement)("p", { className: "bt-q-title" }, title), -- (0, import_react5.createElement)("div", { className: "bt-q-detail" }, (0, import_react5.createElement)("code", { className: "bt-secret-name" }, name), detail ? ` · ${detail}` : "") -- ), -- onClose ? (0, import_react5.createElement)("button", { type: "button", className: "bt-q-x", "aria-label": t("Cancel the request"), title: t("Cancel"), onClick: onClose }, (0, import_react5.createElement)(CloseIcon)) : null -+ { className: "bt-event" }, -+ (0, import_react12.createElement)("span", null, prefix), -+ room2 ? (0, import_react12.createElement)("button", { type: "button", onClick: () => actions.openSession(room2.id) }, (0, import_react12.createElement)(RoomAvatar, { room: room2, roster, size: 16 }), room2.name) : name ? (0, import_react12.createElement)("span", null, name) : null - ); - } --function SecretCard({ bot, request, roster, actions }) { -- const [value, setValue] = (0, import_react5.useState)(""); -- const [scope, setScope] = (0, import_react5.useState)("all"); -- const [replacing, setReplacing] = (0, import_react5.useState)(false); -- const [busy, setBusy] = (0, import_react5.useState)(false); -- const [error, setError] = (0, import_react5.useState)(""); -- const noteId = (0, import_react5.useId)(); -- const secret = (roster.secrets ?? []).find((entry) => entry.name === request.name); -- const run = (promise) => { -- setBusy(true); -- setError(""); -- return Promise.resolve(promise).then(() => setValue(""), (failure) => setError(failure?.message ?? String(failure))).finally(() => setBusy(false)); -- }; -- const cancel = () => run(actions.secretCancel(request.id)); -- const long = value.trim().length >= MIN_VALUE; -- const save = () => { -- if (long && !busy) void run(actions.secretSet({ requestId: request.id, value, scope })); -- }; -- const allow = () => { -- if (!busy) void run(actions.secretAllow(request.id)); -- }; -- const filling = request.kind === "fill" || replacing; -- const warn = insecure() ? (0, import_react5.createElement)("div", { className: "bt-secret-warn", role: "note" }, (0, import_react5.createElement)(WarnIcon), t("This page is not on HTTPS: the key crosses the network unencrypted.")) : null; -- return (0, import_react5.createElement)( -+function MemoryEvent({ sessionId, scope, result, roster, actions, findBot }) { -+ if (!/^(Saved to|Updated in|Removed from) /.test(result)) return null; -+ const self = roster.byId[sessionId]; -+ const team = /^(team|团队|共享)$/i.test(String(scope ?? "").trim()); -+ const other = team || !scope ? void 0 : findBot(scope); -+ const target = other && other.id !== self?.id ? other : self; -+ if (!target) return null; -+ const label = team ? t("Team memory updated") : target === self ? t("Memory updated") : t("Updated {name}'s memory", { name: target.name }); -+ return (0, import_react12.createElement)( - "div", -- { className: "bt-q bt-secret", role: "group", "aria-describedby": noteId, "data-kind": request.kind }, -- (0, import_react5.createElement)(SecretHead, { -- bot, -- title: request.kind === "allow" ? t("Let {bot} use {name}?", { bot: bot.name, name: request.name }) : t("{name} needs a key", { name: bot.name }), -- detail: request.purpose, -- name: request.name, -- onClose: busy ? void 0 : cancel -- }), -- request.kind === "allow" ? (0, import_react5.createElement)("div", { className: "bt-secret-saved" }, (0, import_react5.createElement)(KeyIcon), t("Saved for {scope}", { scope: scopeLabel(secret?.scope, roster) })) : null, -- filling ? (0, import_react5.createElement)( -- "div", -- { className: "bt-secret-body" }, -- (0, import_react5.createElement)("label", { className: "bt-q-field bt-secret-field" }, (0, import_react5.createElement)(MaskedInput, { value, onChange: setValue, onEnter: save, label: t("Value of {name}", { name: request.name }), autoFocus: replacing })), -- request.kind === "fill" ? (0, import_react5.createElement)(ScopeSwitch, { value: scope, onChange: setScope, bot }) : null -- ) : null, -- (0, import_react5.createElement)( -- "div", -- { className: "bt-secret-note", id: noteId }, -- t("{bot} never sees the value. It reaches {bot}'s shell as ", { bot: bot.name }), -- (0, import_react5.createElement)("code", null, `$DSH_SECRET_${request.name}`), -- ".", -- filling && value !== "" && !long ? t(" At least {count} characters.", { count: MIN_VALUE }) : "" -- ), -- warn, -- error ? (0, import_react5.createElement)("div", { className: "bt-secret-error", role: "alert" }, error) : null, -- (0, import_react5.createElement)( -- "div", -- { className: "bt-q-foot" }, -- request.kind === "allow" && !replacing ? (0, import_react5.createElement)("button", { type: "button", className: "bt-q-btn", disabled: busy, onClick: () => setReplacing(true) }, t("Replace value")) : null, -- (0, import_react5.createElement)("button", { type: "button", className: "bt-q-btn", disabled: busy, onClick: cancel }, t("Cancel")), -- filling ? (0, import_react5.createElement)("button", { type: "button", className: "bt-q-submit", disabled: !long || busy, onClick: save }, busy ? t("Saving…") : t("Save")) : (0, import_react5.createElement)("button", { type: "button", className: "bt-q-submit", disabled: busy, onClick: allow }, busy ? t("Allowing…") : t("Allow")) -- ) -+ { className: "bt-event" }, -+ (0, import_react12.createElement)("button", { type: "button", title: result, onClick: () => actions.openMemory(target.id) }, (0, import_react12.createElement)(MemoryIcon), label) - ); - } --function SettledSecret({ bot, request, roster }) { -- const canceled = request.status === "canceled"; -- const text = canceled ? t("{bot} asked for {name}", { bot: bot.name, name: request.name }) : request.status === "allowed" ? t("Allowed {bot} to use {name}", { bot: bot.name, name: request.name }) : t("Saved {name}", { name: request.name }); -- return (0, import_react5.createElement)( -+function PartLine({ time }) { -+ return (0, import_react12.createElement)("div", { className: "bt-part-line", role: "separator" }, Number.isFinite(time) ? (0, import_react12.createElement)("span", null, dayLabel(time)) : null); -+} -+var scrollParent = (node) => { -+ for (let at = node.parentElement; at; at = at.parentElement) { -+ if (/(auto|scroll)/.test(getComputedStyle(at).overflowY)) return at; -+ } -+ return null; -+}; +function EarlierParts({ sessionId, roster, actions, useUi }) { + const [view, setView] = (0, import_react12.useState)({ items: [], cursor: void 0, loading: true, failed: false, startedAt: null }); + const top = (0, import_react12.useRef)(null); @@ -9123,22 +9036,10 @@ diff --git a/client.js b/client.js + rows.push(item); + } + return (0, import_react12.createElement)( - "div", -- { className: "bt-q bt-q-settled bt-secret bt-secret-done", role: "group", "aria-label": text, "data-status": request.status }, -- (0, import_react5.createElement)( ++ "div", + { className: "bt-earlier", role: "feed", "aria-label": t("Earlier messages"), "aria-busy": view.loading }, + (0, import_react12.createElement)( - "div", -- { className: "bt-q-head" }, -- (0, import_react5.createElement)("span", { className: "bt-secret-who" }, (0, import_react5.createElement)(BotMark, { bot, size: 22 })), -- (0, import_react5.createElement)("div", { className: "bt-q-text" }, (0, import_react5.createElement)( -- "p", -- { className: "bt-q-title" }, -- text, -- canceled ? null : (0, import_react5.createElement)("span", { className: "bt-secret-scope-tag" }, ` · ${scopeLabel(request.scope, roster)}`) -- )), -- canceled ? (0, import_react5.createElement)("span", { className: "bt-q-badge" }, t("Canceled")) : (0, import_react5.createElement)("span", { className: "bt-q-check bt-secret-check", title: t("Done") }, (0, import_react5.createElement)(CheckIcon)) -- ) ++ "div", + { ref: top, className: "bt-earlier-top" }, + view.loading ? (0, import_react12.createElement)(Shimmer, null, t("Loading earlier messages…")) : view.failed ? (0, import_react12.createElement)("button", { type: "button", className: "bt-soft", onClick: () => load(view.cursor) }, t("Couldn’t load earlier messages · Retry")) : view.cursor ? (0, import_react12.createElement)("button", { type: "button", className: "bt-soft", onClick: () => load(view.cursor) }, t("Load earlier")) : null + ), @@ -9171,18 +9072,8 @@ diff --git a/client.js b/client.js + } + }), + (0, import_react12.createElement)(PartLine, { time: view.startedAt }) - ); - } --function RequestView({ bot, request, roster, actions }) { -- return request.status === "pending" ? (0, import_react5.createElement)(SecretCard, { key: `${request.id}:${request.kind}`, bot, request, roster, actions }) : (0, import_react5.createElement)(SettledSecret, { bot, request, roster }); --} --function SecretToolCell({ sessionId, callId, name, done, content, roster, actions }) { -- const bot = roster.byId[sessionId]; -- if (!bot) return null; -- const request = (roster.secretRequests?.[bot.id] ?? []).find((entry) => entry.callId === callId && (entry.sessionId ?? sessionId) === sessionId); -- if (request) return (0, import_react5.createElement)("div", { className: "bt-q-inline" }, (0, import_react5.createElement)(RequestView, { bot, request, roster, actions })); -- if (done && /already saved/.test(contentText(content))) { -- return (0, import_react5.createElement)("div", { className: "bt-event" }, (0, import_react5.createElement)("span", { className: "bt-secret-event" }, (0, import_react5.createElement)(KeyIcon), t("{bot} is using {name}", { bot: bot.name, name: name ?? t("a saved key") }))); ++ ); ++} +function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnClock, useUi, actions }) { + const roster = useRoster((value) => value); + const data = node.data; @@ -9254,18 +9145,47 @@ diff --git a/client.js b/client.js + onOpen: (bot) => actions.openExchange(selfId, bot.id), + whole: true + }); -+ } + } +- }); + if (source.kind === "schedule") { + const prompts = reminderPrompts(contentText(data.content)); + return (0, import_react12.createElement)("div", { className: "bt-event" }, prompts.length > 0 ? t("Scheduled task: {text}", { text: cutText(prompts.join(" · "), 80) }) : t("Routine started")); + } + if (source.kind === "user-question-reply") return null; + return (0, import_react12.createElement)("div", { className: "bt-event" }, cutText(contentText(data.content), 80) || t("Update")); - } -+} ++ } + } +-function ScopeSwitch({ value, onChange, bot }) { +- const options = [["all", t("All Bots")], ["bot", t("Only {name}", { name: bot.name })]]; +- return (0, import_react5.createElement)( +- "div", +- { className: "bt-secret-scope", role: "radiogroup", "aria-label": t("Who may use it") }, +- (0, import_react5.createElement)("span", { className: "bt-secret-glide", "data-at": value === "all" ? 0 : 1, "aria-hidden": true }), +- options.map(([id, text]) => (0, import_react5.createElement)("button", { +- key: id, +- type: "button", +- role: "radio", +- "aria-checked": value === id, +- className: "bt-secret-seg", +- onClick: () => onChange(id) +- }, text)) +- ); +function NewDivider() { + return (0, import_react12.createElement)("div", { className: "bt-new-sep", role: "separator", "aria-label": t("New messages") }, (0, import_react12.createElement)("span", null, t("New"))); -+} + } +-function SecretHead({ bot, title, detail, name, onClose }) { +- return (0, import_react5.createElement)( +- "div", +- { className: "bt-q-head bt-secret-head" }, +- (0, import_react5.createElement)("span", { className: "bt-secret-who" }, (0, import_react5.createElement)(BotMark, { bot, size: 28 }), (0, import_react5.createElement)("span", { className: "bt-secret-lock" }, (0, import_react5.createElement)(LockIcon))), +- (0, import_react5.createElement)( +- "div", +- { className: "bt-q-text" }, +- (0, import_react5.createElement)("p", { className: "bt-q-title" }, title), +- (0, import_react5.createElement)("div", { className: "bt-q-detail" }, (0, import_react5.createElement)("code", { className: "bt-secret-name" }, name), detail ? ` · ${detail}` : "") +- ), +- onClose ? (0, import_react5.createElement)("button", { type: "button", className: "bt-q-x", "aria-label": t("Cancel the request"), title: t("Cancel"), onClick: onClose }, (0, import_react5.createElement)(CloseIcon)) : null +- ); +function TurnProcessCell({ node, sessionId, turnProcess, useRoster, useUi, useTurnClock, actions }) { + const open = turnProcess === void 0 || !turnProcess.foldable || turnProcess.open; + (0, import_react12.useEffect)(() => { @@ -9283,20 +9203,87 @@ diff --git a/client.js b/client.js + return !hidden && typeof visit?.seen === "number" && own?.first !== void 0 && own.first <= visit.seen && own.end !== void 0 && own.end > visit.seen && own.end <= visit.entered; + }); + return fresh ? (0, import_react12.createElement)(NewDivider) : null; -+} + } +-function SecretCard({ bot, request, roster, actions }) { +- const [value, setValue] = (0, import_react5.useState)(""); +- const [scope, setScope] = (0, import_react5.useState)("all"); +- const [replacing, setReplacing] = (0, import_react5.useState)(false); +- const [busy, setBusy] = (0, import_react5.useState)(false); +- const [error, setError] = (0, import_react5.useState)(""); +- const noteId = (0, import_react5.useId)(); +- const secret = (roster.secrets ?? []).find((entry) => entry.name === request.name); +- const run = (promise) => { +- setBusy(true); +- setError(""); +- return Promise.resolve(promise).then(() => setValue(""), (failure) => setError(failure?.message ?? String(failure))).finally(() => setBusy(false)); +- }; +- const cancel = () => run(actions.secretCancel(request.id)); +- const long = value.trim().length >= MIN_VALUE; +- const save = () => { +- if (long && !busy) void run(actions.secretSet({ requestId: request.id, value, scope })); +- }; +- const allow = () => { +- if (!busy) void run(actions.secretAllow(request.id)); +- }; +- const filling = request.kind === "fill" || replacing; +- const warn = insecure() ? (0, import_react5.createElement)("div", { className: "bt-secret-warn", role: "note" }, (0, import_react5.createElement)(WarnIcon), t("This page is not on HTTPS: the key crosses the network unencrypted.")) : null; +- return (0, import_react5.createElement)( +- "div", +- { className: "bt-q bt-secret", role: "group", "aria-describedby": noteId, "data-kind": request.kind }, +- (0, import_react5.createElement)(SecretHead, { +- bot, +- title: request.kind === "allow" ? t("Let {bot} use {name}?", { bot: bot.name, name: request.name }) : t("{name} needs a key", { name: bot.name }), +- detail: request.purpose, +- name: request.name, +- onClose: busy ? void 0 : cancel +- }), +- request.kind === "allow" ? (0, import_react5.createElement)("div", { className: "bt-secret-saved" }, (0, import_react5.createElement)(KeyIcon), t("Saved for {scope}", { scope: scopeLabel(secret?.scope, roster) })) : null, +- filling ? (0, import_react5.createElement)( +- "div", +- { className: "bt-secret-body" }, +- (0, import_react5.createElement)("label", { className: "bt-q-field bt-secret-field" }, (0, import_react5.createElement)(MaskedInput, { value, onChange: setValue, onEnter: save, label: t("Value of {name}", { name: request.name }), autoFocus: replacing })), +- request.kind === "fill" ? (0, import_react5.createElement)(ScopeSwitch, { value: scope, onChange: setScope, bot }) : null +- ) : null, +- (0, import_react5.createElement)( +- "div", +- { className: "bt-secret-note", id: noteId }, +- t("{bot} never sees the value. It reaches {bot}'s shell as ", { bot: bot.name }), +- (0, import_react5.createElement)("code", null, `$DSH_SECRET_${request.name}`), +- ".", +- filling && value !== "" && !long ? t(" At least {count} characters.", { count: MIN_VALUE }) : "" +- ), +- warn, +- error ? (0, import_react5.createElement)("div", { className: "bt-secret-error", role: "alert" }, error) : null, +- (0, import_react5.createElement)( +- "div", +- { className: "bt-q-foot" }, +- request.kind === "allow" && !replacing ? (0, import_react5.createElement)("button", { type: "button", className: "bt-q-btn", disabled: busy, onClick: () => setReplacing(true) }, t("Replace value")) : null, +- (0, import_react5.createElement)("button", { type: "button", className: "bt-q-btn", disabled: busy, onClick: cancel }, t("Cancel")), +- filling ? (0, import_react5.createElement)("button", { type: "button", className: "bt-q-submit", disabled: !long || busy, onClick: save }, busy ? t("Saving…") : t("Save")) : (0, import_react5.createElement)("button", { type: "button", className: "bt-q-submit", disabled: busy, onClick: allow }, busy ? t("Allowing…") : t("Allow")) +- ) +- ); +function Nothing() { - return null; ++ return null; } --function SecretDock({ sessionId, useRoster, useCards, useSession, actions }) { -- const roster = useRoster((value) => value); -- const shown = useCards?.((state) => state[sessionId]) ?? NONE; -- const loading = useSession?.(historyLoading) === true; -- const bot = roster.byId[sessionId]; -- if (!bot || currentPart(bot) !== sessionId) return null; -- const drawn = (entry) => entry.callId && entry.sessionId === sessionId && (loading || shown[entry.callId] > 0); -- const waiting = (roster.secretRequests?.[bot.id] ?? []).filter((entry) => entry.status === "pending" && !drawn(entry)); -- if (waiting.length === 0) return null; -- return (0, import_react5.createElement)("div", { className: "bt-q-dock bt-secret-dock" }, waiting.map((request) => (0, import_react5.createElement)(SecretCard, { key: `${request.id}:${request.kind}`, bot, request, roster, actions }))); +-function SettledSecret({ bot, request, roster }) { +- const canceled = request.status === "canceled"; +- const text = canceled ? t("{bot} asked for {name}", { bot: bot.name, name: request.name }) : request.status === "allowed" ? t("Allowed {bot} to use {name}", { bot: bot.name, name: request.name }) : t("Saved {name}", { name: request.name }); +- return (0, import_react5.createElement)( +- "div", +- { className: "bt-q bt-q-settled bt-secret bt-secret-done", role: "group", "aria-label": text, "data-status": request.status }, +- (0, import_react5.createElement)( +- "div", +- { className: "bt-q-head" }, +- (0, import_react5.createElement)("span", { className: "bt-secret-who" }, (0, import_react5.createElement)(BotMark, { bot, size: 22 })), +- (0, import_react5.createElement)("div", { className: "bt-q-text" }, (0, import_react5.createElement)( +- "p", +- { className: "bt-q-title" }, +- text, +- canceled ? null : (0, import_react5.createElement)("span", { className: "bt-secret-scope-tag" }, ` · ${scopeLabel(request.scope, roster)}`) +- )), +- canceled ? (0, import_react5.createElement)("span", { className: "bt-q-badge" }, t("Canceled")) : (0, import_react5.createElement)("span", { className: "bt-q-check bt-secret-check", title: t("Done") }, (0, import_react5.createElement)(CheckIcon)) +- ) +- ); +var HIDDEN_REMOVED_TOOLS = /* @__PURE__ */ new Set(["ask_user_question"]); +var isConnectorTool = (name) => typeof name === "string" && /^mcp__(github|composio)__/.test(name); +var SILENT_REGISTRATION_TOOLS = /* @__PURE__ */ new Set([ @@ -9353,6 +9340,46 @@ diff --git a/client.js b/client.js + if (parts.length === 0) return null; + return (0, import_react12.createElement)("div", { className: "bt-event" }, parts.join(" · ")); } +-function RequestView({ bot, request, roster, actions }) { +- return request.status === "pending" ? (0, import_react5.createElement)(SecretCard, { key: `${request.id}:${request.kind}`, bot, request, roster, actions }) : (0, import_react5.createElement)(SettledSecret, { bot, request, roster }); ++var SEPARATOR_GAP_MS = 30 * 60 * 1e3; ++function clockLabel(time, now = Date.now()) { ++ const date = new Date(time); ++ const midnight = (value) => new Date(value.getFullYear(), value.getMonth(), value.getDate()).getTime(); ++ const days = Math.round((midnight(new Date(now)) - midnight(date)) / 864e5); ++ const clock4 = date.toLocaleTimeString(dateLocale(), { hour: "numeric", minute: "2-digit" }); ++ if (days === 0) return t("Today {time}", { time: clock4 }); ++ if (days === 1) return t("Yesterday {time}", { time: clock4 }); ++ const sameYear = date.getFullYear() === new Date(now).getFullYear(); ++ return `${date.toLocaleDateString(dateLocale(), { weekday: "short", month: "short", day: "numeric", ...sameYear ? {} : { year: "numeric" } })} ${clock4}`; + } +-function SecretToolCell({ sessionId, callId, name, done, content, roster, actions }) { +- const bot = roster.byId[sessionId]; +- if (!bot) return null; +- const request = (roster.secretRequests?.[bot.id] ?? []).find((entry) => entry.callId === callId && (entry.sessionId ?? sessionId) === sessionId); +- if (request) return (0, import_react5.createElement)("div", { className: "bt-q-inline" }, (0, import_react5.createElement)(RequestView, { bot, request, roster, actions })); +- if (done && /already saved/.test(contentText(content))) { +- return (0, import_react5.createElement)("div", { className: "bt-event" }, (0, import_react5.createElement)("span", { className: "bt-secret-event" }, (0, import_react5.createElement)(KeyIcon), t("{bot} is using {name}", { bot: bot.name, name: name ?? t("a saved key") }))); ++function nextTurnStart(turns, turn) { ++ let next; ++ for (const key in turns) { ++ const candidate = Number(key); ++ if (candidate > turn && turns[key].first !== void 0 && (next === void 0 || candidate < next)) next = candidate; + } +- return null; +-} +-function SecretDock({ sessionId, useRoster, useCards, useSession, actions }) { +- const roster = useRoster((value) => value); +- const shown = useCards?.((state) => state[sessionId]) ?? NONE; +- const loading = useSession?.(historyLoading) === true; +- const bot = roster.byId[sessionId]; +- if (!bot || currentPart(bot) !== sessionId) return null; +- const drawn = (entry) => entry.callId && entry.sessionId === sessionId && (loading || shown[entry.callId] > 0); +- const waiting = (roster.secretRequests?.[bot.id] ?? []).filter((entry) => entry.status === "pending" && !drawn(entry)); +- if (waiting.length === 0) return null; +- return (0, import_react5.createElement)("div", { className: "bt-q-dock bt-secret-dock" }, waiting.map((request) => (0, import_react5.createElement)(SecretCard, { key: `${request.id}:${request.kind}`, bot, request, roster, actions }))); ++ return next === void 0 ? void 0 : turns[next].first; + } -function ScopeEditor({ secret, roster, onSave }) { - const [mode, setMode] = (0, import_react5.useState)(secret.scope === "all" ? "all" : "some"); - const [picked, setPicked] = (0, import_react5.useState)(secret.scope === "all" ? [] : secret.scope); @@ -9385,16 +9412,14 @@ diff --git a/client.js b/client.js - (0, import_react5.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", disabled: same, onClick: () => onSave(mode === "all" ? "all" : picked) }, t("Save access")) - ) - ); -+var SEPARATOR_GAP_MS = 30 * 60 * 1e3; -+function clockLabel(time, now = Date.now()) { -+ const date = new Date(time); -+ const midnight = (value) => new Date(value.getFullYear(), value.getMonth(), value.getDate()).getTime(); -+ const days = Math.round((midnight(new Date(now)) - midnight(date)) / 864e5); -+ const clock4 = date.toLocaleTimeString(dateLocale(), { hour: "numeric", minute: "2-digit" }); -+ if (days === 0) return t("Today {time}", { time: clock4 }); -+ if (days === 1) return t("Yesterday {time}", { time: clock4 }); -+ const sameYear = date.getFullYear() === new Date(now).getFullYear(); -+ return `${date.toLocaleDateString(dateLocale(), { weekday: "short", month: "short", day: "numeric", ...sameYear ? {} : { year: "numeric" } })} ${clock4}`; ++function openingTurn(turns, firstTurns, hiddenTurns) { ++ if (!turns || !firstTurns) return null; ++ const start = nextTurnStart(turns, -Infinity); ++ if (start === void 0) return null; ++ const turn = Number(Object.keys(turns).filter((key) => turns[key].first === start)[0]); ++ const listed = firstTurns.split(",").map(Number); ++ const earlier = listed.filter((entry) => entry < turn); ++ return listed.includes(turn) && earlier.every((entry) => hiddenTurns?.includes(entry)) ? { turn, start } : null; } -function ValueEditor({ secret, onSave }) { - const [value, setValue] = (0, import_react5.useState)(""); @@ -9425,13 +9450,14 @@ diff --git a/client.js b/client.js - ), - value !== "" && !long ? (0, import_react5.createElement)("div", { className: "bt-set-hint" }, t("At least {count} characters.", { count: MIN_VALUE })) : replaced ? (0, import_react5.createElement)("div", { className: "bt-set-hint bt-secret-ok", role: "status" }, (0, import_react5.createElement)(CheckIcon), t("Replaced. Bots get the new value from their next command.")) : null - ); -+function nextTurnStart(turns, turn) { -+ let next; -+ for (const key in turns) { -+ const candidate = Number(key); -+ if (candidate > turn && turns[key].first !== void 0 && (next === void 0 || candidate < next)) next = candidate; ++var unseenSince = (visit, time) => typeof visit?.seen === "number" && time > visit.seen && time <= visit.entered; ++function movedOnSince(visit, turns, hiddenTurns) { ++ if (typeof visit?.entered !== "number") return false; ++ for (const key in turns ?? {}) { ++ if (hiddenTurns?.includes(Number(key))) continue; ++ if (turns[key].first !== void 0 && turns[key].first > visit.entered) return true; + } -+ return next === void 0 ? void 0 : turns[next].first; ++ return false; } -function SecretRow({ secret, roster, actions, run, open, onToggle }) { - const [confirm, setConfirm] = (0, import_react5.useState)(false); @@ -9474,15 +9500,31 @@ diff --git a/client.js b/client.js - ] : (0, import_react5.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm bt-secret-danger", onClick: () => setConfirm(true) }, (0, import_react5.createElement)(TrashIcon), t("Delete")) - ) - ) : null -- ); -+function openingTurn(turns, firstTurns, hiddenTurns) { -+ if (!turns || !firstTurns) return null; -+ const start = nextTurnStart(turns, -Infinity); -+ if (start === void 0) return null; -+ const turn = Number(Object.keys(turns).filter((key) => turns[key].first === start)[0]); -+ const listed = firstTurns.split(",").map(Number); -+ const earlier = listed.filter((entry) => entry < turn); -+ return listed.includes(turn) && earlier.every((entry) => hiddenTurns?.includes(entry)) ? { turn, start } : null; ++var settledVisit = (visit) => typeof visit?.seen === "number" && visit.seen < visit.entered ? { ...visit, seen: visit.entered } : visit; ++var leftSeen = (seen, tail, now = Date.now()) => Math.max(typeof seen === "number" ? seen : 0, typeof tail === "number" ? tail : now); ++function TurnTailCell({ turn: location2, sessionId, useTurnClock, useUi, actions }) { ++ const turn = location2.turn; ++ const time = location2.end.time; ++ (0, import_react12.useEffect)(() => { ++ actions.noteTurnTime(sessionId, turn, "end", time); ++ }, [sessionId, turn, time]); ++ const label = useTurnClock((state) => { ++ const start = nextTurnStart(state[sessionId] ?? {}, turn); ++ return start !== void 0 && start - time >= SEPARATOR_GAP_MS ? clockLabel(start) : ""; ++ }); ++ const visit = useUi((state) => state.visits?.[sessionId]); ++ const fresh = useTurnClock((state) => { ++ if (typeof visit?.seen !== "number" || time > visit.seen) return false; ++ const start = nextTurnStart(state[sessionId] ?? {}, turn); ++ return start !== void 0 && start > visit.seen && start <= visit.entered; ++ }); ++ if (!label && !fresh) return null; ++ return (0, import_react12.createElement)( ++ import_react12.Fragment, ++ null, ++ label ? (0, import_react12.createElement)("div", { className: "bt-time-sep", role: "separator" }, label) : null, ++ fresh ? (0, import_react12.createElement)(NewDivider) : null + ); } -function AddSecret({ actions, run, onDone }) { - const [name, setName] = (0, import_react5.useState)(""); @@ -9511,40 +9553,9 @@ diff --git a/client.js b/client.js - (0, import_react5.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", onClick: onDone }, t("Cancel")), - (0, import_react5.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", disabled: !ready, onClick: save }, t("Save key")) - ) -+var unseenSince = (visit, time) => typeof visit?.seen === "number" && time > visit.seen && time <= visit.entered; -+function movedOnSince(visit, turns, hiddenTurns) { -+ if (typeof visit?.entered !== "number") return false; -+ for (const key in turns ?? {}) { -+ if (hiddenTurns?.includes(Number(key))) continue; -+ if (turns[key].first !== void 0 && turns[key].first > visit.entered) return true; -+ } -+ return false; -+} -+var settledVisit = (visit) => typeof visit?.seen === "number" && visit.seen < visit.entered ? { ...visit, seen: visit.entered } : visit; -+var leftSeen = (seen, tail, now = Date.now()) => Math.max(typeof seen === "number" ? seen : 0, typeof tail === "number" ? tail : now); -+function TurnTailCell({ turn: location2, sessionId, useTurnClock, useUi, actions }) { -+ const turn = location2.turn; -+ const time = location2.end.time; -+ (0, import_react12.useEffect)(() => { -+ actions.noteTurnTime(sessionId, turn, "end", time); -+ }, [sessionId, turn, time]); -+ const label = useTurnClock((state) => { -+ const start = nextTurnStart(state[sessionId] ?? {}, turn); -+ return start !== void 0 && start - time >= SEPARATOR_GAP_MS ? clockLabel(start) : ""; -+ }); -+ const visit = useUi((state) => state.visits?.[sessionId]); -+ const fresh = useTurnClock((state) => { -+ if (typeof visit?.seen !== "number" || time > visit.seen) return false; -+ const start = nextTurnStart(state[sessionId] ?? {}, turn); -+ return start !== void 0 && start > visit.seen && start <= visit.entered; -+ }); -+ if (!label && !fresh) return null; -+ return (0, import_react12.createElement)( -+ import_react12.Fragment, -+ null, -+ label ? (0, import_react12.createElement)("div", { className: "bt-time-sep", role: "separator" }, label) : null, -+ fresh ? (0, import_react12.createElement)(NewDivider) : null - ); +- ); ++function Shimmer({ children }) { ++ return (0, import_react12.createElement)("span", { className: "bt-shimmer" }, children); } -function SecretsPage({ roster, actions, run, Section }) { - const [open, setOpen] = (0, import_react5.useState)(null); @@ -9569,8 +9580,63 @@ diff --git a/client.js b/client.js - ), - adding ? null : (0, import_react5.createElement)("div", { key: "add", className: "bt-actions" }, (0, import_react5.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", onClick: () => setAdding(true) }, t("Add a key"))) - ]; -+function Shimmer({ children }) { -+ return (0, import_react12.createElement)("span", { className: "bt-shimmer" }, children); ++var PHRASES = { ++ thinking: ["Thinking about it", "Weighing the options", "Working out a plan", "Sorting out the details"], ++ working: ["On it", "Busy with it", "Moving ahead", "Taking care of it", "Making headway"] ++}; ++var TOOL_PHRASES = [ ++ [/web_?search|search_?web/i, "Searching online"], ++ [/fetch|browse|browser|web/i, "Reading a page"], ++ [/shell|bash|pwsh|powershell|exec|command|terminal/i, "Running shell commands"], ++ [/^(read|view|cat)\b|read_/i, "Opening a file"], ++ [/grep|glob|list_dir|^ls$|find|search/i, "Looking through files"], ++ [/write|edit|patch|apply|replace/i, "Writing changes"], ++ [/image|photo|draw/i, "Working on an image"] ++]; ++var GROUP_PHRASES = { create_group: "Creating a group", update_group: "Updating the group", delete_group: "Deleting the group", post_to_group: "Posting in the group" }; ++function toolActivity(name, arg, findBot, self) { ++ switch (name) { ++ case "ask_user": ++ return null; ++ case "request_secret": ++ return null; ++ case "list_secrets": ++ return { label: t("Checking the keys"), state: "searching" }; ++ case "ask_user_question": ++ return { label: t("Waiting for your answer"), state: "alert" }; ++ case "group_relay": ++ return { relay: true, state: "orbit" }; ++ case "message_bot": { ++ const target = findBot(arg("to")); ++ return { label: target ? t("Asking {name}", { name: target.name }) : t("Asking another Bot"), state: "sending" }; ++ } ++ case "stop_bot": { ++ const target = findBot(arg("bot")); ++ return { label: target ? t("Stopping {name}", { name: target.name }) : t("Stopping another Bot"), state: "sending" }; ++ } ++ case "create_bot": ++ return { label: t("Creating {name}", { name: arg("name") ?? t("a Bot") }), state: "sending" }; ++ case "update_bot": { ++ const target = findBot(arg("name")) ?? findBot(arg("bot")) ?? (arg("bot") ? void 0 : self); ++ return { label: t("Updating {name}", { name: target?.name ?? t("a Bot") }), state: "sending" }; ++ } ++ case "list_bots": ++ return { label: t("Checking the team"), state: "searching" }; ++ case "read_group_chat": ++ return { label: t("Reading {name}", { name: arg("group") ?? t("a group chat") }), state: "searching" }; ++ case "read_own_chat": ++ return { label: t("Looking back through the chat"), state: "searching" }; ++ case "remember": ++ return { label: t("Saving to memory"), state: "working" }; ++ case "forget": ++ return { label: t("Updating memory"), state: "working" }; ++ case "recall": ++ return { label: t("Checking memory"), state: "searching" }; ++ default: ++ if (GROUP_PHRASES[name]) return { label: t(GROUP_PHRASES[name]), state: "sending" }; ++ const phrase = TOOL_PHRASES.find(([pattern]) => pattern.test(name))?.[1]; ++ return { label: phrase ? t(phrase) : null, state: toolState(name) }; ++ } } -var SECRET_CSS = ` -.bt-secret-head{align-items:center;gap:10px} @@ -9641,63 +9707,9 @@ diff --git a/client.js b/client.js - const members = steps.length ? steps : [current]; - if (members.find((step) => stepReasoning(step) !== "")?.step !== current.step) return ""; - return members.filter((step) => !thinkingLive(step)).map(stepReasoning).filter(Boolean).join("\n\n"); -+var PHRASES = { -+ thinking: ["Thinking about it", "Weighing the options", "Working out a plan", "Sorting out the details"], -+ working: ["On it", "Busy with it", "Moving ahead", "Taking care of it", "Making headway"] -+}; -+var TOOL_PHRASES = [ -+ [/web_?search|search_?web/i, "Searching online"], -+ [/fetch|browse|browser|web/i, "Reading a page"], -+ [/shell|bash|pwsh|powershell|exec|command|terminal/i, "Running shell commands"], -+ [/^(read|view|cat)\b|read_/i, "Opening a file"], -+ [/grep|glob|list_dir|^ls$|find|search/i, "Looking through files"], -+ [/write|edit|patch|apply|replace/i, "Writing changes"], -+ [/image|photo|draw/i, "Working on an image"] -+]; -+var GROUP_PHRASES = { create_group: "Creating a group", update_group: "Updating the group", delete_group: "Deleting the group", post_to_group: "Posting in the group" }; -+function toolActivity(name, arg, findBot, self) { -+ switch (name) { -+ case "ask_user": -+ return null; -+ case "request_secret": -+ return null; -+ case "list_secrets": -+ return { label: t("Checking the keys"), state: "searching" }; -+ case "ask_user_question": -+ return { label: t("Waiting for your answer"), state: "alert" }; -+ case "group_relay": -+ return { relay: true, state: "orbit" }; -+ case "message_bot": { -+ const target = findBot(arg("to")); -+ return { label: target ? t("Asking {name}", { name: target.name }) : t("Asking another Bot"), state: "sending" }; -+ } -+ case "stop_bot": { -+ const target = findBot(arg("bot")); -+ return { label: target ? t("Stopping {name}", { name: target.name }) : t("Stopping another Bot"), state: "sending" }; -+ } -+ case "create_bot": -+ return { label: t("Creating {name}", { name: arg("name") ?? t("a Bot") }), state: "sending" }; -+ case "update_bot": { -+ const target = findBot(arg("name")) ?? findBot(arg("bot")) ?? (arg("bot") ? void 0 : self); -+ return { label: t("Updating {name}", { name: target?.name ?? t("a Bot") }), state: "sending" }; -+ } -+ case "list_bots": -+ return { label: t("Checking the team"), state: "searching" }; -+ case "read_group_chat": -+ return { label: t("Reading {name}", { name: arg("group") ?? t("a group chat") }), state: "searching" }; -+ case "read_own_chat": -+ return { label: t("Looking back through the chat"), state: "searching" }; -+ case "remember": -+ return { label: t("Saving to memory"), state: "working" }; -+ case "forget": -+ return { label: t("Updating memory"), state: "working" }; -+ case "recall": -+ return { label: t("Checking memory"), state: "searching" }; -+ default: -+ if (GROUP_PHRASES[name]) return { label: t(GROUP_PHRASES[name]), state: "sending" }; -+ const phrase = TOOL_PHRASES.find(([pattern]) => pattern.test(name))?.[1]; -+ return { label: phrase ? t(phrase) : null, state: toolState(name) }; -+ } ++function workPhrase(tool) { ++ if (!tool) return t("Thinking about it"); ++ return toolActivity(tool, () => void 0, () => void 0)?.label ?? t("Using {tool}", { tool }); } -var texts = (step) => step.blocks.filter((block) => block.kind === "text" && block.text.trim() !== ""); -var thinkingLive = (step) => step.status === "running" && texts(step).length === 0 && step.blocks.some((block) => block.kind === "reasoning"); @@ -9718,10 +9730,6 @@ diff --git a/client.js b/client.js - }; - const reactions = useUi ? useUi((state) => msgKey ? state.reactions?.[msgKey] ?? null : null) : null; - return (0, import_react6.createElement)( -+function workPhrase(tool) { -+ if (!tool) return t("Thinking about it"); -+ return toolActivity(tool, () => void 0, () => void 0)?.label ?? t("Using {tool}", { tool }); -+} +function workText(tool, step) { + return step ? t("{action}: {detail}", { action: workPhrase(tool), detail: step }) : `${workPhrase(tool)}…`; +} @@ -10232,12 +10240,7 @@ diff --git a/client.js b/client.js + return () => clearTimeout(timer); + }, [shown, at]); + return shown; - } --var scrollParent = (node) => { -- for (let at = node.parentElement; at; at = at.parentElement) { -- if (/(auto|scroll)/.test(getComputedStyle(at).overflowY)) return at; -- } -- return null; ++} +function findHost(where) { + if (where !== TAIL_HOST) return findRunningHostIn(document); + const flow = document.querySelector("[data-conversation-scroll] [data-chat-flow]") ?? document.querySelector("[data-chat-flow]"); @@ -10251,7 +10254,47 @@ diff --git a/client.js b/client.js + let top = -1; + for (const node of document.querySelectorAll(`[data-chat-flow-kind${kind ? `="${kind}"` : ""}][data-chat-turn]`)) top = Math.max(top, Number(node.dataset.chatTurn)); + return top; - }; ++}; ++function useReplyAfterSend(remote, sending) { ++ const sendTurn = (0, import_react13.useRef)(-1); ++ const wasSending = (0, import_react13.useRef)(false); ++ const [replied, setReplied] = (0, import_react13.useState)(false); ++ (0, import_react13.useEffect)(() => { ++ if (!remote) return void 0; ++ if (sending) { ++ wasSending.current = true; ++ sendTurn.current = -1; ++ setReplied(false); ++ return void 0; ++ } ++ if (wasSending.current) { ++ wasSending.current = false; ++ sendTurn.current = lastTurnOnScreen(); ++ } ++ if (sendTurn.current < 0) return void 0; ++ let frame = 0; ++ const check = () => { ++ frame = 0; ++ if (lastTurnOnScreen("assistant-step") > sendTurn.current) setReplied(true); ++ }; ++ const observer = new MutationObserver(() => { ++ if (!frame) frame = requestAnimationFrame(check); ++ }); ++ observer.observe(document.querySelector("[data-conversation-scroll]") ?? document.body, { childList: true, subtree: true }); ++ check(); ++ return () => { ++ cancelAnimationFrame(frame); ++ observer.disconnect(); ++ }; ++ }, [remote, sending]); ++ return replied; + } +-var scrollParent = (node) => { +- for (let at = node.parentElement; at; at = at.parentElement) { +- if (/(auto|scroll)/.test(getComputedStyle(at).overflowY)) return at; +- } +- return null; +-}; -function EarlierParts({ sessionId, roster, actions }) { - const [view, setView] = (0, import_react6.useState)({ items: [], cursor: void 0, loading: true, failed: false, startedAt: null }); - const top = (0, import_react6.useRef)(null); @@ -10271,37 +10314,28 @@ diff --git a/client.js b/client.js - }, () => { - busy.current = false; - if (alive.current) setView((current) => ({ ...current, loading: false, failed: true })); -+function useReplyAfterSend(remote, sending) { -+ const sendTurn = (0, import_react13.useRef)(-1); -+ const wasSending = (0, import_react13.useRef)(false); -+ const [replied, setReplied] = (0, import_react13.useState)(false); ++function useRunningHost(active, where = RUNNING_HOST) { ++ const [host, setHost] = (0, import_react13.useState)(null); + (0, import_react13.useEffect)(() => { -+ if (!remote) return void 0; -+ if (sending) { -+ wasSending.current = true; -+ sendTurn.current = -1; -+ setReplied(false); ++ if (!active) { ++ setHost(null); + return void 0; + } -+ if (wasSending.current) { -+ wasSending.current = false; -+ sendTurn.current = lastTurnOnScreen(); -+ } -+ if (sendTurn.current < 0) return void 0; + let frame = 0; -+ const check = () => { ++ const find = () => { + frame = 0; -+ if (lastTurnOnScreen("assistant-step") > sendTurn.current) setReplied(true); ++ const node = findHost(where); ++ setHost((prev) => prev === node ? prev : node); + }; + const observer = new MutationObserver(() => { -+ if (!frame) frame = requestAnimationFrame(check); ++ if (!frame) frame = requestAnimationFrame(find); }); - }; - (0, import_react6.useEffect)(() => { - alive.current = true; - load(void 0); + observer.observe(document.querySelector("[data-conversation-scroll]") ?? document.body, { childList: true, subtree: true }); -+ check(); ++ find(); return () => { - alive.current = false; + cancelAnimationFrame(frame); @@ -10367,8 +10401,8 @@ diff --git a/client.js b/client.js - }), - (0, import_react6.createElement)(PartLine, { time: view.startedAt }) - ); -+ }, [remote, sending]); -+ return replied; ++ }, [active, where]); ++ return host; } -function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnClock, useUi, actions }) { - const roster = useRoster((value) => value); @@ -10426,31 +10460,6 @@ diff --git a/client.js b/client.js - const bots = [sender]; - for (const peer of (run?.peerIds ?? []).map((id) => roster.byId[id]).filter(Boolean)) { - if (!bots.some((bot) => bot.id === peer.id)) bots.push(peer); -+function useRunningHost(active, where = RUNNING_HOST) { -+ const [host, setHost] = (0, import_react13.useState)(null); -+ (0, import_react13.useEffect)(() => { -+ if (!active) { -+ setHost(null); -+ return void 0; -+ } -+ let frame = 0; -+ const find = () => { -+ frame = 0; -+ const node = findHost(where); -+ setHost((prev) => prev === node ? prev : node); -+ }; -+ const observer = new MutationObserver(() => { -+ if (!frame) frame = requestAnimationFrame(find); -+ }); -+ observer.observe(document.querySelector("[data-conversation-scroll]") ?? document.body, { childList: true, subtree: true }); -+ find(); -+ return () => { -+ cancelAnimationFrame(frame); -+ observer.disconnect(); -+ }; -+ }, [active, where]); -+ return host; -+} +function useRowEntrances(replacing) { + const check = (0, import_react13.useRef)(replacing); + check.current = replacing; @@ -10560,28 +10569,6 @@ diff --git a/client.js b/client.js } - if (source.kind === "user-question-reply") return null; - return (0, import_react6.createElement)("div", { className: "bt-event" }, contentText(data.content).slice(0, 80) || t("Update")); -- } --} --function NewDivider() { -- return (0, import_react6.createElement)("div", { className: "bt-new-sep", role: "separator", "aria-label": t("New messages") }, (0, import_react6.createElement)("span", null, t("New"))); --} --function TurnProcessCell({ node, sessionId, turnProcess, useRoster, useUi, useTurnClock, actions }) { -- const open = turnProcess === void 0 || !turnProcess.foldable || turnProcess.open; -- (0, import_react6.useEffect)(() => { -- if (!open) turnProcess.setOpen(true); -- }, [open, turnProcess]); -- const turn = node?.location?.turn?.turn ?? node?.data?.turn; -- const start = node?.location?.turn?.start?.time; -- const hidden = useRoster((roster) => isHiddenTurn(roster, sessionId, turn)); -- (0, import_react6.useEffect)(() => { -- actions.noteTurnTime(sessionId, turn, "first", start); -- }, [sessionId, turn, start]); -- const visit = useUi((state) => state.visits?.[sessionId]); -- const fresh = useTurnClock((state) => { -- const own = state[sessionId]?.[turn]; -- return !hidden && typeof visit?.seen === "number" && own?.first !== void 0 && own.first <= visit.seen && own.end !== void 0 && own.end > visit.seen && own.end <= visit.entered; -- }); -- return fresh ? (0, import_react6.createElement)(NewDivider) : null; + let timer; + const leave = () => { + setPhase((current) => current === "in" ? "out" : current); @@ -10639,9 +10626,7 @@ diff --git a/client.js b/client.js + ) + ) + ), host); - } --function Nothing() { -- return null; ++} + +// src/shared/session-list-filter.js +var SESSION_FILTERS = ["all", "group", "direct", "unread"]; @@ -10659,34 +10644,17 @@ diff --git a/client.js b/client.js + } + if (entry.kind === "room") { + return sessionStatusOf(statusMap, item.id)?.completionUnread === true; -+ } + } + const part = item.sessionId ?? item.id; + const status = sessionStatusOf(statusMap, part); + return status?.completionUnread === true || status?.pendingInteraction !== void 0; - } --var SEPARATOR_GAP_MS = 30 * 60 * 1e3; --function clockLabel(time, now = Date.now()) { -- const date = new Date(time); -- const midnight = (value) => new Date(value.getFullYear(), value.getMonth(), value.getDate()).getTime(); -- const days = Math.round((midnight(new Date(now)) - midnight(date)) / 864e5); -- const clock4 = date.toLocaleTimeString(dateLocale(), { hour: "numeric", minute: "2-digit" }); -- if (days === 0) return t("Today {time}", { time: clock4 }); -- if (days === 1) return t("Yesterday {time}", { time: clock4 }); -- const sameYear = date.getFullYear() === new Date(now).getFullYear(); -- return `${date.toLocaleDateString(dateLocale(), { weekday: "short", month: "short", day: "numeric", ...sameYear ? {} : { year: "numeric" } })} ${clock4}`; ++} +function matchesSessionFilter(entry, filter, unread = false) { + if (filter === "group") return entry?.kind === "room"; + if (filter === "direct") return entry?.kind === "bot" || entry?.kind === "agent"; + if (filter === "unread") return unread === true; + return true; - } --function nextTurnStart(turns, turn) { -- let next; -- for (const key in turns) { -- const candidate = Number(key); -- if (candidate > turn && turns[key].first !== void 0 && (next === void 0 || candidate < next)) next = candidate; -- } -- return next === void 0 ? void 0 : turns[next].first; ++} + +// src/client/dsh-offer.js +var APP_OFFER = /* @__PURE__ */ new Set(["available", "downloading", "verifying", "installing", "ready"]); @@ -10697,14 +10665,8 @@ diff --git a/client.js b/client.js + if (dsh.kind === "npm") return true; + return dsh.kind === "app" && APP_OFFER.has(app?.phase) && sameVersion(app.version, dsh.verified); } --function openingTurn(turns, firstTurns, hiddenTurns) { -- if (!turns || !firstTurns) return null; -- const start = nextTurnStart(turns, -Infinity); -- if (start === void 0) return null; -- const turn = Number(Object.keys(turns).filter((key) => turns[key].first === start)[0]); -- const listed = firstTurns.split(",").map(Number); -- const earlier = listed.filter((entry) => entry < turn); -- return listed.includes(turn) && earlier.every((entry) => hiddenTurns?.includes(entry)) ? { turn, start } : null; +-function NewDivider() { +- return (0, import_react6.createElement)("div", { className: "bt-new-sep", role: "separator", "aria-label": t("New messages") }, (0, import_react6.createElement)("span", null, t("New"))); + +// src/client/overlay-hooks.js +var import_react14 = require("react"); @@ -10724,30 +10686,23 @@ diff --git a/client.js b/client.js + }; + }, []); } --var unseenSince = (visit, time) => typeof visit?.seen === "number" && time > visit.seen && time <= visit.entered; --function TurnTailCell({ turn: location2, sessionId, useTurnClock, useUi, actions }) { -- const turn = location2.turn; -- const time = location2.end.time; +-function TurnProcessCell({ node, sessionId, turnProcess, useRoster, useUi, useTurnClock, actions }) { +- const open = turnProcess === void 0 || !turnProcess.foldable || turnProcess.open; - (0, import_react6.useEffect)(() => { -- actions.noteTurnTime(sessionId, turn, "end", time); -- }, [sessionId, turn, time]); -- const label = useTurnClock((state) => { -- const start = nextTurnStart(state[sessionId] ?? {}, turn); -- return start !== void 0 && start - time >= SEPARATOR_GAP_MS ? clockLabel(start) : ""; -- }); +- if (!open) turnProcess.setOpen(true); +- }, [open, turnProcess]); +- const turn = node?.location?.turn?.turn ?? node?.data?.turn; +- const start = node?.location?.turn?.start?.time; +- const hidden = useRoster((roster) => isHiddenTurn(roster, sessionId, turn)); +- (0, import_react6.useEffect)(() => { +- actions.noteTurnTime(sessionId, turn, "first", start); +- }, [sessionId, turn, start]); - const visit = useUi((state) => state.visits?.[sessionId]); - const fresh = useTurnClock((state) => { -- if (typeof visit?.seen !== "number" || time > visit.seen) return false; -- const start = nextTurnStart(state[sessionId] ?? {}, turn); -- return start !== void 0 && start > visit.seen && start <= visit.entered; +- const own = state[sessionId]?.[turn]; +- return !hidden && typeof visit?.seen === "number" && own?.first !== void 0 && own.first <= visit.seen && own.end !== void 0 && own.end > visit.seen && own.end <= visit.entered; - }); -- if (!label && !fresh) return null; -- return (0, import_react6.createElement)( -- import_react6.Fragment, -- null, -- label ? (0, import_react6.createElement)("div", { className: "bt-time-sep", role: "separator" }, label) : null, -- fresh ? (0, import_react6.createElement)(NewDivider) : null -- ); +- return fresh ? (0, import_react6.createElement)(NewDivider) : null; +function useDialogFocus(ref) { + (0, import_react14.useEffect)(() => { + const before = document.activeElement; @@ -10760,8 +10715,8 @@ diff --git a/client.js b/client.js + }; + }, []); } --function Shimmer({ children }) { -- return (0, import_react6.createElement)("span", { className: "bt-shimmer" }, children); +-function Nothing() { +- return null; +function usePaneLeft() { + const [paneLeft, setPaneLeft] = (0, import_react14.useState)(280); + (0, import_react14.useLayoutEffect)(() => { @@ -10770,9 +10725,16 @@ diff --git a/client.js b/client.js + }, []); + return paneLeft; } --var PHRASES = { -- thinking: ["Thinking about it", "Weighing the options", "Working out a plan", "Sorting out the details"], -- working: ["On it", "Busy with it", "Moving ahead", "Taking care of it", "Making headway"] +-var SEPARATOR_GAP_MS = 30 * 60 * 1e3; +-function clockLabel(time, now = Date.now()) { +- const date = new Date(time); +- const midnight = (value) => new Date(value.getFullYear(), value.getMonth(), value.getDate()).getTime(); +- const days = Math.round((midnight(new Date(now)) - midnight(date)) / 864e5); +- const clock4 = date.toLocaleTimeString(dateLocale(), { hour: "numeric", minute: "2-digit" }); +- if (days === 0) return t("Today {time}", { time: clock4 }); +- if (days === 1) return t("Yesterday {time}", { time: clock4 }); +- const sameYear = date.getFullYear() === new Date(now).getFullYear(); +- return `${date.toLocaleDateString(dateLocale(), { weekday: "short", month: "short", day: "numeric", ...sameYear ? {} : { year: "numeric" } })} ${clock4}`; + +// src/client/member-status.js +var import_react15 = require("react"); @@ -10781,20 +10743,122 @@ diff --git a/client.js b/client.js +var stepIn = (work, botId, roomId, tool) => { + const own = work.bots?.[botId]; + return own?.roomId === roomId && own.tool === tool ? own.step : void 0; - }; --var TOOL_PHRASES = [ -- [/web_?search|search_?web/i, "Searching online"], -- [/fetch|browse|browser|web/i, "Reading a page"], -- [/shell|bash|pwsh|powershell|exec|command|terminal/i, "Running shell commands"], -- [/^(read|view|cat)\b|read_/i, "Opening a file"], -- [/grep|glob|list_dir|^ls$|find|search/i, "Looking through files"], -- [/write|edit|patch|apply|replace/i, "Writing changes"], -- [/image|photo|draw/i, "Working on an image"] --]; --var GROUP_PHRASES = { create_group: "Creating a group", update_group: "Updating the group", delete_group: "Deleting the group", post_to_group: "Posting in the group" }; --function toolActivity(name, arg, findBot, self) { -- switch (name) { -- case "ask_user": ++}; ++var workIn = (room2, work, id) => { ++ const local = (work.rooms?.[room2.id] ?? []).find((entry) => entry.botId === id); ++ if (local) return { ...local, roomId: room2.id, step: stepIn(work, id, room2.id, local.tool) }; ++ const own = work.bots?.[id]; ++ return own !== void 0 && own.roomId === void 0 && own.fromRoomId === room2.id ? { ...own, roomId: room2.id, handed: true } : void 0; ++}; ++var askedIn = (room2, work, id, doing) => (work.approvals ?? []).filter((entry) => entry.botId === id && (entry.roomId === room2.id || entry.roomId === void 0 && doing?.handed === true)); ++function memberWork(room2, work = NO_WORK) { ++ return room2.members.map((id) => { ++ const doing = workIn(room2, work, id); ++ const approvals = askedIn(room2, work, id, doing); ++ return { id, approvals, doing, here: doing !== void 0, state: approvals.length > 0 ? "ask" : doing ? "work" : "idle" }; ++ }); + } +-function nextTurnStart(turns, turn) { +- let next; +- for (const key in turns) { +- const candidate = Number(key); +- if (candidate > turn && turns[key].first !== void 0 && (next === void 0 || candidate < next)) next = candidate; +- } +- return next === void 0 ? void 0 : turns[next].first; ++function busyMembers(room2, work, roster) { ++ const busy = memberWork(room2, work).filter((entry) => entry.state !== "idle" && roster.byId[entry.id]); ++ return [...busy.filter((entry) => entry.state === "ask"), ...busy.filter((entry) => entry.state === "work")].map((entry) => ({ ...entry, bot: roster.byId[entry.id] })); + } +-function openingTurn(turns, firstTurns, hiddenTurns) { +- if (!turns || !firstTurns) return null; +- const start = nextTurnStart(turns, -Infinity); +- if (start === void 0) return null; +- const turn = Number(Object.keys(turns).filter((key) => turns[key].first === start)[0]); +- const listed = firstTurns.split(",").map(Number); +- const earlier = listed.filter((entry) => entry < turn); +- return listed.includes(turn) && earlier.every((entry) => hiddenTurns?.includes(entry)) ? { turn, start } : null; ++function splitBusy(busy) { ++ const here = busy.filter((entry) => entry.state === "work" && entry.here); ++ const rows = [...here.filter((entry) => entry.doing.speaking === true), ...here.filter((entry) => entry.doing.speaking !== true)].slice(0, ROWS_MAX); ++ return { rows, rest: busy.filter((entry) => !rows.includes(entry)) }; + } +-var unseenSince = (visit, time) => typeof visit?.seen === "number" && time > visit.seen && time <= visit.entered; +-function TurnTailCell({ turn: location2, sessionId, useTurnClock, useUi, actions }) { +- const turn = location2.turn; +- const time = location2.end.time; +- (0, import_react6.useEffect)(() => { +- actions.noteTurnTime(sessionId, turn, "end", time); +- }, [sessionId, turn, time]); +- const label = useTurnClock((state) => { +- const start = nextTurnStart(state[sessionId] ?? {}, turn); +- return start !== void 0 && start - time >= SEPARATOR_GAP_MS ? clockLabel(start) : ""; +- }); +- const visit = useUi((state) => state.visits?.[sessionId]); +- const fresh = useTurnClock((state) => { +- if (typeof visit?.seen !== "number" || time > visit.seen) return false; +- const start = nextTurnStart(state[sessionId] ?? {}, turn); +- return start !== void 0 && start > visit.seen && start <= visit.entered; ++function botGroupWork(botId, work, roster) { ++ return Object.entries(work.rooms ?? {}).flatMap(([roomId, entries2]) => { ++ const entry = entries2.find((item) => item.botId === botId); ++ const room2 = roster.roomsById[roomId]; ++ return entry && room2 ? [{ room: room2, tool: entry.tool, step: stepIn(work, botId, roomId, entry.tool), since: entry.since }] : []; + }); +- if (!label && !fresh) return null; +- return (0, import_react6.createElement)( +- import_react6.Fragment, +- null, +- label ? (0, import_react6.createElement)("div", { className: "bt-time-sep", role: "separator" }, label) : null, +- fresh ? (0, import_react6.createElement)(NewDivider) : null ++} ++var moreRooms = (count) => count === 1 ? t("1 more room") : t("{count} more rooms", { count }); ++function summaryText(busy) { ++ const asks = busy.filter((entry) => entry.state === "ask"); ++ const workers = busy.filter((entry) => entry.state === "work"); ++ const names = asks.slice(0, 2).map((entry) => entry.bot.name); ++ const waiting = asks.length === 0 ? "" : asks.length === 1 ? t("{name} is waiting for your approval", { name: names[0] }) : asks.length === 2 ? t("{first} and {second} are waiting for your approval", { first: names[0], second: names[1] }) : t("{first}, {second} and {count} more are waiting for your approval", { first: names[0], second: names[1], count: asks.length - 2, total: asks.length }); ++ const first = workers[0]; ++ const doing = first ? `${first.bot.name} · ${workText(first.doing.tool, first.doing.step)}${workers.length > 1 ? ` +${workers.length - 1}` : ""}` : ""; ++ return { waiting, doing }; ++} ++function Face({ entry, size }) { ++ return (0, import_react15.createElement)( ++ "span", ++ { className: "bt-mw-face", "data-ask": entry.state === "ask" || void 0 }, ++ (0, import_react15.createElement)(BotMark, { bot: entry.bot, size, state: entry.state === "ask" ? "alert" : toolState(entry.doing?.tool ?? "") }) + ); + } +-function Shimmer({ children }) { +- return (0, import_react6.createElement)("span", { className: "bt-shimmer" }, children); ++var elapsedSince = (now, at) => typeof at === "number" && now - at >= 6e4 ? elapsedLabel(now - at) : ""; ++function WorkRow({ bot, tool, step, label, at, now, onOpen }) { ++ const text2 = `${label} · ${workText(tool, step)}`; ++ const elapsed = elapsedSince(now, at); ++ return (0, import_react15.createElement)( ++ "button", ++ { type: "button", className: "bt-mw-row", "aria-label": [text2, elapsed].filter(Boolean).join(" · "), onClick: onOpen }, ++ (0, import_react15.createElement)(BotMark, { bot, size: 22, state: toolState(tool ?? ""), live: true }), ++ (0, import_react15.createElement)("span", { className: "bt-mw-row-text" }, (0, import_react15.createElement)(Shimmer, null, text2)), ++ elapsed ? (0, import_react15.createElement)("span", { className: "bt-mw-row-time" }, `· ${elapsed}`) : null ++ ); + } +-var PHRASES = { +- thinking: ["Thinking about it", "Weighing the options", "Working out a plan", "Sorting out the details"], +- working: ["On it", "Busy with it", "Moving ahead", "Taking care of it", "Making headway"] +-}; +-var TOOL_PHRASES = [ +- [/web_?search|search_?web/i, "Searching online"], +- [/fetch|browse|browser|web/i, "Reading a page"], +- [/shell|bash|pwsh|powershell|exec|command|terminal/i, "Running shell commands"], +- [/^(read|view|cat)\b|read_/i, "Opening a file"], +- [/grep|glob|list_dir|^ls$|find|search/i, "Looking through files"], +- [/write|edit|patch|apply|replace/i, "Writing changes"], +- [/image|photo|draw/i, "Working on an image"] +-]; +-var GROUP_PHRASES = { create_group: "Creating a group", update_group: "Updating the group", delete_group: "Deleting the group", post_to_group: "Posting in the group" }; +-function toolActivity(name, arg, findBot, self) { +- switch (name) { +- case "ask_user": - return null; - case "request_secret": - return null; @@ -10834,27 +10898,87 @@ diff --git a/client.js b/client.js - if (GROUP_PHRASES[name]) return { label: t(GROUP_PHRASES[name]), state: "sending" }; - const phrase = TOOL_PHRASES.find(([pattern]) => pattern.test(name))?.[1]; - return { label: phrase ? t(phrase) : null, state: toolState(name) }; -- } -+var workIn = (room2, work, id) => { -+ const local = (work.rooms?.[room2.id] ?? []).find((entry) => entry.botId === id); -+ if (local) return { ...local, roomId: room2.id, step: stepIn(work, id, room2.id, local.tool) }; -+ const own = work.bots?.[id]; -+ return own !== void 0 && own.roomId === void 0 && own.fromRoomId === room2.id ? { ...own, roomId: room2.id, handed: true } : void 0; -+}; -+var askedIn = (room2, work, id, doing) => (work.approvals ?? []).filter((entry) => entry.botId === id && (entry.roomId === room2.id || entry.roomId === void 0 && doing?.handed === true)); -+function memberWork(room2, work = NO_WORK) { -+ return room2.members.map((id) => { -+ const doing = workIn(room2, work, id); -+ const approvals = askedIn(room2, work, id, doing); -+ return { id, approvals, doing, here: doing !== void 0, state: approvals.length > 0 ? "ask" : doing ? "work" : "idle" }; -+ }); ++function SummaryLine({ busy, now, onOpen }) { ++ const { waiting, doing } = summaryText(busy); ++ const elapsed = doing ? elapsedSince(now, busy.find((entry) => entry.state === "work")?.doing.since) : ""; ++ return (0, import_react15.createElement)( ++ "button", ++ { type: "button", className: "bt-mw-row bt-mw-line", "aria-label": [waiting, doing, elapsed].filter(Boolean).join(" · "), onClick: onOpen }, ++ (0, import_react15.createElement)("span", { className: "bt-mw-stack", "aria-hidden": true }, busy.slice(0, 4).map((entry) => (0, import_react15.createElement)(Face, { key: entry.id, entry, size: 16 }))), ++ (0, import_react15.createElement)( ++ "span", ++ { className: "bt-mw-row-text" }, ++ waiting ? (0, import_react15.createElement)("span", { className: "bt-mw-ask" }, waiting) : null, ++ waiting && doing ? " · " : null, ++ doing ? (0, import_react15.createElement)(Shimmer, null, doing) : null ++ ), ++ elapsed ? (0, import_react15.createElement)("span", { className: "bt-mw-row-time" }, `· ${elapsed}`) : null ++ ); ++} ++function MemberDock({ sessionId, useRoster, useWork, actions }) { ++ const roster = useRoster((value) => value); ++ const work = useWork((value) => value); ++ const room2 = roster.roomsById[sessionId]; ++ const bot = room2 ? void 0 : roster.byId[sessionId]; ++ const ownChat = bot !== void 0 && work.bots?.[bot.id] !== void 0 && work.bots[bot.id].roomId === void 0; ++ const busy = room2 ? busyMembers(room2, work, roster) : []; ++ const groups = bot !== void 0 && !ownChat ? botGroupWork(bot.id, work, roster) : []; ++ const shown = busy.length > 0 || groups.length > 0; ++ const now = useNow(shown); ++ const ref = (0, import_react15.useRef)(null); ++ useFlowColumn(ref, shown, sessionId); ++ if (!shown) return null; ++ if (room2) { ++ const { rows: rows2, rest } = splitBusy(busy); ++ const open = () => actions.showDetails(sessionId); ++ return (0, import_react15.createElement)( ++ "div", ++ { ref, className: "bt-mw-dock-stack" }, ++ rows2.map((entry) => (0, import_react15.createElement)(WorkRow, { key: entry.id, bot: entry.bot, tool: entry.doing.tool, step: entry.doing.step, label: entry.bot.name, at: entry.doing.since, now, onOpen: open })), ++ rest.length > 0 ? (0, import_react15.createElement)(SummaryLine, { busy: rest, now, onOpen: open }) : null ++ ); + } ++ const rows = groups.slice(0, ROWS_MAX); ++ const more = groups.length - rows.length; ++ return (0, import_react15.createElement)( ++ "div", ++ { ref, className: "bt-mw-dock-stack" }, ++ rows.map((item) => (0, import_react15.createElement)(WorkRow, { ++ key: item.room.id, ++ bot, ++ tool: item.tool, ++ step: item.step, ++ label: t("in {name}", { name: item.room.name }), ++ at: item.since, ++ now, ++ onOpen: () => actions.openSession(item.room.id) ++ })), ++ more > 0 ? (0, import_react15.createElement)( ++ "div", ++ { className: "bt-mw-row bt-mw-line bt-mw-static" }, ++ (0, import_react15.createElement)("span", { className: "bt-mw-row-text" }, moreRooms(more)) ++ ) : null ++ ); } -function workPhrase(tool) { - if (!tool) return t("Thinking about it"); - return toolActivity(tool, () => void 0, () => void 0)?.label ?? t("On it"); -+function busyMembers(room2, work, roster) { -+ const busy = memberWork(room2, work).filter((entry) => entry.state !== "idle" && roster.byId[entry.id]); -+ return [...busy.filter((entry) => entry.state === "ask"), ...busy.filter((entry) => entry.state === "work")].map((entry) => ({ ...entry, bot: roster.byId[entry.id] })); ++function useFlowColumn(ref, active, key) { ++ (0, import_react15.useLayoutEffect)(() => { ++ const node = ref.current; ++ const flow = document.querySelector("[data-chat-flow]"); ++ if (!active || !node || !flow) return void 0; ++ const place = () => { ++ node.style.marginInlineStart = "0px"; ++ const column = flow.getBoundingClientRect(); ++ node.style.marginInlineStart = `${Math.round(column.left - node.getBoundingClientRect().left)}px`; ++ node.style.width = `${Math.round(column.width)}px`; ++ }; ++ place(); ++ const observer = new ResizeObserver(place); ++ for (const target of [flow, flow.parentElement, node.parentElement]) if (target) observer.observe(target); ++ return () => observer.disconnect(); ++ }, [active, key]); } -function useLiveNote(actions, sessionId, id, entry) { - const key = entry ? JSON.stringify(entry) : ""; @@ -10863,10 +10987,45 @@ diff --git a/client.js b/client.js - actions.noteLive(sessionId, id, JSON.parse(key)); - return () => actions.noteLive(sessionId, id, null); - }, [sessionId, id, key]); -+function splitBusy(busy) { -+ const here = busy.filter((entry) => entry.state === "work" && entry.here); -+ const rows = [...here.filter((entry) => entry.doing.speaking === true), ...here.filter((entry) => entry.doing.speaking !== true)].slice(0, ROWS_MAX); -+ return { rows, rest: busy.filter((entry) => !rows.includes(entry)) }; ++function useNow(active) { ++ const [now, setNow] = (0, import_react15.useState)(Date.now); ++ (0, import_react15.useEffect)(() => { ++ if (!active) return void 0; ++ const timer = setInterval(() => setNow(Date.now()), 3e4); ++ return () => clearInterval(timer); ++ }, [active]); ++ return now; ++} ++var since = (now, at) => typeof at === "number" && now - at >= 6e4 ? ` · ${elapsedLabel(now - at)}` : ""; ++var alwaysChoices = (approval, bot) => bot?.remote ? [] : [ ++ ["always-bot", "Always allow for this Bot"], ++ ...approval.roomId ? [["always-room", "Always allow for this group"]] : [] ++]; ++function ApprovalCard({ approval, bot, actions }) { ++ const [busy, setBusy] = (0, import_react15.useState)(false); ++ const answer = (choice) => { ++ setBusy(true); ++ void Promise.resolve(actions.answerApproval(approval.id, choice)).catch((error) => actions.reportError(error, "approval")).finally(() => setBusy(false)); ++ }; ++ return (0, import_react15.createElement)( ++ "div", ++ { className: "bt-mw-card", role: "group", "aria-label": t("{name} is waiting for your approval", { name: bot.name }) }, ++ (0, import_react15.createElement)("div", { className: "bt-mw-tool" }, approval.tool), ++ approval.detail?.text ? (0, import_react15.createElement)("div", { className: "bt-mw-text" }, approval.detail.text) : null, ++ approval.reason ? (0, import_react15.createElement)("div", { className: "bt-mw-reason" }, approval.reason) : null, ++ approval.detail?.code ? (0, import_react15.createElement)("code", { className: "bt-mw-code", title: approval.detail.code }, approval.detail.code) : null, ++ approval.answerable ? (0, import_react15.createElement)( ++ "div", ++ { className: "bt-mw-actions" }, ++ (0, import_react15.createElement)("button", { type: "button", className: "bt-q-btn", disabled: busy, onClick: () => answer("reject") }, t("Reject")), ++ (0, import_react15.createElement)("button", { type: "button", className: "bt-q-submit", disabled: busy, onClick: () => answer("allow") }, t("Allow once")), ++ ...alwaysChoices(approval, bot).map(([choice, label]) => (0, import_react15.createElement)("button", { key: choice, type: "button", className: "bt-q-btn", "data-choice": choice, disabled: busy, onClick: () => answer(choice) }, t(label))) ++ ) : (0, import_react15.createElement)( ++ "div", ++ { className: "bt-mw-actions" }, ++ (0, import_react15.createElement)("button", { type: "button", className: "bt-q-btn", onClick: () => actions.openSession(bot.id) }, t("Open {name}'s chat", { name: bot.name })) ++ ) ++ ); } -function GroupReplies({ sessionId, callId, done, content, roster, actions, useUi, useWork }) { - const [live, setLive] = (0, import_react6.useState)({ replies: [], speaking: null }); @@ -10899,13 +11058,28 @@ diff --git a/client.js b/client.js - } catch { - replies = []; - } -- } ++function MemberWork({ entry, bot, room: room2, actions, now }) { ++ const [stopping, setStopping] = (0, import_react15.useState)(false); ++ if (entry.state === "ask") { ++ return (0, import_react15.createElement)( ++ "div", ++ { className: "bt-mw-member" }, ++ (0, import_react15.createElement)("div", { className: "bt-mw-state bt-mw-ask" }, `${t("Waiting for your approval")}${since(now, entry.approvals[0].at)}`), ++ entry.approvals.map((approval) => (0, import_react15.createElement)(ApprovalCard, { key: approval.id, approval, bot, actions })) ++ ); + } - const pending = done || !live.speaking ? [] : [live.speaking]; - const speakerTool = useWork?.((work) => work.bots?.[live.speaking]?.tool) ?? void 0; - if (replies.length === 0 && pending.length === 0) return null; - const room2 = roster.roomsById[sessionId]; - return (0, import_react6.createElement)( -- "div", ++ if (entry.state !== "work") return null; ++ const stop = () => { ++ setStopping(true); ++ void Promise.resolve(actions.stopMemberWork(room2.id, bot.id)).catch((error) => actions.reportError(error, "stop")).finally(() => setStopping(false)); ++ }; ++ return (0, import_react15.createElement)( + "div", - { className: "bt-group-replies" }, - replies.map((reply, index) => { - const bot = roster.byId[reply.botId] ?? { id: reply.botId, name: reply.name, color: reply.color ?? "gray" }; @@ -10966,40 +11140,13 @@ diff --git a/client.js b/client.js - (0, import_react6.createElement)(Shimmer, null, speakerTool ? `${bot.name} · ${workPhrase(speakerTool)}…` : t("{name} is typing…", { name: bot.name })) - ); - }) -+function botGroupWork(botId, work, roster) { -+ return Object.entries(work.rooms ?? {}).flatMap(([roomId, entries2]) => { -+ const entry = entries2.find((item) => item.botId === botId); -+ const room2 = roster.roomsById[roomId]; -+ return entry && room2 ? [{ room: room2, tool: entry.tool, step: stepIn(work, botId, roomId, entry.tool), since: entry.since }] : []; -+ }); -+} -+var moreRooms = (count) => count === 1 ? t("1 more room") : t("{count} more rooms", { count }); -+function summaryText(busy) { -+ const asks = busy.filter((entry) => entry.state === "ask"); -+ const workers = busy.filter((entry) => entry.state === "work"); -+ const names = asks.slice(0, 2).map((entry) => entry.bot.name); -+ const waiting = asks.length === 0 ? "" : asks.length === 1 ? t("{name} is waiting for your approval", { name: names[0] }) : asks.length === 2 ? t("{first} and {second} are waiting for your approval", { first: names[0], second: names[1] }) : t("{first}, {second} and {count} more are waiting for your approval", { first: names[0], second: names[1], count: asks.length - 2, total: asks.length }); -+ const first = workers[0]; -+ const doing = first ? `${first.bot.name} · ${workText(first.doing.tool, first.doing.step)}${workers.length > 1 ? ` +${workers.length - 1}` : ""}` : ""; -+ return { waiting, doing }; -+} -+function Face({ entry, size }) { -+ return (0, import_react15.createElement)( -+ "span", -+ { className: "bt-mw-face", "data-ask": entry.state === "ask" || void 0 }, -+ (0, import_react15.createElement)(BotMark, { bot: entry.bot, size, state: entry.state === "ask" ? "alert" : toolState(entry.doing?.tool ?? "") }) -+ ); -+} -+var elapsedSince = (now, at) => typeof at === "number" && now - at >= 6e4 ? elapsedLabel(now - at) : ""; -+function WorkRow({ bot, tool, step, label, at, now, onOpen }) { -+ const text2 = `${label} · ${workText(tool, step)}`; -+ const elapsed = elapsedSince(now, at); -+ return (0, import_react15.createElement)( -+ "button", -+ { type: "button", className: "bt-mw-row", "aria-label": [text2, elapsed].filter(Boolean).join(" · "), onClick: onOpen }, -+ (0, import_react15.createElement)(BotMark, { bot, size: 22, state: toolState(tool ?? ""), live: true }), -+ (0, import_react15.createElement)("span", { className: "bt-mw-row-text" }, (0, import_react15.createElement)(Shimmer, null, text2)), -+ elapsed ? (0, import_react15.createElement)("span", { className: "bt-mw-row-time" }, `· ${elapsed}`) : null ++ { className: "bt-mw-member" }, ++ (0, import_react15.createElement)( ++ "div", ++ { className: "bt-mw-state bt-mw-work" }, ++ (0, import_react15.createElement)("span", null, (0, import_react15.createElement)(Shimmer, null, workText(entry.doing.tool, entry.doing.step)), since(now, entry.doing.since)), ++ entry.here && entry.doing.handed !== true ? (0, import_react15.createElement)("button", { type: "button", className: "bt-mw-stop", disabled: stopping, onClick: stop }, t("Stop")) : null ++ ) ); } -var DRAWN = /* @__PURE__ */ new Set(["message_bot", "stop_bot", "create_bot", "update_bot", "group_relay", "create_group", "update_group", "delete_group", "post_to_group", "ask_user", "request_secret", "ask_user_question", "read_group_chat", "remember", "forget"]); @@ -11016,22 +11163,11 @@ diff --git a/client.js b/client.js - }; - visit(root); - return calls; -+function SummaryLine({ busy, now, onOpen }) { -+ const { waiting, doing } = summaryText(busy); -+ const elapsed = doing ? elapsedSince(now, busy.find((entry) => entry.state === "work")?.doing.since) : ""; -+ return (0, import_react15.createElement)( -+ "button", -+ { type: "button", className: "bt-mw-row bt-mw-line", "aria-label": [waiting, doing, elapsed].filter(Boolean).join(" · "), onClick: onOpen }, -+ (0, import_react15.createElement)("span", { className: "bt-mw-stack", "aria-hidden": true }, busy.slice(0, 4).map((entry) => (0, import_react15.createElement)(Face, { key: entry.id, entry, size: 16 }))), -+ (0, import_react15.createElement)( -+ "span", -+ { className: "bt-mw-row-text" }, -+ waiting ? (0, import_react15.createElement)("span", { className: "bt-mw-ask" }, waiting) : null, -+ waiting && doing ? " · " : null, -+ doing ? (0, import_react15.createElement)(Shimmer, null, doing) : null -+ ), -+ elapsed ? (0, import_react15.createElement)("span", { className: "bt-mw-row-time" }, `· ${elapsed}`) : null -+ ); ++function useMemberWork(room2, useWork) { ++ const work = useWork?.((value) => value) ?? NO_WORK; ++ const entries2 = room2 ? memberWork(room2, work) : []; ++ const now = useNow(entries2.some((entry) => entry.state !== "idle")); ++ return { entries: entries2, now }; } -function useShownCards(actions, sessionId, callIds) { - const key = JSON.stringify(callIds); @@ -11041,50 +11177,96 @@ diff --git a/client.js b/client.js - actions.noteCards(sessionId, ids, 1); - return () => actions.noteCards(sessionId, ids, -1); - }, [sessionId, key]); -+function MemberDock({ sessionId, useRoster, useWork, actions }) { -+ const roster = useRoster((value) => value); -+ const work = useWork((value) => value); -+ const room2 = roster.roomsById[sessionId]; -+ const bot = room2 ? void 0 : roster.byId[sessionId]; -+ const ownChat = bot !== void 0 && work.bots?.[bot.id] !== void 0 && work.bots[bot.id].roomId === void 0; -+ const busy = room2 ? busyMembers(room2, work, roster) : []; -+ const groups = bot !== void 0 && !ownChat ? botGroupWork(bot.id, work, roster) : []; -+ const shown = busy.length > 0 || groups.length > 0; -+ const now = useNow(shown); -+ const ref = (0, import_react15.useRef)(null); -+ useFlowColumn(ref, shown, sessionId); -+ if (!shown) return null; -+ if (room2) { -+ const { rows: rows2, rest } = splitBusy(busy); -+ const open = () => actions.showDetails(sessionId); -+ return (0, import_react15.createElement)( -+ "div", -+ { ref, className: "bt-mw-dock-stack" }, -+ rows2.map((entry) => (0, import_react15.createElement)(WorkRow, { key: entry.id, bot: entry.bot, tool: entry.doing.tool, step: entry.doing.step, label: entry.bot.name, at: entry.doing.since, now, onOpen: open })), -+ rest.length > 0 ? (0, import_react15.createElement)(SummaryLine, { busy: rest, now, onOpen: open }) : null -+ ); -+ } -+ const rows = groups.slice(0, ROWS_MAX); -+ const more = groups.length - rows.length; -+ return (0, import_react15.createElement)( -+ "div", -+ { ref, className: "bt-mw-dock-stack" }, -+ rows.map((item) => (0, import_react15.createElement)(WorkRow, { -+ key: item.room.id, -+ bot, -+ tool: item.tool, -+ step: item.step, -+ label: t("in {name}", { name: item.room.name }), -+ at: item.since, -+ now, -+ onOpen: () => actions.openSession(item.room.id) -+ })), -+ more > 0 ? (0, import_react15.createElement)( -+ "div", -+ { className: "bt-mw-row bt-mw-line bt-mw-static" }, -+ (0, import_react15.createElement)("span", { className: "bt-mw-row-text" }, moreRooms(more)) -+ ) : null -+ ); ++var MEMBER_CSS = ` ++.bt-mw-dock-stack{box-sizing:border-box;display:flex;flex-direction:column;align-items:flex-start;gap:2px;width:var(--dsh-chat-content-width,min(960px,100%));margin:0 auto 6px;pointer-events:none} ++.bt-mw-row{pointer-events:auto;display:flex;align-items:center;gap:10px;min-width:0;max-width:calc(100% + 6px);height:32px;margin-inline-start:-6px;padding:0 12px 0 6px;border:0;border-radius:16px;background:none;color:var(--bt-ink-2);font:inherit;font-size:14px;cursor:pointer;animation:bt-mw-in .32s cubic-bezier(.23,1,.32,1) backwards;transition:background-color .16s ease-out} ++.bt-mw-row:hover{background:var(--bt-hover)} ++.bt-mw-static{cursor:default;padding-inline-start:38px} ++.bt-mw-static:hover{background:none} ++.bt-mw-row>.bt-mark{flex:none} ++.bt-mw-row-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} ++.bt-mw-row-time{flex:none;font-size:12px;color:var(--bt-ink-3);white-space:nowrap} ++.bt-mw-work{display:flex;align-items:center;justify-content:space-between;gap:8px} ++.bt-mw-stop{flex:none;height:22px;padding:0 10px;border:1px solid var(--bt-line,rgba(0,0,0,.12));border-radius:11px;background:none;color:var(--bt-ink-2);font:inherit;font-size:12px;cursor:pointer} ++.bt-mw-stop:hover{background:var(--bt-hover)} ++.bt-mw-stop:disabled{opacity:.5;cursor:default} ++.bt-mw-line{gap:8px} ++.bt-mw-stack{display:inline-flex;align-items:center;flex:none;line-height:0} ++.bt-mw-stack>*+*{margin-left:-4px} ++.bt-mw-face{position:relative;display:inline-flex;flex:none;border-radius:50%} ++.bt-mw-stack .bt-mw-face{box-shadow:0 0 0 1.5px var(--bt-main,#fff)} ++.bt-mw-face[data-ask]::after{content:"";position:absolute;right:-2px;bottom:-2px;width:7px;height:7px;border-radius:50%;background:#e3a008;box-shadow:0 0 0 1.5px var(--bt-main,#fff)} ++.bt-mw-ask{color:#b7791f;flex:none;white-space:nowrap} ++body[data-ds-dark-theme] .bt-mw-ask{color:#f0b84a} ++.bt-mw-member{padding:0 6px 8px 42px;display:flex;flex-direction:column;gap:6px} ++.bt-mw-state{font-size:12px;line-height:16px;color:var(--bt-ink-2);margin-top:-4px} ++.bt-mw-card{display:flex;flex-direction:column;gap:4px;padding:10px 12px;border-radius:12px;background:var(--bt-hover);font-size:12px;line-height:17px;color:var(--bt-ink-2)} ++.bt-mw-tool{font-weight:600;color:var(--bt-ink)} ++.bt-mw-text{color:var(--bt-ink);overflow-wrap:anywhere} ++.bt-mw-reason{overflow-wrap:anywhere;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden} ++.bt-mw-code{display:block;font:11px/16px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;color:var(--bt-ink);white-space:pre-wrap;overflow-wrap:anywhere;max-height:120px;overflow:auto} ++.bt-mw-actions{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:6px;margin-top:4px} ++.bt-mw-actions>button{height:28px;padding:0 12px;font-size:12px} ++.bt-mw-actions>button:disabled{opacity:.5;cursor:default} ++@keyframes bt-mw-in{from{opacity:0;transform:translateY(4px)}} ++@media (prefers-reduced-motion:reduce){.bt-mw-row{animation:none}} ++`; ++ ++// src/shared/identity.js ++var nameKey = (value) => stripInvisible(String(value ?? "").normalize("NFC")).trim().toLowerCase().normalize("NFC"); ++var drawnKey = (value) => nameKey(value).replace(NOT_DRAWN, ""); ++ ++// src/shared/task-board.js ++var COLUMNS = ["not-started", "in-progress", "done"]; ++var PRIORITIES = ["urgent", "high", "normal", "low"]; ++var COLUMN_OF = { ++ open: "not-started", ++ claimed: "not-started", ++ working: "in-progress", ++ blocked: "in-progress", ++ "result-ready": "in-progress", ++ accepted: "done", ++ cancelled: "done", ++ failed: "done" ++}; ++function columnOf(task) { ++ return COLUMN_OF[task?.status] ?? "not-started"; ++} ++function occupiesSlot(task) { ++ return task?.status === "claimed" || task?.status === "working"; ++} ++function priorityOf(task) { ++ return PRIORITIES.includes(task?.priority) ? task.priority : "normal"; ++} ++var PRIORITY_RANK = { urgent: 0, high: 1, normal: 2, low: 3 }; ++function workBucket(task) { ++ if (task?.status === "open" || task?.status === "claimed" || task?.status === "working") return 0; ++ if (task?.status === "blocked" || task?.status === "result-ready") return 1; ++ return 2; ++} ++function compareForWork(a, b) { ++ const byBucket = workBucket(a) - workBucket(b); ++ if (byBucket !== 0) return byBucket; ++ const byPriority = (PRIORITY_RANK[priorityOf(a)] ?? 2) - (PRIORITY_RANK[priorityOf(b)] ?? 2); ++ if (byPriority !== 0) return byPriority; ++ const byWorking = (a?.status === "working" ? 0 : 1) - (b?.status === "working" ? 0 : 1); ++ if (byWorking !== 0) return byWorking; ++ return (b?.updatedAt ?? 0) - (a?.updatedAt ?? 0); ++} ++function sameRole(a, b) { ++ const left = nameKey(a); ++ const right = nameKey(b); ++ return left !== "" && left === right; ++} ++function compareForQueue(a, b) { ++ const byPriority = (PRIORITY_RANK[priorityOf(a)] ?? 2) - (PRIORITY_RANK[priorityOf(b)] ?? 2); ++ if (byPriority !== 0) return byPriority; ++ return (a?.createdAt ?? 0) - (b?.createdAt ?? 0); ++} ++function progressOf(task) { ++ const value = task?.progress; ++ if (typeof value !== "number" || !Number.isFinite(value)) return columnOf(task) === "done" && task?.status !== "cancelled" && task?.status !== "failed" ? 100 : 0; ++ return Math.max(0, Math.min(100, Math.round(value))); } -function renderCall(call2, { sessionId, roster, actions, useUi, useWork, findBot }) { - const tool = toolName(call2); @@ -11145,7 +11327,21 @@ diff --git a/client.js b/client.js - parsed = JSON.parse(contentText(call2.content)); - } catch { - parsed = null; -- } ++ ++// src/client/read-only.js ++var readOnlySaid = (roster) => typeof roster?.readOnly === "string" && roster.readOnly.trim() !== ""; ++function readOnlyLine(h52, roster, actions, { key, className, style, reload = true } = {}) { ++ if (!readOnlySaid(roster)) return null; ++ return h52( ++ "div", ++ { key, className: ["bt-readonly-line", className].filter(Boolean).join(" "), style }, ++ h52("div", { className: "bt-hint bt-read-only", role: "status" }, hostText(roster.readOnly)), ++ reload ? h52("button", { ++ type: "button", ++ className: "bt-read-only-reload", ++ onClick: () => { ++ void Promise.resolve(actions?.reloadTeam?.()).catch((error) => actions?.reportError?.(error, "reload")); + } - const answer = parsed?.answers?.[0]; - const question = argValue("questions")?.[0]; - if (!answer) return null; @@ -11161,87 +11357,8 @@ diff --git a/client.js b/client.js - return done && !call2.isError ? (0, import_react6.createElement)(MemoryEvent, { sessionId, scope: arg("scope"), result: contentText(call2.content), roster, actions, findBot }) : null; - default: - return null; -+function useFlowColumn(ref, active, key) { -+ (0, import_react15.useLayoutEffect)(() => { -+ const node = ref.current; -+ const flow = document.querySelector("[data-chat-flow]"); -+ if (!active || !node || !flow) return void 0; -+ const place = () => { -+ node.style.marginInlineStart = "0px"; -+ const column = flow.getBoundingClientRect(); -+ node.style.marginInlineStart = `${Math.round(column.left - node.getBoundingClientRect().left)}px`; -+ node.style.width = `${Math.round(column.width)}px`; -+ }; -+ place(); -+ const observer = new ResizeObserver(place); -+ for (const target of [flow, flow.parentElement, node.parentElement]) if (target) observer.observe(target); -+ return () => observer.disconnect(); -+ }, [active, key]); -+} -+function useNow(active) { -+ const [now, setNow] = (0, import_react15.useState)(Date.now); -+ (0, import_react15.useEffect)(() => { -+ if (!active) return void 0; -+ const timer = setInterval(() => setNow(Date.now()), 3e4); -+ return () => clearInterval(timer); -+ }, [active]); -+ return now; -+} -+var since = (now, at) => typeof at === "number" && now - at >= 6e4 ? ` · ${elapsedLabel(now - at)}` : ""; -+var alwaysChoices = (approval, bot) => bot?.remote ? [] : [ -+ ["always-bot", "Always allow for this Bot"], -+ ...approval.roomId ? [["always-room", "Always allow for this group"]] : [] -+]; -+function ApprovalCard({ approval, bot, actions }) { -+ const [busy, setBusy] = (0, import_react15.useState)(false); -+ const answer = (choice) => { -+ setBusy(true); -+ void Promise.resolve(actions.answerApproval(approval.id, choice)).catch((error) => actions.reportError(error, "approval")).finally(() => setBusy(false)); -+ }; -+ return (0, import_react15.createElement)( -+ "div", -+ { className: "bt-mw-card", role: "group", "aria-label": t("{name} is waiting for your approval", { name: bot.name }) }, -+ (0, import_react15.createElement)("div", { className: "bt-mw-tool" }, approval.tool), -+ approval.detail?.text ? (0, import_react15.createElement)("div", { className: "bt-mw-text" }, approval.detail.text) : null, -+ approval.reason ? (0, import_react15.createElement)("div", { className: "bt-mw-reason" }, approval.reason) : null, -+ approval.detail?.code ? (0, import_react15.createElement)("code", { className: "bt-mw-code", title: approval.detail.code }, approval.detail.code) : null, -+ approval.answerable ? (0, import_react15.createElement)( -+ "div", -+ { className: "bt-mw-actions" }, -+ (0, import_react15.createElement)("button", { type: "button", className: "bt-q-btn", disabled: busy, onClick: () => answer("reject") }, t("Reject")), -+ (0, import_react15.createElement)("button", { type: "button", className: "bt-q-submit", disabled: busy, onClick: () => answer("allow") }, t("Allow once")), -+ ...alwaysChoices(approval, bot).map(([choice, label]) => (0, import_react15.createElement)("button", { key: choice, type: "button", className: "bt-q-btn", "data-choice": choice, disabled: busy, onClick: () => answer(choice) }, t(label))) -+ ) : (0, import_react15.createElement)( -+ "div", -+ { className: "bt-mw-actions" }, -+ (0, import_react15.createElement)("button", { type: "button", className: "bt-q-btn", onClick: () => actions.openSession(bot.id) }, t("Open {name}'s chat", { name: bot.name })) -+ ) -+ ); -+} -+function MemberWork({ entry, bot, room: room2, actions, now }) { -+ const [stopping, setStopping] = (0, import_react15.useState)(false); -+ if (entry.state === "ask") { -+ return (0, import_react15.createElement)( -+ "div", -+ { className: "bt-mw-member" }, -+ (0, import_react15.createElement)("div", { className: "bt-mw-state bt-mw-ask" }, `${t("Waiting for your approval")}${since(now, entry.approvals[0].at)}`), -+ entry.approvals.map((approval) => (0, import_react15.createElement)(ApprovalCard, { key: approval.id, approval, bot, actions })) -+ ); - } -+ if (entry.state !== "work") return null; -+ const stop = () => { -+ setStopping(true); -+ void Promise.resolve(actions.stopMemberWork(room2.id, bot.id)).catch((error) => actions.reportError(error, "stop")).finally(() => setStopping(false)); -+ }; -+ return (0, import_react15.createElement)( -+ "div", -+ { className: "bt-mw-member" }, -+ (0, import_react15.createElement)( -+ "div", -+ { className: "bt-mw-state bt-mw-work" }, -+ (0, import_react15.createElement)("span", null, (0, import_react15.createElement)(Shimmer, null, workText(entry.doing.tool, entry.doing.step)), since(now, entry.doing.since)), -+ entry.here && entry.doing.handed !== true ? (0, import_react15.createElement)("button", { type: "button", className: "bt-mw-stop", disabled: stopping, onClick: stop }, t("Stop")) : null -+ ) +- } ++ }, t("Reload")) : null + ); } -function ToolCell({ node, sessionId, useRoster, useUi, useWork, actions }) { @@ -11259,46 +11376,10 @@ diff --git a/client.js b/client.js - if (drawn.length === 0) return null; - const env = { sessionId, roster, actions, useUi, useWork, findBot }; - return (0, import_react6.createElement)(import_react6.Fragment, null, drawn.map((call2, index) => (0, import_react6.createElement)(import_react6.Fragment, { key: call2.callId ?? index }, renderCall(call2, env)))); -+function useMemberWork(room2, useWork) { -+ const work = useWork?.((value) => value) ?? NO_WORK; -+ const entries2 = room2 ? memberWork(room2, work) : []; -+ const now = useNow(entries2.some((entry) => entry.state !== "idle")); -+ return { entries: entries2, now }; ++function reloadReceipt(before, after) { ++ if (!readOnlySaid(before)) return null; ++ return readOnlySaid(after) ? t("Reloaded just now — this window is still read-only.") : t("Reloaded — this window can write again."); } -+var MEMBER_CSS = ` -+.bt-mw-dock-stack{box-sizing:border-box;display:flex;flex-direction:column;align-items:flex-start;gap:2px;width:var(--dsh-chat-content-width,min(960px,100%));margin:0 auto 6px;pointer-events:none} -+.bt-mw-row{pointer-events:auto;display:flex;align-items:center;gap:10px;min-width:0;max-width:calc(100% + 6px);height:32px;margin-inline-start:-6px;padding:0 12px 0 6px;border:0;border-radius:16px;background:none;color:var(--bt-ink-2);font:inherit;font-size:14px;cursor:pointer;animation:bt-mw-in .32s cubic-bezier(.23,1,.32,1) backwards;transition:background-color .16s ease-out} -+.bt-mw-row:hover{background:var(--bt-hover)} -+.bt-mw-static{cursor:default;padding-inline-start:38px} -+.bt-mw-static:hover{background:none} -+.bt-mw-row>.bt-mark{flex:none} -+.bt-mw-row-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} -+.bt-mw-row-time{flex:none;font-size:12px;color:var(--bt-ink-3);white-space:nowrap} -+.bt-mw-work{display:flex;align-items:center;justify-content:space-between;gap:8px} -+.bt-mw-stop{flex:none;height:22px;padding:0 10px;border:1px solid var(--bt-line,rgba(0,0,0,.12));border-radius:11px;background:none;color:var(--bt-ink-2);font:inherit;font-size:12px;cursor:pointer} -+.bt-mw-stop:hover{background:var(--bt-hover)} -+.bt-mw-stop:disabled{opacity:.5;cursor:default} -+.bt-mw-line{gap:8px} -+.bt-mw-stack{display:inline-flex;align-items:center;flex:none;line-height:0} -+.bt-mw-stack>*+*{margin-left:-4px} -+.bt-mw-face{position:relative;display:inline-flex;flex:none;border-radius:50%} -+.bt-mw-stack .bt-mw-face{box-shadow:0 0 0 1.5px var(--bt-main,#fff)} -+.bt-mw-face[data-ask]::after{content:"";position:absolute;right:-2px;bottom:-2px;width:7px;height:7px;border-radius:50%;background:#e3a008;box-shadow:0 0 0 1.5px var(--bt-main,#fff)} -+.bt-mw-ask{color:#b7791f;flex:none;white-space:nowrap} -+body[data-ds-dark-theme] .bt-mw-ask{color:#f0b84a} -+.bt-mw-member{padding:0 6px 8px 42px;display:flex;flex-direction:column;gap:6px} -+.bt-mw-state{font-size:12px;line-height:16px;color:var(--bt-ink-2);margin-top:-4px} -+.bt-mw-card{display:flex;flex-direction:column;gap:4px;padding:10px 12px;border-radius:12px;background:var(--bt-hover);font-size:12px;line-height:17px;color:var(--bt-ink-2)} -+.bt-mw-tool{font-weight:600;color:var(--bt-ink)} -+.bt-mw-text{color:var(--bt-ink);overflow-wrap:anywhere} -+.bt-mw-reason{overflow-wrap:anywhere;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden} -+.bt-mw-code{display:block;font:11px/16px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;color:var(--bt-ink);white-space:pre-wrap;overflow-wrap:anywhere;max-height:120px;overflow:auto} -+.bt-mw-actions{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:6px;margin-top:4px} -+.bt-mw-actions>button{height:28px;padding:0 12px;font-size:12px} -+.bt-mw-actions>button:disabled{opacity:.5;cursor:default} -+@keyframes bt-mw-in{from{opacity:0;transform:translateY(4px)}} -+@media (prefers-reduced-motion:reduce){.bt-mw-row{animation:none}} -+`; -// src/client/activity-row.js -var import_react7 = require("react"); @@ -11335,62 +11416,7 @@ diff --git a/client.js b/client.js - }; - }, [active]); - return host; -+// src/shared/identity.js -+var nameKey = (value) => stripInvisible(String(value ?? "").normalize("NFC")).trim().toLowerCase().normalize("NFC"); -+var drawnKey = (value) => nameKey(value).replace(NOT_DRAWN, ""); -+ -+// src/shared/task-board.js -+var COLUMNS = ["not-started", "in-progress", "done"]; -+var PRIORITIES = ["urgent", "high", "normal", "low"]; -+var COLUMN_OF = { -+ open: "not-started", -+ claimed: "not-started", -+ working: "in-progress", -+ blocked: "in-progress", -+ "result-ready": "in-progress", -+ accepted: "done", -+ cancelled: "done", -+ failed: "done" -+}; -+function columnOf(task) { -+ return COLUMN_OF[task?.status] ?? "not-started"; -+} -+function occupiesSlot(task) { -+ return task?.status === "claimed" || task?.status === "working"; -+} -+function priorityOf(task) { -+ return PRIORITIES.includes(task?.priority) ? task.priority : "normal"; -+} -+var PRIORITY_RANK = { urgent: 0, high: 1, normal: 2, low: 3 }; -+function workBucket(task) { -+ if (task?.status === "open" || task?.status === "claimed" || task?.status === "working") return 0; -+ if (task?.status === "blocked" || task?.status === "result-ready") return 1; -+ return 2; -+} -+function compareForWork(a, b) { -+ const byBucket = workBucket(a) - workBucket(b); -+ if (byBucket !== 0) return byBucket; -+ const byPriority = (PRIORITY_RANK[priorityOf(a)] ?? 2) - (PRIORITY_RANK[priorityOf(b)] ?? 2); -+ if (byPriority !== 0) return byPriority; -+ const byWorking = (a?.status === "working" ? 0 : 1) - (b?.status === "working" ? 0 : 1); -+ if (byWorking !== 0) return byWorking; -+ return (b?.updatedAt ?? 0) - (a?.updatedAt ?? 0); -+} -+function sameRole(a, b) { -+ const left = nameKey(a); -+ const right = nameKey(b); -+ return left !== "" && left === right; -+} -+function compareForQueue(a, b) { -+ const byPriority = (PRIORITY_RANK[priorityOf(a)] ?? 2) - (PRIORITY_RANK[priorityOf(b)] ?? 2); -+ if (byPriority !== 0) return byPriority; -+ return (a?.createdAt ?? 0) - (b?.createdAt ?? 0); -+} -+function progressOf(task) { -+ const value = task?.progress; -+ if (typeof value !== "number" || !Number.isFinite(value)) return columnOf(task) === "done" && task?.status !== "cancelled" && task?.status !== "failed" ? 100 : 0; -+ return Math.max(0, Math.min(100, Math.round(value))); - } +-} -function useRowEntrances(replacing) { - const check = (0, import_react7.useRef)(replacing); - check.current = replacing; @@ -11403,42 +11429,6 @@ diff --git a/client.js b/client.js - if (event.target !== event.currentTarget || !/^bt-row/.test(event.animationName)) return; - delete event.currentTarget.dataset.btEnter; - event.currentTarget.removeEventListener("animationend", settle); -- }; -- const scan = () => { -- frame = 0; -- const next = document.querySelector("[data-chat-flow]"); -- if (next !== column) { -- observer.disconnect(); -- column = next; -- if (column) observer.observe(column, { childList: true, subtree: true }); -+ -+// src/client/read-only.js -+var readOnlySaid = (roster) => typeof roster?.readOnly === "string" && roster.readOnly.trim() !== ""; -+function readOnlyLine(h52, roster, actions, { key, className, style, reload = true } = {}) { -+ if (!readOnlySaid(roster)) return null; -+ return h52( -+ "div", -+ { key, className: ["bt-readonly-line", className].filter(Boolean).join(" "), style }, -+ h52("div", { className: "bt-hint bt-read-only", role: "status" }, hostText(roster.readOnly)), -+ reload ? h52("button", { -+ type: "button", -+ className: "bt-read-only-reload", -+ onClick: () => { -+ void Promise.resolve(actions?.reloadTeam?.()).catch((error) => actions?.reportError?.(error, "reload")); - } -- if (!column) return; -- const items = [...column.querySelectorAll(":scope > [data-chat-flow-key]")]; -- let last = -1; -- items.forEach((item, index) => { -- if (seen.has(item)) last = index; -+ }, t("Reload")) : null -+ ); -+} -+function reloadReceipt(before, after) { -+ if (!readOnlySaid(before)) return null; -+ return readOnlySaid(after) ? t("Reloaded just now — this window is still read-only.") : t("Reloaded — this window can write again."); -+} -+ +// src/client/inbox.js +var import_react16 = require("react"); +var KEEP_MS = 7 * 864e5; @@ -11498,7 +11488,20 @@ diff --git a/client.js b/client.js + stopped = true; + clearTimeout(timer); + taskListeners.delete(setTasks); -+ }; + }; +- const scan = () => { +- frame = 0; +- const next = document.querySelector("[data-chat-flow]"); +- if (next !== column) { +- observer.disconnect(); +- column = next; +- if (column) observer.observe(column, { childList: true, subtree: true }); +- } +- if (!column) return; +- const items = [...column.querySelectorAll(":scope > [data-chat-flow-key]")]; +- let last = -1; +- items.forEach((item, index) => { +- if (seen.has(item)) last = index; + }, []); + return tasks; +} @@ -12376,6 +12379,15 @@ diff --git a/client.js b/client.js + (0, import_react18.createElement)("rect", { x: 8, y: 3, width: 4, height: 9, rx: 1 }), + (0, import_react18.createElement)("rect", { x: 13.5, y: 3, width: 4, height: 12, rx: 1 }) + ); ++} ++function shortId(id) { ++ const hex = String(id ?? "").replace(/^task-/, ""); ++ return `#${hex.slice(-6)}`; ++} ++var ARCHIVE_SHOWN = 20; ++function boardTasksFor(tasks, archive, limit = ARCHIVE_SHOWN) { ++ const newest = [...archive ?? []].sort((a, b) => (b.updatedAt ?? 0) - (a.updatedAt ?? 0) || (b.createdAt ?? 0) - (a.createdAt ?? 0)); ++ return [...tasks ?? [], ...newest.slice(0, limit)]; } -var PinMark = () => (0, import_react8.createElement)("span", { className: "bt-pin", "aria-hidden": true }, (0, import_react8.createElement)(PinMarkIcon)); -var useApproval = (useWork, match) => useWork ? useWork((work) => (work.approvals ?? []).some(match)) : false; @@ -12406,15 +12418,6 @@ diff --git a/client.js b/client.js - const onContextMenu = (event) => { - event.preventDefault(); - actions.openMenu({ kind: "bot", id, x: event.clientX, y: event.clientY }); -+function shortId(id) { -+ const hex = String(id ?? "").replace(/^task-/, ""); -+ return `#${hex.slice(-6)}`; -+} -+var ARCHIVE_SHOWN = 20; -+function boardTasksFor(tasks, archive, limit = ARCHIVE_SHOWN) { -+ const newest = [...archive ?? []].sort((a, b) => (b.updatedAt ?? 0) - (a.updatedAt ?? 0) || (b.createdAt ?? 0) - (a.createdAt ?? 0)); -+ return [...tasks ?? [], ...newest.slice(0, limit)]; -+} +function boardColumns(tasks) { + const columns = { "not-started": [], "in-progress": [], done: [] }; + for (const task of tasks ?? []) { @@ -12941,33 +12944,6 @@ diff --git a/client.js b/client.js - const label = ["DSH Agent", running ? t("Working") : "", unread ? t("Unread activity") : ""].filter(Boolean).join(", "); - const open = active && wide; - return (0, import_react8.createElement)( -- "div", -- { className: "bt-agent" }, -- (0, import_react8.createElement)( -- "button", -- { -- type: "button", -- className: "bt-row", -- "aria-label": label, -- "aria-current": active ? "page" : void 0, -- "data-agent-id": agent.id, -- title: wide ? void 0 : "DSH Agent", -- onClick: () => actions.openAgent(agent.id), -- onContextMenu: (event) => { -- event.preventDefault(); -- actions.openMenu({ kind: "agent", id: agent.id, x: event.clientX, y: event.clientY }); -- } -- }, -- (0, import_react8.createElement)("span", { className: `bt-agent-ava${running ? " bt-run" : ""}` }, (0, import_react8.createElement)(import_dsh_client_ui_primitives2.FishLogo, { size: 22 })), -- wide ? (0, import_react8.createElement)( -- "span", -- { className: "bt-row-body" }, -- (0, import_react8.createElement)("span", { className: "bt-row-name" }, "DSH Agent"), -- preview ? (0, import_react8.createElement)("span", { className: "bt-row-preview" }, preview) : null -- ) : null, -- wide && unread && !active ? (0, import_react8.createElement)("span", { className: "bt-unread", "aria-hidden": true }) : null -- ), -- (0, import_react8.createElement)( +function scopeName(roster, scope) { + if (scope?.kind === "group") return roster.roomsById?.[scope.roomId]?.name || t("Group"); + if (scope?.kind === "bot") return roster.byId?.[scope.botId]?.name || ""; @@ -13027,13 +13003,40 @@ diff --git a/client.js b/client.js + }; + const name = scopeName(roster, scope); + return (0, import_react18.createElement)( -+ "div", + "div", +- { className: "bt-agent" }, +- (0, import_react8.createElement)( +- "button", +- { +- type: "button", +- className: "bt-row", +- "aria-label": label, +- "aria-current": active ? "page" : void 0, +- "data-agent-id": agent.id, +- title: wide ? void 0 : "DSH Agent", +- onClick: () => actions.openAgent(agent.id), +- onContextMenu: (event) => { +- event.preventDefault(); +- actions.openMenu({ kind: "agent", id: agent.id, x: event.clientX, y: event.clientY }); +- } +- }, +- (0, import_react8.createElement)("span", { className: `bt-agent-ava${running ? " bt-run" : ""}` }, (0, import_react8.createElement)(import_dsh_client_ui_primitives2.FishLogo, { size: 22 })), +- wide ? (0, import_react8.createElement)( +- "span", +- { className: "bt-row-body" }, +- (0, import_react8.createElement)("span", { className: "bt-row-name" }, "DSH Agent"), +- preview ? (0, import_react8.createElement)("span", { className: "bt-row-preview" }, preview) : null +- ) : null, +- wide && unread && !active ? (0, import_react8.createElement)("span", { className: "bt-unread", "aria-hidden": true }) : null +- ), +- (0, import_react8.createElement)( +- "div", +- { className: "bt-agent-sub", "data-open": open || void 0 }, +- (0, import_react8.createElement)( + { className: "bt-mem-layer bt-board-layer", "data-leaving": leaving || void 0 }, + (0, import_react18.createElement)("div", { className: "bt-scrim", onClick: close }), + (0, import_react18.createElement)( - "div", -- { className: "bt-agent-sub", "data-open": open || void 0 }, -- (0, import_react8.createElement)( ++ "div", + { className: "bt-mem bt-board", role: "dialog", "aria-modal": true, "aria-labelledby": "bt-board-heading" }, + (0, import_react18.createElement)( "div", @@ -14373,6 +14376,22 @@ diff --git a/client.js b/client.js - }, [Boolean(room2)]); - const memoryNotice = notice && changed !== null && roster.memory !== false; - return (0, import_react9.createElement)( +- "div", +- { className: "bt-head" }, +- (0, import_react9.createElement)( +- "button", +- { +- type: "button", +- className: "bt-pill", +- "aria-expanded": detailsOpen, +- "data-memory": memoryNotice ? "updated" : void 0, +- "aria-label": memoryNotice ? t("Memory updated. Open {name}'s memory", { name: roster.byId[changed]?.name ?? name }) : t("View conversation details"), +- onClick: () => memoryNotice ? actions.openMemory(changed) : actions.toggleDetails(sessionId) +- }, +- bot ? (0, import_react9.createElement)(BotAvatar, { bot, size: 24, state: botState(running, doing, roster.questions?.[currentPart(bot)] !== void 0), badge: false }) : room2 ? (0, import_react9.createElement)(RoomAvatar, { room: room2, roster, size: 24 }) : null, +- (0, import_react9.createElement)("span", { className: "bt-pill-name" }, bot?.name ?? room2?.name ?? (title || t("New chat"))), +- (0, import_react9.createElement)(MemoryNotice, { shown: memoryNotice }), +- (0, import_react9.createElement)("span", { className: "bt-pill-go", "aria-hidden": true }, (0, import_react9.createElement)(GoArrow)) + if (main) consider({ kind: "bot", item: main }); + for (const entry of order) consider(entry); + return ids; @@ -14392,22 +14411,7 @@ diff --git a/client.js b/client.js + actions.openPalette(event.key); + }; + return (0, import_react21.createElement)( - "div", -- { className: "bt-head" }, -- (0, import_react9.createElement)( -- "button", -- { -- type: "button", -- className: "bt-pill", -- "aria-expanded": detailsOpen, -- "data-memory": memoryNotice ? "updated" : void 0, -- "aria-label": memoryNotice ? t("Memory updated. Open {name}'s memory", { name: roster.byId[changed]?.name ?? name }) : t("View conversation details"), -- onClick: () => memoryNotice ? actions.openMemory(changed) : actions.toggleDetails(sessionId) -- }, -- bot ? (0, import_react9.createElement)(BotAvatar, { bot, size: 24, state: botState(running, doing, roster.questions?.[currentPart(bot)] !== void 0), badge: false }) : room2 ? (0, import_react9.createElement)(RoomAvatar, { room: room2, roster, size: 24 }) : null, -- (0, import_react9.createElement)("span", { className: "bt-pill-name" }, bot?.name ?? room2?.name ?? (title || t("New chat"))), -- (0, import_react9.createElement)(MemoryNotice, { shown: memoryNotice }), -- (0, import_react9.createElement)("span", { className: "bt-pill-go", "aria-hidden": true }, (0, import_react9.createElement)(GoArrow)) ++ "div", + { className: wide ? "bt-side" : "bt-side bt-rail", onKeyDown: typeToSearch }, + wide ? (0, import_react21.createElement)( + "div", @@ -14929,40 +14933,6 @@ diff --git a/client.js b/client.js - actions.clearQuote(quote.token); - const excerpt = quote.text.replace(/\s+/g, " ").trim(); - const line = `> ${excerpt.length > 200 ? `${excerpt.slice(0, 200)}…` : excerpt} -- --`; -- inputActions.insertText(line, inputActions.captureInsertion()); -- const box = document.querySelector('[class*="_centerCol"] [role=textbox][contenteditable=true]'); -- if (box instanceof HTMLElement) { -- box.focus(); -- const selection = window.getSelection(); -- selection?.selectAllChildren(box); -- selection?.collapseToEnd(); -- } -- }, [quote?.token]); -- if (sessionId === void 0) return null; -- const pluginMic = actions.speech() !== void 0; -- return (0, import_react10.createElement)( -- import_react10.Fragment, -- null, -- pluginMic ? null : (0, import_react10.createElement)("button", { -- type: "button", -- className: "bt-mic", -- "aria-label": dictation.listening ? t("Stop dictation") : t("Dictate"), -- "aria-pressed": dictation.listening, -- title: dictation.listening ? t("Stop dictation") : t("Dictate"), -- onMouseDown: keepComposerFocus, -- onClick: () => dictation.listening ? dictation.stop() : dictation.start() -- }, (0, import_react10.createElement)(MicIcon)), -- (0, import_react10.createElement)("button", { -- type: "button", -- className: "bt-voice", -- "aria-label": t("Start voice chat"), -- title: t("Voice chat"), -- onMouseDown: keepComposerFocus, -- onClick: () => actions.openVoice(sessionId) -- }, (0, import_react10.createElement)(WaveIcon, { size: 18 })), -- dictation.note ? (0, import_react10.createElement)("span", { className: "bt-mic-note", role: "status" }, dictation.note) : null +function FooterAccount(props) { + const seated = props.useUi((value) => value.accountSeated === true); + if (seated) return null; @@ -14976,16 +14946,8 @@ diff --git a/client.js b/client.js + { type: "button", className: "bt-return", "aria-label": t("FlyBot"), title: t("FlyBot"), onClick: () => actions.setSurface("bot") }, + (0, import_react21.createElement)(FlyBotMark, { size: 20 }), + wide ? (0, import_react21.createElement)("span", { className: "bt-return-name" }, t("FlyBot")) : null - ); - } --function menuIcons(roster) { -- const marks = /* @__PURE__ */ new Map(); -- return (row) => { -- if (!row.bot) return PeopleIcon; -- const id = row.bot.id; -- if (!marks.has(id)) marks.set(id, ({ size = 14 }) => (0, import_react10.createElement)(BotMark, { bot: roster.getSnapshot().byId[id] ?? row.bot, size })); -- return marks.get(id); -- }; ++ ); ++} +var RETURN_CSS = ` +.bt-return{display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:36px;padding:0 14px;border:0;border-radius:999px;background:none;color:inherit;font:inherit;font-size:14px;line-height:20px;cursor:pointer;transition:background-color .12s ease} +.bt-return:hover{background:rgba(127,127,127,.14)} @@ -15069,7 +15031,7 @@ diff --git a/client.js b/client.js +.bt-agent-sub[data-open] .bt-agent-sub-row{animation:bt-agent-row-in .24s ease both;animation-delay:calc(var(--i, 0)*30ms)} +@keyframes bt-agent-row-in{from{opacity:0;filter:blur(4px)}to{opacity:1;filter:blur(0)}} +@media (prefers-reduced-motion:reduce){.bt-agent-sub{transition:none}.bt-agent-sub .bt-agent-sub-row{animation:none}} -+ + +.bt-row-wrap{position:relative;display:flex;align-items:center;width:100%;min-width:0} +.bt-row-wrap>.bt-row{flex:1 1 auto;min-width:0;width:100%} +.bt-tree-item>.bt-row-wrap{flex:1 1 auto;width:auto;min-width:0} @@ -15079,7 +15041,40 @@ diff --git a/client.js b/client.js +.bt-row-wrap:hover .bt-row-settings,.bt-row-wrap:focus-within .bt-row-settings{opacity:1;pointer-events:auto;color:var(--bt-ink-2);background:var(--bt-hover)} +.bt-row-settings:hover{opacity:1;color:var(--bt-ink-2);background:var(--bt-hover)} +.bt-row-settings svg{width:15px;height:15px} -+`; + `; +- inputActions.insertText(line, inputActions.captureInsertion()); +- const box = document.querySelector('[class*="_centerCol"] [role=textbox][contenteditable=true]'); +- if (box instanceof HTMLElement) { +- box.focus(); +- const selection = window.getSelection(); +- selection?.selectAllChildren(box); +- selection?.collapseToEnd(); +- } +- }, [quote?.token]); +- if (sessionId === void 0) return null; +- const pluginMic = actions.speech() !== void 0; +- return (0, import_react10.createElement)( +- import_react10.Fragment, +- null, +- pluginMic ? null : (0, import_react10.createElement)("button", { +- type: "button", +- className: "bt-mic", +- "aria-label": dictation.listening ? t("Stop dictation") : t("Dictate"), +- "aria-pressed": dictation.listening, +- title: dictation.listening ? t("Stop dictation") : t("Dictate"), +- onMouseDown: keepComposerFocus, +- onClick: () => dictation.listening ? dictation.stop() : dictation.start() +- }, (0, import_react10.createElement)(MicIcon)), +- (0, import_react10.createElement)("button", { +- type: "button", +- className: "bt-voice", +- "aria-label": t("Start voice chat"), +- title: t("Voice chat"), +- onMouseDown: keepComposerFocus, +- onClick: () => actions.openVoice(sessionId) +- }, (0, import_react10.createElement)(WaveIcon, { size: 18 })), +- dictation.note ? (0, import_react10.createElement)("span", { className: "bt-mic-note", role: "status" }, dictation.note) : null +- ); + +// src/client/busy-ack-logic.js +function busyAckText(hostAck) { @@ -15088,6 +15083,18 @@ diff --git a/client.js b/client.js +function busyAckPending(hostAck) { + return busyAckText(hostAck) === ""; } +-function menuIcons(roster) { +- const marks = /* @__PURE__ */ new Map(); +- return (row) => { +- if (!row.bot) return PeopleIcon; +- const id = row.bot.id; +- if (!marks.has(id)) marks.set(id, ({ size = 14 }) => (0, import_react10.createElement)(BotMark, { bot: roster.getSnapshot().byId[id] ?? row.bot, size })); +- return marks.get(id); +- }; ++function pendingBusyPlacement(submissions) { ++ if (!Array.isArray(submissions)) return false; ++ return submissions.some((item) => item?.placement === "queued" || item?.placement === "steering"); + } -function ComposerPlus({ sessionId, inputActions, useRoster, actions }) { - const roster = useRoster((value) => value); - const [open, setOpen] = (0, import_react10.useState)(null); @@ -15104,10 +15111,6 @@ diff --git a/client.js b/client.js - event.stopPropagation(); - setOpen(null); - } -+function pendingBusyPlacement(submissions) { -+ if (!Array.isArray(submissions)) return false; -+ return submissions.some((item) => item?.placement === "queued" || item?.placement === "steering"); -+} +function busyAckVisible({ hostAck, pendingBusy, streamingText }) { + if (streamingText) return false; + return busyAckText(hostAck) !== "" || pendingBusy === true; @@ -16672,6 +16675,24 @@ diff --git a/client.js b/client.js + (0, import_react24.createElement)("span", { className: "bt-pill-mem-in", ref: inner }, (0, import_react24.createElement)("span", { className: "bt-pill-mem-ico" }, (0, import_react24.createElement)(MemoryIcon)), label) + ); +} ++function unreadEntryId(roster, sessionId) { ++ const bot = roster?.byId?.[sessionId]; ++ const room2 = roster?.roomsById?.[sessionId]; ++ return bot?.id ?? room2?.id ?? roster?.agentOf?.[sessionId] ?? sessionId; ++} ++function SessionUnreadToggle({ sessionId, roster, unread, actions }) { ++ const target = unreadEntryId(roster, sessionId); ++ const marked = unread?.[target] === true; ++ const label = marked ? t("Clear unread mark") : t("Mark as Unread"); ++ return (0, import_react24.createElement)("button", { ++ type: "button", ++ className: "bt-head-unread", ++ "aria-pressed": marked, ++ "aria-label": label, ++ title: label, ++ onClick: () => marked ? actions.clearUnread(target) : actions.markUnread(target) ++ }, (0, import_react24.createElement)(UnreadIcon)); ++} +function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSession, useActivity, useBusyAcks, useMemoryNews, useTurnClock, useUi, useLive, actions }) { + const roster = useRoster((value) => value); + const title = useSessions((list) => list.byId[sessionId]?.displayTitle ?? list.byId[sessionId]?.title ?? ""); @@ -16681,6 +16702,7 @@ diff --git a/client.js b/client.js + }); + const hiddenTurns = roster.exchangeTurns?.[sessionId]; + const visit = useUi((state) => state.visits?.[sessionId]); ++ const unread = useUi((state) => state.unread); + const opening = useTurnClock((state) => { + const first = openingTurn(state[sessionId], firstTurns, hiddenTurns); + return first && !unseenSince(visit, first.start) ? clockLabel(first.start) : ""; @@ -16731,7 +16753,8 @@ diff --git a/client.js b/client.js + }), + (0, import_react24.createElement)(NewMessagePills, { key: sessionId, sessionId, hiddenTurns, useSessions, useUi, useTurnClock, actions }), + (0, import_react24.createElement)(ActivityIndicator, { key: `activity:${sessionId}`, sessionId, useRoster, useSessionStatus, useSession, useLive, actions }), -+ (0, import_react24.createElement)(BusyAckBubble, { key: `busy-ack:${sessionId}`, sessionId, useRoster, useBusyAcks, useSessionStatus, useSession, useLive }) ++ (0, import_react24.createElement)(BusyAckBubble, { key: `busy-ack:${sessionId}`, sessionId, useRoster, useBusyAcks, useSessionStatus, useSession, useLive }), ++ (0, import_react24.createElement)(SessionUnreadToggle, { sessionId, roster, unread, actions }) + ); +} +function useTranscriptView() { @@ -18158,11 +18181,11 @@ diff --git a/client.js b/client.js - setListing(next); - setView("browse"); - }).catch((failure) => setProblem(failure?.message ?? String(failure))); - }; +- }; - const pickNative = () => { - close(); - void run(Promise.resolve(actions.folderPick()).then((path) => path ? onPick(path) : void 0)); -- }; + }; - const typed = () => { - const path = draft.trim(); - if (path !== "") choose(path); @@ -19548,11 +19571,11 @@ diff --git a/client.js b/client.js counts.set(botId, count); - for (const listener of countListeners) listener(); + notify(); - } ++} +function noteFailure(botId, reason) { + failures.set(botId, reason); + notify(); -+} + } +var countState = (botId) => ({ count: counts.get(botId) ?? null, failure: failures.get(botId) ?? null }); function useMemoryCount(botId, actions) { - const [count, setCount] = (0, import_react17.useState)(counts.get(botId) ?? null); @@ -22932,7 +22955,7 @@ diff --git a/client.js b/client.js + key: `${item.from.id}>${item.to.id}`, + back: true, + d: `M ${x1} ${y1} L ${x1} ${yA} L ${lane} ${yA} L ${lane} ${yB} L ${x2} ${yB} L ${x2} ${y2}` - }); ++ }); + taken.push({ x: lane, yA: Math.min(yA, yB), yB: Math.max(yA, yB) }); + }); + const centres = []; @@ -22958,7 +22981,7 @@ diff --git a/client.js b/client.js + key: `${item.from.id}>${item.to.id}`, + back: false, + d: straight ? `M ${x1} ${y1} L ${x1} ${y2}` : `M ${x1} ${y1} L ${x1} ${yA} L ${lane} ${yA} L ${lane} ${yB} L ${x2} ${yB} L ${x2} ${y2}` -+ }); + }); + } + return routes; +} @@ -24511,16 +24534,16 @@ diff --git a/client.js b/client.js { width: 20, height: 20, viewBox: "0 0 16 16", fill: "currentColor", "aria-hidden": true }, - (0, import_react25.createElement)("path", { d: "M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" }) + (0, import_react42.createElement)("path", { d: "M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" }) - ); --var MARKS = { github: GitHubMark }; --var ABOUT = { github: () => t("Repositories, issues, and pull requests") }; ++); +var FeishuMark = () => (0, import_react42.createElement)( + "svg", + { width: 20, height: 20, viewBox: "0 0 20 20", fill: "currentColor", "aria-hidden": true }, + (0, import_react42.createElement)("path", { d: "M3.2 6.6c3 .1 6.4 1.5 8.6 3.9-1.9.4-3.5 1.4-4.7 2.9-1.9-.6-3.4-1.9-3.9-3.6-.2-.7-.2-1.5 0-3.2z" }), + (0, import_react42.createElement)("path", { d: "M16.8 5.4c-2.9.2-5.6 1.5-7.4 3.4 1.7 1.2 3.1 2.8 3.9 4.9 2.2-1.1 3.8-3.2 4-5.6.1-.9-.1-1.9-.4-2.7z" }), + (0, import_react42.createElement)("path", { d: "M8.6 12.1c.9.7 1.7 1.6 2.2 2.7-1.1.2-2.3 0-3.3-.6.2-.8.6-1.5 1.1-2.1z" }) -+); + ); +-var MARKS = { github: GitHubMark }; +-var ABOUT = { github: () => t("Repositories, issues, and pull requests") }; +var MARKS = { github: GitHubMark, composio: ConnectorIcon, feishu: FeishuMark }; +var ABOUT = { + github: () => t("Repositories, issues, and pull requests"), @@ -25350,8 +25373,8 @@ diff --git a/client.js b/client.js - children ? (0, import_react28.createElement)("div", { className: "bt-set-control" }, children) : null + (0, import_react45.createElement)("div", { className: "bt-set-copy" }, (0, import_react45.createElement)("span", null, label), hint ? (0, import_react45.createElement)("span", { className: "bt-set-hint" }, hint) : null), + children ? (0, import_react45.createElement)("div", { className: "bt-set-control" }, children) : null - ); - } ++ ); ++} +var NOTIFY_KINDS = [ + ["approval", "Waiting for approval", "Once more if it still waits after 15 min."], + ["finished", "Finished"], @@ -25397,8 +25420,8 @@ diff --git a/client.js b/client.js + })), + (0, import_react45.createElement)("p", { className: "bt-set-hint" }, answer?.pendingRestart === true ? t("Restart FlyBot to apply the switches you changed.") : t("A switch takes effect the next time FlyBot starts.")) + ) -+ ); -+} + ); + } +function PluginsPage({ call: call4 }) { + const [answer, setAnswer] = (0, import_react45.useState)(null); + const [error, setError] = (0, import_react45.useState)(""); @@ -25770,7 +25793,7 @@ diff --git a/client.js b/client.js const run = (promise) => Promise.resolve(promise).then(() => { setError(""); return true; -@@ -10779,104 +10779,264 @@ function SettingsDialog({ page, id, roster, actions, useUpdate, leaving = false +@@ -10779,142 +10779,315 @@ function SettingsDialog({ page, id, roster, actions, useUpdate, leaving = false }); const bot = page === "bots" && id ? roster.byId[id] : void 0; const room2 = page === "groups" && id ? roster.roomsById[id] : void 0; @@ -26050,8 +26073,9 @@ diff --git a/client.js b/client.js // src/client/context-menu.js -var import_react29 = require("react"); +-function ContextMenu({ menu, roster, actions, leaving = false }) { +var import_react46 = require("react"); - function ContextMenu({ menu, roster, actions, leaving = false }) { ++function ContextMenu({ menu, roster, actions, leaving = false, unread }) { useEscape(() => actions.closeMenu()); - (0, import_react29.useEffect)(() => { + (0, import_react46.useEffect)(() => { @@ -26077,7 +26101,8 @@ diff --git a/client.js b/client.js const bot = roster.byId[menu.id]; const room2 = roster.roomsById[menu.id]; const entry = bot ?? room2; -@@ -10884,37 +10884,49 @@ function ContextMenu({ menu, roster, actions, leaving = false }) { + if (entry === void 0) return null; ++ const unreadItem = unread?.[menu.id] === true ? [t("Clear unread mark"), UnreadIcon, () => actions.clearUnread(menu.id)] : [t("Mark as Unread"), UnreadIcon, () => actions.markUnread(menu.id)]; const isMainBot = isMainOf(roster, menu.id); const isTile = roster.mainBotId === menu.id; const mainCount = (roster.mainBotIds ?? []).length; @@ -26085,7 +26110,7 @@ diff --git a/client.js b/client.js + const locked = typeof roster?.readOnly === "string" && roster.readOnly.trim() !== ""; + const groups = bot?.remote ? [ + [ -+ [t("Mark as Unread"), UnreadIcon, () => actions.markUnread(menu.id)] ++ unreadItem + ], + [ + [t("Bot settings"), GearIcon, () => actions.openSettings("bots", bot.id)] @@ -26095,8 +26120,9 @@ diff --git a/client.js b/client.js + ] : [ [ - isTile ? null : [entry.pinned ? t("Unpin") : t("Pin"), PinIcon, () => actions.setFlags(menu.id, { pinned: !entry.pinned })], +- [t("Mark as Unread"), UnreadIcon, () => actions.markUnread(menu.id)] + isTile || locked ? null : [entry.pinned ? t("Unpin") : t("Pin"), PinIcon, () => actions.setFlags(menu.id, { pinned: !entry.pinned })], - [t("Mark as Unread"), UnreadIcon, () => actions.markUnread(menu.id)] ++ unreadItem ], [ - bot ? [t("Rename Bot"), PencilIcon, () => actions.renameBot(bot.id)] : null, @@ -27675,7 +27701,7 @@ diff --git a/client.js b/client.js + ui2.palette ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(CommandPalette, { key: ui2.palette.token, start: ui2.palette.query, token: ui2.palette.token, roster, actions, useSessions }), document.body) : null, + ui2.exchange ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(ExchangeDialog, { pair: ui2.exchange, roster, actions }), document.body) : null, + ui2.voice ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(VoiceMode, { key: ui2.voice, sessionId: ui2.voice, roster, actions, useSessions, useSessionStatus }), document.body) : null, -+ menu ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(ContextMenu, { key: `${menu.kind ?? ""}:${menu.id}:${menu.x}:${menu.y}`, menu, roster, actions, leaving: menuLeaving }), document.body) : null, ++ menu ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(ContextMenu, { key: `${menu.kind ?? ""}:${menu.id}:${menu.x}:${menu.y}`, menu, roster, actions, unread: ui2.unread, leaving: menuLeaving }), document.body) : null, + settings ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(SettingsDialog, { page: settings.page, id: settings.id, roster, actions, useUpdate, leaving: settingsLeaving }), document.body) : null, + remoteBotSettings ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(RemoteBotSettingsSheet, { key: remoteBotSettings, bot: roster.byId[remoteBotSettings], roster, actions, leaving: remoteLeaving }), document.body) : null, + memory && roster.byId[memory] ? (0, import_react_dom11.createPortal)((0, import_react50.createElement)(MemoryDialog, { key: memory, bot: roster.byId[memory], roster, actions, leaving: memoryLeaving }), document.body) : null, diff --git a/patches/ds-bot/0012-room-membership.patch b/patches/ds-bot/0012-room-membership.patch index 3302de4ea..9f46374aa 100644 --- a/patches/ds-bot/0012-room-membership.patch +++ b/patches/ds-bot/0012-room-membership.patch @@ -983,8 +983,9 @@ diff --git a/src/client/header.js b/src/client/header.js import { createElement as h, Fragment, useEffect, useLayoutEffect, useRef, useState } from 'react' import { createPortal } from 'react-dom' -import { currentPart, latestMemoryChange } from './text.js' +-import { ArrowUpIcon, CloseIcon, ArrowDownIcon, MemoryIcon } from './icons.js' +import { currentPart, faceRowTitle, latestMemoryChange } from './text.js' - import { ArrowUpIcon, CloseIcon, ArrowDownIcon, MemoryIcon } from './icons.js' ++import { ArrowUpIcon, CloseIcon, ArrowDownIcon, MemoryIcon, UnreadIcon } from './icons.js' import { botState, BotAvatar, RoomAvatar } from './mark.js' +import { clockLabel, movedOnSince, openingTurn, unseenSince } from './cells.js' import { ActivityIndicator } from './activity-row.js' @@ -997,28 +998,50 @@ diff --git a/src/client/header.js b/src/client/header.js // ------------------------------------------------------------------------- // Conversation header -@@ -42,7 +42,7 @@ function MemoryNotice({ shown }) { +@@ -42,7 +42,28 @@ function MemoryNotice({ shown }) { h('span', { className: 'bt-pill-mem-in', ref: inner }, h('span', { className: 'bt-pill-mem-ico' }, h(MemoryIcon)), label)) } -export function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSession, useActivity, useMemoryNews, useTurnClock, useUi, useLive, actions }) { ++// The manual unread mark is keyed by the sidebar's row id (a Bot id, a group id or an Agent ++// id) while the header holds the Session id; an unknown id is left alone (#3114). ++export function unreadEntryId(roster, sessionId) { ++ const bot = roster?.byId?.[sessionId] ++ const room = roster?.roomsById?.[sessionId] ++ return bot?.id ?? room?.id ?? roster?.agentOf?.[sessionId] ?? sessionId ++} ++ ++// The header's local unread control: it marks this chat unread or clears that mark without ++// opening it, and it never writes the host's completion or pending-interaction flags — ++// those still clear only when the chat is opened. ++export function SessionUnreadToggle({ sessionId, roster, unread, actions }) { ++ const target = unreadEntryId(roster, sessionId) ++ const marked = unread?.[target] === true ++ const label = marked ? t('Clear unread mark') : t('Mark as Unread') ++ return h('button', { ++ type: 'button', className: 'bt-head-unread', 'aria-pressed': marked, 'aria-label': label, title: label, ++ onClick: () => (marked ? actions.clearUnread(target) : actions.markUnread(target)), ++ }, h(UnreadIcon)) ++} ++ +export function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSession, useActivity, useBusyAcks, useMemoryNews, useTurnClock, useUi, useLive, actions }) { const roster = useRoster(value => value) const title = useSessions(list => list.byId[sessionId]?.displayTitle ?? list.byId[sessionId]?.title ?? '') const firstTurns = useSessions((list) => { -@@ -51,8 +51,9 @@ export function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus +@@ -51,8 +51,10 @@ export function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus }) const hiddenTurns = roster.exchangeTurns?.[sessionId] const visit = useUi(state => state.visits?.[sessionId]) - // The opening separator has no turn before it, so the transcript column draws it, - // unless the opening is unread: then the first trigger draws it under the divider. ++ const unread = useUi(state => state.unread) + // The opening separator is the one page effect that stays with the pill: it needs a turn, so + // the shell always draws the header for it, and it reads `useTurnClock`, which the installer + // in header-effects.js deliberately does not carry. const opening = useTurnClock((state) => { const first = openingTurn(state[sessionId], firstTurns, hiddenTurns) return first && !unseenSince(visit, first.start) ? clockLabel(first.start) : '' -@@ -66,43 +66,42 @@ export function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus +@@ -66,43 +66,43 @@ export function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus const owner = roster.byId[sessionId]?.id ?? sessionId const doing = useActivity(map => map[owner]) const bot = roster.byId[sessionId] @@ -1076,7 +1099,8 @@ diff --git a/src/client/header.js b/src/client/header.js + }), + h(NewMessagePills, { key: sessionId, sessionId, hiddenTurns, useSessions, useUi, useTurnClock, actions }), + h(ActivityIndicator, { key: `activity:${sessionId}`, sessionId, useRoster, useSessionStatus, useSession, useLive, actions }), -+ h(BusyAckBubble, { key: `busy-ack:${sessionId}`, sessionId, useRoster, useBusyAcks, useSessionStatus, useSession, useLive })) ++ h(BusyAckBubble, { key: `busy-ack:${sessionId}`, sessionId, useRoster, useBusyAcks, useSessionStatus, useSession, useLive }), ++ h(SessionUnreadToggle, { sessionId, roster, unread, actions })) } // New-message pills. "N new messages ↓" takes Back to bottom's place when diff --git a/patches/ds-bot/files/test/unread-mark-menu.test.js b/patches/ds-bot/files/test/unread-mark-menu.test.js new file mode 100644 index 000000000..8b06aff2f --- /dev/null +++ b/patches/ds-bot/files/test/unread-mark-menu.test.js @@ -0,0 +1,175 @@ +// The manual unread mark is a client-only key in `ui.unread` (#3110 L102, #3114): a chat +// that is already marked unread must offer to clear that mark from its row menu and from +// the conversation header, without opening the chat. Clearing it never touches the host's +// completion or pending-interaction flags — opening the chat is what acknowledges those. +import assert from 'node:assert/strict' +import { test } from 'node:test' +import { runInNewContext } from 'node:vm' +import { build } from 'esbuild' +import { indexRoster } from '../src/client/sources.js' + +// One bundle for both surfaces; the header namespace keeps a missing export an assertion, not a build error. +const { outputFiles } = await build({ + stdin: { + contents: [ + "export { ContextMenu } from './src/client/context-menu.js'", + "import * as header from './src/client/header.js'", + 'export { header }', + ].join('\n'), + resolveDir: new URL('..', import.meta.url).pathname, + }, + bundle: true, format: 'cjs', platform: 'node', write: false, logLevel: 'silent', + external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'], +}) + +// One render pass over the hook shim is enough: these components read their inputs and draw. +let pass = null +const h = (type, props, ...children) => ({ type, props: { ...props, children: children.flat(Infinity) } }) +const sandbox = { + module: { exports: {} }, exports: null, Date, Promise, console, JSON, Map, Set, + window: { addEventListener: () => {}, removeEventListener: () => {}, innerWidth: 1400, innerHeight: 900 }, + document: { body: {}, addEventListener: () => {}, removeEventListener: () => {}, querySelector: () => null }, + navigator: { language: 'en' }, localStorage: { getItem: () => null, setItem() {} }, + setTimeout, clearTimeout, + require: (name) => { + const platform = { + react: { + createElement: (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat(Infinity) }), + useState: (initial) => { + const index = pass === null ? 0 : pass.index++ + if (!pass) return [initial, () => {}] + if (!(index in pass.values)) pass.values[index] = typeof initial === 'function' ? initial() : initial + return [pass.values[index], (next) => { pass.values[index] = typeof next === 'function' ? next(pass.values[index]) : next }] + }, + useEffect: () => {}, useLayoutEffect: () => {}, + useRef: current => ({ current }), useCallback: fn => fn, useMemo: fn => fn(), useSyncExternalStore: (_subscribe, get) => get(), + Fragment: 'fragment', + Component: class { constructor(props) { this.props = props } setState() {} render() { return null } }, + }, + 'react-dom': { createPortal: element => element }, + '@deepseek-ai/dsh-client-ui-primitives': {}, + } + if (!(name in platform)) throw new Error(`no platform module ${name}`) + return platform[name] + }, +} +sandbox.exports = sandbox.module.exports +runInNewContext(outputFiles[0].text, sandbox) +const { ContextMenu, header } = sandbox.module.exports +const { SessionUnreadToggle, unreadEntryId } = header + +const renderNode = (node) => { + if (Array.isArray(node)) return node.map(renderNode) + if (node === null || typeof node !== 'object') return node + if (typeof node.type === 'function') return renderNode(node.type({ ...node.props, children: node.children })) + return { ...node, children: (node.children ?? []).map(renderNode) } +} +const draw = (element) => { + pass = { index: 0, values: [] } + try { return renderNode(element()) } finally { pass = null } +} + +const textOf = node => (node?.children ?? []).flat(Infinity).filter(child => typeof child === 'string').join('') +const menuItems = (node, found = []) => { + if (node === null || typeof node !== 'object') return found + if (node.props?.role === 'menuitem') found.push({ label: textOf(node), onClick: node.props.onClick }) + for (const child of node.children ?? []) menuItems(child, found) + return found +} + +const bots = [ + { id: 'chief', name: 'Chief', sessionId: 'chief', parts: ['chief'] }, + { id: 'writer', name: 'Writer', sessionId: 'writer', parts: ['writer'] }, + { id: 'friend', name: 'Friend', sessionId: 'friend', parts: ['friend'], remote: true }, +] +const rooms = [{ id: 'room', name: 'Launch', members: ['chief', 'writer'] }] +const agents = [{ id: 'agent1', name: 'DSH Agent', sessions: ['agent-session'] }] +const rosterOf = (extra = {}) => indexRoster({ bots, rooms, agents, mainBotId: 'chief', mainBotIds: ['chief'], ...extra }) +const WRITER = { kind: 'bot', id: 'writer', x: 10, y: 10 } + +// Only the two local unread actions may be called, so any other entry in `calls` fails the check. +const localCalls = () => { + const calls = [] + const actions = { + closeMenu: () => {}, reportError: () => {}, openSession: id => calls.push({ action: 'openSession', id }), + markUnread: id => calls.push({ action: 'markUnread', id }), + clearUnread: id => calls.push({ action: 'clearUnread', id }), + openSettings: () => calls.push({ action: 'openSettings' }), setFlags: () => calls.push({ action: 'setFlags' }), + renameBot: () => calls.push({ action: 'renameBot' }), duplicateBot: async () => { calls.push({ action: 'duplicateBot' }); return { id: 'copy' } }, + setMain: () => calls.push({ action: 'setMain' }), deleteBot: () => calls.push({ action: 'deleteBot' }), + deleteRoom: () => calls.push({ action: 'deleteRoom' }), + } + return { calls, actions } +} + +// The pin toggle is left out of the message so the line names the entries this cut reads. +const written = labels => labels.filter(label => label !== 'Pin' && label !== 'Unpin') + +test('#3114: a marked chat offers Clear unread mark in its row menu, and that clears only the local mark', () => { + const { calls, actions } = localCalls() + const marked = menuItems(draw(() => ContextMenu({ menu: WRITER, roster: rosterOf(), actions, unread: { writer: true } }))) + assert.ok( + marked.some(item => item.label === 'Clear unread mark'), + `a marked bot (writer) offers no Clear unread mark: ${written(marked.map(item => item.label)).join(', ')}`, + ) + assert.ok(!marked.some(item => item.label === 'Mark as Unread'), 'a marked bot still offers Mark as Unread') + marked.find(item => item.label === 'Clear unread mark').onClick() + assert.deepEqual(calls, [{ action: 'clearUnread', id: 'writer' }], 'clearing the row mark wrote something else') + assert.ok(!calls.some(call => call.action === 'openSession'), 'clearing the row mark opened the chat') + + const plainCalls = localCalls() + const plain = menuItems(draw(() => ContextMenu({ menu: WRITER, roster: rosterOf(), actions: plainCalls.actions, unread: {} }))) + assert.ok(plain.some(item => item.label === 'Mark as Unread'), 'an unmarked bot lost Mark as Unread') + plain.find(item => item.label === 'Mark as Unread').onClick() + assert.deepEqual(plainCalls.calls, [{ action: 'markUnread', id: 'writer' }], 'marking the row wrote something else') +}) + +test('#3114: the chat header marks and clears the chat without opening it', () => { + assert.equal(typeof SessionUnreadToggle, 'function', 'the conversation header draws no unread control') + const roster = rosterOf() + // The header holds the Session id; the mark lives under the sidebar's row id. + assert.equal(unreadEntryId(roster, 'writer'), 'writer', 'a Bot Session maps to its Bot id') + assert.equal(unreadEntryId(roster, 'room'), 'room', 'a group Session maps to its room id') + assert.equal(unreadEntryId(roster, 'agent-session'), 'agent1', 'an Agent Session maps to its Agent id') + assert.equal(unreadEntryId(roster, 'elsewhere'), 'elsewhere', 'an unknown id is left alone') + + const state = localCalls() + const buttonOf = (sessionId, unread) => { + const find = (node) => { + if (node === null || typeof node !== 'object') return null + if (node.type === 'button') return node + for (const child of node.children ?? []) { const hit = find(child); if (hit) return hit } + return null + } + return find(draw(() => h(SessionUnreadToggle, { sessionId, roster, unread, actions: state.actions }))) + } + + const unmarked = buttonOf('writer', {}) + assert.equal(unmarked.props['aria-label'], 'Mark as Unread', 'an unmarked chat offers no way to mark it') + assert.equal(unmarked.props['aria-pressed'], false, 'an unmarked chat claims to be marked') + unmarked.props.onClick() + assert.deepEqual(state.calls, [{ action: 'markUnread', id: 'writer' }], 'the header marked something else') + + state.calls.length = 0 + const marked = buttonOf('writer', { writer: true }) + assert.equal(marked.props['aria-label'], 'Clear unread mark', 'a marked chat offers no way to clear the mark') + assert.equal(marked.props['aria-pressed'], true, 'a marked chat does not say it is marked') + marked.props.onClick() + assert.deepEqual(state.calls, [{ action: 'clearUnread', id: 'writer' }], 'the header cleared something else') + + state.calls.length = 0 + buttonOf('room', { room: true }).props.onClick() + buttonOf('agent-session', { agent1: true }).props.onClick() + assert.deepEqual(state.calls, [{ action: 'clearUnread', id: 'room' }, { action: 'clearUnread', id: 'agent1' }], 'the header cleared the wrong row') + assert.ok(!state.calls.some(call => call.action === 'openSession'), 'the header opened the chat it marked') +}) + +test('#3114: the unread entry stays a local control in a read-only window and never writes through the host', () => { + const locked = rosterOf({ readOnly: 'This window holds the team read-only.' }) + const { calls, actions } = localCalls() + const items = menuItems(draw(() => ContextMenu({ menu: WRITER, roster: locked, actions, unread: {} }))) + assert.ok(items.some(item => item.label === 'Mark as Unread'), 'a read-only window dropped the local unread control') + items.find(item => item.label === 'Mark as Unread').onClick() + assert.deepEqual(calls, [{ action: 'markUnread', id: 'writer' }], 'a read-only window did not mark locally') + assert.ok(!calls.some(call => call.action !== 'markUnread'), 'a read-only window wrote through the host') +})