web context provider

This commit is contained in:
Nate 2024-10-14 21:14:49 -07:00
parent 6659332e2b
commit 99b767d653
8 changed files with 144 additions and 10 deletions

2
.vscode/launch.json vendored
View file

@ -20,7 +20,7 @@
"outFiles": ["${workspaceFolder}/extensions/vscode/out/extension.js"],
"preLaunchTask": "vscode-extension:build",
"env": {
// "CONTROL_PLANE_ENV": "local"
"CONTROL_PLANE_ENV": "local"
}
},
{

View file

@ -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<ContextItem[]> {
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;
}
}

View file

@ -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(

View file

@ -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": {

View file

@ -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": {

View file

@ -3109,4 +3109,4 @@
}
}
}
}
}

View file

@ -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

View file

@ -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;