22
33import { ResizablePanel } from '@/components/ui/resizable' ;
44import { ChatThread } from '@/features/chat/components/chatThread' ;
5- import { LanguageModelInfo , SBChatMessage , SET_CHAT_STATE_QUERY_PARAM , SetChatStatePayload } from '@/features/chat/types' ;
5+ import { LanguageModelInfo , SBChatMessage , SearchScope , SET_CHAT_STATE_QUERY_PARAM , SetChatStatePayload } from '@/features/chat/types' ;
66import { RepositoryQuery , SearchContextQuery } from '@/lib/types' ;
77import { CreateUIMessage } from 'ai' ;
88import { useRouter , useSearchParams } from 'next/navigation' ;
99import { useEffect , useState } from 'react' ;
1010import { useChatId } from '../../useChatId' ;
11- import { ContextItem } from '@/features/chat/components/chatBox/contextSelector' ;
1211
1312interface ChatThreadPanelProps {
1413 languageModels : LanguageModelInfo [ ] ;
@@ -33,62 +32,22 @@ export const ChatThreadPanel = ({
3332 const router = useRouter ( ) ;
3433 const searchParams = useSearchParams ( ) ;
3534 const [ inputMessage , setInputMessage ] = useState < CreateUIMessage < SBChatMessage > | undefined > ( undefined ) ;
36-
35+
3736 // Use the last user's last message to determine what repos and contexts we should select by default.
3837 const lastUserMessage = messages . findLast ( ( message ) => message . role === "user" ) ;
39- const defaultSelectedRepos = lastUserMessage ?. metadata ?. selectedRepos ?? [ ] ;
40- const defaultSelectedContexts = lastUserMessage ?. metadata ?. selectedContexts ?? [ ] ;
38+ const defaultSelectedSearchScopes = lastUserMessage ?. metadata ?. selectedSearchScopes ?? [ ] ;
39+ const [ selectedSearchScopes , setSelectedSearchScopes ] = useState < SearchScope [ ] > ( defaultSelectedSearchScopes ) ;
4140
42- const [ selectedItems , setSelectedItems ] = useState < ContextItem [ ] > ( [
43- ...defaultSelectedRepos . map ( repoName => {
44- const repoInfo = repos . find ( r => r . repoName === repoName ) ;
45- return {
46- type : 'repo' as const ,
47- value : repoName ,
48- name : repoInfo ?. repoDisplayName || repoName . split ( '/' ) . pop ( ) || repoName ,
49- codeHostType : repoInfo ?. codeHostType || ''
50- } ;
51- } ) ,
52- ...defaultSelectedContexts . map ( contextName => {
53- const context = searchContexts . find ( c => c . name === contextName ) ;
54- return {
55- type : 'context' as const ,
56- value : contextName ,
57- name : contextName ,
58- repoCount : context ?. repoNames . length || 0
59- } ;
60- } )
61- ] ) ;
62-
6341 useEffect ( ( ) => {
6442 const setChatState = searchParams . get ( SET_CHAT_STATE_QUERY_PARAM ) ;
6543 if ( ! setChatState ) {
6644 return ;
6745 }
6846
6947 try {
70- const { inputMessage, selectedRepos , selectedContexts } = JSON . parse ( setChatState ) as SetChatStatePayload ;
48+ const { inputMessage, selectedSearchScopes } = JSON . parse ( setChatState ) as SetChatStatePayload ;
7149 setInputMessage ( inputMessage ) ;
72- setSelectedItems ( [
73- ...selectedRepos . map ( repoName => {
74- const repoInfo = repos . find ( r => r . repoName === repoName ) ;
75- return {
76- type : 'repo' as const ,
77- value : repoName ,
78- name : repoInfo ?. repoDisplayName || repoName . split ( '/' ) . pop ( ) || repoName ,
79- codeHostType : repoInfo ?. codeHostType || ''
80- } ;
81- } ) ,
82- ...selectedContexts . map ( contextName => {
83- const context = searchContexts . find ( c => c . name === contextName ) ;
84- return {
85- type : 'context' as const ,
86- value : contextName ,
87- name : contextName ,
88- repoCount : context ?. repoNames . length || 0
89- } ;
90- } )
91- ] ) ;
50+ setSelectedSearchScopes ( selectedSearchScopes ) ;
9251 } catch {
9352 console . error ( 'Invalid message in URL' ) ;
9453 }
@@ -97,7 +56,7 @@ export const ChatThreadPanel = ({
9756 const newSearchParams = new URLSearchParams ( searchParams . toString ( ) ) ;
9857 newSearchParams . delete ( SET_CHAT_STATE_QUERY_PARAM ) ;
9958 router . replace ( `?${ newSearchParams . toString ( ) } ` , { scroll : false } ) ;
100- } , [ searchParams , router , repos , searchContexts ] ) ;
59+ } , [ searchParams , router ] ) ;
10160
10261 return (
10362 < ResizablePanel
@@ -113,8 +72,8 @@ export const ChatThreadPanel = ({
11372 languageModels = { languageModels }
11473 repos = { repos }
11574 searchContexts = { searchContexts }
116- selectedItems = { selectedItems }
117- onSelectedItemsChange = { setSelectedItems }
75+ selectedSearchScopes = { selectedSearchScopes }
76+ onSelectedSearchScopesChange = { setSelectedSearchScopes }
11877 isChatReadonly = { isChatReadonly }
11978 />
12079 </ div >
0 commit comments