support for local .env secrets
This commit is contained in:
parent
e3c56f81a2
commit
2d397ded99
7 changed files with 127 additions and 30 deletions
106
core/config/yaml/LocalPlatformClient.ts
Normal file
106
core/config/yaml/LocalPlatformClient.ts
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
import {
|
||||
FQSN,
|
||||
PlatformClient,
|
||||
SecretResult,
|
||||
SecretType,
|
||||
} from "@continuedev/config-yaml";
|
||||
import * as dotenv from "dotenv";
|
||||
import { IDE } from "../..";
|
||||
import { ControlPlaneClient } from "../../control-plane/client";
|
||||
import { getContinueDotEnv } from "../../util/paths";
|
||||
import { joinPathsToUri } from "../../util/uri";
|
||||
|
||||
export class LocalPlatformClient implements PlatformClient {
|
||||
constructor(
|
||||
private orgScopeId: string | null,
|
||||
private readonly client: ControlPlaneClient,
|
||||
private readonly ide: IDE,
|
||||
) {}
|
||||
|
||||
private async findSecretInEnvFiles(
|
||||
fqsn: FQSN,
|
||||
): Promise<SecretResult | undefined> {
|
||||
const secretValue =
|
||||
this.findSecretInLocalEnvFile(fqsn) ??
|
||||
(await this.findSecretInWorkspaceEnvFiles(fqsn));
|
||||
|
||||
if (secretValue) {
|
||||
return {
|
||||
found: true,
|
||||
fqsn,
|
||||
value: secretValue,
|
||||
secretLocation: {
|
||||
secretName: fqsn.secretName,
|
||||
secretType: SecretType.LocalEnv,
|
||||
},
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private findSecretInLocalEnvFile(fqsn: FQSN): string | undefined {
|
||||
try {
|
||||
const dotEnv = getContinueDotEnv();
|
||||
return dotEnv[fqsn.secretName];
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Error reading ~/.continue/.env file: ${error instanceof Error ? error.message : String(error)}`,
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
private async findSecretInWorkspaceEnvFiles(
|
||||
fqsn: FQSN,
|
||||
): Promise<string | undefined> {
|
||||
try {
|
||||
const workspaceDirs = await this.ide.getWorkspaceDirs();
|
||||
|
||||
for (const folder of workspaceDirs) {
|
||||
const envFilePath = joinPathsToUri(folder, ".env");
|
||||
try {
|
||||
const fileExists = await this.ide.fileExists(envFilePath);
|
||||
if (fileExists) {
|
||||
const envContent = await this.ide.readFile(envFilePath);
|
||||
const env = dotenv.parse(envContent);
|
||||
if (fqsn.secretName in env) {
|
||||
return env[fqsn.secretName];
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Error reading workspace .env file at ${envFilePath}: ${error instanceof Error ? error.message : String(error)}`,
|
||||
);
|
||||
// Continue to next workspace folder
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Error searching workspace .env files: ${error instanceof Error ? error.message : String(error)}`,
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async resolveFQSNs(fqsns: FQSN[]): Promise<(SecretResult | undefined)[]> {
|
||||
if (fqsns.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const results = await this.client.resolveFQSNs(fqsns, this.orgScopeId);
|
||||
|
||||
// For any secret that isn't found, look in .env files
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
if (!results[i]?.found) {
|
||||
const secretFromEnv = await this.findSecretInEnvFiles(fqsns[i]);
|
||||
if (secretFromEnv?.found) {
|
||||
results[i] = secretFromEnv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,11 +4,8 @@ import {
|
|||
AssistantUnrolled,
|
||||
ConfigResult,
|
||||
ConfigValidationError,
|
||||
FQSN,
|
||||
ModelRole,
|
||||
PlatformClient,
|
||||
RegistryClient,
|
||||
SecretResult,
|
||||
unrollAssistantFromContent,
|
||||
validateConfigYaml,
|
||||
} from "@continuedev/config-yaml";
|
||||
|
|
@ -43,30 +40,16 @@ import { PlatformConfigMetadata } from "../profile/PlatformProfileLoader";
|
|||
import { modifyAnyConfigWithSharedConfig } from "../sharedConfig";
|
||||
|
||||
import { getControlPlaneEnvSync } from "../../control-plane/env";
|
||||
import { LocalPlatformClient } from "./LocalPlatformClient";
|
||||
import { llmsFromModelConfig } from "./models";
|
||||
|
||||
export class LocalPlatformClient implements PlatformClient {
|
||||
constructor(
|
||||
private orgScopeId: string | null,
|
||||
private readonly client: ControlPlaneClient,
|
||||
) {}
|
||||
|
||||
async resolveFQSNs(fqsns: FQSN[]): Promise<(SecretResult | undefined)[]> {
|
||||
if (fqsns.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const response = await this.client.resolveFQSNs(fqsns, this.orgScopeId);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadConfigYaml(
|
||||
rawYaml: string,
|
||||
overrideConfigYaml: AssistantUnrolled | undefined,
|
||||
controlPlaneClient: ControlPlaneClient,
|
||||
orgScopeId: string | null,
|
||||
ideSettings: IdeSettings,
|
||||
ide: IDE,
|
||||
): Promise<ConfigResult<AssistantUnrolled>> {
|
||||
let config =
|
||||
overrideConfigYaml ??
|
||||
|
|
@ -89,7 +72,11 @@ async function loadConfigYaml(
|
|||
currentUserSlug: "",
|
||||
onPremProxyUrl: null,
|
||||
orgScopeId,
|
||||
platformClient: new LocalPlatformClient(orgScopeId, controlPlaneClient),
|
||||
platformClient: new LocalPlatformClient(
|
||||
orgScopeId,
|
||||
controlPlaneClient,
|
||||
ide,
|
||||
),
|
||||
renderSecrets: true,
|
||||
},
|
||||
));
|
||||
|
|
@ -435,6 +422,7 @@ export async function loadContinueConfigFromYaml(
|
|||
controlPlaneClient,
|
||||
orgScopeId,
|
||||
ideSettings,
|
||||
ide,
|
||||
);
|
||||
|
||||
if (!configYamlResult.config || configYamlResult.configLoadInterrupted) {
|
||||
|
|
|
|||
11
core/package-lock.json
generated
11
core/package-lock.json
generated
|
|
@ -13,7 +13,7 @@
|
|||
"@aws-sdk/client-sagemaker-runtime": "^3.777.0",
|
||||
"@aws-sdk/credential-providers": "^3.778.0",
|
||||
"@continuedev/config-types": "^1.0.13",
|
||||
"@continuedev/config-yaml": "^1.0.71",
|
||||
"@continuedev/config-yaml": "^1.0.80",
|
||||
"@continuedev/fetch": "^1.0.4",
|
||||
"@continuedev/llm-info": "^1.0.8",
|
||||
"@continuedev/openai-adapters": "^1.0.18",
|
||||
|
|
@ -2977,13 +2977,16 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@continuedev/config-yaml": {
|
||||
"version": "1.0.71",
|
||||
"resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.71.tgz",
|
||||
"integrity": "sha512-c7KVaYfldaYHf2EqeqE9Oo1son33iTp6MAY+WRPJVs9XWmRWOA6Cn7YDf575FpwX6UsPCT/Eb0JJme8AC7UE6g==",
|
||||
"version": "1.0.80",
|
||||
"resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.80.tgz",
|
||||
"integrity": "sha512-fHZLh04aThbgK80+B5O0CBBb0IgJbfM0trBWeDI4/MLpxpTJebxX4QY1RZBOdIULKMDMHnfyWNCe2gSGi/mt9Q==",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.14",
|
||||
"yaml": "^2.6.1",
|
||||
"zod": "^3.24.2"
|
||||
},
|
||||
"bin": {
|
||||
"config-yaml": "dist/cli.js"
|
||||
}
|
||||
},
|
||||
"node_modules/@continuedev/fetch": {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
"@aws-sdk/client-sagemaker-runtime": "^3.777.0",
|
||||
"@aws-sdk/credential-providers": "^3.778.0",
|
||||
"@continuedev/config-types": "^1.0.13",
|
||||
"@continuedev/config-yaml": "^1.0.71",
|
||||
"@continuedev/config-yaml": "^1.0.80",
|
||||
"@continuedev/fetch": "^1.0.4",
|
||||
"@continuedev/llm-info": "^1.0.8",
|
||||
"@continuedev/openai-adapters": "^1.0.18",
|
||||
|
|
|
|||
6
extensions/vscode/package-lock.json
generated
6
extensions/vscode/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "1.1.21",
|
||||
"version": "1.1.22",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "1.1.21",
|
||||
"version": "1.1.22",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/fetch": "^1.0.3",
|
||||
|
|
@ -106,7 +106,7 @@
|
|||
"@aws-sdk/client-sagemaker-runtime": "^3.777.0",
|
||||
"@aws-sdk/credential-providers": "^3.778.0",
|
||||
"@continuedev/config-types": "^1.0.13",
|
||||
"@continuedev/config-yaml": "^1.0.71",
|
||||
"@continuedev/config-yaml": "^1.0.80",
|
||||
"@continuedev/fetch": "^1.0.4",
|
||||
"@continuedev/llm-info": "^1.0.8",
|
||||
"@continuedev/openai-adapters": "^1.0.18",
|
||||
|
|
|
|||
2
gui/package-lock.json
generated
2
gui/package-lock.json
generated
|
|
@ -109,7 +109,7 @@
|
|||
"@aws-sdk/client-sagemaker-runtime": "^3.777.0",
|
||||
"@aws-sdk/credential-providers": "^3.778.0",
|
||||
"@continuedev/config-types": "^1.0.13",
|
||||
"@continuedev/config-yaml": "^1.0.71",
|
||||
"@continuedev/config-yaml": "^1.0.80",
|
||||
"@continuedev/fetch": "^1.0.4",
|
||||
"@continuedev/llm-info": "^1.0.8",
|
||||
"@continuedev/openai-adapters": "^1.0.18",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@continuedev/config-yaml",
|
||||
"version": "1.0.79",
|
||||
"version": "1.0.80",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue