diff --git a/apps/android/src/screens/bot/ds-bot-settings-subpages.tsx b/apps/android/src/screens/bot/ds-bot-settings-subpages.tsx new file mode 100644 index 0000000..d959a8d --- /dev/null +++ b/apps/android/src/screens/bot/ds-bot-settings-subpages.tsx @@ -0,0 +1,1159 @@ +import { useState } from 'react' +import { + ActivityIndicator, + Modal, + Pressable, + ScrollView, + StyleSheet, + Text, + TextInput, + View, +} from 'react-native' +import { + Bot, + CalendarClock, + Check, + Folder, + Globe, + KeyRound, + MessageSquareShare, + Monitor, + Plug, + Plus, + Search, + ShieldCheck, + Sparkles, + Terminal, + Users, + X, +} from 'lucide-react-native' +import { strings as s } from '../../locales/i18n' +import { + object, + objects, + text, + type BotObject, + type BotState, +} from '../../services/bot-catalog' +import { + Button, + GroupCard, + GroupRow, + IconButton, + SectionTitle, +} from '../../ui/components' +import { radius, spacing, type } from '../../ui/theme' +import { useTheme, type ThemeColors } from '../../ui/theme-context' +import { useThemedStyles } from '../../ui/use-themed-styles' +import { ModalSurface } from '../chat/modal' +import { BotAvatar } from './avatar' +import { + DS_BOT_CONNECTOR_CATALOG, + DS_BOT_CONNECTOR_CATEGORIES, + DS_BOT_IM_PLATFORMS, + DS_BOT_RECOMMENDED_CONNECTOR_IDS, + type ActivityYearSummary, + type ConnectorCatalogItem, + type ImPlatformCatalogItem, + type UsageRangeId, + type UsageViewSummary, +} from './ds-bot-usage-data' +import { formatCompactTokens, type BotPerformFn } from './shared-panels' + +export function DsBotConnectorsSubpage({ + effectiveState, +}: { + effectiveState: BotState +}) { + const { colors } = useTheme() + const styles = useThemedStyles(createSubStyles) + const [connectorQuery, setConnectorQuery] = useState('') + const [connectorCat, setConnectorCat] = useState('all') + const [selectedConnector, setSelectedConnector] = useState(null) + const [customConnectorGuideOpen, setCustomConnectorGuideOpen] = useState(false) + + const renderConnectorRow = (conn: ConnectorCatalogItem, first: boolean) => { + const remoteItems = objects(effectiveState.connectors?.items) + const live = remoteItems.find( + it => text(it.id) === conn.id || text(it.name).toLowerCase() === conn.name.toLowerCase(), + ) + const isConnected = Boolean(live && (live.connected === true || text(live.status) === 'connected')) + const toolCount = Number(live?.toolCount ?? live?.tools ?? 0) + return ( + + + + {conn.name.slice(0, 2).toUpperCase()} + + + + {conn.name} + + {isConnected && toolCount > 0 ? `已连接 · ${toolCount} 个工具` : conn.desc} + + + setSelectedConnector(conn)} + style={({ pressed }) => [ + styles.connectBtn, + isConnected && styles.connectBtnConnected, + pressed && { opacity: 0.75 }, + ]} + > + + {isConnected ? '已连接' : '连接'} + + + + ) + } + + const q = connectorQuery.trim().toLowerCase() + + return ( + <> + + + + + {Boolean(connectorQuery) && ( + setConnectorQuery('')} hitSlop={8}> + + + )} + + setCustomConnectorGuideOpen(true)} + style={({ pressed }) => [styles.inlineCreateBtn, pressed && { opacity: 0.75 }]} + > + + 自定义 + + + + + {DS_BOT_CONNECTOR_CATEGORIES.map(cat => { + const on = connectorCat === cat.id + return ( + setConnectorCat(cat.id)} + style={[styles.smallPill, on && styles.smallPillActive]} + > + + {cat.label} + + + ) + })} + + + {connectorCat === 'all' && !q ? ( + <> + 推荐 + + {DS_BOT_RECOMMENDED_CONNECTOR_IDS.map( + id => DS_BOT_CONNECTOR_CATALOG.find(c => c.id === id)!, + ) + .filter(Boolean) + .map((conn, idx) => renderConnectorRow(conn, idx === 0))} + + + {DS_BOT_CONNECTOR_CATEGORIES.filter(c => c.id !== 'all').map(cat => { + const items = DS_BOT_CONNECTOR_CATALOG.filter(c => c.category === cat.id) + if (items.length === 0) return null + return ( + + {cat.label} + + {items.map((conn, idx) => renderConnectorRow(conn, idx === 0))} + + + ) + })} + + ) : ( + (() => { + const filtered = DS_BOT_CONNECTOR_CATALOG.filter( + c => + (connectorCat === 'all' || c.category === connectorCat) + && (!q || `${c.name} ${c.desc} ${c.id}`.toLowerCase().includes(q)), + ) + if (filtered.length === 0) { + return ( + + + 没有匹配的连接器 + + + ) + } + return ( + + {filtered.map((conn, idx) => renderConnectorRow(conn, idx === 0))} + + ) + })() + )} + + {selectedConnector && ( + setSelectedConnector(null)}> + setSelectedConnector(null)}> + + + {selectedConnector.name} + setSelectedConnector(null)} /> + + {selectedConnector.desc} + + + + +