update config.yaml
This commit is contained in:
parent
fd3870641b
commit
8e25d9cbfb
6 changed files with 90 additions and 5 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@continuedev/config-yaml",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.9",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ export function convertJsonToYamlConfig(configJson: ConfigJson): ConfigYaml {
|
|||
version: "0.0.1",
|
||||
models,
|
||||
context,
|
||||
rules: configJson.systemMessage,
|
||||
rules: configJson.systemMessage ? [configJson.systemMessage] : undefined,
|
||||
prompts,
|
||||
mcpServers,
|
||||
docs,
|
||||
|
|
|
|||
|
|
@ -92,6 +92,17 @@ export function fillTemplateVariables(
|
|||
}
|
||||
|
||||
export { convertJsonToYamlConfig } from "./converter.js";
|
||||
export { ConfigYaml, configYamlSchema } from "./schemas/index.js";
|
||||
export { resolveSecretsOnClient } from "./resolveSecretsOnClient.js";
|
||||
export {
|
||||
ClientConfigYaml,
|
||||
clientConfigYamlSchema,
|
||||
ConfigYaml,
|
||||
configYamlSchema,
|
||||
} from "./schemas/index.js";
|
||||
export type { ModelConfig } from "./schemas/models.js";
|
||||
export { validateConfigYaml } from "./validation.js";
|
||||
export {
|
||||
ConfigResult,
|
||||
ConfigValidationError,
|
||||
validateConfigYaml,
|
||||
ValidationLevel,
|
||||
} from "./validation.js";
|
||||
|
|
|
|||
64
packages/config-yaml/src/resolveSecretsOnClient.ts
Normal file
64
packages/config-yaml/src/resolveSecretsOnClient.ts
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import { ClientConfigYaml, ConfigYaml } from "./schemas/index.js";
|
||||
type SecretProvider = (
|
||||
secretNames: string[],
|
||||
) => Promise<{ [key: string]: string }>;
|
||||
|
||||
/**
|
||||
* Take a ConfigYaml with apiKeySecrets, and look to fill in these secrets
|
||||
* with whatever secret store exists in the client.
|
||||
*/
|
||||
export async function resolveSecretsOnClient(
|
||||
configYaml: ClientConfigYaml,
|
||||
getSecretsFromClientStore: SecretProvider,
|
||||
getSecretsFromServer: SecretProvider,
|
||||
): Promise<ClientConfigYaml> {
|
||||
const requiredSecrets = getRequiredSecretsInClientConfig(configYaml);
|
||||
|
||||
const secretsFoundOnClient = await getSecretsFromClientStore(requiredSecrets);
|
||||
|
||||
const secretsNotFoundOnClient = requiredSecrets.filter(
|
||||
(secret) => !secretsFoundOnClient[secret],
|
||||
);
|
||||
|
||||
let secretsFoundOnServer = {};
|
||||
if (secretsNotFoundOnClient.length > 0) {
|
||||
secretsFoundOnServer = await getSecretsFromServer(secretsNotFoundOnClient);
|
||||
}
|
||||
|
||||
const clientSecrets = {
|
||||
...secretsFoundOnClient,
|
||||
...secretsFoundOnServer,
|
||||
};
|
||||
|
||||
const finalConfigYaml = injectClientSecrets(configYaml, clientSecrets);
|
||||
|
||||
// Anything with an apiKeySecret left over must use proxy
|
||||
return finalConfigYaml;
|
||||
}
|
||||
|
||||
function getRequiredSecretsInClientConfig(
|
||||
configYaml: ClientConfigYaml,
|
||||
): string[] {
|
||||
const secrets = new Set<string>();
|
||||
for (const model of configYaml.models ?? []) {
|
||||
if (model.apiKeySecret) {
|
||||
secrets.add(model.apiKeySecret);
|
||||
}
|
||||
}
|
||||
return Array.from(secrets);
|
||||
}
|
||||
|
||||
function injectClientSecrets(
|
||||
configYaml: ClientConfigYaml,
|
||||
clientSecrets: Record<string, string>,
|
||||
): ConfigYaml {
|
||||
for (const model of configYaml.models ?? []) {
|
||||
if (model.apiKeySecret && clientSecrets[model.apiKeySecret]) {
|
||||
// Remove apiKeySecret and place the client secret in apiKey
|
||||
model.apiKey = clientSecrets[model.apiKeySecret];
|
||||
delete model.apiKeySecret;
|
||||
}
|
||||
}
|
||||
|
||||
return configYaml;
|
||||
}
|
||||
|
|
@ -48,9 +48,13 @@ export const configYamlSchema = z.object({
|
|||
data: z.array(dataSchema).optional(),
|
||||
tools: z.array(toolSchema).optional(),
|
||||
mcpServers: z.array(mcpServerSchema).optional(),
|
||||
rules: z.string().optional(),
|
||||
rules: z.array(z.string()).optional(),
|
||||
prompts: z.array(promptSchema).optional(),
|
||||
docs: z.array(docSchema).optional(),
|
||||
});
|
||||
|
||||
export type ConfigYaml = z.infer<typeof configYamlSchema>;
|
||||
|
||||
export const clientConfigYamlSchema = configYamlSchema.omit({ packages: true });
|
||||
|
||||
export type ClientConfigYaml = z.infer<typeof clientConfigYamlSchema>;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,12 @@ export interface ConfigValidationError {
|
|||
message: string;
|
||||
}
|
||||
|
||||
export interface ConfigResult<T> {
|
||||
config: T | undefined;
|
||||
errors: ConfigValidationError[] | undefined;
|
||||
configLoadInterrupted: boolean;
|
||||
}
|
||||
|
||||
export function validateConfigYaml(
|
||||
config: ConfigYaml,
|
||||
): ConfigValidationError[] {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue