Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(agent): name another participant above their prompt (#6605)

Wolf Mermelstein175331dec2d7
diff --git a/apps/web/src/features/block-agent/component/AgentMessage.test.tsx b/apps/web/src/features/block-agent/component/AgentMessage.test.tsx
index 6eba802962..d428dda74f 100644
--- a/apps/web/src/features/block-agent/component/AgentMessage.test.tsx
+++ b/apps/web/src/features/block-agent/component/AgentMessage.test.tsx
@@ -18,6 +18,15 @@ import { Message } from './AgentMessage';
vi.mock('@core/util/message-send-motion', () => ({
messageSendMotion: () => {},
}));
+const viewerId = vi.hoisted(() => ({
+ current: 'macro|[email protected]' as string | undefined,
+}));
+vi.mock('@core/context/user', () => ({
+ useUserId: () => () => viewerId.current,
+}));
+vi.mock('@core/user/util', () => ({
+ idToDisplayName: (id: string) => id.replace(/^macro\|/, ''),
+}));
vi.mock('@ui', () => ({
UserMessageBubble: (props: { children: JSX.Element }) => (
<div data-testid="bubble">{props.children}</div>
@@ -76,7 +85,10 @@ vi.mock('../ui', () => ({
),
}));
-afterEach(cleanup);
+afterEach(() => {
+ viewerId.current = 'macro|[email protected]';
+ cleanup();
+});
const text = (value: string): MessagePart => ({ kind: 'text', text: value });
const tool = (
@@ -363,3 +375,45 @@ describe('Message thought shimmer', () => {
expect(view.getByTestId('thought').dataset.active).toBe('false');
});
});
+
+describe('Message prompt attribution', () => {
+ const prompt = (userId: string | null): FoldedMessage => ({
+ ...message([text('Do the thing.')]),
+ author: { kind: 'user', userId },
+ });
+
+ it("names the sender above another participant's prompt", () => {
+ const view = render(() => (
+ <Message message={prompt('macro|[email protected]')} inFlight={false} />
+ ));
+ expect(view.getByTestId('prompt-author').textContent).toBe(
+ );
+ expect(view.getByTestId('bubble').textContent).toBe('Do the thing.');
+ });
+
+ it("leaves the viewer's own prompt unlabelled", () => {
+ const view = render(() => (
+ <Message message={prompt('macro|[email protected]')} inFlight={false} />
+ ));
+ expect(view.queryByTestId('prompt-author')).toBeNull();
+ expect(view.getByTestId('bubble')).toBeTruthy();
+ });
+
+ it('leaves an unattributed prompt unlabelled', () => {
+ const view = render(() => (
+ <Message message={prompt(null)} inFlight={false} />
+ ));
+ expect(view.queryByTestId('prompt-author')).toBeNull();
+ expect(view.getByTestId('bubble')).toBeTruthy();
+ });
+
+ it('leaves a prompt unlabelled while the viewer id is still loading', () => {
+ viewerId.current = undefined;
+ const view = render(() => (
+ <Message message={prompt('macro|[email protected]')} inFlight={false} />
+ ));
+ expect(view.queryByTestId('prompt-author')).toBeNull();
+ expect(view.getByTestId('bubble')).toBeTruthy();
+ });
+});
diff --git a/apps/web/src/features/block-agent/component/AgentMessage.tsx b/apps/web/src/features/block-agent/component/AgentMessage.tsx
index 9c658a5a16..0ac326b61f 100644
--- a/apps/web/src/features/block-agent/component/AgentMessage.tsx
+++ b/apps/web/src/features/block-agent/component/AgentMessage.tsx
@@ -9,6 +9,8 @@
* transcript that let each message decide showed every one of them working.
*/
+import { useUserId } from '@core/context/user';
+import { idToDisplayName } from '@core/user/util';
import { messageSendMotion } from '@core/util/message-send-motion';
import type {
FoldedMessage,
@@ -162,15 +164,42 @@ function workingLabel(message: FoldedMessage): string {
.otherwise(() => 'Working');
}
+/**
+ * The display name of whoever sent a prompt, when that is somebody other
+ * than the viewer. A session is shared, so a prompt may be another
+ * participant's; one's own prompts (and unattributed ones) need no byline,
+ * matching the queued-prompt list in `AgentComposer`. Attribution waits
+ * until the viewer id is known — `useUserId` is undefined while user-info
+ * is still loading, and a missing viewer must not look like another person.
+ */
+function promptAuthorName(
+ author: FoldedMessage['author'],
+ viewerId: string | undefined
+): string | undefined {
+ if (
+ author.kind !== 'user' ||
+ author.userId === null ||
+ viewerId === undefined
+ )
+ return undefined;
+ return author.userId === viewerId
+ ? undefined
+ : idToDisplayName(author.userId);
+}
+
/**
* A prompt, in the chat block's user-bubble treatment
* (`@core/component/AI/component/message/UserMessage.tsx`): right-aligned,
- * rounded, filled surface shared with production chat.
+ * rounded, filled surface shared with production chat. A prompt another
+ * participant sent carries their name above the bubble.
*/
function UserMessage(props: { message: FoldedMessage }) {
+ const userId = useUserId();
+ const authorName = () => promptAuthorName(props.message.author, userId());
+
return (
<div
- class="flex w-full transition-opacity"
+ class="flex w-full flex-col items-end gap-0.5 transition-opacity"
// Still on the wire: the fold shows the prompt before the log confirms
// it, and the confirmation clears this in place.
classList={{ 'opacity-60': props.message.pending }}
@@ -183,6 +212,13 @@ function UserMessage(props: { message: FoldedMessage }) {
)
}
>
+ <Show when={authorName()}>
+ {(name) => (
+ <div class="text-xs text-ink-extra-muted" data-testid="prompt-author">
+ {name()}
+ </div>
+ )}
+ </Show>
<UserMessageBubble>
<For each={props.message.parts}>
{(part, index) => (
diff --git a/apps/web/src/features/block-agent/debug/Gallery.tsx b/apps/web/src/features/block-agent/debug/Gallery.tsx
index ba7fdbef5d..ddde67ddf9 100644
--- a/apps/web/src/features/block-agent/debug/Gallery.tsx
+++ b/apps/web/src/features/block-agent/debug/Gallery.tsx
@@ -7,6 +7,7 @@
import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
import { MagicChipView } from '@core/component/LexicalMarkdown/component/decorator/MagicChip/MagicChipView';
import type { MagicChipPresentation } from '@core/component/LexicalMarkdown/component/decorator/MagicChip/presentation';
+import { useUserId } from '@core/context/user';
import type {
ElicitationSchema,
FoldedMessage,
@@ -541,6 +542,38 @@ function LiveTurnDemo() {
);
}
+/**
+ * A shared session's prompts: the viewer's own bubble stays bare, another
+ * participant's carries their name.
+ */
+function PromptAuthorDemo() {
+ const userId = useUserId();
+ const prompt = (userId: string | null, text: string): FoldedMessage => ({
+ agentSessionId: 'demo',
+ requestId: null,
+ pending: false,
+ turn: 0,
+ author: { kind: 'user', userId },
+ stop: null,
+ parts: [{ kind: 'text', text }],
+ });
+ return (
+ <div class="flex flex-col gap-3">
+ <Message
+ message={prompt(userId() ?? null, 'Tighten up the fold, please.')}
+ inFlight={false}
+ />
+ <Message
+ message={prompt(
+ 'And run the snapshot tests after.'
+ )}
+ inFlight={false}
+ />
+ </div>
+ );
+}
+
/**
* The Claude Code colour question after the fold collapsed its custom pair,
* plus one of every other field type, so the form's controls can be eyeballed.
@@ -962,6 +995,10 @@ export default function AgentUiGallery() {
<Item label="AgentMessage (turn settles)">
<LiveTurnDemo />
</Item>
+
+ <Item label="AgentMessage (prompts: yours, then another participant's)">
+ <PromptAuthorDemo />
+ </Item>
</div>
</div>
</StaticMarkdownContext>