Squashes the working tree that had accumulated on cloud-agent. Two strands of work, kept in one commit at the maintainer's request. Crash and stability (this session): - Subscribe to MetricKit so crash, hang, CPU, and disk-write diagnostics are recorded on device. Keyboard-extension memory kills are the most likely way a user loses the keyboard mid-sentence and iOS does not classify them as crashes, so they never reach App Store Connect. - Upload those reports to POST /v1/analytics/diagnostics from internal builds only (local Debug and TestFlight), reusing the analytics installation identifier and skipping entirely when analytics are off. App Store builds keep everything on device. - Shed the Chinese engine, English lexicon, and in-flight pipeline work at the 40 MiB and 48 MiB budget thresholds instead of waiting for a system memory warning that jetsam often preempts. - Install audio taps with the input node's live format through one shared adaptive resampler, so an audio-route change mid-recording no longer raises an uncatchable format-mismatch exception. Covers the dictation preview and the Mac recorder, which still used the pattern the Flow capture path had already moved away from. - Harden the librime bridge: never pass a nil string across a nonnull boundary when a user dictionary holds malformed UTF-8, null-check the engine API vector, and distrust a candidate count without its array. - Guard the expanded candidate grid against a list that shrinks while the collection view is still laying out against the previous count. - Resolve localized text without the App Group so the screen shown when that container is missing renders its message instead of crashing on launch, which is the one situation it exists to handle. - Gate CI on the App Group and Keychain wiring that the keyboard extension hard-depends on, with a self-test proving the check fails. Clipboard, reply, and semantics (pre-existing working tree): - Unify the reply center, refresh keyboard AI features, and add native event and reminder exporters. - Expand clipboard semantic routing with authored corpora and a product-blind holdout, plus the scripts that build and validate them. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
560 lines
27 KiB
Swift
560 lines
27 KiB
Swift
// SyncedAppSettingsV2.swift
|
|
// OSGKeyboard · Shared
|
|
//
|
|
// Versioned settings payload with per-field merge metadata. API keys are
|
|
// intentionally excluded — they sync through iCloud Keychain.
|
|
|
|
import Foundation
|
|
|
|
public struct SyncedAppSettingsV2: Codable, Equatable, Sendable {
|
|
public static let schemaVersion = 2
|
|
public static let kvsKey = "appSettings.v2"
|
|
|
|
public var schemaVersion: Int
|
|
public var providerId: SyncedField<String>
|
|
public var baseURL: SyncedField<String>
|
|
public var model: SyncedField<String>
|
|
/// Cloud ASR provider — independent from polish `providerId`.
|
|
public var asrProviderId: SyncedField<String>
|
|
public var asrBaseURL: SyncedField<String>
|
|
public var asrModel: SyncedField<String>
|
|
public var modeId: SyncedField<String>
|
|
public var localeId: SyncedField<String>
|
|
public var engineMode: SyncedField<String>
|
|
public var hasAcknowledgedCloudSharing: SyncedField<Bool>
|
|
public var uiLanguage: SyncedField<AppUILanguage>
|
|
public var translationTargetLocaleId: SyncedField<String>
|
|
public var handednessPreference: SyncedField<HandednessPreference>
|
|
public var cursorDragNavigationEnabled: SyncedField<Bool>
|
|
public var keyboardHapticIntensity: SyncedField<KeyboardHapticIntensity>
|
|
public var polishIntensity: SyncedField<PolishIntensity>
|
|
public var aiResponseLength: SyncedField<AIResponseLength>
|
|
public var multipleReplyVariantsEnabled: SyncedField<Bool>
|
|
public var activePolishStyleId: SyncedField<String>
|
|
/// Distilled personal style for AI replies; empty means disabled.
|
|
public var personalReplyStyleId: SyncedField<String>
|
|
public var llmThinkingEnabled: SyncedField<Bool>
|
|
public var flowSkipAppSwitch: SyncedField<Bool>
|
|
public var flowInactivityDuration: SyncedField<FlowInactivityDuration>
|
|
|
|
public init(
|
|
schemaVersion: Int = Self.schemaVersion,
|
|
providerId: SyncedField<String>,
|
|
baseURL: SyncedField<String>,
|
|
model: SyncedField<String>,
|
|
asrProviderId: SyncedField<String>,
|
|
asrBaseURL: SyncedField<String>,
|
|
asrModel: SyncedField<String>,
|
|
modeId: SyncedField<String>,
|
|
localeId: SyncedField<String>,
|
|
engineMode: SyncedField<String>,
|
|
hasAcknowledgedCloudSharing: SyncedField<Bool>,
|
|
uiLanguage: SyncedField<AppUILanguage>,
|
|
translationTargetLocaleId: SyncedField<String>,
|
|
handednessPreference: SyncedField<HandednessPreference>,
|
|
cursorDragNavigationEnabled: SyncedField<Bool>,
|
|
keyboardHapticIntensity: SyncedField<KeyboardHapticIntensity>,
|
|
polishIntensity: SyncedField<PolishIntensity>? = nil,
|
|
aiResponseLength: SyncedField<AIResponseLength>? = nil,
|
|
multipleReplyVariantsEnabled: SyncedField<Bool>? = nil,
|
|
activePolishStyleId: SyncedField<String>,
|
|
personalReplyStyleId: SyncedField<String>,
|
|
llmThinkingEnabled: SyncedField<Bool>,
|
|
clipboardHistoryEnabled: SyncedField<Bool>? = nil,
|
|
clipboardCandidateBarEnabled: SyncedField<Bool>? = nil,
|
|
flowSkipAppSwitch: SyncedField<Bool>,
|
|
flowInactivityDuration: SyncedField<FlowInactivityDuration>
|
|
) {
|
|
self.schemaVersion = schemaVersion
|
|
self.providerId = providerId
|
|
self.baseURL = baseURL
|
|
self.model = model
|
|
self.asrProviderId = asrProviderId
|
|
self.asrBaseURL = asrBaseURL
|
|
self.asrModel = asrModel
|
|
self.modeId = modeId
|
|
self.localeId = localeId
|
|
self.engineMode = engineMode
|
|
self.hasAcknowledgedCloudSharing = hasAcknowledgedCloudSharing
|
|
self.uiLanguage = uiLanguage
|
|
self.translationTargetLocaleId = translationTargetLocaleId
|
|
self.handednessPreference = handednessPreference
|
|
self.cursorDragNavigationEnabled = cursorDragNavigationEnabled
|
|
self.keyboardHapticIntensity = keyboardHapticIntensity
|
|
self.polishIntensity = polishIntensity ?? SyncedField(
|
|
value: .default,
|
|
updatedAt: keyboardHapticIntensity.updatedAt,
|
|
deviceID: keyboardHapticIntensity.deviceID
|
|
)
|
|
self.aiResponseLength = aiResponseLength ?? SyncedField(
|
|
value: .default,
|
|
updatedAt: keyboardHapticIntensity.updatedAt,
|
|
deviceID: keyboardHapticIntensity.deviceID
|
|
)
|
|
self.multipleReplyVariantsEnabled = multipleReplyVariantsEnabled ?? SyncedField(
|
|
value: true,
|
|
updatedAt: keyboardHapticIntensity.updatedAt,
|
|
deviceID: keyboardHapticIntensity.deviceID
|
|
)
|
|
self.activePolishStyleId = activePolishStyleId
|
|
self.personalReplyStyleId = personalReplyStyleId
|
|
self.llmThinkingEnabled = llmThinkingEnabled
|
|
// Kept as optional parameters so old call sites and payload fixtures
|
|
// remain source-compatible. Clipboard consent is device-local.
|
|
_ = clipboardHistoryEnabled
|
|
_ = clipboardCandidateBarEnabled
|
|
self.flowSkipAppSwitch = flowSkipAppSwitch
|
|
self.flowInactivityDuration = flowInactivityDuration
|
|
}
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case schemaVersion
|
|
case providerId
|
|
case baseURL
|
|
case model
|
|
case asrProviderId
|
|
case asrBaseURL
|
|
case asrModel
|
|
case modeId
|
|
case localeId
|
|
case engineMode
|
|
case hasAcknowledgedCloudSharing
|
|
case uiLanguage
|
|
case translationTargetLocaleId
|
|
case handednessPreference
|
|
case cursorDragNavigationEnabled
|
|
case keyboardHapticIntensity
|
|
case polishIntensity
|
|
case aiResponseLength
|
|
case multipleReplyVariantsEnabled
|
|
case activePolishStyleId
|
|
case personalReplyStyleId
|
|
case llmThinkingEnabled
|
|
case clipboardHistoryEnabled
|
|
case clipboardCandidateBarEnabled
|
|
case flowSkipAppSwitch
|
|
case flowInactivityDuration
|
|
}
|
|
|
|
private enum LegacyCodingKeys: String, CodingKey {
|
|
case flowKeepAliveMode
|
|
}
|
|
|
|
public init(from decoder: Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
schemaVersion = try container.decode(Int.self, forKey: .schemaVersion)
|
|
providerId = try container.decode(SyncedField<String>.self, forKey: .providerId)
|
|
baseURL = try container.decode(SyncedField<String>.self, forKey: .baseURL)
|
|
model = try container.decode(SyncedField<String>.self, forKey: .model)
|
|
modeId = try container.decode(SyncedField<String>.self, forKey: .modeId)
|
|
localeId = try container.decode(SyncedField<String>.self, forKey: .localeId)
|
|
engineMode = try container.decode(SyncedField<String>.self, forKey: .engineMode)
|
|
hasAcknowledgedCloudSharing = try container.decode(SyncedField<Bool>.self, forKey: .hasAcknowledgedCloudSharing)
|
|
uiLanguage = try container.decode(SyncedField<AppUILanguage>.self, forKey: .uiLanguage)
|
|
translationTargetLocaleId = try container.decode(
|
|
SyncedField<String>.self,
|
|
forKey: .translationTargetLocaleId
|
|
)
|
|
handednessPreference = try container.decode(
|
|
SyncedField<HandednessPreference>.self,
|
|
forKey: .handednessPreference
|
|
)
|
|
cursorDragNavigationEnabled = try container.decode(
|
|
SyncedField<Bool>.self,
|
|
forKey: .cursorDragNavigationEnabled
|
|
)
|
|
keyboardHapticIntensity = try container.decodeIfPresent(
|
|
SyncedField<KeyboardHapticIntensity>.self,
|
|
forKey: .keyboardHapticIntensity
|
|
) ?? SyncedField(
|
|
value: .default,
|
|
updatedAt: cursorDragNavigationEnabled.updatedAt,
|
|
deviceID: cursorDragNavigationEnabled.deviceID
|
|
)
|
|
polishIntensity = try container.decodeIfPresent(
|
|
SyncedField<PolishIntensity>.self,
|
|
forKey: .polishIntensity
|
|
) ?? SyncedField(
|
|
value: .default,
|
|
updatedAt: keyboardHapticIntensity.updatedAt,
|
|
deviceID: keyboardHapticIntensity.deviceID
|
|
)
|
|
aiResponseLength = try container.decodeIfPresent(
|
|
SyncedField<AIResponseLength>.self,
|
|
forKey: .aiResponseLength
|
|
) ?? SyncedField(
|
|
value: .default,
|
|
updatedAt: keyboardHapticIntensity.updatedAt,
|
|
deviceID: keyboardHapticIntensity.deviceID
|
|
)
|
|
multipleReplyVariantsEnabled = try container.decodeIfPresent(
|
|
SyncedField<Bool>.self,
|
|
forKey: .multipleReplyVariantsEnabled
|
|
) ?? SyncedField(
|
|
value: true,
|
|
updatedAt: keyboardHapticIntensity.updatedAt,
|
|
deviceID: keyboardHapticIntensity.deviceID
|
|
)
|
|
activePolishStyleId = try container.decodeIfPresent(
|
|
SyncedField<String>.self,
|
|
forKey: .activePolishStyleId
|
|
) ?? SyncedField(
|
|
value: PolishStylePackCatalog.defaultID,
|
|
updatedAt: keyboardHapticIntensity.updatedAt,
|
|
deviceID: keyboardHapticIntensity.deviceID
|
|
)
|
|
// Absent on payloads written before voice input and AI replies were
|
|
// split. Empty is the correct default: the local one-shot migration
|
|
// owns adopting an existing personal style, not the sync layer.
|
|
personalReplyStyleId = try container.decodeIfPresent(
|
|
SyncedField<String>.self,
|
|
forKey: .personalReplyStyleId
|
|
) ?? SyncedField(
|
|
value: "",
|
|
updatedAt: keyboardHapticIntensity.updatedAt,
|
|
deviceID: keyboardHapticIntensity.deviceID
|
|
)
|
|
llmThinkingEnabled = try container.decodeIfPresent(
|
|
SyncedField<Bool>.self,
|
|
forKey: .llmThinkingEnabled
|
|
) ?? SyncedField(
|
|
value: false,
|
|
updatedAt: keyboardHapticIntensity.updatedAt,
|
|
deviceID: keyboardHapticIntensity.deviceID
|
|
)
|
|
_ = try container.decodeIfPresent(
|
|
SyncedField<Bool>.self,
|
|
forKey: .clipboardHistoryEnabled
|
|
)
|
|
_ = try container.decodeIfPresent(
|
|
SyncedField<Bool>.self,
|
|
forKey: .clipboardCandidateBarEnabled
|
|
)
|
|
flowSkipAppSwitch = try container.decode(SyncedField<Bool>.self, forKey: .flowSkipAppSwitch)
|
|
flowInactivityDuration = try container.decode(
|
|
SyncedField<FlowInactivityDuration>.self,
|
|
forKey: .flowInactivityDuration
|
|
)
|
|
let legacyContainer = try decoder.container(keyedBy: LegacyCodingKeys.self)
|
|
_ = try legacyContainer.decodeIfPresent(
|
|
SyncedField<String>.self,
|
|
forKey: .flowKeepAliveMode
|
|
)
|
|
|
|
if let asrProvider = try container.decodeIfPresent(SyncedField<String>.self, forKey: .asrProviderId) {
|
|
asrProviderId = asrProvider
|
|
} else {
|
|
asrProviderId = providerId
|
|
}
|
|
if let asrURL = try container.decodeIfPresent(SyncedField<String>.self, forKey: .asrBaseURL) {
|
|
asrBaseURL = asrURL
|
|
} else {
|
|
asrBaseURL = baseURL
|
|
}
|
|
if let asrModelField = try container.decodeIfPresent(SyncedField<String>.self, forKey: .asrModel) {
|
|
asrModel = asrModelField
|
|
} else {
|
|
let fallbackModel = CloudASRModelCatalog.defaultModel(for: providerId.value)
|
|
asrModel = SyncedField(
|
|
value: fallbackModel,
|
|
updatedAt: model.updatedAt,
|
|
deviceID: model.deviceID
|
|
)
|
|
}
|
|
}
|
|
|
|
/// Monotonic stamp used for `settingsCloudUpdatedAt` bookkeeping.
|
|
public var latestUpdatedAt: Date {
|
|
[
|
|
providerId.updatedAt,
|
|
baseURL.updatedAt,
|
|
model.updatedAt,
|
|
asrProviderId.updatedAt,
|
|
asrBaseURL.updatedAt,
|
|
asrModel.updatedAt,
|
|
modeId.updatedAt,
|
|
localeId.updatedAt,
|
|
engineMode.updatedAt,
|
|
hasAcknowledgedCloudSharing.updatedAt,
|
|
uiLanguage.updatedAt,
|
|
translationTargetLocaleId.updatedAt,
|
|
handednessPreference.updatedAt,
|
|
cursorDragNavigationEnabled.updatedAt,
|
|
keyboardHapticIntensity.updatedAt,
|
|
polishIntensity.updatedAt,
|
|
aiResponseLength.updatedAt,
|
|
multipleReplyVariantsEnabled.updatedAt,
|
|
activePolishStyleId.updatedAt,
|
|
personalReplyStyleId.updatedAt,
|
|
llmThinkingEnabled.updatedAt,
|
|
flowSkipAppSwitch.updatedAt,
|
|
flowInactivityDuration.updatedAt
|
|
].max() ?? .distantPast
|
|
}
|
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
try container.encode(schemaVersion, forKey: .schemaVersion)
|
|
try container.encode(providerId, forKey: .providerId)
|
|
try container.encode(baseURL, forKey: .baseURL)
|
|
try container.encode(model, forKey: .model)
|
|
try container.encode(asrProviderId, forKey: .asrProviderId)
|
|
try container.encode(asrBaseURL, forKey: .asrBaseURL)
|
|
try container.encode(asrModel, forKey: .asrModel)
|
|
try container.encode(modeId, forKey: .modeId)
|
|
try container.encode(localeId, forKey: .localeId)
|
|
try container.encode(engineMode, forKey: .engineMode)
|
|
try container.encode(hasAcknowledgedCloudSharing, forKey: .hasAcknowledgedCloudSharing)
|
|
try container.encode(uiLanguage, forKey: .uiLanguage)
|
|
try container.encode(translationTargetLocaleId, forKey: .translationTargetLocaleId)
|
|
try container.encode(handednessPreference, forKey: .handednessPreference)
|
|
try container.encode(cursorDragNavigationEnabled, forKey: .cursorDragNavigationEnabled)
|
|
try container.encode(keyboardHapticIntensity, forKey: .keyboardHapticIntensity)
|
|
try container.encode(polishIntensity, forKey: .polishIntensity)
|
|
try container.encode(aiResponseLength, forKey: .aiResponseLength)
|
|
try container.encode(multipleReplyVariantsEnabled, forKey: .multipleReplyVariantsEnabled)
|
|
try container.encode(activePolishStyleId, forKey: .activePolishStyleId)
|
|
try container.encode(personalReplyStyleId, forKey: .personalReplyStyleId)
|
|
try container.encode(llmThinkingEnabled, forKey: .llmThinkingEnabled)
|
|
try container.encode(flowSkipAppSwitch, forKey: .flowSkipAppSwitch)
|
|
try container.encode(flowInactivityDuration, forKey: .flowInactivityDuration)
|
|
}
|
|
}
|
|
|
|
public extension SyncedAppSettingsV2 {
|
|
static func from(configuration: AppGroupConfiguration, deviceID: String) -> SyncedAppSettingsV2 {
|
|
seeded(from: configuration, deviceID: deviceID, updatedAt: Date())
|
|
}
|
|
|
|
/// Build a payload from configuration using one shared timestamp (for merge bookkeeping).
|
|
static func seeded(
|
|
from configuration: AppGroupConfiguration,
|
|
deviceID: String,
|
|
updatedAt: Date
|
|
) -> SyncedAppSettingsV2 {
|
|
func field<T>(_ value: T) -> SyncedField<T> {
|
|
SyncedField(value: value, updatedAt: updatedAt, deviceID: deviceID)
|
|
}
|
|
return SyncedAppSettingsV2(
|
|
providerId: field(configuration.providerId),
|
|
baseURL: field(configuration.baseURL),
|
|
model: field(configuration.model),
|
|
asrProviderId: field(configuration.asrProviderId),
|
|
asrBaseURL: field(configuration.asrBaseURL),
|
|
asrModel: field(configuration.asrModel),
|
|
modeId: field(configuration.modeId),
|
|
localeId: field(configuration.localeId),
|
|
engineMode: field(configuration.engineMode),
|
|
hasAcknowledgedCloudSharing: field(configuration.hasAcknowledgedCloudSharing),
|
|
uiLanguage: field(configuration.uiLanguage),
|
|
translationTargetLocaleId: field(configuration.translationTargetLocaleId),
|
|
handednessPreference: field(configuration.handednessPreference),
|
|
cursorDragNavigationEnabled: field(configuration.cursorDragNavigationEnabled),
|
|
keyboardHapticIntensity: field(configuration.keyboardHapticIntensity),
|
|
polishIntensity: field(configuration.polishIntensity),
|
|
aiResponseLength: field(configuration.aiResponseLength),
|
|
multipleReplyVariantsEnabled: field(configuration.multipleReplyVariantsEnabled),
|
|
activePolishStyleId: field(configuration.activePolishStyleId),
|
|
personalReplyStyleId: field(configuration.personalReplyStyleId),
|
|
llmThinkingEnabled: field(configuration.llmThinkingEnabled),
|
|
flowSkipAppSwitch: field(configuration.flowSkipAppSwitch),
|
|
flowInactivityDuration: field(configuration.flowInactivityDuration)
|
|
)
|
|
}
|
|
|
|
/// Upgrade a legacy v1 blob into per-field metadata on this device.
|
|
static func migrated(from legacy: SyncedAppSettings, deviceID: String) -> SyncedAppSettingsV2 {
|
|
let stamp = legacy.updatedAt
|
|
func field<T>(_ value: T) -> SyncedField<T> {
|
|
SyncedField(value: value, updatedAt: stamp, deviceID: deviceID)
|
|
}
|
|
let provider = field(legacy.providerId)
|
|
return SyncedAppSettingsV2(
|
|
providerId: provider,
|
|
baseURL: field(legacy.baseURL),
|
|
model: field(legacy.model),
|
|
asrProviderId: provider,
|
|
asrBaseURL: field(legacy.baseURL),
|
|
asrModel: field(CloudASRModelCatalog.defaultModel(for: legacy.providerId)),
|
|
modeId: field(legacy.modeId),
|
|
localeId: field(legacy.localeId),
|
|
engineMode: field(legacy.engineMode),
|
|
hasAcknowledgedCloudSharing: field(legacy.hasAcknowledgedCloudSharing),
|
|
uiLanguage: field(legacy.uiLanguage),
|
|
translationTargetLocaleId: field(legacy.translationTargetLocaleId),
|
|
handednessPreference: field(legacy.handednessPreference),
|
|
cursorDragNavigationEnabled: field(legacy.cursorDragNavigationEnabled),
|
|
keyboardHapticIntensity: field(KeyboardHapticIntensity.default),
|
|
polishIntensity: field(PolishIntensity.default),
|
|
aiResponseLength: field(AIResponseLength.default),
|
|
multipleReplyVariantsEnabled: field(true),
|
|
activePolishStyleId: field(PolishStylePackCatalog.defaultID),
|
|
personalReplyStyleId: field(""),
|
|
llmThinkingEnabled: field(false),
|
|
flowSkipAppSwitch: field(legacy.flowSkipAppSwitch),
|
|
flowInactivityDuration: field(legacy.flowInactivityDuration)
|
|
)
|
|
}
|
|
|
|
static func merge(local: SyncedAppSettingsV2, remote: SyncedAppSettingsV2) -> SyncedAppSettingsV2 {
|
|
SyncedAppSettingsV2(
|
|
providerId: .merge(local: local.providerId, remote: remote.providerId),
|
|
baseURL: .merge(local: local.baseURL, remote: remote.baseURL),
|
|
model: .merge(local: local.model, remote: remote.model),
|
|
asrProviderId: .merge(local: local.asrProviderId, remote: remote.asrProviderId),
|
|
asrBaseURL: .merge(local: local.asrBaseURL, remote: remote.asrBaseURL),
|
|
asrModel: .merge(local: local.asrModel, remote: remote.asrModel),
|
|
modeId: .merge(local: local.modeId, remote: remote.modeId),
|
|
localeId: .merge(local: local.localeId, remote: remote.localeId),
|
|
engineMode: .merge(local: local.engineMode, remote: remote.engineMode),
|
|
hasAcknowledgedCloudSharing: .merge(
|
|
local: local.hasAcknowledgedCloudSharing,
|
|
remote: remote.hasAcknowledgedCloudSharing
|
|
),
|
|
uiLanguage: .merge(local: local.uiLanguage, remote: remote.uiLanguage),
|
|
translationTargetLocaleId: .merge(
|
|
local: local.translationTargetLocaleId,
|
|
remote: remote.translationTargetLocaleId
|
|
),
|
|
handednessPreference: .merge(local: local.handednessPreference, remote: remote.handednessPreference),
|
|
cursorDragNavigationEnabled: .merge(
|
|
local: local.cursorDragNavigationEnabled,
|
|
remote: remote.cursorDragNavigationEnabled
|
|
),
|
|
keyboardHapticIntensity: .merge(
|
|
local: local.keyboardHapticIntensity,
|
|
remote: remote.keyboardHapticIntensity
|
|
),
|
|
polishIntensity: .merge(
|
|
local: local.polishIntensity,
|
|
remote: remote.polishIntensity
|
|
),
|
|
aiResponseLength: .merge(
|
|
local: local.aiResponseLength,
|
|
remote: remote.aiResponseLength
|
|
),
|
|
multipleReplyVariantsEnabled: .merge(
|
|
local: local.multipleReplyVariantsEnabled,
|
|
remote: remote.multipleReplyVariantsEnabled
|
|
),
|
|
activePolishStyleId: .merge(
|
|
local: local.activePolishStyleId,
|
|
remote: remote.activePolishStyleId
|
|
),
|
|
personalReplyStyleId: .merge(
|
|
local: local.personalReplyStyleId,
|
|
remote: remote.personalReplyStyleId
|
|
),
|
|
llmThinkingEnabled: .merge(local: local.llmThinkingEnabled, remote: remote.llmThinkingEnabled),
|
|
flowSkipAppSwitch: .merge(local: local.flowSkipAppSwitch, remote: remote.flowSkipAppSwitch),
|
|
flowInactivityDuration: .merge(
|
|
local: local.flowInactivityDuration,
|
|
remote: remote.flowInactivityDuration
|
|
)
|
|
)
|
|
}
|
|
|
|
func applying(to configuration: inout AppGroupConfiguration) {
|
|
configuration.providerId = providerId.value
|
|
configuration.baseURL = baseURL.value
|
|
configuration.model = model.value
|
|
configuration.asrProviderId = asrProviderId.value
|
|
configuration.asrBaseURL = asrBaseURL.value
|
|
configuration.asrModel = asrModel.value
|
|
configuration.modeId = modeId.value
|
|
configuration.localeId = localeId.value
|
|
configuration.engineMode = engineMode.value
|
|
configuration.hasAcknowledgedCloudSharing = hasAcknowledgedCloudSharing.value
|
|
configuration.uiLanguage = uiLanguage.value
|
|
configuration.translationTargetLocaleId = translationTargetLocaleId.value
|
|
configuration.handednessPreference = handednessPreference.value
|
|
configuration.cursorDragNavigationEnabled = cursorDragNavigationEnabled.value
|
|
configuration.keyboardHapticIntensity = keyboardHapticIntensity.value
|
|
configuration.polishIntensity = polishIntensity.value
|
|
configuration.aiResponseLength = aiResponseLength.value
|
|
configuration.multipleReplyVariantsEnabled = multipleReplyVariantsEnabled.value
|
|
// Writes bypass `AppGroupStore.setActivePolishStyleId`, so re-apply its
|
|
// gate here: a device still on the pre-split build can push a learned
|
|
// pack id, which must never reach the voice-polish prompt.
|
|
configuration.activePolishStyleId = PolishStylePackCatalog.isValidActiveID(
|
|
activePolishStyleId.value,
|
|
userCatalog: configuration.polishStyleCatalog
|
|
) ? activePolishStyleId.value : PolishStylePackCatalog.defaultID
|
|
configuration.personalReplyStyleId = PolishStylePackCatalog.resolvePersonalReplyStyle(
|
|
id: personalReplyStyleId.value,
|
|
userCatalog: configuration.polishStyleCatalog
|
|
)?.id ?? ""
|
|
configuration.llmThinkingEnabled = llmThinkingEnabled.value
|
|
configuration.flowSkipAppSwitch = flowSkipAppSwitch.value
|
|
configuration.flowInactivityDuration = flowInactivityDuration.value
|
|
}
|
|
|
|
/// Stamp fields whose values differ from `configuration` with this device id.
|
|
func patchLocalChanges(from configuration: AppGroupConfiguration, deviceID: String) -> SyncedAppSettingsV2 {
|
|
var copy = self
|
|
func patch<T: Equatable>(_ field: inout SyncedField<T>, value: T) {
|
|
guard field.value != value else { return }
|
|
field = .make(value: value, deviceID: deviceID)
|
|
}
|
|
patch(©.providerId, value: configuration.providerId)
|
|
patch(©.baseURL, value: configuration.baseURL)
|
|
patch(©.model, value: configuration.model)
|
|
patch(©.asrProviderId, value: configuration.asrProviderId)
|
|
patch(©.asrBaseURL, value: configuration.asrBaseURL)
|
|
patch(©.asrModel, value: configuration.asrModel)
|
|
patch(©.modeId, value: configuration.modeId)
|
|
patch(©.localeId, value: configuration.localeId)
|
|
patch(©.engineMode, value: configuration.engineMode)
|
|
patch(©.hasAcknowledgedCloudSharing, value: configuration.hasAcknowledgedCloudSharing)
|
|
patch(©.uiLanguage, value: configuration.uiLanguage)
|
|
patch(©.translationTargetLocaleId, value: configuration.translationTargetLocaleId)
|
|
patch(©.handednessPreference, value: configuration.handednessPreference)
|
|
patch(©.cursorDragNavigationEnabled, value: configuration.cursorDragNavigationEnabled)
|
|
patch(©.keyboardHapticIntensity, value: configuration.keyboardHapticIntensity)
|
|
patch(©.polishIntensity, value: configuration.polishIntensity)
|
|
patch(©.aiResponseLength, value: configuration.aiResponseLength)
|
|
patch(©.multipleReplyVariantsEnabled, value: configuration.multipleReplyVariantsEnabled)
|
|
patch(©.activePolishStyleId, value: configuration.activePolishStyleId)
|
|
patch(©.personalReplyStyleId, value: configuration.personalReplyStyleId)
|
|
patch(©.llmThinkingEnabled, value: configuration.llmThinkingEnabled)
|
|
patch(©.flowSkipAppSwitch, value: configuration.flowSkipAppSwitch)
|
|
patch(©.flowInactivityDuration, value: configuration.flowInactivityDuration)
|
|
return copy
|
|
}
|
|
|
|
/// Refresh only fields owned by `deviceID` from the current local configuration.
|
|
func refreshedLocalFields(from configuration: AppGroupConfiguration, deviceID: String) -> SyncedAppSettingsV2 {
|
|
var copy = self
|
|
let now = Date()
|
|
func touch<T>(_ field: inout SyncedField<T>, value: T) {
|
|
guard field.deviceID == deviceID else { return }
|
|
field.value = value
|
|
field.updatedAt = now
|
|
}
|
|
touch(©.providerId, value: configuration.providerId)
|
|
touch(©.baseURL, value: configuration.baseURL)
|
|
touch(©.model, value: configuration.model)
|
|
touch(©.asrProviderId, value: configuration.asrProviderId)
|
|
touch(©.asrBaseURL, value: configuration.asrBaseURL)
|
|
touch(©.asrModel, value: configuration.asrModel)
|
|
touch(©.modeId, value: configuration.modeId)
|
|
touch(©.localeId, value: configuration.localeId)
|
|
touch(©.engineMode, value: configuration.engineMode)
|
|
touch(©.hasAcknowledgedCloudSharing, value: configuration.hasAcknowledgedCloudSharing)
|
|
touch(©.uiLanguage, value: configuration.uiLanguage)
|
|
touch(©.translationTargetLocaleId, value: configuration.translationTargetLocaleId)
|
|
touch(©.handednessPreference, value: configuration.handednessPreference)
|
|
touch(©.cursorDragNavigationEnabled, value: configuration.cursorDragNavigationEnabled)
|
|
touch(©.keyboardHapticIntensity, value: configuration.keyboardHapticIntensity)
|
|
touch(©.polishIntensity, value: configuration.polishIntensity)
|
|
touch(©.aiResponseLength, value: configuration.aiResponseLength)
|
|
touch(©.multipleReplyVariantsEnabled, value: configuration.multipleReplyVariantsEnabled)
|
|
touch(©.activePolishStyleId, value: configuration.activePolishStyleId)
|
|
touch(©.personalReplyStyleId, value: configuration.personalReplyStyleId)
|
|
touch(©.llmThinkingEnabled, value: configuration.llmThinkingEnabled)
|
|
touch(©.flowSkipAppSwitch, value: configuration.flowSkipAppSwitch)
|
|
touch(©.flowInactivityDuration, value: configuration.flowInactivityDuration)
|
|
return copy
|
|
}
|
|
}
|