Skip to content

Commit 463db6d

Browse files
baxennpub1qvn3cujt28pg06ehlstrxyz6ayzp06t4uc7r566vxwwgrv24hglq9zju0n
andauthored
feat(desktop): show agent owners in messages (#2080)
Signed-off-by: npub1qvn3cujt28pg06ehlstrxyz6ayzp06t4uc7r566vxwwgrv24hglq9zju0n <03271c724b51c287eb37fc1633105ae90417e975e63c3a6b4c339c81b155ba3e@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1qvn3cujt28pg06ehlstrxyz6ayzp06t4uc7r566vxwwgrv24hglq9zju0n <03271c724b51c287eb37fc1633105ae90417e975e63c3a6b4c339c81b155ba3e@sprout-oss.stage.blox.sqprod.co>
1 parent b18a794 commit 463db6d

19 files changed

Lines changed: 264 additions & 4 deletions

‎desktop/src/features/channels/ui/ChannelPane.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export const ChannelPane = React.memo(function ChannelPane({
132132
unfollowThreadById,
133133
personaLookup,
134134
profiles,
135+
ownerProfiles,
135136
openThreadHeadId,
136137
shouldShowThreadSkeleton,
137138
openAgentSessionChannelId,
@@ -605,6 +606,7 @@ export const ChannelPane = React.memo(function ChannelPane({
605606
isMessageUnreadById={isMessageUnreadById}
606607
personaLookup={personaLookup}
607608
profiles={profiles}
609+
ownerProfiles={ownerProfiles}
608610
unfollowThreadById={unfollowThreadById}
609611
emptyDescription={
610612
activeChannel?.channelType === "forum"

‎desktop/src/features/channels/ui/ChannelPane.types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export type ChannelPaneProps = {
134134
) => void;
135135
personaLookup?: Map<string, string>;
136136
profiles?: UserProfileLookup;
137+
ownerProfiles?: UserProfileLookup;
137138
openThreadHeadId: string | null;
138139
shouldShowThreadSkeleton: boolean;
139140
openAgentSessionChannelId: string | null;

‎desktop/src/features/channels/ui/ChannelScreen.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useAppNavigation } from "@/app/navigation/useAppNavigation";
55
import { useActiveChannelHeader } from "@/features/channels/useActiveChannelHeader";
66
import { useChannelPaneHandlers } from "@/features/channels/useChannelPaneHandlers";
77
import { useMessageEventProfilePubkeys } from "@/features/channels/useMessageEventProfilePubkeys";
8+
import { useMessageOwnerProfiles } from "@/features/channels/useMessageOwnerProfiles";
89
import { useThreadTargetSync } from "@/features/channels/useThreadTargetSync";
910
import {
1011
useChannelMembersQuery,
@@ -350,6 +351,7 @@ export function ChannelScreen({
350351
profiles: messageProfilesQuery.data?.profiles,
351352
relayAgents,
352353
});
354+
const messageOwnerProfiles = useMessageOwnerProfiles(messageProfiles);
353355
// Agent set for ChannelPane's own consumers (DM huddle member resolution,
354356
// the agents list): the community-scoped baseline shared by every surface,
355357
// widened with channel-member roles and this screen's profile lookup.
@@ -393,13 +395,15 @@ export function ChannelScreen({
393395
personaLookup,
394396
respondToLookup,
395397
relaySelfPubkey,
398+
messageOwnerProfiles,
396399
),
397400
[
398401
activeChannel,
399402
channelMembers,
400403
currentProfile?.avatarUrl,
401404
currentPubkey,
402405
messageProfiles,
406+
messageOwnerProfiles,
403407
personaLookup,
404408
relaySelfPubkey,
405409
respondToLookup,
@@ -437,6 +441,7 @@ export function ChannelScreen({
437441
currentPubkey,
438442
currentAvatarUrl: currentProfile?.avatarUrl ?? null,
439443
profiles: messageProfiles,
444+
ownerProfiles: messageOwnerProfiles,
440445
members: channelMembers,
441446
personaLookup,
442447
respondToLookup,
@@ -934,6 +939,7 @@ export function ChannelScreen({
934939
profilePanelView={profilePanelView}
935940
personaLookup={personaLookup}
936941
profiles={messageProfiles}
942+
ownerProfiles={messageOwnerProfiles}
937943
firstUnreadMessageId={firstUnreadMessageId}
938944
unreadCount={unreadCount}
939945
targetMessageId={mainTimelineTargetMessageId}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as React from "react";
2+
3+
import { useUsersBatchQuery } from "@/features/profile/hooks";
4+
import type { UserProfileLookup } from "@/features/profile/lib/identity";
5+
6+
/** Fetches verified agent-owner profiles in one batch for message surfaces. */
7+
export function useMessageOwnerProfiles(profiles: UserProfileLookup) {
8+
const ownerPubkeys = React.useMemo(
9+
() => [
10+
...new Set(
11+
Object.values(profiles)
12+
.map((profile) => profile.ownerPubkey)
13+
.filter((pubkey): pubkey is string => Boolean(pubkey)),
14+
),
15+
],
16+
[profiles],
17+
);
18+
const ownerProfilesQuery = useUsersBatchQuery(ownerPubkeys, {
19+
enabled: ownerPubkeys.length > 0,
20+
});
21+
return ownerProfilesQuery.data?.profiles;
22+
}

‎desktop/src/features/home/lib/inbox.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export type InboxTypeLabel = {
6060
export type InboxReply = {
6161
authorLabel: string;
6262
authorPubkey: string;
63+
isAgent?: boolean;
64+
ownerLabel?: string | null;
65+
ownerPubkey?: string | null;
6366
avatarUrl: string | null;
6467
content: string;
6568
createdAt: number;

‎desktop/src/features/home/lib/inboxViewHelpers.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ export function toInboxContextMessage(
139139
id: message.id,
140140
authorLabel: message.author,
141141
authorPubkey,
142+
isAgent: message.isAgent,
143+
ownerLabel: message.ownerLabel,
144+
ownerPubkey: message.ownerPubkey,
142145
avatarUrl: message.avatarUrl ?? null,
143146
content: message.body,
144147
createdAt: message.createdAt,
@@ -169,6 +172,9 @@ export function toTimelineMessage(
169172
return {
170173
id: message.id,
171174
author: message.authorLabel,
175+
isAgent: message.isAgent,
176+
ownerLabel: message.ownerLabel,
177+
ownerPubkey: message.ownerPubkey,
172178
avatarUrl: message.avatarUrl,
173179
body: message.content,
174180
createdAt: message.createdAt,

‎desktop/src/features/home/ui/HomeView.tsx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,20 @@ export function HomeView({
333333
enabled: feedProfilePubkeys.length > 0,
334334
});
335335
const feedProfiles = feedProfilesQuery.data?.profiles;
336+
const feedOwnerPubkeys = React.useMemo(
337+
() => [
338+
...new Set(
339+
Object.values(feedProfiles ?? {})
340+
.map((profile) => profile.ownerPubkey)
341+
.filter((pubkey): pubkey is string => Boolean(pubkey)),
342+
),
343+
],
344+
[feedProfiles],
345+
);
346+
const feedOwnerProfilesQuery = useUsersBatchQuery(feedOwnerPubkeys, {
347+
enabled: feedOwnerPubkeys.length > 0,
348+
});
349+
const feedOwnerProfiles = feedOwnerProfilesQuery.data?.profiles;
336350
// Agent set for the inbox list/detail bot badges: the community-scoped
337351
// baseline widened with this surface's profile lookup.
338352
const communityAgentPubkeys = useKnownAgentPubkeys();
@@ -477,6 +491,7 @@ export function HomeView({
477491
undefined,
478492
undefined,
479493
relaySelfPubkey,
494+
feedOwnerProfiles,
480495
);
481496

482497
return timelineMessages.map((message) =>
@@ -491,6 +506,7 @@ export function HomeView({
491506
channelMessages,
492507
currentPubkey,
493508
feedProfiles,
509+
feedOwnerProfiles,
494510
relaySelfPubkey,
495511
selectedChannel,
496512
selectedEventId,

‎desktop/src/features/home/ui/InboxMessageRow.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { formatTimeWithoutDayPeriod } from "@/features/messages/lib/dateFormatte
77
import type { TimelineMessage } from "@/features/messages/types";
88
import { getConfigNudgeAuthorPubkey } from "@/features/messages/ui/configNudgeAuthPubkey";
99
import { MessageActionBar } from "@/features/messages/ui/MessageActionBar";
10+
import { MessageAgentOwner } from "@/features/messages/ui/MessageAgentOwner";
1011
import { MessageReactions } from "@/features/messages/ui/MessageReactions";
1112
import { useReactionHandler } from "@/features/messages/ui/useReactionHandler";
1213
import { useMessageEmoji } from "@/features/messages/lib/useMessageEmoji";
@@ -172,6 +173,12 @@ export function InboxMessageRow({
172173
{message.authorLabel}
173174
</span>
174175
</UserProfilePopover>
176+
{message.isAgent ? (
177+
<MessageAgentOwner
178+
ownerLabel={message.ownerLabel}
179+
ownerPubkey={message.ownerPubkey}
180+
/>
181+
) : null}
175182
<p className="shrink-0 text-xs font-normal tabular-nums text-muted-foreground/55">
176183
{message.fullTimestampLabel}
177184
</p>

‎desktop/src/features/messages/lib/formatTimelineMessages.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
isBroadcastReply,
1515
} from "@/features/messages/lib/threading";
1616
import {
17+
formatOwnerLabel,
1718
resolveUserLabel,
1819
type UserProfileLookup,
1920
} from "@/features/profile/lib/identity";
@@ -193,6 +194,8 @@ export function formatTimelineMessages(
193194
respondToLookup?: Map<string, RespondToMode>,
194195
/** Active relay identity from NIP-11 `self`; absent or malformed fails closed to the signer. */
195196
relaySelfPubkey?: string | null,
197+
/** Profiles for verified agent owners, fetched in one batch by the surface. */
198+
ownerProfiles?: UserProfileLookup,
196199
): TimelineMessage[] {
197200
const currentPubkeyLower = currentPubkey?.toLowerCase();
198201
const roleByPubkey = new Map<string, string>();
@@ -423,13 +426,21 @@ export function formatTimelineMessages(
423426
const thread = getThreadReference(event.tags);
424427
const edit = editsByTargetId.get(event.id);
425428
const role = roleByPubkey.get(authorPubkey.toLowerCase());
429+
const authorProfile = profiles?.[authorPubkey.toLowerCase()];
430+
const isAgent = role === "bot" || authorProfile?.isAgent === true;
431+
const ownerPubkey = isAgent ? (authorProfile?.ownerPubkey ?? null) : null;
426432
return {
427433
id: event.id,
428434
renderKey: event.localKey ?? event.id,
429435
createdAt: event.created_at,
430436
pubkey: authorPubkey,
431437
signerPubkey: normalizePubkey(event.pubkey),
432438
author,
439+
isAgent,
440+
ownerPubkey,
441+
ownerLabel: isAgent
442+
? formatOwnerLabel(ownerPubkey, currentPubkey, ownerProfiles)
443+
: null,
433444
avatarUrl: getAuthorAvatarUrl({
434445
authorPubkey,
435446
currentPubkey,

‎desktop/src/features/messages/types.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ export type TimelineMessage = {
2525
*/
2626
signerPubkey?: string;
2727
author: string;
28+
/** True when the displayed author is known to be an agent. */
29+
isAgent?: boolean;
30+
/** Verified owner pubkey for an agent author, when available. */
31+
ownerPubkey?: string | null;
32+
/** Viewer-relative owner label (for example, "you" or "baxen"). */
33+
ownerLabel?: string | null;
2834
avatarUrl?: string | null;
2935
role?: string;
3036
/** For bot messages, the display name of the persona this bot was created from. */

0 commit comments

Comments
 (0)