Elffuss BraidHub

kikocis/continue public

main · 4.2 KiBRawPermalink
1import { AssistantUnrolled, ConfigResult } from "@continuedev/config-yaml";
2
3import { ControlPlaneClient } from "../../control-plane/client.js";
4import { getControlPlaneEnv } from "../../control-plane/env.js";
5import { ContinueConfig, IDE, ILLMLogger } from "../../index.js";
6import { ProfileDescription } from "../ProfileLifecycleManager.js";
7
8import doLoadConfig from "./doLoadConfig.js";
9import { IProfileLoader } from "./IProfileLoader.js";
10
11/**
12 * Metadata about the package that is currently being loaded
13 * If this is `undefined`, it's not a config from the platform,
14 * could be local for example.
15 */
16export interface PlatformConfigMetadata {
17 ownerSlug: string;
18 packageSlug: string;
19}
20
21export default class PlatformProfileLoader implements IProfileLoader {
22 static RELOAD_INTERVAL = 1000 * 5; // 5 seconds
23
24 private configResult: ConfigResult<AssistantUnrolled>;
25 private readonly ownerSlug: string;
26 private readonly packageSlug: string;
27 private readonly iconUrl: string;
28 private readonly versionSlug: string;
29 private readonly controlPlaneClient: ControlPlaneClient;
30 private readonly ide: IDE;
31 private llmLogger: ILLMLogger;
32 readonly description: ProfileDescription;
33 private readonly orgScopeId: string | null;
34
35 private constructor({
36 configResult,
37 ownerSlug,
38 packageSlug,
39 iconUrl,
40 versionSlug,
41 controlPlaneClient,
42 ide,
43 llmLogger,
44 description,
45 orgScopeId,
46 }: {
47 configResult: ConfigResult<AssistantUnrolled>;
48 ownerSlug: string;
49 packageSlug: string;
50 iconUrl: string;
51 versionSlug: string;
52 controlPlaneClient: ControlPlaneClient;
53 ide: IDE;
54 llmLogger: ILLMLogger;
55 description: ProfileDescription;
56 orgScopeId: string | null;
57 }) {
58 this.configResult = configResult;
59 this.ownerSlug = ownerSlug;
60 this.packageSlug = packageSlug;
61 this.iconUrl = iconUrl;
62 this.versionSlug = versionSlug;
63 this.controlPlaneClient = controlPlaneClient;
64 this.ide = ide;
65 this.llmLogger = llmLogger;
66 this.description = description;
67 this.orgScopeId = orgScopeId;
68 }
69
70 static async create({
71 configResult,
72 ownerSlug,
73 packageSlug,
74 iconUrl,
75 versionSlug,
76 controlPlaneClient,
77 ide,
78 llmLogger,
79 rawYaml,
80 orgScopeId,
81 }: {
82 configResult: ConfigResult<AssistantUnrolled>;
83 ownerSlug: string;
84 packageSlug: string;
85 iconUrl: string;
86 versionSlug: string;
87 controlPlaneClient: ControlPlaneClient;
88 ide: IDE;
89 llmLogger: ILLMLogger;
90 rawYaml: string;
91 orgScopeId: string | null;
92 }): Promise<PlatformProfileLoader> {
93 const controlPlaneEnv = await getControlPlaneEnv(ide.getIdeSettings());
94
95 const description: ProfileDescription = {
96 id: `${ownerSlug}/${packageSlug}`,
97 profileType: "platform",
98 fullSlug: {
99 ownerSlug,
100 packageSlug,
101 versionSlug,
102 },
103 title: configResult.config?.name ?? `${ownerSlug}/${packageSlug}`,
104 errors: configResult.errors,
105 iconUrl: iconUrl,
106 uri: `${controlPlaneEnv.APP_URL}${ownerSlug}/${packageSlug}`,
107 rawYaml,
108 };
109
110 return new PlatformProfileLoader({
111 configResult,
112 ownerSlug,
113 packageSlug,
114 iconUrl,
115 versionSlug,
116 controlPlaneClient,
117 ide,
118 llmLogger,
119 description,
120 orgScopeId,
121 });
122 }
123
124 async doLoadConfig(): Promise<ConfigResult<ContinueConfig>> {
125 if (this.configResult.errors?.find((e) => e.fatal)) {
126 return {
127 config: undefined,
128 errors: this.configResult.errors,
129 configLoadInterrupted: false,
130 };
131 }
132
133 const results = await doLoadConfig({
134 ide: this.ide,
135 controlPlaneClient: this.controlPlaneClient,
136 llmLogger: this.llmLogger,
137 overrideConfigYaml: this.configResult.config,
138 profileId: this.description.id,
139 orgScopeId: this.orgScopeId,
140 packageIdentifier: {
141 uriType: "slug",
142 fullSlug: {
143 ownerSlug: this.ownerSlug,
144 packageSlug: this.packageSlug,
145 versionSlug: this.versionSlug,
146 },
147 },
148 });
149
150 return {
151 config: results.config,
152 errors: [...(this.configResult.errors ?? []), ...(results.errors ?? [])],
153 configLoadInterrupted: results.configLoadInterrupted,
154 };
155 }
156
157 setIsActive(isActive: boolean): void {}
158}