From a33187ed7a5cafe128d4c67062d926d48df90c59 Mon Sep 17 00:00:00 2001 From: yiliang114 <1204183885@qq.com> Date: Fri, 21 Nov 2025 01:53:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(vscode-ide-companion):=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=97=B6=E9=97=B4=E7=BA=BF=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 Timeline 组件用于显示会话历史 - 支持展示消息、工具调用等事件 - 提供清晰的时间轴视图 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../src/webview/components/Timeline.css | 218 ++++++++++++++++++ .../src/webview/components/Timeline.tsx | 126 ++++++++++ 2 files changed, 344 insertions(+) create mode 100644 packages/vscode-ide-companion/src/webview/components/Timeline.css create mode 100644 packages/vscode-ide-companion/src/webview/components/Timeline.tsx diff --git a/packages/vscode-ide-companion/src/webview/components/Timeline.css b/packages/vscode-ide-companion/src/webview/components/Timeline.css new file mode 100644 index 00000000..b6f7cd9e --- /dev/null +++ b/packages/vscode-ide-companion/src/webview/components/Timeline.css @@ -0,0 +1,218 @@ +/** + * @license + * Copyright 2025 Qwen Team + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * Timeline.css - 时间线布局样式 + * 统一展示消息、工具调用、输出等 + */ + +.timeline-container { + display: flex; + flex-direction: column; + gap: 0; + padding: 16px 20px; +} + +/* Timeline 项目 */ +.timeline-item { + position: relative; + display: grid; + grid-template-columns: 20px 1fr; + gap: 12px; + padding-bottom: 16px; +} + +.timeline-item.last { + padding-bottom: 0; +} + +/* 时间线连接线 - 暂时禁用 */ +/* +.timeline-line { + position: absolute; + left: 9px; + top: 20px; + bottom: 0; + width: 2px; + background: var(--app-transparent-inner-border); + opacity: 0.3; +} + +.timeline-item.last .timeline-line { + display: none; +} +*/ + +/* 状态圆点 */ +.timeline-dot { + position: relative; + width: 20px; + height: 20px; + display: flex; + align-items: center; + justify-content: center; + flex-shrink: 0; + margin-top: 2px; + z-index: 1; +} + +.dot-inner { + width: 8px; + height: 8px; + border-radius: 50%; + display: block; +} + +/* 不同类型的圆点颜色 */ +.timeline-dot.blue .dot-inner { + background-color: var(--vscode-terminal-ansiBlue, #4fc3f7); +} + +.timeline-dot.gray .dot-inner { + background-color: var(--app-secondary-foreground); + opacity: 0.5; +} + +.timeline-dot.green .dot-inner { + background-color: var(--app-qwen-green, #6BCF7F); +} + +.timeline-dot.purple .dot-inner { + background-color: var(--vscode-terminal-ansiMagenta, #ba68c8); +} + +/* 内容区域 */ +.timeline-content { + flex: 1; + display: flex; + flex-direction: column; + gap: 6px; + min-width: 0; +} + +/* 标签 */ +.timeline-label { + font-size: 11px; + font-weight: 600; + text-transform: uppercase; + letter-spacing: 0.5px; + color: var(--app-secondary-foreground); + opacity: 0.6; +} + +/* 内容主体 */ +.timeline-body { + font-size: 13px; + line-height: 1.6; + color: var(--app-primary-foreground); + word-wrap: break-word; + overflow-wrap: break-word; +} + +/* 折叠/展开按钮 */ +.timeline-toggle { + display: inline-flex; + align-items: center; + gap: 6px; + padding: 4px 8px 4px 4px; + background: transparent; + border: none; + border-radius: 4px; + color: var(--app-secondary-foreground); + font-size: 12px; + cursor: pointer; + transition: background-color 0.15s; + align-self: flex-start; +} + +.timeline-toggle:hover { + background: var(--app-ghost-button-hover-background); +} + +.timeline-toggle-icon { + font-size: 10px; + line-height: 1; + transition: transform 0.15s; +} + +.timeline-toggle-text { + font-weight: 500; +} + +/* 工具输出的特殊样式 */ +.timeline-item.tool-output .timeline-body { + background: var(--app-secondary-background); + border: 1px solid var(--app-transparent-inner-border); + border-radius: 6px; + padding: 12px; + font-family: var(--vscode-editor-font-family, 'Monaco', 'Courier New', monospace); + font-size: 12px; + color: var(--app-secondary-foreground); + max-height: 300px; + overflow-y: auto; +} + +/* 工具调用的特殊样式 */ +.timeline-item.tool-call .timeline-body { + background: var(--app-secondary-background); + border: 1px solid var(--app-transparent-inner-border); + border-radius: 6px; + padding: 12px; +} + +/* 用户消息样式 */ +.timeline-item.user-message .timeline-body { + background: var(--app-qwen-clay-button-orange); + border: 1px solid var(--app-transparent-inner-border); + border-radius: 8px; + padding: 10px 14px; +} + +/* 助手消息样式 */ +.timeline-item.assistant-message .timeline-body { + /* 保持默认样式,不加背景 */ +} + +/* 思考消息样式 */ +.timeline-item.thinking .timeline-body { + color: var(--app-secondary-foreground); + opacity: 0.7; + font-style: italic; +} + +/* 滚动条样式 */ +.timeline-item.tool-output .timeline-body::-webkit-scrollbar { + width: 6px; +} + +.timeline-item.tool-output .timeline-body::-webkit-scrollbar-track { + background: transparent; +} + +.timeline-item.tool-output .timeline-body::-webkit-scrollbar-thumb { + background: rgba(255, 255, 255, 0.2); + border-radius: 3px; +} + +.timeline-item.tool-output .timeline-body::-webkit-scrollbar-thumb:hover { + background: rgba(255, 255, 255, 0.3); +} + +/* 动画 */ +@keyframes timelineFadeIn { + from { + opacity: 0; + transform: translateY(-8px); + } + to { + opacity: 1; + transform: translateY(0); + } +} + +.timeline-item { + animation: timelineFadeIn 0.3s ease-out; +} diff --git a/packages/vscode-ide-companion/src/webview/components/Timeline.tsx b/packages/vscode-ide-companion/src/webview/components/Timeline.tsx new file mode 100644 index 00000000..a38a3e39 --- /dev/null +++ b/packages/vscode-ide-companion/src/webview/components/Timeline.tsx @@ -0,0 +1,126 @@ +/** + * @license + * Copyright 2025 Qwen Team + * SPDX-License-Identifier: Apache-2.0 + */ + +import type React from 'react'; +import { useState } from 'react'; +import './Timeline.css'; + +export type TimelineItemType = + | 'user-message' + | 'assistant-message' + | 'tool-call' + | 'tool-output' + | 'thinking'; + +export interface TimelineItemProps { + type: TimelineItemType; + children: React.ReactNode; + /** 是否可折叠(主要用于工具输出) */ + collapsible?: boolean; + /** 默认是否展开 */ + defaultExpanded?: boolean; + /** 自定义标题(用于折叠时显示) */ + title?: string; + /** 是否是最后一个项目 */ + isLast?: boolean; +} + +/** + * Timeline 项目组件 - 统一展示消息和工具调用 + */ +export const TimelineItem: React.FC = ({ + type, + children, + collapsible = false, + defaultExpanded = true, + title, + isLast = false, +}) => { + const [expanded, setExpanded] = useState(defaultExpanded); + + const getDotColor = (): string => { + switch (type) { + case 'user-message': + return 'blue'; // 用户消息 - 蓝色 + case 'assistant-message': + return 'gray'; // LLM 输出 - 灰色 + case 'tool-call': + return 'green'; // 工具调用 - 绿色 + case 'tool-output': + return 'gray'; // 工具输出 - 灰色 + case 'thinking': + return 'purple'; // 思考 - 紫色 + default: + return 'gray'; + } + }; + + const getItemLabel = (): string | null => { + switch (type) { + case 'user-message': + return 'You'; + case 'assistant-message': + return 'Qwen'; + case 'tool-call': + return 'Tool Call'; + case 'tool-output': + return 'Output'; + case 'thinking': + return 'Thinking'; + default: + return null; + } + }; + + const dotColor = getDotColor(); + const itemLabel = getItemLabel(); + + return ( +
+ {/* 时间线连接线 - 暂时禁用 */} + {/* {!isLast &&
} */} + + {/* 状态圆点 */} +
+ +
+ + {/* 内容区域 */} +
+ {/* 标签(可选) */} + {itemLabel &&
{itemLabel}
} + + {/* 可折叠内容 */} + {collapsible ? ( + <> + + {expanded &&
{children}
} + + ) : ( +
{children}
+ )} +
+
+ ); +}; + +/** + * Timeline 容器组件 + */ +export const Timeline: React.FC<{ children: React.ReactNode }> = ({ + children, +}) =>
{children}
;