@salesforce/plugin-agent 1.36.1 → 1.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,227 +0,0 @@
1
- /*
2
- * Copyright 2026, Salesforce, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- /* eslint-disable camelcase */
17
- import { parse as parseYaml } from 'yaml';
18
- // --- JSONPath mappings from org model to Eval API refs ---
19
- const ACTUAL_PATH_MAP = {
20
- '$.generatedData.outcome': '{sm.response}',
21
- '$.generatedData.topic': '{gs.response.planner_response.lastExecution.topic}',
22
- '$.generatedData.invokedActions': '{gs.response.planner_response.lastExecution.invokedActions}',
23
- '$.generatedData.actionsSequence': '{gs.response.planner_response.lastExecution.invokedActions}',
24
- };
25
- // --- Custom evaluation name to evaluator type mapping ---
26
- const CUSTOM_EVAL_TYPE_MAP = {
27
- string_comparison: 'evaluator.string_assertion',
28
- numeric_comparison: 'evaluator.numeric_assertion',
29
- };
30
- // JSONPaths that require the get_state step
31
- const PLANNER_PATHS = new Set([
32
- '$.generatedData.topic',
33
- '$.generatedData.invokedActions',
34
- '$.generatedData.actionsSequence',
35
- ]);
36
- // --- Public API ---
37
- /**
38
- * Returns true if the content looks like a YAML TestSpec (has testCases + subjectName).
39
- * Returns false for JSON EvalPayload, invalid content, or YAML missing required fields.
40
- */
41
- export function isYamlTestSpec(content) {
42
- try {
43
- const parsed = parseYaml(content);
44
- if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
45
- return false;
46
- }
47
- const obj = parsed;
48
- return Array.isArray(obj.testCases) && typeof obj.subjectName === 'string';
49
- }
50
- catch {
51
- return false;
52
- }
53
- }
54
- /**
55
- * Parse a YAML string into a TestSpec.
56
- * Throws if the content is not valid YAML or is missing required fields.
57
- */
58
- export function parseTestSpec(content) {
59
- const parsed = parseYaml(content);
60
- if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
61
- throw new Error('Invalid TestSpec: expected a YAML object');
62
- }
63
- const obj = parsed;
64
- if (!Array.isArray(obj.testCases)) {
65
- throw new Error('Invalid TestSpec: missing testCases array');
66
- }
67
- if (typeof obj.subjectName !== 'string') {
68
- throw new Error('Invalid TestSpec: missing subjectName');
69
- }
70
- if (typeof obj.name !== 'string') {
71
- throw new Error('Invalid TestSpec: missing name');
72
- }
73
- return parsed;
74
- }
75
- /**
76
- * Translate a full TestSpec into an EvalPayload.
77
- */
78
- export function translateTestSpec(spec) {
79
- return {
80
- tests: spec.testCases.map((tc, idx) => translateTestCase(tc, idx, spec.name)),
81
- };
82
- }
83
- /**
84
- * Translate a single TestCase into an EvalTest with ordered steps.
85
- */
86
- export function translateTestCase(testCase, index, specName) {
87
- const id = specName ? `${specName}_case_${index}` : `test_case_${index}`;
88
- const steps = [];
89
- // 1. agent.create_session
90
- const createSessionStep = {
91
- type: 'agent.create_session',
92
- id: 'cs',
93
- use_agent_api: true,
94
- };
95
- if (testCase.contextVariables && testCase.contextVariables.length > 0) {
96
- // Validate for duplicate names
97
- const names = testCase.contextVariables.map((cv) => cv.name);
98
- const duplicates = names.filter((name, idx) => names.indexOf(name) !== idx);
99
- if (duplicates.length > 0) {
100
- throw new Error(`Duplicate contextVariable names found in test case ${index}: ${[...new Set(duplicates)].join(', ')}. Each contextVariable name must be unique.`);
101
- }
102
- createSessionStep.context_variables = Object.fromEntries(testCase.contextVariables.map((cv) => [cv.name, cv.value]));
103
- }
104
- steps.push(createSessionStep);
105
- // 2. Conversation history — only user messages become send_message steps
106
- let historyIdx = 0;
107
- if (testCase.conversationHistory) {
108
- for (const entry of testCase.conversationHistory) {
109
- if (entry.role === 'user') {
110
- steps.push({
111
- type: 'agent.send_message',
112
- id: `history_${historyIdx}`,
113
- session_id: '{cs.session_id}',
114
- utterance: entry.message,
115
- });
116
- historyIdx++;
117
- }
118
- }
119
- }
120
- // 3. Test utterance
121
- steps.push({
122
- type: 'agent.send_message',
123
- id: 'sm',
124
- session_id: '{cs.session_id}',
125
- utterance: testCase.utterance,
126
- });
127
- // 4. Determine if get_state is needed
128
- const needsGetState = needsPlannerState(testCase);
129
- if (needsGetState) {
130
- steps.push({
131
- type: 'agent.get_state',
132
- id: 'gs',
133
- session_id: '{cs.session_id}',
134
- });
135
- }
136
- // 5. Evaluators
137
- if (testCase.expectedTopic !== undefined) {
138
- steps.push({
139
- type: 'evaluator.planner_topic_assertion',
140
- id: 'check_topic',
141
- expected: testCase.expectedTopic,
142
- actual: '{gs.response.planner_response.lastExecution.topic}',
143
- operator: 'contains',
144
- });
145
- }
146
- if (testCase.expectedActions !== undefined && testCase.expectedActions.length > 0) {
147
- steps.push({
148
- type: 'evaluator.planner_actions_assertion',
149
- id: 'check_actions',
150
- expected: testCase.expectedActions,
151
- actual: '{gs.response.planner_response.lastExecution.invokedActions}',
152
- operator: 'includes_items',
153
- });
154
- }
155
- if (testCase.expectedOutcome !== undefined) {
156
- steps.push({
157
- type: 'evaluator.bot_response_rating',
158
- id: 'check_outcome',
159
- utterance: testCase.utterance,
160
- expected: testCase.expectedOutcome,
161
- actual: '{sm.response}',
162
- threshold: 3.0,
163
- });
164
- }
165
- if (testCase.customEvaluations) {
166
- testCase.customEvaluations.forEach((customEval, customIdx) => {
167
- const step = translateCustomEvaluation(customEval, customIdx);
168
- steps.push(step);
169
- });
170
- }
171
- return { id, steps };
172
- }
173
- // --- Internal helpers ---
174
- /**
175
- * Determine whether the get_state step is needed for this test case.
176
- */
177
- function needsPlannerState(testCase) {
178
- if (testCase.expectedTopic !== undefined)
179
- return true;
180
- if (testCase.expectedActions !== undefined && testCase.expectedActions.length > 0)
181
- return true;
182
- if (testCase.customEvaluations) {
183
- for (const customEval of testCase.customEvaluations) {
184
- for (const param of customEval.parameters) {
185
- if (param.name === 'actual' && PLANNER_PATHS.has(param.value)) {
186
- return true;
187
- }
188
- }
189
- }
190
- }
191
- return false;
192
- }
193
- /**
194
- * Translate a single customEvaluation entry into an EvalStep.
195
- */
196
- function translateCustomEvaluation(customEval, index) {
197
- const evalType = CUSTOM_EVAL_TYPE_MAP[customEval.name] ?? `evaluator.${customEval.name}`;
198
- let operator = '';
199
- let actual = '';
200
- let expected = '';
201
- for (const param of customEval.parameters) {
202
- if (param.name === 'operator') {
203
- operator = param.value;
204
- }
205
- else if (param.name === 'actual') {
206
- actual = mapActualPath(param.value);
207
- }
208
- else if (param.name === 'expected') {
209
- expected = param.value;
210
- }
211
- }
212
- return {
213
- type: evalType,
214
- id: `custom_${index}`,
215
- operator,
216
- actual,
217
- expected,
218
- };
219
- }
220
- /**
221
- * Map an org-model JSONPath to the Eval API shorthand ref.
222
- * Unknown paths are returned as-is.
223
- */
224
- function mapActualPath(path) {
225
- return ACTUAL_PATH_MAP[path] ?? path;
226
- }
227
- //# sourceMappingURL=yamlSpecTranslator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"yamlSpecTranslator.js","sourceRoot":"","sources":["../src/yamlSpecTranslator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,8BAA8B;AAE9B,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAI1C,4DAA4D;AAE5D,MAAM,eAAe,GAA2B;IAC9C,yBAAyB,EAAE,eAAe;IAC1C,uBAAuB,EAAE,oDAAoD;IAC7E,gCAAgC,EAAE,6DAA6D;IAC/F,iCAAiC,EAAE,6DAA6D;CACjG,CAAC;AAEF,2DAA2D;AAE3D,MAAM,oBAAoB,GAA2B;IACnD,iBAAiB,EAAE,4BAA4B;IAC/C,kBAAkB,EAAE,6BAA6B;CAClD,CAA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