A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Install each Bot surface group whole or not at all
Fei24119236f90d86fa
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 9b5e894a..408642f9 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -128,6 +128,7 @@ var ZH = {"Repositories, issues, and pull requests": "仓库、issue 和 PR","Connecting…": "正在连接…","Could not connect: {error}": "连接失败:{error}",+ "Bot mode could not be set up here: {error}": "这里无法启用 Bot 模式:{error}","Connected as {account}": "已连接:{account}",Connected: "已连接",Disconnect: "断开",@@ -13166,7 +13167,7 @@ function disposeAll(disposers, label) {}}}-function surfaceGroups(install) {+function surfaceGroups(install, { onError } = {}) {const mounted = { shell: [], conversation: [] };const withdraw = (group) => {const disposers = mounted[group];@@ -13178,10 +13179,15 @@ function surfaceGroups(install) {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 {- mounted[group] = install[group]();+ 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;}}},@@ -13190,6 +13196,11 @@ function surfaceGroups(install) {}};}+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";@@ -14088,7 +14099,12 @@ function apply(ctx) {}} };};- const shadow = (name, options, component) => ctx.slots.inject(name, () => ctx.slots.register({ name, ...options }, component));+ const BOT_PRIORITY = -100;+ const shadow = (name, options, component) => ctx.slots.inject(name, () => ctx.slots.register({+ name,+ ...options,+ ...options.priority === void 0 ? {} : { priority: freePriority(ctx.slots.entries(name), options) }+ }, component));let atMenu = null;const installAtMenu = () => {const fiber = ctx.inject(["inputTriggers"], (scope) => {@@ -14116,65 +14132,65 @@ function apply(ctx) {controller.toggleSource(CHATS_SOURCE, { trigger: "@", query: "", quoted: false, position: "inline", span });};const installShell = () => [- installCompiledStyles(SHELL_CSS, "shell"),- installCompiledStyles(SIDEBAR_CSS, "sidebar"),- installCompiledStyles(SECRET_CSS, "secrets"),- installCompiledStyles(MODEL_CSS + FOLDER_CSS + BOT_SETTINGS_CSS + GROUP_SETTINGS_CSS, "models"),- installCompiledStyles(USAGE_CSS, "usage"),- installCompiledStyles(SCHEDULE_CSS, "schedules"),- installCompiledStyles(FEEDBACK_CSS, "feedback"),- installCompiledStyles(ABOUT_CSS, "about"),- installCompiledStyles(MEMBER_CSS, "members"),- installCompiledStyles(USER_MESSAGE_CSS, "user-messages"),- browsers ? installCompiledStyles(BROWSER_CSS, "browser") : null,- installTheme(),- shadow("sidebar.workspaces", { priority: -10, inject: face }, TeamSidebar),- shadow("sidebar.brand.mark", { priority: -10 }, BrandMark),- shadow("sidebar.brand.name", { priority: -10 }, BrandName),- shadow("sidebar.footer.action", { id: "bot-account", order: -200, inject: face }, FooterAccount),- shadow("sidebar.footer.action", { id: "bot-connect", order: -100, inject: face }, ConnectPlugins),- shadow("settings.trigger", { priority: -10 }, YouAvatar),- // At priority -10 the whale wins the seat over a shell account plugin's own- // launcher (the Desktop's "··· More"), which comes back in Agent mode.- shadow("settings.launcher", { priority: -10, inject: face }, AccountLauncher),- shadow("shell.overlay", { id: "bot", order: 50, inject: face }, Overlays),- shadow("shell.overlay", { id: "bot-signin", order: 55, inject: face }, DeepSeekSignIn),- shadow("shell.overlay", { id: "bot-toast", order: 60, inject: face }, ErrorToast)+ () => installCompiledStyles(SHELL_CSS, "shell"),+ () => installCompiledStyles(SIDEBAR_CSS, "sidebar"),+ () => installCompiledStyles(SECRET_CSS, "secrets"),+ () => installCompiledStyles(MODEL_CSS + FOLDER_CSS + BOT_SETTINGS_CSS + GROUP_SETTINGS_CSS, "models"),+ () => installCompiledStyles(USAGE_CSS, "usage"),+ () => installCompiledStyles(SCHEDULE_CSS, "schedules"),+ () => installCompiledStyles(FEEDBACK_CSS, "feedback"),+ () => installCompiledStyles(ABOUT_CSS, "about"),+ () => installCompiledStyles(MEMBER_CSS, "members"),+ () => installCompiledStyles(USER_MESSAGE_CSS, "user-messages"),+ browsers ? () => installCompiledStyles(BROWSER_CSS, "browser") : null,+ () => installTheme(),+ () => shadow("sidebar.workspaces", { priority: BOT_PRIORITY, inject: face }, TeamSidebar),+ () => shadow("sidebar.brand.mark", { priority: BOT_PRIORITY }, BrandMark),+ () => shadow("sidebar.brand.name", { priority: BOT_PRIORITY }, BrandName),+ () => shadow("sidebar.footer.action", { id: "bot-account", order: -200, inject: face }, FooterAccount),+ () => shadow("sidebar.footer.action", { id: "bot-connect", order: -100, inject: face }, ConnectPlugins),+ () => shadow("settings.trigger", { priority: BOT_PRIORITY }, YouAvatar),+ // The whale wins the seat over a shell account plugin's own launcher (the+ // Desktop's "··· More"), which comes back in Agent mode.+ () => shadow("settings.launcher", { priority: BOT_PRIORITY, inject: face }, AccountLauncher),+ () => shadow("shell.overlay", { id: "bot", order: 50, inject: face }, Overlays),+ () => shadow("shell.overlay", { id: "bot-signin", order: 55, inject: face }, DeepSeekSignIn),+ () => shadow("shell.overlay", { id: "bot-toast", order: 60, inject: face }, ErrorToast)];const installConversation = () => [- installCompiledStyles(CONVERSATION_CSS, "conversation"),- installMentions(),- installAtMenu(),- shadow("conversation.session.header", { priority: -10, inject: face }, HeaderPill),- shadow("conversation.chat.node", { key: "assistant-step", priority: -10, locale: "chat", inject: assistantFace }, AssistantCell),- shadow("conversation.chat.node", { key: "turn-trigger", priority: -10, locale: "chat", inject: face }, TriggerCell),- shadow("conversation.chat.node", { key: "tool-call", priority: -10, locale: "chat", inject: face }, ToolCell),- shadow("conversation.chat.node", { key: "turn-process", priority: -10, locale: "chat", inject: face }, TurnProcessCell),+ () => installCompiledStyles(CONVERSATION_CSS, "conversation"),+ () => installMentions(),+ () => installAtMenu(),+ () => shadow("conversation.session.header", { priority: BOT_PRIORITY, inject: face }, HeaderPill),+ () => 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),+ () => shadow("conversation.chat.node", { key: "turn-process", priority: BOT_PRIORITY, locale: "chat", inject: face }, TurnProcessCell),// DSH's own turn tail stays, so what other plugins add there shows, such as the// cards of the files a turn delivered; its copy and branch row is hidden.- shadow("conversation.chat.turnTail", { id: "bot-turn-separators", order: 1e3, inject: face }, TurnTailCell),+ () => shadow("conversation.chat.turnTail", { id: "bot-turn-separators", order: 1e3, inject: face }, TurnTailCell),// A Bot condenses its conversation without telling anyone; the chat keeps showing// every message.- shadow("conversation.chat.node", { key: "question-reply", priority: -10, locale: "chat" }, AnsweredCell),- shadow("conversation.chat.node", { key: "compaction", priority: -10, locale: "chat" }, Nothing),- ...canDrawUserMessages() ? ["user", "steering"].map((key) => shadow("conversation.chat.node", { key, priority: -10, locale: "chat", inject: face }, UserMessageCell)) : [],- shadow("conversation.input.permission", { priority: -10 }, Nothing),- shadow("conversation.input.plan", { priority: -10 }, Nothing),+ () => shadow("conversation.chat.node", { key: "question-reply", priority: BOT_PRIORITY, locale: "chat" }, AnsweredCell),+ () => shadow("conversation.chat.node", { key: "compaction", priority: BOT_PRIORITY, locale: "chat" }, Nothing),+ ...canDrawUserMessages() ? ["user", "steering"].map((key) => () => shadow("conversation.chat.node", { key, priority: BOT_PRIORITY, locale: "chat", inject: face }, UserMessageCell)) : [],+ () => shadow("conversation.input.permission", { priority: BOT_PRIORITY }, Nothing),+ () => shadow("conversation.input.plan", { priority: BOT_PRIORITY }, Nothing),// The composer carries no model picker or run statistics; a Bot's model lives// in its details panel.- shadow("conversation.input.model", { priority: -10 }, Nothing),- shadow("conversation.composer.dock", { id: "activity", order: 0, priority: -10 }, Nothing),- shadow("conversation.composer.dock", { id: "usage", order: 1, priority: -10 }, Nothing),- shadow("conversation.input.left", { id: "bot-plus", order: -100, inject: face }, ComposerPlus),- shadow("conversation.input.right", { id: "bot-voice", order: 100, inject: face }, ComposerVoice),- shadow("conversation.composer", {- priority: -10,+ () => shadow("conversation.input.model", { priority: BOT_PRIORITY }, Nothing),+ () => shadow("conversation.composer.dock", { id: "activity", order: 0, priority: BOT_PRIORITY }, Nothing),+ () => shadow("conversation.composer.dock", { id: "usage", order: 1, priority: BOT_PRIORITY }, Nothing),+ () => shadow("conversation.input.left", { id: "bot-plus", order: -100, inject: face }, ComposerPlus),+ () => shadow("conversation.input.right", { id: "bot-voice", order: 100, inject: face }, ComposerVoice),+ () => shadow("conversation.composer", {+ priority: BOT_PRIORITY,select: (owner) => owner.pendingInteraction?.kind === "question" ? owner.pendingInteraction : null}, QuestionCard),- shadow("conversation.input.dock", { id: "bot-members", order: -120, inject: face }, MemberDock),- shadow("conversation.input.dock", { id: "bot-model", order: -110, inject: face }, ModelChoiceDock),- shadow("conversation.input.dock", { id: "bot-question", order: -100, inject: face }, QuestionDock),- shadow("conversation.input.dock", { id: "bot-secret", order: -90, inject: face }, SecretDock)+ () => shadow("conversation.input.dock", { id: "bot-members", order: -120, inject: face }, MemberDock),+ () => shadow("conversation.input.dock", { id: "bot-model", order: -110, inject: face }, ModelChoiceDock),+ () => shadow("conversation.input.dock", { id: "bot-question", order: -100, inject: face }, QuestionDock),+ () => shadow("conversation.input.dock", { id: "bot-secret", order: -90, inject: face }, SecretDock)];ctx.effect(() => {const style = installStyles(RETURN_CSS, "return");@@ -14227,7 +14243,9 @@ function apply(ctx) {};}, "ds-bot: agent surface");ctx.effect(() => {- const groups = surfaceGroups({ shell: installShell, conversation: installConversation });+ const groups = surfaceGroups({ shell: installShell, conversation: installConversation }, {+ onError: (_group, error) => actions.reportError(new Error(t("Bot mode could not be set up here: {error}", { error: error?.message ?? String(error) })), "surface")+ });const reconcile = () => groups.reconcile(groupsFor(surface.getSnapshot()));reconcile();const unsub = surface.subscribe(reconcile);diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.jsindex 83b39980..165d91d1 100644--- a/ds-bot/src/client/i18n.js+++ b/ds-bot/src/client/i18n.js@@ -92,6 +92,7 @@ const ZH = {'Repositories, issues, and pull requests': '仓库、issue 和 PR','Connecting…': '正在连接…','Could not connect: {error}': '连接失败:{error}',+ 'Bot mode could not be set up here: {error}': '这里无法启用 Bot 模式:{error}','Connected as {account}': '已连接:{account}',Connected: '已连接',Disconnect: '断开',diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.jsindex 203345b2..b23497aa 100644--- a/ds-bot/src/client/index.js+++ b/ds-bot/src/client/index.js@@ -25,8 +25,8 @@ import { FOLDER_CSS } from './folder-menu.js'import { USAGE_CSS } from './usage-page.js'import { SCHEDULE_CSS } from './schedules.js'import { STORAGE, migrateStorage } from './storage.js'-import { groupsFor, readMode, surfaceGroups, writeMode } from './surface.js'-import { installLocale, language } from './i18n.js'+import { freePriority, groupsFor, readMode, surfaceGroups, writeMode } from './surface.js'+import { installLocale, language, t } from './i18n.js'import { noteClientError, quietly } from './diagnostics.js'import { ErrorToast, FEEDBACK_CSS } from './feedback.js'import { ABOUT_CSS } from './about.js'@@ -714,7 +714,13 @@ export function apply(ctx) {} }}- const shadow = (name, options, component) => ctx.slots.inject(name, () => ctx.slots.register({ name, ...options }, component))+ // A Bot surface owns the cells it shadows. It starts far below the -10 that plugins+ // commonly use and goes below whatever already holds the cell, so a plugin that+ // shadows the same cell neither breaks the install nor shows through.+ const BOT_PRIORITY = -100+ 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))// 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.@@ -746,68 +752,68 @@ export function apply(ctx) {}// The shell group paints the team surface around the session; the conversation- // group re-skins the session itself. Every disposer comes from slots.inject, so a- // surface change withdraws the whole group and the outlets re-render.+ // group re-skins the session itself. Each step returns a disposer from slots.inject,+ // so a surface change withdraws the whole group and the outlets re-render.const installShell = () => [- installCompiledStyles(SHELL_CSS, 'shell'),- installCompiledStyles(SIDEBAR_CSS, 'sidebar'),- installCompiledStyles(SECRET_CSS, 'secrets'),- installCompiledStyles(MODEL_CSS + FOLDER_CSS + BOT_SETTINGS_CSS + GROUP_SETTINGS_CSS, 'models'),- installCompiledStyles(USAGE_CSS, 'usage'),- installCompiledStyles(SCHEDULE_CSS, 'schedules'),- installCompiledStyles(FEEDBACK_CSS, 'feedback'),- installCompiledStyles(ABOUT_CSS, 'about'),- installCompiledStyles(MEMBER_CSS, 'members'),- installCompiledStyles(USER_MESSAGE_CSS, 'user-messages'),- browsers ? installCompiledStyles(BROWSER_CSS, 'browser') : null,- installTheme(),- shadow('sidebar.workspaces', { priority: -10, inject: face }, TeamSidebar),- shadow('sidebar.brand.mark', { priority: -10 }, BrandMark),- shadow('sidebar.brand.name', { priority: -10 }, BrandName),- shadow('sidebar.footer.action', { id: 'bot-account', order: -200, inject: face }, FooterAccount),- shadow('sidebar.footer.action', { id: 'bot-connect', order: -100, inject: face }, ConnectPlugins),- shadow('settings.trigger', { priority: -10 }, YouAvatar),- // At priority -10 the whale wins the seat over a shell account plugin's own- // launcher (the Desktop's "··· More"), which comes back in Agent mode.- shadow('settings.launcher', { priority: -10, inject: face }, AccountLauncher),- shadow('shell.overlay', { id: 'bot', order: 50, inject: face }, Overlays),- shadow('shell.overlay', { id: 'bot-signin', order: 55, inject: face }, DeepSeekSignIn),- shadow('shell.overlay', { id: 'bot-toast', order: 60, inject: face }, ErrorToast),+ () => installCompiledStyles(SHELL_CSS, 'shell'),+ () => installCompiledStyles(SIDEBAR_CSS, 'sidebar'),+ () => installCompiledStyles(SECRET_CSS, 'secrets'),+ () => installCompiledStyles(MODEL_CSS + FOLDER_CSS + BOT_SETTINGS_CSS + GROUP_SETTINGS_CSS, 'models'),+ () => installCompiledStyles(USAGE_CSS, 'usage'),+ () => installCompiledStyles(SCHEDULE_CSS, 'schedules'),+ () => installCompiledStyles(FEEDBACK_CSS, 'feedback'),+ () => installCompiledStyles(ABOUT_CSS, 'about'),+ () => installCompiledStyles(MEMBER_CSS, 'members'),+ () => installCompiledStyles(USER_MESSAGE_CSS, 'user-messages'),+ browsers ? () => installCompiledStyles(BROWSER_CSS, 'browser') : null,+ () => installTheme(),+ () => shadow('sidebar.workspaces', { priority: BOT_PRIORITY, inject: face }, TeamSidebar),+ () => shadow('sidebar.brand.mark', { priority: BOT_PRIORITY }, BrandMark),+ () => shadow('sidebar.brand.name', { priority: BOT_PRIORITY }, BrandName),+ () => shadow('sidebar.footer.action', { id: 'bot-account', order: -200, inject: face }, FooterAccount),+ () => shadow('sidebar.footer.action', { id: 'bot-connect', order: -100, inject: face }, ConnectPlugins),+ () => shadow('settings.trigger', { priority: BOT_PRIORITY }, YouAvatar),+ // The whale wins the seat over a shell account plugin's own launcher (the+ // Desktop's "··· More"), which comes back in Agent mode.+ () => shadow('settings.launcher', { priority: BOT_PRIORITY, inject: face }, AccountLauncher),+ () => shadow('shell.overlay', { id: 'bot', order: 50, inject: face }, Overlays),+ () => shadow('shell.overlay', { id: 'bot-signin', order: 55, inject: face }, DeepSeekSignIn),+ () => shadow('shell.overlay', { id: 'bot-toast', order: 60, inject: face }, ErrorToast),]const installConversation = () => [- installCompiledStyles(CONVERSATION_CSS, 'conversation'),- installMentions(),- installAtMenu(),- shadow('conversation.session.header', { priority: -10, inject: face }, HeaderPill),- shadow('conversation.chat.node', { key: 'assistant-step', priority: -10, locale: 'chat', inject: assistantFace }, AssistantCell),- shadow('conversation.chat.node', { key: 'turn-trigger', priority: -10, locale: 'chat', inject: face }, TriggerCell),- shadow('conversation.chat.node', { key: 'tool-call', priority: -10, locale: 'chat', inject: face }, ToolCell),- shadow('conversation.chat.node', { key: 'turn-process', priority: -10, locale: 'chat', inject: face }, TurnProcessCell),+ () => installCompiledStyles(CONVERSATION_CSS, 'conversation'),+ () => installMentions(),+ () => installAtMenu(),+ () => shadow('conversation.session.header', { priority: BOT_PRIORITY, inject: face }, HeaderPill),+ () => 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),+ () => shadow('conversation.chat.node', { key: 'turn-process', priority: BOT_PRIORITY, locale: 'chat', inject: face }, TurnProcessCell),// DSH's own turn tail stays, so what other plugins add there shows, such as the// cards of the files a turn delivered; its copy and branch row is hidden.- shadow('conversation.chat.turnTail', { id: 'bot-turn-separators', order: 1000, inject: face }, TurnTailCell),+ () => shadow('conversation.chat.turnTail', { id: 'bot-turn-separators', order: 1000, inject: face }, TurnTailCell),// A Bot condenses its conversation without telling anyone; the chat keeps showing// every message.- shadow('conversation.chat.node', { key: 'question-reply', priority: -10, locale: 'chat' }, AnsweredCell),- shadow('conversation.chat.node', { key: 'compaction', priority: -10, locale: 'chat' }, Nothing),- ...(canDrawUserMessages() ? ['user', 'steering'].map(key => shadow('conversation.chat.node', { key, priority: -10, locale: 'chat', inject: face }, UserMessageCell)) : []),- shadow('conversation.input.permission', { priority: -10 }, Nothing),- shadow('conversation.input.plan', { priority: -10 }, Nothing),+ () => shadow('conversation.chat.node', { key: 'question-reply', priority: BOT_PRIORITY, locale: 'chat' }, AnsweredCell),+ () => shadow('conversation.chat.node', { key: 'compaction', priority: BOT_PRIORITY, locale: 'chat' }, Nothing),+ ...(canDrawUserMessages() ? ['user', 'steering'].map(key => () => shadow('conversation.chat.node', { key, priority: BOT_PRIORITY, locale: 'chat', inject: face }, UserMessageCell)) : []),+ () => shadow('conversation.input.permission', { priority: BOT_PRIORITY }, Nothing),+ () => shadow('conversation.input.plan', { priority: BOT_PRIORITY }, Nothing),// The composer carries no model picker or run statistics; a Bot's model lives// in its details panel.- shadow('conversation.input.model', { priority: -10 }, Nothing),- shadow('conversation.composer.dock', { id: 'activity', order: 0, priority: -10 }, Nothing),- shadow('conversation.composer.dock', { id: 'usage', order: 1, priority: -10 }, Nothing),- shadow('conversation.input.left', { id: 'bot-plus', order: -100, inject: face }, ComposerPlus),- shadow('conversation.input.right', { id: 'bot-voice', order: 100, inject: face }, ComposerVoice),- shadow('conversation.composer', {- priority: -10,+ () => shadow('conversation.input.model', { priority: BOT_PRIORITY }, Nothing),+ () => shadow('conversation.composer.dock', { id: 'activity', order: 0, priority: BOT_PRIORITY }, Nothing),+ () => shadow('conversation.composer.dock', { id: 'usage', order: 1, priority: BOT_PRIORITY }, Nothing),+ () => shadow('conversation.input.left', { id: 'bot-plus', order: -100, inject: face }, ComposerPlus),+ () => shadow('conversation.input.right', { id: 'bot-voice', order: 100, inject: face }, ComposerVoice),+ () => shadow('conversation.composer', {+ priority: BOT_PRIORITY,select: owner => (owner.pendingInteraction?.kind === 'question' ? owner.pendingInteraction : null),}, QuestionCard),- shadow('conversation.input.dock', { id: 'bot-members', order: -120, inject: face }, MemberDock),- shadow('conversation.input.dock', { id: 'bot-model', order: -110, inject: face }, ModelChoiceDock),- shadow('conversation.input.dock', { id: 'bot-question', order: -100, inject: face }, QuestionDock),- shadow('conversation.input.dock', { id: 'bot-secret', order: -90, inject: face }, SecretDock),+ () => shadow('conversation.input.dock', { id: 'bot-members', order: -120, inject: face }, MemberDock),+ () => shadow('conversation.input.dock', { id: 'bot-model', order: -110, inject: face }, ModelChoiceDock),+ () => shadow('conversation.input.dock', { id: 'bot-question', order: -100, inject: face }, QuestionDock),+ () => shadow('conversation.input.dock', { id: 'bot-secret', order: -90, inject: face }, SecretDock),]// The return button belongs to neither group: it renders only in Agent mode.ctx.effect(() => {@@ -874,7 +880,9 @@ export function apply(ctx) {}, 'ds-bot: agent surface')ctx.effect(() => {- const groups = surfaceGroups({ shell: installShell, conversation: installConversation })+ const groups = surfaceGroups({ shell: installShell, conversation: installConversation }, {+ onError: (_group, error) => actions.reportError(new Error(t('Bot mode could not be set up here: {error}', { error: error?.message ?? String(error) })), 'surface'),+ })const reconcile = () => groups.reconcile(groupsFor(surface.getSnapshot()))reconcile()const unsub = surface.subscribe(reconcile)diff --git a/ds-bot/src/client/surface.js b/ds-bot/src/client/surface.jsindex 2c1c54a6..5644b887 100644--- a/ds-bot/src/client/surface.js+++ b/ds-bot/src/client/surface.js@@ -20,9 +20,13 @@ function disposeAll(disposers, label) {// Keeps the mounted groups in step with `groupsFor`. The conversation group sits on// the shell's styles and tokens, so it comes off before the shell and goes on after.-// A group's list is cleared before it is disposed, and a failed install leaves it-// empty, so a throw never makes a later reconcile believe the group is mounted.-export function surfaceGroups(install) {+// A group's list is cleared before it is disposed, so a throw never makes a later+// reconcile believe the group is mounted.+//+// `install[group]()` lists the group's steps; each step mounts one thing and returns+// its disposer. A group goes on whole or not at all: when a step throws, the steps+// before it are withdrawn, so Agent mode never keeps a half-installed Bot skin.+export function surfaceGroups(install, { onError } = {}) {const mounted = { shell: [], conversation: [] }const withdraw = (group) => {const disposers = mounted[group]@@ -34,13 +38,33 @@ export function surfaceGroups(install) {for (const group of [...GROUPS].reverse()) if (!wanted[group]) withdraw(group)for (const group of GROUPS) {if (!wanted[group] || mounted[group].length > 0) continue- try { mounted[group] = install[group]() } catch (error) { console.warn(`[ds-bot] install ${group}`, error) }+ 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) },}}+// The priority that puts an entry below every other entry of its cell (lowest+// renders). Another plugin that shadows the same cell at the same priority would+// make the registration throw; in a Bot surface the cell is DS Bot's.+export function freePriority(entries, { priority, key, id }) {+ if (priority === undefined) return undefined+ const taken = entries+ .filter(entry => (key === undefined || entry.options?.key === key) && (id === undefined || entry.options?.id === id))+ .map(entry => (entry.options?.priority ?? 0) - 1)+ return Math.min(priority, ...taken)+}+export function readMode(storage = globalThis.localStorage) {try { return storage.getItem(STORAGE.surface) === 'agent' ? 'agent' : 'bot' } catch { return 'bot' }}diff --git a/ds-bot/test/surface.test.js b/ds-bot/test/surface.test.jsindex 02e3a5d0..752704a5 100644--- a/ds-bot/test/surface.test.js+++ b/ds-bot/test/surface.test.js@@ -1,6 +1,6 @@import assert from 'node:assert/strict'import { test } from 'node:test'-import { groupsFor, readMode, surfaceGroups, writeMode } from '../src/client/surface.js'+import { freePriority, groupsFor, readMode, surfaceGroups, writeMode } from '../src/client/surface.js'import { STORAGE } from '../src/client/storage.js'test('Bot mode mounts both groups; Agent mode mounts neither', () => {@@ -31,7 +31,7 @@ test('the saved surface mode survives reloads and defaults to bot', () => {})const recordingGroups = (log, { failing = null } = {}) => {- const entry = (name) => () => {+ const entry = name => () => () => {log.push(name)if (name === failing) throw new Error(`could not release ${name}`)}@@ -83,8 +83,8 @@ test('a group whose install throws stays unmounted and is tried again', (t) => {t.mock.method(console, 'warn', () => {})let attempts = 0const groups = surfaceGroups({- shell: () => [() => {}],- conversation: () => { attempts += 1; if (attempts === 1) throw new Error('slot refused'); return [() => {}] },+ shell: () => [() => () => {}],+ conversation: () => [() => { attempts += 1; if (attempts === 1) throw new Error('slot refused'); return () => {} }],})assert.doesNotThrow(() => groups.reconcile(groupsFor({ mode: 'bot' })))groups.reconcile(groupsFor({ mode: 'bot', plain: true }))@@ -92,6 +92,49 @@ test('a group whose install throws stays unmounted and is tried again', (t) => {assert.equal(attempts, 2)})+// 公开#149: another plugin held a cell at the same priority, so one step of the+// conversation group threw after the styles, the header and the chat cells were on.+test('a group whose step throws takes back the steps before it, so Agent mode leaves nothing behind', (t) => {+ t.mock.method(console, 'warn', () => {})+ const live = new Set()+ const mount = name => () => { live.add(name); return () => live.delete(name) }+ const collide = () => { throw new Error('single slot "conversation.input.model" already has a registration at priority -10') }+ const errors = []+ const groups = surfaceGroups({+ shell: () => [mount('shell styles')],+ conversation: () => [mount('conversation css'), mount('HeaderPill'), mount('chat.node cells'), collide, mount('bot-plus')],+ }, { onError: (group, error) => errors.push([group, error.message]) })+ groups.reconcile(groupsFor({ mode: 'bot' }))+ assert.deepEqual([...live], ['shell styles'])+ assert.deepEqual(errors.map(([group]) => group), ['conversation'])+ groups.reconcile(groupsFor({ mode: 'agent' }))+ assert.deepEqual([...live], [])+})++test('a shell that cannot go on keeps the conversation group off too', (t) => {+ t.mock.method(console, 'warn', () => {})+ const live = new Set()+ const mount = name => () => { live.add(name); return () => live.delete(name) }+ const groups = surfaceGroups({+ shell: () => [mount('shell styles'), () => { throw new Error('slot refused') }],+ conversation: () => [mount('conversation css')],+ })+ groups.reconcile(groupsFor({ mode: 'bot' }))+ assert.deepEqual([...live], [])+})++test('a shadow goes below every entry of its cell, so a same-priority plugin does not block it', () => {+ const entry = options => ({ options })+ assert.equal(freePriority([], { priority: -100 }), -100)+ assert.equal(freePriority([entry({}), entry({ priority: -10 })], { priority: -100 }), -100)+ assert.equal(freePriority([entry({}), entry({ priority: -100 })], { priority: -100 }), -101)+ assert.equal(freePriority([entry({ priority: -200 })], { priority: -100 }), -201)+ // Keyed and list cells: only the same key or id share the cell.+ assert.equal(freePriority([entry({ key: 'tool-call', priority: -100 }), entry({ key: 'user', priority: -300 })], { key: 'tool-call', priority: -100 }), -101)+ assert.equal(freePriority([entry({ id: 'usage', priority: -100 })], { id: 'activity', priority: -100 }), -100)+ assert.equal(freePriority([entry({ priority: -100 })], {}), undefined)+})+test('readMode falls back to bot when storage throws', () => {assert.equal(readMode({ getItem: () => { throw new Error('denied') } }), 'bot')})