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
ai: remove auto attachments (#2347)
Eric Hayes1bb71b0075e9
diff --git a/js/app/packages/app/component/Root.tsx b/js/app/packages/app/component/Root.tsxindex cb69881dcf..1daef4b66f 100644--- a/js/app/packages/app/component/Root.tsx+++ b/js/app/packages/app/component/Root.tsx@@ -2,7 +2,7 @@ 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 { TabAttachmentsInit } from '@core/component/AI/signal/globalAttachments';+import { ChatAttachmentsInit } 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';@@ -431,7 +431,7 @@ export function Root() {<ChannelsContextProvider><QuickAccessProvider><SearchProvider>- <TabAttachmentsInit />+ <ChatAttachmentsInit /><ReactiveFavicon /><Title>{tabTitle()}</Title><MacroJump />diff --git a/js/app/packages/app/component/SoupChatInput.tsx b/js/app/packages/app/component/SoupChatInput.tsxindex cc599affd8..b84c0e240c 100644--- a/js/app/packages/app/component/SoupChatInput.tsx+++ b/js/app/packages/app/component/SoupChatInput.tsx@@ -170,7 +170,7 @@ function SoupChatInputInner() {export function SoupChatInput() {return (- <ChatInputProvider autoAttach={false}>+ <ChatInputProvider><SoupChatInputInner /></ChatInputProvider>);diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsxindex 58d20c2159..41e07b2dc8 100644--- a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx@@ -18,9 +18,7 @@ import {} from '@app/component/next-soup/soup-view/soup-view-context';import { useSoupNavigationHotkeys } from './use-soup-navigation-hotkeys';import { useSoupViewHotkeys } from './use-soup-view-hotkeys';-import { registerPreviewEntity } from '@app/signal/splitLayout';import { useSplitLayout } from '@app/component/split-layout/layout';-import { fileTypeToResolvedBlockName } from '@core/constant/allBlocks';import {openEntityInNewTab,openEntityInSplitFromUnifiedList,@@ -482,25 +480,6 @@ export const SoupViewList = (props: SoupViewListProps) => {applyTabPreset,});- // Register previewed entity for auto-attach- createEffect(() => {- const entity = soup.previewEntity() ? soup.focus.item() : undefined;- if (!entity) {- registerPreviewEntity(panel.handle.id, undefined);- return;- }- const type =- entity.type === 'document'- ? fileTypeToResolvedBlockName(- (entity as { fileType?: string }).fileType- )- : entity.type;- registerPreviewEntity(panel.handle.id, { type, id: entity.id });- });- onCleanup(() => {- registerPreviewEntity(panel.handle.id, undefined);- });-// Create markDone action for swipe/click handlersconst userId = useUserId();const notificationSource = useGlobalNotificationSource();diff --git a/js/app/packages/app/signal/splitLayout.ts b/js/app/packages/app/signal/splitLayout.tsindex 4e9465d268..289fbc025d 100644--- a/js/app/packages/app/signal/splitLayout.ts+++ b/js/app/packages/app/signal/splitLayout.ts@@ -1,32 +1,8 @@import { createSignal } from 'solid-js';import type { SplitManager } from '../component/split-layout/layoutManager';-import type { SplitContent } from '../component/split-layout/layoutManager';/*** Primary global split manager for the app.*/export const [globalSplitManager, setGlobalSplitManager] =createSignal<SplitManager>();--/**- * Tracks entities currently shown in preview panels across all Soup instances.- * Keyed by the split ID of the Soup that owns the preview.- */-export const [globalPreviewEntities, setGlobalPreviewEntities] = createSignal<- Map<string, SplitContent>->(new Map());--export function registerPreviewEntity(- splitId: string,- content: SplitContent | undefined-) {- setGlobalPreviewEntities((prev) => {- const next = new Map(prev);- if (content) {- next.set(splitId, content);- } else {- next.delete(splitId);- }- return next;- });-}diff --git a/js/app/packages/core/component/AI/context/ChatContext.tsx b/js/app/packages/core/component/AI/context/ChatContext.tsxindex c8c3b6577d..194b592965 100644--- a/js/app/packages/core/component/AI/context/ChatContext.tsx+++ b/js/app/packages/core/component/AI/context/ChatContext.tsx@@ -1,6 +1,5 @@import { DEFAULT_MODEL } from '@core/component/AI/constant';import { useAttachments } from '@core/component/AI/signal/attachment';-import { globalTabAttachments } from '@core/component/AI/signal/globalAttachments';import type {Attachment,Attachments,@@ -9,20 +8,13 @@ import type {UploadQueue,} from '@core/component/AI/types';import { useUploadAttachment } from '@core/component/AI/util/uploadToChat';-import { ENABLE_AI_AUTO_TAB_ATTACHMENTS } from '@core/constant/featureFlags';import {createChatController,type ChatController,type ChatControllerOptions,} from '@core/component/AI/state/createChatController';import type { Accessor, ParentProps } from 'solid-js';-import {- createContext,- createEffect,- createSignal,- on,- useContext,-} from 'solid-js';+import { createContext, createSignal, useContext } from 'solid-js';// ---- Uncreated state (always present) ----@@ -42,7 +34,6 @@ export function ChatInputProvider(model?: Model;isGenerating?: boolean;initialAttachments?: Attachment[];- autoAttach?: boolean;}) {const [model, _setModel] = createSignal<Model>(props.model ?? DEFAULT_MODEL);@@ -55,21 +46,6 @@ export function ChatInputProvider(const attachments = useAttachments(props.initialAttachments);const uploadQueue = useUploadAttachment();- if (ENABLE_AI_AUTO_TAB_ATTACHMENTS && props.autoAttach !== false) {- createEffect(- on(globalTabAttachments, (tabs, p) => {- for (const prev of p ?? []) {- if (!tabs.find((t) => t.attachmentId === prev.attachmentId)) {- attachments.removeAttachment(prev.attachmentId);- }- }- for (const tab of tabs) {- attachments.addAttachment(tab);- }- })- );- }-return (<ChatInputCtx.Providervalue={{diff --git a/js/app/packages/core/component/AI/signal/globalAttachments.tsx b/js/app/packages/core/component/AI/signal/globalAttachments.tsxindex bf62a3a208..a760d48826 100644--- a/js/app/packages/core/component/AI/signal/globalAttachments.tsx+++ b/js/app/packages/core/component/AI/signal/globalAttachments.tsx@@ -1,39 +1,20 @@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';+import { createEffect, createMemo, createSignal, Suspense } from 'solid-js';// ---- Global signals -----const [globalTabAttachments, setGlobalTabAttachments] = createSignal<- Attachment[]->([]);-const [globalAttachableHistory, setGlobalAttachableHistory] = createSignal<HistoryItem[]>([]);-const [globalAttachmentsReady, setGlobalAttachmentsReady] = createSignal(false);--export {- globalTabAttachments,- globalAttachableHistory,- globalAttachmentsReady,-};+export { globalAttachableHistory };// ---- Init component (mount once at app root) ----function GlobalAttachmentsInner() {- const tabAttachments = useTabAttachments();const historyQuery = useHistoryQuery();const attachableHistory = createMemo(() => {@@ -43,22 +24,14 @@ function GlobalAttachmentsInner() {});});- createEffect(() => {- setGlobalTabAttachments(tabAttachments());- });-createEffect(() => {setGlobalAttachableHistory(attachableHistory());});- onMount(() => {- setGlobalAttachmentsReady(true);- });-return null;}-export function TabAttachmentsInit() {+export function ChatAttachmentsInit() {return (<Suspense><GlobalAttachmentsInner />diff --git a/js/app/packages/core/component/AI/signal/tabAttachments.ts b/js/app/packages/core/component/AI/signal/tabAttachments.tsdeleted file mode 100644index c42769c06a..0000000000--- a/js/app/packages/core/component/AI/signal/tabAttachments.ts+++ /dev/null@@ -1,335 +0,0 @@-import { SUPPORTED_CHAT_ATTACHMENT_BLOCKS } from '@core/component/AI/constant/fileType';-import type { Attachment } from '@core/component/AI/types';-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,- ChatAttachmentWithName,- FileType,-} from '@service-cognition/generated/schemas';-import { emailClient } from '@service-email/client';-import { useQuery } from '@tanstack/solid-query';-import type { SplitContent } from 'app/component/split-layout/layoutManager';-import {- globalPreviewEntities,- globalSplitManager,-} from 'app/signal/splitLayout';-import type { Accessor } from 'solid-js';-import { createMemo } from 'solid-js';--type Item = HistoryItem | null;--function convertSplitToAttachment(- split: SplitContent,- item: Item,- channel: ChannelWithParticipants | null = null,- email: EmailEntity | null = null-): Attachment | null {- let metadata: Attachment['metadata'];- let attachmentType: AttachmentType;-- switch (split.type) {- case 'image': {- if (!item || item.type !== 'document') return null;- const imageName = item.name || 'Image';- const imageExtension = (item.fileType || 'png') as FileType;- // this is correct- metadata = {- type: 'document',- document_name: imageName,- document_type: imageExtension,- };- attachmentType = 'document';- break;- }- case 'channel': {- if (!channel) return null;- const channelName = channel.name || 'Channel';- const channelType: ChannelType = channel.channel_type || 'public';- metadata = {- type: 'channel',- channel_name: channelName,- channel_type: channelType,- };- attachmentType = 'channel';- break;- }- case 'email': {- if (!email) return null;- const emailSubject = email.name || 'No Subject';- metadata = {- type: 'email',- email_subject: emailSubject,- };- attachmentType = 'email';- break;- }- case 'project':- if (!item || item.type !== 'project') return null;- metadata = {- type: 'project',- project_name: item.name,- };- attachmentType = 'project';- break;- default: {- if (!item || item.type !== 'document') return null;- const documentName = item.name || 'Document';- const documentType = (item.fileType || 'txt') as FileType;- metadata = {- type: 'document',- document_name: documentName,- document_type: documentType,- };- attachmentType = 'document';- break;- }- }-- return {- id: `split-${split.id}-${Date.now()}`,- attachmentId: split.id,- attachmentType,- metadata,- };-}--export function useTabAttachments(): Accessor<ChatAttachmentWithName[]> {- const historyQuery = useHistoryQuery();- const channelsContext = useChannelsContext();- const channels = channelsContext.channels;- // TODO: hook into email query because useEmails was deprecated- const emails: Accessor<EmailEntity[]> = () => [];-- // Get valid active tabs using createMemo- const tabs = createMemo(() => {- const splitManager = globalSplitManager();- const splits = splitManager?.splits() ?? [];- const historyItems = historyQuery.data ?? [];- const channelList = channels();- const emailList = emails();-- // Deduplicate by type:id key and resolve names from history/channels/emails- const uniqueSplits = new Map<- string,- {- split: SplitContent;- item: Item;- channel: ChannelWithParticipants | null;- email: EmailEntity | null;- }- >();-- for (const split of splits) {- // TODO: need smarter type checking/inference- if (- split.content.type === 'component' ||- !SUPPORTED_CHAT_ATTACHMENT_BLOCKS.includes(split.content.type)- ) {- continue;- }-- const key = `${split.content.type}:${split.content.id}`;- // For email splits, find in email list- if (split.content.type === 'email') {- const emailItem = emailList.find(- (email) => email.id === split.content.id- );- if (!emailItem) {- continue;- }-- uniqueSplits.set(key, {- split: split.content,- item: null,- channel: null,- email: emailItem,- });- continue;- }-- const channelItem =- split.content.type === 'channel'- ? channelList.find((channel) => channel.id === split.content.id) ||- null- : null;- if (split.content.type === 'channel') {- uniqueSplits.set(key, {- split: split.content,- item: null,- channel: channelItem,- email: null,- });- continue;- }-- const historyItem =- historyItems.find((item) => item.id === split.content.id) || null;- if (historyItem) {- uniqueSplits.set(key, {- split: split.content,- item: historyItem,- channel: channelItem,- email: null,- });- }- }-- // Include entities from preview panels- for (const [, previewContent] of globalPreviewEntities()) {- if (- previewContent.type === 'component' ||- !SUPPORTED_CHAT_ATTACHMENT_BLOCKS.includes(previewContent.type)- ) {- continue;- }-- const key = `${previewContent.type}:${previewContent.id}`;- if (uniqueSplits.has(key)) continue;-- if (previewContent.type === 'email') {- const emailItem = emailList.find(- (email) => email.id === previewContent.id- );- if (emailItem) {- uniqueSplits.set(key, {- split: previewContent,- item: null,- channel: null,- email: emailItem,- });- }- continue;- }-- if (previewContent.type === 'channel') {- const channelItem =- channelList.find((channel) => channel.id === previewContent.id) ||- null;- uniqueSplits.set(key, {- split: previewContent,- item: null,- channel: channelItem,- email: null,- });- continue;- }-- const historyItem =- historyItems.find((item) => item.id === previewContent.id) || null;- if (historyItem) {- uniqueSplits.set(key, {- split: previewContent,- item: historyItem,- channel: null,- email: null,- });- }- }-- return Array.from(uniqueSplits.values());- });-- const emailTabs = createMemo(() => {- const result: { content: SplitContent }[] = [];- const splitManager = globalSplitManager();- if (splitManager) {- result.push(- ...splitManager- .splits()- .filter((split) => split.content.type === 'email')- );- }- // Include previewed emails- for (const [, previewContent] of globalPreviewEntities()) {- if (previewContent.type === 'email') {- result.push({ content: previewContent });- }- }- return result;- });-- const emailQuery = useQuery(() => ({- queryKey: [- 'tab-attachments',- 'emails',- emailTabs().map((t) => t.content.id),- ],- queryFn: async () => {- const eTabs = emailTabs();- const threads = await Promise.allSettled(- eTabs.map((email) =>- emailClient- .getThread({- thread_id: email.content.id,- limit: 1,- })- .then((r) => ({ id: email.content.id, result: r }))- )- ).then((threads) =>- threads.flatMap((r) => {- if (r.status === 'rejected') return [];- return isOk(r.value.result)- ? [- {- id: r.value.id,- thread: r.value.result[1],- },- ]- : [];- })- );-- const attachments: ChatAttachmentWithName[] = threads.flatMap(- (thread) => {- // :(- const subject = thread.thread.thread.messages[0]?.subject;- if (!subject) return [];- return [- {- attachmentType: 'email',- attachmentId: thread.id,- id: thread.id,- metadata: {- email_subject: subject,- type: 'email',- },- },- ];- }- );- return attachments;- },- enabled: emailTabs().length > 0,- }));-- const tabAttachments = createMemo(() => {- const openTabs = tabs();- const attachments: Attachment[] = [];- for (const tabData of openTabs) {- const { split, item, channel, email } = tabData;- const attachment = convertSplitToAttachment(split, item, channel, email);- if (attachment) {- attachments.push(attachment);- }- }- return attachments;- });-- const combinedAttachments = createMemo(() => {- const tabs = tabAttachments();- const existingAttachments = new Set(tabs.map((a) => a.attachmentId));- const queriedEmails = emailQuery.isSuccess ? (emailQuery.data ?? []) : [];- const newEmails = queriedEmails.filter(- (e) => !existingAttachments.has(e.attachmentId)- );- return [...newEmails, ...tabs];- });-- return combinedAttachments;-}diff --git a/js/app/packages/core/constant/featureFlags.ts b/js/app/packages/core/constant/featureFlags.tsindex b2152d00de..b5461445a6 100644--- a/js/app/packages/core/constant/featureFlags.ts+++ b/js/app/packages/core/constant/featureFlags.ts@@ -270,11 +270,6 @@ export const ENABLE_EMAIL_SCHEDULED_SEND = resolveFeatureFlag(true);-export const ENABLE_AI_AUTO_TAB_ATTACHMENTS = resolveFeatureFlag(- 'ENABLE_AI_AUTO_TAB_ATTACHMENTS',- true-);-export const ENABLE_FEATURED_SEARCH_RESULTS = resolveFeatureFlag('ENABLE_FEATURED_SEARCH_RESULTS',true