Elffuss BraidHub

kikocis/continue public

71fd2e7d4456 · 2.4 KiBRawPermalink
1import { BlockType, ConfigYaml } from "@continuedev/config-yaml";
2import * as YAML from "yaml";
3import { IDE } from "../..";
4import { joinPathsToUri } from "../../util/uri";
5
6function getContentsForNewBlock(blockType: BlockType): ConfigYaml {
7 const configYaml: ConfigYaml = {
8 name: `New ${blockType.slice(0, -1)}`,
9 version: "0.0.1",
10 schema: "v1",
11 };
12 switch (blockType) {
13 case "context":
14 configYaml.context = [
15 {
16 provider: "file",
17 },
18 ];
19 break;
20 case "models":
21 configYaml.models = [
22 {
23 provider: "anthropic",
24 model: "claude-3-7-sonnet-latest",
25 apiKey: "${{ secrets.ANTHROPIC_API_KEY }}",
26 name: "Claude 3.7 Sonnet",
27 roles: ["chat", "edit"],
28 },
29 ];
30 break;
31 case "rules":
32 configYaml.rules = ["Always give concise responses"];
33 break;
34 case "docs":
35 configYaml.docs = [
36 {
37 name: "New docs",
38 startUrl: "https://docs.continue.dev",
39 },
40 ];
41 break;
42 case "prompts":
43 configYaml.prompts = [
44 {
45 name: "New prompt",
46 description: "New prompt",
47 prompt:
48 "Please write a thorough suite of unit tests for this code, making sure to cover all relevant edge cases",
49 },
50 ];
51 break;
52 case "mcpServers":
53 configYaml.mcpServers = [
54 {
55 name: "New MCP server",
56 command: "npx",
57 args: ["-y", "<your-mcp-server>"],
58 env: {},
59 },
60 ];
61 break;
62 }
63
64 return configYaml;
65}
66
67export async function createNewWorkspaceBlockFile(
68 ide: IDE,
69 blockType: BlockType,
70): Promise<void> {
71 const workspaceDirs = await ide.getWorkspaceDirs();
72 if (workspaceDirs.length === 0) {
73 throw new Error(
74 "No workspace directories found. Make sure you've opened a folder in your IDE.",
75 );
76 }
77
78 const baseDirUri = joinPathsToUri(workspaceDirs[0], `.continue/${blockType}`);
79
80 // Find the first available filename
81 let counter = 0;
82 let fileUri: string;
83 do {
84 const suffix = counter === 0 ? "" : `-${counter}`;
85 fileUri = joinPathsToUri(
86 baseDirUri,
87 `new-${blockType.slice(0, -1)}${suffix}.yaml`,
88 );
89 counter++;
90 } while (await ide.fileExists(fileUri));
91
92 await ide.writeFile(
93 fileUri,
94 YAML.stringify(getContentsForNewBlock(blockType)),
95 );
96 await ide.openFile(fileUri);
97}