From 876164ab23231cd30488f967209b162c92567ffd Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Fri, 12 Jan 2024 10:28:16 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20move=20core=20types=20to=20.cont?= =?UTF-8?q?inue/types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/config/types.ts | 146 ++++++++++-------- core/index.d.ts | 13 +- core/index/chunk/chunk.ts | 2 +- core/index/chunk/index.d.ts | 12 -- core/util/paths.ts | 18 +-- gui/src/components/mainInput/getSuggestion.ts | 2 +- 6 files changed, 103 insertions(+), 90 deletions(-) delete mode 100644 core/index/chunk/index.d.ts diff --git a/core/config/types.ts b/core/config/types.ts index 657e4e011..9a320e690 100644 --- a/core/config/types.ts +++ b/core/config/types.ts @@ -1,15 +1,28 @@ const Types = ` declare global { + export interface ChunkWithoutID { + content: string; + startLine: number; + endLine: number; + otherMetadata?: { [key: string]: any }; + } + + export interface Chunk extends ChunkWithoutID { + digest: string; + filepath: string; + index: number; // Index of the chunk in the document at filepath + } + export interface LLMReturnValue { prompt: string; completion: string; } export interface ILLM extends LLMOptions { get providerName(): ModelProvider; - + uniqueId: string; model: string; - + title?: string; systemMessage?: string; contextLength: number; @@ -21,35 +34,35 @@ declare global { llmRequestHook?: (model: string, prompt: string) => any; apiKey?: string; apiBase?: string; - + engine?: string; apiVersion?: string; apiType?: string; region?: string; projectId?: string; - + _fetch?: (input: any, init?: any) => Promise; - + complete(prompt: string, options?: LLMFullCompletionOptions): Promise; - + streamComplete( prompt: string, options?: LLMFullCompletionOptions ): AsyncGenerator; - + streamChat( messages: ChatMessage[], options?: LLMFullCompletionOptions ): AsyncGenerator; - + chat( messages: ChatMessage[], options?: LLMFullCompletionOptions ): Promise; - + countTokens(text: string): number; } - + export interface ContextProviderDescription { title: string; displayTitle: string; @@ -57,13 +70,13 @@ declare global { dynamic: boolean; requiresQuery: boolean; } - + interface ContextProviderExtras { fullInput: string; embeddingsProvider?: EmbeddingsProvider; llm: ILLM; } - + export interface CustomContextProvider { title: string; displayTitle?: string; @@ -73,35 +86,35 @@ declare global { extras: ContextProviderExtras ): Promise; } - + export interface IContextProvider { get description(): ContextProviderDescription; - + getContextItems( query: string, extras: ContextProviderExtras ): Promise; } - + export interface PersistedSessionInfo { history: ChatHistory; title: string; workspaceDirectory: string; sessionId: string; } - + export interface SessionInfo { sessionId: string; title: string; dateCreated: string; workspaceDirectory: string; } - + export interface RangeInFile { filepath: string; range: Range; } - + export interface Range { start: Position; end: Position; @@ -115,15 +128,15 @@ declare global { range: Range; replacement: string; } - + export interface ContinueError { title: string; message: string; } - + export interface CompletionOptions { model: string; - + maxTokens: number; temperature?: number; topP?: number; @@ -133,19 +146,19 @@ declare global { frequencyPenalty?: number; stop?: string[]; } - + export type ChatMessageRole = "user" | "assistant" | "system"; - + export interface ChatMessage { role: ChatMessageRole; content: string; } - + export interface ContextItemId { providerTitle: string; itemId: string; } - + export interface ContextItem { content: string; name: string; @@ -153,7 +166,7 @@ declare global { editing?: boolean; editable?: boolean; } - + export interface ContextItemWithId { content: string; name: string; @@ -162,24 +175,24 @@ declare global { editing?: boolean; editable?: boolean; } - + export interface ChatHistoryItem { message: ChatMessage; editorState?: any; contextItems: ContextItemWithId[]; promptLogs?: [string, string][]; // [prompt, completion] } - + export type ChatHistory = ChatHistoryItem[]; - + // LLM - + export interface LLMFullCompletionOptions { raw?: boolean; log?: boolean; - + model?: string; - + temperature?: number; topP?: number; topK?: number; @@ -191,7 +204,7 @@ declare global { } export interface LLMOptions { model: string; - + title?: string; uniqueId?: string; systemMessage?: string; @@ -205,12 +218,12 @@ declare global { llmRequestHook?: (model: string, prompt: string) => any; apiKey?: string; apiBase?: string; - + // Azure options engine?: string; apiVersion?: string; apiType?: string; - + // GCP Options region?: string; projectId?: string; @@ -222,7 +235,7 @@ declare global { { [K in Keys]-?: Required> & Partial>>; }[Keys]; - + export interface CustomLLMWithOptionals { options?: LLMOptions; streamCompletion?: ( @@ -236,7 +249,7 @@ declare global { fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise ) => AsyncGenerator; } - + /** * The LLM interface requires you to specify either \`streamCompletion\` or \`streamChat\` (or both). */ @@ -244,14 +257,14 @@ declare global { CustomLLMWithOptionals, "streamCompletion" | "streamChat" >; - + // IDE - + export interface DiffLine { type: "new" | "old" | "same"; line: string; } - + export interface IDE { getSerializedConfig(): Promise; getConfigJsUrl(): Promise; @@ -280,7 +293,7 @@ declare global { getOpenFiles(): Promise; getSearchResults(query: string): Promise; subprocess(command: string): Promise<[string, string]>; - + // Embeddings /** * Returns list of [tag, filepath, hash of contents] that need to be embedded @@ -298,9 +311,9 @@ declare global { providerId: string ): Promise; } - + // Slash Commands - + export interface ContinueSDK { ide: IDE; llm: ILLM; @@ -310,20 +323,20 @@ declare global { params?: any; contextItems: ContextItemWithId[]; } - + export interface SlashCommand { name: string; description: string; params?: { [key: string]: any }; run: (sdk: ContinueSDK) => AsyncGenerator; - + // If true, this command will be run in NodeJs and have access to the filesystem and other Node-only APIs // You must make sure to dynamically import any Node-only dependencies in your command so that it doesn't break in the browser runInNodeJs?: boolean; } - + // Config - + type StepName = | "AnswerQuestionChroma" | "GenerateShellCommandStep" @@ -335,7 +348,7 @@ declare global { | "OpenConfigStep" | "GenerateShellCommandStep" | "DraftIssueStep"; - + type ContextProviderName = | "diff" | "github" @@ -347,7 +360,7 @@ declare global { | "tree" | "http" | "codebase"; - + type TemplateType = | "llama2" | "alpaca" @@ -359,7 +372,7 @@ declare global { | "openchat" | "deepseek" | "xwin-coder"; - + type ModelProvider = | "openai" | "free-trial" @@ -378,7 +391,7 @@ declare global { | "mistral" | "bedrock" | "deepinfra"; - + export type ModelName = // OpenAI | "gpt-3.5-turbo" @@ -414,7 +427,7 @@ declare global { | "mistral-tiny" | "mistral-small" | "mistral-medium"; - + export interface RequestOptions { timeout?: number; verifySsl?: boolean; @@ -422,29 +435,29 @@ declare global { proxy?: string; headers?: { [key: string]: string }; } - + export interface StepWithParams { name: StepName; params: { [key: string]: any }; } - + export interface ContextProviderWithParams { name: ContextProviderName; params: { [key: string]: any }; } - + export interface SlashCommandDescription { name: string; description: string; params?: { [key: string]: any }; } - + export interface CustomCommand { name: string; prompt: string; description: string; } - + interface BaseCompletionOptions { temperature?: number; topP?: number; @@ -455,7 +468,7 @@ declare global { stop?: string[]; maxTokens: number; } - + export interface ModelDescription { title: string; provider: ModelProvider; @@ -469,24 +482,24 @@ declare global { requestOptions?: RequestOptions; promptTemplates?: { [key: string]: string }; } - + export type EmbeddingsProviderName = "transformers.js" | "ollama" | "openai"; - + export interface EmbedOptions { apiBase?: string; apiKey?: string; model?: string; } - + export interface EmbeddingsProviderDescription extends EmbedOptions { provider: EmbeddingsProviderName; } - + export interface EmbeddingsProvider { id: string; embed(chunks: string[]): Promise; } - + export interface SerializedContinueConfig { disallowedSteps?: string[]; allowAnonymousTelemetry?: boolean; @@ -501,7 +514,7 @@ declare global { userToken?: string; embeddingsProvider?: EmbeddingsProviderDescription; } - + export interface Config { /** If set to true, Continue will collect anonymous usage data to improve the product. If set to false, we will collect nothing. Read here to learn more: https://continue.dev/docs/telemetry */ allowAnonymousTelemetry?: boolean; @@ -529,7 +542,7 @@ declare global { /** The provider used to calculate embeddings. If left empty, Continue will use transformers.js to calculate the embeddings with all-MiniLM-L6-v2 */ embeddingsProvider?: EmbeddingsProviderDescription | EmbeddingsProvider; } - + export interface ContinueConfig { allowAnonymousTelemetry?: boolean; models: ILLM[]; @@ -541,7 +554,8 @@ declare global { disableIndexing?: boolean; userToken?: string; embeddingsProvider?: EmbeddingsProvider; - } + } + } export {}; diff --git a/core/index.d.ts b/core/index.d.ts index 5d7d14889..ef6167195 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1,4 +1,15 @@ -import { Chunk } from "./index/chunk"; +export interface ChunkWithoutID { + content: string; + startLine: number; + endLine: number; + otherMetadata?: { [key: string]: any }; +} + +export interface Chunk extends ChunkWithoutID { + digest: string; + filepath: string; + index: number; // Index of the chunk in the document at filepath +} export interface LLMReturnValue { prompt: string; diff --git a/core/index/chunk/chunk.ts b/core/index/chunk/chunk.ts index aa197e0ad..a2fc13fab 100644 --- a/core/index/chunk/chunk.ts +++ b/core/index/chunk/chunk.ts @@ -1,4 +1,4 @@ -import { Chunk, ChunkWithoutID } from "."; +import { Chunk, ChunkWithoutID } from "../.."; import { basicChunker } from "./basic"; import { codeChunker, fileExtensionToLanguage } from "./code"; diff --git a/core/index/chunk/index.d.ts b/core/index/chunk/index.d.ts deleted file mode 100644 index 48162a617..000000000 --- a/core/index/chunk/index.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface ChunkWithoutID { - content: string; - startLine: number; - endLine: number; - otherMetadata?: { [key: string]: any }; -} - -export interface Chunk extends ChunkWithoutID { - digest: string; - filepath: string; - index: number; // Index of the chunk in the document at filepath -} diff --git a/core/util/paths.ts b/core/util/paths.ts index cc1f56424..b2fef7325 100644 --- a/core/util/paths.ts +++ b/core/util/paths.ts @@ -53,16 +53,15 @@ export function getConfigTsPath(): string { ); } - const node_modules_path = path.join(getContinueGlobalPath(), "node_modules"); - if (!fs.existsSync(node_modules_path)) { - fs.mkdirSync(node_modules_path); - fs.mkdirSync(path.join(node_modules_path, "@types")); - fs.mkdirSync(path.join(node_modules_path, "@types/core")); + const typesPath = path.join(getContinueGlobalPath(), "types"); + if (!fs.existsSync(typesPath)) { + fs.mkdirSync(typesPath); } - fs.writeFileSync( - path.join(node_modules_path, "@types/core", "index.d.ts"), - Types - ); + const corePath = path.join(typesPath, "core"); + if (!fs.existsSync(corePath)) { + fs.mkdirSync(corePath); + } + fs.writeFileSync(path.join(corePath, "index.d.ts"), Types); return p; } @@ -93,6 +92,7 @@ export function getTsConfigPath(): string { noEmit: false, noEmitOnError: false, outFile: "./config.js", + typeRoots: ["./node_modules/@types", "./types"], }, include: ["./config.ts"], }, diff --git a/gui/src/components/mainInput/getSuggestion.ts b/gui/src/components/mainInput/getSuggestion.ts index b45616e03..934c0999a 100644 --- a/gui/src/components/mainInput/getSuggestion.ts +++ b/gui/src/components/mainInput/getSuggestion.ts @@ -69,7 +69,7 @@ function getSuggestion( }, onExit() { - popup[0]?.destroy(); + popup?.[0]?.destroy(); component.destroy(); onClose(); },