Skip to content

Commit b32f2c0

Browse files
wpfleger96npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
andauthored
fix(desktop): omit invalid snapshot imeta thumbnails (#1800)
Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
1 parent 095f3c7 commit b32f2c0

5 files changed

Lines changed: 58 additions & 65 deletions

File tree

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,6 @@ export function AgentSnapshotSendDialog({
171171
memorySourcePubkey: linkedAgentPubkey,
172172
}),
173173
destination.id,
174-
// Pass the agent's avatar URL as the NIP-92 thumb hint so the recipient
175-
// card can show the avatar instead of the generic Bot icon.
176-
persona.avatarUrl ?? undefined,
177174
);
178175
// Phase transitions (done/error) are driven by beginSend via setState
179176
// inside the controller; the mirror effect above keeps `step` in sync.

‎desktop/src/features/agents/ui/agentSnapshotSend.test.mjs‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
recordTimeoutFromRejection,
1616
clearTimeoutState,
1717
} from "../../moderation/lib/timeoutStore.ts";
18+
import { buildOutgoingMessage } from "../../messages/lib/imetaMediaMarkdown.ts";
1819

1920
// ── isSendableDestination ─────────────────────────────────────────────────────
2021

@@ -403,6 +404,54 @@ test("runSendPipeline_checkpoint2_blocks_upload_after_encode", async () => {
403404
);
404405
});
405406

407+
test("runSendPipeline_avatar_bearing_snapshot_omits_thumb_and_keeps_filename", async () => {
408+
let sentMediaTags = null;
409+
410+
const result = await runSendPipeline({
411+
channelId: "ch-1",
412+
checkEligibilityFn: () => null,
413+
encodeFn: async () => ({
414+
fileBytes: [1],
415+
fileName: "avatar-bearing.agent.json",
416+
}),
417+
uploadFn: async () => ({
418+
url: "https://example.com/avatar-bearing.agent.json",
419+
sha256: "a".repeat(64),
420+
size: 1,
421+
type: "application/json",
422+
uploaded: 0,
423+
// This represents an upload descriptor that happens to include a thumb.
424+
// A snapshot send must not serialize it as NIP-92 imeta metadata.
425+
thumb: "https://example.com/avatar.png",
426+
}),
427+
sendFn: async ({ mediaTags }) => {
428+
sentMediaTags = mediaTags;
429+
},
430+
setStateFn: () => {},
431+
buildMessageFn: (descriptor) => buildOutgoingMessage("", [descriptor]),
432+
});
433+
434+
assert.equal(result, true);
435+
assert.deepEqual(sentMediaTags, [
436+
[
437+
"imeta",
438+
"url https://example.com/avatar-bearing.agent.json",
439+
"m application/json",
440+
`x ${"a".repeat(64)}`,
441+
"size 1",
442+
"filename avatar-bearing.agent.json",
443+
],
444+
]);
445+
assert.ok(
446+
sentMediaTags[0].includes("filename avatar-bearing.agent.json"),
447+
"snapshot imeta must retain its filename",
448+
);
449+
assert.ok(
450+
!sentMediaTags[0].some((entry) => entry.startsWith("thumb ")),
451+
"snapshot imeta must not include a thumb field",
452+
);
453+
});
454+
406455
test("runSendPipeline_happy_path_sets_all_phases", async () => {
407456
// All checkpoints pass and encode/upload/send succeed — full phase sequence.
408457
const states = [];

‎desktop/src/features/agents/ui/useSnapshotSendController.ts‎

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,6 @@ export async function runSendPipeline(deps: {
212212
};
213213
checkEligibilityFn: () => string | null;
214214
channelId: string;
215-
/** Optional avatar URL emitted as the NIP-92 `thumb` field on the snapshot
216-
* attachment. Decorative — lets the recipient card show the agent's avatar
217-
* without trusting sender-supplied identity. */
218-
thumbUrl?: string;
219215
}): Promise<boolean> {
220216
const {
221217
encodeFn,
@@ -225,7 +221,6 @@ export async function runSendPipeline(deps: {
225221
buildMessageFn,
226222
checkEligibilityFn,
227223
channelId,
228-
thumbUrl,
229224
} = deps;
230225

231226
// ── Eligibility checkpoint 1: before encode ───────────────────────────────
@@ -284,13 +279,13 @@ export async function runSendPipeline(deps: {
284279
}
285280

286281
// Preserve the original filename so `buildImetaTags` emits a `filename`
287-
// field and the recipient's FileCard renders the correct label.
288-
// Also carry the agent's avatar URL as the NIP-92 `thumb` field when
289-
// the caller supplied one — decorative hint for the recipient card.
282+
// field and the recipient's FileCard renders the correct label. Snapshot
283+
// sends never emit `thumb`: NIP-92 requires it to be this upload's local
284+
// thumbnail sidecar, which an agent avatar is not.
285+
const { thumb: _thumb, ...descriptorWithoutThumb } = descriptor;
290286
const descriptorWithFilename: BlobDescriptor = {
291-
...descriptor,
287+
...descriptorWithoutThumb,
292288
filename: fileName,
293-
...(thumbUrl ? { thumb: thumbUrl } : {}),
294289
};
295290

296291
// ── Build message content + NIP-92 imeta tags ─────────────────────────────
@@ -361,14 +356,10 @@ export type UseSnapshotSendControllerResult = {
361356
* false and sets error state if blocked, ineligible, or if any step fails.
362357
* Never throws.
363358
*
364-
* @param thumbUrl Optional avatar URL emitted as the NIP-92 `thumb` imeta
365-
* field on the snapshot attachment — decorative, lets the recipient card
366-
* show the agent's avatar without any identity assertion.
367359
*/
368360
beginSend: (
369361
encodeFn: () => Promise<{ fileBytes: number[]; fileName: string }>,
370362
channelId: string,
371-
thumbUrl?: string,
372363
) => Promise<boolean>;
373364
/** Set state to error with a message (for pre-send gate failures). */
374365
setErrorState: (message: string) => void;
@@ -461,12 +452,10 @@ export function useSnapshotSendController(): UseSnapshotSendControllerResult {
461452
async function beginSend(
462453
encodeFn: () => Promise<{ fileBytes: number[]; fileName: string }>,
463454
channelId: string,
464-
thumbUrl?: string,
465455
): Promise<boolean> {
466456
return runGuardedSend(guardRef.current, {
467457
encodeFn,
468458
channelId,
469-
thumbUrl,
470459
// Eligibility is checked by reading directly from the React Query cache
471460
// and the timeout external store — not from rendered React state.
472461
checkEligibilityFn: () => checkSendEligibility(queryClient, channelId),

‎desktop/src/shared/ui/markdownFileCard.test.mjs‎

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -225,44 +225,7 @@ test("resolveSnapshotCard: uppercase .AGENT.JSON classifies as snapshot card", (
225225
assert.equal(card.sha256, SHA256);
226226
});
227227

228-
// ── thumb plumbing ────────────────────────────────────────────────────────────
229-
230-
test("resolveSnapshotCard: thumb field from imeta is forwarded for .agent.json", () => {
231-
const thumbUrl = "https://relay.example/avatar.png";
232-
const card = resolveSnapshotCard(
233-
{
234-
m: "application/json",
235-
size: 500,
236-
filename: "bot.agent.json",
237-
x: SHA256,
238-
thumb: thumbUrl,
239-
},
240-
JSON_URL,
241-
"",
242-
);
243-
assert.ok(card !== null);
244-
assert.equal(card.thumb, thumbUrl);
245-
});
246-
247-
test("resolveSnapshotCard: relay-hosted JSON thumb is rewritten through media proxy", () => {
248-
const thumbUrl = `https://relay.example/media/${"b".repeat(64)}.png`;
249-
const card = resolveSnapshotCard(
250-
{
251-
m: "application/json",
252-
size: 500,
253-
filename: "bot.agent.json",
254-
x: SHA256,
255-
thumb: thumbUrl,
256-
},
257-
JSON_URL,
258-
"",
259-
);
260-
assert.ok(card !== null);
261-
assert.equal(
262-
card.thumb,
263-
`buzz-media://localhost/media/${"b".repeat(64)}.png`,
264-
);
265-
});
228+
// ── snapshot card thumbnails ─────────────────────────────────────────────────
266229

267230
test("resolveSnapshotCard: .agent.png uses its own URL as thumb", () => {
268231
const card = resolveSnapshotCard(

‎desktop/src/shared/ui/markdownFileCard.ts‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,9 @@ export function resolveSnapshotCard(
8686
size: entry.size,
8787
sha256,
8888
snapshotKind: "agent",
89-
// For PNG snapshots, use the attachment URL as the thumb source (it IS
90-
// the avatar card image). For JSON, use the explicit imeta `thumb` field
91-
// if the sender included one.
92-
thumb: isPng
93-
? rewriteRelayUrl(href)
94-
: entry.thumb
95-
? rewriteRelayUrl(entry.thumb)
96-
: undefined,
89+
// PNG snapshots use the attachment URL as the thumb source because it is
90+
// the avatar card image. JSON snapshots use the generic icon.
91+
thumb: isPng ? rewriteRelayUrl(href) : undefined,
9792
};
9893
}
9994

0 commit comments

Comments
 (0)