mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-15 13:55:20 +00:00
Remove search scope constraint
This commit is contained in:
parent
565d93051d
commit
e69ac0d806
4 changed files with 15 additions and 71 deletions
|
|
@ -51,7 +51,6 @@ export const NewChatPanel = ({
|
||||||
languageModels={languageModels}
|
languageModels={languageModels}
|
||||||
selectedSearchScopes={selectedSearchScopes}
|
selectedSearchScopes={selectedSearchScopes}
|
||||||
searchContexts={searchContexts}
|
searchContexts={searchContexts}
|
||||||
onContextSelectorOpenChanged={setIsContextSelectorOpen}
|
|
||||||
/>
|
/>
|
||||||
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
|
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
|
||||||
<ChatBoxToolbar
|
<ChatBoxToolbar
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,6 @@ export const AgenticSearch = ({
|
||||||
languageModels={languageModels}
|
languageModels={languageModels}
|
||||||
selectedSearchScopes={selectedSearchScopes}
|
selectedSearchScopes={selectedSearchScopes}
|
||||||
searchContexts={searchContexts}
|
searchContexts={searchContexts}
|
||||||
onContextSelectorOpenChanged={setIsContextSelectorOpen}
|
|
||||||
/>
|
/>
|
||||||
<Separator />
|
<Separator />
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@ import { Button } from "@/components/ui/button";
|
||||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||||
import { CustomEditor, LanguageModelInfo, MentionElement, RenderElementPropsFor, SearchScope } from "@/features/chat/types";
|
import { CustomEditor, LanguageModelInfo, MentionElement, RenderElementPropsFor, SearchScope } from "@/features/chat/types";
|
||||||
import { insertMention, slateContentToString } from "@/features/chat/utils";
|
import { insertMention, slateContentToString } from "@/features/chat/utils";
|
||||||
|
import { SearchContextQuery } from "@/lib/types";
|
||||||
import { cn, IS_MAC } from "@/lib/utils";
|
import { cn, IS_MAC } from "@/lib/utils";
|
||||||
import { computePosition, flip, offset, shift, VirtualElement } from "@floating-ui/react";
|
import { computePosition, flip, offset, shift, VirtualElement } from "@floating-ui/react";
|
||||||
import { ArrowUp, Loader2, StopCircleIcon, TriangleAlertIcon } from "lucide-react";
|
import { ArrowUp, Loader2, StopCircleIcon } from "lucide-react";
|
||||||
import { Fragment, KeyboardEvent, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { Fragment, KeyboardEvent, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { useHotkeys } from "react-hotkeys-hook";
|
import { useHotkeys } from "react-hotkeys-hook";
|
||||||
import { Descendant, insertText } from "slate";
|
import { Descendant, insertText } from "slate";
|
||||||
|
|
@ -17,8 +18,6 @@ import { SuggestionBox } from "./suggestionsBox";
|
||||||
import { Suggestion } from "./types";
|
import { Suggestion } from "./types";
|
||||||
import { useSuggestionModeAndQuery } from "./useSuggestionModeAndQuery";
|
import { useSuggestionModeAndQuery } from "./useSuggestionModeAndQuery";
|
||||||
import { useSuggestionsData } from "./useSuggestionsData";
|
import { useSuggestionsData } from "./useSuggestionsData";
|
||||||
import { useToast } from "@/components/hooks/use-toast";
|
|
||||||
import { SearchContextQuery } from "@/lib/types";
|
|
||||||
|
|
||||||
interface ChatBoxProps {
|
interface ChatBoxProps {
|
||||||
onSubmit: (children: Descendant[], editor: CustomEditor) => void;
|
onSubmit: (children: Descendant[], editor: CustomEditor) => void;
|
||||||
|
|
@ -30,7 +29,6 @@ interface ChatBoxProps {
|
||||||
languageModels: LanguageModelInfo[];
|
languageModels: LanguageModelInfo[];
|
||||||
selectedSearchScopes: SearchScope[];
|
selectedSearchScopes: SearchScope[];
|
||||||
searchContexts: SearchContextQuery[];
|
searchContexts: SearchContextQuery[];
|
||||||
onContextSelectorOpenChanged: (isOpen: boolean) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ChatBox = ({
|
export const ChatBox = ({
|
||||||
|
|
@ -43,7 +41,6 @@ export const ChatBox = ({
|
||||||
languageModels,
|
languageModels,
|
||||||
selectedSearchScopes,
|
selectedSearchScopes,
|
||||||
searchContexts,
|
searchContexts,
|
||||||
onContextSelectorOpenChanged,
|
|
||||||
}: ChatBoxProps) => {
|
}: ChatBoxProps) => {
|
||||||
const suggestionsBoxRef = useRef<HTMLDivElement>(null);
|
const suggestionsBoxRef = useRef<HTMLDivElement>(null);
|
||||||
const [index, setIndex] = useState(0);
|
const [index, setIndex] = useState(0);
|
||||||
|
|
@ -70,7 +67,6 @@ export const ChatBox = ({
|
||||||
const { selectedLanguageModel } = useSelectedLanguageModel({
|
const { selectedLanguageModel } = useSelectedLanguageModel({
|
||||||
initialLanguageModel: languageModels.length > 0 ? languageModels[0] : undefined,
|
initialLanguageModel: languageModels.length > 0 ? languageModels[0] : undefined,
|
||||||
});
|
});
|
||||||
const { toast } = useToast();
|
|
||||||
|
|
||||||
// Reset the index when the suggestion mode changes.
|
// Reset the index when the suggestion mode changes.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -101,9 +97,9 @@ export const ChatBox = ({
|
||||||
return <Leaf {...props} />
|
return <Leaf {...props} />
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const { isSubmitDisabled, isSubmitDisabledReason } = useMemo((): {
|
const { isSubmitDisabled } = useMemo((): {
|
||||||
isSubmitDisabled: true,
|
isSubmitDisabled: true,
|
||||||
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-repos-selected" | "no-language-model-selected"
|
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-language-model-selected"
|
||||||
} | {
|
} | {
|
||||||
isSubmitDisabled: false,
|
isSubmitDisabled: false,
|
||||||
isSubmitDisabledReason: undefined,
|
isSubmitDisabledReason: undefined,
|
||||||
|
|
@ -129,13 +125,6 @@ export const ChatBox = ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedSearchScopes.length === 0) {
|
|
||||||
return {
|
|
||||||
isSubmitDisabled: true,
|
|
||||||
isSubmitDisabledReason: "no-repos-selected",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedLanguageModel === undefined) {
|
if (selectedLanguageModel === undefined) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -149,29 +138,11 @@ export const ChatBox = ({
|
||||||
isSubmitDisabledReason: undefined,
|
isSubmitDisabledReason: undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
}, [
|
}, [editor.children, isRedirecting, isGenerating, selectedLanguageModel])
|
||||||
editor.children,
|
|
||||||
isRedirecting,
|
|
||||||
isGenerating,
|
|
||||||
selectedSearchScopes.length,
|
|
||||||
selectedLanguageModel,
|
|
||||||
])
|
|
||||||
|
|
||||||
const onSubmit = useCallback(() => {
|
const onSubmit = useCallback(() => {
|
||||||
if (isSubmitDisabled) {
|
|
||||||
if (isSubmitDisabledReason === "no-repos-selected") {
|
|
||||||
toast({
|
|
||||||
description: "⚠️ You must select at least one search scope",
|
|
||||||
variant: "destructive",
|
|
||||||
});
|
|
||||||
onContextSelectorOpenChanged(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_onSubmit(editor.children, editor);
|
_onSubmit(editor.children, editor);
|
||||||
}, [_onSubmit, editor, isSubmitDisabled, isSubmitDisabledReason, toast, onContextSelectorOpenChanged]);
|
}, [_onSubmit, editor]);
|
||||||
|
|
||||||
const onInsertSuggestion = useCallback((suggestion: Suggestion) => {
|
const onInsertSuggestion = useCallback((suggestion: Suggestion) => {
|
||||||
switch (suggestion.type) {
|
switch (suggestion.type) {
|
||||||
|
|
@ -310,39 +281,15 @@ export const ChatBox = ({
|
||||||
Stop
|
Stop
|
||||||
</Button>
|
</Button>
|
||||||
) : (
|
) : (
|
||||||
<Tooltip>
|
<Button
|
||||||
<TooltipTrigger asChild>
|
variant={isSubmitDisabled ? "outline" : "default"}
|
||||||
<div
|
size="sm"
|
||||||
onClick={() => {
|
className="w-6 h-6"
|
||||||
// @hack: When submission is disabled, we still want to issue
|
onClick={onSubmit}
|
||||||
// a warning to the user as to why the submission is disabled.
|
disabled={isSubmitDisabled}
|
||||||
// onSubmit on the Button will not be called because of the
|
>
|
||||||
// disabled prop, hence the call here.
|
<ArrowUp className="w-4 h-4" />
|
||||||
if (isSubmitDisabled) {
|
</Button>
|
||||||
onSubmit();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
variant={isSubmitDisabled ? "outline" : "default"}
|
|
||||||
size="sm"
|
|
||||||
className="w-6 h-6"
|
|
||||||
onClick={onSubmit}
|
|
||||||
disabled={isSubmitDisabled}
|
|
||||||
>
|
|
||||||
<ArrowUp className="w-4 h-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</TooltipTrigger>
|
|
||||||
{(isSubmitDisabled && isSubmitDisabledReason === "no-repos-selected") && (
|
|
||||||
<TooltipContent>
|
|
||||||
<div className="flex flex-row items-center">
|
|
||||||
<TriangleAlertIcon className="h-4 w-4 text-warning mr-1" />
|
|
||||||
<span className="text-destructive">You must select at least one search scope</span>
|
|
||||||
</div>
|
|
||||||
</TooltipContent>
|
|
||||||
)}
|
|
||||||
</Tooltip>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{suggestionMode !== "none" && (
|
{suggestionMode !== "none" && (
|
||||||
|
|
|
||||||
|
|
@ -321,7 +321,6 @@ export const ChatThread = ({
|
||||||
languageModels={languageModels}
|
languageModels={languageModels}
|
||||||
selectedSearchScopes={selectedSearchScopes}
|
selectedSearchScopes={selectedSearchScopes}
|
||||||
searchContexts={searchContexts}
|
searchContexts={searchContexts}
|
||||||
onContextSelectorOpenChanged={setIsContextSelectorOpen}
|
|
||||||
/>
|
/>
|
||||||
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
|
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
|
||||||
<ChatBoxToolbar
|
<ChatBoxToolbar
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue