/** * 配置管理 * 支持 dev(本地开发)和 test(测试服务器)两种环境 */ import * as vscode from "vscode"; /** 环境类型 */ type Environment = "dev" | "test" | "prod"; /** 当前环境 - 修改这里切换环境 */ const CURRENT_ENV: Environment = "test"; /** 服务等级类型 */ export type ServiceTier = "lite" | "syntaxic" | "max" | "auto"; /** 配置项接口 */ export interface IccoderConfig { /** 后端服务地址 */ backendUrl: string; /** 请求超时时间(毫秒) */ timeout: number; /** 用户ID(临时使用,后续对接认证) */ userId: string; /** 服务等级 */ serviceTier: ServiceTier; } /** 环境配置 */ const ENV_CONFIG: Record = { /** 本地开发环境 */ dev: { backendUrl: "http://localhost:2233", 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", timeout: 60000, userId: "default-user", serviceTier: "auto", }, }; /** * 获取当前环境 */ export function getCurrentEnv(): Environment { return CURRENT_ENV; } /** * 获取配置项 */ export function getConfig(): IccoderConfig { return { ...ENV_CONFIG[CURRENT_ENV] }; } /** * 获取后端 API 地址 */ export function getApiUrl(path: string): string { const { backendUrl } = getConfig(); const baseUrl = backendUrl.endsWith("/") ? backendUrl.slice(0, -1) : backendUrl; const apiPath = path.startsWith("/") ? path : `/${path}`; return `${baseUrl}${apiPath}`; }