Elffuss BraidHub

kikocis/continue public

main · 2.3 KiBRawPermalink
1import { ConfigResult, parseConfigYaml } from "@continuedev/config-yaml";
2
3import { ControlPlaneClient } from "../../control-plane/client.js";
4import { ContinueConfig, IDE, ILLMLogger } from "../../index.js";
5import { ProfileDescription } from "../ProfileLifecycleManager.js";
6
7import { getPrimaryConfigFilePath } from "../../util/paths.js";
8import { localPathToUri } from "../../util/pathToUri.js";
9import { getUriPathBasename } from "../../util/uri.js";
10import doLoadConfig from "./doLoadConfig.js";
11import { IProfileLoader } from "./IProfileLoader.js";
12
13export default class LocalProfileLoader implements IProfileLoader {
14 static ID = "local";
15
16 constructor(
17 private ide: IDE,
18 private controlPlaneClient: ControlPlaneClient,
19 private llmLogger: ILLMLogger,
20 private overrideAssistantFile?:
21 | { path: string; content: string }
22 | undefined,
23 ) {
24 const description: ProfileDescription = {
25 id: overrideAssistantFile?.path ?? LocalProfileLoader.ID,
26 profileType: "local",
27 fullSlug: {
28 ownerSlug: "",
29 packageSlug: "",
30 versionSlug: "",
31 },
32 iconUrl: "",
33 title: overrideAssistantFile?.path
34 ? getUriPathBasename(overrideAssistantFile.path)
35 : "Local Agent",
36 errors: undefined,
37 uri:
38 overrideAssistantFile?.path ??
39 localPathToUri(getPrimaryConfigFilePath()),
40 rawYaml: undefined,
41 };
42 this.description = description;
43 if (overrideAssistantFile?.content) {
44 try {
45 const parsedAssistant = parseConfigYaml(
46 overrideAssistantFile?.content ?? "",
47 );
48 this.description.title = parsedAssistant.name;
49 } catch (e) {
50 console.error("Failed to parse agent file: ", e);
51 }
52 }
53 }
54 description: ProfileDescription;
55
56 async doLoadConfig(): Promise<ConfigResult<ContinueConfig>> {
57 const result = await doLoadConfig({
58 ide: this.ide,
59 controlPlaneClient: this.controlPlaneClient,
60 llmLogger: this.llmLogger,
61 profileId: this.description.id,
62 overrideConfigYamlByPath: this.overrideAssistantFile?.path,
63 orgScopeId: null,
64 packageIdentifier: {
65 uriType: "file",
66 fileUri: this.overrideAssistantFile?.path ?? getPrimaryConfigFilePath(),
67 },
68 });
69
70 this.description.errors = result.errors;
71
72 return result;
73 }
74
75 setIsActive(isActive: boolean): void {}
76}