Skip to content

Commit 6098fbf

Browse files
authored
fix(cli): agent injected blocks ignored (#8361)
1 parent d729b5d commit 6098fbf

File tree

3 files changed

+36
-52
lines changed

3 files changed

+36
-52
lines changed

extensions/cli/src/configLoader.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,12 @@ async function loadFromSource(
195195
);
196196

197197
case "no-config":
198-
return {
199-
name: "No Config Specified",
200-
version: "1.0.0",
201-
};
202-
198+
return await unrollPackageIdentifiersAsConfigYaml(
199+
injectBlocks,
200+
accessToken,
201+
organizationId,
202+
apiClient,
203+
);
203204
default:
204205
throw new Error(`Unknown config source type: ${(source as any).type}`);
205206
}
@@ -324,9 +325,7 @@ async function loadUserAssistantWithFallback(
324325
organizationId,
325326
apiClient,
326327
);
327-
if (injectedConfig?.block) {
328-
apiConfig = mergeUnrolledAssistants(apiConfig, injectedConfig.block);
329-
}
328+
apiConfig = mergeUnrolledAssistants(apiConfig, injectedConfig);
330329
}
331330

332331
return apiConfig;
@@ -386,9 +385,7 @@ async function loadDefaultAgent(
386385
organizationId,
387386
apiClient,
388387
);
389-
if (injectedConfig?.block) {
390-
apiConfig = mergeUnrolledAssistants(apiConfig, injectedConfig.block);
391-
}
388+
apiConfig = mergeUnrolledAssistants(apiConfig, injectedConfig);
392389
}
393390

394391
return apiConfig;
@@ -399,13 +396,13 @@ export async function unrollPackageIdentifiersAsConfigYaml(
399396
accessToken: string | null,
400397
organizationId: string | null,
401398
apiClient: DefaultApiInterface,
402-
): Promise<{ block: AssistantUnrolled | undefined } | null> {
399+
): Promise<AssistantUnrolled> {
403400
const unrollResult = await unrollAssistantFromContent(
404401
{
405402
uriType: "file",
406403
fileUri: "",
407404
},
408-
"name: FILLER\nschema: v1\nversion: 0.0.1",
405+
"name: Agent\nschema: v1\nversion: 0.0.1",
409406
new RegistryClient({
410407
accessToken: accessToken ?? undefined,
411408
apiBase: env.apiBase,
@@ -420,16 +417,17 @@ export async function unrollPackageIdentifiersAsConfigYaml(
420417
injectBlocks: packageIdentifiers,
421418
},
422419
);
423-
if (!unrollResult?.config) {
420+
if (unrollResult.errors) {
424421
const fatalError = unrollResult.errors?.find((e) => e.fatal);
425422
if (fatalError) {
426-
throw new Error(`Error(s) unrolling package: ${fatalError.message}`);
423+
throw new Error(`Failed to load config: ${fatalError.message}`);
427424
}
428425
}
426+
if (!unrollResult?.config) {
427+
throw new Error(`Failed to load config`);
428+
}
429429

430-
return {
431-
block: unrollResult?.config,
432-
};
430+
return unrollResult.config;
433431
}
434432

435433
async function unrollAssistantWithConfig(
@@ -546,9 +544,7 @@ async function loadAssistantSlug(
546544
organizationId,
547545
apiClient,
548546
);
549-
if (injectedConfig?.block) {
550-
apiConfig = mergeUnrolledAssistants(apiConfig, injectedConfig.block);
551-
}
547+
apiConfig = mergeUnrolledAssistants(apiConfig, injectedConfig);
552548
}
553549

554550
return apiConfig;

extensions/cli/src/services/ConfigService.test.ts

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,9 @@ describe("ConfigService", () => {
6868
vi.mocked(
6969
configLoader.unrollPackageIdentifiersAsConfigYaml,
7070
).mockResolvedValue({
71-
block: {
72-
name: "default-chat-model",
73-
version: "1.0.0",
74-
models: [defaultModel],
75-
},
71+
name: "default-chat-model",
72+
version: "1.0.0",
73+
models: [defaultModel],
7674
});
7775
});
7876

@@ -520,11 +518,9 @@ describe("ConfigService", () => {
520518
vi.mocked(
521519
configLoader.unrollPackageIdentifiersAsConfigYaml,
522520
).mockResolvedValue({
523-
block: {
524-
name: "default",
525-
version: "1.0.0",
526-
models: [defaultModel],
527-
},
521+
name: "default",
522+
version: "1.0.0",
523+
models: [defaultModel],
528524
});
529525

530526
const result = await service.addDefaultChatModelIfNone(
@@ -616,11 +612,9 @@ describe("ConfigService", () => {
616612
vi.mocked(
617613
configLoader.unrollPackageIdentifiersAsConfigYaml,
618614
).mockResolvedValue({
619-
block: {
620-
name: "default",
621-
version: "1.0.0",
622-
models: [defaultModel],
623-
},
615+
name: "default",
616+
version: "1.0.0",
617+
models: [defaultModel],
624618
});
625619

626620
const result = await service.addDefaultChatModelIfNone(
@@ -643,11 +637,9 @@ describe("ConfigService", () => {
643637
vi.mocked(
644638
configLoader.unrollPackageIdentifiersAsConfigYaml,
645639
).mockResolvedValue({
646-
block: {
647-
name: "default",
648-
version: "1.0.0",
649-
models: [defaultModel],
650-
},
640+
name: "default",
641+
version: "1.0.0",
642+
models: [defaultModel],
651643
});
652644

653645
const result = await service.addDefaultChatModelIfNone(
@@ -695,11 +687,9 @@ describe("ConfigService", () => {
695687
vi.mocked(
696688
configLoader.unrollPackageIdentifiersAsConfigYaml,
697689
).mockResolvedValue({
698-
block: {
699-
name: "default",
700-
version: "1.0.0",
701-
models: [], // Empty models array
702-
},
690+
name: "default",
691+
version: "1.0.0",
692+
models: [], // Empty models array
703693
});
704694

705695
await expect(
@@ -724,11 +714,9 @@ describe("ConfigService", () => {
724714
vi.mocked(
725715
configLoader.unrollPackageIdentifiersAsConfigYaml,
726716
).mockResolvedValue({
727-
block: {
728-
name: "default",
729-
version: "1.0.0",
730-
models: [defaultModel],
731-
},
717+
name: "default",
718+
version: "1.0.0",
719+
models: [defaultModel],
732720
});
733721

734722
const result = await service.addDefaultChatModelIfNone(

extensions/cli/src/services/ConfigService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export class ConfigService
228228
authConfig?.organizationId ?? null,
229229
apiClient,
230230
);
231-
const defaultModel = modelConfig?.block?.models?.[0];
231+
const defaultModel = modelConfig?.models?.[0];
232232
if (!defaultModel) {
233233
throw new Error("Loaded default model contained no model block");
234234
}

0 commit comments

Comments
 (0)