Skip to content

Commit f745a6c

Browse files
committed
feat(search): auto-send Ask Sim queries via the chat handoff
Re-lands the auto-send flip: with fix/mship-mount-send-loss beneath this branch, sends started during Home's mount-settling window survive the cleanup abort (queued, restored, re-dispatched), so the handoff no longer loses the query on cross-route navigation.
1 parent 3a61b86 commit f745a6c

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/search-modal/search-modal.test.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { act } from 'react'
55
import { createRoot, type Root } from 'react-dom/client'
66
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
7-
import { LandingPromptStorage } from '@/lib/core/utils/browser-storage'
7+
import { MothershipHandoffStorage } from '@/lib/core/utils/browser-storage'
88
import {
99
MOTHERSHIP_SEND_MESSAGE_EVENT,
1010
type MothershipSendMessageDetail,
@@ -163,7 +163,10 @@ describe('SearchModal', () => {
163163

164164
expect(onOpenChange).toHaveBeenCalledWith(false)
165165
expect(mockPush).toHaveBeenCalledWith('/workspace/workspace-1/home')
166-
expect(LandingPromptStorage.consume()).toBe('plan our Slack launch week')
166+
expect(MothershipHandoffStorage.consume('workspace-1')).toEqual({
167+
message: 'plan our Slack launch week',
168+
contexts: [],
169+
})
167170
})
168171

169172
it('returns to search results when Tab is pressed again in ask mode', async () => {
@@ -295,7 +298,7 @@ describe('SearchModal', () => {
295298

296299
expect(receivedMessages).toEqual(['summarize this workspace'])
297300
expect(mockPush).not.toHaveBeenCalled()
298-
expect(LandingPromptStorage.consume()).toBeNull()
301+
expect(MothershipHandoffStorage.consume('workspace-1')).toBeNull()
299302
} finally {
300303
window.removeEventListener(MOTHERSHIP_SEND_MESSAGE_EVENT, handleMessage)
301304
}
@@ -691,7 +694,7 @@ describe('SearchModal', () => {
691694

692695
it('keeps the palette open when the query handoff cannot be persisted', async () => {
693696
const onOpenChange = vi.fn()
694-
const storeSpy = vi.spyOn(LandingPromptStorage, 'store').mockReturnValue(false)
697+
const storeSpy = vi.spyOn(MothershipHandoffStorage, 'store').mockReturnValue(false)
695698

696699
try {
697700
await act(async () => {

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/search-modal/search-modal.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { usePostHog } from 'posthog-js/react'
4141
import { createPortal } from 'react-dom'
4242
import { supportsAtomicBrowserPanelOcclusion } from '@/lib/browser-agent/transport'
4343
import { isChatEnabled } from '@/lib/core/config/env-flags'
44-
import { LandingPromptStorage } from '@/lib/core/utils/browser-storage'
44+
import { MothershipHandoffStorage } from '@/lib/core/utils/browser-storage'
4545
import { sendMothershipMessage } from '@/lib/mothership/events'
4646
import { captureEvent } from '@/lib/posthog/client'
4747
import { toSearchToken } from '@/lib/search/tokens'
@@ -844,11 +844,12 @@ function SearchModalContent({
844844
const sentToMountedHome = window.location.pathname === homeHref && sendMothershipMessage(query)
845845

846846
if (!sentToMountedHome) {
847-
/* Prefill, not auto-send: sends started during Home's mount-settling
848-
window are still silently aborted by use-chat's cleanup effect, so a
849-
MothershipHandoffStorage handoff would vanish (verified live). Stored
850-
raw — user prose is never mentionified into @ chips. */
851-
if (!LandingPromptStorage.store(query)) {
847+
/* One-shot auto-send handoff: Home's mount consumer sends it on arrival,
848+
so both routes deliver the raw query identically. use-chat's queued
849+
send dispatch now survives the mount-settling effect cycle that used
850+
to silently abort programmatic sends (the old reason this was a
851+
prefill). */
852+
if (!MothershipHandoffStorage.store({ message: query }, workspaceId)) {
852853
logger.warn('Failed to persist command palette query for a new chat', {
853854
workspaceId,
854855
})

0 commit comments

Comments
 (0)