Files
buzz/desktop/src/features/sidebar/lib/useActiveWorkingChannelsById.ts
npub1223z34hd7vtwc6qj4s7flsxkj644nlre2nthu7lrrmkumhu3xddsrx9r6w f255af4c03 feat(desktop): owner-global observer ingestion at app level
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>
2026-07-03 12:36:01 -07:00

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],
);
}