fix(swift-ios): tolerate evolving provider catalogs
This commit is contained in:
6 files changed
+149
-41
No files matched your search
@@ -3765,6 +3765,7 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
|
||||
|| searchable.contains("thinking")
|
||||
},
|
||||
isDefault: model.isDefault ?? false,
|
||||
isLegacy: model.isLegacy,
|
||||
options: options
|
||||
)
|
||||
},
|
||||
|
||||
@@ -79,6 +79,7 @@ public struct ServerProviderModelSnapshot: Codable, Identifiable, Equatable, Sen
|
||||
public let subProvider: String?
|
||||
public let isCustom: Bool
|
||||
public let isDefault: Bool?
|
||||
public let isLegacy: Bool?
|
||||
public let capabilities: ServerModelCapabilities?
|
||||
}
|
||||
|
||||
@@ -158,6 +159,31 @@ public struct ServerConfigSnapshot: Codable, Equatable, Sendable {
|
||||
self.providers = providers
|
||||
self.settings = settings
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey { case providers, settings }
|
||||
|
||||
public init(from decoder: any Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
providers = try container.decode(
|
||||
[LossyDecodableElement<ServerProviderSnapshot>].self,
|
||||
forKey: .providers
|
||||
).compactMap(\.value)
|
||||
settings = try container.decodeIfPresent(ServerSettingsSnapshot.self, forKey: .settings)
|
||||
}
|
||||
|
||||
public func encode(to encoder: any Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(providers, forKey: .providers)
|
||||
try container.encodeIfPresent(settings, forKey: .settings)
|
||||
}
|
||||
}
|
||||
|
||||
private struct LossyDecodableElement<Value: Decodable>: Decodable {
|
||||
let value: Value?
|
||||
|
||||
init(from decoder: any Decoder) throws {
|
||||
value = try? Value(from: decoder)
|
||||
}
|
||||
}
|
||||
|
||||
public enum ServerConfigStreamEvent: Decodable, Sendable {
|
||||
@@ -167,7 +193,19 @@ public enum ServerConfigStreamEvent: Decodable, Sendable {
|
||||
case unrelated(type: String)
|
||||
|
||||
private enum CodingKeys: String, CodingKey { case type, config, payload }
|
||||
private struct ProviderPayload: Decodable { let providers: [ServerProviderSnapshot] }
|
||||
private struct ProviderPayload: Decodable {
|
||||
let providers: [ServerProviderSnapshot]
|
||||
|
||||
private enum CodingKeys: String, CodingKey { case providers }
|
||||
|
||||
init(from decoder: any Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
providers = try container.decode(
|
||||
[LossyDecodableElement<ServerProviderSnapshot>].self,
|
||||
forKey: .providers
|
||||
).compactMap(\.value)
|
||||
}
|
||||
}
|
||||
private struct SettingsPayload: Decodable { let settings: ServerSettingsSnapshot }
|
||||
|
||||
public init(from decoder: any Decoder) throws {
|
||||
|
||||
@@ -511,6 +511,7 @@ public struct FeatureModel: Identifiable, Sendable, Equatable, Hashable, Codable
|
||||
public var supportsImages: Bool
|
||||
public var supportsReasoning: Bool
|
||||
public var isDefault: Bool
|
||||
public var isLegacy: Bool?
|
||||
public var options: [FeatureModelOptionDescriptor]
|
||||
|
||||
public init(
|
||||
@@ -520,6 +521,7 @@ public struct FeatureModel: Identifiable, Sendable, Equatable, Hashable, Codable
|
||||
supportsImages: Bool = false,
|
||||
supportsReasoning: Bool = false,
|
||||
isDefault: Bool = false,
|
||||
isLegacy: Bool? = nil,
|
||||
options: [FeatureModelOptionDescriptor] = []
|
||||
) {
|
||||
self.id = id
|
||||
@@ -528,6 +530,7 @@ public struct FeatureModel: Identifiable, Sendable, Equatable, Hashable, Codable
|
||||
self.supportsImages = supportsImages
|
||||
self.supportsReasoning = supportsReasoning
|
||||
self.isDefault = isDefault
|
||||
self.isLegacy = isLegacy
|
||||
self.options = options
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,6 +210,8 @@ private struct ModelPickerSheet: View {
|
||||
.presentationDetents([.large])
|
||||
.presentationDragIndicator(.visible)
|
||||
.preferredColorScheme(.dark)
|
||||
.onAppear(perform: revealSelectedLegacyModel)
|
||||
.onChange(of: selection) { revealSelectedLegacyModel() }
|
||||
}
|
||||
|
||||
private var modelList: some View {
|
||||
@@ -369,6 +371,14 @@ private struct ModelPickerSheet: View {
|
||||
.joined(separator: "\n")
|
||||
}
|
||||
|
||||
private func revealSelectedLegacyModel() {
|
||||
guard let resolvedSelection else { return }
|
||||
legacyModelsExpanded = displaySections.legacy.contains {
|
||||
$0.provider.id == resolvedSelection.providerID
|
||||
&& $0.model.id == resolvedSelection.modelID
|
||||
}
|
||||
}
|
||||
|
||||
private var modelChangesAreLocked: Bool {
|
||||
guard let threadSelection,
|
||||
let provider = providers.first(where: { $0.id == threadSelection.providerID }) else {
|
||||
@@ -528,35 +538,8 @@ struct ProviderModelDisplaySections {
|
||||
}
|
||||
|
||||
enum ProviderModelFamilyClassifier {
|
||||
static func isCurrent(_ model: FeatureModel, provider: FeatureProvider) -> Bool {
|
||||
let providerTokens = tokens(
|
||||
[provider.id, provider.name, provider.driver].joined(separator: " ")
|
||||
)
|
||||
let modelTokens = tokens([model.id, model.name].joined(separator: " "))
|
||||
let combined = providerTokens.union(modelTokens)
|
||||
|
||||
let isCodex = !providerTokens.isDisjoint(with: ["codex", "openai"])
|
||||
|| modelTokens.contains("gpt")
|
||||
if isCodex,
|
||||
combined.contains("5"),
|
||||
combined.contains("6"),
|
||||
!combined.isDisjoint(with: ["luna", "terra", "sol"]) {
|
||||
return true
|
||||
}
|
||||
|
||||
let isClaude = !providerTokens.isDisjoint(with: ["claude", "anthropic", "claudeagent"])
|
||||
|| modelTokens.contains("claude")
|
||||
return isClaude
|
||||
&& combined.contains("5")
|
||||
&& !combined.isDisjoint(with: ["fable", "opus", "sonnet"])
|
||||
}
|
||||
|
||||
private static func tokens(_ value: String) -> Set<String> {
|
||||
Set(
|
||||
value.lowercased()
|
||||
.split { !$0.isLetter && !$0.isNumber }
|
||||
.map(String.init)
|
||||
)
|
||||
static func isCurrent(_ model: FeatureModel, provider _: FeatureProvider) -> Bool {
|
||||
model.isLegacy != true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -189,6 +189,7 @@ final class NativeContractExpansionTests: XCTestCase {
|
||||
"shortName": "Terra",
|
||||
"isCustom": false,
|
||||
"isDefault": false,
|
||||
"isLegacy": true,
|
||||
"capabilities": null
|
||||
}],
|
||||
"slashCommands": [{
|
||||
@@ -222,6 +223,8 @@ final class NativeContractExpansionTests: XCTestCase {
|
||||
XCTAssertEqual(config.settings?.newWorktreesStartFromOrigin, false)
|
||||
let model = try XCTUnwrap(provider.models.first)
|
||||
XCTAssertEqual(model.slug, "gpt-5.6-sol")
|
||||
XCTAssertNil(model.isLegacy)
|
||||
XCTAssertEqual(provider.models[1].isLegacy, true)
|
||||
let descriptors = try XCTUnwrap(model.capabilities?.optionDescriptors)
|
||||
guard case let .select(effort) = descriptors[0],
|
||||
case let .boolean(fastMode) = descriptors[1]
|
||||
@@ -258,6 +261,75 @@ final class NativeContractExpansionTests: XCTestCase {
|
||||
XCTAssertEqual(settings.defaultThreadEnvMode, .worktree)
|
||||
XCTAssertFalse(settings.newWorktreesStartFromOrigin)
|
||||
}
|
||||
|
||||
func testProviderArraysDropOnlyUnknownProviderEntries() throws {
|
||||
let providers = """
|
||||
[{
|
||||
"instanceId": "future-provider",
|
||||
"driver": "future",
|
||||
"enabled": true,
|
||||
"installed": true,
|
||||
"status": "ready",
|
||||
"auth": { "status": "authenticated" },
|
||||
"checkedAt": "2026-08-04T12:00:00.000Z",
|
||||
"models": [{
|
||||
"slug": "future-model",
|
||||
"name": "Future",
|
||||
"isCustom": false,
|
||||
"capabilities": {
|
||||
"optionDescriptors": [{ "type": "future-option" }]
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
"instanceId": "codex",
|
||||
"driver": "codex",
|
||||
"enabled": true,
|
||||
"installed": true,
|
||||
"status": "ready",
|
||||
"auth": { "status": "authenticated" },
|
||||
"checkedAt": "2026-08-04T12:00:00.000Z",
|
||||
"models": [{
|
||||
"slug": "gpt-5.6-sol",
|
||||
"name": "GPT-5.6 Sol",
|
||||
"isCustom": false,
|
||||
"isLegacy": false
|
||||
}]
|
||||
}]
|
||||
"""
|
||||
let snapshot = try JSONDecoder.t3.decode(
|
||||
ServerConfigSnapshot.self,
|
||||
from: Data(
|
||||
"""
|
||||
{
|
||||
"providers": \(providers),
|
||||
"settings": {
|
||||
"defaultThreadEnvMode": "worktree",
|
||||
"newWorktreesStartFromOrigin": false
|
||||
}
|
||||
}
|
||||
""".utf8
|
||||
)
|
||||
)
|
||||
|
||||
XCTAssertEqual(snapshot.providers.map(\.instanceId), ["codex"])
|
||||
XCTAssertEqual(snapshot.settings?.defaultThreadEnvMode, .worktree)
|
||||
|
||||
let event = try JSONDecoder.t3.decode(
|
||||
ServerConfigStreamEvent.self,
|
||||
from: Data(
|
||||
"""
|
||||
{
|
||||
"type": "providerStatuses",
|
||||
"payload": { "providers": \(providers) }
|
||||
}
|
||||
""".utf8
|
||||
)
|
||||
)
|
||||
guard case let .providerStatuses(decodedProviders) = event else {
|
||||
return XCTFail("Expected provider statuses")
|
||||
}
|
||||
XCTAssertEqual(decodedProviders.map(\.instanceId), ["codex"])
|
||||
}
|
||||
}
|
||||
|
||||
private actor AccessHTTPTransport: HTTPTransport {
|
||||
|
||||
@@ -246,7 +246,12 @@ struct DailyUXModelPickerTests {
|
||||
id: "claude",
|
||||
name: "Claude",
|
||||
models: [
|
||||
.init(id: "claude-sonnet-4", name: "Sonnet 4", isDefault: true),
|
||||
.init(
|
||||
id: "claude-sonnet-4",
|
||||
name: "Sonnet 4",
|
||||
isDefault: true,
|
||||
isLegacy: true
|
||||
),
|
||||
.init(id: "claude-opus-5", name: "Opus 5"),
|
||||
]
|
||||
),
|
||||
@@ -409,7 +414,7 @@ struct DailyUXModelPickerTests {
|
||||
.init(id: "claude-opus-5", name: "Opus 5"),
|
||||
.init(id: "claude-sonnet-5", name: "Sonnet 5"),
|
||||
.init(id: "claude-fable-5", name: "Fable 5"),
|
||||
.init(id: "claude-haiku-3", name: "Haiku 3"),
|
||||
.init(id: "claude-haiku-3", name: "Haiku 3", isLegacy: true),
|
||||
]
|
||||
),
|
||||
]
|
||||
@@ -438,7 +443,7 @@ struct DailyUXModelPickerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
func currentFamiliesAreClassifiedFromStableIDsAndNames() {
|
||||
func serverLegacyMetadataIsAuthoritative() {
|
||||
let codex = FeatureProvider(id: "work-openai", name: "Codex", driver: "codex")
|
||||
let claude = FeatureProvider(
|
||||
id: "work-claude",
|
||||
@@ -448,51 +453,57 @@ struct DailyUXModelPickerTests {
|
||||
|
||||
#expect(
|
||||
ProviderModelFamilyClassifier.isCurrent(
|
||||
.init(id: "gpt-5.6-codex-luna", name: "Luna"),
|
||||
.init(id: "gpt-5.6-codex-luna", name: "Luna", isLegacy: false),
|
||||
provider: codex
|
||||
)
|
||||
)
|
||||
#expect(
|
||||
ProviderModelFamilyClassifier.isCurrent(
|
||||
.init(id: "gpt_5_6_terra", name: "GPT 5.6 Terra"),
|
||||
.init(id: "gpt_5_6_terra", name: "GPT 5.6 Terra", isLegacy: false),
|
||||
provider: codex
|
||||
)
|
||||
)
|
||||
#expect(
|
||||
ProviderModelFamilyClassifier.isCurrent(
|
||||
.init(id: "gpt-5-6-sol", name: "Sol"),
|
||||
.init(id: "gpt-5-6-sol", name: "Sol", isLegacy: false),
|
||||
provider: codex
|
||||
)
|
||||
)
|
||||
#expect(
|
||||
ProviderModelFamilyClassifier.isCurrent(
|
||||
.init(id: "claude-fable-5-202607", name: "Fable 5"),
|
||||
.init(id: "claude-fable-5-202607", name: "Fable 5", isLegacy: false),
|
||||
provider: claude
|
||||
)
|
||||
)
|
||||
#expect(
|
||||
ProviderModelFamilyClassifier.isCurrent(
|
||||
.init(id: "claude-opus-5", name: "OPUS 5"),
|
||||
.init(id: "claude-opus-5", name: "OPUS 5", isLegacy: false),
|
||||
provider: claude
|
||||
)
|
||||
)
|
||||
#expect(
|
||||
ProviderModelFamilyClassifier.isCurrent(
|
||||
.init(id: "claude-sonnet-5", name: "Sonnet v5"),
|
||||
.init(id: "claude-sonnet-5", name: "Sonnet v5", isLegacy: false),
|
||||
provider: claude
|
||||
)
|
||||
)
|
||||
#expect(
|
||||
!ProviderModelFamilyClassifier.isCurrent(
|
||||
.init(id: "claude-opus-4-1", name: "Opus 4.1"),
|
||||
.init(id: "claude-opus-4-1", name: "Opus 4.1", isLegacy: true),
|
||||
provider: claude
|
||||
)
|
||||
)
|
||||
#expect(
|
||||
!ProviderModelFamilyClassifier.isCurrent(
|
||||
.init(id: "gpt-5.5-codex-sol", name: "GPT 5.5 Sol"),
|
||||
.init(id: "gpt-5.5-codex-sol", name: "GPT 5.5 Sol", isLegacy: true),
|
||||
provider: codex
|
||||
)
|
||||
)
|
||||
#expect(
|
||||
ProviderModelFamilyClassifier.isCurrent(
|
||||
.init(id: "custom-opus-4", name: "Custom Opus 4"),
|
||||
provider: claude
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user