Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(im): 中国大陆版开放完整机器人渠道 (#5230)

Dash168bbd18e925
diff --git a/apps/desktop/src/renderer/components/settings/FeishuBotSection.tsx b/apps/desktop/src/renderer/components/settings/FeishuBotSection.tsx
index 5e18746ee8..ed8dc8de00 100644
--- a/apps/desktop/src/renderer/components/settings/FeishuBotSection.tsx
+++ b/apps/desktop/src/renderer/components/settings/FeishuBotSection.tsx
@@ -19,7 +19,6 @@ const APP_LAUNCHER_URL: Record<FeishuBotService, string> = {
lark: 'https://open.larksuite.com/page/launcher?from=backend_oneclick',
};
const FEISHU_SERVICES = ['feishu', 'lark'] as const;
-const FEISHU_ONLY = ['feishu'] as const;
const statusKey: Record<FeishuBotStatus, string> = {
idle: 'settings.feishuBot.status.needsConfig',
@@ -58,11 +57,13 @@ function maskTail(value: string): string {
export function FeishuBotSection({
expanded,
onToggle,
- showLark,
+ preferredService,
+ searchActivation,
}: {
expanded: boolean;
onToggle: () => void;
- showLark: boolean;
+ preferredService?: FeishuBotService | null;
+ searchActivation?: number;
}) {
const {
service,
@@ -74,6 +75,7 @@ export function FeishuBotSection({
status,
errorMessage,
hasSavedCreds,
+ hasLoadedState,
ownerOpenId,
validationError,
isSaving,
@@ -89,20 +91,12 @@ export function FeishuBotSection({
const { confirm } = useConfirmDialog();
const { t } = useTranslation();
- const showSavedCredentialsCard = shouldShowSavedCredentialsCard(hasSavedCreds);
- // 已保存的 Lark 凭证仍允许查看和清除,身份限制只影响新的配置入口。
- const configurableService = showLark || hasSavedCreds ? service : 'feishu';
- const canSave =
- service === configurableService &&
- appId.trim().length > 0 &&
- appSecret.trim().length > 0 &&
- !isSaving;
-
useEffect(() => {
- if (!showLark && !hasSavedCreds && service === 'lark') {
- setService('feishu');
- }
- }, [hasSavedCreds, service, setService, showLark]);
+ if (hasLoadedState && !hasSavedCreds && preferredService) setService(preferredService);
+ }, [hasLoadedState, hasSavedCreds, preferredService, searchActivation, setService]);
+
+ const showSavedCredentialsCard = shouldShowSavedCredentialsCard(hasSavedCreds);
+ const canSave = appId.trim().length > 0 && appSecret.trim().length > 0 && !isSaving;
const handleClearClick = useCallback(async () => {
const confirmed = await confirm({
@@ -116,8 +110,8 @@ export function FeishuBotSection({
}, [confirm, clear, t]);
const openLauncher = useCallback(() => {
- window.electronAPI.openExternal?.(APP_LAUNCHER_URL[configurableService]);
- }, [configurableService]);
+ window.electronAPI.openExternal?.(APP_LAUNCHER_URL[service]);
+ }, [service]);
return (
<ImChannelSettingsCard
@@ -169,9 +163,8 @@ export function FeishuBotSection({
/>
) : (
<ManualConfig
- service={configurableService}
+ service={service}
setService={setService}
- showLark={showLark}
appId={appId}
setAppId={setAppId}
appSecret={appSecret}
@@ -316,7 +309,6 @@ function SavedCredentialsCard(props: {
function ManualConfig(props: {
service: FeishuBotService;
setService: (service: FeishuBotService) => void;
- showLark: boolean;
appId: string;
setAppId: (v: string) => void;
appSecret: string;
@@ -344,7 +336,7 @@ function ManualConfig(props: {
aria-label={t('settings.feishuBot.serviceAria')}
value={props.service}
onValueChange={props.setService}
- options={(props.showLark ? FEISHU_SERVICES : FEISHU_ONLY).map((service) => ({
+ options={FEISHU_SERVICES.map((service) => ({
value: service,
label: t(`settings.feishuBot.services.${service}`),
}))}
diff --git a/apps/desktop/src/renderer/components/settings/ImBotSection.settings-search.ts b/apps/desktop/src/renderer/components/settings/ImBotSection.settings-search.ts
index 2b000ccf35..8fb1aacc5c 100644
--- a/apps/desktop/src/renderer/components/settings/ImBotSection.settings-search.ts
+++ b/apps/desktop/src/renderer/components/settings/ImBotSection.settings-search.ts
@@ -1,4 +1,4 @@
-import { showCindyGroup, showDiscordBot, showTelegramBot } from './imBotVisibility';
+import { showCindyGroup } from './imBotVisibility';
import type { SettingsSearchModule } from './settingsSearchTypes';
/** Static search metadata owned by this settings module; no component mounting or IPC. */
@@ -6,16 +6,109 @@ export default {
id: 'im-bot',
order: 12,
entries: [
- { id: 'imBot', tab: 'im-bot', targetId: 'settings-panel-im-bot', titleKey: 'settings.tabs.imBot', sectionKey: 'settings.sections.imBot' },
- { id: 'imBot.cindy', isVisible: showCindyGroup, tab: 'im-bot', targetId: 'im-bot-group-cindy', titleKey: 'settings.imBot.groups.cindy', sectionKey: 'settings.sections.imBot', aliases: ['Cindy', 'official bot', '官方机器人'] },
- { id: 'imBot.cindy.slack', isVisible: (identity) => identity.mode === 'cloud' && showCindyGroup(identity), fallbackTargetId: 'im-bot-group-cindy', tab: 'im-bot', targetId: 'cindy-im-slack', titleKey: 'settings.remoteControl.sections.hook', sectionKey: 'settings.imBot.groups.cindy', aliases: ['Slack', 'Slack bot', 'IM'] },
- { id: 'imBot.cindy.telegram', isVisible: (identity) => identity.mode === 'cloud' && showCindyGroup(identity), fallbackTargetId: 'im-bot-group-cindy', tab: 'im-bot', targetId: 'cindy-im-telegram', titleKey: 'settings.tina.prefs.providerTelegram', sectionKey: 'settings.imBot.groups.cindy', descriptionKey: 'settings.remoteControl.hook.telegram.description', aliases: ['Telegram', 'Telegram bot'] },
- { id: 'imBot.cindy.x', isVisible: (identity) => identity.mode === 'cloud' && showCindyGroup(identity), fallbackTargetId: 'im-bot-group-cindy', tab: 'im-bot', targetId: 'cindy-im-x', titleKey: 'settings.tina.prefs.providerX', sectionKey: 'settings.imBot.groups.cindy', descriptionKey: 'settings.remoteControl.hook.x.description', aliases: ['X', 'Twitter'] },
- { id: 'imBot.wechat', tab: 'im-bot', targetId: 'personal-im-wechat', titleKey: 'settings.wechatBot.title', sectionKey: 'settings.imBot.groups.personal', aliases: ['WeChat', '微信', '个人微信'] },
- { id: 'imBot.wecom', tab: 'im-bot', targetId: 'personal-im-wecom', titleKey: 'settings.wecomBot.title', sectionKey: 'settings.imBot.groups.personal', aliases: ['WeCom', '企业微信', '企业微信机器人'] },
- { id: 'imBot.feishu', tab: 'im-bot', targetId: 'personal-im-feishu', titleKey: 'settings.feishuBot.title', sectionKey: 'settings.imBot.groups.personal', aliases: ['Feishu', '飞书', '飞书机器人'] },
- { id: 'imBot.dingtalk', tab: 'im-bot', targetId: 'personal-im-dingtalk', titleKey: 'settings.dingtalkBot.title', sectionKey: 'settings.imBot.groups.personal', aliases: ['DingTalk', '钉钉', '钉钉机器人'] },
- { id: 'imBot.discord', isVisible: showDiscordBot, tab: 'im-bot', targetId: 'personal-im-discord', titleKey: 'settings.discordBot.title', sectionKey: 'settings.imBot.groups.personal', aliases: ['Discord', 'Discord bot'] },
- { id: 'imBot.telegram', isVisible: showTelegramBot, tab: 'im-bot', targetId: 'personal-im-telegram', titleKey: 'settings.telegramBot.title', sectionKey: 'settings.imBot.groups.personal', aliases: ['Telegram', 'Telegram bot'] },
+ {
+ id: 'imBot',
+ tab: 'im-bot',
+ targetId: 'settings-panel-im-bot',
+ titleKey: 'settings.tabs.imBot',
+ sectionKey: 'settings.sections.imBot',
+ },
+ {
+ id: 'imBot.cindy',
+ isVisible: showCindyGroup,
+ tab: 'im-bot',
+ targetId: 'im-bot-group-cindy',
+ titleKey: 'settings.imBot.groups.cindy',
+ sectionKey: 'settings.sections.imBot',
+ aliases: ['Cindy', 'official bot', '官方机器人'],
+ },
+ {
+ id: 'imBot.cindy.slack',
+ isVisible: (identity) => identity.mode === 'cloud' && showCindyGroup(identity),
+ fallbackTargetId: 'im-bot-group-cindy',
+ tab: 'im-bot',
+ targetId: 'cindy-im-slack',
+ titleKey: 'settings.remoteControl.sections.hook',
+ sectionKey: 'settings.imBot.groups.cindy',
+ aliases: ['Slack', 'Slack bot', 'IM'],
+ },
+ {
+ id: 'imBot.cindy.telegram',
+ isVisible: (identity) => identity.mode === 'cloud' && showCindyGroup(identity),
+ fallbackTargetId: 'im-bot-group-cindy',
+ tab: 'im-bot',
+ targetId: 'cindy-im-telegram',
+ titleKey: 'settings.tina.prefs.providerTelegram',
+ sectionKey: 'settings.imBot.groups.cindy',
+ descriptionKey: 'settings.remoteControl.hook.telegram.description',
+ aliases: ['Telegram', 'Telegram bot'],
+ },
+ {
+ id: 'imBot.cindy.x',
+ isVisible: (identity) => identity.mode === 'cloud' && showCindyGroup(identity),
+ fallbackTargetId: 'im-bot-group-cindy',
+ tab: 'im-bot',
+ targetId: 'cindy-im-x',
+ titleKey: 'settings.tina.prefs.providerX',
+ sectionKey: 'settings.imBot.groups.cindy',
+ descriptionKey: 'settings.remoteControl.hook.x.description',
+ aliases: ['X', 'Twitter'],
+ },
+ {
+ id: 'imBot.wechat',
+ tab: 'im-bot',
+ targetId: 'personal-im-wechat',
+ titleKey: 'settings.wechatBot.title',
+ sectionKey: 'settings.imBot.groups.personal',
+ aliases: ['WeChat', '微信', '个人微信'],
+ },
+ {
+ id: 'imBot.wecom',
+ tab: 'im-bot',
+ targetId: 'personal-im-wecom',
+ titleKey: 'settings.wecomBot.title',
+ sectionKey: 'settings.imBot.groups.personal',
+ aliases: ['WeCom', '企业微信', '企业微信机器人'],
+ },
+ {
+ id: 'imBot.feishu',
+ tab: 'im-bot',
+ targetId: 'personal-im-feishu',
+ titleKey: 'settings.feishuBot.title',
+ sectionKey: 'settings.imBot.groups.personal',
+ aliases: ['Feishu', '飞书', '飞书机器人'],
+ },
+ {
+ id: 'imBot.lark',
+ tab: 'im-bot',
+ targetId: 'personal-im-feishu',
+ titleKey: 'settings.feishuBot.services.lark',
+ sectionKey: 'settings.imBot.groups.personal',
+ aliases: ['Lark bot'],
+ },
+ {
+ id: 'imBot.dingtalk',
+ tab: 'im-bot',
+ targetId: 'personal-im-dingtalk',
+ titleKey: 'settings.dingtalkBot.title',
+ sectionKey: 'settings.imBot.groups.personal',
+ aliases: ['DingTalk', '钉钉', '钉钉机器人'],
+ },
+ {
+ id: 'imBot.discord',
+ tab: 'im-bot',
+ targetId: 'personal-im-discord',
+ titleKey: 'settings.discordBot.title',
+ sectionKey: 'settings.imBot.groups.personal',
+ aliases: ['Discord', 'Discord bot'],
+ },
+ {
+ id: 'imBot.telegram',
+ tab: 'im-bot',
+ targetId: 'personal-im-telegram',
+ titleKey: 'settings.telegramBot.title',
+ sectionKey: 'settings.imBot.groups.personal',
+ aliases: ['Telegram', 'Telegram bot'],
+ },
],
} satisfies SettingsSearchModule;
diff --git a/apps/desktop/src/renderer/components/settings/ImBotSection.tsx b/apps/desktop/src/renderer/components/settings/ImBotSection.tsx
index 5bb0df94ba..9e9d95808d 100644
--- a/apps/desktop/src/renderer/components/settings/ImBotSection.tsx
+++ b/apps/desktop/src/renderer/components/settings/ImBotSection.tsx
@@ -13,9 +13,8 @@
* 保持页面顶部不动,旧「飞书机器人」深链继续定位到「个人」。
* Beta 标识用一颗 pill(主题 token,无硬编码 hex),表示整块功能处于 Beta。
*
- * 可见性(imBotVisibility 单点):本地模式与「国区构建 + 个人账号登录」都
- * 没有 Cindy 分栏(深链/兜底一律落「个人」);国区个人账号的个人分栏进一步
- * 隐藏 Discord / Telegram 机器人,保留中国大陆可用的个人连接。
+ * 可见性(imBotVisibility 单点):本地模式没有 Cindy 分栏,深链落「个人」。
+ * 个人机器人在各构建与账号中都显示。
*/
import { Lightbulb } from 'lucide-react';
@@ -24,7 +23,6 @@ import { useTranslation } from 'react-i18next';
import { useSettingsSearchNavigation } from './SettingsSearchNavigation';
import { useAuth } from '@/contexts/AuthContext';
-import { CURRENT_CINDY_REGION } from '../../../shared/brandRegion';
import { DiscordBotSection } from './DiscordBotSection';
import { DingTalkBotSection } from './DingTalkBotSection';
import { FeishuBotSection } from './FeishuBotSection';
@@ -32,13 +30,7 @@ import { HookConnectionsSection } from './HookConnectionsSection';
import { TelegramBotSection } from './TelegramBotSection';
import { WechatBotSection } from './WechatBotSection';
import { WecomBotSection } from './WecomBotSection';
-import {
- showCindyGroup,
- showDiscordBot,
- showLarkBot,
- showTelegramBot,
- type ImBotIdentity,
-} from './imBotVisibility';
+import { showCindyGroup } from './imBotVisibility';
/** 「IM 机器人」页面分区 id(与 ?imGroup= 参数共用)。 */
export type ImBotSettingsGroup = 'cindy' | 'personal';
@@ -68,18 +60,14 @@ export function isImBotSettingsGroup(value: string | null): value is ImBotSettin
return value === 'cindy' || value === 'personal';
}
-/** 个人栏内容 —— 用户自配凭证的机器人(国区个人账号无 Discord/Lark/Telegram)。 */
+/** 个人栏内容 —— 用户自配凭证的机器人。 */
function PersonalGroupContent({
- showDiscord,
- showLark,
- showTelegram,
targetChannel,
+ preferredFeishuService,
activation,
}: {
- showDiscord: boolean;
- showLark: boolean;
- showTelegram: boolean;
targetChannel: 'wechat' | 'wecom' | 'feishu' | 'discord' | 'telegram' | 'dingtalk' | null;
+ preferredFeishuService: 'feishu' | 'lark' | null;
activation: number;
}) {
const [expandedChannel, setExpandedChannel] = useState<
@@ -101,43 +89,36 @@ function PersonalGroupContent({
<FeishuBotSection
expanded={expandedChannel === 'feishu'}
onToggle={() => toggle('feishu')}
- showLark={showLark}
+ preferredService={preferredFeishuService}
+ searchActivation={activation}
/>
<DingTalkBotSection
expanded={expandedChannel === 'dingtalk'}
onToggle={() => toggle('dingtalk')}
/>
- {showDiscord && (
- <DiscordBotSection
- expanded={expandedChannel === 'discord'}
- onToggle={() => toggle('discord')}
- />
- )}
- {showTelegram && (
- <TelegramBotSection
- expanded={expandedChannel === 'telegram'}
- onToggle={() => toggle('telegram')}
- />
- )}
+ <DiscordBotSection
+ expanded={expandedChannel === 'discord'}
+ onToggle={() => toggle('discord')}
+ />
+ <TelegramBotSection
+ expanded={expandedChannel === 'telegram'}
+ onToggle={() => toggle('telegram')}
+ />
</div>
);
}
export function ImBotSection({ targetGroup }: { targetGroup: ImBotSettingsGroup | null }) {
const { t } = useTranslation();
- const { mode, dataOwnerId, user } = useAuth();
+ const { mode, dataOwnerId } = useAuth();
const { entry, activation } = useSettingsSearchNavigation();
- const identity: ImBotIdentity = {
- region: CURRENT_CINDY_REGION,
- mode,
- membershipKind: user?.membershipKind ?? null,
- };
- const cindyGroupAvailable = showCindyGroup(identity);
- const discordVisible = showDiscordBot(identity);
- const larkVisible = showLarkBot(identity);
- const telegramVisible = showTelegramBot(identity);
- const targetChannel = (['wechat', 'wecom', 'feishu', 'discord', 'telegram', 'dingtalk'] as const)
- .find((channel) => entry?.targetId === 'personal-im-' + channel) ?? null;
+ const cindyGroupAvailable = showCindyGroup({ mode });
+ const targetChannel =
+ (['wechat', 'wecom', 'feishu', 'discord', 'telegram', 'dingtalk'] as const).find(
+ (channel) => entry?.targetId === 'personal-im-' + channel,
+ ) ?? null;
+ const preferredFeishuService =
+ entry?.id === 'imBot.lark' ? 'lark' : entry?.id === 'imBot.feishu' ? 'feishu' : null;
const cindySectionRef = useRef<HTMLElement | null>(null);
const personalSectionRef = useRef<HTMLElement | null>(null);
const effectiveTargetGroup = targetGroup
@@ -204,10 +185,8 @@ export function ImBotSection({ targetGroup }: { targetGroup: ImBotSettingsGroup
</h3>
<GroupTip message={t(IM_BOT_GROUP_TIP_KEY.personal)} />
<PersonalGroupContent
- showDiscord={discordVisible}
- showLark={larkVisible}
- showTelegram={telegramVisible}
targetChannel={targetChannel}
+ preferredFeishuService={preferredFeishuService}
activation={activation}
/>
</section>
diff --git a/apps/desktop/src/renderer/components/settings/__tests__/ImBotSection.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/ImBotSection.test.tsx
index 40dad33ff6..0dca31f804 100644
--- a/apps/desktop/src/renderer/components/settings/__tests__/ImBotSection.test.tsx
+++ b/apps/desktop/src/renderer/components/settings/__tests__/ImBotSection.test.tsx
@@ -1,8 +1,10 @@
// @vitest-environment jsdom
-import { render, screen } from '@testing-library/react';
+import { fireEvent, render, screen } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { ImBotSection } from '../ImBotSection';
+import { SettingsSearchNavigationContext } from '../SettingsSearchNavigation';
+import imBotSearch from '../ImBotSection.settings-search';
const authState = vi.hoisted(() => ({
mode: 'cloud' as 'signed-out' | 'local' | 'cloud',
@@ -30,8 +32,43 @@ vi.mock('../WechatBotSection', () => ({
vi.mock('../WecomBotSection', () => ({
WecomBotSection: () => <div data-testid="wecom-bot" />,
}));
-vi.mock('../FeishuBotSection', () => ({
- FeishuBotSection: () => <div data-testid="feishu-bot" />,
+vi.mock('@/hooks/useFeishuBot', async () => {
+ const { useState } = await import('react');
+ return {
+ useFeishuBot: () => {
+ const [service, setService] = useState<'feishu' | 'lark'>('feishu');
+ return {
+ service,
+ setService,
+ appId: '',
+ setAppId: vi.fn(),
+ appSecret: '',
+ setAppSecret: vi.fn(),
+ status: 'idle',
+ errorMessage: null,
+ hasSavedCreds: false,
+ hasLoadedState: true,
+ ownerOpenId: null,
+ validationError: null,
+ isSaving: false,
+ isClearing: false,
+ isReconnecting: false,
+ save: vi.fn(),
+ reconnect: vi.fn(),
+ clear: vi.fn(),
+ };
+ },
+ };
+});
+vi.mock('@/components/ui/confirm-dialog-provider', () => ({
+ useConfirmDialog: () => ({ confirm: vi.fn() }),
+}));
+vi.mock('../ImChannelSettingsCard', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('../ImChannelSettingsCard')>()),
+ useImChannelSettingsSummary: () => [null, vi.fn()],
+}));
+vi.mock('../ImDefaultSettingsSection', () => ({
+ ImDefaultSettingsSection: () => null,
}));
vi.mock('../DingTalkBotSection', () => ({
DingTalkBotSection: () => <div data-testid="dingtalk-bot" />,
@@ -73,13 +110,49 @@ describe('ImBotSection', () => {
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.getByRole('button', { name: /settings.feishuBot.title/ })).toBeTruthy();
expect(screen.getByTestId('dingtalk-bot')).toBeTruthy();
expect(screen.getByTestId('discord-bot')).toBeTruthy();
expect(screen.getByTestId('telegram-bot')).toBeTruthy();
expect(scrollIntoView).not.toHaveBeenCalled();
});
+ it('shows official, Discord, and Telegram bots to personal cloud accounts', () => {
+ authState.membershipKind = 'personal';
+
+ render(<ImBotSection targetGroup="cindy" />);
+
+ expect(screen.getByTestId('official-connections')).toBeTruthy();
+ expect(screen.getByTestId('discord-bot')).toBeTruthy();
+ expect(screen.getByTestId('telegram-bot')).toBeTruthy();
+ expect(scrollIntoView.mock.instances[0]).toBe(
+ screen.getByRole('heading', { name: 'settings.imBot.groups.cindy' }).closest('section'),
+ );
+ });
+
+ it('shows and selects Lark for a personal cloud account opened from Lark search', () => {
+ authState.membershipKind = 'personal';
+ const entry = imBotSearch.entries.find((item) => item.id === 'imBot.lark')!;
+
+ render(
+ <SettingsSearchNavigationContext.Provider value={{ entry, activation: 1 }}>
+ <ImBotSection targetGroup="personal" />
+ </SettingsSearchNavigationContext.Provider>,
+ );
+
+ expect(
+ screen
+ .getByRole('radio', { name: 'settings.feishuBot.services.lark' })
+ .getAttribute('aria-checked'),
+ ).toBe('true');
+ fireEvent.click(screen.getByRole('radio', { name: 'settings.feishuBot.services.feishu' }));
+ expect(
+ screen
+ .getByRole('radio', { name: 'settings.feishuBot.services.feishu' })
+ .getAttribute('aria-checked'),
+ ).toBe('true');
+ });
+
it('keeps imGroup deep links by scrolling to the requested section', () => {
render(<ImBotSection targetGroup="personal" />);
diff --git a/apps/desktop/src/renderer/components/settings/__tests__/imBotVisibility.test.ts b/apps/desktop/src/renderer/components/settings/__tests__/imBotVisibility.test.ts
index 390961f8a5..e72b95af47 100644
--- a/apps/desktop/src/renderer/components/settings/__tests__/imBotVisibility.test.ts
+++ b/apps/desktop/src/renderer/components/settings/__tests__/imBotVisibility.test.ts
@@ -1,75 +1,27 @@
-// imBotVisibility —— 「IM 机器人」分栏/渠道可见性规则:
-// - 国区构建(cn/dev)+ 个人账号 cloud 登录:无 Cindy 分栏、无 Discord/Lark
-// - 企业账号 / global 构建:全量
-// - 国区本地模式 / 未登录:Lark 隐藏;global 仍显示
import { describe, expect, it } from 'vitest';
-import {
- isCnPersonalIdentity,
- showCindyGroup,
- showDiscordBot,
- showLarkBot,
- type ImBotIdentity,
-} from '../imBotVisibility';
+import { showCindyGroup, type ImBotIdentity } from '../imBotVisibility';
function identity(overrides: Partial<ImBotIdentity>): ImBotIdentity {
return { region: 'cn', mode: 'cloud', membershipKind: 'personal', ...overrides };
}
describe('imBotVisibility', () => {
- it('hides the Cindy group, Discord, and Lark for cn-build personal cloud accounts', () => {
- const cnPersonal = identity({});
- expect(isCnPersonalIdentity(cnPersonal)).toBe(true);
- expect(showCindyGroup(cnPersonal)).toBe(false);
- expect(showDiscordBot(cnPersonal)).toBe(false);
- expect(showLarkBot(cnPersonal)).toBe(false);
- });
-
- it('treats the dev region as cn for the personal-account rule', () => {
- const devPersonal = identity({ region: 'dev' });
- expect(showCindyGroup(devPersonal)).toBe(false);
- expect(showDiscordBot(devPersonal)).toBe(false);
- expect(showLarkBot(devPersonal)).toBe(false);
- });
-
- it('keeps everything for cn-build org accounts', () => {
- const cnOrg = identity({ membershipKind: 'org' });
- expect(isCnPersonalIdentity(cnOrg)).toBe(false);
- expect(showCindyGroup(cnOrg)).toBe(true);
- expect(showDiscordBot(cnOrg)).toBe(true);
- expect(showLarkBot(cnOrg)).toBe(true);
- });
-
- it('keeps everything for global-build personal accounts', () => {
- const globalPersonal = identity({ region: 'global' });
- expect(showCindyGroup(globalPersonal)).toBe(true);
- expect(showDiscordBot(globalPersonal)).toBe(true);
- expect(showLarkBot(globalPersonal)).toBe(true);
- });
-
- it('hides Lark for cn local mode while keeping the existing Discord rule', () => {
- const cnLocal = identity({ mode: 'local', membershipKind: null });
- expect(isCnPersonalIdentity(cnLocal)).toBe(false);
- expect(showCindyGroup(cnLocal)).toBe(false);
- expect(showDiscordBot(cnLocal)).toBe(true);
- expect(showLarkBot(cnLocal)).toBe(false);
-
- const devLocal = identity({ region: 'dev', mode: 'local', membershipKind: null });
- expect(showLarkBot(devLocal)).toBe(false);
-
- const globalLocal = identity({ region: 'global', mode: 'local', membershipKind: null });
- expect(showCindyGroup(globalLocal)).toBe(false);
- expect(showDiscordBot(globalLocal)).toBe(true);
- expect(showLarkBot(globalLocal)).toBe(true);
- });
-
- it('hides Lark when signed out in cn/dev and keeps it visible in global', () => {
- expect(showLarkBot(identity({ mode: 'signed-out', membershipKind: null }))).toBe(false);
- expect(showLarkBot(identity({ region: 'dev', mode: 'signed-out', membershipKind: null }))).toBe(
- false,
- );
- expect(
- showLarkBot(identity({ region: 'global', mode: 'signed-out', membershipKind: null })),
- ).toBe(true);
- });
+ it.each(['cn', 'dev', 'global'] as const)(
+ 'shows official bots to %s personal and organization cloud accounts',
+ (region) => {
+ expect(showCindyGroup(identity({ region }))).toBe(true);
+ expect(showCindyGroup(identity({ region, membershipKind: 'org' }))).toBe(true);
+ },
+ );
+
+ it.each(['cn', 'dev', 'global'] as const)(
+ 'hides official bots in %s local mode while retaining the signed-out introduction',
+ (region) => {
+ expect(showCindyGroup(identity({ region, mode: 'local', membershipKind: null }))).toBe(false);
+ expect(showCindyGroup(identity({ region, mode: 'signed-out', membershipKind: null }))).toBe(
+ true,
+ );
+ },
+ );
});
diff --git a/apps/desktop/src/renderer/components/settings/__tests__/settingsSearchCatalog.test.ts b/apps/desktop/src/renderer/components/settings/__tests__/settingsSearchCatalog.test.ts
index f6d4baa6a1..9f39e2e22e 100644
--- a/apps/desktop/src/renderer/components/settings/__tests__/settingsSearchCatalog.test.ts
+++ b/apps/desktop/src/renderer/components/settings/__tests__/settingsSearchCatalog.test.ts
@@ -72,6 +72,7 @@ describe('settings search catalog', () => {
expect(searchSettings(documents, '个人微信').map(({ entry }) => entry.id)).toContain(
'imBot.wechat',
);
+ expect(searchSettings(documents, 'Lark')[0]?.entry.id).toBe('imBot.lark');
});
it('finds common aliases and multi-word queries', () => {
@@ -82,37 +83,80 @@ describe('settings search catalog', () => {
it('keeps the declaration catalog complete and unique', () => {
expect(validateSettingsSearchCatalog()).toEqual([]);
- expect(new Set(SETTINGS_SEARCH_MODULES.map(({ id }) => id)).size).toBe(SETTINGS_SEARCH_MODULES.length);
+ expect(new Set(SETTINGS_SEARCH_MODULES.map(({ id }) => id)).size).toBe(
+ SETTINGS_SEARCH_MODULES.length,
+ );
for (const tab of TAB_IDS) {
- expect(SETTINGS_SEARCH_ENTRIES.some((entry) => entry.tab === tab && entry.titleKey === TAB_LABEL_KEY[tab]), tab).toBe(true);
+ expect(
+ SETTINGS_SEARCH_ENTRIES.some(
+ (entry) => entry.tab === tab && entry.titleKey === TAB_LABEL_KEY[tab],
+ ),
+ tab,
+ ).toBe(true);
}
});
it('uses real translated text in every supported language', async () => {
- const locales = import.meta.glob<Record<string, unknown>>('../../../i18n/locales/*/common.json', { eager: true, import: 'default' });
+ const locales = import.meta.glob<Record<string, unknown>>(
+ '../../../i18n/locales/*/common.json',
+ { eager: true, import: 'default' },
+ );
for (const [path, translation] of Object.entries(locales)) {
const language = path.split('/').at(-2)!;
const instance = createInstance();
- await instance.init({ lng: language, resources: { [language]: { translation } }, fallbackLng: false });
+ await instance.init({
+ lng: language,
+ resources: { [language]: { translation } },
+ fallbackLng: false,
+ });
for (const entry of SETTINGS_SEARCH_ENTRIES) {
- for (const key of [entry.titleKey, entry.sectionKey, entry.descriptionKey, ...(entry.keywordKeys ?? [])].filter((key): key is string => Boolean(key))) {
- expect(instance.exists(key) && typeof instance.t(key) === 'string', language + ': ' + key).toBe(true);
+ for (const key of [
+ entry.titleKey,
+ entry.sectionKey,
+ entry.descriptionKey,
+ ...(entry.keywordKeys ?? []),
+ ].filter((key): key is string => Boolean(key))) {
+ expect(
+ instance.exists(key) && typeof instance.t(key) === 'string',
+ language + ': ' + key,
+ ).toBe(true);
}
}
- const documents = buildSettingsSearchDocuments(instance.t, TAB_IDS, { platform: 'win32', region: 'global', mode: 'cloud', membershipKind: 'personal' });
+ const documents = buildSettingsSearchDocuments(instance.t, TAB_IDS, {
+ platform: 'win32',
+ region: 'global',
+ mode: 'cloud',
+ membershipKind: 'personal',
+ });
for (const document of documents) {
- expect(searchSettings(documents, document.title).some(({ entry }) => entry.id === document.entry.id), language + ': ' + document.entry.id).toBe(true);
+ expect(
+ searchSettings(documents, document.title).some(
+ ({ entry }) => entry.id === document.entry.id,
+ ),
+ language + ': ' + document.entry.id,
+ ).toBe(true);
}
}
});
it('points to existing anchors and covers every search anchor', () => {
- const sources = import.meta.glob<string>('../**/*.tsx', { query: '?raw', eager: true, import: 'default' });
- const source = Object.entries(sources).filter(([path]) => !path.includes('__tests__') && !path.endsWith('/SettingsSearchBox.tsx')).map(([, text]) => text).join();
- const targets = new Set(SETTINGS_SEARCH_ENTRIES.flatMap((entry) => [entry.targetId, entry.fallbackTargetId]));
+ const sources = import.meta.glob<string>('../**/*.tsx', {
+ query: '?raw',
+ eager: true,
+ import: 'default',
+ });
+ const source = Object.entries(sources)
+ .filter(([path]) => !path.includes('__tests__') && !path.endsWith('/SettingsSearchBox.tsx'))
+ .map(([, text]) => text)
+ .join();
+ const targets = new Set(
+ SETTINGS_SEARCH_ENTRIES.flatMap((entry) => [entry.targetId, entry.fallbackTargetId]),
+ );
for (const target of targets) {
if (target) {
- const dynamicProviderAnchor = /^cindy-im-(slack|telegram|x)$/.test(target) && source.includes('id={\`cindy-im-\${provider}\`}');
+ const dynamicProviderAnchor =
+ /^cindy-im-(slack|telegram|x)$/.test(target) &&
+ source.includes('id={\`cindy-im-\${provider}\`}');
expect(source.includes('id="' + target + '"') || dynamicProviderAnchor, target).toBe(true);
}
}
@@ -122,12 +166,28 @@ describe('settings search catalog', () => {
});
it('uses the same account and platform visibility as settings', () => {
- const context = { platform: 'linux', region: 'cn', mode: 'local', membershipKind: null } as const;
- const ids = (override = {}) => buildSettingsSearchDocuments(t, TAB_IDS, { ...context, ...override }).map(({ entry }) => entry.id);
+ const context = {
+ platform: 'linux',
+ region: 'cn',
+ mode: 'local',
+ membershipKind: null,
+ } as const;
+ const ids = (override = {}) =>
+ buildSettingsSearchDocuments(t, TAB_IDS, { ...context, ...override }).map(
+ ({ entry }) => entry.id,
+ );
expect(ids()).not.toContain('remoteControl.devices');
expect(ids({ mode: 'cloud' })).toContain('remoteControl.devices');
- expect(ids({ mode: 'cloud', membershipKind: 'personal' })).not.toContain('imBot.discord');
- expect(ids({ mode: 'cloud', membershipKind: 'personal' })).toContain('imBot.feishu');
+ for (const region of ['cn', 'dev', 'global'] as const) {
+ const visible = ids({ region, mode: 'cloud', membershipKind: 'personal' });
+ expect(visible).toContain('imBot.cindy');
+ expect(visible).toContain('imBot.cindy.telegram');
+ expect(visible).toContain('imBot.cindy.x');
+ expect(visible).toContain('imBot.discord');
+ expect(visible).toContain('imBot.telegram');
+ expect(visible).toContain('imBot.feishu');
+ expect(visible).toContain('imBot.lark');
+ }
expect(ids()).not.toContain('imBot.cindy');
});
});
diff --git a/apps/desktop/src/renderer/components/settings/imBotVisibility.ts b/apps/desktop/src/renderer/components/settings/imBotVisibility.ts
index dc172a3eb2..d3abc46b0c 100644
--- a/apps/desktop/src/renderer/components/settings/imBotVisibility.ts
+++ b/apps/desktop/src/renderer/components/settings/imBotVisibility.ts
@@ -1,53 +1,15 @@
-/**
- * imBotVisibility —— 「IM 机器人」页按构建区域 + 登录身份的分栏/渠道可见性单点。
- *
- * 产品规则(2026-07-24):中国区构建(cn;dev 行为归 cn 系,见 brandIdentity)
- * 下的**个人账号**(cloud 登录且 membershipKind='personal')不提供官方共享
- * Cindy 机器人分栏与 Discord 机器人入口——个人分栏只保留飞书机器人。
- * 企业账号(org)与 global 构建不受影响;本地模式沿用既有规则(无 Cindy
- * 分栏,Discord 保留)。
- *
- * 纯函数、零组件依赖:ImBotSection 与 ImDefaultSettingsSection 共用,避免
- * 两处条件漂移(ImBotSection 已 import ImDefaultSettingsSection,把条件放
- * 组件文件里会成环)。
- */
+/** 「IM 机器人」官方分栏的可见性。个人机器人在所有构建与账号中均可配置。 */
import type { CindyRegion } from '@cindy/maker-shared/brand-identity';
-/** 判定可见性所需的最小身份快照(全部来自 useAuth + 构建期区域常量)。 */
+/** 设置搜索仍使用完整身份快照;官方分栏只取登录模式。 */
export interface ImBotIdentity {
region: CindyRegion;
mode: 'signed-out' | 'local' | 'cloud';
membershipKind: 'personal' | 'org' | null;
}
-/** 中国区构建 + 个人账号 cloud 登录(不含企业账号与本地模式)。 */
-export function isCnPersonalIdentity(identity: ImBotIdentity): boolean {
- return (
- identity.region !== 'global' &&
- identity.mode === 'cloud' &&
- identity.membershipKind === 'personal'
- );
-}
-
-/** 是否提供「Cindy」分栏(官方共享机器人;本地模式与国区个人账号都没有)。 */
-export function showCindyGroup(identity: ImBotIdentity): boolean {
- return identity.mode !== 'local' && !isCnPersonalIdentity(identity);
-}
-
-/** 个人分栏是否提供 Discord 机器人配置(国区个人账号没有)。 */
-export function showDiscordBot(identity: ImBotIdentity): boolean {
- return !isCnPersonalIdentity(identity);
-}
-
-/** Lark 在国区只对已登录的云端企业账号开放;global 不受登录模式限制。 */
-export function showLarkBot(identity: ImBotIdentity): boolean {
- return (
- identity.region === 'global' || (identity.mode === 'cloud' && identity.membershipKind === 'org')
- );
-}
-
-/** 个人分栏是否提供 Telegram 机器人配置 — 可见性规则与 Discord 同组。 */
-export function showTelegramBot(identity: ImBotIdentity): boolean {
- return !isCnPersonalIdentity(identity);
+/** 本地模式不提供官方分栏;未登录时仍可看到入口和登录引导。 */
+export function showCindyGroup(identity: Pick<ImBotIdentity, 'mode'>): boolean {
+ return identity.mode !== 'local';
}
diff --git a/apps/desktop/src/renderer/hooks/__tests__/useFeishuBot.test.ts b/apps/desktop/src/renderer/hooks/__tests__/useFeishuBot.test.ts
index 75877532a6..6b4131ed30 100644
--- a/apps/desktop/src/renderer/hooks/__tests__/useFeishuBot.test.ts
+++ b/apps/desktop/src/renderer/hooks/__tests__/useFeishuBot.test.ts
@@ -140,6 +140,7 @@ describe('useFeishuBot', () => {
const hook = renderHook(() => useFeishuBot());
await waitFor(() => expect(hook.result.current.service).toBe('lark'));
+ expect(hook.result.current.hasLoadedState).toBe(true);
act(() => {
hook.result.current.setAppId('cli_1234567890');
hook.result.current.setAppSecret('sec_test');
diff --git a/apps/desktop/src/renderer/hooks/useFeishuBot.ts b/apps/desktop/src/renderer/hooks/useFeishuBot.ts
index 67944340e4..b608baa111 100644
--- a/apps/desktop/src/renderer/hooks/useFeishuBot.ts
+++ b/apps/desktop/src/renderer/hooks/useFeishuBot.ts
@@ -43,6 +43,8 @@ export interface UseFeishuBotReturn {
errorMessage: string | null;
/** 是否已有持久化凭证(独立于当前连接状态) */
hasSavedCreds: boolean;
+ /** 初次从 main 读取状态已经结束,搜索导航可以安全地选择未绑定服务。 */
+ hasLoadedState: boolean;
/** 已绑定的 owner openId(仅显示用,可能为 null) */
ownerOpenId: string | null;
@@ -92,6 +94,7 @@ export function useFeishuBot(): UseFeishuBotReturn {
() => cachedState?.errorMessage ?? null,
);
const [hasSavedCreds, setHasSavedCreds] = useState(() => cachedState?.hasSavedCreds ?? false);
+ const [hasLoadedState, setHasLoadedState] = useState(false);
const [ownerOpenId, setOwnerOpenId] = useState<string | null>(
() => cachedState?.ownerOpenId ?? null,
);
@@ -158,6 +161,8 @@ export function useFeishuBot(): UseFeishuBotReturn {
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
log.error('getState failed:', msg);
+ } finally {
+ setHasLoadedState(true);
}
}, []);
@@ -399,6 +404,7 @@ export function useFeishuBot(): UseFeishuBotReturn {
status,
errorMessage,
hasSavedCreds,
+ hasLoadedState,
ownerOpenId,
lifecycleAnnouncement,
setLifecycleAnnouncement,
diff --git a/docs/product-rules/telegram-bot-parity.md b/docs/product-rules/telegram-bot-parity.md
index b8921b7fb8..f7701abf4b 100644
--- a/docs/product-rules/telegram-bot-parity.md
+++ b/docs/product-rules/telegram-bot-parity.md
@@ -147,6 +147,7 @@ Hook 与本地 IM 共享消息级来源及上下文快照结构。本地所有
| 差异 | 官方 | 个人 | 裁决与理由 |
|---|---|---|---|
+| 桌面设置入口的区域与账号可见性 | 中国大陆版与国际版的云账号均显示官方 Telegram 入口;本地模式不显示需要 Cindy 账号的官方分栏 | 中国大陆版与国际版的个人、组织及本地模式均显示个人 Telegram 入口 | 2026-09-29 按 Dash 的跨版本入口一致要求,`ImBotSection.tsx` 与 `imBotVisibility.ts` 不再按区域或个人账号隐藏两侧入口;设置搜索由 `ImBotSection.settings-search.ts` 同步。两侧仍是独立机器人,官方入口需要云账号,个人入口由用户自配凭证;这项架构差异不应再造成中国大陆版缺入口。 |
| 群轮次权限档 | 完全按用户配的走 | Auto 对渠道策略命中的动作先交 AI 三态审阅;Ask 保留逐次确认;「完全访问」只让 owner 触发的轮次按该档直接执行,非 owner 的群消息继续保留逐轮策略并 fail-closed | Chris 2026-09-04 实踩裁决:个人 bot 的群任务已经明确设成 Pi + Grok + Full access,Cindy 侧能继续对话,Telegram 却因额外挂的逐轮策略与 Full access 互斥而在模型启动前拒绝每条消息。**owner 明确选择的完全访问必须正常执行,但不能把这份授权扩给同群其他成员**;个人侧在 `bypassPermissions` 下仅对 owner 触发的 policy 通过 `turnPolicyOptionalForMode` 取缔逐轮策略,非 owner 的授权边界与群历史 lane 隔离照常保留;scheduler 的创建、修改、前置脚本安装、恢复和立即运行同样进入该逐轮策略,防止可信 MCP 绕过群轮次权限;Auto 的风险判定交 AI,只有 ask 或服务不可用才转 owner 确认。官方侧继续完全按用户配置,不改服务端行为。见 `hook-control/session-runner.ts`、`im/telegram/adapter.ts`、`im/shared/channelToolPolicy.ts` 与 `im/shared/turnRunner.ts` |
| 私聊过程态的载体 | 默认真实进度消息;开启 `TELEGRAM_DM_DRAFT_ENABLED` 时使用 Telegram **草稿**(`sendDraft`),终稿一发草稿自然消失 | 真实消息,原地 `editMessageText` 覆盖 | 草稿只有官方路径拿得到。个人栈**不是零推送**:惰性占位让「没有真实内容就不建消息」,但**第一帧真实内容那次 `sendMessage` 会推送**,之后的编辑才不推送。`presentationCapabilities.ts` 的 `progressSilent: true` 说的是「过程帧不额外推送」,不是「整轮零推送」 |
| `/status` | 有 | 无 | 官方 bot 经服务端中继,链路可断,所以有「关联状态」可看;个人 bot 由桌面直连 Bot API,没有等价概念。见注册表 `parityNote` |