injectBlock

This commit is contained in:
Nate 2025-04-01 20:25:51 -07:00
parent 4e1cdb48ea
commit 4ae3ac9434
7 changed files with 90 additions and 15 deletions

View file

@ -13,7 +13,7 @@
"@aws-sdk/client-sagemaker-runtime": "^3.758.0",
"@aws-sdk/credential-providers": "^3.758.0",
"@continuedev/config-types": "^1.0.13",
"@continuedev/config-yaml": "^1.0.67",
"@continuedev/config-yaml": "^1.0.70",
"@continuedev/fetch": "^1.0.4",
"@continuedev/llm-info": "^1.0.8",
"@continuedev/openai-adapters": "^1.0.18",
@ -2974,9 +2974,9 @@
}
},
"node_modules/@continuedev/config-yaml": {
"version": "1.0.67",
"resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.67.tgz",
"integrity": "sha512-RbJXSH2Z9XmaN1h9Dm0Qfru7UeAdCAEWMiEgJ9A2FGHysR9oxbQDqptk1Y61oDSpYeX+lWsxkz/SFIc2PjNnKg==",
"version": "1.0.70",
"resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.70.tgz",
"integrity": "sha512-0hwc2a2NyUDDNDAx23SOFfY4sV8EafuCow4JNpRzCz8swH3ZfO+vdOzKMIEzAzcYXcpjldsOAZsYE4iypu1L+Q==",
"dependencies": {
"@continuedev/config-types": "^1.0.14",
"yaml": "^2.6.1",

View file

@ -47,7 +47,7 @@
"@aws-sdk/client-sagemaker-runtime": "^3.758.0",
"@aws-sdk/credential-providers": "^3.758.0",
"@continuedev/config-types": "^1.0.13",
"@continuedev/config-yaml": "^1.0.67",
"@continuedev/config-yaml": "^1.0.70",
"@continuedev/fetch": "^1.0.4",
"@continuedev/llm-info": "^1.0.8",
"@continuedev/openai-adapters": "^1.0.18",

10
gui/package-lock.json generated
View file

@ -7,7 +7,7 @@
"name": "gui",
"license": "Apache-2.0",
"dependencies": {
"@continuedev/config-yaml": "^1.0.67",
"@continuedev/config-yaml": "^1.0.70",
"@headlessui/react": "^2.2.0",
"@heroicons/react": "^2.0.18",
"@reduxjs/toolkit": "^2.3.0",
@ -111,7 +111,7 @@
"@aws-sdk/client-sagemaker-runtime": "^3.758.0",
"@aws-sdk/credential-providers": "^3.758.0",
"@continuedev/config-types": "^1.0.13",
"@continuedev/config-yaml": "^1.0.67",
"@continuedev/config-yaml": "^1.0.70",
"@continuedev/fetch": "^1.0.4",
"@continuedev/llm-info": "^1.0.8",
"@continuedev/openai-adapters": "^1.0.18",
@ -554,9 +554,9 @@
}
},
"node_modules/@continuedev/config-yaml": {
"version": "1.0.67",
"resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.67.tgz",
"integrity": "sha512-RbJXSH2Z9XmaN1h9Dm0Qfru7UeAdCAEWMiEgJ9A2FGHysR9oxbQDqptk1Y61oDSpYeX+lWsxkz/SFIc2PjNnKg==",
"version": "1.0.70",
"resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.70.tgz",
"integrity": "sha512-0hwc2a2NyUDDNDAx23SOFfY4sV8EafuCow4JNpRzCz8swH3ZfO+vdOzKMIEzAzcYXcpjldsOAZsYE4iypu1L+Q==",
"dependencies": {
"@continuedev/config-types": "^1.0.14",
"yaml": "^2.6.1",

View file

@ -15,7 +15,7 @@
"test:watch": "vitest"
},
"dependencies": {
"@continuedev/config-yaml": "^1.0.67",
"@continuedev/config-yaml": "^1.0.70",
"@headlessui/react": "^2.2.0",
"@heroicons/react": "^2.0.18",
"@reduxjs/toolkit": "^2.3.0",

View file

@ -1,6 +1,6 @@
{
"name": "@continuedev/config-yaml",
"version": "1.0.69",
"version": "1.0.70",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",

View file

@ -193,5 +193,40 @@ describe("E2E Scenarios", () => {
expect(geminiSecretValue2).toBe("gemini-api-key");
});
it("should correctly unroll assistant with injected blocks", async () => {
const unrolledConfig = await unrollAssistant(
"test-org/assistant",
registry,
{
renderSecrets: true,
platformClient,
orgScopeId: "test-org",
currentUserSlug: "test-user",
onPremProxyUrl: null,
// Add an injected block
injectBlocks: [
{
ownerSlug: "test-org",
packageSlug: "docs",
versionSlug: "latest",
},
],
},
);
// The original docs array should have one item
expect(unrolledConfig.docs?.length).toBe(2); // Now 2 with the injected block
// Check the original doc is still there
expect(unrolledConfig.docs?.[0]?.startUrl).toBe(
"https://docs.python.org/release/3.13.1",
);
// Check the injected doc block was added
expect(unrolledConfig.docs?.[1]?.startUrl).toBe(
"https://docs.python.org/release/3.13.1",
);
});
it.skip("should prioritize org over user / package secrets", () => {});
});

View file

@ -19,6 +19,7 @@ import {
configYamlSchema,
} from "../schemas/index.js";
import { useProxyForUnrenderedSecrets } from "./clientRender.js";
import { getBlockType } from "./getBlockType.js";
export function parseConfigYaml(configYaml: string): ConfigYaml {
try {
@ -176,11 +177,18 @@ async function extractRenderedSecretsMap(
return map;
}
export interface DoNotRenderSecretsUnrollAssistantOptions {
export interface BaseUnrollAssistantOptions {
renderSecrets: boolean;
injectBlocks?: FullSlug[];
}
export interface DoNotRenderSecretsUnrollAssistantOptions
extends BaseUnrollAssistantOptions {
renderSecrets: false;
}
export interface RenderSecretsUnrollAssistantOptions {
export interface RenderSecretsUnrollAssistantOptions
extends BaseUnrollAssistantOptions {
renderSecrets: true;
orgScopeId: string | null;
currentUserSlug: string;
@ -236,7 +244,11 @@ export async function unrollAssistantFromContent(
let parsedYaml = parseConfigYaml(rawYaml);
// Unroll blocks and convert their secrets to FQSNs
const unrolledAssistant = await unrollBlocks(parsedYaml, registry);
const unrolledAssistant = await unrollBlocks(
parsedYaml,
registry,
options.injectBlocks,
);
// Back to a string so we can fill in template variables
const rawUnrolledYaml = YAML.stringify(unrolledAssistant);
@ -273,6 +285,7 @@ export async function unrollAssistantFromContent(
export async function unrollBlocks(
assistant: ConfigYaml,
registry: Registry,
injectBlocks: FullSlug[] | undefined,
): Promise<AssistantUnrolled> {
const unrolledAssistant: AssistantUnrolled = {
name: assistant.name,
@ -349,6 +362,33 @@ export async function unrollBlocks(
unrolledAssistant.rules = rules;
}
// Add injected blocks
for (const injectBlock of injectBlocks ?? []) {
try {
const blockConfigYaml = await registry.getContent(injectBlock);
const parsedBlock = parseConfigYaml(blockConfigYaml);
const blockType = getBlockType(parsedBlock);
const resolvedBlock = await resolveBlock(
injectBlock,
undefined,
registry,
);
if (blockType) {
if (!unrolledAssistant[blockType]) {
unrolledAssistant[blockType] = [];
}
unrolledAssistant[blockType]?.push(
...(resolvedBlock[blockType] as any),
);
}
} catch (err) {
console.error(
`Failed to unroll block ${injectBlock}: ${(err as Error).message}`,
);
}
}
return unrolledAssistant;
}