From 434b776a3b8b77591197b0fd05ad047bbabee0c0 Mon Sep 17 00:00:00 2001 From: QQ Date: Sat, 14 Nov 2026 14:12:56 +0800 Subject: [PATCH] Import apps/android/src/screens/bot/ds-bot-settings-screen.tsx --- .../screens/bot/ds-bot-settings-screen.tsx | 1423 +++++++++++++++++ 1 file changed, 1423 insertions(+) create mode 100644 apps/android/src/screens/bot/ds-bot-settings-screen.tsx diff --git a/apps/android/src/screens/bot/ds-bot-settings-screen.tsx b/apps/android/src/screens/bot/ds-bot-settings-screen.tsx new file mode 100644 index 0000000..fe0ddf7 --- /dev/null +++ b/apps/android/src/screens/bot/ds-bot-settings-screen.tsx @@ -0,0 +1,1423 @@ +import { useCallback, useEffect, useMemo, useState } from 'react' +import { + ActivityIndicator, + Alert, + Modal, + Pressable, + ScrollView, + StyleSheet, + Text, + View, +} from 'react-native' +import { + Bot, + CalendarClock, + ChartNoAxesColumn, + Check, + ChevronRight, + CircleAlert, + Cpu, + Folder, + Globe, + KeyRound, + MessageSquareShare, + Monitor, + Plug, + Plus, + ShieldCheck, + SlidersHorizontal, + Sparkles, + Terminal, + Trash2, + Users, + X, + type LucideIcon, +} from 'lucide-react-native' +import { strings as s } from '../../locales/i18n' +import { + canDeleteBot, + object, + objects, + parseBotState, + text, + type BotEntry, + type BotObject, + type BotRemoteClient, + type BotRoom, + type BotState, +} from '../../services/bot-catalog' +import { + loadPluginInventory, + setPluginEnabled, + type PluginBundleView, +} from '../../services/plugin-inventory' +import { requireBotClient, useAppStore } from '../../state/store' +import { useBotTeamStore } from '../../state/bot-store' +import { + BlurHeaderFrame, + GroupCard, + GroupRow, + IconButton, + RefreshAction, + Screen, + SectionTitle, + TopBar, +} from '../../ui/components' +import { useResponsiveLayout } from '../../ui/responsive' +import { radius, spacing, type } from '../../ui/theme' +import { useTheme, type ThemeColors } from '../../ui/theme-context' +import { Toggle } from '../../ui/toggle' +import { useThemedStyles } from '../../ui/use-themed-styles' +import { DsBotInstallCard } from '../bot-sidebar-section' +import { ModalSurface } from '../chat/modal' +import { PluginsModal } from '../plugins-modal' +import { BotAgentBadge } from './agent-badge' +import { BotAvatarWithBadge } from './avatar' +import { + DsBotCapabilitiesSubpage, + DsBotComputerSubpage, + DsBotConnectorsSubpage, + DsBotImSubpage, + DsBotSecretsSubpage, + DsBotUsageSubpage, +} from './ds-bot-settings-subpages' +import { + buildDsBotActivityYear, + buildDsBotUsageView, + DS_BOT_CONNECTOR_CATALOG, + DS_BOT_LOCAL_SERVERS, + DS_BOT_POPULAR_PROVIDERS, + type UsageRangeId, +} from './ds-bot-usage-data' +import { BotEditor } from './editor' +import { + BotBrowserGrantsSection, + BotFolderPickerModal, + BotSchedulesPanel, + folderBasename, + formatCompactTokens, +} from './shared-panels' + +export type DsBotSettingsTab = + | 'general' + | 'models' + | 'local-agents' + | 'bots' + | 'groups' + | 'connectors' + | 'im' + | 'capabilities' + | 'browser' + | 'computer' + | 'schedules' + | 'usage' + | 'secrets' + +interface TabItem { + id: DsBotSettingsTab + label: string + detail: string + icon: LucideIcon +} + +const KNOWN_LOCAL_AGENTS = [ + { id: 'claude', name: 'Claude Code', cmd: 'claude-agent-acp', desc: 'Anthropic Claude Code 命令行 Agent' }, + { id: 'codex', name: 'Codex', cmd: 'codex', desc: 'OpenAI Codex 本地编码 Agent' }, + { id: 'opencode', name: 'OpenCode', cmd: 'opencode', desc: 'OpenCode 终端编码 Agent' }, + { id: 'hermes', name: 'Hermes Agent', cmd: 'hermes', desc: 'Nous Research Hermes 本地 Agent' }, + { id: 'cursor', name: 'Cursor Agent', cmd: 'cursor-agent', desc: 'Cursor 命令行编码 Agent' }, + { id: 'pi', name: 'Pi', cmd: 'pi-acp', desc: 'Pi 极简命令行 Agent' }, +] + +const FALLBACK_PREVIEW_STATE: BotState = parseBotState({ + bots: [ + { + id: 'chief', + sessionId: 'chief', + name: 'Chief', + role: 'Chief of Staff', + main: true, + color: '#4D6BFE', + }, + ], + rooms: [], + mainBotId: 'chief', + mainBotIds: ['chief'], + defaultModel: 'deepseek/deepseek-chat', + prefs: { motion: 'lively', thinking: true, enterToSend: true }, +}) + +/** + * Secondary Settings screen for DS Bot, matching `SettingsScreen`'s GroupCard/GroupRow design + * with a level-1 index page, missing/disabled `ds-bot` plugin reminder card, and 13 level-2 subpages: + * 通用 / 模型 / 本地 Agent / Bot / 群聊 / 连接器 / IM / 能力 / 浏览器 / 电脑操控 / 定时任务 / 用量 / 密钥 + */ +export function DsBotSettingsModal({ + visible, + initialTab, + onClose, +}: { + visible: boolean + initialTab?: DsBotSettingsTab + onClose: () => void +}) { + const { colors, scheme } = useTheme() + const styles = useThemedStyles(createStyles) + const { contentMaxWidth, landscape } = useResponsiveLayout() + const isDark = scheme === 'dark' + + const connected = useAppStore(store => store.connection.phase === 'connected') + const selectedDevice = useAppStore(store => store.selectedDevice) + const state = useBotTeamStore(store => store.state) + const loading = useBotTeamStore(store => store.loading) + const busy = useBotTeamStore(store => store.busy) + const error = useBotTeamStore(store => store.error) + const actionError = useBotTeamStore(store => store.actionError) + const refresh = useBotTeamStore(store => store.refresh) + const perform = useBotTeamStore(store => store.perform) + + const [subpage, setSubpage] = useState(initialTab ?? null) + const [editorTarget, setEditorTarget] = useState<{ kind: 'bot' | 'room'; bot?: BotEntry; room?: BotRoom } | null>(null) + const [defaultModelPickerOpen, setDefaultModelPickerOpen] = useState(false) + const [mainBotPickerOpen, setMainBotPickerOpen] = useState(false) + const [teamFolderPickerOpen, setTeamFolderPickerOpen] = useState(false) + const [botFolderTarget, setBotFolderTarget] = useState(null) + const [pluginsModalOpen, setPluginsModalOpen] = useState(false) + + // Plugin prerequisite check state + const [dsBotBundle, setDsBotBundle] = useState(null) + const [checkingPlugin, setCheckingPlugin] = useState(false) + const [enablingPlugin, setEnablingPlugin] = useState(false) + + // Remote-fetched sub-views + const [providersData, setProvidersData] = useState(null) + const [localAgentsData, setLocalAgentsData] = useState(null) + const [usageData, setUsageData] = useState(null) + const [usageLoading, setUsageLoading] = useState(false) + const [usageRange, setUsageRange] = useState('7d') + + let clientInstance: BotRemoteClient | undefined + try { + clientInstance = requireBotClient() + } catch { + clientInstance = undefined + } + + const checkDsBotPluginStatus = useCallback(async () => { + if (!connected) { + setDsBotBundle(null) + return + } + setCheckingPlugin(true) + try { + const inv = await loadPluginInventory() + const found = inv.bundles.find(b => b.name === 'ds-bot') ?? null + setDsBotBundle(found) + } catch { + // Ignore inventory check error; fall back to bot state + } finally { + setCheckingPlugin(false) + } + }, [connected]) + + const handleRetryAll = useCallback(async () => { + await Promise.all([checkDsBotPluginStatus(), refresh(true)]) + }, [checkDsBotPluginStatus, refresh]) + + const handleEnableDsBot = useCallback(async () => { + if (!dsBotBundle || enablingPlugin) return + setEnablingPlugin(true) + try { + await setPluginEnabled('bundle', dsBotBundle.name, true) + await handleRetryAll() + } catch { + // Handled via refresh/inventory state + } finally { + setEnablingPlugin(false) + } + }, [dsBotBundle, enablingPlugin, handleRetryAll]) + + useEffect(() => { + if (!visible) return + setSubpage(initialTab ?? null) + void checkDsBotPluginStatus() + if (connected && !state) { + void refresh(true) + } + }, [visible, initialTab, connected, state, checkDsBotPluginStatus, refresh]) + + useEffect(() => { + if (!visible || !clientInstance) return + if (subpage === 'models' || subpage === null) { + void clientInstance + .call('providers') + .then(res => setProvidersData(objects(object(res).providers))) + .catch(() => setProvidersData([])) + } + if (subpage === 'local-agents' || subpage === null) { + void clientInstance + .call('local-agents') + .then(res => setLocalAgentsData(object(res))) + .catch(() => setLocalAgentsData(null)) + } + if (subpage === 'usage' || subpage === null) { + setUsageLoading(true) + void clientInstance + .call('usage', { timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone }) + .then(res => setUsageData(object(res))) + .catch(() => setUsageData(null)) + .finally(() => setUsageLoading(false)) + } + }, [visible, subpage, clientInstance]) + + const effectiveState = state ?? FALLBACK_PREVIEW_STATE + const isLiveState = state !== undefined + + const setPref = useCallback( + async (patch: BotObject) => { + if (!isLiveState) return + await perform('set-prefs', patch) + }, + [isLiveState, perform], + ) + + const tabs: TabItem[] = useMemo( + () => [ + { id: 'general', label: s.bots.tabGeneral, detail: '默认模型、回复体验与工作文件夹', icon: SlidersHorizontal }, + { id: 'models', label: s.bots.tabModels, detail: '模型服务商、API 密钥与本地服务', icon: Cpu }, + { id: 'local-agents', label: s.bots.tabLocalAgents, detail: 'Claude Code、Codex、OpenCode 与原生会话', icon: Terminal }, + { id: 'bots', label: s.bots.tabBots, detail: '主 Bot、动画风格与团队成员管理', icon: Bot }, + { id: 'groups', label: s.bots.tabGroups, detail: '多 Bot 协作群聊、管理员与回复模式', icon: Users }, + { id: 'connectors', label: s.bots.tabConnectors, detail: 'GitHub、邮箱、Notion、Linear 等第三方服务', icon: Plug }, + { id: 'im', label: s.bots.tabIm, detail: '微信、飞书、钉钉、企微、QQ、Telegram 等平台', icon: MessageSquareShare }, + { id: 'capabilities', label: s.bots.tabCapabilities, detail: '按 Bot 配置工具权限与共享技能', icon: Sparkles }, + { id: 'browser', label: s.bots.tabBrowser, detail: '网页自动化与站点敏感操作预授权', icon: Globe }, + { id: 'computer', label: s.bots.tabComputer, detail: '屏幕查看与键鼠操控权限等级', icon: Monitor }, + { id: 'schedules', label: s.bots.tabSchedules, detail: '周期性简报、定时提醒与自动任务', icon: CalendarClock }, + { id: 'usage', label: s.bots.tabUsage, detail: 'Token 走势、缓存命中率与年度活跃度', icon: ChartNoAxesColumn }, + { id: 'secrets', label: s.bots.tabSecrets, detail: 'Bot 环境变量密钥与访问范围', icon: KeyRound }, + ], + [], + ) + + const usageView = useMemo( + () => buildDsBotUsageView(usageData, usageRange), + [usageData, usageRange], + ) + const activityYear = useMemo( + () => buildDsBotActivityYear(usageData, 24), + [usageData], + ) + + if (!visible) return null + + const prefs = object(effectiveState.prefs) + const showThinking = prefs.thinking !== false && prefs.showThinking !== false + const motion = text(prefs.motion) || text(prefs.animation) || 'lively' + const enterToSend = prefs.enterToSend !== false + const defaultBotModel = text(prefs.defaultBotModel) || effectiveState.defaultModel || '' + + const mainBot = + effectiveState.bots.find(b => b.id === effectiveState.mainBotId) + ?? effectiveState.bots.find(b => b.main) + ?? effectiveState.bots[0] + const mainBotName = mainBot?.name ?? 'Chief' + + const connectedConnectorItems = objects(effectiveState.connectors?.items).filter( + it => it.connected === true || text(it.status) === 'connected', + ) + const connectedImList = objects(effectiveState.im?.connections ?? effectiveState.im?.bots) + const totalBrowserGrants = effectiveState.bots.reduce( + (sum, b) => sum + (b.browserGrants?.length ?? 0), + 0, + ) + const configuredProviderCount = + providersData && providersData.length > 0 + ? providersData.length + : new Set( + effectiveState.models + .map(m => text(m.provider) || text(m.ref).split('/')[0]) + .filter(Boolean), + ).size + + const summaryForTab = (id: DsBotSettingsTab): string => { + switch (id) { + case 'general': + return effectiveState.workspaceId + ? folderBasename(effectiveState.workspaceId) + : defaultBotModel + ? defaultBotModel.split('/').pop() ?? '' + : '默认' + case 'models': + return configuredProviderCount > 0 ? `${configuredProviderCount} 个服务商` : `${effectiveState.models.length} 个模型` + case 'local-agents': { + const det = objects(localAgentsData?.detected).filter(d => d.installed === true || d.available === true).length + const dshCount = effectiveState.agents.length + return det + dshCount > 0 ? `已启用 ${det + dshCount}` : `${KNOWN_LOCAL_AGENTS.length} 项` + } + case 'bots': + return `${mainBotName} · ${effectiveState.bots.length} 个` + case 'groups': + return `${effectiveState.rooms.length} 个` + case 'connectors': + return connectedConnectorItems.length > 0 + ? `已连接 ${connectedConnectorItems.length}` + : `${DS_BOT_CONNECTOR_CATALOG.length} 个` + case 'im': + return connectedImList.length > 0 ? `已连接 ${connectedImList.length}` : '8 个平台' + case 'capabilities': + return (effectiveState.capabilities ?? []).length > 0 + ? `${(effectiveState.capabilities ?? []).length} 项能力` + : '按 Bot 授权' + case 'browser': + return totalBrowserGrants > 0 ? `${totalBrowserGrants} 项预授权` : '无预授权' + case 'computer': + return effectiveState.computer?.enabled === true ? '已开启' : '关' + case 'schedules': + return '管理任务' + case 'usage': + return usageView.current.tokens > 0 + ? `${formatCompactTokens(usageView.current.tokens)} Token` + : '查看统计' + case 'secrets': + return `${(effectiveState.secrets ?? []).length} 个` + } + } + + const isPluginNotInstalled = + connected && !isLiveState && (dsBotBundle?.available === false || (!loading && !checkingPlugin)) + const isPluginDisabled = + connected && dsBotBundle?.available === true && dsBotBundle.enabled === false + + const activeTabItem = subpage ? tabs.find(t => t.id === subpage) ?? null : null + const visibleError = actionError ?? error + const switchColors = { trackColor: { false: colors.disabled, true: colors.primary }, thumbColor: colors.white } as const + + const handleBack = () => { + if (subpage !== null) { + setSubpage(null) + return + } + onClose() + } + + const renderPrerequisiteNotice = () => { + if (isLiveState && !isPluginDisabled) return null + + if (!connected) { + return ( + + DS Bot 插件状态 + + + + void handleRetryAll()} /> + + ) + } + + if (isPluginDisabled) { + return ( + + DS Bot 插件状态 + + + void handleEnableDsBot()} + /> + setPluginsModalOpen(true)} + /> + + + ) + } + + if (loading || checkingPlugin) { + return ( + + + + 正在检测电脑端 DS Bot 插件状态… + + + ) + } + + if (isPluginNotInstalled) { + return ( + + 未检测到 DS Bot 插件 + void handleRetryAll()} + /> + + setPluginsModalOpen(true)} + /> + + + ) + } + + return null + } + + return ( + + + void handleRetryAll()} />} + /> + } + > + + + {/* ==================== LEVEL 1: SETTINGS-STYLE INDEX PAGE ==================== */} + {subpage === null && ( + <> + {renderPrerequisiteNotice()} + + 基础与模型 + + {tabs.slice(0, 3).map((item, idx) => ( + setSubpage(item.id)} + /> + ))} + + + 团队与协作 + + {tabs.slice(3, 5).map((item, idx) => ( + setSubpage(item.id)} + /> + ))} + + + 连接器与消息渠道 + + {tabs.slice(5, 7).map((item, idx) => ( + setSubpage(item.id)} + /> + ))} + + + 能力与操作授权 + + {tabs.slice(7, 10).map((item, idx) => ( + setSubpage(item.id)} + /> + ))} + + + 任务、统计与密钥 + + {tabs.slice(10, 13).map((item, idx) => ( + setSubpage(item.id)} + /> + ))} + + + )} + + {/* ==================== LEVEL 2 SUBPAGES ==================== */} + {subpage !== null && !isLiveState && ( + + + + )} + + {/* 1. 通用 (General — excludes computer window appearance & keep-awake) */} + {subpage === 'general' && ( + <> + {s.bots.defaultModel} + + setDefaultModelPickerOpen(true)} + /> + + + 对话与回复 + + void setPref({ thinking: val })} + accessibilityLabel={s.bots.showThinking} + {...switchColors} + /> + } + /> + void setPref({ enterToSend: val })} + accessibilityLabel={s.bots.enterToSend} + {...switchColors} + /> + } + /> + + + 位置 + + setTeamFolderPickerOpen(true)} + /> + + + 各 Bot 自己的文件夹 + + {effectiveState.bots.map((bot, idx) => ( + setBotFolderTarget(bot)} + /> + ))} + + + {(effectiveState.privateArchives ?? []).length > 0 && ( + <> + {`删除后仍受保护 · ${(effectiveState.privateArchives ?? []).length}`} + + {(effectiveState.privateArchives ?? []).map((arc, idx) => ( + + ))} + + + )} + + )} + + {/* 2. 模型 (Models / ProvidersPage) */} + {subpage === 'models' && ( + <> + 已配置服务商 + {(() => { + const list = + providersData && providersData.length > 0 + ? providersData + : (() => { + const map = new Map() + for (const m of effectiveState.models) { + const p = text(m.provider) || text(m.providerName) || text(m.ref).split('/')[0] || 'deepseek' + const arr = map.get(p) ?? [] + arr.push(m) + map.set(p, arr) + } + return [...map].map(([id, models]) => ({ + id, + name: text(models[0]?.providerName) || id, + models, + key: { configured: true }, + })) + })() + + if (list.length === 0) { + return ( + + + + ) + } + return list.map(prov => { + const pid = text(prov.id) + const pname = text(prov.name) || pid + const pmodels = objects(prov.models) + const configured = object(prov.key).configured !== false + return ( + + + + + {pname} + + {pmodels.length} 个模型 · {configured ? '已配置密钥' : '需要 API Key'} + + + + {pmodels.length > 0 && ( + + {pmodels.slice(0, 12).map(m => { + const mname = text(m.name) || text(m.id) || text(m.ref) + return ( + + {mname} + + ) + })} + + )} + + ) + }) + })()} + + 常用服务商 + + {DS_BOT_POPULAR_PROVIDERS.map((prov, idx) => { + const isConfigured = + (providersData ?? []).some(p => text(p.id).toLowerCase() === prov.id) + || effectiveState.models.some(m => text(m.provider).toLowerCase() === prov.id || text(m.ref).toLowerCase().startsWith(`${prov.id}/`)) + return ( + + ) + })} + + + 本地模型服务 + + {DS_BOT_LOCAL_SERVERS.map((srv, idx) => ( + + ))} + + + )} + + {/* 3. 本地 Agent (Local Agents) */} + {subpage === 'local-agents' && ( + <> + + 将电脑上已安装的命令行编码 Agent 接入 DS Bot,各 Bot 可直接选用其作为底层运行模型。 + + + DeepSeek Harness 原生会话 + + 0 ? '已添加' : '未添加'} + disabled={!isLiveState || busy} + onPress={() => { + if (effectiveState.agents[0]) { + void perform('remove-agent', { agentId: effectiveState.agents[0].id }) + } else { + void perform('add-agent', {}) + } + }} + /> + + + 本地编码 Agent + + {KNOWN_LOCAL_AGENTS.map((agent, idx) => { + const detectedList = objects(localAgentsData?.detected) + const matched = detectedList.find(d => text(d.id) === agent.id) + const hasModels = effectiveState.models.some( + m => text(m.provider) === agent.id || text(m.ref).startsWith(`${agent.id}/`), + ) + const ready = Boolean(matched?.available ?? matched?.installed ?? hasModels) + const ver = text(matched?.version) + return ( + + ) + })} + + + )} + + {/* 4. Bot (BotsPage — strictly aligned with Screenshot 1) */} + {subpage === 'bots' && ( + <> + + setMainBotPickerOpen(true)} + /> + + + + + + {s.bots.botAnimation} + 聊天与状态栏中 Bot 头像的呼吸和工作动效。 + + + {([ + ['lively', s.bots.animLively], + ['normal', s.bots.animNormal], + ['quiet', s.bots.animQuiet], + ] as const).map(([id, label]) => { + const on = motion === id + return ( + void setPref({ motion: id })} + style={[styles.smallPill, on && styles.smallPillActive]} + > + {label} + + ) + })} + + + + + setEditorTarget({ kind: 'bot' })} + style={({ pressed }) => [ + styles.inlineCreateBtn, + !isLiveState && { opacity: 0.45 }, + pressed && { opacity: 0.75 }, + ]} + > + + {s.bots.newBot} + + } + > + {`Bot · ${effectiveState.bots.length}`} + + + + {effectiveState.bots.map((bot, idx) => ( + 0 && styles.topHairline, + ]} + > + setEditorTarget({ kind: 'bot', bot })} + style={({ pressed }) => [ + { flex: 1, flexDirection: 'row', alignItems: 'center', gap: 12, minWidth: 0 }, + pressed && { opacity: 0.75 }, + ]} + > + + + + {bot.name} + {Boolean(bot.role) && ( + {bot.role} + )} + {(bot.main || bot.id === effectiveState.mainBotId) && ( + + 主 Bot + + )} + {bot.private && ( + + {s.bots.privateBot} + + )} + + + {bot.instructions || (bot.model || effectiveState.defaultModel) || '点击管理模型、指令与文件夹'} + + + + + {isLiveState && canDeleteBot(effectiveState, bot) && ( + { + Alert.alert(s.bots.delete, s.bots.deleteHint, [ + { text: s.bots.cancel, style: 'cancel' }, + { + text: s.bots.delete, + style: 'destructive', + onPress: () => void perform('delete-bot', { id: bot.id }), + }, + ]) + }} + style={({ pressed }) => [ + { padding: 6 }, + pressed && { opacity: 0.65 }, + busy && { opacity: 0.4 }, + ]} + > + + + )} + + ))} + + + )} + + {/* 5. 群聊 (GroupsPage) */} + {subpage === 'groups' && ( + <> + setEditorTarget({ kind: 'room' })} + style={({ pressed }) => [ + styles.inlineCreateBtn, + (!isLiveState || effectiveState.bots.length < 2) && { opacity: 0.45 }, + pressed && { opacity: 0.75 }, + ]} + > + + {s.bots.newGroup} + + } + > + {`群聊 · ${effectiveState.rooms.length}`} + + + + {effectiveState.rooms.length === 0 ? ( + + 还没有群聊。 + 在群聊里,几个 Bot 和你一起做一件事。 + + ) : ( + effectiveState.rooms.map((room, idx) => { + const memberNames = room.members + .map(id => effectiveState.bots.find(b => b.id === id)?.name ?? id) + .join('、') + return ( + 0 && styles.topHairline, + ]} + > + setEditorTarget({ kind: 'room', room })} + style={({ pressed }) => [ + { flex: 1, flexDirection: 'row', alignItems: 'center', gap: 12, minWidth: 0 }, + pressed && { opacity: 0.75 }, + ]} + > + + + {room.name} + + {memberNames || `${room.members.length} ${s.bots.members}`} + + + {`${room.members.length} 成员`} + + + {isLiveState && !effectiveState.readOnly && ( + { + Alert.alert(s.bots.delete, s.bots.deleteHint, [ + { text: s.bots.cancel, style: 'cancel' }, + { + text: s.bots.delete, + style: 'destructive', + onPress: () => void perform('delete-room', { id: room.id }), + }, + ]) + }} + style={({ pressed }) => [ + { padding: 6 }, + pressed && { opacity: 0.65 }, + busy && { opacity: 0.4 }, + ]} + > + + + )} + + ) + }) + )} + + + )} + + {/* 6. 连接器 (ConnectorsPage — strictly aligned with Screenshot 2) */} + {subpage === 'connectors' && ( + + )} + + {/* 7. IM (ImPage — strictly aligned with Screenshot 3) */} + {subpage === 'im' && ( + + )} + + {/* 8. 能力 (CapabilitiesPage) */} + {subpage === 'capabilities' && ( + + )} + + {/* 9. 浏览器 (BrowserSettingsPage — strictly aligned with Screenshot 4) */} + {subpage === 'browser' && ( + + )} + + {/* 10. 电脑操控 (ComputerPage) */} + {subpage === 'computer' && ( + + )} + + {/* 11. 定时任务 (SchedulesPage) */} + {subpage === 'schedules' && ( + + )} + + {/* 12. 用量 (UsagePage — strictly aligned with Screenshot 5) */} + {subpage === 'usage' && ( + + )} + + {/* 13. 密钥 (SecretsPage) */} + {subpage === 'secrets' && ( + + )} + + + + + {/* Main Bot Picker Modal */} + {mainBotPickerOpen && ( + setMainBotPickerOpen(false)}> + setMainBotPickerOpen(false)}> + + + 选择主 Bot + setMainBotPickerOpen(false)} /> + + + {effectiveState.bots + .filter(b => !b.private) + .map((bot, idx) => { + const on = bot.id === mainBot?.id + return ( + : undefined} + onPress={() => { + setMainBotPickerOpen(false) + if (bot.id !== mainBot?.id) { + void perform('set-main', { + id: bot.id, + main: true, + primary: true, + ...(mainBot?.id ? { replace: mainBot.id } : {}), + }) + } + }} + /> + ) + })} + + + + + )} + + {/* Default Model Picker Modal */} + {defaultModelPickerOpen && ( + setDefaultModelPickerOpen(false)}> + setDefaultModelPickerOpen(false)}> + + + {s.bots.defaultModel} + setDefaultModelPickerOpen(false)} /> + + + + {effectiveState.models.length === 0 ? ( + } + onPress={() => setDefaultModelPickerOpen(false)} + /> + ) : ( + effectiveState.models.map((m, idx) => { + const ref = text(m.ref) + const label = text(m.name) || text(m.label) || ref + const on = defaultBotModel === ref + return ( + : undefined} + onPress={() => { + setDefaultModelPickerOpen(false) + void setPref({ defaultBotModel: ref }) + }} + /> + ) + }) + )} + + + + + + )} + + {/* Team Workspace Folder Picker */} + setTeamFolderPickerOpen(false)} + onPick={folder => { + if (folder) void perform('team-workspace', { path: folder }) + }} + /> + + {/* Per-Bot Working Folder Picker */} + setBotFolderTarget(null)} + onPick={folder => { + if (botFolderTarget) { + void perform('update-bot', { id: botFolderTarget.id, workDir: folder }) + } + }} + /> + + {/* Single-Bot / Group Editor */} + {isLiveState && editorTarget && clientInstance && ( + setEditorTarget(null)} + /> + )} + + {/* Plugins Management Modal */} + setPluginsModalOpen(false)} /> + + + ) +} + +const createStyles = (colors: ThemeColors) => + StyleSheet.create({ + root: { + flex: 1, + backgroundColor: colors.background, + }, + contentColumn: { + width: '100%', + alignSelf: 'center', + gap: spacing.sm, + }, + loadingCardRow: { + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center', + gap: 10, + paddingVertical: 20, + paddingHorizontal: 16, + }, + rowTitle: { + ...type.bodyStrong, + fontSize: 15, + color: colors.ink, + }, + rowSub: { + ...type.small, + fontSize: 12.5, + color: colors.muted, + marginTop: 2, + }, + topHairline: { + borderTopWidth: StyleSheet.hairlineWidth, + borderTopColor: colors.separator, + }, + inlinePills: { + flexDirection: 'row', + alignItems: 'center', + gap: 6, + }, + smallPill: { + paddingHorizontal: 12, + paddingVertical: 6, + borderRadius: radius.pill, + backgroundColor: colors.grouped, + }, + smallPillActive: { + backgroundColor: colors.primary, + }, + smallPillText: { + fontSize: 12.5, + fontWeight: '500', + color: colors.ink, + }, + smallPillTextActive: { + color: colors.white, + fontWeight: '600', + }, + inlineCreateBtn: { + flexDirection: 'row', + alignItems: 'center', + gap: 5, + paddingHorizontal: 12, + paddingVertical: 6, + borderRadius: radius.lg, + backgroundColor: colors.surface, + borderWidth: StyleSheet.hairlineWidth, + borderColor: colors.separator, + }, + inlineCreateBtnText: { + fontSize: 13, + fontWeight: '600', + color: colors.ink, + }, + botListRow: { + flexDirection: 'row', + alignItems: 'center', + gap: 12, + paddingHorizontal: spacing.md, + paddingVertical: 12, + }, + tagChip: { + paddingHorizontal: 9, + paddingVertical: 4, + borderRadius: 8, + backgroundColor: colors.grouped, + }, + tagChipText: { + fontSize: 12, + color: colors.ink, + }, + statusBadge: { + paddingHorizontal: 8, + paddingVertical: 3, + borderRadius: radius.pill, + backgroundColor: colors.grouped, + }, + statusBadgeReady: { + backgroundColor: colors.primarySoft, + }, + statusBadgeText: { + fontSize: 11.5, + fontWeight: '600', + color: colors.muted, + }, + emptyCardBox: { + paddingVertical: 24, + paddingHorizontal: 16, + alignItems: 'center', + justifyContent: 'center', + gap: 4, + }, + mutedText: { + fontSize: 13.5, + color: colors.muted, + textAlign: 'center', + }, + helperNote: { + fontSize: 13, + lineHeight: 19, + color: colors.muted, + paddingHorizontal: 4, + }, + sheetTitle: { + ...type.heading, + fontSize: 18, + color: colors.ink, + }, + })