mirror of
https://github.com/block/buzz.git
synced 2026-11-26 19:21:50 +00:00
fix(sidebar): include declared-owned working agents
Co-authored-by: Taylor Ho <taylorkmho@gmail.com> Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
This commit is contained in:
parent
8ecc68e4e7
commit
00d5039669
@@ -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<ManagedAgent, "pubkey" | "status">;
|
||||
|
||||
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<BridgeAgent[]>(() => {
|
||||
const agentsByPubkey = new Map<string, BridgeAgent>();
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user