This commit refactors how IdeSettings and ControlPlaneClient are accessed throughout
the configuration system to improve state management and reduce coupling.
Previously, ideSettingsPromise was passed down from the top-level ConfigHandler
through various profile loaders and clients. This created a rigid dependency chain
and required manual promise replacement when settings were updated. Similarly,
downstream components could hold onto stale instances of ControlPlaneClient after a
change in authentication state.
The key changes are:
- Removed ideSettingsPromise prop drilling: Components that require IDE settings
now fetch them directly from the IDE object (ide.getIdeSettings()) when
needed.
- Updated globalLocalProfileManager during every cascadeInit: This ensures it
always holds the most recent ControlPlaneClient, preventing issues with stale
client objects after re-authentication.
- Simplified constructors: The constructors for ConfigHandler, ControlPlaneClient,
and various loaders have been simplified to reflect these changes, primarily by
passing the IDE object directly instead of its derived promises.
76 lines
2.3 KiB
TypeScript
76 lines
2.3 KiB
TypeScript
import { ConfigResult, parseConfigYaml } from "@continuedev/config-yaml";
|
|
|
|
import { ControlPlaneClient } from "../../control-plane/client.js";
|
|
import { ContinueConfig, IDE, ILLMLogger } from "../../index.js";
|
|
import { ProfileDescription } from "../ProfileLifecycleManager.js";
|
|
|
|
import { getPrimaryConfigFilePath } from "../../util/paths.js";
|
|
import { localPathToUri } from "../../util/pathToUri.js";
|
|
import { getUriPathBasename } from "../../util/uri.js";
|
|
import doLoadConfig from "./doLoadConfig.js";
|
|
import { IProfileLoader } from "./IProfileLoader.js";
|
|
|
|
export default class LocalProfileLoader implements IProfileLoader {
|
|
static ID = "local";
|
|
|
|
constructor(
|
|
private ide: IDE,
|
|
private controlPlaneClient: ControlPlaneClient,
|
|
private llmLogger: ILLMLogger,
|
|
private overrideAssistantFile?:
|
|
| { path: string; content: string }
|
|
| undefined,
|
|
) {
|
|
const description: ProfileDescription = {
|
|
id: overrideAssistantFile?.path ?? LocalProfileLoader.ID,
|
|
profileType: "local",
|
|
fullSlug: {
|
|
ownerSlug: "",
|
|
packageSlug: "",
|
|
versionSlug: "",
|
|
},
|
|
iconUrl: "",
|
|
title: overrideAssistantFile?.path
|
|
? getUriPathBasename(overrideAssistantFile.path)
|
|
: "Local Agent",
|
|
errors: undefined,
|
|
uri:
|
|
overrideAssistantFile?.path ??
|
|
localPathToUri(getPrimaryConfigFilePath()),
|
|
rawYaml: undefined,
|
|
};
|
|
this.description = description;
|
|
if (overrideAssistantFile?.content) {
|
|
try {
|
|
const parsedAssistant = parseConfigYaml(
|
|
overrideAssistantFile?.content ?? "",
|
|
);
|
|
this.description.title = parsedAssistant.name;
|
|
} catch (e) {
|
|
console.error("Failed to parse agent file: ", e);
|
|
}
|
|
}
|
|
}
|
|
description: ProfileDescription;
|
|
|
|
async doLoadConfig(): Promise<ConfigResult<ContinueConfig>> {
|
|
const result = await doLoadConfig({
|
|
ide: this.ide,
|
|
controlPlaneClient: this.controlPlaneClient,
|
|
llmLogger: this.llmLogger,
|
|
profileId: this.description.id,
|
|
overrideConfigYamlByPath: this.overrideAssistantFile?.path,
|
|
orgScopeId: null,
|
|
packageIdentifier: {
|
|
uriType: "file",
|
|
fileUri: this.overrideAssistantFile?.path ?? getPrimaryConfigFilePath(),
|
|
},
|
|
});
|
|
|
|
this.description.errors = result.errors;
|
|
|
|
return result;
|
|
}
|
|
|
|
setIsActive(isActive: boolean): void {}
|
|
}
|