8 Commits

13 changed files with 800 additions and 227 deletions

12
LICENSE Normal file
View File

@ -0,0 +1,12 @@
Copyright (c) 2025 IC Coder Team. All rights reserved.
本软件及其相关文档文件(以下简称"软件")的版权归 IC Coder 所有。
未经版权所有者事先书面许可,不得以任何形式或方式(电子、机械、复印、录制或其他方式)
复制、分发、传播、展示、修改或创建本软件的衍生作品。
本软件按"原样"提供,不提供任何明示或暗示的保证,包括但不限于适销性、特定用途适用性
和非侵权性的保证。在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,
无论是在合同诉讼、侵权行为还是其他方面。
如需商业使用或获取许可,请联系:[pyjtkj@pyjtkj.com]

356
PUBLISH.md Normal file
View File

@ -0,0 +1,356 @@
# IC Coder 插件发布流程文档
本文档详细说明如何将 IC Coder 插件发布到 VS Code 插件市场进行测试和正式发布。
## 目录
- [前置准备](#前置准备)
- [账号配置](#账号配置)
- [插件信息完善](#插件信息完善)
- [打包与发布](#打包与发布)
- [版本更新](#版本更新)
- [常见问题](#常见问题)
---
## 前置准备
### 环境要求
- Node.js 和 pnpm 已安装
- VS Code 1.80.0 或更高版本
- 已安装 `@vscode/vsce` 工具(项目已包含)
### 检查清单
在发布前,请确保以下文件和配置已准备就绪:
- [x] `package.json` - 插件配置文件
- [x] `README.md` - 插件说明文档
- [x] `dist/` - 编译后的代码
- [x] `media/` - 图标和资源文件
- [ ] `CHANGELOG.md` - 版本更新日志(建议添加)
- [x] `LICENSE` - 开源许可证(建议添加)
---
## 账号配置
### 1. 创建 Azure DevOps 账号
1. 访问 [Azure DevOps](https://dev.azure.com)
2. 使用 Microsoft 账号注册或登录
3. 创建一个组织(如果还没有)
### 2. 生成 Personal Access Token (PAT)
这是发布插件的关键凭证,请妥善保管。
**步骤:**
1. 登录 Azure DevOps
2. 点击右上角用户图标 → **User settings****Personal access tokens**
3. 点击 **New Token** 按钮
4. 配置 Token 信息:
- **Name**: `vscode-publisher`(或其他易识别的名称)
- **Organization**: 选择 **All accessible organizations**
- **Expiration**: 建议选择较长期限(如 90 天或自定义)
- **Scopes**: 选择 **Custom defined**
- 展开 **Marketplace**
- 勾选 **Manage**(包含发布和管理权限)
5. 点击 **Create** 生成 Token
6. **重要**: 立即复制并保存 Token页面关闭后将无法再次查看
**Token 示例格式:**
```
CO03l8nmFBBTNPDg7lN9a9fYwDdgsRIDVDwTrx6Esggi6HnzmrMTJQQJ99BLACAAAAAAAAAAAAAGAZDOVVyT
```
### 3. 创建发布者账号
发布者账号是你在 VS Code 市场的身份标识。
**步骤:**
1. 访问 [VS Code Marketplace 管理页面](https://marketplace.visualstudio.com/manage)
2. 使用 Azure DevOps 账号登录
3. 点击 **Create publisher** 按钮
4. 填写发布者信息:
- **ID**: `ICCoder`(必须与 package.json 中的 `publisher` 字段一致)
- **Name**: `IC Coder`(显示名称,可自定义)
- **Email**: 你的联系邮箱
5. 点击 **Create** 完成创建
**注意事项:**
- Publisher ID 一旦创建无法修改
- Publisher ID 必须全局唯一
- 建议使用有意义且专业的 ID
---
## 插件信息完善
### 1. 完善 package.json
建议在 `package.json` 中添加以下字段以提升插件质量:
```json
{
"repository": {
"type": "git",
"url": "https://github.com/your-org/ic-coder.git"
},
"homepage": "https://github.com/your-org/ic-coder#readme",
"bugs": {
"url": "https://github.com/your-org/ic-coder/issues"
},
"license": "MIT"
}
```
### 2. 创建 CHANGELOG.md
版本更新日志帮助用户了解每个版本的变化。
**示例内容:**
```markdown
# 更新日志
## [0.0.2] - 2025-12-29
### 新增
- 添加发送和暂停按钮功能
- 添加一键优化按钮组件
- 添加 Plan 开关组件
- 添加模式选择器组件
- 添加上下文压缩功能
### 改进
- 优化用户界面交互体验
## [0.0.1] - 2025-12-XX
### 新增
- 初始版本发布
- Verilog 代码智能生成
- 集成 iverilog 仿真工具
- VCD 波形文件查看器
```
### 3. 创建 LICENSE 文件
如果使用 MIT 许可证,创建 `LICENSE` 文件:
```
MIT License
Copyright (c) 2025 IC Coder Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction...
```
### 4. 优化 README.md
确保 README 包含:
- 清晰的功能介绍
- 使用截图或 GIF 演示
- 详细的使用说明
- 系统要求
- 常见问题解答
---
## 打包与发布
### 方式一:命令行发布(推荐)
这是最便捷的发布方式,适合频繁更新。
**步骤:**
1. **登录发布者账号**
```bash
pnpm vsce login ic-coder-team
```
系统会提示输入 Personal Access Token粘贴之前创建的 PAT。
2. **打包插件**
```bash
# 执行生产环境构建
pnpm run package
# 打包成 .vsix 文件
pnpm vsce package
```
这会生成 `ic-coder-plugin-0.0.2.vsix` 文件。
3. **发布到市场**
```bash
pnpm vsce publish
```
发布成功后会显示插件的市场链接。
**一键发布(跳过打包步骤):**
```bash
# 直接发布当前版本
pnpm vsce publish
```
### 方式二:手动上传
适合首次发布或网络环境受限的情况。
**步骤:**
1. 本地打包插件:
```bash
pnpm run package
pnpm vsce package[pnpm vsce package --no-dependencies]
```
2. 访问 [发布者管理页面](https://marketplace.visualstudio.com/manage/publishers/ic-coder-team)
3. 点击 **New extension****Visual Studio Code**
4. 上传 `ic-coder-plugin-0.0.2.vsix` 文件
5. 填写插件信息(如果需要)并提交
6. 等待审核通过
---
## 版本更新
### 自动更新版本号
使用 `vsce publish` 命令可以自动更新版本号并发布:
```bash
# 补丁版本更新0.0.2 → 0.0.3
pnpm vsce publish patch
# 次版本更新0.0.2 → 0.1.0
pnpm vsce publish minor
# 主版本更新0.0.2 → 1.0.0
pnpm vsce publish major
```
### 手动指定版本
```bash
# 发布指定版本
pnpm vsce publish 0.0.3
```
### 更新流程建议
1. 修改代码并测试
2. 更新 `CHANGELOG.md` 记录变更
3. 提交代码到 Git
4. 执行发布命令
5. 验证市场上的插件是否正常
---
## 常见问题
### 1. 发布失败Authentication failed
**原因:** PAT Token 无效或过期
**解决方案:**
- 重新生成 PAT Token
- 重新登录:`pnpm vsce login ic-coder-team`
### 2. 发布失败Publisher not found
**原因:** Publisher ID 不存在或不匹配
**解决方案:**
- 检查 `package.json` 中的 `publisher` 字段
- 确认已在市场创建对应的 Publisher
### 3. 打包失败Missing files
**原因:** 必需文件缺失
**解决方案:**
- 确保 `dist/` 目录存在且包含编译后的代码
- 运行 `pnpm run package` 重新构建
### 4. 插件审核被拒
**常见原因:**
- 插件名称或描述违反市场规则
- 图标不符合要求(建议 128x128 PNG
- README 内容不完整
**解决方案:**
- 查看审核反馈邮件
- 修改相关内容后重新发布
### 5. 如何撤回已发布的版本?
```bash
# 取消发布指定版本
pnpm vsce unpublish ic-coder-team.ic-coder-plugin@0.0.2
# 取消发布整个插件(慎用)
pnpm vsce unpublish ic-coder-team.ic-coder-plugin
```
### 6. 如何本地测试 .vsix 文件?
```bash
# 在 VS Code 中安装本地 .vsix 文件
code --install-extension ic-coder-plugin-0.0.2.vsix
```
或者在 VS Code 中:
1. 打开扩展面板
2. 点击 `...` 菜单
3. 选择 **Install from VSIX...**
4. 选择 `.vsix` 文件
---
## 发布检查清单
在正式发布前,请确认以下事项:
- [ ] 代码已充分测试,无明显 Bug
- [ ] `package.json` 版本号已更新
- [ ] `CHANGELOG.md` 已记录本次更新内容
- [ ] README.md 内容完整且准确
- [ ] 图标和资源文件正常显示
- [ ] 已在本地安装测试 .vsix 文件
- [ ] 已创建 Azure DevOps PAT Token
- [ ] 已创建 VS Code Marketplace Publisher
- [ ] 已执行 `pnpm run package` 构建生产版本
---
## 参考资源
- [VS Code 插件发布官方文档](https://code.visualstudio.com/api/working-with-extensions/publishing-extension)
- [vsce 工具文档](https://github.com/microsoft/vscode-vsce)
- [Azure DevOps 文档](https://docs.microsoft.com/en-us/azure/devops/)
- [VS Code 插件市场](https://marketplace.visualstudio.com/)
---
**文档维护:** IC Coder Team
**最后更新:** 2025-12-29

View File

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 160 KiB

View File

Before

Width:  |  Height:  |  Size: 889 KiB

After

Width:  |  Height:  |  Size: 889 KiB

View File

Before

Width:  |  Height:  |  Size: 681 B

After

Width:  |  Height:  |  Size: 681 B

View File

@ -1,13 +1,13 @@
{ {
"name": "ic-coder-plugin", "name": "iccoder",
"displayName": "IC Coder plugin", "displayName": "IC Coder",
"description": "Agentic Verilog Coding Platform for Real-World FPGAs", "description": "Agentic Verilog Coding Platform for Real-World FPGAs",
"version": "0.0.2", "version": "0.0.2",
"publisher": "ic-coder-team", "publisher": "ICCoder",
"engines": { "engines": {
"vscode": "^1.80.0" "vscode": "^1.80.0"
}, },
"icon": "media/图案(方底).png", "icon": "media/icon.png",
"categories": [ "categories": [
"Other" "Other"
], ],
@ -19,6 +19,7 @@
"eda", "eda",
"assistant" "assistant"
], ],
"license": "SEE LICENSE IN LICENSE",
"activationEvents": [ "activationEvents": [
"onCommand:ic-coder.openPanel", "onCommand:ic-coder.openPanel",
"onView:ic-coder-sidebar", "onView:ic-coder-sidebar",
@ -43,36 +44,6 @@
"command": "ic-coder.openVCDViewer", "command": "ic-coder.openVCDViewer",
"title": "打开 VCD 波形查看器", "title": "打开 VCD 波形查看器",
"category": "IC Coder" "category": "IC Coder"
},
{
"command": "ic-coder.viewHistory",
"title": "查看会话历史",
"category": "IC Coder"
},
{
"command": "ic-coder.newSession",
"title": "新建会话",
"category": "IC Coder"
},
{
"command": "ic-coder.exportSession",
"title": "导出当前会话",
"category": "IC Coder"
},
{
"command": "ic-coder.deleteSession",
"title": "删除会话",
"category": "IC Coder"
},
{
"command": "ic-coder.clearHistory",
"title": "清空会话历史",
"category": "IC Coder"
},
{
"command": "ic-coder.searchSession",
"title": "搜索会话",
"category": "IC Coder"
} }
], ],
"viewsContainers": { "viewsContainers": {
@ -80,7 +51,7 @@
{ {
"id": "ic-coder-sidebar", "id": "ic-coder-sidebar",
"title": "IC Coder", "title": "IC Coder",
"icon": "media/侧边栏logo.png" "icon": "media/sidebar-icon.png"
} }
] ]
}, },

View File

@ -50,3 +50,23 @@ export const SearchCode = `
</svg> </svg>
</span> </span>
`; `;
/**
* 发送按钮图标 SVG向上箭头
*/
export const sendIconSvg = `
<svg class="send-icon" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
<path d="M507.904 882.688c-18.432 0-33.28-14.848-33.28-33.28v-655.36c0-18.432 14.848-33.28 33.28-33.28s33.28 14.848 33.28 33.28v654.848c0 18.432-14.848 33.792-33.28 33.792z" fill="currentColor"></path>
<path d="M787.968 502.784c-8.704 0-16.896-3.072-23.552-9.728L507.904 236.544 251.392 493.056c-12.8 12.8-34.304 12.8-47.104 0-12.8-12.8-12.8-34.304 0-47.104l280.064-280.064c6.144-6.144 14.848-9.728 23.552-9.728s17.408 3.584 23.552 9.728l280.064 280.064c12.8 12.8 12.8 34.304 0 47.104-6.656 6.656-15.36 9.728-23.552 9.728z" fill="currentColor"></path>
</svg>
`;
/**
* 暂停按钮图标 SVG圆形边框内的方块
*/
export const stopIconSvg = `
<svg class="stop-icon" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
<path d="M512 936a424.1 424.1 0 0 1-165.05-814.66 424.1 424.1 0 0 1 330.1 781.33A421.38 421.38 0 0 1 512 936z m0-768c-189.68 0-344 154.32-344 344s154.32 344 344 344 344-154.32 344-344-154.32-344-344-344z" fill="currentColor"></path>
<path d="M349.75 349.75m57.15 0l210.2 0q57.15 0 57.15 57.15l0 210.2q0 57.15-57.15 57.15l-210.2 0q-57.15 0-57.15-57.15l0-210.2q0-57.15 57.15-57.15Z" fill="currentColor"></path>
</svg>
`;

View File

@ -34,19 +34,21 @@ export async function showICHelperPanel(
); );
// 为面板生成唯一ID // 为面板生成唯一ID
const panelId = `panel_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; const panelId = `panel_${Date.now()}_${Math.random()
.toString(36)
.substr(2, 9)}`;
(panel as any).__uniqueId = panelId; (panel as any).__uniqueId = panelId;
// 设置标签页图标 // 设置标签页图标
panel.iconPath = vscode.Uri.joinPath( panel.iconPath = vscode.Uri.joinPath(
context.extensionUri, context.extensionUri,
"media", "media",
"图案(方底).png" "icon.png"
); );
// 获取页面内图标URI // 获取页面内图标URI
const iconUri = panel.webview.asWebviewUri( const iconUri = panel.webview.asWebviewUri(
vscode.Uri.joinPath(context.extensionUri, "media", "图案(方底).png") vscode.Uri.joinPath(context.extensionUri, "media", "icon.png")
); );
// 设置HTML内容 // 设置HTML内容
@ -63,11 +65,19 @@ export async function showICHelperPanel(
// 仅在用户发送消息时,确保面板有任务上下文 // 仅在用户发送消息时,确保面板有任务上下文
// 如果没有,则创建新任务(仅在首次发送消息时) // 如果没有,则创建新任务(仅在首次发送消息时)
if (!historyManager.getPanelTask(panelId)) { if (!historyManager.getPanelTask(panelId)) {
const workspacePath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath; const workspacePath =
vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
if (workspacePath) { if (workspacePath) {
try { try {
const taskMeta = await historyManager.createTask(workspacePath, "新对话"); const taskMeta = await historyManager.createTask(
historyManager.setPanelTask(panelId, taskMeta.taskId, workspacePath); workspacePath,
"新对话"
);
historyManager.setPanelTask(
panelId,
taskMeta.taskId,
workspacePath
);
} catch (error) { } catch (error) {
console.error("创建任务失败:", error); console.error("创建任务失败:", error);
} }
@ -123,12 +133,20 @@ export async function showICHelperPanel(
break; break;
case "loadConversationHistory": case "loadConversationHistory":
// 加载会话历史(支持分页) // 加载会话历史(支持分页)
loadConversationHistory(panel, message.offset || 0, message.limit || 10); loadConversationHistory(
panel,
message.offset || 0,
message.limit || 10
);
break; break;
case "selectConversation": case "selectConversation":
// 选择会话 // 选择会话
if (message.conversationId) { if (message.conversationId) {
selectConversation(panel, message.conversationId, context.extensionPath); selectConversation(
panel,
message.conversationId,
context.extensionPath
);
} }
break; break;
// 新增:处理用户回答 // 新增:处理用户回答
@ -407,10 +425,15 @@ async function selectConversation(
} }
// 加载任务会话 // 加载任务会话
const taskSession = await historyManager.loadTaskSession(workspacePath, taskId); const taskSession = await historyManager.loadTaskSession(
workspacePath,
taskId
);
if (!taskSession) { if (!taskSession) {
vscode.window.showErrorMessage(`加载任务 ${taskId} 失败: 任务不存在或数据损坏`); vscode.window.showErrorMessage(
`加载任务 ${taskId} 失败: 任务不存在或数据损坏`
);
return; return;
} }
@ -427,7 +450,7 @@ async function selectConversation(
// 清空当前聊天界面 // 清空当前聊天界面
panel.webview.postMessage({ panel.webview.postMessage({
command: "clearChat" command: "clearChat",
}); });
// 将会话历史消息转换为 segments 格式并发送到前端显示 // 将会话历史消息转换为 segments 格式并发送到前端显示
@ -442,17 +465,17 @@ async function selectConversation(
if (segments.length > 0) { if (segments.length > 0) {
panel.webview.postMessage({ panel.webview.postMessage({
command: "receiveSegments", command: "receiveSegments",
segments: [...segments] segments: [...segments],
}); });
segments.length = 0; segments.length = 0;
} }
// 发送用户消息 // 发送用户消息
const textContent = message.contents?.find(c => c.type === 'TEXT'); const textContent = message.contents?.find((c) => c.type === "TEXT");
if (textContent && 'text' in textContent) { if (textContent && "text" in textContent) {
panel.webview.postMessage({ panel.webview.postMessage({
command: "addUserMessage", command: "addUserMessage",
text: textContent.text text: textContent.text,
}); });
} }
i++; i++;
@ -461,7 +484,7 @@ async function selectConversation(
if (message.segments && message.segments.length > 0) { if (message.segments && message.segments.length > 0) {
panel.webview.postMessage({ panel.webview.postMessage({
command: "receiveSegments", command: "receiveSegments",
segments: message.segments segments: message.segments,
}); });
i++; i++;
} else { } else {
@ -469,30 +492,35 @@ async function selectConversation(
// 收集连续的 AI 消息、工具调用和工具结果 // 收集连续的 AI 消息、工具调用和工具结果
if (message.text) { if (message.text) {
segments.push({ segments.push({
type: 'text', type: "text",
content: message.text content: message.text,
}); });
} }
// 检查是否有工具调用 // 检查是否有工具调用
if (message.toolExecutionRequests && message.toolExecutionRequests.length > 0) { if (
message.toolExecutionRequests &&
message.toolExecutionRequests.length > 0
) {
for (const toolReq of message.toolExecutionRequests) { for (const toolReq of message.toolExecutionRequests) {
// 查找对应的工具执行结果 // 查找对应的工具执行结果
let toolResult = ''; let toolResult = "";
if (i + 1 < taskSession.messages.length) { if (i + 1 < taskSession.messages.length) {
const nextMsg = taskSession.messages[i + 1]; const nextMsg = taskSession.messages[i + 1];
if (nextMsg.type === MessageType.TOOL_EXECUTION_RESULT && if (
nextMsg.id === toolReq.id) { nextMsg.type === MessageType.TOOL_EXECUTION_RESULT &&
nextMsg.id === toolReq.id
) {
toolResult = nextMsg.text; toolResult = nextMsg.text;
i++; // 跳过工具结果消息 i++; // 跳过工具结果消息
} }
} }
segments.push({ segments.push({
type: 'tool', type: "tool",
toolName: toolReq.name, toolName: toolReq.name,
askId: toolReq.id, askId: toolReq.id,
toolResult: toolResult toolResult: toolResult,
}); });
} }
} }
@ -511,26 +539,31 @@ async function selectConversation(
} }
if (nextMsg.text) { if (nextMsg.text) {
segments.push({ segments.push({
type: 'text', type: "text",
content: nextMsg.text content: nextMsg.text,
}); });
} }
if (nextMsg.toolExecutionRequests && nextMsg.toolExecutionRequests.length > 0) { if (
nextMsg.toolExecutionRequests &&
nextMsg.toolExecutionRequests.length > 0
) {
for (const toolReq of nextMsg.toolExecutionRequests) { for (const toolReq of nextMsg.toolExecutionRequests) {
let toolResult = ''; let toolResult = "";
if (i + 1 < taskSession.messages.length) { if (i + 1 < taskSession.messages.length) {
const resultMsg = taskSession.messages[i + 1]; const resultMsg = taskSession.messages[i + 1];
if (resultMsg.type === MessageType.TOOL_EXECUTION_RESULT && if (
resultMsg.id === toolReq.id) { resultMsg.type === MessageType.TOOL_EXECUTION_RESULT &&
resultMsg.id === toolReq.id
) {
toolResult = resultMsg.text; toolResult = resultMsg.text;
i++; // 跳过工具结果消息 i++; // 跳过工具结果消息
} }
} }
segments.push({ segments.push({
type: 'tool', type: "tool",
toolName: toolReq.name, toolName: toolReq.name,
askId: toolReq.id, askId: toolReq.id,
toolResult: toolResult toolResult: toolResult,
}); });
} }
} }
@ -552,11 +585,13 @@ async function selectConversation(
if (segments.length > 0) { if (segments.length > 0) {
panel.webview.postMessage({ panel.webview.postMessage({
command: "receiveSegments", command: "receiveSegments",
segments: segments segments: segments,
}); });
} }
vscode.window.showInformationMessage(`已加载会话: ${taskSession.meta.taskName}`); vscode.window.showInformationMessage(
`已加载会话: ${taskSession.meta.taskName}`
);
} catch (error) { } catch (error) {
console.error("选择会话失败:", error); console.error("选择会话失败:", error);
vscode.window.showErrorMessage(`加载会话失败: ${error}`); vscode.window.showErrorMessage(`加载会话失败: ${error}`);

View File

@ -32,12 +32,12 @@ export function showICHelperPanel(context: vscode.ExtensionContext) {
panel.iconPath = vscode.Uri.joinPath( panel.iconPath = vscode.Uri.joinPath(
context.extensionUri, context.extensionUri,
"media", "media",
"图案(方底).png" "icon.png"
); );
// 获取页面内图标URI // 获取页面内图标URI
const iconUri = panel.webview.asWebviewUri( const iconUri = panel.webview.asWebviewUri(
vscode.Uri.joinPath(context.extensionUri, "media", "图案(方底).png") vscode.Uri.joinPath(context.extensionUri, "media", "icon.png")
); );
// 设置HTML内容 // 设置HTML内容
panel.webview.html = getWebviewContent(iconUri.toString()); panel.webview.html = getWebviewContent(iconUri.toString());
@ -59,7 +59,12 @@ export function showICHelperPanel(context: vscode.ExtensionContext) {
handleRenameFile(panel, message.oldPath, message.newPath); handleRenameFile(panel, message.oldPath, message.newPath);
break; break;
case "replaceInFile": case "replaceInFile":
handleReplaceInFile(panel, message.filePath, message.searchText, message.replaceText); handleReplaceInFile(
panel,
message.filePath,
message.searchText,
message.replaceText
);
break; break;
case "insertCode": case "insertCode":
insertCodeToEditor(message.code); insertCodeToEditor(message.code);
@ -77,7 +82,11 @@ export function showICHelperPanel(context: vscode.ExtensionContext) {
break; break;
// 新增:处理用户回答 // 新增:处理用户回答
case "submitAnswer": case "submitAnswer":
handleUserAnswer(message.askId, message.selected, message.customInput); handleUserAnswer(
message.askId,
message.selected,
message.customInput
);
break; break;
// 新增:中止对话 // 新增:中止对话
case "abortDialog": case "abortDialog":
@ -114,7 +123,7 @@ export class ICViewProvider implements vscode.WebviewViewProvider {
private getWebviewContent(webview: vscode.Webview): string { private getWebviewContent(webview: vscode.Webview): string {
const logoUri = webview.asWebviewUri( const logoUri = webview.asWebviewUri(
vscode.Uri.joinPath(this.extensionUri, "media", "ICCoder主页标志.png") vscode.Uri.joinPath(this.extensionUri, "media", "icon.png")
); );
return ` return `

View File

@ -19,6 +19,20 @@ import {
getContextCompressStyles, getContextCompressStyles,
getContextCompressScript getContextCompressScript
} from "./contextCompress"; } from "./contextCompress";
import {
getPlanToggleContent,
getPlanToggleStyles,
getPlanToggleScript
} from "./planToggle";
import {
getOptimizeButtonContent,
getOptimizeButtonStyles,
getOptimizeButtonScript
} from "./optimizeButton";
import {
sendIconSvg,
stopIconSvg
} from "../constants/toolIcons";
/** /**
* 获取输入区域的 HTML 内容 * 获取输入区域的 HTML 内容
@ -31,16 +45,7 @@ export function getInputAreaContent(): string {
<!-- 顶部工具栏 --> <!-- 顶部工具栏 -->
<div class="input-top-toolbar"> <div class="input-top-toolbar">
${getContextButtonContent()} ${getContextButtonContent()}
${getPlanToggleContent()}
<!-- Plan 开关 -->
<div class="tooltip">
<label class="plan-toggle">
<input type="checkbox" id="planToggle" onchange="handlePlanToggle()">
<span class="plan-toggle-slider"></span>
<span class="plan-toggle-label">Plan</span>
</label>
<span class="tooltiptext" id="planTooltip">启用 Plan 模式</span>
</div>
</div> </div>
<textarea <textarea
id="messageInput" id="messageInput"
@ -54,16 +59,11 @@ export function getInputAreaContent(): string {
</div> </div>
<div class="input-actions"> <div class="input-actions">
${getContextCompressContent()} ${getContextCompressContent()}
${getOptimizeButtonContent()}
<!-- 一键优化按钮 --> <button id="sendButton" onclick="handleSendOrStop()">
<div class="tooltip"> ${sendIconSvg}
<button id="optimizeButton" class="optimize-button" onclick="handleOptimize()"> <span style="display: none;">${stopIconSvg}</span>
<svg t="1765867478136" id="optimizeIcon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2314"><path d="M490.048929 399.773864c7.042381-21.120144 36.85976-21.120144 43.902142 0l41.273372 123.957105A184.967743 184.967743 0 0 0 692.274156 640.713687l123.890111 41.273373c21.119144 7.042381 21.119144 36.85976 0 43.902141L692.207161 767.162574A184.967743 184.967743 0 0 0 575.224443 884.212286l-41.273372 123.890111A23.09997 23.09997 0 0 1 512 1024c-9.983123 0-18.838344-6.409437-21.951071-15.897603L448.775557 884.145292A184.946745 184.946745 0 0 0 331.792839 767.162574L207.836733 725.889201A23.09997 23.09997 0 0 1 191.93813 703.93813c0-9.983123 6.409437-18.838344 15.897603-21.95107l123.957106-41.273373A184.946745 184.946745 0 0 0 448.775557 523.730969zM242.840657 73.466543A13.888779 13.888779 0 0 1 256.022498 63.94338c5.987474 0 11.299007 3.839663 13.182841 9.523163l24.767824 74.360464a111.070238 111.070238 0 0 0 70.19983 70.20083l74.360464 24.767824A13.888779 13.888779 0 0 1 448.05662 255.977502c0 5.987474-3.839663 11.299007-9.523163 13.182841l-74.360464 24.767823a110.947249 110.947249 0 0 0-70.20083 70.199831l-24.767824 74.360464A13.888779 13.888779 0 0 1 256.022498 448.011624a13.888779 13.888779 0 0 1-13.182841-9.523163l-24.767823-74.360464a110.947249 110.947249 0 0 0-70.199831-70.20083l-74.360464-24.767824A13.888779 13.888779 0 0 1 63.988376 255.977502c0-5.987474 3.839663-11.299007 9.523163-13.182841l74.360464-24.767824a110.947249 110.947249 0 0 0 70.20083-70.19983zM695.213897 6.335443a9.283184 9.283184 0 0 1 17.538459 0L729.260905 55.86509a73.889506 73.889506 0 0 0 46.843883 46.843883l49.530646 16.509549a9.283184 9.283184 0 0 1 0 17.538458L776.106787 153.266529a73.9585 73.9585 0 0 0-46.843882 46.843883l-16.509549 49.530647a9.283184 9.283184 0 0 1-17.538459 0L678.705348 200.112412a73.9585 73.9585 0 0 0-46.843883-46.843883l-49.468652-16.509549a9.283184 9.283184 0 0 1 0-17.538458l49.535646-16.509549a73.897505 73.897505 0 0 0 46.842883-46.843883L695.213897 6.397438z m0 0" p-id="2315" fill="#409eff"></path></svg> </button>
</button>
<span class="tooltiptext" id="optimizeTooltip">一键优化</span>
</div>
<button onclick="sendMessage()">发送</button>
</div> </div>
</div> </div>
</div> </div>
@ -81,6 +81,8 @@ export function getInputAreaStyles(): string {
${getModelSelectorStyles()} ${getModelSelectorStyles()}
${getContextButtonStyles()} ${getContextButtonStyles()}
${getContextCompressStyles()} ${getContextCompressStyles()}
${getPlanToggleStyles()}
${getOptimizeButtonStyles()}
.input-area { .input-area {
border-top: 1px solid var(--vscode-panel-border); border-top: 1px solid var(--vscode-panel-border);
padding-top: 15px; padding-top: 15px;
@ -118,49 +120,6 @@ export function getInputAreaStyles(): string {
margin-bottom: 8px; margin-bottom: 8px;
gap: 12px; gap: 12px;
} }
.plan-toggle {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
user-select: none;
}
.plan-toggle input[type="checkbox"] {
display: none;
}
.plan-toggle-slider {
position: relative;
width: 36px;
height: 20px;
background: var(--vscode-input-background);
border: 1px solid var(--vscode-input-border);
border-radius: 10px;
transition: all 0.3s ease;
}
.plan-toggle-slider::before {
content: "";
position: absolute;
width: 14px;
height: 14px;
left: 2px;
top: 2px;
background: var(--vscode-foreground);
border-radius: 50%;
transition: all 0.3s ease;
}
.plan-toggle input[type="checkbox"]:checked + .plan-toggle-slider {
background: #409eff;
border-color: #409eff;
}
.plan-toggle input[type="checkbox"]:checked + .plan-toggle-slider::before {
transform: translateX(16px);
background: white;
}
.plan-toggle-label {
font-size: 13px;
font-weight: 500;
color: var(--vscode-foreground);
}
.input-bottom-row { .input-bottom-row {
display: flex; display: flex;
align-items: center; align-items: center;
@ -269,30 +228,30 @@ export function getInputAreaStyles(): string {
border: none; border: none;
border-radius: 4px; border-radius: 4px;
cursor: pointer; cursor: pointer;
} transition: background 0.2s ease;
.optimize-button {
padding: 8px;
background: transparent;
color: var(--vscode-foreground);
border: none;
cursor: pointer;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
transition: opacity 0.2s ease;
width: 32px;
height: 32px;
} }
.optimize-button:hover { button:hover {
opacity: 0.7; background: var(--vscode-button-hoverBackground);
} }
.optimize-button svg { /* 发送按钮状态样式 */
width: 16px; #sendButton {
height: 16px; position: relative;
min-width: 32px;
padding: 6px 8px;
} }
.optimize-button-wrapper { #sendButton svg {
display: flex; width: 14px;
align-items: flex-end; height: 14px;
display: block;
}
#sendButton.sending {
background: var(--vscode-button-background);
}
#sendButton.sending:hover {
background: var(--vscode-button-hoverBackground);
} }
`; `;
} }
@ -306,6 +265,11 @@ export function getInputAreaScript(): string {
${getModelSelectorScript()} ${getModelSelectorScript()}
${getContextButtonScript()} ${getContextButtonScript()}
${getContextCompressScript()} ${getContextCompressScript()}
${getPlanToggleScript()}
${getOptimizeButtonScript()}
// 对话状态管理
let isConversationActive = false;
// 自动调整 textarea 高度 // 自动调整 textarea 高度
function autoResizeTextarea() { function autoResizeTextarea() {
@ -326,6 +290,38 @@ export function getInputAreaScript(): string {
messageInput.focus(); messageInput.focus();
} }
// 切换发送按钮状态
function setSendButtonState(isSending) {
const sendButton = document.getElementById('sendButton');
const children = sendButton.children;
const sendIconContainer = children[0]; // 第一个子元素是发送图标的 SVG
const stopIconContainer = children[1]; // 第二个子元素是包含暂停图标的 span
if (isSending) {
sendButton.classList.add('sending');
sendIconContainer.style.display = 'none';
stopIconContainer.style.display = 'block';
isConversationActive = true;
} else {
sendButton.classList.remove('sending');
sendIconContainer.style.display = 'block';
stopIconContainer.style.display = 'none';
isConversationActive = false;
}
}
// 处理发送或停止
function handleSendOrStop() {
if (isConversationActive) {
// 当前正在对话,执行停止操作
vscode.postMessage({ command: 'abortDialog' });
setSendButtonState(false);
} else {
// 当前未在对话,执行发送操作
sendMessage();
}
}
function sendMessage() { function sendMessage() {
const text = messageInput.value.trim(); const text = messageInput.value.trim();
if (!text) return; if (!text) return;
@ -334,6 +330,10 @@ export function getInputAreaScript(): string {
const model = getCurrentModel(); // 从模型选择器组件获取当前模型 const model = getCurrentModel(); // 从模型选择器组件获取当前模型
addMessage(text, 'user'); addMessage(text, 'user');
// 切换按钮为暂停状态
setSendButtonState(true);
vscode.postMessage({ command: 'sendMessage', text: text, mode: mode, model: model }); vscode.postMessage({ command: 'sendMessage', text: text, mode: mode, model: model });
messageInput.value = ''; messageInput.value = '';
autoResizeTextarea(); // 重置输入框高度 autoResizeTextarea(); // 重置输入框高度
@ -342,77 +342,5 @@ export function getInputAreaScript(): string {
// 重置优化状态 // 重置优化状态
resetOptimizeButton(); resetOptimizeButton();
} }
// Plan 开关处理函数
function handlePlanToggle() {
const planToggle = document.getElementById('planToggle');
const planTooltip = document.getElementById('planTooltip');
if (planToggle && planTooltip) {
if (planToggle.checked) {
// 开启 Plan 模式
planTooltip.textContent = '关闭 Plan 模式';
} else {
// 关闭 Plan 模式
planTooltip.textContent = '启用 Plan 模式';
}
}
}
let isOptimized = false; // 标记是否已优化
let originalText = ''; // 保存原始文本用于撤回
function handleOptimize() {
if (isOptimized) {
// 撤回操作
messageInput.value = originalText;
resetOptimizeButton();
} else {
// 优化操作
originalText = messageInput.value; // 保存原始文本
// 使用死数据替换输入框内容
const optimizedTexts = [
'请帮我优化这段代码,提高性能和可读性',
'请分析这个问题并给出最佳解决方案',
'请帮我重构这段代码,使其更加简洁高效',
'请检查代码中的潜在问题并提供改进建议'
];
const randomText = optimizedTexts[Math.floor(Math.random() * optimizedTexts.length)];
messageInput.value = randomText;
// 切换到撤回状态
isOptimized = true;
updateOptimizeButton();
}
messageInput.focus();
autoResizeTextarea();
}
function updateOptimizeButton() {
const optimizeIcon = document.getElementById('optimizeIcon');
const optimizeTooltip = document.getElementById('optimizeTooltip');
if (optimizeIcon && optimizeTooltip) {
// 切换为撤回图标
optimizeIcon.innerHTML = '<path d="M581.056 288.32H232.96l108.352-102.208c15.552-15.744 19.456-31.104 4.16-46.208-16.064-15.872-32.576-15.808-48.64 0l-145.92 144.768c-8.768 8.832-23.488 20.608-22.08 32.448l0.64 4.8-0.64 4.864c-1.344 11.776 6.4 18.24 14.848 26.816l147.648 145.216c16.064 15.808 38.08 20.992 54.144 5.12 15.296-15.104 3.84-38.208-11.328-53.504L233.152 353.6 581.056 352c126.464 0 250.944 111.488 250.944 236.16C832 712.832 707.52 832 581.056 832H246.4c-22.592 0-29.696 9.6-29.696 32.256s7.04 31.744 29.696 31.744H581.12C755.136 896 896 757.696 896 588.16c0-169.408-140.8-299.84-314.944-299.84z" fill="currentColor"/><path d="M323.392 192a32 32 0 1 1 0-64 32 32 0 0 1 0 64zM320.192 514.048a32 32 0 1 1 0-64 32 32 0 0 1 0 64zM237.824 896a32 32 0 1 1 0-64 32 32 0 0 1 0 64z" fill="currentColor"/>';
optimizeTooltip.textContent = '撤回';
}
}
function resetOptimizeButton() {
const optimizeIcon = document.getElementById('optimizeIcon');
const optimizeTooltip = document.getElementById('optimizeTooltip');
if (optimizeIcon && optimizeTooltip) {
// 切换回优化图标(星星图标)
optimizeIcon.innerHTML = '<path d="M490.048929 399.773864c7.042381-21.120144 36.85976-21.120144 43.902142 0l41.273372 123.957105A184.967743 184.967743 0 0 0 692.274156 640.713687l123.890111 41.273373c21.119144 7.042381 21.119144 36.85976 0 43.902141L692.207161 767.162574A184.967743 184.967743 0 0 0 575.224443 884.212286l-41.273372 123.890111A23.09997 23.09997 0 0 1 512 1024c-9.983123 0-18.838344-6.409437-21.951071-15.897603L448.775557 884.145292A184.946745 184.946745 0 0 0 331.792839 767.162574L207.836733 725.889201A23.09997 23.09997 0 0 1 191.93813 703.93813c0-9.983123 6.409437-18.838344 15.897603-21.95107l123.957106-41.273373A184.946745 184.946745 0 0 0 448.775557 523.730969zM242.840657 73.466543A13.888779 13.888779 0 0 1 256.022498 63.94338c5.987474 0 11.299007 3.839663 13.182841 9.523163l24.767824 74.360464a111.070238 111.070238 0 0 0 70.19983 70.20083l74.360464 24.767824A13.888779 13.888779 0 0 1 448.05662 255.977502c0 5.987474-3.839663 11.299007-9.523163 13.182841l-74.360464 24.767823a110.947249 110.947249 0 0 0-70.20083 70.199831l-24.767824 74.360464A13.888779 13.888779 0 0 1 256.022498 448.011624a13.888779 13.888779 0 0 1-13.182841-9.523163l-24.767823-74.360464a110.947249 110.947249 0 0 0-70.199831-70.20083l-74.360464-24.767824A13.888779 13.888779 0 0 1 63.988376 255.977502c0-5.987474 3.839663-11.299007 9.523163-13.182841l74.360464-24.767824a110.947249 110.947249 0 0 0 70.20083-70.19983zM695.213897 6.335443a9.283184 9.283184 0 0 1 17.538459 0L729.260905 55.86509a73.889506 73.889506 0 0 0 46.843883 46.843883l49.530646 16.509549a9.283184 9.283184 0 0 1 0 17.538458L776.106787 153.266529a73.9585 73.9585 0 0 0-46.843882 46.843883l-16.509549 49.530647a9.283184 9.283184 0 0 1-17.538459 0L678.705348 200.112412a73.9585 73.9585 0 0 0-46.843883-46.843883l-49.468652-16.509549a9.283184 9.283184 0 0 1 0-17.538458l49.535646-16.509549a73.897505 73.897505 0 0 0 46.842883-46.843883L695.213897 6.397438z m0 0" fill="#409eff"/>';
optimizeTooltip.textContent = '一键优化';
}
isOptimized = false;
originalText = '';
}
`; `;
} }

117
src/views/optimizeButton.ts Normal file
View File

@ -0,0 +1,117 @@
/**
* 一键优化按钮组件
*/
/**
* 获取一键优化按钮的 HTML 内容
*/
export function getOptimizeButtonContent(): string {
return `
<!-- 一键优化按钮 -->
<div class="tooltip">
<button id="optimizeButton" class="optimize-button" onclick="handleOptimize()">
<svg t="1765867478136" id="optimizeIcon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2314"><path d="M490.048929 399.773864c7.042381-21.120144 36.85976-21.120144 43.902142 0l41.273372 123.957105A184.967743 184.967743 0 0 0 692.274156 640.713687l123.890111 41.273373c21.119144 7.042381 21.119144 36.85976 0 43.902141L692.207161 767.162574A184.967743 184.967743 0 0 0 575.224443 884.212286l-41.273372 123.890111A23.09997 23.09997 0 0 1 512 1024c-9.983123 0-18.838344-6.409437-21.951071-15.897603L448.775557 884.145292A184.946745 184.946745 0 0 0 331.792839 767.162574L207.836733 725.889201A23.09997 23.09997 0 0 1 191.93813 703.93813c0-9.983123 6.409437-18.838344 15.897603-21.95107l123.957106-41.273373A184.946745 184.946745 0 0 0 448.775557 523.730969zM242.840657 73.466543A13.888779 13.888779 0 0 1 256.022498 63.94338c5.987474 0 11.299007 3.839663 13.182841 9.523163l24.767824 74.360464a111.070238 111.070238 0 0 0 70.19983 70.20083l74.360464 24.767824A13.888779 13.888779 0 0 1 448.05662 255.977502c0 5.987474-3.839663 11.299007-9.523163 13.182841l-74.360464 24.767823a110.947249 110.947249 0 0 0-70.20083 70.199831l-24.767824 74.360464A13.888779 13.888779 0 0 1 256.022498 448.011624a13.888779 13.888779 0 0 1-13.182841-9.523163l-24.767823-74.360464a110.947249 110.947249 0 0 0-70.199831-70.20083l-74.360464-24.767824A13.888779 13.888779 0 0 1 63.988376 255.977502c0-5.987474 3.839663-11.299007 9.523163-13.182841l74.360464-24.767824a110.947249 110.947249 0 0 0 70.20083-70.19983zM695.213897 6.335443a9.283184 9.283184 0 0 1 17.538459 0L729.260905 55.86509a73.889506 73.889506 0 0 0 46.843883 46.843883l49.530646 16.509549a9.283184 9.283184 0 0 1 0 17.538458L776.106787 153.266529a73.9585 73.9585 0 0 0-46.843882 46.843883l-16.509549 49.530647a9.283184 9.283184 0 0 1-17.538459 0L678.705348 200.112412a73.9585 73.9585 0 0 0-46.843883-46.843883l-49.468652-16.509549a9.283184 9.283184 0 0 1 0-17.538458l49.535646-16.509549a73.897505 73.897505 0 0 0 46.842883-46.843883L695.213897 6.397438z m0 0" p-id="2315" fill="#409eff"></path></svg>
</button>
<span class="tooltiptext" id="optimizeTooltip">一键优化</span>
</div>
`;
}
/**
* 获取一键优化按钮的样式
*/
export function getOptimizeButtonStyles(): string {
return `
/* 一键优化按钮样式 */
.optimize-button {
padding: 8px;
background: transparent;
color: var(--vscode-foreground);
border: none;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: opacity 0.2s ease;
width: 32px;
height: 32px;
}
.optimize-button:hover {
opacity: 0.7;
}
.optimize-button svg {
width: 16px;
height: 16px;
}
.optimize-button-wrapper {
display: flex;
align-items: flex-end;
}
`;
}
/**
* 获取一键优化按钮的脚本
*/
export function getOptimizeButtonScript(): string {
return `
let isOptimized = false; // 标记是否已优化
let originalText = ''; // 保存原始文本用于撤回
function handleOptimize() {
if (isOptimized) {
// 撤回操作
messageInput.value = originalText;
resetOptimizeButton();
} else {
// 优化操作
originalText = messageInput.value; // 保存原始文本
// 使用死数据替换输入框内容
const optimizedTexts = [
'请帮我优化这段代码,提高性能和可读性',
'请分析这个问题并给出最佳解决方案',
'请帮我重构这段代码,使其更加简洁高效',
'请检查代码中的潜在问题并提供改进建议'
];
const randomText = optimizedTexts[Math.floor(Math.random() * optimizedTexts.length)];
messageInput.value = randomText;
// 切换到撤回状态
isOptimized = true;
updateOptimizeButton();
}
messageInput.focus();
autoResizeTextarea();
}
function updateOptimizeButton() {
const optimizeIcon = document.getElementById('optimizeIcon');
const optimizeTooltip = document.getElementById('optimizeTooltip');
if (optimizeIcon && optimizeTooltip) {
// 切换为撤回图标
optimizeIcon.innerHTML = '<path d="M581.056 288.32H232.96l108.352-102.208c15.552-15.744 19.456-31.104 4.16-46.208-16.064-15.872-32.576-15.808-48.64 0l-145.92 144.768c-8.768 8.832-23.488 20.608-22.08 32.448l0.64 4.8-0.64 4.864c-1.344 11.776 6.4 18.24 14.848 26.816l147.648 145.216c16.064 15.808 38.08 20.992 54.144 5.12 15.296-15.104 3.84-38.208-11.328-53.504L233.152 353.6 581.056 352c126.464 0 250.944 111.488 250.944 236.16C832 712.832 707.52 832 581.056 832H246.4c-22.592 0-29.696 9.6-29.696 32.256s7.04 31.744 29.696 31.744H581.12C755.136 896 896 757.696 896 588.16c0-169.408-140.8-299.84-314.944-299.84z" fill="currentColor"/><path d="M323.392 192a32 32 0 1 1 0-64 32 32 0 0 1 0 64zM320.192 514.048a32 32 0 1 1 0-64 32 32 0 0 1 0 64zM237.824 896a32 32 0 1 1 0-64 32 32 0 0 1 0 64z" fill="currentColor"/>';
optimizeTooltip.textContent = '撤回';
}
}
function resetOptimizeButton() {
const optimizeIcon = document.getElementById('optimizeIcon');
const optimizeTooltip = document.getElementById('optimizeTooltip');
if (optimizeIcon && optimizeTooltip) {
// 切换回优化图标(星星图标)
optimizeIcon.innerHTML = '<path d="M490.048929 399.773864c7.042381-21.120144 36.85976-21.120144 43.902142 0l41.273372 123.957105A184.967743 184.967743 0 0 0 692.274156 640.713687l123.890111 41.273373c21.119144 7.042381 21.119144 36.85976 0 43.902141L692.207161 767.162574A184.967743 184.967743 0 0 0 575.224443 884.212286l-41.273372 123.890111A23.09997 23.09997 0 0 1 512 1024c-9.983123 0-18.838344-6.409437-21.951071-15.897603L448.775557 884.145292A184.946745 184.946745 0 0 0 331.792839 767.162574L207.836733 725.889201A23.09997 23.09997 0 0 1 191.93813 703.93813c0-9.983123 6.409437-18.838344 15.897603-21.95107l123.957106-41.273373A184.946745 184.946745 0 0 0 448.775557 523.730969zM242.840657 73.466543A13.888779 13.888779 0 0 1 256.022498 63.94338c5.987474 0 11.299007 3.839663 13.182841 9.523163l24.767824 74.360464a111.070238 111.070238 0 0 0 70.19983 70.20083l74.360464 24.767824A13.888779 13.888779 0 0 1 448.05662 255.977502c0 5.987474-3.839663 11.299007-9.523163 13.182841l-74.360464 24.767823a110.947249 110.947249 0 0 0-70.20083 70.199831l-24.767824 74.360464A13.888779 13.888779 0 0 1 256.022498 448.011624a13.888779 13.888779 0 0 1-13.182841-9.523163l-24.767823-74.360464a110.947249 110.947249 0 0 0-70.199831-70.20083l-74.360464-24.767824A13.888779 13.888779 0 0 1 63.988376 255.977502c0-5.987474 3.839663-11.299007 9.523163-13.182841l74.360464-24.767824a110.947249 110.947249 0 0 0 70.20083-70.19983zM695.213897 6.335443a9.283184 9.283184 0 0 1 17.538459 0L729.260905 55.86509a73.889506 73.889506 0 0 0 46.843883 46.843883l49.530646 16.509549a9.283184 9.283184 0 0 1 0 17.538458L776.106787 153.266529a73.9585 73.9585 0 0 0-46.843882 46.843883l-16.509549 49.530647a9.283184 9.283184 0 0 1-17.538459 0L678.705348 200.112412a73.9585 73.9585 0 0 0-46.843883-46.843883l-49.468652-16.509549a9.283184 9.283184 0 0 1 0-17.538458l49.535646-16.509549a73.897505 73.897505 0 0 0 46.842883-46.843883L695.213897 6.397438z m0 0" fill="#409eff"/>';
optimizeTooltip.textContent = '一键优化';
}
isOptimized = false;
originalText = '';
}
`;
}

100
src/views/planToggle.ts Normal file
View File

@ -0,0 +1,100 @@
/**
* Plan 开关组件
*/
/**
* 获取 Plan 开关的 HTML 内容
*/
export function getPlanToggleContent(): string {
return `
<div class="tooltip">
<label class="plan-toggle">
<input type="checkbox" id="planToggle" onchange="handlePlanToggle()">
<span class="plan-toggle-slider"></span>
<span class="plan-toggle-label">Plan</span>
</label>
<span class="tooltiptext" id="planTooltip">启用 Plan 模式</span>
</div>
`;
}
/**
* 获取 Plan 开关的样式
*/
export function getPlanToggleStyles(): string {
return `
/* Plan 开关样式 */
.plan-toggle {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
user-select: none;
}
.plan-toggle input[type="checkbox"] {
display: none;
}
.plan-toggle-slider {
position: relative;
width: 36px;
height: 20px;
background: var(--vscode-input-background);
border: 1px solid var(--vscode-input-border);
border-radius: 10px;
transition: all 0.3s ease;
}
.plan-toggle-slider::before {
content: "";
position: absolute;
width: 14px;
height: 14px;
left: 2px;
top: 2px;
background: var(--vscode-foreground);
border-radius: 50%;
transition: all 0.3s ease;
}
.plan-toggle input[type="checkbox"]:checked + .plan-toggle-slider {
background: #409eff;
border-color: #409eff;
}
.plan-toggle input[type="checkbox"]:checked + .plan-toggle-slider::before {
transform: translateX(16px);
background: white;
}
.plan-toggle-label {
font-size: 13px;
font-weight: 500;
color: var(--vscode-foreground);
}
`;
}
/**
* 获取 Plan 开关的脚本
*/
export function getPlanToggleScript(): string {
return `
// Plan 开关处理函数
function handlePlanToggle() {
const planToggle = document.getElementById('planToggle');
const planTooltip = document.getElementById('planTooltip');
if (planToggle && planTooltip) {
if (planToggle.checked) {
// 开启 Plan 模式
planTooltip.textContent = '关闭 Plan 模式';
} else {
// 关闭 Plan 模式
planTooltip.textContent = '启用 Plan 模式';
}
}
}
`;
}

View File

@ -347,6 +347,27 @@ export function getWebviewContent(iconUri?: string): string {
background: var(--vscode-charts-red); background: var(--vscode-charts-red);
animation: none; animation: none;
} }
/* 快捷操作按钮样式 */
.quick-actions {
display: flex;
gap: 10px;
margin-bottom: 15px;
flex-wrap: wrap;
}
.quick-btn {
padding: 8px 16px;
background: var(--vscode-button-secondaryBackground);
color: var(--vscode-button-secondaryForeground);
border: 1px solid var(--vscode-button-border);
border-radius: 6px;
cursor: pointer;
font-size: 13px;
transition: all 0.2s;
}
.quick-btn:hover {
background: var(--vscode-button-secondaryHoverBackground);
}
</style> </style>
</head> </head>
<body> <body>
@ -437,6 +458,10 @@ export function getWebviewContent(iconUri?: string): string {
// 实时更新分段消息(按后端返回顺序) // 实时更新分段消息(按后端返回顺序)
console.log('[WebView] 实时更新段落, segments:', message.segments); console.log('[WebView] 实时更新段落, segments:', message.segments);
updateSegmentsRealtime(message.segments, message.isComplete); updateSegmentsRealtime(message.segments, message.isComplete);
// 如果对话完成,恢复发送按钮状态
if (message.isComplete && typeof setSendButtonState === 'function') {
setSendButtonState(false);
}
break; break;
case 'receiveSegments': case 'receiveSegments':