From 00d5039669fa4f86f0c6650370018a38eb874d3f Mon Sep 17 00:00:00 2001 From: npub1223z34hd7vtwc6qj4s7flsxkj644nlre2nthu7lrrmkumhu3xddsrx9r6w <52a228d6edf316ec6812ac3c9fc0d696ab59fc7954d77e7be31eedcddf91335b@sprout-oss.stage.blox.sqprod.co> Date: Mon, 29 Jun 2026 10:33:12 -0700 Subject: [PATCH] fix(sidebar): include declared-owned working agents Co-authored-by: Taylor Ho Signed-off-by: Taylor Ho --- .../lib/useActiveWorkingChannelsById.ts | 54 +++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/desktop/src/features/sidebar/lib/useActiveWorkingChannelsById.ts b/desktop/src/features/sidebar/lib/useActiveWorkingChannelsById.ts index 69f4c8b6ea..d3d57e552f 100644 --- a/desktop/src/features/sidebar/lib/useActiveWorkingChannelsById.ts +++ b/desktop/src/features/sidebar/lib/useActiveWorkingChannelsById.ts @@ -5,21 +5,69 @@ import { useActiveAgentTurnsBridge, useActiveAgentTurnsByChannel, } from "@/features/agents/activeAgentTurnsStore"; -import { useManagedAgentsQuery } from "@/features/agents/hooks"; +import { + useManagedAgentsQuery, + useRelayAgentsQuery, +} from "@/features/agents/hooks"; import { useManagedAgentObserverBridge } from "@/features/agents/observerRelayStore"; +import { useUsersBatchQuery } from "@/features/profile/hooks"; +import { useIdentityQuery } from "@/shared/api/hooks"; +import type { ManagedAgent } from "@/shared/api/types"; + +type BridgeAgent = Pick; export function useActiveWorkingChannelsById(): ReadonlyMap< string, ActiveChannelTurnSummary > { + const identityQuery = useIdentityQuery(); + const currentPubkey = identityQuery.data?.pubkey; const managedAgentsQuery = useManagedAgentsQuery(); + const relayAgentsQuery = useRelayAgentsQuery({ enabled: true }); const managedAgents = React.useMemo( () => managedAgentsQuery.data ?? [], [managedAgentsQuery.data], ); + const relayAgents = React.useMemo( + () => relayAgentsQuery.data ?? [], + [relayAgentsQuery.data], + ); + const relayAgentPubkeys = React.useMemo( + () => relayAgents.map((agent) => agent.pubkey), + [relayAgents], + ); + const relayAgentProfilesQuery = useUsersBatchQuery(relayAgentPubkeys, { + enabled: Boolean(currentPubkey) && relayAgentPubkeys.length > 0, + }); + const bridgeAgents = React.useMemo(() => { + const agentsByPubkey = new Map(); + for (const agent of managedAgents) { + agentsByPubkey.set(agent.pubkey.toLowerCase(), { + pubkey: agent.pubkey, + status: agent.status, + }); + } - useManagedAgentObserverBridge(managedAgents); - useActiveAgentTurnsBridge(managedAgents); + if (currentPubkey) { + const currentPubkeyLower = currentPubkey.toLowerCase(); + const profiles = relayAgentProfilesQuery.data?.profiles ?? {}; + for (const agent of relayAgents) { + const key = agent.pubkey.toLowerCase(); + const ownerPubkey = profiles[key]?.ownerPubkey; + if (ownerPubkey?.toLowerCase() !== currentPubkeyLower) continue; + if (agentsByPubkey.has(key)) continue; + agentsByPubkey.set(key, { + pubkey: agent.pubkey, + status: "deployed", + }); + } + } + + return [...agentsByPubkey.values()]; + }, [currentPubkey, managedAgents, relayAgentProfilesQuery.data, relayAgents]); + + useManagedAgentObserverBridge(bridgeAgents); + useActiveAgentTurnsBridge(bridgeAgents); const activeWorkingChannels = useActiveAgentTurnsByChannel(); return React.useMemo(