Skip to content

Commit 1b88ade

Browse files
authored
feat: updated homepage chat (#481)
* feat: updated chat ui from homepage * fix: vertical scroll * fix: horizontal scroll issue * fix: lint issues * fix: header width * fix: message input from home to chat * feat: created sidebar header support in new tab chat * fix: remove history from new tab chat * fix: remove the shared element transition * fix: lint issues * fix: review comments * fix: defer the sendMessage callback * fix: all code concerns * fix: preserve state of chat on homepage * fix: review comments
1 parent 079a254 commit 1b88ade

9 files changed

Lines changed: 364 additions & 222 deletions

File tree

packages/browseros-agent/apps/agent/entrypoints/app/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from 'react-router'
1111

1212
import { NewTab } from '../newtab/index/NewTab'
13+
import { NewTabChat } from '../newtab/index/NewTabChat'
1314
import { NewTabLayout } from '../newtab/layout/NewTabLayout'
1415
import { Personalize } from '../newtab/personalize/Personalize'
1516
import { OnboardingDemo } from '../onboarding/demo/OnboardingDemo'
@@ -99,6 +100,7 @@ const AppRoutes: FC = () => {
99100
{/* Home routes */}
100101
<Route path="home" element={<NewTabLayout />}>
101102
<Route index element={<NewTab />} />
103+
<Route path="chat" element={<NewTabChat />} />
102104
<Route path="personalize" element={<Personalize />} />
103105
<Route path="soul" element={<SoulPage />} />
104106
<Route path="skills" element={<SkillsPage />} />

packages/browseros-agent/apps/agent/entrypoints/app/layout/SidebarLayout.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,17 @@ export const SidebarLayout: FC = () => {
9696
</div>
9797

9898
{/* Main content - full width, centered */}
99-
<main className="min-h-screen overflow-y-auto">
100-
<div className="mx-auto max-w-4xl px-4 py-8 sm:px-6 lg:px-8">
99+
{location.pathname === '/home/chat' ? (
100+
<main className="h-screen overflow-hidden">
101101
<Outlet />
102-
</div>
103-
</main>
102+
</main>
103+
) : (
104+
<main className="min-h-screen overflow-y-auto">
105+
<div className="mx-auto max-w-4xl px-4 py-8 sm:px-6 lg:px-8">
106+
<Outlet />
107+
</div>
108+
</main>
109+
)}
104110
</div>
105111
<ShortcutsDialog
106112
open={shortcutsDialogOpen}

packages/browseros-agent/apps/agent/entrypoints/newtab/index/NewTab.tsx

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from 'lucide-react'
1212
import { AnimatePresence, motion } from 'motion/react'
1313
import { useCallback, useEffect, useRef, useState } from 'react'
14+
import { useNavigate } from 'react-router'
1415
import { AppSelector } from '@/components/elements/AppSelector'
1516
import {
1617
GlowingBorder,
@@ -26,7 +27,6 @@ import {
2627
} from '@/components/ui/tooltip'
2728
import { McpServerIcon } from '@/entrypoints/app/connect-mcp/McpServerIcon'
2829
import { useGetUserMCPIntegrations } from '@/entrypoints/app/connect-mcp/useGetUserMCPIntegrations'
29-
import { useChatSessionContext } from '@/entrypoints/sidepanel/layout/ChatSessionContext'
3030
import { Feature } from '@/lib/browseros/capabilities'
3131
import { useCapabilities } from '@/lib/browseros/useCapabilities'
3232
import {
@@ -36,7 +36,6 @@ import {
3636
import {
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'
6059
import { NewTabBranding } from './NewTabBranding'
61-
import { NewTabChat } from './NewTabChat'
6260
import { NewTabTip } from './NewTabTip'
6361
import { ScheduleResults } from './ScheduleResults'
6462
import { SearchSuggestions } from './SearchSuggestions'
@@ -78,13 +76,13 @@ interface MentionState {
7876
*/
7977
export 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

Comments
 (0)