@salesforce/metadata-plugins 1.2.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.
Files changed (73) hide show
  1. package/dist/index.d.ts +4 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +9 -2
  4. package/dist/plugins/agent/AgentParser.d.ts +34 -0
  5. package/dist/plugins/agent/AgentParser.d.ts.map +1 -0
  6. package/dist/plugins/agent/AgentParser.js +189 -0
  7. package/dist/plugins/agent/AgentVisualizer.d.ts +27 -0
  8. package/dist/plugins/agent/AgentVisualizer.d.ts.map +1 -0
  9. package/dist/plugins/agent/AgentVisualizer.js +36 -0
  10. package/dist/plugins/agent/extract/assertNever.d.ts +23 -0
  11. package/dist/plugins/agent/extract/assertNever.d.ts.map +1 -0
  12. package/dist/plugins/agent/extract/assertNever.js +24 -0
  13. package/dist/plugins/agent/extract/ast-to-graph.d.ts +137 -0
  14. package/dist/plugins/agent/extract/ast-to-graph.d.ts.map +1 -0
  15. package/dist/plugins/agent/extract/ast-to-graph.js +523 -0
  16. package/dist/plugins/agent/extract/ast-utils.d.ts +61 -0
  17. package/dist/plugins/agent/extract/ast-utils.d.ts.map +1 -0
  18. package/dist/plugins/agent/extract/ast-utils.js +7 -0
  19. package/dist/plugins/agent/extract/parseNamespacedRef.d.ts +31 -0
  20. package/dist/plugins/agent/extract/parseNamespacedRef.d.ts.map +1 -0
  21. package/dist/plugins/agent/extract/parseNamespacedRef.js +31 -0
  22. package/dist/plugins/agent/extract/reasoningParser.d.ts +112 -0
  23. package/dist/plugins/agent/extract/reasoningParser.d.ts.map +1 -0
  24. package/dist/plugins/agent/extract/reasoningParser.js +804 -0
  25. package/dist/plugins/agent/types/AgentScriptData.d.ts +31 -0
  26. package/dist/plugins/agent/types/AgentScriptData.d.ts.map +1 -0
  27. package/dist/plugins/agent/types/AgentScriptData.js +7 -0
  28. package/dist/plugins/agent/ui/assets/index-CTzSDPPx.css +1 -0
  29. package/dist/plugins/agent/ui/assets/index-D0wb9GBs.js +71 -0
  30. package/dist/plugins/agent/ui/index.html +14 -0
  31. package/dist/plugins/flexipage/FlexipageParser.d.ts +1 -1
  32. package/dist/plugins/flexipage/FlexipageParser.js +1 -1
  33. package/dist/plugins/flexipage/FlexipageVisualizer.d.ts +1 -1
  34. package/dist/plugins/flexipage/FlexipageVisualizer.d.ts.map +1 -1
  35. package/dist/plugins/flexipage/FlexipageVisualizer.js +3 -1
  36. package/dist/plugins/flexipage/transformer/FlexipageToUemTransformer.d.ts +1 -1
  37. package/dist/plugins/flexipage/transformer/FlexipageToUemTransformer.js +1 -1
  38. package/dist/plugins/flexipage/transformer/FlexipageTransformerUtils.d.ts +1 -1
  39. package/dist/plugins/flexipage/transformer/FlexipageTransformerUtils.js +1 -1
  40. package/dist/plugins/flexipage/types/FlexipageMetadata.d.ts +1 -1
  41. package/dist/plugins/flexipage/types/FlexipageMetadata.js +1 -1
  42. package/dist/plugins/schema/SchemaParser.d.ts +1 -1
  43. package/dist/plugins/schema/SchemaParser.js +1 -1
  44. package/dist/plugins/schema/SchemaVisualizer.d.ts +1 -1
  45. package/dist/plugins/schema/SchemaVisualizer.d.ts.map +1 -1
  46. package/dist/plugins/schema/SchemaVisualizer.js +2 -1
  47. package/dist/plugins/schema/types/SchemaERDData.d.ts +1 -1
  48. package/dist/plugins/schema/types/SchemaERDData.js +1 -1
  49. package/dist/shared/bootstrap/createPluginApp.d.ts +1 -1
  50. package/dist/shared/bootstrap/createPluginApp.js +1 -1
  51. package/dist/shared/components/ErrorBoundary.d.ts +1 -1
  52. package/dist/shared/components/ErrorBoundary.js +1 -1
  53. package/dist/shared/uem/transformer/ITransformer.d.ts +1 -1
  54. package/dist/shared/uem/transformer/ITransformer.js +1 -1
  55. package/dist/shared/uem/transformer/TransformerRegistry.d.ts +1 -1
  56. package/dist/shared/uem/transformer/TransformerRegistry.js +1 -1
  57. package/dist/shared/uem/transformer/UemBasedVisualizer.d.ts +1 -1
  58. package/dist/shared/uem/transformer/UemBasedVisualizer.js +1 -1
  59. package/dist/shared/uem/types/UemMetadata.d.ts +1 -1
  60. package/dist/shared/uem/types/UemMetadata.js +1 -1
  61. package/dist/shared/uem/ui/components/PropertyRenderer/PropertyRenderer.d.ts +1 -1
  62. package/dist/shared/uem/ui/components/PropertyRenderer/PropertyRenderer.js +1 -1
  63. package/dist/shared/uem/ui/components/UEMVisualization/UEMVisualization.d.ts +1 -1
  64. package/dist/shared/uem/ui/components/UEMVisualization/UEMVisualization.js +1 -1
  65. package/dist/shared/utils/isPluginError.d.ts +1 -1
  66. package/dist/shared/utils/isPluginError.js +1 -1
  67. package/dist/shared/utils/patternMatcher.d.ts +1 -1
  68. package/dist/shared/utils/patternMatcher.js +1 -1
  69. package/dist/shared/utils/uemTreeUtils.d.ts +1 -1
  70. package/dist/shared/utils/uemTreeUtils.js +1 -1
  71. package/dist/shared/utils/vizDependentPathsHelper.d.ts +1 -1
  72. package/dist/shared/utils/vizDependentPathsHelper.js +1 -1
  73. package/package.json +6 -3
package/dist/index.d.ts CHANGED
@@ -1,15 +1,18 @@
1
1
  /**
2
- * Copyright (c) 2025, Salesforce, Inc.
2
+ * Copyright (c) 2026, Salesforce, Inc.
3
3
  * All rights reserved.
4
4
  * Licensed under the BSD 3-Clause license.
5
5
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
6
  **/
7
7
  export { FlexipageVisualizer } from './plugins/flexipage/FlexipageVisualizer.js';
8
8
  export { SchemaVisualizer } from './plugins/schema/SchemaVisualizer.js';
9
+ export { AgentVisualizer } from './plugins/agent/AgentVisualizer.js';
9
10
  export { FlexipageParser } from './plugins/flexipage/FlexipageParser.js';
10
11
  export { SchemaParser } from './plugins/schema/SchemaParser.js';
12
+ export { AgentParser } from './plugins/agent/AgentParser.js';
11
13
  export type { FlexipageMetadata } from './plugins/flexipage/types/FlexipageMetadata.js';
12
14
  export type { SchemaERDData } from './plugins/schema/types/SchemaERDData.js';
15
+ export type { AgentScriptData } from './plugins/agent/types/AgentScriptData.js';
13
16
  import { IVisualizationPlugin, PluginConfig } from '@salesforce/metadata-core-sdk';
14
17
  /**
15
18
  * Get all visualization plugins
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAkBJ,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAGxE,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAGhE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACxF,YAAY,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAG7E,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEnF;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,oBAAoB,EAAE,CAY/E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAmBJ,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAGrE,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAG7D,YAAY,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACxF,YAAY,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAC7E,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAGhF,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEnF;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,oBAAoB,EAAE,CAgB/E"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2025, Salesforce, Inc.
2
+ * Copyright (c) 2026, Salesforce, Inc.
3
3
  * All rights reserved.
4
4
  * Licensed under the BSD 3-Clause license.
5
5
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
@@ -17,12 +17,15 @@
17
17
  // Import visualization plugins (static visualization only)
18
18
  import { FlexipageVisualizer } from './plugins/flexipage/FlexipageVisualizer.js';
19
19
  import { SchemaVisualizer } from './plugins/schema/SchemaVisualizer.js';
20
+ import { AgentVisualizer } from './plugins/agent/AgentVisualizer.js';
20
21
  // Export visualization plugins
21
22
  export { FlexipageVisualizer } from './plugins/flexipage/FlexipageVisualizer.js';
22
23
  export { SchemaVisualizer } from './plugins/schema/SchemaVisualizer.js';
24
+ export { AgentVisualizer } from './plugins/agent/AgentVisualizer.js';
23
25
  // Export parsers
24
26
  export { FlexipageParser } from './plugins/flexipage/FlexipageParser.js';
25
27
  export { SchemaParser } from './plugins/schema/SchemaParser.js';
28
+ export { AgentParser } from './plugins/agent/AgentParser.js';
26
29
  /**
27
30
  * Get all visualization plugins
28
31
  *
@@ -34,7 +37,11 @@ export { SchemaParser } from './plugins/schema/SchemaParser.js';
34
37
  * @returns Array of visualization plugin instances
35
38
  */
36
39
  export function getAllVisualizers(config) {
37
- const all = [new FlexipageVisualizer(), new SchemaVisualizer()];
40
+ const all = [
41
+ new FlexipageVisualizer(),
42
+ new SchemaVisualizer(),
43
+ new AgentVisualizer(),
44
+ ];
38
45
  if (!config?.pluginSettings) {
39
46
  return all;
40
47
  }
@@ -0,0 +1,34 @@
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
+ * Agent Script Parser
9
+ *
10
+ * Reads a `.agent` file, runs the AgentScript parser (JS-only browser
11
+ * bundle — runs fine in Node and avoids any WASM/tree-sitter setup), and
12
+ * extracts a JSON-safe overview graph (meta box + start_agent + subagents)
13
+ * for the webview to render.
14
+ *
15
+ * Doing the parse on the host keeps the heavy AgentScript parser out of the
16
+ * webview bundle, so it boots fast and `getPluginData` doesn't time out — the
17
+ * webview only ships React Flow + dagre and renders the pre-built JSON graph.
18
+ */
19
+ import { IMetadataParser, MetadataFileInfo, IPlatformContext, VersionInfo } from '@salesforce/metadata-core-sdk';
20
+ import { AgentScriptData } from './types/AgentScriptData.js';
21
+ export declare class AgentParser implements IMetadataParser<AgentScriptData> {
22
+ private platformContext?;
23
+ private logger?;
24
+ private telemetry?;
25
+ setPlatformContext(context: IPlatformContext): void;
26
+ parse(filePath: string, _versionInfo: VersionInfo): Promise<AgentScriptData>;
27
+ /**
28
+ * Mirror the meta info node's label — read from the same `config:` block
29
+ * the visualizer renders (`agent_label` ↦ `developer_name` ↦ filename
30
+ * basename).
31
+ */
32
+ extractMetadataInfo(data: AgentScriptData): MetadataFileInfo | null;
33
+ }
34
+ //# sourceMappingURL=AgentParser.d.ts.map
@@ -0,0 +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,EAGZ,MAAM,+BAA+B,CAAC;AAOvC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAoD7D,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;IA+HlF;;;;OAIG;IACH,mBAAmB,CAAC,IAAI,EAAE,eAAe,GAAG,gBAAgB,GAAG,IAAI;CAIpE"}
@@ -0,0 +1,189 @@
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
+ * Agent Script Parser
9
+ *
10
+ * Reads a `.agent` file, runs the AgentScript parser (JS-only browser
11
+ * bundle — runs fine in Node and avoids any WASM/tree-sitter setup), and
12
+ * extracts a JSON-safe overview graph (meta box + start_agent + subagents)
13
+ * for the webview to render.
14
+ *
15
+ * Doing the parse on the host keeps the heavy AgentScript parser out of the
16
+ * webview bundle, so it boots fast and `getPluginData` doesn't time out — the
17
+ * webview only ships React Flow + dagre and renders the pre-built JSON graph.
18
+ */
19
+ import { ErrorBuilder, ErrorCategory, } from '@salesforce/metadata-core-sdk';
20
+ // Official AgentScript parser (public npm package). The default entry uses
21
+ // the pure-TS `parser-javascript` backend — no WASM, no native bindings, no
22
+ // async init — so it runs fine in the Node extension host. It accepts both
23
+ // v66 (`subagent`) and the deprecated v65 (`topic`) keywords; `start_agent`
24
+ // is unchanged across versions.
25
+ import { parse } from '@sf-agentscript/agentforce';
26
+ import { isPluginError } from '../../shared/utils/isPluginError.js';
27
+ import { astToOverviewGraph } from './extract/ast-to-graph.js';
28
+ /**
29
+ * LSP severity values: 1=Error, 2=Warning, 3=Info, 4=Hint. Only severity 1
30
+ * blocks visualization — warnings/info/hints are non-fatal.
31
+ */
32
+ const LSP_SEVERITY_ERROR = 1;
33
+ /**
34
+ * Extract basename from a file path without importing Node's `path` module.
35
+ * Handles both `/` and `\` separators.
36
+ */
37
+ function basename(filePath) {
38
+ return filePath.split(/[\\/]/).pop() ?? filePath;
39
+ }
40
+ /**
41
+ * Format diagnostics into a single-line summary for the thrown error message.
42
+ * Each entry shows `Line L:C — message [code]` with 1-based positions (LSP
43
+ * positions are zero-based; humans read 1-based). The first few errors are
44
+ * inlined; the rest are summarized as "(+N more)" so a flood of cascading
45
+ * errors doesn't produce an unreadable wall of text.
46
+ */
47
+ function formatErrorSummary(diagnostics) {
48
+ // The parser's public type is `readonly Diagnostic[]`, but defend against
49
+ // any shape — older parser builds and recovery paths have been observed
50
+ // to return `undefined` or an iterable. Coerce to a plain array first so
51
+ // the .filter below never blows up.
52
+ const list = Array.isArray(diagnostics)
53
+ ? diagnostics
54
+ : diagnostics && typeof diagnostics[Symbol.iterator] === 'function'
55
+ ? Array.from(diagnostics)
56
+ : [];
57
+ const errors = list.filter((d) => !!d && typeof d === 'object' && d.severity === LSP_SEVERITY_ERROR);
58
+ const MAX = 5;
59
+ const head = errors.slice(0, MAX).map((d) => {
60
+ const range = d.range;
61
+ const line = typeof range?.start?.line === 'number' ? range.start.line + 1 : 1;
62
+ const col = typeof range?.start?.character === 'number' ? range.start.character + 1 : 1;
63
+ const code = typeof d.code === 'string' ? ` [${d.code}]` : '';
64
+ const message = typeof d.message === 'string' ? d.message : String(d.message ?? '');
65
+ return `Line ${line}:${col} — ${message}${code}`;
66
+ });
67
+ const overflow = errors.length > MAX ? ` (+${errors.length - MAX} more)` : '';
68
+ return head.join('; ') + overflow;
69
+ }
70
+ export class AgentParser {
71
+ setPlatformContext(context) {
72
+ this.platformContext = context;
73
+ this.logger = context.logger.createChild('AgentParser');
74
+ this.telemetry = context.telemetry.createChild({ component: 'AgentParser' });
75
+ }
76
+ async parse(filePath, _versionInfo) {
77
+ if (!this.platformContext) {
78
+ throw ErrorBuilder.create()
79
+ .category(ErrorCategory.Configuration)
80
+ .message('AgentParser not initialized with platform context')
81
+ .build();
82
+ }
83
+ const ctx = this.platformContext;
84
+ const log = this.logger ?? ctx.logger.createChild('AgentParser');
85
+ const telemetry = this.telemetry ?? ctx.telemetry.createChild({ component: 'AgentParser' });
86
+ // Basename is retained for the ErrorBuilder `context` (host-side error
87
+ // chrome shows it to the user) but is intentionally NEVER shipped in a
88
+ // telemetry event — `.agent` filenames are customer-authored and can
89
+ // reveal product / feature names.
90
+ const fileName = basename(filePath);
91
+ return telemetry.withSpan('agent.parse', async (span) => {
92
+ try {
93
+ const readResult = await ctx.fileSystem.readFile(filePath);
94
+ if (!readResult.success || !readResult.data) {
95
+ throw ErrorBuilder.create()
96
+ .category(ErrorCategory.Dependency)
97
+ .message(`Failed to read agent file: ${readResult.error?.message ?? 'unknown error'}`)
98
+ .context({ fileName })
99
+ .build();
100
+ }
101
+ const source = readResult.data;
102
+ // Defensive guard: `IFileSystem.readFile` is typed to return string
103
+ // data, but if a host violates that contract we'd rather throw a
104
+ // clear Parsing error than feed a non-string into `parse()` (whose
105
+ // diagnostics wouldn't be meaningful for a raw type mismatch).
106
+ if (typeof source !== 'string') {
107
+ throw ErrorBuilder.create()
108
+ .category(ErrorCategory.Parsing)
109
+ .message('Agent file content is not a string')
110
+ .context({ fileName })
111
+ .build();
112
+ }
113
+ span.setAttribute('sourceLength', String(source.length));
114
+ const doc = parse(source);
115
+ // A script with parse errors must fail the plugin — there's no useful
116
+ // visualization to show, and silently rendering a possibly-empty graph
117
+ // hides the real problem from the user. The host surfaces this as a
118
+ // plugin error in the webview chrome.
119
+ if (doc.hasErrors) {
120
+ const summary = formatErrorSummary(doc.diagnostics);
121
+ const errorCount = Array.isArray(doc.diagnostics)
122
+ ? doc.diagnostics.filter((d) => !!d &&
123
+ typeof d === 'object' &&
124
+ d.severity === LSP_SEVERITY_ERROR).length
125
+ : 0;
126
+ telemetry.sendEvent('agent.parse_error', { pluginId: 'agent' }, { errorCount });
127
+ throw ErrorBuilder.create()
128
+ .category(ErrorCategory.Parsing)
129
+ .message(`Agent script has parse errors: ${summary}`)
130
+ .context({ fileName, errorSummary: summary })
131
+ .build();
132
+ }
133
+ const graph = astToOverviewGraph(doc.ast, source);
134
+ const subagentCount = graph.nodes.filter((n) => n.data.nodeType === 'subagent').length;
135
+ // Requirement 1.2 — agent complexity. `subagentCount` is the only
136
+ // shape metric we emit; anything richer (node/edge counts, start-agent
137
+ // presence, source length) belongs in the webview layer or not at all.
138
+ span.setAttribute('subagentCount', String(subagentCount));
139
+ // Requirement 4.3 — parse reliability. The AgentScript parser
140
+ // accepts a file without error yet the graph builder can still
141
+ // produce an empty or incomplete diagram if the source uses
142
+ // syntax the extractor hasn't caught up with (new top-level
143
+ // keywords, renamed collections, etc). Two shapes count as
144
+ // silent failures:
145
+ // - `empty` — only the meta node was produced (no
146
+ // `start_agent`, no `subagent`/`topic`)
147
+ // - `no_edges` — multiple nodes but zero connecting edges
148
+ // A rise in either signal means the extractor is falling
149
+ // behind the syntax. `reason` is a fixed low-cardinality string
150
+ // so it's safe on the properties dimension.
151
+ const edgeCount = graph.edges.length;
152
+ const nodeCount = graph.nodes.length;
153
+ let incompleteReason;
154
+ if (nodeCount <= 1) {
155
+ incompleteReason = 'empty';
156
+ }
157
+ else if (edgeCount === 0) {
158
+ incompleteReason = 'no_edges';
159
+ }
160
+ if (incompleteReason) {
161
+ telemetry.sendEvent('agent.parse_incomplete', { pluginId: 'agent', reason: incompleteReason }, { nodeCount, edgeCount, subagentCount });
162
+ log.warn(`Agent parse produced ${incompleteReason} diagram (nodes=${nodeCount}, edges=${edgeCount})`);
163
+ }
164
+ telemetry.sendEvent('agent.parse_complete', { pluginId: 'agent' }, { subagentCount });
165
+ log.info(`Parsed agent file (subagentCount=${subagentCount})`);
166
+ return {
167
+ filePath,
168
+ graph,
169
+ };
170
+ }
171
+ catch (error) {
172
+ log.error('Error parsing agent file:', error);
173
+ if (isPluginError(error)) {
174
+ throw error;
175
+ }
176
+ throw ErrorBuilder.fromError(ErrorCategory.Parsing, error, { fileName }).build();
177
+ }
178
+ }, { pluginId: 'agent' });
179
+ }
180
+ /**
181
+ * Mirror the meta info node's label — read from the same `config:` block
182
+ * the visualizer renders (`agent_label` ↦ `developer_name` ↦ filename
183
+ * basename).
184
+ */
185
+ extractMetadataInfo(data) {
186
+ const metaNode = data.graph?.nodes.find((n) => n.data.nodeType === 'meta');
187
+ return metaNode?.data.label ? { label: metaNode.data.label } : null;
188
+ }
189
+ }
@@ -0,0 +1,27 @@
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
+ * Agent Script Visualizer Plugin
9
+ *
10
+ * Handles `.agent` text-DSL files and renders the agent as an interactive
11
+ * React Flow overview graph (meta → start_agent → subagents) using the local
12
+ * node components in `ui/graph/components/nodes/`.
13
+ */
14
+ import { IVisualizationPlugin, MetadataPluginInfo, IPlatformContext } from '@salesforce/metadata-core-sdk';
15
+ import { AgentScriptData } from './types/AgentScriptData.js';
16
+ import { AgentParser } from './AgentParser.js';
17
+ export declare class AgentVisualizer implements IVisualizationPlugin<AgentScriptData> {
18
+ private readonly pluginMetadata;
19
+ readonly parser: AgentParser;
20
+ private logger?;
21
+ constructor();
22
+ getMetadataPluginInfo(): MetadataPluginInfo;
23
+ canHandle(filePath: string): boolean;
24
+ initialize(context: IPlatformContext): Promise<void>;
25
+ dispose?(): void;
26
+ }
27
+ //# sourceMappingURL=AgentVisualizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentVisualizer.d.ts","sourceRoot":"","sources":["../../../src/plugins/agent/AgentVisualizer.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;GAMG;AAEH,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAEjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,qBAAa,eAAgB,YAAW,oBAAoB,CAAC,eAAe,CAAC;IAC3E,OAAO,CAAC,QAAQ,CAAC,cAAc,CAQ7B;IAEF,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAE7B,OAAO,CAAC,MAAM,CAAC,CAAU;;IAMzB,qBAAqB,IAAI,kBAAkB;IAI3C,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAM9B,UAAU,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAO1D,OAAO,CAAC,IAAI,IAAI;CAGjB"}
@@ -0,0 +1,36 @@
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
+ import { AgentParser } from './AgentParser.js';
8
+ import { matchesFilePattern } from '../../shared/utils/patternMatcher.js';
9
+ export class AgentVisualizer {
10
+ constructor() {
11
+ this.pluginMetadata = {
12
+ id: 'agent',
13
+ name: 'Salesforce Agent Script Visualizer',
14
+ displayName: 'Agent Script',
15
+ description: 'Interactive topic graph for AgentScript (.agent) files',
16
+ author: 'Metadata Visualizer Team',
17
+ filePatterns: ['.agent'],
18
+ priority: 10,
19
+ };
20
+ this.parser = new AgentParser();
21
+ }
22
+ getMetadataPluginInfo() {
23
+ return this.pluginMetadata;
24
+ }
25
+ canHandle(filePath) {
26
+ return this.getMetadataPluginInfo().filePatterns.some((pattern) => matchesFilePattern(filePath, pattern));
27
+ }
28
+ async initialize(context) {
29
+ this.logger = context.logger.createChild(this.getMetadataPluginInfo().id);
30
+ this.logger.info('Agent visualizer initialized');
31
+ this.parser.setPlatformContext(context);
32
+ }
33
+ dispose() {
34
+ this.logger?.info(`Disposing ${this.getMetadataPluginInfo().name}`);
35
+ }
36
+ }
@@ -0,0 +1,23 @@
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
+ * Exhaustiveness check for discriminated union switches. When all cases are
9
+ * handled, the TypeScript compiler narrows the remaining value to `never`.
10
+ * If a new discriminant is added but not handled, the compiler flags the gap.
11
+ *
12
+ * Usage:
13
+ * ```ts
14
+ * switch (block.kind) {
15
+ * case 'if': return handleIf(block);
16
+ * case 'set': return handleSet(block);
17
+ * // ... all other cases
18
+ * default: return assertNever(block);
19
+ * }
20
+ * ```
21
+ */
22
+ export declare function assertNever(value: never): never;
23
+ //# sourceMappingURL=assertNever.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertNever.d.ts","sourceRoot":"","sources":["../../../../src/plugins/agent/extract/assertNever.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAE/C"}
@@ -0,0 +1,24 @@
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
+ * Exhaustiveness check for discriminated union switches. When all cases are
9
+ * handled, the TypeScript compiler narrows the remaining value to `never`.
10
+ * If a new discriminant is added but not handled, the compiler flags the gap.
11
+ *
12
+ * Usage:
13
+ * ```ts
14
+ * switch (block.kind) {
15
+ * case 'if': return handleIf(block);
16
+ * case 'set': return handleSet(block);
17
+ * // ... all other cases
18
+ * default: return assertNever(block);
19
+ * }
20
+ * ```
21
+ */
22
+ export function assertNever(value) {
23
+ throw new Error(`Unhandled discriminant: ${JSON.stringify(value)}`);
24
+ }
@@ -0,0 +1,137 @@
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
+ * AST → Graph Data Transformer
9
+ *
10
+ * Produces a minimal three-tier overview:
11
+ * [Meta box] — agent label + description (from `config:`)
12
+ * ↓
13
+ * [Start Agent] — label, description
14
+ * ↓
15
+ * [Subagent boxes] — label, description, action count
16
+ */
17
+ import type { Node, Edge } from '@xyflow/react';
18
+ import type { AgentScriptAST } from './ast-utils.js';
19
+ export type GraphNodeType = 'meta' | 'start-agent' | 'subagent' | 'junction';
20
+ /**
21
+ * Per-variant data shapes. React Flow requires `NodeData extends
22
+ * Record<string, unknown>`, so each variant extends `Record<string,
23
+ * unknown>` directly — but only its declared fields appear in the
24
+ * discriminated union, so typos are compile errors at the construction
25
+ * and consumption sites.
26
+ */
27
+ export interface MetaNodeData extends Record<string, unknown> {
28
+ nodeType: 'meta';
29
+ label: string;
30
+ /** Static "Agent" label is rendered by the component; carries description. */
31
+ description?: string;
32
+ /** Agent-level `system.instructions` text (indentation-preserved). */
33
+ systemInstructions?: string;
34
+ /** `system.messages.welcome` string. */
35
+ welcomeMessage?: string;
36
+ /** `system.messages.error` string. */
37
+ errorMessage?: string;
38
+ }
39
+ export interface StartAgentNodeData extends Record<string, unknown> {
40
+ nodeType: 'start-agent';
41
+ label: string;
42
+ /** Block name (e.g. `Router`); rendered as the small subtitle line. */
43
+ subtitle?: string;
44
+ description?: string;
45
+ /** `start_agent` is unchanged across API versions. */
46
+ sourceKeyword: 'start_agent';
47
+ }
48
+ /** A single declared input/output of an action, surfaced in the detail panel. */
49
+ export interface ActionParam {
50
+ name: string;
51
+ /** Data type as written in the source (`string`, `object`, ...). */
52
+ type?: string;
53
+ /** Optional label override; falls back to the param name when rendering. */
54
+ label?: string;
55
+ }
56
+ /** Full per-action detail extracted for the subagent detail panel. */
57
+ export interface ActionDetail {
58
+ name: string;
59
+ label?: string;
60
+ description?: string;
61
+ target?: string;
62
+ inputs: ActionParam[];
63
+ outputs: ActionParam[];
64
+ }
65
+ /** Reasoning block extracted as plain JSON for the detail panel. */
66
+ export interface ReasoningDetail {
67
+ instructions?: string;
68
+ /** Action names referenced in the reasoning block (rendered as pills). */
69
+ actionRefs: string[];
70
+ /**
71
+ * Full action definitions declared INLINE under `reasoning.actions:`. These
72
+ * are separate from the subagent's top-level `actions:` (the ACTIONS card)
73
+ * and drive the "ACTIONS AVAILABLE FOR REASONING" pills' icon resolution.
74
+ */
75
+ actions: ActionDetail[];
76
+ }
77
+ export interface SubagentNodeData extends Record<string, unknown> {
78
+ nodeType: 'subagent';
79
+ label: string;
80
+ description?: string;
81
+ /** Number of `actions` declared on this subagent block. */
82
+ actionsCount?: number;
83
+ /**
84
+ * Top-level `variables:` declared types, keyed by variable name (no `@`
85
+ * prefix). Used by the reasoning renderer to pick a type-specific icon
86
+ * for `@variables.X` chips.
87
+ */
88
+ variableTypes?: Record<string, string>;
89
+ /**
90
+ * Source-level keyword the block came from. `subagent` is the v66 keyword;
91
+ * `topic` is the deprecated v65 keyword. The UI uses this to label
92
+ * v65-era nodes as "Topic" while v66 stays "Sub Agent".
93
+ */
94
+ sourceKeyword: 'subagent' | 'topic';
95
+ /** Subagent-level `system.instructions` template text. */
96
+ systemInstructions?: string;
97
+ /** `before_reasoning:` template text — runs before each reasoning step. */
98
+ beforeReasoning?: string;
99
+ /** `after_reasoning:` template text — runs after each reasoning step. */
100
+ afterReasoning?: string;
101
+ /** Full reasoning block — populated when the subagent declares one. */
102
+ reasoning?: ReasoningDetail;
103
+ /** Full action definitions, ordered by appearance in the source. */
104
+ actions: ActionDetail[];
105
+ }
106
+ export interface JunctionNodeData extends Record<string, unknown> {
107
+ nodeType: 'junction';
108
+ /** Always empty — junctions render no visible text. */
109
+ label: '';
110
+ }
111
+ export type GraphNodeData = MetaNodeData | StartAgentNodeData | SubagentNodeData | JunctionNodeData;
112
+ /**
113
+ * Variant-typed React Flow nodes. Pinning the second `Node<>` generic to the
114
+ * matching `nodeType` literal couples the React Flow `type` field to the
115
+ * discriminant, so `{ type: 'meta', data: { nodeType: 'subagent', ... } }`
116
+ * is a compile error.
117
+ */
118
+ export type MetaGraphNode = Node<MetaNodeData, 'meta'>;
119
+ export type StartAgentGraphNode = Node<StartAgentNodeData, 'start-agent'>;
120
+ export type SubagentGraphNode = Node<SubagentNodeData, 'subagent'>;
121
+ export type JunctionGraphNode = Node<JunctionNodeData, 'junction'>;
122
+ export type GraphNode = MetaGraphNode | StartAgentGraphNode | SubagentGraphNode | JunctionGraphNode;
123
+ export type GraphEdge = Edge;
124
+ /**
125
+ * Build the high-level overview graph: meta → start_agent → subagents.
126
+ *
127
+ * `source` is the original `.agent` text. When provided, we use it to
128
+ * re-derive indentation for `|`-block reasoning instructions — the parser
129
+ * flattens those to column zero, which breaks the indentation-sensitive
130
+ * reasoning UI. The graph builder works without it; downstream renderers
131
+ * just see un-nested instruction lines.
132
+ */
133
+ export declare function astToOverviewGraph(ast: AgentScriptAST, source?: string): {
134
+ nodes: GraphNode[];
135
+ edges: GraphEdge[];
136
+ };
137
+ //# sourceMappingURL=ast-to-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-to-graph.d.ts","sourceRoot":"","sources":["../../../../src/plugins/agent/extract/ast-to-graph.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAyB,MAAM,gBAAgB,CAAC;AAE5E,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,aAAa,GAA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