Update app
Browse files
app.py
CHANGED
|
@@ -246,6 +246,42 @@ def parse_js_object(js_obj_str):
|
|
| 246 |
print(f"Warning: Could not parse parameters '{js_obj_str}': {e}")
|
| 247 |
return {}
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
def convert_to_n8n_json(typescript_code):
|
| 250 |
"""Convert TypeScript DSL to n8n JSON format"""
|
| 251 |
|
|
@@ -258,23 +294,34 @@ def convert_to_n8n_json(typescript_code):
|
|
| 258 |
if name_match:
|
| 259 |
workflow_name = name_match.group(1)
|
| 260 |
|
| 261 |
-
# Extract node definitions
|
| 262 |
-
node_pattern = r'const\s+(\w+)\s*=\s*workflow\.add\([\'"]([^\'\"]+)[\'"]
|
| 263 |
-
node_matches = re.finditer(node_pattern, typescript_code)
|
| 264 |
|
| 265 |
node_map = {} # variable name -> node id
|
| 266 |
position_y = 250
|
| 267 |
position_x = 300
|
| 268 |
|
| 269 |
-
for
|
| 270 |
var_name = match.group(1)
|
| 271 |
node_type = match.group(2)
|
| 272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
# Convert JavaScript object notation to valid JSON
|
| 275 |
parameters = parse_js_object(params_str)
|
| 276 |
|
| 277 |
-
node_id = str(
|
| 278 |
node_map[var_name] = node_id
|
| 279 |
|
| 280 |
nodes.append({
|
|
|
|
| 246 |
print(f"Warning: Could not parse parameters '{js_obj_str}': {e}")
|
| 247 |
return {}
|
| 248 |
|
| 249 |
+
def extract_balanced_braces(text, start_pos):
|
| 250 |
+
"""Extract content within balanced braces starting at start_pos"""
|
| 251 |
+
if start_pos >= len(text) or text[start_pos] != '{':
|
| 252 |
+
return None
|
| 253 |
+
|
| 254 |
+
brace_count = 0
|
| 255 |
+
in_string = False
|
| 256 |
+
escape_next = False
|
| 257 |
+
string_char = None
|
| 258 |
+
|
| 259 |
+
for i in range(start_pos, len(text)):
|
| 260 |
+
char = text[i]
|
| 261 |
+
|
| 262 |
+
if escape_next:
|
| 263 |
+
escape_next = False
|
| 264 |
+
continue
|
| 265 |
+
|
| 266 |
+
if char == '\\':
|
| 267 |
+
escape_next = True
|
| 268 |
+
continue
|
| 269 |
+
|
| 270 |
+
if char in ('"', "'") and not in_string:
|
| 271 |
+
in_string = True
|
| 272 |
+
string_char = char
|
| 273 |
+
elif char == string_char and in_string:
|
| 274 |
+
in_string = False
|
| 275 |
+
string_char = None
|
| 276 |
+
elif char == '{' and not in_string:
|
| 277 |
+
brace_count += 1
|
| 278 |
+
elif char == '}' and not in_string:
|
| 279 |
+
brace_count -= 1
|
| 280 |
+
if brace_count == 0:
|
| 281 |
+
return text[start_pos:i+1]
|
| 282 |
+
|
| 283 |
+
return None
|
| 284 |
+
|
| 285 |
def convert_to_n8n_json(typescript_code):
|
| 286 |
"""Convert TypeScript DSL to n8n JSON format"""
|
| 287 |
|
|
|
|
| 294 |
if name_match:
|
| 295 |
workflow_name = name_match.group(1)
|
| 296 |
|
| 297 |
+
# Extract node definitions - find all workflow.add() calls
|
| 298 |
+
node_pattern = r'const\s+(\w+)\s*=\s*workflow\.add\([\'"]([^\'\"]+)[\'"]'
|
|
|
|
| 299 |
|
| 300 |
node_map = {} # variable name -> node id
|
| 301 |
position_y = 250
|
| 302 |
position_x = 300
|
| 303 |
|
| 304 |
+
for match in re.finditer(node_pattern, typescript_code):
|
| 305 |
var_name = match.group(1)
|
| 306 |
node_type = match.group(2)
|
| 307 |
+
|
| 308 |
+
# Look for parameters after the node type
|
| 309 |
+
params_str = "{}"
|
| 310 |
+
remaining_text = typescript_code[match.end():]
|
| 311 |
+
|
| 312 |
+
# Check if there's a comma followed by parameters
|
| 313 |
+
comma_match = re.match(r'\s*,\s*', remaining_text)
|
| 314 |
+
if comma_match:
|
| 315 |
+
param_start = match.end() + comma_match.end()
|
| 316 |
+
if param_start < len(typescript_code) and typescript_code[param_start] == '{':
|
| 317 |
+
params_str = extract_balanced_braces(typescript_code, param_start)
|
| 318 |
+
if params_str is None:
|
| 319 |
+
params_str = "{}"
|
| 320 |
|
| 321 |
# Convert JavaScript object notation to valid JSON
|
| 322 |
parameters = parse_js_object(params_str)
|
| 323 |
|
| 324 |
+
node_id = str(len(nodes))
|
| 325 |
node_map[var_name] = node_id
|
| 326 |
|
| 327 |
nodes.append({
|