File size: 8,421 Bytes
4ef3a0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*

Copyright (C) 2025 QuantumNous



This program is free software: you can redistribute it and/or modify

it under the terms of the GNU Affero General Public License as

published by the Free Software Foundation, either version 3 of the

License, or (at your option) any later version.



This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU Affero General Public License for more details.



You should have received a copy of the GNU Affero General Public License

along with this program. If not, see <https://www.gnu.org/licenses/>.



For commercial licensing, please contact support@quantumnous.com

*/

import React from 'react';
import { Card, Select, Typography, Button, Switch } from '@douyinfe/semi-ui';
import { Sparkles, Users, ToggleLeft, X, Settings } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { renderGroupOption, selectFilter } from '../../helpers';
import ParameterControl from './ParameterControl';
import ImageUrlInput from './ImageUrlInput';
import ConfigManager from './ConfigManager';
import CustomRequestEditor from './CustomRequestEditor';

const SettingsPanel = ({

  inputs,

  parameterEnabled,

  models,

  groups,

  styleState,

  showDebugPanel,

  customRequestMode,

  customRequestBody,

  onInputChange,

  onParameterToggle,

  onCloseSettings,

  onConfigImport,

  onConfigReset,

  onCustomRequestModeChange,

  onCustomRequestBodyChange,

  previewPayload,

  messages,

}) => {
  const { t } = useTranslation();

  const currentConfig = {
    inputs,
    parameterEnabled,
    showDebugPanel,
    customRequestMode,
    customRequestBody,
  };

  return (
    <Card

      className='h-full flex flex-col'

      bordered={false}

      bodyStyle={{

        padding: styleState.isMobile ? '16px' : '24px',

        height: '100%',

        display: 'flex',

        flexDirection: 'column',

      }}

    >

      {/* 标题区域 - 与调试面板保持一致 */}

      <div className='flex items-center justify-between mb-6 flex-shrink-0'>

        <div className='flex items-center'>

          <div className='w-10 h-10 rounded-full bg-gradient-to-r from-purple-500 to-pink-500 flex items-center justify-center mr-3'>

            <Settings size={20} className='text-white' />

          </div>

          <Typography.Title heading={5} className='mb-0'>

            {t('模型配置')}

          </Typography.Title>

        </div>



        {styleState.isMobile && onCloseSettings && (

          <Button

            icon={<X size={16} />}

            onClick={onCloseSettings}

            theme='borderless'

            type='tertiary'

            size='small'

            className='!rounded-lg'

          />

        )}

      </div>



      {/* 移动端配置管理 */}

      {styleState.isMobile && (

        <div className='mb-4 flex-shrink-0'>

          <ConfigManager

            currentConfig={currentConfig}

            onConfigImport={onConfigImport}

            onConfigReset={onConfigReset}

            styleState={{ ...styleState, isMobile: false }}

            messages={messages}

          />

        </div>

      )}



      <div className='space-y-6 overflow-y-auto flex-1 pr-2 model-settings-scroll'>

        {/* 自定义请求体编辑器 */}

        <CustomRequestEditor

          customRequestMode={customRequestMode}

          customRequestBody={customRequestBody}

          onCustomRequestModeChange={onCustomRequestModeChange}

          onCustomRequestBodyChange={onCustomRequestBodyChange}

          defaultPayload={previewPayload}

        />



        {/* 分组选择 */}

        <div className={customRequestMode ? 'opacity-50' : ''}>

          <div className='flex items-center gap-2 mb-2'>

            <Users size={16} className='text-gray-500' />

            <Typography.Text strong className='text-sm'>

              {t('分组')}

            </Typography.Text>

            {customRequestMode && (

              <Typography.Text className='text-xs text-orange-600'>

                (已在自定义模式中忽略)

              </Typography.Text>

            )}

          </div>

          <Select

            placeholder={t('请选择分组')}

            name='group'

            required

            selection

            filter={selectFilter}

            autoClearSearchValue={false}

            onChange={(value) => onInputChange('group', value)}

            value={inputs.group}

            autoComplete='new-password'

            optionList={groups}

            renderOptionItem={renderGroupOption}

            style={{ width: '100%' }}

            dropdownStyle={{ width: '100%', maxWidth: '100%' }}

            className='!rounded-lg'

            disabled={customRequestMode}

          />

        </div>



        {/* 模型选择 */}

        <div className={customRequestMode ? 'opacity-50' : ''}>

          <div className='flex items-center gap-2 mb-2'>

            <Sparkles size={16} className='text-gray-500' />

            <Typography.Text strong className='text-sm'>

              {t('模型')}

            </Typography.Text>

            {customRequestMode && (

              <Typography.Text className='text-xs text-orange-600'>

                (已在自定义模式中忽略)

              </Typography.Text>

            )}

          </div>

          <Select

            placeholder={t('请选择模型')}

            name='model'

            required

            selection

            filter={selectFilter}

            autoClearSearchValue={false}

            onChange={(value) => onInputChange('model', value)}

            value={inputs.model}

            autoComplete='new-password'

            optionList={models}

            style={{ width: '100%' }}

            dropdownStyle={{ width: '100%', maxWidth: '100%' }}

            className='!rounded-lg'

            disabled={customRequestMode}

          />

        </div>



        {/* 图片URL输入 */}

        <div className={customRequestMode ? 'opacity-50' : ''}>

          <ImageUrlInput

            imageUrls={inputs.imageUrls}

            imageEnabled={inputs.imageEnabled}

            onImageUrlsChange={(urls) => onInputChange('imageUrls', urls)}

            onImageEnabledChange={(enabled) =>

              onInputChange('imageEnabled', enabled)

            }

            disabled={customRequestMode}

          />

        </div>



        {/* 参数控制组件 */}

        <div className={customRequestMode ? 'opacity-50' : ''}>

          <ParameterControl

            inputs={inputs}

            parameterEnabled={parameterEnabled}

            onInputChange={onInputChange}

            onParameterToggle={onParameterToggle}

            disabled={customRequestMode}

          />

        </div>



        {/* 流式输出开关 */}

        <div className={customRequestMode ? 'opacity-50' : ''}>

          <div className='flex items-center justify-between'>

            <div className='flex items-center gap-2'>

              <ToggleLeft size={16} className='text-gray-500' />

              <Typography.Text strong className='text-sm'>

                流式输出

              </Typography.Text>

              {customRequestMode && (

                <Typography.Text className='text-xs text-orange-600'>

                  (已在自定义模式中忽略)

                </Typography.Text>

              )}

            </div>

            <Switch

              checked={inputs.stream}

              onChange={(checked) => onInputChange('stream', checked)}

              checkedText='开'

              uncheckedText='关'

              size='small'

              disabled={customRequestMode}

            />

          </div>

        </div>

      </div>



      {/* 桌面端的配置管理放在底部 */}

      {!styleState.isMobile && (

        <div className='flex-shrink-0 pt-3'>

          <ConfigManager

            currentConfig={currentConfig}

            onConfigImport={onConfigImport}

            onConfigReset={onConfigReset}

            styleState={styleState}

            messages={messages}

          />

        </div>

      )}

    </Card>
  );
};

export default SettingsPanel;