Skip to content

Commit d0744a8

Browse files
committed
improvement(home): make Assistant a peer of Build and Search in the mode switcher
1 parent 4740899 commit d0744a8

12 files changed

Lines changed: 42 additions & 202 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/suggested-actions/suggested-actions.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,14 @@ describe('SuggestedActions', () => {
128128
expect(document.querySelector('[data-testid="search-sources"]')).not.toBeNull()
129129
expect(rows()).toHaveLength(0)
130130
})
131+
132+
it('shows the sources in Assistant mode, which answers from them', () => {
133+
mount()
134+
135+
act(() => useMothershipModeStore.getState().setMode('assistant'))
136+
137+
expect(heading()).toBe('Sources')
138+
expect(document.querySelector('[data-testid="search-sources"]')).not.toBeNull()
139+
expect(rows()).toHaveLength(0)
140+
})
131141
})

apps/sim/app/workspace/[workspaceId]/home/components/suggested-actions/suggested-actions.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ const INITIAL_ACTIONS: Action[] = [
235235
const HEADINGS: Record<MothershipMode, string> = {
236236
build: 'Suggested actions',
237237
search: 'Sources',
238+
assistant: 'Sources',
238239
}
239240

240241
interface SuggestedActionsProps {
@@ -372,7 +373,7 @@ export function SuggestedActions({ onSelectPrompt }: SuggestedActionsProps) {
372373
`collapsible-up`/`-down` interpolate height alone, so a margin here
373374
would hold its full value through the close and then vanish on unmount,
374375
snapping the content below up. */}
375-
{mode === 'search' && workspaceId ? (
376+
{mode !== 'build' && workspaceId ? (
376377
<div className='pt-1.5'>
377378
<SearchSources workspaceId={workspaceId} />
378379
</div>

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,3 @@ export { PromptEditor, usePromptEditor } from './prompt-editor'
3636
export { SendButton } from './send-button'
3737
export type { SkillsMenuHandle } from './skills-menu-dropdown/skills-menu-dropdown'
3838
export { SkillsMenuDropdown } from './skills-menu-dropdown/skills-menu-dropdown'
39-
export { SourcesModeToggle } from './sources-mode-toggle'

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/mode-switcher/mode-switcher.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ describe('ModeSwitcher', () => {
7878
expect(button.querySelector('svg')).toBeNull()
7979
})
8080

81-
it('lists both modes and checks the active one', () => {
81+
it('lists every mode and checks the active one', () => {
8282
mount()
8383
openMenu()
8484

8585
const rows = items()
86-
expect(rows.map((row) => row.textContent)).toEqual(['Build', 'Sources'])
86+
expect(rows.map((row) => row.textContent)).toEqual(['Build', 'Search', 'Assistant'])
8787
expect(rows[0].querySelector('svg')).not.toBeNull()
8888
expect(rows[1].querySelector('svg')).toBeNull()
89+
expect(rows[2].querySelector('svg')).toBeNull()
8990
})
9091

9192
it('switches the shared mode and reports the change', () => {
@@ -97,15 +98,15 @@ describe('ModeSwitcher', () => {
9798
})
9899

99100
expect(useMothershipModeStore.getState().mode).toBe('search')
100-
expect(trigger().textContent).toBe('Sources')
101+
expect(trigger().textContent).toBe('Search')
101102
expect(mockCaptureEvent).toHaveBeenCalledWith(null, 'chat_mode_changed', {
102103
workspace_id: 'workspace-1',
103104
mode: 'search',
104105
})
105106
expect(mockSetSearchQuery).not.toHaveBeenCalled()
106107
})
107108

108-
it('drops the search query from the URL when leaving Sources', () => {
109+
it('drops the search query from the URL when leaving Search', () => {
109110
useMothershipModeStore.getState().setMode('search')
110111
mount()
111112
openMenu()

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/mode-switcher/mode-switcher.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ import {
2828

2929
const MODE_LABELS: Record<MothershipMode, string> = {
3030
build: 'Build',
31-
search: 'Sources',
31+
search: 'Search',
32+
assistant: 'Assistant',
3233
}
3334

3435
/**
35-
* The composer's Build / Sources switcher: a label-only `Chip` in its `round`
36+
* The composer's Build / Search / Assistant switcher: a label-only `Chip` in its `round`
3637
* shape — chip chrome throughout (`--text-body` label, `--surface-hover` on
3738
* hover, no text-color shift), fully round to sit in the toolbar's row of
3839
* round controls — opening a menu that checks the active mode, as
@@ -47,7 +48,7 @@ export const ModeSwitcher = memo(function ModeSwitcher() {
4748
const [, setSearchQueryParam] = useQueryState(searchQueryParam.key, searchQueryParam.parser)
4849
const [, setSearchFilters] = useQueryStates(searchFilterParsers, resourceUrlKeys)
4950

50-
/** Leaving Sources drops the query from the URL, so a clean URL always means no search is showing. */
51+
/** Leaving Search drops the query from the URL, so a clean URL always means no search is showing. */
5152
const handleSelect = (next: MothershipMode) => {
5253
if (next === mode) return
5354
setMode(next)

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/sources-mode-toggle/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/sources-mode-toggle/sources-mode-toggle.test.tsx

Lines changed: 0 additions & 84 deletions
This file was deleted.

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/sources-mode-toggle/sources-mode-toggle.tsx

Lines changed: 0 additions & 68 deletions
This file was deleted.

apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
ModeSwitcher,
2929
PromptEditor,
3030
SendButton,
31-
SourcesModeToggle,
3231
usePromptEditor,
3332
} from '@/app/workspace/[workspaceId]/home/components/user-input/components'
3433
import { handleMothershipAddContextEvent } from '@/app/workspace/[workspaceId]/home/components/user-input/mothership-context-event'
@@ -720,7 +719,6 @@ const UserInputImpl = forwardRef<UserInputHandle, UserInputProps>(function UserI
720719
</Tooltip.Root>
721720
</div>
722721
<div className='flex items-center gap-1.5'>
723-
{canSearch && <SourcesModeToggle />}
724722
{canSearch && <ModeSwitcher />}
725723
{isSttSupported && (
726724
<MicButton

apps/sim/app/workspace/[workspaceId]/home/home.tsx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ export function Home({ chatId, userName, userId }: HomeProps) {
195195
if (searchQuery) useMothershipModeStore.getState().setMode('search')
196196
}, [searchQuery])
197197
const composerMode = useMothershipModeStore((state) => state.mode)
198-
const assistantMode = useMothershipModeStore((state) => state.assistant)
199198
/** The bases an Ask turn is grounded in; read through a ref so a list refresh never rebuilds the submit handler. */
200199
const { data: knowledgeBases = EMPTY_KNOWLEDGE_BASES } = useKnowledgeBasesQuery(workspaceId)
201200
const knowledgeBasesRef = useRef(knowledgeBases)
@@ -488,13 +487,13 @@ export function Home({ chatId, userName, userId }: HomeProps) {
488487
})
489488

490489
/**
491-
* Sources mode's Search lists documents, not a turn of the agent, and only
492-
* a query can be searched: attachments alone have nothing to search for.
493-
* Its Assistant makes the query a turn of the agent grounded in the sources.
490+
* Search lists documents, not a turn of the agent, and only a query can
491+
* be searched: attachments alone have nothing to search for. Assistant
492+
* makes the query a turn of the agent grounded in the sources.
494493
*/
495-
const { mode, assistant } = useMothershipModeStore.getState()
496-
const answering = mode === 'search' && assistant
497-
if (mode === 'search' && !assistant) {
494+
const mode = useMothershipModeStore.getState().mode
495+
const answering = mode === 'assistant'
496+
if (mode === 'search') {
498497
if (trimmed) setSearchQuery(trimmed)
499498
return
500499
}
@@ -525,21 +524,18 @@ export function Home({ chatId, userName, userId }: HomeProps) {
525524

526525
/** Summarize or Answer on a result: switch to Assistant and hand the question to it. */
527526
const handleSummarize = (prompt: string) => {
528-
const store = useMothershipModeStore.getState()
529-
store.setMode('search')
530-
store.setAssistant(true)
527+
useMothershipModeStore.getState().setMode('assistant')
531528
setSearchQuery('')
532529
handleSubmit(prompt)
533530
}
534531
/**
535-
* A chat that already exists never opens in Sources' document-listing
536-
* Search: its transcript is a conversation, and search results never join
537-
* it. Build and the Assistant both carry over, so a follow-up stays grounded
538-
* in the sources.
532+
* A chat that already exists never opens in Search: its transcript is a
533+
* conversation, and search results never join it. Build and Assistant both
534+
* carry over, so a follow-up stays grounded in the sources.
539535
*/
540536
useEffect(() => {
541537
const store = useMothershipModeStore.getState()
542-
if (chatId && store.mode === 'search' && !store.assistant) store.setMode('build')
538+
if (chatId && store.mode === 'search') store.setMode('build')
543539
}, [chatId])
544540
const showSearchResults = composerMode === 'search' && searchQuery.trim().length > 0
545541
const searchResults = showSearchResults ? (
@@ -772,7 +768,7 @@ export function Home({ chatId, userName, userId }: HomeProps) {
772768
draftScopeKey={draftScopeKey}
773769
onSubmit={handleSubmit}
774770
canSearch
775-
clearOnSubmit={composerMode !== 'search' || assistantMode}
771+
clearOnSubmit={composerMode !== 'search'}
776772
onCleared={clearSearch}
777773
isSending={isSending}
778774
onStopGeneration={handleStopGeneration}
@@ -801,7 +797,7 @@ export function Home({ chatId, userName, userId }: HomeProps) {
801797
isLoading={showChatSkeleton}
802798
onSubmit={handleSubmit}
803799
canSearch
804-
clearOnSubmit={composerMode !== 'search' || assistantMode}
800+
clearOnSubmit={composerMode !== 'search'}
805801
onCleared={clearSearch}
806802
onStopGeneration={handleStopGeneration}
807803
messageQueue={messageQueue}

0 commit comments

Comments
 (0)