@salesforce/metadata-plugins 1.3.0 → 1.4.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.
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/plugins/agent/AgentParser.d.ts +34 -0
- package/dist/plugins/agent/AgentParser.d.ts.map +1 -0
- package/dist/plugins/agent/AgentParser.js +189 -0
- package/dist/plugins/agent/AgentVisualizer.d.ts +27 -0
- package/dist/plugins/agent/AgentVisualizer.d.ts.map +1 -0
- package/dist/plugins/agent/AgentVisualizer.js +36 -0
- package/dist/plugins/agent/extract/assertNever.d.ts +23 -0
- package/dist/plugins/agent/extract/assertNever.d.ts.map +1 -0
- package/dist/plugins/agent/extract/assertNever.js +24 -0
- package/dist/plugins/agent/extract/ast-to-graph.d.ts +137 -0
- package/dist/plugins/agent/extract/ast-to-graph.d.ts.map +1 -0
- package/dist/plugins/agent/extract/ast-to-graph.js +523 -0
- package/dist/plugins/agent/extract/ast-utils.d.ts +61 -0
- package/dist/plugins/agent/extract/ast-utils.d.ts.map +1 -0
- package/dist/plugins/agent/extract/ast-utils.js +7 -0
- package/dist/plugins/agent/extract/parseNamespacedRef.d.ts +31 -0
- package/dist/plugins/agent/extract/parseNamespacedRef.d.ts.map +1 -0
- package/dist/plugins/agent/extract/parseNamespacedRef.js +31 -0
- package/dist/plugins/agent/extract/reasoningParser.d.ts +112 -0
- package/dist/plugins/agent/extract/reasoningParser.d.ts.map +1 -0
- package/dist/plugins/agent/extract/reasoningParser.js +804 -0
- package/dist/plugins/agent/types/AgentScriptData.d.ts +31 -0
- package/dist/plugins/agent/types/AgentScriptData.d.ts.map +1 -0
- package/dist/plugins/agent/types/AgentScriptData.js +7 -0
- package/dist/plugins/agent/ui/assets/index-CTzSDPPx.css +1 -0
- package/dist/plugins/agent/ui/assets/index-D0wb9GBs.js +71 -0
- package/dist/plugins/agent/ui/index.html +14 -0
- package/dist/plugins/flexipage/FlexipageParser.d.ts +1 -1
- package/dist/plugins/flexipage/FlexipageParser.js +1 -1
- package/dist/plugins/flexipage/FlexipageVisualizer.d.ts +1 -1
- package/dist/plugins/flexipage/FlexipageVisualizer.js +1 -1
- package/dist/plugins/flexipage/transformer/FlexipageToUemTransformer.d.ts +1 -1
- package/dist/plugins/flexipage/transformer/FlexipageToUemTransformer.js +1 -1
- package/dist/plugins/flexipage/transformer/FlexipageTransformerUtils.d.ts +1 -1
- package/dist/plugins/flexipage/transformer/FlexipageTransformerUtils.js +1 -1
- package/dist/plugins/flexipage/types/FlexipageMetadata.d.ts +1 -1
- package/dist/plugins/flexipage/types/FlexipageMetadata.js +1 -1
- package/dist/plugins/schema/SchemaParser.d.ts +1 -1
- package/dist/plugins/schema/SchemaParser.js +1 -1
- package/dist/plugins/schema/SchemaVisualizer.d.ts +1 -1
- package/dist/plugins/schema/SchemaVisualizer.js +1 -1
- package/dist/plugins/schema/types/SchemaERDData.d.ts +1 -1
- package/dist/plugins/schema/types/SchemaERDData.js +1 -1
- package/dist/shared/bootstrap/createPluginApp.d.ts +1 -1
- package/dist/shared/bootstrap/createPluginApp.js +1 -1
- package/dist/shared/components/ErrorBoundary.d.ts +1 -1
- package/dist/shared/components/ErrorBoundary.js +1 -1
- package/dist/shared/uem/transformer/ITransformer.d.ts +1 -1
- package/dist/shared/uem/transformer/ITransformer.js +1 -1
- package/dist/shared/uem/transformer/TransformerRegistry.d.ts +1 -1
- package/dist/shared/uem/transformer/TransformerRegistry.js +1 -1
- package/dist/shared/uem/transformer/UemBasedVisualizer.d.ts +1 -1
- package/dist/shared/uem/transformer/UemBasedVisualizer.js +1 -1
- package/dist/shared/uem/types/UemMetadata.d.ts +1 -1
- package/dist/shared/uem/types/UemMetadata.js +1 -1
- package/dist/shared/uem/ui/components/PropertyRenderer/PropertyRenderer.d.ts +1 -1
- package/dist/shared/uem/ui/components/PropertyRenderer/PropertyRenderer.js +1 -1
- package/dist/shared/uem/ui/components/UEMVisualization/UEMVisualization.d.ts +1 -1
- package/dist/shared/uem/ui/components/UEMVisualization/UEMVisualization.js +1 -1
- package/dist/shared/utils/isPluginError.d.ts +1 -1
- package/dist/shared/utils/isPluginError.js +1 -1
- package/dist/shared/utils/patternMatcher.d.ts +1 -1
- package/dist/shared/utils/patternMatcher.js +1 -1
- package/dist/shared/utils/uemTreeUtils.d.ts +1 -1
- package/dist/shared/utils/uemTreeUtils.js +1 -1
- package/dist/shared/utils/vizDependentPathsHelper.d.ts +1 -1
- package/dist/shared/utils/vizDependentPathsHelper.js +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* Licensed under the BSD 3-Clause license.
|
|
5
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
**/
|
|
7
|
+
function isNamedMapLike(value) {
|
|
8
|
+
if (!value || typeof value !== 'object') {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const v = value;
|
|
12
|
+
return (typeof v.keys === 'function' &&
|
|
13
|
+
typeof v.has === 'function' &&
|
|
14
|
+
typeof v[Symbol.iterator] === 'function');
|
|
15
|
+
}
|
|
16
|
+
function readStringField(block, key) {
|
|
17
|
+
if (!block) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const field = block[key];
|
|
21
|
+
if (!field || typeof field !== 'object') {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const value = field.value;
|
|
25
|
+
if (typeof value === 'string') {
|
|
26
|
+
return value.trim();
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
function readBlockDescription(block) {
|
|
31
|
+
return readStringField(block, 'description');
|
|
32
|
+
}
|
|
33
|
+
function readBlockLabel(block, fallback) {
|
|
34
|
+
const label = readStringField(block, 'label');
|
|
35
|
+
return label && label.length > 0 ? label : fallback;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Count entries in the `actions` collection on a subagent block. Handles the
|
|
39
|
+
* parser's named-collection node as well as array / plain-object shapes (the
|
|
40
|
+
* latter come from test fixtures).
|
|
41
|
+
*/
|
|
42
|
+
function readActionsCount(block) {
|
|
43
|
+
const countOf = (actions) => {
|
|
44
|
+
if (!actions || typeof actions !== 'object') {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
if (isNamedMapLike(actions)) {
|
|
48
|
+
return Array.from(actions).length;
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(actions)) {
|
|
51
|
+
return actions.length;
|
|
52
|
+
}
|
|
53
|
+
const keys = Object.keys(actions).filter((k) => !k.startsWith('__'));
|
|
54
|
+
return keys.length > 0 ? keys.length : undefined;
|
|
55
|
+
};
|
|
56
|
+
// Count only the subagent's own top-level `actions:` block — the same source
|
|
57
|
+
// the detail panel's ACTIONS card renders from.
|
|
58
|
+
return countOf(block.actions);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Read a typed param node (the per-entry value inside `inputs:` / `outputs:`).
|
|
62
|
+
* Handles three AST shapes the parser may emit:
|
|
63
|
+
* - `Identifier` (e.g. `string`) → `{ __kind: 'Identifier', name: 'string' }`
|
|
64
|
+
* - `SubscriptExpression` (`list[string]`) → `{ __kind: 'SubscriptExpression', object, index }`
|
|
65
|
+
* - `MemberExpression` (`a.b`) → `{ __kind: 'MemberExpression', object, property }`
|
|
66
|
+
* Legacy `{ value: 'string' }` shape is still accepted.
|
|
67
|
+
*/
|
|
68
|
+
function readParamType(entry) {
|
|
69
|
+
const t = entry?.type;
|
|
70
|
+
const text = stringifyTypeNode(t);
|
|
71
|
+
return text && text.length ? text : undefined;
|
|
72
|
+
}
|
|
73
|
+
function stringifyTypeNode(node) {
|
|
74
|
+
if (node === null || node === undefined) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
if (typeof node === 'string') {
|
|
78
|
+
return node.trim() || undefined;
|
|
79
|
+
}
|
|
80
|
+
if (typeof node !== 'object') {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const n = node;
|
|
84
|
+
if (n.__kind === 'SubscriptExpression') {
|
|
85
|
+
const obj = stringifyTypeNode(n.object) ?? '';
|
|
86
|
+
const idx = stringifyTypeNode(n.index) ?? '';
|
|
87
|
+
return `${obj}[${idx}]`;
|
|
88
|
+
}
|
|
89
|
+
if (n.__kind === 'MemberExpression') {
|
|
90
|
+
const obj = stringifyTypeNode(n.object) ?? '';
|
|
91
|
+
const prop = stringifyTypeNode(n.property) ?? '';
|
|
92
|
+
return prop ? `${obj}.${prop}` : obj;
|
|
93
|
+
}
|
|
94
|
+
if (typeof n.name === 'string' && n.name.trim()) {
|
|
95
|
+
return n.name.trim();
|
|
96
|
+
}
|
|
97
|
+
if (typeof n.value === 'string' && n.value.trim()) {
|
|
98
|
+
return n.value.trim();
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
function readParams(collection) {
|
|
103
|
+
if (!isNamedMapLike(collection)) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
const out = [];
|
|
107
|
+
for (const [name, entry] of collection) {
|
|
108
|
+
out.push({
|
|
109
|
+
name: String(name),
|
|
110
|
+
type: readParamType(entry),
|
|
111
|
+
label: readStringField(entry, 'label'),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Pull every action declared on a `NamedMap` (a subagent's top-level
|
|
118
|
+
* `actions:`, or a `reasoning.actions:` sub-block) into a plain array. The
|
|
119
|
+
* parser preserves source order via its `NamedMap` iterator.
|
|
120
|
+
*/
|
|
121
|
+
function readActionDetails(actions) {
|
|
122
|
+
if (!isNamedMapLike(actions)) {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
const out = [];
|
|
126
|
+
for (const [name, entry] of actions) {
|
|
127
|
+
out.push({
|
|
128
|
+
name: String(name),
|
|
129
|
+
label: readStringField(entry, 'label'),
|
|
130
|
+
description: readStringField(entry, 'description'),
|
|
131
|
+
target: readStringField(entry, 'target') ?? readShorthandTarget(entry),
|
|
132
|
+
inputs: readParams(entry.inputs),
|
|
133
|
+
outputs: readParams(entry.outputs),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Read the shorthand "header target" form `action_name: @utils.X` (and
|
|
140
|
+
* `: @actions.X`) where the action's value appears on the same line as its
|
|
141
|
+
* key rather than as a child `target:` field. The parser surfaces this on
|
|
142
|
+
* the action's parent `mapping_element` CST node as a sibling child of type
|
|
143
|
+
* `expression_with_to` whose text is the `@...` token.
|
|
144
|
+
*/
|
|
145
|
+
function readShorthandTarget(entry) {
|
|
146
|
+
const cst = entry.__cst;
|
|
147
|
+
const node = cst?.node;
|
|
148
|
+
const parent = node?.parent;
|
|
149
|
+
const children = parent?.children;
|
|
150
|
+
if (!Array.isArray(children)) {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
for (const c of children) {
|
|
154
|
+
if (c && typeof c === 'object') {
|
|
155
|
+
const ch = c;
|
|
156
|
+
if (ch.type === 'expression_with_to' && typeof ch.text === 'string') {
|
|
157
|
+
const text = ch.text.trim();
|
|
158
|
+
return text.length > 0 ? text : undefined;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Pull the reasoning block's instructions text + referenced action names.
|
|
166
|
+
*
|
|
167
|
+
* Instructions are stored as a YAML template (`instructions.statements[]`
|
|
168
|
+
* with `.parts[]` text fragments) when written as a `|`-block, or as a
|
|
169
|
+
* plain `{ value: string }` leaf when written inline.
|
|
170
|
+
*
|
|
171
|
+
* The parser flattens `|`-block text and strips indentation, so when source
|
|
172
|
+
* lines are available we re-slice them from the original document using
|
|
173
|
+
* the CST range. The reasoning UI depends on indentation to detect nested
|
|
174
|
+
* `If` bodies, so without this rebuild every block ends up at depth zero.
|
|
175
|
+
*/
|
|
176
|
+
function readReasoning(block, sourceLines) {
|
|
177
|
+
const reasoning = block.reasoning;
|
|
178
|
+
if (!reasoning) {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
const instructions = readInstructions(reasoning.instructions, sourceLines);
|
|
182
|
+
const actions = readActionDetails(reasoning.actions);
|
|
183
|
+
const actionRefs = actions.map((a) => a.name);
|
|
184
|
+
if (!instructions && actionRefs.length === 0) {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
return { instructions, actionRefs, actions };
|
|
188
|
+
}
|
|
189
|
+
function readCstRange(node) {
|
|
190
|
+
if (!node || typeof node !== 'object') {
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
const cst = node.__cst;
|
|
194
|
+
const range = cst?.range;
|
|
195
|
+
if (!range?.start || !range.end) {
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
if (typeof range.start.line !== 'number' ||
|
|
199
|
+
typeof range.start.character !== 'number' ||
|
|
200
|
+
typeof range.end.line !== 'number' ||
|
|
201
|
+
typeof range.end.character !== 'number') {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
return range;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Re-slice an instructions block's contents directly out of the source.
|
|
208
|
+
*
|
|
209
|
+
* Two source forms feed this:
|
|
210
|
+
* - `instructions: |` — the CST range covers the `instructions: |` keyword
|
|
211
|
+
* line through the final content line, so the body starts at
|
|
212
|
+
* `start.line + 1`.
|
|
213
|
+
* - `instructions: ->` — the CST range starts at the first *statement*
|
|
214
|
+
* line (the keyword line sits one row above), so the body starts at
|
|
215
|
+
* `start.line`.
|
|
216
|
+
*
|
|
217
|
+
* We disambiguate by looking at the first line of the range: if it matches
|
|
218
|
+
* the `instructions:` keyword header, skip it; otherwise include it.
|
|
219
|
+
*
|
|
220
|
+
* We strip the common leading indent (the block's base column) and join
|
|
221
|
+
* with `\n` so downstream parsers see the original layout.
|
|
222
|
+
*/
|
|
223
|
+
function rebuildInstructionsFromSource(field, sourceLines) {
|
|
224
|
+
const range = readCstRange(field);
|
|
225
|
+
if (!range || range.end.line < range.start.line) {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
const firstLine = sourceLines[range.start.line] ?? '';
|
|
229
|
+
// Any `<key>:` line — the CST range for a `|`-block field points at the
|
|
230
|
+
// key line itself, so drop it whether we're reading `instructions:`,
|
|
231
|
+
// `welcome:`, `error:`, or any other block-scalar field.
|
|
232
|
+
const startsOnKeywordLine = /^\s*[A-Za-z_][A-Za-z0-9_]*\s*:/.test(firstLine);
|
|
233
|
+
const sliceStart = startsOnKeywordLine ? range.start.line + 1 : range.start.line;
|
|
234
|
+
const slice = sourceLines.slice(sliceStart, range.end.line + 1);
|
|
235
|
+
if (slice.length === 0) {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
// Trim the last line at the end character — for a `|`-block this is the
|
|
239
|
+
// final non-whitespace column, so trailing whitespace is already absent.
|
|
240
|
+
// Compute the base indent BEFORE trimming the last line so we don't drop
|
|
241
|
+
// characters when range.end.character < baseIndent.
|
|
242
|
+
const lastIdx = slice.length - 1;
|
|
243
|
+
const indents = slice
|
|
244
|
+
.filter((l) => l.trim().length > 0)
|
|
245
|
+
.map((l) => l.match(/^ */)?.[0].length ?? 0);
|
|
246
|
+
const baseIndent = indents.length > 0 ? indents.reduce((a, b) => (a < b ? a : b)) : 0;
|
|
247
|
+
slice[lastIdx] = slice[lastIdx].slice(0, range.end.character);
|
|
248
|
+
// Strip at most `baseIndent` leading spaces, but never past the line's own
|
|
249
|
+
// leading whitespace — a line shorter than baseIndent keeps its content.
|
|
250
|
+
const dedented = slice
|
|
251
|
+
.map((l) => {
|
|
252
|
+
const leading = l.match(/^ */)?.[0].length ?? 0;
|
|
253
|
+
return l.slice(Math.min(leading, baseIndent));
|
|
254
|
+
})
|
|
255
|
+
.join('\n');
|
|
256
|
+
// Drop a stray YAML block-scalar indicator (`|`, `>`, `|-`, `|+`, `->`) that
|
|
257
|
+
// sometimes leaks through as the first line of the rebuilt instructions.
|
|
258
|
+
const withoutLeadingIndicator = dedented.replace(/^\s*(?:\|[+-]?|>[+-]?|->)\s*\n/, '');
|
|
259
|
+
// Agentscript prose commonly uses `| ` as a per-line prefix carried over
|
|
260
|
+
// from YAML literal blocks. Strip a leading `|` (with optional trailing
|
|
261
|
+
// space/tab) on every line — the marker is purely stylistic and has no
|
|
262
|
+
// place in the rendered instructions.
|
|
263
|
+
const finalText = stripLeadingLinePipe(withoutLeadingIndicator).replace(/\s+$/, '');
|
|
264
|
+
return finalText.length > 0 ? finalText : undefined;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Strip a leading `|` (with optional trailing space/tab) from every line.
|
|
268
|
+
* `|` carries no semantic meaning inside the rebuilt instructions; it is a
|
|
269
|
+
* YAML-block stylistic carryover that should not surface in the UI.
|
|
270
|
+
*/
|
|
271
|
+
function stripLeadingLinePipe(text) {
|
|
272
|
+
return text
|
|
273
|
+
.split('\n')
|
|
274
|
+
.map((l) => l.replace(/^(\s*)\|[ \t]?/, '$1'))
|
|
275
|
+
.join('\n');
|
|
276
|
+
}
|
|
277
|
+
function readInstructions(field, sourceLines) {
|
|
278
|
+
if (!field || typeof field !== 'object') {
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
const direct = field.value;
|
|
282
|
+
if (typeof direct === 'string') {
|
|
283
|
+
const trimmed = direct.trim();
|
|
284
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
285
|
+
}
|
|
286
|
+
// Preferred path: pull indented content back from the source.
|
|
287
|
+
if (sourceLines && sourceLines.length > 0) {
|
|
288
|
+
const rebuilt = rebuildInstructionsFromSource(field, sourceLines);
|
|
289
|
+
if (rebuilt) {
|
|
290
|
+
return rebuilt;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
// Fallback (no source available, or CST range missing): flatten the
|
|
294
|
+
// template fragments. Indentation is lost — the renderer's structural
|
|
295
|
+
// parser still recognizes top-level `If` / headers / lists, but nested
|
|
296
|
+
// bodies collapse to siblings.
|
|
297
|
+
//
|
|
298
|
+
// The parser can emit two shapes here: a `ProcedureValue` wrapping
|
|
299
|
+
// `statements[].parts[]` (older/nested contexts), or a flat `Template`
|
|
300
|
+
// that exposes `parts[]` directly (the shape used for
|
|
301
|
+
// `reasoning.instructions` in this dialect). Handle both.
|
|
302
|
+
const f = field;
|
|
303
|
+
const partsArrays = [];
|
|
304
|
+
if (Array.isArray(f.parts)) {
|
|
305
|
+
partsArrays.push(f.parts);
|
|
306
|
+
}
|
|
307
|
+
else if (Array.isArray(f.statements)) {
|
|
308
|
+
for (const stmt of f.statements) {
|
|
309
|
+
if (stmt && typeof stmt === 'object') {
|
|
310
|
+
const parts = stmt.parts;
|
|
311
|
+
if (Array.isArray(parts)) {
|
|
312
|
+
partsArrays.push(parts);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
return undefined;
|
|
319
|
+
}
|
|
320
|
+
const fragments = [];
|
|
321
|
+
for (const parts of partsArrays) {
|
|
322
|
+
for (const part of parts) {
|
|
323
|
+
const value = part.value;
|
|
324
|
+
if (typeof value === 'string') {
|
|
325
|
+
fragments.push(value);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const joined = fragments.join('').trim();
|
|
330
|
+
return joined.length > 0 ? joined : undefined;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Read declared top-level variable types from `variables:`. Each entry may
|
|
334
|
+
* be a typed-declaration block or a leaf with a type string; we accept any
|
|
335
|
+
* shape that yields a string identifier (`string`, `number`, `boolean`,
|
|
336
|
+
* `list[object]`, etc.).
|
|
337
|
+
*/
|
|
338
|
+
function readVariableTypes(ast) {
|
|
339
|
+
const variables = ast.variables;
|
|
340
|
+
if (!isNamedMapLike(variables)) {
|
|
341
|
+
return undefined;
|
|
342
|
+
}
|
|
343
|
+
// Prototype-safe map: variable names come from user input and could
|
|
344
|
+
// collide with `__proto__`, `constructor`, etc. — a plain object literal
|
|
345
|
+
// would expose those slots and risk prototype pollution downstream.
|
|
346
|
+
const out = Object.create(null);
|
|
347
|
+
for (const [name, entry] of variables) {
|
|
348
|
+
const t = readParamType(entry);
|
|
349
|
+
if (t) {
|
|
350
|
+
out[String(name)] = t;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Read a `messages.<key>` field. Handles both plain string leaves
|
|
357
|
+
* (`welcome: "Hi"`) and `|`-block Template values (`welcome: |\n Hi …`).
|
|
358
|
+
* For templates, delegates to `readInstructions` so multi-line YAML blocks
|
|
359
|
+
* are rebuilt from the source with indentation preserved.
|
|
360
|
+
*/
|
|
361
|
+
function readMessage(block, key, sourceLines) {
|
|
362
|
+
const direct = readStringField(block, key);
|
|
363
|
+
if (direct !== undefined) {
|
|
364
|
+
return direct;
|
|
365
|
+
}
|
|
366
|
+
const field = block?.[key];
|
|
367
|
+
if (field && typeof field === 'object') {
|
|
368
|
+
return readInstructions(field, sourceLines);
|
|
369
|
+
}
|
|
370
|
+
return undefined;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Read the top-level `system:` block. The `instructions` field is a
|
|
374
|
+
* `|`-template (same flattening problem as reasoning.instructions) so we go
|
|
375
|
+
* through `readInstructions` to recover indentation from the source when
|
|
376
|
+
* available. `messages.welcome` and `messages.error` are plain string leaves.
|
|
377
|
+
*/
|
|
378
|
+
function readSystemBlock(ast, sourceLines) {
|
|
379
|
+
const system = ast.system;
|
|
380
|
+
if (!system || typeof system !== 'object') {
|
|
381
|
+
return {};
|
|
382
|
+
}
|
|
383
|
+
const systemInstructions = readInstructions(system.instructions, sourceLines);
|
|
384
|
+
const messages = system.messages;
|
|
385
|
+
const welcomeMessage = readMessage(messages, 'welcome', sourceLines);
|
|
386
|
+
const errorMessage = readMessage(messages, 'error', sourceLines);
|
|
387
|
+
return { systemInstructions, welcomeMessage, errorMessage };
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Pull header fields for the meta box from the `config:` block.
|
|
391
|
+
* - title ← agent_label (else agent_name, else developer_name, else file basename)
|
|
392
|
+
* - description ← description
|
|
393
|
+
*
|
|
394
|
+
* (`agent_type` was previously surfaced as a subtitle but the meta node now
|
|
395
|
+
* always renders the static "Agent" label, so it isn't read here.)
|
|
396
|
+
*/
|
|
397
|
+
function readMetaHeader(ast, fallback) {
|
|
398
|
+
const { config } = ast;
|
|
399
|
+
if (!config) {
|
|
400
|
+
return { label: fallback };
|
|
401
|
+
}
|
|
402
|
+
const agentLabel = readStringField(config, 'agent_label');
|
|
403
|
+
const agentName = readStringField(config, 'agent_name');
|
|
404
|
+
const developerName = readStringField(config, 'developer_name');
|
|
405
|
+
const description = readStringField(config, 'description');
|
|
406
|
+
return {
|
|
407
|
+
label: agentLabel ?? agentName ?? developerName ?? fallback,
|
|
408
|
+
description,
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Build the high-level overview graph: meta → start_agent → subagents.
|
|
413
|
+
*
|
|
414
|
+
* `source` is the original `.agent` text. When provided, we use it to
|
|
415
|
+
* re-derive indentation for `|`-block reasoning instructions — the parser
|
|
416
|
+
* flattens those to column zero, which breaks the indentation-sensitive
|
|
417
|
+
* reasoning UI. The graph builder works without it; downstream renderers
|
|
418
|
+
* just see un-nested instruction lines.
|
|
419
|
+
*/
|
|
420
|
+
export function astToOverviewGraph(ast, source) {
|
|
421
|
+
const nodes = [];
|
|
422
|
+
const edges = [];
|
|
423
|
+
const sourceLines = typeof source === 'string' ? source.split(/\r?\n/) : undefined;
|
|
424
|
+
const fileLabel = typeof ast.__sourceName === 'string' ? ast.__sourceName : 'Agent';
|
|
425
|
+
const header = readMetaHeader(ast, fileLabel);
|
|
426
|
+
const systemBlock = readSystemBlock(ast, sourceLines);
|
|
427
|
+
const variableTypes = readVariableTypes(ast);
|
|
428
|
+
const metaId = 'meta';
|
|
429
|
+
const metaNode = {
|
|
430
|
+
id: metaId,
|
|
431
|
+
type: 'meta',
|
|
432
|
+
position: { x: 0, y: 0 },
|
|
433
|
+
data: {
|
|
434
|
+
nodeType: 'meta',
|
|
435
|
+
label: header.label,
|
|
436
|
+
description: header.description,
|
|
437
|
+
systemInstructions: systemBlock.systemInstructions,
|
|
438
|
+
welcomeMessage: systemBlock.welcomeMessage,
|
|
439
|
+
errorMessage: systemBlock.errorMessage,
|
|
440
|
+
},
|
|
441
|
+
};
|
|
442
|
+
nodes.push(metaNode);
|
|
443
|
+
// Start agent — pick the first entry. The `start_agent` keyword is unchanged
|
|
444
|
+
// across API versions (unlike `topic` → `subagent`, it was never renamed).
|
|
445
|
+
let startNodeId;
|
|
446
|
+
if (isNamedMapLike(ast.start_agent)) {
|
|
447
|
+
const first = ast.start_agent.keys().next();
|
|
448
|
+
if (!first.done) {
|
|
449
|
+
const name = first.value;
|
|
450
|
+
const block = ast.start_agent.get(name);
|
|
451
|
+
const id = `start-agent-${name}`;
|
|
452
|
+
const startNode = {
|
|
453
|
+
id,
|
|
454
|
+
type: 'start-agent',
|
|
455
|
+
position: { x: 0, y: 0 },
|
|
456
|
+
data: {
|
|
457
|
+
nodeType: 'start-agent',
|
|
458
|
+
label: readBlockLabel(block, String(name)),
|
|
459
|
+
subtitle: String(name),
|
|
460
|
+
description: readBlockDescription(block),
|
|
461
|
+
sourceKeyword: 'start_agent',
|
|
462
|
+
},
|
|
463
|
+
};
|
|
464
|
+
nodes.push(startNode);
|
|
465
|
+
edges.push({
|
|
466
|
+
id: `e-${metaId}-${id}`,
|
|
467
|
+
source: metaId,
|
|
468
|
+
target: id,
|
|
469
|
+
type: 'default',
|
|
470
|
+
});
|
|
471
|
+
startNodeId = id;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
// Subagents fan out from the start node (or meta if none). v66 scripts use
|
|
475
|
+
// the `subagent` key; deprecated v65 scripts use `topic`. They are distinct
|
|
476
|
+
// top-level collections, so the source keyword is whichever key the block
|
|
477
|
+
// came from. A script could mix both during migration — render all of them.
|
|
478
|
+
const fanSource = startNodeId ?? metaId;
|
|
479
|
+
const subagentSources = [
|
|
480
|
+
{ collection: ast.subagent, keyword: 'subagent' },
|
|
481
|
+
{ collection: ast.topic, keyword: 'topic' },
|
|
482
|
+
];
|
|
483
|
+
for (const { collection, keyword } of subagentSources) {
|
|
484
|
+
if (!isNamedMapLike(collection)) {
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
for (const [name, block] of collection) {
|
|
488
|
+
const id = `subagent-${name}`;
|
|
489
|
+
const subagentSystem = block.system;
|
|
490
|
+
const systemInstructions = subagentSystem
|
|
491
|
+
? readInstructions(subagentSystem.instructions, sourceLines)
|
|
492
|
+
: undefined;
|
|
493
|
+
const beforeReasoning = readInstructions(block.before_reasoning, sourceLines);
|
|
494
|
+
const afterReasoning = readInstructions(block.after_reasoning, sourceLines);
|
|
495
|
+
const subNode = {
|
|
496
|
+
id,
|
|
497
|
+
type: 'subagent',
|
|
498
|
+
position: { x: 0, y: 0 },
|
|
499
|
+
data: {
|
|
500
|
+
nodeType: 'subagent',
|
|
501
|
+
label: readBlockLabel(block, String(name)),
|
|
502
|
+
description: readBlockDescription(block),
|
|
503
|
+
actionsCount: readActionsCount(block),
|
|
504
|
+
sourceKeyword: keyword,
|
|
505
|
+
systemInstructions,
|
|
506
|
+
beforeReasoning,
|
|
507
|
+
afterReasoning,
|
|
508
|
+
reasoning: readReasoning(block, sourceLines),
|
|
509
|
+
actions: readActionDetails(block.actions),
|
|
510
|
+
variableTypes,
|
|
511
|
+
},
|
|
512
|
+
};
|
|
513
|
+
nodes.push(subNode);
|
|
514
|
+
edges.push({
|
|
515
|
+
id: `e-${fanSource}-${id}`,
|
|
516
|
+
source: fanSource,
|
|
517
|
+
target: id,
|
|
518
|
+
type: 'default',
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return { nodes, edges };
|
|
523
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* Licensed under the BSD 3-Clause license.
|
|
5
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
**/
|
|
7
|
+
/**
|
|
8
|
+
* Structural type for the parsed `.agent` AST (the `ast` of the `Document`
|
|
9
|
+
* returned by `@sf-agentscript/agentforce`'s `parse`). We use a loose shape
|
|
10
|
+
* here rather than the package's deeply-generic, schema-inferred AST type
|
|
11
|
+
* because the visualizer only reads a handful of well-known top-level keys
|
|
12
|
+
* by duck-typing, and coupling to the full inferred type would be brittle
|
|
13
|
+
* without buying us anything.
|
|
14
|
+
*
|
|
15
|
+
* Each top-level key is typed as `AstBlock | undefined` so consumers see
|
|
16
|
+
* "this might be missing or might be the parser's CST/parsed-block shape"
|
|
17
|
+
* rather than `unknown` — the runtime guards in `ast-to-graph.ts` still
|
|
18
|
+
* verify the duck-typed `NamedMap` shape before iterating.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* A leaf field as the parser emits it: `{ value: T, ...metadata }`. The
|
|
22
|
+
* extractor only reads `.value` and treats anything else as missing.
|
|
23
|
+
*/
|
|
24
|
+
export interface AstField<T = unknown> {
|
|
25
|
+
value?: T;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A parsed block (the per-entry value inside a NamedMap). The extractor
|
|
29
|
+
* reads `label`, `description`, `actions`, and `reasoning` — all are
|
|
30
|
+
* optional and individually guarded at runtime.
|
|
31
|
+
*/
|
|
32
|
+
export type AstBlock = Record<string, unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* The named-collection container the parser emits for `start_agent` /
|
|
35
|
+
* `subagent` / `topic` blocks (`CollectionBlockNode`). We don't import the
|
|
36
|
+
* parser's class here — duck-typing in `isNamedMapLike` is the runtime
|
|
37
|
+
* source of truth.
|
|
38
|
+
*/
|
|
39
|
+
export interface AstNamedMap<V = AstBlock> {
|
|
40
|
+
has(key: string): boolean;
|
|
41
|
+
get(key: string): V | undefined;
|
|
42
|
+
keys(): IterableIterator<string>;
|
|
43
|
+
[Symbol.iterator](): IterableIterator<[string, V]>;
|
|
44
|
+
}
|
|
45
|
+
export interface AgentScriptAST {
|
|
46
|
+
/** Optional source-name annotation the host can attach for fallback labels. */
|
|
47
|
+
__sourceName?: string;
|
|
48
|
+
config?: AstBlock;
|
|
49
|
+
/**
|
|
50
|
+
* Top-level `system:` block (sibling of `config`). Carries the agent-level
|
|
51
|
+
* `instructions` template plus `messages.welcome` / `messages.error`.
|
|
52
|
+
*/
|
|
53
|
+
system?: AstBlock;
|
|
54
|
+
/** Top-level `variables:` block — each entry's value is the typed declaration. */
|
|
55
|
+
variables?: AstNamedMap;
|
|
56
|
+
start_agent?: AstNamedMap;
|
|
57
|
+
subagent?: AstNamedMap;
|
|
58
|
+
/** Deprecated v65 keyword for `subagent`. */
|
|
59
|
+
topic?: AstNamedMap;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=ast-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-utils.d.ts","sourceRoot":"","sources":["../../../../src/plugins/agent/extract/ast-utils.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;;;;;;;GAYG;AAEH;;;GAGG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,GAAG,OAAO;IACnC,KAAK,CAAC,EAAE,CAAC,CAAC;CACX;AAED;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,QAAQ;IACvC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;IAChC,IAAI,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;CACpD;AAED,MAAM,WAAW,cAAc;IAC7B,+EAA+E;IAC/E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB;;;OAGG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,kFAAkF;IAClF,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,6CAA6C;IAC7C,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* Licensed under the BSD 3-Clause license.
|
|
5
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
**/
|
|
7
|
+
/**
|
|
8
|
+
* Parsed result of a namespaced reference like `@variables.foo.bar`.
|
|
9
|
+
*/
|
|
10
|
+
export interface RefSpec {
|
|
11
|
+
/** The namespace (`variables`, `actions`, `subagent`, etc.) */
|
|
12
|
+
namespace: string;
|
|
13
|
+
/** The root identifier after the namespace (`foo` in `@variables.foo.bar`) */
|
|
14
|
+
root: string;
|
|
15
|
+
/** The full dotted path after the namespace (`foo.bar` in `@variables.foo.bar`) */
|
|
16
|
+
path: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parse a `@namespace.path` reference into its components.
|
|
20
|
+
*
|
|
21
|
+
* Returns null for non-namespaced strings (no leading `@` or no dot).
|
|
22
|
+
*
|
|
23
|
+
* Examples:
|
|
24
|
+
* - `@variables.foo` → `{namespace: 'variables', root: 'foo', path: 'foo'}`
|
|
25
|
+
* - `@variables.row.field` → `{namespace: 'variables', root: 'row', path: 'row.field'}`
|
|
26
|
+
* - `@actions.send_email` → `{namespace: 'actions', root: 'send_email', path: 'send_email'}`
|
|
27
|
+
* - `plain text` → `null`
|
|
28
|
+
* - `@nonamespace` → `null` (missing dot)
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseNamespacedRef(s: string): RefSpec | null;
|
|
31
|
+
//# sourceMappingURL=parseNamespacedRef.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseNamespacedRef.d.ts","sourceRoot":"","sources":["../../../../src/plugins/agent/extract/parseNamespacedRef.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb,mFAAmF;IACnF,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAY5D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* Licensed under the BSD 3-Clause license.
|
|
5
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
**/
|
|
7
|
+
/**
|
|
8
|
+
* Parse a `@namespace.path` reference into its components.
|
|
9
|
+
*
|
|
10
|
+
* Returns null for non-namespaced strings (no leading `@` or no dot).
|
|
11
|
+
*
|
|
12
|
+
* Examples:
|
|
13
|
+
* - `@variables.foo` → `{namespace: 'variables', root: 'foo', path: 'foo'}`
|
|
14
|
+
* - `@variables.row.field` → `{namespace: 'variables', root: 'row', path: 'row.field'}`
|
|
15
|
+
* - `@actions.send_email` → `{namespace: 'actions', root: 'send_email', path: 'send_email'}`
|
|
16
|
+
* - `plain text` → `null`
|
|
17
|
+
* - `@nonamespace` → `null` (missing dot)
|
|
18
|
+
*/
|
|
19
|
+
export function parseNamespacedRef(s) {
|
|
20
|
+
if (!s.startsWith('@')) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const dot = s.indexOf('.');
|
|
24
|
+
if (dot < 0) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const namespace = s.slice(1, dot);
|
|
28
|
+
const path = s.slice(dot + 1);
|
|
29
|
+
const root = path.split('.')[0];
|
|
30
|
+
return { namespace, root, path };
|
|
31
|
+
}
|