// // UserAccountParameter.swift // shortcut // // Created by Bailey Townsend on 6/29/25. // import AppIntents import Foundation struct AtIdentifierAppEntity: AppEntity { //The users handle var id: UUID @Property var handle: String @Property var did: String static var typeDisplayName: LocalizedStringResource = "Saved AT Identifier" static var typeDescription: LocalizedStringResource? = "This is your saved user session that is created inside of the app" var displayRepresentation: AppIntents.DisplayRepresentation { DisplayRepresentation(title: LocalizedStringResource(stringLiteral: handle)) } static var typeDisplayRepresentation: TypeDisplayRepresentation = TypeDisplayRepresentation( name: LocalizedStringResource("AT Identifier")) static var defaultQuery = AtIdentifierAppEntityQuery() } struct AtIdentifierAppEntityQuery: EntityQuery { func entities(for identifiers: [UUID]) async throws -> [AtIdentifierAppEntity] { let atProtocolManager = AtProtocolManager() do { let sessions = try await atProtocolManager.getSessions(sessionIDs: identifiers) if sessions.isEmpty { return [] } return sessions.map { session in let userAccount: AtIdentifierAppEntity = AtIdentifierAppEntity(id: session.id) userAccount.handle = session.handle userAccount.did = session.sessionDID return userAccount } } // return identifiers.compactMap { SessionManager.session(for: $0) } catch { print(error) throw GenericIntentError.message( "Could not retrieve saved AT Identifiers. Please make sure you have logged in via the app" ) } } func suggestedEntities() async throws -> [AtIdentifierAppEntity] { let atProtocolManager = AtProtocolManager() do { let sessions = try await atProtocolManager.getAllSessions() if sessions.isEmpty { return [] } return sessions.map { session in let userAccount: AtIdentifierAppEntity = AtIdentifierAppEntity(id: session.id) userAccount.handle = session.handle userAccount.did = session.sessionDID return userAccount } } catch { throw GenericIntentError.message( "Could not retrieve saved AT Identifiers. Please make sure you have logged in via the app" ) } } }