From cbdc79e60133327b0fa91d0063e96def38cddfcc Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 19 Jan 2025 18:27:49 -0800 Subject: [PATCH] clean up config loading bugs --- core/config/ConfigHandler.ts | 43 ++++++++++++------- core/config/yaml/clientRender.ts | 2 +- core/package-lock.json | 8 ++-- core/package.json | 2 +- extensions/vscode/package-lock.json | 2 +- gui/package-lock.json | 10 ++--- gui/package.json | 2 +- packages/config-yaml/package.json | 2 +- packages/config-yaml/src/load/clientRender.ts | 22 ++++++++-- 9 files changed, 61 insertions(+), 32 deletions(-) diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index 626e237db..fbac40e6e 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -14,9 +14,11 @@ import Ollama from "../llm/llms/Ollama.js"; import { GlobalContext } from "../util/GlobalContext.js"; import { getConfigJsonPath } from "../util/paths.js"; -import { ConfigResult } from "@continuedev/config-yaml"; +import { ConfigResult, ConfigYaml } from "@continuedev/config-yaml"; +import * as YAML from "yaml"; import { controlPlaneEnv } from "../control-plane/env.js"; import { usePlatform } from "../control-plane/flags.js"; +import { localPathToUri } from "../util/pathToUri.js"; import { LOCAL_ONBOARDING_CHAT_MODEL, ONBOARDING_LOCAL_MODEL_TITLE, @@ -28,7 +30,7 @@ import { ProfileDescription, ProfileLifecycleManager, } from "./ProfileLifecycleManager.js"; -import { localPathToUri } from "../util/pathToUri.js"; +import { clientRenderHelper } from "./yaml/clientRender.js"; export type { ProfileDescription }; @@ -109,19 +111,30 @@ export class ConfigHandler { this.profiles = this.profiles.filter( (profile) => profile.profileDescription.id === "local", ); - assistants.forEach((assistant) => { - const profileLoader = new PlatformProfileLoader( - assistant.configResult, - assistant.ownerSlug, - assistant.packageSlug, - this.controlPlaneClient, - this.ide, - this.ideSettingsPromise, - this.writeLog, - this.reloadConfig.bind(this), - ); - this.profiles.push(new ProfileLifecycleManager(profileLoader)); - }); + await Promise.all( + assistants.map(async (assistant) => { + let renderedConfig: ConfigYaml | undefined = undefined; + if (assistant.configResult.config) { + renderedConfig = await clientRenderHelper( + YAML.stringify(assistant.configResult.config), + this.ide, + this.controlPlaneClient, + ); + } + + const profileLoader = new PlatformProfileLoader( + { ...assistant.configResult, config: renderedConfig }, + assistant.ownerSlug, + assistant.packageSlug, + this.controlPlaneClient, + this.ide, + this.ideSettingsPromise, + this.writeLog, + this.reloadConfig.bind(this), + ); + this.profiles.push(new ProfileLifecycleManager(profileLoader)); + }), + ); this.notifyProfileListeners( this.profiles.map((profile) => profile.profileDescription), diff --git a/core/config/yaml/clientRender.ts b/core/config/yaml/clientRender.ts index 7e9689046..1f9e2f98f 100644 --- a/core/config/yaml/clientRender.ts +++ b/core/config/yaml/clientRender.ts @@ -28,7 +28,7 @@ export function clientRenderHelper( }; const platformClient: PlatformClient = { - resolveFQSNs: controlPlaneClient.resolveFQSNs, + resolveFQSNs: controlPlaneClient.resolveFQSNs.bind(controlPlaneClient), }; return clientRender(unrolledAssistant, ideSecretStore, platformClient); diff --git a/core/package-lock.json b/core/package-lock.json index d020deb94..82e73913f 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -13,7 +13,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.621.0", "@aws-sdk/credential-providers": "^3.620.1", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.13", + "@continuedev/config-yaml": "^1.0.15", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.2", "@continuedev/openai-adapters": "^1.0.10", @@ -3038,9 +3038,9 @@ } }, "node_modules/@continuedev/config-yaml": { - "version": "1.0.13", - "resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.13.tgz", - "integrity": "sha512-mBet+NPqQHDvIx+CKLaR3dCSlvhrVaJSZ9DAMuZ2bqTNLUGN6I7GikJi0CmhiiD8qU2dlrfNfdkLDfnoCwpaOA==", + "version": "1.0.15", + "resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.15.tgz", + "integrity": "sha512-00c1pz+FqAVEWLo8t71OJzm1KBAAJCXqIjd917Vy8lr7xO0Eoj42lo2GFlVRnqQ0hQvhFQ0s9onHhRag/phHZA==", "dependencies": { "@continuedev/config-types": "^1.0.14", "yaml": "^2.6.1", diff --git a/core/package.json b/core/package.json index f34b077be..3f5391b28 100644 --- a/core/package.json +++ b/core/package.json @@ -46,7 +46,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.621.0", "@aws-sdk/credential-providers": "^3.620.1", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.13", + "@continuedev/config-yaml": "^1.0.15", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.2", "@continuedev/openai-adapters": "^1.0.10", diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 84b56c12a..c81130d17 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -106,7 +106,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.621.0", "@aws-sdk/credential-providers": "^3.620.1", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.13", + "@continuedev/config-yaml": "^1.0.15", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.2", "@continuedev/openai-adapters": "^1.0.10", diff --git a/gui/package-lock.json b/gui/package-lock.json index 342824f2d..612acedbd 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -7,7 +7,7 @@ "name": "gui", "license": "Apache-2.0", "dependencies": { - "@continuedev/config-yaml": "^1.0.13", + "@continuedev/config-yaml": "^1.0.15", "@headlessui/react": "^1.7.17", "@heroicons/react": "^2.0.18", "@reduxjs/toolkit": "^2.3.0", @@ -108,7 +108,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.621.0", "@aws-sdk/credential-providers": "^3.620.1", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.13", + "@continuedev/config-yaml": "^1.0.15", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.2", "@continuedev/openai-adapters": "^1.0.10", @@ -556,9 +556,9 @@ } }, "node_modules/@continuedev/config-yaml": { - "version": "1.0.13", - "resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.13.tgz", - "integrity": "sha512-mBet+NPqQHDvIx+CKLaR3dCSlvhrVaJSZ9DAMuZ2bqTNLUGN6I7GikJi0CmhiiD8qU2dlrfNfdkLDfnoCwpaOA==", + "version": "1.0.15", + "resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.15.tgz", + "integrity": "sha512-00c1pz+FqAVEWLo8t71OJzm1KBAAJCXqIjd917Vy8lr7xO0Eoj42lo2GFlVRnqQ0hQvhFQ0s9onHhRag/phHZA==", "dependencies": { "@continuedev/config-types": "^1.0.14", "yaml": "^2.6.1", diff --git a/gui/package.json b/gui/package.json index 6bd3d9374..5bed963dd 100644 --- a/gui/package.json +++ b/gui/package.json @@ -15,7 +15,7 @@ "test:watch": "vitest" }, "dependencies": { - "@continuedev/config-yaml": "^1.0.13", + "@continuedev/config-yaml": "^1.0.15", "@headlessui/react": "^1.7.17", "@heroicons/react": "^2.0.18", "@reduxjs/toolkit": "^2.3.0", diff --git a/packages/config-yaml/package.json b/packages/config-yaml/package.json index bbcfbda46..6fb90abbf 100644 --- a/packages/config-yaml/package.json +++ b/packages/config-yaml/package.json @@ -1,6 +1,6 @@ { "name": "@continuedev/config-yaml", - "version": "1.0.13", + "version": "1.0.15", "description": "", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/config-yaml/src/load/clientRender.ts b/packages/config-yaml/src/load/clientRender.ts index f5cc238d9..dfb1c4181 100644 --- a/packages/config-yaml/src/load/clientRender.ts +++ b/packages/config-yaml/src/load/clientRender.ts @@ -39,7 +39,17 @@ export async function clientRender( // 4. (back to the client) Any “user” secrets that were returned back are added to the local secret store so we don’t have to request them again for (const secretResult of secretResults) { - if (!secretResult?.found) continue; + if (!secretResult) { + continue; + } + + if (!secretResult.found) { + // When a secret isn't found anywhere, we keep it templated as just the secret name + // in case it can be found in the on-prem proxy's env + secretsTemplateData["secrets." + encodeFQSN(secretResult.fqsn)] = + `\${{ secrets.${secretResult.fqsn.secretName} }}`; + continue; + } if ("value" in secretResult) { secretStore.set(secretResult.fqsn.secretName, secretResult.value); @@ -73,8 +83,14 @@ function getUnrenderedSecretLocation( const templateVars = getTemplateVariables(value); if (templateVars.length === 1) { const secretLocationEncoded = templateVars[0].split("secrets.")[1]; - const secretLocation = decodeSecretLocation(secretLocationEncoded); - return secretLocation; + try { + const secretLocation = decodeSecretLocation(secretLocationEncoded); + return secretLocation; + } catch (e) { + // If it's templated but not a valid secret location, leave it be + // in case on-prem proxy has the secret in an env variable + return undefined; + } } return undefined;