Files
markbaseengine/Sources/MarkBaseServer/CrossDeviceProtocol.swift
T
MarkBase Admin 8a66b9086a
CI / build (push) Has been cancelled
CI / unit-tests (push) Has been cancelled
CI / lint (push) Has been cancelled
v2: Initial clean branch with unit tests + CI/CD pipeline
- Started from ac75faa (initial E4B-MarkBase integration)
- Kept Sources/ (all engine code) + Package.swift + .gitignore
- Removed all ad-hoc tests, documentation, scripts, Python files
- Added Tests/00_Unit/ (MathTest, TokenizerTest, SamplerTest)
- Added .gitea/workflows/ci.yaml (build + unit tests + lint)
- Added Scripts/check_resources.sh (memory-aware test runner)
- Added Tests/Manifest.json (resource requirements for all tests)
- Focus: 4-bit quantized models only
2026-07-05 13:29:25 +08:00

110 lines
2.9 KiB
Swift

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
}
}