Merge branch 'feat/back-to-front' into feature/waveform-renderer

This commit is contained in:
Roe-xin
2026-01-08 17:26:29 +08:00
5 changed files with 71 additions and 46 deletions

View File

@ -10,6 +10,9 @@ type Environment = "dev" | "test" | "prod";
/** 当前环境 - 修改这里切换环境 */ /** 当前环境 - 修改这里切换环境 */
const CURRENT_ENV: Environment = "test"; const CURRENT_ENV: Environment = "test";
/** 服务等级类型 */
export type ServiceTier = "lite" | "syntaxic" | "max" | "auto";
/** 配置项接口 */ /** 配置项接口 */
export interface IccoderConfig { export interface IccoderConfig {
/** 后端服务地址 */ /** 后端服务地址 */
@ -18,6 +21,8 @@ export interface IccoderConfig {
timeout: number; timeout: number;
/** 用户ID临时使用后续对接认证 */ /** 用户ID临时使用后续对接认证 */
userId: string; userId: string;
/** 服务等级 */
serviceTier: ServiceTier;
} }
/** 环境配置 */ /** 环境配置 */
@ -25,20 +30,23 @@ const ENV_CONFIG: Record<Environment, IccoderConfig> = {
/** 本地开发环境 */ /** 本地开发环境 */
dev: { dev: {
backendUrl: "http://localhost:2233", backendUrl: "http://localhost:2233",
timeout: 300000, // 5分钟与子智能体超时一致 timeout: 300000,
userId: "default-user", userId: "default-user",
serviceTier: "max", // 默认使用 max
}, },
/** 测试服务器环境 */ /** 测试服务器环境 */
test: { test: {
backendUrl: "http://192.168.1.108:2233", backendUrl: "http://192.168.1.108:2233",
timeout: 60000, timeout: 60000,
userId: "default-user", userId: "default-user",
serviceTier: "max",
}, },
/** 生产环境 */ /** 生产环境 */
prod: { prod: {
backendUrl: "https://api.iccoder.com", // TODO: 替换为实际生产地址 backendUrl: "https://api.iccoder.com",
timeout: 60000, timeout: 60000,
userId: "default-user", userId: "default-user",
serviceTier: "auto",
}, },
}; };

View File

@ -148,7 +148,8 @@ export async function showICHelperPanel(
panel, panel,
message.text, message.text,
context.extensionPath, context.extensionPath,
message.mode message.mode,
message.model // 传递服务等级
); );
break; break;
case "readFile": case "readFile":

View File

@ -9,7 +9,7 @@ import { startStreamDialog, generateTaskId, SSEController, SSECallbacks } from '
import { executeToolCall, createToolExecutorContext, ToolExecutorContext } from './toolExecutor'; import { executeToolCall, createToolExecutorContext, ToolExecutorContext } from './toolExecutor';
import { userInteractionManager } from './userInteraction'; import { userInteractionManager } from './userInteraction';
import { getConfig } from '../config/settings'; import { getConfig } from '../config/settings';
import type { DialogRequest, ToolCallRequest, AskUserEvent, RunMode, ToolConfirmEvent, PlanConfirmEvent } from '../types/api'; import type { DialogRequest, ToolCallRequest, AskUserEvent, RunMode, ServiceTier, ToolConfirmEvent, PlanConfirmEvent } from '../types/api';
import { submitToolConfirm, submitAnswer, stopDialog } from './apiClient'; import { submitToolConfirm, submitAnswer, stopDialog } from './apiClient';
import { ChatHistoryManager } from '../utils/chatHistoryManager'; import { ChatHistoryManager } from '../utils/chatHistoryManager';
@ -316,7 +316,8 @@ export class DialogSession {
async sendMessage( async sendMessage(
message: string, message: string,
callbacks: DialogCallbacks, callbacks: DialogCallbacks,
mode?: RunMode mode?: RunMode,
serviceTier?: ServiceTier // 新增:服务等级参数
): Promise<void> { ): Promise<void> {
if (this.isActive) { if (this.isActive) {
callbacks.onError?.('当前有对话正在进行中'); callbacks.onError?.('当前有对话正在进行中');
@ -344,6 +345,7 @@ export class DialogSession {
message, message,
userId: config.userId, userId: config.userId,
mode: mode || 'agent', mode: mode || 'agent',
serviceTier: serviceTier || config.serviceTier, // 优先使用传入的参数
compactedData: compactedData || undefined, compactedData: compactedData || undefined,
newMessages: newMessages.length > 0 ? newMessages : undefined, newMessages: newMessages.length > 0 ? newMessages : undefined,
knowledgeData: knowledgeData || undefined knowledgeData: knowledgeData || undefined

View File

@ -3,7 +3,7 @@
* 对应后端 IC Coder Backend 的接口格式 * 对应后端 IC Coder Backend 的接口格式
*/ */
import { CompactedMemory, CompactedMessage } from './memory'; import { CompactedMemory, CompactedMessage } from "./memory";
// ============== 对话请求/响应 ============== // ============== 对话请求/响应 ==============
@ -14,7 +14,16 @@ import { CompactedMemory, CompactedMessage } from './memory';
* - agent: 智能体自主(默认) * - agent: 智能体自主(默认)
* - auto: 完全自动 * - auto: 完全自动
*/ */
export type RunMode = 'plan' | 'ask' | 'agent' | 'auto'; export type RunMode = "plan" | "ask" | "agent" | "auto";
/**
* 服务等级类型
* - lite: 轻量级
* - syntaxic: 语法级
* - max: 最大性能
* - auto: 自动选择
*/
export type ServiceTier = "lite" | "syntaxic" | "max" | "auto";
/** /**
* 对话请求 * 对话请求
@ -29,6 +38,8 @@ export interface DialogRequest {
userId: string; userId: string;
/** 运行模式 */ /** 运行模式 */
mode: RunMode; mode: RunMode;
/** 服务等级 */
serviceTier?: ServiceTier;
/** 压缩后的记忆数据(用于后端重启后恢复) */ /** 压缩后的记忆数据(用于后端重启后恢复) */
compactedData?: CompactedMemory; compactedData?: CompactedMemory;
/** 压缩后产生的新消息 */ /** 压缩后产生的新消息 */
@ -41,26 +52,26 @@ export interface DialogRequest {
/** SSE 事件类型枚举 */ /** SSE 事件类型枚举 */
export type SSEEventType = export type SSEEventType =
| 'text_delta' // 文本增量 | "text_delta" // 文本增量
| 'tool_call' // 客户端工具调用请求 | "tool_call" // 客户端工具调用请求
| 'tool_confirm' // 工具确认请求Ask 模式) | "tool_confirm" // 工具确认请求Ask 模式)
| 'plan_confirm' // 计划确认请求Plan 模式) | "plan_confirm" // 计划确认请求Plan 模式)
| 'tool_start' // 工具开始执行 | "tool_start" // 工具开始执行
| 'tool_complete' // 工具执行完成 | "tool_complete" // 工具执行完成
| 'tool_error' // 工具执行错误 | "tool_error" // 工具执行错误
| 'ask_user' // 向用户提问 | "ask_user" // 向用户提问
| 'agent_start' // 子智能体启动 | "agent_start" // 子智能体启动
| 'agent_progress' // 子智能体进度 | "agent_progress" // 子智能体进度
| 'agent_complete' // 子智能体完成 | "agent_complete" // 子智能体完成
| 'agent_error' // 子智能体错误 | "agent_error" // 子智能体错误
| 'memory_compacted' // 记忆压缩完成 | "memory_compacted" // 记忆压缩完成
| 'context_usage' // 上下文使用量 | "context_usage" // 上下文使用量
| 'complete' // 对话完成 | "complete" // 对话完成
| 'error' // 错误 | "error" // 错误
| 'warning' // 警告 | "warning" // 警告
| 'notification' // 通知 | "notification" // 通知
| 'depth_update' // 深度更新 | "depth_update" // 深度更新
| 'heartbeat'; // 心跳事件 | "heartbeat"; // 心跳
/** text_delta 事件数据 */ /** text_delta 事件数据 */
export interface TextDeltaEvent { export interface TextDeltaEvent {
@ -162,7 +173,7 @@ export interface AgentProgressEvent {
toolName: string; toolName: string;
toolInput?: unknown; toolInput?: unknown;
toolResult?: string; toolResult?: string;
status: 'running' | 'completed' | 'error'; status: "running" | "completed" | "error";
timestamp: number; timestamp: number;
} }
@ -198,11 +209,11 @@ export interface ContextUsageEvent {
*/ */
export interface ToolCallRequest { export interface ToolCallRequest {
/** JSON-RPC版本固定为"2.0" */ /** JSON-RPC版本固定为"2.0" */
jsonrpc: '2.0'; jsonrpc: "2.0";
/** 请求ID用于匹配响应 */ /** 请求ID用于匹配响应 */
id: number; id: number;
/** 方法名,固定为"tools/call" */ /** 方法名,固定为"tools/call" */
method: 'tools/call'; method: "tools/call";
/** 调用参数 */ /** 调用参数 */
params: { params: {
/** 工具名称 */ /** 工具名称 */
@ -218,7 +229,7 @@ export interface ToolCallRequest {
*/ */
export interface ToolCallResult { export interface ToolCallResult {
/** JSON-RPC版本 */ /** JSON-RPC版本 */
jsonrpc: '2.0'; jsonrpc: "2.0";
/** 请求ID与ToolCallRequest.id对应 */ /** 请求ID与ToolCallRequest.id对应 */
id: number; id: number;
/** 执行结果与error互斥 */ /** 执行结果与error互斥 */
@ -303,16 +314,16 @@ export interface ToolConfirmResponse {
/** 后端工具名称 */ /** 后端工具名称 */
export type ToolName = export type ToolName =
| 'file_read' | "file_read"
| 'file_write' | "file_write"
| 'file_delete' | "file_delete"
| 'file_list' | "file_list"
| 'syntax_check' | "syntax_check"
| 'simulation' | "simulation"
| 'waveform_summary' | "waveform_summary"
| 'waveform_trace' | "waveform_trace"
| 'knowledge_save' | "knowledge_save"
| 'knowledge_load'; | "knowledge_load";
/** file_read 工具参数 */ /** file_read 工具参数 */
export interface FileReadArgs { export interface FileReadArgs {

View File

@ -19,7 +19,7 @@ import { dialogManager, DialogSession } from "../services/dialogService";
import { userInteractionManager } from "../services/userInteraction"; import { userInteractionManager } from "../services/userInteraction";
import { healthCheck } from "../services/apiClient"; import { healthCheck } from "../services/apiClient";
import type { RunMode } from "../types/api"; import type { RunMode, ServiceTier } from "../types/api";
/** 是否使用后端服务(可通过配置控制) */ /** 是否使用后端服务(可通过配置控制) */
let useBackendService = true; let useBackendService = true;
@ -58,7 +58,8 @@ export async function handleUserMessage(
panel: vscode.WebviewPanel, panel: vscode.WebviewPanel,
text: string, text: string,
extensionPath?: string, extensionPath?: string,
mode?: RunMode mode?: RunMode,
serviceTier?: ServiceTier // 新增:服务等级参数
) { ) {
console.log("收到用户消息:", text); console.log("收到用户消息:", text);
@ -90,7 +91,7 @@ export async function handleUserMessage(
// 尝试使用后端服务 // 尝试使用后端服务
if (useBackendService && extensionPath) { if (useBackendService && extensionPath) {
try { try {
await handleUserMessageWithBackend(panel, text, extensionPath, mode); await handleUserMessageWithBackend(panel, text, extensionPath, mode, undefined, serviceTier);
return; return;
} catch (error) { } catch (error) {
console.error("后端服务不可用:", error); console.error("后端服务不可用:", error);
@ -125,7 +126,8 @@ async function handleUserMessageWithBackend(
text: string, text: string,
extensionPath: string, extensionPath: string,
mode?: RunMode, mode?: RunMode,
reuseTaskId?: string // 可选,复用现有 taskId用于 Plan 模式确认后继续执行) reuseTaskId?: string, // 可选,复用现有 taskId用于 Plan 模式确认后继续执行)
serviceTier?: ServiceTier // 新增:服务等级参数
): Promise<void> { ): Promise<void> {
const historyManager = ChatHistoryManager.getInstance(); const historyManager = ChatHistoryManager.getInstance();
@ -287,7 +289,8 @@ async function handleUserMessageWithBackend(
}); });
}, },
}, },
mode mode,
serviceTier // 传递服务等级
); );
}); });
} }