mirror of
https://github.com/block/buzz.git
synced 2026-11-27 11:41:21 +00:00
Rebased from tho/observer-owner-global (#1493) onto post-#1380 main. Make agent observer ingestion (kind 24200 frame decryption + derived active-turn liveness) a single app-level concern instead of per-surface bridge mounts: - useAgentObserverIngestion mounted once in AppShell registers all locally managed agents plus relay agents the identity declared-owns (NIP-OA ownerPubkey via one batched profile query, treated deployed) - Pure combineObserverIngestionAgents() with unit coverage - Remove per-surface bridge mounts: ChannelScreen, UserProfilePanel, useManagedAgentActions, useActiveWorkingChannelsById, usePreventSleep Conflict note vs #1380: UserProfilePanel keeps #1380's activityAgent memo (still feeds the profile activity preview); only its bridge mounts (activityBridgeAgents) are removed since app-level ingestion covers both managed and declared-owned relay agents. Co-authored-by: Taylor Ho <taylorkmho@gmail.com> Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import * as React from "react";
|
|
|
|
import {
|
|
type ActiveChannelTurnSummary,
|
|
useActiveAgentTurnsByChannel,
|
|
} from "@/features/agents/activeAgentTurnsStore";
|
|
import { useManagedAgentsQuery } from "@/features/agents/hooks";
|
|
import { normalizePubkey } from "@/shared/lib/pubkey";
|
|
|
|
export function resolveActiveWorkingChannelNames(
|
|
summary: ActiveChannelTurnSummary,
|
|
managedAgents: readonly { pubkey: string; name: string }[],
|
|
): ActiveChannelTurnSummary {
|
|
const namesByPubkey = new Map(
|
|
managedAgents.map((agent) => [normalizePubkey(agent.pubkey), agent.name]),
|
|
);
|
|
|
|
return {
|
|
...summary,
|
|
agentNames: summary.agentPubkeys.flatMap((pubkey) => {
|
|
const name = namesByPubkey.get(normalizePubkey(pubkey));
|
|
return name ? [name] : [];
|
|
}),
|
|
};
|
|
}
|
|
|
|
export function useActiveWorkingChannelsById(): ReadonlyMap<
|
|
string,
|
|
ActiveChannelTurnSummary
|
|
> {
|
|
const managedAgentsQuery = useManagedAgentsQuery();
|
|
const managedAgents = React.useMemo(
|
|
() => managedAgentsQuery.data ?? [],
|
|
[managedAgentsQuery.data],
|
|
);
|
|
|
|
// Observer ingestion is owner-global (useAgentObserverIngestion in
|
|
// AppShell); this hook only reads derived state.
|
|
const activeWorkingChannels = useActiveAgentTurnsByChannel();
|
|
return React.useMemo(
|
|
() =>
|
|
new Map(
|
|
activeWorkingChannels.map((summary) => {
|
|
const resolvedSummary = resolveActiveWorkingChannelNames(
|
|
summary,
|
|
managedAgents,
|
|
);
|
|
return [resolvedSummary.channelId, resolvedSummary];
|
|
}),
|
|
),
|
|
[activeWorkingChannels, managedAgents],
|
|
);
|
|
}
|