feat: updated homepage chat - #481
Merged
Merged
Conversation
Contributor
Greptile SummaryThis PR refactors the New Tab chat experience by promoting it from inline component state to a dedicated Key changes:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
actor User
participant NewTab as NewTab (/home)
participant Router as React Router
participant NewTabChat as NewTabChat (/home/chat)
participant useChatActions as useChatActions hook
participant ChatSession as ChatSessionContext
User->>NewTab: types query + submits
NewTab->>NewTab: startInlineChat(message, mode, aiTab?)
NewTab->>Router: navigate('/home/chat?q=...&mode=...&tabs=...')
Router->>NewTabChat: mount component
NewTabChat->>useChatActions: initialize(events config)
useChatActions->>ChatSession: useChatSessionContext()
useChatActions-->>NewTabChat: { sendMessage, mode, input, voiceState, ... }
NewTabChat->>NewTabChat: useEffect (hasSentInitialRef guard)
NewTabChat->>NewTabChat: read q, mode, tabs from searchParams
NewTabChat->>Router: setSearchParams({}, replace) — clean URL
alt tabs param present
NewTabChat->>NewTabChat: chrome.tabs.query({})
NewTabChat->>ChatSession: sendMessage({ text, action })
else no tabs
NewTabChat->>ChatSession: sendMessage({ text: query })
end
User->>NewTabChat: types follow-up + submits
NewTabChat->>useChatActions: handleSubmit(e)
useChatActions->>ChatSession: sendMessage({ text, action? })
Prompt To Fix All With AIThis is a comment left during a code review.
Path: packages/browseros-agent/apps/agent/entrypoints/newtab/index/NewTabChat.tsx
Line: 112
Comment:
**Unsafe type cast for `chatMode`**
`chatMode` is read directly from URL query params (`searchParams.get('mode')`) and returns `string | null`. The guard `if (chatMode === 'chat' || chatMode === 'agent')` is correctly used to call `setMode`, but `chatMode` is later passed to `createBrowserOSAction` via an unsafe cast. If `chatMode` is any string other than `'chat'` or `'agent'` (e.g., a tampered/malformed URL), the `?? 'agent'` null-coalescing fallback will NOT trigger (since the value is non-null), silently passing an invalid mode string. Prefer a narrowing check that also handles the invalid-string case:
```suggestion
mode: chatMode === 'chat' || chatMode === 'agent' ? chatMode : 'agent',
```
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: "fix: review comments" |
Contributor
Author
Contributor
Author
Contributor
Author
Contributor
Author
Contributor
Author
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors and streamlines the New Tab chat experience in the BrowserOS Agent app. It introduces a dedicated
/home/chatroute for chat, decouples chat state from theNewTabcomponent, and centralizes chat logic using a newuseChatActionshook. The result is a more modular, maintainable, and scalable chat feature, with improved routing and UI consistency across the app.Routing and Layout Improvements:
/home/chatroute in the router and updatedSidebarLayoutandNewTabLayoutto properly handle full-screen chat and hide the focus grid when appropriate. (App.tsx,SidebarLayout.tsx,NewTabLayout.tsx) [1] [2] [3] [4]NewTab and Chat Refactor:
NewTabto remove embedded chat state and logic, delegating chat to the new/home/chatroute. Chat is now started by navigating to/home/chatwith query parameters, and all chat state is managed in the dedicatedNewTabChatcomponent. (NewTab.tsx) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]Chat Component and State Management:
NewTabChatto use a newuseChatActionshook, consolidating chat actions, state, and analytics events. The chat component now reads initial messages from URL query parameters and supports a more flexible, stateless design. (NewTabChat.tsx) [1] [2] [3] [4] [5]UI Consistency and Header Updates:
ChatHeaderto support ahideHistoryprop, ensuring that chat history controls are only shown in the appropriate context (e.g., hidden in the new tab chat view). (ChatHeader.tsx) [1] [2] [3] [4]