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(markdown): render document mentions that omit documentName (#9567)

Wolf Mermelstein65a329a9f29e
diff --git a/apps/web/src/features/block-agent/browser-test/mentions.browser.e2e.ts b/apps/web/src/features/block-agent/browser-test/mentions.browser.e2e.ts
index c05e7100bc..96da6d56da 100644
--- a/apps/web/src/features/block-agent/browser-test/mentions.browser.e2e.ts
+++ b/apps/web/src/features/block-agent/browser-test/mentions.browser.e2e.ts
@@ -62,3 +62,25 @@ test('literal mention examples stay code when stopped and reloaded', async ({
);
await expect(reply).toContainText('as the tag name.');
});
+
+test('mentions without a documentName render as typed chips', async ({
+ page,
+}) => {
+ await page.goto('/mentions.html?unnamed');
+ const reply = page.getByRole('region', { name: 'Agent reply' });
+ const chips = reply.locator('[data-document-mention]');
+ await expect(chips).toHaveCount(5, { timeout: 30_000 });
+ for (const [index, blockName] of [
+ 'calendar',
+ 'email',
+ 'call',
+ 'channel',
+ 'md',
+ ].entries()) {
+ await expect(chips.nth(index)).toHaveAttribute(
+ 'data-block-name',
+ blockName
+ );
+ }
+ await expect(reply).not.toContainText('Unknown');
+});
diff --git a/apps/web/src/features/block-agent/browser-test/mentions.tsx b/apps/web/src/features/block-agent/browser-test/mentions.tsx
index c324f91fe9..49de84eab9 100644
--- a/apps/web/src/features/block-agent/browser-test/mentions.tsx
+++ b/apps/web/src/features/block-agent/browser-test/mentions.tsx
@@ -22,11 +22,26 @@ const MENTION = buildAgentSessionMentionMarkdown({
label: LABEL,
});
+// Agents often leave out the empty documentName their instructions show.
+const UNNAMED_MENTIONS = [
+ ['calendar-event', 'calendar', {}],
+ ['email-thread', 'email', {}],
+ ['call-record', 'call', {}],
+ ['channel', 'channel', { channel_message_id: 'channel-message' }],
+ ['document', 'md', {}],
+]
+ .map(
+ ([documentId, blockName, blockParams]) =>
+ `- <m-document-mention>${JSON.stringify({ documentId, blockName, blockParams })}</m-document-mention>`
+ )
+ .join('\n');
+
function Fixture() {
const [stopped, setStopped] = createSignal(
new URLSearchParams(location.search).has('stopped')
);
const literal = new URLSearchParams(location.search).has('literal');
+ const unnamed = new URLSearchParams(location.search).has('unnamed');
const reply = (): FoldedMessage => ({
agentSessionId: 'fixture',
key: '1:agent',
@@ -35,9 +50,11 @@ function Fixture() {
parts: [
{
kind: 'text',
- text: literal
- ? 'Use `<m-document-mention>` as the tag name.'
- : `Here is ${MENTION}. The next reference is <m-document-mention>{"documentId":"unfinished`,
+ text: unnamed
+ ? UNNAMED_MENTIONS
+ : literal
+ ? 'Use `<m-document-mention>` as the tag name.'
+ : `Here is ${MENTION}. The next reference is <m-document-mention>{"documentId":"unfinished`,
},
],
stop: stopped() ? { kind: 'cancelled' } : null,
diff --git a/packages/lexical-core/AGENTS.md b/packages/lexical-core/AGENTS.md
index 0d560f6319..401efa540c 100644
--- a/packages/lexical-core/AGENTS.md
+++ b/packages/lexical-core/AGENTS.md
@@ -31,6 +31,9 @@ composer imports the URL matcher from this package; do not duplicate it.
Human user mention Markdown requires only a nonempty string `userId`; the importer
derives a missing email from `macro|` IDs so web name lookup and clipboard round
trips can resolve the user. Other identities still need an email or display name.
+Document mention Markdown requires only `documentId` (cards also need
+`blockName`); `documentName` is a cached label the chip replaces with the live
+name, and agents routinely omit it.
Keep URLs protected from inline formatting during import; matching rendered
text is too late. Preserve code, mention payloads, existing links, and escaped
diff --git a/packages/lexical-core/tests/document-mention-without-name.test.ts b/packages/lexical-core/tests/document-mention-without-name.test.ts
new file mode 100644
index 0000000000..52dc82d77e
--- /dev/null
+++ b/packages/lexical-core/tests/document-mention-without-name.test.ts
@@ -0,0 +1,70 @@
+import { describe, expect, it } from 'vitest';
+import { markdownToSerializedEditorStateWithIds } from '../utils/markdown-state';
+
+describe('document mentions without a cached name', () => {
+ it('imports the chips an agent wrote without documentName', () => {
+ // Verbatim shapes from an agent briefing that rendered "Unknown Item" for
+ // every chip: the model left out the empty documentName the prompt shows.
+ const markdown = [
+ '<m-document-mention>{"documentId":"01a19313-9b37-7e60-b932-bf486394ba48","blockName":"calendar","blockParams":{}}</m-document-mention>',
+ '<m-document-mention>{"documentId":"01a1a1cd-bc44-7b70-8598-19c9b4c76cdc","blockName":"email","blockParams":{}}</m-document-mention>',
+ '<m-document-mention>{"documentId":"01a19d1a-8248-7631-b5a0-cf51b4d692a1","blockName":"call","blockParams":{}}</m-document-mention>',
+ '<m-document-mention>{"documentId":"0195cea4-5491-77f9-9224-1291fdb8f150","blockName":"channel","blockParams":{"channel_message_id":"01a19985-6478-7ee8-98ed-a7549b9b66a2"}}</m-document-mention>',
+ '<m-document-mention>{"documentId":"01a18d30-5a4c-7c73-97f1-2f94925f98e0","blockName":"md","blockParams":{}}</m-document-mention>',
+ ].join(' ');
+ const state = markdownToSerializedEditorStateWithIds(markdown);
+ expect(state.root.children[0]).toMatchObject({
+ children: [
+ {
+ type: 'document-mention',
+ documentId: '01a19313-9b37-7e60-b932-bf486394ba48',
+ documentName: '',
+ blockName: 'calendar',
+ },
+ { type: 'text', text: ' ' },
+ {
+ type: 'document-mention',
+ documentId: '01a1a1cd-bc44-7b70-8598-19c9b4c76cdc',
+ documentName: '',
+ blockName: 'email',
+ },
+ { type: 'text', text: ' ' },
+ {
+ type: 'document-mention',
+ documentId: '01a19d1a-8248-7631-b5a0-cf51b4d692a1',
+ documentName: '',
+ blockName: 'call',
+ },
+ { type: 'text', text: ' ' },
+ {
+ type: 'document-mention',
+ documentId: '0195cea4-5491-77f9-9224-1291fdb8f150',
+ documentName: '',
+ blockName: 'channel',
+ blockParams: {
+ channel_message_id: '01a19985-6478-7ee8-98ed-a7549b9b66a2',
+ },
+ },
+ { type: 'text', text: ' ' },
+ {
+ type: 'document-mention',
+ documentId: '01a18d30-5a4c-7c73-97f1-2f94925f98e0',
+ documentName: '',
+ blockName: 'md',
+ },
+ ],
+ });
+ });
+
+ it('imports a document card without documentName', () => {
+ const state = markdownToSerializedEditorStateWithIds(
+ '<m-document-card>{"documentId":"01a18d30-5a4c-7c73-97f1-2f94925f98e0","blockName":"md","blockParams":{}}</m-document-card>'
+ );
+ expect(state.root.children[0]).toMatchObject({
+ type: 'document-card',
+ documentId: '01a18d30-5a4c-7c73-97f1-2f94925f98e0',
+ documentName: '',
+ blockName: 'md',
+ });
+ });
+});
diff --git a/packages/lexical-core/transformers/mentions.ts b/packages/lexical-core/transformers/mentions.ts
index 12c29b45d3..0ec907dc3d 100644
--- a/packages/lexical-core/transformers/mentions.ts
+++ b/packages/lexical-core/transformers/mentions.ts
@@ -252,12 +252,11 @@ export const I_DOCUMENT_MENTION: TextMatchTransformer = {
replace: (node: TextNode, match: RegExpMatchArray) => {
try {
const data = JSON.parse(match[1]);
- for (const field of ['documentId', 'documentName']) {
- if (!(field in data)) throw new Error(`Missing field ${field}`);
- }
+ if (!('documentId' in data)) throw new Error('Missing field documentId');
+ // documentName only caches the label; the chip loads the real name.
const documentMentionNode = new DocumentMentionNode(
data.documentId,
- data.documentName,
+ data.documentName ?? '',
data.blockName ?? 'unknown',
data.blockParams,
undefined,
@@ -560,12 +559,12 @@ export const I_DOCUMENT_CARD: ElementTransformer = {
) => {
try {
const data = JSON.parse(match[1]);
- for (const field of ['documentId', 'documentName', 'blockName']) {
+ for (const field of ['documentId', 'blockName']) {
if (!(field in data)) throw new Error(`Missing field ${field}`);
}
const documentCardNode = new DocumentCardNode(
data.documentId,
- data.documentName,
+ data.documentName ?? '',
data.blockName,
data.blockParams,
data.previewBox,