feat: 添加模型选择器组件,整合模型选择功能到输入区域
This commit is contained in:
@ -1,4 +1,9 @@
|
||||
import { getWaveformPreviewContent } from "./waveformPreviewContent";
|
||||
import {
|
||||
getModelSelectorContent,
|
||||
getModelSelectorStyles,
|
||||
getModelSelectorScript
|
||||
} from "./modelSelector";
|
||||
|
||||
/**
|
||||
* 获取输入区域的 HTML 内容
|
||||
@ -54,24 +59,7 @@ export function getInputAreaContent(): string {
|
||||
<span class="tooltiptext">切换模式</span>
|
||||
</div>
|
||||
|
||||
<!-- 模型选择 -->
|
||||
<div class="tooltip">
|
||||
<div class="custom-select" id="modelSelect">
|
||||
<div class="select-trigger" onclick="toggleModelDropdown()">
|
||||
<span class="select-value" id="modelValue">Auto</span>
|
||||
<svg class="select-arrow" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M507.8 727.728a30.016 30.016 0 0 1-21.288-8.824L231.104 463.496a30.088 30.088 0 0 1 0-42.568 30.088 30.088 0 0 1 42.568 0l234.128 234.128 234.16-234.128a30.088 30.088 0 0 1 42.568 0 30.088 30.088 0 0 1 0 42.568L529.08 718.904a30 30 0 0 1-21.28 8.824z" fill="#8a8a8a"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="select-dropdown" id="modelDropdown">
|
||||
<div class="select-option" data-value="lite" onclick="selectModel('lite', 'Lite')">Lite</div>
|
||||
<div class="select-option selected" data-value="auto" onclick="selectModel('auto', 'Auto')">Auto</div>
|
||||
<div class="select-option" data-value="syntaxic" onclick="selectModel('syntaxic', 'Syntaxic')">Syntaxic</div>
|
||||
<div class="select-option" data-value="max" onclick="selectModel('max', 'Max')">Max</div>
|
||||
</div>
|
||||
</div>
|
||||
<span class="tooltiptext">选择模型</span>
|
||||
</div>
|
||||
${getModelSelectorContent()}
|
||||
</div>
|
||||
<div class="input-actions">
|
||||
<!-- 上下文显示 -->
|
||||
@ -132,6 +120,7 @@ export function getInputAreaContent(): string {
|
||||
*/
|
||||
export function getInputAreaStyles(): string {
|
||||
return `
|
||||
${getModelSelectorStyles()}
|
||||
.input-area {
|
||||
border-top: 1px solid var(--vscode-panel-border);
|
||||
padding-top: 15px;
|
||||
@ -256,7 +245,7 @@ export function getInputAreaStyles(): string {
|
||||
gap: 8px;
|
||||
position: relative;
|
||||
}
|
||||
/* 自定义下拉框样式 */
|
||||
/* 自定义下拉框样式(用于模式选择) */
|
||||
.custom-select {
|
||||
position: relative;
|
||||
user-select: none;
|
||||
@ -305,17 +294,18 @@ export function getInputAreaStyles(): string {
|
||||
.custom-select.active .select-dropdown {
|
||||
display: block;
|
||||
}
|
||||
.select-option {
|
||||
/* 模式选择器的选项样式 */
|
||||
#selectDropdown .select-option {
|
||||
padding: 6px 12px;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s ease;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.select-option:hover {
|
||||
#selectDropdown .select-option:hover {
|
||||
background: rgba(128, 128, 128, 0.3);
|
||||
}
|
||||
.select-option.selected {
|
||||
#selectDropdown .select-option.selected {
|
||||
background: rgba(128, 128, 128, 0.5);
|
||||
color: var(--vscode-foreground);
|
||||
}
|
||||
@ -571,6 +561,8 @@ export function getInputAreaStyles(): string {
|
||||
*/
|
||||
export function getInputAreaScript(): string {
|
||||
return `
|
||||
${getModelSelectorScript()}
|
||||
|
||||
// 自动调整 textarea 高度
|
||||
function autoResizeTextarea() {
|
||||
if (messageInput) {
|
||||
@ -592,7 +584,6 @@ export function getInputAreaScript(): string {
|
||||
|
||||
// 自定义下拉框相关变量
|
||||
let currentMode = 'agent';
|
||||
let currentModel = 'auto';
|
||||
|
||||
// 切换模式下拉框显示/隐藏
|
||||
function toggleModeDropdown() {
|
||||
@ -607,19 +598,6 @@ export function getInputAreaScript(): string {
|
||||
}
|
||||
}
|
||||
|
||||
// 切换模型下拉框显示/隐藏
|
||||
function toggleModelDropdown() {
|
||||
const modelSelect = document.getElementById('modelSelect');
|
||||
const customSelect = document.getElementById('customSelect');
|
||||
if (modelSelect) {
|
||||
modelSelect.classList.toggle('active');
|
||||
// 关闭模式下拉框
|
||||
if (customSelect) {
|
||||
customSelect.classList.remove('active');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 选择模式
|
||||
function selectMode(value, label) {
|
||||
currentMode = value;
|
||||
@ -645,43 +623,13 @@ export function getInputAreaScript(): string {
|
||||
}
|
||||
}
|
||||
|
||||
// 选择模型
|
||||
function selectModel(value, label) {
|
||||
currentModel = value;
|
||||
const modelValue = document.getElementById('modelValue');
|
||||
if (modelValue) {
|
||||
modelValue.textContent = label;
|
||||
}
|
||||
|
||||
// 更新选中状态
|
||||
const options = document.querySelectorAll('#modelDropdown .select-option');
|
||||
options.forEach(option => {
|
||||
if (option.getAttribute('data-value') === value) {
|
||||
option.classList.add('selected');
|
||||
} else {
|
||||
option.classList.remove('selected');
|
||||
}
|
||||
});
|
||||
|
||||
// 关闭下拉框
|
||||
const modelSelect = document.getElementById('modelSelect');
|
||||
if (modelSelect) {
|
||||
modelSelect.classList.remove('active');
|
||||
}
|
||||
}
|
||||
|
||||
// 点击外部关闭下拉框
|
||||
document.addEventListener('click', (event) => {
|
||||
const customSelect = document.getElementById('customSelect');
|
||||
const modelSelect = document.getElementById('modelSelect');
|
||||
|
||||
if (customSelect && !customSelect.contains(event.target)) {
|
||||
customSelect.classList.remove('active');
|
||||
}
|
||||
|
||||
if (modelSelect && !modelSelect.contains(event.target)) {
|
||||
modelSelect.classList.remove('active');
|
||||
}
|
||||
});
|
||||
|
||||
function sendMessage() {
|
||||
@ -689,7 +637,7 @@ export function getInputAreaScript(): string {
|
||||
if (!text) return;
|
||||
|
||||
const mode = currentMode;
|
||||
const model = currentModel;
|
||||
const model = getCurrentModel(); // 从模型选择器组件获取当前模型
|
||||
|
||||
addMessage(text, 'user');
|
||||
vscode.postMessage({ command: 'sendMessage', text: text, mode: mode, model: model });
|
||||
|
||||
Reference in New Issue
Block a user