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 1 commit
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
5 changes: 3 additions & 2 deletions packages/config-yaml/package-lock.json

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

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 @@ -98,6 +99,22 @@ describe("E2E Scenarios", () => {
},
};

it.only("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
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
50 changes: 32 additions & 18 deletions packages/config-yaml/src/load/unroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,23 @@ export async function unrollBlocks(
for (const unrolledBlock of assistant[section]) {
// "uses/with" block
if ("uses" in unrolledBlock) {
const blockConfigYaml = await resolveBlock(
decodeFullSlug(unrolledBlock.uses),
unrolledBlock.with,
registry,
);
const block = blockConfigYaml[section]?.[0];
if (block) {
sectionBlocks.push(
mergeOverrides(block, unrolledBlock.override ?? {}),
try {
const blockConfigYaml = await resolveBlock(
decodeFullSlug(unrolledBlock.uses),
unrolledBlock.with,
registry,
);
const block = blockConfigYaml[section]?.[0];
if (block) {
sectionBlocks.push(
mergeOverrides(block, unrolledBlock.override ?? {}),
);
}
} catch (err) {
console.error(
`Failed to unroll block ${unrolledBlock.uses}: ${(err as Error).message}`,
);
sectionBlocks.push(null);
}
} else {
// Normal block
Expand All @@ -315,19 +322,26 @@ export async function unrollBlocks(

// Rules are a bit different because they're just strings, so handle separately
if (assistant.rules) {
const rules: string[] = [];
const rules: Array<string | null> = [];
for (const rule of assistant.rules) {
if (typeof rule === "string") {
rules.push(rule);
} else {
const blockConfigYaml = await resolveBlock(
decodeFullSlug(rule.uses),
rule.with,
registry,
);
const block = blockConfigYaml.rules?.[0];
if (block) {
rules.push(block);
try {
const blockConfigYaml = await resolveBlock(
decodeFullSlug(rule.uses),
rule.with,
registry,
);
const block = blockConfigYaml.rules?.[0];
if (block) {
rules.push(block);
}
} catch (err) {
console.error(
`Failed to unroll block ${rule.uses}: ${(err as Error).message}`,
);
rules.push(null);
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions packages/config-yaml/src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ export const configYamlSchema = baseConfigYamlSchema.extend({
export type ConfigYaml = z.infer<typeof configYamlSchema>;

export const assistantUnrolledSchema = baseConfigYamlSchema.extend({
models: z.array(modelSchema).optional(),
context: z.array(contextSchema).optional(),
data: z.array(dataSchema).optional(),
mcpServers: z.array(mcpServerSchema).optional(),
rules: z.array(z.string()).optional(),
prompts: z.array(promptSchema).optional(),
docs: z.array(docSchema).optional(),
models: z.array(modelSchema.nullable()).optional(),
context: z.array(contextSchema.nullable()).optional(),
data: z.array(dataSchema.nullable()).optional(),
mcpServers: z.array(mcpServerSchema.nullable()).optional(),
rules: z.array(z.string().nullable()).optional(),
prompts: z.array(promptSchema.nullable()).optional(),
docs: z.array(docSchema.nullable()).optional(),
});

export type AssistantUnrolled = z.infer<typeof assistantUnrolledSchema>;
Expand Down
Loading