@salesforce/metadata-plugins 1.9.0 → 1.10.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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentParser.d.ts","sourceRoot":"","sources":["../../../src/plugins/agent/AgentParser.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAGhB,WAAW,EAGX,KAAK,cAAc,EACpB,MAAM,+BAA+B,CAAC;AAQvC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"AgentParser.d.ts","sourceRoot":"","sources":["../../../src/plugins/agent/AgentParser.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAGhB,WAAW,EAGX,KAAK,cAAc,EACpB,MAAM,+BAA+B,CAAC;AAQvC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAqF7D,qBAAa,WAAY,YAAW,eAAe,CAAC,eAAe,CAAC;IAClE,OAAO,CAAC,eAAe,CAAC,CAAmB;IAC3C,OAAO,CAAC,MAAM,CAAC,CAAU;IACzB,OAAO,CAAC,SAAS,CAAC,CAAa;IAE/B,kBAAkB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAM7C,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC;IA2IlF;;;;OAIG;IACH,mBAAmB,CAAC,IAAI,EAAE,eAAe,GAAG,gBAAgB,GAAG,IAAI;IAKnE;;;;OAIG;IACH,kBAAkB,CAAC,IAAI,EAAE,eAAe,GAAG,cAAc,EAAE;CAG5D"}
|
|
@@ -31,6 +31,19 @@ import { astToOverviewGraph } from './extract/ast-to-graph.js';
|
|
|
31
31
|
* blocks visualization — warnings/info/hints are non-fatal.
|
|
32
32
|
*/
|
|
33
33
|
const LSP_SEVERITY_ERROR = 1;
|
|
34
|
+
/**
|
|
35
|
+
* Rule codes that the AgentScript parser flags at severity=Error but which
|
|
36
|
+
* leave the AST intact and the graph renderable. We surface these as warnings
|
|
37
|
+
* rather than failing the parse. Everything not in this allowlist — including
|
|
38
|
+
* other `agentscript-lint` codes like `config-missing-agent-name` or the
|
|
39
|
+
* undefined-reference checks — stays fatal, because those indicate the script
|
|
40
|
+
* is genuinely broken even though the grammar accepted it.
|
|
41
|
+
*
|
|
42
|
+
* Keep this list narrow: only add a code after confirming (a) the parser
|
|
43
|
+
* still produces a usable AST when it fires, and (b) failing on it would
|
|
44
|
+
* regress users who upgrade the parser without changing their scripts.
|
|
45
|
+
*/
|
|
46
|
+
const NON_FATAL_DIAGNOSTIC_CODES = new Set(['config-missing-default-agent-user']);
|
|
34
47
|
/**
|
|
35
48
|
* Extract basename from a file path without importing Node's `path` module.
|
|
36
49
|
* Handles both `/` and `\` separators.
|
|
@@ -39,31 +52,51 @@ function basename(filePath) {
|
|
|
39
52
|
return filePath.split(/[\\/]/).pop() ?? filePath;
|
|
40
53
|
}
|
|
41
54
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* errors doesn't produce an unreadable wall of text.
|
|
55
|
+
* Coerce the parser's diagnostics into a plain array. The public type is
|
|
56
|
+
* `readonly Diagnostic[]`, but older parser builds and recovery paths have
|
|
57
|
+
* been observed to return `undefined` or an iterable, so we defend against
|
|
58
|
+
* both shapes.
|
|
47
59
|
*/
|
|
48
|
-
function
|
|
49
|
-
// The parser's public type is `readonly Diagnostic[]`, but defend against
|
|
50
|
-
// any shape — older parser builds and recovery paths have been observed
|
|
51
|
-
// to return `undefined` or an iterable. Coerce to a plain array first so
|
|
52
|
-
// the .filter below never blows up.
|
|
60
|
+
function toDiagnosticArray(diagnostics) {
|
|
53
61
|
const list = Array.isArray(diagnostics)
|
|
54
62
|
? diagnostics
|
|
55
63
|
: diagnostics && typeof diagnostics[Symbol.iterator] === 'function'
|
|
56
64
|
? Array.from(diagnostics)
|
|
57
65
|
: [];
|
|
58
|
-
|
|
66
|
+
return list.filter((d) => !!d && typeof d === 'object');
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A diagnostic is fatal (blocks visualization) if it is severity=Error and
|
|
70
|
+
* its `code` is not in the explicit non-fatal allowlist. We match by code
|
|
71
|
+
* (a stable kebab-case identifier) rather than by `source` suffix, because
|
|
72
|
+
* sources like `agentscript-lint` cover both benign rules and genuinely
|
|
73
|
+
* blocking config/reference errors (e.g. `config-missing-agent-name`,
|
|
74
|
+
* undefined `@variable`/`@action` references).
|
|
75
|
+
*/
|
|
76
|
+
function isFatalDiagnostic(d) {
|
|
77
|
+
if (d.severity !== LSP_SEVERITY_ERROR) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
const code = typeof d.code === 'string' ? d.code : '';
|
|
81
|
+
return !NON_FATAL_DIAGNOSTIC_CODES.has(code);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Format diagnostics into a single-line summary for the thrown error message.
|
|
85
|
+
* Each entry shows `Line L:C [code]` with 1-based positions (LSP positions are
|
|
86
|
+
* zero-based; humans read 1-based). Diagnostic `message` is intentionally
|
|
87
|
+
* omitted — parser messages routinely embed source excerpts (e.g.
|
|
88
|
+
* `Unrecognized syntax: <customer text>`), which is customer-authored content
|
|
89
|
+
* that must not flow into logs or telemetry. `code` is a fixed kebab-case
|
|
90
|
+
* identifier (`syntax-error`, `missing-token`, …) and is safe.
|
|
91
|
+
*/
|
|
92
|
+
function formatErrorSummary(errors) {
|
|
59
93
|
const MAX = 5;
|
|
60
94
|
const head = errors.slice(0, MAX).map((d) => {
|
|
61
95
|
const range = d.range;
|
|
62
96
|
const line = typeof range?.start?.line === 'number' ? range.start.line + 1 : 1;
|
|
63
97
|
const col = typeof range?.start?.character === 'number' ? range.start.character + 1 : 1;
|
|
64
98
|
const code = typeof d.code === 'string' ? ` [${d.code}]` : '';
|
|
65
|
-
|
|
66
|
-
return `Line ${line}:${col} — ${message}${code}`;
|
|
99
|
+
return `Line ${line}:${col}${code}`;
|
|
67
100
|
});
|
|
68
101
|
const overflow = errors.length > MAX ? ` (+${errors.length - MAX} more)` : '';
|
|
69
102
|
return head.join('; ') + overflow;
|
|
@@ -113,18 +146,16 @@ export class AgentParser {
|
|
|
113
146
|
}
|
|
114
147
|
span.setAttribute('sourceLength', String(source.length));
|
|
115
148
|
const doc = parse(source);
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
: 0;
|
|
127
|
-
telemetry.sendEvent('agent.parse_error', { pluginId: 'agent' }, { errorCount });
|
|
149
|
+
// Filter to fatal errors only. The 2.10.x parser adds new severity=
|
|
150
|
+
// Error lint rules (e.g. `config-missing-default-agent-user`) that
|
|
151
|
+
// fire on a successfully parsed AST; those are allowlisted in
|
|
152
|
+
// NON_FATAL_DIAGNOSTIC_CODES so users still see their graph. Any
|
|
153
|
+
// other severity=Error diagnostic — grammar failures, missing
|
|
154
|
+
// required config, undefined references — remains blocking.
|
|
155
|
+
const fatalErrors = toDiagnosticArray(doc.diagnostics).filter(isFatalDiagnostic);
|
|
156
|
+
if (fatalErrors.length > 0) {
|
|
157
|
+
const summary = formatErrorSummary(fatalErrors);
|
|
158
|
+
telemetry.sendEvent('agent.parse_error', { pluginId: 'agent' }, { errorCount: fatalErrors.length });
|
|
128
159
|
throw ErrorBuilder.create()
|
|
129
160
|
.category(ErrorCategory.Parsing)
|
|
130
161
|
.message(`Agent script has parse errors: ${summary}`)
|
|
@@ -170,11 +201,23 @@ export class AgentParser {
|
|
|
170
201
|
};
|
|
171
202
|
}
|
|
172
203
|
catch (error) {
|
|
173
|
-
|
|
204
|
+
// Plugin errors were built with sanitized content above — safe to
|
|
205
|
+
// re-throw and safe to log by category. Non-plugin errors may carry
|
|
206
|
+
// raw source excerpts in their `message`/`stack` (parser library
|
|
207
|
+
// throws are not under our control), so we log only a fixed string
|
|
208
|
+
// and the error's constructor name — no message, no stack, no cause.
|
|
174
209
|
if (isPluginError(error)) {
|
|
210
|
+
const category = error.category;
|
|
211
|
+
log.error(`Error parsing agent file (category=${category})`);
|
|
175
212
|
throw error;
|
|
176
213
|
}
|
|
177
|
-
|
|
214
|
+
const errorName = error instanceof Error ? error.constructor.name : 'unknown';
|
|
215
|
+
log.error(`Error parsing agent file (name=${errorName})`);
|
|
216
|
+
throw ErrorBuilder.create()
|
|
217
|
+
.category(ErrorCategory.Parsing)
|
|
218
|
+
.message('Agent script parsing failed')
|
|
219
|
+
.context({ fileName, errorName })
|
|
220
|
+
.build();
|
|
178
221
|
}
|
|
179
222
|
}, { pluginId: 'agent' });
|
|
180
223
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/metadata-plugins",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Visualizer implementations for Salesforce metadata",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -110,6 +110,6 @@
|
|
|
110
110
|
"test-exclude": ">=7.0.0"
|
|
111
111
|
},
|
|
112
112
|
"dependencies": {
|
|
113
|
-
"@sf-agentscript/agentforce": "2.
|
|
113
|
+
"@sf-agentscript/agentforce": "^2.10.38"
|
|
114
114
|
}
|
|
115
115
|
}
|