Skip to content

Commit b570318

Browse files
npub1g8493u0xfsjrvflg4n08ezd7vec99mnwzlv0qgwpr9d7gvjwhuzqx59rhwwpfleger96
andcommitted
feat(catalog): resolve publisher display name in catalog detail pane
The `PersonaCatalogDetail` component hardcoded the label passed to `PersonaAddedBy` as "Community member" for any non-own catalog entry. The publisher's pubkey is already available as `catalogSource.ownerPubkey` (set from the kind:30175 event's pubkey). Use `useUsersBatchQuery` to resolve the pubkey to a kind:0 display name. Label precedence: own entry → "You"; resolved profile → `displayName` then `name`; loading or unresolvable → "Community member" (unchanged fallback). The batch query is disabled when the entry is not a community entry, so there is no extra network call for own entries or built-in agents. E2e: update the existing assertion that was checking for the hardcoded fallback, add a new test that verifies "Community member" still renders when the publisher pubkey is not in the mock profile registry. Co-authored-by: Will Pfleger <[email protected]> Signed-off-by: Will Pfleger <[email protected]>
1 parent ab55fee commit b570318

2 files changed

Lines changed: 56 additions & 9 deletions

File tree

‎desktop/src/features/agents/ui/PersonaCatalogDialog.tsx‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from "react";
22

33
import { isCatalogPersonaSelected } from "@/features/agents/lib/catalog";
44
import { isCatalogPersona } from "@/features/agents/lib/personaCatalogRelay";
5+
import { useUsersBatchQuery } from "@/features/profile/hooks";
56
import { ProfileAvatar } from "@/features/profile/ui/ProfileAvatar";
67
import type { AgentPersona } from "@/shared/api/types";
78
import { useFeedbackToasts } from "@/shared/hooks/useToastEffect";
@@ -277,6 +278,25 @@ function PersonaCatalogChooser({
277278
}
278279

279280
function PersonaCatalogDetail({ persona }: { persona: AgentPersona }) {
281+
const isCommunityEntry =
282+
isCatalogPersona(persona) && !persona.catalogSource.isOwn;
283+
const ownerPubkey = isCommunityEntry
284+
? persona.catalogSource.ownerPubkey
285+
: undefined;
286+
const ownerBatchQuery = useUsersBatchQuery(ownerPubkey ? [ownerPubkey] : [], {
287+
enabled: !!ownerPubkey,
288+
});
289+
290+
let addedByLabel: string;
291+
if (!isCommunityEntry) {
292+
addedByLabel = "You";
293+
} else {
294+
const summary = ownerPubkey
295+
? ownerBatchQuery.data?.profiles[ownerPubkey.toLowerCase()]
296+
: undefined;
297+
addedByLabel = summary?.displayName ?? summary?.name ?? "Community member";
298+
}
299+
280300
return (
281301
<div className="w-full min-w-0 max-w-full space-y-6 overflow-x-hidden">
282302
<div className="flex items-center gap-3">
@@ -290,14 +310,7 @@ function PersonaCatalogDetail({ persona }: { persona: AgentPersona }) {
290310
{persona.displayName}
291311
</h3>
292312
{persona.isBuiltIn ? null : (
293-
<PersonaAddedBy
294-
className="mt-0.5"
295-
label={
296-
isCatalogPersona(persona) && !persona.catalogSource.isOwn
297-
? "Community member"
298-
: "You"
299-
}
300-
/>
313+
<PersonaAddedBy className="mt-0.5" label={addedByLabel} />
301314
)}
302315
</div>
303316
</div>

‎desktop/tests/e2e/agents.spec.ts‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,8 +1674,10 @@ test("a community member can discover and add another member's catalog agent", a
16741674
);
16751675
await expect(remoteEntry).toContainText("Alice’s Reviewer");
16761676
await remoteEntry.click();
1677+
// The detail pane resolves the publisher's display name; 'Community member'
1678+
// is only the fallback for an unresolvable pubkey.
16771679
await expect(page.getByTestId("persona-catalog-detail-pane")).toContainText(
1678-
"Added by Community member",
1680+
"Added by alice",
16791681
);
16801682

16811683
await page
@@ -1728,6 +1730,38 @@ test("a community member can discover and add another member's catalog agent", a
17281730
expect(await countCommandInvocations(page, "create_persona")).toBe(1);
17291731
});
17301732

1733+
test("catalog detail shows Community member when the publisher profile cannot be resolved", async ({
1734+
page,
1735+
}) => {
1736+
// A pubkey that is not in the mock profile registry — profile resolution
1737+
// will fail and the detail pane must fall back gracefully.
1738+
const unknownPubkey =
1739+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1740+
const personaId = "unresolvable-reviewer";
1741+
await installMockBridge(page, {
1742+
personaCatalogEvents: [
1743+
createCatalogEvent({
1744+
ownerPubkey: unknownPubkey,
1745+
sourcePersonaId: personaId,
1746+
displayName: "Mystery Agent",
1747+
systemPrompt: "Published by someone whose profile cannot be fetched.",
1748+
}),
1749+
],
1750+
});
1751+
await gotoApp(page);
1752+
await page.getByTestId("open-agents-view").click();
1753+
await openPersonaCatalog(page);
1754+
1755+
await page
1756+
.getByTestId(
1757+
`persona-catalog-list-item-catalog:${unknownPubkey}:${personaId}`,
1758+
)
1759+
.click();
1760+
await expect(page.getByTestId("persona-catalog-detail-pane")).toContainText(
1761+
"Added by Community member",
1762+
);
1763+
});
1764+
17311765
test("one share level selector drives both the link and send paths", async ({
17321766
page,
17331767
}) => {

0 commit comments

Comments
 (0)