Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(command+k): update go to search snippet location (#63)
Seamuse088bbd2deaa
diff --git a/js/app/packages/app/component/command/KonsoleItem.tsx b/js/app/packages/app/component/command/KonsoleItem.tsxindex 9a52302857..0bdab14e73 100644--- a/js/app/packages/app/component/command/KonsoleItem.tsx+++ b/js/app/packages/app/component/command/KonsoleItem.tsx@@ -1,4 +1,6 @@-import { URL_PARAMS } from '@block-pdf/signal/location';+import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';+import { URL_PARAMS as MD_PARAMS } from '@block-md/constants';+import { URL_PARAMS as PDF_PARAMS } from '@block-pdf/signal/location';import type { BlockName } from '@core/block';import { BozzyBracket } from '@core/component/BozzyBracket';import type { ChannelsContext } from '@core/component/ChannelsProvider';@@ -15,6 +17,7 @@ import {import { runCommand } from '@core/hotkey/hotkeys';import { pressedKeys } from '@core/hotkey/state';import type { ValidHotkey } from '@core/hotkey/types';+import type { BlockOrchestrator } from '@core/orchestrator';import { type ChannelWithParticipants, idToDisplayName } from '@core/user';import PushPin from '@phosphor-icons/core/regular/push-pin.svg?component-solid';import Terminal from '@phosphor-icons/core/regular/terminal.svg?component-solid';@@ -38,10 +41,11 @@ import {type Setter,Switch,} from 'solid-js';+import { useGlobalBlockOrchestrator } from '../GlobalAppState';import { useSplitLayout } from '../split-layout/layout';import { EmailCommandItem } from './EmailKonsoleItem';import {- rawQuery,+ cleanQuery,resetKonsoleMode,resetQuery,setKonsoleOpen,@@ -206,35 +210,39 @@ export type CommandItemCard = () &CommandItemBase;-/**- * Builds a URL with search snippet parameters for navigating to specific locations within documents- * @param baseHref - The base URL for the document/item- * @param snippet - Search snippet containing location and file type information- * @param searchTerm - The search term used to find the snippet- * @returns URL with appropriate query parameters for the file type- */-function buildSnippetUrl(- baseHref: string,+async function gotoSnippetLocation(+ orchestrator: BlockOrchestrator,+ id: string,snippet: SearchSnippet,searchTerm: string-): string {- const params = new URLSearchParams();- const fileType = snippet.fileType;- const matchIndex = snippet.matchIndex ? snippet.matchIndex.toString() : '0';-- if (fileType === 'docx' || fileType === 'pdf') {- params.set(URL_PARAMS.searchPage, snippet.locationId);- params.set(URL_PARAMS.searchMatchNumOnPage, matchIndex);- // HACK: searchTerm() works well enough for exact matching, but it would be better- // to have the match term explicitly stored for fuzzy matching- params.set(URL_PARAMS.searchTerm, searchTerm);- } else if (fileType === 'chat' || fileType === 'channel') {- params.set('message_id', snippet.locationId);- } else if (fileType === 'md') {- params.set('node_id', snippet.locationId);+) {+ const handle = await orchestrator.getBlockHandle(id);+ if (!handle) return;+ switch (snippet.fileType) {+ case 'pdf':+ case 'docx':+ handle.goToLocationFromParams({+ [PDF_PARAMS.searchPage]: snippet.locationId,+ [PDF_PARAMS.searchMatchNumOnPage]: (snippet.matchIndex ?? 0).toString(),+ [PDF_PARAMS.searchTerm]: searchTerm,+ });+ break;+ case 'chat':+ handle.goToLocationFromParams({+ message_id: snippet.locationId,+ });+ break;+ case 'channel':+ handle.goToLocationFromParams({+ [CHANNEL_PARAMS.message]: snippet.locationId,+ });+ break;+ case 'md':+ handle.goToLocationFromParams({+ [MD_PARAMS.nodeId]: snippet.locationId,+ });+ break;}-- return baseHref + '?' + params.toString();}// Actions on an item from the command palette@@ -245,20 +253,24 @@ export function useCommandItemAction(args: {}) {const { setCommandScopeCommands } = args;const { replaceSplit, insertSplit } = useSplitLayout();+ const blockOrchestrator = useGlobalBlockOrchestrator();return function itemAction(item: CommandItemCard | undefined,action: ItemAction) {+ console.log('ITEM ACTION', item, action);if (!item) return;const blockName = getCommandItemBlockName(item);- const id = item.snippet- ? buildSnippetUrl(item.data.id, item.snippet, rawQuery())- : item.data.id;+ const id = item.data.id;const split = action === 'new-split' ? insertSplit : replaceSplit;+ console.log('GO TO LOCATION', id);if (blockName) {split({ type: blockName, id });+ if (item.snippet) {+ gotoSnippetLocation(blockOrchestrator, id, item.snippet, cleanQuery());+ }} else {switch (item.type) {case 'loadmore': {diff --git a/js/app/packages/block-chat/blockClient.ts b/js/app/packages/block-chat/blockClient.tsindex 81d163e15e..68305bd263 100644--- a/js/app/packages/block-chat/blockClient.ts+++ b/js/app/packages/block-chat/blockClient.ts@@ -9,4 +9,5 @@ export type SendBuilder = Parameters<export type BlockChatSpec = {setQuote: (quote: string) => Promise<void>;sendMessage: (request: SendBuilder) => Promise<void>;+ goToLocationFromParams: (params: Record<string, any>) => Promise<void>;};diff --git a/js/app/packages/block-chat/component/Chat.tsx b/js/app/packages/block-chat/component/Chat.tsxindex 0cbf8fa7f0..24385476b2 100644--- a/js/app/packages/block-chat/component/Chat.tsx+++ b/js/app/packages/block-chat/component/Chat.tsx@@ -24,6 +24,7 @@ import { invalidateUserQuota } from '@service-auth/userQuota';import { cognitionWebsocketServiceClient } from '@service-cognition/client';import { createCallback } from '@solid-primitives/rootless';import { createEffect, createSignal, Show } from 'solid-js';+import { pendingLocationParamsSignal } from '../signal/pendingLocationParams';export function Chat(props: { data: ChatData }) {const canEdit = useCanEdit();@@ -47,6 +48,7 @@ export function Chat(props: { data: ChatData }) {messages: props.data.chat.messages,chatId: props.data.chat.id,editDisabled: disabled,+ pendingLocationParams: pendingLocationParamsSignal.get,});const blockHandle = blockHandleSignal.get;@@ -121,12 +123,17 @@ export function Chat(props: { data: ChatData }) {saveChatState({ attachments: attached, input, model: model_ });});+ const setPendingLocation = pendingLocationParamsSignal.set;const buildChatSendRequest = useBuildChatSendRequest();+createMethodRegistration(blockHandle, {sendMessage: async (sendRequest: SendBuilder) => {const send = await buildChatSendRequest(sendRequest);onSend(send);},+ goToLocationFromParams: (params: Record<string, string>) => {+ setPendingLocation(params);+ },});return (diff --git a/js/app/packages/block-chat/signal/pendingLocationParams.ts b/js/app/packages/block-chat/signal/pendingLocationParams.tsnew file mode 100644index 0000000000..23bbf1318d--- /dev/null+++ b/js/app/packages/block-chat/signal/pendingLocationParams.ts@@ -0,0 +1,5 @@+import { createBlockSignal } from '@core/block';++export const pendingLocationParamsSignal = createBlockSignal<+ Record<string, string> | undefined+>();diff --git a/js/app/packages/block-pdf/component/Block.tsx b/js/app/packages/block-pdf/component/Block.tsxindex e04194d541..7884844d69 100644--- a/js/app/packages/block-pdf/component/Block.tsx+++ b/js/app/packages/block-pdf/component/Block.tsx@@ -170,6 +170,7 @@ export default function BlockPdf() {const goToLocationFromParams = createCallback((params: Record<string, any>) => {+ console.log('GO TO LOCATION FROM PARAMS', params);const setPendingLocationParamsSignal = pendingLocationParamsSignal.set;const setLocationChanged = locationChangedSignal.set;diff --git a/js/app/packages/block-pdf/signal/location.ts b/js/app/packages/block-pdf/signal/location.tsindex dadd48912e..035865eaf9 100644--- a/js/app/packages/block-pdf/signal/location.ts+++ b/js/app/packages/block-pdf/signal/location.ts@@ -576,7 +576,9 @@ export async function goToLinkLocation(params: LocationSearchParams) {export async function goToLinkLocationFromParams(params: Record<string, string>) {+ console.log(' go to link location, ', params);const location = parseLocationFromBlockParams(params);+ console.log({ location });if (location) {return await goToPdfLocation(location);}diff --git a/js/app/packages/core/component/AI/component/message/ChatMessages.tsx b/js/app/packages/core/component/AI/component/message/ChatMessages.tsxindex ab4e4292d3..04728304af 100644--- a/js/app/packages/core/component/AI/component/message/ChatMessages.tsx+++ b/js/app/packages/core/component/AI/component/message/ChatMessages.tsx@@ -11,6 +11,7 @@ import type { Accessor, JSXElement, Setter } from 'solid-js';import {createEffect,createMemo,+ createSelector,createSignal,For,Match,@@ -51,6 +52,7 @@ export function useChatMessages(args: {actions?: MessageActions;chatId?: string;editDisabled?: Accessor<boolean>;+ pendingLocationParams?: Accessor<Record<string, string> | undefined>;}): ChatMessages {const [messages, setMessages] = createSignal(args.messages);const [stream, setStream] = createSignal<MessageStream>();@@ -66,6 +68,7 @@ export function useChatMessages(args: {messageActions={args.actions}stream={[stream, setStream]}editDisabled={editDisabled()}+ pendingLocationParams={args.pendingLocationParams}/>));@@ -95,6 +98,7 @@ export type ChatMessagesProps = {chatId?: string;messageActions?: MessageActions;editDisabled?: boolean;+ pendingLocationParams?: Accessor<Record<string, string> | undefined>;};function messageContentIsEmpty(message: ChatMessageWithAttachments) {@@ -235,6 +239,40 @@ export function ChatMessages(props: ChatMessagesProps) {scrollToBottom('instant');});+ // the highlight message id when arriving from search+ const [activeTargetMessageId, setActiveTargetMessageId] = createSignal<+ string | undefined+ >(undefined);++ createEffect(() => {+ const params = props.pendingLocationParams?.();+ if (!params) return;++ if (params.message_id) {+ setActiveTargetMessageId(params.message_id);+ setTimeout(() => {+ const messageElement = document.getElementById(+ `chat-${params.message_id}`+ );+ if (messageElement) {+ const scrollContainer = messageElement.closest(+ '[data-chat-scroll]'+ ) as HTMLElement;+ if (scrollContainer) {+ messageElement.scrollIntoView({+ behavior: 'smooth',+ block: 'center',+ });+ }+ }+ }, 0);++ setTimeout(() => {+ setActiveTargetMessageId(undefined);+ }, 1500);+ }+ });+const lastPair = () => {const msgs = messages();if (generatingMessage() || isStream()) {@@ -257,12 +295,20 @@ export function ChatMessages(props: ChatMessagesProps) {}};+ const activeIdSelector = createSelector(activeTargetMessageId);+return (<StaticMarkdownContext theme={aiChatTheme}><div class="flex flex-col w-full px-2 gap-y-2" ref={messagesRef}><For each={allButLastMessagePair()}>{(msg) => (- <div id={'chat-' + msg.id} class="w-full">+ <div+ id={'chat-' + msg.id}+ class="w-full transition-colors duration-300"+ classList={{+ 'bg-accent': activeIdSelector(msg.id),+ }}+ ><Switch><Match when={msg.role === 'user'}><UserMessage message={msg} />@@ -289,7 +335,13 @@ export function ChatMessages(props: ChatMessagesProps) {{(pair) => (<For each={pair()}>{(msg) => (- <div id={'chat-' + msg.id} class="w-full">+ <div+ id={'chat-' + msg.id}+ class="w-full transition-colors duration-300"+ classList={{+ 'bg-accent': activeIdSelector(msg.id),+ }}+ ><Switch><Match when={msg.role === 'user'}><UserMessage