import Foundation // ───────────────────────────────────────────────────────────── // Cross-Device Communication Protocol // ───────────────────────────────────────────────────────────── /// Device node in the cluster public struct DeviceNode: Codable, Sendable { public let id: String public let host: String public let port: Int public let capabilities: DeviceCapabilities public var status: DeviceStatus public var load: Double // 0.0 to 1.0 public init( id: String, host: String, port: Int, capabilities: DeviceCapabilities, status: DeviceStatus = .healthy, load: Double = 0.0 ) { self.id = id self.host = host self.port = port self.capabilities = capabilities self.status = status self.load = load } public var baseURL: String { "http://\(host):\(port)" } } /// Device capabilities public struct DeviceCapabilities: Codable, Sendable { public let maxConcurrency: Int public let supportedModels: [String] public let hasGPU: Bool public let memoryGB: Int public init( maxConcurrency: Int = 4, supportedModels: [String] = [], hasGPU: Bool = true, memoryGB: Int = 16 ) { self.maxConcurrency = maxConcurrency self.supportedModels = supportedModels self.hasGPU = hasGPU self.memoryGB = memoryGB } } /// Device status public enum DeviceStatus: String, Codable, Sendable { case healthy case degraded case unhealthy case offline } /// Cross-device request public struct CrossDeviceRequest: Codable, Sendable { public let id: String public let endpoint: String public let method: String public let body: Data? public let timeout: TimeInterval public init( id: String = UUID().uuidString, endpoint: String, method: String = "POST", body: Data? = nil, timeout: TimeInterval = 30 ) { self.id = id self.endpoint = endpoint self.method = method self.body = body self.timeout = timeout } } /// Cross-device response public struct CrossDeviceResponse: Codable, Sendable { public let requestId: String public let statusCode: Int public let body: Data? public let latency: TimeInterval public let nodeId: String public init( requestId: String, statusCode: Int, body: Data? = nil, latency: TimeInterval, nodeId: String ) { self.requestId = requestId self.statusCode = statusCode self.body = body self.latency = latency self.nodeId = nodeId } }