require configresult for unrolling
This commit is contained in:
parent
547ad0e271
commit
e210afa336
3 changed files with 43 additions and 64 deletions
|
|
@ -134,6 +134,7 @@ async function loadConfigYaml(options: {
|
|||
rootPath,
|
||||
}),
|
||||
{
|
||||
renderSecrets: true,
|
||||
currentUserSlug: "",
|
||||
onPremProxyUrl: null,
|
||||
orgScopeId,
|
||||
|
|
@ -142,9 +143,7 @@ async function loadConfigYaml(options: {
|
|||
controlPlaneClient,
|
||||
ide,
|
||||
),
|
||||
renderSecrets: true,
|
||||
injectBlocks: allLocalBlocks,
|
||||
asConfigResult: true,
|
||||
},
|
||||
);
|
||||
config = unrollResult.config;
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ describe("E2E Scenarios", () => {
|
|||
},
|
||||
);
|
||||
|
||||
expect(unrolledConfig.rules?.[0]).toBeNull();
|
||||
expect(unrolledConfig.config?.rules?.[0]).toBeNull();
|
||||
});
|
||||
|
||||
it("should correctly unroll assistant", async () => {
|
||||
|
|
@ -142,19 +142,21 @@ describe("E2E Scenarios", () => {
|
|||
},
|
||||
);
|
||||
|
||||
// Test that packages were correctly unrolled and params replaced
|
||||
expect(unrolledConfig.models?.length).toBe(4);
|
||||
const config = unrolledConfig.config;
|
||||
|
||||
const openAiModel = unrolledConfig.models?.[0]!;
|
||||
// Test that packages were correctly unrolled and params replaced
|
||||
expect(config?.models?.length).toBe(4);
|
||||
|
||||
const openAiModel = config?.models?.[0]!;
|
||||
expect(openAiModel.apiKey).toBe("sk-123");
|
||||
|
||||
const geminiModel = unrolledConfig.models?.[1]!;
|
||||
const geminiModel = config?.models?.[1]!;
|
||||
expect(geminiModel.provider).toBe("continue-proxy");
|
||||
expect(geminiModel.apiKey).toBeUndefined();
|
||||
const geminiSecretLocation = "organization:test-org/GEMINI_API_KEY";
|
||||
expect((geminiModel as any).apiKeyLocation).toBe(geminiSecretLocation);
|
||||
|
||||
const anthropicModel = unrolledConfig.models?.[2]!;
|
||||
const anthropicModel = config?.models?.[2]!;
|
||||
expect(anthropicModel.provider).toBe("continue-proxy");
|
||||
expect(anthropicModel.apiKey).toBeUndefined();
|
||||
const anthropicSecretLocation =
|
||||
|
|
@ -163,15 +165,15 @@ describe("E2E Scenarios", () => {
|
|||
anthropicSecretLocation,
|
||||
);
|
||||
|
||||
const proxyOllamaModel = unrolledConfig.models?.[3]!;
|
||||
const proxyOllamaModel = config?.models?.[3]!;
|
||||
expect(proxyOllamaModel.provider).toBe("ollama");
|
||||
expect(proxyOllamaModel.defaultCompletionOptions?.stream).toBe(false);
|
||||
|
||||
expect(unrolledConfig.rules?.length).toBe(2);
|
||||
expect(unrolledConfig.docs?.[0]?.startUrl).toBe(
|
||||
expect(config?.rules?.length).toBe(2);
|
||||
expect(config?.docs?.[0]?.startUrl).toBe(
|
||||
"https://docs.python.org/release/3.13.1",
|
||||
);
|
||||
expect(unrolledConfig.docs?.[0]?.rootUrl).toBe(
|
||||
expect(config?.docs?.[0]?.rootUrl).toBe(
|
||||
"https://docs.python.org/release/3.13.1",
|
||||
);
|
||||
|
||||
|
|
@ -242,16 +244,18 @@ describe("E2E Scenarios", () => {
|
|||
},
|
||||
);
|
||||
|
||||
const config = unrolledConfig.config;
|
||||
|
||||
// The original rules array should have two items
|
||||
expect(unrolledConfig.rules?.length).toBe(3); // Now 3 with the injected block
|
||||
expect(config?.rules?.length).toBe(3); // Now 3 with the injected block
|
||||
|
||||
// Check the original doc is still there
|
||||
expect(unrolledConfig.docs?.[0]?.startUrl).toBe(
|
||||
expect(config?.docs?.[0]?.startUrl).toBe(
|
||||
"https://docs.python.org/release/3.13.1",
|
||||
);
|
||||
|
||||
// Check the injected doc block was added
|
||||
expect(unrolledConfig.rules?.[2]).toBe("Be kind");
|
||||
expect(config?.rules?.[2]).toBe("Be kind");
|
||||
});
|
||||
|
||||
it.skip("should prioritize org over user / package secrets", () => {});
|
||||
|
|
|
|||
|
|
@ -196,7 +196,6 @@ async function extractRenderedSecretsMap(
|
|||
export interface BaseUnrollAssistantOptions {
|
||||
renderSecrets: boolean;
|
||||
injectBlocks?: PackageIdentifier[];
|
||||
asConfigResult?: boolean; // TODO: Decide
|
||||
}
|
||||
|
||||
export interface DoNotRenderSecretsUnrollAssistantOptions
|
||||
|
|
@ -218,24 +217,11 @@ export type UnrollAssistantOptions =
|
|||
| DoNotRenderSecretsUnrollAssistantOptions
|
||||
| RenderSecretsUnrollAssistantOptions;
|
||||
|
||||
// Overload to satisfy existing consumers of unrollAssistant.
|
||||
export async function unrollAssistant(
|
||||
id: PackageIdentifier,
|
||||
registry: Registry,
|
||||
options: UnrollAssistantOptions & { asConfigResult: true },
|
||||
): Promise<ConfigResult<AssistantUnrolled>>;
|
||||
|
||||
export async function unrollAssistant(
|
||||
id: PackageIdentifier,
|
||||
registry: Registry,
|
||||
options: UnrollAssistantOptions,
|
||||
): Promise<AssistantUnrolled>;
|
||||
|
||||
export async function unrollAssistant(
|
||||
id: PackageIdentifier,
|
||||
registry: Registry,
|
||||
options: UnrollAssistantOptions,
|
||||
): Promise<AssistantUnrolled | ConfigResult<AssistantUnrolled>> {
|
||||
): Promise<ConfigResult<AssistantUnrolled>> {
|
||||
// Request the content from the registry
|
||||
const rawContent = await registry.getContent(id);
|
||||
|
||||
|
|
@ -266,7 +252,7 @@ export async function unrollAssistantFromContent(
|
|||
rawYaml: string,
|
||||
registry: Registry,
|
||||
options: UnrollAssistantOptions,
|
||||
): Promise<AssistantUnrolled | ConfigResult<AssistantUnrolled>> {
|
||||
): Promise<ConfigResult<AssistantUnrolled>> {
|
||||
// Parse string to Zod-validated YAML
|
||||
let parsedYaml = parseConfigYaml(rawYaml);
|
||||
|
||||
|
|
@ -275,15 +261,10 @@ export async function unrollAssistantFromContent(
|
|||
parsedYaml,
|
||||
registry,
|
||||
options.injectBlocks,
|
||||
options.asConfigResult ?? false,
|
||||
);
|
||||
|
||||
// Back to a string so we can fill in template variables
|
||||
const rawUnrolledYaml = options.asConfigResult
|
||||
? YAML.stringify(
|
||||
(unrolledAssistant as ConfigResult<AssistantUnrolled>).config,
|
||||
)
|
||||
: YAML.stringify(unrolledAssistant);
|
||||
const rawUnrolledYaml = YAML.stringify(unrolledAssistant);
|
||||
|
||||
// Convert all of the template variables to FQSNs
|
||||
// Secrets from the block will have the assistant slug prepended to the FQSN
|
||||
|
|
@ -292,7 +273,11 @@ export async function unrollAssistantFromContent(
|
|||
});
|
||||
|
||||
if (!options.renderSecrets) {
|
||||
return parseAssistantUnrolled(templatedYaml);
|
||||
return {
|
||||
config: parseAssistantUnrolled(templatedYaml),
|
||||
errors: [],
|
||||
configLoadInterrupted: false,
|
||||
};
|
||||
}
|
||||
|
||||
// Render secret values/locations for client
|
||||
|
|
@ -313,25 +298,20 @@ export async function unrollAssistantFromContent(
|
|||
options.onPremProxyUrl,
|
||||
);
|
||||
|
||||
if (options.asConfigResult) {
|
||||
return {
|
||||
config: finalConfig,
|
||||
errors: (unrolledAssistant as ConfigResult<AssistantUnrolled>).errors,
|
||||
configLoadInterrupted: (
|
||||
unrolledAssistant as ConfigResult<AssistantUnrolled>
|
||||
).configLoadInterrupted,
|
||||
};
|
||||
}
|
||||
|
||||
return finalConfig;
|
||||
return {
|
||||
config: finalConfig,
|
||||
errors: (unrolledAssistant as ConfigResult<AssistantUnrolled>).errors,
|
||||
configLoadInterrupted: (
|
||||
unrolledAssistant as ConfigResult<AssistantUnrolled>
|
||||
).configLoadInterrupted,
|
||||
};
|
||||
}
|
||||
|
||||
export async function unrollBlocks(
|
||||
assistant: ConfigYaml,
|
||||
registry: Registry,
|
||||
injectBlocks: PackageIdentifier[] | undefined,
|
||||
asConfigError: boolean,
|
||||
): Promise<AssistantUnrolled | ConfigResult<AssistantUnrolled>> {
|
||||
): Promise<ConfigResult<AssistantUnrolled>> {
|
||||
const errors: ConfigValidationError[] = [];
|
||||
|
||||
const unrolledAssistant: AssistantUnrolled = {
|
||||
|
|
@ -467,20 +447,16 @@ export async function unrollBlocks(
|
|||
}
|
||||
}
|
||||
|
||||
if (asConfigError) {
|
||||
const configResult: ConfigResult<AssistantUnrolled> = {
|
||||
config: undefined,
|
||||
errors: undefined,
|
||||
configLoadInterrupted: false,
|
||||
};
|
||||
configResult.config = unrolledAssistant;
|
||||
if (errors.length > 0) {
|
||||
configResult.errors = errors;
|
||||
}
|
||||
return configResult;
|
||||
const configResult: ConfigResult<AssistantUnrolled> = {
|
||||
config: undefined,
|
||||
errors: undefined,
|
||||
configLoadInterrupted: false,
|
||||
};
|
||||
configResult.config = unrolledAssistant;
|
||||
if (errors.length > 0) {
|
||||
configResult.errors = errors;
|
||||
}
|
||||
|
||||
return unrolledAssistant;
|
||||
return configResult;
|
||||
}
|
||||
|
||||
export async function resolveBlock(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue