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.
This commit is contained in:
@@ -1,20 +1,7 @@
|
|||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import {
|
import { parse as parseToml } from 'smol-toml'
|
||||||
BotInfoSection,
|
|
||||||
PersonalitySection,
|
import { AlertDescription, Alert } from '@/components/ui/alert'
|
||||||
DreamSection,
|
|
||||||
LPMMSection,
|
|
||||||
LogSection,
|
|
||||||
DebugSection,
|
|
||||||
ExperimentalSection,
|
|
||||||
MaimMessageSection,
|
|
||||||
TelemetrySection,
|
|
||||||
FeaturesSection,
|
|
||||||
ExpressionSection,
|
|
||||||
ProcessingSection,
|
|
||||||
MessageReceiveSection,
|
|
||||||
WebUISection,
|
|
||||||
} from './bot/sections'
|
|
||||||
import {
|
import {
|
||||||
AlertDialog,
|
AlertDialog,
|
||||||
AlertDialogAction,
|
AlertDialogAction,
|
||||||
@@ -26,53 +13,60 @@ import {
|
|||||||
AlertDialogTitle,
|
AlertDialogTitle,
|
||||||
AlertDialogTrigger,
|
AlertDialogTrigger,
|
||||||
} from '@/components/ui/alert-dialog'
|
} from '@/components/ui/alert-dialog'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||||
import { Save, Power, Code2, Layout } from 'lucide-react'
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||||
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 { CodeEditor } from '@/components'
|
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 {
|
import type {
|
||||||
BotConfig,
|
BotConfig,
|
||||||
PersonalityConfig,
|
|
||||||
ChatConfig,
|
ChatConfig,
|
||||||
ExpressionConfig,
|
ChineseTypoConfig,
|
||||||
|
DebugConfig,
|
||||||
|
DreamConfig,
|
||||||
EmojiConfig,
|
EmojiConfig,
|
||||||
|
ExperimentalConfig,
|
||||||
|
ExpressionConfig,
|
||||||
|
KeywordReactionConfig,
|
||||||
|
LogConfig,
|
||||||
|
LPMMKnowledgeConfig,
|
||||||
|
MaimMessageConfig,
|
||||||
MemoryConfig,
|
MemoryConfig,
|
||||||
|
MessageReceiveConfig,
|
||||||
|
PersonalityConfig,
|
||||||
|
ResponsePostProcessConfig,
|
||||||
|
ResponseSplitterConfig,
|
||||||
|
TelemetryConfig,
|
||||||
ToolConfig,
|
ToolConfig,
|
||||||
VoiceConfig,
|
VoiceConfig,
|
||||||
MessageReceiveConfig,
|
|
||||||
DreamConfig,
|
|
||||||
LPMMKnowledgeConfig,
|
|
||||||
KeywordReactionConfig,
|
|
||||||
ResponsePostProcessConfig,
|
|
||||||
ChineseTypoConfig,
|
|
||||||
ResponseSplitterConfig,
|
|
||||||
LogConfig,
|
|
||||||
DebugConfig,
|
|
||||||
ExperimentalConfig,
|
|
||||||
MaimMessageConfig,
|
|
||||||
TelemetryConfig,
|
|
||||||
WebUIConfig,
|
WebUIConfig,
|
||||||
} from './bot/types'
|
} from './bot/types'
|
||||||
|
|
||||||
// 导入 useAutoSave hook
|
|
||||||
import { useAutoSave, useConfigAutoSave } from './bot/hooks'
|
import { useAutoSave, useConfigAutoSave } from './bot/hooks'
|
||||||
|
import { ChatSectionHook } from './bot/hooks'
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
import {
|
||||||
import { Button } from '@/components/ui/button'
|
BotInfoSection,
|
||||||
|
DebugSection,
|
||||||
// 导入动态表单和 Hook 系统
|
DreamSection,
|
||||||
import { DynamicConfigForm } from '@/components/dynamic-form'
|
ExperimentalSection,
|
||||||
import { fieldHooks } from '@/lib/field-hooks'
|
ExpressionSection,
|
||||||
import { ChatSectionHook } from '@/routes/config/bot/hooks'
|
FeaturesSection,
|
||||||
|
LogSection,
|
||||||
|
LPMMSection,
|
||||||
|
MaimMessageSection,
|
||||||
|
MessageReceiveSection,
|
||||||
|
PersonalitySection,
|
||||||
|
ProcessingSection,
|
||||||
|
TelemetrySection,
|
||||||
|
WebUISection,
|
||||||
|
} from './bot/sections'
|
||||||
// ==================== 常量定义 ====================
|
// ==================== 常量定义 ====================
|
||||||
/** Toast 显示前的延迟时间 (毫秒) */
|
/** Toast 显示前的延迟时间 (毫秒) */
|
||||||
const TOAST_DISPLAY_DELAY = 500
|
const TOAST_DISPLAY_DELAY = 500
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import type { FieldHookComponent } from '@/lib/field-hooks'
|
import type { FieldHookComponent } from '@/lib/field-hooks'
|
||||||
|
|
||||||
|
import type { BotConfig } from '../types'
|
||||||
import { BotInfoSection } from '../sections/BotInfoSection'
|
import { BotInfoSection } from '../sections/BotInfoSection'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,7 +10,7 @@ import { BotInfoSection } from '../sections/BotInfoSection'
|
|||||||
export const BotInfoSectionHook: FieldHookComponent = ({ value, onChange }) => {
|
export const BotInfoSectionHook: FieldHookComponent = ({ value, onChange }) => {
|
||||||
return (
|
return (
|
||||||
<BotInfoSection
|
<BotInfoSection
|
||||||
config={value as any}
|
config={value as BotConfig}
|
||||||
onChange={(newConfig) => onChange?.(newConfig)}
|
onChange={(newConfig) => onChange?.(newConfig)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import type { FieldHookComponent } from '@/lib/field-hooks'
|
import type { FieldHookComponent } from '@/lib/field-hooks'
|
||||||
|
|
||||||
|
import type { DebugConfig } from '../types'
|
||||||
import { DebugSection } from '../sections/DebugSection'
|
import { DebugSection } from '../sections/DebugSection'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,7 +10,7 @@ import { DebugSection } from '../sections/DebugSection'
|
|||||||
export const DebugSectionHook: FieldHookComponent = ({ value, onChange }) => {
|
export const DebugSectionHook: FieldHookComponent = ({ value, onChange }) => {
|
||||||
return (
|
return (
|
||||||
<DebugSection
|
<DebugSection
|
||||||
config={value as any}
|
config={value as DebugConfig}
|
||||||
onChange={(newConfig) => onChange?.(newConfig)}
|
onChange={(newConfig) => onChange?.(newConfig)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import type { FieldHookComponent } from '@/lib/field-hooks'
|
import type { FieldHookComponent } from '@/lib/field-hooks'
|
||||||
|
|
||||||
|
import type { ExpressionConfig } from '../types'
|
||||||
import { ExpressionSection } from '../sections/ExpressionSection'
|
import { ExpressionSection } from '../sections/ExpressionSection'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,7 +10,7 @@ import { ExpressionSection } from '../sections/ExpressionSection'
|
|||||||
export const ExpressionSectionHook: FieldHookComponent = ({ value, onChange }) => {
|
export const ExpressionSectionHook: FieldHookComponent = ({ value, onChange }) => {
|
||||||
return (
|
return (
|
||||||
<ExpressionSection
|
<ExpressionSection
|
||||||
config={value as any}
|
config={value as ExpressionConfig}
|
||||||
onChange={(newConfig) => onChange?.(newConfig)}
|
onChange={(newConfig) => onChange?.(newConfig)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import type { FieldHookComponent } from '@/lib/field-hooks'
|
import type { FieldHookComponent } from '@/lib/field-hooks'
|
||||||
|
|
||||||
|
import type { PersonalityConfig } from '../types'
|
||||||
import { PersonalitySection } from '../sections/PersonalitySection'
|
import { PersonalitySection } from '../sections/PersonalitySection'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,7 +10,7 @@ import { PersonalitySection } from '../sections/PersonalitySection'
|
|||||||
export const PersonalitySectionHook: FieldHookComponent = ({ value, onChange }) => {
|
export const PersonalitySectionHook: FieldHookComponent = ({ value, onChange }) => {
|
||||||
return (
|
return (
|
||||||
<PersonalitySection
|
<PersonalitySection
|
||||||
config={value as any}
|
config={value as PersonalityConfig}
|
||||||
onChange={(newConfig) => onChange?.(newConfig)}
|
onChange={(newConfig) => onChange?.(newConfig)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,9 +4,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
|
|||||||
import { Switch } from '@/components/ui/switch'
|
import { Switch } from '@/components/ui/switch'
|
||||||
|
|
||||||
import type { ChatConfig } from '../types'
|
import type { ChatConfig } from '../types'
|
||||||
|
|
||||||
import { RuleList } from './RuleList'
|
import { RuleList } from './RuleList'
|
||||||
|
|
||||||
interface ChatSectionProps {
|
interface ChatSectionProps {
|
||||||
config: ChatConfig
|
config: ChatConfig
|
||||||
onChange: (config: ChatConfig) => void
|
onChange: (config: ChatConfig) => void
|
||||||
|
|||||||
Reference in New Issue
Block a user