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: chat suspense (#1563)
Eric Hayes8decee670a6d
diff --git a/js/app/packages/app/component/Root.tsx b/js/app/packages/app/component/Root.tsxindex e7d67d8734..b8f3455f6d 100644--- a/js/app/packages/app/component/Root.tsx+++ b/js/app/packages/app/component/Root.tsx@@ -1,10 +1,9 @@import { DEFAULT_ROUTE } from '@app/constants/defaultRoute';+import { ROUTER_BASE } from '@app/constants/routerBase';import { setHotkeyRoot } from '@app/signal/hotkeyRoot';import { globalSplitManager } from '@app/signal/splitLayout';import { withAnalytics } from '@coparse/analytics';-import { ChannelsContextProvider } from '@core/context/channels';-import { UserContextProvider, useUserId } from '@core/context/user';-import { QuerySyncProvider } from '@queries/sync/SyncProvider';+import { TabAttachmentsInit } from '@core/component/AI/signal/globalAttachments';import { DeprecatedTextButton } from '@core/component/DeprecatedTextButton';import { toast } from '@core/component/Toast/Toast';import { ToastRegion } from '@core/component/Toast/ToastRegion';@@ -13,9 +12,12 @@ import {ENABLE_WEBSOCKET_DEBUGGER,PROD_MODE_ENV,} from '@core/constant/featureFlags';+import { ChannelsContextProvider } from '@core/context/channels';+import { UserContextProvider, useUserId } from '@core/context/user';import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';import { createBlockOrchestrator } from '@core/orchestrator';import { formatTabTitle, tabTitleSignal } from '@core/signal/tabTitle';+import { getLoginCookieOptions, updateCookie } from '@core/util/cookies';import { licenseChannel } from '@core/util/licenseUpdateBroadcastChannel';import { isTauri } from '@core/util/platform';import { transformShortIdInUrlPathname } from '@core/util/url';@@ -28,14 +30,15 @@ import {} from '@notifications';import { maybeHandlePlatformNotification } from '@notifications/notification-platform';import { setUser, useObserveRouting } from '@observability';-import { prefetchHistory } from '@queries/history/history';-import { ws as connectionGatewayWebsocket } from '@service-connection/websocket';import {invalidateUserInfo,prefetchUserInfo,useUserInfoQuery,} from '@queries/auth/user-info';+import { prefetchHistory } from '@queries/history/history';import { invalidateUserNotifications } from '@queries/notification/user-notifications';+import { QuerySyncProvider } from '@queries/sync/SyncProvider';+import { ws as connectionGatewayWebsocket } from '@service-connection/websocket';import { MetaProvider, Title } from '@solidjs/meta';import {HashRouter,@@ -65,7 +68,6 @@ import {systemThemeEffect,} from '../../block-theme/utils/themeUtils';import { TauriRouteListener } from '../../tauri/src/TauriProvider';-import { getLoginCookieOptions, updateCookie } from '@core/util/cookies';import { Login } from './auth/Login';import { setCookie } from './auth/Shared';import { makeEmailAuthComponents } from './EmailAuth';@@ -73,11 +75,10 @@ import { GlobalAppStateProvider } from './GlobalAppState';import { Layout } from './Layout';import MacroJump from './MacroJump';import Onboarding from './Onboarding';+import { ReactiveFavicon } from './ReactiveFavicon';import { SuspenseContextComp } from './SuspenseContext';import { LAYOUT_ROUTE } from './split-layout/SplitLayoutRoute';import Visor from './Visor';-import { ReactiveFavicon } from './ReactiveFavicon';-import { ROUTER_BASE } from '@app/constants/routerBase';const { track, identify, TrackingEvents } = withAnalytics();@@ -405,6 +406,7 @@ export function Root() {<UserInfoSideEffects /><ConfiguredGlobalAppStateProvider><ChannelsContextProvider>+ <TabAttachmentsInit /><ReactiveFavicon /><Title>{tabTitle()}</Title><MacroJump />diff --git a/js/app/packages/app/component/rightbar/Rightbar.tsx b/js/app/packages/app/component/rightbar/Rightbar.tsxindex 58a607baf9..2e8f5844f8 100644--- a/js/app/packages/app/component/rightbar/Rightbar.tsx+++ b/js/app/packages/app/component/rightbar/Rightbar.tsx@@ -55,6 +55,7 @@ import NotepadIcon from '@icon/regular/notepad.svg';import PlusIcon from '@icon/regular/plus.svg';import XIcon from '@icon/regular/x.svg';import { DropdownMenu } from '@kobalte/core/dropdown-menu';+import { useWaitChatRename } from '@macro-entity';import { invalidateUserQuota } from '@queries/auth';import { refetchHistory, useHistoryQuery } from '@queries/history/history';import { cognitionApiServiceClient } from '@service-cognition/client';@@ -80,7 +81,6 @@ import {Suspense,untrack,} from 'solid-js';-import { useWaitChatRename } from '@macro-entity';import { SplitlikeContainer } from '../split-layout/components/SplitContainer';type ChatData = {diff --git a/js/app/packages/block-chat/component/Chat.tsx b/js/app/packages/block-chat/component/Chat.tsxindex 3e1bd87d5d..514214140e 100644--- a/js/app/packages/block-chat/component/Chat.tsx+++ b/js/app/packages/block-chat/component/Chat.tsx@@ -2,6 +2,7 @@ import { useNavigatedFromJK } from '@app/component/useNavigatedFromJK';import type { SendBuilder } from '@block-chat/blockClient';import { TopBar } from '@block-chat/component/TopBar';import type { ChatData } from '@block-chat/definition';+import { pendingLocationParamsSignal } from '@block-chat/signal/pendingLocationParams';import { useBlockId } from '@core/block';import { DragDropWrapper } from '@core/component/AI/component/DragDrop';import type { ChatSendInput } from '@core/component/AI/component/input/buildRequest';@@ -23,6 +24,7 @@ import {storeChatState,} from '@core/component/AI/util/storage';import { CustomScrollbar } from '@core/component/CustomScrollbar';+import { DEV_MODE_ENV } from '@core/constant/featureFlags';import { usePaywallState } from '@core/constant/PaywallState';import { TOKENS } from '@core/hotkey/tokens';import { registerScopeSignalHotkey } from '@core/hotkey/utils';@@ -37,9 +39,7 @@ import { invalidateUserQuota } from '@queries/auth';import { createCallback } from '@solid-primitives/rootless';import { ChatInput } from 'core/component/AI/component/input/ChatInput';import type { LexicalEditor } from 'lexical';-import { DEV_MODE_ENV } from '@core/constant/featureFlags';import { createEffect, createSignal, Show } from 'solid-js';-import { pendingLocationParamsSignal } from '../signal/pendingLocationParams';export function Chat(props: { data: ChatData }) {const loadedState = getChatInputStoredState(props.data.chat.id);@@ -73,7 +73,6 @@ function ChatInner(props: {const [chatEditor, setChatEditor] = createSignal<LexicalEditor>();const [scrollRef, setScrollRef] = createSignal<HTMLElement>();const [showStreamDebug, setShowStreamDebug] = createSignal(false);-const chatMarkdownArea = useChatMarkdownArea({initialValue: props.loadedInputText,addAttachment: (a) => input.attachments.addAttachment(a),diff --git a/js/app/packages/core/component/AI/component/message/ChatMessages.tsx b/js/app/packages/core/component/AI/component/message/ChatMessages.tsxindex 982ccc3541..37fa1371b8 100644--- a/js/app/packages/core/component/AI/component/message/ChatMessages.tsx+++ b/js/app/packages/core/component/AI/component/message/ChatMessages.tsx@@ -7,20 +7,20 @@ import type {ChatMessageWithAttachments,} from '@core/component/AI/types';import { asChatMessage } from '@core/component/AI/util/message';-import { getMacroApiToken } from '@service-auth/fetch';-import { cognitionWebsocketServiceClient } from '@service-cognition/client';import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';import { aiChatTheme } from '@core/component/LexicalMarkdown/theme';+import { getMacroApiToken } from '@service-auth/fetch';+import { cognitionWebsocketServiceClient } from '@service-cognition/client';import { createElementSize } from '@solid-primitives/resize-observer';import type { Accessor, JSXElement, Setter } from 'solid-js';import {- on,createEffect,createMemo,createSelector,createSignal,For,Match,+ on,onMount,Show,Switch,diff --git a/js/app/packages/core/component/AI/context/ChatContext.tsx b/js/app/packages/core/component/AI/context/ChatContext.tsxindex cbae19fcf2..32a414779e 100644--- a/js/app/packages/core/component/AI/context/ChatContext.tsx+++ b/js/app/packages/core/component/AI/context/ChatContext.tsx@@ -1,6 +1,6 @@import { DEFAULT_MODEL } from '@core/component/AI/constant';import { useAttachments } from '@core/component/AI/signal/attachment';-import { useTabAttachments } from '@core/component/AI/signal/tabAttachments';+import { globalTabAttachments } from '@core/component/AI/signal/globalAttachments';import type {Attachment,Attachments,@@ -53,10 +53,9 @@ export function ChatInputProvider(const attachments = useAttachments(props.initialAttachments);const uploadQueue = useUploadAttachment();- const tabAttachments = useTabAttachments();if (ENABLE_AI_AUTO_TAB_ATTACHMENTS && props.autoAttach !== false) {createEffect(- on(tabAttachments, (tabs, p) => {+ on(globalTabAttachments, (tabs, p) => {for (const prev of p ?? []) {if (!tabs.find((t) => t.attachmentId === prev.attachmentId)) {attachments.removeAttachment(prev.attachmentId);diff --git a/js/app/packages/core/component/AI/signal/attachment.ts b/js/app/packages/core/component/AI/signal/attachment.tsindex 2a3b4573a6..ee4c1634c1 100644--- a/js/app/packages/core/component/AI/signal/attachment.ts+++ b/js/app/packages/core/component/AI/signal/attachment.ts@@ -1,15 +1,11 @@-import {- SUPPORTED_ATTACHMENT_EXTENSIONS,- SUPPORTED_CHAT_ATTACHMENT_BLOCKS,-} from '@core/component/AI/constant';+import { SUPPORTED_ATTACHMENT_EXTENSIONS } from '@core/component/AI/constant';+import { globalAttachableHistory } from '@core/component/AI/signal/globalAttachments';import type { Attachment, Attachments } from '@core/component/AI/types';import { asFileType } from '@core/component/AI/util';import type { ItemMention } from '@core/component/LexicalMarkdown/plugins/mentions';import { ENABLE_CHAT_CHANNEL_ATTACHMENT } from '@core/constant/featureFlags';import { useChannelsContext } from '@core/context/channels';-import { getItemBlockName } from '@core/util/getItemBlockName';-import { useHistoryQuery } from '@queries/history/history';-import { createMemo, createSignal } from 'solid-js';+import { createSignal } from 'solid-js';export function useAttachments(initial?: Attachment[]): Attachments {const [attachments, setAttachments] = createSignal<Attachment[]>(@@ -42,14 +38,7 @@ export function useAttachments(initial?: Attachment[]): Attachments {}export const useChatAttachableHistory = () => {- const historyQuery = useHistoryQuery();-- return createMemo(() => {- return (historyQuery.data ?? []).filter((item) => {- const blockName = getItemBlockName(item, true);- return SUPPORTED_CHAT_ATTACHMENT_BLOCKS.includes(blockName);- });- });+ return globalAttachableHistory;};export const useGetChatAttachmentInfo = () => {diff --git a/js/app/packages/core/component/AI/signal/globalAttachments.tsx b/js/app/packages/core/component/AI/signal/globalAttachments.tsxnew file mode 100644index 0000000000..bf62a3a208--- /dev/null+++ b/js/app/packages/core/component/AI/signal/globalAttachments.tsx@@ -0,0 +1,67 @@+import { SUPPORTED_CHAT_ATTACHMENT_BLOCKS } from '@core/component/AI/constant/fileType';+import type { Attachment } from '@core/component/AI/types';+import { getItemBlockName } from '@core/util/getItemBlockName';+import type { HistoryItem } from '@queries/history/history';+import { useHistoryQuery } from '@queries/history/history';+import {+ createEffect,+ createMemo,+ createSignal,+ onMount,+ Suspense,+} from 'solid-js';+import { useTabAttachments } from './tabAttachments';++// ---- Global signals ----++const [globalTabAttachments, setGlobalTabAttachments] = createSignal<+ Attachment[]+>([]);++const [globalAttachableHistory, setGlobalAttachableHistory] = createSignal<+ HistoryItem[]+>([]);++const [globalAttachmentsReady, setGlobalAttachmentsReady] = createSignal(false);++export {+ globalTabAttachments,+ globalAttachableHistory,+ globalAttachmentsReady,+};++// ---- Init component (mount once at app root) ----++function GlobalAttachmentsInner() {+ const tabAttachments = useTabAttachments();+ const historyQuery = useHistoryQuery();++ const attachableHistory = createMemo(() => {+ return (historyQuery.data ?? []).filter((item) => {+ const blockName = getItemBlockName(item, true);+ return SUPPORTED_CHAT_ATTACHMENT_BLOCKS.includes(blockName);+ });+ });++ createEffect(() => {+ setGlobalTabAttachments(tabAttachments());+ });++ createEffect(() => {+ setGlobalAttachableHistory(attachableHistory());+ });++ onMount(() => {+ setGlobalAttachmentsReady(true);+ });++ return null;+}++export function TabAttachmentsInit() {+ return (+ <Suspense>+ <GlobalAttachmentsInner />+ </Suspense>+ );+}diff --git a/js/app/packages/core/component/AI/signal/tabAttachments.ts b/js/app/packages/core/component/AI/signal/tabAttachments.tsindex d328edd098..c42769c06a 100644--- a/js/app/packages/core/component/AI/signal/tabAttachments.ts+++ b/js/app/packages/core/component/AI/signal/tabAttachments.ts@@ -4,6 +4,8 @@ import { useChannelsContext } from '@core/context/channels';import type { ChannelWithParticipants } from '@core/user';import { isOk } from '@core/util/maybeResult';import type { EmailEntity } from '@entity';+import type { HistoryItem } from '@queries/history/history';+import { useHistoryQuery } from '@queries/history/history';import type {AttachmentType,ChannelType,@@ -11,16 +13,14 @@ import type {FileType,} from '@service-cognition/generated/schemas';import { emailClient } from '@service-email/client';-import { useHistoryQuery } from '@queries/history/history';import { useQuery } from '@tanstack/solid-query';import type { SplitContent } from 'app/component/split-layout/layoutManager';import {- globalSplitManager,globalPreviewEntities,+ globalSplitManager,} from 'app/signal/splitLayout';import type { Accessor } from 'solid-js';import { createMemo } from 'solid-js';-import type { HistoryItem } from '@queries/history/history';type Item = HistoryItem | null;@@ -34,7 +34,7 @@ function convertSplitToAttachment(let attachmentType: AttachmentType;switch (split.type) {- case 'image':+ case 'image': {if (!item || item.type !== 'document') return null;const imageName = item.name || 'Image';const imageExtension = (item.fileType || 'png') as FileType;@@ -46,7 +46,8 @@ function convertSplitToAttachment(};attachmentType = 'document';break;- case 'channel':+ }+ case 'channel': {if (!channel) return null;const channelName = channel.name || 'Channel';const channelType: ChannelType = channel.channel_type || 'public';@@ -57,7 +58,8 @@ function convertSplitToAttachment(};attachmentType = 'channel';break;- case 'email':+ }+ case 'email': {if (!email) return null;const emailSubject = email.name || 'No Subject';metadata = {@@ -66,6 +68,7 @@ function convertSplitToAttachment(};attachmentType = 'email';break;+ }case 'project':if (!item || item.type !== 'project') return null;metadata = {@@ -74,7 +77,7 @@ function convertSplitToAttachment(};attachmentType = 'project';break;- default:+ default: {if (!item || item.type !== 'document') return null;const documentName = item.name || 'Document';const documentType = (item.fileType || 'txt') as FileType;@@ -85,6 +88,7 @@ function convertSplitToAttachment(};attachmentType = 'document';break;+ }}return {diff --git a/js/app/packages/core/component/AI/util/uploadToChat.ts b/js/app/packages/core/component/AI/util/uploadToChat.tsindex 2b271e513c..df41c51641 100644--- a/js/app/packages/core/component/AI/util/uploadToChat.ts+++ b/js/app/packages/core/component/AI/util/uploadToChat.ts@@ -180,7 +180,7 @@ export function useUploadAttachment(): UploadQueue {// Show error toast if the result indicates an errorif (result.type === 'error') {- let filename = getUploadFilename(result);+ const filename = getUploadFilename(result);const errorMessage =result.error === 'upload'@@ -198,7 +198,7 @@ export function useUploadAttachment(): UploadQueue {// Remove from uploading on errorsetUploading((prev) => prev.filter((u) => u !== item));- let filename = getUploadFilename(item);+ const filename = getUploadFilename(item);// Show error toasttoast.failure(