Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Tell the desktop app when the team view has drawn

AdamPlatin1237afb3d8d0f8a
diff --git a/ds-bot/client.js b/ds-bot/client.js
index fb6153f5..aee3dc74 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -8605,6 +8605,7 @@ function TeamSidebar(props) {
const main = roster.byId[roster.mainBotId];
useListGlide(listRef, wide, order.map((entry) => entry.item.id).join(","));
useLandOnMainBot(roster, useSessions, actions);
+ useReportReady(roster.ready);
const navigate = (open, id) => {
const result = open(id);
if (wide && window.innerWidth < 1024 && !closing.current) {
@@ -9013,6 +9014,14 @@ function AccountLauncher({ seat = true, settingsOpen, openSettings, openOnboardi
), document.body) : null
);
}
+var readyReported = false;
+function useReportReady(drawn) {
+ (0, import_react14.useEffect)(() => {
+ if (!drawn || readyReported) return;
+ readyReported = true;
+ void Promise.resolve().then(() => globalThis.dsBotApp?.ready?.()).catch(quietly("app ready"));
+ }, [drawn]);
+}
function useLandOnMainBot(roster, useSessions, actions) {
const mainView = useSessions((list) => {
const row = Object.values(list.byId).find((session) => (session?.retainedBy?.mainView ?? 0) > 0);
@@ -9042,8 +9051,10 @@ function FooterAccount(props) {
if (seated) return null;
return (0, import_react14.createElement)("span", { className: "bt-foot-account" }, (0, import_react14.createElement)(AccountLauncher, { ...props, seat: false }));
}
-function BotReturn({ wide, useSurface, actions }) {
+function BotReturn({ wide, useSurface, useRoster, actions }) {
const mode = useSurface((value) => value.mode);
+ const ready = useRoster((value) => value.ready);
+ useReportReady(mode === "agent" && ready);
if (mode !== "agent") return null;
return (0, import_react14.createElement)(
"button",
diff --git a/ds-bot/src/client/sidebar.js b/ds-bot/src/client/sidebar.js
index 62a34ece..e699bb48 100644
--- a/ds-bot/src/client/sidebar.js
+++ b/ds-bot/src/client/sidebar.js
@@ -11,6 +11,7 @@ import { Shimmer, workPhrase } from './cells.js'
import { springEasing, SPRING_SHAPE, useViewport, viewBottom } from './motion.js'
import { hostText, t } from './i18n.js'
import { showsDshRow } from './dsh-offer.js'
+import { quietly } from './diagnostics.js'
// -------------------------------------------------------------------------
// Sidebar
@@ -274,6 +275,7 @@ export function TeamSidebar(props) {
const main = roster.byId[roster.mainBotId]
useListGlide(listRef, wide, order.map(entry => entry.item.id).join(','))
useLandOnMainBot(roster, useSessions, actions)
+ useReportReady(roster.ready)
// The shell keeps wide content during its collapse fade. Normalize through its
// public expansion action before toggling; coalesce synchronous activations
// until React commits the result.
@@ -626,6 +628,17 @@ export function AccountLauncher({ seat = true, settingsOpen, openSettings, openO
}, h(Icon), h('span', { className: 'bt-menu-label' }, label), hint ? h('span', { className: 'bt-menu-hint' }, hint) : null))))), document.body) : null)
}
+// The desktop app keeps its main window hidden until the team interface has drawn
+// the first state, and shows its failure page when that never comes.
+let readyReported = false
+function useReportReady(drawn) {
+ useEffect(() => {
+ if (!drawn || readyReported) return
+ readyReported = true
+ void Promise.resolve().then(() => globalThis.dsBotApp?.ready?.()).catch(quietly('app ready'))
+ }, [drawn])
+}
+
// Opens the Main Bot whenever the main view holds no Bot conversation, the way
// The view always lands on a Bot rather than an empty New Session page.
// When a Bot's chat moves on to a fresh part, the shell clears the view of the part
@@ -664,8 +677,11 @@ export function FooterAccount(props) {
// The only entry registered in every mode: in Agent mode the whole Bot surface is
// withdrawn, and this button in the shell's own footer is the way back.
-export function BotReturn({ wide, useSurface, actions }) {
+export function BotReturn({ wide, useSurface, useRoster, actions }) {
const mode = useSurface(value => value.mode)
+ const ready = useRoster(value => value.ready)
+ // Agent mode draws no team sidebar; there this button is the team interface.
+ useReportReady(mode === 'agent' && ready)
if (mode !== 'agent') return null
return h('button', { type: 'button', className: 'bt-return', 'aria-label': t('DS Bot'), title: t('DS Bot'), onClick: () => actions.setSurface('bot') },
h(BotMark, { look: MAIN_LOOK, size: 20 }),
diff --git a/ds-bot/test/app-ready.test.js b/ds-bot/test/app-ready.test.js
new file mode 100644
index 00000000..555d8b3c
--- /dev/null
+++ b/ds-bot/test/app-ready.test.js
@@ -0,0 +1,125 @@
+import { test } from 'node:test'
+import assert from 'node:assert/strict'
+import { dirname } from 'node:path'
+import { setImmediate } from 'node:timers/promises'
+import { fileURLToPath } from 'node:url'
+import { runInNewContext } from 'node:vm'
+import { build } from 'esbuild'
+
+// The sidebar imports the browser's React; bundle it with a minimal stand-in, as the
+// sidebar tests do: components run as plain functions, and each mounted one keeps its
+// refs and runs an effect after a render when the effect's dependencies changed.
+const PLUGIN = dirname(dirname(fileURLToPath(import.meta.url)))
+const { outputFiles } = await build({
+ stdin: {
+ contents: "export { BotReturn, TeamSidebar } from './src/client/sidebar.js'\nexport { clientErrors } from './src/client/diagnostics.js'",
+ resolveDir: PLUGIN,
+ },
+ bundle: true, format: 'cjs', platform: 'browser', write: false, logLevel: 'silent',
+ external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'],
+})
+
+let hooks
+const react = {
+ createElement: (type, props, ...children) => ({ type, props: { ...props, children } }), Fragment: Symbol('Fragment'),
+ useRef: initial => hooks.ref(initial), useEffect: (run, deps) => hooks.effect(run, deps), useLayoutEffect() {},
+ useMemo: make => make(), useState: initial => [initial, () => {}], useId: () => 'id',
+}
+
+function mount(component) {
+ const slots = []
+ return (props) => {
+ let at = 0
+ const effects = []
+ hooks = {
+ ref: initial => (slots[at++] ??= { current: initial }),
+ effect: (run, deps) => {
+ const i = at++
+ if (slots[i] !== undefined && deps.every((value, index) => value === slots[i][index])) return
+ slots[i] = deps
+ effects.push(run)
+ },
+ }
+ const tree = component(props)
+ hooks = undefined
+ for (const run of effects) run()
+ return tree
+ }
+}
+
+// One page load: a fresh copy of the client modules, under the app bridge it was given.
+function page(dsBotApp) {
+ const module = { exports: {} }
+ runInNewContext(outputFiles[0].text, {
+ module, exports: module.exports,
+ require: name => (name === 'react' ? react : {}),
+ window: { innerWidth: 1280 },
+ setTimeout: () => 0, clearTimeout() {},
+ ...(dsBotApp === undefined ? {} : { dsBotApp }),
+ })
+ return module.exports
+}
+
+const BEFORE_STATE = { ready: false, mainBotId: null, bots: [], rooms: [], agents: [], byId: {}, roomsById: {}, agentOf: {} }
+const main = { id: 'main', name: 'DeepSeek', createdAt: 1 }
+const TEAM = { ...BEFORE_STATE, ready: true, revision: 1, mainBotId: 'main', mainBotIds: ['main'], bots: [main], byId: { main } }
+
+const sidebarProps = roster => ({
+ wide: true, actions: { landOn() {} },
+ useRoster: pick => pick(roster), useUi: pick => pick({ unread: {} }), useRegistry: pick => pick({}),
+ useSessions: pick => pick({ ids: [], byId: {} }), useUpdate: () => ({}),
+})
+const returnProps = (mode, roster) => ({ wide: true, actions: {}, useSurface: pick => pick({ mode }), useRoster: pick => pick(roster) })
+
+function readyCalls() {
+ const calls = []
+ return { calls, app: { ready: (...args) => { calls.push(args) } } }
+}
+
+test('the desktop app hears once that the team sidebar drew the first state', async () => {
+ const { calls, app } = readyCalls()
+ const { TeamSidebar } = page(app)
+ const sidebar = mount(TeamSidebar)
+ sidebar(sidebarProps(BEFORE_STATE))
+ await setImmediate()
+ assert.deepEqual(calls, [], 'the sidebar is not ready before the first state')
+ sidebar(sidebarProps(TEAM))
+ await setImmediate()
+ assert.deepEqual(calls, [[]])
+ sidebar(sidebarProps({ ...TEAM, revision: 2 }))
+ mount(TeamSidebar)(sidebarProps(TEAM))
+ await setImmediate()
+ assert.deepEqual(calls, [[]], 'later states and a second mount report nothing more')
+})
+
+test('in Agent mode the return button reports what the team sidebar would', async () => {
+ const { calls, app } = readyCalls()
+ const { BotReturn, TeamSidebar } = page(app)
+ const button = mount(BotReturn)
+ assert.equal(button(returnProps('bot', TEAM)), null)
+ button(returnProps('agent', BEFORE_STATE))
+ await setImmediate()
+ assert.deepEqual(calls, [])
+ button(returnProps('agent', TEAM))
+ mount(TeamSidebar)(sidebarProps(TEAM))
+ await setImmediate()
+ assert.deepEqual(calls, [[]])
+})
+
+test('without the app bridge or its ready() the sidebar draws as before', async () => {
+ for (const app of [undefined, {}]) {
+ const { TeamSidebar, clientErrors } = page(app)
+ const tree = mount(TeamSidebar)(sidebarProps(TEAM))
+ await setImmediate()
+ assert.equal(tree.props.className, 'bt-side')
+ assert.equal(clientErrors().length, 0)
+ }
+})
+
+test('a ready() that throws is noted and the sidebar stays', async () => {
+ const { TeamSidebar, clientErrors } = page({ ready: () => { throw new Error('bridge gone') } })
+ const tree = mount(TeamSidebar)(sidebarProps(TEAM))
+ await setImmediate()
+ assert.equal(tree.props.className, 'bt-side')
+ assert.deepEqual(Array.from(clientErrors(), entry => entry.text), ['app ready: bridge gone'])
+})