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(mentions): make app link parsing be route aware (#7093)

dev-rb9102ee818a17
diff --git a/apps/web/src/components/app/split-layout/split-router/mention-links.ts b/apps/web/src/components/app/split-layout/split-router/mention-links.ts
new file mode 100644
index 0000000000..8328cf00e1
--- /dev/null
+++ b/apps/web/src/components/app/split-layout/split-router/mention-links.ts
@@ -0,0 +1,95 @@
+import {
+ BlockAliasRegistry,
+ BlockRegistry,
+} from '@app/lib/constants/block-registry';
+import {
+ decodeRouteLayout,
+ getExternalSearchKeys,
+ parseRoutePathname,
+ SPLIT_PATH_SEPARATOR,
+ type SplitReference,
+ type SplitRoutesManifest,
+ useOptionalSplitRouter,
+} from '@app/lib/split-router';
+import type { BlockAlias, BlockName } from '@core/block';
+import { parseInternalAppLink } from '@core/util/macroAppUrl';
+import { z } from 'zod';
+
+export type MacroMentionLink = {
+ id: string;
+ block: BlockName | BlockAlias;
+ params: Record<string, string>;
+};
+
+export type MacroMentionLinkResolver = (
+ url: string
+) => MacroMentionLink | undefined;
+
+const referenceSchema = z.object({
+ id: z.string().min(1),
+ type: z.enum([...BlockRegistry, ...BlockAliasRegistry]),
+});
+const uuidReferenceSchema = referenceSchema.extend({
+ id: z.guid(),
+});
+
+export function uuidRouteReference(
+ id: unknown,
+ type: unknown
+): SplitReference | undefined {
+ const parsed = uuidReferenceSchema.safeParse({ id, type });
+ return parsed.success ? parsed.data : undefined;
+}
+
+function isBlockRouteReference(
+ reference: SplitReference | undefined
+): reference is SplitReference & { type: BlockName | BlockAlias } {
+ return referenceSchema.safeParse(reference).success;
+}
+
+/** Interpret a matched app route as an entity without importing eager view routes. */
+export function createMacroMentionLinkResolver(
+ routes: SplitRoutesManifest
+): MacroMentionLinkResolver {
+ return (url) => {
+ const link = parseInternalAppLink(url);
+ if (!link) return;
+
+ const segments = parseRoutePathname(routes, link.path);
+ if (!segments) return;
+ const entries = decodeRouteLayout(routes, segments);
+ const paneCount =
+ segments.filter((segment) => segment === SPLIT_PATH_SEPARATOR).length + 1;
+ if (entries.length !== paneCount) return;
+ // A copied layout URL lists panes from left to right without an active-pane id.
+ const entry = entries.at(-1);
+ if (!entry) return;
+
+ const leaf = entry.location.route.matches.at(-1);
+ if (!leaf) return;
+ const reference = routes.byId
+ .get(leaf.id)
+ ?.definition.toReference?.(leaf.params);
+ if (!isBlockRouteReference(reference)) return;
+ const mention: MacroMentionLink = {
+ id: reference.id,
+ block: reference.type,
+ params: {},
+ };
+ const externalKeys = getExternalSearchKeys(routes, [entry]);
+ new URLSearchParams(link.query).forEach((value, key) => {
+ if (key !== 'referral_code' && externalKeys.has(key)) {
+ mention.params[key] = value;
+ }
+ });
+ return mention;
+ };
+}
+
+/** Capture an app-owned resolver at an editor host, then pass it to the editor. */
+export function useMacroMentionLinkResolver():
+ | MacroMentionLinkResolver
+ | undefined {
+ const router = useOptionalSplitRouter();
+ return router && createMacroMentionLinkResolver(router.routes);
+}
diff --git a/apps/web/src/components/app/split-layout/tests/app-route-search.test.ts b/apps/web/src/components/app/split-layout/tests/app-route-search.test.ts
index 118acc6d00..b6c37b8208 100644
--- a/apps/web/src/components/app/split-layout/tests/app-route-search.test.ts
+++ b/apps/web/src/components/app/split-layout/tests/app-route-search.test.ts
@@ -5,6 +5,7 @@ import {
} from '@app/lib/split-router/url';
import { describe, expect, it, vi } from 'vitest';
import { appSplitRoutes } from '../split-router/app-routes';
+import { createMacroMentionLinkResolver } from '../split-router/mention-links';
vi.mock('@service-storage/websocket', () => ({
storageWS: { reconnectIfDisconnected: vi.fn() },
@@ -59,3 +60,78 @@ describe('application route search ownership', () => {
);
});
});
+
+const mentionId = '019507e8-14a3-7bc1-8610-419f16bd03a8';
+const projectId = '019507e8-14a3-7bc1-8610-419f16bd03a9';
+const resolveMention = createMacroMentionLinkResolver(routes);
+
+describe('application route mentions', () => {
+ it('preserves task comment targets in both task contexts', () => {
+ for (const path of [
+ `tasks/${mentionId}`,
+ `tasks/projects/${projectId}/tasks/task/${mentionId}`,
+ ]) {
+ expect(
+ resolveMention(
+ `https://dev.macro.com/app/${path}?comment_id=comment&referral_code=ignored&unknown=drop`
+ )
+ ).toEqual({
+ id: mentionId,
+ block: 'task',
+ params: { comment_id: 'comment' },
+ });
+ }
+ });
+
+ it('converts Home PR links with foreign entity IDs', () => {
+ const id = 'macro-inc/macro/pull/6303';
+ expect(
+ resolveMention(
+ `https://dev.macro.com/app/home/pr/${encodeURIComponent(id)}`
+ )
+ ).toEqual({ id, block: 'pr', params: {} });
+ });
+
+ it('converts agent chats and coding sessions', () => {
+ expect(
+ resolveMention(`https://dev.macro.com/app/agents/chat/${mentionId}`)
+ ).toEqual({ id: mentionId, block: 'chat', params: {} });
+ expect(
+ resolveMention(`https://dev.macro.com/app/coders/${mentionId}`)
+ ).toEqual({ id: mentionId, block: 'agent', params: {} });
+ });
+
+ it('uses the rightmost pane of a copied layout URL', () => {
+ expect(
+ resolveMention(
+ `https://dev.macro.com/app/home/~/drive/md/${mentionId}?comment_id=comment`
+ )
+ ).toEqual({
+ id: mentionId,
+ block: 'md',
+ params: { comment_id: 'comment' },
+ });
+ expect(
+ resolveMention(
+ `https://dev.macro.com/app/md/${mentionId}/~/drive/md/${mentionId}`
+ )
+ ).toEqual({ id: mentionId, block: 'md', params: {} });
+ expect(
+ resolveMention(
+ `https://dev.macro.com/app/not-a-route/~/drive/md/${mentionId}`
+ )
+ ).toBeUndefined();
+ expect(
+ resolveMention(
+ `https://dev.macro.com/app/drive/md/${mentionId}/~/reviews`
+ )
+ ).toBeUndefined();
+ });
+
+ it('leaves unsupported and invalid destinations as links', () => {
+ expect(resolveMention('https://dev.macro.com/app/reviews')).toBeUndefined();
+ expect(
+ resolveMention('https://dev.macro.com/app/tasks/not-a-uuid')
+ ).toBeUndefined();
+ });
+});
diff --git a/apps/web/src/features/agents-view/components/ChatComposer.test.tsx b/apps/web/src/features/agents-view/components/ChatComposer.test.tsx
index 2f64ff2a1c..684fdbbc8f 100644
--- a/apps/web/src/features/agents-view/components/ChatComposer.test.tsx
+++ b/apps/web/src/features/agents-view/components/ChatComposer.test.tsx
@@ -34,6 +34,7 @@ vi.mock(
const builder = {
buildHandle: () => ({ lexical: editor.lexical }),
namespace: () => builder,
+ withAppLinkResolver: () => builder,
withMentions: () => builder,
withEmojis: () => builder,
withLinks: () => builder,
diff --git a/apps/web/src/features/agents-view/components/ChatComposer.tsx b/apps/web/src/features/agents-view/components/ChatComposer.tsx
index ce266db5a7..fbe687d40c 100644
--- a/apps/web/src/features/agents-view/components/ChatComposer.tsx
+++ b/apps/web/src/features/agents-view/components/ChatComposer.tsx
@@ -8,6 +8,7 @@ import { createComposerDictation } from '@app/features/dictation/composer-dictat
import { InputProvider } from '@channel/Input/context';
import { Input } from '@channel/Input/Input';
import type { InputAttachmentData, InputCommands } from '@channel/Input/types';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';
import { MarkdownShell } from '@core/component/LexicalMarkdown/builder/MarkdownShell';
import { createComposerLayout } from '@core/component/LexicalMarkdown/utils/create-composer-layout';
@@ -84,6 +85,7 @@ export function ChatComposer(props: {
props.session.onStop &&
!disabled();
const editor = buildConfig('chat')
+ .withAppLinkResolver(useMacroMentionLinkResolver())
.namespace('agents-chat-composer')
.withMentions({ showOpenTabs: true, block: 'agent' })
.withEmojis()
diff --git a/apps/web/src/features/agents-view/route.tsx b/apps/web/src/features/agents-view/route.tsx
index 8a04406a1f..bf93a07b48 100644
--- a/apps/web/src/features/agents-view/route.tsx
+++ b/apps/web/src/features/agents-view/route.tsx
@@ -7,6 +7,7 @@ import {
usePageViewTracking,
withAuth,
} from '@components/app/split-layout/split-router/app-route-shell';
+import { uuidRouteReference } from '@components/app/split-layout/split-router/mention-links';
import { LoadingBlock } from '@core/component/LoadingBlock';
import { enableChatV3Agents } from '@core/constant/featureFlags';
import { useUserContext } from '@core/context/user';
@@ -113,6 +114,7 @@ export const agentsRoute = defineRoute({
remountKey: ({ id }) => id,
claim: ({ id }) => ({ namespace: 'agent', id }),
search: [changesSearch.namespace],
+ toReference: ({ id }) => uuidRouteReference(id, 'agent'),
});
export const codersRoute = defineRoute({
@@ -123,6 +125,7 @@ export const codersRoute = defineRoute({
remountKey: ({ id }) => id,
claim: ({ id }) => ({ namespace: 'agent', id }),
search: [changesSearch.namespace],
+ toReference: ({ id }) => uuidRouteReference(id, 'agent'),
});
export const agentChatsRoute = defineRoute({
@@ -134,6 +137,7 @@ export const agentChatsRoute = defineRoute({
remountKey: ({ id }) => id,
claim: ({ id }) => ({ namespace: 'chat', id }),
search: [changesSearch.namespace],
+ toReference: ({ id }) => uuidRouteReference(id, 'chat'),
});
export const agentsViewRoute = defineRoute({
diff --git a/apps/web/src/features/block-agent/ui/AgentInput.test.tsx b/apps/web/src/features/block-agent/ui/AgentInput.test.tsx
index 74be54c606..c63a0eca87 100644
--- a/apps/web/src/features/block-agent/ui/AgentInput.test.tsx
+++ b/apps/web/src/features/block-agent/ui/AgentInput.test.tsx
@@ -29,6 +29,7 @@ vi.mock(
const builder = {
buildHandle: () => ({ lexical: editor.lexical }),
namespace: () => builder,
+ withAppLinkResolver: () => builder,
withMentions: () => builder,
withEmojis: () => builder,
withLinks: () => builder,
diff --git a/apps/web/src/features/block-agent/ui/AgentInput.tsx b/apps/web/src/features/block-agent/ui/AgentInput.tsx
index aca0e69bf3..83de65832a 100644
--- a/apps/web/src/features/block-agent/ui/AgentInput.tsx
+++ b/apps/web/src/features/block-agent/ui/AgentInput.tsx
@@ -19,6 +19,7 @@ import { createComposerDictation } from '@app/features/dictation/composer-dictat
import { InputProvider } from '@channel/Input/context';
import { Input } from '@channel/Input/Input';
import type { InputAttachmentData, InputCommands } from '@channel/Input/types';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';
import { ComposerEditor } from '@core/component/LexicalMarkdown/component/ComposerEditor';
import type { AgentCommandItem } from '@core/component/LexicalMarkdown/plugins';
@@ -195,6 +196,7 @@ export function AgentInput(props: AgentInputProps) {
};
const editor = buildConfig('chat')
+ .withAppLinkResolver(useMacroMentionLinkResolver())
.namespace('agent-input')
.withMentions({
showOpenTabs: true,
diff --git a/apps/web/src/features/block-automation/component/AutomationPromptEditor.tsx b/apps/web/src/features/block-automation/component/AutomationPromptEditor.tsx
index 34e38ab89a..b99d6bb68d 100644
--- a/apps/web/src/features/block-automation/component/AutomationPromptEditor.tsx
+++ b/apps/web/src/features/block-automation/component/AutomationPromptEditor.tsx
@@ -1,3 +1,4 @@
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { EditorConfigBuilder } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';
import { MarkdownShell } from '@core/component/LexicalMarkdown/builder/MarkdownShell';
@@ -6,6 +7,7 @@ export function AutomationPromptEditor(props: {
onChange: (markdown: string) => void;
}) {
const editor = new EditorConfigBuilder()
+ .withAppLinkResolver(useMacroMentionLinkResolver())
.namespace('automation-prompt')
.withHistory()
.withLinks()
diff --git a/apps/web/src/features/block-canvas/component/nodes/TextBox.tsx b/apps/web/src/features/block-canvas/component/nodes/TextBox.tsx
index 6c796cd410..ce86bab7c2 100644
--- a/apps/web/src/features/block-canvas/component/nodes/TextBox.tsx
+++ b/apps/web/src/features/block-canvas/component/nodes/TextBox.tsx
@@ -1,4 +1,5 @@
import { type Vector2, vec2 } from '@block-canvas/util/vector2';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';
import { DecoratorRenderer } from '@core/component/LexicalMarkdown/component/core/DecoratorRenderer';
import { NodeAccessoryRenderer } from '@core/component/LexicalMarkdown/component/core/NodeAccessoryRenderer';
@@ -71,6 +72,7 @@ function TextBoxEditor(props: {
const toolManager = useToolManager();
const config = buildConfig('markdown')
+ .withAppLinkResolver(useMacroMentionLinkResolver())
.namespace('canvas-text-box')
.withHistory({ timeGap: 400 })
.withEmojis()
diff --git a/apps/web/src/features/block-canvas/signal/clipboard.ts b/apps/web/src/features/block-canvas/signal/clipboard.ts
index d494a8e584..a3a52f65e6 100644
--- a/apps/web/src/features/block-canvas/signal/clipboard.ts
+++ b/apps/web/src/features/block-canvas/signal/clipboard.ts
@@ -1,7 +1,8 @@
import { sharedInstance } from '@block-canvas/util/sharedInstance';
import { getTextNodeHeight } from '@block-canvas/util/style';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { jsonToXML } from '@core/component/LexicalMarkdown/citationsUtils';
-import { parseMacroAppUrl } from '@core/component/LexicalMarkdown/plugins';
+import { resolvePastedMacroAppUrl } from '@core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin';
import { blockNameToFileExtensions } from '@core/constant/allBlocks';
import { CANVAS_SVG_IMPORT } from '@core/constant/featureFlags';
import { nanoid } from 'nanoid';
@@ -44,6 +45,7 @@ export const useClipboard = sharedInstance(() => {
const { staticImageUpload, parseSVGStringToNodes } = useCanvasFileDrop();
const boundingBox = useBoundingBox();
const { activeTextEditor } = useToolManager();
+ const resolveAppLink = useMacroMentionLinkResolver();
const cachedStyle = useCachedStyle();
const style = cachedStyle.getStyle;
@@ -51,12 +53,8 @@ export const useClipboard = sharedInstance(() => {
const { currentPosition, currentScale, viewBox } = useRenderState();
const checkForMacroUrl = (text: string): string => {
- const parsedMacroAppUrl = parseMacroAppUrl(text);
- if (
- !parsedMacroAppUrl.isValid ||
- !parsedMacroAppUrl.id ||
- !parsedMacroAppUrl.block
- ) {
+ const parsedMacroAppUrl = resolvePastedMacroAppUrl(text, resolveAppLink);
+ if (!parsedMacroAppUrl?.id || !parsedMacroAppUrl.block) {
return text;
}
diff --git a/apps/web/src/features/block-channel/component/Compose.tsx b/apps/web/src/features/block-channel/component/Compose.tsx
index 94da7a2b7e..e43064915e 100644
--- a/apps/web/src/features/block-channel/component/Compose.tsx
+++ b/apps/web/src/features/block-channel/component/Compose.tsx
@@ -19,6 +19,7 @@ import {
StaticSplitLabel,
} from '@components/app/split-layout/components/SplitLabel';
import { SplitToolbarLeft } from '@components/app/split-layout/components/SplitToolbar';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { ComposerEditor } from '@core/component/LexicalMarkdown/component/ComposerEditor';
import { createComposerLayout } from '@core/component/LexicalMarkdown/utils/create-composer-layout';
import { RecipientSelector } from '@core/component/RecipientSelector';
@@ -181,6 +182,7 @@ export function ChannelCompose() {
const markdownEditor = createConfiguredChannelMarkdownEditor({
namespace: 'compose-input-markdown',
+ resolveAppLink: useMacroMentionLinkResolver(),
enableMentions: true,
scrollContainer,
onMentionCreate: (mention) => mentionsTracker.onMentionCreate(mention),
diff --git a/apps/web/src/features/block-chat/component/Chat.tsx b/apps/web/src/features/block-chat/component/Chat.tsx
index 973f386087..53f533589c 100644
--- a/apps/web/src/features/block-chat/component/Chat.tsx
+++ b/apps/web/src/features/block-chat/component/Chat.tsx
@@ -4,6 +4,7 @@ import type { ChatData } from '@block-chat/definition';
import { pendingLocationParamsSignal } from '@block-chat/signal/pendingLocationParams';
import { FloatRegionOrInline } from '@components/app/mobile/float-regions/FloatRegion';
import { useCanAutofocusSplitContent } from '@components/app/split-layout/layoutUtils';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { useNavigatedFromJK } from '@components/app/useNavigatedFromJK';
import { useHasPaidAccess } from '@core/auth/license';
import { useBlockId, useIsNestedBlock } from '@core/block';
@@ -163,11 +164,13 @@ function ChatInner(props: {
input.attachments,
getAttachmentFromMention
);
- const editor = buildChatEditor().withMentions({
- ...attachmentMentionCallbacks,
- block: 'chat',
- showOpenTabs: true,
- });
+ const editor = buildChatEditor()
+ .withAppLinkResolver(useMacroMentionLinkResolver())
+ .withMentions({
+ ...attachmentMentionCallbacks,
+ block: 'chat',
+ showOpenTabs: true,
+ });
// Sync isGenerating from controller phase
createEffect(() => {
diff --git a/apps/web/src/features/block-md/component/ComposeSkill.tsx b/apps/web/src/features/block-md/component/ComposeSkill.tsx
index f18083cdb1..e917193948 100644
--- a/apps/web/src/features/block-md/component/ComposeSkill.tsx
+++ b/apps/web/src/features/block-md/component/ComposeSkill.tsx
@@ -1,5 +1,6 @@
import { useSplitLayout } from '@components/app/split-layout/layout';
import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';
import { MarkdownShell } from '@core/component/LexicalMarkdown/builder/MarkdownShell';
import { createLexicalWrapper } from '@core/component/LexicalMarkdown/context/LexicalWrapperContext';
@@ -344,6 +345,7 @@ export function ComposeSkill(props: ComposeSkillProps) {
});
const editorConfig = buildConfig('markdown')
+ .withAppLinkResolver(useMacroMentionLinkResolver())
.withMentions()
.withEmojis()
.withActions()
diff --git a/apps/web/src/features/block-md/component/ComposeTask.tsx b/apps/web/src/features/block-md/component/ComposeTask.tsx
index d7d079ea00..45348f66e6 100644
--- a/apps/web/src/features/block-md/component/ComposeTask.tsx
+++ b/apps/web/src/features/block-md/component/ComposeTask.tsx
@@ -1,5 +1,6 @@
import { useSplitLayout } from '@components/app/split-layout/layout';
import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';
import { MarkdownShell } from '@core/component/LexicalMarkdown/builder/MarkdownShell';
import { EmojiMenu } from '@core/component/LexicalMarkdown/component/menu/EmojiMenu';
@@ -790,6 +791,7 @@ export function ComposeTask(props: ComposeTaskProps) {
});
const editorConfig = buildConfig('markdown')
+ .withAppLinkResolver(useMacroMentionLinkResolver())
.withMentions()
.withTags({
applyTargetLabel: 'Task',
diff --git a/apps/web/src/features/block-md/component/InstructionsEditor.tsx b/apps/web/src/features/block-md/component/InstructionsEditor.tsx
index 97d0c9c81f..9daa638769 100644
--- a/apps/web/src/features/block-md/component/InstructionsEditor.tsx
+++ b/apps/web/src/features/block-md/component/InstructionsEditor.tsx
@@ -25,6 +25,7 @@ import {
} from '@core/component/LexicalMarkdown/plugins';
import { emojisPlugin } from '@core/component/LexicalMarkdown/plugins/emojis/emojisPlugin';
import { snippetsPlugin } from '@core/component/LexicalMarkdown/plugins/snippets';
+import type { MentionLinkResolver } from '@core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin';
import { useUserPromptPlugin } from '@core/component/LexicalMarkdown/plugins/userPrompt';
import { createMenuOperations } from '@core/component/LexicalMarkdown/shared/inlineMenu';
import {
@@ -68,6 +69,7 @@ export function InstructionsEditor(props: {
loroManager: LoroManager;
showLexicalStateDebugger?: boolean;
onLexicalStateDebuggerClose?: () => void;
+ resolveAppLink?: MentionLinkResolver;
}) {
const {
documentId,
@@ -188,7 +190,7 @@ export function InstructionsEditor(props: {
sourceDocumentId: blockId,
})
)
- .use(textPastePlugin())
+ .use(textPastePlugin(props.resolveAppLink))
.use(markdownPastePlugin())
.use(awaitPlugin())
.use(
diff --git a/apps/web/src/features/block-md/component/MarkdownEditor.tsx b/apps/web/src/features/block-md/component/MarkdownEditor.tsx
index fde7a2c9e0..ff05bfd6d9 100644
--- a/apps/web/src/features/block-md/component/MarkdownEditor.tsx
+++ b/apps/web/src/features/block-md/component/MarkdownEditor.tsx
@@ -109,6 +109,7 @@ import {
registerInternalLayoutShiftListener,
} from '@core/component/LexicalMarkdown/plugins/shared/utils';
import { snippetsPlugin } from '@core/component/LexicalMarkdown/plugins/snippets';
+import type { MentionLinkResolver } from '@core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin';
import { createMenuOperations } from '@core/component/LexicalMarkdown/shared/inlineMenu';
import {
editorFocusSignal,
@@ -206,6 +207,7 @@ export function MarkdownEditor(props: {
loroManager: LoroManager;
showLexicalStateDebugger?: boolean;
onLexicalStateDebuggerClose?: () => void;
+ resolveAppLink?: MentionLinkResolver;
}) {
const {
documentId,
@@ -625,7 +627,7 @@ export function MarkdownEditor(props: {
dragListenerRef: editorContainerRef,
})
)
- .use(textPastePlugin())
+ .use(textPastePlugin(props.resolveAppLink))
.use(restoreFocusPlugin())
.use(markdownPastePlugin())
.use(normalizeEnterPlugin())
diff --git a/apps/web/src/features/block-md/component/Notebook.tsx b/apps/web/src/features/block-md/component/Notebook.tsx
index 26080f0b62..815a1ab492 100644
--- a/apps/web/src/features/block-md/component/Notebook.tsx
+++ b/apps/web/src/features/block-md/component/Notebook.tsx
@@ -1,6 +1,7 @@
import { useFeatureFlag } from '@app/lib/analytics/posthog';
import { createSizeBreakpoints } from '@app/util/create-size-breakpoints';
import { CommentMargin } from '@block-md/comments/CommentMargin';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import {
editorFocusSignal,
getSaveState,
@@ -115,6 +116,7 @@ export function Notebook(props: {
const scopeId = () => props.hotkeyScope;
const history = useHistory();
const inlineAiEditing = useFeatureFlag(enableInlineAiEditing);
+ const resolveAppLink = useMacroMentionLinkResolver();
let notebookRef!: HTMLDivElement;
let commentMarginRef: HTMLDivElement | undefined;
@@ -377,6 +379,7 @@ export function Notebook(props: {
leaving the title + properties above it untouched and aligned. */}
<div class="relative">
<MarkdownEditor
+ resolveAppLink={resolveAppLink}
loroManager={props.loroManager}
showLexicalStateDebugger={
canUseLexicalStateDebugger() && showLexicalStateDebugger()
@@ -436,6 +439,7 @@ export function InstructionsNotebook(props: {
const setMd = state.editor.setMd;
const scopeId = () => props.hotkeyScope;
const canUseLexicalStateDebugger = useCanUseLexicalStateDebugger();
+ const resolveAppLink = useMacroMentionLinkResolver();
let notebookRef!: HTMLDivElement;
let contentRef!: HTMLDivElement;
@@ -479,6 +483,7 @@ export function InstructionsNotebook(props: {
>
<div class="grow max-w-3xl pt-12 min-w-0 mx-auto" ref={contentRef}>
<InstructionsEditor
+ resolveAppLink={resolveAppLink}
loroManager={props.loroManager}
showLexicalStateDebugger={
canUseLexicalStateDebugger() && showLexicalStateDebugger()
diff --git a/apps/web/src/features/block-spreadsheet/spreadsheet-mentions.tsx b/apps/web/src/features/block-spreadsheet/spreadsheet-mentions.tsx
index 3069413a38..43a7e54523 100644
--- a/apps/web/src/features/block-spreadsheet/spreadsheet-mentions.tsx
+++ b/apps/web/src/features/block-spreadsheet/spreadsheet-mentions.tsx
@@ -1,3 +1,7 @@
+import {
+ type MacroMentionLinkResolver,
+ useMacroMentionLinkResolver,
+} from '@components/app/split-layout/split-router/mention-links';
import { DocumentMention } from '@core/component/LexicalMarkdown/component/decorator/DocumentMention';
import { UserMention } from '@core/component/LexicalMarkdown/component/decorator/UserMention';
import { MentionsMenu } from '@core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu';
@@ -13,18 +17,25 @@ import {
import ClockIcon from '@phosphor/clock.svg';
import { For, Suspense } from 'solid-js';
import { CellMentionEditor } from './components/CellMentionEditor';
-import type { SpreadsheetMentions } from './context/spreadsheet-mentions';
+import type {
+ CellTextEditorProps,
+ SpreadsheetMentions,
+} from './context/spreadsheet-mentions';
import { SpreadsheetCellLinks } from './spreadsheet-cell-links';
-function linkMentions(value: string): string {
+export function linkMentions(
+ value: string,
+ resolveAppLink?: MacroMentionLinkResolver
+): string {
if (value.startsWith('=')) return value;
return cellTextParts(value)
.map((part) =>
part.mention
? part.text
: part.text.replace(/https?:\/\/[^\s<>]+/g, (url) => {
- const parsed = parseMacroAppUrl(url);
- return parsed.isValid && parsed.id && parsed.block
+ const legacy = parseMacroAppUrl(url);
+ const parsed = legacy.isValid ? legacy : resolveAppLink?.(url);
+ return parsed?.id && parsed.block
? encodeCellMention({
type: 'document',
documentId: parsed.id,
@@ -77,8 +88,9 @@ function CellDateChip(props: CellDateMention) {
);
}
function CellMentions(props: { value: string }) {
+ const resolveAppLink = useMacroMentionLinkResolver();
return (
- <For each={cellTextParts(linkMentions(props.value))}>
+ <For each={cellTextParts(linkMentions(props.value, resolveAppLink))}>
{(part) => {
const mention = part.mention;
if (!mention) return <SpreadsheetCellLinks value={part.text} />;
@@ -110,12 +122,12 @@ function CellMentions(props: { value: string }) {
</For>
);
}
-export const spreadsheetMentions: SpreadsheetMentions = {
- renderText: (value) => <CellMentions value={value} />,
- renderEditor: (props) => (
+function SpreadsheetMentionEditor(props: CellTextEditorProps) {
+ const resolveAppLink = useMacroMentionLinkResolver();
+ return (
<CellMentionEditor
{...props}
- convertPaste={linkMentions}
+ convertPaste={(text) => linkMentions(text, resolveAppLink)}
renderMenu={(menu, anchor, pick) => (
<MentionsMenu
menu={menu}
@@ -129,5 +141,10 @@ export const spreadsheetMentions: SpreadsheetMentions = {
/>
)}
/>
- ),
+ );
+}
+
+export const spreadsheetMentions: SpreadsheetMentions = {
+ renderText: (value) => <CellMentions value={value} />,
+ renderEditor: (props) => <SpreadsheetMentionEditor {...props} />,
};
diff --git a/apps/web/src/features/calendar/components/composer/EventForm.tsx b/apps/web/src/features/calendar/components/composer/EventForm.tsx
index 9bf6893133..bfbc11dfc7 100644
--- a/apps/web/src/features/calendar/components/composer/EventForm.tsx
+++ b/apps/web/src/features/calendar/components/composer/EventForm.tsx
@@ -1,3 +1,4 @@
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { MarkdownTextarea } from '@core/component/LexicalMarkdown/component/core/MarkdownTextarea';
import SpinnerIcon from '@phosphor/spinner.svg';
import type { CalendarUpdateScope } from '@service-email/client';
@@ -66,6 +67,7 @@ const RECURRING_EDIT_SCOPE_OPTIONS = [
/** Create/edit event form laid out like the standalone task composer. */
export function EventForm(props: EventFormProps) {
const formId = createUniqueId();
+ const resolveAppLink = useMacroMentionLinkResolver();
const dateRangeErrorId = `event-composer-date-range-error-${formId}`;
const pastEventWarningId = `event-composer-past-event-warning-${formId}`;
@@ -197,6 +199,7 @@ export function EventForm(props: EventFormProps) {
<Show when={!isOutOfOffice()}>
<div class="h-12 overflow-y-auto">
<MarkdownTextarea
+ resolveAppLink={resolveAppLink}
type="calendar"
initialHtml={calendarDescriptionToEditorHtml(
initialDescription
diff --git a/apps/web/src/features/channel/Input/ChannelInput.tsx b/apps/web/src/features/channel/Input/ChannelInput.tsx
index c7a23d17d0..1328d0b99c 100644
--- a/apps/web/src/features/channel/Input/ChannelInput.tsx
+++ b/apps/web/src/features/channel/Input/ChannelInput.tsx
@@ -1,3 +1,4 @@
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { ComposerEditor } from '@core/component/LexicalMarkdown/component/ComposerEditor';
import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
import { DragInsertIndicator } from '@core/component/LexicalMarkdown/component/misc/DragInsertIndicator';
@@ -270,6 +271,7 @@ export function ChannelInput(props: ChannelInputProps) {
const markdownEditor = createConfiguredChannelMarkdownEditor({
groupMentions: !props.parent || props.parent.type === 'channel',
namespace: props.markdownNamespace ?? 'channel-input-markdown',
+ resolveAppLink: useMacroMentionLinkResolver(),
enableMentions: true,
users: mentionUsers,
scrollContainer,
diff --git a/apps/web/src/features/channels-view/route.tsx b/apps/web/src/features/channels-view/route.tsx
index 91377c34cc..3b1592ae7d 100644
--- a/apps/web/src/features/channels-view/route.tsx
+++ b/apps/web/src/features/channels-view/route.tsx
@@ -10,6 +10,7 @@ import {
RedirectSplit,
withAuth,
} from '@components/app/split-layout/split-router/app-route-shell';
+import { uuidRouteReference } from '@components/app/split-layout/split-router/mention-links';
import { lazy, Show } from 'solid-js';
import { z } from 'zod';
import { getViewPreset } from '../next-soup/sidebar/soup-filter-presets';
@@ -77,6 +78,7 @@ export const channelDetailRoute = defineRoute({
namespace: 'block',
id: `channel:${channelId}`,
}),
+ toReference: ({ channelId }) => uuidRouteReference(channelId, 'channel'),
});
export const channelsSplitRoute = defineRoute({
diff --git a/apps/web/src/features/chat/SoupChatInput.test.tsx b/apps/web/src/features/chat/SoupChatInput.test.tsx
index 10b8d91d5d..1d854cae96 100644
--- a/apps/web/src/features/chat/SoupChatInput.test.tsx
+++ b/apps/web/src/features/chat/SoupChatInput.test.tsx
@@ -22,7 +22,13 @@ vi.mock('@components/app/split-layout/layoutUtils', () => ({
useSplitPanelOrThrow: () => ({ handle: { replace: mocks.replace } }),
}));
vi.mock('@core/component/AI/component/input/buildChatEditor', () => ({
- buildChatEditor: () => ({ withMentions: () => ({}) }),
+ buildChatEditor: () => {
+ const builder = {
+ withAppLinkResolver: () => builder,
+ withMentions: () => ({}),
+ };
+ return builder;
+ },
}));
vi.mock('@core/component/AI/component/input/ChatInput', () => ({
ChatInput: (props: {
diff --git a/apps/web/src/features/chat/SoupChatInput.tsx b/apps/web/src/features/chat/SoupChatInput.tsx
index ead41e87f5..f65d799c10 100644
--- a/apps/web/src/features/chat/SoupChatInput.tsx
+++ b/apps/web/src/features/chat/SoupChatInput.tsx
@@ -1,4 +1,5 @@
import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { buildChatEditor } from '@core/component/AI/component/input/buildChatEditor';
import type { ChatSendInput } from '@core/component/AI/component/input/buildRequest';
import { ChatInput } from '@core/component/AI/component/input/ChatInput';
@@ -33,11 +34,13 @@ function SoupChatInputInner() {
input.attachments,
getAttachmentFromMention
);
- const editor = buildChatEditor().withMentions({
- ...attachmentMentionCallbacks,
- block: 'chat',
- showOpenTabs: true,
- });
+ const editor = buildChatEditor()
+ .withAppLinkResolver(useMacroMentionLinkResolver())
+ .withMentions({
+ ...attachmentMentionCallbacks,
+ block: 'chat',
+ showOpenTabs: true,
+ });
// Persist the model the user picks in the new-chat composer so it survives
// reload/navigation, matching how the existing-chat draft model is restored.
diff --git a/apps/web/src/features/drive-view/route.tsx b/apps/web/src/features/drive-view/route.tsx
index 61f5ad7075..94f80799fb 100644
--- a/apps/web/src/features/drive-view/route.tsx
+++ b/apps/web/src/features/drive-view/route.tsx
@@ -15,6 +15,7 @@ import {
NewAppView,
withAuth,
} from '@components/app/split-layout/split-router/app-route-shell';
+import { uuidRouteReference } from '@components/app/split-layout/split-router/mention-links';
import { useUserContext } from '@core/context/user';
import { lazy } from 'solid-js';
import { z } from 'zod';
@@ -120,6 +121,7 @@ export const driveCallRoute = defineRoute({
component: DriveCallRouteView,
remountKey: ({ callId }) => callId,
claim: ({ callId }) => ({ namespace: 'block', id: `call:${callId}` }),
+ toReference: ({ callId }) => uuidRouteReference(callId, 'call'),
});
const driveDocumentParams = z.object({
documentType: z.enum(DRIVE_DOCUMENT_TYPES),
@@ -143,6 +145,8 @@ export const driveRootDocumentRoute = defineRoute({
namespace: 'block',
id: `${driveDocumentBlockType(documentType)}:${documentId}`,
}),
+ toReference: ({ documentId, documentType }) =>
+ uuidRouteReference(documentId, documentType),
});
export const driveFolderDocumentRoute = defineRoute({
@@ -156,6 +160,8 @@ export const driveFolderDocumentRoute = defineRoute({
namespace: 'block',
id: `${driveDocumentBlockType(documentType)}:${documentId}`,
}),
+ toReference: ({ documentId, documentType }) =>
+ uuidRouteReference(documentId, documentType),
});
export const driveTabDocumentRoute = defineRoute({
@@ -169,6 +175,8 @@ export const driveTabDocumentRoute = defineRoute({
namespace: 'block',
id: `${driveDocumentBlockType(documentType)}:${documentId}`,
}),
+ toReference: ({ documentId, documentType }) =>
+ uuidRouteReference(documentId, documentType),
});
export const driveFolderRoute = defineRoute({
diff --git a/apps/web/src/features/email-compose/views/compose-body.tsx b/apps/web/src/features/email-compose/views/compose-body.tsx
index 4052ebdd99..8c5f31a8c1 100644
--- a/apps/web/src/features/email-compose/views/compose-body.tsx
+++ b/apps/web/src/features/email-compose/views/compose-body.tsx
@@ -1,4 +1,5 @@
import { EmailAttachmentPill } from '@app/features/email-message/components/attachment-pill';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { FileDropOverlay } from '@core/component/FileDropOverlay';
import { MarkdownTextarea } from '@core/component/LexicalMarkdown/component/core/MarkdownTextarea';
import { isInlineMediaFileName } from '@core/component/LexicalMarkdown/utils/fileUploadUtils';
@@ -33,6 +34,7 @@ export function ComposeBody(props: {
}) {
const ctx = useCompose();
const attachmentViewer = createAttachmentViewer();
+ const resolveAppLink = useMacroMentionLinkResolver();
const [editor, setEditor] = createSignal<LexicalEditor>();
const [isDragging, setIsDragging] = createSignal<boolean>();
@@ -128,6 +130,7 @@ export function ComposeBody(props: {
<Scroll>
<MarkdownTextarea
+ resolveAppLink={resolveAppLink}
autoLinkMatchMode="common-tlds"
floatingFormatMenu
domRef={props.inputRef}
diff --git a/apps/web/src/features/email-compose/views/reply-input.tsx b/apps/web/src/features/email-compose/views/reply-input.tsx
index 3bf59e78dd..a2a051abb5 100644
--- a/apps/web/src/features/email-compose/views/reply-input.tsx
+++ b/apps/web/src/features/email-compose/views/reply-input.tsx
@@ -1,4 +1,5 @@
import { EmailAttachmentPill } from '@app/features/email-message/components/attachment-pill';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { FileDropOverlay } from '@core/component/FileDropOverlay';
import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';
import { MarkdownShell } from '@core/component/LexicalMarkdown/builder/MarkdownShell';
@@ -147,6 +148,7 @@ export function ReplyInputView(props: ReplyInputViewProps) {
// File sharing and editor plugin wiring belong to this view. The controller only
// needs to know when editor content has changed and requires another save.
const editorConfig = buildConfig('markdown')
+ .withAppLinkResolver(useMacroMentionLinkResolver())
.namespace('email-base-input-markdown')
.withMentions({
onUserMention: state.handleUserMention,
diff --git a/apps/web/src/features/email-view/route.tsx b/apps/web/src/features/email-view/route.tsx
index 2e46f03282..f30ba9cf21 100644
--- a/apps/web/src/features/email-view/route.tsx
+++ b/apps/web/src/features/email-view/route.tsx
@@ -9,6 +9,7 @@ import {
RedirectSplit,
withAuth,
} from '@components/app/split-layout/split-router/app-route-shell';
+import { uuidRouteReference } from '@components/app/split-layout/split-router/mention-links';
import { lazy, Show } from 'solid-js';
import { z } from 'zod';
import { URL_PARAMS as EMAIL_URL_PARAMS } from '../email-thread/core/location';
@@ -77,6 +78,7 @@ export const emailThreadRoute = defineRoute({
namespace: 'block',
id: `email:${threadId}`,
}),
+ toReference: ({ threadId }) => uuidRouteReference(threadId, 'email'),
});
export const emailSplitRoute = defineRoute({
diff --git a/apps/web/src/features/home/home-chat-input.test.tsx b/apps/web/src/features/home/home-chat-input.test.tsx
index ef6652007c..87baa672d2 100644
--- a/apps/web/src/features/home/home-chat-input.test.tsx
+++ b/apps/web/src/features/home/home-chat-input.test.tsx
@@ -32,9 +32,13 @@ vi.mock('@components/app/split-layout/layoutUtils', () => ({
useSplitPanelOrThrow: () => ({ handle: { replace: mocks.replace } }),
}));
vi.mock('@core/component/AI/component/input/buildChatEditor', () => ({
- buildChatEditor: () => ({
- withMentions: () => ({ controls: { setMarkdown: mocks.setMarkdown } }),
- }),
+ buildChatEditor: () => {
+ const builder = {
+ withAppLinkResolver: () => builder,
+ withMentions: () => ({ controls: { setMarkdown: mocks.setMarkdown } }),
+ };
+ return builder;
+ },
}));
vi.mock('@core/component/AI/component/input/ChatInput', () => ({
ChatInput: (props: { onSend: typeof mocks.onSend }) => {
diff --git a/apps/web/src/features/home/home-chat-input.tsx b/apps/web/src/features/home/home-chat-input.tsx
index bdfb6e42eb..23a7880695 100644
--- a/apps/web/src/features/home/home-chat-input.tsx
+++ b/apps/web/src/features/home/home-chat-input.tsx
@@ -1,6 +1,7 @@
import { useFeatureFlag } from '@app/lib/analytics/posthog';
import { DebugSuspense } from '@channel/DebugSuspense';
import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { buildChatEditor } from '@core/component/AI/component/input/buildChatEditor';
import type { ChatSendInput } from '@core/component/AI/component/input/buildRequest';
import { ChatInput } from '@core/component/AI/component/input/ChatInput';
@@ -64,11 +65,13 @@ export const LegacyHomeChatInput = (props: HomeChatInputProps) => {
input.attachments,
getAttachmentFromMention
);
- const editor = buildChatEditor().withMentions({
- ...attachmentMentionCallbacks,
- block: 'chat',
- showOpenTabs: true,
- });
+ const editor = buildChatEditor()
+ .withAppLinkResolver(useMacroMentionLinkResolver())
+ .withMentions({
+ ...attachmentMentionCallbacks,
+ block: 'chat',
+ showOpenTabs: true,
+ });
const applyDraft = (text: string) => {
replaceHomeComposerDraft(editor.controls, text);
diff --git a/apps/web/src/features/home/route.tsx b/apps/web/src/features/home/route.tsx
index 32ab533368..424acbfbc4 100644
--- a/apps/web/src/features/home/route.tsx
+++ b/apps/web/src/features/home/route.tsx
@@ -24,6 +24,7 @@ import {
RedirectSplit,
withAuth,
} from '@components/app/split-layout/split-router/app-route-shell';
+import { uuidRouteReference } from '@components/app/split-layout/split-router/mention-links';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { lazy, Show } from 'solid-js';
import { URL_PARAMS as EMAIL_URL_PARAMS } from '../email-thread/core/location';
@@ -182,6 +183,10 @@ export const homePreviewRoute = defineRoute({
namespace: 'block',
id: `${homeBaseBlockType(blockType)}:${previewId}`,
}),
+ toReference: ({ previewId, blockType }) =>
+ blockType === 'pr'
+ ? { type: 'pr', id: previewId }
+ : uuidRouteReference(previewId, blockType),
});
export const homeSplitRoute = defineRoute({
diff --git a/apps/web/src/features/projects/project-description.tsx b/apps/web/src/features/projects/project-description.tsx
index 2422fb2ea5..884f8a20d6 100644
--- a/apps/web/src/features/projects/project-description.tsx
+++ b/apps/web/src/features/projects/project-description.tsx
@@ -1,3 +1,4 @@
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { CollabMarkdownEditor } from '@core/collab-surface/CollabMarkdownEditor';
import { Button } from '@ui';
import { createMemo, createSignal, onCleanup, Show } from 'solid-js';
@@ -13,6 +14,7 @@ function DescriptionSession(props: {
return (
<>
<CollabMarkdownEditor
+ resolveAppLink={useMacroMentionLinkResolver()}
sourceId={props.documentId}
session={session}
canEdit={() => props.canEdit}
diff --git a/apps/web/src/features/reviews-view/route.tsx b/apps/web/src/features/reviews-view/route.tsx
index e520978ad6..9c3243b8fc 100644
--- a/apps/web/src/features/reviews-view/route.tsx
+++ b/apps/web/src/features/reviews-view/route.tsx
@@ -32,6 +32,7 @@ export const reviewsPrRoute = defineRoute({
namespace: 'block',
id: `pr:${foreignEntityId}`,
}),
+ toReference: ({ foreignEntityId }) => ({ type: 'pr', id: foreignEntityId }),
});
export const reviewsSplitRoute = defineRoute({
diff --git a/apps/web/src/features/settings/components/instructions-editor.tsx b/apps/web/src/features/settings/components/instructions-editor.tsx
index d47944c171..6a76874944 100644
--- a/apps/web/src/features/settings/components/instructions-editor.tsx
+++ b/apps/web/src/features/settings/components/instructions-editor.tsx
@@ -1,3 +1,4 @@
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';
import { MarkdownShell } from '@core/component/LexicalMarkdown/builder/MarkdownShell';
import { createEffect, on, untrack } from 'solid-js';
@@ -17,6 +18,7 @@ export function AgentInstructionsEditor(props: {
let renderedMarkdown = '';
let editable: HTMLDivElement | undefined;
const config = buildConfig('markdown')
+ .withAppLinkResolver(useMacroMentionLinkResolver())
.namespace('agent-instructions')
.withHistory()
.withCode()
diff --git a/apps/web/src/features/sharing/ios-share-sheet/IosShareSheet.tsx b/apps/web/src/features/sharing/ios-share-sheet/IosShareSheet.tsx
index 37b27afa44..9c788b2b3c 100644
--- a/apps/web/src/features/sharing/ios-share-sheet/IosShareSheet.tsx
+++ b/apps/web/src/features/sharing/ios-share-sheet/IosShareSheet.tsx
@@ -18,6 +18,7 @@ import { buildPostMessageRequest } from '@channel/Input/message-payload';
import { getAttachmentKindFromFile } from '@channel/Input/utils/file-helpers';
import { hasSendableInputContent } from '@channel/Input/utils/sendable-content';
import { MobileDrawer } from '@components/app/mobile/MobileDrawer';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { MarkdownShell } from '@core/component/LexicalMarkdown/builder/MarkdownShell';
import { RecipientSelector } from '@core/component/RecipientSelector';
import { toast } from '@core/component/Toast/Toast';
@@ -352,6 +353,7 @@ function IosShareSheetComposer(props: {
const markdownEditor = createConfiguredChannelMarkdownEditor({
namespace: `ios-share-input-${composerId}`,
+ resolveAppLink: useMacroMentionLinkResolver(),
enableMentions: true,
scrollContainer,
onMentionCreate: (mention) => {
diff --git a/apps/web/src/features/tasks-view/route.tsx b/apps/web/src/features/tasks-view/route.tsx
index 13b58e5d93..b163ba63d7 100644
--- a/apps/web/src/features/tasks-view/route.tsx
+++ b/apps/web/src/features/tasks-view/route.tsx
@@ -13,12 +13,14 @@ import {
useParams,
useRouteParams,
} from '@app/lib/split-router';
+import { URL_PARAMS as MARKDOWN_URL_PARAMS } from '@block-md/constants';
import { SidePanel } from '@components/app/side-panel';
import {
NewAppView,
RedirectSplit,
withAuth,
} from '@components/app/split-layout/split-router/app-route-shell';
+import { uuidRouteReference } from '@components/app/split-layout/split-router/mention-links';
import { LoadingBlock } from '@core/component/LoadingBlock';
import { enableProjects } from '@core/constant/featureFlags';
import { useUserContext } from '@core/context/user';
@@ -89,6 +91,8 @@ export const taskDetailRoute = defineRoute({
namespace: 'block',
id: `md:${taskId}`,
}),
+ toReference: ({ taskId }) => uuidRouteReference(taskId, 'task'),
+ externalSearch: Object.values(MARKDOWN_URL_PARAMS),
});
export const projectDetailSearch = {
@@ -202,6 +206,8 @@ export const projectTaskRoute = defineRoute({
component: ProjectTaskRouteView,
remountKey: ({ taskId }) => taskId,
claim: ({ taskId }) => ({ namespace: 'block', id: `md:${taskId}` }),
+ toReference: ({ taskId }) => uuidRouteReference(taskId, 'task'),
+ externalSearch: Object.values(MARKDOWN_URL_PARAMS),
});
export const projectDetailRoute = defineRoute({
diff --git a/apps/web/src/lib/constants/block-registry.ts b/apps/web/src/lib/constants/block-registry.ts
new file mode 100644
index 0000000000..6ce17b26d3
--- /dev/null
+++ b/apps/web/src/lib/constants/block-registry.ts
@@ -0,0 +1,26 @@
+/** Block types accepted by the application. Keep this module free of BlockLoader imports. */
+export const BlockRegistry = [
+ 'call',
+ 'calendar',
+ 'chat',
+ 'write',
+ 'pdf',
+ 'md',
+ 'code',
+ 'image',
+ 'canvas',
+ 'spreadsheet',
+ 'channel',
+ 'project',
+ 'unknown',
+ 'video',
+ 'email',
+ 'contact',
+ 'company',
+ 'automation',
+ 'pr',
+ 'agent',
+] as const;
+
+/** Aliases for block types that share a concrete block implementation. */
+export const BlockAliasRegistry = ['csv', 'task', 'snippet', 'skill'] as const;
diff --git a/apps/web/src/lib/core/block.ts b/apps/web/src/lib/core/block.ts
index 2e77cb90a2..98416cda5c 100644
--- a/apps/web/src/lib/core/block.ts
+++ b/apps/web/src/lib/core/block.ts
@@ -40,36 +40,16 @@ import {
useContext,
} from 'solid-js';
import { createStore, type SetStoreFunction, type Store } from 'solid-js/store';
+import {
+ type BlockAliasRegistry,
+ BlockRegistry,
+} from '../constants/block-registry';
import { ENABLE_PDF_MULTISPLIT } from './constant/featureFlags';
import { blockDataSignal } from './internal/BlockLoader';
import type { Source, SourcePreload } from './source';
import type { ObjectLike, ResultError } from './util/result';
-/**
- * List of valid block types that can be used in the application.
- */
-export const BlockRegistry = [
- 'call',
- 'calendar',
- 'chat',
- 'write',
- 'pdf',
- 'md',
- 'code',
- 'image',
- 'canvas',
- 'spreadsheet',
- 'channel',
- 'project',
- 'unknown',
- 'video',
- 'email',
- 'contact',
- 'company',
- 'automation',
- 'pr',
- 'agent',
-] as const;
+export { BlockAliasRegistry, BlockRegistry } from '../constants/block-registry';
/** Block names that resolve through another concrete block implementation. */
export const VirtualBlockRegistry = ['write'] as const;
@@ -85,12 +65,6 @@ type BlockNameKeys = keyof typeof BlockRegistry & number;
*/
export type BlockName = (typeof BlockRegistry)[BlockNameKeys];
-/**
- * List of strongly-typed, valid aliases that can be used as pseudo-differentiated
- * block types.
- */
-export const BlockAliasRegistry = ['csv', 'task', 'snippet', 'skill'] as const;
-
type BlockAliasKeys = keyof typeof BlockAliasRegistry & number;
/**
diff --git a/apps/web/src/lib/core/collab-surface/CollabMarkdownEditor.tsx b/apps/web/src/lib/core/collab-surface/CollabMarkdownEditor.tsx
index cebeb969e4..31a2a3bbab 100644
--- a/apps/web/src/lib/core/collab-surface/CollabMarkdownEditor.tsx
+++ b/apps/web/src/lib/core/collab-surface/CollabMarkdownEditor.tsx
@@ -22,6 +22,7 @@ import {
} from '@core/component/LexicalMarkdown/plugins';
import { emojisPlugin } from '@core/component/LexicalMarkdown/plugins/emojis/emojisPlugin';
import { snippetsPlugin } from '@core/component/LexicalMarkdown/plugins/snippets';
+import type { MentionLinkResolver } from '@core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin';
import { createMenuOperations } from '@core/component/LexicalMarkdown/shared/inlineMenu';
import {
editorFocusSignal,
@@ -93,6 +94,8 @@ export type CollabMarkdownEditorProps = {
onControls?: (controls: CollabMarkdownControls) => void;
/** Called when the editor enters an error state. */
onError?: (error: MarkdownEditorErrors) => void;
+ /** Convert routed app URLs to document mentions on paste. */
+ resolveAppLink?: MentionLinkResolver;
/** Optional status UI rendered by the collab provider. */
statusChrome?: JSX.Element;
};
@@ -165,7 +168,7 @@ export function CollabMarkdownEditor(props: CollabMarkdownEditorProps) {
sourceDocumentId: props.sourceId,
})
)
- .use(textPastePlugin())
+ .use(textPastePlugin(props.resolveAppLink))
.use(markdownPastePlugin())
.use(awaitPlugin())
.use(
diff --git a/apps/web/src/lib/core/collab-surface/debug/CollabSurfaceDemoPage.tsx b/apps/web/src/lib/core/collab-surface/debug/CollabSurfaceDemoPage.tsx
index 9a25c21cc5..230df95fdd 100644
--- a/apps/web/src/lib/core/collab-surface/debug/CollabSurfaceDemoPage.tsx
+++ b/apps/web/src/lib/core/collab-surface/debug/CollabSurfaceDemoPage.tsx
@@ -1,3 +1,4 @@
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { Block, type BlockName } from '@core/block';
import { createSignal, Show } from 'solid-js';
import { CollabMdSurface } from '../CollabMdSurface';
@@ -39,6 +40,7 @@ export default function CollabSurfaceDemoPage() {
const [surfaceId, setSurfaceId] = createSignal<string>(crypto.randomUUID());
const [seedMarkdown, setSeedMarkdown] = createSignal('# Hello surface');
const [mounted, setMounted] = createSignal<Mounted>();
+ const resolveAppLink = useMacroMentionLinkResolver();
const open = () => {
setMounted(undefined);
@@ -136,6 +138,7 @@ export default function CollabSurfaceDemoPage() {
name={BLOCK_FOR_PARENT[m.parent.entityType] ?? 'md'}
>
<CollabMdSurface
+ resolveAppLink={resolveAppLink}
surfaceId={m.surfaceId}
initialMarkdown={m.initialMarkdown}
placeholder="Type here…"
diff --git a/apps/web/src/lib/core/comments/Inputs.tsx b/apps/web/src/lib/core/comments/Inputs.tsx
index 7ad61d8c7c..83a0986403 100644
--- a/apps/web/src/lib/core/comments/Inputs.tsx
+++ b/apps/web/src/lib/core/comments/Inputs.tsx
@@ -1,3 +1,4 @@
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { MarkdownTextarea } from '@core/component/LexicalMarkdown/component/core/MarkdownTextarea';
import type { ItemMention } from '@core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin';
import XIcon from '@phosphor/x.svg';
@@ -59,6 +60,7 @@ export function EditInput(props: {
const [isSending, setIsSending] = createSignal(false);
const { setActiveThread } = useContext(CommentsContext);
const { mentionsSignal } = useContext(ThreadContext);
+ const resolveAppLink = useMacroMentionLinkResolver();
const [, setMentions] = mentionsSignal;
createEffect(() => {
@@ -108,6 +110,7 @@ export function EditInput(props: {
}}
>
<MarkdownTextarea
+ resolveAppLink={resolveAppLink}
autoLinkMatchMode="common-tlds"
class="text-base wrap-break-word text-ink"
editable={() => true}
diff --git a/apps/web/src/lib/core/comments/discussion/DiscussionInput.tsx b/apps/web/src/lib/core/comments/discussion/DiscussionInput.tsx
index afe04cffa2..1e59fa7752 100644
--- a/apps/web/src/lib/core/comments/discussion/DiscussionInput.tsx
+++ b/apps/web/src/lib/core/comments/discussion/DiscussionInput.tsx
@@ -14,6 +14,7 @@ import {
applyInlineFormat,
applyNodeFormat,
} from '@channel/Input/utils/formatting';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { ComposerEditor } from '@core/component/LexicalMarkdown/component/ComposerEditor';
import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
import type { ItemMention } from '@core/component/LexicalMarkdown/plugins';
@@ -131,6 +132,7 @@ export function DiscussionInput(props: DiscussionInputProps) {
const markdownEditor = createConfiguredDiscussionMarkdownEditor({
type: 'markdown',
namespace: props.markdownNamespace ?? 'discussion-input-markdown',
+ resolveAppLink: useMacroMentionLinkResolver(),
enableMentions: true,
users: props.participants,
scrollContainer,
diff --git a/apps/web/src/lib/core/comments/discussion/configured-discussion-markdown-editor.ts b/apps/web/src/lib/core/comments/discussion/configured-discussion-markdown-editor.ts
index a2e698a13c..944965107a 100644
--- a/apps/web/src/lib/core/comments/discussion/configured-discussion-markdown-editor.ts
+++ b/apps/web/src/lib/core/comments/discussion/configured-discussion-markdown-editor.ts
@@ -7,6 +7,7 @@ import {
import { iosCursorScrollPlugin } from '@core/component/LexicalMarkdown/plugins/ios-cursor-scroll';
import { tableCellResizerPlugin } from '@core/component/LexicalMarkdown/plugins/tables/tableCellResizerPlugin';
import { tablePlugin } from '@core/component/LexicalMarkdown/plugins/tables/tablePlugin';
+import type { MentionLinkResolver } from '@core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin';
import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
import type { IUser } from '@core/user/types';
import type { EditorType } from '@macro-inc/lexical-core';
@@ -15,6 +16,7 @@ import type { Accessor } from 'solid-js';
type CreateConfiguredDiscussionMarkdownEditorOptions = {
namespace: string;
+ resolveAppLink?: MentionLinkResolver;
enableMentions?: boolean;
onMentionCreate?: (mention: ItemMention) => void;
onMentionRemove?: (mention: ItemMention) => void;
@@ -30,6 +32,8 @@ export function createConfiguredDiscussionMarkdownEditor(
) {
const editor = buildConfig(options.type ?? 'chat');
editor.namespace(options.namespace);
+ if (options.resolveAppLink)
+ editor.withAppLinkResolver(options.resolveAppLink);
if (options.enableMentions !== false) {
// Intentionally no `block: 'channel'` — discussions live inside docs/tasks,
diff --git a/apps/web/src/lib/core/component/AI/component/input/ChatInput.model.test.tsx b/apps/web/src/lib/core/component/AI/component/input/ChatInput.model.test.tsx
index c2cae5c69e..a4c4dc1a26 100644
--- a/apps/web/src/lib/core/component/AI/component/input/ChatInput.model.test.tsx
+++ b/apps/web/src/lib/core/component/AI/component/input/ChatInput.model.test.tsx
@@ -85,7 +85,13 @@ vi.mock('@core/signal/permissions', () => ({ useCanEdit: () => () => true }));
vi.mock('@core/util/message-send-motion', () => ({ markMessageSent: vi.fn() }));
vi.mock('@queries/auth', () => ({ invalidateUserQuota: vi.fn() }));
vi.mock('@core/component/AI/component/input/buildChatEditor', () => ({
- buildChatEditor: () => ({ withMentions: () => mocks.editor }),
+ buildChatEditor: () => {
+ const builder = {
+ withAppLinkResolver: () => builder,
+ withMentions: () => mocks.editor,
+ };
+ return builder;
+ },
}));
vi.mock('@core/component/AI/signal/mention-attachment-callbacks', () => ({
createMentionAttachmentCallbacks: () => ({}),
diff --git a/apps/web/src/lib/core/component/AI/component/message/EditableChatMessage.tsx b/apps/web/src/lib/core/component/AI/component/message/EditableChatMessage.tsx
index 961f489754..a22bb57259 100644
--- a/apps/web/src/lib/core/component/AI/component/message/EditableChatMessage.tsx
+++ b/apps/web/src/lib/core/component/AI/component/message/EditableChatMessage.tsx
@@ -1,3 +1,4 @@
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { buildChatEditor } from '@core/component/AI/component/input/buildChatEditor';
import type { ChatSendInput } from '@core/component/AI/component/input/buildRequest';
import { ChatInput } from '@core/component/AI/component/input/ChatInput';
@@ -24,11 +25,13 @@ function EditableChatMessageInner(props: {
input.attachments,
getAttachmentFromMention
);
- const editor = buildChatEditor().withMentions({
- ...attachmentMentionCallbacks,
- block: 'chat',
- showOpenTabs: true,
- });
+ const editor = buildChatEditor()
+ .withAppLinkResolver(useMacroMentionLinkResolver())
+ .withMentions({
+ ...attachmentMentionCallbacks,
+ block: 'chat',
+ showOpenTabs: true,
+ });
onMount(() => {
editor.controls.focus();
diff --git a/apps/web/src/lib/core/component/ForwardToChannel.tsx b/apps/web/src/lib/core/component/ForwardToChannel.tsx
index d3da47d568..48743f1b8d 100644
--- a/apps/web/src/lib/core/component/ForwardToChannel.tsx
+++ b/apps/web/src/lib/core/component/ForwardToChannel.tsx
@@ -1,5 +1,6 @@
import { useAnalytics } from '@app/lib/analytics/analytics-context';
import { createConfiguredChannelMarkdownEditor } from '@channel/Input';
+import { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';
import { useIsAuthenticated } from '@core/auth';
import {
type BlockAlias,
@@ -222,6 +223,7 @@ export function ForwardToChannel(props: ForwardToChannelProps) {
// cmd+enter through the hotkey system below.
const markdownEditor = createConfiguredChannelMarkdownEditor({
namespace: 'forward-to-channel-markdown',
+ resolveAppLink: useMacroMentionLinkResolver(),
enableMentions: true,
onChange: setMarkdown,
});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/builder/MarkdownConfigBuilder.ts b/apps/web/src/lib/core/component/LexicalMarkdown/builder/MarkdownConfigBuilder.ts
index c656f0eee9..ba30e160bf 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/builder/MarkdownConfigBuilder.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/builder/MarkdownConfigBuilder.ts
@@ -3,6 +3,7 @@ import type { LexicalEditor } from 'lexical';
import type { Store } from 'solid-js/store';
import type { PluginManager, SelectionData } from '../plugins';
import type { Action } from '../plugins/actions/types';
+import type { MentionLinkResolver } from '../plugins/text-paste/textPastePlugin';
import { buildHandleFromConfig } from './buildHandleFromConfig';
import type {
ActionsOptions,
@@ -57,6 +58,10 @@ export class EditorConfigBuilder implements EditorBuilder {
return this;
}
+ withAppLinkResolver(resolveAppLink: MentionLinkResolver | undefined): this {
+ this.state.resolveAppLink = resolveAppLink;
+ return this;
+ }
withTags(config: TagsOptions = {}): this {
this.state.tags = {
...config,
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/builder/buildHandleFromConfig.ts b/apps/web/src/lib/core/component/LexicalMarkdown/builder/buildHandleFromConfig.ts
index b3dd7477fb..2253fa8f58 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/builder/buildHandleFromConfig.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/builder/buildHandleFromConfig.ts
@@ -149,7 +149,7 @@ export function buildHandleFromConfig(config: EditorConfig): EditorHandle {
}
// Text paste handling
- plugins.use(textPastePlugin());
+ plugins.use(textPastePlugin(config.resolveAppLink));
// Markdown paste handling (rich & full editors only)
if (config.type !== 'plain-text') {
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/builder/types.ts b/apps/web/src/lib/core/component/LexicalMarkdown/builder/types.ts
index aad3a3848d..e971682fc8 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/builder/types.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/builder/types.ts
@@ -19,6 +19,7 @@ import type {
} from '../plugins';
import type { Action } from '../plugins/actions/types';
import type { TagMentionLifecycle } from '../plugins/tags';
+import type { MentionLinkResolver } from '../plugins/text-paste/textPastePlugin';
import type { createMenuOperations } from '../shared/inlineMenu';
import type { UserMentionRecord } from '../utils/mentionsUtils';
@@ -164,6 +165,7 @@ export interface EditorConfig {
agentCommands?: AgentCommandsOptions;
emojis?: EmojisOptions;
links?: LinksOptions;
+ resolveAppLink?: MentionLinkResolver;
history?: HistoryOptions;
singleLine: boolean;
handlers: EditorCallbacks;
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsx
index 7710b7ed6c..0cc98564f7 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsx
@@ -53,6 +53,7 @@ import {
} from '../../plugins';
import { checkboxToTaskPlugin } from '../../plugins/checkbox-to-task';
import { restoreFocusPlugin } from '../../plugins/restore-focus';
+import type { MentionLinkResolver } from '../../plugins/text-paste/textPastePlugin';
import { createMenuOperations } from '../../shared/inlineMenu';
import {
editorIsEmpty,
@@ -128,6 +129,7 @@ interface MarkdownTextareaProps {
files: FileSystemFileEntry[],
directories: FileSystemDirectoryEntry[]
) => void;
+ resolveAppLink?: MentionLinkResolver;
autoLinkMatchMode?: AutoLinkMatchMode;
/**
* Show a floating format toolbar (headings, lists, inline styles, links)
@@ -235,7 +237,7 @@ export function MarkdownTextarea(props: MarkdownTextareaProps) {
)
.use(tabIndentationPlugin())
.use(listSwipeIndentPlugin(props.editable))
- .use(textPastePlugin())
+ .use(textPastePlugin(props.resolveAppLink))
.use(
mentionsPlugin({
menu: mentionsMenuOperations,
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin.test.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin.test.ts
index 417298290d..a8c6cf6437 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin.test.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it, vi } from 'vitest';
-import { parseMacroAppUrl } from './textPastePlugin';
+import { parseMacroAppUrl, resolvePastedMacroAppUrl } from './textPastePlugin';
// Keep the parser tests independent of application boot and editor UI wiring.
vi.mock('@core/internal/BlockLoader', () => ({}));
@@ -34,6 +34,14 @@ describe('parseMacroAppUrl', () => {
}
);
+ it('does not treat a legacy first pane as a complete legacy link', () => {
+ expect(
+ parseMacroAppUrl(
+ `https://dev.macro.com/app/md/${sessionId}/~/drive/pdf/${sessionId}`
+ ).isValid
+ ).toBe(false);
+ });
+
it.each([
'https://dev.macro.com/app/agents',
'https://dev.macro.com/app/agents/not-a-uuid',
@@ -43,3 +51,78 @@ describe('parseMacroAppUrl', () => {
expect(parseMacroAppUrl(url).isValid).toBe(false);
});
});
+
+describe('route-aware paste resolver', () => {
+ const resolveAppLink = vi.fn(() => ({
+ id: sessionId,
+ block: 'md' as const,
+ params: {},
+ }));
+
+ it('uses the app resolver for routed links', () => {
+ const url = `https://dev.macro.com/app/drive/md/${sessionId}`;
+ expect(resolvePastedMacroAppUrl(url, resolveAppLink)).toEqual({
+ id: sessionId,
+ block: 'md',
+ params: {},
+ });
+ expect(resolveAppLink).toHaveBeenCalledWith(url);
+ });
+
+ it('preserves legacy query parameters without consulting the app resolver', () => {
+ resolveAppLink.mockClear();
+ expect(
+ resolvePastedMacroAppUrl(
+ `https://dev.macro.com/app/md/${sessionId}?comment_id=target`,
+ resolveAppLink
+ )
+ ).toEqual({
+ isValid: true,
+ id: sessionId,
+ block: 'md',
+ params: { comment_id: 'target' },
+ });
+ expect(resolveAppLink).not.toHaveBeenCalled();
+ });
+
+ it.each([
+ ['call', 'call'],
+ ['pr', 'pr'],
+ ['agents', 'agent'],
+ ])(
+ 'keeps legacy /app/%s links ahead of the route resolver',
+ (route, block) => {
+ resolveAppLink.mockClear();
+ expect(
+ resolvePastedMacroAppUrl(
+ `https://dev.macro.com/app/${route}/${sessionId}`,
+ resolveAppLink
+ )
+ ).toEqual({ isValid: true, id: sessionId, block, params: {} });
+ expect(resolveAppLink).not.toHaveBeenCalled();
+ }
+ );
+
+ it('delegates a copied layout with a legacy first pane to the route resolver', () => {
+ const url = `https://dev.macro.com/app/md/${sessionId}/~/drive/pdf/${sessionId}`;
+ const resolveLayout = vi.fn(() => ({
+ id: sessionId,
+ block: 'pdf' as const,
+ params: {},
+ }));
+ expect(resolvePastedMacroAppUrl(url, resolveLayout)).toEqual({
+ id: sessionId,
+ block: 'pdf',
+ params: {},
+ });
+ expect(resolveLayout).toHaveBeenCalledWith(url);
+ });
+
+ it('leaves unknown links unconverted without an app resolver', () => {
+ expect(
+ resolvePastedMacroAppUrl(
+ `https://dev.macro.com/app/drive/md/${sessionId}`
+ )
+ ).toBeUndefined();
+ });
+});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin.ts
index ccdd5f3c41..6db7505e6b 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin.ts
@@ -39,6 +39,13 @@ type MacroAppUrlParsed = {
block: BlockName | BlockAlias | undefined;
params: Record<string, string> | undefined;
};
+export type MentionLinkResolver = (url: string) =>
+ | {
+ id: string;
+ block: BlockName | BlockAlias;
+ params: Record<string, string>;
+ }
+ | undefined;
const IgnoredParams = new Set(['referral_code']);
@@ -60,7 +67,7 @@ export function parseMacroAppUrl(text: string): MacroAppUrlParsed {
}
const pathParts: string[] = url.pathname.split('/').filter((part) => part);
- if (pathParts.length < 3) {
+ if (pathParts.length !== 3) {
return {
isValid: false,
id: undefined,
@@ -114,7 +121,18 @@ export function parseMacroAppUrl(text: string): MacroAppUrlParsed {
}
}
-function registerTextPastePlugin(editor: LexicalEditor) {
+export function resolvePastedMacroAppUrl(
+ text: string,
+ resolveAppLink?: MentionLinkResolver
+) {
+ const legacy = parseMacroAppUrl(text);
+ return legacy.isValid ? legacy : resolveAppLink?.(text);
+}
+
+function registerTextPastePlugin(
+ editor: LexicalEditor,
+ resolveAppLink?: MentionLinkResolver
+) {
return mergeRegister(
editor.registerCommand(
PASTE_COMMAND,
@@ -143,12 +161,11 @@ function registerTextPastePlugin(editor: LexicalEditor) {
return true;
}
- const parsedMacroAppUrl = parseMacroAppUrl(pastedText);
- if (
- !parsedMacroAppUrl.isValid ||
- !parsedMacroAppUrl.id ||
- !parsedMacroAppUrl.block
- ) {
+ const parsedMacroAppUrl = resolvePastedMacroAppUrl(
+ pastedText,
+ resolveAppLink
+ );
+ if (!parsedMacroAppUrl?.id || !parsedMacroAppUrl.block) {
// Large plain-text pastes collapse into a block-level PasteNode
// (Anthropic-style "pasted" chip). Only handle genuine plain text
// pastes: defer to the richer paste handlers for HTML / Lexical
@@ -203,6 +220,7 @@ function registerTextPastePlugin(editor: LexicalEditor) {
);
}
-export function textPastePlugin() {
- return (editor: LexicalEditor) => registerTextPastePlugin(editor);
+export function textPastePlugin(resolveAppLink?: MentionLinkResolver) {
+ return (editor: LexicalEditor) =>
+ registerTextPastePlugin(editor, resolveAppLink);
}
diff --git a/apps/web/src/lib/core/messages/configured-message-editor.ts b/apps/web/src/lib/core/messages/configured-message-editor.ts
index 5b2224d9d3..54560a05f2 100644
--- a/apps/web/src/lib/core/messages/configured-message-editor.ts
+++ b/apps/web/src/lib/core/messages/configured-message-editor.ts
@@ -11,6 +11,7 @@ import {
import { iosCursorScrollPlugin } from '@core/component/LexicalMarkdown/plugins/ios-cursor-scroll';
import { tableCellResizerPlugin } from '@core/component/LexicalMarkdown/plugins/tables/tableCellResizerPlugin';
import { tablePlugin } from '@core/component/LexicalMarkdown/plugins/tables/tablePlugin';
+import type { MentionLinkResolver } from '@core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin';
import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
import type { IUser } from '@core/user/types';
import ImageIcon from '@phosphor/image.svg';
@@ -24,6 +25,7 @@ export type MessageEditorOptions = {
floatingFormatMenu?: boolean;
disableMentionTracking?: boolean;
namespace: string;
+ resolveAppLink?: MentionLinkResolver;
enableMentions?: boolean;
onMentionCreate?: (mention: ItemMention) => void;
onMentionRemove?: (mention: ItemMention) => void;
@@ -43,6 +45,8 @@ export function createConfiguredMessageEditor(options: MessageEditorOptions) {
const editor = buildConfig(options.type ?? 'chat').namespace(
options.namespace
);
+ if (options.resolveAppLink)
+ editor.withAppLinkResolver(options.resolveAppLink);
if (options.enableMentions !== false) {
editor.withMentions({
diff --git a/apps/web/src/lib/split-router/README.md b/apps/web/src/lib/split-router/README.md
index c9a45fa0f8..302623984b 100644
--- a/apps/web/src/lib/split-router/README.md
+++ b/apps/web/src/lib/split-router/README.md
@@ -13,6 +13,8 @@ stay outside this library.
output types, including `remountKey`, and types descendant references relative
to that root. `defineRoutes()` assembles the static tree and rebinds ancestry.
Both attach a non-enumerable `to(params)` builder to route definitions in place.
+- `toReference(params)` optionally describes the matched content as `{ type, id }`
+ for host consumers. The router does not interpret or invoke it during navigation.
- `useRouteParams(route)` reads only that node's params. `useParams(route)` reads
the merged branch through that node; `useParams()` still reads the entire
active branch.
diff --git a/apps/web/src/lib/split-router/index.ts b/apps/web/src/lib/split-router/index.ts
index 99ab45cf9f..99ad75c879 100644
--- a/apps/web/src/lib/split-router/index.ts
+++ b/apps/web/src/lib/split-router/index.ts
@@ -60,6 +60,7 @@ export {
type SplitRouterScopeProps,
useCanGo,
useNavigate,
+ useOptionalSplitRouter,
useOwnsSearchNamespace,
useParams,
useRouteParams,
@@ -83,6 +84,7 @@ export type {
SplitNavigateTo,
SplitNonRouteNavigateTo,
SplitParentNavigationTarget,
+ SplitReference,
SplitRouteClaim,
SplitRouteDefinition,
SplitRouteMatch,
diff --git a/apps/web/src/lib/split-router/routes.ts b/apps/web/src/lib/split-router/routes.ts
index aa22c51686..ca0717f46c 100644
--- a/apps/web/src/lib/split-router/routes.ts
+++ b/apps/web/src/lib/split-router/routes.ts
@@ -7,6 +7,7 @@ import type {
InferSplitRouteParams,
InferSplitRoutePathParams,
InferSplitRouteState,
+ SplitReference,
SplitRouteClaim,
SplitRouteDefinition,
SplitRouteMatch,
@@ -31,6 +32,7 @@ type SplitRouteDefinitionConstraint = {
state?: StandardSchemaV1;
serializeParams?: unknown;
claim?: unknown;
+ toReference?: unknown;
search?: readonly string[] | '*';
externalSearch?: SplitRouteDefinition['externalSearch'];
remountKey?: unknown;
@@ -39,6 +41,7 @@ type SplitRouteDefinitionConstraint = {
type RouteParamCallbacks<TParams> = {
serializeParams?: (params: TParams) => SplitRouteRawParams;
claim?: (params: TParams) => SplitRouteClaim | undefined;
+ toReference?: (params: TParams) => SplitReference | undefined;
remountKey?: (params: TParams) => string | number | undefined;
};
diff --git a/apps/web/src/lib/split-router/solid.tsx b/apps/web/src/lib/split-router/solid.tsx
index 8cf58e8a9c..ab323817ab 100644
--- a/apps/web/src/lib/split-router/solid.tsx
+++ b/apps/web/src/lib/split-router/solid.tsx
@@ -70,6 +70,12 @@ export function useSplitRouter<TSplitId>(): SplitRouterController<TSplitId> {
.router as unknown as SplitRouterController<TSplitId>;
}
+export function useOptionalSplitRouter<TSplitId>() {
+ return useContext(SplitRouterContext)?.router as
+ | SplitRouterController<TSplitId>
+ | undefined;
+}
+
export function useSplitRouterState<TSplitId>() {
const context = useSplitRouterContext();
const router = context.router as unknown as SplitRouterController<TSplitId>;
diff --git a/apps/web/src/lib/split-router/tests/routes.test.ts b/apps/web/src/lib/split-router/tests/routes.test.ts
index 4f017123cb..6b3264f782 100644
--- a/apps/web/src/lib/split-router/tests/routes.test.ts
+++ b/apps/web/src/lib/split-router/tests/routes.test.ts
@@ -81,6 +81,7 @@ describe('split route parameter schemas', () => {
path: 'issue/:issueId',
params: z.object({ issueId: z.coerce.number().int().positive() }),
remountKey: ({ issueId }) => issueId.toFixed(0),
+ toReference: ({ issueId }) => ({ type: 'issue', id: issueId.toFixed(0) }),
});
it('coerces URL strings to typed runtime values', () => {
@@ -96,6 +97,15 @@ describe('split route parameter schemas', () => {
}>();
});
+ it('keeps the route reference callback on the matched definition', () => {
+ const manifest = createRoutesManifest({ definitions: [issueRoute] });
+ expect(manifest.byId.get(issueRoute.id)?.definition).toBe(issueRoute);
+ expect(issueRoute.toReference({ issueId: 42 })).toEqual({
+ type: 'issue',
+ id: '42',
+ });
+ });
+
it('rejects invalid values', () => {
expect(
validateRouteParams(issueRoute.params, { issueId: 'not-a-number' })
diff --git a/apps/web/src/lib/split-router/types.ts b/apps/web/src/lib/split-router/types.ts
index 9de22fab0e..8a0ea85cf4 100644
--- a/apps/web/src/lib/split-router/types.ts
+++ b/apps/web/src/lib/split-router/types.ts
@@ -138,6 +138,12 @@ export type SplitRouteClaim = {
id: string;
};
+/** App-defined identity for a matched route, independent of its pane claim. */
+export type SplitReference = {
+ type: string;
+ id: string;
+};
+
export type SplitRouteMatch = {
id: string;
params: SplitRouteParams;
@@ -188,6 +194,10 @@ export type SplitRouteDefinition<
StandardSchemaV1.InferOutput<TParamsSchema>,
SplitRouteClaim | undefined
>;
+ toReference?: SplitRouteParamCallback<
+ StandardSchemaV1.InferOutput<TParamsSchema>,
+ SplitReference | undefined
+ >;
search?: readonly string[] | '*';
externalSearch?:
| readonly string[]
diff --git a/docs/AGENT_GUIDE/documents.md b/docs/AGENT_GUIDE/documents.md
index 065164d8dc..9e90663382 100644
--- a/docs/AGENT_GUIDE/documents.md
+++ b/docs/AGENT_GUIDE/documents.md
@@ -132,7 +132,8 @@ bottom remains available. Hidden cells are skipped by keyboard navigation.
Cells support Macro mentions without Markdown formatting. Type `@` in a cell or
the formula bar to search people, documents, channels, email and dates, then choose an
item with the pointer or keyboard. Pasting a Macro app link renders a document
-pill, preserving navigation parameters. Formulas still use the formula editor;
+pill. Legacy links retain navigation parameters. Routed links retain compatible
+block targets, but not workspace paths or pane-local search. Formulas still use
`@` inside a formula or email address does not start mention search. Other Markdown
is literal text. Mentions remain attached through copy/fill, undo and collaboration;
Excel/CSV export uses their display text. Plain URLs and email addresses are clickable;
@@ -297,6 +298,14 @@ Pasting a Macro `/app/agents/<uuid>` session URL into a Markdown editor converts
it to an agent mention, just like the legacy `/app/agent/<uuid>` URL. Link query
parameters are retained, except for referral codes.
+Pasting a routed entity link such as `/app/drive/md/<uuid>` in an app editor
+creates the same document mention as a legacy link. Routed links retain the
+entity identity and compatible block targets (for example `comment_id`), but
+not the workspace path or pane-local search state. A copied multi-pane URL
+(`/app/.../~/...`) references its rightmost pane. If that pane has no supported
+entity, the URL remains an ordinary link. Project task comment targets, Home PRs,
+and agent chat links also convert to their respective entity mentions.
+
1. `Create` → `Document D`. The app navigates to `/app/md/<uuid>` with the **title field
focused**.
2. `type_text` the title, then `submitKey: "Enter"` to drop into the body.
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index 397093549e..a555bd1131 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -33,6 +33,13 @@ outline; the text should be dark and visible. Also check the neutral swatch afte
selecting another color. Neutral colors use an OKLCH `none` hue, which must render
as gray rather than transparent.
+## Canvas link paste
+
+Pasting a supported routed Macro app link onto the canvas creates a text
+node with an entity mention, as legacy links do. Routed links retain compatible
+block targets, but not workspace paths or pane-local search state; unsupported
+links remain text.
+
## Live updates in flat Soup lists
With browser or native Tauri GraphQL caching enabled, locally supported flat lists reconcile their