Files
qwen-code/packages/vscode-ide-companion/src/cli/cliContextManager.ts
yiliang114 8bc9bea5a1 feat(cli): 添加 CLI 版本检测和会话验证功能
- 新增 CLI 版本检测功能,支持检测 CLI 版本并缓存结果
- 实现会话验证方法,用于检查当前会话是否有效
- 在连接处理中集成 CLI 版本检测和会话验证逻辑
- 优化 WebViewProvider 中的初始化流程,支持背景初始化
- 更新消息处理逻辑,增加与 CLI 相关的错误处理
2025-11-28 01:13:57 +08:00

127 lines
2.9 KiB
TypeScript

/**
* @license
* Copyright 2025 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/
import type { CliFeatureFlags, CliVersionInfo } from './cliVersionManager.js';
/**
* CLI Context Manager
*
* Manages the current CLI context including version information and feature availability
*/
export class CliContextManager {
private static instance: CliContextManager;
private currentVersionInfo: CliVersionInfo | null = null;
private constructor() {}
/**
* Get singleton instance
*/
static getInstance(): CliContextManager {
if (!CliContextManager.instance) {
CliContextManager.instance = new CliContextManager();
}
return CliContextManager.instance;
}
/**
* Set current CLI version information
*
* @param versionInfo - CLI version information
*/
setCurrentVersionInfo(versionInfo: CliVersionInfo): void {
this.currentVersionInfo = versionInfo;
}
/**
* Get current CLI version information
*
* @returns Current CLI version information or null if not set
*/
getCurrentVersionInfo(): CliVersionInfo | null {
return this.currentVersionInfo;
}
/**
* Get current CLI feature flags
*
* @returns Current CLI feature flags or default flags if not set
*/
getCurrentFeatures(): CliFeatureFlags {
if (this.currentVersionInfo) {
return this.currentVersionInfo.features;
}
// Return default feature flags (all disabled)
return {
supportsSessionList: false,
supportsSessionLoad: false,
supportsSessionSave: false,
};
}
/**
* Check if current CLI supports session/list method
*
* @returns Whether session/list is supported
*/
supportsSessionList(): boolean {
return this.getCurrentFeatures().supportsSessionList;
}
/**
* Check if current CLI supports session/load method
*
* @returns Whether session/load is supported
*/
supportsSessionLoad(): boolean {
return this.getCurrentFeatures().supportsSessionLoad;
}
/**
* Check if current CLI supports session/save method
*
* @returns Whether session/save is supported
*/
supportsSessionSave(): boolean {
return this.getCurrentFeatures().supportsSessionSave;
}
/**
* Check if CLI is installed and detected
*
* @returns Whether CLI is installed
*/
isCliInstalled(): boolean {
return this.currentVersionInfo?.detectionResult.isInstalled ?? false;
}
/**
* Get CLI version string
*
* @returns CLI version string or undefined if not detected
*/
getCliVersion(): string | undefined {
return this.currentVersionInfo?.version;
}
/**
* Check if CLI version is supported
*
* @returns Whether CLI version is supported
*/
isCliVersionSupported(): boolean {
return this.currentVersionInfo?.isSupported ?? false;
}
/**
* Clear current CLI context
*/
clearContext(): void {
this.currentVersionInfo = null;
}
}