A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Show message times in private chats
klarkxy24db6a430dc7
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 24d0962b..78839c28 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -7832,7 +7832,7 @@ function BtwTurnTail({ turn, sessionId, useRoster, actions }) {var import_react17 = require("react");var import_react_dom = require("react-dom");var mdLabels3 = () => ({ code: { copyLabel: t("Copy"), copiedLabel: t("Copied") }, footnotes: t("Footnotes") });-function Bubbles({ texts: texts2, roster, selfId, actions, streaming, sessionId, msgKey, useUi, lead, mentions, fold = FOLD_AT, whole }) {+function Bubbles({ texts: texts2, roster, selfId, actions, streaming, sessionId, msgKey, useUi, lead, mentions, fold = FOLD_AT, whole, time }) {const onClick = (event) => {const target = mentionTarget(event);if (target === null) return;@@ -7862,7 +7862,8 @@ function Bubbles({ texts: texts2, roster, selfId, actions, streaming, sessionId,lead: lead && last ? lead : null,whole: last ? whole : void 0});- })+ }),+ Number.isFinite(time) ? (0, import_react17.createElement)("div", { className: "bt-utime", title: clockLabel(time) }, messageClock(time)) : null);}function FoldCodeCopy({ code, actions }) {@@ -8127,7 +8128,7 @@ function AssistantCell({ node, groupPart, sessionId, openFile, fileMentions, use// time makes one Elapsed show settled + running....thinking !== void 0 ? { at: typeof thinking.time === "number" ? thinking.time - (ms ?? 0) : void 0 } : { ms }}) : null,- texts2.length ? (0, import_react17.createElement)(Bubbles, { texts: texts2, roster, selfId, actions, streaming: running, sessionId, msgKey: `${sessionId}:${data.turn}:${node.key ?? data.seq ?? ""}`, useUi, mentions, fold: FOLD_HUGE }) : null+ texts2.length ? (0, import_react17.createElement)(Bubbles, { texts: texts2, roster, selfId, actions, streaming: running, sessionId, msgKey: `${sessionId}:${data.turn}:${node.key ?? data.seq ?? ""}`, useUi, mentions, fold: FOLD_HUGE, time: speaker === void 0 ? data.time : void 0 }) : null);}function EventLine({ prefix, bots, joiner = t("and"), onOpen, whole = false }) {@@ -20422,7 +20423,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 sentAt = Number.isFinite(data.time) ? messageClock(data.time) : void 0;const { shown, folded, control } = useFold(text, { markdown: false });const body = (0, import_react52.createElement)(UserText, { text: shown, bots: mentionableBots(roster, sessionId), referenceLabels, skillNames: data.skillNames ?? [], references, actions });const row = (0, import_react52.useRef)(null);@@ -20458,7 +20459,7 @@ function UserMessageCell({ node, sessionId, useRoster, actions, renderMessageImarest.map((block, index) => ui.JsonBlock ? (0, import_react52.createElement)(ui.JsonBlock, { key: index, label: t("Content"), payload: block }) : null)) : null,referenceLabels.length > 0 ? (0, import_react52.createElement)("div", { className: "bt-urefs" }, t("Referenced {labels}", { labels: referenceLabels.join(t(", ")) })) : null,- groupTime ? (0, import_react52.createElement)("div", { className: "bt-utime", title: clockLabel(data.time) }, groupTime) : null+ sentAt ? (0, import_react52.createElement)("div", { className: "bt-utime", title: clockLabel(data.time) }, sentAt) : null),text === "" ? null : (0, import_react52.createElement)("div", { className: "bt-utools", "data-open": toolsOpen || void 0 }, (0, import_react52.createElement)(CopyButton, { text })));diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.jsindex 6575a1ba..53bd675d 100644--- a/ds-bot/src/client/cells.js+++ b/ds-bot/src/client/cells.js@@ -32,8 +32,9 @@ const mdLabels = () => ({ code: { copyLabel: t('Copy'), copiedLabel: t('Copied')// `lead` (a sender avatar in group chats) sits beside the last bubble, in the same// row, so it lines up with the bubble whether or not reactions hang below it.// `fold`: past what a bubble folds (fold.js); `whole`: the last text is only the start-// of its message (see useFold).-export function Bubbles({ texts, roster, selfId, actions, streaming, sessionId, msgKey, useUi, lead, mentions, fold = FOLD_AT, whole }) {+// of its message (see useFold). `time` marks the bubbles' message below them; a caller+// whose own head already shows one (the flat speaker line, the group name row) leaves it unset.+export function Bubbles({ texts, roster, selfId, actions, streaming, sessionId, msgKey, useUi, lead, mentions, fold = FOLD_AT, whole, time }) {const onClick = (event) => {const target = mentionTarget(event)if (target === null) return@@ -52,7 +53,8 @@ export function Bubbles({ texts, roster, selfId, actions, streaming, sessionId,lead: lead && last ? lead : null,whole: last ? whole : undefined,})- }))+ }),+ Number.isFinite(time) ? h('div', { className: 'bt-utime', title: clockLabel(time) }, messageClock(time)) : null)}// A folded message's last code block shows only its start; DS Bot draws its own@@ -294,7 +296,7 @@ export function AssistantCell({ node, groupPart, sessionId, openFile, fileMentio// time makes one Elapsed show settled + running....(thinking !== undefined ? { at: typeof thinking.time === 'number' ? thinking.time - (ms ?? 0) : undefined } : { ms }),}) : null,- texts.length ? h(Bubbles, { texts, roster, selfId, actions, streaming: running, sessionId, msgKey: `${sessionId}:${data.turn}:${node.key ?? data.seq ?? ''}`, useUi, mentions, fold: FOLD_HUGE }) : null)+ texts.length ? h(Bubbles, { texts, roster, selfId, actions, streaming: running, sessionId, msgKey: `${sessionId}:${data.turn}:${node.key ?? data.seq ?? ''}`, useUi, mentions, fold: FOLD_HUGE, time: speaker === undefined ? data.time : undefined }) : null)}function EventLine({ prefix, bots, joiner = t('and'), onOpen, whole = false }) {diff --git a/ds-bot/src/client/user-message.js b/ds-bot/src/client/user-message.jsindex fa94f505..564be3b0 100644--- a/ds-bot/src/client/user-message.js+++ b/ds-bot/src/client/user-message.js@@ -90,7 +90,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) : undefined+ const sentAt = 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 })const row = useRef(null)@@ -115,7 +115,7 @@ export function UserMessageCell({ node, sessionId, useRoster, actions, renderMescontrol,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,- groupTime ? h('div', { className: 'bt-utime', title: clockLabel(data.time) }, groupTime) : null),+ sentAt ? h('div', { className: 'bt-utime', title: clockLabel(data.time) }, sentAt) : null),text === '' ? null : h('div', { className: 'bt-utools', 'data-open': toolsOpen || undefined }, h(CopyButton, { text })))}diff --git a/ds-bot/test/message-times.test.js b/ds-bot/test/message-times.test.jsnew file mode 100644index 00000000..42eb4d07--- /dev/null+++ b/ds-bot/test/message-times.test.js@@ -0,0 +1,105 @@+import assert from 'node:assert/strict'+import { test } from 'node:test'+import { dirname } from 'node:path'+import { fileURLToPath } from 'node:url'+import { runInNewContext } from 'node:vm'+import { build } from 'esbuild'++// cells.js and user-message.js import react; the client tests bundle them and stub+// react, as the other client tests do.+const root = dirname(dirname(fileURLToPath(import.meta.url)))+const bundle = await build({+ stdin: {+ contents: "export { AssistantCell } from './src/client/cells.js'\nexport { UserMessageCell } from './src/client/user-message.js'",+ resolveDir: root,+ },+ bundle: true, format: 'cjs', platform: 'node', write: false, logLevel: 'silent',+ external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'],+})+const module = { exports: {} }+runInNewContext(bundle.outputFiles[0].text, {+ module, exports: module.exports, AbortController, fetch,+ require: (name) => {+ const platform = {+ react: {+ createElement: (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat(Infinity) }),+ useState: initial => [initial, () => {}], useEffect: () => {}, useLayoutEffect: () => {}, useRef: current => ({ current }),+ useMemo: make => make(), useCallback: fn => fn, useId: () => 'mt-id',+ useSyncExternalStore: (subscribe, getSnapshot) => getSnapshot(),+ createContext: (initial) => { const ctx = { value: initial }; ctx.Provider = ({ value, children }) => { ctx.value = value; return children }; return ctx },+ useContext: ctx => ctx.value, Fragment: 'fragment',+ },+ 'react-dom': { createPortal: node => node },+ '@deepseek-ai/dsh-client-ui-primitives': { MarkdownText: () => null, projectUserText: text => text },+ }+ if (!(name in platform)) throw new Error('no platform module ' + name)+ return platform[name]+ },+})+const { AssistantCell, UserMessageCell } = module.exports++// Renders the named components of an element tree, leaving the rest as elements.+const expand = (node, names) => {+ if (Array.isArray(node)) return node.flatMap(child => expand(child, names))+ if (node === null || typeof node !== 'object') return node+ if (names.includes(node.type?.name)) return expand(node.type({ ...node.props, children: node.children }), names)+ return { ...node, children: node.children.map(child => expand(child, names)) }+}+const find = (node, match) => {+ if (Array.isArray(node)) return node.flatMap(child => find(child, match))+ if (node === null || typeof node !== 'object') return []+ return [...(match(node) ? [node] : []), ...find(node.children, match)]+}+const times = (node, names = []) => find(expand(node, names), item => item.props?.className === 'bt-utime')++const roster = { bots: [], byId: { b: { id: 'b', name: 'Writer' } }, roomsById: {}, exchangeTurns: {} }+const userProps = (data = {}, sessionId = 'b') => ({+ node: { kind: 'message', data: { content: [{ type: 'text', text: 'hello' }], time: 1_700_000_000_000, ...data } },+ sessionId,+ useRoster: select => select(roster),+ actions: {},+})++test('a user message shows when it was sent, in its own chat as in a group', () => {+ for (const [sessionId, where] of [['b', 'own chat'], ['room-1', 'group']]) {+ const [when] = times(UserMessageCell(userProps({}, sessionId)))+ assert.equal(when.props.className, 'bt-utime', where)+ assert.equal(typeof when.props.title, 'string', where)+ assert.equal(typeof when.children[0], 'string', where)+ }+})++test('a user message without a real time draws no time node', () => {+ assert.equal(times(UserMessageCell(userProps({ time: undefined }))).length, 0)+ assert.equal(times(UserMessageCell(userProps({ time: 'later' }))).length, 0)+})++const assistantProps = (data = {}, rosterPrefs) => ({+ node: {+ key: 'n10',+ location: { kind: 'step', turn: { turn: 3, status: 'closed', end: { time: 2_000 } } },+ data: { turn: 3, step: 1, seq: 10, status: 'done', time: 1_700_000_000_000, blocks: [{ kind: 'text', text: 'Done.' }], ...data },+ },+ sessionId: 'b',+ useRoster: select => select({ ...roster, prefs: rosterPrefs }),+ useUi: () => null,+ useTurnSteps: () => [],+ useTurnContext: () => [],+ actions: { noteLive() {} },+})+const bubbles = node => expand(node, ['Bubbles', 'Bubble', 'SpeakerHead'])++test('a Bot reply in its own chat shows when it went out under the bubbles', () => {+ const [when] = times(bubbles(AssistantCell(assistantProps())))+ assert.equal(when.props.className, 'bt-utime')+ assert.equal(typeof when.props.title, 'string')+ assert.equal(typeof when.children[0], 'string')+})++test('a reply without a real time, and the flat layout whose head already shows one, draw no extra time', () => {+ assert.equal(times(bubbles(AssistantCell(assistantProps({ time: undefined })))).length, 0)+ const flat = bubbles(AssistantCell(assistantProps({}, { layout: 'flat' })))+ // The speaker head keeps the turn's one time; nothing repeats it under the bubbles.+ assert.equal(find(flat, node => node.props?.className === 'bt-group-time').length, 1)+ assert.equal(times(flat).length, 0)+})