@@ -47,7 +47,7 @@ const snapshotByAgent = new Map<string, ObserverSnapshot>();
4747// We key each subscriber's contribution in `knownAgentsBySubscription` and
4848// recompute the union, so co-mounted callers no longer clobber each other.
4949const knownAgentPubkeys = new Set < string > ( ) ;
50- const knownAgentsBySubscription = new Map < string , Set < string > > ( ) ;
50+ const knownAgentsBySubscription = new Map < string | symbol , Set < string > > ( ) ;
5151
5252function recomputeKnownAgentPubkeys ( ) {
5353 knownAgentPubkeys . clear ( ) ;
@@ -58,8 +58,8 @@ function recomputeKnownAgentPubkeys() {
5858 }
5959}
6060
61- function registerKnownAgents (
62- subscriptionId : string ,
61+ export function registerKnownAgentPubkeys (
62+ subscriptionId : string | symbol ,
6363 pubkeys : readonly string [ ] ,
6464) {
6565 knownAgentsBySubscription . set (
@@ -69,12 +69,16 @@ function registerKnownAgents(
6969 recomputeKnownAgentPubkeys ( ) ;
7070}
7171
72- function unregisterKnownAgents ( subscriptionId : string ) {
72+ export function unregisterKnownAgentPubkeys ( subscriptionId : string | symbol ) {
7373 if ( knownAgentsBySubscription . delete ( subscriptionId ) ) {
7474 recomputeKnownAgentPubkeys ( ) ;
7575 }
7676}
7777
78+ export function isKnownAgentPubkey ( pubkey : string ) {
79+ return knownAgentPubkeys . has ( normalizePubkey ( pubkey ) ) ;
80+ }
81+
7882let connectionState : ConnectionState = "idle" ;
7983let errorMessage : string | null = null ;
8084let unsubscribeRelay : ( ( ) => Promise < void > ) | null = null ;
@@ -176,7 +180,7 @@ async function handleRelayObserverEvent(
176180
177181 // Verify agent is known/trusted before decrypting.
178182 // Silently drop events from agents we are not managing.
179- if ( ! knownAgentPubkeys . has ( normalizePubkey ( agentPubkey ) ) ) {
183+ if ( ! isKnownAgentPubkey ( agentPubkey ) ) {
180184 return ;
181185 }
182186
@@ -326,9 +330,9 @@ export function useManagedAgentObserverBridge(
326330 // own agent list. The store recomputes the union across all subscribers, so
327331 // a co-mounted caller no longer wipes out this caller's agents.
328332 React . useEffect ( ( ) => {
329- registerKnownAgents ( subscriptionId , agentPubkeys ) ;
333+ registerKnownAgentPubkeys ( subscriptionId , agentPubkeys ) ;
330334 return ( ) => {
331- unregisterKnownAgents ( subscriptionId ) ;
335+ unregisterKnownAgentPubkeys ( subscriptionId ) ;
332336 } ;
333337 } , [ subscriptionId , agentPubkeys ] ) ;
334338
0 commit comments