58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { ConfigJson } from "@continuedev/config-types";
|
|
import {
|
|
ContinueConfig,
|
|
IDE,
|
|
IdeSettings,
|
|
SerializedContinueConfig,
|
|
} from "../..";
|
|
import { ControlPlaneClient } from "../../control-plane/client";
|
|
import { IProfileLoader } from "./IProfileLoader";
|
|
import doLoadConfig from "./doLoadConfig";
|
|
|
|
export default class ControlPlaneProfileLoader implements IProfileLoader {
|
|
private static RELOAD_INTERVAL = 1000 * 60 * 15; // every 15 minutes
|
|
|
|
readonly profileId: string;
|
|
profileTitle: string;
|
|
|
|
workspaceSettings: ConfigJson | undefined;
|
|
|
|
constructor(
|
|
private readonly workspaceId: string,
|
|
private workspaceTitle: string,
|
|
private readonly controlPlaneClient: ControlPlaneClient,
|
|
private readonly ide: IDE,
|
|
private ideSettingsPromise: Promise<IdeSettings>,
|
|
private writeLog: (message: string) => Promise<void>,
|
|
private readonly onReload: () => void,
|
|
) {
|
|
this.profileId = workspaceId;
|
|
this.profileTitle = workspaceTitle;
|
|
|
|
setInterval(async () => {
|
|
this.workspaceSettings =
|
|
await this.controlPlaneClient.getSettingsForWorkspace(this.profileId);
|
|
this.onReload();
|
|
}, ControlPlaneProfileLoader.RELOAD_INTERVAL);
|
|
}
|
|
|
|
async doLoadConfig(): Promise<ContinueConfig> {
|
|
const settings =
|
|
this.workspaceSettings ??
|
|
((await this.controlPlaneClient.getSettingsForWorkspace(
|
|
this.profileId,
|
|
)) as any);
|
|
const serializedConfig: SerializedContinueConfig = settings;
|
|
|
|
return doLoadConfig(
|
|
this.ide,
|
|
this.ideSettingsPromise,
|
|
this.controlPlaneClient,
|
|
this.writeLog,
|
|
serializedConfig,
|
|
);
|
|
}
|
|
|
|
setIsActive(isActive: boolean): void {}
|
|
}
|