2
2
3
3
import { ResizablePanel } from '@/components/ui/resizable' ;
4
4
import { 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' ;
6
6
import { RepositoryQuery , SearchContextQuery } from '@/lib/types' ;
7
7
import { CreateUIMessage } from 'ai' ;
8
8
import { useRouter , useSearchParams } from 'next/navigation' ;
9
9
import { useEffect , useState } from 'react' ;
10
10
import { useChatId } from '../../useChatId' ;
11
- import { ContextItem } from '@/features/chat/components/chatBox/contextSelector' ;
12
11
13
12
interface ChatThreadPanelProps {
14
13
languageModels : LanguageModelInfo [ ] ;
@@ -33,62 +32,22 @@ export const ChatThreadPanel = ({
33
32
const router = useRouter ( ) ;
34
33
const searchParams = useSearchParams ( ) ;
35
34
const [ inputMessage , setInputMessage ] = useState < CreateUIMessage < SBChatMessage > | undefined > ( undefined ) ;
36
-
35
+
37
36
// Use the last user's last message to determine what repos and contexts we should select by default.
38
37
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 ) ;
41
40
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
-
63
41
useEffect ( ( ) => {
64
42
const setChatState = searchParams . get ( SET_CHAT_STATE_QUERY_PARAM ) ;
65
43
if ( ! setChatState ) {
66
44
return ;
67
45
}
68
46
69
47
try {
70
- const { inputMessage, selectedRepos , selectedContexts } = JSON . parse ( setChatState ) as SetChatStatePayload ;
48
+ const { inputMessage, selectedSearchScopes } = JSON . parse ( setChatState ) as SetChatStatePayload ;
71
49
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 ) ;
92
51
} catch {
93
52
console . error ( 'Invalid message in URL' ) ;
94
53
}
@@ -97,7 +56,7 @@ export const ChatThreadPanel = ({
97
56
const newSearchParams = new URLSearchParams ( searchParams . toString ( ) ) ;
98
57
newSearchParams . delete ( SET_CHAT_STATE_QUERY_PARAM ) ;
99
58
router . replace ( `?${ newSearchParams . toString ( ) } ` , { scroll : false } ) ;
100
- } , [ searchParams , router , repos , searchContexts ] ) ;
59
+ } , [ searchParams , router ] ) ;
101
60
102
61
return (
103
62
< ResizablePanel
@@ -113,8 +72,8 @@ export const ChatThreadPanel = ({
113
72
languageModels = { languageModels }
114
73
repos = { repos }
115
74
searchContexts = { searchContexts }
116
- selectedItems = { selectedItems }
117
- onSelectedItemsChange = { setSelectedItems }
75
+ selectedSearchScopes = { selectedSearchScopes }
76
+ onSelectedSearchScopesChange = { setSelectedSearchScopes }
118
77
isChatReadonly = { isChatReadonly }
119
78
/>
120
79
</ div >
0 commit comments