diff --git a/src/config/settings.ts b/src/config/settings.ts index cbd5fa4..b760a4e 100644 --- a/src/config/settings.ts +++ b/src/config/settings.ts @@ -10,6 +10,9 @@ type Environment = "dev" | "test" | "prod"; /** 当前环境 - 修改这里切换环境 */ const CURRENT_ENV: Environment = "test"; +/** 服务等级类型 */ +export type ServiceTier = "lite" | "syntaxic" | "max" | "auto"; + /** 配置项接口 */ export interface IccoderConfig { /** 后端服务地址 */ @@ -18,6 +21,8 @@ export interface IccoderConfig { timeout: number; /** 用户ID(临时使用,后续对接认证) */ userId: string; + /** 服务等级 */ + serviceTier: ServiceTier; } /** 环境配置 */ @@ -25,20 +30,23 @@ const ENV_CONFIG: Record = { /** 本地开发环境 */ dev: { backendUrl: "http://localhost:2233", - timeout: 300000, // 5分钟,与子智能体超时一致 + timeout: 300000, userId: "default-user", + serviceTier: "max", // 默认使用 max }, /** 测试服务器环境 */ test: { backendUrl: "http://192.168.1.108:2233", timeout: 60000, userId: "default-user", + serviceTier: "max", }, /** 生产环境 */ prod: { - backendUrl: "https://api.iccoder.com", // TODO: 替换为实际生产地址 + backendUrl: "https://api.iccoder.com", timeout: 60000, userId: "default-user", + serviceTier: "auto", }, }; diff --git a/src/panels/ICHelperPanel.ts b/src/panels/ICHelperPanel.ts index 8d36194..2d7978e 100644 --- a/src/panels/ICHelperPanel.ts +++ b/src/panels/ICHelperPanel.ts @@ -148,7 +148,8 @@ export async function showICHelperPanel( panel, message.text, context.extensionPath, - message.mode + message.mode, + message.model // 传递服务等级 ); break; case "readFile": diff --git a/src/services/dialogService.ts b/src/services/dialogService.ts index 3f6b6ca..c819840 100644 --- a/src/services/dialogService.ts +++ b/src/services/dialogService.ts @@ -9,7 +9,7 @@ import { startStreamDialog, generateTaskId, SSEController, SSECallbacks } from ' import { executeToolCall, createToolExecutorContext, ToolExecutorContext } from './toolExecutor'; import { userInteractionManager } from './userInteraction'; 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 { ChatHistoryManager } from '../utils/chatHistoryManager'; @@ -316,7 +316,8 @@ export class DialogSession { async sendMessage( message: string, callbacks: DialogCallbacks, - mode?: RunMode + mode?: RunMode, + serviceTier?: ServiceTier // 新增:服务等级参数 ): Promise { if (this.isActive) { callbacks.onError?.('当前有对话正在进行中'); @@ -344,6 +345,7 @@ export class DialogSession { message, userId: config.userId, mode: mode || 'agent', + serviceTier: serviceTier || config.serviceTier, // 优先使用传入的参数 compactedData: compactedData || undefined, newMessages: newMessages.length > 0 ? newMessages : undefined, knowledgeData: knowledgeData || undefined diff --git a/src/types/api.ts b/src/types/api.ts index 28289fe..34bb475 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -3,7 +3,7 @@ * 对应后端 IC Coder Backend 的接口格式 */ -import { CompactedMemory, CompactedMessage } from './memory'; +import { CompactedMemory, CompactedMessage } from "./memory"; // ============== 对话请求/响应 ============== @@ -14,7 +14,16 @@ import { CompactedMemory, CompactedMessage } from './memory'; * - agent: 智能体自主(默认) * - 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; /** 运行模式 */ mode: RunMode; + /** 服务等级 */ + serviceTier?: ServiceTier; /** 压缩后的记忆数据(用于后端重启后恢复) */ compactedData?: CompactedMemory; /** 压缩后产生的新消息 */ @@ -41,26 +52,26 @@ export interface DialogRequest { /** SSE 事件类型枚举 */ export type SSEEventType = - | 'text_delta' // 文本增量 - | 'tool_call' // 客户端工具调用请求 - | 'tool_confirm' // 工具确认请求(Ask 模式) - | 'plan_confirm' // 计划确认请求(Plan 模式) - | 'tool_start' // 工具开始执行 - | 'tool_complete' // 工具执行完成 - | 'tool_error' // 工具执行错误 - | 'ask_user' // 向用户提问 - | 'agent_start' // 子智能体启动 - | 'agent_progress' // 子智能体进度 - | 'agent_complete' // 子智能体完成 - | 'agent_error' // 子智能体错误 - | 'memory_compacted' // 记忆压缩完成 - | 'context_usage' // 上下文使用量 - | 'complete' // 对话完成 - | 'error' // 错误 - | 'warning' // 警告 - | 'notification' // 通知 - | 'depth_update' // 深度更新 - | 'heartbeat'; // 心跳事件 + | "text_delta" // 文本增量 + | "tool_call" // 客户端工具调用请求 + | "tool_confirm" // 工具确认请求(Ask 模式) + | "plan_confirm" // 计划确认请求(Plan 模式) + | "tool_start" // 工具开始执行 + | "tool_complete" // 工具执行完成 + | "tool_error" // 工具执行错误 + | "ask_user" // 向用户提问 + | "agent_start" // 子智能体启动 + | "agent_progress" // 子智能体进度 + | "agent_complete" // 子智能体完成 + | "agent_error" // 子智能体错误 + | "memory_compacted" // 记忆压缩完成 + | "context_usage" // 上下文使用量 + | "complete" // 对话完成 + | "error" // 错误 + | "warning" // 警告 + | "notification" // 通知 + | "depth_update" // 深度更新 + | "heartbeat"; // 心跳 /** text_delta 事件数据 */ export interface TextDeltaEvent { @@ -162,7 +173,7 @@ export interface AgentProgressEvent { toolName: string; toolInput?: unknown; toolResult?: string; - status: 'running' | 'completed' | 'error'; + status: "running" | "completed" | "error"; timestamp: number; } @@ -198,11 +209,11 @@ export interface ContextUsageEvent { */ export interface ToolCallRequest { /** JSON-RPC版本,固定为"2.0" */ - jsonrpc: '2.0'; + jsonrpc: "2.0"; /** 请求ID,用于匹配响应 */ id: number; /** 方法名,固定为"tools/call" */ - method: 'tools/call'; + method: "tools/call"; /** 调用参数 */ params: { /** 工具名称 */ @@ -218,7 +229,7 @@ export interface ToolCallRequest { */ export interface ToolCallResult { /** JSON-RPC版本 */ - jsonrpc: '2.0'; + jsonrpc: "2.0"; /** 请求ID,与ToolCallRequest.id对应 */ id: number; /** 执行结果(与error互斥) */ @@ -303,16 +314,16 @@ export interface ToolConfirmResponse { /** 后端工具名称 */ export type ToolName = - | 'file_read' - | 'file_write' - | 'file_delete' - | 'file_list' - | 'syntax_check' - | 'simulation' - | 'waveform_summary' - | 'waveform_trace' - | 'knowledge_save' - | 'knowledge_load'; + | "file_read" + | "file_write" + | "file_delete" + | "file_list" + | "syntax_check" + | "simulation" + | "waveform_summary" + | "waveform_trace" + | "knowledge_save" + | "knowledge_load"; /** file_read 工具参数 */ export interface FileReadArgs { diff --git a/src/utils/messageHandler.ts b/src/utils/messageHandler.ts index 3ea034d..872e043 100644 --- a/src/utils/messageHandler.ts +++ b/src/utils/messageHandler.ts @@ -19,7 +19,7 @@ import { dialogManager, DialogSession } from "../services/dialogService"; import { userInteractionManager } from "../services/userInteraction"; import { healthCheck } from "../services/apiClient"; -import type { RunMode } from "../types/api"; +import type { RunMode, ServiceTier } from "../types/api"; /** 是否使用后端服务(可通过配置控制) */ let useBackendService = true; @@ -58,7 +58,8 @@ export async function handleUserMessage( panel: vscode.WebviewPanel, text: string, extensionPath?: string, - mode?: RunMode + mode?: RunMode, + serviceTier?: ServiceTier // 新增:服务等级参数 ) { console.log("收到用户消息:", text); @@ -90,7 +91,7 @@ export async function handleUserMessage( // 尝试使用后端服务 if (useBackendService && extensionPath) { try { - await handleUserMessageWithBackend(panel, text, extensionPath, mode); + await handleUserMessageWithBackend(panel, text, extensionPath, mode, undefined, serviceTier); return; } catch (error) { console.error("后端服务不可用:", error); @@ -125,7 +126,8 @@ async function handleUserMessageWithBackend( text: string, extensionPath: string, mode?: RunMode, - reuseTaskId?: string // 可选,复用现有 taskId(用于 Plan 模式确认后继续执行) + reuseTaskId?: string, // 可选,复用现有 taskId(用于 Plan 模式确认后继续执行) + serviceTier?: ServiceTier // 新增:服务等级参数 ): Promise { const historyManager = ChatHistoryManager.getInstance(); @@ -287,7 +289,8 @@ async function handleUserMessageWithBackend( }); }, }, - mode + mode, + serviceTier // 传递服务等级 ); }); }