mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 09:17:53 +00:00
fix(vscode-ide-companion): slight delay to ensure auth state settlement
This commit is contained in:
@@ -149,6 +149,50 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
return this.isSavingCheckpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt user to login and invoke the registered login handler/command.
|
||||
* Returns true if a login was initiated.
|
||||
*/
|
||||
private async promptLogin(message: string): Promise<boolean> {
|
||||
const result = await vscode.window.showWarningMessage(message, 'Login Now');
|
||||
if (result === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt user to login or view offline. Returns 'login', 'offline', or 'dismiss'.
|
||||
* When login is chosen, it triggers the login handler/command.
|
||||
*/
|
||||
private async promptLoginOrOffline(
|
||||
message: string,
|
||||
): Promise<'login' | 'offline' | 'dismiss'> {
|
||||
const selection = await vscode.window.showWarningMessage(
|
||||
message,
|
||||
'Login Now',
|
||||
'View Offline',
|
||||
);
|
||||
|
||||
if (selection === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
return 'login';
|
||||
}
|
||||
if (selection === 'View Offline') {
|
||||
return 'offline';
|
||||
}
|
||||
return 'dismiss';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle send message request
|
||||
*/
|
||||
@@ -271,23 +315,7 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
console.warn('[SessionMessageHandler] Agent not connected');
|
||||
|
||||
// Show non-modal notification with Login button
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
'You need to login first to use Qwen Code.',
|
||||
'Login Now',
|
||||
);
|
||||
|
||||
if (result === 'Login Now') {
|
||||
// Use login handler directly
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
// Fallback to command
|
||||
vscode.window.showInformationMessage(
|
||||
'Please wait while we connect to Qwen Code...',
|
||||
);
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
}
|
||||
await this.promptLogin('You need to login first to use Qwen Code.');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -308,17 +336,9 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
errorMsg.includes('Authentication required') ||
|
||||
errorMsg.includes('(code: -32000)')
|
||||
) {
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
await this.promptLogin(
|
||||
'Your login session has expired or is invalid. Please login again to continue using Qwen Code.',
|
||||
'Login Now',
|
||||
);
|
||||
if (result === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
vscode.window.showErrorMessage(`Failed to create session: ${errorMsg}`);
|
||||
@@ -426,19 +446,10 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
errorMsg.includes('Invalid token')
|
||||
) {
|
||||
// Show a more user-friendly error message for expired sessions
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
await this.promptLogin(
|
||||
'Your login session has expired or is invalid. Please login again to continue using Qwen Code.',
|
||||
'Login Now',
|
||||
);
|
||||
|
||||
if (result === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
}
|
||||
|
||||
// Send a specific error to the webview for better UI handling
|
||||
this.sendToWebView({
|
||||
type: 'sessionExpired',
|
||||
@@ -463,17 +474,10 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
|
||||
// Ensure connection (login) before creating a new session
|
||||
if (!this.agentManager.isConnected) {
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
const proceeded = await this.promptLogin(
|
||||
'You need to login before creating a new session.',
|
||||
'Login Now',
|
||||
);
|
||||
if (result === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
} else {
|
||||
if (!proceeded) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -524,19 +528,10 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
errorMsg.includes('No active ACP session')
|
||||
) {
|
||||
// Show a more user-friendly error message for expired sessions
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
await this.promptLogin(
|
||||
'Your login session has expired or is invalid. Please login again to create a new session.',
|
||||
'Login Now',
|
||||
);
|
||||
|
||||
if (result === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
}
|
||||
|
||||
// Send a specific error to the webview for better UI handling
|
||||
this.sendToWebView({
|
||||
type: 'sessionExpired',
|
||||
@@ -560,19 +555,11 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
|
||||
// If not connected yet, offer to login or view offline
|
||||
if (!this.agentManager.isConnected) {
|
||||
const selection = await vscode.window.showWarningMessage(
|
||||
const choice = await this.promptLoginOrOffline(
|
||||
'You are not logged in. Login now to fully restore this session, or view it offline.',
|
||||
'Login Now',
|
||||
'View Offline',
|
||||
);
|
||||
|
||||
if (selection === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
} else if (selection === 'View Offline') {
|
||||
if (choice === 'offline') {
|
||||
// Show messages from local cache only
|
||||
const messages =
|
||||
await this.agentManager.getSessionMessages(sessionId);
|
||||
@@ -585,7 +572,7 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
'Showing cached session content. Login to interact with the AI.',
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
} else if (choice !== 'login') {
|
||||
// User dismissed; do nothing
|
||||
return;
|
||||
}
|
||||
@@ -672,19 +659,10 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
errorMsg.includes('No active ACP session')
|
||||
) {
|
||||
// Show a more user-friendly error message for expired sessions
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
await this.promptLogin(
|
||||
'Your login session has expired or is invalid. Please login again to switch sessions.',
|
||||
'Login Now',
|
||||
);
|
||||
|
||||
if (result === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
}
|
||||
|
||||
// Send a specific error to the webview for better UI handling
|
||||
this.sendToWebView({
|
||||
type: 'sessionExpired',
|
||||
@@ -741,19 +719,10 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
createErrorMsg.includes('No active ACP session')
|
||||
) {
|
||||
// Show a more user-friendly error message for expired sessions
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
await this.promptLogin(
|
||||
'Your login session has expired or is invalid. Please login again to switch sessions.',
|
||||
'Login Now',
|
||||
);
|
||||
|
||||
if (result === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
}
|
||||
|
||||
// Send a specific error to the webview for better UI handling
|
||||
this.sendToWebView({
|
||||
type: 'sessionExpired',
|
||||
@@ -790,19 +759,10 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
errorMsg.includes('No active ACP session')
|
||||
) {
|
||||
// Show a more user-friendly error message for expired sessions
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
await this.promptLogin(
|
||||
'Your login session has expired or is invalid. Please login again to switch sessions.',
|
||||
'Login Now',
|
||||
);
|
||||
|
||||
if (result === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
}
|
||||
|
||||
// Send a specific error to the webview for better UI handling
|
||||
this.sendToWebView({
|
||||
type: 'sessionExpired',
|
||||
@@ -854,19 +814,10 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
errorMsg.includes('No active ACP session')
|
||||
) {
|
||||
// Show a more user-friendly error message for expired sessions
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
await this.promptLogin(
|
||||
'Your login session has expired or is invalid. Please login again to view sessions.',
|
||||
'Login Now',
|
||||
);
|
||||
|
||||
if (result === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
}
|
||||
|
||||
// Send a specific error to the webview for better UI handling
|
||||
this.sendToWebView({
|
||||
type: 'sessionExpired',
|
||||
@@ -918,19 +869,10 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
errorMsg.includes('No active ACP session')
|
||||
) {
|
||||
// Show a more user-friendly error message for expired sessions
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
await this.promptLogin(
|
||||
'Your login session has expired or is invalid. Please login again to save sessions.',
|
||||
'Login Now',
|
||||
);
|
||||
|
||||
if (result === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
}
|
||||
|
||||
// Send a specific error to the webview for better UI handling
|
||||
this.sendToWebView({
|
||||
type: 'sessionExpired',
|
||||
@@ -966,19 +908,10 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
errorMsg.includes('No active ACP session')
|
||||
) {
|
||||
// Show a more user-friendly error message for expired sessions
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
await this.promptLogin(
|
||||
'Your login session has expired or is invalid. Please login again to save sessions.',
|
||||
'Login Now',
|
||||
);
|
||||
|
||||
if (result === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
}
|
||||
|
||||
// Send a specific error to the webview for better UI handling
|
||||
this.sendToWebView({
|
||||
type: 'sessionExpired',
|
||||
@@ -1031,19 +964,11 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
try {
|
||||
// If not connected, offer to login or view offline
|
||||
if (!this.agentManager.isConnected) {
|
||||
const selection = await vscode.window.showWarningMessage(
|
||||
const choice = await this.promptLoginOrOffline(
|
||||
'You are not logged in. Login now to fully restore this session, or view it offline.',
|
||||
'Login Now',
|
||||
'View Offline',
|
||||
);
|
||||
|
||||
if (selection === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
} else if (selection === 'View Offline') {
|
||||
if (choice === 'offline') {
|
||||
const messages =
|
||||
await this.agentManager.getSessionMessages(sessionId);
|
||||
this.currentConversationId = sessionId;
|
||||
@@ -1055,7 +980,7 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
'Showing cached session content. Login to interact with the AI.',
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
} else if (choice !== 'login') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1089,19 +1014,10 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
errorMsg.includes('No active ACP session')
|
||||
) {
|
||||
// Show a more user-friendly error message for expired sessions
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
await this.promptLogin(
|
||||
'Your login session has expired or is invalid. Please login again to resume sessions.',
|
||||
'Login Now',
|
||||
);
|
||||
|
||||
if (result === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
}
|
||||
|
||||
// Send a specific error to the webview for better UI handling
|
||||
this.sendToWebView({
|
||||
type: 'sessionExpired',
|
||||
@@ -1140,19 +1056,10 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
||||
errorMsg.includes('No active ACP session')
|
||||
) {
|
||||
// Show a more user-friendly error message for expired sessions
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
await this.promptLogin(
|
||||
'Your login session has expired or is invalid. Please login again to resume sessions.',
|
||||
'Login Now',
|
||||
);
|
||||
|
||||
if (result === 'Login Now') {
|
||||
if (this.loginHandler) {
|
||||
await this.loginHandler();
|
||||
} else {
|
||||
await vscode.commands.executeCommand('qwen-code.login');
|
||||
}
|
||||
}
|
||||
|
||||
// Send a specific error to the webview for better UI handling
|
||||
this.sendToWebView({
|
||||
type: 'sessionExpired',
|
||||
|
||||
Reference in New Issue
Block a user