Skip to content

Commit 2b4a901

Browse files
chore: fix reading from bundle, when already read from planner
1 parent f5d3820 commit 2b4a901

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

src/commands/agent/generate/test-spec.ts

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -196,38 +196,41 @@ export async function getPluginsAndFunctions(
196196
}
197197

198198
try {
199-
const genAiPlannerBundles = getMetadataFilePaths(cs, 'GenAiPlannerBundle');
200-
const plannerBundleXml = await fs.promises.readFile(
201-
genAiPlannerBundles[parsedBotVersion.BotVersion.conversationDefinitionPlanners.genAiPlannerName ?? subjectName],
202-
'utf-8'
203-
);
204-
const parsedPlannerBundle = parser.parse(plannerBundleXml) as {
205-
GenAiPlannerBundle: {
206-
genAiPlugins: Array<
207-
| {
208-
genAiPluginName: string;
209-
}
210-
| { genAiPluginName: string; genAiCustomizedPlugin: { genAiFunctions: Array<{ functionName: string }> } }
211-
>;
199+
if (genAiFunctions.length === 0 && Object.keys(genAiPlugins).length === 0) {
200+
// if we've already found functions and plugins from the genAiPlanner, don't try to read the bundle
201+
const genAiPlannerBundles = getMetadataFilePaths(cs, 'GenAiPlannerBundle');
202+
const plannerBundleXml = await fs.promises.readFile(
203+
genAiPlannerBundles[parsedBotVersion.BotVersion.conversationDefinitionPlanners.genAiPlannerName ?? subjectName],
204+
'utf-8'
205+
);
206+
const parsedPlannerBundle = parser.parse(plannerBundleXml) as {
207+
GenAiPlannerBundle: {
208+
genAiPlugins: Array<
209+
| {
210+
genAiPluginName: string;
211+
}
212+
| { genAiPluginName: string; genAiCustomizedPlugin: { genAiFunctions: Array<{ functionName: string }> } }
213+
>;
214+
};
212215
};
213-
};
214-
genAiFunctions = ensureArray(parsedPlannerBundle.GenAiPlannerBundle.genAiPlugins)
215-
.filter((f) => 'genAiCustomizedPlugin' in f)
216-
.map(
217-
({ genAiCustomizedPlugin }) =>
218-
genAiCustomizedPlugin.genAiFunctions.find((plugin) => plugin.functionName !== '')!.functionName
216+
genAiFunctions = ensureArray(parsedPlannerBundle.GenAiPlannerBundle.genAiPlugins)
217+
.filter((f) => 'genAiCustomizedPlugin' in f)
218+
.map(
219+
({ genAiCustomizedPlugin }) =>
220+
genAiCustomizedPlugin.genAiFunctions.find((plugin) => plugin.functionName !== '')!.functionName
221+
);
222+
223+
genAiPlugins = ensureArray(parsedPlannerBundle.GenAiPlannerBundle.genAiPlugins).reduce(
224+
(acc, { genAiPluginName }) => ({
225+
...acc,
226+
[genAiPluginName]: cs.getComponentFilenamesByNameAndType({
227+
fullName: genAiPluginName,
228+
type: 'GenAiPlugin',
229+
})[0],
230+
}),
231+
{}
219232
);
220-
221-
genAiPlugins = ensureArray(parsedPlannerBundle.GenAiPlannerBundle.genAiPlugins).reduce(
222-
(acc, { genAiPluginName }) => ({
223-
...acc,
224-
[genAiPluginName]: cs.getComponentFilenamesByNameAndType({
225-
fullName: genAiPluginName,
226-
type: 'GenAiPlugin',
227-
})[0],
228-
}),
229-
{}
230-
);
233+
}
231234
} catch (e) {
232235
throw new SfError(
233236
`Error parsing GenAiPlannerBundle: ${

0 commit comments

Comments
 (0)