A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Let a window read DSH's figures for a Bot's chat
Fei24110ce8dd16ed9c
diff --git a/ds-bot/src/host/channel.js b/ds-bot/src/host/channel.jsindex 7728a237..b880f38f 100644--- a/ds-bot/src/host/channel.js+++ b/ds-bot/src/host/channel.js@@ -5,6 +5,7 @@ import { questionReply } from './parts.js'import { COLORS, EXTRA_COLORS, ROUTE } from './constants.js'const LANGUAGES = { zh: 'Chinese (简体中文)', en: 'English' }+const RUN_STATS = ['sessionStats', 'tokenUsage', 'contextPressure']const invalid = message => Object.assign(new Error(message), { code: 'bot/invalid' })// Programming and file system errors are DS Bot's own faults, logged with their stack;@@ -80,7 +81,7 @@ export function install(rt) {})// What a host that only reads the team may still answer.// Updates change the dsh profile, not the team, so a reading host may run them too.- const READS = new Set(['state', 'models', 'efforts', 'earlier', 'chat', 'room-progress', 'exchange', 'exchange-text', 'file-text', 'usage', 'schedules', 'memory-view', 'browser-wait', 'browser-result', 'diagnostics', 'diagnostics-log', 'diagnostics-clear', 'update-check', 'update-install', 'dsh-update-install', 'repo-stars', 'approval-answer'])+ const READS = new Set(['state', 'models', 'efforts', 'earlier', 'chat', 'run-stats', 'room-progress', 'exchange', 'exchange-text', 'file-text', 'usage', 'schedules', 'memory-view', 'browser-wait', 'browser-result', 'diagnostics', 'diagnostics-log', 'diagnostics-clear', 'update-check', 'update-install', 'dsh-update-install', 'repo-stars', 'approval-answer'])function setPrefs(body) {if (body.theme !== undefined) {@@ -149,6 +150,17 @@ export function install(rt) {case 'chat':await rt.load()return ok(await rt.chatPage(String(body.botId ?? ''), body.cursor ?? undefined))+ // DSH's own whole-log figures for the current part of a Bot's chat, the ones its+ // status bar shows; a window without that bar shows them in the Bot's details.+ case 'run-stats': {+ await rt.load()+ const bot = rt.botOf(String(body.botId ?? ''))+ if (bot === undefined) return fail('Unknown Bot', 'bot/not-found')+ const projections = ctx.get?.('sessionProjections')+ if (projections === undefined) return ok(null)+ const agent = await rt.resolveAgent(rt.chatOf(bot.id))+ return ok(projections.snapshot(agent.session, RUN_STATS).values)+ }case 'usage':await rt.load()return ok(await rt.usageView({ timeZone: typeof body.timeZone === 'string' ? body.timeZone.slice(0, 64) : undefined }))diff --git a/ds-bot/test/feed.test.js b/ds-bot/test/feed.test.jsindex 2ef7b4d1..d664c5d7 100644--- a/ds-bot/test/feed.test.js+++ b/ds-bot/test/feed.test.js@@ -24,10 +24,10 @@ const TEAM = {const userMessage = (text, time) => ({ type: 'user/message', time, data: { source: { kind: 'user' }, content: [{ type: 'text', text }] } })const botMessage = (text, time, turn = 1) => ({ type: 'assistant/message', time, data: { turn, message: { content: [{ type: 'text', text }] } } })-function start({ pages = {} } = {}) {+function start({ pages = {}, services = {} } = {}) {const home = mkdtempSync(join(tmpdir(), 'ds-bot-feed-'))writeFileSync(join(home, 'state.json'), JSON.stringify(TEAM))- const ctx = fakeContext()+ const ctx = fakeContext({ services })ctx.sessionController = {resolveAgent: async sessionId => ({ agent: { session: { id: sessionId, seq: 100 } } }),// Two pages per Session, newest first, keyed by the cursor that asks for them.@@ -161,3 +161,27 @@ test('the chat endpoint pages a Bot\'s own chat from the newest part back', asynassert.deepEqual([third.items, third.cursor], [[{ kind: 'user', text: 'long ago', time: 5 }], null])assert.equal((await call('chat', { botId: 'nobody' })).error.code, 'bot/not-found')})++test('the run-stats endpoint reads DSH\'s figures for the current part of a Bot\'s chat', async (t) => {+ const views = { sessionStats: { turns: 3 }, tokenUsage: { cacheReadTokens: 9 }, contextPressure: { contextWindow: 100 } }+ const read = []+ const sessionProjections = {+ snapshot: (session, keys) => {+ read.push([session.id, keys])+ return { asOfSeq: 7, values: views }+ },+ }+ const { call, stop } = start({ services: { sessionProjections } })+ t.after(stop)+ await call('state')+ assert.deepEqual((await call('run-stats', { botId: 'm1' })).value, views)+ assert.deepEqual(read, [['m1c', ['sessionStats', 'tokenUsage', 'contextPressure']]])+ assert.equal((await call('run-stats', { botId: 'nobody' })).error.code, 'bot/not-found')+})++test('without DSH\'s session projections the run-stats endpoint has nothing to show', async (t) => {+ const { call, stop } = start()+ t.after(stop)+ await call('state')+ assert.deepEqual(await call('run-stats', { botId: 'm1' }), { ok: true, value: null })+})