🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(bot): new bots start with status reactions off (#22182)
Rdmclin2da797858a890
diff --git a/apps/server/src/services/bot/__tests__/agentBotProviderSettings.test.ts b/apps/server/src/services/bot/__tests__/agentBotProviderSettings.test.tsindex b389c51b291..0133c80c9cc 100644--- a/apps/server/src/services/bot/__tests__/agentBotProviderSettings.test.ts+++ b/apps/server/src/services/bot/__tests__/agentBotProviderSettings.test.ts@@ -315,10 +315,41 @@ describe('mergeBotSettingsForCreate', () => {).toBe(true);});- it('leaves an ordinary agent created without settings as before', async () => {- expect(- await mergeBotSettingsForCreate(dbWith({}), 'agt', 'discord', undefined),- ).toBeUndefined();+ it('writes the defaults for an ordinary agent created without settings, reactions off', async () => {+ const settings = await mergeBotSettingsForCreate(dbWith({}), 'agt', 'discord', undefined);++ expect(settings).toMatchObject({ botWakeDisabled: false, reactionMode: 'none' });+ });++ it('creates a bot with status reactions off when the caller did not choose', async () => {+ const settings = await mergeBotSettingsForCreate(dbWith({}), 'agt', 'discord', {+ dmPolicy: 'open',+ });++ expect(settings).toMatchObject({ dmPolicy: 'open', reactionMode: 'none' });+ });++ it('keeps the status reaction mode the caller chose', async () => {+ const settings = await mergeBotSettingsForCreate(dbWith({}), 'agt', 'discord', {+ reactionMode: 'full',+ });++ expect(settings?.reactionMode).toBe('full');+ });++ it('turns reactions off for a heterogeneous agent created without settings too', async () => {+ const db = dbWith({ heterogeneousProvider: { type: 'claude-code' } });++ expect(await mergeBotSettingsForCreate(db, 'agt', 'discord', undefined)).toMatchObject({+ botWakeDisabled: true,+ reactionMode: 'none',+ });+ });++ it('adds no reaction mode on a platform without status reactions', async () => {+ const settings = await mergeBotSettingsForCreate(dbWith({}), 'agt', 'wechat', {});++ expect(settings).not.toHaveProperty('reactionMode');});it('keeps a heterogeneous agent opted in when the caller turned it on', async () => {@@ -330,3 +361,15 @@ describe('mergeBotSettingsForCreate', () => {expect(settings?.botWakeDisabled).toBe(false);});});++describe('status reactions of an existing bot', () => {+ it('keep the stored mode on a partial update', () => {+ expect(+ mergeBotSettingsPatch('discord', { reactionMode: 'minimal' }, { charLimit: 1000 }),+ ).toMatchObject({ charLimit: 1000, reactionMode: 'minimal' });+ });++ it('stay on for a row saved before the field existed', () => {+ expect(mergeBotSettingsPatch('discord', {}, { charLimit: 1000 })?.reactionMode).toBe('minimal');+ });+});diff --git a/apps/server/src/services/bot/agentBotProviderSettings.ts b/apps/server/src/services/bot/agentBotProviderSettings.tsindex 740708f8c72..924695c2c91 100644--- a/apps/server/src/services/bot/agentBotProviderSettings.ts+++ b/apps/server/src/services/bot/agentBotProviderSettings.ts@@ -14,6 +14,7 @@ import { getBotMessageRouter } from './BotMessageRouter';import {extractWatchKeywordEntries,mergeWithDefaults,+ NEW_BOT_REACTION_MODE,platformRegistry,resolveConnectionMode,validateAccessSettings,@@ -37,12 +38,34 @@ export function mergeBotSettingsForPersist(return mergeWithDefaults(definition.schema, settings);}+const REACTION_MODE_KEY = 'reactionMode';++/**+ * {@link mergeBotSettingsForPersist} for a bot being created, with status reactions off unless the+ * caller chose a mode. Omitted settings would persist as `{}`, where an absent mode reads as the+ * schema default (on), so on a platform that offers reactions the defaults are written instead.+ */+function withNewBotReactionMode(+ platform: string | undefined,+ settings: Record<string, unknown> | undefined,+): Record<string, unknown> | undefined {+ const merged = mergeBotSettingsForPersist(platform, settings);+ if (settings?.[REACTION_MODE_KEY] !== undefined) return merged;+ const withDefaults = merged ?? mergeBotSettingsForPersist(platform, {});+ if (!withDefaults || !(REACTION_MODE_KEY in withDefaults)) return merged;++ return { ...withDefaults, [REACTION_MODE_KEY]: NEW_BOT_REACTION_MODE };+}+/**- * The settings to persist for a bot being created: {@link mergeBotSettingsForPersist}, with bot- * wake switched off when the agent runs on a heterogeneous runtime (Claude Code, Codex) and the- * caller did not choose. Every other bot speaks up on its own by default; a heterogeneous agent- * runs on its owner's device and their CLI quota, so it joins conversations only once the owner- * turns it on.+ * The settings to persist for a bot being created: {@link mergeBotSettingsForPersist}, with+ * - status reactions off ({@link NEW_BOT_REACTION_MODE}) when the platform offers them and the+ * caller did not choose. The schema default stays on, since it is also what a bot saved before+ * the field existed reads as; only a new bot starts quiet.+ * - bot wake switched off when the agent runs on a heterogeneous runtime (Claude Code, Codex) and+ * the caller did not choose. Every other bot speaks up on its own by default; a heterogeneous+ * agent runs on its owner's device and their CLI quota, so it joins conversations only once the+ * owner turns it on.*/export async function mergeBotSettingsForCreate(db: LobeChatDatabase,@@ -50,7 +73,7 @@ export async function mergeBotSettingsForCreate(platform: string | undefined,settings: Record<string, unknown> | undefined,): Promise<Record<string, unknown> | undefined> {- const merged = mergeBotSettingsForPersist(platform, settings);+ const merged = withNewBotReactionMode(platform, settings);const key = BOT_WAKE_SETTING_KEYS.disabled;if (settings?.[key] !== undefined) return merged;// Omitted settings persist as `{}`, where an absent switch reads as on: the defaults are writtendiff --git a/apps/server/src/services/bot/platforms/const.ts b/apps/server/src/services/bot/platforms/const.tsindex dd3561a1e7b..1a4cae4e8e8 100644--- a/apps/server/src/services/bot/platforms/const.ts+++ b/apps/server/src/services/bot/platforms/const.ts@@ -956,6 +956,14 @@ export const BOT_REACTION_MODES: readonly BotReactionMode[] = ['minimal', 'full'export const DEFAULT_BOT_REACTION_MODE: BotReactionMode = 'minimal';+/**+ * The mode a bot is created with. A new bot starts with status reactions off, so it does not ping+ * anyone until its owner turns them on. {@link DEFAULT_BOT_REACTION_MODE} stays the schema default+ * and the runtime fallback, because rows saved before the field existed carry no `reactionMode`+ * and must keep reacting as they always have; only a bot being created gets this mode.+ */+export const NEW_BOT_REACTION_MODE: BotReactionMode = 'none';+export const reactionModeField: FieldSchema = {key: 'reactionMode',default: DEFAULT_BOT_REACTION_MODE,diff --git a/apps/server/src/services/bot/platforms/index.ts b/apps/server/src/services/bot/platforms/index.tsindex 5826f79c180..b5dc72560e1 100644--- a/apps/server/src/services/bot/platforms/index.ts+++ b/apps/server/src/services/bot/platforms/index.ts@@ -44,6 +44,7 @@ export {makeServerIdField,makeUserIdField,messageMatchesWatchKeyword,+ NEW_BOT_REACTION_MODE,normalizeAllowFromEntries,normalizeBotReactionMode,normalizeBotReplyLocale,diff --git a/apps/server/src/services/bot/platforms/reactionMode.test.ts b/apps/server/src/services/bot/platforms/reactionMode.test.tsindex 5f453538553..9a97fd200da 100644--- a/apps/server/src/services/bot/platforms/reactionMode.test.ts+++ b/apps/server/src/services/bot/platforms/reactionMode.test.ts@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';import {BOT_REACTION_MODES,DEFAULT_BOT_REACTION_MODE,+ NEW_BOT_REACTION_MODE,normalizeBotReactionMode,reactionModeField,shouldApplyReaction,@@ -57,3 +58,12 @@ describe('reactionModeField', () => {expect(reactionModeField.enumDescriptions).toHaveLength(BOT_REACTION_MODES.length);});});++describe('NEW_BOT_REACTION_MODE', () => {+ it('starts a new bot with reactions off, while old rows keep the on default', () => {+ expect(NEW_BOT_REACTION_MODE).toBe('none');+ expect(shouldApplyReaction(NEW_BOT_REACTION_MODE, 'received')).toBe(false);+ expect(reactionModeField.default).toBe(DEFAULT_BOT_REACTION_MODE);+ expect(normalizeBotReactionMode(undefined)).not.toBe(NEW_BOT_REACTION_MODE);+ });+});diff --git a/src/features/AgentChannel/PlatformDetail/formState.test.ts b/src/features/AgentChannel/PlatformDetail/formState.test.tsindex 611a663fce9..c15258c8322 100644--- a/src/features/AgentChannel/PlatformDetail/formState.test.ts+++ b/src/features/AgentChannel/PlatformDetail/formState.test.ts@@ -1,6 +1,7 @@import { describe, expect, it } from 'vitest';import { BOT_WAKE_SETTING_KEYS } from '@/server/services/agentSignal/scenarios/botWake/config';+import { schema as discordSchema } from '@/server/services/bot/platforms/discord/schema';import type { FieldSchema } from '@/server/services/bot/platforms/types';import {@@ -12,6 +13,7 @@ import {mergeSettingsWithDefaults,shouldAdoptIncomingConfig,withHeterogeneousWakeOff,+ withNewBotReactionOff,} from './formState';const slackSchema: FieldSchema[] = [@@ -351,3 +353,26 @@ describe('withHeterogeneousWakeOff', () => {expect(withHeterogeneousWakeOff([], { charLimit: 2000 })).toEqual({ charLimit: 2000 });});});++describe('withNewBotReactionOff', () => {+ it('starts a new bot with status reactions off, over the schema default', () => {+ expect(+ mergeSettingsWithDefaults(discordSchema, withNewBotReactionOff(discordSchema, {}))+ .reactionMode,+ ).toBe('none');+ });++ it('leaves the schema default on, which a saved bot without the field reads as', () => {+ expect(extractSettingsDefaults(discordSchema).reactionMode).toBe('minimal');+ });++ it('keeps a mode the owner already picked', () => {+ const settings = { reactionMode: 'full' };++ expect(withNewBotReactionOff(discordSchema, settings)).toBe(settings);+ });++ it('adds nothing on a platform without status reactions', () => {+ expect(withNewBotReactionOff(slackSchema, { charLimit: 2000 })).toEqual({ charLimit: 2000 });+ });+});diff --git a/src/features/AgentChannel/PlatformDetail/formState.ts b/src/features/AgentChannel/PlatformDetail/formState.tsindex 333011f3d24..768483ace6c 100644--- a/src/features/AgentChannel/PlatformDetail/formState.ts+++ b/src/features/AgentChannel/PlatformDetail/formState.ts@@ -221,3 +221,23 @@ export const withHeterogeneousWakeOff = (return { ...settings, [WAKE_MASTER_KEY]: true };};++/** The status-reaction mode setting, offered by the platforms that support reactions. */+export const REACTION_MODE_KEY = 'reactionMode';++/**+ * Settings for a bot being created: status reactions start off (`none`), so a new bot does not ping+ * anyone until its owner turns them on. A saved bot keeps what it stored, and one saved before the+ * field existed reads as the schema default, as the runtime does. A choice already made is kept.+ * Mirrors `NEW_BOT_REACTION_MODE` on the server, which applies the same rule to every create.+ */+export const withNewBotReactionOff = (+ schema: FieldSchema[] | undefined,+ settings: Record<string, unknown>,+): Record<string, unknown> => {+ const fields = schema?.find((field) => field.key === 'settings')?.properties ?? [];+ if (settings[REACTION_MODE_KEY] !== undefined) return settings;+ if (!fields.some((field) => field.key === REACTION_MODE_KEY)) return settings;++ return { ...settings, [REACTION_MODE_KEY]: 'none' };+};diff --git a/src/features/AgentChannel/PlatformDetail/index.save.test.tsx b/src/features/AgentChannel/PlatformDetail/index.save.test.tsxindex 8336b4763d5..261b88f5a56 100644--- a/src/features/AgentChannel/PlatformDetail/index.save.test.tsx+++ b/src/features/AgentChannel/PlatformDetail/index.save.test.tsx@@ -290,3 +290,28 @@ describe('PlatformDetail saving', () => {expect(sensitivity).toHaveValue('0.9');});});++describe('PlatformDetail status reactions', () => {+ beforeEach(() => {+ mocks.heterogeneous = false;+ vi.clearAllMocks();+ });++ it('starts a new bot with status reactions off', () => {+ render(<PlatformDetail agentId="agt" platformDef={platformDef} />, { wrapper: MemoryRouter });++ openTab(en['channel.tab.reply']);+ expect(screen.getByText(en['channel.reactionModeNoneHint'])).toBeInTheDocument();+ expect(screen.queryByText(en['channel.reactionModeMinimalHint'])).toBeNull();+ });++ it('shows a bot saved before the field existed with reactions on, as the runtime reads it', () => {+ render(<PlatformDetail agentId="agt" currentConfig={config} platformDef={platformDef} />, {+ wrapper: MemoryRouter,+ });++ openTab(en['channel.tab.reply']);+ expect(screen.getByText(en['channel.reactionModeMinimalHint'])).toBeInTheDocument();+ expect(screen.queryByText(en['channel.reactionModeNoneHint'])).toBeNull();+ });+});diff --git a/src/features/AgentChannel/PlatformDetail/index.tsx b/src/features/AgentChannel/PlatformDetail/index.tsxindex b0de693a09c..a9935a52652 100644--- a/src/features/AgentChannel/PlatformDetail/index.tsx+++ b/src/features/AgentChannel/PlatformDetail/index.tsx@@ -52,6 +52,7 @@ import {shouldAdoptIncomingConfig,WAKE_MASTER_KEY,withHeterogeneousWakeOff,+ withNewBotReactionOff,} from './formState';import { type ChannelPostSave, ChannelPostSaveContext } from './postSaveContext';import { QuickView } from './QuickView';@@ -156,10 +157,15 @@ const getFormValues = (): ChannelFormValues => {const values = config ? getChannelFormValues(config) : { credentials: {}, settings: {} };const stored = omitUndefinedValues(values.settings);- const settings = mergeSettingsWithDefaults(- schema,- config || !heterogeneous ? stored : withHeterogeneousWakeOff(schema, stored),- );+ // A bot being created starts with status reactions off (and, for a heterogeneous agent, bot wake+ // off); a saved bot shows what it stored.+ const seeded = config+ ? stored+ : withNewBotReactionOff(+ schema,+ heterogeneous ? withHeterogeneousWakeOff(schema, stored) : stored,+ );+ const settings = mergeSettingsWithDefaults(schema, seeded);return { ...values, settings: settings as Record<string, {} | undefined> };};diff --git a/src/routes/(main)/agent/channel/importPlan.test.ts b/src/routes/(main)/agent/channel/importPlan.test.tsindex 99dbf75818b..3ca6c053de5 100644--- a/src/routes/(main)/agent/channel/importPlan.test.ts+++ b/src/routes/(main)/agent/channel/importPlan.test.ts@@ -44,6 +44,30 @@ describe('planChannelImport', () => {});});+describe('planChannelImport status reactions', () => {+ it('restores a bot exported before reactionMode existed with its legacy reactions on', () => {+ const [step] = planChannelImport([+ { applicationId: 'app-1', platform: 'discord', settings: { charLimit: 2000 } },+ ]);++ expect(step.settings).toEqual({ charLimit: 2000, reactionMode: 'minimal' });+ });++ it('restores an entry without settings the same way', () => {+ const [step] = planChannelImport([{ applicationId: 'app-1', platform: 'discord' }]);++ expect(step.settings.reactionMode).toBe('minimal');+ });++ it('keeps the mode an export carries, reactions off included', () => {+ const [step] = planChannelImport([+ { applicationId: 'app-1', platform: 'discord', settings: { reactionMode: 'none' } },+ ]);++ expect(step.settings.reactionMode).toBe('none');+ });+});+describe('isImportableChannel', () => {it.each([[{ applicationId: 'a', platform: 'discord' }, true],diff --git a/src/routes/(main)/agent/channel/importPlan.ts b/src/routes/(main)/agent/channel/importPlan.tsindex b44badd30a3..1c5b0872cb9 100644--- a/src/routes/(main)/agent/channel/importPlan.ts+++ b/src/routes/(main)/agent/channel/importPlan.ts@@ -14,9 +14,24 @@ export interface ChannelImportStep {credentials: Record<string, string>;enabled: boolean | undefined;platform: string;- settings: Record<string, unknown> | undefined;+ settings: Record<string, unknown>;}+/**+ * The status-reaction mode a bot saved before `reactionMode` existed runs with (the runtime+ * fallback, `DEFAULT_BOT_REACTION_MODE` on the server).+ */+const LEGACY_REACTION_MODE = 'minimal';++/**+ * An imported entry restores a bot that already existed, so it keeps the status reactions it ran+ * with. Without this, an export of a bot saved before `reactionMode` existed would reach the create+ * path with the field absent, and a new bot starts with reactions off.+ */+const withRestoredReactionMode = (+ settings: Record<string, unknown> | undefined,+): Record<string, unknown> => ({ reactionMode: LEGACY_REACTION_MODE, ...settings });+/*** Decide what each entry of an import file should become.*@@ -37,7 +52,7 @@ export const planChannelImport = (items: ChannelImportItem[]): ChannelImportStepcredentials,enabled: hasCredentials ? undefined : false,platform: item.platform!,- settings: item.settings ?? undefined,+ settings: withRestoredReactionMode(item.settings ?? undefined),};});