diff --git a/core/config/types.ts b/core/config/types.ts index 8d91ff986..70839ecee 100644 --- a/core/config/types.ts +++ b/core/config/types.ts @@ -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; 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; + loadSubmenuItems?: ( + args: LoadSubmenuItemsArgs + ) => Promise; + } + + export interface ContextSubmenuItem { + id: string; + title: string; + description: string; } export interface IContextProvider { @@ -94,6 +118,8 @@ declare global { query: string, extras: ContextProviderExtras ): Promise; + + loadSubmenuItems(args: LoadSubmenuItemsArgs): Promise; } 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; getOpenFiles(): Promise; + getPinnedFiles(): Promise; getSearchResults(query: string): Promise; subprocess(command: string): Promise<[string, string]>; getProblems(filepath?: string | undefined): Promise; @@ -552,7 +587,7 @@ declare global { userToken?: string; embeddingsProvider: EmbeddingsProvider; } - + } export {}; diff --git a/core/index.d.ts b/core/index.d.ts index a3a368e48..93b413902 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -82,6 +82,7 @@ export interface ContextProviderExtras { embeddingsProvider: EmbeddingsProvider; llm: ILLM; ide: IDE; + selectedCode: RangeInFile[]; } export interface LoadSubmenuItemsArgs { diff --git a/extensions/vscode/src/debugPanel.ts b/extensions/vscode/src/debugPanel.ts index 7cd31c300..40d69b8a5 100644 --- a/extensions/vscode/src/debugPanel.ts +++ b/extensions/vscode/src/debugPanel.ts @@ -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) { diff --git a/extensions/vscode/src/ideProtocol.ts b/extensions/vscode/src/ideProtocol.ts index 0d339c224..87176446d 100644 --- a/extensions/vscode/src/ideProtocol.ts +++ b/extensions/vscode/src/ideProtocol.ts @@ -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); diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index 0d7d397ac..afecf29c0 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -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",