Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 优化 IM 机器人设置展示 (#1305)
Dashaff212a36ec6
diff --git a/apps/desktop/src/renderer/components/settings/ImBotSection.tsx b/apps/desktop/src/renderer/components/settings/ImBotSection.tsxindex 54e2f8a187..b896f72805 100644--- a/apps/desktop/src/renderer/components/settings/ImBotSection.tsx+++ b/apps/desktop/src/renderer/components/settings/ImBotSection.tsx@@ -1,16 +1,16 @@/**- * ImBotSection —— 「IM 机器人」设置页(单页 + 页内分栏 tab)。+ * ImBotSection —— 「IM 机器人」设置页(单页 + 官方/个人纵向分区)。*- * 侧边栏「IM 机器人」是普通 cell(不再有可展开的子 cell),内容整合在本页,- * 顶部用 pill 分段 tab 切换两个分栏(视觉对齐 ImDefaultSettingsSection 的- * agent 切换器 / VendorSegmentedSwitcher),每个分栏配一条简短 Tips 说明差异:- * 1. Cindy(group='cindy',默认):官方 Cindy 机器人渠道 —— Slack 卡片- * (HookConnectionsSection,原 Tina 设置区,共享 App 零凭证)+ * 侧边栏「IM 机器人」是普通 cell(不再有可展开的子 cell),内容整合在本页。+ * 官方与个人分区同时渲染、上下排列,避免 tab 把另一组支持的机器人类型藏起来;+ * 每个分区配一条简短 Tips 说明差异:+ * 1. Cindy(group='cindy',默认):官方 Cindy 机器人渠道 —— 多渠道卡片+ * (HookConnectionsSection,原 Tina 设置区,由 Cindy 维护、用户零凭证)* 2. 个人(group='personal'):按渠道折叠的用户自配机器人。每个渠道独立保存* Agent / 模型与凭证配置;同一时刻最多展开一个,渠道增加时页面不会线性变长。*- * 分栏选择经 ?imGroup= 参数由 SettingsView 驱动(深链可直达某分栏);缺省/非法- * 时 SettingsView 落到默认分栏(旧「飞书机器人」深链落「个人」,其余落「Cindy」)。+ * ?imGroup= 参数仍由 SettingsView 驱动,但只负责把深链滚动到对应分区;缺省时+ * 保持页面顶部不动,旧「飞书机器人」深链继续定位到「个人」。* Beta 标识用一颗 pill(主题 token,无硬编码 hex),表示整块功能处于 Beta。** 可见性(imBotVisibility 单点):本地模式与「国区构建 + 个人账号登录」都@@ -19,10 +19,9 @@*/import { Lightbulb } from 'lucide-react';-import { useState } from 'react';+import { useEffect, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';-import { cn } from '@/lib/utils';import { useAuth } from '@/contexts/AuthContext';import { CURRENT_CINDY_REGION } from '../../../shared/brandRegion';import { DiscordBotSection } from './DiscordBotSection';@@ -40,25 +39,30 @@ import {type ImBotIdentity,} from './imBotVisibility';-/** 「IM 机器人」页内分栏 id(tab 与 ?imGroup= 参数共用)。 */+/** 「IM 机器人」页面分区 id(与 ?imGroup= 参数共用)。 */export type ImBotSettingsGroup = 'cindy' | 'personal';-/** 分栏 tab 的固定顺序(Cindy 在前为默认)。 */-export const IM_BOT_SETTINGS_GROUPS: readonly ImBotSettingsGroup[] = ['cindy', 'personal'];-const PERSONAL_ONLY_IM_BOT_SETTINGS_GROUPS: readonly ImBotSettingsGroup[] = ['personal'];--/** 分栏标题的 i18n key(tab 文案)。 */-export const IM_BOT_GROUP_LABEL_KEY: Record<ImBotSettingsGroup, string> = {+/** 分区标题的 i18n key。 */+const IM_BOT_GROUP_LABEL_KEY: Record<ImBotSettingsGroup, string> = {cindy: 'settings.imBot.groups.cindy',personal: 'settings.imBot.groups.personal',};-/** 分栏 Tips 的 i18n key —— 一句话讲清该分栏是什么、与另一栏的差异。 */+/** 分区 Tips 的 i18n key —— 一句话讲清该分区是什么、与另一区的差异。 */const IM_BOT_GROUP_TIP_KEY: Record<ImBotSettingsGroup, string> = {cindy: 'settings.imBot.tips.cindy',personal: 'settings.imBot.tips.personal',};+function GroupTip({ message }: { message: string }) {+ return (+ <div className="flex items-start gap-2 rounded-xl bg-[var(--surface-chip)] px-3.5 py-2.5">+ <Lightbulb size={14} className="mt-[2px] shrink-0 text-[var(--text-tertiary)]" />+ <p className="text-[12.5px] leading-[1.6] text-[var(--text-secondary)]">{message}</p>+ </div>+ );+}+export function isImBotSettingsGroup(value: string | null): value is ImBotSettingsGroup {return value === 'cindy' || value === 'personal';}@@ -77,9 +81,7 @@ function PersonalGroupContent({'wechat' | 'wecom' | 'feishu' | 'discord' | 'telegram' | 'dingtalk' | null>(null);- const toggle = (- channel: 'wechat' | 'wecom' | 'feishu' | 'discord' | 'telegram' | 'dingtalk',- ) => {+ const toggle = (channel: 'wechat' | 'wecom' | 'feishu' | 'discord' | 'telegram' | 'dingtalk') => {setExpandedChannel((current) => (current === channel ? null : channel));};@@ -112,13 +114,7 @@ function PersonalGroupContent({);}-export function ImBotSection({- group,- onGroupChange,-}: {- group: ImBotSettingsGroup;- onGroupChange: (group: ImBotSettingsGroup) => void;-}) {+export function ImBotSection({ targetGroup }: { targetGroup: ImBotSettingsGroup | null }) {const { t } = useTranslation();const { mode, dataOwnerId, user } = useAuth();const identity: ImBotIdentity = {@@ -130,10 +126,27 @@ export function ImBotSection({const discordVisible = showDiscordBot(identity);const larkVisible = showLarkBot(identity);const telegramVisible = showTelegramBot(identity);- const availableGroups = cindyGroupAvailable- ? IM_BOT_SETTINGS_GROUPS- : PERSONAL_ONLY_IM_BOT_SETTINGS_GROUPS;- const effectiveGroup = cindyGroupAvailable ? group : 'personal';+ const cindySectionRef = useRef<HTMLElement | null>(null);+ const personalSectionRef = useRef<HTMLElement | null>(null);+ const effectiveTargetGroup = targetGroup+ ? cindyGroupAvailable+ ? targetGroup+ : 'personal'+ : null;++ useEffect(() => {+ if (!effectiveTargetGroup) return;+ const section =+ effectiveTargetGroup === 'cindy' ? cindySectionRef.current : personalSectionRef.current;+ if (!section) return;++ // SettingsView 切 tab 时会先把外层滚动容器回顶;下一帧再处理分区深链,+ // 避免父级回顶覆盖 personal 定位。+ const frame = window.requestAnimationFrame(() => {+ section.scrollIntoView({ block: 'start', inline: 'nearest' });+ });+ return () => window.cancelAnimationFrame(frame);+ }, [effectiveTargetGroup]);return (<div className="flex flex-col gap-2">@@ -146,67 +159,44 @@ export function ImBotSection({</span></div>- {/* 分栏 pill tab —— 视觉对齐 ImDefaultSettingsSection 的 agent 切换器 */}- <div- className="mt-3 flex h-9 w-[220px] items-center gap-0.5 rounded-full bg-[var(--surface-chip)] p-[3px]"- role="tablist"- aria-label={t('settings.sections.imBot')}- >- {availableGroups.map((g) => {- const active = g === effectiveGroup;- return (- <button- key={g}- type="button"- role="tab"- id={`im-bot-group-tab-${g}`}- aria-selected={active}- aria-controls={`im-bot-group-panel-${g}`}- onClick={() => {- if (!active) onGroupChange(g);- }}- className={cn(- 'flex h-full min-w-0 flex-1 items-center justify-center rounded-full px-3',- 'border text-[13px] leading-none transition-colors',- active- ? 'border-[var(--border-default)] bg-[var(--surface-elevated)] font-medium text-[var(--settings-section-title)]'- : 'border-transparent font-normal text-[var(--text-secondary)] hover:text-[var(--text-primary)]',- )}+ <div key={`${mode}:${dataOwnerId ?? 'none'}`} className="mt-4 flex flex-col gap-8">+ {cindyGroupAvailable && (+ <section+ ref={cindySectionRef}+ id="im-bot-group-cindy"+ aria-labelledby="im-bot-group-heading-cindy"+ className="flex scroll-mt-4 flex-col gap-3"+ >+ <h3+ id="im-bot-group-heading-cindy"+ className="text-14 font-medium leading-[1.4] text-[var(--settings-section-title)]">- <span className="truncate">{t(IM_BOT_GROUP_LABEL_KEY[g])}</span>- </button>- );- })}- </div>-- {/* Tips —— 一句话讲清当前分栏与另一栏的差异 */}- <div className="mt-2 flex items-start gap-2 rounded-lg bg-[var(--surface-chip)] px-3.5 py-2.5">- <Lightbulb size={14} className="mt-[2px] shrink-0 text-[var(--text-tertiary)]" />- <p className="text-[12.5px] leading-[1.6] text-[var(--text-secondary)]">- {t(- effectiveGroup === 'personal' && !discordVisible- ? 'settings.imBot.tips.personalFeishuOnly'- : IM_BOT_GROUP_TIP_KEY[effectiveGroup],- )}- </p>- </div>+ {t(IM_BOT_GROUP_LABEL_KEY.cindy)}+ </h3>+ <GroupTip message={t(IM_BOT_GROUP_TIP_KEY.cindy)} />+ <HookConnectionsSection />+ </section>+ )}- <div- key={`${mode}:${dataOwnerId ?? 'none'}`}- role="tabpanel"- id={`im-bot-group-panel-${effectiveGroup}`}- aria-labelledby={`im-bot-group-tab-${effectiveGroup}`}- className="mt-4 flex flex-col gap-8"- >- {effectiveGroup === 'cindy' ? (- <HookConnectionsSection />- ) : (+ <section+ ref={personalSectionRef}+ id="im-bot-group-personal"+ aria-labelledby="im-bot-group-heading-personal"+ className="flex scroll-mt-4 flex-col gap-3"+ >+ <h3+ id="im-bot-group-heading-personal"+ className="text-14 font-medium leading-[1.4] text-[var(--settings-section-title)]"+ >+ {t(IM_BOT_GROUP_LABEL_KEY.personal)}+ </h3>+ <GroupTip message={t(IM_BOT_GROUP_TIP_KEY.personal)} /><PersonalGroupContentshowDiscord={discordVisible}showLark={larkVisible}showTelegram={telegramVisible}/>- )}+ </section></div></div>);diff --git a/apps/desktop/src/renderer/components/settings/SettingsView.tsx b/apps/desktop/src/renderer/components/settings/SettingsView.tsxindex 0fc697b487..4c713b6dc0 100644--- a/apps/desktop/src/renderer/components/settings/SettingsView.tsx+++ b/apps/desktop/src/renderer/components/settings/SettingsView.tsx@@ -91,18 +91,16 @@ export function SettingsView() {setSearchParams(next, { replace: true });}, [canAccessBilling, rawTab, searchParams, setSearchParams]);- // 「IM 机器人」页内分栏:?imGroup=cindy|personal 定位到某个 tab(深链可直达)。- // 缺省/非法 imGroup 一律落到默认分栏:旧「飞书机器人」深链落「个人」(飞书在- // 个人栏),其余(im-bot / slack-bot / tina)落「Cindy」。+ // 「IM 机器人」官方/个人已纵向同页展示;?imGroup=cindy|personal 只负责把+ // 深链滚动到对应分区。旧「飞书机器人」深链继续定位到「个人」。const activeImGroupRaw = activeTab === 'im-bot' ? searchParams.get('imGroup') : null;const activeImBotGroup: ImBotSettingsGroup | null = isImBotSettingsGroup(activeImGroupRaw)? activeImGroupRaw: null;- const imBotFallbackGroup: ImBotSettingsGroup =- searchParams.get('tab') === 'feishu-bot' ? 'personal' : 'cindy';- // 渲染层直接用兜底值,imGroup 缺省时不回写 URL(少一次 replace,深链语义不变)。- const resolvedImBotGroup: ImBotSettingsGroup | null =- activeTab === 'im-bot' ? (activeImBotGroup ?? imBotFallbackGroup) : null;+ const imBotTargetGroup: ImBotSettingsGroup | null =+ activeTab === 'im-bot'+ ? (activeImBotGroup ?? (searchParams.get('tab') === 'feishu-bot' ? 'personal' : null))+ : null;// 切分区后外层滚动容器回顶:滚动偏移是容器的、不随内层 key 重挂归零,// 长页滚到底再切短页会停在中段(review 反馈)。瞬时回顶,不做平滑。@@ -132,17 +130,6 @@ export function SettingsView() {[activeTab, searchParams, setSearchParams],);- const handleSelectImBotGroup = useCallback(- (group: ImBotSettingsGroup) => {- const next = new URLSearchParams(searchParams);- next.delete('openPanel');- next.set('tab', 'im-bot');- next.set('imGroup', group);- setSearchParams(next, { replace: true });- },- [searchParams, setSearchParams],- );-useEffect(() => {if (activeTab !== 'help') {setHelpAssistantOpen(false);@@ -508,14 +495,9 @@ export function SettingsView() {{activeTab === 'im-bot' && (<div role="tabpanel" id="settings-panel-im-bot" aria-labelledby="settings-tab-im-bot">- {/* 单页 + 页内分栏 tab:imGroup 缺省时渲染默认分栏 */}+ {/* 官方/个人纵向同页展示;imGroup 只保留深链定位语义。 */}<section aria-label={t('settings.sections.imBot')}>- {resolvedImBotGroup && (- <ImBotSection- group={resolvedImBotGroup}- onGroupChange={handleSelectImBotGroup}- />- )}+ <ImBotSection targetGroup={imBotTargetGroup} /></section></div>)}diff --git a/apps/desktop/src/renderer/components/settings/__tests__/ImBotSection.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/ImBotSection.test.tsxnew file mode 100644index 0000000000..40dad33ff6--- /dev/null+++ b/apps/desktop/src/renderer/components/settings/__tests__/ImBotSection.test.tsx@@ -0,0 +1,105 @@+// @vitest-environment jsdom+import { render, screen } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { ImBotSection } from '../ImBotSection';++const authState = vi.hoisted(() => ({+ mode: 'cloud' as 'signed-out' | 'local' | 'cloud',+ membershipKind: 'org' as 'personal' | 'org' | null,+}));++vi.mock('@/contexts/AuthContext', () => ({+ useAuth: () => ({+ mode: authState.mode,+ dataOwnerId: 'owner-1',+ user: { membershipKind: authState.membershipKind },+ }),+}));++vi.mock('react-i18next', () => ({+ useTranslation: () => ({ t: (key: string) => key }),+}));++vi.mock('../HookConnectionsSection', () => ({+ HookConnectionsSection: () => <div data-testid="official-connections" />,+}));+vi.mock('../WechatBotSection', () => ({+ WechatBotSection: () => <div data-testid="wechat-bot" />,+}));+vi.mock('../WecomBotSection', () => ({+ WecomBotSection: () => <div data-testid="wecom-bot" />,+}));+vi.mock('../FeishuBotSection', () => ({+ FeishuBotSection: () => <div data-testid="feishu-bot" />,+}));+vi.mock('../DingTalkBotSection', () => ({+ DingTalkBotSection: () => <div data-testid="dingtalk-bot" />,+}));+vi.mock('../DiscordBotSection', () => ({+ DiscordBotSection: () => <div data-testid="discord-bot" />,+}));+vi.mock('../TelegramBotSection', () => ({+ TelegramBotSection: () => <div data-testid="telegram-bot" />,+}));++describe('ImBotSection', () => {+ const scrollIntoView = vi.fn();++ beforeEach(() => {+ authState.mode = 'cloud';+ authState.membershipKind = 'org';+ scrollIntoView.mockReset();+ Object.defineProperty(Element.prototype, 'scrollIntoView', {+ configurable: true,+ value: scrollIntoView,+ });+ vi.spyOn(window, 'requestAnimationFrame').mockImplementation((callback) => {+ callback(0);+ return 1;+ });+ vi.spyOn(window, 'cancelAnimationFrame').mockImplementation(() => {});+ });++ it('shows official and personal bot types together in vertical sections', () => {+ render(<ImBotSection targetGroup={null} />);++ const official = screen.getByRole('heading', { name: 'settings.imBot.groups.cindy' });+ const personal = screen.getByRole('heading', { name: 'settings.imBot.groups.personal' });++ expect(official.compareDocumentPosition(personal) & Node.DOCUMENT_POSITION_FOLLOWING).toBe(+ Node.DOCUMENT_POSITION_FOLLOWING,+ );+ expect(screen.getByTestId('official-connections')).toBeTruthy();+ expect(screen.getByTestId('wechat-bot')).toBeTruthy();+ expect(screen.getByTestId('wecom-bot')).toBeTruthy();+ expect(screen.getByTestId('feishu-bot')).toBeTruthy();+ expect(screen.getByTestId('dingtalk-bot')).toBeTruthy();+ expect(screen.getByTestId('discord-bot')).toBeTruthy();+ expect(screen.getByTestId('telegram-bot')).toBeTruthy();+ expect(scrollIntoView).not.toHaveBeenCalled();+ });++ it('keeps imGroup deep links by scrolling to the requested section', () => {+ render(<ImBotSection targetGroup="personal" />);++ expect(scrollIntoView).toHaveBeenCalledWith({ block: 'start', inline: 'nearest' });+ expect(scrollIntoView.mock.instances[0]).toBe(+ screen.getByRole('heading', { name: 'settings.imBot.groups.personal' }).closest('section'),+ );+ });++ it('shows only the personal section when the official group is unavailable', () => {+ authState.mode = 'local';+ authState.membershipKind = null;++ render(<ImBotSection targetGroup="cindy" />);++ expect(screen.queryByRole('heading', { name: 'settings.imBot.groups.cindy' })).toBeNull();+ expect(screen.getByRole('heading', { name: 'settings.imBot.groups.personal' })).toBeTruthy();+ expect(screen.getByText('settings.imBot.tips.personal')).toBeTruthy();+ expect(scrollIntoView.mock.instances[0]).toBe(+ screen.getByRole('heading', { name: 'settings.imBot.groups.personal' }).closest('section'),+ );+ });+});diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex ae14e332df..ab28a5242d 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -2792,9 +2792,8 @@"personal": "Personal"},"tips": {- "cindy": "Cindy is the official shared bot — no credentials needed. Connect Slack and just @Cindy to hand off tasks.",- "personal": "Personal connections include WeChat scan authorization and your own WeCom / Feishu / Discord / Telegram credentials. Each channel keeps independent new-conversation settings.",- "personalFeishuOnly": "Personal connections include WeChat scan authorization plus your own WeCom, Feishu, and DingTalk credentials. Each channel keeps independent new-conversation settings."+ "cindy": "Provided and maintained by Cindy. No need to create a bot or supply credentials—follow the connection steps to get started.",+ "personal": "Use your own account or bot and manage the required credentials yourself. Each channel keeps its own account, permissions, and settings."},"defaults": {"title": "New Conversation Configuration",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex 04db03876d..45fe69a3dc 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -2791,9 +2791,8 @@"personal": "個人"},"tips": {- "cindy": "Cindy は公式提供の共有ボットです。認証情報の申請は不要で、Slack を連携して @Cindy にメンションするだけでタスクを任せられます。",- "personal": "個人接続には WeChat のスキャン認証と、自分の WeCom / Feishu / Discord / Telegram 認証情報を使用する接続があります。新規会話設定はチャネルごとに保存されます。",- "personalFeishuOnly": "個人接続には WeChat のスキャン認証と、自分の WeCom / Feishu / DingTalk 認証情報を使用する接続があります。新規会話設定はチャネルごとに保存されます。"+ "cindy": "Cindy が提供・管理します。自分でボットを作成したり認証情報を用意したりする必要はなく、案内に沿って接続するだけで利用できます。",+ "personal": "自分のアカウントまたはボットを接続し、必要な認証情報を自分で管理します。アカウント、権限、設定はチャネルごとに保存されます。"},"defaults": {"title": "新規会話設定",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex 33fac30bf7..16a7ee272a 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -2791,9 +2791,8 @@"personal": "개인"},"tips": {- "cindy": "Cindy는 공식 제공 공유 봇입니다. 자격 증명을 신청할 필요 없이 Slack을 연결하고 @Cindy를 멘션하면 바로 작업을 맡길 수 있습니다.",- "personal": "개인 연결에는 WeChat 스캔 인증과 직접 발급한 WeCom / Feishu / Discord / Telegram 인증 정보 연결이 포함됩니다. 새 대화 설정은 채널별로 저장됩니다.",- "personalFeishuOnly": "개인 연결에는 WeChat 스캔 인증과 직접 발급한 WeCom, Feishu 및 DingTalk 자격 증명 연결이 포함됩니다. 새 대화 설정은 채널별로 저장됩니다."+ "cindy": "Cindy가 제공하고 관리합니다. 봇을 직접 만들거나 인증 정보를 준비할 필요 없이 안내에 따라 연결하면 바로 사용할 수 있습니다.",+ "personal": "본인의 계정이나 봇을 연결하고 필요한 인증 정보를 직접 관리합니다. 계정, 권한 및 설정은 채널별로 저장됩니다."},"defaults": {"title": "새 대화 설정",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 35bbe49655..693cda06db 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -2791,9 +2791,8 @@"personal": "个人"},"tips": {- "cindy": "Cindy 是官方提供的共享机器人:无需申请任何凭证,连接 Slack 后 @Cindy 即可直接派活。",- "personal": "个人连接包括微信扫码,以及使用自有凭证接入企业微信 / 飞书 / Discord / Telegram;各渠道独立保存新对话配置。",- "personalFeishuOnly": "个人连接包括微信扫码,以及使用自有凭证接入企业微信、飞书和钉钉;各渠道独立保存新对话配置。"+ "cindy": "由 Cindy 提供并维护。无需自行创建机器人或准备凭证,按引导连接后即可使用。",+ "personal": "使用你自己的账号或机器人,由你提供并管理所需凭证;每个渠道的账号、权限和设置独立保存。"},"defaults": {"title": "新对话配置",