@@ -17,6 +17,10 @@ struct ChatProTab: View {
1717 // Track the real agent so gateway metadata replaces the captured transport.
1818 @ State private var viewModelTransportAgentID = " "
1919 @ State private var viewModelRoutingContract = " "
20+ @ State private var viewModelPresentationAgentID = " main "
21+ @ State private var viewModelPresentationAgentName = " Main "
22+ @ State private var viewModelPresentationAgentBadge = " M "
23+ @ State private var viewModelHasVerifiedOfflineRoutingIdentity = false
2024 @ State private var speech : OpenClawChatSpeechController ?
2125 let headerLeadingAction : OpenClawSidebarHeaderAction ?
2226 let headerTitle : String ?
@@ -75,6 +79,14 @@ struct ChatProTab: View {
7579 . onChange ( of : self . appModel . chatSessionRoutingContract ) { _ , _ in
7680 self . syncChatViewModel ( )
7781 }
82+ . onChange ( of : self . appModel . voiceNoteRecorder . ownsPendingChatAttachment ) { _ , _ in
83+ self . viewModel ? . attachmentOwnerActivityChanged ( )
84+ self . syncChatViewModel ( )
85+ }
86+ . onChange ( of : self . viewModel ? . isAttachmentOwnerPinned ) { _ , pinned in
87+ guard pinned == false else { return }
88+ self . syncChatViewModel ( )
89+ }
7890 . onChange ( of : self . appModel . isAppleReviewDemoModeEnabled ) { _ , _ in
7991 self . syncChatViewModel ( )
8092 self . viewModel ? . refresh ( )
@@ -145,11 +157,11 @@ struct ChatProTab: View {
145157 showsAssistantAvatars : false ,
146158 composerChrome : . clean ,
147159 isComposerEnabled : self . gatewayConnected || self . canQueueOffline ,
148- isAttachmentInputEnabled : self . gatewayConnected ,
160+ isAttachmentInputEnabled : self . gatewayConnected || self . canQueueOffline ,
149161 messagePlaceholder : self . messagePlaceholder ,
150162 emptyAssistantIntro : String ( localized : " What would you like to work on? " ) ,
151163 emptyAssistantPrompts : Self . emptyAssistantPrompts ,
152- talkControl : self . talkControl ,
164+ talkControl : viewModel . isAttachmentOwnerPinned ? nil : self . talkControl ,
153165 voiceNoteControl : self . voiceNoteControl ,
154166 speech : self . speech )
155167 // iMessage-style grey bubbles for agent replies in the clean chrome.
@@ -188,6 +200,7 @@ struct ChatProTab: View {
188200 self . viewModelOwnerID = ownerID
189201 self . viewModelTransportAgentID = transportAgentID
190202 self . viewModelRoutingContract = routingContract
203+ self . captureCurrentPresentationIdentity ( )
191204 self . viewModel = self . makeChatViewModel ( sessionKey : sessionKey )
192205 return
193206 }
@@ -197,31 +210,46 @@ struct ChatProTab: View {
197210 currentTransportAgentID : self . viewModelTransportAgentID ,
198211 nextTransportAgentID : transportAgentID )
199212 {
213+ // Keep recording, staging, and delivery on their captured route.
214+ // The pin-change observer replays this rebuild with latest state.
215+ guard ! viewModel . isAttachmentOwnerPinned else { return }
200216 self . viewModelOwnerID = ownerID
201217 self . viewModelTransportAgentID = transportAgentID
202218 self . viewModelRoutingContract = routingContract
219+ self . captureCurrentPresentationIdentity ( )
203220 self . viewModel = self . makeChatViewModel ( sessionKey : sessionKey )
204221 return
205222 }
206223 if self . viewModelRoutingContract != routingContract {
207224 self . viewModelRoutingContract = routingContract
208225 viewModel . syncSessionRoutingContract ( self . appModel . chatSessionRoutingContract )
209226 }
210- guard viewModel . sessionKey != sessionKey else { return }
211227 viewModel . syncSession ( to : sessionKey )
228+ if ! viewModel . isAttachmentOwnerPinned {
229+ self . captureCurrentPresentationIdentity ( )
230+ }
231+ }
232+
233+ private func captureCurrentPresentationIdentity ( ) {
234+ self . viewModelPresentationAgentID = self . currentAgentID
235+ self . viewModelPresentationAgentName = self . currentAgentDisplayName
236+ self . viewModelPresentationAgentBadge = self . currentAgentBadge
237+ self . viewModelHasVerifiedOfflineRoutingIdentity = self . appModel . hasVerifiedChatOfflineRoutingIdentity
212238 }
213239
214240 private func makeChatViewModel ( sessionKey : String ) -> OpenClawChatViewModel {
215241 // One store instance backs both seams so the transcript cache and the
216242 // offline outbox share a single SQLite connection.
217243 let offlineStore = self . appModel . makeChatOfflineStore ( )
244+ let voiceNoteRecorder = self . appModel . voiceNoteRecorder
218245 return OpenClawChatViewModel (
219246 sessionKey : sessionKey ,
220247 // Bind durable rows and their transport lease to the exact same
221248 // gateway owner even if app state switches between these calls.
222249 transport : self . appModel . makeChatTransport ( outboxGatewayID : offlineStore ? . gatewayID ) ,
223250 activeAgentId : self . appModel . chatDeliveryAgentId ,
224251 sessionRoutingContract : self . appModel . chatSessionRoutingContract ,
252+ attachmentOwnerIsActive : { voiceNoteRecorder . ownsPendingChatAttachment } ,
225253 transcriptCache : offlineStore ,
226254 outbox : offlineStore ,
227255 onSessionChanged : { sessionKey in
@@ -249,12 +277,7 @@ struct ChatProTab: View {
249277 private var voiceNoteControl : OpenClawChatVoiceNoteControl {
250278 OpenClawChatVoiceNoteControl (
251279 recorder : self . appModel . voiceNoteRecorder ,
252- isTalkActive : self . appModel . talkMode . isEnabled || self . appModel . talkMode . isPushToTalkActive )
253- }
254-
255- private var activeAgentID : String {
256- self . normalized ( self . appModel . chatAgentId )
257- ?? " main "
280+ isTalkActive : self . appModel . isTalkCaptureActive )
258281 }
259282
260283 @ ViewBuilder
@@ -296,7 +319,7 @@ struct ChatProTab: View {
296319 Image ( systemName : " plus.bubble " )
297320 }
298321 }
299- . disabled ( self . viewModel == nil || ! self . gatewayConnected )
322+ . disabled ( self . viewModel == nil || ! self . gatewayConnected || self . isAttachmentOwnerPinned )
300323
301324 if self . activeAgent ? . workspacegit == true {
302325 Button {
@@ -309,7 +332,7 @@ struct ChatProTab: View {
309332 Image ( systemName : " arrow.triangle.branch " )
310333 }
311334 }
312- . disabled ( self . viewModel == nil || ! self . gatewayConnected )
335+ . disabled ( self . viewModel == nil || ! self . gatewayConnected || self . isAttachmentOwnerPinned )
313336 }
314337
315338 Divider ( )
@@ -358,7 +381,23 @@ struct ChatProTab: View {
358381 }
359382
360383 private var gatewayDisplayState : GatewayDisplayState {
361- GatewayStatusBuilder . build ( appModel : self . appModel )
384+ Self . presentationGatewayState (
385+ current : GatewayStatusBuilder . build ( appModel : self . appModel ) ,
386+ isAttachmentOwnerPinned : self . isAttachmentOwnerPinned ,
387+ capturedOwnerID : self . viewModelOwnerID ,
388+ currentOwnerID : self . appModel . chatViewModelOwnerID )
389+ }
390+
391+ nonisolated static func presentationGatewayState (
392+ current : GatewayDisplayState ,
393+ isAttachmentOwnerPinned : Bool ,
394+ capturedOwnerID : String ,
395+ currentOwnerID : String ) -> GatewayDisplayState
396+ {
397+ if isAttachmentOwnerPinned , capturedOwnerID != currentOwnerID {
398+ return . disconnected
399+ }
400+ return current
362401 }
363402
364403 private var gatewayAccessibilityLabel : String {
@@ -403,7 +442,9 @@ struct ChatProTab: View {
403442
404443 private var canQueueOffline : Bool {
405444 self . viewModel ? . supportsOfflineTextOutbox == true &&
406- self . appModel . hasVerifiedChatOfflineRoutingIdentity
445+ ( self . isAttachmentOwnerPinned
446+ ? self . viewModelHasVerifiedOfflineRoutingIdentity
447+ : self . appModel . hasVerifiedChatOfflineRoutingIdentity )
407448 }
408449
409450 private var headerDisplayTitle : String {
@@ -419,22 +460,50 @@ struct ChatProTab: View {
419460 OpenClawBrand . accent
420461 }
421462
463+ private var isAttachmentOwnerPinned : Bool {
464+ self . viewModel ? . isAttachmentOwnerPinned == true
465+ }
466+
467+ private var currentAgentID : String {
468+ self . normalized ( self . appModel . chatAgentId ) ?? " main "
469+ }
470+
471+ private var currentActiveAgent : AgentSummary ? {
472+ self . appModel . gatewayAgents . first { $0 . id == self . currentAgentID }
473+ }
474+
475+ private var activeAgentID : String {
476+ self . isAttachmentOwnerPinned ? self . viewModelPresentationAgentID : self . currentAgentID
477+ }
478+
422479 private var activeAgent : AgentSummary ? {
423480 self . appModel . gatewayAgents . first { $0 . id == self . activeAgentID }
424481 }
425482
483+ private var currentAgentDisplayName : String {
484+ self . normalized ( self . currentActiveAgent ? . name ) ?? self . appModel . chatAgentName
485+ }
486+
426487 private var agentDisplayName : String {
427- self . normalized ( self . activeAgent ? . name ) ?? self . appModel . chatAgentName
488+ self . isAttachmentOwnerPinned ? self . viewModelPresentationAgentName : self . currentAgentDisplayName
428489 }
429490
430- private var agentBadge : String {
431- if let identity = activeAgent ? . identity ,
491+ private var currentAgentBadge : String {
492+ if let identity = self . currentActiveAgent ? . identity ,
432493 let emoji = identity [ " emoji " ] ? . value as? String ,
433494 let normalizedEmoji = Self . normalizedBadgeEmoji ( emoji )
434495 {
435496 return normalizedEmoji
436497 }
437- let words = self . agentDisplayName
498+ return Self . initialsBadge ( for : self . currentAgentDisplayName )
499+ }
500+
501+ private var agentBadge : String {
502+ self . isAttachmentOwnerPinned ? self . viewModelPresentationAgentBadge : self . currentAgentBadge
503+ }
504+
505+ nonisolated static func initialsBadge ( for displayName : String ) -> String {
506+ let words = displayName
438507 . split ( whereSeparator : { $0 . isWhitespace || $0 == " - " || $0 == " _ " } )
439508 . prefix ( 2 )
440509 let initials = words . compactMap ( \. first ) . map ( String . init ) . joined ( )
0 commit comments