refactor(chat): use select model picker in composer
parent
6ad8a1517f
commit
f665030ee6
|
|
@ -1,5 +1,5 @@
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { Button, Input, Space, Tag, App as AntApp, Popconfirm, Empty, Collapse, Switch, Drawer, Slider, InputNumber, Upload, Tooltip, Modal, Image as AntImage, Divider, Dropdown } from 'antd';
|
import { Button, Input, Space, Tag, App as AntApp, Popconfirm, Empty, Collapse, Switch, Drawer, Slider, InputNumber, Upload, Tooltip, Modal, Image as AntImage, Divider, Dropdown, Select } from 'antd';
|
||||||
import { SettingOutlined, ApiOutlined, EditOutlined, DeleteOutlined, PaperClipOutlined, BookOutlined, ArrowUpOutlined, CloseOutlined, DownOutlined } from '@ant-design/icons';
|
import { SettingOutlined, ApiOutlined, EditOutlined, DeleteOutlined, PaperClipOutlined, BookOutlined, ArrowUpOutlined, CloseOutlined, DownOutlined } from '@ant-design/icons';
|
||||||
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
||||||
import ReactMarkdown from 'react-markdown';
|
import ReactMarkdown from 'react-markdown';
|
||||||
|
|
@ -418,9 +418,15 @@ export default function ChatPage() {
|
||||||
label: modelName
|
label: modelName
|
||||||
}));
|
}));
|
||||||
const activeModelValue = overrides.model || '';
|
const activeModelValue = overrides.model || '';
|
||||||
const activeModelOption = modelOptions.find((item) => item.value === activeModelValue);
|
|
||||||
const defaultModelLabel = allowedModels.length > 0 ? allowedModels.join(', ') : agentModel || '默认模型';
|
const defaultModelLabel = allowedModels.length > 0 ? allowedModels.join(', ') : agentModel || '默认模型';
|
||||||
const currentModelName = activeModelOption?.label || activeModelValue || defaultModelLabel;
|
const selectedModelKey = activeModelValue || '__default__';
|
||||||
|
const modelSelectOptions = [
|
||||||
|
{
|
||||||
|
value: '__default__',
|
||||||
|
label: `跟随默认 · ${defaultModelLabel}`
|
||||||
|
},
|
||||||
|
...modelOptions
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="chat-shell">
|
<div className="chat-shell">
|
||||||
|
|
@ -639,7 +645,7 @@ export default function ChatPage() {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="chat-input-card">
|
<div className="chat-input-card">
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 10, width: '100%' }}>
|
<div className="chat-input-stack">
|
||||||
<Input.TextArea
|
<Input.TextArea
|
||||||
value={input}
|
value={input}
|
||||||
onChange={(e) => setInput(e.target.value)}
|
onChange={(e) => setInput(e.target.value)}
|
||||||
|
|
@ -653,73 +659,23 @@ export default function ChatPage() {
|
||||||
}}
|
}}
|
||||||
className="chat-input-textarea"
|
className="chat-input-textarea"
|
||||||
disabled={sending}
|
disabled={sending}
|
||||||
style={{ width: '100%' }}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div
|
<div className="chat-input-toolbar">
|
||||||
style={{
|
<div className="chat-input-toolbar-left">
|
||||||
display: 'flex',
|
<Select
|
||||||
alignItems: 'center',
|
value={selectedModelKey}
|
||||||
justifyContent: 'space-between',
|
className="chat-model-select"
|
||||||
gap: 12,
|
popupMatchSelectWidth={false}
|
||||||
paddingTop: 8,
|
options={modelSelectOptions}
|
||||||
borderTop: '1px solid var(--color-border)'
|
suffixIcon={<DownOutlined className="chat-model-select-arrow" />}
|
||||||
}}
|
onChange={(value) =>
|
||||||
>
|
setOverrides((o) => ({
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, flex: 1, minWidth: 0 }}>
|
...o,
|
||||||
<Dropdown
|
model: value === '__default__' ? undefined : String(value)
|
||||||
trigger={['hover']}
|
}))
|
||||||
placement="topLeft"
|
}
|
||||||
menu={{
|
/>
|
||||||
selectedKeys: [activeModelValue || '__default__'],
|
|
||||||
onClick: ({ key }) =>
|
|
||||||
setOverrides((o) => ({
|
|
||||||
...o,
|
|
||||||
model: String(key) === '__default__' ? undefined : String(key)
|
|
||||||
})),
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
key: '__default__',
|
|
||||||
label: `跟随默认 · ${defaultModelLabel}`
|
|
||||||
},
|
|
||||||
...modelOptions.map((item) => ({
|
|
||||||
key: item.value,
|
|
||||||
label: `${item.label}`
|
|
||||||
}))
|
|
||||||
]
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
style={{
|
|
||||||
display: 'inline-flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: 6,
|
|
||||||
minWidth: 0,
|
|
||||||
padding: '0 2px',
|
|
||||||
background: 'transparent',
|
|
||||||
border: 'none',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
cursor: 'pointer',
|
|
||||||
fontSize: 13,
|
|
||||||
lineHeight: 1.2
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
maxWidth: 240,
|
|
||||||
overflow: 'hidden',
|
|
||||||
textOverflow: 'ellipsis',
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
fontWeight: 500,
|
|
||||||
color: 'var(--color-text)'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{currentModelName}
|
|
||||||
</span>
|
|
||||||
<DownOutlined style={{ fontSize: 10, color: 'var(--color-text-tertiary)' }} />
|
|
||||||
</button>
|
|
||||||
</Dropdown>
|
|
||||||
|
|
||||||
<Upload
|
<Upload
|
||||||
multiple
|
multiple
|
||||||
|
|
@ -740,8 +696,8 @@ export default function ChatPage() {
|
||||||
danger
|
danger
|
||||||
shape="circle"
|
shape="circle"
|
||||||
onClick={handleStop}
|
onClick={handleStop}
|
||||||
icon={<div style={{ width: 10, height: 10, background: 'currentColor', borderRadius: 2 }} />}
|
icon={<span className="chat-stop-icon" />}
|
||||||
style={{ width: 40, height: 40, flexShrink: 0 }}
|
className="chat-send-button"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Button
|
<Button
|
||||||
|
|
@ -750,13 +706,13 @@ export default function ChatPage() {
|
||||||
onClick={handleSend}
|
onClick={handleSend}
|
||||||
icon={<ArrowUpOutlined />}
|
icon={<ArrowUpOutlined />}
|
||||||
disabled={!input.trim()}
|
disabled={!input.trim()}
|
||||||
style={{ background: 'var(--color-brand)', border: 'none', width: 40, height: 40, flexShrink: 0 }}
|
className="chat-send-button chat-send-button-primary"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ textAlign: 'center', fontSize: 11, color: 'var(--color-text-tertiary)', marginTop: 8 }}>
|
<div className="chat-disclaimer">
|
||||||
AI 可能会产生错误信息,请核实重要信息。
|
AI 可能会产生错误信息,请核实重要信息。
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -561,6 +561,84 @@ body {
|
||||||
box-shadow: var(--shadow-focus);
|
box-shadow: var(--shadow-focus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.chat-input-stack {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-input-toolbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
padding-top: 8px;
|
||||||
|
border-top: 1px solid var(--color-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-input-toolbar-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-model-select {
|
||||||
|
min-width: 240px;
|
||||||
|
max-width: 320px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-model-select .ant-select-selector {
|
||||||
|
border: none !important;
|
||||||
|
box-shadow: none !important;
|
||||||
|
background: transparent !important;
|
||||||
|
padding: 0 24px 0 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-model-select .ant-select-selection-item {
|
||||||
|
color: var(--color-text);
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-model-select .ant-select-selection-placeholder {
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-model-select-arrow {
|
||||||
|
font-size: 10px;
|
||||||
|
color: var(--color-text-tertiary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-send-button {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-send-button-primary {
|
||||||
|
background: var(--color-brand);
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-stop-icon {
|
||||||
|
display: block;
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
background: currentColor;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-disclaimer {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--color-text-tertiary);
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
.agent-model-dropdown-trigger {
|
.agent-model-dropdown-trigger {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
min-height: 42px;
|
min-height: 42px;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue