🚚 move core types to .continue/types

This commit is contained in:
Nate Sesti 2024-01-12 10:28:16 -08:00
parent b49342300a
commit 876164ab23
6 changed files with 103 additions and 90 deletions

View file

@ -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<any>;
complete(prompt: string, options?: LLMFullCompletionOptions): Promise<string>;
streamComplete(
prompt: string,
options?: LLMFullCompletionOptions
): AsyncGenerator<string, LLMReturnValue>;
streamChat(
messages: ChatMessage[],
options?: LLMFullCompletionOptions
): AsyncGenerator<ChatMessage, LLMReturnValue>;
chat(
messages: ChatMessage[],
options?: LLMFullCompletionOptions
): Promise<ChatMessage>;
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<ContextItem[]>;
}
export interface IContextProvider {
get description(): ContextProviderDescription;
getContextItems(
query: string,
extras: ContextProviderExtras
): Promise<ContextItem[]>;
}
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<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
}[Keys];
export interface CustomLLMWithOptionals {
options?: LLMOptions;
streamCompletion?: (
@ -236,7 +249,7 @@ declare global {
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>
) => AsyncGenerator<string>;
}
/**
* 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<SerializedContinueConfig>;
getConfigJsUrl(): Promise<string | undefined>;
@ -280,7 +293,7 @@ declare global {
getOpenFiles(): Promise<string[]>;
getSearchResults(query: string): Promise<string>;
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<Chunk[]>;
}
// 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<string | undefined>;
// 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<number[][]>;
}
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 {};

13
core/index.d.ts vendored
View file

@ -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;

View file

@ -1,4 +1,4 @@
import { Chunk, ChunkWithoutID } from ".";
import { Chunk, ChunkWithoutID } from "../..";
import { basicChunker } from "./basic";
import { codeChunker, fileExtensionToLanguage } from "./code";

View file

@ -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
}

View file

@ -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"],
},

View file

@ -69,7 +69,7 @@ function getSuggestion(
},
onExit() {
popup[0]?.destroy();
popup?.[0]?.destroy();
component.destroy();
onClose();
},