✨ give context providers access to full input
This commit is contained in:
parent
9174647d68
commit
1dfd2ae906
17 changed files with 59 additions and 35 deletions
|
|
@ -58,13 +58,13 @@ declare global {
|
|||
title: string;
|
||||
displayTitle?: string;
|
||||
description?: string;
|
||||
getContextItems(query: string): Promise<ContextItem[]>;
|
||||
getContextItems(query: string, fullInput: string): Promise<ContextItem[]>;
|
||||
}
|
||||
|
||||
export interface IContextProvider {
|
||||
get description(): ContextProviderDescription;
|
||||
|
||||
getContextItems(query: string): Promise<ContextItem[]>;
|
||||
getContextItems(query: string, fullInput: string): Promise<ContextItem[]>;
|
||||
}
|
||||
|
||||
export interface PersistedSessionInfo {
|
||||
|
|
|
|||
|
|
@ -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<ContextItem[]>;
|
||||
abstract getContextItems(
|
||||
query: string,
|
||||
fullInput: string
|
||||
): Promise<ContextItem[]>;
|
||||
|
||||
abstract load(): Promise<void>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,10 @@ class CustomContextProviderClass implements IContextProvider {
|
|||
};
|
||||
}
|
||||
|
||||
async getContextItems(query: string): Promise<ContextItem[]> {
|
||||
async getContextItems(
|
||||
query: string,
|
||||
fullInput: string
|
||||
): Promise<ContextItem[]> {
|
||||
return await this.custom.getContextItems(query);
|
||||
}
|
||||
async load(): Promise<void> {}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,10 @@ class DiffContextProvider extends BaseContextProvider {
|
|||
requiresQuery: false,
|
||||
};
|
||||
|
||||
async getContextItems(query: string): Promise<ContextItem[]> {
|
||||
async getContextItems(
|
||||
query: string,
|
||||
fullInput: string
|
||||
): Promise<ContextItem[]> {
|
||||
const diff = await new ExtensionIde().getDiff();
|
||||
return [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,10 @@ class FileContextProvider extends BaseContextProvider {
|
|||
requiresQuery: false,
|
||||
};
|
||||
|
||||
async getContextItems(query: string): Promise<ContextItem[]> {
|
||||
async getContextItems(
|
||||
query: string,
|
||||
fullInput: string
|
||||
): Promise<ContextItem[]> {
|
||||
// Assume the query is a filepath
|
||||
query = query.trim();
|
||||
const content = await new ExtensionIde().readFile(query);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,10 @@ class FileTreeContextProvider extends BaseContextProvider {
|
|||
requiresQuery: false,
|
||||
};
|
||||
|
||||
async getContextItems(query: string): Promise<ContextItem[]> {
|
||||
async getContextItems(
|
||||
query: string,
|
||||
fullInput: string
|
||||
): Promise<ContextItem[]> {
|
||||
const workspaceDirs = await new ExtensionIde().getWorkspaceDirs();
|
||||
let trees = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@ class GitHubIssuesContextProvider extends BaseContextProvider {
|
|||
requiresQuery: false,
|
||||
};
|
||||
|
||||
async getContextItems(query: string): Promise<ContextItem[]> {
|
||||
async getContextItems(
|
||||
query: string,
|
||||
fullInput: string
|
||||
): Promise<ContextItem[]> {
|
||||
return [];
|
||||
}
|
||||
async load(): Promise<void> {}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,10 @@ class GoogleContextProvider extends BaseContextProvider {
|
|||
this._serperApiKey = options.serperApiKey;
|
||||
}
|
||||
|
||||
async getContextItems(query: string): Promise<ContextItem[]> {
|
||||
async getContextItems(
|
||||
query: string,
|
||||
fullInput: string
|
||||
): Promise<ContextItem[]> {
|
||||
const url = "https://google.serper.dev/search";
|
||||
|
||||
const payload = JSON.stringify({ q: query });
|
||||
|
|
|
|||
|
|
@ -22,7 +22,10 @@ class HttpContextProvider extends BaseContextProvider {
|
|||
};
|
||||
}
|
||||
|
||||
async getContextItems(query: string): Promise<ContextItem[]> {
|
||||
async getContextItems(
|
||||
query: string,
|
||||
fullInput: string
|
||||
): Promise<ContextItem[]> {
|
||||
const response = await fetch(this.options.url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,10 @@ class OpenFilesContextProvider extends BaseContextProvider {
|
|||
requiresQuery: false,
|
||||
};
|
||||
|
||||
async getContextItems(query: string): Promise<ContextItem[]> {
|
||||
async getContextItems(
|
||||
query: string,
|
||||
fullInput: string
|
||||
): Promise<ContextItem[]> {
|
||||
const ide = new ExtensionIde();
|
||||
const openFiles = await ide.getOpenFiles();
|
||||
return await Promise.all(
|
||||
|
|
|
|||
|
|
@ -11,7 +11,10 @@ class SearchContextProvider extends BaseContextProvider {
|
|||
requiresQuery: true,
|
||||
};
|
||||
|
||||
async getContextItems(query: string): Promise<ContextItem[]> {
|
||||
async getContextItems(
|
||||
query: string,
|
||||
fullInput: string
|
||||
): Promise<ContextItem[]> {
|
||||
const results = await new ExtensionIde().getSearchResults(query);
|
||||
return [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,10 @@ class TerminalContextProvider extends BaseContextProvider {
|
|||
requiresQuery: false,
|
||||
};
|
||||
|
||||
async getContextItems(query: string): Promise<ContextItem[]> {
|
||||
async getContextItems(
|
||||
query: string,
|
||||
fullInput: string
|
||||
): Promise<ContextItem[]> {
|
||||
const content = await new ExtensionIde().getTerminalContents();
|
||||
return [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@ class URLContextProvider extends BaseContextProvider {
|
|||
requiresQuery: true,
|
||||
};
|
||||
|
||||
async getContextItems(query: string): Promise<ContextItem[]> {
|
||||
async getContextItems(
|
||||
query: string,
|
||||
fullInput: string
|
||||
): Promise<ContextItem[]> {
|
||||
let url = query.trim();
|
||||
if (!url.startsWith("http")) {
|
||||
url = "https://" + url;
|
||||
|
|
|
|||
4
core/index.d.ts
vendored
4
core/index.d.ts
vendored
|
|
@ -56,13 +56,13 @@ export interface CustomContextProvider {
|
|||
title: string;
|
||||
displayTitle?: string;
|
||||
description?: string;
|
||||
getContextItems(query: string): Promise<ContextItem[]>;
|
||||
getContextItems(query: string, fullInput: string): Promise<ContextItem[]>;
|
||||
}
|
||||
|
||||
export interface IContextProvider {
|
||||
get description(): ContextProviderDescription;
|
||||
|
||||
getContextItems(query: string): Promise<ContextItem[]>;
|
||||
getContextItems(query: string, fullInput: string): Promise<ContextItem[]>;
|
||||
}
|
||||
|
||||
export interface PersistedSessionInfo {
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ interface CustomContextProvider {
|
|||
title: string;
|
||||
displayTitle?: string;
|
||||
description?: string;
|
||||
getContextItems(query: string): Promise<ContextItem[]>;
|
||||
getContextItems(query: string, fullInput: string): Promise<ContextItem[]>;
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -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 }),
|
||||
|
|
|
|||
|
|
@ -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`;
|
||||
|
|
|
|||
|
|
@ -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<ContextItemWithId[]> {
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue