From 99b767d653f12008c63727de678ec84fde951eac Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 14 Oct 2024 21:14:49 -0700 Subject: [PATCH] web context provider --- .vscode/launch.json | 2 +- core/context/providers/WebContextProvider.ts | 43 ++++++++++++ core/context/providers/index.ts | 10 +-- docs/static/schemas/config.json | 66 +++++++++++++++++++ extensions/vscode/config_schema.json | 24 ++++++- extensions/vscode/continue_rc_schema.json | 2 +- .../src/quickEdit/QuickEditQuickPick.ts | 2 +- gui/src/components/mainInput/MentionList.tsx | 5 +- 8 files changed, 144 insertions(+), 10 deletions(-) create mode 100644 core/context/providers/WebContextProvider.ts diff --git a/.vscode/launch.json b/.vscode/launch.json index 896793040..835c09089 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -20,7 +20,7 @@ "outFiles": ["${workspaceFolder}/extensions/vscode/out/extension.js"], "preLaunchTask": "vscode-extension:build", "env": { - // "CONTROL_PLANE_ENV": "local" + "CONTROL_PLANE_ENV": "local" } }, { diff --git a/core/context/providers/WebContextProvider.ts b/core/context/providers/WebContextProvider.ts new file mode 100644 index 000000000..3e1002d33 --- /dev/null +++ b/core/context/providers/WebContextProvider.ts @@ -0,0 +1,43 @@ +import { BaseContextProvider } from ".."; +import { + ContextItem, + ContextProviderDescription, + ContextProviderExtras, +} from "../.."; +import { getHeaders } from "../../continueServer/stubs/headers"; +import { constants } from "../../deploy/constants"; + +export default class WebContextProvider extends BaseContextProvider { + private static ENDPOINT = new URL("web", constants.a); + private static DEFAULT_N = 6; + + static description: ContextProviderDescription = { + title: "web", + displayTitle: "Web", + description: "Search the web", + type: "normal", + renderInlineAs: "", + }; + + async getContextItems( + query: string, + extras: ContextProviderExtras, + ): Promise { + const resp = await extras.fetch(WebContextProvider.ENDPOINT, { + method: "POST", + headers: { + "Content-Type": "application/json", + ...(await getHeaders()), + }, + body: JSON.stringify({ + query: extras.fullInput, + n: this.options.n ?? WebContextProvider.DEFAULT_N, + }), + }); + if (!resp.ok) { + throw new Error("Failed to fetch web context"); + } + const json = await resp.json(); + return json; + } +} diff --git a/core/context/providers/index.ts b/core/context/providers/index.ts index 853c4c4fc..28f8aa33c 100644 --- a/core/context/providers/index.ts +++ b/core/context/providers/index.ts @@ -1,16 +1,18 @@ -import { ContextItem, ContextProviderName } from "../../"; import { BaseContextProvider } from "../"; +import { ContextProviderName } from "../../"; import CodeContextProvider from "./CodeContextProvider"; import ContinueProxyContextProvider from "./ContinueProxyContextProvider"; import CurrentFileContextProvider from "./CurrentFileContextProvider"; import DatabaseContextProvider from "./DatabaseContextProvider"; import DiffContextProvider from "./DiffContextProvider"; +import DiscordContextProvider from "./DiscordContextProvider"; import DocsContextProvider from "./DocsContextProvider"; import FileTreeContextProvider from "./FileTreeContextProvider"; import FolderContextProvider from "./FolderContextProvider"; import GitHubIssuesContextProvider from "./GitHubIssuesContextProvider"; import GitLabMergeRequestContextProvider from "./GitLabMergeRequestContextProvider"; import GoogleContextProvider from "./GoogleContextProvider"; +import GreptileContextProvider from "./GreptileContextProvider"; import HttpContextProvider from "./HttpContextProvider"; import JiraIssuesContextProvider from "./JiraIssuesContextProvider/"; import LocalsProvider from "./LocalsProvider"; @@ -18,12 +20,11 @@ import OSContextProvider from "./OSContextProvider"; import OpenFilesContextProvider from "./OpenFilesContextProvider"; import PostgresContextProvider from "./PostgresContextProvider"; import ProblemsContextProvider from "./ProblemsContextProvider"; +import RepoMapContextProvider from "./RepoMapContextProvider"; import SearchContextProvider from "./SearchContextProvider"; import TerminalContextProvider from "./TerminalContextProvider"; import URLContextProvider from "./URLContextProvider"; -import RepoMapContextProvider from "./RepoMapContextProvider"; -import DiscordContextProvider from "./DiscordContextProvider"; -import GreptileContextProvider from "./GreptileContextProvider"; +import WebContextProvider from "./WebContextProvider"; /** * Note: We are currently omitting the following providers due to bugs: @@ -57,6 +58,7 @@ export const Providers: (typeof BaseContextProvider)[] = [ RepoMapContextProvider, DiscordContextProvider, GreptileContextProvider, + WebContextProvider, ]; export function contextProviderClassFromName( diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index 1d18d3512..f7e4daf53 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -1650,6 +1650,72 @@ } }, "allOf": [ + { + "if": { + "properties": { + "name": { + "enum": ["discord"] + } + } + }, + "then": { + "allOf": [ + { + "properties": { + "params": { + "properties": { + "discordKey": { + "type": "string", + "description": "Your Discord bot token to access the Discord API. Required to fetch messages from servers." + }, + "guildId": { + "type": "string", + "description": "The ID of the guild (server) from which to fetch channels and messages." + }, + "channels": { + "type": "array", + "description": "A list of channel objects to search for messages", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "The unique ID of the channel" + }, + "name": { + "type": "string", + "description": "The name of the channel" + } + }, + "required": ["id"] + } + } + }, + "required": ["discordKey"] + } + } + }, + { + "oneOf": [ + { + "properties": { + "params": { + "required": ["guildId"] + } + } + }, + { + "properties": { + "params": { + "required": ["channels"] + } + } + } + ] + } + ] + } + }, { "if": { "properties": { diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index f7e4daf53..69221f9c7 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -1609,7 +1609,8 @@ "database", "os", "repo-map", - "greptile" + "greptile", + "web" ], "markdownEnumDescriptions": [ "Reference the contents of the current changes as given by `git diff`", @@ -1634,7 +1635,8 @@ "Reference table schemas", "Operating system and CPU Information", "Map of files in the repository with important code highlights", - "Query your greptile index of the current repo" + "Query your greptile index of the current repo", + "Search the web for sources related to your question" ], "type": "string" }, @@ -1739,6 +1741,24 @@ "required": ["params"] } }, + { + "if": { "properties": { "name": { "enum": ["web"] } } }, + "then": { + "properties": { + "params": { + "properties": { + "n": { + "title": "N", + "description": "The number of results to return", + "default": 6, + "type": "integer" + } + } + } + }, + "required": ["params"] + } + }, { "if": { "properties": { diff --git a/extensions/vscode/continue_rc_schema.json b/extensions/vscode/continue_rc_schema.json index 252b5a173..7414be280 100644 --- a/extensions/vscode/continue_rc_schema.json +++ b/extensions/vscode/continue_rc_schema.json @@ -3109,4 +3109,4 @@ } } } -} +} \ No newline at end of file diff --git a/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts b/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts index 0c0b276a8..64d262957 100644 --- a/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts +++ b/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts @@ -384,7 +384,7 @@ export class QuickEdit { const searchResults = this.miniSearch.search( searchQuery, - ) as FileMiniSearchResult[]; + ) as unknown as FileMiniSearchResult[]; if (searchResults.length > 0) { quickPick.items = searchResults diff --git a/gui/src/components/mainInput/MentionList.tsx b/gui/src/components/mainInput/MentionList.tsx index 95ddc15ca..a84294a23 100644 --- a/gui/src/components/mainInput/MentionList.tsx +++ b/gui/src/components/mainInput/MentionList.tsx @@ -60,6 +60,7 @@ const ICONS_FOR_DROPDOWN: { [key: string]: any } = { docs: BookOpenIcon, issue: ExclamationCircleIcon, trash: TrashIcon, + web: GlobeAltIcon, "repo-map": FolderIcon, "/edit": PencilIcon, "/clear": TrashIcon, @@ -114,7 +115,9 @@ function DropdownIcon(props: { className?: string; item: ComboBoxItem }) { const ItemsDiv = styled.div` border-radius: ${defaultBorderRadius}; - box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05), 0px 10px 20px rgba(0, 0, 0, 0.1); + box-shadow: + 0 0 0 1px rgba(0, 0, 0, 0.05), + 0px 10px 20px rgba(0, 0, 0, 0.1); font-size: 0.9rem; overflow-x: hidden; overflow-y: auto;