import Foundation enum ClaudeAuthService { static func parseOAuthJSON(_ json: [String: Any], source: ClaudeCredentialSource = .credentialsFile) throws -> ClaudeOAuthCredentials { let oauth = json["claudeAiOauth"] as? [String: Any] guard let oauth, let accessToken = oauth["accessToken"] as? String, !accessToken.isEmpty else { throw ClaudeAuthError.tokenNotFound } var expiresAt: Date? if let expiresMs = oauth["expiresAt"] as? Double { expiresAt = Date(timeIntervalSince1970: expiresMs / 1000) } let subscriptionType = oauth["subscriptionType"] as? String return ClaudeOAuthCredentials( accessToken: accessToken, expiresAt: expiresAt, subscriptionType: subscriptionType, source: source ) } } enum ClaudeCredentialSource: String, Sendable { case credentialsFile case manual } enum ClaudeAuthError: Error, LocalizedError { case tokenNotFound var errorDescription: String? { switch self { case .tokenNotFound: "No OAuth token found." } } } struct ClaudeOAuthCredentials: Sendable { let accessToken: String let expiresAt: Date? let subscriptionType: String? let source: ClaudeCredentialSource }