✨ add selectedCode property to ContextProviderExtras
This commit is contained in:
parent
44d40db724
commit
579acf2efb
5 changed files with 61 additions and 7 deletions
|
|
@ -13,6 +13,11 @@ declare global {
|
|||
index: number; // Index of the chunk in the document at filepath
|
||||
}
|
||||
|
||||
export interface IndexingProgressUpdate {
|
||||
progress: number;
|
||||
desc: string;
|
||||
}
|
||||
|
||||
export interface LLMReturnValue {
|
||||
prompt: string;
|
||||
completion: string;
|
||||
|
|
@ -61,30 +66,49 @@ declare global {
|
|||
): Promise<ChatMessage>;
|
||||
|
||||
countTokens(text: string): number;
|
||||
|
||||
supportsImages(): boolean;
|
||||
}
|
||||
|
||||
export type ContextProviderType = "normal" | "query" | "submenu";
|
||||
|
||||
export interface ContextProviderDescription {
|
||||
title: string;
|
||||
displayTitle: string;
|
||||
description: string;
|
||||
dynamic: boolean;
|
||||
requiresQuery: boolean;
|
||||
type: ContextProviderType;
|
||||
}
|
||||
|
||||
interface ContextProviderExtras {
|
||||
export interface ContextProviderExtras {
|
||||
fullInput: string;
|
||||
embeddingsProvider?: EmbeddingsProvider;
|
||||
embeddingsProvider: EmbeddingsProvider;
|
||||
llm: ILLM;
|
||||
ide: IDE;
|
||||
selectedCode: RangeInFile[];
|
||||
}
|
||||
|
||||
export interface LoadSubmenuItemsArgs {
|
||||
ide: IDE;
|
||||
}
|
||||
|
||||
export interface CustomContextProvider {
|
||||
title: string;
|
||||
displayTitle?: string;
|
||||
description?: string;
|
||||
type?: ContextProviderType;
|
||||
getContextItems(
|
||||
query: string,
|
||||
extras: ContextProviderExtras
|
||||
): Promise<ContextItem[]>;
|
||||
loadSubmenuItems?: (
|
||||
args: LoadSubmenuItemsArgs
|
||||
) => Promise<ContextSubmenuItem[]>;
|
||||
}
|
||||
|
||||
export interface ContextSubmenuItem {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface IContextProvider {
|
||||
|
|
@ -94,6 +118,8 @@ declare global {
|
|||
query: string,
|
||||
extras: ContextProviderExtras
|
||||
): Promise<ContextItem[]>;
|
||||
|
||||
loadSubmenuItems(args: LoadSubmenuItemsArgs): Promise<ContextSubmenuItem[]>;
|
||||
}
|
||||
|
||||
export interface PersistedSessionInfo {
|
||||
|
|
@ -140,9 +166,17 @@ declare global {
|
|||
|
||||
export type ChatMessageRole = "user" | "assistant" | "system";
|
||||
|
||||
export interface MessagePart {
|
||||
type: "text" | "imageUrl";
|
||||
text?: string;
|
||||
imageUrl?: { url: string };
|
||||
}
|
||||
|
||||
export type MessageContent = string | MessagePart[];
|
||||
|
||||
export interface ChatMessage {
|
||||
role: ChatMessageRole;
|
||||
content: string;
|
||||
content: MessageContent;
|
||||
}
|
||||
|
||||
export interface ContextItemId {
|
||||
|
|
@ -280,6 +314,7 @@ declare global {
|
|||
diffLine: DiffLine
|
||||
): Promise<void>;
|
||||
getOpenFiles(): Promise<string[]>;
|
||||
getPinnedFiles(): Promise<string[]>;
|
||||
getSearchResults(query: string): Promise<string>;
|
||||
subprocess(command: string): Promise<[string, string]>;
|
||||
getProblems(filepath?: string | undefined): Promise<Problem[]>;
|
||||
|
|
@ -552,7 +587,7 @@ declare global {
|
|||
userToken?: string;
|
||||
embeddingsProvider: EmbeddingsProvider;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
export {};
|
||||
|
|
|
|||
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -82,6 +82,7 @@ export interface ContextProviderExtras {
|
|||
embeddingsProvider: EmbeddingsProvider;
|
||||
llm: ILLM;
|
||||
ide: IDE;
|
||||
selectedCode: RangeInFile[];
|
||||
}
|
||||
|
||||
export interface LoadSubmenuItemsArgs {
|
||||
|
|
|
|||
|
|
@ -627,7 +627,7 @@ export function getSidebarContent(
|
|||
break;
|
||||
}
|
||||
case "getContextItems": {
|
||||
const { name, query, fullInput } = data.message;
|
||||
const { name, query, fullInput, selectedCode } = data.message;
|
||||
const config = await configHandler.loadConfig(ide);
|
||||
const llm = await llmFromTitle();
|
||||
const provider = config.contextProviders?.find(
|
||||
|
|
@ -653,6 +653,7 @@ export function getSidebarContent(
|
|||
embeddingsProvider: config.embeddingsProvider,
|
||||
fullInput,
|
||||
ide,
|
||||
selectedCode,
|
||||
});
|
||||
respond({ items: items.map((item) => ({ ...item, id })) });
|
||||
} catch (e) {
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ async function buildConfigTs(browser: boolean) {
|
|||
format: browser ? "esm" : "cjs",
|
||||
outfile: getConfigJsPath(!browser),
|
||||
external: ["fetch", "fs", "path", "os", "child_process"],
|
||||
sourcemap: true,
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
ILLM,
|
||||
MessageContent,
|
||||
MessagePart,
|
||||
RangeInFile,
|
||||
} from "core";
|
||||
import { ExtensionIde } from "core/ide";
|
||||
import { ideRequest } from "core/ide/messaging";
|
||||
|
|
@ -34,6 +35,7 @@ async function resolveEditorContent(
|
|||
): Promise<[ContextItemWithId[], MessageContent]> {
|
||||
let parts: MessagePart[] = [];
|
||||
let contextItemAttrs: MentionAttrs[] = [];
|
||||
const selectedCode: RangeInFile[] = [];
|
||||
let slashCommand = undefined;
|
||||
for (const p of editorState?.content) {
|
||||
if (p.type === "paragraph") {
|
||||
|
|
@ -64,6 +66,19 @@ async function resolveEditorContent(
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
const name: string = p.attrs.item.name;
|
||||
let lines = name.substring(name.lastIndexOf("(") + 1);
|
||||
lines = lines.substring(0, lines.lastIndexOf(")"));
|
||||
const [start, end] = lines.split("-");
|
||||
|
||||
selectedCode.push({
|
||||
filepath: p.attrs.item.description,
|
||||
range: {
|
||||
start: { line: parseInt(start) - 1, character: 0 },
|
||||
end: { line: parseInt(end) - 1, character: 0 },
|
||||
},
|
||||
});
|
||||
} else if (p.type === "image") {
|
||||
parts.push({
|
||||
type: "imageUrl",
|
||||
|
|
@ -99,6 +114,7 @@ async function resolveEditorContent(
|
|||
name: item.itemType === "contextProvider" ? item.id : item.itemType,
|
||||
query: item.query,
|
||||
fullInput: stripImages(parts),
|
||||
selectedCode,
|
||||
};
|
||||
const { items: resolvedItems } = await ideRequest(
|
||||
"getContextItems",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue