🎨 run context providers from IDE-side to avoid proxy server
This commit is contained in:
parent
88df903fe7
commit
6d5fc054f4
13 changed files with 58 additions and 66 deletions
|
|
@ -4,7 +4,6 @@ import {
|
|||
ContextProviderExtras,
|
||||
IContextProvider,
|
||||
} from "..";
|
||||
|
||||
export abstract class BaseContextProvider implements IContextProvider {
|
||||
options: { [key: string]: any };
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import {
|
|||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { ExtensionIde } from "../../ide";
|
||||
|
||||
class DiffContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
@ -19,7 +18,7 @@ class DiffContextProvider extends BaseContextProvider {
|
|||
query: string,
|
||||
extras: ContextProviderExtras
|
||||
): Promise<ContextItem[]> {
|
||||
const diff = await new ExtensionIde().getDiff();
|
||||
const diff = await extras.ide.getDiff();
|
||||
return [
|
||||
{
|
||||
description: "The current git diff",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import {
|
|||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { ExtensionIde } from "../../ide";
|
||||
|
||||
class FileContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
@ -21,7 +20,7 @@ class FileContextProvider extends BaseContextProvider {
|
|||
): Promise<ContextItem[]> {
|
||||
// Assume the query is a filepath
|
||||
query = query.trim();
|
||||
const content = await new ExtensionIde().readFile(query);
|
||||
const content = await extras.ide.readFile(query);
|
||||
return [
|
||||
{
|
||||
name: query.split(/[\\/]/).pop() || query,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import {
|
|||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { ExtensionIde } from "../../ide";
|
||||
|
||||
interface Directory {
|
||||
name: string;
|
||||
|
|
@ -48,13 +47,11 @@ class FileTreeContextProvider extends BaseContextProvider {
|
|||
query: string,
|
||||
extras: ContextProviderExtras
|
||||
): Promise<ContextItem[]> {
|
||||
const workspaceDirs = await new ExtensionIde().getWorkspaceDirs();
|
||||
const workspaceDirs = await extras.ide.getWorkspaceDirs();
|
||||
let trees = [];
|
||||
|
||||
for (let workspaceDir of workspaceDirs) {
|
||||
const contents = await new ExtensionIde().listWorkspaceContents(
|
||||
workspaceDir
|
||||
);
|
||||
const contents = await extras.ide.listWorkspaceContents(workspaceDir);
|
||||
|
||||
const subDirTree: Directory = {
|
||||
name: splitPath(workspaceDir).pop() || "",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import {
|
|||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { ExtensionIde } from "../../ide";
|
||||
import { getBasename } from "../../util";
|
||||
|
||||
class OpenFilesContextProvider extends BaseContextProvider {
|
||||
|
|
@ -20,7 +19,7 @@ class OpenFilesContextProvider extends BaseContextProvider {
|
|||
query: string,
|
||||
extras: ContextProviderExtras
|
||||
): Promise<ContextItem[]> {
|
||||
const ide = new ExtensionIde();
|
||||
const ide = extras.ide;
|
||||
const openFiles = await ide.getOpenFiles();
|
||||
return await Promise.all(
|
||||
openFiles.map(async (filepath: string) => {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import {
|
|||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { ExtensionIde } from "../../ide";
|
||||
import { getBasename } from "../../util";
|
||||
|
||||
class ProblemsContextProvider extends BaseContextProvider {
|
||||
|
|
@ -20,7 +19,7 @@ class ProblemsContextProvider extends BaseContextProvider {
|
|||
query: string,
|
||||
extras: ContextProviderExtras
|
||||
): Promise<ContextItem[]> {
|
||||
const ide = new ExtensionIde();
|
||||
const ide = extras.ide;
|
||||
const problems = await ide.getProblems();
|
||||
|
||||
const items = await Promise.all(
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import {
|
|||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { ExtensionIde } from "../../ide";
|
||||
|
||||
class SearchContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
@ -19,7 +18,7 @@ class SearchContextProvider extends BaseContextProvider {
|
|||
query: string,
|
||||
extras: ContextProviderExtras
|
||||
): Promise<ContextItem[]> {
|
||||
const results = await new ExtensionIde().getSearchResults(query);
|
||||
const results = await extras.ide.getSearchResults(query);
|
||||
return [
|
||||
{
|
||||
description: "Search results",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import {
|
|||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { ExtensionIde } from "../../ide";
|
||||
|
||||
class TerminalContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
@ -19,7 +18,7 @@ class TerminalContextProvider extends BaseContextProvider {
|
|||
query: string,
|
||||
extras: ContextProviderExtras
|
||||
): Promise<ContextItem[]> {
|
||||
const content = await new ExtensionIde().getTerminalContents();
|
||||
const content = await extras.ide.getTerminalContents();
|
||||
return [
|
||||
{
|
||||
description: "The contents of the terminal",
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import {
|
|||
ILLM,
|
||||
ModelProvider,
|
||||
} from "..";
|
||||
import { ExtensionIde } from "../ide";
|
||||
import { getBasename } from "../util";
|
||||
|
||||
const RERANK_PROMPT = (
|
||||
|
|
@ -141,7 +140,7 @@ export async function retrieveContextItemsFromEmbeddings(
|
|||
(options?.useReranking === undefined ? false : options?.useReranking);
|
||||
|
||||
// Similarity search
|
||||
let results = await new ExtensionIde().retrieveChunks(
|
||||
let results = await extras.ide.retrieveChunks(
|
||||
extras.fullInput,
|
||||
useReranking === false ? nFinal : nRetrieve,
|
||||
filterDirectory
|
||||
|
|
|
|||
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -73,6 +73,7 @@ interface ContextProviderExtras {
|
|||
fullInput: string;
|
||||
embeddingsProvider?: EmbeddingsProvider;
|
||||
llm: ILLM;
|
||||
ide: IDE;
|
||||
}
|
||||
|
||||
export interface CustomContextProvider {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { DiffLine, FileEdit, ModelDescription } from "core";
|
||||
import { ContextItemId, DiffLine, FileEdit, ModelDescription } from "core";
|
||||
import { editConfigJson, getConfigJsonPath } from "core/util/paths";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import * as io from "socket.io-client";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import * as vscode from "vscode";
|
||||
import { ideProtocolClient, windowId } from "./activation/activate";
|
||||
import { getContinueServerUrl } from "./bridge";
|
||||
|
|
@ -592,6 +593,43 @@ export function getSidebarContent(
|
|||
respond({ done: true });
|
||||
break;
|
||||
}
|
||||
case "getContextItems": {
|
||||
const { name, query, fullInput } = data.message;
|
||||
const config = await configHandler.loadConfig(ide);
|
||||
const llm = await llmFromTitle();
|
||||
const provider = config.contextProviders?.find(
|
||||
(p) => p.description.title === name
|
||||
);
|
||||
if (!provider) {
|
||||
vscode.window.showErrorMessage(
|
||||
`Unknown provider ${name}. Existing providers: ${config.contextProviders
|
||||
?.map((p) => p.description.title)
|
||||
.join(", ")}`
|
||||
);
|
||||
respond({ items: [] });
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
const id: ContextItemId = {
|
||||
providerTitle: provider.description.title,
|
||||
itemId: uuidv4(),
|
||||
};
|
||||
const items = await provider.getContextItems(query, {
|
||||
llm,
|
||||
embeddingsProvider: config.embeddingsProvider,
|
||||
fullInput,
|
||||
ide,
|
||||
});
|
||||
respond({ items: items.map((item) => ({ ...item, id })) });
|
||||
} catch (e) {
|
||||
vscode.window.showErrorMessage(
|
||||
`Error getting context items from ${name}: ${e}`
|
||||
);
|
||||
respond({ items: [] });
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
vscode.window
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import {
|
|||
ILLM,
|
||||
} from "core";
|
||||
import { ExtensionIde } from "core/ide";
|
||||
import { ideRequest } from "core/ide/messaging";
|
||||
import { getBasename } from "core/util";
|
||||
import { getContextItems } from "../../hooks/useContextProviders";
|
||||
|
||||
interface MentionAttrs {
|
||||
label: string;
|
||||
|
|
@ -73,15 +73,14 @@ async function resolveEditorContent(
|
|||
},
|
||||
});
|
||||
} else {
|
||||
const resolvedItems = await getContextItems(
|
||||
contextProviders,
|
||||
item.id,
|
||||
item.query,
|
||||
{
|
||||
fullInput: paragraphs.join("\n"),
|
||||
embeddingsProvider,
|
||||
llm,
|
||||
}
|
||||
const data = {
|
||||
name: item.id,
|
||||
query: item.query,
|
||||
fullInput: paragraphs.join("\n"),
|
||||
};
|
||||
const { items: resolvedItems } = await ideRequest(
|
||||
"getContextItems",
|
||||
data
|
||||
);
|
||||
contextItems.push(...resolvedItems);
|
||||
for (const resolvedItem of resolvedItems) {
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
import {
|
||||
ContextItemId,
|
||||
ContextItemWithId,
|
||||
ContextProviderExtras,
|
||||
IContextProvider,
|
||||
} from "core";
|
||||
import { v4 } from "uuid";
|
||||
import { errorPopup } from "../util/ide";
|
||||
|
||||
export async function getContextItems(
|
||||
contextProviders: IContextProvider[],
|
||||
name: string,
|
||||
query: string,
|
||||
extras: ContextProviderExtras
|
||||
): Promise<ContextItemWithId[]> {
|
||||
const provider = contextProviders.find((p) => p.description.title === name);
|
||||
if (!provider) {
|
||||
errorPopup(
|
||||
`Unknown provider ${name}. Existing providers: ${contextProviders
|
||||
.map((p) => p.description.title)
|
||||
.join(", ")}`
|
||||
);
|
||||
}
|
||||
try {
|
||||
const id: ContextItemId = {
|
||||
providerTitle: provider.description.title,
|
||||
itemId: v4(),
|
||||
};
|
||||
const items = await provider.getContextItems(query, extras);
|
||||
return items.map((item) => ({ ...item, id }));
|
||||
} catch (e) {
|
||||
errorPopup(`Error getting context items from ${name}: ${e.message}`);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue