()
| 1668 | } |
| 1669 | |
| 1670 | private async updateChatSubscription(): Promise<void> { |
| 1671 | if (!this.isWebviewReady || !this.view) { |
| 1672 | return; |
| 1673 | } |
| 1674 | |
| 1675 | const workspaceId = this.selectedWorkspaceId; |
| 1676 | if (!workspaceId || this.connectionStatus.mode !== "api") { |
| 1677 | this.subscriptionAbort?.abort(); |
| 1678 | this.subscriptionAbort = null; |
| 1679 | this.subscribedWorkspaceId = null; |
| 1680 | return; |
| 1681 | } |
| 1682 | |
| 1683 | if ( |
| 1684 | this.subscribedWorkspaceId === workspaceId && |
| 1685 | this.subscriptionAbort && |
| 1686 | !this.subscriptionAbort.signal.aborted |
| 1687 | ) { |
| 1688 | return; |
| 1689 | } |
| 1690 | |
| 1691 | this.subscriptionAbort?.abort(); |
| 1692 | |
| 1693 | const controller = new AbortController(); |
| 1694 | this.subscriptionAbort = controller; |
| 1695 | this.subscribedWorkspaceId = workspaceId; |
| 1696 | |
| 1697 | this.postMessage({ type: "chatReset", workspaceId }); |
| 1698 | |
| 1699 | const api = await tryGetApiClient(this.context); |
| 1700 | if ("failure" in api) { |
| 1701 | // Drop back to file mode (chat disabled). |
| 1702 | this.connectionStatus = { |
| 1703 | mode: "file", |
| 1704 | baseUrl: api.failure.baseUrl, |
| 1705 | error: `${describeFailure(api.failure)}. (${api.failure.error})`, |
| 1706 | }; |
| 1707 | this.postMessage({ type: "connectionStatus", status: this.connectionStatus }); |
| 1708 | this.postMessage({ |
| 1709 | type: "uiNotice", |
| 1710 | level: "error", |
| 1711 | message: this.connectionStatus.error ?? "mux server unavailable", |
| 1712 | }); |
| 1713 | |
| 1714 | controller.abort(); |
| 1715 | if (this.subscriptionAbort === controller) { |
| 1716 | this.subscriptionAbort = null; |
| 1717 | this.subscribedWorkspaceId = null; |
| 1718 | } |
| 1719 | return; |
| 1720 | } |
| 1721 | |
| 1722 | try { |
| 1723 | const iterator = await api.client.workspace.onChat( |
| 1724 | { workspaceId }, |
| 1725 | { signal: controller.signal } |
| 1726 | ); |
| 1727 |
no test coverage detected