1- import React , { useRef , forwardRef , useImperativeHandle } from 'react'
2- import { Input , Button , Alert } from 'antd'
3- import { SendOutlined , StopOutlined , SettingOutlined } from '@ant-design/icons'
1+ import React , { useRef , forwardRef , useImperativeHandle , useState } from 'react'
2+ import { Input , Button , Alert , Switch , Tooltip , Space , Select , Dropdown } from 'antd'
3+ import { SendOutlined , StopOutlined , SettingOutlined , QuestionCircleOutlined , BulbOutlined , DownOutlined } from '@ant-design/icons'
44import { LLMConfig } from '../../../types/type'
5+ import { useSettingsStore } from '../../../stores/settingsStore'
56import ModelSelector from './ModelSelector'
67
78const { TextArea } = Input
9+ const { Option } = Select
10+
11+ // 自动提问控件组件
12+ interface AutoQuestionControlsProps {
13+ enabled : boolean
14+ mode : 'ai' | 'preset'
15+ selectedListId ?: string
16+ promptLists : any [ ]
17+ disabled : boolean
18+ onChange ?: ( enabled : boolean , mode : 'ai' | 'preset' , listId ?: string ) => void
19+ }
20+
21+ function AutoQuestionControls ( {
22+ enabled,
23+ mode,
24+ selectedListId,
25+ promptLists,
26+ disabled,
27+ onChange
28+ } : AutoQuestionControlsProps ) {
29+ const handleEnabledChange = ( checked : boolean ) => {
30+ let finalListId = selectedListId
31+ // 如果开启自动提问且是预设模式,但没有选择列表,使用第一个可用列表
32+ if ( checked && mode === 'preset' && ! selectedListId && promptLists . length > 0 ) {
33+ finalListId = promptLists [ 0 ] . id
34+ }
35+ console . log ( 'AutoQuestionControls handleEnabledChange:' , {
36+ checked,
37+ mode,
38+ selectedListId,
39+ finalListId,
40+ promptListsLength : promptLists . length
41+ } )
42+ onChange ?.( checked , mode , finalListId )
43+ }
44+
45+ const handleModeChange = ( newMode : 'ai' | 'preset' ) => {
46+ onChange ?.( enabled , newMode , newMode === 'preset' ? ( selectedListId || promptLists [ 0 ] ?. id ) : undefined )
47+ }
48+
49+ const handleListChange = ( listId : string ) => {
50+ onChange ?.( enabled , mode , listId )
51+ }
52+
53+ const getCurrentPromptList = ( ) => {
54+ return promptLists . find ( list => list . id === selectedListId )
55+ }
56+
57+ const modeOptions = [
58+ {
59+ key : 'ai' ,
60+ label : (
61+ < Space >
62+ < QuestionCircleOutlined />
63+ AI自动追问
64+ </ Space >
65+ )
66+ } ,
67+ {
68+ key : 'preset' ,
69+ label : (
70+ < Space >
71+ < BulbOutlined />
72+ 预设列表提问
73+ </ Space >
74+ )
75+ }
76+ ]
77+
78+ const dropdownMenu = {
79+ items : modeOptions . map ( option => ( {
80+ key : option . key ,
81+ label : option . label ,
82+ onClick : ( ) => handleModeChange ( option . key as 'ai' | 'preset' )
83+ } ) )
84+ }
85+
86+ return (
87+ < div style = { { display : 'flex' , alignItems : 'center' , gap : 8 , flexWrap : 'wrap' } } >
88+ < Tooltip title = "开启后,AI回答完成将自动继续提问" >
89+ < Space align = "center" size = "small" >
90+ < Switch
91+ size = "small"
92+ checked = { enabled }
93+ onChange = { handleEnabledChange }
94+ disabled = { disabled }
95+ />
96+ < span style = { { fontSize : '12px' } } > 自动提问</ span >
97+ </ Space >
98+ </ Tooltip >
99+
100+ { enabled && (
101+ < >
102+ < Dropdown menu = { dropdownMenu } trigger = { [ 'click' ] } disabled = { disabled } >
103+ < Button size = "small" style = { { fontSize : '11px' } } >
104+ { mode === 'ai' ? (
105+ < Space size = { 4 } >
106+ < QuestionCircleOutlined />
107+ AI追问
108+ </ Space >
109+ ) : (
110+ < Space size = { 4 } >
111+ < BulbOutlined />
112+ 预设列表
113+ </ Space >
114+ ) }
115+ < DownOutlined />
116+ </ Button >
117+ </ Dropdown >
118+
119+ { mode === 'preset' && (
120+ < Select
121+ size = "small"
122+ value = { selectedListId }
123+ onChange = { handleListChange }
124+ placeholder = "选择列表"
125+ style = { { minWidth : 120 , fontSize : '11px' } }
126+ disabled = { disabled || promptLists . length === 0 }
127+ >
128+ { promptLists . map ( ( list ) => (
129+ < Option key = { list . id } value = { list . id } >
130+ { list . name }
131+ </ Option >
132+ ) ) }
133+ </ Select >
134+ ) }
135+ </ >
136+ ) }
137+ </ div >
138+ )
139+ }
8140
9141interface ChatInputProps {
10142 value : string
@@ -18,6 +150,11 @@ interface ChatInputProps {
18150 defaultModelId ?: string
19151 onModelChange : ( modelId : string ) => void
20152 onOpenSettings ?: ( ) => void
153+ // 自动提问相关
154+ autoQuestionEnabled ?: boolean
155+ autoQuestionMode ?: 'ai' | 'preset'
156+ autoQuestionListId ?: string
157+ onAutoQuestionChange ?: ( enabled : boolean , mode : 'ai' | 'preset' , listId ?: string ) => void
21158}
22159
23160export interface ChatInputRef {
@@ -37,11 +174,16 @@ const ChatInput = forwardRef<ChatInputRef, ChatInputProps>(
37174 selectedModel,
38175 defaultModelId,
39176 onModelChange,
40- onOpenSettings
177+ onOpenSettings,
178+ autoQuestionEnabled = false ,
179+ autoQuestionMode = 'ai' ,
180+ autoQuestionListId,
181+ onAutoQuestionChange
41182 } ,
42183 ref
43184 ) => {
44185 const textAreaRef = useRef < any > ( null )
186+ const { settings } = useSettingsStore ( )
45187
46188 useImperativeHandle ( ref , ( ) => ( {
47189 focus : ( ) => {
@@ -97,14 +239,24 @@ const ChatInput = forwardRef<ChatInputRef, ChatInputProps>(
97239 ) }
98240
99241 < div className = "chat-input-container" >
100- < ModelSelector
101- llmConfigs = { llmConfigs }
102- selectedModel = { selectedModel }
103- defaultLLMId = { defaultModelId }
104- onChange = { onModelChange }
105- disabled = { disabled || loading }
106- size = "small"
107- />
242+ < div style = { { display : 'flex' , alignItems : 'center' , gap : 8 , marginBottom : 8 } } >
243+ < ModelSelector
244+ llmConfigs = { llmConfigs }
245+ selectedModel = { selectedModel }
246+ defaultLLMId = { defaultModelId }
247+ onChange = { onModelChange }
248+ disabled = { disabled || loading }
249+ size = "small"
250+ />
251+ < AutoQuestionControls
252+ enabled = { autoQuestionEnabled }
253+ mode = { autoQuestionMode }
254+ selectedListId = { autoQuestionListId }
255+ promptLists = { settings . promptLists || [ ] }
256+ disabled = { disabled || loading }
257+ onChange = { onAutoQuestionChange }
258+ />
259+ </ div >
108260 < TextArea
109261 ref = { textAreaRef }
110262 placeholder = {
0 commit comments