Skip to content

Commit 4324bde

Browse files
committed
search context for chat suggestion, nits
1 parent f47ffc3 commit 4324bde

File tree

9 files changed

+30
-9
lines changed

9 files changed

+30
-9
lines changed

packages/web/src/actions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1868,9 +1868,10 @@ export const getSearchContexts = async (domain: string) => sew(() =>
18681868
});
18691869

18701870
return searchContexts.map((context) => ({
1871+
id: context.id,
18711872
name: context.name,
18721873
description: context.description ?? undefined,
1873-
repoCount: context.repos.length,
1874+
repoNames: context.repos.map((repo) => repo.name),
18741875
}));
18751876
}, /* minRequiredRole = */ OrgRole.GUEST), /* allowAnonymousAccess = */ true
18761877
));

packages/web/src/app/[domain]/chat/[id]/components/chatThreadPanel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const ChatThreadPanel = ({
5555
type: 'context' as const,
5656
value: contextName,
5757
name: contextName,
58-
repoCount: context?.repoCount || 0
58+
repoCount: context?.repoNames.length || 0
5959
};
6060
})
6161
]);
@@ -79,13 +79,13 @@ export const ChatThreadPanel = ({
7979
codeHostType: repoInfo?.codeHostType || ''
8080
};
8181
}),
82-
...(selectedContexts || []).map(contextName => {
82+
...selectedContexts.map(contextName => {
8383
const context = searchContexts.find(c => c.name === contextName);
8484
return {
8585
type: 'context' as const,
8686
value: contextName,
8787
name: contextName,
88-
repoCount: context?.repoCount || 0
88+
repoCount: context?.repoNames.length || 0
8989
};
9090
})
9191
]);

packages/web/src/app/[domain]/chat/components/newChatPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const NewChatPanel = ({
5151
isRedirecting={isLoading}
5252
languageModels={languageModels}
5353
selectedItems={selectedItems}
54+
searchContexts={searchContexts}
5455
onContextSelectorOpenChanged={setIsContextSelectorOpen}
5556
/>
5657
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">

packages/web/src/app/[domain]/components/homepage/agenticSearch.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export const AgenticSearch = ({
167167
isRedirecting={isLoading}
168168
languageModels={languageModels}
169169
selectedItems={selectedItems}
170+
searchContexts={searchContexts}
170171
onContextSelectorOpenChanged={setIsContextSelectorOpen}
171172
/>
172173
<Separator />

packages/web/src/features/chat/components/chatBox/chatBox.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { useSuggestionModeAndQuery } from "./useSuggestionModeAndQuery";
1919
import { useSuggestionsData } from "./useSuggestionsData";
2020
import { useToast } from "@/components/hooks/use-toast";
2121
import { ContextItem } from "./contextSelector";
22+
import { SearchContextQuery } from "@/lib/types";
2223

2324
interface ChatBoxProps {
2425
onSubmit: (children: Descendant[], editor: CustomEditor) => void;
@@ -29,6 +30,7 @@ interface ChatBoxProps {
2930
isGenerating?: boolean;
3031
languageModels: LanguageModelInfo[];
3132
selectedItems: ContextItem[];
33+
searchContexts: SearchContextQuery[];
3234
onContextSelectorOpenChanged: (isOpen: boolean) => void;
3335
}
3436

@@ -41,6 +43,7 @@ export const ChatBox = ({
4143
isGenerating,
4244
languageModels,
4345
selectedItems,
46+
searchContexts,
4447
onContextSelectorOpenChanged,
4548
}: ChatBoxProps) => {
4649
const suggestionsBoxRef = useRef<HTMLDivElement>(null);
@@ -50,7 +53,20 @@ export const ChatBox = ({
5053
const { suggestions, isLoading } = useSuggestionsData({
5154
suggestionMode,
5255
suggestionQuery,
53-
selectedRepos: selectedItems.filter(item => item.type === 'repo').map(item => item.value),
56+
selectedRepos: selectedItems.map((item) => {
57+
if (item.type === 'repo') {
58+
return [item.value];
59+
}
60+
61+
if (item.type === 'context') {
62+
const context = searchContexts.find((context) => context.name === item.value);
63+
if (context) {
64+
return context.repoNames;
65+
}
66+
}
67+
68+
return [];
69+
}).flat(),
5470
});
5571
const { selectedLanguageModel } = useSelectedLanguageModel({
5672
initialLanguageModel: languageModels.length > 0 ? languageModels[0] : undefined,

packages/web/src/features/chat/components/chatBox/contextSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export const ContextSelector = React.forwardRef<
118118
type: 'context' as const,
119119
value: context.name,
120120
name: context.name,
121-
repoCount: context.repoCount
121+
repoCount: context.repoNames.length
122122
}));
123123

124124
const repoItems: ContextItem[] = repos.map(repo => ({

packages/web/src/features/chat/components/chatThread/chatThread.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ export const ChatThread = ({
328328
onStop={stop}
329329
languageModels={languageModels}
330330
selectedItems={selectedItems}
331+
searchContexts={searchContexts}
331332
onContextSelectorOpenChanged={setIsContextSelectorOpen}
332333
/>
333334
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">

packages/web/src/features/chat/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export const SET_CHAT_STATE_QUERY_PARAM = 'setChatState';
140140
export type SetChatStatePayload = {
141141
inputMessage: CreateUIMessage<SBChatMessage>;
142142
selectedRepos: string[];
143-
selectedContexts?: string[];
143+
selectedContexts: string[];
144144
}
145145

146146

@@ -158,6 +158,6 @@ export type LanguageModelInfo = {
158158
export const additionalChatRequestParamsSchema = z.object({
159159
languageModelId: z.string(),
160160
selectedRepos: z.array(z.string()),
161-
selectedContexts: z.array(z.string()).optional(),
161+
selectedContexts: z.array(z.string()),
162162
});
163163
export type AdditionalChatRequestParams = z.infer<typeof additionalChatRequestParamsSchema>;

packages/web/src/lib/schemas.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ export const repositoryQuerySchema = z.object({
2929
});
3030

3131
export const searchContextQuerySchema = z.object({
32+
id: z.number(),
3233
name: z.string(),
3334
description: z.string().optional(),
34-
repoCount: z.number(),
35+
repoNames: z.array(z.string()),
3536
});
3637

3738
export const verifyCredentialsRequestSchema = z.object({

0 commit comments

Comments
 (0)