@@ -1616,6 +1616,8 @@ function resetMockMesh() {
16161616}
16171617let mockPersonas : RawPersona [ ] = [ ] ;
16181618let mockTeams : RawTeam [ ] = [ ] ;
1619+ // Listeners registered via the mock __TAURI_INTERNALS__.listen — keyed by event name.
1620+ const tauriEventListeners = new Map < string , Set < ( ) => void > > ( ) ;
16191621const defaultMockRelayAgents : RawRelayAgent [ ] = [
16201622 {
16211623 pubkey : ALICE_PUBKEY ,
@@ -6644,6 +6646,61 @@ export function maybeInstallE2eTauriMocks() {
66446646 return handleDeletePersona (
66456647 payload as Parameters < typeof handleDeletePersona > [ 0 ] ,
66466648 ) ;
6649+ case "reconcile_inbound_persona_event" : {
6650+ const nostrEvent = JSON . parse (
6651+ ( payload as { eventJson : string } ) . eventJson ,
6652+ ) as {
6653+ kind : number ;
6654+ tags : string [ ] [ ] ;
6655+ content : string ;
6656+ created_at : number ;
6657+ } ;
6658+ if ( nostrEvent . kind === 30175 ) {
6659+ // Persona upsert — parse content and upsert into mockPersonas by d-tag
6660+ const dTag = nostrEvent . tags . find ( ( t ) => t [ 0 ] === "d" ) ?. [ 1 ] ;
6661+ if ( dTag ) {
6662+ const content = JSON . parse ( nostrEvent . content ) as {
6663+ display_name ?: string ;
6664+ system_prompt ?: string ;
6665+ } ;
6666+ const now = new Date ( ) . toISOString ( ) ;
6667+ const existing = mockPersonas . find ( ( p ) => p . id === dTag ) ;
6668+ if ( existing ) {
6669+ existing . display_name =
6670+ content . display_name ?? existing . display_name ;
6671+ existing . system_prompt =
6672+ content . system_prompt ?? existing . system_prompt ;
6673+ existing . updated_at = now ;
6674+ } else {
6675+ mockPersonas . push ( {
6676+ id : dTag ,
6677+ display_name : content . display_name ?? dTag ,
6678+ avatar_url : null ,
6679+ system_prompt : content . system_prompt ?? "" ,
6680+ is_builtin : false ,
6681+ is_active : true ,
6682+ env_vars : { } ,
6683+ created_at : now ,
6684+ updated_at : now ,
6685+ } ) ;
6686+ }
6687+ }
6688+ } else if ( nostrEvent . kind === 5 ) {
6689+ // Tombstone — extract d-tag from a-tag "30175:<pubkey>:<d_tag>" and remove
6690+ const aTagValue = nostrEvent . tags . find ( ( t ) => t [ 0 ] === "a" ) ?. [ 1 ] ;
6691+ if ( aTagValue ) {
6692+ const dTag = aTagValue . split ( ":" ) [ 2 ] ;
6693+ if ( dTag ) {
6694+ mockPersonas = mockPersonas . filter ( ( p ) => p . id !== dTag ) ;
6695+ }
6696+ }
6697+ }
6698+ // Mirror the real Rust backend: emit "agents-data-changed" after reconcile.
6699+ for ( const cb of tauriEventListeners . get ( "agents-data-changed" ) ?? [ ] ) {
6700+ cb ( ) ;
6701+ }
6702+ return undefined ;
6703+ }
66476704 case "set_persona_active" :
66486705 return handleSetPersonaActive (
66496706 payload as Parameters < typeof handleSetPersonaActive > [ 0 ] ,
@@ -7028,5 +7085,26 @@ export function maybeInstallE2eTauriMocks() {
70287085 handleMockCommand ( command , payload ?? null ) ;
70297086 mockIPC ( handleMockCommand ) ;
70307087
7088+ // Wire up __TAURI_INTERNALS__.listen so tests can subscribe to backend-emitted
7089+ // events (e.g. "agents-data-changed"). mockIPC already ensures __TAURI_INTERNALS__
7090+ // exists; we just add the listen property without clobbering invoke.
7091+ (
7092+ window as unknown as {
7093+ __TAURI_INTERNALS__ : {
7094+ listen ?: ( event : string , cb : ( ) => void ) => Promise < ( ) => void > ;
7095+ } ;
7096+ }
7097+ ) . __TAURI_INTERNALS__ . listen = async ( event : string , cb : ( ) => void ) => {
7098+ let listeners = tauriEventListeners . get ( event ) ;
7099+ if ( ! listeners ) {
7100+ listeners = new Set ( ) ;
7101+ tauriEventListeners . set ( event , listeners ) ;
7102+ }
7103+ listeners . add ( cb ) ;
7104+ return ( ) => {
7105+ tauriEventListeners . get ( event ) ?. delete ( cb ) ;
7106+ } ;
7107+ } ;
7108+
70317109 installed = true ;
70327110}
0 commit comments