File size: 761 Bytes
7b2dfc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@preconcurrency import Darwin
import Foundation

struct SystemResourceSnapshotProvider: Sendable {
  func snapshot() -> AssistantResourceSnapshot {
    let processInfo = ProcessInfo.processInfo
    return AssistantResourceSnapshot(
      thermalLevel: thermalLevel(processInfo.thermalState),
      lowPowerModeEnabled: processInfo.isLowPowerModeEnabled,
      availableMemoryBytes: UInt64(os_proc_available_memory())
    )
  }

  private func thermalLevel(
    _ state: ProcessInfo.ThermalState
  ) -> AssistantThermalLevel {
    switch state {
    case .nominal:
      return .nominal
    case .fair:
      return .fair
    case .serious:
      return .serious
    case .critical:
      return .critical
    @unknown default:
      return .unknown
    }
  }
}