@sembix/cli 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,34 +1,165 @@
1
1
  /**
2
- * Parse workflow inputs from JSON string and detect format.
3
- * Supports two formats:
4
- * 1. Simple key-value object: {"key": "value"} -> maps to inputVariables (deprecated)
5
- * 2. InitialInstructions array: [{"id": "x", "instruction": "value"}] -> maps to initialInstructions
6
- * 3. Complete StartWorkflowConfiguration object with initialInstructions or workspaceMetadata
2
+ * Parse workflow inputs from JSON string with automatic format detection.
7
3
  *
8
- * @param inputsJson - JSON string containing workflow inputs
9
- * @returns StartWorkflowConfiguration object ready to send to API
4
+ * Supports three input formats:
5
+ * 1. ID-based array: [{"id": "var_123", "instruction": "value"}]
6
+ * 2. Name-based object: {"repositoryUrl": "value"} (requires template)
7
+ * 3. Complete configuration: {"initialInstructions": [...], "workspaceMetadata": {...}}
8
+ *
9
+ * @param options.inputsJson - JSON string containing workflow inputs
10
+ * @param options.template - Template instructions (required for name-based format)
11
+ * @returns StartWorkflowConfiguration with initialInstructions
10
12
  * @throws Error if JSON is invalid or format is unrecognized
11
13
  */
12
- export function parseWorkflowInputs(inputsJson) {
14
+ export function parseWorkflowInputs(options) {
15
+ const { inputsJson, template, validate = false } = options;
13
16
  const parsed = JSON.parse(inputsJson);
14
- // Detect format by structure
17
+ let initialInstructions;
18
+ let preserveFullConfig = false;
19
+ let fullConfig;
20
+ // Format 1: Array → ID-based initialInstructions
15
21
  if (Array.isArray(parsed)) {
16
- // Array format → InitialInstructions
17
- return {
18
- initialInstructions: parsed
19
- };
20
- }
21
- else if (typeof parsed === 'object' && parsed !== null) {
22
- // Check if it's already a complete StartWorkflowConfiguration
23
- if ('initialInstructions' in parsed || 'workspaceMetadata' in parsed || 'inputVariables' in parsed) {
24
- // Already in correct format
25
- return parsed;
22
+ initialInstructions = parsed;
23
+ }
24
+ // Validate object type before checking properties
25
+ else if (typeof parsed !== 'object' || parsed === null) {
26
+ throw new Error('Invalid input format. Expected object or array.');
27
+ }
28
+ // Format 2: Complete configuration (has config fields)
29
+ else if ('initialInstructions' in parsed || 'workspaceMetadata' in parsed) {
30
+ fullConfig = parsed;
31
+ initialInstructions = parsed.initialInstructions;
32
+ preserveFullConfig = true;
33
+ }
34
+ // Format 3: Name-based object (needs template resolution)
35
+ else {
36
+ if (!template || template.length === 0) {
37
+ throw new Error('Cannot resolve input variable names: name-based format requires workflow template.\n\n' +
38
+ 'Either:\n' +
39
+ ' 1. Use ID-based format: --inputs \'[{"id": "var_123", "instruction": "value"}]\'\n' +
40
+ ' 2. Run interactively to see input prompts\n\n' +
41
+ 'To see available IDs:\n' +
42
+ ' sembix workflow template show --project-id <id> --workflow-id <id>');
26
43
  }
27
- // Simple key-value object → Legacy inputVariables
28
- return {
29
- inputVariables: parsed
30
- };
44
+ // Resolve names to IDs
45
+ initialInstructions = resolveNames(parsed, template);
46
+ }
47
+ // Validate and normalize inputs if requested and template is available
48
+ if (validate && template && template.length > 0) {
49
+ initialInstructions = validateWorkflowInputs(initialInstructions, template);
50
+ }
51
+ // Build and return configuration
52
+ if (preserveFullConfig) {
53
+ // Preserve all fields from original config, update initialInstructions if present
54
+ if (initialInstructions) {
55
+ return {
56
+ ...fullConfig,
57
+ initialInstructions
58
+ };
59
+ }
60
+ return fullConfig;
61
+ }
62
+ return { initialInstructions };
63
+ }
64
+ /**
65
+ * Internal helper: Resolve input variable names to IDs using template.
66
+ *
67
+ * @param inputVariables - Object with input variable names as keys
68
+ * @param templateInstructions - Array of template instructions with id/name mappings
69
+ * @returns Array of InitialInstructions with resolved IDs
70
+ * @throws Error if input name not found in template
71
+ */
72
+ function resolveNames(inputVariables, templateInstructions) {
73
+ const resolvedInstructions = [];
74
+ const availableNames = templateInstructions.map(t => t.name).filter(Boolean);
75
+ for (const [inputName, inputValue] of Object.entries(inputVariables)) {
76
+ // Find matching template instruction by name (case-sensitive)
77
+ const matchingInstruction = templateInstructions.find(t => t.name === inputName);
78
+ if (!matchingInstruction) {
79
+ throw new Error(`Input variable name "${inputName}" not found in workflow template.\n\n` +
80
+ `Available input variables:\n` +
81
+ availableNames.map(name => ` - ${name}`).join('\n') +
82
+ '\n\n' +
83
+ 'To see full details:\n' +
84
+ ' sembix workflow template show --project-id <id> --workflow-id <id>');
85
+ }
86
+ // Create a full InitialInstructions object with all fields from template
87
+ // and the user-provided instruction value
88
+ resolvedInstructions.push({
89
+ id: matchingInstruction.id,
90
+ name: matchingInstruction.name,
91
+ description: matchingInstruction.description,
92
+ instruction: inputValue,
93
+ dataType: matchingInstruction.dataType,
94
+ isRequired: matchingInstruction.isRequired
95
+ });
96
+ }
97
+ return resolvedInstructions;
98
+ }
99
+ /**
100
+ * Validate workflow inputs against template requirements.
101
+ * Ensures required fields have values and data types are correct.
102
+ * Fills in optional fields with empty strings if not provided.
103
+ *
104
+ * @param instructions - Array of initial instructions to validate
105
+ * @param template - Template instructions with requirements
106
+ * @returns Validated and normalized instructions
107
+ * @throws Error if validation fails
108
+ */
109
+ export function validateWorkflowInputs(instructions, template) {
110
+ const validated = [];
111
+ const errors = [];
112
+ // Create map of provided instructions by ID
113
+ const providedMap = new Map(instructions.map(i => [i.id, i]));
114
+ // Iterate through template to validate all fields
115
+ for (const templateInstr of template) {
116
+ const provided = providedMap.get(templateInstr.id);
117
+ const value = provided?.instruction;
118
+ // Validate required fields
119
+ if (templateInstr.isRequired) {
120
+ if (value === undefined || value === null || value === '') {
121
+ errors.push(`Required input "${templateInstr.name}" is missing or empty`);
122
+ continue;
123
+ }
124
+ // Validate boolean fields
125
+ if (templateInstr.dataType === 'boolean') {
126
+ if (typeof value === 'boolean') {
127
+ // Convert boolean to string for API
128
+ validated.push({
129
+ ...templateInstr,
130
+ instruction: String(value)
131
+ });
132
+ }
133
+ else if (value === 'true' || value === 'false') {
134
+ validated.push({
135
+ ...templateInstr,
136
+ instruction: value
137
+ });
138
+ }
139
+ else {
140
+ errors.push(`Input "${templateInstr.name}" must be true or false (got: ${value})`);
141
+ }
142
+ continue;
143
+ }
144
+ }
145
+ // Handle optional fields - always include with empty string if not provided
146
+ if (!templateInstr.isRequired && (value === undefined || value === null)) {
147
+ validated.push({
148
+ ...templateInstr,
149
+ instruction: ''
150
+ });
151
+ continue;
152
+ }
153
+ // For provided values, pass through with template metadata
154
+ validated.push({
155
+ ...templateInstr,
156
+ instruction: value !== undefined ? value : ''
157
+ });
158
+ }
159
+ if (errors.length > 0) {
160
+ throw new Error('Input validation failed:\n' +
161
+ errors.map(e => ` - ${e}`).join('\n'));
31
162
  }
32
- throw new Error('Invalid input format. Expected object or array.');
163
+ return validated;
33
164
  }
34
165
  //# sourceMappingURL=input-parser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"input-parser.js","sourceRoot":"","sources":["../../src/utils/input-parser.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAAkB;IACpD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAEtC,6BAA6B;IAC7B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,qCAAqC;QACrC,OAAO;YACL,mBAAmB,EAAE,MAAM;SAC5B,CAAC;IACJ,CAAC;SAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACzD,8DAA8D;QAC9D,IAAI,qBAAqB,IAAI,MAAM,IAAI,mBAAmB,IAAI,MAAM,IAAI,gBAAgB,IAAI,MAAM,EAAE,CAAC;YACnG,4BAA4B;YAC5B,OAAO,MAAoC,CAAC;QAC9C,CAAC;QAED,kDAAkD;QAClD,OAAO;YACL,cAAc,EAAE,MAAM;SACvB,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;AACrE,CAAC"}
1
+ {"version":3,"file":"input-parser.js","sourceRoot":"","sources":["../../src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,CAAC;qBAAM,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;oBACjD,SAAS,CAAC,IAAI,CAAC;wBACb,GAAG,aAAa;wBAChB,WAAW,EAAE,KAAK;qBACnB,CAAC,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,IAAI,CACT,UAAU,aAAa,CAAC,IAAI,iCAAiC,KAAK,GAAG,CACtE,CAAC;gBACJ,CAAC;gBACD,SAAS;YACX,CAAC;QACH,CAAC;QAED,4EAA4E;QAC5E,IAAI,CAAC,aAAa,CAAC,UAAU,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC,EAAE,CAAC;YACzE,SAAS,CAAC,IAAI,CAAC;gBACb,GAAG,aAAa;gBAChB,WAAW,EAAE,EAAE;aAChB,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QAED,2DAA2D;QAC3D,SAAS,CAAC,IAAI,CAAC;YACb,GAAG,aAAa;YAChB,WAAW,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;SAC9C,CAAC,CAAC;IACL,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,4BAA4B;YAC5B,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CACvC,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sembix/cli",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "CLI tool for managing Sembix products",
5
5
  "type": "module",
6
6
  "bin": {
Binary file