From c45ee1a98e77597d319f01e6db8d414e8faa21ff Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sun, 1 Mar 2026 21:17:17 +0800 Subject: [PATCH] refactor(routes): review and fix config/bot/ directory (T16) - Fixed import order in bot.tsx, ChatSection.tsx and Hook files - Replaced 'as any' with specific type assertions (ExpressionConfig, PersonalityConfig, etc.) - All files now comply with AGENTS.md import rules - Build passes with zero errors - LSP diagnostics clean on all modified files Changes: - bot.tsx: Reorganized imports (React first, then third-party, then @/, then ./) - ChatSection.tsx: Fixed import order - *SectionHook.tsx (4 files): Added type imports, replaced 'as any' with typed assertions Note: ProcessingSection (1121 lines) and ExpressionSection (996 lines) not split due to tight coupling and clear responsibilities. --- dashboard/src/routes/config/bot.tsx | 96 +++++++++---------- .../config/bot/hooks/BotInfoSectionHook.tsx | 4 +- .../config/bot/hooks/DebugSectionHook.tsx | 4 +- .../bot/hooks/ExpressionSectionHook.tsx | 4 +- .../bot/hooks/PersonalitySectionHook.tsx | 4 +- .../config/bot/sections/ChatSection.tsx | 2 - 6 files changed, 57 insertions(+), 57 deletions(-) diff --git a/dashboard/src/routes/config/bot.tsx b/dashboard/src/routes/config/bot.tsx index ee923f9f..0f81d58a 100644 --- a/dashboard/src/routes/config/bot.tsx +++ b/dashboard/src/routes/config/bot.tsx @@ -1,20 +1,7 @@ -import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs' -import { - BotInfoSection, - PersonalitySection, - DreamSection, - LPMMSection, - LogSection, - DebugSection, - ExperimentalSection, - MaimMessageSection, - TelemetrySection, - FeaturesSection, - ExpressionSection, - ProcessingSection, - MessageReceiveSection, - WebUISection, -} from './bot/sections' +import { useCallback, useEffect, useRef, useState } from 'react' +import { parse as parseToml } from 'smol-toml' + +import { AlertDescription, Alert } from '@/components/ui/alert' import { AlertDialog, AlertDialogAction, @@ -26,53 +13,60 @@ import { AlertDialogTitle, AlertDialogTrigger, } from '@/components/ui/alert-dialog' +import { Button } from '@/components/ui/button' import { ScrollArea } from '@/components/ui/scroll-area' -import { Save, Power, Code2, Layout } from 'lucide-react' -import { getBotConfig, updateBotConfig, getBotConfigRaw, updateBotConfigRaw } from '@/lib/config-api' -import { useToast } from '@/hooks/use-toast' -import { Alert, AlertDescription } from '@/components/ui/alert' -import { Info } from 'lucide-react' -import { RestartOverlay } from '@/components/restart-overlay' -import { RestartProvider, useRestart } from '@/lib/restart-context' +import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs' import { CodeEditor } from '@/components' -import { parse as parseToml } from 'smol-toml' +import { DynamicConfigForm } from '@/components/dynamic-form' +import { RestartOverlay } from '@/components/restart-overlay' +import { useToast } from '@/hooks/use-toast' +import { getBotConfig, getBotConfigRaw, updateBotConfig, updateBotConfigRaw } from '@/lib/config-api' +import { fieldHooks } from '@/lib/field-hooks' +import { RestartProvider, useRestart } from '@/lib/restart-context' + +import { Code2, Info, Layout, Power, Save } from 'lucide-react' -// 导入模块化的类型定义 import type { BotConfig, - PersonalityConfig, ChatConfig, - ExpressionConfig, + ChineseTypoConfig, + DebugConfig, + DreamConfig, EmojiConfig, + ExperimentalConfig, + ExpressionConfig, + KeywordReactionConfig, + LogConfig, + LPMMKnowledgeConfig, + MaimMessageConfig, MemoryConfig, + MessageReceiveConfig, + PersonalityConfig, + ResponsePostProcessConfig, + ResponseSplitterConfig, + TelemetryConfig, ToolConfig, VoiceConfig, - MessageReceiveConfig, - DreamConfig, - LPMMKnowledgeConfig, - KeywordReactionConfig, - ResponsePostProcessConfig, - ChineseTypoConfig, - ResponseSplitterConfig, - LogConfig, - DebugConfig, - ExperimentalConfig, - MaimMessageConfig, - TelemetryConfig, WebUIConfig, } from './bot/types' - -// 导入 useAutoSave hook import { useAutoSave, useConfigAutoSave } from './bot/hooks' - -import { useCallback, useEffect, useRef, useState } from 'react' -import { Button } from '@/components/ui/button' - -// 导入动态表单和 Hook 系统 -import { DynamicConfigForm } from '@/components/dynamic-form' -import { fieldHooks } from '@/lib/field-hooks' -import { ChatSectionHook } from '@/routes/config/bot/hooks' - +import { ChatSectionHook } from './bot/hooks' +import { + BotInfoSection, + DebugSection, + DreamSection, + ExperimentalSection, + ExpressionSection, + FeaturesSection, + LogSection, + LPMMSection, + MaimMessageSection, + MessageReceiveSection, + PersonalitySection, + ProcessingSection, + TelemetrySection, + WebUISection, +} from './bot/sections' // ==================== 常量定义 ==================== /** Toast 显示前的延迟时间 (毫秒) */ const TOAST_DISPLAY_DELAY = 500 diff --git a/dashboard/src/routes/config/bot/hooks/BotInfoSectionHook.tsx b/dashboard/src/routes/config/bot/hooks/BotInfoSectionHook.tsx index 70ba89f9..d5a4e35d 100644 --- a/dashboard/src/routes/config/bot/hooks/BotInfoSectionHook.tsx +++ b/dashboard/src/routes/config/bot/hooks/BotInfoSectionHook.tsx @@ -1,4 +1,6 @@ import type { FieldHookComponent } from '@/lib/field-hooks' + +import type { BotConfig } from '../types' import { BotInfoSection } from '../sections/BotInfoSection' /** @@ -8,7 +10,7 @@ import { BotInfoSection } from '../sections/BotInfoSection' export const BotInfoSectionHook: FieldHookComponent = ({ value, onChange }) => { return ( onChange?.(newConfig)} /> ) diff --git a/dashboard/src/routes/config/bot/hooks/DebugSectionHook.tsx b/dashboard/src/routes/config/bot/hooks/DebugSectionHook.tsx index f5b63e11..9e4eae9a 100644 --- a/dashboard/src/routes/config/bot/hooks/DebugSectionHook.tsx +++ b/dashboard/src/routes/config/bot/hooks/DebugSectionHook.tsx @@ -1,4 +1,6 @@ import type { FieldHookComponent } from '@/lib/field-hooks' + +import type { DebugConfig } from '../types' import { DebugSection } from '../sections/DebugSection' /** @@ -8,7 +10,7 @@ import { DebugSection } from '../sections/DebugSection' export const DebugSectionHook: FieldHookComponent = ({ value, onChange }) => { return ( onChange?.(newConfig)} /> ) diff --git a/dashboard/src/routes/config/bot/hooks/ExpressionSectionHook.tsx b/dashboard/src/routes/config/bot/hooks/ExpressionSectionHook.tsx index d2f9ee01..6ff6c49d 100644 --- a/dashboard/src/routes/config/bot/hooks/ExpressionSectionHook.tsx +++ b/dashboard/src/routes/config/bot/hooks/ExpressionSectionHook.tsx @@ -1,4 +1,6 @@ import type { FieldHookComponent } from '@/lib/field-hooks' + +import type { ExpressionConfig } from '../types' import { ExpressionSection } from '../sections/ExpressionSection' /** @@ -8,7 +10,7 @@ import { ExpressionSection } from '../sections/ExpressionSection' export const ExpressionSectionHook: FieldHookComponent = ({ value, onChange }) => { return ( onChange?.(newConfig)} /> ) diff --git a/dashboard/src/routes/config/bot/hooks/PersonalitySectionHook.tsx b/dashboard/src/routes/config/bot/hooks/PersonalitySectionHook.tsx index d97b86ea..32ab8cee 100644 --- a/dashboard/src/routes/config/bot/hooks/PersonalitySectionHook.tsx +++ b/dashboard/src/routes/config/bot/hooks/PersonalitySectionHook.tsx @@ -1,4 +1,6 @@ import type { FieldHookComponent } from '@/lib/field-hooks' + +import type { PersonalityConfig } from '../types' import { PersonalitySection } from '../sections/PersonalitySection' /** @@ -8,7 +10,7 @@ import { PersonalitySection } from '../sections/PersonalitySection' export const PersonalitySectionHook: FieldHookComponent = ({ value, onChange }) => { return ( onChange?.(newConfig)} /> ) diff --git a/dashboard/src/routes/config/bot/sections/ChatSection.tsx b/dashboard/src/routes/config/bot/sections/ChatSection.tsx index 6546b4d3..5648a3c0 100644 --- a/dashboard/src/routes/config/bot/sections/ChatSection.tsx +++ b/dashboard/src/routes/config/bot/sections/ChatSection.tsx @@ -4,9 +4,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@ import { Switch } from '@/components/ui/switch' import type { ChatConfig } from '../types' - import { RuleList } from './RuleList' - interface ChatSectionProps { config: ChatConfig onChange: (config: ChatConfig) => void