feat: 添加后端通信基础设施
- 新增 API 类型定义(src/types/api.ts) - 定义对话请求/响应接口 - 定义 SSE 事件类型(MessageChunk、ToolExecution、AskUser 等) - 定义工具执行和用户交互相关类型 - 新增配置管理模块(src/config/settings.ts) - 实现后端服务器配置读取 - 支持从 VSCode 配置中获取 baseUrl 和 timeout - 提供统一的配置访问接口
This commit is contained in:
46
src/config/settings.ts
Normal file
46
src/config/settings.ts
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 配置管理
|
||||
* 从 VSCode 设置读取配置项
|
||||
*/
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
/** 配置项接口 */
|
||||
export interface IccoderConfig {
|
||||
/** 后端服务地址 */
|
||||
backendUrl: string;
|
||||
/** 请求超时时间(毫秒) */
|
||||
timeout: number;
|
||||
/** 用户ID(临时使用,后续对接认证) */
|
||||
userId: string;
|
||||
}
|
||||
|
||||
/** 默认配置 */
|
||||
const DEFAULT_CONFIG: IccoderConfig = {
|
||||
backendUrl: 'http://localhost:8080',
|
||||
timeout: 60000,
|
||||
userId: 'default-user'
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取配置项
|
||||
*/
|
||||
export function getConfig(): IccoderConfig {
|
||||
const config = vscode.workspace.getConfiguration('icCoder');
|
||||
|
||||
return {
|
||||
backendUrl: config.get<string>('backendUrl', DEFAULT_CONFIG.backendUrl),
|
||||
timeout: config.get<number>('timeout', DEFAULT_CONFIG.timeout),
|
||||
userId: config.get<string>('userId', DEFAULT_CONFIG.userId)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取后端 API 地址
|
||||
*/
|
||||
export function getApiUrl(path: string): string {
|
||||
const { backendUrl } = getConfig();
|
||||
// 确保 URL 格式正确
|
||||
const baseUrl = backendUrl.endsWith('/') ? backendUrl.slice(0, -1) : backendUrl;
|
||||
const apiPath = path.startsWith('/') ? path : `/${path}`;
|
||||
return `${baseUrl}${apiPath}`;
|
||||
}
|
||||
Reference in New Issue
Block a user