mana-swift-llm/Sources/ManaLLM/LLMDownloadOverCellularStore.swift
till 7bbde8ed1a v0.2.0 — Lift LLMBackendPreferenceStore + LLMDownloadOverCellularStore aus memoro-native
Stores leben jetzt im Package mit App-übergreifenden Keys
(mana.llm.backend, mana.llm.allowCellular). Auto-Migration aus
memoro.* Legacy-Keys beim ersten Read (memoro.llmBackend,
memoro.onDeviceLLMEnabled Bool-Toggle, memoro.llmDownloadOverCellular).

Ermöglicht ManaLLMUI in mana-swift-ui 0.8.0 als geteilte Settings-
Schicht für alle 4 Konsumenten (Memoro, Pageta, Comicello, Herbatrium).

Außerdem:
- LLMBackend.removeCachedModel() als Protocol-Methode mit Default-
  No-Op. GemmaBackend überschreibt (async throws statt throws).
- 13 neue Tests in LLMPreferenceStoresTests (.serialized wegen
  UserDefaults.standard).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 14:19:46 +02:00

43 lines
1.4 KiB
Swift

import Foundation
/// WiFi-only-Default für große Modell-Downloads (Gemma 4 E2B ~1.3 GB,
/// E4B ~2.5 GB). User kann via Settings-Toggle auch Mobilfunk erlauben.
///
/// Wert pro App in `UserDefaults.standard`. Default `false`. Apps
/// reichen den Wert beim Erzeugen eines `LLMRouter` als
/// `gemmaAllowsCellular`-Parameter weiter:
///
/// ```swift
/// LLMRouter(
/// preferred: [LLMBackendPreferenceStore.current],
/// gemmaAllowsCellular: LLMDownloadOverCellularStore.isAllowed
/// )
/// ```
///
/// **Legacy-Migration:** Memoros bisheriger Key
/// `memoro.llmDownloadOverCellular` wird beim ersten Read einmalig in
/// `mana.llm.allowCellular` überführt.
public enum LLMDownloadOverCellularStore {
private static let key = "mana.llm.allowCellular"
private static let legacyMemoroKey = "memoro.llmDownloadOverCellular"
public static var isAllowed: Bool {
// 1. Neuer Key
if UserDefaults.standard.object(forKey: key) != nil {
return UserDefaults.standard.bool(forKey: key)
}
// 2. Memoro-Legacy
if UserDefaults.standard.object(forKey: legacyMemoroKey) != nil {
let migrated = UserDefaults.standard.bool(forKey: legacyMemoroKey)
set(migrated)
UserDefaults.standard.removeObject(forKey: legacyMemoroKey)
return migrated
}
// 3. Default: WiFi-only
return false
}
public static func set(_ value: Bool) {
UserDefaults.standard.set(value, forKey: key)
}
}