@@ -11,6 +11,7 @@ import {
1111} from 'lucide-react'
1212import { AnimatePresence , motion } from 'motion/react'
1313import { useCallback , useEffect , useRef , useState } from 'react'
14+ import { useNavigate } from 'react-router'
1415import { AppSelector } from '@/components/elements/AppSelector'
1516import {
1617 GlowingBorder ,
@@ -26,7 +27,6 @@ import {
2627} from '@/components/ui/tooltip'
2728import { McpServerIcon } from '@/entrypoints/app/connect-mcp/McpServerIcon'
2829import { useGetUserMCPIntegrations } from '@/entrypoints/app/connect-mcp/useGetUserMCPIntegrations'
29- import { useChatSessionContext } from '@/entrypoints/sidepanel/layout/ChatSessionContext'
3030import { Feature } from '@/lib/browseros/capabilities'
3131import { useCapabilities } from '@/lib/browseros/useCapabilities'
3232import {
@@ -36,7 +36,6 @@ import {
3636import {
3737 NEWTAB_AI_TRIGGERED_EVENT ,
3838 NEWTAB_APPS_OPENED_EVENT ,
39- NEWTAB_CHAT_RESET_EVENT ,
4039 NEWTAB_CHAT_STARTED_EVENT ,
4140 NEWTAB_OPENED_EVENT ,
4241 NEWTAB_SEARCH_EXECUTED_EVENT ,
@@ -58,7 +57,6 @@ import {
5857 useSuggestions ,
5958} from './lib/suggestions/useSuggestions'
6059import { NewTabBranding } from './NewTabBranding'
61- import { NewTabChat } from './NewTabChat'
6260import { NewTabTip } from './NewTabTip'
6361import { ScheduleResults } from './ScheduleResults'
6462import { SearchSuggestions } from './SearchSuggestions'
@@ -78,13 +76,13 @@ interface MentionState {
7876 */
7977export const NewTab = ( ) => {
8078 const activeHint = useActiveHint ( )
79+ const navigate = useNavigate ( )
8180 const [ inputValue , setInputValue ] = useState ( '' )
8281 const [ mounted , setMounted ] = useState ( false )
8382 const inputRef = useRef < HTMLInputElement > ( null )
8483 const tabsDropdownRef = useRef < HTMLDivElement > ( null )
8584 const [ selectedTabs , setSelectedTabs ] = useState < chrome . tabs . Tab [ ] > ( [ ] )
8685 const [ shortcutsDialogOpen , setShortcutsDialogOpen ] = useState ( false )
87- const [ chatActive , setChatActive ] = useState ( false )
8886 const [ mentionState , setMentionState ] = useState < MentionState > ( {
8987 isOpen : false ,
9088 filterText : '' ,
@@ -96,9 +94,6 @@ export const NewTab = () => {
9694 const { data : userMCPIntegrations } = useGetUserMCPIntegrations ( )
9795 useSyncRemoteIntegrations ( )
9896
99- const { messages, sendMessage, setMode, resetConversation } =
100- useChatSessionContext ( )
101-
10297 const connectedManagedServers = mcpServers . filter ( ( s ) => {
10398 if ( s . type !== 'managed' || ! s . managedServerName ) return false
10499 return userMCPIntegrations ?. integrations ?. find (
@@ -275,17 +270,28 @@ export const NewTab = () => {
275270
276271 const startInlineChat = (
277272 message : string ,
278- mode : 'chat' | 'agent' ,
279- action ?: ReturnType <
280- typeof createBrowserOSAction | typeof createAITabAction
281- > ,
273+ chatMode : 'chat' | 'agent' ,
274+ aiTab ?: { name : string ; description : string } ,
282275 ) => {
283- track ( NEWTAB_CHAT_STARTED_EVENT , { mode, tabs_count : selectedTabs . length } )
284- setMode ( mode )
285- setChatActive ( true )
286- sendMessage ( { text : message , action } )
276+ track ( NEWTAB_CHAT_STARTED_EVENT , {
277+ mode : chatMode ,
278+ tabs_count : selectedTabs . length ,
279+ } )
280+ const tabIds = selectedTabs
281+ . map ( ( t ) => t . id )
282+ . filter ( ( id ) : id is number => id !== undefined )
287283 reset ( )
288284 setSelectedTabs ( [ ] )
285+ const params = new URLSearchParams ( { q : message , mode : chatMode } )
286+ if ( tabIds . length > 0 ) {
287+ params . set ( 'tabs' , tabIds . join ( ',' ) )
288+ }
289+ if ( aiTab ) {
290+ params . set ( 'actionType' , 'ai-tab' )
291+ params . set ( 'tabName' , aiTab . name )
292+ params . set ( 'tabDescription' , aiTab . description )
293+ }
294+ navigate ( `/home/chat?${ params . toString ( ) } ` )
289295 }
290296
291297 const runSelectedAction = ( item : SuggestionItem | undefined ) => {
@@ -306,15 +312,18 @@ export const NewTab = () => {
306312 mode : 'agent' ,
307313 tabs_count : selectedTabs . length ,
308314 } )
309- const action = createAITabAction ( {
310- name : item . name ,
311- description : item . description ,
312- tabs : selectedTabs ,
313- } )
314315 const searchQuery = `${ item . name } ${ item . description ? ` - ${ item . description } ` : '' } }`
315316 if ( supports ( Feature . NEWTAB_CHAT_SUPPORT ) ) {
316- startInlineChat ( searchQuery , 'agent' , action )
317+ startInlineChat ( searchQuery , 'agent' , {
318+ name : item . name ,
319+ description : item . description ,
320+ } )
317321 } else {
322+ const action = createAITabAction ( {
323+ name : item . name ,
324+ description : item . description ,
325+ tabs : selectedTabs ,
326+ } )
318327 openSidePanelWithSearch ( 'open' , {
319328 query : searchQuery ,
320329 mode : 'agent' ,
@@ -330,14 +339,14 @@ export const NewTab = () => {
330339 mode : item . mode ,
331340 tabs_count : selectedTabs . length ,
332341 } )
333- const action = createBrowserOSAction ( {
334- mode : item . mode ,
335- message : item . message ,
336- tabs : selectedTabs ,
337- } )
338342 if ( supports ( Feature . NEWTAB_CHAT_SUPPORT ) ) {
339- startInlineChat ( item . message , item . mode , action )
343+ startInlineChat ( item . message , item . mode )
340344 } else {
345+ const action = createBrowserOSAction ( {
346+ mode : item . mode ,
347+ message : item . message ,
348+ tabs : selectedTabs ,
349+ } )
341350 openSidePanelWithSearch ( 'open' , {
342351 query : item . message ,
343352 mode : item . mode ,
@@ -351,12 +360,6 @@ export const NewTab = () => {
351360 }
352361 }
353362
354- const handleBackToSearch = ( ) => {
355- track ( NEWTAB_CHAT_RESET_EVENT , { message_count : messages . length } )
356- resetConversation ( )
357- setChatActive ( false )
358- }
359-
360363 const isSuggestionsVisible =
361364 ! mentionState . isOpen &&
362365 ( ( isOpen && inputValue . length ) ||
@@ -368,10 +371,6 @@ export const NewTab = () => {
368371 track ( NEWTAB_OPENED_EVENT )
369372 } , [ ] )
370373
371- if ( chatActive ) {
372- return < NewTabChat onBackToSearch = { handleBackToSearch } />
373- }
374-
375374 return (
376375 < div className = "pt-[max(25vh,16px)]" >
377376 { /* Main content */ }
0 commit comments