(opts: {
json?: boolean
text?: boolean
})
| 230 | } |
| 231 | |
| 232 | export async function authStatus(opts: { |
| 233 | json?: boolean |
| 234 | text?: boolean |
| 235 | }): Promise<void> { |
| 236 | const { source: authTokenSource, hasToken } = getAuthTokenSource() |
| 237 | const { source: apiKeySource } = getAnthropicApiKeyWithSource() |
| 238 | const hasApiKeyEnvVar = |
| 239 | !!process.env.ANTHROPIC_API_KEY && !isRunningOnHomespace() |
| 240 | const oauthAccount = getOauthAccountInfo() |
| 241 | const subscriptionType = getSubscriptionType() |
| 242 | const using3P = isUsing3PServices() |
| 243 | const loggedIn = |
| 244 | hasToken || apiKeySource !== 'none' || hasApiKeyEnvVar || using3P |
| 245 | |
| 246 | // Determine auth method |
| 247 | let authMethod: string = 'none' |
| 248 | if (using3P) { |
| 249 | authMethod = 'third_party' |
| 250 | } else if (authTokenSource === 'claude.ai') { |
| 251 | authMethod = 'claude.ai' |
| 252 | } else if (authTokenSource === 'apiKeyHelper') { |
| 253 | authMethod = 'api_key_helper' |
| 254 | } else if (authTokenSource !== 'none') { |
| 255 | authMethod = 'oauth_token' |
| 256 | } else if (apiKeySource === 'ANTHROPIC_API_KEY' || hasApiKeyEnvVar) { |
| 257 | authMethod = 'api_key' |
| 258 | } else if (apiKeySource === '/login managed key') { |
| 259 | authMethod = 'claude.ai' |
| 260 | } |
| 261 | |
| 262 | if (opts.text) { |
| 263 | const properties = [ |
| 264 | ...buildAccountProperties(), |
| 265 | ...buildAPIProviderProperties(), |
| 266 | ] |
| 267 | let hasAuthProperty = false |
| 268 | for (const prop of properties) { |
| 269 | const value = |
| 270 | typeof prop.value === 'string' |
| 271 | ? prop.value |
| 272 | : Array.isArray(prop.value) |
| 273 | ? prop.value.join(', ') |
| 274 | : null |
| 275 | if (value === null || value === 'none') { |
| 276 | continue |
| 277 | } |
| 278 | hasAuthProperty = true |
| 279 | if (prop.label) { |
| 280 | process.stdout.write(`${prop.label}: ${value}\n`) |
| 281 | } else { |
| 282 | process.stdout.write(`${value}\n`) |
| 283 | } |
| 284 | } |
| 285 | if (!hasAuthProperty && hasApiKeyEnvVar) { |
| 286 | process.stdout.write('API key: ANTHROPIC_API_KEY\n') |
| 287 | } |
| 288 | if (!loggedIn) { |
| 289 | process.stdout.write( |
no test coverage detected