Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle deleted blocks #4945

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 44 additions & 20 deletions core/config/yaml/loadYaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ConfigResult,
ConfigValidationError,
FQSN,
isAssistantUnrolledNonNullable,
ModelRole,
PlatformClient,
RegistryClient,
Expand Down Expand Up @@ -92,7 +93,15 @@ async function loadConfigYaml(
renderSecrets: true,
},
));
const errors = validateConfigYaml(config);

const errors = isAssistantUnrolledNonNullable(config)
? validateConfigYaml(config)
: [
{
fatal: true,
message: "Assistant includes blocks that don't exist",
},
];

if (errors?.some((error) => error.fatal)) {
return {
Expand Down Expand Up @@ -122,29 +131,13 @@ async function configYamlToContinueConfig(
allowFreeTrial: boolean = true,
): Promise<{ config: ContinueConfig; errors: ConfigValidationError[] }> {
const localErrors: ConfigValidationError[] = [];

const continueConfig: ContinueConfig = {
slashCommands: [],
models: [],
tools: [...allTools],
mcpServerStatuses: [],
systemMessage: undefined,
experimental: {
modelContextProtocolServers: config.mcpServers?.map((mcpServer) => ({
transport: {
type: "stdio",
command: mcpServer.command,
args: mcpServer.args ?? [],
env: mcpServer.env,
},
})),
},
docs: config.docs?.map((doc) => ({
title: doc.name,
startUrl: doc.startUrl,
rootUrl: doc.rootUrl,
faviconUrl: doc.faviconUrl,
})),
rules: config.rules,
systemMessage: config.rules?.join("\n"),
contextProviders: [],
modelsByRole: {
chat: [],
Expand All @@ -164,7 +157,38 @@ async function configYamlToContinueConfig(
rerank: null,
summarize: null,
},
data: config.data,
};

// Right now, if there are any missing packages in the config, then we will just throw an error
if (!isAssistantUnrolledNonNullable(config)) {
return {
config: continueConfig,
errors: [
{
message: "Found missing blocks in config.yaml",
fatal: true,
},
],
};
}

continueConfig.data = config.data;
continueConfig.rules = config.rules;
continueConfig.docs = config.docs?.map((doc) => ({
title: doc.name,
startUrl: doc.startUrl,
rootUrl: doc.rootUrl,
faviconUrl: doc.faviconUrl,
}));
continueConfig.experimental = {
modelContextProtocolServers: config.mcpServers?.map((mcpServer) => ({
transport: {
type: "stdio",
command: mcpServer.command,
args: mcpServer.args ?? [],
env: mcpServer.env,
},
})),
};

// Prompt files -
Expand Down
8 changes: 4 additions & 4 deletions core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.77",
"@continuedev/fetch": "^1.0.4",
"@continuedev/llm-info": "^1.0.8",
"@continuedev/openai-adapters": "^1.0.18",
Expand Down
10 changes: 5 additions & 5 deletions gui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test:watch": "vitest"
},
"dependencies": {
"@continuedev/config-yaml": "^1.0.71",
"@continuedev/config-yaml": "^1.0.77",
"@headlessui/react": "^2.2.0",
"@heroicons/react": "^2.0.18",
"@reduxjs/toolkit": "^2.3.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseConfigYaml, Rule } from "@continuedev/config-yaml";
import { parseConfigYaml, type Rule } from "@continuedev/config-yaml";
import { ArrowsPointingOutIcon, PencilIcon } from "@heroicons/react/24/outline";
import { useContext, useMemo } from "react";
import { useSelector } from "react-redux";
Expand Down
1 change: 1 addition & 0 deletions packages/config-yaml/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/config-yaml/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@continuedev/config-yaml",
"version": "1.0.72",
"version": "1.0.77",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import * as fs from "fs";
import { decodeSecretLocation, resolveSecretLocationInProxy } from "../dist";
import {
decodeSecretLocation,
FQSN,
FullSlug,
PlatformClient,
PlatformSecretStore,
Registry,
resolveFQSN,
resolveSecretLocationInProxy,
SecretLocation,
SecretResult,
SecretStore,
SecretType,
unrollAssistant,
} from "../src";
} from "../index.js";

// Test e2e flows from raw yaml -> unroll -> client render -> resolve secrets on proxy
describe("E2E Scenarios", () => {
Expand Down Expand Up @@ -92,12 +93,28 @@ describe("E2E Scenarios", () => {
getContent: async function (fullSlug: FullSlug): Promise<string> {
return fs
.readFileSync(
`./test/packages/${fullSlug.ownerSlug}/${fullSlug.packageSlug}.yaml`,
`./src/__tests__/packages/${fullSlug.ownerSlug}/${fullSlug.packageSlug}.yaml`,
)
.toString();
},
};

it("should unroll assistant with a single block that doesn't exist", async () => {
const unrolledConfig = await unrollAssistant(
"test-org/assistant-with-non-existing-block",
registry,
{
renderSecrets: true,
platformClient,
orgScopeId: "test-org",
currentUserSlug: "test-user",
onPremProxyUrl: null,
},
);

expect(unrolledConfig.rules?.[0]).toBeNull();
});

it("should correctly unroll assistant", async () => {
const unrolledConfig = await unrollAssistant(
"test-org/assistant",
Expand Down Expand Up @@ -133,10 +150,10 @@ describe("E2E Scenarios", () => {
);

expect(unrolledConfig.rules?.length).toBe(2);
expect(unrolledConfig.docs?.[0].startUrl).toBe(
expect(unrolledConfig.docs?.[0]?.startUrl).toBe(
"https://docs.python.org/release/3.13.1",
);
expect(unrolledConfig.docs?.[0].rootUrl).toBe(
expect(unrolledConfig.docs?.[0]?.rootUrl).toBe(
"https://docs.python.org/release/3.13.1",
);

Expand Down Expand Up @@ -176,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", () => {});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: Assistant with non-existing block
version: 0.0.1
schema: v1

rules:
- uses: test-org/non-existing-package
7 changes: 4 additions & 3 deletions packages/config-yaml/src/load/clientRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,17 @@ export function useProxyForUnrenderedSecrets(
if (config.models) {
for (let i = 0; i < config.models.length; i++) {
const apiKeyLocation = getUnrenderedSecretLocation(
config.models[i].apiKey,
config.models[i]?.apiKey,
);
if (apiKeyLocation) {
config.models[i] = {
...config.models[i],
name: config.models[i]?.name ?? "",
provider: "continue-proxy",
model: getContinueProxyModelName(
packageSlug,
config.models[i].provider,
config.models[i].model,
config.models[i]?.provider ?? "",
config.models[i]?.model ?? "",
),
apiKeyLocation: encodeSecretLocation(apiKeyLocation),
orgScopeId,
Expand Down
Loading
Loading