(host: SlashCommandHost)
| 180 | } |
| 181 | |
| 182 | export async function handleLogoutCommand(host: SlashCommandHost): Promise<void> { |
| 183 | const oauthStatus = await host.harness.auth.status(DEFAULT_OAUTH_PROVIDER_NAME); |
| 184 | const hasOAuthToken = oauthStatus.providers.some( |
| 185 | (p) => p.providerName === DEFAULT_OAUTH_PROVIDER_NAME && p.hasToken, |
| 186 | ); |
| 187 | const config = await host.harness.getConfig(); |
| 188 | const hasManagedRemnant = |
| 189 | hasOAuthToken || config.providers[DEFAULT_OAUTH_PROVIDER_NAME] !== undefined; |
| 190 | const apiKeyProviderIds = Object.keys(config.providers ?? {}) |
| 191 | .filter((id) => id !== DEFAULT_OAUTH_PROVIDER_NAME) |
| 192 | .toSorted(); |
| 193 | |
| 194 | const options: ChoiceOption[] = []; |
| 195 | if (hasManagedRemnant) { |
| 196 | options.push({ |
| 197 | value: DEFAULT_OAUTH_PROVIDER_NAME, |
| 198 | label: PRODUCT_NAME, |
| 199 | description: 'OAuth login', |
| 200 | }); |
| 201 | } |
| 202 | for (const id of apiKeyProviderIds) { |
| 203 | const baseUrl = config.providers[id]?.baseUrl; |
| 204 | options.push({ |
| 205 | value: id, |
| 206 | label: id, |
| 207 | description: typeof baseUrl === 'string' && baseUrl.length > 0 ? baseUrl : undefined, |
| 208 | }); |
| 209 | } |
| 210 | |
| 211 | if (options.length === 0) { |
| 212 | host.showStatus('Nothing to logout.'); |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | const currentModel = host.state.appState.model.trim(); |
| 217 | const currentProvider = host.state.appState.availableModels[currentModel]?.provider; |
| 218 | |
| 219 | const target = await promptLogoutProviderSelection(host, options, currentProvider); |
| 220 | if (target === undefined) return; |
| 221 | |
| 222 | if (target === DEFAULT_OAUTH_PROVIDER_NAME) { |
| 223 | await host.harness.auth.logout(DEFAULT_OAUTH_PROVIDER_NAME); |
| 224 | } else { |
| 225 | await host.harness.removeProvider(target); |
| 226 | } |
| 227 | |
| 228 | if (target === currentProvider) { |
| 229 | await host.authFlow.refreshConfigAfterLogout(); |
| 230 | await host.authFlow.clearActiveSessionAfterLogout(); |
| 231 | } else { |
| 232 | const updated = await host.harness.getConfig({ reload: true }); |
| 233 | host.setAppState({ |
| 234 | availableModels: updated.models ?? {}, |
| 235 | availableProviders: updated.providers ?? {}, |
| 236 | }); |
| 237 | } |
| 238 | |
| 239 | host.track('logout', { provider: target }); |
no test coverage detected