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.

fix(channel/agent): extract magic chip message + id on all reply paths (#6157)

Seamus54533bf3b8a9
diff --git a/apps/web/src/features/channel/Channel/create-channel-hotkeys.ts b/apps/web/src/features/channel/Channel/create-channel-hotkeys.ts
index d4de361026..f96eca0ef3 100644
--- a/apps/web/src/features/channel/Channel/create-channel-hotkeys.ts
+++ b/apps/web/src/features/channel/Channel/create-channel-hotkeys.ts
@@ -3,6 +3,7 @@ import { TOKENS } from '@core/hotkey/tokens';
import type { ApiChannelMessage } from '@service-storage/generated/schemas/apiChannelMessage';
import type { Accessor } from 'solid-js';
import type { MessageActions, MessageData } from '../Message';
+import { getMessageReplyPreviewTexts } from '../Message/browser-selection';
import { isBotMessage } from '../Thread/utils/message-actions';
import type { MessageSelection } from './create-message-selection';
import type { ThreadListNavigation } from './ThreadList';
@@ -123,7 +124,10 @@ export function createChannelHotkeys(options: CreateChannelHotkeysOptions) {
const msg = getSelectedMessage();
if (!msg) return false;
const actions = options.getMessageActions(msg);
- actions?.onReply?.({ message: msg });
+ actions?.onReply?.({
+ message: msg,
+ ...getMessageReplyPreviewTexts(msg.id),
+ });
return true;
},
});
diff --git a/apps/web/src/features/channel/Channel/tests/create-channel-hotkeys.test.tsx b/apps/web/src/features/channel/Channel/tests/create-channel-hotkeys.test.tsx
index bd3a35d6cd..c14c29ca1e 100644
--- a/apps/web/src/features/channel/Channel/tests/create-channel-hotkeys.test.tsx
+++ b/apps/web/src/features/channel/Channel/tests/create-channel-hotkeys.test.tsx
@@ -77,6 +77,13 @@ function ChannelEditHarness(props: {
return (
<div ref={attachGlobalDOMScope}>
<div ref={attachMessageListRef} tabIndex={-1} data-testid="message-list">
+ <div data-message data-message-id={originalMessage.id}>
+ <div data-message-content>
+ <div data-message-reply-preview="Resolved bot response">
+ Resolved bot response
+ </div>
+ </div>
+ </div>
<Show when={isEditing()}>
<TestMessageEditor
onSave={() => {
@@ -136,4 +143,21 @@ describe('createChannelHotkeys', () => {
fireEvent.keyUp(messageList, { key: 'Enter' });
expect(onReply).not.toHaveBeenCalled();
});
+
+ it('passes resolved decorator text when Enter opens a reply', () => {
+ const onSave = vi.fn();
+ const onReply = vi.fn();
+ render(() => <ChannelEditHarness onSave={onSave} onReply={onReply} />);
+
+ const messageList = screen.getByTestId('message-list');
+ messageList.focus();
+ fireEvent.keyDown(messageList, { key: 'Enter' });
+
+ expect(onReply).toHaveBeenCalledWith(
+ expect.objectContaining({
+ message: originalMessage,
+ renderedText: 'Resolved bot response',
+ })
+ );
+ });
});
diff --git a/apps/web/src/features/channel/Message/SwipeToReplyRow.tsx b/apps/web/src/features/channel/Message/SwipeToReplyRow.tsx
index 5ca5799d0f..165dbf7f60 100644
--- a/apps/web/src/features/channel/Message/SwipeToReplyRow.tsx
+++ b/apps/web/src/features/channel/Message/SwipeToReplyRow.tsx
@@ -6,6 +6,7 @@ import { triggerFocusInput } from '@core/directive/focusInput';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import ReplyIcon from '@phosphor/arrow-bend-up-left.svg';
import { type ParentProps, Show, useContext } from 'solid-js';
+import { getMessageReplyPreviewTexts } from './browser-selection';
import type { MessageActions, MessageData } from './types';
/**
@@ -54,7 +55,10 @@ export function MaybeSwipeToReplyRow(
`[data-input-id="thread-reply-input-${threadId}"] [contenteditable]`
)
);
- void onReply({ message: props.message });
+ void onReply({
+ message: props.message,
+ ...getMessageReplyPreviewTexts(props.message.id),
+ });
};
return (
diff --git a/apps/web/src/features/channel/Message/browser-selection.ts b/apps/web/src/features/channel/Message/browser-selection.ts
index 8ed09a627a..bdbad293f6 100644
--- a/apps/web/src/features/channel/Message/browser-selection.ts
+++ b/apps/web/src/features/channel/Message/browser-selection.ts
@@ -49,3 +49,22 @@ export function getRenderedMessageReplyText(
const text = (explicitText || renderedText || preview?.textContent)?.trim();
return text || undefined;
}
+
+/**
+ * Look up a mounted message by id and return the same reply-preview fields
+ * the hover Reply action captures. Keyboard and swipe replies have no click
+ * target, so they need this DOM lookup instead.
+ */
+export function getMessageReplyPreviewTexts(messageId: string): {
+ selectedText?: string;
+ renderedText?: string;
+} {
+ const messageRoot = document.querySelector<HTMLElement>(
+ `[data-message-id="${messageId}"]`
+ );
+ if (!messageRoot) return {};
+ return {
+ selectedText: getSelectedMessageText(messageRoot, messageId),
+ renderedText: getRenderedMessageReplyText(messageRoot, messageId),
+ };
+}
diff --git a/apps/web/src/features/channel/Thread/create-thread-hotkeys.ts b/apps/web/src/features/channel/Thread/create-thread-hotkeys.ts
index 1c5b19401b..07625e678a 100644
--- a/apps/web/src/features/channel/Thread/create-thread-hotkeys.ts
+++ b/apps/web/src/features/channel/Thread/create-thread-hotkeys.ts
@@ -10,6 +10,7 @@ import type { ApiThreadReply } from '@service-storage/generated/schemas/apiThrea
import { type Accessor, onCleanup } from 'solid-js';
import type { MessageSelection } from '../Channel/create-message-selection';
import type { MessageActions, MessageData } from '../Message';
+import { getMessageReplyPreviewTexts } from '../Message/browser-selection';
import { scrollMessageIntoView } from '../scroll-utils';
import { isBotMessage } from './utils/message-actions';
@@ -179,7 +180,10 @@ export function createThreadHotkeys(options: CreateThreadHotkeysOptions) {
if (event?.repeat) return true;
const parentMsg = options.parentMessage();
const actions = options.getMessageActions(parentMsg);
- actions?.onReply?.({ message: parentMsg });
+ actions?.onReply?.({
+ message: parentMsg,
+ ...getMessageReplyPreviewTexts(parentMsg.id),
+ });
return true;
},
}).withGroup(group);
diff --git a/apps/web/src/features/channel/Thread/tests/message-actions.test.ts b/apps/web/src/features/channel/Thread/tests/message-actions.test.ts
index 13b6448d77..4749ea337b 100644
--- a/apps/web/src/features/channel/Thread/tests/message-actions.test.ts
+++ b/apps/web/src/features/channel/Thread/tests/message-actions.test.ts
@@ -116,6 +116,28 @@ describe('message-actions helpers', () => {
).toContain('"displayText":"> original prompt"');
});
+ it('needs rendered text when a reply-target plus magic chip leaves no preview', () => {
+ const agentSessionReply = {
+ ...threadReply,
+ content:
+ '<m-reply-target>{"channelId":"channel-1","targetMessageId":"earlier-reply","targetThreadId":"thread-1","displayText":"earlier preview","senderId":"macro|[email protected]"}</m-reply-target>\n\n<m-magic-chip>{"agentSessionId":"session-1","promptedMessage":{"turn":0,"author":"user"},"status":"booting"}</m-magic-chip>',
+ };
+
+ expect(
+ buildReplyTargetValue({
+ channelId: 'channel-1',
+ message: agentSessionReply,
+ })
+ ).toContain('"displayText":""');
+ expect(
+ buildReplyTargetValue({
+ channelId: 'channel-1',
+ message: agentSessionReply,
+ renderedText: 'Resolved bot response',
+ })
+ ).toContain('"displayText":"Resolved bot response"');
+ });
+
it('ignores a leading reply-target block in the automatic preview', () => {
expect(
buildReplyTargetValue({