mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-22 01:37:50 +00:00
feat(cli): 添加 CLI 版本检测和会话验证功能
- 新增 CLI 版本检测功能,支持检测 CLI 版本并缓存结果 - 实现会话验证方法,用于检查当前会话是否有效 - 在连接处理中集成 CLI 版本检测和会话验证逻辑 - 优化 WebViewProvider 中的初始化流程,支持背景初始化 - 更新消息处理逻辑,增加与 CLI 相关的错误处理
This commit is contained in:
@@ -99,7 +99,40 @@ export class QwenAgentManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get session list
|
||||
* Validate if current session is still active
|
||||
* This is a lightweight check to verify session validity
|
||||
*
|
||||
* @returns True if session is valid, false otherwise
|
||||
*/
|
||||
async validateCurrentSession(): Promise<boolean> {
|
||||
try {
|
||||
// If we don't have a current session, it's definitely not valid
|
||||
if (!this.connection.currentSessionId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Try to get session list to verify our session still exists
|
||||
const sessions = await this.getSessionList();
|
||||
const currentSessionId = this.connection.currentSessionId;
|
||||
|
||||
// Check if our current session exists in the session list
|
||||
const sessionExists = sessions.some(
|
||||
(session: Record<string, unknown>) =>
|
||||
session.id === currentSessionId ||
|
||||
session.sessionId === currentSessionId,
|
||||
);
|
||||
|
||||
return sessionExists;
|
||||
} catch (error) {
|
||||
console.warn('[QwenAgentManager] Session validation failed:', error);
|
||||
// If we can't validate, assume session is invalid
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get session list with version-aware strategy
|
||||
* First tries ACP method if CLI version supports it, falls back to file system method
|
||||
*
|
||||
* @returns Session list
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,8 @@ import * as vscode from 'vscode';
|
||||
import type { AcpConnection } from '../acp/acpConnection.js';
|
||||
import type { QwenSessionReader } from '../services/qwenSessionReader.js';
|
||||
import type { AuthStateManager } from '../auth/authStateManager.js';
|
||||
import { CliVersionManager } from '../cli/cliVersionManager.js';
|
||||
import { CliContextManager } from '../cli/cliContextManager.js';
|
||||
|
||||
/**
|
||||
* Qwen Connection Handler class
|
||||
@@ -41,6 +43,25 @@ export class QwenConnectionHandler {
|
||||
console.log(`[QwenAgentManager] Call stack:\n${new Error().stack}`);
|
||||
console.log(`========================================\n`);
|
||||
|
||||
// Check CLI version and features
|
||||
const cliVersionManager = CliVersionManager.getInstance();
|
||||
const versionInfo = await cliVersionManager.detectCliVersion();
|
||||
console.log('[QwenAgentManager] CLI version info:', versionInfo);
|
||||
|
||||
// Store CLI context
|
||||
const cliContextManager = CliContextManager.getInstance();
|
||||
cliContextManager.setCurrentVersionInfo(versionInfo);
|
||||
|
||||
// Show warning if CLI version is below minimum requirement
|
||||
if (!versionInfo.isSupported) {
|
||||
console.warn(
|
||||
`[QwenAgentManager] CLI version ${versionInfo.version} is below minimum required version ${'0.2.4'}`,
|
||||
);
|
||||
// vscode.window.showWarningMessage(
|
||||
// `Qwen Code CLI version ${versionInfo.version} is below the minimum required version. Some features may not work properly. Please upgrade to version 0.2.4 or later.`,
|
||||
// );
|
||||
}
|
||||
|
||||
const config = vscode.workspace.getConfiguration('qwenCode');
|
||||
const cliPath = config.get<string>('qwen.cliPath', 'qwen');
|
||||
const openaiApiKey = config.get<string>('qwen.openaiApiKey', '');
|
||||
|
||||
Reference in New Issue
Block a user