Skip to content

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

Restore a way back to chat from other conversation views

Chimneye57c6ee9b012
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 70a0f3d1..1e0b4c16 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -50,6 +50,7 @@ var ZH = {
"Unread activity": "有未读",
Search: "搜索",
"New chat": "新对话",
+ "Back to chat": "返回对话",
"New…": "新建",
"Collapse sidebar": "收起侧边栏",
"Expand sidebar": "展开侧边栏",
@@ -6045,8 +6046,10 @@ function MemoryNotice({ shown }) {
(0, import_react10.createElement)("span", { className: "bt-pill-mem-in", ref: inner }, (0, import_react10.createElement)("span", { className: "bt-pill-mem-ico" }, (0, import_react10.createElement)(MemoryIcon)), label)
);
}
-function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSession, useActivity, useMemoryNews, useTurnClock, useUi, useLive, useWork, actions }) {
+function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSession, useActivity, useMemoryNews, useTurnClock, useUi, useLive, useWork, useStore, useConversationViews, selectView, actions }) {
const roster = useRoster((value) => value);
+ const selectedView = useStore?.((state) => state.view);
+ const away = useConversationViews?.((views) => views.some((view) => view.id === selectedView && view.id !== "chat")) === true && typeof selectView === "function";
const title = useSessions((list) => list.byId[sessionId]?.displayTitle ?? list.byId[sessionId]?.title ?? "");
const firstTurns = useSessions((list) => {
const outline = list.projectionsBySession?.[sessionId]?.values?.turnOutline ?? list.byId[sessionId]?.projectionValues?.turnOutline;
@@ -6088,7 +6091,7 @@ function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSe
delete document.body.dataset.btRoom;
};
}, [Boolean(room2)]);
- const memoryNotice = notice && changed !== null && roster.memory !== false;
+ const memoryNotice = !away && notice && changed !== null && roster.memory !== false;
return (0, import_react10.createElement)(
"div",
{ className: "bt-head" },
@@ -6097,13 +6100,14 @@ function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSe
{
type: "button",
className: "bt-pill",
- "aria-expanded": detailsOpen,
+ "aria-expanded": away ? void 0 : 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)
+ "aria-label": away ? t("Back to chat") : memoryNotice ? t("Memory updated. Open {name}'s memory", { name: roster.byId[changed]?.name ?? name }) : t("View conversation details"),
+ title: away ? name : void 0,
+ onClick: () => away ? selectView("chat") : memoryNotice ? actions.openMemory(changed) : actions.toggleDetails(sessionId)
},
bot ? (0, import_react10.createElement)(BotAvatar, { bot, size: 24, state: botState(running, doing, roster.questions?.[currentPart(bot)] !== void 0), badge: false }) : room2 ? (0, import_react10.createElement)(RoomAvatar, { room: room2, roster, size: 24 }) : null,
- (0, import_react10.createElement)("span", { className: "bt-pill-name" }, bot?.name ?? room2?.name ?? (title || t("New chat"))),
+ (0, import_react10.createElement)("span", { className: "bt-pill-name" }, away ? t("Back to chat") : bot?.name ?? room2?.name ?? (title || t("New chat"))),
(0, import_react10.createElement)(MemoryNotice, { shown: memoryNotice }),
(0, import_react10.createElement)("span", { className: "bt-pill-go", "aria-hidden": true }, (0, import_react10.createElement)(GoArrow))
),
@@ -6645,6 +6649,171 @@ function turnDetector({ loud = 0.12, quiet = 0.06, quietMs = 1200 } = {}) {
};
}
+// src/client/storage.js
+var STORAGE = {
+ unread: "ds-bot:unread",
+ reactions: "ds-bot:reactions",
+ seen: "ds-bot:seen",
+ prefs: "ds-bot:prefs",
+ surface: "ds-bot:surface",
+ agentSessions: "ds-bot:agent-sessions",
+ browserWidth: "ds-bot:browser-width",
+ browsers: "ds-bot.browser.v2"
+};
+var LEGACY_PREFIXES = ["dsh-bot:", "dsh-bot-team:"];
+var LEGACY_BROWSER_KEYS = ["ds-bot.browser.v1", "dsh-bot.browser.v1"];
+var LEGACY_THEMES = { grok: "mono" };
+function legacyKeys(key) {
+ if (key === STORAGE.browsers) return LEGACY_BROWSER_KEYS;
+ const name = key.slice(key.indexOf(":") + 1);
+ return LEGACY_PREFIXES.map((prefix) => `${prefix}${name}`);
+}
+var migrateBrowsers = (storage) => {
+ if (storage.getItem(STORAGE.browsers) !== null) {
+ for (const key of LEGACY_BROWSER_KEYS) storage.removeItem(key);
+ return;
+ }
+ for (const key of LEGACY_BROWSER_KEYS) {
+ try {
+ const value = storage.getItem(key);
+ if (value === null) continue;
+ const previous = JSON.parse(value) ?? {};
+ const tabs = Object.fromEntries(Object.entries(previous).filter(([, page]) => page && typeof page === "object").map(([botId, page]) => {
+ const tab = { id: `v1-${botId}`, url: page.url ?? "", title: page.title ?? "" };
+ return [botId, { tabs: [tab], active: tab.id }];
+ }));
+ storage.setItem(STORAGE.browsers, JSON.stringify(tabs));
+ for (const earlier of LEGACY_BROWSER_KEYS) storage.removeItem(earlier);
+ return;
+ } catch {
+ }
+ }
+};
+function migrateStorage(storage = globalThis.localStorage) {
+ for (const key of Object.values(STORAGE)) {
+ if (key === STORAGE.browsers) continue;
+ for (const legacy of legacyKeys(key)) {
+ try {
+ const value = storage.getItem(legacy);
+ if (value !== null && storage.getItem(key) === null) storage.setItem(key, value);
+ storage.removeItem(legacy);
+ } catch {
+ }
+ }
+ }
+ try {
+ migrateBrowsers(storage);
+ } catch {
+ }
+ try {
+ const prefs = JSON.parse(storage.getItem(STORAGE.prefs) ?? "null");
+ if (prefs && Object.hasOwn(LEGACY_THEMES, prefs.theme ?? "")) {
+ storage.setItem(STORAGE.prefs, JSON.stringify({ ...prefs, theme: LEGACY_THEMES[prefs.theme] }));
+ }
+ } catch {
+ }
+}
+
+// src/client/surface.js
+function groupsFor({ mode, plain = false }) {
+ return { shell: mode === "bot", conversation: mode === "bot" && !plain };
+}
+var GROUPS = ["shell", "conversation"];
+function disposeAll(disposers, label) {
+ for (const dispose of [...disposers].reverse()) {
+ try {
+ dispose?.();
+ } catch (error) {
+ console.warn(`[ds-bot] ${label}`, error);
+ }
+ }
+}
+function surfaceGroups(install, { onError } = {}) {
+ const mounted = { shell: [], conversation: [] };
+ const withdraw = (group) => {
+ const disposers = mounted[group];
+ mounted[group] = [];
+ disposeAll(disposers, `withdraw ${group}`);
+ };
+ return {
+ reconcile(wanted) {
+ for (const group of [...GROUPS].reverse()) if (!wanted[group]) withdraw(group);
+ for (const group of GROUPS) {
+ if (!wanted[group] || mounted[group].length > 0) continue;
+ const disposers = [];
+ try {
+ for (const step of install[group]()) if (step) disposers.push(step());
+ mounted[group] = disposers;
+ } catch (error) {
+ disposeAll(disposers, `roll back ${group}`);
+ console.warn(`[ds-bot] install ${group}`, error);
+ onError?.(group, error);
+ break;
+ }
+ }
+ },
+ dispose() {
+ for (const group of [...GROUPS].reverse()) withdraw(group);
+ }
+ };
+}
+function freePriority(entries2, { priority, key, id }) {
+ if (priority === void 0) return void 0;
+ const taken = entries2.filter((entry) => (key === void 0 || entry.options?.key === key) && (id === void 0 || entry.options?.id === id)).map((entry) => (entry.options?.priority ?? 0) - 1);
+ return Math.min(priority, ...taken);
+}
+function readMode(storage = globalThis.localStorage) {
+ try {
+ return storage.getItem(STORAGE.surface) === "agent" ? "agent" : "bot";
+ } catch {
+ return "bot";
+ }
+}
+function writeMode(mode, storage = globalThis.localStorage) {
+ try {
+ storage.setItem(STORAGE.surface, mode);
+ } catch {
+ }
+}
+
+// src/client/header-navigation.js
+var navigationEntry = (entries2) => entries2.find((entry) => entry.store && typeof entry.inject === "function");
+function headerNavigation(entries2, face) {
+ const source = navigationEntry(entries2);
+ return {
+ ...source ? { store: source.store } : {},
+ inject: (...args) => {
+ const navigation = source?.inject(...args) ?? {};
+ const own = face();
+ return { ...navigation, ...own, hooks: { ...navigation.hooks, ...own.hooks } };
+ }
+ };
+}
+function installHeaderNavigation(slots, face, component, priority) {
+ const name = "conversation.session.header";
+ let source;
+ let dispose;
+ const refresh = () => {
+ const entries2 = slots.entries(name).filter((entry) => entry.component !== component);
+ const next = navigationEntry(entries2);
+ if (dispose && source === next) return;
+ dispose?.();
+ source = next;
+ dispose = slots.register({ name, priority: freePriority(entries2, { priority }), ...headerNavigation(entries2, face) }, component);
+ };
+ const unsubscribe = slots.subscribe(name, refresh);
+ try {
+ refresh();
+ } catch (error) {
+ unsubscribe();
+ throw error;
+ }
+ return () => {
+ unsubscribe();
+ dispose?.();
+ };
+}
+
// src/client/overlay-hooks.js
var import_react12 = require("react");
var escapeLayers = [];
@@ -11937,71 +12106,6 @@ function AgentMenu({ menu, roster, actions, leaving }) {
);
}
-// src/client/storage.js
-var STORAGE = {
- unread: "ds-bot:unread",
- reactions: "ds-bot:reactions",
- seen: "ds-bot:seen",
- prefs: "ds-bot:prefs",
- surface: "ds-bot:surface",
- agentSessions: "ds-bot:agent-sessions",
- browserWidth: "ds-bot:browser-width",
- browsers: "ds-bot.browser.v2"
-};
-var LEGACY_PREFIXES = ["dsh-bot:", "dsh-bot-team:"];
-var LEGACY_BROWSER_KEYS = ["ds-bot.browser.v1", "dsh-bot.browser.v1"];
-var LEGACY_THEMES = { grok: "mono" };
-function legacyKeys(key) {
- if (key === STORAGE.browsers) return LEGACY_BROWSER_KEYS;
- const name = key.slice(key.indexOf(":") + 1);
- return LEGACY_PREFIXES.map((prefix) => `${prefix}${name}`);
-}
-var migrateBrowsers = (storage) => {
- if (storage.getItem(STORAGE.browsers) !== null) {
- for (const key of LEGACY_BROWSER_KEYS) storage.removeItem(key);
- return;
- }
- for (const key of LEGACY_BROWSER_KEYS) {
- try {
- const value = storage.getItem(key);
- if (value === null) continue;
- const previous = JSON.parse(value) ?? {};
- const tabs = Object.fromEntries(Object.entries(previous).filter(([, page]) => page && typeof page === "object").map(([botId, page]) => {
- const tab = { id: `v1-${botId}`, url: page.url ?? "", title: page.title ?? "" };
- return [botId, { tabs: [tab], active: tab.id }];
- }));
- storage.setItem(STORAGE.browsers, JSON.stringify(tabs));
- for (const earlier of LEGACY_BROWSER_KEYS) storage.removeItem(earlier);
- return;
- } catch {
- }
- }
-};
-function migrateStorage(storage = globalThis.localStorage) {
- for (const key of Object.values(STORAGE)) {
- if (key === STORAGE.browsers) continue;
- for (const legacy of legacyKeys(key)) {
- try {
- const value = storage.getItem(legacy);
- if (value !== null && storage.getItem(key) === null) storage.setItem(key, value);
- storage.removeItem(legacy);
- } catch {
- }
- }
- }
- try {
- migrateBrowsers(storage);
- } catch {
- }
- try {
- const prefs = JSON.parse(storage.getItem(STORAGE.prefs) ?? "null");
- if (prefs && Object.hasOwn(LEGACY_THEMES, prefs.theme ?? "")) {
- storage.setItem(STORAGE.prefs, JSON.stringify({ ...prefs, theme: LEGACY_THEMES[prefs.theme] }));
- }
- } catch {
- }
-}
-
// src/client/member-status.js
var import_react33 = require("react");
var NO_WORK = { bots: {}, rooms: {}, approvals: [] };
@@ -14079,68 +14183,6 @@ function serveBrowserReads({ browsers, post, clientId = globalThis.crypto.random
};
}
-// src/client/surface.js
-function groupsFor({ mode, plain = false }) {
- return { shell: mode === "bot", conversation: mode === "bot" && !plain };
-}
-var GROUPS = ["shell", "conversation"];
-function disposeAll(disposers, label) {
- for (const dispose of [...disposers].reverse()) {
- try {
- dispose?.();
- } catch (error) {
- console.warn(`[ds-bot] ${label}`, error);
- }
- }
-}
-function surfaceGroups(install, { onError } = {}) {
- const mounted = { shell: [], conversation: [] };
- const withdraw = (group) => {
- const disposers = mounted[group];
- mounted[group] = [];
- disposeAll(disposers, `withdraw ${group}`);
- };
- return {
- reconcile(wanted) {
- for (const group of [...GROUPS].reverse()) if (!wanted[group]) withdraw(group);
- for (const group of GROUPS) {
- if (!wanted[group] || mounted[group].length > 0) continue;
- const disposers = [];
- try {
- for (const step of install[group]()) if (step) disposers.push(step());
- mounted[group] = disposers;
- } catch (error) {
- disposeAll(disposers, `roll back ${group}`);
- console.warn(`[ds-bot] install ${group}`, error);
- onError?.(group, error);
- break;
- }
- }
- },
- dispose() {
- for (const group of [...GROUPS].reverse()) withdraw(group);
- }
- };
-}
-function freePriority(entries2, { priority, key, id }) {
- if (priority === void 0) return void 0;
- const taken = entries2.filter((entry) => (key === void 0 || entry.options?.key === key) && (id === void 0 || entry.options?.id === id)).map((entry) => (entry.options?.priority ?? 0) - 1);
- return Math.min(priority, ...taken);
-}
-function readMode(storage = globalThis.localStorage) {
- try {
- return storage.getItem(STORAGE.surface) === "agent" ? "agent" : "bot";
- } catch {
- return "bot";
- }
-}
-function writeMode(mode, storage = globalThis.localStorage) {
- try {
- storage.setItem(STORAGE.surface, mode);
- } catch {
- }
-}
-
// src/client/user-message.js
var import_react37 = require("react");
var ui = __toESM(require("@deepseek-ai/dsh-client-ui-primitives"), 1);
@@ -14883,6 +14925,7 @@ function apply(ctx) {
...options,
...options.priority === void 0 ? {} : { priority: freePriority(ctx.slots.entries(name), options) }
}, component));
+ const installHeader = () => ctx.slots.inject("conversation.session.header", () => installHeaderNavigation(ctx.slots, face, HeaderPill, BOT_PRIORITY));
let atMenu = null;
const installAtMenu = () => {
const fiber = ctx.inject(["inputTriggers"], (scope) => {
@@ -14939,7 +14982,7 @@ function apply(ctx) {
() => installCompiledStyles(CONVERSATION_CSS, "conversation"),
() => installMentions(),
() => installAtMenu(),
- () => shadow("conversation.session.header", { priority: BOT_PRIORITY, inject: face }, HeaderPill),
+ installHeader,
() => shadow("conversation.chat.node", { key: "assistant-step", priority: BOT_PRIORITY, locale: "chat", inject: assistantFace }, AssistantCell),
() => shadow("conversation.chat.node", { key: "turn-trigger", priority: BOT_PRIORITY, locale: "chat", inject: face }, TriggerCell),
() => shadow("conversation.chat.node", { key: "tool-call", priority: BOT_PRIORITY, locale: "chat", inject: face }, ToolCell),
diff --git a/ds-bot/src/client/header-navigation.js b/ds-bot/src/client/header-navigation.js
new file mode 100644
index 00000000..dd6296ac
--- /dev/null
+++ b/ds-bot/src/client/header-navigation.js
@@ -0,0 +1,36 @@
+import { freePriority } from './surface.js'
+
+const navigationEntry = entries => entries.find(entry => entry.store && typeof entry.inject === 'function')
+
+// Reuse the replaced header's public navigation face and store: activating a
+// Conversation target alone does not change its persisted View selection.
+export function headerNavigation(entries, face) {
+ const source = navigationEntry(entries)
+ return {
+ ...(source ? { store: source.store } : {}),
+ inject: (...args) => {
+ const navigation = source?.inject(...args) ?? {}
+ const own = face()
+ return { ...navigation, ...own, hooks: { ...navigation.hooks, ...own.hooks } }
+ },
+ }
+}
+
+export function installHeaderNavigation(slots, face, component, priority) {
+ const name = 'conversation.session.header'
+ let source
+ let dispose
+ const refresh = () => {
+ const entries = slots.entries(name).filter(entry => entry.component !== component)
+ const next = navigationEntry(entries)
+ if (dispose && source === next) return
+ dispose?.()
+ source = next
+ dispose = slots.register({ name, priority: freePriority(entries, { priority }), ...headerNavigation(entries, face) }, component)
+ }
+ // Slot declaration precedes the owner's registration. Follow that arrival,
+ // and later host reloads, without treating our own registration as a source.
+ const unsubscribe = slots.subscribe(name, refresh)
+ try { refresh() } catch (error) { unsubscribe(); throw error }
+ return () => { unsubscribe(); dispose?.() }
+}
diff --git a/ds-bot/src/client/header.js b/ds-bot/src/client/header.js
index 4279bd26..8de18db9 100644
--- a/ds-bot/src/client/header.js
+++ b/ds-bot/src/client/header.js
@@ -42,8 +42,11 @@ 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, useWork, actions }) {
+export function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSession, useActivity, useMemoryNews, useTurnClock, useUi, useLive, useWork, useStore, useConversationViews, selectView, actions }) {
const roster = useRoster(value => value)
+ const selectedView = useStore?.(state => state.view)
+ const away = useConversationViews?.(views => views.some(view => view.id === selectedView && view.id !== 'chat')) === true
+ && typeof selectView === 'function'
const title = useSessions(list => list.byId[sessionId]?.displayTitle ?? list.byId[sessionId]?.title ?? '')
const firstTurns = useSessions((list) => {
const outline = list.projectionsBySession?.[sessionId]?.values?.turnOutline ?? list.byId[sessionId]?.projectionValues?.turnOutline
@@ -88,16 +91,17 @@ export function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus
else delete document.body.dataset.btRoom
return () => { delete document.body.dataset.btRoom }
}, [Boolean(room)])
- const memoryNotice = notice && changed !== null && roster.memory !== false
+ const memoryNotice = !away && notice && changed !== null && roster.memory !== false
return h('div', { className: 'bt-head' },
h('button', {
- type: 'button', className: 'bt-pill', 'aria-expanded': detailsOpen, 'data-memory': memoryNotice ? 'updated' : undefined,
- '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)),
+ type: 'button', className: 'bt-pill', 'aria-expanded': away ? undefined : detailsOpen, 'data-memory': memoryNotice ? 'updated' : undefined,
+ 'aria-label': away ? t('Back to chat') : memoryNotice ? t('Memory updated. Open {name}\'s memory', { name: roster.byId[changed]?.name ?? name }) : t('View conversation details'),
+ title: away ? name : undefined,
+ onClick: () => (away ? selectView('chat') : memoryNotice ? actions.openMemory(changed) : actions.toggleDetails(sessionId)),
},
bot ? h(BotAvatar, { bot, size: 24, state: botState(running, doing, roster.questions?.[currentPart(bot)] !== undefined), badge: false })
: room ? h(RoomAvatar, { room, roster, size: 24 }) : null,
- h('span', { className: 'bt-pill-name' }, bot?.name ?? room?.name ?? (title || t('New chat'))),
+ h('span', { className: 'bt-pill-name' }, away ? t('Back to chat') : bot?.name ?? room?.name ?? (title || t('New chat'))),
h(MemoryNotice, { shown: memoryNotice }),
h('span', { className: 'bt-pill-go', 'aria-hidden': true }, h(GoArrow))),
h('span', { className: 'bt-sr', role: 'status' }, memoryNotice ? t('Memory updated') : ''),
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index 0032ebeb..9487ce38 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -13,6 +13,7 @@ const ZH = {
'Unread activity': '有未读',
Search: '搜索',
'New chat': '新对话',
+ 'Back to chat': '返回对话',
'New…': '新建',
'Collapse sidebar': '收起侧边栏',
'Expand sidebar': '展开侧边栏',
diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.js
index 335c5a23..87114de4 100644
--- a/ds-bot/src/client/index.js
+++ b/ds-bot/src/client/index.js
@@ -14,6 +14,7 @@ import { CHATS_SOURCE, atSources } from './at-menu.js'
import { VOICE_BUNDLE } from './speech.js'
import { sameVersion } from './dsh-offer.js'
import { AnsweredCell, QuestionCard, QuestionDock } from './questions.js'
+import { installHeaderNavigation } from './header-navigation.js'
import { AssistantCell, TriggerCell, TurnProcessCell, Nothing, TurnTailCell, ToolCell } from './cells.js'
import { Overlays } from './overlays.js'
import { createBotBrowsers, serveBrowserReads } from './bot-browsers.js'
@@ -595,6 +596,7 @@ export function apply(ctx) {
const shadow = (name, options, component) => ctx.slots.inject(name, () => ctx.slots.register({
name, ...options, ...(options.priority === undefined ? {} : { priority: freePriority(ctx.slots.entries(name), options) }),
}, component))
+ const installHeader = () => ctx.slots.inject('conversation.session.header', () => installHeaderNavigation(ctx.slots, face, HeaderPill, BOT_PRIORITY))
// The "@" menu's Bot group and the chats "+" references. The composer's controller
// for a Session is the shell's own, so the chats open at its caret.
@@ -658,7 +660,7 @@ export function apply(ctx) {
() => installCompiledStyles(CONVERSATION_CSS, 'conversation'),
() => installMentions(),
() => installAtMenu(),
- () => shadow('conversation.session.header', { priority: BOT_PRIORITY, inject: face }, HeaderPill),
+ installHeader,
() => shadow('conversation.chat.node', { key: 'assistant-step', priority: BOT_PRIORITY, locale: 'chat', inject: assistantFace }, AssistantCell),
() => shadow('conversation.chat.node', { key: 'turn-trigger', priority: BOT_PRIORITY, locale: 'chat', inject: face }, TriggerCell),
() => shadow('conversation.chat.node', { key: 'tool-call', priority: BOT_PRIORITY, locale: 'chat', inject: face }, ToolCell),
diff --git a/ds-bot/test/header.test.js b/ds-bot/test/header.test.js
index b9f129cd..20b73fcb 100644
--- a/ds-bot/test/header.test.js
+++ b/ds-bot/test/header.test.js
@@ -3,6 +3,7 @@ import { test } from 'node:test'
import { fileURLToPath } from 'node:url'
import { runInNewContext } from 'node:vm'
import { build } from 'esbuild'
+import { headerNavigation, installHeaderNavigation } from '../src/client/header-navigation.js'
const bundle = await build({
entryPoints: [fileURLToPath(new URL('../src/client/header.js', import.meta.url))],
@@ -26,7 +27,7 @@ const { HeaderPill } = module.exports
const roster = { byId: { a: { id: 'a', name: 'Chief', sessionId: 'a' } }, roomsById: {}, bots: [], exchangeTurns: {}, questions: {} }
const hook = value => select => select(value)
-const header = actions => HeaderPill({
+const header = (actions, navigation = {}) => HeaderPill({
sessionId: 'a',
useRoster: hook(roster),
useSessions: hook({ byId: {} }),
@@ -38,6 +39,7 @@ const header = actions => HeaderPill({
useUi: hook({}),
useLive: hook({}),
actions,
+ ...navigation,
})
const sideButton = (node) => {
if (node === null || typeof node !== 'object') return null
@@ -63,3 +65,95 @@ test('the Bot header has the right sidebar toggle that DSH keeps in the header i
test('without DSH\'s right sidebar the Bot header shows no toggle', () => {
assert.equal(sideButton(header({ hasRightSidebar: () => false, toggleRightSidebar: () => {} })), null)
})
+
+test('a Bot in another Conversation View can return to chat without changing its draft', () => {
+ const state = { view: 'study-workspace', draft: 'Keep this draft', viewRequest: null }
+ const views = [{ id: 'chat' }, { id: 'study-workspace' }]
+ let details = 0
+ const navigation = {
+ useStore: hook(state), useConversationViews: hook(views),
+ selectView: view => { state.view = view },
+ }
+ const actions = { toggleDetails: () => { details += 1 } }
+ const pill = header(actions, navigation).children[0]
+ assert.equal(pill.props['aria-label'], 'Back to chat')
+ assert.equal(pill.props['aria-expanded'], undefined)
+ assert.equal(pill.props.title, 'Chief')
+ pill.props.onClick()
+ assert.equal(state.view, 'chat')
+ assert.equal(state.draft, 'Keep this draft')
+ assert.equal(details, 0)
+ const restored = header(actions, navigation).children[0]
+ assert.equal(restored.props['aria-label'], 'View conversation details')
+ restored.props.onClick()
+ assert.equal(details, 1)
+})
+
+test('a missing View or navigation face keeps the ordinary Bot header', () => {
+ const views = [{ id: 'chat' }, { id: 'trajectory' }]
+ for (const view of [null, 'chat', 'uninstalled-plugin']) {
+ const pill = header({}, { useStore: hook({ view }), useConversationViews: hook(views), selectView() {} }).children[0]
+ assert.equal(pill.props['aria-label'], 'View conversation details')
+ }
+ assert.equal(header({}).children[0].props['aria-label'], 'View conversation details')
+})
+
+test('the replacement header shares DSH\'s store and navigation injection without declaring its children again', () => {
+ const store = {}
+ const views = { getSnapshot: () => [{ id: 'chat' }] }
+ const roster = {}
+ const picked = []
+ const bound = { setView: view => picked.push(view) }
+ const source = { options: {},
+ store,
+ children: { 'conversation.session.header.actions': { kind: 'list', scope: 'session' } },
+ inject: (sessionId, actions) => ({ hooks: { conversationViews: views }, selectView: view => { assert.equal(sessionId, 'a'); actions.setView(view) } }),
+ }
+ const own = { actions: { openMemory() {} }, hooks: { roster } }
+ const options = headerNavigation([{ options: {} }, source], () => own)
+ assert.equal(options.store, store)
+ assert.equal(options.children, undefined)
+ const injected = options.inject('a', bound)
+ assert.equal(injected.hooks.conversationViews, views)
+ assert.equal(injected.hooks.roster, roster)
+ assert.equal(injected.actions, own.actions)
+ injected.selectView('chat')
+ assert.deepEqual(picked, ['chat'])
+ const absent = headerNavigation([], () => own)
+ assert.equal(absent.store, undefined)
+ assert.deepEqual(absent.inject('a'), own)
+})
+
+test('the Bot header follows a later host header registration and releases its subscription', () => {
+ const entries = []
+ const listeners = new Set()
+ let registrations = 0
+ const slots = {
+ entries: () => entries,
+ subscribe: (_name, listener) => { listeners.add(listener); return () => listeners.delete(listener) },
+ register: ({ priority, store, inject }, component) => {
+ registrations += 1
+ const entry = { options: { priority }, store, inject, component }
+ entries.push(entry)
+ return () => { const at = entries.indexOf(entry); if (at !== -1) entries.splice(at, 1) }
+ },
+ }
+ const changed = () => { for (const listener of listeners) listener() }
+ const own = { hooks: {}, actions: {} }
+ const stop = installHeaderNavigation(slots, () => own, HeaderPill, -100)
+ assert.equal(entries[0].store, undefined)
+ const store = {}
+ const host = { options: { priority: 0 }, component() {}, store, inject: () => ({ selectView() {} }) }
+ entries.push(host)
+ changed()
+ assert.equal(entries.find(entry => entry.component === HeaderPill).store, store)
+ assert.equal(registrations, 2)
+ changed()
+ assert.equal(registrations, 2, 'the replacement does not react to its own registration')
+ entries.splice(entries.indexOf(host), 1)
+ changed()
+ assert.equal(entries[0].store, undefined, 'a removed host releases its old navigation face')
+ stop()
+ assert.equal(entries.length, 0)
+ assert.equal(listeners.size, 0)
+})