diff --git a/PulseLoop/Coach/Apple/AppleFoundationModelsClient.swift b/PulseLoop/Coach/Apple/AppleFoundationModelsClient.swift
index 80750291..f93acf1a 100644
--- a/PulseLoop/Coach/Apple/AppleFoundationModelsClient.swift
+++ b/PulseLoop/Coach/Apple/AppleFoundationModelsClient.swift
@@ -16,10 +16,8 @@ import FoundationModels
/// guided generation can't be built for that schema (the orchestrator's
/// `JSONRepair` then recovers the object).
///
-/// **Text-only:** the shipping FoundationModels SDK has no image-input API
-/// (`PromptBuilder` accepts only text), so image attachments aren't supported
-/// on-device. The Settings UI hides the image-input option when this provider is
-/// selected, so image turns never reach this client.
+/// The coach sends text prompts to this client. Settings hides the image-input
+/// option when this provider is selected.
///
/// Like `GeminiClient`, one instance covers a single agent turn and accumulates
/// the conversation across `send` calls so repair turns keep prior context.
@@ -150,8 +148,11 @@ final class AppleFoundationModelsClient: ResponsesClient, @unchecked Sendable {
@available(iOS 26.0, *)
private func generate(requestBody: Data) async throws -> OpenAIResponse {
- guard SystemLanguageModel.default.isAvailable else {
- throw ResponsesError.http(status: 503, body: AppleOnDeviceAvailability.current.statusMessage)
+ // iOS supplies the model, including Apple's updated version on iOS 27.
+ let model = SystemLanguageModel.default
+ guard model.isAvailable else {
+ let statusMessage = await MainActor.run { AppleOnDeviceAvailability.current.statusMessage }
+ throw ResponsesError.http(status: 503, body: statusMessage)
}
let (schema, schemaName) = try ingest(requestBody)
@@ -161,7 +162,7 @@ final class AppleFoundationModelsClient: ResponsesClient, @unchecked Sendable {
let instructions = systemText.isEmpty
? "You are a concise, supportive personal health coach."
: systemText
- let session = LanguageModelSession(instructions: instructions)
+ let session = LanguageModelSession(model: model, instructions: instructions)
let text: String
if let schema, let generated = try? await respondGuided(session: session, prompt: prompt, schema: schema, name: schemaName) {
diff --git a/PulseLoop/Coach/Config/CoachSettings.swift b/PulseLoop/Coach/Config/CoachSettings.swift
index 178c83b2..76157a94 100644
--- a/PulseLoop/Coach/Config/CoachSettings.swift
+++ b/PulseLoop/Coach/Config/CoachSettings.swift
@@ -86,23 +86,15 @@ enum ReasoningEffort: String, CaseIterable, Identifiable {
/// Levels every reasoning-capable model accepts — offered for a Custom slug.
static let common: [ReasoningEffort] = [.low, .medium, .high]
- /// GPT-6 Sol/Astra and Claude 5.5.
static let lowToMax: [ReasoningEffort] = [.low, .medium, .high, .xhigh, .max]
}
/// Preset MiniMax model choices surfaced in Settings. MiniMax's catalog is small
/// and fixed (unlike OpenRouter), so these are exact API model names rather than a
-/// free-text field. The stored `CoachSettings.model` stays a string, so a new
-/// model name still works if typed/served; these are just the curated picks.
-///
-/// The M2.5 and M2.7 families are omitted: MiniMax closes them to new users on
-/// Oct 19 2026 and retires them on Nov 18 2026. `MiniMax-M3.1-Flash-Preview` is
-/// plan-only (not pay-as-you-go), so it isn't offered to API-key users either.
+/// free-text field. The stored `CoachSettings.model` stays a string.
enum MiniMaxModel: String, CaseIterable, Identifiable {
- case m3 = "MiniMax-M3"
- case m21 = "MiniMax-M2.1"
- case m21highspeed = "MiniMax-M2.1-highspeed"
- case m2 = "MiniMax-M2"
+ case m31Flash = "MiniMax-M3.1-Flash"
+ case m3 = "MiniMax-M3"
var id: String { rawValue }
@@ -110,25 +102,26 @@ enum MiniMaxModel: String, CaseIterable, Identifiable {
var blurb: String {
switch self {
- case .m3: return "Latest — agentic reasoning, tool use, 1M context (default)"
- case .m21: return "Strong multi-language programming (~60 tps)"
- case .m21highspeed: return "M2.1 — faster (~100 tps)"
- case .m2: return "Agentic capabilities, advanced reasoning"
+ case .m31Flash: return "Fast & lower cost (default)"
+ case .m3: return "Multimodal reasoning & tool use"
}
}
- /// Sensible default when switching to MiniMax — the latest agentic model, best
- /// suited to the coach's multi-round tool loop.
- static let `default` = MiniMaxModel.m3
+ var reasoningEfforts: [ReasoningEffort] {
+ self == .m31Flash ? ReasoningEffort.lowToMax : []
+ }
+
+ static let `default` = MiniMaxModel.m31Flash
}
-/// Preset Gemini model choices surfaced in Settings. `gemini-2.0-flash` was shut
-/// down June 1 2026, and since Sep 18 2026 the 2.5 models only serve keys that
-/// already used them, so the picks are the current Gemini 3/4 models.
+/// Preset Gemini model choices surfaced in Settings.
enum GeminiModel: String, CaseIterable, Identifiable {
case flash38 = "gemini-3.8-flash"
case flashLite = "gemini-3.5-flash-lite"
case argon = "gemini-4-argon"
+ case hydrogen = "gemini-4-hydrogen"
+ case neon = "gemini-4-neon"
+ case carbon = "gemini-4-carbon"
var id: String { rawValue }
@@ -138,16 +131,19 @@ enum GeminiModel: String, CaseIterable, Identifiable {
switch self {
case .flash38: return "Fast & capable (default)"
case .flashLite: return "Lowest cost & latency"
- case .argon: return "Best reasoning"
+ case .argon: return "Deep reasoning"
+ case .hydrogen: return "Fast Gemini 4 reasoning"
+ case .neon: return "Balanced Gemini 4 reasoning"
+ case .carbon: return "Best Gemini 4 reasoning"
}
}
- /// Accepted `thinkingConfig.thinkingLevel` values — 3.8 Flash and 4 Argon
- /// reject `minimal`.
+ /// Accepted `thinkingConfig.thinkingLevel` values.
var reasoningEfforts: [ReasoningEffort] {
switch self {
case .flashLite: return [.minimal, .low, .medium, .high]
- case .flash38, .argon: return [.low, .medium, .high]
+ case .flash38, .argon, .carbon: return [.low, .medium, .high]
+ case .hydrogen, .neon: return [.low, .medium, .high, .xhigh]
}
}
@@ -163,11 +159,17 @@ enum OpenRouterModel: String, CaseIterable, Identifiable {
case claudeSonnet = "anthropic/claude-sonnet-5.5"
case claudeOpus = "anthropic/claude-opus-5.5"
case claudeHaiku = "anthropic/claude-haiku-5.5"
- case gptSol = "openai/gpt-6.1-sol"
+ case claudeFable = "anthropic/claude-fable-5.2"
+ case gptAstra = "openai/gpt-6.2-astra"
+ case gptSol = "openai/gpt-6.2-sol"
+ case gptSol61 = "openai/gpt-6.1-sol"
case gptLuna = "openai/gpt-6-luna"
case geminiPro = "google/gemini-4-argon"
case geminiFlash = "google/gemini-3.8-flash"
- case deepseek = "deepseek/deepseek-v4.1-flash"
+ case geminiNeon = "google/gemini-4-neon"
+ case geminiLite = "google/gemini-3.5-flash-lite"
+ case deepseek = "deepseek/deepseek-v4.1-flash-1017"
+ case deepseek910 = "deepseek/deepseek-v4.1-flash"
var id: String { rawValue }
@@ -176,23 +178,32 @@ enum OpenRouterModel: String, CaseIterable, Identifiable {
var blurb: String {
switch self {
case .claudeSonnet: return "Balanced, great for coaching (default)"
- case .claudeOpus: return "Most capable Claude"
+ case .claudeOpus: return "Advanced reasoning"
case .claudeHaiku: return "Fastest, lowest-cost Claude"
+ case .claudeFable: return "Most capable Claude"
+ case .gptAstra: return "Best OpenAI reasoning"
case .gptSol: return "OpenAI balanced flagship"
+ case .gptSol61: return "Previous-generation Sol"
case .gptLuna: return "Lower cost & latency"
case .geminiPro: return "Deep reasoning"
case .geminiFlash: return "Fast & capable"
+ case .geminiNeon: return "Balanced Gemini 4 reasoning"
+ case .geminiLite: return "Lowest-cost Gemini"
case .deepseek: return "Strong open reasoning, low cost"
+ case .deepseek910: return "Previous DeepSeek V4.1 Flash snapshot"
}
}
/// Effort levels the model lists in OpenRouter's `reasoning.supported_efforts`.
var reasoningEfforts: [ReasoningEffort] {
switch self {
- case .claudeSonnet, .claudeOpus, .claudeHaiku, .gptSol: return ReasoningEffort.lowToMax
- case .gptLuna: return [.none] + ReasoningEffort.lowToMax
+ case .claudeSonnet, .claudeOpus, .claudeFable, .gptAstra, .gptSol, .gptSol61:
+ return ReasoningEffort.lowToMax
+ case .claudeHaiku, .gptLuna: return [.none] + ReasoningEffort.lowToMax
case .geminiPro, .geminiFlash: return [.low, .medium, .high]
- case .deepseek: return [.low, .high, .max]
+ case .geminiNeon: return [.low, .medium, .high, .xhigh]
+ case .geminiLite: return [.minimal, .low, .medium, .high]
+ case .deepseek, .deepseek910: return [.none, .low, .high, .max]
}
}
@@ -206,8 +217,11 @@ enum OpenRouterModel: String, CaseIterable, Identifiable {
/// just the curated picks surfaced in Settings.
enum CoachModel: String, CaseIterable, Identifiable {
case luna = "gpt-6-luna"
- case sol = "gpt-6.1-sol"
- case astra = "gpt-6-astra"
+ case terra = "gpt-6.1-terra"
+ case sol = "gpt-6.2-sol"
+ case astra = "gpt-6.2-astra"
+ case sol61 = "gpt-6.1-sol"
+ case astra60 = "gpt-6-astra"
var id: String { rawValue }
@@ -216,16 +230,19 @@ enum CoachModel: String, CaseIterable, Identifiable {
var blurb: String {
switch self {
case .luna: return "Lower cost & latency"
+ case .terra: return "Efficient reasoning"
case .sol: return "Balanced (default)"
case .astra: return "Best reasoning"
+ case .sol61: return "Previous-generation Sol"
+ case .astra60: return "Previous-generation Astra"
}
}
/// Accepted `reasoning.effort` levels — Sol and Astra reject `none` (HTTP 400).
var reasoningEfforts: [ReasoningEffort] {
switch self {
- case .luna: return [.none] + ReasoningEffort.lowToMax
- case .sol, .astra: return ReasoningEffort.lowToMax
+ case .luna, .terra: return [.none] + ReasoningEffort.lowToMax
+ case .sol, .astra, .sol61, .astra60: return ReasoningEffort.lowToMax
}
}
@@ -326,9 +343,13 @@ struct CoachSettings: Codable, Equatable {
var knownReasoningEfforts: [ReasoningEffort]? {
switch providerMode {
case .userOpenAIKey: return CoachModel(rawValue: model)?.reasoningEfforts
- case .userOpenRouterKey: return OpenRouterModel(rawValue: model)?.reasoningEfforts
- // A non-preset Gemini model may be a 2.5 model, which rejects `thinkingLevel`.
+ case .userOpenRouterKey:
+ let slug = openRouterModel
+ let base = slug.hasSuffix(":online") ? String(slug.dropLast(":online".count)) : slug
+ return OpenRouterModel(rawValue: base)?.reasoningEfforts
+ // Older Gemini models can reject `thinkingLevel`.
case .userGeminiKey: return GeminiModel(rawValue: model)?.reasoningEfforts ?? []
+ case .userMiniMaxKey: return MiniMaxModel(rawValue: minimaxModel)?.reasoningEfforts ?? []
default: return nil
}
}
@@ -355,6 +376,36 @@ struct CoachSettings: Codable, Equatable {
init() {}
+ /// Replace only known retired IDs for the saved provider. Stored message IDs
+ /// and usage prices are separate from these settings.
+ private static func migrateRetiredModel(_ model: String, provider: CoachProviderMode) -> String {
+ let trimmed = model.trimmingCharacters(in: .whitespacesAndNewlines)
+ switch provider {
+ case .userGeminiKey:
+ switch trimmed {
+ case "gemini-2.0-flash", "gemini-2.0-flash-001", "gemini-2.5-pro": return GeminiModel.flash38.rawValue
+ case "gemini-2.5-flash": return GeminiModel.flashLite.rawValue
+ default: return model
+ }
+ case .userOpenRouterKey:
+ switch trimmed {
+ case "google/gemini-2.5-pro": return OpenRouterModel.geminiFlash.rawValue
+ case "google/gemini-2.5-pro:online": return OpenRouterModel.geminiFlash.rawValue + ":online"
+ case "google/gemini-2.5-flash": return OpenRouterModel.geminiLite.rawValue
+ case "google/gemini-2.5-flash:online": return OpenRouterModel.geminiLite.rawValue + ":online"
+ default: return model
+ }
+ case .userMiniMaxKey:
+ switch trimmed.lowercased() {
+ case "minimax-m2", "minimax-m2.1", "minimax-m2.1-highspeed",
+ "minimax-m2.5", "minimax-m2.5-highspeed", "minimax-m2.7", "minimax-m2.7-highspeed":
+ return MiniMaxModel.default.rawValue
+ default: return model
+ }
+ default: return model
+ }
+ }
+
/// Tolerant decode: missing keys (older stored settings, new fields) fall back
/// to defaults instead of failing the whole decode.
init(from decoder: Decoder) throws {
@@ -362,7 +413,8 @@ struct CoachSettings: Codable, Equatable {
let d = CoachSettings.default
coachMasterEnabled = try c.decodeIfPresent(Bool.self, forKey: .coachMasterEnabled) ?? d.coachMasterEnabled
providerMode = try c.decodeIfPresent(CoachProviderMode.self, forKey: .providerMode) ?? d.providerMode
- model = try c.decodeIfPresent(String.self, forKey: .model) ?? d.model
+ let storedModel = try c.decodeIfPresent(String.self, forKey: .model) ?? d.model
+ model = Self.migrateRetiredModel(storedModel, provider: providerMode)
reasoningEffort = try c.decodeIfPresent(String.self, forKey: .reasoningEffort)
enableWebSearch = try c.decodeIfPresent(Bool.self, forKey: .enableWebSearch) ?? d.enableWebSearch
orEnablePrivacyRouting = try c.decodeIfPresent(Bool.self, forKey: .orEnablePrivacyRouting) ?? d.orEnablePrivacyRouting
diff --git a/PulseLoop/Coach/Config/CoachSettingsSection.swift b/PulseLoop/Coach/Config/CoachSettingsSection.swift
index 6415371e..8fd4c87b 100644
--- a/PulseLoop/Coach/Config/CoachSettingsSection.swift
+++ b/PulseLoop/Coach/Config/CoachSettingsSection.swift
@@ -100,13 +100,12 @@ struct CoachSettingsSection: View {
!OpenRouterModel.allCases.contains { $0.rawValue == store.settings.model }
}
- /// Whether to offer the image-input (multimodal) toggle. Hidden on-device (no
- /// image API) and on text-only MiniMax models — only MiniMax-M3 is multimodal,
- /// so attaching a photo to M2.x would just error.
+ /// Whether to offer image input. The Apple coach client sends text prompts,
+ /// and image support on MiniMax is model-specific.
private var showsImageInputToggle: Bool {
switch store.settings.providerMode {
case .appleOnDevice: return false
- case .userMiniMaxKey: return store.settings.model == MiniMaxModel.m3.rawValue
+ case .userMiniMaxKey: return MiniMaxModel(rawValue: store.settings.minimaxModel) != nil
default: return true
}
}
@@ -149,9 +148,7 @@ struct CoachSettingsSection: View {
}
}
- // On-device has a single fixed model and runs only on-device (no
- // cloud backup) — show a privacy/availability card instead of a
- // model picker.
+ // iOS supplies the on-device model. Show its availability here.
if store.settings.providerMode == .appleOnDevice {
appleOnDeviceCard
} else if store.settings.providerMode == .localOpenAICompat {
@@ -276,6 +273,14 @@ struct CoachSettingsSection: View {
SettingsGroup(header: "Routing") {
FormToggleRow(title: "Privacy routing", isOn: privacyRoutingBinding)
+ let fable = OpenRouterModel.claudeFable.rawValue
+ let model = store.settings.openRouterModel
+ if model == fable || model == fable + ":online" {
+ Text("Claude Fable 5.2 requests are retained for safety monitoring.")
+ .font(.caption)
+ .foregroundStyle(PulseColors.textMuted)
+ }
+
FormValueRow(title: "Provider sort") {
Picker("Provider sort", selection: providerSortBinding) {
Text("Default").tag("")
@@ -408,7 +413,7 @@ struct CoachSettingsSection: View {
// MARK: - On-device (Apple) info card
/// Privacy + availability panel shown when the on-device provider is picked.
- /// Replaces the model picker (the model is fixed) and explains the v1 limits.
+ /// Describes the system-supplied model and supported coach features.
private var appleOnDeviceCard: some View {
let availability = AppleOnDeviceAvailability.current
return FormField {
@@ -422,7 +427,7 @@ struct CoachSettingsSection: View {
.foregroundStyle(PulseColors.textPrimary)
}
Text(availability.isAvailable
- ? "Your health data is analyzed entirely on your iPhone and never leaves the device. No API key, no network — works offline and free of charge."
+ ? "Coach uses Apple's updated on-device model on iOS 27 and later. It works offline and needs no API key."
: availability.statusMessage)
.font(PulseFont.caption.weight(.regular))
.foregroundStyle(PulseColors.textSecondary)
@@ -552,10 +557,7 @@ struct CoachSettingsSection: View {
} else {
store.settings.model = newValue
}
- // MiniMax: only M3 is multimodal — drop image input on text-only
- // picks so the (now hidden) toggle can't linger enabled.
- if store.settings.providerMode == .userMiniMaxKey,
- store.settings.model != MiniMaxModel.m3.rawValue {
+ if store.settings.providerMode == .userMiniMaxKey, !showsImageInputToggle {
store.settings.enableImageInput = false
}
}
diff --git a/PulseLoop/Coach/MiniMax/MiniMaxClient.swift b/PulseLoop/Coach/MiniMax/MiniMaxClient.swift
index 4eb80143..22be1bbf 100644
--- a/PulseLoop/Coach/MiniMax/MiniMaxClient.swift
+++ b/PulseLoop/Coach/MiniMax/MiniMaxClient.swift
@@ -12,6 +12,7 @@ import Foundation
/// `reasoning` object — so none of those are sent. The coach's output shape is
/// enforced by the injected `promptInstruction` system message plus the
/// orchestrator's JSON-repair loop, exactly as in the OpenRouter fallback path.
+/// M3.1 Flash accepts a top-level `reasoning_effort`.
///
/// State across turns: the OpenAI Responses API is stateful; Chat Completions is
/// stateless. This class accumulates the conversation as Chat Completions
@@ -27,8 +28,8 @@ final class MiniMaxClient: ResponsesClient, @unchecked Sendable {
// Accumulated Chat Completions messages for this turn.
private var messages: [[String: Any]] = []
- // Maps generated response IDs → the assistant message dict (content + tool_calls)
- // so a continuation turn can re-insert it before the matching tool results.
+ // Maps response IDs to the assistant message so a continuation turn can
+ // replay its text, reasoning, and tool calls before the matching tool results.
private var storedAssistantMessage: [String: [String: Any]] = [:]
init(
@@ -58,7 +59,8 @@ final class MiniMaxClient: ResponsesClient, @unchecked Sendable {
appendContinuation(previousId: previousResponseId!, input: input)
}
- let body = buildChatBody(tools: convertTools(tools))
+ let effort = (req["reasoning"] as? [String: Any])?["effort"] as? String
+ let body = buildChatBody(tools: convertTools(tools), reasoningEffort: effort)
let bodyData = try JSONSerialization.data(withJSONObject: body, options: [.withoutEscapingSlashes])
var request = URLRequest(url: endpoint)
@@ -171,9 +173,13 @@ final class MiniMaxClient: ResponsesClient, @unchecked Sendable {
// MARK: - Build request body
- private func buildChatBody(tools: [[String: Any]]) -> [String: Any] {
+ private func buildChatBody(tools: [[String: Any]], reasoningEffort: String?) -> [String: Any] {
var body: [String: Any] = ["model": model, "messages": messages]
if !tools.isEmpty { body["tools"] = tools }
+ if let reasoningEffort, let effort = ReasoningEffort(rawValue: reasoningEffort),
+ MiniMaxModel(rawValue: model)?.reasoningEfforts.contains(effort) == true {
+ body["reasoning_effort"] = effort.rawValue
+ }
return body
}
@@ -205,12 +211,15 @@ final class MiniMaxClient: ResponsesClient, @unchecked Sendable {
let responseId = (root["id"] as? String).map { $0.isEmpty ? UUID().uuidString : $0 } ?? UUID().uuidString
var outputItems: [ResponseOutputItem] = []
- // Persist the raw assistant message so a continuation turn can replay it.
+ // Preserve provider reasoning for subsequent tool calls without exposing it as reply text.
var assistantMessage: [String: Any] = ["role": "assistant"]
+ if let reasoning = message["reasoning_content"] as? String {
+ assistantMessage["reasoning_content"] = reasoning
+ }
if let rawContent = message["content"] as? String {
- // M-series models emit reasoning inline as `…` blocks by
- // default; strip them so the coach_response JSON parses cleanly.
+ // Older M-series models can emit inline `` blocks. Strip them
+ // so the coach_response JSON parses cleanly.
let content = stripThinking(rawContent)
if !content.isEmpty {
outputItems.append(.message(text: content))
diff --git a/PulseLoop/Coach/OpenAI/OpenAIResponsesClient.swift b/PulseLoop/Coach/OpenAI/OpenAIResponsesClient.swift
index a059fdb8..6c127c5e 100644
--- a/PulseLoop/Coach/OpenAI/OpenAIResponsesClient.swift
+++ b/PulseLoop/Coach/OpenAI/OpenAIResponsesClient.swift
@@ -3,7 +3,7 @@ import Foundation
/// Transport-agnostic interface the orchestrator depends on (so tests can inject
/// a stub). Takes a pre-serialized request body so no non-Sendable dictionaries
/// cross the concurrency boundary.
-protocol ResponsesClient: Sendable {
+nonisolated protocol ResponsesClient: Sendable {
func send(requestBody: Data) async throws -> OpenAIResponse
}
diff --git a/PulseLoop/Coach/OpenRouter/OpenRouterClient.swift b/PulseLoop/Coach/OpenRouter/OpenRouterClient.swift
index 76b34a41..d48ba78b 100644
--- a/PulseLoop/Coach/OpenRouter/OpenRouterClient.swift
+++ b/PulseLoop/Coach/OpenRouter/OpenRouterClient.swift
@@ -25,8 +25,7 @@ final class OpenRouterClient: ResponsesClient, @unchecked Sendable {
// Accumulated Chat Completions messages for this turn.
private var messages: [[String: Any]] = []
- // Maps generated response IDs → the assistant message dict (content + tool_calls)
- // so a continuation turn can re-insert it before the matching tool results.
+ // Maps generated response IDs to assistant messages for replay before matching tool results.
private var storedAssistantMessage: [String: [String: Any]] = [:]
// Set in `convertTools` when the orchestrator's hosted `web_search` tool spec
// is seen; routes to OpenRouter's `:online` model suffix (see `onlineModelSlug`).
@@ -346,6 +345,10 @@ final class OpenRouterClient: ResponsesClient, @unchecked Sendable {
if outputItems.isEmpty { throw ResponsesError.emptyOutput }
+ // OpenRouter needs the original reasoning details when continuing a tool call.
+ if let details = message["reasoning_details"] as? [[String: Any]] {
+ assistantMessage["reasoning_details"] = details
+ }
storedAssistantMessage[responseId] = assistantMessage
return OpenAIResponse(id: responseId, outputItems: outputItems, usage: usage(from: root))
}
diff --git a/PulseLoop/Coach/Usage/CoachModelPricing.swift b/PulseLoop/Coach/Usage/CoachModelPricing.swift
index 389a53e4..21610d69 100644
--- a/PulseLoop/Coach/Usage/CoachModelPricing.swift
+++ b/PulseLoop/Coach/Usage/CoachModelPricing.swift
@@ -20,7 +20,7 @@ struct CoachModelPrice: Equatable {
/// `nil` so the UI can show "cost unavailable" rather than a wrong number.
enum CoachPricingCatalog {
/// Normalized-key → published list price, standard (non-batch) tier, as of
- /// October 2026. Sources: platform OpenAI/Google/DeepSeek/MiniMax pricing pages,
+ /// December 2026. Sources: platform OpenAI/Google/DeepSeek/MiniMax pricing pages,
/// platform.claude.com pricing docs, and openrouter.ai model pages. Estimates
/// only — OpenRouter's API-reported exact cost always takes precedence. Models
/// that dropped out of the pickers keep their entry so a stored or Custom
@@ -29,6 +29,9 @@ enum CoachPricingCatalog {
// OpenAI (native) — CoachModel enum. GPT-6 bills the whole request at 2x
// input / 1.5x output above 272k input tokens.
"gpt-6-luna": CoachModelPrice(inputPer1M: 0.10, cachedInputPer1M: 0.01, outputPer1M: 0.50),
+ "gpt-6.1-terra": CoachModelPrice(inputPer1M: 1.00, cachedInputPer1M: 0.05, outputPer1M: 5.00),
+ "gpt-6.2-sol": CoachModelPrice(inputPer1M: 2.00, cachedInputPer1M: 0.10, outputPer1M: 10.00),
+ "gpt-6.2-astra": CoachModelPrice(inputPer1M: 8.00, cachedInputPer1M: 0.40, outputPer1M: 40.00),
"gpt-6.1-sol": CoachModelPrice(inputPer1M: 2.00, cachedInputPer1M: 0.10, outputPer1M: 10.00),
"gpt-6-astra": CoachModelPrice(inputPer1M: 10.00, cachedInputPer1M: 1.00, outputPer1M: 50.00),
"gpt-5.4-mini": CoachModelPrice(inputPer1M: 0.75, cachedInputPer1M: 0.075, outputPer1M: 4.50),
@@ -36,11 +39,14 @@ enum CoachPricingCatalog {
"gpt-5.5": CoachModelPrice(inputPer1M: 5.00, cachedInputPer1M: 0.50, outputPer1M: 30.00),
// Gemini (native) — GeminiModel enum. gemini-2.0-flash was shut down
// June 1 2026 and has no published price; it intentionally has no entry
- // so the UI reports "cost unavailable". 4 Argon's rates double Dec 1 2026
- // and 3.8 Flash's on Jan 1 2027.
+ // so the UI reports "cost unavailable". Google doubles 3.8 Flash's rates
+ // on Jan 1 2027.
"gemini-3.8-flash": CoachModelPrice(inputPer1M: 0.75, cachedInputPer1M: 0.075, outputPer1M: 3.75),
"gemini-3.5-flash-lite": CoachModelPrice(inputPer1M: 0.30, cachedInputPer1M: 0.03, outputPer1M: 2.50),
- "gemini-4-argon": CoachModelPrice(inputPer1M: 2.00, cachedInputPer1M: 0.10, outputPer1M: 10.00),
+ "gemini-4-argon": CoachModelPrice(inputPer1M: 4.00, cachedInputPer1M: 0.20, outputPer1M: 20.00),
+ "gemini-4-hydrogen": CoachModelPrice(inputPer1M: 1.50, cachedInputPer1M: 0.075, outputPer1M: 7.50),
+ "gemini-4-neon": CoachModelPrice(inputPer1M: 3.00, cachedInputPer1M: 0.15, outputPer1M: 15.00),
+ "gemini-4-carbon": CoachModelPrice(inputPer1M: 4.00, cachedInputPer1M: 0.20, outputPer1M: 20.00),
"gemini-2.5-flash": CoachModelPrice(inputPer1M: 0.30, cachedInputPer1M: 0.03, outputPer1M: 2.50),
"gemini-2.5-pro": CoachModelPrice(inputPer1M: 1.25, cachedInputPer1M: 0.125, outputPer1M: 10.00), // ≤200k-token tier; >200k bills 2x
// OpenRouter — OpenRouterModel enum (vendor/model slugs). List prices
@@ -48,11 +54,17 @@ enum CoachPricingCatalog {
"anthropic/claude-sonnet-5.5": CoachModelPrice(inputPer1M: 2.00, cachedInputPer1M: 0.10, outputPer1M: 10.00),
"anthropic/claude-opus-5.5": CoachModelPrice(inputPer1M: 4.00, cachedInputPer1M: 0.20, outputPer1M: 20.00),
"anthropic/claude-haiku-5.5": CoachModelPrice(inputPer1M: 0.10, cachedInputPer1M: 0.01, outputPer1M: 0.50), // ≤100k-token tier
+ "anthropic/claude-fable-5.2": CoachModelPrice(inputPer1M: 8.00, cachedInputPer1M: 0.20, outputPer1M: 40.00),
+ "openai/gpt-6.2-astra": CoachModelPrice(inputPer1M: 8.00, cachedInputPer1M: 0.40, outputPer1M: 40.00),
+ "openai/gpt-6.2-sol": CoachModelPrice(inputPer1M: 2.00, cachedInputPer1M: 0.10, outputPer1M: 10.00),
"openai/gpt-6.1-sol": CoachModelPrice(inputPer1M: 2.00, cachedInputPer1M: 0.10, outputPer1M: 10.00),
"openai/gpt-6-luna": CoachModelPrice(inputPer1M: 0.10, cachedInputPer1M: 0.01, outputPer1M: 0.50),
- "google/gemini-4-argon": CoachModelPrice(inputPer1M: 2.00, cachedInputPer1M: 0.10, outputPer1M: 10.00),
- "google/gemini-3.8-flash": CoachModelPrice(inputPer1M: 0.75, cachedInputPer1M: 0.075, outputPer1M: 3.75),
- "deepseek/deepseek-v4.1-flash": CoachModelPrice(inputPer1M: 0.016, cachedInputPer1M: 0.005, outputPer1M: 0.891), // cheapest OpenRouter endpoint
+ "google/gemini-4-argon": CoachModelPrice(inputPer1M: 4.00, cachedInputPer1M: 0.20, outputPer1M: 20.00),
+ "google/gemini-4-neon": CoachModelPrice(inputPer1M: 3.00, cachedInputPer1M: 0.15, outputPer1M: 15.00),
+ "google/gemini-3.8-flash": CoachModelPrice(inputPer1M: 0.825, cachedInputPer1M: 0.0825, outputPer1M: 4.125),
+ "google/gemini-3.5-flash-lite": CoachModelPrice(inputPer1M: 0.30, cachedInputPer1M: 0.03, outputPer1M: 2.50),
+ "deepseek/deepseek-v4.1-flash-1017": CoachModelPrice(inputPer1M: 0.02, cachedInputPer1M: 0.001, outputPer1M: 0.20),
+ "deepseek/deepseek-v4.1-flash": CoachModelPrice(inputPer1M: 0.051, cachedInputPer1M: 0.018, outputPer1M: 0.567),
"anthropic/claude-sonnet-4.6": CoachModelPrice(inputPer1M: 3.00, cachedInputPer1M: 0.30, outputPer1M: 15.00),
"anthropic/claude-opus-4.7": CoachModelPrice(inputPer1M: 5.00, cachedInputPer1M: 0.50, outputPer1M: 25.00),
"openai/gpt-5.5": CoachModelPrice(inputPer1M: 5.00, cachedInputPer1M: 0.50, outputPer1M: 30.00),
@@ -60,8 +72,8 @@ enum CoachPricingCatalog {
"google/gemini-2.5-flash": CoachModelPrice(inputPer1M: 0.30, cachedInputPer1M: 0.03, outputPer1M: 2.50),
"google/gemini-2.5-pro": CoachModelPrice(inputPer1M: 1.25, cachedInputPer1M: 0.125, outputPer1M: 10.00),
"deepseek/deepseek-v4-flash": CoachModelPrice(inputPer1M: 0.09, cachedInputPer1M: nil, outputPer1M: 0.18), // OpenRouter routes below DeepSeek's direct $0.14/$0.28
- // MiniMax — MiniMaxModel enum. -highspeed variants bill 2x the standard
- // input/output rate; M2.5/M2.7 retire Nov 18 2026.
+ // MiniMax — MiniMaxModel enum. M2-era rates are kept for historical usage.
+ "minimax-m3.1-flash": CoachModelPrice(inputPer1M: 0.15, cachedInputPer1M: 0.015, outputPer1M: 0.60),
"minimax-m3": CoachModelPrice(inputPer1M: 0.30, cachedInputPer1M: 0.06, outputPer1M: 1.20), // ≤512k-token tier; >512k bills 2x
"minimax-m2.7": CoachModelPrice(inputPer1M: 0.30, cachedInputPer1M: 0.06, outputPer1M: 1.20),
"minimax-m2.7-highspeed": CoachModelPrice(inputPer1M: 0.60, cachedInputPer1M: 0.06, outputPer1M: 2.40),
diff --git a/PulseLoop/Views/Settings/DeviceHeroCard.swift b/PulseLoop/Views/Settings/DeviceHeroCard.swift
index a0e0a06f..03f8d8ed 100644
--- a/PulseLoop/Views/Settings/DeviceHeroCard.swift
+++ b/PulseLoop/Views/Settings/DeviceHeroCard.swift
@@ -1,3 +1,4 @@
+import SwiftData
import SwiftUI
/// Pure, view-agnostic description of the ring's state for the Settings hero card.
diff --git a/PulseLoopTests/CoachTests.swift b/PulseLoopTests/CoachTests.swift
index 92fd3720..43c6bb59 100644
--- a/PulseLoopTests/CoachTests.swift
+++ b/PulseLoopTests/CoachTests.swift
@@ -577,15 +577,26 @@ final class ReasoningEffortTests: XCTestCase {
return s
}
- /// GPT-6.1 Sol rejects `none` with HTTP 400, so a level left over from Luna is
+ /// GPT-6.2 Sol rejects `none` with HTTP 400, so a level left over from Luna is
/// dropped back to the model default rather than sent.
func testUnsupportedEffortIsDropped() {
XCTAssertEqual(settings(.userOpenAIKey, CoachModel.luna.rawValue, "none").resolvedReasoningEffort, "none")
XCTAssertNil(settings(.userOpenAIKey, CoachModel.sol.rawValue, "none").resolvedReasoningEffort)
XCTAssertEqual(settings(.userOpenAIKey, CoachModel.sol.rawValue, "max").resolvedReasoningEffort, "max")
+ XCTAssertNil(settings(.userOpenRouterKey, OpenRouterModel.claudeFable.rawValue, "none").resolvedReasoningEffort)
XCTAssertNil(settings(.userOpenRouterKey, OpenRouterModel.deepseek.rawValue, "medium").resolvedReasoningEffort)
}
+ func testNewModelsUseProviderSpecificReasoningLevels() {
+ XCTAssertEqual(CoachModel.default.rawValue, "gpt-6.2-sol")
+ XCTAssertEqual(CoachModel.astra.rawValue, "gpt-6.2-astra")
+ XCTAssertEqual(settings(.userOpenAIKey, CoachModel.terra.rawValue, "none").resolvedReasoningEffort, "none")
+ XCTAssertEqual(settings(.userGeminiKey, GeminiModel.neon.rawValue, "xhigh").resolvedReasoningEffort, "xhigh")
+ XCTAssertNil(settings(.userGeminiKey, GeminiModel.carbon.rawValue, "xhigh").resolvedReasoningEffort)
+ XCTAssertEqual(settings(.userMiniMaxKey, MiniMaxModel.m31Flash.rawValue, "xhigh").resolvedReasoningEffort, "xhigh")
+ XCTAssertNil(settings(.userMiniMaxKey, MiniMaxModel.m3.rawValue, "xhigh").resolvedReasoningEffort)
+ }
+
/// A Custom OpenRouter slug isn't known, so the hint passes through and the
/// picker offers only the common levels; a non-preset Gemini model (a 2.5
/// model rejects `thinkingLevel`) gets no hint at all.
@@ -612,6 +623,46 @@ final class ReasoningEffortTests: XCTestCase {
}
}
+final class CoachModelMigrationTests: XCTestCase {
+ private func load(_ provider: CoachProviderMode, _ model: String, effort: String = "high") throws -> CoachSettings {
+ let data = try JSONEncoder().encode(["providerMode": provider.rawValue, "model": model, "reasoningEffort": effort])
+ return try JSONDecoder().decode(CoachSettings.self, from: data)
+ }
+
+ func testRetiredGeminiSelectionsUseAvailableRoutes() throws {
+ let flash = try load(.userGeminiKey, "gemini-2.5-flash")
+ XCTAssertEqual(flash.model, GeminiModel.flashLite.rawValue)
+ XCTAssertEqual(flash.resolvedReasoningEffort, "high")
+ XCTAssertEqual(try load(.userGeminiKey, "gemini-2.5-pro").model, GeminiModel.flash38.rawValue)
+ XCTAssertEqual(try load(.userGeminiKey, "gemini-2.0-flash-001").model, GeminiModel.flash38.rawValue)
+ XCTAssertEqual(try load(.userOpenRouterKey, "google/gemini-2.5-flash").openRouterModel, OpenRouterModel.geminiLite.rawValue)
+ let online = try load(.userOpenRouterKey, "google/gemini-2.5-pro:online", effort: "max")
+ XCTAssertEqual(online.openRouterModel, OpenRouterModel.geminiFlash.rawValue + ":online")
+ XCTAssertNil(online.resolvedReasoningEffort)
+ }
+
+ func testRetiredMiniMaxSelectionsUseFlash() throws {
+ let retired = ["MiniMax-M2", "MiniMax-M2.1", "MiniMax-M2.1-highspeed", "MiniMax-M2.5", "MiniMax-M2.5-highspeed",
+ "MiniMax-M2.7", "MiniMax-M2.7-highspeed"]
+ for model in retired {
+ XCTAssertEqual(try load(.userMiniMaxKey, model, effort: "none").minimaxModel, MiniMaxModel.m31Flash.rawValue)
+ XCTAssertFalse(MiniMaxModel.allCases.contains { $0.rawValue == model })
+ XCTAssertNotNil(CoachPricingCatalog.price(for: model))
+ }
+ let upgraded = try load(.userMiniMaxKey, "MiniMax-M2.1", effort: "none")
+ XCTAssertNil(upgraded.resolvedReasoningEffort)
+ XCTAssertEqual(try JSONDecoder().decode(CoachSettings.self, from: JSONEncoder().encode(upgraded)), upgraded)
+ }
+
+ func testActiveAndCustomSelectionsStaySelected() throws {
+ XCTAssertEqual(try load(.userOpenAIKey, "gpt-6.1-sol").model, "gpt-6.1-sol")
+ XCTAssertEqual(try load(.userGeminiKey, "gemini-2.5-flash-lite").model, "gemini-2.5-flash-lite")
+ XCTAssertEqual(try load(.userMiniMaxKey, "MiniMax-M3").minimaxModel, "MiniMax-M3")
+ XCTAssertEqual(try load(.userOpenRouterKey, "acme/custom-model:online").openRouterModel, "acme/custom-model:online")
+ XCTAssertEqual(try load(.localOpenAICompat, "gemini-2.5-flash").model, "gemini-2.5-flash")
+ }
+}
+
// MARK: - OpenRouterClient
final class OpenRouterClientTests: XCTestCase {
@@ -753,6 +804,36 @@ final class OpenRouterClientTests: XCTestCase {
XCTAssertEqual(reasoning["effort"] as? String, "high")
}
+ func testReplaysReasoningDetailsWithToolResults() async throws {
+ StubURLProtocol.statusCode = 200
+ StubURLProtocol.responseBody = Data(#"""
+ {"id":"gen-reasoning","choices":[{"message":{"content":null,
+ "reasoning_details":[{"type":"reasoning.encrypted","data":"opaque","format":"anthropic-claude-v1","index":0}],
+ "tool_calls":[{"id":"call_1","type":"function","function":{"name":"get_daily_summary","arguments":"{}"}}]
+ }}]}
+ """#.utf8)
+
+ let client = OpenRouterClient(apiKey: "sk-or-v1-test", model: "anthropic/claude-fable-5.2", session: session())
+ let first = try await client.send(requestBody: OpenAIRequestBuilder.data(
+ model: "x", input: [], tools: [], textFormat: nil, previousResponseId: nil, reasoningEffort: "low"))
+ let call = try XCTUnwrap(first.functionCalls.first)
+
+ StubURLProtocol.responseBody = okBody
+ _ = try await client.send(requestBody: OpenAIRequestBuilder.data(
+ model: "x", input: [OpenAIRequestBuilder.functionCallOutput(callID: call.callID, output: "{}")],
+ tools: [], textFormat: nil, previousResponseId: first.id, reasoningEffort: "low"))
+
+ let messages = try XCTUnwrap(try sentBody()["messages"] as? [[String: Any]])
+ let assistantIndex = try XCTUnwrap(messages.firstIndex { ($0["role"] as? String) == "assistant" })
+ let details = try XCTUnwrap(messages[assistantIndex]["reasoning_details"] as? [[String: Any]])
+ let expected: [[String: Any]] = [[
+ "type": "reasoning.encrypted", "data": "opaque", "format": "anthropic-claude-v1", "index": 0,
+ ]]
+ XCTAssertEqual(details as NSArray, expected as NSArray)
+ XCTAssertEqual(messages.dropFirst(assistantIndex + 1).first?["tool_call_id"] as? String, call.callID)
+ XCTAssertTrue(first.outputText.isEmpty)
+ }
+
/// Structured outputs: the Responses-API `text.format` schema must be sent as
/// Chat Completions `response_format` with `strict: true`, and the provider
/// object must carry `require_parameters: true` so OpenRouter only routes to
@@ -882,9 +963,47 @@ final class MiniMaxClientTests: XCTestCase {
let json = try sentBody()
XCTAssertNil(json["response_format"])
XCTAssertNil(json["reasoning"])
+ XCTAssertNil(json["reasoning_effort"])
XCTAssertNil(json["provider"])
}
+ func testM31FlashForwardsSupportedReasoningEffortAndImage() async throws {
+ StubURLProtocol.statusCode = 200
+ StubURLProtocol.responseBody = okBody
+
+ let client = MiniMaxClient(apiKey: "mm-test", model: "MiniMax-M3.1-Flash", session: session())
+ let imageURL = "data:image/jpeg;base64,dGVzdA=="
+ let input: [[String: Any]] = [["role": "user", "content": [
+ ["type": "input_text", "text": "What is in this photo?"],
+ ["type": "input_image", "image_url": imageURL],
+ ]]]
+ let body = try OpenAIRequestBuilder.data(
+ model: "x", input: input, tools: [], textFormat: nil,
+ previousResponseId: nil, reasoningEffort: "xhigh")
+ _ = try await client.send(requestBody: body)
+
+ let json = try sentBody()
+ XCTAssertEqual(json["reasoning_effort"] as? String, "xhigh")
+ XCTAssertNil(json["reasoning"])
+ let messages = try XCTUnwrap(json["messages"] as? [[String: Any]])
+ let parts = try XCTUnwrap(messages.first?["content"] as? [[String: Any]])
+ XCTAssertEqual(parts.last?["type"] as? String, "image_url")
+ XCTAssertEqual((parts.last?["image_url"] as? [String: String])?["url"], imageURL)
+ }
+
+ func testM31FlashOmitsUnsupportedReasoningEffort() async throws {
+ StubURLProtocol.statusCode = 200
+ StubURLProtocol.responseBody = okBody
+
+ let client = MiniMaxClient(apiKey: "mm-test", model: "MiniMax-M3.1-Flash", session: session())
+ let body = try OpenAIRequestBuilder.data(
+ model: "x", input: [], tools: [], textFormat: nil,
+ previousResponseId: nil, reasoningEffort: "none")
+ _ = try await client.send(requestBody: body)
+
+ XCTAssertNil(try sentBody()["reasoning_effort"])
+ }
+
/// M-series models emit reasoning inline as `…`; those blocks
/// must be stripped so the coach_response JSON parses.
func testStripsThinkingBlocks() async throws {
@@ -901,16 +1020,14 @@ final class MiniMaxClientTests: XCTestCase {
XCTAssertEqual(response.outputText, "the answer")
}
- /// Continuation turn: the assistant `tool_calls` message must be replayed
- /// before the `tool` result answering it (Chat Completions ordering), on the
- /// same client instance.
- func testReplaysAssistantToolCallsOnContinuation() async throws {
- let client = MiniMaxClient(apiKey: "mm-test", model: "MiniMax-M3", session: session())
+ /// Replay the assistant's tool calls and separate reasoning before the tool result.
+ func testM31FlashReplaysAssistantToolCallsAndReasoning() async throws {
+ let client = MiniMaxClient(apiKey: "mm-test", model: "MiniMax-M3.1-Flash", session: session())
// Turn 1: the model asks for a tool call.
StubURLProtocol.statusCode = 200
StubURLProtocol.responseBody = Data("""
- {"id":"mm-turn1","choices":[{"message":{"content":null,"tool_calls":[
+ {"id":"mm-turn1","choices":[{"message":{"content":null,"reasoning_content":"Check the daily summary.","tool_calls":[
{"id":"call_1","type":"function","function":{"name":"get_daily_summary","arguments":"{}"}}
]}}]}
""".utf8)
@@ -918,6 +1035,7 @@ final class MiniMaxClientTests: XCTestCase {
model: "x", input: [], tools: [], textFormat: nil,
previousResponseId: nil, reasoningEffort: nil))
let callID = try XCTUnwrap(first.functionCalls.first).callID
+ XCTAssertEqual(first.outputText, "")
// Turn 2: we feed the tool result back, keyed by the prior response id.
StubURLProtocol.responseBody = okBody
@@ -929,6 +1047,7 @@ final class MiniMaxClientTests: XCTestCase {
let messages = try XCTUnwrap(try sentBody()["messages"] as? [[String: Any]])
// The replayed assistant message carrying the tool call.
let assistant = try XCTUnwrap(messages.first { ($0["role"] as? String) == "assistant" })
+ XCTAssertEqual(assistant["reasoning_content"] as? String, "Check the daily summary.")
let toolCalls = try XCTUnwrap(assistant["tool_calls"] as? [[String: Any]])
XCTAssertEqual(toolCalls.first?["id"] as? String, "call_1")
// The tool result, ordered after the assistant message.
diff --git a/README.md b/README.md
index 938a35fe..76c5b7b6 100644
--- a/README.md
+++ b/README.md
@@ -197,8 +197,9 @@ Then build and run on your device.
A ring and an API key are optional for exploring the app: load demo data from
**Settings → Reseed demo data**. For the Coach, choose a hosted provider with
-your own key, an Apple on-device model on an eligible iPhone running iOS 26+,
-or a [local / self-hosted server](https://saksham2001.github.io/PulseLoopiOS/local-llm-coach/).
+your own key, Apple's on-device model on an eligible iPhone running iOS 26 or
+later, or a [local / self-hosted server](https://saksham2001.github.io/PulseLoopiOS/local-llm-coach/).
+On iOS 27 and later, Coach automatically uses Apple's updated on-device model.
> 📚 **Full step-by-step build, signing, and demo-data instructions:
> [Getting started — iOS](https://saksham2001.github.io/PulseLoopiOS/getting-started/ios/).**