Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions packages/cloud/src/bridge/BridgeOrchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,28 @@ export class BridgeOrchestrator {
return BridgeOrchestrator.instance
}

public static isEnabled(user?: CloudUserInfo | null, remoteControlEnabled?: boolean): boolean {
return !!(user?.id && user.extensionBridgeEnabled && remoteControlEnabled)
public static isEnabled(user: CloudUserInfo | null, remoteControlEnabled: boolean): boolean {
// Always disabled if signed out.
if (!user) {
return false
}

// Disabled by the user's organization?
if (!user.extensionBridgeEnabled) {
return false
}

// Disabled by the user?
if (!remoteControlEnabled) {
return false
}

return true
}

public static async connectOrDisconnect(
userInfo: CloudUserInfo | null,
remoteControlEnabled: boolean | undefined,
userInfo: CloudUserInfo,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? The connectOrDisconnect() method now requires a non-null userInfo parameter, but it's being called from ClineProvider.remoteControlEnabled() where userInfo could be null. This type mismatch could lead to runtime errors.

Consider either:

  1. Making userInfo nullable here: userInfo: CloudUserInfo | null
  2. Or ensuring all callers check for null before calling this method

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no type mismatches; the build would fail otherwise.

remoteControlEnabled: boolean,
options: BridgeOrchestratorOptions,
): Promise<void> {
if (BridgeOrchestrator.isEnabled(userInfo, remoteControlEnabled)) {
Expand Down
12 changes: 12 additions & 0 deletions src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2262,7 +2262,19 @@ export class ClineProvider
}

public async remoteControlEnabled(enabled: boolean) {
if (!enabled) {
await BridgeOrchestrator.disconnect()
return
}

const userInfo = CloudService.instance.getUserInfo()

if (!userInfo) {
this.log("[ClineProvider#remoteControlEnabled] Failed to get user info, disconnecting")
await BridgeOrchestrator.disconnect()
return
}

const config = await CloudService.instance.cloudAPI?.bridgeConfig().catch(() => undefined)

if (!config) {
Expand Down
9 changes: 4 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ export async function activate(context: vscode.ExtensionContext) {
if (data.state === "logged-out") {
try {
await provider.remoteControlEnabled(false)
cloudLogger("[CloudService] BridgeOrchestrator disconnected on logout")
} catch (error) {
cloudLogger(
`[CloudService] Failed to disconnect BridgeOrchestrator on logout: ${error instanceof Error ? error.message : String(error)}`,
`[authStateChangedHandler] remoteControlEnabled(false) failed: ${error instanceof Error ? error.message : String(error)}`,
)
}
}
Expand All @@ -151,7 +150,7 @@ export async function activate(context: vscode.ExtensionContext) {
provider.remoteControlEnabled(CloudService.instance.isTaskSyncEnabled())
} catch (error) {
cloudLogger(
`[CloudService] BridgeOrchestrator#connectOrDisconnect failed on settings change: ${error instanceof Error ? error.message : String(error)}`,
`[settingsUpdatedHandler] remoteControlEnabled failed: ${error instanceof Error ? error.message : String(error)}`,
)
}
}
Expand All @@ -163,15 +162,15 @@ export async function activate(context: vscode.ExtensionContext) {
postStateListener()

if (!CloudService.instance.cloudAPI) {
cloudLogger("[CloudService] CloudAPI is not initialized")
cloudLogger("[userInfoHandler] CloudAPI is not initialized")
return
}

try {
provider.remoteControlEnabled(CloudService.instance.isTaskSyncEnabled())
} catch (error) {
cloudLogger(
`[CloudService] BridgeOrchestrator#connectOrDisconnect failed on user change: ${error instanceof Error ? error.message : String(error)}`,
`[userInfoHandler] remoteControlEnabled failed: ${error instanceof Error ? error.message : String(error)}`,
)
}
}
Expand Down
Loading