// Namespace for talking to Claude through a gated Backend-for-Frontend Worker. // // EXAMPLE CODE. Placeholders only, point baseURL at your own Worker. // Requires Xcode 27 / OS 27 betas and the ClaudeForFoundationModels package. // // A caseless enum is Swift's idiomatic namespace: it groups the static members // across these files and cannot be instantiated (unlike a struct, which can). // One concern per file: entitlement, App Attest, headers, and errors each live // in their own extension. import Foundation import FoundationModels import ClaudeForFoundationModels enum ClaudeBFF { /// The BFF endpoint host. The Foundation Models client appends the Messages /// path, so the Worker sees "/v1/messages", the one upstream path it allows. static let baseURL = URL(string: "https://bff.example.com")! /// Headers the BFF reads each credential from. static let transactionHeader = "X-IAP-Transaction" static let assertionHeader = "X-App-Attest-Assertion" static let keyIdHeader = "X-App-Attest-Key-Id" /// Convenience: gather credentials, build a session, and respond. static func respond(to prompt: String) async throws -> String { let session = LanguageModelSession(model: try await model()) let response = try await session.respond(to: prompt) return response.content } }