()
| 1381 | } |
| 1382 | |
| 1383 | private async refreshWorkspaces(): Promise<void> { |
| 1384 | const startedAt = Date.now(); |
| 1385 | const generation = ++this.refreshWorkspacesGeneration; |
| 1386 | muxLogDebug("mux.chatView: refreshWorkspaces start", { traceId: this.traceId, generation }); |
| 1387 | |
| 1388 | try { |
| 1389 | const result = await getWorkspacesForSidebar(this.context); |
| 1390 | |
| 1391 | if (generation !== this.refreshWorkspacesGeneration) { |
| 1392 | muxLogDebug("mux.chatView: refreshWorkspaces stale result discarded", { |
| 1393 | traceId: this.traceId, |
| 1394 | generation, |
| 1395 | }); |
| 1396 | return; |
| 1397 | } |
| 1398 | |
| 1399 | this.connectionStatus = result.status; |
| 1400 | this.workspaces = result.workspaces; |
| 1401 | this.workspacesById = new Map(this.workspaces.map((w) => [w.id, w])); |
| 1402 | |
| 1403 | this.postMessage({ type: "connectionStatus", status: this.connectionStatus }); |
| 1404 | this.postMessage({ type: "workspaces", workspaces: this.workspaces.map(toUiWorkspace) }); |
| 1405 | |
| 1406 | if (this.selectedWorkspaceId && !this.workspacesById.has(this.selectedWorkspaceId)) { |
| 1407 | await this.setSelectedWorkspaceId(null); |
| 1408 | } |
| 1409 | |
| 1410 | // Intentionally do not auto-select a workspace; the user must explicitly choose one. |
| 1411 | await this.updateChatSubscription(); |
| 1412 | |
| 1413 | muxLogDebug("mux.chatView: refreshWorkspaces done", { |
| 1414 | traceId: this.traceId, |
| 1415 | durationMs: Date.now() - startedAt, |
| 1416 | workspaceCount: this.workspaces.length, |
| 1417 | connectionMode: this.connectionStatus.mode, |
| 1418 | hasError: Boolean(this.connectionStatus.error), |
| 1419 | }); |
| 1420 | } catch (error) { |
| 1421 | muxLogError("mux.chatView: refreshWorkspaces failed", { |
| 1422 | traceId: this.traceId, |
| 1423 | durationMs: Date.now() - startedAt, |
| 1424 | error: formatError(error), |
| 1425 | }); |
| 1426 | |
| 1427 | const message = `Failed to load mux workspaces. (${formatError(error)})`; |
| 1428 | |
| 1429 | this.connectionStatus = { mode: "file", error: message }; |
| 1430 | this.workspaces = []; |
| 1431 | this.workspacesById = new Map(); |
| 1432 | |
| 1433 | this.subscriptionAbort?.abort(); |
| 1434 | this.subscriptionAbort = null; |
| 1435 | this.subscribedWorkspaceId = null; |
| 1436 | |
| 1437 | this.selectedWorkspaceId = null; |
| 1438 | await this.context.workspaceState.update(SELECTED_WORKSPACE_STATE_KEY, undefined); |
| 1439 | |
| 1440 | this.postMessage({ type: "connectionStatus", status: this.connectionStatus }); |
no test coverage detected