Implements a Swift gRPC server that exposes Apple's Foundation Models (Apple Intelligence) over the network for LAN access. Features: - Complete: Unary RPC for prompt/response - StreamComplete: Server streaming RPC for token-by-token responses - Health: Check model availability - Optional API key authentication via gRPC metadata - Configurable host/port via CLI args or environment variables Requires macOS 26 (Tahoe) with Apple Intelligence enabled. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
28 lines
859 B
Swift
28 lines
859 B
Swift
import Foundation
|
|
|
|
/// Server configuration loaded from environment variables
|
|
struct Config {
|
|
/// Host to bind the server to (default: 0.0.0.0 for LAN access)
|
|
let host: String
|
|
|
|
/// Port to listen on (default: 50051)
|
|
let port: Int
|
|
|
|
/// Optional API key for authentication via gRPC metadata
|
|
let apiKey: String?
|
|
|
|
/// Initialize configuration from environment variables
|
|
init() {
|
|
self.host = ProcessInfo.processInfo.environment["GRPC_HOST"] ?? "0.0.0.0"
|
|
self.port = Int(ProcessInfo.processInfo.environment["GRPC_PORT"] ?? "50051") ?? 50051
|
|
self.apiKey = ProcessInfo.processInfo.environment["API_KEY"]
|
|
}
|
|
|
|
/// Initialize with explicit values (for testing)
|
|
init(host: String, port: Int, apiKey: String? = nil) {
|
|
self.host = host
|
|
self.port = port
|
|
self.apiKey = apiKey
|
|
}
|
|
}
|