🤯 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
✨ feat: support bot manage (#13365)
Rdmclin2c7c2b56f3bfd
diff --git a/locales/en-US/agent.json b/locales/en-US/agent.jsonindex bd803a01b3a..be3ff41ae0a 100644--- a/locales/en-US/agent.json+++ b/locales/en-US/agent.json@@ -27,6 +27,11 @@"channel.credentials": "Credentials","channel.debounceMs": "Debounce Window (ms)","channel.debounceMsHint": "How long to wait for additional messages before dispatching to the agent (ms)",+ "channel.deleteAllChannels": "Remove All Channels",+ "channel.deleteAllConfirm": "Are you sure you want to remove all channels?",+ "channel.deleteAllConfirmDesc": "This action will permanently remove all message channels and their configurations for this agent. This cannot be undone.",+ "channel.deleteAllFailed": "Failed to remove all channels",+ "channel.deleteAllSuccess": "All channels removed","channel.deleteConfirm": "Are you sure you want to remove this channel?","channel.deleteConfirmDesc": "This action will permanently remove this message channel and its configuration. This cannot be undone.","channel.devWebhookProxyUrl": "HTTPS Tunnel URL",@@ -48,7 +53,12 @@"channel.encryptKeyPlaceholder": "Optional encryption key","channel.endpointUrl": "Webhook URL","channel.endpointUrlHint": "Please copy this URL and paste it into the <bold>{{fieldName}}</bold> field in the {{name}} Developer Portal.",+ "channel.exportConfig": "Export Configuration","channel.feishu.description": "Connect this assistant to Feishu for private and group chats.",+ "channel.importConfig": "Import Configuration",+ "channel.importFailed": "Failed to import configuration",+ "channel.importInvalidFormat": "Invalid configuration file format",+ "channel.importSuccess": "Configuration imported successfully","channel.lark.description": "Connect this assistant to Lark for private and group chats.","channel.openPlatform": "Open Platform","channel.platforms": "Platforms",diff --git a/locales/zh-CN/agent.json b/locales/zh-CN/agent.jsonindex dc37ec97175..382a86837c1 100644--- a/locales/zh-CN/agent.json+++ b/locales/zh-CN/agent.json@@ -27,6 +27,11 @@"channel.credentials": "凭证配置","channel.debounceMs": "防抖窗口(毫秒)","channel.debounceMsHint": "在派发给 Agent 之前等待更多消息的时间(毫秒)",+ "channel.deleteAllChannels": "移除所有频道",+ "channel.deleteAllConfirm": "确定要移除所有频道吗?",+ "channel.deleteAllConfirmDesc": "此操作将永久移除该助手的所有消息频道及其配置,且无法撤销。",+ "channel.deleteAllFailed": "移除所有频道失败",+ "channel.deleteAllSuccess": "所有频道已移除","channel.deleteConfirm": "确定要移除此消息频道吗?","channel.deleteConfirmDesc": "此操作将永久移除该消息频道及其配置,且无法撤销。","channel.devWebhookProxyUrl": "HTTPS 隧道地址",@@ -48,7 +53,12 @@"channel.encryptKeyPlaceholder": "可选的加密密钥","channel.endpointUrl": "Webhook URL","channel.endpointUrlHint": "请复制此 URL 并粘贴到 {{name}} 开发者门户的 <bold>{{fieldName}}</bold> 字段中。",+ "channel.exportConfig": "导出平台配置","channel.feishu.description": "将助手连接到飞书,支持私聊和群聊。",+ "channel.importConfig": "导入平台配置",+ "channel.importFailed": "配置导入失败",+ "channel.importInvalidFormat": "配置文件格式无效",+ "channel.importSuccess": "配置导入成功","channel.lark.description": "将助手连接到 Lark,支持私聊和群聊。","channel.openPlatform": "开放平台","channel.platforms": "平台",diff --git a/src/locales/default/agent.ts b/src/locales/default/agent.tsindex 0bfd73510cc..e4ed339ba2f 100644--- a/src/locales/default/agent.ts+++ b/src/locales/default/agent.ts@@ -12,6 +12,12 @@ export default {'channel.connectionConfig': 'Connection Configuration','channel.copied': 'Copied to clipboard','channel.copy': 'Copy',+ 'channel.deleteAllChannels': 'Remove All Channels',+ 'channel.deleteAllConfirm': 'Are you sure you want to remove all channels?',+ 'channel.deleteAllConfirmDesc':+ 'This action will permanently remove all message channels and their configurations for this agent. This cannot be undone.',+ 'channel.deleteAllSuccess': 'All channels removed',+ 'channel.deleteAllFailed': 'Failed to remove all channels','channel.deleteConfirm': 'Are you sure you want to remove this channel?','channel.deleteConfirmDesc':'This action will permanently remove this message channel and its configuration. This cannot be undone.',@@ -22,6 +28,11 @@ export default {'channel.discord.description':'Connect this assistant to Discord server for channel chat and direct messages.','channel.documentation': 'Documentation',+ 'channel.exportConfig': 'Export Configuration',+ 'channel.importConfig': 'Import Configuration',+ 'channel.importSuccess': 'Configuration imported successfully',+ 'channel.importFailed': 'Failed to import configuration',+ 'channel.importInvalidFormat': 'Invalid configuration file format','channel.enabled': 'Enabled','channel.encryptKey': 'Encrypt Key','channel.encryptKeyHint': 'Optional. Used to decrypt encrypted event payloads.',diff --git a/src/routes/(main)/agent/channel/index.tsx b/src/routes/(main)/agent/channel/index.tsxindex 31141edc3bc..8ec39353002 100644--- a/src/routes/(main)/agent/channel/index.tsx+++ b/src/routes/(main)/agent/channel/index.tsx@@ -81,7 +81,9 @@ const ChannelPage = memo(() => {<div className={styles.container}><PlatformListactiveId={effectiveActiveId}+ agentId={aid}platforms={platforms}+ providers={providers}runtimeStatuses={platformRuntimeStatuses}onSelect={setActiveProviderId}/>diff --git a/src/routes/(main)/agent/channel/list.tsx b/src/routes/(main)/agent/channel/list.tsxindex bae20b23cb5..1890b9f8cd9 100644--- a/src/routes/(main)/agent/channel/list.tsx+++ b/src/routes/(main)/agent/channel/list.tsx@@ -1,12 +1,16 @@'use client';+import { exportJSONFile } from '@lobechat/utils/client';import { Icon } from '@lobehub/ui';+import { App, Dropdown, type MenuProps } from 'antd';import { createStaticStyles, cx, useTheme } from 'antd-style';-import { Info } from 'lucide-react';-import { memo } from 'react';+import { Download, Info, MoreHorizontal, Trash2, Upload } from 'lucide-react';+import { memo, useCallback, useRef } from 'react';import { useTranslation } from 'react-i18next';import type { SerializedPlatformDefinition } from '@/server/services/bot/platforms/types';+import { useAgentStore } from '@/store/agent';+import type { BotProviderItem } from '@/store/agent/slices/bot/action';import { BOT_RUNTIME_STATUSES, type BotRuntimeStatus } from '../../../../types/botRuntimeStatus';import { getPlatformIcon } from './const';@@ -79,15 +83,125 @@ const styles = createStaticStyles(({ css, cssVar }) => ({interface PlatformListProps {activeId: string;+ agentId: string;onSelect: (id: string) => void;platforms: SerializedPlatformDefinition[];+ providers?: BotProviderItem[];runtimeStatuses: Map<string, BotRuntimeStatus>;}const PlatformList = memo<PlatformListProps>(- ({ platforms, activeId, onSelect, runtimeStatuses }) => {+ ({ platforms, activeId, agentId, onSelect, providers, runtimeStatuses }) => {const { t } = useTranslation('agent');const theme = useTheme();+ const { modal, message } = App.useApp();+ const fileInputRef = useRef<HTMLInputElement>(null);+ const deleteAllBotProviders = useAgentStore((s) => s.deleteAllBotProviders);+ const createBotProvider = useAgentStore((s) => s.createBotProvider);+ const connectBot = useAgentStore((s) => s.connectBot);++ const handleExport = useCallback(() => {+ if (!providers?.length) return;+ const exportData = providers.map(({ id: _, ...rest }) => rest);+ exportJSONFile(exportData, `lobehub-channels-${agentId}.json`);+ }, [providers, agentId]);++ const handleImport = useCallback(() => {+ fileInputRef.current?.click();+ }, []);++ const handleFileChange = useCallback(+ async (e: React.ChangeEvent<HTMLInputElement>) => {+ const file = e.target.files?.[0];+ if (!file) return;++ try {+ const text = await file.text();+ const data = JSON.parse(text);++ if (!Array.isArray(data)) {+ message.error(t('channel.importInvalidFormat'));+ return;+ }++ for (const item of data) {+ if (!item.platform || !item.applicationId || !item.credentials) {+ message.error(t('channel.importInvalidFormat'));+ return;+ }+ }++ for (const item of data) {+ await createBotProvider({+ agentId,+ applicationId: item.applicationId,+ credentials: item.credentials,+ platform: item.platform,+ settings: item.settings ?? undefined,+ });+ if (item.enabled) {+ await connectBot({+ agentId,+ applicationId: item.applicationId,+ platform: item.platform,+ });+ }+ }++ message.success(t('channel.importSuccess'));+ } catch {+ message.error(t('channel.importFailed'));+ } finally {+ e.target.value = '';+ }+ },+ [agentId, connectBot, createBotProvider, message, t],+ );++ const handleDeleteAll = useCallback(() => {+ if (!providers?.length) return;+ modal.confirm({+ content: t('channel.deleteAllConfirmDesc'),+ okButtonProps: { danger: true },+ okText: t('channel.deleteAllChannels'),+ onOk: async () => {+ try {+ await deleteAllBotProviders(agentId);+ message.success(t('channel.deleteAllSuccess'));+ } catch {+ message.error(t('channel.deleteAllFailed'));+ }+ },+ title: t('channel.deleteAllConfirm'),+ type: 'warning',+ });+ }, [agentId, deleteAllBotProviders, message, modal, providers, t]);++ const hasProviders = !!providers?.length;+ const menuItems: MenuProps['items'] = [+ {+ icon: <Icon icon={Download} size={'small'} />,+ key: 'export',+ disabled: !hasProviders,+ label: t('channel.exportConfig'),+ onClick: handleExport,+ },+ {+ icon: <Icon icon={Upload} size={'small'} />,+ key: 'import',+ label: t('channel.importConfig'),+ onClick: handleImport,+ },+ { type: 'divider' },+ {+ danger: true,+ disabled: !hasProviders,+ icon: <Icon icon={Trash2} size={'small'} />,+ key: 'deleteAll',+ label: t('channel.deleteAllChannels'),+ onClick: handleDeleteAll,+ },+ ];const getStatusColor = (status?: BotRuntimeStatus) => {switch (status) {@@ -136,7 +250,31 @@ const PlatformList = memo<PlatformListProps>(return (<aside className={styles.root}><div className={styles.list}>- <div className={styles.title}>{t('channel.platforms')}</div>+ <div style={{ alignItems: 'center', display: 'flex', justifyContent: 'space-between' }}>+ <div className={styles.title}>{t('channel.platforms')}</div>+ <Dropdown menu={{ items: menuItems }} trigger={['click']}>+ <button+ style={{+ background: 'transparent',+ border: 'none',+ borderRadius: 4,+ color: theme.colorTextQuaternary,+ cursor: 'pointer',+ display: 'flex',+ padding: 4,+ }}+ >+ <Icon icon={MoreHorizontal} size={'small'} />+ </button>+ </Dropdown>+ </div>+ <input+ accept=".json"+ ref={fileInputRef}+ style={{ display: 'none' }}+ type="file"+ onChange={handleFileChange}+ />{platforms.map((platform) => {const PlatformIcon = getPlatformIcon(platform.name);const ColorIcon =diff --git a/src/store/agent/slices/bot/action.ts b/src/store/agent/slices/bot/action.tsindex 5af46bb96ce..96ef5021f85 100644--- a/src/store/agent/slices/bot/action.ts+++ b/src/store/agent/slices/bot/action.ts@@ -62,6 +62,13 @@ export class BotSliceActionImpl {return agentBotProviderService.testConnection(params);};+ deleteAllBotProviders = async (agentId: string) => {+ const providers = await agentBotProviderService.getByAgentId(agentId);+ await Promise.all(providers.map((p) => agentBotProviderService.delete(p.id)));+ await this.internal_refreshBotProviders(agentId);+ await this.internal_refreshBotRuntimeStatuses(agentId);+ };+deleteBotProvider = async (id: string, agentId: string) => {await agentBotProviderService.delete(id);await this.internal_refreshBotProviders(agentId);