A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Show message times and run durations in group chats
chimneya66ea5e0e2a9
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 22b7d294..fd7b5673 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -492,6 +492,7 @@ var ZH = {// Time and usage"Today {time}": "今天 {time}","Yesterday {time}": "昨天 {time}",+ "Ran for {duration}": "本次用时 {duration}","{tokens} tok · Cache hit {hit}%": "{tokens} tok · 缓存命中 {hit}%","1 turn": "1 轮","{count} turns": "{count} 轮",@@ -1730,12 +1731,26 @@ function mentionTarget(event) {function clock(ms) {return new Date(ms).toLocaleTimeString(dateLocale(), { hour: "numeric", minute: "2-digit" });}+var midnight = (value) => new Date(value.getFullYear(), value.getMonth(), value.getDate()).getTime();+var daysBefore = (date, now) => Math.round((midnight(new Date(now)) - midnight(date)) / 864e5);function dayLabel(ms) {const date = new Date(ms);const today = /* @__PURE__ */ new Date();const sameDay = date.toDateString() === today.toDateString();return sameDay ? t("Today {time}", { time: clock(ms) }) : `${date.toLocaleDateString(dateLocale(), { weekday: "short", month: "short", day: "numeric" })} ${clock(ms)}`;}+function clockLabel(time, now = Date.now()) {+ const date = new Date(time);+ const days = daysBefore(date, now);+ const stamp = clock(time);+ if (days === 0) return t("Today {time}", { time: stamp });+ if (days === 1) return t("Yesterday {time}", { time: stamp });+ const sameYear = date.getFullYear() === new Date(now).getFullYear();+ return `${date.toLocaleDateString(dateLocale(), { weekday: "short", month: "short", day: "numeric", ...sameYear ? {} : { year: "numeric" } })} ${stamp}`;+}+function messageClock(time, now = Date.now()) {+ return daysBefore(new Date(time), now) === 0 ? clock(time) : clockLabel(time, now);+}function relativeShort(ms) {const diff = Math.max(0, Date.now() - ms);if (diff < 6e4) return t("just now");@@ -2315,6 +2330,7 @@ button.bt-lead{border:0;background:none;padding:0;cursor:pointer}/* Rows without the avatar start where the bubble beside it starts: 22px avatar + 8px gap. */.bt-astack[data-lead]>.bt-msg:not(:last-child)>.bt-msg-line,.bt-astack[data-lead] .bt-reacts{margin-left:30px}.bt-group-name{font-size:12px;line-height:16px;font-weight:500;margin-left:42px}+.bt-group-time,.bt-group-took{margin-left:6px;font-size:11px;line-height:16px;font-weight:400;color:var(--bt-ink-2);font-variant-numeric:tabular-nums;white-space:nowrap}.bt-x{border:0;background:none;color:var(--bt-ink-2);cursor:pointer;width:24px;height:24px;border-radius:6px;font-size:16px;line-height:24px;padding:0;transition:background-color .12s ease,color .12s ease,${spring(SPRING_TAP, "scale")}}.bt-x:hover{background:var(--bt-hover);color:var(--bt-ink)}@@ -3117,6 +3133,7 @@ div:has(> nav [class*="_marks"]){display:none!important}.bt-ububble [class*="_markdown"],.bt-ububble a{color:inherit!important}.bt-ububble p{margin:0;line-height:22px}.bt-uimages{display:block;font-size:12px;opacity:.7}+.bt-utime{margin-top:-4px;font-size:11px;line-height:14px;color:var(--bt-ink-3);font-variant-numeric:tabular-nums;white-space:nowrap}.bt-earlier .bt-event{margin:4px 0}.bt-part-line{display:flex;align-items:center;gap:10px;margin:10px 0 6px;font-size:11px;line-height:14px;color:var(--bt-ink-3)}.bt-part-line::before,.bt-part-line::after{content:"";flex:1;height:1px;background:var(--bt-line)}@@ -4428,12 +4445,13 @@ function EventLine({ prefix, bots, joiner = t("and"), onOpen, whole = false }) {});return (0, import_react7.createElement)("div", { className: "bt-event" }, parts);}-function GroupMessage({ bot, text, texts: texts2 = [text], room: room2, roster, actions, msgKey, useUi, whole }) {+function GroupMessage({ bot, text, texts: texts2 = [text], room: room2, roster, actions, msgKey, useUi, whole, time, duration }) {const lead = (0, import_react7.createElement)("button",{ type: "button", className: "bt-lead", "aria-label": t("Open {name}'s chat", { name: bot.name }), onClick: () => actions.openSession(bot.id) },(0, import_react7.createElement)(BotMark, { bot, size: 22 }));+ const took = Number.isFinite(duration) ? elapsedLabel(duration) : void 0;return (0, import_react7.createElement)("div",{ className: "bt-group-msg" },@@ -4441,7 +4459,9 @@ function GroupMessage({ bot, text, texts: texts2 = [text], room: room2, roster,"span",{ className: "bt-group-name", style: { color: inkText(colorOf(bot)) } },bot.name,- room2?.admin === bot.id ? (0, import_react7.createElement)("span", { className: "bt-group-role" }, t("Admin")) : null+ room2?.admin === bot.id ? (0, import_react7.createElement)("span", { className: "bt-group-role" }, t("Admin")) : null,+ Number.isFinite(time) ? (0, import_react7.createElement)("span", { className: "bt-group-time", title: clockLabel(time) }, messageClock(time)) : null,+ took ? (0, import_react7.createElement)("span", { className: "bt-group-took", title: t("Ran for {duration}", { duration: took }) }, took) : null),(0, import_react7.createElement)(Bubbles, { texts: texts2, roster, selfId: bot.id, actions, sessionId: room2?.id, msgKey, useUi, lead, whole }));@@ -4450,8 +4470,11 @@ function stackReplies(replies) {const items = [];replies.forEach((reply, index) => {const last = items.at(-1);- if (reply.kind === void 0 && last?.reply.kind === void 0 && last?.reply.botId === reply.botId) last.texts.push(reply.text);- else items.push({ reply, index, texts: reply.kind === void 0 ? [reply.text] : [] });+ if (reply.kind === void 0 && last?.reply.kind === void 0 && last?.reply.botId === reply.botId) {+ last.texts.push(reply.text);+ last.time = reply.time;+ last.duration = reply.duration;+ } else items.push({ reply, index, texts: reply.kind === void 0 ? [reply.text] : [], time: reply.time, duration: reply.duration });});return items;}@@ -4644,6 +4667,7 @@ function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnClock, usactions,msgKey: `${sessionId}:post:${data.seq ?? node.key}`,useUi,+ time: data.time,whole: file ? { length: source.length, load: () => actions.fileText(file) } : void 0});}@@ -4705,16 +4729,6 @@ function Nothing() {return null;}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 nextTurnStart(turns, turn) {let next;for (const key in turns) {@@ -4889,7 +4903,7 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUireturn (0, import_react7.createElement)("div",{ className: "bt-group-replies" },- stackReplies(replies).map(({ reply, index, texts: texts2 }) => {+ stackReplies(replies).map(({ reply, index, texts: texts2, time, duration }) => {const bot = roster.byId[reply.botId] ?? { id: reply.botId, name: reply.name, color: reply.color ?? "gray" };if (reply.kind === "user") {return (0, import_react7.createElement)("div", { key: `user-${index}`, className: "bt-urow" }, (0, import_react7.createElement)(@@ -4939,7 +4953,7 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUiif (reply.kind === "done") {return (0, import_react7.createElement)("div", { key: `${reply.botId}-${index}`, className: "bt-event" }, t("{name} finished its work", { name: bot.name }));}- return (0, import_react7.createElement)(GroupMessage, { key: `${reply.botId}-${index}`, bot, texts: texts2, room: room2, roster, actions, msgKey: callId ? `${sessionId}:${callId}:${index}` : void 0, useUi });+ return (0, import_react7.createElement)(GroupMessage, { key: `${reply.botId}-${index}`, bot, texts: texts2, room: room2, roster, actions, msgKey: callId ? `${sessionId}:${callId}:${index}` : void 0, useUi, time, duration });}),pending.map((id) => {const bot = roster.byId[id];@@ -14163,6 +14177,7 @@ function UserMessageCell({ node, sessionId, useRoster, actions, renderMessageImaconst referenceLabels = data.referenceLabels ?? [];const references = openFile && openSkill ? { openFile, openSkill } : void 0;const steering = node.kind === "steering";+ const groupTime = roster.roomsById?.[sessionId] && Number.isFinite(data.time) ? messageClock(data.time) : void 0;const { shown, folded, control } = useFold(text, { markdown: false });const body = (0, import_react37.createElement)(UserText, { text: shown, bots: mentionableBots(roster, sessionId), referenceLabels, skillNames: data.skillNames ?? [], references, actions });return (0, import_react37.createElement)(@@ -14179,7 +14194,8 @@ function UserMessageCell({ node, sessionId, useRoster, actions, renderMessageImacontrol,rest.map((block, index) => ui.JsonBlock ? (0, import_react37.createElement)(ui.JsonBlock, { key: index, label: t("Content"), payload: block }) : null)) : null,- referenceLabels.length > 0 ? (0, import_react37.createElement)("div", { className: "bt-urefs" }, t("Referenced {labels}", { labels: referenceLabels.join(t(", ")) })) : null+ referenceLabels.length > 0 ? (0, import_react37.createElement)("div", { className: "bt-urefs" }, t("Referenced {labels}", { labels: referenceLabels.join(t(", ")) })) : null,+ groupTime ? (0, import_react37.createElement)("div", { className: "bt-utime", title: clockLabel(data.time) }, groupTime) : null),text === "" ? null : (0, import_react37.createElement)("div", { className: "bt-utools" }, (0, import_react37.createElement)(CopyButton, { text })));diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.jsindex 9e9abe0d..91787e18 100644--- a/ds-bot/src/client/cells.js+++ b/ds-bot/src/client/cells.js@@ -2,16 +2,18 @@ import { createElement as h, Fragment, useEffect, useLayoutEffect, useMemo, useRimport { createPortal } from 'react-dom'import { MarkdownText } from './dsh-primitives.js'import { inkText } from './inks.js'-import { linkMentions, mentionTarget, dayLabel, contentText, stripHeader, isHiddenTurn, isRelayContext, relaysBefore, relayPart, commRunOf, toolName, toolArgs, reminderPrompts, elapsedLabel } from './text.js'+import { linkMentions, mentionTarget, dayLabel, contentText, stripHeader, isHiddenTurn, isRelayContext, relaysBefore, relayPart, commRunOf, toolName, toolArgs, reminderPrompts, elapsedLabel, clockLabel, messageClock } from './text.js'import { SmileIcon, ReplyIcon, DotsIcon, CheckIcon, DownloadIcon, CopyIcon, MemoryIcon } from './icons.js'import { colorOf, toolState, BotMark, RoomAvatar } from './mark.js'import { AnsweredCell, SettledQuestion, PendingQuestion } from './questions.js'import { SecretToolCell } from './secret-card.js'-import { dateLocale, t } from './i18n.js'+import { t } from './i18n.js'import { failureLabel } from './diagnostics.js'import { turnReasoning } from './turn-reasoning.js'import { FOLD_AT, FOLD_HUGE, stripLongNote, useFold } from './fold.js'+export { clockLabel }+// -------------------------------------------------------------------------// Chat cells@@ -202,24 +204,31 @@ function EventLine({ prefix, bots, joiner = t('and'), onOpen, whole = false }) {return h('div', { className: 'bt-event' }, parts)}-// One Bot message inside a group chat: avatar, name (with its group role), bubble.-function GroupMessage({ bot, text, texts = [text], room, roster, actions, msgKey, useUi, whole }) {+// One Bot message inside a group chat: avatar, name (with its group role), when it ran+// and how long it took, bubble.+function GroupMessage({ bot, text, texts = [text], room, roster, actions, msgKey, useUi, whole, time, duration }) {const lead = h('button', { type: 'button', className: 'bt-lead', 'aria-label': t("Open {name}'s chat", { name: bot.name }), onClick: () => actions.openSession(bot.id) },h(BotMark, { bot, size: 22 }))+ const took = Number.isFinite(duration) ? elapsedLabel(duration) : undefinedreturn h('div', { className: 'bt-group-msg' },h('span', { className: 'bt-group-name', style: { color: inkText(colorOf(bot)) } }, bot.name,- room?.admin === bot.id ? h('span', { className: 'bt-group-role' }, t('Admin')) : null),+ room?.admin === bot.id ? h('span', { className: 'bt-group-role' }, t('Admin')) : null,+ Number.isFinite(time) ? h('span', { className: 'bt-group-time', title: clockLabel(time) }, messageClock(time)) : null,+ took ? h('span', { className: 'bt-group-took', title: t('Ran for {duration}', { duration: took }) }, took) : null),h(Bubbles, { texts, roster, selfId: bot.id, actions, sessionId: room?.id, msgKey, useUi, lead, whole }))}// A member's messages in a row, as one block under its name: what it says while it-// works comes one message at a time.+// works comes one message at a time. A block carries the last message's time and run.export function stackReplies(replies) {const items = []replies.forEach((reply, index) => {const last = items.at(-1)- if (reply.kind === undefined && last?.reply.kind === undefined && last?.reply.botId === reply.botId) last.texts.push(reply.text)- else items.push({ reply, index, texts: reply.kind === undefined ? [reply.text] : [] })+ if (reply.kind === undefined && last?.reply.kind === undefined && last?.reply.botId === reply.botId) {+ last.texts.push(reply.text)+ last.time = reply.time+ last.duration = reply.duration+ } else items.push({ reply, index, texts: reply.kind === undefined ? [reply.text] : [], time: reply.time, duration: reply.duration })})return items}@@ -425,7 +434,7 @@ export function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnClconst text = stripHeader(contentText(data.content))// A trigger's data carries no turn; its event seq is the one durable name of this post.return h(GroupMessage, {- bot: poster, text: file ? stripLongNote(text) : text, room, roster, actions, msgKey: `${sessionId}:post:${data.seq ?? node.key}`, useUi,+ bot: poster, text: file ? stripLongNote(text) : text, room, roster, actions, msgKey: `${sessionId}:post:${data.seq ?? node.key}`, useUi, time: data.time,whole: file ? { length: source.length, load: () => actions.fileText(file) } : undefined,})}@@ -494,18 +503,8 @@ export function TurnProcessCell({ node, sessionId, turnProcess, useRoster, useUiexport function Nothing() { return null }-// The time separator: "Today 1:12 AM", "Yesterday 9:03 PM", "Thu, Sep 3 4:20 PM".+// A pause longer than this splits the transcript with a time separator.const SEPARATOR_GAP_MS = 30 * 60 * 1000-export 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)) / 86400000)- const clock = date.toLocaleTimeString(dateLocale(), { hour: 'numeric', minute: '2-digit' })- if (days === 0) return t('Today {time}', { time: clock })- if (days === 1) return t('Yesterday {time}', { time: clock })- const sameYear = date.getFullYear() === new Date(now).getFullYear()- return `${date.toLocaleDateString(dateLocale(), { weekday: 'short', month: 'short', day: 'numeric', ...(sameYear ? {} : { year: 'numeric' }) })} ${clock}`-}function nextTurnStart(turns, turn) {let nextfor (const key in turns) {@@ -676,7 +675,7 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUiif (replies.length === 0 && pending.length === 0) return nullconst room = roster.roomsById[sessionId]return h('div', { className: 'bt-group-replies' },- stackReplies(replies).map(({ reply, index, texts }) => {+ stackReplies(replies).map(({ reply, index, texts, time, duration }) => {const bot = roster.byId[reply.botId] ?? { id: reply.botId, name: reply.name, color: reply.color ?? 'gray' }if (reply.kind === 'user') {return h('div', { key: `user-${index}`, className: 'bt-urow' }, h('div', { className: 'bt-ububble' },@@ -710,7 +709,7 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUiif (reply.kind === 'done') {return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' }, t('{name} finished its work', { name: bot.name }))}- return h(GroupMessage, { key: `${reply.botId}-${index}`, bot, texts, room, roster, actions, msgKey: callId ? `${sessionId}:${callId}:${index}` : undefined, useUi })+ return h(GroupMessage, { key: `${reply.botId}-${index}`, bot, texts, room, roster, actions, msgKey: callId ? `${sessionId}:${callId}:${index}` : undefined, useUi, time, duration })}),pending.map((id) => {const bot = roster.byId[id]diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.jsindex 06bb3594..4d65a8c7 100644--- a/ds-bot/src/client/i18n.js+++ b/ds-bot/src/client/i18n.js@@ -435,6 +435,7 @@ const ZH = {// Time and usage'Today {time}': '今天 {time}','Yesterday {time}': '昨天 {time}',+ 'Ran for {duration}': '本次用时 {duration}','{tokens} tok · Cache hit {hit}%': '{tokens} tok · 缓存命中 {hit}%','1 turn': '1 轮','{count} turns': '{count} 轮',diff --git a/ds-bot/src/client/styles.js b/ds-bot/src/client/styles.jsindex 2ff9f1f9..3bd81551 100644--- a/ds-bot/src/client/styles.js+++ b/ds-bot/src/client/styles.js@@ -198,6 +198,7 @@ button.bt-lead{border:0;background:none;padding:0;cursor:pointer}/* Rows without the avatar start where the bubble beside it starts: 22px avatar + 8px gap. */.bt-astack[data-lead]>.bt-msg:not(:last-child)>.bt-msg-line,.bt-astack[data-lead] .bt-reacts{margin-left:30px}.bt-group-name{font-size:12px;line-height:16px;font-weight:500;margin-left:42px}+.bt-group-time,.bt-group-took{margin-left:6px;font-size:11px;line-height:16px;font-weight:400;color:var(--bt-ink-2);font-variant-numeric:tabular-nums;white-space:nowrap}.bt-x{border:0;background:none;color:var(--bt-ink-2);cursor:pointer;width:24px;height:24px;border-radius:6px;font-size:16px;line-height:24px;padding:0;transition:background-color .12s ease,color .12s ease,${spring(SPRING_TAP, 'scale')}}.bt-x:hover{background:var(--bt-hover);color:var(--bt-ink)}@@ -1001,6 +1002,7 @@ div:has(> nav [class*="_marks"]){display:none!important}.bt-ububble [class*="_markdown"],.bt-ububble a{color:inherit!important}.bt-ububble p{margin:0;line-height:22px}.bt-uimages{display:block;font-size:12px;opacity:.7}+.bt-utime{margin-top:-4px;font-size:11px;line-height:14px;color:var(--bt-ink-3);font-variant-numeric:tabular-nums;white-space:nowrap}.bt-earlier .bt-event{margin:4px 0}.bt-part-line{display:flex;align-items:center;gap:10px;margin:10px 0 6px;font-size:11px;line-height:14px;color:var(--bt-ink-3)}.bt-part-line::before,.bt-part-line::after{content:"";flex:1;height:1px;background:var(--bt-line)}diff --git a/ds-bot/src/client/text.js b/ds-bot/src/client/text.jsindex b4bc637a..f5252550 100644--- a/ds-bot/src/client/text.js+++ b/ds-bot/src/client/text.js@@ -28,6 +28,8 @@ export function mentionTarget(event) {function clock(ms) {return new Date(ms).toLocaleTimeString(dateLocale(), { hour: 'numeric', minute: '2-digit' })}+const midnight = value => new Date(value.getFullYear(), value.getMonth(), value.getDate()).getTime()+const daysBefore = (date, now) => Math.round((midnight(new Date(now)) - midnight(date)) / 86400000)export function dayLabel(ms) {const date = new Date(ms)const today = new Date()@@ -35,6 +37,22 @@ export function dayLabel(ms) {return sameDay ? t('Today {time}', { time: clock(ms) }) : `${date.toLocaleDateString(dateLocale(), { weekday: 'short', month: 'short', day: 'numeric' })} ${clock(ms)}`}+// The time separator's stamp: "Today 1:12 AM", "Yesterday 9:03 PM", "Thu, Sep 3 4:20 PM".+export function clockLabel(time, now = Date.now()) {+ const date = new Date(time)+ const days = daysBefore(date, now)+ const stamp = clock(time)+ if (days === 0) return t('Today {time}', { time: stamp })+ if (days === 1) return t('Yesterday {time}', { time: stamp })+ const sameYear = date.getFullYear() === new Date(now).getFullYear()+ return `${date.toLocaleDateString(dateLocale(), { weekday: 'short', month: 'short', day: 'numeric', ...(sameYear ? {} : { year: 'numeric' }) })} ${stamp}`+}++// A message's own stamp: today only the clock, an earlier day named as a separator does.+export function messageClock(time, now = Date.now()) {+ return daysBefore(new Date(time), now) === 0 ? clock(time) : clockLabel(time, now)+}+// A short relative stamp for list rows: "just now", "5 min", "3 h", "2 d", then a date.export function relativeShort(ms) {const diff = Math.max(0, Date.now() - ms)diff --git a/ds-bot/src/client/user-message.js b/ds-bot/src/client/user-message.jsindex 01193a9b..95d1c56c 100644--- a/ds-bot/src/client/user-message.js+++ b/ds-bot/src/client/user-message.js@@ -4,6 +4,7 @@ import { mentionSpans } from '../shared/mentions.js'import { BotMark } from './mark.js'import { CheckIcon, CopyIcon } from './icons.js'import { dateLocale, t } from './i18n.js'+import { clockLabel, messageClock } from './text.js'import { useFold } from './fold.js'// -------------------------------------------------------------------------@@ -88,6 +89,7 @@ export function UserMessageCell({ node, sessionId, useRoster, actions, renderMesconst referenceLabels = data.referenceLabels ?? []const references = openFile && openSkill ? { openFile, openSkill } : undefinedconst steering = node.kind === 'steering'+ const groupTime = roster.roomsById?.[sessionId] && Number.isFinite(data.time) ? messageClock(data.time) : undefinedconst { shown, folded, control } = useFold(text, { markdown: false })const body = h(UserText, { text: shown, bots: mentionableBots(roster, sessionId), referenceLabels, skillNames: data.skillNames ?? [], references, actions })return h('div', { className: 'bt-umsg', 'data-steering': steering || undefined },@@ -97,7 +99,8 @@ export function UserMessageCell({ node, sessionId, useRoster, actions, renderMescontrol ? h('div', { className: 'bt-fold-body' }, body) : body,control,rest.map((block, index) => (ui.JsonBlock ? h(ui.JsonBlock, { key: index, label: t('Content'), payload: block }) : null))) : null,- referenceLabels.length > 0 ? h('div', { className: 'bt-urefs' }, t('Referenced {labels}', { labels: referenceLabels.join(t(', ')) })) : null),+ referenceLabels.length > 0 ? h('div', { className: 'bt-urefs' }, t('Referenced {labels}', { labels: referenceLabels.join(t(', ')) })) : null,+ groupTime ? h('div', { className: 'bt-utime', title: clockLabel(data.time) }, groupTime) : null),text === '' ? null : h('div', { className: 'bt-utools' }, h(CopyButton, { text })))}diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.jsindex 5dc679df..4cb60fad 100644--- a/ds-bot/src/host/groups.js+++ b/ds-bot/src/host/groups.js@@ -258,9 +258,9 @@ export function install(rt) {// A member's message in the round: in the log, for the members after it, and in the// round's replies, for the user.- const postInRound = (room, round, member, text) => {+ const postInRound = (room, round, member, text, duration) => {appendRoom(room, { who: member.name, botId: member.id, text })- round.replies.push({ botId: member.id, name: member.name, color: member.color, text, time: Date.now() })+ round.replies.push({ botId: member.id, name: member.name, color: member.color, text, time: Date.now(), ...(duration === undefined ? {} : { duration }) })void rt.save().catch(() => {})}@@ -273,6 +273,7 @@ export function install(rt) {// member writes before its last step is posted at once and collected in `said`.async function roomTurn(room, member, sessionId, { text, files }, note, signal, round, by, said = []) {if (signal.aborted) return null+ const startedAt = Date.now()const exchangeId = randomUUID()const turn = { botId: member.id, sessionId, exchangeId }const { started } = round@@ -298,7 +299,7 @@ export function install(rt) {const step = stripOwnName(member.name, raw)if (isPass(step)) returnsaid.push(step)- postInRound(room, round, member, step)+ postInRound(room, round, member, step, Date.now() - startedAt)}touch()rt.roomWaiters.set(exchangeId, { sessionId, botId: member.id, roomId: room.id, resolve: finish, fail: failure => finish({ failure }), touch, work, say, approval: () => finish({ approval: true }) })@@ -448,6 +449,7 @@ export function install(rt) {round.shown?.push(member.id)const text = session.brief === undefined ? prompt.text : `${session.brief}\n\n${prompt.text}`const said = []+ const startedAt = Date.now()const reply = await roomTurn(room, member, session.id, { text, files: prompt.files }, slot.note ?? 'your turn', signal, round, slot.by, said)round.speaking = nullconst final = typeof reply === 'string' && !isPass(reply) ? reply : undefined@@ -466,7 +468,7 @@ export function install(rt) {round.replies.push({ kind: 'working', botId: member.id, name: member.name, color: member.color, time: Date.now() })} else if (final !== undefined || (typeof reply === 'string' && said.length > 0)) {slot.status = 'posted'- if (final !== undefined) postInRound(room, round, member, final)+ if (final !== undefined) postInRound(room, round, member, final, Date.now() - startedAt)} else {slot.status = typeof reply === 'string' ? 'passed' : 'missed'round.passed.push(member.name)diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.jsindex ab539700..768e8b0f 100644--- a/ds-bot/test/group-work.test.js+++ b/ds-bot/test/group-work.test.js@@ -301,6 +301,8 @@ test('a member called while still at earlier work lets the round go on at once',const result = host.round('c1', host.say('@Writer 再看看这个'))await settle(() => result() !== undefined)assert.deepEqual(kinds(result()), [['working', 'Writer']])+ // A member at work has not run its turn here, and an event is not a message.+ assert.equal(result().replies[0].duration, undefined)// The call waits for the work before it.assert.equal(host.agentOf('gb').inbox.nextTurn.length, 1)})@@ -736,6 +738,28 @@ test('a member whose every message went out while it worked counts as posted, noassert.deepEqual([result().passed, result().replies.map(reply => reply.text)], [[], ['我看一下。']])})+test('a member\'s messages carry how long its turn ran', async (t) => {+ const host = await start(t)+ const result = host.round('c1', host.say('@Writer 整理文档'))+ await settle(() => host.agentOf('gb').calls.length === 1)+ host.begin('gb')+ step(host, 'gb', '收到,先看看。', 'k1', 'list_bots')+ await settle(() => true)+ const live = await progress(host)+ assert.equal(typeof live.replies[0].duration, 'number')+ assert.ok(live.replies[0].duration >= 0)+ host.emit('gb', 'tool/result', { callId: 'k1' })+ host.finish('gb', '整理好了。')+ await settle(() => result() !== undefined)+ const messages = result().replies.filter(reply => reply.kind === undefined)+ assert.deepEqual(messages.map(reply => reply.text), ['收到,先看看。', '整理好了。'])+ for (const reply of messages) {+ assert.equal(typeof reply.duration, 'number')+ assert.ok(reply.duration >= 0)+ }+ assert.ok(result().replies.every(reply => reply.kind === undefined || reply.duration === undefined))+})+test('after the round went on, lines a member writes close together reach the group as one message; only the result is answered', async (t) => {t.mock.timers.enable({ apis: ['setTimeout'] })const host = await start(t)diff --git a/ds-bot/test/message-clock.test.js b/ds-bot/test/message-clock.test.jsnew file mode 100644index 00000000..de7da2f3--- /dev/null+++ b/ds-bot/test/message-clock.test.js@@ -0,0 +1,26 @@+import assert from 'node:assert/strict'+import { test } from 'node:test'+import { clockLabel, messageClock } from '../src/client/text.js'++// A time in the machine's own zone, some days back, so the test does not depend on the zone.+const at = (daysAgo, hour, minute) => {+ const today = new Date()+ return new Date(today.getFullYear(), today.getMonth(), today.getDate() - daysAgo, hour, minute).getTime()+}+const clockOf = ms => new Date(ms).toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit' })++test('a message shows the clock today, and the day it came in before that', () => {+ const today = at(0, 14, 5)+ assert.equal(messageClock(today), clockOf(today))+ const yesterday = at(1, 9, 3)+ assert.equal(messageClock(yesterday), `Yesterday ${clockOf(yesterday)}`)+ const older = at(5, 9, 3)+ const date = new Date(older)+ const sameYear = date.getFullYear() === new Date().getFullYear()+ const day = date.toLocaleDateString('en-US', { weekday: 'short', month: 'short', day: 'numeric', ...(sameYear ? {} : { year: 'numeric' }) })+ assert.equal(messageClock(older), `${day} ${clockOf(older)}`)+ // The hover title always names the day.+ assert.equal(clockLabel(today), `Today ${clockOf(today)}`)+ assert.equal(clockLabel(yesterday), `Yesterday ${clockOf(yesterday)}`)+ assert.equal(clockLabel(older), messageClock(older))+})diff --git a/ds-bot/test/tool-cells.test.js b/ds-bot/test/tool-cells.test.jsindex e8b29285..8ec3fb2c 100644--- a/ds-bot/test/tool-cells.test.js+++ b/ds-bot/test/tool-cells.test.js@@ -89,10 +89,69 @@ const program = (subCalls, over = {}) => call('run_code', 'program', { subCalls,test('a member\'s messages in a row stack under its name, and an event line starts a new block', () => {const replies = [- { botId: 'writer', text: 'a' }, { botId: 'writer', text: 'b' }, { kind: 'working', botId: 'writer' },- { botId: 'writer', text: 'c' }, { botId: 'chief', text: 'd' }, { botId: 'writer', text: 'e' },+ { botId: 'writer', text: 'a', time: 10, duration: 1000 }, { botId: 'writer', text: 'b', time: 20, duration: 2000 },+ { kind: 'working', botId: 'writer', time: 30 },+ { botId: 'writer', text: 'c', time: 40, duration: 4000 }, { botId: 'chief', text: 'd', time: 50, duration: 5000 },+ { botId: 'writer', text: 'e', time: 60, duration: 6000 },]assert.deepEqual(JSON.parse(JSON.stringify(stackReplies(replies).map(item => [item.index, item.texts]))), [[0, ['a', 'b']], [2, []], [3, ['c']], [4, ['d']], [5, ['e']]])+ // A stacked block carries its last message's time and how long that turn ran.+ const [stacked, event, single] = stackReplies(replies)+ assert.deepEqual([stacked.time, stacked.duration], [20, 2000])+ assert.deepEqual([event.time, event.duration], [30, undefined])+ assert.deepEqual([single.time, single.duration], [40, 4000])+})++// A time in the machine's own zone, some days back, so the test does not depend on the zone.+const at = (daysAgo, hour, minute) => {+ const today = new Date()+ return new Date(today.getFullYear(), today.getMonth(), today.getDate() - daysAgo, hour, minute).getTime()+}+const clockOf = ms => new Date(ms).toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit' })+const findAll = (node, match) => {+ const found = []+ const visit = (entry) => {+ if (Array.isArray(entry)) { entry.forEach(visit); return }+ if (!entry || typeof entry !== 'object') return+ if (match(entry)) found.push(entry)+ visit(entry.props?.children)+ }+ visit(node)+ return found+}++test('a group reply shows its time, and how long its turn ran', () => {+ const today = at(0, 14, 5)+ const yesterday = at(1, 9, 3)+ const replies = [+ { botId: 'writer', text: 'Draft is up.', time: today, duration: 68_000 },+ { botId: 'chief', text: 'Looks good.', time: yesterday, duration: 2_000 },+ ]+ const out = show(call('group_relay', 'direct', { content: { replies } }), { sessionId: 'room' })+ const times = findAll(out, node => node.props?.className === 'bt-group-time')+ const tooks = findAll(out, node => node.props?.className === 'bt-group-took')+ assert.deepEqual(times.map(text), [clockOf(today), `Yesterday ${clockOf(yesterday)}`])+ assert.deepEqual(times.map(node => node.props.title), [`Today ${clockOf(today)}`, `Yesterday ${clockOf(yesterday)}`])+ assert.deepEqual(tooks.map(text), ['1m 8s', '2s'])+ assert.deepEqual(tooks.map(node => node.props.title), ['Ran for 1m 8s', 'Ran for 2s'])+})++// The trigger of a post in a group chat carries the event's time, not the post's.+test('a group post drawn from its trigger shows the time it came in', () => {+ const time = at(0, 16, 42)+ const node = {+ key: 'trigger', kind: 'turn-trigger', location: { turn: { turn: 1 } },+ data: { seq: 7, time, content: text$('Draft is up.'), source: { kind: 'bot', role: 'post', senderSessionId: 'writer', senderName: 'Writer' } },+ }+ const out = expand(TriggerCell({+ node, sessionId: 'room', actions: {},+ useRoster: select => select(team()), useSessions: select => select({ byId: {} }),+ useTurnClock: select => select({}), useUi: select => select({ visits: {}, reactions: {} }),+ }))+ const stamps = findAll(out, entry => entry.props?.className === 'bt-group-time')+ assert.equal(stamps.length, 1)+ assert.equal(text(stamps[0]), clockOf(time))+ effects = []})const props = (root, { sessionId = chief.id, roster = team(), actions = {}, turn = 1 } = {}) => ({