feat(app): add crash visibility, memory relief, and clipboard reply work

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>
This commit is contained in:
2026-09-18 17:31:29 -07:00
co-authored by Claude Opus 5
parent 628e983794
commit 0023741455
210 changed files with 14731 additions and 2940 deletions
+17 -3
View File
@@ -189,14 +189,28 @@ public enum AIHintFeedEndpoints {
public enum AIHintLocaleResolver {
/// Only `zh-Hans` uses the Chinese pack; everything else uses English.
///
/// The in-app UI language override wins over the system preference: a user
/// on a Chinese device who switches the app to English must also get the
/// English idle carousel, not Chinese hint chips.
public static func packLocale(
language: AppUILanguage? = nil,
preferredLanguages: [String] = Locale.preferredLanguages
) -> String {
let primary = (preferredLanguages.first ?? "").lowercased()
if primary == "zh-hans" || primary.hasPrefix("zh-hans-") || primary.hasPrefix("zh-hans_") {
switch language ?? AppGroupStore().uiLanguage {
case .english:
return "en"
case .chinese:
return "zh"
case .auto:
// Traditional Chinese deliberately falls back to the English pack —
// only a Simplified pack is authored.
let primary = (preferredLanguages.first ?? "").lowercased()
if primary == "zh-hans" || primary.hasPrefix("zh-hans-") || primary.hasPrefix("zh-hans_") {
return "zh"
}
return "en"
}
return "en"
}
}
+37 -1
View File
@@ -23,6 +23,10 @@ public struct AIReplyVariant: Equatable, Identifiable, Sendable {
case clarificationDirect
case clarificationQuestion
case clarificationConfirm
case answerAffirmative
case answerNegative
case answerConditional
case answerDefer
public var systemImage: String {
switch self {
@@ -52,6 +56,14 @@ public struct AIReplyVariant: Equatable, Identifiable, Sendable {
return "bubble.left.and.text.bubble.right.fill"
case .clarificationConfirm:
return "checkmark.bubble.fill"
case .answerAffirmative:
return "checkmark.circle.fill"
case .answerNegative:
return "xmark.circle.fill"
case .answerConditional:
return "arrow.triangle.branch"
case .answerDefer:
return "clock.fill"
}
}
@@ -87,6 +99,14 @@ public struct AIReplyVariant: Equatable, Identifiable, Sendable {
return "keyboard.ai.replyVariant.clarificationQuestion"
case .clarificationConfirm:
return "keyboard.ai.replyVariant.clarificationConfirm"
case .answerAffirmative:
return "keyboard.ai.replyVariant.answerAffirmative"
case .answerNegative:
return "keyboard.ai.replyVariant.answerNegative"
case .answerConditional:
return "keyboard.ai.replyVariant.answerConditional"
case .answerDefer:
return "keyboard.ai.replyVariant.answerDefer"
}
}
@@ -107,7 +127,11 @@ public struct AIReplyVariant: Equatable, Identifiable, Sendable {
.blessingPlayful,
.clarificationDirect,
.clarificationQuestion,
.clarificationConfirm:
.clarificationConfirm,
.answerAffirmative,
.answerNegative,
.answerConditional,
.answerDefer:
return false
}
}
@@ -180,6 +204,7 @@ public enum AIReplyVariantSet: String, CaseIterable, Sendable {
case task
case blessing
case clarification
case yesNoQuestion
public var kinds: [AIReplyVariant.Kind] {
switch self {
@@ -197,6 +222,15 @@ public enum AIReplyVariantSet: String, CaseIterable, Sendable {
.clarificationQuestion,
.clarificationConfirm
]
case .yesNoQuestion:
// A yes/no question deserves both stances, not just tone variants —
// and this set intentionally exceeds three options.
return [
.answerAffirmative,
.answerNegative,
.answerConditional,
.answerDefer
]
}
}
@@ -210,6 +244,8 @@ public enum AIReplyVariantSet: String, CaseIterable, Sendable {
return .blessing
case .clarification:
return .clarification
case .yesNoQuestion:
return .yesNoQuestion
case .complaint, .negativeQuestion, nil:
return .generic
}
@@ -50,12 +50,27 @@ public struct AppGroupConfiguration: Sendable, Equatable {
public static let clipboardHistoryEnabled = "config.clipboardHistoryEnabled"
/// When true (and history is on), show the newest clipboard item as a suggestion strip.
public static let clipboardCandidateBarEnabled = "config.clipboardCandidateBarEnabled"
/// When true (and history is on), auto-route a freshly copied, replyable
/// message into the Reply flow when the keyboard opens. Device-local.
public static let clipboardAutoModeEnabled = "config.clipboardAutoModeEnabled"
/// When true (and history is on), auto-translate a freshly copied,
/// non-system-language paste on open. Device-local.
public static let clipboardAutoTranslateEnabled = "config.clipboardAutoTranslateEnabled"
/// When true (and history is on), auto-draft a reply when a freshly
/// copied paste is detected as an email. Device-local.
public static let clipboardAutoEmailReplyEnabled = "config.clipboardAutoEmailReplyEnabled"
public static let detectedAppContext = "config.detectedAppContext"
public static let detectedAppContextAt = "config.detectedAppContextAt"
public static let personalDictionary = "config.personalDictionary.v1"
public static let polishStyleCatalog = "config.polishStyles.v1"
public static let activePolishStyleId = "config.activePolishStyleId"
public static let polishStylesMigrated = "config.polishStyles.migrated"
/// Distilled personal style used for AI replies. Empty means disabled.
/// Deliberately separate from `activePolishStyleId`: voice input and AI
/// replies must not share one selection.
public static let personalReplyStyleId = "config.personalReplyStyleId"
/// One-shot: split the personal style out of the voice-polish selection.
public static let personalReplyStyleMigrated = "config.personalReplyStyle.migrated"
/// Legacy keys from the removed manual scenario implementation.
public static let legacyPolishScenarioId = "config.polishScenarioId"
public static let legacySystemPrompt = "config.systemPrompt"
@@ -122,9 +137,21 @@ public struct AppGroupConfiguration: Sendable, Equatable {
public var clipboardHistoryEnabled: Bool
/// Opt-in clipboard suggestion strip above the key surfaces.
public var clipboardCandidateBarEnabled: Bool
/// Opt-in: auto-route a freshly copied replyable message into the Reply
/// flow when the keyboard opens. Off by default; never syncs via iCloud.
public var clipboardAutoModeEnabled: Bool
/// Opt-in: auto-translate a freshly copied non-system-language paste on
/// open. Off by default; never syncs via iCloud.
public var clipboardAutoTranslateEnabled: Bool
/// Opt-in: auto-draft a reply when a freshly copied paste is an email.
/// Off by default; never syncs via iCloud.
public var clipboardAutoEmailReplyEnabled: Bool
public var personalDictionary: PersonalDictionary
public var polishStyleCatalog: PolishStyleCatalog
/// Voice-input polish style. Never a distilled personal style.
public var activePolishStyleId: String
/// Distilled personal style applied to AI replies; empty when disabled.
public var personalReplyStyleId: String
/// Opt-in iCloud KVS sync for the personal dictionary (main app only).
public var personalDictionaryICloudSyncEnabled: Bool
/// Opt-in iCloud KVS sync for user settings (main app only).
@@ -325,11 +352,17 @@ public struct AppGroupConfiguration: Sendable, Equatable {
}(),
llmThinkingEnabled: defaults.bool(forKey: Keys.llmThinkingEnabled),
clipboardHistoryEnabled: defaults.bool(forKey: Keys.clipboardHistoryEnabled),
clipboardCandidateBarEnabled: defaults.bool(forKey: Keys.clipboardCandidateBarEnabled),
// Paste capsule is always on now (its opt-in toggle was removed), so
// default to true when the key was never written.
clipboardCandidateBarEnabled: defaults.object(forKey: Keys.clipboardCandidateBarEnabled) as? Bool ?? true,
clipboardAutoModeEnabled: defaults.bool(forKey: Keys.clipboardAutoModeEnabled),
clipboardAutoTranslateEnabled: defaults.bool(forKey: Keys.clipboardAutoTranslateEnabled),
clipboardAutoEmailReplyEnabled: defaults.bool(forKey: Keys.clipboardAutoEmailReplyEnabled),
personalDictionary: decodePersonalDictionary(from: defaults),
polishStyleCatalog: decodePolishStyleCatalog(from: defaults),
activePolishStyleId: defaults.string(forKey: Keys.activePolishStyleId)
?? PolishStylePackCatalog.defaultID,
personalReplyStyleId: defaults.string(forKey: Keys.personalReplyStyleId) ?? "",
personalDictionaryICloudSyncEnabled: {
if defaults.object(forKey: Keys.personalDictionaryICloudSyncEnabled) == nil {
return true
@@ -443,6 +476,7 @@ public struct AppGroupConfiguration: Sendable, Equatable {
defaults.set("polish", forKey: Keys.modeId)
}
migrateLegacyPolishStyleIfNeeded(configuration: &config, defaults: defaults)
migratePersonalReplyStyleIfNeeded(configuration: &config, defaults: defaults)
return config
}
@@ -471,7 +505,11 @@ public struct AppGroupConfiguration: Sendable, Equatable {
defaults.set(llmThinkingEnabled, forKey: Keys.llmThinkingEnabled)
defaults.set(clipboardHistoryEnabled, forKey: Keys.clipboardHistoryEnabled)
defaults.set(clipboardCandidateBarEnabled, forKey: Keys.clipboardCandidateBarEnabled)
defaults.set(clipboardAutoModeEnabled, forKey: Keys.clipboardAutoModeEnabled)
defaults.set(clipboardAutoTranslateEnabled, forKey: Keys.clipboardAutoTranslateEnabled)
defaults.set(clipboardAutoEmailReplyEnabled, forKey: Keys.clipboardAutoEmailReplyEnabled)
defaults.set(activePolishStyleId, forKey: Keys.activePolishStyleId)
defaults.set(personalReplyStyleId, forKey: Keys.personalReplyStyleId)
defaults.set(flowSkipAppSwitch, forKey: Keys.flowSkipAppSwitch)
defaults.set(flowInactivityDuration.rawValue, forKey: Keys.flowInactivityDuration)
defaults.set(localASRCustomLanguageModelEnabled, forKey: Keys.localASRCustomLanguageModelEnabled)
@@ -568,11 +606,31 @@ public struct AppGroupConfiguration: Sendable, Equatable {
previous: baseline.clipboardCandidateBarEnabled,
key: Keys.clipboardCandidateBarEnabled
)
set(
clipboardAutoModeEnabled,
previous: baseline.clipboardAutoModeEnabled,
key: Keys.clipboardAutoModeEnabled
)
set(
clipboardAutoTranslateEnabled,
previous: baseline.clipboardAutoTranslateEnabled,
key: Keys.clipboardAutoTranslateEnabled
)
set(
clipboardAutoEmailReplyEnabled,
previous: baseline.clipboardAutoEmailReplyEnabled,
key: Keys.clipboardAutoEmailReplyEnabled
)
set(
activePolishStyleId,
previous: baseline.activePolishStyleId,
key: Keys.activePolishStyleId
)
set(
personalReplyStyleId,
previous: baseline.personalReplyStyleId,
key: Keys.personalReplyStyleId
)
set(flowSkipAppSwitch, previous: baseline.flowSkipAppSwitch, key: Keys.flowSkipAppSwitch)
set(
flowInactivityDuration.rawValue,
@@ -644,6 +702,40 @@ public struct AppGroupConfiguration: Sendable, Equatable {
}
}
/// Splits the distilled personal style out of the voice-polish selection.
///
/// Before this migration one `activePolishStyleId` drove both pipelines, so
/// selecting a learned pack let it outrank the core filler cleanup, and
/// selecting a built-in silently disabled personalization for AI replies —
/// "clean voice input" and "replies that sound like me" were mutually
/// exclusive. Runs after `migrateLegacyPolishStyleIfNeeded`, which may
/// itself rewrite `activePolishStyleId`.
private static func migratePersonalReplyStyleIfNeeded(
configuration: inout AppGroupConfiguration,
defaults: UserDefaults
) {
guard !defaults.bool(forKey: Keys.personalReplyStyleMigrated) else { return }
defer { defaults.set(true, forKey: Keys.personalReplyStyleMigrated) }
let catalog = configuration.polishStyleCatalog
let active = catalog.entries.first { $0.id == configuration.activePolishStyleId }
if let active, PolishStylePackCatalog.isPersonalReplyStyle(active) {
// Keep the personal style working where it now belongs, and give
// voice input its cleanup back.
configuration.personalReplyStyleId = active.id
configuration.activePolishStyleId = PolishStylePackCatalog.defaultID
} else if let latest = PolishStylePackCatalog.latestPersonalReplyStyle(userCatalog: catalog) {
// These users generated a personal style but were not using it: the
// single selector forced them to pick voice cleanup instead. Turning
// it on for replies restores the intent behind generating it.
configuration.personalReplyStyleId = latest.id
} else {
configuration.personalReplyStyleId = ""
}
defaults.set(configuration.activePolishStyleId, forKey: Keys.activePolishStyleId)
defaults.set(configuration.personalReplyStyleId, forKey: Keys.personalReplyStyleId)
}
private static func migrateLegacyPolishStyleIfNeeded(
configuration: inout AppGroupConfiguration,
defaults: UserDefaults
@@ -33,6 +33,7 @@ public enum CloudASRError: Error, LocalizedError, Sendable, Equatable {
case emptyTranscript
case audioTooLong
case providerUnsupported
case timedOut
public var errorDescription: String? {
switch self {
@@ -41,6 +42,12 @@ public enum CloudASRError: Error, LocalizedError, Sendable, Equatable {
case .invalidURL:
return SharedL10n.string("error.cloudASR.invalidURL")
case .http(let status, let message):
// 402 / balance-related errors: SiliconFlow gates some ¥0-priced
// models behind a positive account balance. Surface an actionable
// hint instead of the raw provider string.
if Self.isInsufficientBalance(status: status, message: message) {
return SharedL10n.string("error.cloudASR.insufficientBalance")
}
if let message, !message.isEmpty {
return SharedL10n.format("error.cloudASR.httpWithMessage", status, message)
}
@@ -55,8 +62,22 @@ public enum CloudASRError: Error, LocalizedError, Sendable, Equatable {
return SharedL10n.string("error.cloudASR.audioTooLong")
case .providerUnsupported:
return SharedL10n.string("error.cloudASR.providerUnsupported")
case .timedOut:
return SharedL10n.string("error.cloudASR.timedOut")
}
}
/// Whether an HTTP failure is an account-balance / billing gate rather than
/// a bad key or missing model. Keyed off the 402 status or a message that
/// mentions balance/欠费, covering providers that reuse other 4xx codes.
static func isInsufficientBalance(status: Int, message: String?) -> Bool {
if status == 402 { return true }
guard let message = message?.lowercased() else { return false }
return message.contains("insufficient")
|| message.contains("balance")
|| message.contains("余额")
|| message.contains("欠费")
}
}
public enum CloudASRModelCatalog {
@@ -90,7 +90,7 @@ public enum FlowHandoffPolicy {
if let snapshotReason {
switch snapshotReason {
case .recording, .processing, .awaitingDelivery, .starting,
.waitingForAudioProof, .audioEngineNotLive:
.waitingForForeground, .waitingForAudioProof, .audioEngineNotLive:
return false
case .ready, .noSession, .permissionMissing, .appGroupUnavailable,
.hostLost, .error:
@@ -8,6 +8,12 @@ public struct FlowReadySnapshot: Codable, Equatable, Sendable {
case ready
case noSession
case starting
/// Host received the `startflow` request but is not in the foreground
/// yet, so PiP (the keep-alive that gates readiness) cannot arm. Proof
/// the host is alive and warming — distinct from `noSession` (no host)
/// — so the keyboard can hold its start budget and prompt the user to
/// bring the app forward instead of silently timing out.
case waitingForForeground
case audioEngineNotLive
case waitingForAudioProof
case recording
+20 -47
View File
@@ -12,8 +12,6 @@ public struct LLMProvider: Identifiable, Codable, Hashable, Sendable {
public let defaultBaseURL: String
public let defaultModel: String
public let apiKeyURL: URL?
/// Optional short blurb shown under the provider name in the picker.
public let blurb: String?
/// Whether this preset should appear in user-facing provider pickers
/// (settings / onboarding). Defaults to `true` so the existing
/// `presets` array keeps its public surface area; future passes can
@@ -27,7 +25,6 @@ public struct LLMProvider: Identifiable, Codable, Hashable, Sendable {
defaultBaseURL: String,
defaultModel: String,
apiKeyURL: URL? = nil,
blurb: String? = nil,
isUserSelectable: Bool = true
) {
self.id = id
@@ -35,7 +32,6 @@ public struct LLMProvider: Identifiable, Codable, Hashable, Sendable {
self.defaultBaseURL = defaultBaseURL
self.defaultModel = defaultModel
self.apiKeyURL = apiKeyURL
self.blurb = blurb
self.isUserSelectable = isUserSelectable
}
@@ -45,144 +41,126 @@ public struct LLMProvider: Identifiable, Codable, Hashable, Sendable {
name: "OpenAI",
defaultBaseURL: "https://api.openai.com/v1",
defaultModel: "gpt-5.4-mini",
apiKeyURL: URL(string: "https://platform.openai.com/api-keys"),
blurb: "gpt-5.4-mini · Responses web_search · AI 模式可联网"
apiKeyURL: URL(string: "https://platform.openai.com/api-keys")
),
.init(
id: "ark",
name: "火山方舟 Ark",
defaultBaseURL: "https://ark.cn-beijing.volces.com/api/v3",
defaultModel: "deepseek-v3-2-251201",
apiKeyURL: URL(string: "https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey"),
blurb: "豆包 / DeepSeek · 接入点 ID 需在控制台确认"
apiKeyURL: URL(string: "https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey")
),
.init(
id: "deepseek",
name: "DeepSeek",
defaultBaseURL: "https://api.deepseek.com/v1",
defaultModel: "deepseek-v4-flash",
apiKeyURL: URL(string: "https://platform.deepseek.com/api_keys"),
blurb: "deepseek-v4-flash · Responses 联网 · 润色/AI 共用"
apiKeyURL: URL(string: "https://platform.deepseek.com/api_keys")
),
.init(
id: "qwen",
name: "Qwen (DashScope)",
defaultBaseURL: "https://dashscope.aliyuncs.com/compatible-mode/v1",
defaultModel: "qwen-plus-latest",
apiKeyURL: URL(string: "https://dashscope.console.aliyun.com/apiKey"),
blurb: "qwen-plus-latest · enable_search · 滚动最新 Plus"
apiKeyURL: URL(string: "https://dashscope.console.aliyun.com/apiKey")
),
.init(
id: "zhipu",
name: "智谱 GLM · Zhipu",
defaultBaseURL: "https://open.bigmodel.cn/api/paas/v4",
defaultModel: "glm-4.7-flash",
apiKeyURL: URL(string: "https://bigmodel.cn/usercenter/apikeys"),
blurb: "GLM-4.7-Flash · 快 · 可 web_search"
apiKeyURL: URL(string: "https://bigmodel.cn/usercenter/apikeys")
),
.init(
id: "moonshot",
name: "月之暗面 Moonshot",
defaultBaseURL: "https://api.moonshot.cn/v1",
defaultModel: "kimi-k2.5",
apiKeyURL: URL(string: "https://platform.moonshot.cn/console/api-keys"),
blurb: "kimi-k2.5 · 长上下文 · AI 可尝试联网"
apiKeyURL: URL(string: "https://platform.moonshot.cn/console/api-keys")
),
.init(
id: "siliconflow",
name: "硅基流动 SiliconFlow",
defaultBaseURL: "https://api.siliconflow.cn/v1",
defaultModel: "Qwen/Qwen3-8B-Instruct",
apiKeyURL: URL(string: "https://cloud.siliconflow.cn/account/ak"),
blurb: "Qwen3-8B · 多模型聚合 · OpenAI 兼容"
apiKeyURL: URL(string: "https://cloud.siliconflow.cn/account/ak")
),
.init(
id: "groq",
name: "Groq",
defaultBaseURL: "https://api.groq.com/openai/v1",
defaultModel: "llama-3.3-70b-versatile",
apiKeyURL: URL(string: "https://console.groq.com/keys"),
blurb: "Llama 3.3 70B · 超低延迟 LPU"
apiKeyURL: URL(string: "https://console.groq.com/keys")
),
.init(
id: "minimax",
name: "MiniMax",
defaultBaseURL: "https://api.minimaxi.com/v1",
defaultModel: "MiniMax-M2.7",
apiKeyURL: URL(string: "https://platform.minimaxi.com/user-center/basic-information"),
blurb: "MiniMax-M2.7 · 中文优化"
apiKeyURL: URL(string: "https://platform.minimaxi.com/user-center/basic-information")
),
.init(
id: "mimo",
name: "小米 MiMo",
defaultBaseURL: "https://api.xiaomimimo.com/v1",
defaultModel: "mimo-v2.5",
apiKeyURL: URL(string: "https://platform.xiaomimimo.com"),
blurb: "mimo-v2.5 · 中文优化"
apiKeyURL: URL(string: "https://platform.xiaomimimo.com")
),
.init(
id: "openrouter",
name: "OpenRouter",
defaultBaseURL: "https://openrouter.ai/api/v1",
defaultModel: "qwen/qwen3-8b:free",
apiKeyURL: URL(string: "https://openrouter.ai/keys"),
blurb: "qwen3-8b:free · 通用润色/问答(非 coder)"
defaultModel: "qwen/qwen3-8b",
apiKeyURL: URL(string: "https://openrouter.ai/keys")
),
.init(
id: "gemini",
name: "Google Gemini",
defaultBaseURL: "https://generativelanguage.googleapis.com/v1beta/openai",
defaultModel: "gemini-3.1-flash-lite",
apiKeyURL: URL(string: "https://aistudio.google.com/apikey"),
blurb: "gemini-3.1-flash-lite · 低延迟 · OpenAI 兼容端点"
apiKeyURL: URL(string: "https://aistudio.google.com/apikey")
),
.init(
id: "anthropic",
name: "Anthropic Claude",
defaultBaseURL: "https://api.anthropic.com/v1",
defaultModel: "claude-sonnet-4-6",
apiKeyURL: URL(string: "https://console.anthropic.com/settings/keys"),
blurb: "Claude Sonnet 4.6 · Messages · AI 可联网"
apiKeyURL: URL(string: "https://console.anthropic.com/settings/keys")
),
.init(
id: "xai",
name: "xAI Grok",
defaultBaseURL: "https://api.x.ai/v1",
defaultModel: "grok-4-fast-reasoning",
apiKeyURL: URL(string: "https://console.x.ai"),
blurb: "grok-4-fast-reasoning · Responses web_search"
apiKeyURL: URL(string: "https://console.x.ai")
),
.init(
id: "mistral",
name: "Mistral AI",
defaultBaseURL: "https://api.mistral.ai/v1",
defaultModel: "mistral-small-latest",
apiKeyURL: URL(string: "https://console.mistral.ai/api-keys"),
blurb: "Mistral Small · 欧洲托管 · -latest 滚动"
apiKeyURL: URL(string: "https://console.mistral.ai/api-keys")
),
.init(
id: "cometapi",
name: "CometAPI",
defaultBaseURL: "https://api.cometapi.com/v1",
defaultModel: "gpt-5.4-mini",
apiKeyURL: URL(string: "https://api.cometapi.com"),
blurb: "gpt-5.4-mini · 多模型聚合"
apiKeyURL: URL(string: "https://api.cometapi.com")
),
.init(
id: "alibabaCoding",
name: "阿里 Coding Plan",
defaultBaseURL: "https://coding-intl.dashscope.aliyuncs.com/v1",
defaultModel: "qwen3-coder-plus",
apiKeyURL: URL(string: "https://dashscope.console.aliyun.com/apiKey"),
blurb: "通义 Coder · 代码润色"
apiKeyURL: URL(string: "https://dashscope.console.aliyun.com/apiKey")
),
.init(
id: "codingPlanX",
name: "CodingPlanX",
defaultBaseURL: "https://api.codingplanx.ai/v1",
defaultModel: "gpt-5.4-mini",
apiKeyURL: URL(string: "https://codingplanx.ai"),
blurb: "gpt-5.4-mini · OpenAI 兼容"
apiKeyURL: URL(string: "https://codingplanx.ai")
),
// MARK: - ASR-only presets (hidden from polish picker)
.init(
@@ -191,7 +169,6 @@ public struct LLMProvider: Identifiable, Codable, Hashable, Sendable {
defaultBaseURL: "wss://openspeech.bytedance.com/api/v3/sauc/bigmodel_async",
defaultModel: "volc.seedasr.sauc.duration",
apiKeyURL: URL(string: "https://console.volcengine.com/speech"),
blurb: "流式大模型 ASR · 旧版 AppID+Token / 新版 API Key",
isUserSelectable: false
),
.init(
@@ -200,7 +177,6 @@ public struct LLMProvider: Identifiable, Codable, Hashable, Sendable {
defaultBaseURL: "wss://dashscope.aliyuncs.com/api-ws/v1/inference/",
defaultModel: "fun-asr-realtime",
apiKeyURL: URL(string: "https://dashscope.console.aliyun.com/apiKey"),
blurb: "Fun-ASR Realtime · 百炼词表",
isUserSelectable: false
),
.init(
@@ -209,7 +185,6 @@ public struct LLMProvider: Identifiable, Codable, Hashable, Sendable {
defaultBaseURL: "https://api.openai.com/v1",
defaultModel: "whisper-1",
apiKeyURL: URL(string: "https://platform.openai.com/api-keys"),
blurb: "whisper-1 · 经典 Whisper 端点",
isUserSelectable: false
),
.init(
@@ -217,15 +192,13 @@ public struct LLMProvider: Identifiable, Codable, Hashable, Sendable {
name: "Codex OAuth",
defaultBaseURL: "",
defaultModel: "gpt-5.3-codex-spark",
blurb: "ChatGPT Codex OAuth · 暂不支持",
isUserSelectable: false
),
.init(
id: "custom",
name: "Custom · 自定义",
defaultBaseURL: "",
defaultModel: "",
blurb: "自建 / 任意 OpenAI 兼容端点 · Any OpenAI-compatible endpoint"
defaultModel: ""
)
]
@@ -232,9 +232,9 @@ public enum LocalASRModelCatalogError: Error, LocalizedError {
public var errorDescription: String? {
switch self {
case .missingBundledCatalog:
return "Missing bundled local ASR catalog."
return SharedL10n.string("error.localASR.missingBundledCatalog")
case .modelNotFound(let id):
return "Local ASR model not found: \(id)"
return SharedL10n.format("error.localASR.modelNotFound", id)
}
}
}
+36 -1
View File
@@ -263,8 +263,43 @@ public enum PolishStylePackCatalog {
}
}
/// Distilled personal styles serve the AI-reply pipeline only. Voice polish
/// must never load one: a learned pack is injected as "outranks generic
/// cleanup", which would override the core T1/T2 filler and repetition
/// cleanup and put the speaker's disfluencies back into the transcript.
public static func isPersonalReplyStyle(_ pack: PolishStylePack) -> Bool {
pack.learningMetadata != nil
}
/// Voice-polish eligibility. Rejecting learned packs here — rather than in
/// the UI — means a stale iCloud value or a view bug still cannot reach
/// `PolishPromptComposer`; `setActivePolishStyleId` falls back to `defaultID`.
public static func isValidActiveID(_ id: String, userCatalog: PolishStyleCatalog) -> Bool {
builtins.contains(where: { $0.id == id }) || userCatalog.entries.contains(where: { $0.id == id })
if builtins.contains(where: { $0.id == id }) { return true }
guard let pack = userCatalog.entries.first(where: { $0.id == id }) else { return false }
return !isPersonalReplyStyle(pack)
}
/// The mirror gate: only a distilled personal style may drive AI replies.
/// Hand-written user packs stay on the Styles page (voice input only).
public static func resolvePersonalReplyStyle(
id: String,
userCatalog: PolishStyleCatalog
) -> PolishStylePack? {
guard !id.isEmpty,
let pack = userCatalog.entries.first(where: { $0.id == id }),
isPersonalReplyStyle(pack) else { return nil }
return pack
}
/// Newest distilled personal style. Used by the Skills page and by the
/// one-shot migration that splits voice input from AI replies.
public static func latestPersonalReplyStyle(
userCatalog: PolishStyleCatalog
) -> PolishStylePack? {
userCatalog.entries
.filter(isPersonalReplyStyle)
.max { $0.updatedAt < $1.updatedAt }
}
/// Fun personality packs that fully rewrite voice (dating / flex / corp / diba / xhs).
@@ -303,6 +303,39 @@ public final class ProviderConfig: ObservableObject, @unchecked Sendable {
}
}
/// When enabled (and history is on), a freshly copied replyable message is
/// auto-routed into the Reply flow when the keyboard opens. Default off.
@Published public var clipboardAutoModeEnabled: Bool {
didSet {
guard !isApplyingConfiguration,
clipboardAutoModeEnabled != configuration.clipboardAutoModeEnabled else { return }
configuration.clipboardAutoModeEnabled = clipboardAutoModeEnabled
persistConfiguration(postConfigChanged: true)
}
}
/// When enabled (and history is on), a freshly copied non-system-language
/// paste is auto-translated on open. Default off.
@Published public var clipboardAutoTranslateEnabled: Bool {
didSet {
guard !isApplyingConfiguration,
clipboardAutoTranslateEnabled != configuration.clipboardAutoTranslateEnabled else { return }
configuration.clipboardAutoTranslateEnabled = clipboardAutoTranslateEnabled
persistConfiguration(postConfigChanged: true)
}
}
/// When enabled (and history is on), a freshly copied email auto-drafts a
/// reply on open. Default off.
@Published public var clipboardAutoEmailReplyEnabled: Bool {
didSet {
guard !isApplyingConfiguration,
clipboardAutoEmailReplyEnabled != configuration.clipboardAutoEmailReplyEnabled else { return }
configuration.clipboardAutoEmailReplyEnabled = clipboardAutoEmailReplyEnabled
persistConfiguration(postConfigChanged: true)
}
}
/// When enabled, the host app tries to return to the source app after a cold-start handoff.
@Published public var flowSkipAppSwitch: Bool {
didSet {
@@ -454,6 +487,9 @@ public final class ProviderConfig: ObservableObject, @unchecked Sendable {
llmThinkingEnabled = configuration.llmThinkingEnabled
clipboardHistoryEnabled = configuration.clipboardHistoryEnabled
clipboardCandidateBarEnabled = configuration.clipboardCandidateBarEnabled
clipboardAutoModeEnabled = configuration.clipboardAutoModeEnabled
clipboardAutoTranslateEnabled = configuration.clipboardAutoTranslateEnabled
clipboardAutoEmailReplyEnabled = configuration.clipboardAutoEmailReplyEnabled
flowSkipAppSwitch = configuration.flowSkipAppSwitch
flowInactivityDuration = configuration.flowInactivityDuration
localASRCustomLanguageModelEnabled = configuration.localASRCustomLanguageModelEnabled
@@ -487,6 +523,9 @@ public final class ProviderConfig: ObservableObject, @unchecked Sendable {
llmThinkingEnabled = false
clipboardHistoryEnabled = false
clipboardCandidateBarEnabled = false
clipboardAutoModeEnabled = false
clipboardAutoTranslateEnabled = false
clipboardAutoEmailReplyEnabled = false
hasAcknowledgedCloudSharing = false
credentialSource = .byok
configuration.providerId = polishPreset.id
@@ -504,6 +543,9 @@ public final class ProviderConfig: ObservableObject, @unchecked Sendable {
configuration.llmThinkingEnabled = false
configuration.clipboardHistoryEnabled = false
configuration.clipboardCandidateBarEnabled = false
configuration.clipboardAutoModeEnabled = false
configuration.clipboardAutoTranslateEnabled = false
configuration.clipboardAutoEmailReplyEnabled = false
configuration.hasAcknowledgedCloudSharing = false
configuration.credentialSource = .byok
isApplyingConfiguration = false
@@ -562,6 +604,9 @@ public final class ProviderConfig: ObservableObject, @unchecked Sendable {
llmThinkingEnabled = fresh.llmThinkingEnabled
clipboardHistoryEnabled = fresh.clipboardHistoryEnabled
clipboardCandidateBarEnabled = fresh.clipboardCandidateBarEnabled
clipboardAutoModeEnabled = fresh.clipboardAutoModeEnabled
clipboardAutoTranslateEnabled = fresh.clipboardAutoTranslateEnabled
clipboardAutoEmailReplyEnabled = fresh.clipboardAutoEmailReplyEnabled
flowSkipAppSwitch = fresh.flowSkipAppSwitch
flowInactivityDuration = fresh.flowInactivityDuration
localASRCustomLanguageModelEnabled = fresh.localASRCustomLanguageModelEnabled
@@ -31,6 +31,8 @@ public struct SyncedAppSettingsV2: Codable, Equatable, Sendable {
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>
@@ -56,6 +58,7 @@ public struct SyncedAppSettingsV2: Codable, Equatable, Sendable {
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,
@@ -94,6 +97,7 @@ public struct SyncedAppSettingsV2: Codable, Equatable, Sendable {
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.
@@ -124,6 +128,7 @@ public struct SyncedAppSettingsV2: Codable, Equatable, Sendable {
case aiResponseLength
case multipleReplyVariantsEnabled
case activePolishStyleId
case personalReplyStyleId
case llmThinkingEnabled
case clipboardHistoryEnabled
case clipboardCandidateBarEnabled
@@ -198,6 +203,17 @@ public struct SyncedAppSettingsV2: Codable, Equatable, Sendable {
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
@@ -269,6 +285,7 @@ public struct SyncedAppSettingsV2: Codable, Equatable, Sendable {
aiResponseLength.updatedAt,
multipleReplyVariantsEnabled.updatedAt,
activePolishStyleId.updatedAt,
personalReplyStyleId.updatedAt,
llmThinkingEnabled.updatedAt,
flowSkipAppSwitch.updatedAt,
flowInactivityDuration.updatedAt
@@ -297,6 +314,7 @@ public struct SyncedAppSettingsV2: Codable, Equatable, Sendable {
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)
@@ -337,6 +355,7 @@ public extension SyncedAppSettingsV2 {
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)
@@ -370,6 +389,7 @@ public extension SyncedAppSettingsV2 {
aiResponseLength: field(AIResponseLength.default),
multipleReplyVariantsEnabled: field(true),
activePolishStyleId: field(PolishStylePackCatalog.defaultID),
personalReplyStyleId: field(""),
llmThinkingEnabled: field(false),
flowSkipAppSwitch: field(legacy.flowSkipAppSwitch),
flowInactivityDuration: field(legacy.flowInactivityDuration)
@@ -421,6 +441,10 @@ public extension SyncedAppSettingsV2 {
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(
@@ -449,7 +473,17 @@ public extension SyncedAppSettingsV2 {
configuration.polishIntensity = polishIntensity.value
configuration.aiResponseLength = aiResponseLength.value
configuration.multipleReplyVariantsEnabled = multipleReplyVariantsEnabled.value
configuration.activePolishStyleId = activePolishStyleId.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
@@ -481,6 +515,7 @@ public extension SyncedAppSettingsV2 {
patch(&copy.aiResponseLength, value: configuration.aiResponseLength)
patch(&copy.multipleReplyVariantsEnabled, value: configuration.multipleReplyVariantsEnabled)
patch(&copy.activePolishStyleId, value: configuration.activePolishStyleId)
patch(&copy.personalReplyStyleId, value: configuration.personalReplyStyleId)
patch(&copy.llmThinkingEnabled, value: configuration.llmThinkingEnabled)
patch(&copy.flowSkipAppSwitch, value: configuration.flowSkipAppSwitch)
patch(&copy.flowInactivityDuration, value: configuration.flowInactivityDuration)
@@ -515,6 +550,7 @@ public extension SyncedAppSettingsV2 {
touch(&copy.aiResponseLength, value: configuration.aiResponseLength)
touch(&copy.multipleReplyVariantsEnabled, value: configuration.multipleReplyVariantsEnabled)
touch(&copy.activePolishStyleId, value: configuration.activePolishStyleId)
touch(&copy.personalReplyStyleId, value: configuration.personalReplyStyleId)
touch(&copy.llmThinkingEnabled, value: configuration.llmThinkingEnabled)
touch(&copy.flowSkipAppSwitch, value: configuration.flowSkipAppSwitch)
touch(&copy.flowInactivityDuration, value: configuration.flowInactivityDuration)
@@ -26,39 +26,7 @@ public struct TranslationLanguage: Identifiable, Hashable, Sendable {
self.nativeName = nativeName
}
/// One-character Chinese token for compact chips such as「中译英」.
public var chineseShort: String {
switch id {
case "en": return "英"
case "zh-Hans": return "中"
case "zh-Hant": return "繁"
case "ja": return "日"
case "ko": return "韩"
case "fr": return "法"
case "de": return "德"
case "es": return "西"
case "ru": return "俄"
case "pt": return "葡"
default: return nativeName
}
}
/// Country-style English code for compact chips such as「To JP」.
public var englishShort: String {
switch id {
case "en": return "EN"
case "zh-Hans": return "CN"
case "zh-Hant": return "TW"
case "ja": return "JP"
case "ko": return "KR"
case "fr": return "FR"
case "de": return "DE"
case "es": return "ES"
case "ru": return "RU"
case "pt": return "PT"
default: return id.uppercased()
}
}
/// True when this target is a Chinese script (简体 or 繁體).
public var isChineseScript: Bool {
@@ -195,6 +195,22 @@ public final class TypingInputConfiguration: ObservableObject {
(defaults ?? AppGroup.defaultsIfAvailable)?.bool(forKey: Key.rememberLastSurface) ?? false
}
/// The surface present when the keyboard last left the screen, regardless of
/// the "remember last surface" preference. `.ai` migrates to `.voice`;
/// returns `.voice` when nothing was persisted. Auto mode uses this to send
/// the user back to the keyboard they last used after a reply takeover,
/// even when the keyboard opened straight onto voice.
nonisolated public static func lastLeftSurface(
defaults: UserDefaults? = nil
) -> KeyboardState.Surface {
guard let store = defaults ?? AppGroup.defaultsIfAvailable,
let raw = store.string(forKey: Key.lastSurface),
let surface = KeyboardState.Surface(rawValue: raw) else {
return .voice
}
return surface == .ai ? .voice : surface
}
/// Surface to show on the first frame of a keyboard presentation.
/// Prefer last-left surface when remembering; otherwise default input mode.
nonisolated public static func preferredSurfaceOnOpen(