@@ -595,6 +595,33 @@ function installControlUiMockGateway(input: {
595595 return { found : true , value : matchingCase . response } ;
596596 }
597597
598+ /** Presence slice of the connect snapshot. The self-flagged entry adopts the
599+ * connecting client's instanceId so presence surfaces resolve "you". */
600+ function presenceSnapshot ( connectParams : unknown ) : { presence ?: unknown [ ] } {
601+ if ( scenario . presenceUsers . length === 0 ) {
602+ return { } ;
603+ }
604+ const client = isRecord ( connectParams ) ? connectParams . client : undefined ;
605+ const selfInstanceId =
606+ isRecord ( client ) && typeof client . instanceId === "string"
607+ ? client . instanceId
608+ : "e2e-self-instance" ;
609+ return {
610+ presence : scenario . presenceUsers . map ( ( user , index ) => ( {
611+ instanceId : user . self ? selfInstanceId : `e2e-presence-${ index } ` ,
612+ mode : "webchat" ,
613+ reason : "connect" ,
614+ user : {
615+ id : user . id ,
616+ name : user . name ?? null ,
617+ email : user . email ?? null ,
618+ avatarUrl : user . avatarUrl ?? null ,
619+ } ,
620+ watchedSessions : user . watchedSessions ?? [ ] ,
621+ } ) ) ,
622+ } ;
623+ }
624+
598625 function recordSessionPatch ( params : unknown ) : void {
599626 if ( ! isRecord ( params ) || typeof params . key !== "string" ) {
600627 return ;
@@ -799,24 +826,7 @@ function installControlUiMockGateway(input: {
799826 : configured . value ;
800827 }
801828 switch ( method ) {
802- case "connect" : {
803- const connectClient = isRecord ( params ) ? params . client : undefined ;
804- const clientInstanceId =
805- isRecord ( connectClient ) && typeof connectClient . instanceId === "string"
806- ? connectClient . instanceId
807- : "e2e-self-instance" ;
808- const presence = scenario . presenceUsers . map ( ( user , index ) => ( {
809- instanceId : user . self ? clientInstanceId : `e2e-presence-${ index } ` ,
810- mode : "webchat" ,
811- reason : "connect" ,
812- user : {
813- id : user . id ,
814- name : user . name ?? null ,
815- email : user . email ?? null ,
816- avatarUrl : user . avatarUrl ?? null ,
817- } ,
818- watchedSessions : user . watchedSessions ?? [ ] ,
819- } ) ) ;
829+ case "connect" :
820830 return {
821831 auth : {
822832 deviceToken : scenario . deviceToken ,
@@ -838,7 +848,7 @@ function installControlUiMockGateway(input: {
838848 protocol : protocolVersion ,
839849 server : { connId : "control-ui-e2e" , version : "e2e" } ,
840850 snapshot : {
841- ...( presence . length > 0 ? { presence } : { } ) ,
851+ ...presenceSnapshot ( params ) ,
842852 sessionDefaults : {
843853 defaultAgentId : scenario . defaultAgentId ,
844854 mainKey : "main" ,
@@ -848,7 +858,6 @@ function installControlUiMockGateway(input: {
848858 } ,
849859 type : "hello-ok" ,
850860 } ;
851- }
852861 case "agent.identity.get" :
853862 return {
854863 agentId : scenario . assistantAgentId ,
0 commit comments