Merge pull request #5132 from continuedev/nate/config-json-converter
update converter
This commit is contained in:
commit
fce9dba73f
8 changed files with 146 additions and 40 deletions
|
|
@ -1,35 +0,0 @@
|
|||
import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml";
|
||||
|
||||
import { SerializedContinueConfig } from "../..";
|
||||
|
||||
/*
|
||||
TODO this is not functional
|
||||
*/
|
||||
export function convertConfigJsonToConfigYaml(
|
||||
configJson: SerializedContinueConfig,
|
||||
): AssistantUnrolled {
|
||||
return {
|
||||
name: "Local Assistant",
|
||||
version: "1.0.0",
|
||||
schema: "v1",
|
||||
models: [
|
||||
...configJson.models.map(
|
||||
(model): ModelConfig => ({
|
||||
model: model.model,
|
||||
name: model.title,
|
||||
// defaultCompletionOptions: model.completionOptions,
|
||||
provider: model.provider,
|
||||
roles: ["chat", "edit", "apply", "summarize"],
|
||||
}),
|
||||
),
|
||||
// TODO
|
||||
// tabAutocompleteModels
|
||||
// embeddingsModels
|
||||
// rerankModels
|
||||
],
|
||||
context: configJson.contextProviders?.map((provider) => ({
|
||||
provider: provider.name,
|
||||
params: provider.params,
|
||||
})),
|
||||
};
|
||||
}
|
||||
7
extensions/vscode/package-lock.json
generated
7
extensions/vscode/package-lock.json
generated
|
|
@ -9,6 +9,7 @@
|
|||
"version": "1.1.28",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.14",
|
||||
"@continuedev/fetch": "^1.0.3",
|
||||
"@electron/rebuild": "^3.2.10",
|
||||
"@reduxjs/toolkit": "^1.9.3",
|
||||
|
|
@ -693,9 +694,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@continuedev/config-types": {
|
||||
"version": "1.0.13",
|
||||
"resolved": "https://registry.npmjs.org/@continuedev/config-types/-/config-types-1.0.13.tgz",
|
||||
"integrity": "sha512-5Qmy2x58uhW1GYknypFT/7iwxEJSbt8gMgfQReV7d6xjbJ09ISOTki3hIfCilKrTCo0gIY6pzKEfCoQkUTEi6Q==",
|
||||
"version": "1.0.14",
|
||||
"resolved": "https://registry.npmjs.org/@continuedev/config-types/-/config-types-1.0.14.tgz",
|
||||
"integrity": "sha512-PVHyHPyRXd2QsaNgnCpiKYU3uHFTlyuQSkqE8OwrBmQqO6/TXUVIr/2EGtyIZGrml4Y+rGMSH40WU4/0t4SGpQ==",
|
||||
"dependencies": {
|
||||
"zod": "^3.23.8"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -666,6 +666,7 @@
|
|||
"vscode-extension-tester": "^8.10.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.14",
|
||||
"@continuedev/fetch": "^1.0.3",
|
||||
"@electron/rebuild": "^3.2.10",
|
||||
"@reduxjs/toolkit": "^1.9.3",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import * as fs from "node:fs";
|
||||
import * as os from "node:os";
|
||||
|
||||
import {
|
||||
|
|
@ -17,10 +18,15 @@ import { walkDirAsync } from "core/indexing/walkDir";
|
|||
import { isModelInstaller } from "core/llm";
|
||||
import { extractMinimalStackTraceInfo } from "core/util/extractMinimalStackTraceInfo";
|
||||
import { startLocalOllama } from "core/util/ollamaHelper";
|
||||
import { getDevDataFilePath } from "core/util/paths";
|
||||
import {
|
||||
getConfigJsonPath,
|
||||
getConfigYamlPath,
|
||||
getDevDataFilePath,
|
||||
} from "core/util/paths";
|
||||
import { Telemetry } from "core/util/posthog";
|
||||
import readLastLines from "read-last-lines";
|
||||
import * as vscode from "vscode";
|
||||
import * as YAML from "yaml";
|
||||
|
||||
import {
|
||||
getAutocompleteStatusBarDescription,
|
||||
|
|
@ -40,6 +46,8 @@ import { Battery } from "./util/battery";
|
|||
import { getMetaKeyLabel } from "./util/util";
|
||||
import { VsCodeIde } from "./VsCodeIde";
|
||||
|
||||
import { convertJsonToYamlConfig } from "../../../packages/config-yaml/dist";
|
||||
import { openEditorAndRevealRange } from "./util/vscode";
|
||||
import type { VsCodeWebviewProtocol } from "./webviewProtocol";
|
||||
|
||||
let fullScreenPanel: vscode.WebviewPanel | undefined;
|
||||
|
|
@ -1013,6 +1021,35 @@ const getCommandsMap: (
|
|||
);
|
||||
}
|
||||
},
|
||||
"continue.convertConfigJsonToConfigYaml": async () => {
|
||||
const configJson = fs.readFileSync(getConfigJsonPath(), "utf-8");
|
||||
const parsed = JSON.parse(configJson);
|
||||
const configYaml = convertJsonToYamlConfig(parsed);
|
||||
|
||||
const configYamlPath = getConfigYamlPath();
|
||||
fs.writeFileSync(configYamlPath, YAML.stringify(configYaml));
|
||||
|
||||
// Open config.yaml
|
||||
await openEditorAndRevealRange(
|
||||
vscode.Uri.file(configYamlPath),
|
||||
undefined,
|
||||
undefined,
|
||||
false,
|
||||
);
|
||||
|
||||
vscode.window
|
||||
.showInformationMessage(
|
||||
"Your config.json has been converted to the new config.yaml format. If you need to switch back to config.json, you can delete or rename config.yaml.",
|
||||
"Read the docs",
|
||||
)
|
||||
.then((selection) => {
|
||||
if (selection === "Read the docs") {
|
||||
vscode.env.openExternal(
|
||||
vscode.Uri.parse("https://docs.continue.dev/yaml-migration"),
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
import { getConfigYamlPath } from "core/util/paths";
|
||||
import * as fs from "fs";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
export class ConfigJsonConverterCodeLensProvider
|
||||
implements vscode.CodeLensProvider
|
||||
{
|
||||
public provideCodeLenses(
|
||||
document: vscode.TextDocument,
|
||||
_: vscode.CancellationToken,
|
||||
): vscode.CodeLens[] | Thenable<vscode.CodeLens[]> {
|
||||
if (
|
||||
!document.uri.fsPath.includes(".continue") ||
|
||||
!document.uri.fsPath.endsWith("config.json")
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (fs.existsSync(getConfigYamlPath())) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
new vscode.CodeLens(new vscode.Range(0, 0, 0, 0), {
|
||||
title: "config.json is being deprecated. Convert to config.yaml",
|
||||
command: "continue.convertConfigJsonToConfigYaml",
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -2,3 +2,5 @@ export { DownloadYamlExtensionCodeLensProvider } from "./DownloadYamlExtensionCo
|
|||
export { QuickActionsCodeLensProvider } from "./QuickActionsCodeLensProvider";
|
||||
export { SuggestionsCodeLensProvider } from "./SuggestionsCodeLensProvider";
|
||||
export { VerticalDiffCodeLensProvider as VerticalPerLineCodeLensProvider } from "./VerticalPerLineCodeLensProvider";
|
||||
|
||||
export { ConfigJsonConverterCodeLensProvider } from "./ConfigJsonConverterCodeLensProvider";
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ let suggestionsCodeLensDisposable: vscode.Disposable | undefined = undefined;
|
|||
let configPyCodeLensDisposable: vscode.Disposable | undefined = undefined;
|
||||
let tutorialCodeLensDisposable: vscode.Disposable | undefined = undefined;
|
||||
let quickActionsCodeLensDisposable: vscode.Disposable | undefined = undefined;
|
||||
let configJsonConverterCodeLensDisposable: vscode.Disposable | undefined =
|
||||
undefined;
|
||||
let downloadYamlExtensionCodeLensDisposable: vscode.Disposable | undefined =
|
||||
undefined;
|
||||
|
||||
|
|
@ -98,6 +100,10 @@ export function registerAllCodeLensProviders(
|
|||
tutorialCodeLensDisposable.dispose();
|
||||
}
|
||||
|
||||
if (configJsonConverterCodeLensDisposable) {
|
||||
configJsonConverterCodeLensDisposable.dispose();
|
||||
}
|
||||
|
||||
if (downloadYamlExtensionCodeLensDisposable) {
|
||||
downloadYamlExtensionCodeLensDisposable.dispose();
|
||||
}
|
||||
|
|
@ -116,6 +122,11 @@ export function registerAllCodeLensProviders(
|
|||
new providers.SuggestionsCodeLensProvider(),
|
||||
);
|
||||
|
||||
configJsonConverterCodeLensDisposable = registerCodeLensProvider(
|
||||
"*",
|
||||
new providers.ConfigJsonConverterCodeLensProvider(),
|
||||
);
|
||||
|
||||
downloadYamlExtensionCodeLensDisposable = registerCodeLensProvider(
|
||||
"yaml",
|
||||
new providers.DownloadYamlExtensionCodeLensProvider(),
|
||||
|
|
@ -131,6 +142,7 @@ export function registerAllCodeLensProviders(
|
|||
|
||||
context.subscriptions.push(verticalPerLineCodeLensProvider);
|
||||
context.subscriptions.push(suggestionsCodeLensDisposable);
|
||||
context.subscriptions.push(configJsonConverterCodeLensDisposable);
|
||||
|
||||
return { verticalDiffCodeLens };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,11 +46,69 @@ function convertReranker(m: NonNullable<ConfigJson["reranker"]>): ModelYaml {
|
|||
};
|
||||
}
|
||||
|
||||
function withFromContextProvider(
|
||||
contextProvider: NonNullable<ConfigJson["contextProviders"]>[number],
|
||||
): Record<string, string> | undefined {
|
||||
const { name, params } = contextProvider;
|
||||
|
||||
switch (name) {
|
||||
case "greptile":
|
||||
return {
|
||||
GITHUB_TOKEN: params?.GithubToken ?? "",
|
||||
GREPTILE_TOKEN: params?.GreptileToken ?? "",
|
||||
};
|
||||
case "jira":
|
||||
return {
|
||||
JIRA_TOKEN: params?.JiraToken ?? "",
|
||||
JIRA_API_VERSION: params?.JiraEmail,
|
||||
JIRA_DOMAIN: params?.JiraDomain ?? "",
|
||||
};
|
||||
case "postgres":
|
||||
return {
|
||||
POSTGRES_HOST: params?.host,
|
||||
POSTGRES_PORT: params?.port,
|
||||
POSTGRES_USER: params?.user,
|
||||
POSTGRES_PASSWORD: params?.password,
|
||||
POSTGRES_DATABASE: params?.database,
|
||||
POSTGRES_SCHEMA: params?.schema,
|
||||
};
|
||||
case "gitlab-mr":
|
||||
return {
|
||||
GITLAB_TOKEN: params?.token,
|
||||
DOMAIN: params?.domain,
|
||||
};
|
||||
case "discord":
|
||||
return {
|
||||
DISCORD_KEY: params?.discordKey,
|
||||
DISCORD_GUILD_ID: params?.guildId,
|
||||
DISCORD_CHANNELS: params?.channels,
|
||||
};
|
||||
case "commits":
|
||||
return {
|
||||
DEPTH: params?.Depth,
|
||||
LAST_N_COMMITS_DEPTH: params?.LastXCommitsDepth,
|
||||
};
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function convertContext(configJson: ConfigJson): ContextYaml[] {
|
||||
const context: ContextYaml[] =
|
||||
configJson.contextProviders?.map((ctx) => {
|
||||
// ctx providers that weren't given official blocks
|
||||
if (
|
||||
["web", "debugger", "issue", "database", "google", "http"].includes(
|
||||
ctx.name,
|
||||
)
|
||||
) {
|
||||
return {
|
||||
provider: ctx.name,
|
||||
params: ctx.params,
|
||||
};
|
||||
}
|
||||
return {
|
||||
uses: `builtin/${ctx.name}`,
|
||||
uses: `continuedev/${ctx.name === "open" ? "open-files" : ctx.name}-context`,
|
||||
with: ctx.params,
|
||||
};
|
||||
}) ?? [];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue