Agent pages: a view gets the writers' names and pictures from the page, read and signed as the viewer #10
merged member-faces was squashed into main as e63d3b3 by jonas, 2026-11-28 02:06 UTC. jonas opened it 2026-11-28 02:06 UTC.
A view in its frame draws a person's message with initials. A person's own context (/users/<platform id>) can say a name and a picture in its catalog row's metadata. The page reads that row for each person who wrote a held message, by the platform's id on the message, signs the picture's address as the viewer, and hands the view `props.people`. A picture is taken only when it is an image under /users/. A viewer who may not list /users gets nothing, and the view draws initials as before. `pnpm check` passes. Card: tasks/show-member-names-and-portrait-avatars-in-the-dash-feed-and.md Via: /agents/claude/dash-context-feed-threads-mwy308tb-4d1e63 Session: claude 89f0feea-b83f-4937-8b4a-56af6cb8884b on beelink
Conversation
Nobody has said anything yet.
Sign in to comment or to merge.
Files
6 files changed
- M src/agent-kind-view/bridge.ts
- M src/agent-kind-view/dash-agents.tsx
- M src/agent-kind-view/frame-view.tsx
- M src/agent-kind-view/types.ts
- A src/agent-kind-view/writers.test.ts
- A src/agent-kind-view/writers.ts
M src/agent-kind-view/bridge.ts
@@ -50,6 +50,8 @@ me?: string; /** `true`: the page shows who else is here (`AgentKindViewProps.presence`). */ presenceOn?: boolean; + /** The writers' names and pictures (`AgentKindViewProps.people`). */ + people?: AgentKindViewProps["people"]; }; /** What changed: the fields that did, and the events added at either end, or all of them again
M src/agent-kind-view/dash-agents.tsx
@@ -18,6 +18,7 @@ // not import this folder. Each loads its larger part when it first draws (the composer, the chat), // and reads the kinds once for the page's life: which kind has which file (the mind's KV, // `agent-kinds`, which worker.ts writes at every publish), and each file's source. +import { useWriters, type WritersItx } from "./writers.ts"; import { createContext, Suspense, @@ -1052,6 +1053,7 @@ const { loading, exhausted } = log.older; const older = useMemo(() => (exhausted ? null : { loading, exhausted }), [loading, exhausted]); const { stub } = agent; + const people = useWriters(itx as unknown as WritersItx, log.events); const hostError = agent.error || load.error; // the cover stands until the frame has drawn (its own document loads first) and the log has // answered: a saved copy answers at once, so the frame's load is said outright @@ -1081,6 +1083,8 @@ // oxlint-disable-next-line iterate/simple-truthiness-check -- the wire view: an absent optional field stays absent ...(me && { me }), presenceOn: presence, + // the writers' names and pictures, read and signed as the viewer (writers.ts) + people, }; // the view's state, as the frame reads it const state = inputs.state;
M src/agent-kind-view/frame-view.tsx
@@ -83,6 +83,7 @@ ...verbs, me: held.me, presence: held.presenceOn, + people: held.people, }; }
M src/agent-kind-view/types.ts
@@ -102,6 +102,12 @@ /** The viewer's actor id or address, when the page knows it: `AgentChat` draws no sender line * under their own messages. */ me?: string; + /** The people who wrote the held messages, by the platform's id on a message + * (`source.principal.actor`): the name and the picture that the person's own context says + * (`/users/<id>`), the picture as an address that the page signed as the viewer. Only those + * with a name or a picture; none on a page whose viewer may not read them (a guest), and + * none on a page older than this field. A view draws initials for anyone who is not here. */ + people?: Readonly<Record<string, { name?: string; picture?: string }>>; /** Another server's MCP App in the feed calls its server through these, as this agent: pass * them on to `AgentChat` as `widgetCalls`. None: a page older than these verbs. */ widgetCalls?: {
A src/agent-kind-view/writers.test.ts
@@ -0,0 +1,71 @@ +import { describe, expect, it } from "vitest"; +import { writerIdsOf, writerOf } from "./writers.ts"; + +const T = "events.iterate.com/"; +const ID = "user_0123456789abcdef0123456789abcdef"; + +describe("the writers of a conversation", () => { + it("names each person once, by the platform's id on their message", () => { + const events = [ + { type: `${T}agent-ui/message-received`, source: { principal: { actor: ID } } }, + { + type: `${T}agent-ui/message-received`, + source: { onBehalfOf: { principal: { actor: ID } } }, + }, + { type: `${T}agent/message-received`, source: {} }, + { + type: `${T}agent-ui/message-sent`, + source: { principal: { actor: "user_0000000000000000" } }, + }, + { + type: `${T}agent-ui/message-received`, + payload: { message: "I am user_ffffffffffffffff" }, + source: {}, + }, + { type: `${T}agent-ui/message-received`, source: { principal: { actor: "not an id" } } }, + ]; + expect(writerIdsOf(events)).toEqual([ID]); + }); + + it("reads the name and an image under /users from the person's own row", () => { + const rows = [ + { path: `/secrets/x-${ID}`, metadata: { title: "A secret" } }, + { + path: `/users/${ID}`, + metadata: { + title: " Ada Example ", + image: { file: "/users/ada/avatar-x.png", contentType: "image/png" }, + }, + }, + ]; + expect(writerOf(ID, rows)).toEqual({ + name: "Ada Example", + file: "/users/ada/avatar-x.png", + }); + }); + + it("gives no picture for a file outside /users, a path that climbs, or a type that is no image", () => { + const row = (image: unknown) => [{ path: `/users/${ID}`, metadata: { title: "J", image } }]; + expect(writerOf(ID, row({ file: "/secrets/key.png", contentType: "image/png" }))).toEqual({ + name: "J", + file: undefined, + }); + expect( + writerOf(ID, row({ file: "/users/../secrets/key.png", contentType: "image/png" })), + ).toEqual({ name: "J", file: undefined }); + expect(writerOf(ID, row({ file: "/users/ada/page.html", contentType: "text/html" }))).toEqual({ + name: "J", + file: undefined, + }); + expect(writerOf(ID, row({ file: "/users/ada/a.svg", contentType: "image/svg+xml" }))).toEqual({ + name: "J", + file: undefined, + }); + }); + + it("says nothing of a person with no row, or a row with neither", () => { + expect(writerOf(ID, [])).toBeNull(); + expect(writerOf(ID, [{ path: `/users/${ID}` }])).toBeNull(); + expect(writerOf(ID, [{ path: `/users/${ID}`, metadata: { title: "" } }])).toBeNull(); + }); +});
A src/agent-kind-view/writers.ts
@@ -0,0 +1,132 @@ +// writers.ts — WHO WROTE THE MESSAGES OF A CONVERSATION, as a member's page may show them: the +// name and the picture that a person's own context says of them, in the place of initials. +// +// A person's context is `/users/<their platform id>`; its `itx/described` gives the catalog row +// a `metadata.title` (the name) and a `metadata.image.file` (a file of the mind). The PAGE reads +// that row and signs the file's address, as the person who looks at the page: a view in its frame +// names no path of the mind and gets a signed address only for its own agent's files (`fileUrl` +// in dash-agents.tsx). So the page hands the view this record, by the platform's id on a message +// and never by a name in a text. A page whose viewer may not list `/users` (a guest) gets a +// refusal and hands nothing: the view then draws initials, as before. +import { useEffect, useMemo, useState } from "react"; + +/** One writer, as the view draws them. */ +export type Writer = { name?: string; picture?: string }; +/** The writers of the held messages that have a name or a picture, by platform id. */ +export type Writers = Readonly<Record<string, Writer>>; + +type CatalogRow = { path?: unknown; metadata?: unknown }; +/** The slice of the member's itx that this reads: the catalog, and a file's signed address. */ +export type WritersItx = { + contexts: { + list(input: { under: string; search: string; limit: number }): Promise<readonly CatalogRow[]>; + }; + files: { + get(path: string): { url(): Promise<{ url: string }>; [Symbol.dispose](): void }; + }; +}; + +const ID = /^user_[0-9a-f]{8,64}$/; +const NONE: Writers = Object.freeze({}); + +/** The platform ids of the people who wrote the messages among `events`, each once. */ +export function writerIdsOf(events: readonly unknown[]): string[] { + const ids = new Set<string>(); + for (const raw of events) { + const event = raw as { + type?: unknown; + source?: { + principal?: { actor?: unknown }; + onBehalfOf?: { principal?: { actor?: unknown } }; + }; + } | null; + if (typeof event?.type !== "string" || !event.type.endsWith("/message-received")) continue; + const actor = (event.source?.principal || event.source?.onBehalfOf?.principal)?.actor; + if (typeof actor === "string" && ID.test(actor)) ids.add(actor); + } + return [...ids]; +} + +/** What the catalog row of `/users/<id>` says of the person: a name, and a picture's file when it + * is an image under `/users/`. A row that names any other file gives no picture: a context's + * metadata is written by agents, and this signs an address as the viewer. */ +export function writerOf( + id: string, + rows: readonly CatalogRow[], +): { name?: string; file?: string } | null { + const row = rows.find((each) => each.path === `/users/${id}`); + const metadata = row?.metadata as + | { title?: unknown; image?: { file?: unknown; contentType?: unknown } } + | undefined; + if (!metadata || typeof metadata !== "object") return null; + const name = + typeof metadata.title === "string" && metadata.title.trim() + ? metadata.title.trim().slice(0, 80) + : undefined; + const image = metadata.image; + const file = + image && + typeof image.file === "string" && + /^\/users\/[^?#]+$/.test(image.file) && + !image.file.includes("..") && + typeof image.contentType === "string" && + /^image\/(png|jpeg|webp|gif)$/.test(image.contentType) + ? image.file + : undefined; + return name || file ? { name, file } : null; +} + +/** One person's record, read and signed as the viewer. Null: nothing to show, or refused. */ +async function readWriter(itx: WritersItx, id: string): Promise<Writer | null> { + const rows = await itx.contexts.list({ under: "/users", search: id, limit: 5 }); + const said = writerOf(id, rows); + if (!said) return null; + if (!said.file) return { name: said.name }; + const file = itx.files.get(said.file); + try { + return { name: said.name, picture: (await file.url()).url }; + } catch { + // the picture is not there, or not the viewer's to read: the name alone + return said.name ? { name: said.name } : null; + } finally { + file[Symbol.dispose](); + } +} + +/** THE WRITERS OF `events`, read once for each person while the page lives. `itx` undefined (no + * member's session): none. The same object while nothing changed, so the frame is told once. */ +export function useWriters(itx: WritersItx | undefined, events: readonly unknown[]): Writers { + const ids = useMemo(() => writerIdsOf(events).join(","), [events]); + const [known, setKnown] = useState<{ itx: unknown; writers: Record<string, Writer | null> }>({ + itx, + writers: {}, + }); + // another session: what was read as another viewer is not this one's + if (known.itx !== itx) setKnown({ itx, writers: {} }); + useEffect(() => { + if (!itx || !ids) return; + let current = true; + for (const id of ids.split(",")) { + if (id in known.writers) continue; + readWriter(itx, id) + .catch(() => null) + .then((writer) => { + if (current) + setKnown((held) => + held.itx !== itx || id in held.writers + ? held + : { itx, writers: { ...held.writers, [id]: writer } }, + ); + }); + } + return () => { + current = false; + }; + }, [itx, ids, known.writers]); + return useMemo(() => { + const shown = Object.entries(known.writers).filter( + (entry): entry is [string, Writer] => entry[1] !== null, + ); + return shown.length ? Object.fromEntries(shown) : NONE; + }, [known.writers]); +}