Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Search context refactor to search scope and demo card UI changes. [#405](https://github.com/sourcebot-dev/sourcebot/pull/405)
- Add GitHub star toast. [#409](https://github.com/sourcebot-dev/sourcebot/pull/409)
- Added a onboarding modal when first visiting the homepage when `ask` mode is selected. [#408](https://github.com/sourcebot-dev/sourcebot/pull/408)
- [ask sb] Added `searchReposTool` and `listAllReposTool`. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

### Fixed
- Fixed multiple writes race condition on config file watcher. [#398](https://github.com/sourcebot-dev/sourcebot/pull/398)
Expand All@@ -21,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bumped AI SDK and associated packages version. [#404](https://github.com/sourcebot-dev/sourcebot/pull/404)
- Bumped form-data package version. [#407](https://github.com/sourcebot-dev/sourcebot/pull/407)
- Bumped next version. [#406](https://github.com/sourcebot-dev/sourcebot/pull/406)
- [ask sb] Improved search code tool with filter options. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)
- [ask sb] Removed search scope constraint. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

## [4.6.0] - 2025-07-25

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,7 +51,6 @@ export const NewChatPanel = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,7 +58,6 @@ export const AgenticSearch = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<Separator />
<div className="relative">
Expand Down
12 changes: 4 additions & 8 deletions packages/web/src/features/chat/agent.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ import { ProviderOptions } from "@ai-sdk/provider-utils";
import { createLogger } from "@sourcebot/logger";
import { LanguageModel, ModelMessage, StopCondition, streamText } from "ai";
import { ANSWER_TAG, FILE_REFERENCE_PREFIX, toolNames } from "./constants";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool } from "./tools";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool, searchReposTool, listAllReposTool } from "./tools";
import { FileSource, Source } from "./types";
import { addLineNumbers, fileReferenceToString } from "./utils";

Expand DownExpand Up@@ -54,6 +54,8 @@ export const createAgentStream = async ({
[toolNames.readFiles]: readFilesTool,
[toolNames.findSymbolReferences]: findSymbolReferencesTool,
[toolNames.findSymbolDefinitions]: findSymbolDefinitionsTool,
[toolNames.searchRepos]: searchReposTool,
[toolNames.listAllRepos]: listAllReposTool,
},
prepareStep: async ({ stepNumber }) => {
// The first step attaches any mentioned sources to the system prompt.
Expand DownExpand Up@@ -185,13 +187,7 @@ ${searchScopeRepoNames.map(repo => `- ${repo}`).join('\n')}
</available_repositories>

<research_phase_instructions>
During the research phase, you have these tools available:
- \`${toolNames.searchCode}\`: Search for code patterns, functions, or text across repositories
- \`${toolNames.readFiles}\`: Read the contents of specific files
- \`${toolNames.findSymbolReferences}\`: Find where symbols are referenced
- \`${toolNames.findSymbolDefinitions}\`: Find where symbols are defined

Use these tools to gather comprehensive context before answering. Always explain why you're using each tool.
During the research phase, use the tools available to you to gather comprehensive context before answering. Always explain why you're using each tool. Depending on the user's question, you may need to use multiple tools. If the question is vague, ask the user for more information.
</research_phase_instructions>

${answerInstructions}
Expand Down
83 changes: 15 additions & 68 deletions packages/web/src/features/chat/components/chatBox/chatBox.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,9 +5,10 @@ import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { CustomEditor, LanguageModelInfo, MentionElement, RenderElementPropsFor, SearchScope } from "@/features/chat/types";
import { insertMention, slateContentToString } from "@/features/chat/utils";
import { SearchContextQuery } from "@/lib/types";
import { cn, IS_MAC } from "@/lib/utils";
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 { useHotkeys } from "react-hotkeys-hook";
import { Descendant, insertText } from "slate";
Expand All@@ -17,8 +18,6 @@ import { SuggestionBox } from "./suggestionsBox";
import { Suggestion } from "./types";
import { useSuggestionModeAndQuery } from "./useSuggestionModeAndQuery";
import { useSuggestionsData } from "./useSuggestionsData";
import { useToast } from "@/components/hooks/use-toast";
import { SearchContextQuery } from "@/lib/types";

interface ChatBoxProps {
onSubmit: (children: Descendant[], editor: CustomEditor) => void;
Expand All@@ -30,7 +29,6 @@ interface ChatBoxProps {
languageModels: LanguageModelInfo[];
selectedSearchScopes: SearchScope[];
searchContexts: SearchContextQuery[];
onContextSelectorOpenChanged: (isOpen: boolean) => void;
}

export const ChatBox = ({
Expand All@@ -43,7 +41,6 @@ export const ChatBox = ({
languageModels,
selectedSearchScopes,
searchContexts,
onContextSelectorOpenChanged,
}: ChatBoxProps) => {
const suggestionsBoxRef = useRef<HTMLDivElement>(null);
const [index, setIndex] = useState(0);
Expand All@@ -70,7 +67,6 @@ export const ChatBox = ({
const { selectedLanguageModel } = useSelectedLanguageModel({
initialLanguageModel: languageModels.length > 0 ? languageModels[0] : undefined,
});
const { toast } = useToast();

// Reset the index when the suggestion mode changes.
useEffect(() => {
Expand DownExpand Up@@ -101,9 +97,9 @@ export const ChatBox = ({
return <Leaf {...props} />
}, []);

const { isSubmitDisabled, isSubmitDisabledReason } = useMemo((): {
const { isSubmitDisabled } = useMemo((): {
isSubmitDisabled: true,
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-repos-selected" | "no-language-model-selected"
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-language-model-selected"
} | {
isSubmitDisabled: false,
isSubmitDisabledReason: undefined,
Expand All@@ -129,13 +125,6 @@ export const ChatBox = ({
}
}

if (selectedSearchScopes.length === 0) {
return {
isSubmitDisabled: true,
isSubmitDisabledReason: "no-repos-selected",
}
}

if (selectedLanguageModel === undefined) {

return {
Expand All@@ -149,29 +138,11 @@ export const ChatBox = ({
isSubmitDisabledReason: undefined,
}

}, [
editor.children,
isRedirecting,
isGenerating,
selectedSearchScopes.length,
selectedLanguageModel,
])
}, [editor.children, isRedirecting, isGenerating, selectedLanguageModel])

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, isSubmitDisabled, isSubmitDisabledReason, toast, onContextSelectorOpenChanged]);
}, [_onSubmit, editor]);

const onInsertSuggestion = useCallback((suggestion: Suggestion) => {
switch (suggestion.type) {
Expand DownExpand Up@@ -310,39 +281,15 @@ export const ChatBox = ({
Stop
</Button>
) : (
<Tooltip>
<TooltipTrigger asChild>
<div
onClick={() => {
// @hack: When submission is disabled, we still want to issue
// a warning to the user as to why the submission is disabled.
// onSubmit on the Button will not be called because of the
// disabled prop, hence the call here.
if (isSubmitDisabled) {
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>
<Button
variant={isSubmitDisabled ? "outline" : "default"}
size="sm"
className="w-6 h-6"
onClick={onSubmit}
disabled={isSubmitDisabled}
>
<ArrowUp className="w-4 h-4" />
</Button>
)}
</div>
{suggestionMode !== "none" && (
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -321,7 +321,6 @@ export const ChatThread = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,8 @@ import { FindSymbolDefinitionsToolComponent } from './tools/findSymbolDefinition
import { FindSymbolReferencesToolComponent } from './tools/findSymbolReferencesToolComponent';
import { ReadFilesToolComponent } from './tools/readFilesToolComponent';
import { SearchCodeToolComponent } from './tools/searchCodeToolComponent';
import { SearchReposToolComponent } from './tools/searchReposToolComponent';
import { ListAllReposToolComponent } from './tools/listAllReposToolComponent';
import { SBChatMessageMetadata, SBChatMessagePart } from '../../types';
import { SearchScopeIcon } from '../searchScopeIcon';

Expand DownExpand Up@@ -63,7 +65,7 @@ export const DetailsCard = ({
{!isStreaming && (
<>
<Separator orientation="vertical" className="h-4" />
{metadata?.selectedSearchScopes && (
{(metadata?.selectedSearchScopes && metadata.selectedSearchScopes.length > 0) && (
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center text-xs cursor-help">
Expand DownExpand Up@@ -181,6 +183,20 @@ export const DetailsCard = ({
part={part}
/>
)
case 'tool-searchRepos':
return (
<SearchReposToolComponent
key={index}
part={part}
/>
)
case 'tool-listAllRepos':
return (
<ListAllReposToolComponent
key={index}
part={part}
/>
)
default:
return null;
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -221,7 +221,7 @@ export const ReferencedSourcesListView = ({
<span className="text-sm font-medium">{fileName}</span>
</div>
<div className="p-4 text-sm text-destructive bg-destructive/10 rounded border">
Failed to load file: {isServiceError(query.data) ? query.data.message : 'Unknown error'}
Failed to load file: {isServiceError(query.data) ? query.data.message : query.error?.message ?? 'Unknown error'}
</div>
</div>
);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
'use client';

import { ListAllReposToolUIPart } from "@/features/chat/tools";
import { isServiceError } from "@/lib/utils";
import { useMemo, useState } from "react";
import { ToolHeader, TreeList } from "./shared";
import { CodeSnippet } from "@/app/components/codeSnippet";
import { Separator } from "@/components/ui/separator";
import { FolderOpenIcon } from "lucide-react";

export const ListAllReposToolComponent = ({ part }: { part: ListAllReposToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Loading all repositories...';
case 'output-error':
return '"List all repositories" tool call failed';
case 'input-available':
case 'output-available':
return 'Listed all repositories';
}
}, [part]);

return (
<div className="my-4">
<ToolHeader
isLoading={part.state !== 'output-available' && part.state !== 'output-error'}
isError={part.state === 'output-error' || (part.state === 'output-available' && isServiceError(part.output))}
isExpanded={isExpanded}
label={label}
Icon={FolderOpenIcon}
onExpand={setIsExpanded}
/>
{part.state === 'output-available' && isExpanded && (
<>
{isServiceError(part.output) ? (
<TreeList>
<span>Failed with the following error: <CodeSnippet className="text-sm text-destructive">{part.output.message}</CodeSnippet></span>
</TreeList>
) : (
<>
{part.output.length === 0 ? (
<span className="text-sm text-muted-foreground ml-[25px]">No repositories found</span>
) : (
<TreeList>
<div className="text-sm text-muted-foreground mb-2">
Found {part.output.length} repositories:
</div>
{part.output.map((repoName, index) => (
<div key={index} className="flex items-center gap-2 text-sm">
<FolderOpenIcon className="h-4 w-4 text-muted-foreground" />
<span className="truncate">{repoName}</span>
</div>
))}
</TreeList>
)}
</>
)}
<Separator className='ml-[7px] my-2' />
</>
)}
</div>
)
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,24 +11,38 @@ import { SearchIcon } from "lucide-react";
import Link from "next/link";
import { SearchQueryParams } from "@/lib/types";
import { PlayIcon } from "@radix-ui/react-icons";

import { buildSearchQuery } from "@/features/chat/utils";

export const SearchCodeToolComponent = ({ part }: { part: SearchCodeToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);
const domain = useDomain();

const displayQuery = useMemo(() => {
if (part.state !== 'input-available' && part.state !== 'output-available') {
return '';
}

const query = buildSearchQuery({
query: part.input.queryRegexp,
repoNamesFilterRegexp: part.input.repoNamesFilterRegexp,
languageNamesFilter: part.input.languageNamesFilter,
fileNamesFilterRegexp: part.input.fileNamesFilterRegexp,
});

return query;
}, [part]);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Searching...';
case 'input-available':
return <span>Searching for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
case 'output-error':
return '"Search code" tool call failed';
case 'input-available':
case 'output-available':
return <span>Searched for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
return <span>Searched for <CodeSnippet>{displayQuery}</CodeSnippet></span>;
}
}, [part]);
}, [part, displayQuery]);

return (
<div className="my-4">
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all \u003cpre\u003e\u003ccode\u003e blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks"); } } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); } })(); (function(){ try { var __m = "github.com"; var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Search context refactor to search scope and demo card UI changes. [#405](https://github.com/sourcebot-dev/sourcebot/pull/405)
- Add GitHub star toast. [#409](https://github.com/sourcebot-dev/sourcebot/pull/409)
- Added a onboarding modal when first visiting the homepage when `ask` mode is selected. [#408](https://github.com/sourcebot-dev/sourcebot/pull/408)
- [ask sb] Added `searchReposTool` and `listAllReposTool`. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

### Fixed
- Fixed multiple writes race condition on config file watcher. [#398](https://github.com/sourcebot-dev/sourcebot/pull/398)
Expand All@@ -21,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bumped AI SDK and associated packages version. [#404](https://github.com/sourcebot-dev/sourcebot/pull/404)
- Bumped form-data package version. [#407](https://github.com/sourcebot-dev/sourcebot/pull/407)
- Bumped next version. [#406](https://github.com/sourcebot-dev/sourcebot/pull/406)
- [ask sb] Improved search code tool with filter options. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)
- [ask sb] Removed search scope constraint. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

## [4.6.0] - 2025-07-25

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,7 +51,6 @@ export const NewChatPanel = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,7 +58,6 @@ export const AgenticSearch = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<Separator />
<div className="relative">
Expand Down
12 changes: 4 additions & 8 deletions packages/web/src/features/chat/agent.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ import { ProviderOptions } from "@ai-sdk/provider-utils";
import { createLogger } from "@sourcebot/logger";
import { LanguageModel, ModelMessage, StopCondition, streamText } from "ai";
import { ANSWER_TAG, FILE_REFERENCE_PREFIX, toolNames } from "./constants";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool } from "./tools";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool, searchReposTool, listAllReposTool } from "./tools";
import { FileSource, Source } from "./types";
import { addLineNumbers, fileReferenceToString } from "./utils";

Expand DownExpand Up@@ -54,6 +54,8 @@ export const createAgentStream = async ({
[toolNames.readFiles]: readFilesTool,
[toolNames.findSymbolReferences]: findSymbolReferencesTool,
[toolNames.findSymbolDefinitions]: findSymbolDefinitionsTool,
[toolNames.searchRepos]: searchReposTool,
[toolNames.listAllRepos]: listAllReposTool,
},
prepareStep: async ({ stepNumber }) => {
// The first step attaches any mentioned sources to the system prompt.
Expand DownExpand Up@@ -185,13 +187,7 @@ ${searchScopeRepoNames.map(repo => `- ${repo}`).join('\n')}
</available_repositories>

<research_phase_instructions>
During the research phase, you have these tools available:
- \`${toolNames.searchCode}\`: Search for code patterns, functions, or text across repositories
- \`${toolNames.readFiles}\`: Read the contents of specific files
- \`${toolNames.findSymbolReferences}\`: Find where symbols are referenced
- \`${toolNames.findSymbolDefinitions}\`: Find where symbols are defined

Use these tools to gather comprehensive context before answering. Always explain why you're using each tool.
During the research phase, use the tools available to you to gather comprehensive context before answering. Always explain why you're using each tool. Depending on the user's question, you may need to use multiple tools. If the question is vague, ask the user for more information.
</research_phase_instructions>

${answerInstructions}
Expand Down
83 changes: 15 additions & 68 deletions packages/web/src/features/chat/components/chatBox/chatBox.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,9 +5,10 @@ import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { CustomEditor, LanguageModelInfo, MentionElement, RenderElementPropsFor, SearchScope } from "@/features/chat/types";
import { insertMention, slateContentToString } from "@/features/chat/utils";
import { SearchContextQuery } from "@/lib/types";
import { cn, IS_MAC } from "@/lib/utils";
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 { useHotkeys } from "react-hotkeys-hook";
import { Descendant, insertText } from "slate";
Expand All@@ -17,8 +18,6 @@ import { SuggestionBox } from "./suggestionsBox";
import { Suggestion } from "./types";
import { useSuggestionModeAndQuery } from "./useSuggestionModeAndQuery";
import { useSuggestionsData } from "./useSuggestionsData";
import { useToast } from "@/components/hooks/use-toast";
import { SearchContextQuery } from "@/lib/types";

interface ChatBoxProps {
onSubmit: (children: Descendant[], editor: CustomEditor) => void;
Expand All@@ -30,7 +29,6 @@ interface ChatBoxProps {
languageModels: LanguageModelInfo[];
selectedSearchScopes: SearchScope[];
searchContexts: SearchContextQuery[];
onContextSelectorOpenChanged: (isOpen: boolean) => void;
}

export const ChatBox = ({
Expand All@@ -43,7 +41,6 @@ export const ChatBox = ({
languageModels,
selectedSearchScopes,
searchContexts,
onContextSelectorOpenChanged,
}: ChatBoxProps) => {
const suggestionsBoxRef = useRef<HTMLDivElement>(null);
const [index, setIndex] = useState(0);
Expand All@@ -70,7 +67,6 @@ export const ChatBox = ({
const { selectedLanguageModel } = useSelectedLanguageModel({
initialLanguageModel: languageModels.length > 0 ? languageModels[0] : undefined,
});
const { toast } = useToast();

// Reset the index when the suggestion mode changes.
useEffect(() => {
Expand DownExpand Up@@ -101,9 +97,9 @@ export const ChatBox = ({
return <Leaf {...props} />
}, []);

const { isSubmitDisabled, isSubmitDisabledReason } = useMemo((): {
const { isSubmitDisabled } = useMemo((): {
isSubmitDisabled: true,
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-repos-selected" | "no-language-model-selected"
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-language-model-selected"
} | {
isSubmitDisabled: false,
isSubmitDisabledReason: undefined,
Expand All@@ -129,13 +125,6 @@ export const ChatBox = ({
}
}

if (selectedSearchScopes.length === 0) {
return {
isSubmitDisabled: true,
isSubmitDisabledReason: "no-repos-selected",
}
}

if (selectedLanguageModel === undefined) {

return {
Expand All@@ -149,29 +138,11 @@ export const ChatBox = ({
isSubmitDisabledReason: undefined,
}

}, [
editor.children,
isRedirecting,
isGenerating,
selectedSearchScopes.length,
selectedLanguageModel,
])
}, [editor.children, isRedirecting, isGenerating, selectedLanguageModel])

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, isSubmitDisabled, isSubmitDisabledReason, toast, onContextSelectorOpenChanged]);
}, [_onSubmit, editor]);

const onInsertSuggestion = useCallback((suggestion: Suggestion) => {
switch (suggestion.type) {
Expand DownExpand Up@@ -310,39 +281,15 @@ export const ChatBox = ({
Stop
</Button>
) : (
<Tooltip>
<TooltipTrigger asChild>
<div
onClick={() => {
// @hack: When submission is disabled, we still want to issue
// a warning to the user as to why the submission is disabled.
// onSubmit on the Button will not be called because of the
// disabled prop, hence the call here.
if (isSubmitDisabled) {
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>
<Button
variant={isSubmitDisabled ? "outline" : "default"}
size="sm"
className="w-6 h-6"
onClick={onSubmit}
disabled={isSubmitDisabled}
>
<ArrowUp className="w-4 h-4" />
</Button>
)}
</div>
{suggestionMode !== "none" && (
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -321,7 +321,6 @@ export const ChatThread = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,8 @@ import { FindSymbolDefinitionsToolComponent } from './tools/findSymbolDefinition
import { FindSymbolReferencesToolComponent } from './tools/findSymbolReferencesToolComponent';
import { ReadFilesToolComponent } from './tools/readFilesToolComponent';
import { SearchCodeToolComponent } from './tools/searchCodeToolComponent';
import { SearchReposToolComponent } from './tools/searchReposToolComponent';
import { ListAllReposToolComponent } from './tools/listAllReposToolComponent';
import { SBChatMessageMetadata, SBChatMessagePart } from '../../types';
import { SearchScopeIcon } from '../searchScopeIcon';

Expand DownExpand Up@@ -63,7 +65,7 @@ export const DetailsCard = ({
{!isStreaming && (
<>
<Separator orientation="vertical" className="h-4" />
{metadata?.selectedSearchScopes && (
{(metadata?.selectedSearchScopes && metadata.selectedSearchScopes.length > 0) && (
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center text-xs cursor-help">
Expand DownExpand Up@@ -181,6 +183,20 @@ export const DetailsCard = ({
part={part}
/>
)
case 'tool-searchRepos':
return (
<SearchReposToolComponent
key={index}
part={part}
/>
)
case 'tool-listAllRepos':
return (
<ListAllReposToolComponent
key={index}
part={part}
/>
)
default:
return null;
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -221,7 +221,7 @@ export const ReferencedSourcesListView = ({
<span className="text-sm font-medium">{fileName}</span>
</div>
<div className="p-4 text-sm text-destructive bg-destructive/10 rounded border">
Failed to load file: {isServiceError(query.data) ? query.data.message : 'Unknown error'}
Failed to load file: {isServiceError(query.data) ? query.data.message : query.error?.message ?? 'Unknown error'}
</div>
</div>
);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
'use client';

import { ListAllReposToolUIPart } from "@/features/chat/tools";
import { isServiceError } from "@/lib/utils";
import { useMemo, useState } from "react";
import { ToolHeader, TreeList } from "./shared";
import { CodeSnippet } from "@/app/components/codeSnippet";
import { Separator } from "@/components/ui/separator";
import { FolderOpenIcon } from "lucide-react";

export const ListAllReposToolComponent = ({ part }: { part: ListAllReposToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Loading all repositories...';
case 'output-error':
return '"List all repositories" tool call failed';
case 'input-available':
case 'output-available':
return 'Listed all repositories';
}
}, [part]);

return (
<div className="my-4">
<ToolHeader
isLoading={part.state !== 'output-available' && part.state !== 'output-error'}
isError={part.state === 'output-error' || (part.state === 'output-available' && isServiceError(part.output))}
isExpanded={isExpanded}
label={label}
Icon={FolderOpenIcon}
onExpand={setIsExpanded}
/>
{part.state === 'output-available' && isExpanded && (
<>
{isServiceError(part.output) ? (
<TreeList>
<span>Failed with the following error: <CodeSnippet className="text-sm text-destructive">{part.output.message}</CodeSnippet></span>
</TreeList>
) : (
<>
{part.output.length === 0 ? (
<span className="text-sm text-muted-foreground ml-[25px]">No repositories found</span>
) : (
<TreeList>
<div className="text-sm text-muted-foreground mb-2">
Found {part.output.length} repositories:
</div>
{part.output.map((repoName, index) => (
<div key={index} className="flex items-center gap-2 text-sm">
<FolderOpenIcon className="h-4 w-4 text-muted-foreground" />
<span className="truncate">{repoName}</span>
</div>
))}
</TreeList>
)}
</>
)}
<Separator className='ml-[7px] my-2' />
</>
)}
</div>
)
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,24 +11,38 @@ import { SearchIcon } from "lucide-react";
import Link from "next/link";
import { SearchQueryParams } from "@/lib/types";
import { PlayIcon } from "@radix-ui/react-icons";

import { buildSearchQuery } from "@/features/chat/utils";

export const SearchCodeToolComponent = ({ part }: { part: SearchCodeToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);
const domain = useDomain();

const displayQuery = useMemo(() => {
if (part.state !== 'input-available' && part.state !== 'output-available') {
return '';
}

const query = buildSearchQuery({
query: part.input.queryRegexp,
repoNamesFilterRegexp: part.input.repoNamesFilterRegexp,
languageNamesFilter: part.input.languageNamesFilter,
fileNamesFilterRegexp: part.input.fileNamesFilterRegexp,
});

return query;
}, [part]);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Searching...';
case 'input-available':
return <span>Searching for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
case 'output-error':
return '"Search code" tool call failed';
case 'input-available':
case 'output-available':
return <span>Searched for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
return <span>Searched for <CodeSnippet>{displayQuery}</CodeSnippet></span>;
}
}, [part]);
}, [part, displayQuery]);

return (
<div className="my-4">
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Search context refactor to search scope and demo card UI changes. [#405](https://github.com/sourcebot-dev/sourcebot/pull/405)
- Add GitHub star toast. [#409](https://github.com/sourcebot-dev/sourcebot/pull/409)
- Added a onboarding modal when first visiting the homepage when `ask` mode is selected. [#408](https://github.com/sourcebot-dev/sourcebot/pull/408)
- [ask sb] Added `searchReposTool` and `listAllReposTool`. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

### Fixed
- Fixed multiple writes race condition on config file watcher. [#398](https://github.com/sourcebot-dev/sourcebot/pull/398)
Expand All@@ -21,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bumped AI SDK and associated packages version. [#404](https://github.com/sourcebot-dev/sourcebot/pull/404)
- Bumped form-data package version. [#407](https://github.com/sourcebot-dev/sourcebot/pull/407)
- Bumped next version. [#406](https://github.com/sourcebot-dev/sourcebot/pull/406)
- [ask sb] Improved search code tool with filter options. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)
- [ask sb] Removed search scope constraint. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

## [4.6.0] - 2025-07-25

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,7 +51,6 @@ export const NewChatPanel = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,7 +58,6 @@ export const AgenticSearch = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<Separator />
<div className="relative">
Expand Down
12 changes: 4 additions & 8 deletions packages/web/src/features/chat/agent.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ import { ProviderOptions } from "@ai-sdk/provider-utils";
import { createLogger } from "@sourcebot/logger";
import { LanguageModel, ModelMessage, StopCondition, streamText } from "ai";
import { ANSWER_TAG, FILE_REFERENCE_PREFIX, toolNames } from "./constants";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool } from "./tools";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool, searchReposTool, listAllReposTool } from "./tools";
import { FileSource, Source } from "./types";
import { addLineNumbers, fileReferenceToString } from "./utils";

Expand DownExpand Up@@ -54,6 +54,8 @@ export const createAgentStream = async ({
[toolNames.readFiles]: readFilesTool,
[toolNames.findSymbolReferences]: findSymbolReferencesTool,
[toolNames.findSymbolDefinitions]: findSymbolDefinitionsTool,
[toolNames.searchRepos]: searchReposTool,
[toolNames.listAllRepos]: listAllReposTool,
},
prepareStep: async ({ stepNumber }) => {
// The first step attaches any mentioned sources to the system prompt.
Expand DownExpand Up@@ -185,13 +187,7 @@ ${searchScopeRepoNames.map(repo => `- ${repo}`).join('\n')}
</available_repositories>

<research_phase_instructions>
During the research phase, you have these tools available:
- \`${toolNames.searchCode}\`: Search for code patterns, functions, or text across repositories
- \`${toolNames.readFiles}\`: Read the contents of specific files
- \`${toolNames.findSymbolReferences}\`: Find where symbols are referenced
- \`${toolNames.findSymbolDefinitions}\`: Find where symbols are defined

Use these tools to gather comprehensive context before answering. Always explain why you're using each tool.
During the research phase, use the tools available to you to gather comprehensive context before answering. Always explain why you're using each tool. Depending on the user's question, you may need to use multiple tools. If the question is vague, ask the user for more information.
</research_phase_instructions>

${answerInstructions}
Expand Down
83 changes: 15 additions & 68 deletions packages/web/src/features/chat/components/chatBox/chatBox.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,9 +5,10 @@ import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { CustomEditor, LanguageModelInfo, MentionElement, RenderElementPropsFor, SearchScope } from "@/features/chat/types";
import { insertMention, slateContentToString } from "@/features/chat/utils";
import { SearchContextQuery } from "@/lib/types";
import { cn, IS_MAC } from "@/lib/utils";
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 { useHotkeys } from "react-hotkeys-hook";
import { Descendant, insertText } from "slate";
Expand All@@ -17,8 +18,6 @@ import { SuggestionBox } from "./suggestionsBox";
import { Suggestion } from "./types";
import { useSuggestionModeAndQuery } from "./useSuggestionModeAndQuery";
import { useSuggestionsData } from "./useSuggestionsData";
import { useToast } from "@/components/hooks/use-toast";
import { SearchContextQuery } from "@/lib/types";

interface ChatBoxProps {
onSubmit: (children: Descendant[], editor: CustomEditor) => void;
Expand All@@ -30,7 +29,6 @@ interface ChatBoxProps {
languageModels: LanguageModelInfo[];
selectedSearchScopes: SearchScope[];
searchContexts: SearchContextQuery[];
onContextSelectorOpenChanged: (isOpen: boolean) => void;
}

export const ChatBox = ({
Expand All@@ -43,7 +41,6 @@ export const ChatBox = ({
languageModels,
selectedSearchScopes,
searchContexts,
onContextSelectorOpenChanged,
}: ChatBoxProps) => {
const suggestionsBoxRef = useRef<HTMLDivElement>(null);
const [index, setIndex] = useState(0);
Expand All@@ -70,7 +67,6 @@ export const ChatBox = ({
const { selectedLanguageModel } = useSelectedLanguageModel({
initialLanguageModel: languageModels.length > 0 ? languageModels[0] : undefined,
});
const { toast } = useToast();

// Reset the index when the suggestion mode changes.
useEffect(() => {
Expand DownExpand Up@@ -101,9 +97,9 @@ export const ChatBox = ({
return <Leaf {...props} />
}, []);

const { isSubmitDisabled, isSubmitDisabledReason } = useMemo((): {
const { isSubmitDisabled } = useMemo((): {
isSubmitDisabled: true,
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-repos-selected" | "no-language-model-selected"
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-language-model-selected"
} | {
isSubmitDisabled: false,
isSubmitDisabledReason: undefined,
Expand All@@ -129,13 +125,6 @@ export const ChatBox = ({
}
}

if (selectedSearchScopes.length === 0) {
return {
isSubmitDisabled: true,
isSubmitDisabledReason: "no-repos-selected",
}
}

if (selectedLanguageModel === undefined) {

return {
Expand All@@ -149,29 +138,11 @@ export const ChatBox = ({
isSubmitDisabledReason: undefined,
}

}, [
editor.children,
isRedirecting,
isGenerating,
selectedSearchScopes.length,
selectedLanguageModel,
])
}, [editor.children, isRedirecting, isGenerating, selectedLanguageModel])

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, isSubmitDisabled, isSubmitDisabledReason, toast, onContextSelectorOpenChanged]);
}, [_onSubmit, editor]);

const onInsertSuggestion = useCallback((suggestion: Suggestion) => {
switch (suggestion.type) {
Expand DownExpand Up@@ -310,39 +281,15 @@ export const ChatBox = ({
Stop
</Button>
) : (
<Tooltip>
<TooltipTrigger asChild>
<div
onClick={() => {
// @hack: When submission is disabled, we still want to issue
// a warning to the user as to why the submission is disabled.
// onSubmit on the Button will not be called because of the
// disabled prop, hence the call here.
if (isSubmitDisabled) {
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>
<Button
variant={isSubmitDisabled ? "outline" : "default"}
size="sm"
className="w-6 h-6"
onClick={onSubmit}
disabled={isSubmitDisabled}
>
<ArrowUp className="w-4 h-4" />
</Button>
)}
</div>
{suggestionMode !== "none" && (
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -321,7 +321,6 @@ export const ChatThread = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,8 @@ import { FindSymbolDefinitionsToolComponent } from './tools/findSymbolDefinition
import { FindSymbolReferencesToolComponent } from './tools/findSymbolReferencesToolComponent';
import { ReadFilesToolComponent } from './tools/readFilesToolComponent';
import { SearchCodeToolComponent } from './tools/searchCodeToolComponent';
import { SearchReposToolComponent } from './tools/searchReposToolComponent';
import { ListAllReposToolComponent } from './tools/listAllReposToolComponent';
import { SBChatMessageMetadata, SBChatMessagePart } from '../../types';
import { SearchScopeIcon } from '../searchScopeIcon';

Expand DownExpand Up@@ -63,7 +65,7 @@ export const DetailsCard = ({
{!isStreaming && (
<>
<Separator orientation="vertical" className="h-4" />
{metadata?.selectedSearchScopes && (
{(metadata?.selectedSearchScopes && metadata.selectedSearchScopes.length > 0) && (
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center text-xs cursor-help">
Expand DownExpand Up@@ -181,6 +183,20 @@ export const DetailsCard = ({
part={part}
/>
)
case 'tool-searchRepos':
return (
<SearchReposToolComponent
key={index}
part={part}
/>
)
case 'tool-listAllRepos':
return (
<ListAllReposToolComponent
key={index}
part={part}
/>
)
default:
return null;
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -221,7 +221,7 @@ export const ReferencedSourcesListView = ({
<span className="text-sm font-medium">{fileName}</span>
</div>
<div className="p-4 text-sm text-destructive bg-destructive/10 rounded border">
Failed to load file: {isServiceError(query.data) ? query.data.message : 'Unknown error'}
Failed to load file: {isServiceError(query.data) ? query.data.message : query.error?.message ?? 'Unknown error'}
</div>
</div>
);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
'use client';

import { ListAllReposToolUIPart } from "@/features/chat/tools";
import { isServiceError } from "@/lib/utils";
import { useMemo, useState } from "react";
import { ToolHeader, TreeList } from "./shared";
import { CodeSnippet } from "@/app/components/codeSnippet";
import { Separator } from "@/components/ui/separator";
import { FolderOpenIcon } from "lucide-react";

export const ListAllReposToolComponent = ({ part }: { part: ListAllReposToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Loading all repositories...';
case 'output-error':
return '"List all repositories" tool call failed';
case 'input-available':
case 'output-available':
return 'Listed all repositories';
}
}, [part]);

return (
<div className="my-4">
<ToolHeader
isLoading={part.state !== 'output-available' && part.state !== 'output-error'}
isError={part.state === 'output-error' || (part.state === 'output-available' && isServiceError(part.output))}
isExpanded={isExpanded}
label={label}
Icon={FolderOpenIcon}
onExpand={setIsExpanded}
/>
{part.state === 'output-available' && isExpanded && (
<>
{isServiceError(part.output) ? (
<TreeList>
<span>Failed with the following error: <CodeSnippet className="text-sm text-destructive">{part.output.message}</CodeSnippet></span>
</TreeList>
) : (
<>
{part.output.length === 0 ? (
<span className="text-sm text-muted-foreground ml-[25px]">No repositories found</span>
) : (
<TreeList>
<div className="text-sm text-muted-foreground mb-2">
Found {part.output.length} repositories:
</div>
{part.output.map((repoName, index) => (
<div key={index} className="flex items-center gap-2 text-sm">
<FolderOpenIcon className="h-4 w-4 text-muted-foreground" />
<span className="truncate">{repoName}</span>
</div>
))}
</TreeList>
)}
</>
)}
<Separator className='ml-[7px] my-2' />
</>
)}
</div>
)
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,24 +11,38 @@ import { SearchIcon } from "lucide-react";
import Link from "next/link";
import { SearchQueryParams } from "@/lib/types";
import { PlayIcon } from "@radix-ui/react-icons";

import { buildSearchQuery } from "@/features/chat/utils";

export const SearchCodeToolComponent = ({ part }: { part: SearchCodeToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);
const domain = useDomain();

const displayQuery = useMemo(() => {
if (part.state !== 'input-available' && part.state !== 'output-available') {
return '';
}

const query = buildSearchQuery({
query: part.input.queryRegexp,
repoNamesFilterRegexp: part.input.repoNamesFilterRegexp,
languageNamesFilter: part.input.languageNamesFilter,
fileNamesFilterRegexp: part.input.fileNamesFilterRegexp,
});

return query;
}, [part]);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Searching...';
case 'input-available':
return <span>Searching for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
case 'output-error':
return '"Search code" tool call failed';
case 'input-available':
case 'output-available':
return <span>Searched for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
return <span>Searched for <CodeSnippet>{displayQuery}</CodeSnippet></span>;
}
}, [part]);
}, [part, displayQuery]);

return (
<div className="my-4">
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length \u003e 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Search context refactor to search scope and demo card UI changes. [#405](https://github.com/sourcebot-dev/sourcebot/pull/405)
- Add GitHub star toast. [#409](https://github.com/sourcebot-dev/sourcebot/pull/409)
- Added a onboarding modal when first visiting the homepage when `ask` mode is selected. [#408](https://github.com/sourcebot-dev/sourcebot/pull/408)
- [ask sb] Added `searchReposTool` and `listAllReposTool`. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

### Fixed
- Fixed multiple writes race condition on config file watcher. [#398](https://github.com/sourcebot-dev/sourcebot/pull/398)
Expand All@@ -21,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bumped AI SDK and associated packages version. [#404](https://github.com/sourcebot-dev/sourcebot/pull/404)
- Bumped form-data package version. [#407](https://github.com/sourcebot-dev/sourcebot/pull/407)
- Bumped next version. [#406](https://github.com/sourcebot-dev/sourcebot/pull/406)
- [ask sb] Improved search code tool with filter options. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)
- [ask sb] Removed search scope constraint. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

## [4.6.0] - 2025-07-25

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,7 +51,6 @@ export const NewChatPanel = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,7 +58,6 @@ export const AgenticSearch = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<Separator />
<div className="relative">
Expand Down
12 changes: 4 additions & 8 deletions packages/web/src/features/chat/agent.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ import { ProviderOptions } from "@ai-sdk/provider-utils";
import { createLogger } from "@sourcebot/logger";
import { LanguageModel, ModelMessage, StopCondition, streamText } from "ai";
import { ANSWER_TAG, FILE_REFERENCE_PREFIX, toolNames } from "./constants";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool } from "./tools";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool, searchReposTool, listAllReposTool } from "./tools";
import { FileSource, Source } from "./types";
import { addLineNumbers, fileReferenceToString } from "./utils";

Expand DownExpand Up@@ -54,6 +54,8 @@ export const createAgentStream = async ({
[toolNames.readFiles]: readFilesTool,
[toolNames.findSymbolReferences]: findSymbolReferencesTool,
[toolNames.findSymbolDefinitions]: findSymbolDefinitionsTool,
[toolNames.searchRepos]: searchReposTool,
[toolNames.listAllRepos]: listAllReposTool,
},
prepareStep: async ({ stepNumber }) => {
// The first step attaches any mentioned sources to the system prompt.
Expand DownExpand Up@@ -185,13 +187,7 @@ ${searchScopeRepoNames.map(repo => `- ${repo}`).join('\n')}
</available_repositories>

<research_phase_instructions>
During the research phase, you have these tools available:
- \`${toolNames.searchCode}\`: Search for code patterns, functions, or text across repositories
- \`${toolNames.readFiles}\`: Read the contents of specific files
- \`${toolNames.findSymbolReferences}\`: Find where symbols are referenced
- \`${toolNames.findSymbolDefinitions}\`: Find where symbols are defined

Use these tools to gather comprehensive context before answering. Always explain why you're using each tool.
During the research phase, use the tools available to you to gather comprehensive context before answering. Always explain why you're using each tool. Depending on the user's question, you may need to use multiple tools. If the question is vague, ask the user for more information.
</research_phase_instructions>

${answerInstructions}
Expand Down
83 changes: 15 additions & 68 deletions packages/web/src/features/chat/components/chatBox/chatBox.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,9 +5,10 @@ import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { CustomEditor, LanguageModelInfo, MentionElement, RenderElementPropsFor, SearchScope } from "@/features/chat/types";
import { insertMention, slateContentToString } from "@/features/chat/utils";
import { SearchContextQuery } from "@/lib/types";
import { cn, IS_MAC } from "@/lib/utils";
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 { useHotkeys } from "react-hotkeys-hook";
import { Descendant, insertText } from "slate";
Expand All@@ -17,8 +18,6 @@ import { SuggestionBox } from "./suggestionsBox";
import { Suggestion } from "./types";
import { useSuggestionModeAndQuery } from "./useSuggestionModeAndQuery";
import { useSuggestionsData } from "./useSuggestionsData";
import { useToast } from "@/components/hooks/use-toast";
import { SearchContextQuery } from "@/lib/types";

interface ChatBoxProps {
onSubmit: (children: Descendant[], editor: CustomEditor) => void;
Expand All@@ -30,7 +29,6 @@ interface ChatBoxProps {
languageModels: LanguageModelInfo[];
selectedSearchScopes: SearchScope[];
searchContexts: SearchContextQuery[];
onContextSelectorOpenChanged: (isOpen: boolean) => void;
}

export const ChatBox = ({
Expand All@@ -43,7 +41,6 @@ export const ChatBox = ({
languageModels,
selectedSearchScopes,
searchContexts,
onContextSelectorOpenChanged,
}: ChatBoxProps) => {
const suggestionsBoxRef = useRef<HTMLDivElement>(null);
const [index, setIndex] = useState(0);
Expand All@@ -70,7 +67,6 @@ export const ChatBox = ({
const { selectedLanguageModel } = useSelectedLanguageModel({
initialLanguageModel: languageModels.length > 0 ? languageModels[0] : undefined,
});
const { toast } = useToast();

// Reset the index when the suggestion mode changes.
useEffect(() => {
Expand DownExpand Up@@ -101,9 +97,9 @@ export const ChatBox = ({
return <Leaf {...props} />
}, []);

const { isSubmitDisabled, isSubmitDisabledReason } = useMemo((): {
const { isSubmitDisabled } = useMemo((): {
isSubmitDisabled: true,
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-repos-selected" | "no-language-model-selected"
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-language-model-selected"
} | {
isSubmitDisabled: false,
isSubmitDisabledReason: undefined,
Expand All@@ -129,13 +125,6 @@ export const ChatBox = ({
}
}

if (selectedSearchScopes.length === 0) {
return {
isSubmitDisabled: true,
isSubmitDisabledReason: "no-repos-selected",
}
}

if (selectedLanguageModel === undefined) {

return {
Expand All@@ -149,29 +138,11 @@ export const ChatBox = ({
isSubmitDisabledReason: undefined,
}

}, [
editor.children,
isRedirecting,
isGenerating,
selectedSearchScopes.length,
selectedLanguageModel,
])
}, [editor.children, isRedirecting, isGenerating, selectedLanguageModel])

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, isSubmitDisabled, isSubmitDisabledReason, toast, onContextSelectorOpenChanged]);
}, [_onSubmit, editor]);

const onInsertSuggestion = useCallback((suggestion: Suggestion) => {
switch (suggestion.type) {
Expand DownExpand Up@@ -310,39 +281,15 @@ export const ChatBox = ({
Stop
</Button>
) : (
<Tooltip>
<TooltipTrigger asChild>
<div
onClick={() => {
// @hack: When submission is disabled, we still want to issue
// a warning to the user as to why the submission is disabled.
// onSubmit on the Button will not be called because of the
// disabled prop, hence the call here.
if (isSubmitDisabled) {
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>
<Button
variant={isSubmitDisabled ? "outline" : "default"}
size="sm"
className="w-6 h-6"
onClick={onSubmit}
disabled={isSubmitDisabled}
>
<ArrowUp className="w-4 h-4" />
</Button>
)}
</div>
{suggestionMode !== "none" && (
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -321,7 +321,6 @@ export const ChatThread = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,8 @@ import { FindSymbolDefinitionsToolComponent } from './tools/findSymbolDefinition
import { FindSymbolReferencesToolComponent } from './tools/findSymbolReferencesToolComponent';
import { ReadFilesToolComponent } from './tools/readFilesToolComponent';
import { SearchCodeToolComponent } from './tools/searchCodeToolComponent';
import { SearchReposToolComponent } from './tools/searchReposToolComponent';
import { ListAllReposToolComponent } from './tools/listAllReposToolComponent';
import { SBChatMessageMetadata, SBChatMessagePart } from '../../types';
import { SearchScopeIcon } from '../searchScopeIcon';

Expand DownExpand Up@@ -63,7 +65,7 @@ export const DetailsCard = ({
{!isStreaming && (
<>
<Separator orientation="vertical" className="h-4" />
{metadata?.selectedSearchScopes && (
{(metadata?.selectedSearchScopes && metadata.selectedSearchScopes.length > 0) && (
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center text-xs cursor-help">
Expand DownExpand Up@@ -181,6 +183,20 @@ export const DetailsCard = ({
part={part}
/>
)
case 'tool-searchRepos':
return (
<SearchReposToolComponent
key={index}
part={part}
/>
)
case 'tool-listAllRepos':
return (
<ListAllReposToolComponent
key={index}
part={part}
/>
)
default:
return null;
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -221,7 +221,7 @@ export const ReferencedSourcesListView = ({
<span className="text-sm font-medium">{fileName}</span>
</div>
<div className="p-4 text-sm text-destructive bg-destructive/10 rounded border">
Failed to load file: {isServiceError(query.data) ? query.data.message : 'Unknown error'}
Failed to load file: {isServiceError(query.data) ? query.data.message : query.error?.message ?? 'Unknown error'}
</div>
</div>
);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
'use client';

import { ListAllReposToolUIPart } from "@/features/chat/tools";
import { isServiceError } from "@/lib/utils";
import { useMemo, useState } from "react";
import { ToolHeader, TreeList } from "./shared";
import { CodeSnippet } from "@/app/components/codeSnippet";
import { Separator } from "@/components/ui/separator";
import { FolderOpenIcon } from "lucide-react";

export const ListAllReposToolComponent = ({ part }: { part: ListAllReposToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Loading all repositories...';
case 'output-error':
return '"List all repositories" tool call failed';
case 'input-available':
case 'output-available':
return 'Listed all repositories';
}
}, [part]);

return (
<div className="my-4">
<ToolHeader
isLoading={part.state !== 'output-available' && part.state !== 'output-error'}
isError={part.state === 'output-error' || (part.state === 'output-available' && isServiceError(part.output))}
isExpanded={isExpanded}
label={label}
Icon={FolderOpenIcon}
onExpand={setIsExpanded}
/>
{part.state === 'output-available' && isExpanded && (
<>
{isServiceError(part.output) ? (
<TreeList>
<span>Failed with the following error: <CodeSnippet className="text-sm text-destructive">{part.output.message}</CodeSnippet></span>
</TreeList>
) : (
<>
{part.output.length === 0 ? (
<span className="text-sm text-muted-foreground ml-[25px]">No repositories found</span>
) : (
<TreeList>
<div className="text-sm text-muted-foreground mb-2">
Found {part.output.length} repositories:
</div>
{part.output.map((repoName, index) => (
<div key={index} className="flex items-center gap-2 text-sm">
<FolderOpenIcon className="h-4 w-4 text-muted-foreground" />
<span className="truncate">{repoName}</span>
</div>
))}
</TreeList>
)}
</>
)}
<Separator className='ml-[7px] my-2' />
</>
)}
</div>
)
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,24 +11,38 @@ import { SearchIcon } from "lucide-react";
import Link from "next/link";
import { SearchQueryParams } from "@/lib/types";
import { PlayIcon } from "@radix-ui/react-icons";

import { buildSearchQuery } from "@/features/chat/utils";

export const SearchCodeToolComponent = ({ part }: { part: SearchCodeToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);
const domain = useDomain();

const displayQuery = useMemo(() => {
if (part.state !== 'input-available' && part.state !== 'output-available') {
return '';
}

const query = buildSearchQuery({
query: part.input.queryRegexp,
repoNamesFilterRegexp: part.input.repoNamesFilterRegexp,
languageNamesFilter: part.input.languageNamesFilter,
fileNamesFilterRegexp: part.input.fileNamesFilterRegexp,
});

return query;
}, [part]);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Searching...';
case 'input-available':
return <span>Searching for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
case 'output-error':
return '"Search code" tool call failed';
case 'input-available':
case 'output-available':
return <span>Searched for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
return <span>Searched for <CodeSnippet>{displayQuery}</CodeSnippet></span>;
}
}, [part]);
}, [part, displayQuery]);

return (
<div className="my-4">
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Search context refactor to search scope and demo card UI changes. [#405](https://github.com/sourcebot-dev/sourcebot/pull/405)
- Add GitHub star toast. [#409](https://github.com/sourcebot-dev/sourcebot/pull/409)
- Added a onboarding modal when first visiting the homepage when `ask` mode is selected. [#408](https://github.com/sourcebot-dev/sourcebot/pull/408)
- [ask sb] Added `searchReposTool` and `listAllReposTool`. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

### Fixed
- Fixed multiple writes race condition on config file watcher. [#398](https://github.com/sourcebot-dev/sourcebot/pull/398)
Expand All@@ -21,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bumped AI SDK and associated packages version. [#404](https://github.com/sourcebot-dev/sourcebot/pull/404)
- Bumped form-data package version. [#407](https://github.com/sourcebot-dev/sourcebot/pull/407)
- Bumped next version. [#406](https://github.com/sourcebot-dev/sourcebot/pull/406)
- [ask sb] Improved search code tool with filter options. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)
- [ask sb] Removed search scope constraint. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

## [4.6.0] - 2025-07-25

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,7 +51,6 @@ export const NewChatPanel = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,7 +58,6 @@ export const AgenticSearch = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<Separator />
<div className="relative">
Expand Down
12 changes: 4 additions & 8 deletions packages/web/src/features/chat/agent.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ import { ProviderOptions } from "@ai-sdk/provider-utils";
import { createLogger } from "@sourcebot/logger";
import { LanguageModel, ModelMessage, StopCondition, streamText } from "ai";
import { ANSWER_TAG, FILE_REFERENCE_PREFIX, toolNames } from "./constants";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool } from "./tools";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool, searchReposTool, listAllReposTool } from "./tools";
import { FileSource, Source } from "./types";
import { addLineNumbers, fileReferenceToString } from "./utils";

Expand DownExpand Up@@ -54,6 +54,8 @@ export const createAgentStream = async ({
[toolNames.readFiles]: readFilesTool,
[toolNames.findSymbolReferences]: findSymbolReferencesTool,
[toolNames.findSymbolDefinitions]: findSymbolDefinitionsTool,
[toolNames.searchRepos]: searchReposTool,
[toolNames.listAllRepos]: listAllReposTool,
},
prepareStep: async ({ stepNumber }) => {
// The first step attaches any mentioned sources to the system prompt.
Expand DownExpand Up@@ -185,13 +187,7 @@ ${searchScopeRepoNames.map(repo => `- ${repo}`).join('\n')}
</available_repositories>

<research_phase_instructions>
During the research phase, you have these tools available:
- \`${toolNames.searchCode}\`: Search for code patterns, functions, or text across repositories
- \`${toolNames.readFiles}\`: Read the contents of specific files
- \`${toolNames.findSymbolReferences}\`: Find where symbols are referenced
- \`${toolNames.findSymbolDefinitions}\`: Find where symbols are defined

Use these tools to gather comprehensive context before answering. Always explain why you're using each tool.
During the research phase, use the tools available to you to gather comprehensive context before answering. Always explain why you're using each tool. Depending on the user's question, you may need to use multiple tools. If the question is vague, ask the user for more information.
</research_phase_instructions>

${answerInstructions}
Expand Down
83 changes: 15 additions & 68 deletions packages/web/src/features/chat/components/chatBox/chatBox.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,9 +5,10 @@ import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { CustomEditor, LanguageModelInfo, MentionElement, RenderElementPropsFor, SearchScope } from "@/features/chat/types";
import { insertMention, slateContentToString } from "@/features/chat/utils";
import { SearchContextQuery } from "@/lib/types";
import { cn, IS_MAC } from "@/lib/utils";
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 { useHotkeys } from "react-hotkeys-hook";
import { Descendant, insertText } from "slate";
Expand All@@ -17,8 +18,6 @@ import { SuggestionBox } from "./suggestionsBox";
import { Suggestion } from "./types";
import { useSuggestionModeAndQuery } from "./useSuggestionModeAndQuery";
import { useSuggestionsData } from "./useSuggestionsData";
import { useToast } from "@/components/hooks/use-toast";
import { SearchContextQuery } from "@/lib/types";

interface ChatBoxProps {
onSubmit: (children: Descendant[], editor: CustomEditor) => void;
Expand All@@ -30,7 +29,6 @@ interface ChatBoxProps {
languageModels: LanguageModelInfo[];
selectedSearchScopes: SearchScope[];
searchContexts: SearchContextQuery[];
onContextSelectorOpenChanged: (isOpen: boolean) => void;
}

export const ChatBox = ({
Expand All@@ -43,7 +41,6 @@ export const ChatBox = ({
languageModels,
selectedSearchScopes,
searchContexts,
onContextSelectorOpenChanged,
}: ChatBoxProps) => {
const suggestionsBoxRef = useRef<HTMLDivElement>(null);
const [index, setIndex] = useState(0);
Expand All@@ -70,7 +67,6 @@ export const ChatBox = ({
const { selectedLanguageModel } = useSelectedLanguageModel({
initialLanguageModel: languageModels.length > 0 ? languageModels[0] : undefined,
});
const { toast } = useToast();

// Reset the index when the suggestion mode changes.
useEffect(() => {
Expand DownExpand Up@@ -101,9 +97,9 @@ export const ChatBox = ({
return <Leaf {...props} />
}, []);

const { isSubmitDisabled, isSubmitDisabledReason } = useMemo((): {
const { isSubmitDisabled } = useMemo((): {
isSubmitDisabled: true,
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-repos-selected" | "no-language-model-selected"
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-language-model-selected"
} | {
isSubmitDisabled: false,
isSubmitDisabledReason: undefined,
Expand All@@ -129,13 +125,6 @@ export const ChatBox = ({
}
}

if (selectedSearchScopes.length === 0) {
return {
isSubmitDisabled: true,
isSubmitDisabledReason: "no-repos-selected",
}
}

if (selectedLanguageModel === undefined) {

return {
Expand All@@ -149,29 +138,11 @@ export const ChatBox = ({
isSubmitDisabledReason: undefined,
}

}, [
editor.children,
isRedirecting,
isGenerating,
selectedSearchScopes.length,
selectedLanguageModel,
])
}, [editor.children, isRedirecting, isGenerating, selectedLanguageModel])

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, isSubmitDisabled, isSubmitDisabledReason, toast, onContextSelectorOpenChanged]);
}, [_onSubmit, editor]);

const onInsertSuggestion = useCallback((suggestion: Suggestion) => {
switch (suggestion.type) {
Expand DownExpand Up@@ -310,39 +281,15 @@ export const ChatBox = ({
Stop
</Button>
) : (
<Tooltip>
<TooltipTrigger asChild>
<div
onClick={() => {
// @hack: When submission is disabled, we still want to issue
// a warning to the user as to why the submission is disabled.
// onSubmit on the Button will not be called because of the
// disabled prop, hence the call here.
if (isSubmitDisabled) {
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>
<Button
variant={isSubmitDisabled ? "outline" : "default"}
size="sm"
className="w-6 h-6"
onClick={onSubmit}
disabled={isSubmitDisabled}
>
<ArrowUp className="w-4 h-4" />
</Button>
)}
</div>
{suggestionMode !== "none" && (
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -321,7 +321,6 @@ export const ChatThread = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,8 @@ import { FindSymbolDefinitionsToolComponent } from './tools/findSymbolDefinition
import { FindSymbolReferencesToolComponent } from './tools/findSymbolReferencesToolComponent';
import { ReadFilesToolComponent } from './tools/readFilesToolComponent';
import { SearchCodeToolComponent } from './tools/searchCodeToolComponent';
import { SearchReposToolComponent } from './tools/searchReposToolComponent';
import { ListAllReposToolComponent } from './tools/listAllReposToolComponent';
import { SBChatMessageMetadata, SBChatMessagePart } from '../../types';
import { SearchScopeIcon } from '../searchScopeIcon';

Expand DownExpand Up@@ -63,7 +65,7 @@ export const DetailsCard = ({
{!isStreaming && (
<>
<Separator orientation="vertical" className="h-4" />
{metadata?.selectedSearchScopes && (
{(metadata?.selectedSearchScopes && metadata.selectedSearchScopes.length > 0) && (
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center text-xs cursor-help">
Expand DownExpand Up@@ -181,6 +183,20 @@ export const DetailsCard = ({
part={part}
/>
)
case 'tool-searchRepos':
return (
<SearchReposToolComponent
key={index}
part={part}
/>
)
case 'tool-listAllRepos':
return (
<ListAllReposToolComponent
key={index}
part={part}
/>
)
default:
return null;
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -221,7 +221,7 @@ export const ReferencedSourcesListView = ({
<span className="text-sm font-medium">{fileName}</span>
</div>
<div className="p-4 text-sm text-destructive bg-destructive/10 rounded border">
Failed to load file: {isServiceError(query.data) ? query.data.message : 'Unknown error'}
Failed to load file: {isServiceError(query.data) ? query.data.message : query.error?.message ?? 'Unknown error'}
</div>
</div>
);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
'use client';

import { ListAllReposToolUIPart } from "@/features/chat/tools";
import { isServiceError } from "@/lib/utils";
import { useMemo, useState } from "react";
import { ToolHeader, TreeList } from "./shared";
import { CodeSnippet } from "@/app/components/codeSnippet";
import { Separator } from "@/components/ui/separator";
import { FolderOpenIcon } from "lucide-react";

export const ListAllReposToolComponent = ({ part }: { part: ListAllReposToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Loading all repositories...';
case 'output-error':
return '"List all repositories" tool call failed';
case 'input-available':
case 'output-available':
return 'Listed all repositories';
}
}, [part]);

return (
<div className="my-4">
<ToolHeader
isLoading={part.state !== 'output-available' && part.state !== 'output-error'}
isError={part.state === 'output-error' || (part.state === 'output-available' && isServiceError(part.output))}
isExpanded={isExpanded}
label={label}
Icon={FolderOpenIcon}
onExpand={setIsExpanded}
/>
{part.state === 'output-available' && isExpanded && (
<>
{isServiceError(part.output) ? (
<TreeList>
<span>Failed with the following error: <CodeSnippet className="text-sm text-destructive">{part.output.message}</CodeSnippet></span>
</TreeList>
) : (
<>
{part.output.length === 0 ? (
<span className="text-sm text-muted-foreground ml-[25px]">No repositories found</span>
) : (
<TreeList>
<div className="text-sm text-muted-foreground mb-2">
Found {part.output.length} repositories:
</div>
{part.output.map((repoName, index) => (
<div key={index} className="flex items-center gap-2 text-sm">
<FolderOpenIcon className="h-4 w-4 text-muted-foreground" />
<span className="truncate">{repoName}</span>
</div>
))}
</TreeList>
)}
</>
)}
<Separator className='ml-[7px] my-2' />
</>
)}
</div>
)
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,24 +11,38 @@ import { SearchIcon } from "lucide-react";
import Link from "next/link";
import { SearchQueryParams } from "@/lib/types";
import { PlayIcon } from "@radix-ui/react-icons";

import { buildSearchQuery } from "@/features/chat/utils";

export const SearchCodeToolComponent = ({ part }: { part: SearchCodeToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);
const domain = useDomain();

const displayQuery = useMemo(() => {
if (part.state !== 'input-available' && part.state !== 'output-available') {
return '';
}

const query = buildSearchQuery({
query: part.input.queryRegexp,
repoNamesFilterRegexp: part.input.repoNamesFilterRegexp,
languageNamesFilter: part.input.languageNamesFilter,
fileNamesFilterRegexp: part.input.fileNamesFilterRegexp,
});

return query;
}, [part]);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Searching...';
case 'input-available':
return <span>Searching for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
case 'output-error':
return '"Search code" tool call failed';
case 'input-available':
case 'output-available':
return <span>Searched for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
return <span>Searched for <CodeSnippet>{displayQuery}</CodeSnippet></span>;
}
}, [part]);
}, [part, displayQuery]);

return (
<div className="my-4">
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Search context refactor to search scope and demo card UI changes. [#405](https://github.com/sourcebot-dev/sourcebot/pull/405)
- Add GitHub star toast. [#409](https://github.com/sourcebot-dev/sourcebot/pull/409)
- Added a onboarding modal when first visiting the homepage when `ask` mode is selected. [#408](https://github.com/sourcebot-dev/sourcebot/pull/408)
- [ask sb] Added `searchReposTool` and `listAllReposTool`. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

### Fixed
- Fixed multiple writes race condition on config file watcher. [#398](https://github.com/sourcebot-dev/sourcebot/pull/398)
Expand All@@ -21,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bumped AI SDK and associated packages version. [#404](https://github.com/sourcebot-dev/sourcebot/pull/404)
- Bumped form-data package version. [#407](https://github.com/sourcebot-dev/sourcebot/pull/407)
- Bumped next version. [#406](https://github.com/sourcebot-dev/sourcebot/pull/406)
- [ask sb] Improved search code tool with filter options. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)
- [ask sb] Removed search scope constraint. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

## [4.6.0] - 2025-07-25

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,7 +51,6 @@ export const NewChatPanel = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,7 +58,6 @@ export const AgenticSearch = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<Separator />
<div className="relative">
Expand Down
12 changes: 4 additions & 8 deletions packages/web/src/features/chat/agent.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ import { ProviderOptions } from "@ai-sdk/provider-utils";
import { createLogger } from "@sourcebot/logger";
import { LanguageModel, ModelMessage, StopCondition, streamText } from "ai";
import { ANSWER_TAG, FILE_REFERENCE_PREFIX, toolNames } from "./constants";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool } from "./tools";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool, searchReposTool, listAllReposTool } from "./tools";
import { FileSource, Source } from "./types";
import { addLineNumbers, fileReferenceToString } from "./utils";

Expand DownExpand Up@@ -54,6 +54,8 @@ export const createAgentStream = async ({
[toolNames.readFiles]: readFilesTool,
[toolNames.findSymbolReferences]: findSymbolReferencesTool,
[toolNames.findSymbolDefinitions]: findSymbolDefinitionsTool,
[toolNames.searchRepos]: searchReposTool,
[toolNames.listAllRepos]: listAllReposTool,
},
prepareStep: async ({ stepNumber }) => {
// The first step attaches any mentioned sources to the system prompt.
Expand DownExpand Up@@ -185,13 +187,7 @@ ${searchScopeRepoNames.map(repo => `- ${repo}`).join('\n')}
</available_repositories>

<research_phase_instructions>
During the research phase, you have these tools available:
- \`${toolNames.searchCode}\`: Search for code patterns, functions, or text across repositories
- \`${toolNames.readFiles}\`: Read the contents of specific files
- \`${toolNames.findSymbolReferences}\`: Find where symbols are referenced
- \`${toolNames.findSymbolDefinitions}\`: Find where symbols are defined

Use these tools to gather comprehensive context before answering. Always explain why you're using each tool.
During the research phase, use the tools available to you to gather comprehensive context before answering. Always explain why you're using each tool. Depending on the user's question, you may need to use multiple tools. If the question is vague, ask the user for more information.
</research_phase_instructions>

${answerInstructions}
Expand Down
83 changes: 15 additions & 68 deletions packages/web/src/features/chat/components/chatBox/chatBox.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,9 +5,10 @@ import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { CustomEditor, LanguageModelInfo, MentionElement, RenderElementPropsFor, SearchScope } from "@/features/chat/types";
import { insertMention, slateContentToString } from "@/features/chat/utils";
import { SearchContextQuery } from "@/lib/types";
import { cn, IS_MAC } from "@/lib/utils";
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 { useHotkeys } from "react-hotkeys-hook";
import { Descendant, insertText } from "slate";
Expand All@@ -17,8 +18,6 @@ import { SuggestionBox } from "./suggestionsBox";
import { Suggestion } from "./types";
import { useSuggestionModeAndQuery } from "./useSuggestionModeAndQuery";
import { useSuggestionsData } from "./useSuggestionsData";
import { useToast } from "@/components/hooks/use-toast";
import { SearchContextQuery } from "@/lib/types";

interface ChatBoxProps {
onSubmit: (children: Descendant[], editor: CustomEditor) => void;
Expand All@@ -30,7 +29,6 @@ interface ChatBoxProps {
languageModels: LanguageModelInfo[];
selectedSearchScopes: SearchScope[];
searchContexts: SearchContextQuery[];
onContextSelectorOpenChanged: (isOpen: boolean) => void;
}

export const ChatBox = ({
Expand All@@ -43,7 +41,6 @@ export const ChatBox = ({
languageModels,
selectedSearchScopes,
searchContexts,
onContextSelectorOpenChanged,
}: ChatBoxProps) => {
const suggestionsBoxRef = useRef<HTMLDivElement>(null);
const [index, setIndex] = useState(0);
Expand All@@ -70,7 +67,6 @@ export const ChatBox = ({
const { selectedLanguageModel } = useSelectedLanguageModel({
initialLanguageModel: languageModels.length > 0 ? languageModels[0] : undefined,
});
const { toast } = useToast();

// Reset the index when the suggestion mode changes.
useEffect(() => {
Expand DownExpand Up@@ -101,9 +97,9 @@ export const ChatBox = ({
return <Leaf {...props} />
}, []);

const { isSubmitDisabled, isSubmitDisabledReason } = useMemo((): {
const { isSubmitDisabled } = useMemo((): {
isSubmitDisabled: true,
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-repos-selected" | "no-language-model-selected"
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-language-model-selected"
} | {
isSubmitDisabled: false,
isSubmitDisabledReason: undefined,
Expand All@@ -129,13 +125,6 @@ export const ChatBox = ({
}
}

if (selectedSearchScopes.length === 0) {
return {
isSubmitDisabled: true,
isSubmitDisabledReason: "no-repos-selected",
}
}

if (selectedLanguageModel === undefined) {

return {
Expand All@@ -149,29 +138,11 @@ export const ChatBox = ({
isSubmitDisabledReason: undefined,
}

}, [
editor.children,
isRedirecting,
isGenerating,
selectedSearchScopes.length,
selectedLanguageModel,
])
}, [editor.children, isRedirecting, isGenerating, selectedLanguageModel])

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, isSubmitDisabled, isSubmitDisabledReason, toast, onContextSelectorOpenChanged]);
}, [_onSubmit, editor]);

const onInsertSuggestion = useCallback((suggestion: Suggestion) => {
switch (suggestion.type) {
Expand DownExpand Up@@ -310,39 +281,15 @@ export const ChatBox = ({
Stop
</Button>
) : (
<Tooltip>
<TooltipTrigger asChild>
<div
onClick={() => {
// @hack: When submission is disabled, we still want to issue
// a warning to the user as to why the submission is disabled.
// onSubmit on the Button will not be called because of the
// disabled prop, hence the call here.
if (isSubmitDisabled) {
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>
<Button
variant={isSubmitDisabled ? "outline" : "default"}
size="sm"
className="w-6 h-6"
onClick={onSubmit}
disabled={isSubmitDisabled}
>
<ArrowUp className="w-4 h-4" />
</Button>
)}
</div>
{suggestionMode !== "none" && (
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -321,7 +321,6 @@ export const ChatThread = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,8 @@ import { FindSymbolDefinitionsToolComponent } from './tools/findSymbolDefinition
import { FindSymbolReferencesToolComponent } from './tools/findSymbolReferencesToolComponent';
import { ReadFilesToolComponent } from './tools/readFilesToolComponent';
import { SearchCodeToolComponent } from './tools/searchCodeToolComponent';
import { SearchReposToolComponent } from './tools/searchReposToolComponent';
import { ListAllReposToolComponent } from './tools/listAllReposToolComponent';
import { SBChatMessageMetadata, SBChatMessagePart } from '../../types';
import { SearchScopeIcon } from '../searchScopeIcon';

Expand DownExpand Up@@ -63,7 +65,7 @@ export const DetailsCard = ({
{!isStreaming && (
<>
<Separator orientation="vertical" className="h-4" />
{metadata?.selectedSearchScopes && (
{(metadata?.selectedSearchScopes && metadata.selectedSearchScopes.length > 0) && (
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center text-xs cursor-help">
Expand DownExpand Up@@ -181,6 +183,20 @@ export const DetailsCard = ({
part={part}
/>
)
case 'tool-searchRepos':
return (
<SearchReposToolComponent
key={index}
part={part}
/>
)
case 'tool-listAllRepos':
return (
<ListAllReposToolComponent
key={index}
part={part}
/>
)
default:
return null;
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -221,7 +221,7 @@ export const ReferencedSourcesListView = ({
<span className="text-sm font-medium">{fileName}</span>
</div>
<div className="p-4 text-sm text-destructive bg-destructive/10 rounded border">
Failed to load file: {isServiceError(query.data) ? query.data.message : 'Unknown error'}
Failed to load file: {isServiceError(query.data) ? query.data.message : query.error?.message ?? 'Unknown error'}
</div>
</div>
);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
'use client';

import { ListAllReposToolUIPart } from "@/features/chat/tools";
import { isServiceError } from "@/lib/utils";
import { useMemo, useState } from "react";
import { ToolHeader, TreeList } from "./shared";
import { CodeSnippet } from "@/app/components/codeSnippet";
import { Separator } from "@/components/ui/separator";
import { FolderOpenIcon } from "lucide-react";

export const ListAllReposToolComponent = ({ part }: { part: ListAllReposToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Loading all repositories...';
case 'output-error':
return '"List all repositories" tool call failed';
case 'input-available':
case 'output-available':
return 'Listed all repositories';
}
}, [part]);

return (
<div className="my-4">
<ToolHeader
isLoading={part.state !== 'output-available' && part.state !== 'output-error'}
isError={part.state === 'output-error' || (part.state === 'output-available' && isServiceError(part.output))}
isExpanded={isExpanded}
label={label}
Icon={FolderOpenIcon}
onExpand={setIsExpanded}
/>
{part.state === 'output-available' && isExpanded && (
<>
{isServiceError(part.output) ? (
<TreeList>
<span>Failed with the following error: <CodeSnippet className="text-sm text-destructive">{part.output.message}</CodeSnippet></span>
</TreeList>
) : (
<>
{part.output.length === 0 ? (
<span className="text-sm text-muted-foreground ml-[25px]">No repositories found</span>
) : (
<TreeList>
<div className="text-sm text-muted-foreground mb-2">
Found {part.output.length} repositories:
</div>
{part.output.map((repoName, index) => (
<div key={index} className="flex items-center gap-2 text-sm">
<FolderOpenIcon className="h-4 w-4 text-muted-foreground" />
<span className="truncate">{repoName}</span>
</div>
))}
</TreeList>
)}
</>
)}
<Separator className='ml-[7px] my-2' />
</>
)}
</div>
)
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,24 +11,38 @@ import { SearchIcon } from "lucide-react";
import Link from "next/link";
import { SearchQueryParams } from "@/lib/types";
import { PlayIcon } from "@radix-ui/react-icons";

import { buildSearchQuery } from "@/features/chat/utils";

export const SearchCodeToolComponent = ({ part }: { part: SearchCodeToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);
const domain = useDomain();

const displayQuery = useMemo(() => {
if (part.state !== 'input-available' && part.state !== 'output-available') {
return '';
}

const query = buildSearchQuery({
query: part.input.queryRegexp,
repoNamesFilterRegexp: part.input.repoNamesFilterRegexp,
languageNamesFilter: part.input.languageNamesFilter,
fileNamesFilterRegexp: part.input.fileNamesFilterRegexp,
});

return query;
}, [part]);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Searching...';
case 'input-available':
return <span>Searching for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
case 'output-error':
return '"Search code" tool call failed';
case 'input-available':
case 'output-available':
return <span>Searched for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
return <span>Searched for <CodeSnippet>{displayQuery}</CodeSnippet></span>;
}
}, [part]);
}, [part, displayQuery]);

return (
<div className="my-4">
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Search context refactor to search scope and demo card UI changes. [#405](https://github.com/sourcebot-dev/sourcebot/pull/405)
- Add GitHub star toast. [#409](https://github.com/sourcebot-dev/sourcebot/pull/409)
- Added a onboarding modal when first visiting the homepage when `ask` mode is selected. [#408](https://github.com/sourcebot-dev/sourcebot/pull/408)
- [ask sb] Added `searchReposTool` and `listAllReposTool`. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

### Fixed
- Fixed multiple writes race condition on config file watcher. [#398](https://github.com/sourcebot-dev/sourcebot/pull/398)
Expand All@@ -21,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bumped AI SDK and associated packages version. [#404](https://github.com/sourcebot-dev/sourcebot/pull/404)
- Bumped form-data package version. [#407](https://github.com/sourcebot-dev/sourcebot/pull/407)
- Bumped next version. [#406](https://github.com/sourcebot-dev/sourcebot/pull/406)
- [ask sb] Improved search code tool with filter options. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)
- [ask sb] Removed search scope constraint. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

## [4.6.0] - 2025-07-25

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,7 +51,6 @@ export const NewChatPanel = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,7 +58,6 @@ export const AgenticSearch = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<Separator />
<div className="relative">
Expand Down
12 changes: 4 additions & 8 deletions packages/web/src/features/chat/agent.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ import { ProviderOptions } from "@ai-sdk/provider-utils";
import { createLogger } from "@sourcebot/logger";
import { LanguageModel, ModelMessage, StopCondition, streamText } from "ai";
import { ANSWER_TAG, FILE_REFERENCE_PREFIX, toolNames } from "./constants";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool } from "./tools";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool, searchReposTool, listAllReposTool } from "./tools";
import { FileSource, Source } from "./types";
import { addLineNumbers, fileReferenceToString } from "./utils";

Expand DownExpand Up@@ -54,6 +54,8 @@ export const createAgentStream = async ({
[toolNames.readFiles]: readFilesTool,
[toolNames.findSymbolReferences]: findSymbolReferencesTool,
[toolNames.findSymbolDefinitions]: findSymbolDefinitionsTool,
[toolNames.searchRepos]: searchReposTool,
[toolNames.listAllRepos]: listAllReposTool,
},
prepareStep: async ({ stepNumber }) => {
// The first step attaches any mentioned sources to the system prompt.
Expand DownExpand Up@@ -185,13 +187,7 @@ ${searchScopeRepoNames.map(repo => `- ${repo}`).join('\n')}
</available_repositories>

<research_phase_instructions>
During the research phase, you have these tools available:
- \`${toolNames.searchCode}\`: Search for code patterns, functions, or text across repositories
- \`${toolNames.readFiles}\`: Read the contents of specific files
- \`${toolNames.findSymbolReferences}\`: Find where symbols are referenced
- \`${toolNames.findSymbolDefinitions}\`: Find where symbols are defined

Use these tools to gather comprehensive context before answering. Always explain why you're using each tool.
During the research phase, use the tools available to you to gather comprehensive context before answering. Always explain why you're using each tool. Depending on the user's question, you may need to use multiple tools. If the question is vague, ask the user for more information.
</research_phase_instructions>

${answerInstructions}
Expand Down
83 changes: 15 additions & 68 deletions packages/web/src/features/chat/components/chatBox/chatBox.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,9 +5,10 @@ import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { CustomEditor, LanguageModelInfo, MentionElement, RenderElementPropsFor, SearchScope } from "@/features/chat/types";
import { insertMention, slateContentToString } from "@/features/chat/utils";
import { SearchContextQuery } from "@/lib/types";
import { cn, IS_MAC } from "@/lib/utils";
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 { useHotkeys } from "react-hotkeys-hook";
import { Descendant, insertText } from "slate";
Expand All@@ -17,8 +18,6 @@ import { SuggestionBox } from "./suggestionsBox";
import { Suggestion } from "./types";
import { useSuggestionModeAndQuery } from "./useSuggestionModeAndQuery";
import { useSuggestionsData } from "./useSuggestionsData";
import { useToast } from "@/components/hooks/use-toast";
import { SearchContextQuery } from "@/lib/types";

interface ChatBoxProps {
onSubmit: (children: Descendant[], editor: CustomEditor) => void;
Expand All@@ -30,7 +29,6 @@ interface ChatBoxProps {
languageModels: LanguageModelInfo[];
selectedSearchScopes: SearchScope[];
searchContexts: SearchContextQuery[];
onContextSelectorOpenChanged: (isOpen: boolean) => void;
}

export const ChatBox = ({
Expand All@@ -43,7 +41,6 @@ export const ChatBox = ({
languageModels,
selectedSearchScopes,
searchContexts,
onContextSelectorOpenChanged,
}: ChatBoxProps) => {
const suggestionsBoxRef = useRef<HTMLDivElement>(null);
const [index, setIndex] = useState(0);
Expand All@@ -70,7 +67,6 @@ export const ChatBox = ({
const { selectedLanguageModel } = useSelectedLanguageModel({
initialLanguageModel: languageModels.length > 0 ? languageModels[0] : undefined,
});
const { toast } = useToast();

// Reset the index when the suggestion mode changes.
useEffect(() => {
Expand DownExpand Up@@ -101,9 +97,9 @@ export const ChatBox = ({
return <Leaf {...props} />
}, []);

const { isSubmitDisabled, isSubmitDisabledReason } = useMemo((): {
const { isSubmitDisabled } = useMemo((): {
isSubmitDisabled: true,
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-repos-selected" | "no-language-model-selected"
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-language-model-selected"
} | {
isSubmitDisabled: false,
isSubmitDisabledReason: undefined,
Expand All@@ -129,13 +125,6 @@ export const ChatBox = ({
}
}

if (selectedSearchScopes.length === 0) {
return {
isSubmitDisabled: true,
isSubmitDisabledReason: "no-repos-selected",
}
}

if (selectedLanguageModel === undefined) {

return {
Expand All@@ -149,29 +138,11 @@ export const ChatBox = ({
isSubmitDisabledReason: undefined,
}

}, [
editor.children,
isRedirecting,
isGenerating,
selectedSearchScopes.length,
selectedLanguageModel,
])
}, [editor.children, isRedirecting, isGenerating, selectedLanguageModel])

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, isSubmitDisabled, isSubmitDisabledReason, toast, onContextSelectorOpenChanged]);
}, [_onSubmit, editor]);

const onInsertSuggestion = useCallback((suggestion: Suggestion) => {
switch (suggestion.type) {
Expand DownExpand Up@@ -310,39 +281,15 @@ export const ChatBox = ({
Stop
</Button>
) : (
<Tooltip>
<TooltipTrigger asChild>
<div
onClick={() => {
// @hack: When submission is disabled, we still want to issue
// a warning to the user as to why the submission is disabled.
// onSubmit on the Button will not be called because of the
// disabled prop, hence the call here.
if (isSubmitDisabled) {
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>
<Button
variant={isSubmitDisabled ? "outline" : "default"}
size="sm"
className="w-6 h-6"
onClick={onSubmit}
disabled={isSubmitDisabled}
>
<ArrowUp className="w-4 h-4" />
</Button>
)}
</div>
{suggestionMode !== "none" && (
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -321,7 +321,6 @@ export const ChatThread = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,8 @@ import { FindSymbolDefinitionsToolComponent } from './tools/findSymbolDefinition
import { FindSymbolReferencesToolComponent } from './tools/findSymbolReferencesToolComponent';
import { ReadFilesToolComponent } from './tools/readFilesToolComponent';
import { SearchCodeToolComponent } from './tools/searchCodeToolComponent';
import { SearchReposToolComponent } from './tools/searchReposToolComponent';
import { ListAllReposToolComponent } from './tools/listAllReposToolComponent';
import { SBChatMessageMetadata, SBChatMessagePart } from '../../types';
import { SearchScopeIcon } from '../searchScopeIcon';

Expand DownExpand Up@@ -63,7 +65,7 @@ export const DetailsCard = ({
{!isStreaming && (
<>
<Separator orientation="vertical" className="h-4" />
{metadata?.selectedSearchScopes && (
{(metadata?.selectedSearchScopes && metadata.selectedSearchScopes.length > 0) && (
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center text-xs cursor-help">
Expand DownExpand Up@@ -181,6 +183,20 @@ export const DetailsCard = ({
part={part}
/>
)
case 'tool-searchRepos':
return (
<SearchReposToolComponent
key={index}
part={part}
/>
)
case 'tool-listAllRepos':
return (
<ListAllReposToolComponent
key={index}
part={part}
/>
)
default:
return null;
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -221,7 +221,7 @@ export const ReferencedSourcesListView = ({
<span className="text-sm font-medium">{fileName}</span>
</div>
<div className="p-4 text-sm text-destructive bg-destructive/10 rounded border">
Failed to load file: {isServiceError(query.data) ? query.data.message : 'Unknown error'}
Failed to load file: {isServiceError(query.data) ? query.data.message : query.error?.message ?? 'Unknown error'}
</div>
</div>
);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
'use client';

import { ListAllReposToolUIPart } from "@/features/chat/tools";
import { isServiceError } from "@/lib/utils";
import { useMemo, useState } from "react";
import { ToolHeader, TreeList } from "./shared";
import { CodeSnippet } from "@/app/components/codeSnippet";
import { Separator } from "@/components/ui/separator";
import { FolderOpenIcon } from "lucide-react";

export const ListAllReposToolComponent = ({ part }: { part: ListAllReposToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Loading all repositories...';
case 'output-error':
return '"List all repositories" tool call failed';
case 'input-available':
case 'output-available':
return 'Listed all repositories';
}
}, [part]);

return (
<div className="my-4">
<ToolHeader
isLoading={part.state !== 'output-available' && part.state !== 'output-error'}
isError={part.state === 'output-error' || (part.state === 'output-available' && isServiceError(part.output))}
isExpanded={isExpanded}
label={label}
Icon={FolderOpenIcon}
onExpand={setIsExpanded}
/>
{part.state === 'output-available' && isExpanded && (
<>
{isServiceError(part.output) ? (
<TreeList>
<span>Failed with the following error: <CodeSnippet className="text-sm text-destructive">{part.output.message}</CodeSnippet></span>
</TreeList>
) : (
<>
{part.output.length === 0 ? (
<span className="text-sm text-muted-foreground ml-[25px]">No repositories found</span>
) : (
<TreeList>
<div className="text-sm text-muted-foreground mb-2">
Found {part.output.length} repositories:
</div>
{part.output.map((repoName, index) => (
<div key={index} className="flex items-center gap-2 text-sm">
<FolderOpenIcon className="h-4 w-4 text-muted-foreground" />
<span className="truncate">{repoName}</span>
</div>
))}
</TreeList>
)}
</>
)}
<Separator className='ml-[7px] my-2' />
</>
)}
</div>
)
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,24 +11,38 @@ import { SearchIcon } from "lucide-react";
import Link from "next/link";
import { SearchQueryParams } from "@/lib/types";
import { PlayIcon } from "@radix-ui/react-icons";

import { buildSearchQuery } from "@/features/chat/utils";

export const SearchCodeToolComponent = ({ part }: { part: SearchCodeToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);
const domain = useDomain();

const displayQuery = useMemo(() => {
if (part.state !== 'input-available' && part.state !== 'output-available') {
return '';
}

const query = buildSearchQuery({
query: part.input.queryRegexp,
repoNamesFilterRegexp: part.input.repoNamesFilterRegexp,
languageNamesFilter: part.input.languageNamesFilter,
fileNamesFilterRegexp: part.input.fileNamesFilterRegexp,
});

return query;
}, [part]);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Searching...';
case 'input-available':
return <span>Searching for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
case 'output-error':
return '"Search code" tool call failed';
case 'input-available':
case 'output-available':
return <span>Searched for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
return <span>Searched for <CodeSnippet>{displayQuery}</CodeSnippet></span>;
}
}, [part]);
}, [part, displayQuery]);

return (
<div className="my-4">
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Search context refactor to search scope and demo card UI changes. [#405](https://github.com/sourcebot-dev/sourcebot/pull/405)
- Add GitHub star toast. [#409](https://github.com/sourcebot-dev/sourcebot/pull/409)
- Added a onboarding modal when first visiting the homepage when `ask` mode is selected. [#408](https://github.com/sourcebot-dev/sourcebot/pull/408)
- [ask sb] Added `searchReposTool` and `listAllReposTool`. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

### Fixed
- Fixed multiple writes race condition on config file watcher. [#398](https://github.com/sourcebot-dev/sourcebot/pull/398)
Expand All@@ -21,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bumped AI SDK and associated packages version. [#404](https://github.com/sourcebot-dev/sourcebot/pull/404)
- Bumped form-data package version. [#407](https://github.com/sourcebot-dev/sourcebot/pull/407)
- Bumped next version. [#406](https://github.com/sourcebot-dev/sourcebot/pull/406)
- [ask sb] Improved search code tool with filter options. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)
- [ask sb] Removed search scope constraint. [#400](https://github.com/sourcebot-dev/sourcebot/pull/400)

## [4.6.0] - 2025-07-25

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,7 +51,6 @@ export const NewChatPanel = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,7 +58,6 @@ export const AgenticSearch = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<Separator />
<div className="relative">
Expand Down
12 changes: 4 additions & 8 deletions packages/web/src/features/chat/agent.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ import { ProviderOptions } from "@ai-sdk/provider-utils";
import { createLogger } from "@sourcebot/logger";
import { LanguageModel, ModelMessage, StopCondition, streamText } from "ai";
import { ANSWER_TAG, FILE_REFERENCE_PREFIX, toolNames } from "./constants";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool } from "./tools";
import { createCodeSearchTool, findSymbolDefinitionsTool, findSymbolReferencesTool, readFilesTool, searchReposTool, listAllReposTool } from "./tools";
import { FileSource, Source } from "./types";
import { addLineNumbers, fileReferenceToString } from "./utils";

Expand DownExpand Up@@ -54,6 +54,8 @@ export const createAgentStream = async ({
[toolNames.readFiles]: readFilesTool,
[toolNames.findSymbolReferences]: findSymbolReferencesTool,
[toolNames.findSymbolDefinitions]: findSymbolDefinitionsTool,
[toolNames.searchRepos]: searchReposTool,
[toolNames.listAllRepos]: listAllReposTool,
},
prepareStep: async ({ stepNumber }) => {
// The first step attaches any mentioned sources to the system prompt.
Expand DownExpand Up@@ -185,13 +187,7 @@ ${searchScopeRepoNames.map(repo => `- ${repo}`).join('\n')}
</available_repositories>

<research_phase_instructions>
During the research phase, you have these tools available:
- \`${toolNames.searchCode}\`: Search for code patterns, functions, or text across repositories
- \`${toolNames.readFiles}\`: Read the contents of specific files
- \`${toolNames.findSymbolReferences}\`: Find where symbols are referenced
- \`${toolNames.findSymbolDefinitions}\`: Find where symbols are defined

Use these tools to gather comprehensive context before answering. Always explain why you're using each tool.
During the research phase, use the tools available to you to gather comprehensive context before answering. Always explain why you're using each tool. Depending on the user's question, you may need to use multiple tools. If the question is vague, ask the user for more information.
</research_phase_instructions>

${answerInstructions}
Expand Down
83 changes: 15 additions & 68 deletions packages/web/src/features/chat/components/chatBox/chatBox.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,9 +5,10 @@ import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { CustomEditor, LanguageModelInfo, MentionElement, RenderElementPropsFor, SearchScope } from "@/features/chat/types";
import { insertMention, slateContentToString } from "@/features/chat/utils";
import { SearchContextQuery } from "@/lib/types";
import { cn, IS_MAC } from "@/lib/utils";
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 { useHotkeys } from "react-hotkeys-hook";
import { Descendant, insertText } from "slate";
Expand All@@ -17,8 +18,6 @@ import { SuggestionBox } from "./suggestionsBox";
import { Suggestion } from "./types";
import { useSuggestionModeAndQuery } from "./useSuggestionModeAndQuery";
import { useSuggestionsData } from "./useSuggestionsData";
import { useToast } from "@/components/hooks/use-toast";
import { SearchContextQuery } from "@/lib/types";

interface ChatBoxProps {
onSubmit: (children: Descendant[], editor: CustomEditor) => void;
Expand All@@ -30,7 +29,6 @@ interface ChatBoxProps {
languageModels: LanguageModelInfo[];
selectedSearchScopes: SearchScope[];
searchContexts: SearchContextQuery[];
onContextSelectorOpenChanged: (isOpen: boolean) => void;
}

export const ChatBox = ({
Expand All@@ -43,7 +41,6 @@ export const ChatBox = ({
languageModels,
selectedSearchScopes,
searchContexts,
onContextSelectorOpenChanged,
}: ChatBoxProps) => {
const suggestionsBoxRef = useRef<HTMLDivElement>(null);
const [index, setIndex] = useState(0);
Expand All@@ -70,7 +67,6 @@ export const ChatBox = ({
const { selectedLanguageModel } = useSelectedLanguageModel({
initialLanguageModel: languageModels.length > 0 ? languageModels[0] : undefined,
});
const { toast } = useToast();

// Reset the index when the suggestion mode changes.
useEffect(() => {
Expand DownExpand Up@@ -101,9 +97,9 @@ export const ChatBox = ({
return <Leaf {...props} />
}, []);

const { isSubmitDisabled, isSubmitDisabledReason } = useMemo((): {
const { isSubmitDisabled } = useMemo((): {
isSubmitDisabled: true,
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-repos-selected" | "no-language-model-selected"
isSubmitDisabledReason: "empty" | "redirecting" | "generating" | "no-language-model-selected"
} | {
isSubmitDisabled: false,
isSubmitDisabledReason: undefined,
Expand All@@ -129,13 +125,6 @@ export const ChatBox = ({
}
}

if (selectedSearchScopes.length === 0) {
return {
isSubmitDisabled: true,
isSubmitDisabledReason: "no-repos-selected",
}
}

if (selectedLanguageModel === undefined) {

return {
Expand All@@ -149,29 +138,11 @@ export const ChatBox = ({
isSubmitDisabledReason: undefined,
}

}, [
editor.children,
isRedirecting,
isGenerating,
selectedSearchScopes.length,
selectedLanguageModel,
])
}, [editor.children, isRedirecting, isGenerating, selectedLanguageModel])

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, isSubmitDisabled, isSubmitDisabledReason, toast, onContextSelectorOpenChanged]);
}, [_onSubmit, editor]);

const onInsertSuggestion = useCallback((suggestion: Suggestion) => {
switch (suggestion.type) {
Expand DownExpand Up@@ -310,39 +281,15 @@ export const ChatBox = ({
Stop
</Button>
) : (
<Tooltip>
<TooltipTrigger asChild>
<div
onClick={() => {
// @hack: When submission is disabled, we still want to issue
// a warning to the user as to why the submission is disabled.
// onSubmit on the Button will not be called because of the
// disabled prop, hence the call here.
if (isSubmitDisabled) {
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>
<Button
variant={isSubmitDisabled ? "outline" : "default"}
size="sm"
className="w-6 h-6"
onClick={onSubmit}
disabled={isSubmitDisabled}
>
<ArrowUp className="w-4 h-4" />
</Button>
)}
</div>
{suggestionMode !== "none" && (
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -321,7 +321,6 @@ export const ChatThread = ({
languageModels={languageModels}
selectedSearchScopes={selectedSearchScopes}
searchContexts={searchContexts}
onContextSelectorOpenChanged={setIsContextSelectorOpen}
/>
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
<ChatBoxToolbar
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,8 @@ import { FindSymbolDefinitionsToolComponent } from './tools/findSymbolDefinition
import { FindSymbolReferencesToolComponent } from './tools/findSymbolReferencesToolComponent';
import { ReadFilesToolComponent } from './tools/readFilesToolComponent';
import { SearchCodeToolComponent } from './tools/searchCodeToolComponent';
import { SearchReposToolComponent } from './tools/searchReposToolComponent';
import { ListAllReposToolComponent } from './tools/listAllReposToolComponent';
import { SBChatMessageMetadata, SBChatMessagePart } from '../../types';
import { SearchScopeIcon } from '../searchScopeIcon';

Expand DownExpand Up@@ -63,7 +65,7 @@ export const DetailsCard = ({
{!isStreaming && (
<>
<Separator orientation="vertical" className="h-4" />
{metadata?.selectedSearchScopes && (
{(metadata?.selectedSearchScopes && metadata.selectedSearchScopes.length > 0) && (
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center text-xs cursor-help">
Expand DownExpand Up@@ -181,6 +183,20 @@ export const DetailsCard = ({
part={part}
/>
)
case 'tool-searchRepos':
return (
<SearchReposToolComponent
key={index}
part={part}
/>
)
case 'tool-listAllRepos':
return (
<ListAllReposToolComponent
key={index}
part={part}
/>
)
default:
return null;
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -221,7 +221,7 @@ export const ReferencedSourcesListView = ({
<span className="text-sm font-medium">{fileName}</span>
</div>
<div className="p-4 text-sm text-destructive bg-destructive/10 rounded border">
Failed to load file: {isServiceError(query.data) ? query.data.message : 'Unknown error'}
Failed to load file: {isServiceError(query.data) ? query.data.message : query.error?.message ?? 'Unknown error'}
</div>
</div>
);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
'use client';

import { ListAllReposToolUIPart } from "@/features/chat/tools";
import { isServiceError } from "@/lib/utils";
import { useMemo, useState } from "react";
import { ToolHeader, TreeList } from "./shared";
import { CodeSnippet } from "@/app/components/codeSnippet";
import { Separator } from "@/components/ui/separator";
import { FolderOpenIcon } from "lucide-react";

export const ListAllReposToolComponent = ({ part }: { part: ListAllReposToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Loading all repositories...';
case 'output-error':
return '"List all repositories" tool call failed';
case 'input-available':
case 'output-available':
return 'Listed all repositories';
}
}, [part]);

return (
<div className="my-4">
<ToolHeader
isLoading={part.state !== 'output-available' && part.state !== 'output-error'}
isError={part.state === 'output-error' || (part.state === 'output-available' && isServiceError(part.output))}
isExpanded={isExpanded}
label={label}
Icon={FolderOpenIcon}
onExpand={setIsExpanded}
/>
{part.state === 'output-available' && isExpanded && (
<>
{isServiceError(part.output) ? (
<TreeList>
<span>Failed with the following error: <CodeSnippet className="text-sm text-destructive">{part.output.message}</CodeSnippet></span>
</TreeList>
) : (
<>
{part.output.length === 0 ? (
<span className="text-sm text-muted-foreground ml-[25px]">No repositories found</span>
) : (
<TreeList>
<div className="text-sm text-muted-foreground mb-2">
Found {part.output.length} repositories:
</div>
{part.output.map((repoName, index) => (
<div key={index} className="flex items-center gap-2 text-sm">
<FolderOpenIcon className="h-4 w-4 text-muted-foreground" />
<span className="truncate">{repoName}</span>
</div>
))}
</TreeList>
)}
</>
)}
<Separator className='ml-[7px] my-2' />
</>
)}
</div>
)
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,24 +11,38 @@ import { SearchIcon } from "lucide-react";
import Link from "next/link";
import { SearchQueryParams } from "@/lib/types";
import { PlayIcon } from "@radix-ui/react-icons";

import { buildSearchQuery } from "@/features/chat/utils";

export const SearchCodeToolComponent = ({ part }: { part: SearchCodeToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);
const domain = useDomain();

const displayQuery = useMemo(() => {
if (part.state !== 'input-available' && part.state !== 'output-available') {
return '';
}

const query = buildSearchQuery({
query: part.input.queryRegexp,
repoNamesFilterRegexp: part.input.repoNamesFilterRegexp,
languageNamesFilter: part.input.languageNamesFilter,
fileNamesFilterRegexp: part.input.fileNamesFilterRegexp,
});

return query;
}, [part]);

const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Searching...';
case 'input-available':
return <span>Searching for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
case 'output-error':
return '"Search code" tool call failed';
case 'input-available':
case 'output-available':
return <span>Searched for <CodeSnippet>{part.input.query}</CodeSnippet></span>;
return <span>Searched for <CodeSnippet>{displayQuery}</CodeSnippet></span>;
}
}, [part]);
}, [part, displayQuery]);

return (
<div className="my-4">
Expand Down
Loading