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.

feat(ai): auto attach previews (#1402)

Eric Hayesf0b830203fc5
diff --git a/js/app/packages/app/component/Soup.tsx b/js/app/packages/app/component/Soup.tsx
new file mode 100644
index 0000000000..e69de29bb2
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.tsx
index c0f87be8c9..9037bae136 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
@@ -20,7 +20,9 @@ import {
import { useSoupNavigationHotkeys } from './use-soup-navigation-hotkeys';
import { useSoupViewHotkeys } from './use-soup-view-hotkeys';
import { useElementItemCount } from '@app/component/next-soup/use-element-item-count';
+import { registerPreviewEntity } from '@app/signal/splitLayout';
import { useSplitLayout } from '@app/component/split-layout/layout';
+import { fileTypeToResolvedBlockName } from '@core/constant/allBlocks';
import {
openEntityInNewTab,
openEntityInSplitFromUnifiedList,
@@ -263,6 +265,25 @@ export const SoupViewList = (props: SoupViewListProps) => {
getSplitCount,
});
+ // 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 handlers
const userId = useUserId();
const notificationSource = useGlobalNotificationSource();
diff --git a/js/app/packages/app/signal/splitLayout.ts b/js/app/packages/app/signal/splitLayout.ts
index 289fbc025d..4e9465d268 100644
--- a/js/app/packages/app/signal/splitLayout.ts
+++ b/js/app/packages/app/signal/splitLayout.ts
@@ -1,8 +1,32 @@
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/signal/tabAttachments.ts b/js/app/packages/core/component/AI/signal/tabAttachments.ts
index 646146604b..64b15d6832 100644
--- a/js/app/packages/core/component/AI/signal/tabAttachments.ts
+++ b/js/app/packages/core/component/AI/signal/tabAttachments.ts
@@ -14,7 +14,10 @@ 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 } from 'app/signal/splitLayout';
+import {
+ globalSplitManager,
+ globalPreviewEntities,
+} from 'app/signal/splitLayout';
import type { Accessor } from 'solid-js';
import { createMemo } from 'solid-js';
import type { HistoryItem } from '@queries/history/history';
@@ -101,9 +104,7 @@ export function useTabAttachments(): Accessor<ChatAttachmentWithName[]> {
// Get valid active tabs using createMemo
const tabs = createMemo(() => {
const splitManager = globalSplitManager();
- if (!splitManager) return [];
-
- const splits = splitManager.splits();
+ const splits = splitManager?.splits() ?? [];
const historyItems = historyQuery.data ?? [];
const channelList = channels();
const emailList = emails();
@@ -174,15 +175,78 @@ export function useTabAttachments(): Accessor<ChatAttachmentWithName[]> {
}
}
+ // 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) return [];
- return splitManager
- .splits()
- .filter((split) => split.content.type === 'email');
+ 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(() => ({