From 0b4ec2ca6eb8b48517ef4af21bff7c4172675d2b Mon Sep 17 00:00:00 2001 From: Roe-xin Date: Wed, 24 Dec 2025 10:25:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BF=AE=E6=94=B9=E4=BA=86=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E8=B0=83=E7=94=A8=E7=9A=84=E6=A0=B7=E5=BC=8F=20+=20?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=B7=A5=E5=85=B7=E8=B0=83=E7=94=A8=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E5=A4=AA=E9=95=BF=E5=8F=AF=E4=BB=A5=E6=8A=98=E5=8F=A0?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/messageArea.ts | 179 ++++++++++++++++++++++++++++++++------- 1 file changed, 148 insertions(+), 31 deletions(-) diff --git a/src/views/messageArea.ts b/src/views/messageArea.ts index a70cbcf..342afab 100644 --- a/src/views/messageArea.ts +++ b/src/views/messageArea.ts @@ -349,38 +349,57 @@ export function getMessageAreaStyles(): string { } .segment-tool { - background: var(--vscode-textBlockQuote-background); - border-radius: 6px; - margin: 8px 0; - padding: 10px 14px; + margin: 4px 0; + padding: 4px 0; } .tool-segment-header { display: flex; align-items: center; - gap: 8px; - font-size: 13px; - } - .tool-segment-icon { - font-size: 14px; - } - .tool-segment-name { - font-weight: 500; - color: var(--vscode-foreground); - } - .tool-segment-result { - margin-top: 6px; + gap: 6px; font-size: 12px; color: var(--vscode-descriptionForeground); - padding-left: 22px; + cursor: pointer; } - .segment-tool.tool-success { - border-left: 3px solid var(--vscode-charts-green); + .tool-segment-icon { + font-size: 12px; } - .segment-tool.tool-error { - border-left: 3px solid var(--vscode-charts-red); + .tool-segment-name { + font-weight: normal; } - .segment-tool.tool-running { - border-left: 3px solid var(--vscode-charts-blue); + .tool-segment-result { + display: inline; + font-size: 12px; + color: var(--vscode-descriptionForeground); + margin-left: 6px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + max-width: 500px; + } + .tool-collapse-icon { + width: 12px; + height: 12px; + flex-shrink: 0; + transition: transform 0.2s ease; + cursor: pointer; + } + .tool-collapse-icon svg { + width: 100%; + height: 100%; + display: block; + } + .tool-segment-header.collapsed .tool-collapse-icon { + transform: rotate(0deg); + } + .tool-segment-header:not(.collapsed) .tool-collapse-icon { + transform: rotate(0deg); + } + .tool-segment-content { + overflow: hidden; + transition: max-height 0.3s ease; + } + .tool-segment-content.collapsed { + max-height: 0; } .segment-question { background: var(--vscode-textBlockQuote-background); @@ -689,15 +708,64 @@ export function getMessageAreaScript(): string { } else if (segment.type === 'tool') { const statusIcon = segment.toolStatus === 'success' ? '✅' : segment.toolStatus === 'error' ? '❌' : '🔧'; - const statusClass = 'tool-' + (segment.toolStatus || 'running'); - segmentDiv.className += ' ' + statusClass; + const toolResult = segment.toolResult || ''; + + // 检查工具结果是否过长(超过一行显示不下) + const shouldCollapse = toolResult && toolResult.length > 60; + + // 折叠图标 SVG + const collapseIconSvg = \` + + + + + + + \`; + segmentDiv.innerHTML = \` -
+
+ \${shouldCollapse ? collapseIconSvg : ''} \${statusIcon} \${segment.toolName || '工具'} + \${toolResult && !shouldCollapse ? \`\${toolResult}\` : ''}
- \${segment.toolResult ? \`
\${segment.toolResult}
\` : ''} + \${shouldCollapse ? \`\` : ''} \`; + + // 添加折叠/展开事件监听 + if (shouldCollapse) { + setTimeout(() => { + const header = segmentDiv.querySelector('.tool-segment-header'); + const content = segmentDiv.querySelector('.tool-segment-content'); + const iconCollapsed = segmentDiv.querySelector('.icon-collapsed'); + const iconExpanded = segmentDiv.querySelector('.icon-expanded'); + + if (header && content) { + header.addEventListener('click', function() { + const isCollapsed = header.classList.contains('collapsed'); + + if (isCollapsed) { + // 展开 + header.classList.remove('collapsed'); + content.classList.remove('collapsed'); + content.style.maxHeight = content.scrollHeight + 'px'; + if (iconCollapsed) iconCollapsed.style.display = 'none'; + if (iconExpanded) iconExpanded.style.display = 'block'; + } else { + // 折叠 + header.classList.add('collapsed'); + content.classList.add('collapsed'); + content.style.maxHeight = '0'; + if (iconCollapsed) iconCollapsed.style.display = 'block'; + if (iconExpanded) iconExpanded.style.display = 'none'; + } + }); + } + }, 0); + } } else if (segment.type === 'question') { segmentDiv.className += ' segment-question'; @@ -831,15 +899,64 @@ export function getMessageAreaScript(): string { } else if (segment.type === 'tool') { const statusIcon = segment.toolStatus === 'success' ? '✅' : segment.toolStatus === 'error' ? '❌' : '🔧'; - const statusClass = 'tool-' + (segment.toolStatus || 'running'); - segmentDiv.className += ' ' + statusClass; + const toolResult = segment.toolResult || ''; + + // 检查工具结果是否过长(超过一行显示不下) + const shouldCollapse = toolResult && toolResult.length > 60; + + // 折叠图标 SVG + const collapseIconSvg = \` + + + + + + + \`; + segmentDiv.innerHTML = \` -
+
+ \${shouldCollapse ? collapseIconSvg : ''} \${statusIcon} \${segment.toolName || '工具'} + \${toolResult && !shouldCollapse ? \`\${toolResult}\` : ''}
- \${segment.toolResult ? \`
\${segment.toolResult}
\` : ''} + \${shouldCollapse ? \`\` : ''} \`; + + // 添加折叠/展开事件监听 + if (shouldCollapse) { + setTimeout(() => { + const header = segmentDiv.querySelector('.tool-segment-header'); + const content = segmentDiv.querySelector('.tool-segment-content'); + const iconCollapsed = segmentDiv.querySelector('.icon-collapsed'); + const iconExpanded = segmentDiv.querySelector('.icon-expanded'); + + if (header && content) { + header.addEventListener('click', function() { + const isCollapsed = header.classList.contains('collapsed'); + + if (isCollapsed) { + // 展开 + header.classList.remove('collapsed'); + content.classList.remove('collapsed'); + content.style.maxHeight = content.scrollHeight + 'px'; + if (iconCollapsed) iconCollapsed.style.display = 'none'; + if (iconExpanded) iconExpanded.style.display = 'block'; + } else { + // 折叠 + header.classList.add('collapsed'); + content.classList.add('collapsed'); + content.style.maxHeight = '0'; + if (iconCollapsed) iconCollapsed.style.display = 'block'; + if (iconExpanded) iconExpanded.style.display = 'none'; + } + }); + } + }, 0); + } } else if (segment.type === 'question') { segmentDiv.innerHTML = \`