import { getUserInfoComponentContent, getUserInfoComponentStyles, getUserInfoComponentScript, } from "./userInfoComponent"; import { getMoreOptionsComponentContent, getMoreOptionsComponentStyles, getMoreOptionsComponentScript, } from "./moreOptionsComponent"; import { getSettingsComponentContent, getSettingsComponentStyles, getSettingsComponentScript, } from "./settingsComponent"; import { userAvatarIconSvg, moreIconSvg, setting, } from "../constants/toolIcons"; /** * 获取会话历史栏的 HTML 内容 */ export function getConversationHistoryBarContent(): string { return `
${getSettingsComponentContent()} `; } /** * 获取会话历史栏的 CSS 样式 */ export function getConversationHistoryBarStyles(): string { return ` .conversation-history-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px; background: var(--vscode-tab-activeBackground); border-bottom: 1px solid var(--vscode-panel-border); flex-shrink: 0; min-height: 35px; } .history-dropdown-container { position: relative; flex: 1; } .right-actions { display: flex; align-items: center; gap: 8px; } .user-info-container { position: relative; } .user-avatar-icon-button { width: 30px; height: 30px; padding: 0; background: transparent; color: var(--vscode-foreground); border: none; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; flex-shrink: 0; } .user-avatar-icon-button:hover { background: var(--vscode-toolbar-hoverBackground); transform: scale(1.1); } .user-avatar-icon-button:active { transform: scale(0.95); } .user-avatar-icon-button.active { background: var(--vscode-toolbar-hoverBackground); } .user-avatar-icon-button svg { width: 20px; height: 20px; } ${getUserInfoComponentStyles()} ${getSettingsComponentStyles()} .setting { position: relative; } .setting-btn { width: 30px; height: 30px; padding: 0; background: transparent; color: var(--vscode-foreground); border: none; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; flex-shrink: 0; } .setting-btn:hover { background: var(--vscode-toolbar-hoverBackground); transform: scale(1.1); } .setting-btn:active { transform: scale(0.95); } .more-container { position: relative; } .more-button { width: 30px; height: 30px; padding: 0; background: transparent; color: var(--vscode-foreground); border: none; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; flex-shrink: 0; } .more-button:hover { background: var(--vscode-toolbar-hoverBackground); transform: scale(1.1); } .more-button:active { transform: scale(0.95); } .more-button.active { background: var(--vscode-toolbar-hoverBackground); } ${getMoreOptionsComponentStyles()} .history-dropdown-button { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; background: transparent; color: var(--vscode-foreground); border: none; border-radius: 4px; cursor: pointer; font-size: 14px; transition: all 0.2s ease; } .history-dropdown-button:hover { background: var(--vscode-toolbar-hoverBackground); } .dropdown-label { white-space: nowrap; } .dropdown-icon { width: 12px; height: 12px; transition: transform 0.2s ease; flex-shrink: 0; } .history-dropdown-button.active .dropdown-icon { transform: rotate(180deg); } .history-dropdown-menu { position: absolute; top: calc(100% + 4px); left: 0; min-width: 300px; max-height: 400px; background: var(--vscode-dropdown-background); border: 1px solid var(--vscode-dropdown-border); border-radius: 4px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); max-height: 400px; overflow-y: auto; z-index: 1000; display: none; } .history-dropdown-menu.active { display: block; } .history-list { padding: 4px 0; } .history-item { padding: 10px 16px; cursor: pointer; transition: background 0.2s ease; border-bottom: 1px solid var(--vscode-panel-border); display: flex; align-items: center; justify-content: space-between; gap: 12px; } .history-item:last-child { border-bottom: none; } .history-item:hover { background: var(--vscode-list-hoverBackground); } .history-item-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; } .history-item-time { font-size: 12px; opacity: 0.7; white-space: nowrap; flex-shrink: 0; } .history-empty { padding: 20px; text-align: center; color: var(--vscode-descriptionForeground); font-size: 14px; } .history-load-more { padding: 12px 16px; text-align: center; color: var(--vscode-descriptionForeground); font-size: 12px; border-top: 1px solid var(--vscode-panel-border); } .new-conversation-button { width: 30px; height: 30px; padding: 0; background: transparent; color: var(--vscode-foreground); border: none; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; flex-shrink: 0; } .new-conversation-button:hover { background: #007ACC; transform: scale(1.1); } .new-conversation-button:active { transform: scale(0.95); } .new-conversation-button svg { width: 20px; height: 20px; } /* 滚动条样式 */ .history-dropdown-menu::-webkit-scrollbar { width: 8px; } .history-dropdown-menu::-webkit-scrollbar-track { background: transparent; } .history-dropdown-menu::-webkit-scrollbar-thumb { background: rgba(128, 128, 128, 0.5); border-radius: 4px; } .history-dropdown-menu::-webkit-scrollbar-thumb:hover { background: rgba(128, 128, 128, 0.7); } `; } /** * 获取会话历史栏的 JavaScript 脚本 */ export function getConversationHistoryBarScript(): string { return ` ${getUserInfoComponentScript()} ${getMoreOptionsComponentScript()} ${getSettingsComponentScript()} // 更新用户头像图标按钮显示 function updateUserAvatarIconButton(userInfo) { const userAvatarIconButton = document.getElementById('userAvatarIconButton'); if (userInfo && userInfo.nickname) { // 显示用户头像图标按钮 if (userAvatarIconButton) { userAvatarIconButton.style.display = 'flex'; } // 同时更新用户详情弹窗的数据 if (typeof updateUserInfoDisplay === 'function') { updateUserInfoDisplay(userInfo); } } else { // 隐藏用户头像图标按钮 if (userAvatarIconButton) { userAvatarIconButton.style.display = 'none'; } } } // 会话历史相关变量 let conversationHistory = []; let currentConversationId = null; let currentOffset = 0; let totalHistory = 0; let hasMoreHistory = false; let isLoadingHistory = false; let currentLoadRequestId = 0; // 请求 ID,用于防止并发加载 const HISTORY_PAGE_SIZE = 10; const MAX_HISTORY_ITEMS = 100; // 切换历史记录下拉菜单 function toggleHistoryDropdown() { const menu = document.getElementById('historyDropdownMenu'); const button = document.querySelector('.history-dropdown-button'); if (menu.classList.contains('active')) { menu.classList.remove('active'); button.classList.remove('active'); } else { menu.classList.add('active'); button.classList.add('active'); // 重置并加载会话历史 resetAndLoadHistory(); } } // 重置并加载会话历史 function resetAndLoadHistory() { conversationHistory = []; currentOffset = 0; totalHistory = 0; hasMoreHistory = false; const historyList = document.getElementById('historyList'); if (historyList) { historyList.innerHTML = '