Merge pull request #5051 from continuedev/nate/gen-config-yaml-json-schema
generate json schema
This commit is contained in:
commit
a4fb80476a
16 changed files with 189 additions and 13 deletions
3
core/package-lock.json
generated
3
core/package-lock.json
generated
|
|
@ -126,7 +126,8 @@
|
|||
"cross-env": "^7.0.3",
|
||||
"jest": "^29.7.0",
|
||||
"ts-jest": "^29.2.3",
|
||||
"ts-node": "^10.9.2"
|
||||
"ts-node": "^10.9.2",
|
||||
"zod-to-json-schema": "^3.24.5"
|
||||
}
|
||||
},
|
||||
"node_modules/@75lb/deep-merge": {
|
||||
|
|
|
|||
4
extensions/vscode/.gitignore
vendored
4
extensions/vscode/.gitignore
vendored
|
|
@ -25,4 +25,6 @@ e2e/vsix
|
|||
e2e/test-continue/*
|
||||
!e2e/test-continue/config.json
|
||||
e2e/test-continue-yaml/*
|
||||
!e2e/test-continue-yaml/config.yaml
|
||||
!e2e/test-continue-yaml/config.yaml
|
||||
|
||||
config-yaml-schema.json
|
||||
|
|
@ -588,6 +588,10 @@
|
|||
{
|
||||
"fileMatch": ".continuerc.json",
|
||||
"url": "./continue_rc_schema.json"
|
||||
},
|
||||
{
|
||||
"fileMatch": "**/config.yaml",
|
||||
"url": "./config-yaml-schema.json"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
|||
|
|
@ -10,7 +10,11 @@ const {
|
|||
autodetectPlatformAndArch,
|
||||
} = require("../../../scripts/util/index");
|
||||
|
||||
const { copyConfigSchema, writeBuildTimestamp } = require("./utils");
|
||||
const {
|
||||
copyConfigSchema,
|
||||
writeBuildTimestamp,
|
||||
generateConfigYamlSchema,
|
||||
} = require("./utils");
|
||||
|
||||
// Clear folders that will be packaged to ensure clean slate
|
||||
rimrafSync(path.join(__dirname, "..", "bin"));
|
||||
|
|
@ -63,6 +67,9 @@ const isMacTarget = target?.startsWith("darwin");
|
|||
(async () => {
|
||||
console.log("[info] Packaging extension for target ", target);
|
||||
|
||||
// Generate and copy over config-yaml-schema.json
|
||||
generateConfigYamlSchema();
|
||||
|
||||
// Copy config schemas to intellij
|
||||
copyConfigSchema();
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,20 @@ const {
|
|||
|
||||
const continueDir = path.join(__dirname, "..", "..", "..");
|
||||
|
||||
function generateConfigYamlSchema() {
|
||||
process.chdir(path.join(continueDir, "packages", "config-yaml"));
|
||||
execCmdSync("npm install");
|
||||
execCmdSync("npm run build");
|
||||
execCmdSync("npm run generate-schema");
|
||||
fs.copyFileSync(
|
||||
path.join("schema", "config-yaml-schema.json"),
|
||||
path.join(continueDir, "extensions", "vscode", "config-yaml-schema.json"),
|
||||
);
|
||||
console.log("[info] Generated config.yaml schema");
|
||||
}
|
||||
|
||||
function copyConfigSchema() {
|
||||
process.chdir(path.join(continueDir, "extensions", "vscode"));
|
||||
// Modify and copy for .continuerc.json
|
||||
const schema = JSON.parse(fs.readFileSync("config_schema.json", "utf8"));
|
||||
schema.$defs.SerializedContinueConfig.properties.mergeBehavior = {
|
||||
|
|
@ -526,6 +539,7 @@ function writeBuildTimestamp() {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
generateConfigYamlSchema,
|
||||
copyConfigSchema,
|
||||
installNodeModules,
|
||||
buildGui,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { getContinueRcPath, getTsConfigPath } from "core/util/paths";
|
|||
import { Telemetry } from "core/util/posthog";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
import * as path from "path";
|
||||
import { VsCodeExtension } from "../extension/VsCodeExtension";
|
||||
import registerQuickFixProvider from "../lang-server/codeActions";
|
||||
import { getExtensionVersion } from "../util/util";
|
||||
|
|
@ -32,6 +33,22 @@ export async function activateExtension(context: vscode.ExtensionContext) {
|
|||
);
|
||||
}
|
||||
|
||||
// Only set the YAML schema configuration if it hasn't been set before
|
||||
if (!context.globalState.get("yamlSchemaConfigured")) {
|
||||
vscode.workspace.getConfiguration("yaml").update(
|
||||
"schemas",
|
||||
{
|
||||
[path.join(
|
||||
context.extension.extensionUri.fsPath,
|
||||
"config-yaml-schema.json",
|
||||
)]: [".continue/**/*.yaml"],
|
||||
},
|
||||
vscode.ConfigurationTarget.Global,
|
||||
);
|
||||
// Mark that we've configured the YAML schema
|
||||
context.globalState.update("yamlSchemaConfigured", true);
|
||||
}
|
||||
|
||||
const api = new VsCodeContinueApi(vscodeExtension);
|
||||
const continuePublicApi = {
|
||||
registerCustomContextProvider: api.registerCustomContextProvider.bind(api),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
import * as vscode from "vscode";
|
||||
|
||||
export class DownloadYamlExtensionCodeLensProvider
|
||||
implements vscode.CodeLensProvider
|
||||
{
|
||||
private yamlExtensionDownloaded(): boolean {
|
||||
const yamlExtension = vscode.extensions.getExtension("redhat.vscode-yaml");
|
||||
return yamlExtension !== undefined;
|
||||
}
|
||||
|
||||
public provideCodeLenses(
|
||||
document: vscode.TextDocument,
|
||||
_: vscode.CancellationToken,
|
||||
): vscode.CodeLens[] | Thenable<vscode.CodeLens[]> {
|
||||
if (!document.uri.fsPath.includes(".continue")) {
|
||||
return [];
|
||||
}
|
||||
if (this.yamlExtensionDownloaded()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const codeLens: vscode.CodeLens = {
|
||||
range: new vscode.Range(0, 0, 0, 0),
|
||||
command: {
|
||||
title: "Download YAML extension for Intellisense",
|
||||
command: "workbench.extensions.installExtension",
|
||||
arguments: ["redhat.vscode-yaml"],
|
||||
},
|
||||
isResolved: true,
|
||||
};
|
||||
|
||||
return [codeLens];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
export { DownloadYamlExtensionCodeLensProvider } from "./DownloadYamlExtensionCodeLensProvider";
|
||||
export { QuickActionsCodeLensProvider } from "./QuickActionsCodeLensProvider";
|
||||
export { SuggestionsCodeLensProvider } from "./SuggestionsCodeLensProvider";
|
||||
export { VerticalDiffCodeLensProvider as VerticalPerLineCodeLensProvider } from "./VerticalPerLineCodeLensProvider";
|
||||
|
|
|
|||
|
|
@ -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 downloadYamlExtensionCodeLensDisposable: vscode.Disposable | undefined =
|
||||
undefined;
|
||||
|
||||
/**
|
||||
* Registers the Quick Actions CodeLens provider if Quick Actions are enabled.
|
||||
|
|
@ -96,6 +98,10 @@ export function registerAllCodeLensProviders(
|
|||
tutorialCodeLensDisposable.dispose();
|
||||
}
|
||||
|
||||
if (downloadYamlExtensionCodeLensDisposable) {
|
||||
downloadYamlExtensionCodeLensDisposable.dispose();
|
||||
}
|
||||
|
||||
const verticalDiffCodeLens = new providers.VerticalPerLineCodeLensProvider(
|
||||
editorToVerticalDiffCodeLens,
|
||||
);
|
||||
|
|
@ -110,6 +116,11 @@ export function registerAllCodeLensProviders(
|
|||
new providers.SuggestionsCodeLensProvider(),
|
||||
);
|
||||
|
||||
downloadYamlExtensionCodeLensDisposable = registerCodeLensProvider(
|
||||
"yaml",
|
||||
new providers.DownloadYamlExtensionCodeLensProvider(),
|
||||
);
|
||||
|
||||
if (config) {
|
||||
registerQuickActionsProvider(config, context);
|
||||
|
||||
|
|
|
|||
3
gui/package-lock.json
generated
3
gui/package-lock.json
generated
|
|
@ -222,7 +222,8 @@
|
|||
"cross-env": "^7.0.3",
|
||||
"jest": "^29.7.0",
|
||||
"ts-jest": "^29.2.3",
|
||||
"ts-node": "^10.9.2"
|
||||
"ts-node": "^10.9.2",
|
||||
"zod-to-json-schema": "^3.24.5"
|
||||
}
|
||||
},
|
||||
"node_modules/@adobe/css-tools": {
|
||||
|
|
|
|||
1
packages/config-yaml/.gitignore
vendored
Normal file
1
packages/config-yaml/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
schema/
|
||||
13
packages/config-yaml/package-lock.json
generated
13
packages/config-yaml/package-lock.json
generated
|
|
@ -22,7 +22,8 @@
|
|||
"cross-env": "^7.0.3",
|
||||
"jest": "^29.7.0",
|
||||
"ts-jest": "^29.2.3",
|
||||
"ts-node": "^10.9.2"
|
||||
"ts-node": "^10.9.2",
|
||||
"zod-to-json-schema": "^3.24.5"
|
||||
}
|
||||
},
|
||||
"node_modules/@ampproject/remapping": {
|
||||
|
|
@ -3823,6 +3824,16 @@
|
|||
"funding": {
|
||||
"url": "https://github.com/sponsors/colinhacks"
|
||||
}
|
||||
},
|
||||
"node_modules/zod-to-json-schema": {
|
||||
"version": "3.24.5",
|
||||
"resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.24.5.tgz",
|
||||
"integrity": "sha512-/AuWwMP+YqiPbsJx5D6TfgRTc4kTLjsh5SOcd4bLsfUg2RcEXrFMJl1DGgdHy2aCfsIA/cr/1JM0xcB2GZji8g==",
|
||||
"dev": true,
|
||||
"license": "ISC",
|
||||
"peerDependencies": {
|
||||
"zod": "^3.24.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@
|
|||
},
|
||||
"scripts": {
|
||||
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
|
||||
"build": "tsc"
|
||||
"build": "tsc",
|
||||
"generate-schema": "tsc && node dist/scripts/generateJsonSchema.js"
|
||||
},
|
||||
"author": "Continue Dev, Inc.",
|
||||
"license": "Apache-2.0",
|
||||
|
|
@ -25,6 +26,7 @@
|
|||
"cross-env": "^7.0.3",
|
||||
"jest": "^29.7.0",
|
||||
"ts-jest": "^29.2.3",
|
||||
"ts-node": "^10.9.2"
|
||||
"ts-node": "^10.9.2",
|
||||
"zod-to-json-schema": "^3.24.5"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
packages/config-yaml/src/schemas/commonSlugs.ts
Normal file
30
packages/config-yaml/src/schemas/commonSlugs.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
export const commonModelSlugs = [
|
||||
"anthropic/claude-3-7-sonnet",
|
||||
"togetherai/llama-4-maverick-instruct-17bx128e",
|
||||
"google/gemini-2.5-pro",
|
||||
"mistral/codestral",
|
||||
"voyageai/voyage-code-3",
|
||||
"relace/instant-apply",
|
||||
"xai/grok-2",
|
||||
"openai/gpt-4o",
|
||||
"togetherai/llama-4-scout-instruct-17bx16e",
|
||||
"anthropic/claude-3-5-sonnet",
|
||||
"google/gemini-2.0-flash",
|
||||
"voyageai/rerank-2",
|
||||
"ollama/deepseek-r1",
|
||||
"morphllm/morph-v0",
|
||||
"anthropic/claude-3-5-haiku",
|
||||
"lmstudio/deepseek-r1",
|
||||
"openai/o3-mini",
|
||||
"voyageai/voyage-code-2",
|
||||
"ollama/qwen2.5-coder-1.5b",
|
||||
"openai/gpt-4o-mini",
|
||||
"openai/o1",
|
||||
"mistral/mistral-embed",
|
||||
"ollama/nomic-embed-text-latest",
|
||||
"lmstudio/deepseek-r1-8b",
|
||||
"mistral/mistral-large",
|
||||
"lmstudio/qwen2.5-coder-1.5b",
|
||||
"ollama/deepseek-r1-8b",
|
||||
"openai/text-embedding-3-large",
|
||||
];
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import * as z from "zod";
|
||||
import { commonModelSlugs } from "./commonSlugs.js";
|
||||
import { dataSchema } from "./data/index.js";
|
||||
import { modelSchema, partialModelSchema } from "./models.js";
|
||||
|
||||
|
|
@ -38,15 +39,22 @@ const ruleSchema = z.union([z.string(), ruleObjectSchema]);
|
|||
|
||||
export type Rule = z.infer<typeof ruleSchema>;
|
||||
|
||||
export const blockItemWrapperSchema = <T extends z.AnyZodObject>(schema: T) =>
|
||||
const defaultUsesSchema = z.string();
|
||||
|
||||
export const blockItemWrapperSchema = <T extends z.AnyZodObject>(
|
||||
schema: T,
|
||||
usesSchema: z.ZodTypeAny = defaultUsesSchema,
|
||||
) =>
|
||||
z.object({
|
||||
uses: z.string(),
|
||||
uses: usesSchema,
|
||||
with: z.record(z.string()).optional(),
|
||||
override: schema.partial().optional(),
|
||||
});
|
||||
|
||||
export const blockOrSchema = <T extends z.AnyZodObject>(schema: T) =>
|
||||
z.union([schema, blockItemWrapperSchema(schema)]);
|
||||
export const blockOrSchema = <T extends z.AnyZodObject>(
|
||||
schema: T,
|
||||
usesSchema: z.ZodTypeAny = defaultUsesSchema,
|
||||
) => z.union([schema, blockItemWrapperSchema(schema, usesSchema)]);
|
||||
|
||||
export const commonMetadataSchema = z.object({
|
||||
tags: z.string().optional(),
|
||||
|
|
@ -64,13 +72,17 @@ export const baseConfigYamlSchema = z.object({
|
|||
metadata: z.record(z.string()).and(commonMetadataSchema.partial()).optional(),
|
||||
});
|
||||
|
||||
const modelsUsesSchema = z
|
||||
.string()
|
||||
.or(z.enum(commonModelSlugs as [string, ...string[]]));
|
||||
|
||||
export const configYamlSchema = baseConfigYamlSchema.extend({
|
||||
models: z
|
||||
.array(
|
||||
z.union([
|
||||
modelSchema,
|
||||
z.object({
|
||||
uses: z.string(),
|
||||
uses: modelsUsesSchema,
|
||||
with: z.record(z.string()).optional(),
|
||||
override: partialModelSchema.optional(),
|
||||
}),
|
||||
|
|
@ -85,7 +97,7 @@ export const configYamlSchema = baseConfigYamlSchema.extend({
|
|||
z.union([
|
||||
ruleSchema,
|
||||
z.object({
|
||||
uses: z.string(),
|
||||
uses: defaultUsesSchema,
|
||||
with: z.record(z.string()).optional(),
|
||||
}),
|
||||
]),
|
||||
|
|
|
|||
28
packages/config-yaml/src/scripts/generateJsonSchema.ts
Normal file
28
packages/config-yaml/src/scripts/generateJsonSchema.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { zodToJsonSchema } from 'zod-to-json-schema';
|
||||
import { configYamlSchema } from '../schemas/index.js';
|
||||
|
||||
// Get the directory name of the current module
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
// Convert Zod schema to JSON schema
|
||||
const jsonSchema = zodToJsonSchema(configYamlSchema, {
|
||||
$refStrategy: 'none',
|
||||
name: 'ConfigYaml',
|
||||
});
|
||||
|
||||
// Output directory and file path
|
||||
const outDir = path.resolve(__dirname, '../../schema');
|
||||
const outFile = path.join(outDir, 'config-yaml-schema.json');
|
||||
|
||||
// Ensure output directory exists
|
||||
if (!fs.existsSync(outDir)) {
|
||||
fs.mkdirSync(outDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Write the JSON schema to file
|
||||
fs.writeFileSync(outFile, JSON.stringify(jsonSchema, null, 2));
|
||||
|
||||
console.log(`JSON schema has been written to ${outFile}`);
|
||||
Loading…
Add table
Reference in a new issue