Skip to content

Commit 19397d4

Browse files
fix: read from genAiPlanner/Bundle
1 parent 42676eb commit 19397d4

File tree

3 files changed

+96
-46
lines changed

3 files changed

+96
-46
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"@oclif/core": "^4",
1111
"@oclif/multi-stage-output": "^0.8.17",
1212
"@salesforce/agents": "0.15.3",
13-
"@salesforce/core": "^8.13.0",
13+
"@salesforce/core": "^8.18.3",
1414
"@salesforce/kit": "^3.2.3",
1515
"@salesforce/sf-plugins-core": "^12.2.0",
16-
"@salesforce/source-deploy-retrieve": "^12.19.3",
16+
"@salesforce/source-deploy-retrieve": "^12.21.4",
1717
"@salesforce/types": "^1.3.0",
1818
"ansis": "^3.3.2",
1919
"fast-xml-parser": "^4.5.1",

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

Lines changed: 74 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { readFile } from 'node:fs/promises';
88
import { join, parse } from 'node:path';
99
import { existsSync } from 'node:fs';
1010
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
11-
import { Messages, SfProject } from '@salesforce/core';
11+
import { Messages, SfError, SfProject } from '@salesforce/core';
1212
import { AgentTest } from '@salesforce/agents';
1313
import { select, input, confirm, checkbox } from '@inquirer/prompts';
1414
import { XMLParser } from 'fast-xml-parser';
@@ -158,39 +158,88 @@ async function getPluginsAndFunctions(
158158
genAiFunctions: string[];
159159
}> {
160160
const botVersions = getMetadataFilePaths(cs, 'Bot');
161-
const genAiPlanners = getMetadataFilePaths(cs, 'GenAiPlanner');
161+
let genAiFunctions: string[] = [];
162+
let genAiPlugins: Record<string, string> = {};
162163

163164
const parser = new XMLParser();
164165
const botVersionXml = await readFile(botVersions[subjectName], 'utf-8');
165166
const parsedBotVersion = parser.parse(botVersionXml) as {
166167
BotVersion: { conversationDefinitionPlanners: { genAiPlannerName: string } };
167168
};
168169

169-
const plannerXml = await readFile(
170-
genAiPlanners[parsedBotVersion.BotVersion.conversationDefinitionPlanners.genAiPlannerName ?? subjectName],
171-
'utf-8'
172-
);
173-
const parsedPlanner = parser.parse(plannerXml) as {
174-
GenAiPlanner: {
175-
genAiPlugins: Array<{ genAiPluginName: string }>;
176-
genAiFunctions: Array<{ genAiFunctionName: string }>;
170+
try {
171+
// if the users still have genAiPlanner, not the bundle, we can work with that
172+
const genAiPlanners = getMetadataFilePaths(cs, 'GenAiPlanner');
173+
174+
const plannerXml = await readFile(
175+
genAiPlanners[parsedBotVersion.BotVersion.conversationDefinitionPlanners.genAiPlannerName ?? subjectName],
176+
'utf-8'
177+
);
178+
const parsedPlanner = parser.parse(plannerXml) as {
179+
GenAiPlanner: {
180+
genAiPlugins: Array<{ genAiPluginName: string }>;
181+
genAiFunctions: Array<{ genAiFunctionName: string }>;
182+
};
177183
};
178-
};
184+
genAiFunctions = castArray(parsedPlanner.GenAiPlanner.genAiFunctions).map(
185+
({ genAiFunctionName }) => genAiFunctionName
186+
);
179187

180-
const genAiFunctions = castArray(parsedPlanner.GenAiPlanner.genAiFunctions).map(
181-
({ genAiFunctionName }) => genAiFunctionName
182-
);
188+
genAiPlugins = castArray(parsedPlanner.GenAiPlanner.genAiPlugins).reduce(
189+
(acc, { genAiPluginName }) => ({
190+
...acc,
191+
[genAiPluginName]: cs.getComponentFilenamesByNameAndType({
192+
fullName: genAiPluginName,
193+
type: 'GenAiPlugin',
194+
})[0],
195+
}),
196+
{}
197+
);
198+
} catch (e) {
199+
// do nothing, we were trying to read the old genAiPlanner
200+
}
183201

184-
const genAiPlugins = castArray(parsedPlanner.GenAiPlanner.genAiPlugins).reduce(
185-
(acc, { genAiPluginName }) => ({
186-
...acc,
187-
[genAiPluginName]: cs.getComponentFilenamesByNameAndType({
188-
fullName: genAiPluginName,
189-
type: 'GenAiPlugin',
190-
})[0],
191-
}),
192-
{}
193-
);
202+
try {
203+
const genAiPlannerBundles = getMetadataFilePaths(cs, 'GenAiPlannerBundle');
204+
const plannerBundleXml = await readFile(
205+
genAiPlannerBundles[parsedBotVersion.BotVersion.conversationDefinitionPlanners.genAiPlannerName ?? subjectName],
206+
'utf-8'
207+
);
208+
const parsedPlannerBundle = parser.parse(plannerBundleXml) as {
209+
GenAiPlannerBundle: {
210+
genAiPlugins: Array<
211+
| {
212+
genAiPluginName: string;
213+
}
214+
| { genAiPluginName: string; genAiCustomizedPlugin: { genAiFunctions: Array<{ functionName: string }> } }
215+
>;
216+
// genAiFunctions: Array<{ genAiFunctionName: string }>;
217+
};
218+
};
219+
genAiFunctions = castArray(parsedPlannerBundle.GenAiPlannerBundle.genAiPlugins)
220+
.filter((f) => 'genAiCustomizedPlugin' in f)
221+
.map(
222+
({ genAiCustomizedPlugin }) =>
223+
genAiCustomizedPlugin.genAiFunctions.find((plugin) => plugin.functionName !== '')!.functionName
224+
);
225+
226+
genAiPlugins = castArray(parsedPlannerBundle.GenAiPlannerBundle.genAiPlugins).reduce(
227+
(acc, { genAiPluginName }) => ({
228+
...acc,
229+
[genAiPluginName]: cs.getComponentFilenamesByNameAndType({
230+
fullName: genAiPluginName,
231+
type: 'GenAiPlugin',
232+
})[0],
233+
}),
234+
{}
235+
);
236+
} catch (e) {
237+
throw new SfError(
238+
`Error parsing GenAiPlannerBundle: ${
239+
parsedBotVersion.BotVersion.conversationDefinitionPlanners.genAiPlannerName ?? subjectName
240+
}`
241+
);
242+
}
194243

195244
return { genAiPlugins, genAiFunctions };
196245
}
@@ -292,7 +341,7 @@ export default class AgentGenerateTestSpec extends SfCommand<void> {
292341

293342
const cs = await ComponentSetBuilder.build({
294343
metadata: {
295-
metadataEntries: ['GenAiPlanner', 'GenAiPlugin', 'Bot'],
344+
metadataEntries: ['GenAiPlannerBundle', 'GenAiPlugin', 'Bot'],
296345
directoryPaths,
297346
},
298347
});

yarn.lock

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,10 +1271,10 @@
12711271
"@jridgewell/resolve-uri" "^3.1.0"
12721272
"@jridgewell/sourcemap-codec" "^1.4.14"
12731273

1274-
"@jsforce/jsforce-node@^3.8.2":
1275-
version "3.8.2"
1276-
resolved "https://registry.yarnpkg.com/@jsforce/jsforce-node/-/jsforce-node-3.8.2.tgz#68b903f6733ae479086ab02ea4a2de87a7f208eb"
1277-
integrity sha512-ewaRr9JnZRW6I28C/TzUnv5p70zMrWsKCq2ovRW6X557/ikdfvA24F9k4cQXZnTG2lZLEfVn+WwdBGEtY7pPnQ==
1274+
"@jsforce/jsforce-node@^3.9.1":
1275+
version "3.9.1"
1276+
resolved "https://registry.yarnpkg.com/@jsforce/jsforce-node/-/jsforce-node-3.9.1.tgz#503bcee3b511b2768abb090b8c8af508c2412244"
1277+
integrity sha512-tHG9Wozb9tQMiOyKz4MgcSK0XEDdER+dUm42o7qUaokwqC+IPmjgptx0PNTO75U1nqgW6yX6M5Qq1thhj7KMCA==
12781278
dependencies:
12791279
"@sindresorhus/is" "^4"
12801280
base64url "^3.0.1"
@@ -1472,20 +1472,20 @@
14721472
strip-ansi "6.0.1"
14731473
ts-retry-promise "^0.8.1"
14741474

1475-
"@salesforce/core@^8.10.0", "@salesforce/core@^8.10.3", "@salesforce/core@^8.13.0", "@salesforce/core@^8.5.1", "@salesforce/core@^8.8.0", "@salesforce/core@^8.8.5":
1476-
version "8.13.0"
1477-
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-8.13.0.tgz#ffc00a776c60a401d4385abfeb6cd7fee0d90f3b"
1478-
integrity sha512-FyAn0UGa93D0N++8poeJt7yEaWQH++qxrv/Wf4TjNaUCLoh19g57lrXuos3qDJPr8Ut4x6QjVxEc49XLy+vBkw==
1475+
"@salesforce/core@^8.10.0", "@salesforce/core@^8.10.3", "@salesforce/core@^8.18.1", "@salesforce/core@^8.18.3", "@salesforce/core@^8.5.1", "@salesforce/core@^8.8.0", "@salesforce/core@^8.8.5":
1476+
version "8.18.3"
1477+
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-8.18.3.tgz#9ad84b5d64fbf6269cc508fcde5d8c8676a1c0fc"
1478+
integrity sha512-RWloPTkA6SGWgiwvXZkqQELEFjPZH2Rv7VAFqwucrZJDrsewaNFsktLdmLnTWnURghSBW+iff0+/z/z1vvUOiQ==
14791479
dependencies:
1480-
"@jsforce/jsforce-node" "^3.8.2"
1480+
"@jsforce/jsforce-node" "^3.9.1"
14811481
"@salesforce/kit" "^3.2.2"
14821482
"@salesforce/schemas" "^1.9.0"
14831483
"@salesforce/ts-types" "^2.0.10"
14841484
ajv "^8.17.1"
14851485
change-case "^4.1.2"
14861486
fast-levenshtein "^3.0.0"
14871487
faye "^1.4.0"
1488-
form-data "^4.0.0"
1488+
form-data "^4.0.4"
14891489
js2xmlparser "^4.0.1"
14901490
jsonwebtoken "9.0.2"
14911491
jszip "3.10.1"
@@ -1598,12 +1598,12 @@
15981598
cli-progress "^3.12.0"
15991599
terminal-link "^3.0.0"
16001600

1601-
"@salesforce/source-deploy-retrieve@^12.19.3", "@salesforce/source-deploy-retrieve@^12.19.5":
1602-
version "12.19.6"
1603-
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-12.19.6.tgz#0c208d2dfef6944e24afcea74ed05aa823e966aa"
1604-
integrity sha512-A/886Ht23G1snfyUj26pNDjaRWuMmiWIk5ckp+d9mdQjV8i45kPiOFJj5aHzAQ8071i/JgfnDYEhnk1voDujUA==
1601+
"@salesforce/source-deploy-retrieve@^12.19.5", "@salesforce/source-deploy-retrieve@^12.21.4":
1602+
version "12.21.4"
1603+
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-12.21.4.tgz#dee92e9ad1feb7863f713e3b959a51a998f19279"
1604+
integrity sha512-ree+qZKUglNb1a80msPUzf4xH84sRze/m62X/FL5kCuCp28qEW/1qh8fjlmCpNFqEp92uwNkM6qKJ/GKr/Mtrw==
16051605
dependencies:
1606-
"@salesforce/core" "^8.10.3"
1606+
"@salesforce/core" "^8.18.1"
16071607
"@salesforce/kit" "^3.2.3"
16081608
"@salesforce/ts-types" "^2.0.12"
16091609
"@salesforce/types" "^1.3.0"
@@ -4548,14 +4548,15 @@ form-data-encoder@^2.1.2:
45484548
resolved "https://registry.yarnpkg.com/form-data-encoder/-/form-data-encoder-2.1.4.tgz#261ea35d2a70d48d30ec7a9603130fa5515e9cd5"
45494549
integrity sha512-yDYSgNMraqvnxiEXO4hi88+YZxaHC6QKzb5N84iRCTDeRO7ZALpir/lVmf/uXUhnwUr2O4HU8s/n6x+yNjQkHw==
45504550

4551-
form-data@^4.0.0:
4552-
version "4.0.2"
4553-
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.2.tgz#35cabbdd30c3ce73deb2c42d3c8d3ed9ca51794c"
4554-
integrity sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==
4551+
form-data@^4.0.0, form-data@^4.0.4:
4552+
version "4.0.4"
4553+
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.4.tgz#784cdcce0669a9d68e94d11ac4eea98088edd2c4"
4554+
integrity sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==
45554555
dependencies:
45564556
asynckit "^0.4.0"
45574557
combined-stream "^1.0.8"
45584558
es-set-tostringtag "^2.1.0"
4559+
hasown "^2.0.2"
45594560
mime-types "^2.1.12"
45604561

45614562
fromentries@^1.2.0:

0 commit comments

Comments
 (0)