From 1dfd2ae90600889d3c8e60f867081619eae9eaf0 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Thu, 4 Jan 2024 23:25:44 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20give=20context=20providers=20access?= =?UTF-8?q?=20to=20full=20input?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/config/types.ts | 4 ++-- core/context/index.ts | 5 ++++- .../providers/CustomContextProvider.ts | 5 ++++- core/context/providers/DiffContextProvider.ts | 5 ++++- core/context/providers/FileContextProvider.ts | 5 ++++- .../providers/FileTreeContextProvider.ts | 5 ++++- .../providers/GitHubIssuesContextProvider.ts | 5 ++++- .../providers/GoogleContextProvider.ts | 5 ++++- core/context/providers/HttpContextProvider.ts | 5 ++++- .../providers/OpenFilesContextProvider.ts | 5 ++++- .../providers/SearchContextProvider.ts | 5 ++++- .../providers/TerminalContextProvider.ts | 5 ++++- core/context/providers/URLContextProvider.ts | 5 ++++- core/index.d.ts | 4 ++-- docs/docs/customization/context-providers.md | 4 ++-- gui/src/components/mainInput/resolveInput.ts | 3 ++- gui/src/hooks/useContextProviders.ts | 19 +++---------------- 17 files changed, 59 insertions(+), 35 deletions(-) diff --git a/core/config/types.ts b/core/config/types.ts index 7f22b468f..a20a002ee 100644 --- a/core/config/types.ts +++ b/core/config/types.ts @@ -58,13 +58,13 @@ declare global { title: string; displayTitle?: string; description?: string; - getContextItems(query: string): Promise; + getContextItems(query: string, fullInput: string): Promise; } export interface IContextProvider { get description(): ContextProviderDescription; - getContextItems(query: string): Promise; + getContextItems(query: string, fullInput: string): Promise; } export interface PersistedSessionInfo { diff --git a/core/context/index.ts b/core/context/index.ts index 7dd8b406f..256abaa17 100644 --- a/core/context/index.ts +++ b/core/context/index.ts @@ -14,7 +14,10 @@ export abstract class BaseContextProvider implements IContextProvider { } // Maybe just include the chat message in here. Should never have to go back to the context provider once you have the information. - abstract getContextItems(query: string): Promise; + abstract getContextItems( + query: string, + fullInput: string + ): Promise; abstract load(): Promise; } diff --git a/core/context/providers/CustomContextProvider.ts b/core/context/providers/CustomContextProvider.ts index 0f742e498..6e854cc29 100644 --- a/core/context/providers/CustomContextProvider.ts +++ b/core/context/providers/CustomContextProvider.ts @@ -21,7 +21,10 @@ class CustomContextProviderClass implements IContextProvider { }; } - async getContextItems(query: string): Promise { + async getContextItems( + query: string, + fullInput: string + ): Promise { return await this.custom.getContextItems(query); } async load(): Promise {} diff --git a/core/context/providers/DiffContextProvider.ts b/core/context/providers/DiffContextProvider.ts index e804465ce..fbe5eecf7 100644 --- a/core/context/providers/DiffContextProvider.ts +++ b/core/context/providers/DiffContextProvider.ts @@ -11,7 +11,10 @@ class DiffContextProvider extends BaseContextProvider { requiresQuery: false, }; - async getContextItems(query: string): Promise { + async getContextItems( + query: string, + fullInput: string + ): Promise { const diff = await new ExtensionIde().getDiff(); return [ { diff --git a/core/context/providers/FileContextProvider.ts b/core/context/providers/FileContextProvider.ts index 80e89a3cc..6403514f0 100644 --- a/core/context/providers/FileContextProvider.ts +++ b/core/context/providers/FileContextProvider.ts @@ -11,7 +11,10 @@ class FileContextProvider extends BaseContextProvider { requiresQuery: false, }; - async getContextItems(query: string): Promise { + async getContextItems( + query: string, + fullInput: string + ): Promise { // Assume the query is a filepath query = query.trim(); const content = await new ExtensionIde().readFile(query); diff --git a/core/context/providers/FileTreeContextProvider.ts b/core/context/providers/FileTreeContextProvider.ts index 105ced23a..7de4eb2f0 100644 --- a/core/context/providers/FileTreeContextProvider.ts +++ b/core/context/providers/FileTreeContextProvider.ts @@ -40,7 +40,10 @@ class FileTreeContextProvider extends BaseContextProvider { requiresQuery: false, }; - async getContextItems(query: string): Promise { + async getContextItems( + query: string, + fullInput: string + ): Promise { const workspaceDirs = await new ExtensionIde().getWorkspaceDirs(); let trees = []; diff --git a/core/context/providers/GitHubIssuesContextProvider.ts b/core/context/providers/GitHubIssuesContextProvider.ts index 8c28ae30e..d848fb4fa 100644 --- a/core/context/providers/GitHubIssuesContextProvider.ts +++ b/core/context/providers/GitHubIssuesContextProvider.ts @@ -10,7 +10,10 @@ class GitHubIssuesContextProvider extends BaseContextProvider { requiresQuery: false, }; - async getContextItems(query: string): Promise { + async getContextItems( + query: string, + fullInput: string + ): Promise { return []; } async load(): Promise {} diff --git a/core/context/providers/GoogleContextProvider.ts b/core/context/providers/GoogleContextProvider.ts index a31009c26..fecbabe0c 100644 --- a/core/context/providers/GoogleContextProvider.ts +++ b/core/context/providers/GoogleContextProvider.ts @@ -17,7 +17,10 @@ class GoogleContextProvider extends BaseContextProvider { this._serperApiKey = options.serperApiKey; } - async getContextItems(query: string): Promise { + async getContextItems( + query: string, + fullInput: string + ): Promise { const url = "https://google.serper.dev/search"; const payload = JSON.stringify({ q: query }); diff --git a/core/context/providers/HttpContextProvider.ts b/core/context/providers/HttpContextProvider.ts index 01882189f..1bac52b7a 100644 --- a/core/context/providers/HttpContextProvider.ts +++ b/core/context/providers/HttpContextProvider.ts @@ -22,7 +22,10 @@ class HttpContextProvider extends BaseContextProvider { }; } - async getContextItems(query: string): Promise { + async getContextItems( + query: string, + fullInput: string + ): Promise { const response = await fetch(this.options.url, { method: "POST", headers: { diff --git a/core/context/providers/OpenFilesContextProvider.ts b/core/context/providers/OpenFilesContextProvider.ts index 5f68a4f75..4738513af 100644 --- a/core/context/providers/OpenFilesContextProvider.ts +++ b/core/context/providers/OpenFilesContextProvider.ts @@ -11,7 +11,10 @@ class OpenFilesContextProvider extends BaseContextProvider { requiresQuery: false, }; - async getContextItems(query: string): Promise { + async getContextItems( + query: string, + fullInput: string + ): Promise { const ide = new ExtensionIde(); const openFiles = await ide.getOpenFiles(); return await Promise.all( diff --git a/core/context/providers/SearchContextProvider.ts b/core/context/providers/SearchContextProvider.ts index c0ff888cd..be8254c22 100644 --- a/core/context/providers/SearchContextProvider.ts +++ b/core/context/providers/SearchContextProvider.ts @@ -11,7 +11,10 @@ class SearchContextProvider extends BaseContextProvider { requiresQuery: true, }; - async getContextItems(query: string): Promise { + async getContextItems( + query: string, + fullInput: string + ): Promise { const results = await new ExtensionIde().getSearchResults(query); return [ { diff --git a/core/context/providers/TerminalContextProvider.ts b/core/context/providers/TerminalContextProvider.ts index c1abb6a94..e131e3f3c 100644 --- a/core/context/providers/TerminalContextProvider.ts +++ b/core/context/providers/TerminalContextProvider.ts @@ -11,7 +11,10 @@ class TerminalContextProvider extends BaseContextProvider { requiresQuery: false, }; - async getContextItems(query: string): Promise { + async getContextItems( + query: string, + fullInput: string + ): Promise { const content = await new ExtensionIde().getTerminalContents(); return [ { diff --git a/core/context/providers/URLContextProvider.ts b/core/context/providers/URLContextProvider.ts index 7f009b6ea..ec2e37510 100644 --- a/core/context/providers/URLContextProvider.ts +++ b/core/context/providers/URLContextProvider.ts @@ -10,7 +10,10 @@ class URLContextProvider extends BaseContextProvider { requiresQuery: true, }; - async getContextItems(query: string): Promise { + async getContextItems( + query: string, + fullInput: string + ): Promise { let url = query.trim(); if (!url.startsWith("http")) { url = "https://" + url; diff --git a/core/index.d.ts b/core/index.d.ts index ef240c99c..e1203fa48 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -56,13 +56,13 @@ export interface CustomContextProvider { title: string; displayTitle?: string; description?: string; - getContextItems(query: string): Promise; + getContextItems(query: string, fullInput: string): Promise; } export interface IContextProvider { get description(): ContextProviderDescription; - getContextItems(query: string): Promise; + getContextItems(query: string, fullInput: string): Promise; } export interface PersistedSessionInfo { diff --git a/docs/docs/customization/context-providers.md b/docs/docs/customization/context-providers.md index 97f7fac7f..b8fc1c91f 100644 --- a/docs/docs/customization/context-providers.md +++ b/docs/docs/customization/context-providers.md @@ -113,7 +113,7 @@ interface CustomContextProvider { title: string; displayTitle?: string; description?: string; - getContextItems(query: string): Promise; + getContextItems(query: string, fullInput: string): Promise; } ``` @@ -126,7 +126,7 @@ const RagContextProvider = { description: "Retrieve snippets from our vector database of internal documents", - getContextItems: async (query: string) => { + getContextItems: async (query: string, fullInput: string) => { const response = await fetch("https://internal_rag_server.com/retrieve", { method: "POST", body: JSON.stringify({ query }), diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index 4b47650f6..c4eba98b7 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -58,7 +58,8 @@ async function resolveEditorContent( const resolvedItems = await getContextItems( contextProviders, item.id, - item.query + item.query, + paragraphs.join("\n") ); for (const resolvedItem of resolvedItems) { contextItemsText += `\`\`\`title="${item.label}"\n${resolvedItem.content}\n\`\`\`\n`; diff --git a/gui/src/hooks/useContextProviders.ts b/gui/src/hooks/useContextProviders.ts index 63eb0af4f..31d898282 100644 --- a/gui/src/hooks/useContextProviders.ts +++ b/gui/src/hooks/useContextProviders.ts @@ -1,13 +1,12 @@ import { ContextItemId, ContextItemWithId, IContextProvider } from "core"; -import { useSelector } from "react-redux"; import { v4 } from "uuid"; -import { RootStore } from "../redux/store"; import { errorPopup } from "../util/ide"; export async function getContextItems( contextProviders: IContextProvider[], name: string, - query: string + query: string, + fullInput: string ): Promise { const provider = contextProviders.find((p) => p.description.title === name); if (!provider) { @@ -22,22 +21,10 @@ export async function getContextItems( providerTitle: provider.description.title, itemId: v4(), }; - const items = await provider.getContextItems(query); + const items = await provider.getContextItems(query, fullInput); return items.map((item) => ({ ...item, id })); } catch (e) { errorPopup(`Error getting context items from ${name}: ${e.message}`); return []; } } -function useContextProviders() { - const contextProviders = useSelector( - (state: RootStore) => state.state.config.contextProviders || [] - ); - - return { - getContextItems: (name, query) => - getContextItems(contextProviders, name, query), - }; -} - -export default useContextProviders;