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): send to bg (#1798)

Eric Hayes78d5f8407ad3
diff --git a/js/app/packages/app/component/SoupChatInput.tsx b/js/app/packages/app/component/SoupChatInput.tsx
index 1a7e179c26..60a44eeebd 100644
--- a/js/app/packages/app/component/SoupChatInput.tsx
+++ b/js/app/packages/app/component/SoupChatInput.tsx
@@ -8,10 +8,14 @@ import {
} from '@core/component/AI/context';
import { useGetChatAttachmentInfo } from '@core/component/AI/signal/attachment';
import { setPendingSendData } from '@core/component/AI/signal/pendingSend';
+import { Hotkey } from '@core/component/Hotkey';
+import { Tooltip } from '@core/component/Tooltip';
import { ENABLE_SNAPSHOT_NODE } from '@core/constant/featureFlags';
+import { pressedKeys } from '@core/hotkey/state';
import { TOKENS } from '@core/hotkey/tokens';
import { isErr } from '@core/util/maybeResult';
import { markdownToPlainText } from '@lexical-core/utils/parsers';
+import { invalidateAllSoup } from '@queries/soup/cache';
import { cognitionApiServiceClient } from '@service-cognition/client';
import { ChatInput } from 'core/component/AI/component/input/ChatInput';
import { registerHotkey, useHotkeyDOMScope } from 'core/hotkey/hotkeys';
@@ -41,6 +45,8 @@ function SoupChatInputInner() {
const [attachHotkeys] = useHotkeyDOMScope('soup.chatInput');
+ const metaHeld = () => pressedKeys().has('cmd');
+
onMount(() => {
attachHotkeys(containerRef);
});
@@ -69,6 +75,8 @@ function SoupChatInputInner() {
}
const handleSend = async (request: ChatSendInput) => {
+ const backgroundSend = request.metaKey;
+
// Create a new persistent chat
const name = deriveChatName(request.content);
@@ -78,17 +86,30 @@ function SoupChatInputInner() {
}
const [, { id: chatId }] = response;
- // Store the pending send data for the chat to pick up
- setPendingSendData({
- content: request.content,
- attachments: request.attachments,
- model: request.model,
- });
-
- // Replace the soup split with the chat split
- splitPanelContext.handle.replace({
- next: { type: 'chat', id: chatId },
- });
+ if (backgroundSend) {
+ // Send the message in the background without navigating
+ cognitionApiServiceClient.sendStreamChatMessage({
+ content: request.content,
+ model: request.model,
+ chat_id: chatId,
+ attachments:
+ request.attachments.length > 0 ? request.attachments : undefined,
+ toolset: { type: 'all' },
+ });
+ invalidateAllSoup();
+ } else {
+ // Store the pending send data for the chat to pick up
+ setPendingSendData({
+ content: request.content,
+ attachments: request.attachments,
+ model: request.model,
+ });
+
+ // Replace the soup split with the chat split
+ splitPanelContext.handle.replace({
+ next: { type: 'chat', id: chatId },
+ });
+ }
};
return (
@@ -111,6 +132,30 @@ function SoupChatInputInner() {
}}
isPersistent={true}
autoFocusOnMount={false}
+ extraRightControls={() => (
+ <Tooltip
+ tooltip="⌘ Enter to send in background"
+ placement="top"
+ >
+ <div
+ class="flex items-center gap-1"
+ classList={{
+ 'text-accent': metaHeld(),
+ }}
+ >
+ <div
+ class="flex border text-[0.625rem] rounded-xs items-center px-1 py-0.5"
+ classList={{
+ 'border-accent text-accent': metaHeld(),
+ 'border-edge-muted': !metaHeld(),
+ }}
+ >
+ <Hotkey shortcut="cmd+Enter" />
+ </div>
+ <span>Background</span>
+ </div>
+ </Tooltip>
+ )}
/>
</div>
</div>
diff --git a/js/app/packages/core/component/AI/component/input/ChatInput.tsx b/js/app/packages/core/component/AI/component/input/ChatInput.tsx
index edb8ff5558..833fcd57c5 100644
--- a/js/app/packages/core/component/AI/component/input/ChatInput.tsx
+++ b/js/app/packages/core/component/AI/component/input/ChatInput.tsx
@@ -34,6 +34,7 @@ export type ChatInputProps = {
showActiveTabs?: boolean;
autoFocusOnMount?: boolean;
chatId?: string;
+ extraRightControls?: () => import('solid-js').JSX.Element;
};
export type ChatInputComponentProps = {
@@ -83,23 +84,26 @@ export function ChatInput(props: ChatInputComponentProps) {
return mdRef.scrollHeight > LINE_HEIGHT_THRESHOLD;
};
- const sendMessage = createCallback(async (modelOverride?: Model) => {
- if (!canSendMessage()) return;
+ const sendMessage = createCallback(
+ async (opts?: { modelOverride?: Model; metaKey?: boolean }) => {
+ if (!canSendMessage()) return;
- if (isNativeMobilePlatform() && !hasConsent()) {
- requestConsent(() => sendMessage(modelOverride));
- return;
- }
+ if (isNativeMobilePlatform() && !hasConsent()) {
+ requestConsent(() => sendMessage(opts));
+ return;
+ }
- const sendInput: ChatSendInput = {
- content: markdownText(),
- model: modelOverride ?? model(),
- attachments: attachments.attached(),
- toolset: toolsetSignal[0](),
- };
- props.editor.controls.clear();
- props.onSend(sendInput);
- });
+ const sendInput: ChatSendInput = {
+ content: markdownText(),
+ model: opts?.modelOverride ?? model(),
+ attachments: attachments.attached(),
+ toolset: toolsetSignal[0](),
+ metaKey: opts?.metaKey,
+ };
+ props.editor.controls.clear();
+ props.onSend(sendInput);
+ }
+ );
props.editor
.withFilePaste({
@@ -113,9 +117,9 @@ export function ChatInput(props: ChatInputComponentProps) {
});
},
})
- .onEnter(() => {
+ .onEnter((e) => {
if (canSendMessage()) {
- sendMessage();
+ sendMessage({ metaKey: e?.metaKey });
}
return true;
})
@@ -142,6 +146,7 @@ export function ChatInput(props: ChatInputComponentProps) {
<Switch>
<Match when={!isTouchDevice()}>
<div class="flex flex-row items-center gap-3 text-xs text-ink-disabled opacity-70 shrink-0">
+ {props.extraRightControls?.()}
<Tooltip tooltip="Enter to send with Opus" placement="top">
<div class="flex items-center gap-1">
<div class="flex border border-edge-muted text-[0.625rem] rounded-xs items-center px-1 py-0.5">
@@ -155,7 +160,9 @@ export function ChatInput(props: ChatInputComponentProps) {
<Match when={isTouchDevice()}>
<div class="flex flex-row gap-1 items-center shrink-0">
<Show when={!generating()}>
- <Button onClick={() => sendMessage('claude-opus-4-6')}>
+ <Button
+ onClick={() => sendMessage({ modelOverride: 'claude-opus-4-6' })}
+ >
<div class="group hover:bg-accent transition ease-in-out size-6 p-[2px] border border-accent rounded-full flex items-center justify-center">
<ArrowUp class="group-hover:!text-input group-hover:!fill-input !text-accent-ink !fill-accent size-4 transition ease-in-out" />
</div>
diff --git a/js/app/packages/core/component/AI/component/input/buildRequest.ts b/js/app/packages/core/component/AI/component/input/buildRequest.ts
index 7dd8b726dd..692ad5e831 100644
--- a/js/app/packages/core/component/AI/component/input/buildRequest.ts
+++ b/js/app/packages/core/component/AI/component/input/buildRequest.ts
@@ -12,6 +12,7 @@ export type ChatSendInput = {
model: Model;
attachments: Attachment[];
toolset: ToolSet;
+ metaKey?: boolean;
};
export type SendChatMessageResult =