@sf-explorer/agentscript-migration-tool 1.0.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 (68) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/LICENSE +21 -0
  3. package/README.md +342 -0
  4. package/dist/builders/actionBuilder.d.ts +39 -0
  5. package/dist/builders/actionBuilder.d.ts.map +1 -0
  6. package/dist/builders/actionBuilder.js +120 -0
  7. package/dist/builders/actionBuilder.js.map +1 -0
  8. package/dist/builders/configBuilder.d.ts +14 -0
  9. package/dist/builders/configBuilder.d.ts.map +1 -0
  10. package/dist/builders/configBuilder.js +22 -0
  11. package/dist/builders/configBuilder.js.map +1 -0
  12. package/dist/builders/index.d.ts +12 -0
  13. package/dist/builders/index.d.ts.map +1 -0
  14. package/dist/builders/index.js +12 -0
  15. package/dist/builders/index.js.map +1 -0
  16. package/dist/builders/languageBuilder.d.ts +13 -0
  17. package/dist/builders/languageBuilder.d.ts.map +1 -0
  18. package/dist/builders/languageBuilder.js +18 -0
  19. package/dist/builders/languageBuilder.js.map +1 -0
  20. package/dist/builders/startAgentBuilder.d.ts +14 -0
  21. package/dist/builders/startAgentBuilder.d.ts.map +1 -0
  22. package/dist/builders/startAgentBuilder.js +35 -0
  23. package/dist/builders/startAgentBuilder.js.map +1 -0
  24. package/dist/builders/systemBuilder.d.ts +14 -0
  25. package/dist/builders/systemBuilder.d.ts.map +1 -0
  26. package/dist/builders/systemBuilder.js +22 -0
  27. package/dist/builders/systemBuilder.js.map +1 -0
  28. package/dist/builders/topicBuilder.d.ts +23 -0
  29. package/dist/builders/topicBuilder.d.ts.map +1 -0
  30. package/dist/builders/topicBuilder.js +77 -0
  31. package/dist/builders/topicBuilder.js.map +1 -0
  32. package/dist/builders/variablesBuilder.d.ts +14 -0
  33. package/dist/builders/variablesBuilder.d.ts.map +1 -0
  34. package/dist/builders/variablesBuilder.js +46 -0
  35. package/dist/builders/variablesBuilder.js.map +1 -0
  36. package/dist/formatters/index.d.ts +5 -0
  37. package/dist/formatters/index.d.ts.map +1 -0
  38. package/dist/formatters/index.js +5 -0
  39. package/dist/formatters/index.js.map +1 -0
  40. package/dist/formatters/yamlFormatter.d.ts +17 -0
  41. package/dist/formatters/yamlFormatter.d.ts.map +1 -0
  42. package/dist/formatters/yamlFormatter.js +226 -0
  43. package/dist/formatters/yamlFormatter.js.map +1 -0
  44. package/dist/generator.d.ts +60 -0
  45. package/dist/generator.d.ts.map +1 -0
  46. package/dist/generator.js +109 -0
  47. package/dist/generator.js.map +1 -0
  48. package/dist/index.d.ts +15 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +15 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/types.d.ts +178 -0
  53. package/dist/types.d.ts.map +1 -0
  54. package/dist/types.js +7 -0
  55. package/dist/types.js.map +1 -0
  56. package/dist/utils/index.d.ts +5 -0
  57. package/dist/utils/index.d.ts.map +1 -0
  58. package/dist/utils/index.js +5 -0
  59. package/dist/utils/index.js.map +1 -0
  60. package/dist/utils/nameSanitizer.d.ts +30 -0
  61. package/dist/utils/nameSanitizer.d.ts.map +1 -0
  62. package/dist/utils/nameSanitizer.js +76 -0
  63. package/dist/utils/nameSanitizer.js.map +1 -0
  64. package/dist/validation.d.ts +46 -0
  65. package/dist/validation.d.ts.map +1 -0
  66. package/dist/validation.js +123 -0
  67. package/dist/validation.js.map +1 -0
  68. package/package.json +54 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,iBAAiB,EAEjB,4BAA4B,EAC7B,MAAM,SAAS,CAAA;AAiBhB;;;;;;;;;;;;GAYG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,OAAO,CAAwC;IAEvD;;;;;OAKG;gBAED,OAAO,EAAE,iBAAiB,EAC1B,OAAO,GAAE,4BAAiC;IAgB5C;;;;OAIG;IACH,QAAQ,IAAI,MAAM;IAmBlB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;CA8BzB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,4BAA4B,GACrC,MAAM,CAGR"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Agent Script Generator
3
+ * Generates Salesforce Agent Script YAML from PlannerDefinition
4
+ * Based on official Salesforce Agent Script Recipes
5
+ * @see https://developer.salesforce.com/sample-apps/agent-script-recipes/getting-started/overview
6
+ */
7
+ import { validatePlannerDefinition, validateIndent, ValidationError, } from "./validation";
8
+ import { buildConfig, buildSystem, buildLanguage, buildVariables, buildStartAgent, buildTopic, } from "./builders";
9
+ import { convertToYaml } from "./formatters";
10
+ import { sanitizeTopicName } from "./utils";
11
+ /**
12
+ * AgentScriptGenerator
13
+ * Generates complete Agent Script YAML following Salesforce patterns
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const generator = new AgentScriptGenerator(planner, {
18
+ * includeComments: true,
19
+ * yamlIndent: 4
20
+ * })
21
+ * const yaml = generator.generate()
22
+ * ```
23
+ */
24
+ export class AgentScriptGenerator {
25
+ /**
26
+ * Creates a new AgentScriptGenerator instance
27
+ * @param planner - The planner definition to generate YAML from
28
+ * @param options - Optional generation options
29
+ * @throws {ValidationError} If the planner definition is invalid
30
+ */
31
+ constructor(planner, options = {}) {
32
+ // Validate input
33
+ validatePlannerDefinition(planner);
34
+ this.planner = planner;
35
+ const validatedIndent = validateIndent(options.yamlIndent ?? 4);
36
+ this.options = {
37
+ includeComments: options.includeComments ?? true,
38
+ includeExamples: options.includeExamples ?? false,
39
+ yamlIndent: validatedIndent,
40
+ generateVariables: options.generateVariables ?? false,
41
+ includeLanguageConfig: options.includeLanguageConfig ?? true,
42
+ };
43
+ }
44
+ /**
45
+ * Generate complete Agent Script YAML
46
+ * @returns Generated YAML string
47
+ * @throws {Error} If generation fails
48
+ */
49
+ generate() {
50
+ try {
51
+ const agentScript = this.buildAgentScript();
52
+ return convertToYaml(agentScript, this.options, this.planner.MasterLabel, this.planner.DeveloperName);
53
+ }
54
+ catch (error) {
55
+ if (error instanceof ValidationError) {
56
+ throw error;
57
+ }
58
+ throw new Error(`Failed to generate Agent Script: ${error instanceof Error ? error.message : String(error)}`);
59
+ }
60
+ }
61
+ /**
62
+ * Build the complete agent script structure
63
+ * @returns Complete AgentScriptStructure
64
+ */
65
+ buildAgentScript() {
66
+ const script = {
67
+ config: buildConfig(this.planner),
68
+ system: buildSystem(this.planner),
69
+ };
70
+ // Add optional language configuration
71
+ if (this.options.includeLanguageConfig) {
72
+ script.language = buildLanguage();
73
+ }
74
+ // Add variables if they exist
75
+ if (this.planner.variables && this.planner.variables.length > 0) {
76
+ script.variables = buildVariables(this.planner);
77
+ }
78
+ // Add start_agent topic selector (with named sub-topic)
79
+ script["start_agent topic_selector"] = buildStartAgent(this.planner);
80
+ // Add individual topics (with 'topic' prefix per Salesforce spec)
81
+ const topics = this.planner.topics || [];
82
+ topics.forEach((topic, index) => {
83
+ const topicName = sanitizeTopicName(topic.DeveloperName || topic.MasterLabel || `Topic_${index}`);
84
+ script[`topic ${topicName}`] = buildTopic(topic);
85
+ });
86
+ return script;
87
+ }
88
+ }
89
+ /**
90
+ * Convenience function to generate Agent Script YAML
91
+ *
92
+ * @param planner - The planner definition to generate YAML from
93
+ * @param options - Optional generation options
94
+ * @returns Generated YAML string
95
+ * @throws {ValidationError} If the planner definition is invalid
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * const yaml = generateAgentScript(planner, {
100
+ * includeComments: true,
101
+ * includeLanguageConfig: true
102
+ * })
103
+ * ```
104
+ */
105
+ export function generateAgentScript(planner, options) {
106
+ const generator = new AgentScriptGenerator(planner, options);
107
+ return generator.generate();
108
+ }
109
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1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ACF;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAA0B,EAC1B,OAAsC;IAEtC,MAAM,SAAS,GAAG,IAAI,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC5D,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAA;AAC7B,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Agent Script Migration Tool
3
+ * Generates Salesforce Agent Script YAML from PlannerDefinition
4
+ *
5
+ * Based on official Salesforce Agent Script Recipes
6
+ * @see https://developer.salesforce.com/sample-apps/agent-script-recipes/getting-started/overview
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ export * from "./types";
11
+ export * from "./generator";
12
+ export * from "./validation";
13
+ export { AgentScriptGenerator, generateAgentScript } from "./generator";
14
+ export { ValidationError } from "./validation";
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Agent Script Migration Tool
3
+ * Generates Salesforce Agent Script YAML from PlannerDefinition
4
+ *
5
+ * Based on official Salesforce Agent Script Recipes
6
+ * @see https://developer.salesforce.com/sample-apps/agent-script-recipes/getting-started/overview
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ export * from "./types";
11
+ export * from "./generator";
12
+ export * from "./validation";
13
+ export { AgentScriptGenerator, generateAgentScript } from "./generator";
14
+ export { ValidationError } from "./validation";
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Agent Script Types
3
+ * Based on Salesforce Agent Script Recipes
4
+ * @see https://developer.salesforce.com/sample-apps/agent-script-recipes/getting-started/overview
5
+ */
6
+ /**
7
+ * Agent Script Config Block
8
+ * Defines agent metadata and configuration
9
+ */
10
+ export interface AgentScriptConfig {
11
+ agent_name?: string;
12
+ developer_name: string;
13
+ default_agent_user?: string;
14
+ description?: string;
15
+ }
16
+ /**
17
+ * Agent Script System Block
18
+ * Defines global settings and instructions
19
+ */
20
+ export interface AgentScriptSystemBlock {
21
+ instructions: string;
22
+ messages?: {
23
+ welcome?: string;
24
+ error?: string;
25
+ [key: string]: string | undefined;
26
+ };
27
+ system_instructions?: string;
28
+ }
29
+ /**
30
+ * Agent Script Variable Declaration
31
+ * Defines state management
32
+ */
33
+ export interface AgentScriptVariable {
34
+ type: "string" | "number" | "boolean" | "object" | "array";
35
+ mutable: boolean;
36
+ linked?: boolean;
37
+ default?: string | number | boolean | Record<string, unknown> | unknown[];
38
+ description?: string;
39
+ }
40
+ /**
41
+ * Agent Script Language Block
42
+ * Defines locale configuration
43
+ */
44
+ export interface AgentScriptLanguageBlock {
45
+ default_locale: string;
46
+ additional_locales?: string;
47
+ all_additional_locales?: boolean;
48
+ }
49
+ /**
50
+ * Agent Script Action Definition
51
+ * Defines external integrations (Flow, Apex, API)
52
+ */
53
+ export interface AgentScriptActionDefinition {
54
+ description: string;
55
+ inputs?: Record<string, string>;
56
+ outputs?: Record<string, string | {
57
+ description?: string;
58
+ [key: string]: unknown;
59
+ }>;
60
+ target: string;
61
+ }
62
+ /**
63
+ * Agent Script Reasoning Action
64
+ * Actions available to LLM in reasoning block
65
+ */
66
+ export interface AgentScriptReasoningAction {
67
+ action?: string;
68
+ description?: string;
69
+ available_when?: string;
70
+ with?: Record<string, unknown>;
71
+ set?: Record<string, unknown>;
72
+ }
73
+ /**
74
+ * Agent Script Reasoning Block
75
+ * Defines topic behavior and available actions
76
+ */
77
+ export interface AgentScriptReasoningBlock {
78
+ instructions?: string | string[];
79
+ actions?: Record<string, AgentScriptReasoningAction | string>;
80
+ before_reasoning?: string;
81
+ after_reasoning?: string;
82
+ }
83
+ /**
84
+ * Agent Script Topic Block
85
+ * Defines individual topics with reasoning and actions
86
+ */
87
+ export interface AgentScriptTopicBlock {
88
+ description: string;
89
+ reasoning?: AgentScriptReasoningBlock;
90
+ actions?: Record<string, AgentScriptActionDefinition>;
91
+ system_instructions?: string;
92
+ }
93
+ /**
94
+ * Complete Agent Script Structure
95
+ * Following official Salesforce Agent Script format
96
+ */
97
+ export interface AgentScriptStructure {
98
+ config: AgentScriptConfig;
99
+ system: AgentScriptSystemBlock;
100
+ variables?: Record<string, AgentScriptVariable>;
101
+ language?: AgentScriptLanguageBlock;
102
+ start_agent?: AgentScriptTopicBlock;
103
+ [topicName: string]: unknown;
104
+ }
105
+ /**
106
+ * Agent Script Generation Options
107
+ */
108
+ export interface AgentScriptGenerationOptions {
109
+ includeComments?: boolean;
110
+ includeExamples?: boolean;
111
+ yamlIndent?: number;
112
+ generateVariables?: boolean;
113
+ includeLanguageConfig?: boolean;
114
+ }
115
+ /**
116
+ * Abstract interfaces for planner data structures
117
+ * These replace the Salesforce model dependencies
118
+ */
119
+ /**
120
+ * Represents a variable/attribute definition
121
+ */
122
+ export interface PlannerVariable {
123
+ Id?: string;
124
+ DeveloperName?: string;
125
+ parameterName?: string;
126
+ mappingType?: string;
127
+ description?: string;
128
+ }
129
+ /**
130
+ * Represents an action/function definition
131
+ */
132
+ export interface PlannerAction {
133
+ Id?: string;
134
+ DeveloperName?: string;
135
+ MasterLabel?: string;
136
+ Description?: string;
137
+ InvocationTarget?: string;
138
+ InvocationTargetType?: string;
139
+ Source?: string;
140
+ Metadata?: {
141
+ inputs?: Record<string, string>;
142
+ outputs?: Record<string, string | Record<string, unknown>>;
143
+ [key: string]: unknown;
144
+ };
145
+ }
146
+ /**
147
+ * Represents a topic/plugin definition
148
+ */
149
+ export interface PlannerTopic {
150
+ Id?: string;
151
+ DeveloperName?: string;
152
+ MasterLabel?: string;
153
+ Description?: string;
154
+ Scope?: string;
155
+ actions?: PlannerAction[];
156
+ Metadata?: {
157
+ description?: string;
158
+ scope?: string;
159
+ [key: string]: unknown;
160
+ };
161
+ }
162
+ /**
163
+ * Represents a planner definition
164
+ * This is the main input to the generator
165
+ */
166
+ export interface PlannerDefinition {
167
+ Id?: string;
168
+ MasterLabel?: string;
169
+ DeveloperName?: string;
170
+ topics?: PlannerTopic[];
171
+ actions?: PlannerAction[];
172
+ variables?: PlannerVariable[];
173
+ Metadata?: {
174
+ description?: string;
175
+ [key: string]: unknown;
176
+ };
177
+ }
178
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,MAAM,CAAA;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE;QACT,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;KAClC,CAAA;IACD,mBAAm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EAAE,MAAM,CAAA;QACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KACvB,CAAA;CACF"}
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Agent Script Types
3
+ * Based on Salesforce Agent Script Recipes
4
+ * @see https://developer.salesforce.com/sample-apps/agent-script-recipes/getting-started/overview
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Utilities Module Exports
3
+ */
4
+ export * from "./nameSanitizer";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,iBAAiB,CAAA"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Utilities Module Exports
3
+ */
4
+ export * from "./nameSanitizer";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,iBAAiB,CAAA"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Name Sanitization Utilities
3
+ * Provides functions to sanitize names for Agent Script compatibility
4
+ */
5
+ /**
6
+ * Clean developer name by removing ID suffix
7
+ * Removes pattern: underscore followed by alphanumeric ID (typically 15-18 chars)
8
+ * e.g., "MyAction_16ja0590c168ff0" -> "MyAction"
9
+ *
10
+ * @param name - The developer name to clean
11
+ * @returns Cleaned developer name without ID suffix
12
+ */
13
+ export declare function cleanDeveloperName(name: string): string;
14
+ /**
15
+ * Sanitize topic name for Agent Script
16
+ * Removes IDs and converts to valid identifier (alphanumeric + underscores)
17
+ *
18
+ * @param name - The topic name to sanitize
19
+ * @returns Sanitized topic name
20
+ */
21
+ export declare function sanitizeTopicName(name: string): string;
22
+ /**
23
+ * Sanitize action name for Agent Script
24
+ * Removes IDs and converts to valid identifier (alphanumeric + underscores)
25
+ *
26
+ * @param name - The action name to sanitize
27
+ * @returns Sanitized action name
28
+ */
29
+ export declare function sanitizeActionName(name: string): string;
30
+ //# sourceMappingURL=nameSanitizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nameSanitizer.d.ts","sourceRoot":"","sources":["../../src/utils/nameSanitizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA8BtD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA8BvD"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Name Sanitization Utilities
3
+ * Provides functions to sanitize names for Agent Script compatibility
4
+ */
5
+ /**
6
+ * Clean developer name by removing ID suffix
7
+ * Removes pattern: underscore followed by alphanumeric ID (typically 15-18 chars)
8
+ * e.g., "MyAction_16ja0590c168ff0" -> "MyAction"
9
+ *
10
+ * @param name - The developer name to clean
11
+ * @returns Cleaned developer name without ID suffix
12
+ */
13
+ export function cleanDeveloperName(name) {
14
+ return name.replace(/_[a-zA-Z0-9]{12,18}$/, "");
15
+ }
16
+ /**
17
+ * Sanitize topic name for Agent Script
18
+ * Removes IDs and converts to valid identifier (alphanumeric + underscores)
19
+ *
20
+ * @param name - The topic name to sanitize
21
+ * @returns Sanitized topic name
22
+ */
23
+ export function sanitizeTopicName(name) {
24
+ // Remove common ID patterns (e.g., __c, _12345, UUID-like patterns)
25
+ let cleaned = name
26
+ // Remove __c suffix
27
+ .replace(/__c$/i, "")
28
+ // Remove trailing IDs like _12345 or _abc123
29
+ .replace(/_[a-zA-Z0-9]{5,}$/i, "")
30
+ // Remove UUID-like patterns
31
+ .replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, "")
32
+ // Remove standalone numbers at the end
33
+ .replace(/_\d+$/g, "");
34
+ // Convert to valid identifier (alphanumeric + underscores only)
35
+ cleaned = cleaned.replace(/[^a-zA-Z0-9_]/g, "_");
36
+ // Remove multiple consecutive underscores
37
+ cleaned = cleaned.replace(/_+/g, "_");
38
+ // Remove leading/trailing underscores
39
+ cleaned = cleaned.replace(/^_+|_+$/g, "");
40
+ // Ensure it starts with a letter (add prefix if it doesn't)
41
+ if (cleaned && !/^[a-zA-Z]/.test(cleaned)) {
42
+ cleaned = "topic_" + cleaned;
43
+ }
44
+ return cleaned || "topic";
45
+ }
46
+ /**
47
+ * Sanitize action name for Agent Script
48
+ * Removes IDs and converts to valid identifier (alphanumeric + underscores)
49
+ *
50
+ * @param name - The action name to sanitize
51
+ * @returns Sanitized action name
52
+ */
53
+ export function sanitizeActionName(name) {
54
+ // Remove common ID patterns
55
+ let cleaned = name
56
+ // Remove __c suffix
57
+ .replace(/__c$/i, "")
58
+ // Remove trailing IDs like _12345 or _abc123
59
+ .replace(/_[a-zA-Z0-9]{5,}$/i, "")
60
+ // Remove UUID-like patterns
61
+ .replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, "")
62
+ // Remove standalone numbers at the end
63
+ .replace(/_\d+$/g, "");
64
+ // Convert to valid identifier (alphanumeric + underscores only)
65
+ cleaned = cleaned.replace(/[^a-zA-Z0-9_]/g, "_");
66
+ // Remove multiple consecutive underscores
67
+ cleaned = cleaned.replace(/_+/g, "_");
68
+ // Remove leading/trailing underscores
69
+ cleaned = cleaned.replace(/^_+|_+$/g, "");
70
+ // Ensure it starts with a letter (add prefix if it doesn't)
71
+ if (cleaned && !/^[a-zA-Z]/.test(cleaned)) {
72
+ cleaned = "action_" + cleaned;
73
+ }
74
+ return cleaned || "action";
75
+ }
76
+ //# sourceMappingURL=nameSanitizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nameSanitizer.js","sourceRoot":"","sources":["../../src/utils/nameSanitizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAA;AACjD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,oEAAoE;IACpE,IAAI,OAAO,GAAG,IAAI;QAChB,oBAAoB;SACnB,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;QACrB,6CAA6C;SAC5C,OAAO,CAAC,oBAAoB,EAAE,EAAE,CAAC;QAClC,4BAA4B;SAC3B,OAAO,CACN,gEAAgE,EAChE,EAAE,CACH;QACD,uCAAuC;SACtC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAExB,gEAAgE;IAChE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAA;IAEhD,0CAA0C;IAC1C,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IAErC,sCAAsC;IACtC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;IAEzC,4DAA4D;IAC5D,IAAI,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1C,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;IAC9B,CAAC;IAED,OAAO,OAAO,IAAI,OAAO,CAAA;AAC3B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,4BAA4B;IAC5B,IAAI,OAAO,GAAG,IAAI;QAChB,oBAAoB;SACnB,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;QACrB,6CAA6C;SAC5C,OAAO,CAAC,oBAAoB,EAAE,EAAE,CAAC;QAClC,4BAA4B;SAC3B,OAAO,CACN,gEAAgE,EAChE,EAAE,CACH;QACD,uCAAuC;SACtC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAExB,gEAAgE;IAChE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAA;IAEhD,0CAA0C;IAC1C,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IAErC,sCAAsC;IACtC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;IAEzC,4DAA4D;IAC5D,IAAI,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1C,OAAO,GAAG,SAAS,GAAG,OAAO,CAAA;IAC/B,CAAC;IAED,OAAO,OAAO,IAAI,QAAQ,CAAA;AAC5B,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Validation utilities for AgentScript Generator
3
+ * Provides input validation and error handling
4
+ */
5
+ import type { PlannerDefinition, PlannerTopic, PlannerAction } from "./types";
6
+ /**
7
+ * Custom error class for validation errors
8
+ */
9
+ export declare class ValidationError extends Error {
10
+ readonly field?: string | undefined;
11
+ constructor(message: string, field?: string | undefined);
12
+ }
13
+ /**
14
+ * Validates a PlannerDefinition object
15
+ * @param planner - The planner definition to validate
16
+ * @throws {ValidationError} If validation fails
17
+ */
18
+ export declare function validatePlannerDefinition(planner: unknown): asserts planner is PlannerDefinition;
19
+ /**
20
+ * Validates a PlannerTopic object
21
+ * @param topic - The topic to validate
22
+ * @param index - Optional index for error reporting
23
+ * @throws {ValidationError} If validation fails
24
+ */
25
+ export declare function validateTopic(topic: unknown, index?: number): asserts topic is PlannerTopic;
26
+ /**
27
+ * Validates a PlannerAction object
28
+ * @param action - The action to validate
29
+ * @param topicIndex - Optional topic index for error reporting
30
+ * @param actionIndex - Optional action index for error reporting
31
+ * @throws {ValidationError} If validation fails
32
+ */
33
+ export declare function validateAction(action: unknown, topicIndex?: number, actionIndex?: number): asserts action is PlannerAction;
34
+ /**
35
+ * Sanitizes a string to ensure it's safe for use in YAML
36
+ * @param value - The string to sanitize
37
+ * @returns Sanitized string
38
+ */
39
+ export declare function sanitizeString(value: string): string;
40
+ /**
41
+ * Validates YAML indentation value
42
+ * @param indent - The indentation value to validate
43
+ * @returns Valid indentation value (defaults to 4)
44
+ */
45
+ export declare function validateIndent(indent: unknown): number;
46
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE7E;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;aACK,KAAK,CAAC,EAAE,MAAM;gBAA/C,OAAO,EAAE,MAAM,EAAkB,KAAK,CAAC,EAAE,MAAM,YAAA;CAK5D;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,OAAO,IAAI,iBAAiB,CAmCtC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,EACd,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,KAAK,IAAI,YAAY,CA8B/B;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,OAAO,EACf,UAAU,CAAC,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,IAAI,aAAa,CAwBjC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOpD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAWtD"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Validation utilities for AgentScript Generator
3
+ * Provides input validation and error handling
4
+ */
5
+ /**
6
+ * Custom error class for validation errors
7
+ */
8
+ export class ValidationError extends Error {
9
+ constructor(message, field) {
10
+ super(message);
11
+ this.field = field;
12
+ this.name = "ValidationError";
13
+ Object.setPrototypeOf(this, ValidationError.prototype);
14
+ }
15
+ }
16
+ /**
17
+ * Validates a PlannerDefinition object
18
+ * @param planner - The planner definition to validate
19
+ * @throws {ValidationError} If validation fails
20
+ */
21
+ export function validatePlannerDefinition(planner) {
22
+ if (!planner || typeof planner !== "object") {
23
+ throw new ValidationError("Planner definition must be an object", "planner");
24
+ }
25
+ const p = planner;
26
+ // Validate required fields
27
+ if (!p.DeveloperName && !p.MasterLabel) {
28
+ throw new ValidationError("Planner must have either DeveloperName or MasterLabel", "DeveloperName|MasterLabel");
29
+ }
30
+ // Validate topics if provided
31
+ if (p.topics !== undefined) {
32
+ if (!Array.isArray(p.topics)) {
33
+ throw new ValidationError("Topics must be an array", "topics");
34
+ }
35
+ p.topics.forEach((topic, index) => {
36
+ validateTopic(topic, index);
37
+ });
38
+ }
39
+ // Validate variables if provided
40
+ if (p.variables !== undefined) {
41
+ if (!Array.isArray(p.variables)) {
42
+ throw new ValidationError("Variables must be an array", "variables");
43
+ }
44
+ }
45
+ }
46
+ /**
47
+ * Validates a PlannerTopic object
48
+ * @param topic - The topic to validate
49
+ * @param index - Optional index for error reporting
50
+ * @throws {ValidationError} If validation fails
51
+ */
52
+ export function validateTopic(topic, index) {
53
+ if (!topic || typeof topic !== "object") {
54
+ throw new ValidationError(`Topic at index ${index ?? "unknown"} must be an object`, `topics[${index ?? "?"}]`);
55
+ }
56
+ const t = topic;
57
+ if (!t.DeveloperName && !t.MasterLabel) {
58
+ throw new ValidationError(`Topic at index ${index ?? "unknown"} must have either DeveloperName or MasterLabel`, `topics[${index ?? "?"}].DeveloperName|MasterLabel`);
59
+ }
60
+ // Validate actions if provided
61
+ if (t.actions !== undefined) {
62
+ if (!Array.isArray(t.actions)) {
63
+ throw new ValidationError(`Topic actions at index ${index ?? "unknown"} must be an array`, `topics[${index ?? "?"}].actions`);
64
+ }
65
+ t.actions.forEach((action, actionIndex) => {
66
+ validateAction(action, index, actionIndex);
67
+ });
68
+ }
69
+ }
70
+ /**
71
+ * Validates a PlannerAction object
72
+ * @param action - The action to validate
73
+ * @param topicIndex - Optional topic index for error reporting
74
+ * @param actionIndex - Optional action index for error reporting
75
+ * @throws {ValidationError} If validation fails
76
+ */
77
+ export function validateAction(action, topicIndex, actionIndex) {
78
+ if (!action || typeof action !== "object") {
79
+ const path = topicIndex !== undefined && actionIndex !== undefined
80
+ ? `topics[${topicIndex}].actions[${actionIndex}]`
81
+ : "action";
82
+ throw new ValidationError(`${path} must be an object`, path);
83
+ }
84
+ const a = action;
85
+ if (!a.DeveloperName && !a.MasterLabel) {
86
+ const path = topicIndex !== undefined && actionIndex !== undefined
87
+ ? `topics[${topicIndex}].actions[${actionIndex}]`
88
+ : "action";
89
+ throw new ValidationError(`${path} must have either DeveloperName or MasterLabel`, `${path}.DeveloperName|MasterLabel`);
90
+ }
91
+ // Warn if no InvocationTarget (but don't fail validation)
92
+ if (!a.InvocationTarget && !a.InvocationTargetType) {
93
+ // This is acceptable - will use default
94
+ }
95
+ }
96
+ /**
97
+ * Sanitizes a string to ensure it's safe for use in YAML
98
+ * @param value - The string to sanitize
99
+ * @returns Sanitized string
100
+ */
101
+ export function sanitizeString(value) {
102
+ if (typeof value !== "string") {
103
+ return String(value);
104
+ }
105
+ // Remove null bytes and other control characters except newlines
106
+ return value.replace(/[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F]/g, "");
107
+ }
108
+ /**
109
+ * Validates YAML indentation value
110
+ * @param indent - The indentation value to validate
111
+ * @returns Valid indentation value (defaults to 4)
112
+ */
113
+ export function validateIndent(indent) {
114
+ if (typeof indent === "number") {
115
+ if (indent < 1 || indent > 10) {
116
+ console.warn(`[AgentScript] Invalid indent value ${indent}. Using default: 4`);
117
+ return 4;
118
+ }
119
+ return indent;
120
+ }
121
+ return 4;
122
+ }
123
+ //# sourceMappingURL=validation.js.map