@@ -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
0 commit comments