diff --git a/core/.eslintrc.json b/core/.eslintrc.json index 4790b5c45..64c478d09 100644 --- a/core/.eslintrc.json +++ b/core/.eslintrc.json @@ -17,6 +17,6 @@ "max-statements": ["error", { "max": 114 }], "max-depth": ["error", { "max": 6 }], "max-nested-callbacks": ["error", { "max": 4 }], - "max-params": ["error", { "max": 11 }] + "max-params": ["error", { "max": 8 }] } } diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index 2d4a471d5..aa213d270 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -172,22 +172,22 @@ export class ConfigHandler { return await Promise.all( assistants.map(async (assistant) => { - const profileLoader = await PlatformProfileLoader.create( - { + const profileLoader = await PlatformProfileLoader.create({ + configResult: { ...assistant.configResult, config: assistant.configResult.config, }, - assistant.ownerSlug, - assistant.packageSlug, - assistant.iconUrl, - assistant.configResult.config?.version ?? "latest", - this.controlPlaneClient, - this.ide, - this.ideSettingsPromise, - this.llmLogger, - assistant.rawYaml, - orgScopeId, - ); + ownerSlug: assistant.ownerSlug, + packageSlug: assistant.packageSlug, + iconUrl: assistant.iconUrl, + versionSlug: assistant.configResult.config?.version ?? "latest", + controlPlaneClient: this.controlPlaneClient, + ide: this.ide, + ideSettingsPromise: this.ideSettingsPromise, + llmLogger: this.llmLogger, + rawYaml: assistant.rawYaml, + orgScopeId: orgScopeId, + }); return new ProfileLifecycleManager(profileLoader, this.ide); }), diff --git a/core/config/load.ts b/core/config/load.ts index b85359641..6ca5ce17a 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -217,17 +217,27 @@ export function isContextProviderWithParams( } /** Only difference between intermediate and final configs is the `models` array */ -async function intermediateToFinalConfig( - config: Config, - ide: IDE, - ideSettings: IdeSettings, - ideInfo: IdeInfo, - uniqueId: string, - llmLogger: ILLMLogger, - workOsAccessToken: string | undefined, - loadPromptFiles: boolean = true, - allowFreeTrial: boolean = true, -): Promise<{ config: ContinueConfig; errors: ConfigValidationError[] }> { +async function intermediateToFinalConfig({ + config, + ide, + ideSettings, + ideInfo, + uniqueId, + llmLogger, + workOsAccessToken, + loadPromptFiles = true, + allowFreeTrial = true, +}: { + config: Config; + ide: IDE; + ideSettings: IdeSettings; + ideInfo: IdeInfo; + uniqueId: string; + llmLogger: ILLMLogger; + workOsAccessToken: string | undefined; + loadPromptFiles?: boolean; + allowFreeTrial?: boolean; +}): Promise<{ config: ContinueConfig; errors: ConfigValidationError[] }> { const errors: ConfigValidationError[] = []; // Auto-detect models @@ -930,15 +940,15 @@ async function loadContinueConfigFromJson( // Convert to final config format const { config: finalConfig, errors: finalErrors } = - await intermediateToFinalConfig( - intermediate, + await intermediateToFinalConfig({ + config: intermediate, ide, ideSettings, ideInfo, uniqueId, llmLogger, workOsAccessToken, - ); + }); return { config: finalConfig, errors: [...(errors ?? []), ...finalErrors], diff --git a/core/config/profile/ControlPlaneProfileLoader.ts b/core/config/profile/ControlPlaneProfileLoader.ts index 21ea27e14..bf705fd95 100644 --- a/core/config/profile/ControlPlaneProfileLoader.ts +++ b/core/config/profile/ControlPlaneProfileLoader.ts @@ -62,18 +62,18 @@ export default class ControlPlaneProfileLoader implements IProfileLoader { )) as any); const serializedConfig: SerializedContinueConfig = settings; - return await doLoadConfig( - this.ide, - this.ideSettingsPromise, - this.controlPlaneClient, - this.llmLogger, - serializedConfig, - undefined, - undefined, - this.workspaceId, - undefined, - null, - ); + return await doLoadConfig({ + ide: this.ide, + ideSettingsPromise: this.ideSettingsPromise, + controlPlaneClient: this.controlPlaneClient, + llmLogger: this.llmLogger, + overrideConfigJson: serializedConfig, + overrideConfigYaml: undefined, + platformConfigMetadata: undefined, + profileId: this.workspaceId, + overrideConfigYamlByPath: undefined, + orgScopeId: null, + }); } setIsActive(isActive: boolean): void {} diff --git a/core/config/profile/LocalProfileLoader.ts b/core/config/profile/LocalProfileLoader.ts index f49c8bb7a..5b73a13e6 100644 --- a/core/config/profile/LocalProfileLoader.ts +++ b/core/config/profile/LocalProfileLoader.ts @@ -55,18 +55,18 @@ export default class LocalProfileLoader implements IProfileLoader { description: ProfileDescription; async doLoadConfig(): Promise> { - const result = await doLoadConfig( - this.ide, - this.ideSettingsPromise, - this.controlPlaneClient, - this.llmLogger, - undefined, - undefined, - undefined, - this.description.id, - this.overrideAssistantFile?.path, - null, - ); + const result = await doLoadConfig({ + ide: this.ide, + ideSettingsPromise: this.ideSettingsPromise, + controlPlaneClient: this.controlPlaneClient, + llmLogger: this.llmLogger, + overrideConfigJson: undefined, + overrideConfigYaml: undefined, + platformConfigMetadata: undefined, + profileId: this.description.id, + overrideConfigYamlByPath: this.overrideAssistantFile?.path, + orgScopeId: null, + }); this.description.errors = result.errors; diff --git a/core/config/profile/PlatformProfileLoader.ts b/core/config/profile/PlatformProfileLoader.ts index cf9efb399..66bea1ef2 100644 --- a/core/config/profile/PlatformProfileLoader.ts +++ b/core/config/profile/PlatformProfileLoader.ts @@ -21,33 +21,81 @@ export interface PlatformConfigMetadata { export default class PlatformProfileLoader implements IProfileLoader { static RELOAD_INTERVAL = 1000 * 5; // 5 seconds - private constructor( - private configResult: ConfigResult, - private readonly ownerSlug: string, - private readonly packageSlug: string, - private readonly iconUrl: string, - private readonly versionSlug: string, - private readonly controlPlaneClient: ControlPlaneClient, - private readonly ide: IDE, - private ideSettingsPromise: Promise, - private llmLogger: ILLMLogger, - readonly description: ProfileDescription, - private readonly orgScopeId: string | null, - ) {} + private configResult: ConfigResult; + private readonly ownerSlug: string; + private readonly packageSlug: string; + private readonly iconUrl: string; + private readonly versionSlug: string; + private readonly controlPlaneClient: ControlPlaneClient; + private readonly ide: IDE; + private ideSettingsPromise: Promise; + private llmLogger: ILLMLogger; + readonly description: ProfileDescription; + private readonly orgScopeId: string | null; - static async create( - configResult: ConfigResult, - ownerSlug: string, - packageSlug: string, - iconUrl: string, - versionSlug: string, - controlPlaneClient: ControlPlaneClient, - ide: IDE, - ideSettingsPromise: Promise, - llmLogger: ILLMLogger, - rawYaml: string, - orgScopeId: string | null, - ): Promise { + private constructor({ + configResult, + ownerSlug, + packageSlug, + iconUrl, + versionSlug, + controlPlaneClient, + ide, + ideSettingsPromise, + llmLogger, + description, + orgScopeId, + }: { + configResult: ConfigResult; + ownerSlug: string; + packageSlug: string; + iconUrl: string; + versionSlug: string; + controlPlaneClient: ControlPlaneClient; + ide: IDE; + ideSettingsPromise: Promise; + llmLogger: ILLMLogger; + description: ProfileDescription; + orgScopeId: string | null; + }) { + this.configResult = configResult; + this.ownerSlug = ownerSlug; + this.packageSlug = packageSlug; + this.iconUrl = iconUrl; + this.versionSlug = versionSlug; + this.controlPlaneClient = controlPlaneClient; + this.ide = ide; + this.ideSettingsPromise = ideSettingsPromise; + this.llmLogger = llmLogger; + this.description = description; + this.orgScopeId = orgScopeId; + } + + static async create({ + configResult, + ownerSlug, + packageSlug, + iconUrl, + versionSlug, + controlPlaneClient, + ide, + ideSettingsPromise, + llmLogger, + rawYaml, + orgScopeId, + }: { + configResult: ConfigResult; + ownerSlug: string; + packageSlug: string; + iconUrl: string; + versionSlug: string; + controlPlaneClient: ControlPlaneClient; + ide: IDE; + ideSettingsPromise: Promise; + llmLogger: ILLMLogger; + rawYaml: string; + orgScopeId: string | null; + }): Promise { const controlPlaneEnv = await getControlPlaneEnv(ideSettingsPromise); const description: ProfileDescription = { @@ -65,7 +113,7 @@ export default class PlatformProfileLoader implements IProfileLoader { rawYaml, }; - return new PlatformProfileLoader( + return new PlatformProfileLoader({ configResult, ownerSlug, packageSlug, @@ -77,7 +125,7 @@ export default class PlatformProfileLoader implements IProfileLoader { llmLogger, description, orgScopeId, - ); + }); } async doLoadConfig(): Promise> { @@ -89,21 +137,21 @@ export default class PlatformProfileLoader implements IProfileLoader { }; } - const results = await doLoadConfig( - this.ide, - this.ideSettingsPromise, - this.controlPlaneClient, - this.llmLogger, - undefined, - this.configResult.config, - { + const results = await doLoadConfig({ + ide: this.ide, + ideSettingsPromise: this.ideSettingsPromise, + controlPlaneClient: this.controlPlaneClient, + llmLogger: this.llmLogger, + overrideConfigJson: undefined, + overrideConfigYaml: this.configResult.config, + platformConfigMetadata: { ownerSlug: this.ownerSlug, packageSlug: this.packageSlug, }, - this.description.id, - undefined, - this.orgScopeId, - ); + profileId: this.description.id, + overrideConfigYamlByPath: undefined, + orgScopeId: this.orgScopeId, + }); return { config: results.config, diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index 626546b74..d3f720017 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -36,18 +36,29 @@ import { loadContinueConfigFromYaml } from "../yaml/loadYaml"; import { PlatformConfigMetadata } from "./PlatformProfileLoader"; -export default async function doLoadConfig( - ide: IDE, - ideSettingsPromise: Promise, - controlPlaneClient: ControlPlaneClient, - llmLogger: ILLMLogger, - overrideConfigJson: SerializedContinueConfig | undefined, - overrideConfigYaml: AssistantUnrolled | undefined, - platformConfigMetadata: PlatformConfigMetadata | undefined, - profileId: string, - overrideConfigYamlByPath: string | undefined, - orgScopeId: string | null, -): Promise> { +export default async function doLoadConfig({ + ide, + ideSettingsPromise, + controlPlaneClient, + llmLogger, + overrideConfigJson, + overrideConfigYaml, + platformConfigMetadata, + profileId, + overrideConfigYamlByPath, + orgScopeId, +}: { + ide: IDE; + ideSettingsPromise: Promise; + controlPlaneClient: ControlPlaneClient; + llmLogger: ILLMLogger; + overrideConfigJson: SerializedContinueConfig | undefined; + overrideConfigYaml: AssistantUnrolled | undefined; + platformConfigMetadata: PlatformConfigMetadata | undefined; + profileId: string; + overrideConfigYamlByPath: string | undefined; + orgScopeId: string | null; +}): Promise> { const workspaceConfigs = await getWorkspaceConfigs(ide); const ideInfo = await ide.getIdeInfo(); const uniqueId = await ide.getUniqueId(); @@ -70,19 +81,18 @@ export default async function doLoadConfig( let configLoadInterrupted = false; if (overrideConfigYaml || fs.existsSync(configYamlPath)) { - const result = await loadContinueConfigFromYaml( + const result = await loadContinueConfigFromYaml({ ide, ideSettings, ideInfo, uniqueId, llmLogger, - workOsAccessToken, overrideConfigYaml, platformConfigMetadata, controlPlaneClient, configYamlPath, orgScopeId, - ); + }); newConfig = result.config; errors = result.errors; configLoadInterrupted = result.configLoadInterrupted; diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 1edb48604..fd1c8ac02 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -111,17 +111,25 @@ async function loadConfigYaml( }; } -async function configYamlToContinueConfig( - config: AssistantUnrolled, - ide: IDE, - ideSettings: IdeSettings, - ideInfo: IdeInfo, - uniqueId: string, - llmLogger: ILLMLogger, - workOsAccessToken: string | undefined, - platformConfigMetadata: PlatformConfigMetadata | undefined, - allowFreeTrial: boolean = true, -): Promise<{ config: ContinueConfig; errors: ConfigValidationError[] }> { +async function configYamlToContinueConfig({ + config, + ide, + ideSettings, + ideInfo, + uniqueId, + llmLogger, + platformConfigMetadata, + allowFreeTrial = true, +}: { + config: AssistantUnrolled; + ide: IDE; + ideSettings: IdeSettings; + ideInfo: IdeInfo; + uniqueId: string; + llmLogger: ILLMLogger; + platformConfigMetadata: PlatformConfigMetadata | undefined; + allowFreeTrial: boolean; +}): Promise<{ config: ContinueConfig; errors: ConfigValidationError[] }> { const localErrors: ConfigValidationError[] = []; const continueConfig: ContinueConfig = { slashCommands: [], @@ -408,19 +416,31 @@ async function configYamlToContinueConfig( return { config: continueConfig, errors: localErrors }; } -export async function loadContinueConfigFromYaml( - ide: IDE, - ideSettings: IdeSettings, - ideInfo: IdeInfo, - uniqueId: string, - llmLogger: ILLMLogger, - workOsAccessToken: string | undefined, - overrideConfigYaml: AssistantUnrolled | undefined, - platformConfigMetadata: PlatformConfigMetadata | undefined, - controlPlaneClient: ControlPlaneClient, - configYamlPath: string | undefined, - orgScopeId: string | null, -): Promise> { +export async function loadContinueConfigFromYaml({ + ide, + ideSettings, + ideInfo, + uniqueId, + llmLogger, + // workOsAccessToken, + overrideConfigYaml, + platformConfigMetadata, + controlPlaneClient, + configYamlPath, + orgScopeId, +}: { + ide: IDE; + ideSettings: IdeSettings; + ideInfo: IdeInfo; + uniqueId: string; + llmLogger: ILLMLogger; + // workOsAccessToken: string | undefined; + overrideConfigYaml: AssistantUnrolled | undefined; + platformConfigMetadata: PlatformConfigMetadata | undefined; + controlPlaneClient: ControlPlaneClient; + configYamlPath: string | undefined; + orgScopeId: string | null; +}): Promise> { const rawYaml = overrideConfigYaml === undefined ? fs.readFileSync( @@ -446,16 +466,16 @@ export async function loadContinueConfigFromYaml( } const { config: continueConfig, errors: localErrors } = - await configYamlToContinueConfig( - configYamlResult.config, + await configYamlToContinueConfig({ + config: configYamlResult.config, ide, ideSettings, ideInfo, uniqueId, llmLogger, - workOsAccessToken, platformConfigMetadata, - ); + allowFreeTrial: true, + }); try { const systemPromptDotFile = await getSystemPromptDotFile(ide);