@@ -66,6 +66,17 @@ export type ControlUiMockGatewayScenario = {
6666 methodResponses ?: Record < string , unknown > ;
6767 /** Replayed in-flight run snapshot served by chat.history and chat.startup. */
6868 inFlightRun ?: { runId : string ; text ?: string ; plan ?: unknown } | null ;
69+ /** Online users included in the connect snapshot's presence list. The entry
70+ * flagged `self` adopts the connecting client's instanceId so presence
71+ * surfaces (footer facepile, who's-online roster) resolve "you". */
72+ presenceUsers ?: Array < {
73+ self ?: boolean ;
74+ id : string ;
75+ name ?: string ;
76+ email ?: string ;
77+ avatarUrl ?: string ;
78+ watchedSessions ?: string [ ] ;
79+ } > ;
6980 /** Subscription-scoped Gateway events replayed on a fixed browser-side cycle. */
7081 repeatingSessionEvents ?: {
7182 events : Array < { event : "agent" | "session.tool" ; payload : unknown } > ;
@@ -268,6 +279,7 @@ function normalizeScenario(
268279 historyMessages : scenario . historyMessages ?? [ ] ,
269280 methodResponses : scenario . methodResponses ?? { } ,
270281 inFlightRun : scenario . inFlightRun ?? null ,
282+ presenceUsers : scenario . presenceUsers ?? [ ] ,
271283 models : scenario . models ?? [ { id : "gpt-5.5" , name : "gpt-5.5" , provider : "openai" } ] ,
272284 repeatingSessionEvents : scenario . repeatingSessionEvents ?? { events : [ ] } ,
273285 sessionInfo : scenario . sessionInfo ?? null ,
@@ -583,6 +595,33 @@ function installControlUiMockGateway(input: {
583595 return { found : true , value : matchingCase . response } ;
584596 }
585597
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+
586625 function recordSessionPatch ( params : unknown ) : void {
587626 if ( ! isRecord ( params ) || typeof params . key !== "string" ) {
588627 return ;
@@ -809,6 +848,7 @@ function installControlUiMockGateway(input: {
809848 protocol : protocolVersion ,
810849 server : { connId : "control-ui-e2e" , version : "e2e" } ,
811850 snapshot : {
851+ ...presenceSnapshot ( params ) ,
812852 sessionDefaults : {
813853 defaultAgentId : scenario . defaultAgentId ,
814854 mainKey : "main" ,
0 commit comments