// // GetRemoteInfo.swift // shortcut // // Created by Bailey Townsend on 7/2/25. // import Foundation struct GetRemoteInfo { public static func getRemoteRepoInfo(possibleRepo: String, atProtoManager: AtProtocolManager) async throws -> RemoteRepoInfo { let lowerCaseRepo = possibleRepo.lowercased() var repo = "" var pdsUrl = "https://bsky.social" var handle = "" if lowerCaseRepo.hasPrefix("did:") { do { let didDoc = try await atProtoManager.resolveDidDocument(did: lowerCaseRepo) repo = didDoc.id if let pds = didDoc.getPDSEndpoint() { pdsUrl = pds.absoluteString } if let knownAs = didDoc.alsoKnownAs?.first { handle = knownAs } } catch { throw GenericIntentError.message("Could not resolve DID document") } } else { let cleanedHandle = lowerCaseRepo.replacingOccurrences(of: "@", with: "") do { let didDoc = try await atProtoManager.resolveDidDocument(handle: cleanedHandle) repo = didDoc.id if let pds = didDoc.getPDSEndpoint() { pdsUrl = pds.absoluteString } if let knownAs = didDoc.alsoKnownAs?.first { handle = knownAs } } catch let error as LoginError { switch error { case LoginError.handleDoesNotResolve: throw GenericIntentError.message("Cannot resolve handle to a DID") case .didDocumentNotFound: throw GenericIntentError.message("Cannot resolve DID document") } } } return RemoteRepoInfo( repo: repo, pdsURL: pdsUrl, handle: handle.replacingOccurrences(of: "at://", with: "")) } } struct RemoteRepoInfo { let repo: String let pdsURL: String let handle: String }