Skip to content

Commit 8f8e774

Browse files
fix(ios): disclose model targets and enforce availability (#135044)
* fix(ios): disclose model selection target * fix(ios): respect model availability in chat * test(ios): prove model picker target variants * chore(ios): refresh native localization inventory * fix(ios): refresh model availability after session mutations * fix(ios): refresh model availability during resync
1 parent 6a883dd commit 8f8e774

22 files changed

Lines changed: 1040 additions & 38 deletions

‎apps/.i18n/native-source.json‎

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎apps/ios/Sources/Chat/AppleReviewDemoChatTransport.swift‎

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct LocalChatFixture {
2929
let modelProvider: String
3030
let modelID: String
3131
let modelName: String
32+
let modelSelectionTarget: String
3233
let additionalModels: [OpenClawChatModelChoice]
3334
let responsePrefix: String
3435
let seedMessages: [String]
@@ -43,6 +44,7 @@ struct LocalChatFixture {
4344
modelProvider: "demo",
4445
modelID: "local-demo",
4546
modelName: "Apple Review Demo",
47+
modelSelectionTarget: "session",
4648
additionalModels: [],
4749
responsePrefix: "Demo mode is active.",
4850
seedMessages: [
@@ -74,6 +76,7 @@ struct LocalChatFixture {
7476
modelProvider: "openai",
7577
modelID: "gpt-5.6-sol",
7678
modelName: "GPT-5.6 Sol",
79+
modelSelectionTarget: "global",
7780
additionalModels: [
7881
OpenClawChatModelChoice(
7982
modelID: "claude-opus-4-1",
@@ -227,7 +230,27 @@ struct LocalFixtureChatTransport: OpenClawChatTransport {
227230
}
228231

229232
func listModels(agentID _: String?) async throws -> [OpenClawChatModelChoice] {
230-
[
233+
if ProcessInfo.processInfo.arguments.contains("--openclaw-unavailable-model-fixture") {
234+
return try OpenClawChatGatewayPayloadCodec.decodeModelChoices(Data(#"""
235+
{"models":[
236+
{"id":"gpt-5.6-sol","name":"GPT-5.6 Sol","provider":"openai",
237+
"available":true,"contextWindow":128000},
238+
{"id":"claude-opus-4-1","name":"Claude Opus 4.1","provider":"anthropic",
239+
"available":false,"unavailableReason":"missing-auth","contextWindow":200000}
240+
]}
241+
"""#.utf8))
242+
}
243+
if ProcessInfo.processInfo.arguments.contains("--openclaw-selected-model-auth-failure-fixture") {
244+
return try OpenClawChatGatewayPayloadCodec.decodeModelChoices(Data(#"""
245+
{"models":[
246+
{"id":"gpt-5.6-sol","name":"GPT-5.6 Sol","provider":"openai",
247+
"available":false,"unavailableReason":"auth-failed","contextWindow":128000},
248+
{"id":"claude-opus-4-1","name":"Claude Opus 4.1","provider":"anthropic",
249+
"available":true,"contextWindow":200000}
250+
]}
251+
"""#.utf8))
252+
}
253+
return [
231254
OpenClawChatModelChoice(
232255
modelID: self.fixture.modelID,
233256
name: self.fixture.modelName,
@@ -236,6 +259,16 @@ struct LocalFixtureChatTransport: OpenClawChatTransport {
236259
] + self.fixture.additionalModels
237260
}
238261

262+
func loadModelCatalog(
263+
sessionKey _: String,
264+
agentID: String?) async throws -> OpenClawChatModelCatalogSnapshot
265+
{
266+
let choices = try await self.listModels(agentID: agentID)
267+
return OpenClawChatModelCatalogSnapshot(
268+
choices: choices,
269+
availabilityIsSessionScoped: true)
270+
}
271+
239272
func isSwarmEnabled(sessionKey _: String) async throws -> Bool {
240273
ProcessInfo.processInfo.arguments.contains("--openclaw-swarm-chat-fixture")
241274
}
@@ -534,10 +567,24 @@ private actor LocalFixtureChatStore {
534567
thinkingLevels: Self.thinkingLevels,
535568
thinkingOptions: Self.thinkingOptions,
536569
thinkingDefault: "auto",
537-
mainSessionKey: self.fixture.sessionKey),
570+
mainSessionKey: self.fixture.sessionKey,
571+
modelSelectionTarget: self.fixtureModelSelectionTarget),
538572
sessions: [entry])
539573
}
540574

575+
private var fixtureModelSelectionTarget: String {
576+
let arguments = ProcessInfo.processInfo.arguments
577+
guard let index = arguments.firstIndex(of: "--openclaw-model-selection-target"),
578+
arguments.indices.contains(index + 1)
579+
else {
580+
return self.fixture.modelSelectionTarget
581+
}
582+
switch arguments[index + 1] {
583+
case "session", "agent", "global": return arguments[index + 1]
584+
default: return self.fixture.modelSelectionTarget
585+
}
586+
}
587+
541588
func reset() {
542589
self.messages = Self.seedMessages(fixture: self.fixture)
543590
self.modelID = self.fixture.modelID

‎apps/ios/Sources/Chat/IOSGatewayChatTransport.swift‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,33 @@ struct IOSGatewayChatTransport: OpenClawChatTransport {
336336
return try OpenClawChatGatewayPayloadCodec.decodeModelChoices(response)
337337
}
338338

339+
func loadModelCatalog(
340+
sessionKey: String,
341+
agentID: String?) async throws -> OpenClawChatModelCatalogSnapshot
342+
{
343+
guard let route = await self.currentSessionMutationRoute() else {
344+
throw CancellationError()
345+
}
346+
let sessionScoped = await self.gateway.supportsServerCapability(
347+
.sessionScopedChatMetadata,
348+
ifCurrentRoute: route) == true
349+
let request = if sessionScoped {
350+
OpenClawChatGatewayRequests.chatMetadata(
351+
sessionKey: sessionKey,
352+
fallbackAgentID: agentID ?? self.globalAgentId,
353+
includeSessionKey: true)
354+
} else {
355+
OpenClawChatGatewayRequests.modelsList(agentID: agentID)
356+
}
357+
let response = try await self.gateway.request(request, ifCurrentRoute: route)
358+
let choices = try sessionScoped
359+
? OpenClawChatGatewayPayloadCodec.decodeChatMetadataModelChoices(response)
360+
: OpenClawChatGatewayPayloadCodec.decodeModelChoices(response)
361+
return OpenClawChatModelCatalogSnapshot(
362+
choices: choices,
363+
availabilityIsSessionScoped: sessionScoped)
364+
}
365+
339366
func isSwarmEnabled(sessionKey: String) async throws -> Bool {
340367
try await self.isSwarmEnabled(sessionKey: sessionKey, ifCurrentRoute: nil)
341368
}

0 commit comments

Comments
 (0)