🤯 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
💄 style(channel): move reply style and emoji into the reply tab as their own block (#21846)
Arvin Xuad877a5ec796
diff --git a/locales/en-US/agent.json b/locales/en-US/agent.jsonindex f561df89057..dd76503835f 100644--- a/locales/en-US/agent.json+++ b/locales/en-US/agent.json@@ -457,6 +457,8 @@"channel.removeFailed": "Failed to remove bot","channel.removed": "Bot removed","channel.reply.instant": "Changes here take effect as soon as you make them. There is nothing to save.",+ "channel.reply.section.display": "How replies look",+ "channel.reply.section.style": "Style and emoji","channel.replyEmojiLabel": "Emoji","channel.replyEmojiPlaceholder": "e.g. <:doge:1234567890>","channel.replyEmojiUsageLabel": "When to use",@@ -537,9 +539,9 @@"channel.verificationToken": "Verification Token","channel.verificationTokenHint": "Optional. Used to verify webhook event source.","channel.verificationTokenPlaceholder": "Paste your verification token here",- "channel.wake.intro": "Lets the bot speak up when nobody @-mentioned it: when a message calls it by name, when someone follows up soon after it spoke, or when a watch keyword matches. It judges each message first, and may choose to stay silent.",- "channel.wake.feishuScope.title": "Group messages need an extra permission","channel.wake.feishuScope.desc": "To hear group messages that do not @-mention the bot, the app needs the im:message.group_msg scope. If other bots share the group, also add im:message.group_msg.include_bot:read so the bot sees what they say when it decides whether to step in. Add scopes under Permissions & Scopes in the developer console, then create and publish a new version. Apps made with one-click setup already have the first one.",+ "channel.wake.feishuScope.title": "Group messages need an extra permission",+ "channel.wake.intro": "Lets the bot speak up when nobody @-mentioned it: when a message calls it by name, when someone follows up soon after it spoke, or when a watch keyword matches. It judges each message first, and may choose to stay silent.","channel.wake.section.channels": "Channels","channel.wake.section.channelsDesc": "Where the bot may join a conversation nobody addressed to it.","channel.wake.section.judgement": "Duties",diff --git a/locales/zh-CN/agent.json b/locales/zh-CN/agent.jsonindex fe38f6c8ab2..ac830cb8b01 100644--- a/locales/zh-CN/agent.json+++ b/locales/zh-CN/agent.json@@ -457,6 +457,8 @@"channel.removeFailed": "移除 Bot 失败","channel.removed": "Bot 已移除","channel.reply.instant": "这里的改动一做就生效,不需要再保存。",+ "channel.reply.section.display": "回复展示",+ "channel.reply.section.style": "风格与表情","channel.replyEmojiLabel": "表情","channel.replyEmojiPlaceholder": "如 <:doge:1234567890>","channel.replyEmojiUsageLabel": "什么时候用",@@ -537,9 +539,9 @@"channel.verificationToken": "Verification Token","channel.verificationTokenHint": "可选。用于验证事件推送来源。","channel.verificationTokenPlaceholder": "在此粘贴你的 Verification Token",- "channel.wake.intro": "没人 @ 它时,机器人也能主动参与:消息里直接叫了它的名字、在它刚发言不久后有人接着说,或命中了监听关键词。它会先判断这条消息是不是在对它说,也可以选择不回复。",- "channel.wake.feishuScope.title": "群消息需要额外权限","channel.wake.feishuScope.desc": "要收到群里没有 @ 机器人的消息,应用需开通「获取群组中所有消息」(im:message.group_msg)权限。群里还有其他机器人时,再开通「获取群组中用户和机器人发送的消息」(im:message.group_msg.include_bot:read),机器人判断要不要插话时才能看到它们说了什么。在开发者后台「权限管理」中添加后,需创建版本并发布才会生效。一键创建的应用已自带第一项权限。",+ "channel.wake.feishuScope.title": "群消息需要额外权限",+ "channel.wake.intro": "没人 @ 它时,机器人也能主动参与:消息里直接叫了它的名字、在它刚发言不久后有人接着说,或命中了监听关键词。它会先判断这条消息是不是在对它说,也可以选择不回复。","channel.wake.section.channels": "频道","channel.wake.section.channelsDesc": "机器人可以在哪些频道里,主动参与没人叫它的对话。","channel.wake.section.judgement": "职责边界",diff --git a/packages/locales/src/default/agent.ts b/packages/locales/src/default/agent.tsindex 1ae9ca9b3eb..b41b0eb0694 100644--- a/packages/locales/src/default/agent.ts+++ b/packages/locales/src/default/agent.ts@@ -674,6 +674,8 @@ export default {'channel.group.connection': 'Connection options','channel.reply.instant':'Changes here take effect as soon as you make them. There is nothing to save.',+ 'channel.reply.section.display': 'How replies look',+ 'channel.reply.section.style': 'Style and emoji','channel.settings': 'Advanced Settings','channel.settingsResetConfirm': 'Are you sure you want to reset advanced settings to default?','channel.settingsResetDefault': 'Reset to Default',diff --git a/src/features/AgentChannel/PlatformDetail/Body.tsx b/src/features/AgentChannel/PlatformDetail/Body.tsxindex 13bcbd52610..4bc5e0f1c2c 100644--- a/src/features/AgentChannel/PlatformDetail/Body.tsx+++ b/src/features/AgentChannel/PlatformDetail/Body.tsx@@ -31,6 +31,7 @@ import { ApplicationIdField, SchemaField } from './SchemaField';import {getSchemaFields,groupAccessFields,+ groupReplyFields,groupSettingsFields,groupWakeFields,WAKE_KEY_PREFIX,@@ -375,11 +376,6 @@ const Body = memo<BodyProps>(</Text>)}{group.key === 'wake' && WakeNotice && <WakeNotice />}- {group.key === 'reply' && hasConfig && (- <Text fontSize={12} type={'secondary'}>- {t('channel.reply.instant')}- </Text>- )}{group.key === 'access' ? (// Who the owner is, who may talk to the bot and who may use the owner's devices are// three separate decisions, so each gets a block (and a Save) of its own.@@ -408,6 +404,27 @@ const Body = memo<BodyProps>(/></Form.Group>))+ ) : group.key === 'reply' ? (+ // How a reply looks saves itself as it changes; how the bot talks is long text, so+ // it is a block of its own with a Save.+ groupReplyFields(group.fields).map((section) => (+ <Form.Group+ className={styles.moduleGroup}+ collapsible={false}+ extra={section.key === 'style' ? moduleExtra('reply-style') : undefined}+ key={section.key}+ keyValue={`settings-reply-${section.key}-${platformDef.id}`}+ title={t(`channel.reply.section.${section.key}`)}+ variant={'filled'}+ desc={+ section.key === 'display' && hasConfig+ ? t('channel.reply.instant')+ : undefined+ }+ >+ {renderSettingsFields(section.fields)}+ </Form.Group>+ ))) : group.key === 'wake' ? (// Keywords, channels, pace and judgement each get a block of their own, so a long// list of options reads as four decisions.diff --git a/src/features/AgentChannel/PlatformDetail/index.save.test.tsx b/src/features/AgentChannel/PlatformDetail/index.save.test.tsxindex 2e61a36e40d..fb40e72fc99 100644--- a/src/features/AgentChannel/PlatformDetail/index.save.test.tsx+++ b/src/features/AgentChannel/PlatformDetail/index.save.test.tsx@@ -131,7 +131,7 @@ describe('PlatformDetail saving', () => {expect(mocks.updateBotProvider.mock.calls[0][2].settings.botWake).toEqual(override);});- it('shows a Save in each wake block and none on the replies', () => {+ it('shows a Save in each wake block, and on the replies only for how the bot talks', () => {render(<PlatformDetail agentId="agt" currentConfig={config} platformDef={platformDef} />, {wrapper: MemoryRouter,});@@ -140,7 +140,40 @@ describe('PlatformDetail saving', () => {expect(screen.getAllByRole('button', { name: en['channel.module.save'] })).toHaveLength(4);openTab(en['channel.tab.reply']);- expect(screen.queryByRole('button', { name: en['channel.module.save'] })).toBeNull();+ const style = screen+ .getByText(en['channel.reply.section.style'])+ .closest('div[class*="header"]')!.parentElement!;+ expect(screen.getAllByRole('button', { name: en['channel.module.save'] })).toEqual([+ within(style).getByRole('button', { name: en['channel.module.save'] }),+ ]);+ });++ it('keeps the reply style off the advanced tab and saves it only with its own Save', async () => {+ render(<PlatformDetail agentId="agt" currentConfig={config} platformDef={platformDef} />, {+ wrapper: MemoryRouter,+ });++ openTab(en['channel.tab.advanced']);+ expect(screen.queryByText(en['channel.replyStyle'])).not.toBeVisible();++ openTab(en['channel.tab.reply']);+ const area = screen.getByPlaceholderText(en['channel.replyStylePlaceholder']);+ expect(area).toBeVisible();+ fireEvent.change(area, { target: { value: 'Short and casual.' } });+ fireEvent.blur(area);++ await waitFor(() => expect(screen.getByText(en['channel.module.unsaved'])).toBeVisible());+ // Typed text is not an instant reply setting: nothing is written until Save.+ await new Promise((resolve) => setTimeout(resolve, 600));+ expect(mocks.updateBotProvider).not.toHaveBeenCalled();++ const style = screen+ .getByText(en['channel.reply.section.style'])+ .closest('div[class*="header"]')!.parentElement!;+ fireEvent.click(within(style).getByRole('button', { name: en['channel.module.save'] }));++ await waitFor(() => expect(mocks.updateBotProvider).toHaveBeenCalledTimes(1));+ expect(mocks.updateBotProvider.mock.calls[0][2].settings.replyStyle).toBe('Short and casual.');});it('leaves the bottom bar to Remove and Test connection for a saved bot', () => {diff --git a/src/features/AgentChannel/PlatformDetail/saveModules.test.ts b/src/features/AgentChannel/PlatformDetail/saveModules.test.tsindex d5f562e96e8..a255b30ef45 100644--- a/src/features/AgentChannel/PlatformDetail/saveModules.test.ts+++ b/src/features/AgentChannel/PlatformDetail/saveModules.test.ts@@ -31,6 +31,9 @@ describe('resolveSaveModules', () => {'botWakeCustomInstructions','displayToolCalls','reactionMode',+ 'replyStyle',+ 'channelReplyStyles',+ 'replyEmojis','charLimit',]);@@ -45,10 +48,18 @@ describe('resolveSaveModules', () => {'wake-keywords','wake-channels','wake-pace',+ 'reply-style','advanced',]);});+ it('saves how the bot talks with its own block, on the reply tab', () => {+ const style = resolveSaveModules(discord, true).find((m) => m.id === 'reply-style')!;++ expect(style.keys).toEqual(['replyStyle', 'channelReplyStyles', 'replyEmojis']);+ expect(tabOfModule('reply-style')).toBe('reply');+ });+it('leaves the replies out: they save themselves as soon as they change', () => {const keys = resolveSaveModules(discord, true).flatMap((m) => m.keys);diff --git a/src/features/AgentChannel/PlatformDetail/saveModules.ts b/src/features/AgentChannel/PlatformDetail/saveModules.tsindex d3a28a3476e..1e48d9f6676 100644--- a/src/features/AgentChannel/PlatformDetail/saveModules.ts+++ b/src/features/AgentChannel/PlatformDetail/saveModules.ts@@ -2,20 +2,27 @@ import isEqual from 'fast-deep-equal';import type { ChannelTab, ChannelValues } from './channelTabs';import { pickKeys, replyDiffers } from './replySettings';-import { groupAccessFields, groupWakeFields, type SettingsGroup } from './settingsGroups';+import {+ groupAccessFields,+ groupReplyFields,+ groupWakeFields,+ type SettingsGroup,+} from './settingsGroups';/*** The page saves one block at a time. A block is a titled group of options with its own Save* button: the long page has no single button to scroll to, and a person who changes an option* knows exactly what pressing Save will write.*- * Replies are not a block: they take effect as soon as they change and save themselves.+ * How a reply looks is not a block: those options take effect as soon as they change and save+ * themselves. How the bot talks (its reply style and emoji) is long text, so it is a block.*/export type SaveModuleId =| `access-${'conversation' | 'device' | 'identity'}`| 'advanced'| 'connection'| 'credentials'+ | 'reply-style'| `wake-${'channels' | 'judgement' | 'keywords' | 'more' | 'pace'}`;export interface SaveModule {@@ -42,7 +49,7 @@ const WAKE_MASTER = 'botWakeEnabled';** Returns:* - A `credentials` block when the platform asks for credentials, then one block per titled group- * of settings. Every option the page shows, other than the replies, is in exactly one.+ * of settings. Every option the page shows, other than how a reply looks, is in exactly one.*/export const resolveSaveModules = (groups: SettingsGroup[],@@ -86,7 +93,13 @@ export const resolveSaveModules = (}break;}- // Replies save themselves.+ case 'reply': {+ // How a reply looks saves itself; only how the bot talks waits for a Save.+ for (const section of groupReplyFields(group.fields)) {+ if (section.key === 'style') settings('reply-style', section.fields);+ }+ break;+ }}}@@ -98,6 +111,7 @@ export const tabOfModule = (id: SaveModuleId): ChannelTab => {if (id === 'credentials' || id === 'connection') return 'connect';if (id.startsWith('access-')) return 'access';if (id === 'advanced') return id;+ if (id === 'reply-style') return 'reply';return 'wake';};diff --git a/src/features/AgentChannel/PlatformDetail/settingsGroups.test.ts b/src/features/AgentChannel/PlatformDetail/settingsGroups.test.tsindex cd63d267f89..da731f80710 100644--- a/src/features/AgentChannel/PlatformDetail/settingsGroups.test.ts+++ b/src/features/AgentChannel/PlatformDetail/settingsGroups.test.ts@@ -7,6 +7,7 @@ import type { FieldSchema } from '@/server/services/bot/platforms/types';import {getSchemaFields,groupAccessFields,+ groupReplyFields,groupSettingsFields,groupWakeFields,} from './settingsGroups';@@ -107,6 +108,19 @@ describe('groupSettingsFields', () => {]);});+ it('puts the reply style and emoji with the replies, not in advanced', () => {+ const groups = groupSettingsFields(+ ['charLimit', 'replyStyle', 'displayToolCalls', 'channelReplyStyles', 'replyEmojis'].map(+ field,+ ),+ );++ expect(groups.map((g) => [g.key, g.fields.map((f) => f.key)])).toEqual([+ ['reply', ['displayToolCalls', 'replyStyle', 'channelReplyStyles', 'replyEmojis']],+ ['advanced', ['charLimit']],+ ]);+ });+it('drops sections a platform has no fields for', () => {const groups = groupSettingsFields(['displayToolCalls', 'reactionMode'].map(field));@@ -234,3 +248,22 @@ describe('groupWakeFields', () => {);});});++describe('groupReplyFields', () => {+ it('splits the replies into how they look, then how the bot talks', () => {+ const sections = groupReplyFields(+ ['replyEmojis', 'reactionMode', 'replyStyle', 'displayToolCalls', 'channelReplyStyles'].map(+ field,+ ),+ );++ expect(sections.map((s) => [s.key, s.fields.map((f) => f.key)])).toEqual([+ ['display', ['displayToolCalls', 'reactionMode']],+ ['style', ['replyStyle', 'channelReplyStyles', 'replyEmojis']],+ ]);+ });++ it('drops a block the platform has no fields for', () => {+ expect(groupReplyFields(['replyStyle'].map(field)).map((s) => s.key)).toEqual(['style']);+ });+});diff --git a/src/features/AgentChannel/PlatformDetail/settingsGroups.ts b/src/features/AgentChannel/PlatformDetail/settingsGroups.tsindex 163aa89de25..d736b6ba40c 100644--- a/src/features/AgentChannel/PlatformDetail/settingsGroups.ts+++ b/src/features/AgentChannel/PlatformDetail/settingsGroups.ts@@ -64,9 +64,36 @@ export const groupAccessFields = (fields: FieldSchema[]): AccessSectionGroup[] =})).filter((section) => section.fields.length > 0);};-/** What a reply looks like in the chat. */+/** What a reply looks like in the chat. These save themselves as soon as they change. */export const REPLY_KEYS = ['replyPlacement', 'displayToolCalls', 'showUsageStats', 'reactionMode'];+/**+ * How the bot talks: its style everywhere, a style per channel, and the emoji it may use. Long+ * text a person writes and rewrites, so it waits for its own Save instead of saving per keystroke.+ */+export const REPLY_STYLE_KEYS = ['replyStyle', 'channelReplyStyles', 'replyEmojis'];++export type ReplySectionKey = 'display' | 'style';++export interface ReplySection {+ fields: FieldSchema[];+ key: ReplySectionKey;+}++/** Split the reply tab's fields into how a reply looks and how the bot talks. Empty blocks are dropped. */+export const groupReplyFields = (fields: FieldSchema[]): ReplySection[] => {+ const byKey = new Map(fields.map((field) => [field.key, field]));+ const pick = (keys: string[]) =>+ keys.map((key) => byKey.get(key)).filter((field): field is FieldSchema => !!field);++ return (+ [+ { fields: pick(REPLY_KEYS), key: 'display' },+ { fields: pick(REPLY_STYLE_KEYS), key: 'style' },+ ] satisfies ReplySection[]+ ).filter((section) => section.fields.length > 0);+};+/*** When the bot speaks up without being @mentioned: first the keywords that wake it, then the* bot-wake rules, which all share one prefix and judge the messages nobody addressed to it.@@ -169,7 +196,7 @@ export const groupSettingsFields = (fields: FieldSchema[]): SettingsGroup[] => {const connect = pick(CONNECT_KEYS);const access = pick(ACCESS_KEYS);- const reply = pick(REPLY_KEYS);+ const reply = pick([...REPLY_KEYS, ...REPLY_STYLE_KEYS]);const wake = [...pick(WAKE_KEYS),...fields.filter((field) => field.key.startsWith(WAKE_KEY_PREFIX)),