feat(vscode-ide-companion): 新增时间线组件

- 新增 Timeline 组件用于显示会话历史
- 支持展示消息、工具调用等事件
- 提供清晰的时间轴视图

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
yiliang114
2025-11-21 01:53:05 +08:00
parent 088c766c22
commit a33187ed7a
2 changed files with 344 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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<TimelineItemProps> = ({
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 (
<div className={`timeline-item ${type} ${isLast ? 'last' : ''}`}>
{/* 时间线连接线 - 暂时禁用 */}
{/* {!isLast && <div className="timeline-line" />} */}
{/* 状态圆点 */}
<div className={`timeline-dot ${dotColor}`}>
<span className="dot-inner" />
</div>
{/* 内容区域 */}
<div className="timeline-content">
{/* 标签(可选) */}
{itemLabel && <div className="timeline-label">{itemLabel}</div>}
{/* 可折叠内容 */}
{collapsible ? (
<>
<button
className="timeline-toggle"
onClick={() => setExpanded(!expanded)}
aria-expanded={expanded}
>
<span className="timeline-toggle-icon">
{expanded ? '▼' : '▶'}
</span>
<span className="timeline-toggle-text">
{title || (expanded ? 'Hide details' : 'Show details')}
</span>
</button>
{expanded && <div className="timeline-body">{children}</div>}
</>
) : (
<div className="timeline-body">{children}</div>
)}
</div>
</div>
);
};
/**
* Timeline 容器组件
*/
export const Timeline: React.FC<{ children: React.ReactNode }> = ({
children,
}) => <div className="timeline-container">{children}</div>;