@@ -36,6 +36,7 @@ import type {
3636 SSESessionConnectedPayload ,
3737 SSESessionMessagePayload ,
3838 SSETrustUpdatedPayload ,
39+ TrustChangeCallback ,
3940 WorkspaceFolder ,
4041} from './types' ;
4142
@@ -76,6 +77,9 @@ export class WebBridge {
7677 /** Callback invoked whenever the chat list or selection changes. */
7778 private onChatListChange : ChatListChangeCallback | null = null ;
7879
80+ /** Callback invoked whenever trust mode changes. */
81+ private onTrustChange : TrustChangeCallback | null = null ;
82+
7983 /**
8084 * IDs of chats whose full message history has been fetched from the REST API
8185 * and dispatched to the webview. Used to avoid redundant loads when switching
@@ -458,6 +462,32 @@ export class WebBridge {
458462 }
459463 }
460464
465+ // ---------------------------------------------------------------------------
466+ // Trust API (for the shell layer)
467+ // ---------------------------------------------------------------------------
468+
469+ /** Register a listener for trust state changes. */
470+ onTrustChanged ( cb : TrustChangeCallback ) : void {
471+ this . onTrustChange = cb ;
472+ // Immediately fire with current state
473+ cb ( this . sessionState ?. trust ?? false ) ;
474+ }
475+
476+ /** Get the current trust mode. */
477+ getTrust ( ) : boolean {
478+ return this . sessionState ?. trust ?? false ;
479+ }
480+
481+ /** Toggle trust mode — calls the REST API and lets the SSE event confirm the change. */
482+ async toggleTrust ( ) : Promise < void > {
483+ const newTrust = ! ( this . sessionState ?. trust ?? false ) ;
484+ try {
485+ await this . api . setTrust ( newTrust ) ;
486+ } catch ( err ) {
487+ console . error ( '[Bridge] Failed to toggle trust:' , err ) ;
488+ }
489+ }
490+
461491 // ---------------------------------------------------------------------------
462492 // SSE connection
463493 // ---------------------------------------------------------------------------
@@ -632,7 +662,11 @@ export class WebBridge {
632662
633663 case 'trust:updated' : {
634664 const trustData = data as SSETrustUpdatedPayload ;
665+ if ( this . sessionState ) {
666+ this . sessionState . trust = trustData . trust ;
667+ }
635668 this . dispatch ( 'server/setTrust' , trustData . trust ) ;
669+ this . onTrustChange ?.( trustData . trust ) ;
636670 break ;
637671 }
638672
0 commit comments