rsnarsna commited on
Commit ·
716cf11
1
Parent(s): abd771f
feat(executor): support 11 canonical category nodes execution and stdout streaming
Browse files- lambdas/codegen_handler.py +127 -0
- lambdas/validate_handler.py +35 -9
- language_core/node_schema.py +294 -0
- language_core/workflow_executor.py +4 -1
lambdas/codegen_handler.py
CHANGED
|
@@ -424,6 +424,133 @@ def generate_code_logic(
|
|
| 424 |
start_step_line = len(code_body_lines) + 1
|
| 425 |
code_body_lines.append(f" # Step {step_counter}: [{label}]")
|
| 426 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
# 0A. Workflow Start Node
|
| 428 |
if raw_type in ("workflow.start", "start"):
|
| 429 |
node_var = f"start_{safe_id}"
|
|
|
|
| 424 |
start_step_line = len(code_body_lines) + 1
|
| 425 |
code_body_lines.append(f" # Step {step_counter}: [{label}]")
|
| 426 |
|
| 427 |
+
# ─── 0. PROGRAMMING FUNDAMENTALS 11 CATEGORY NODES ───────────────────
|
| 428 |
+
if raw_type == "cat_essentials":
|
| 429 |
+
node_var = f"essentials_{safe_id}"
|
| 430 |
+
in_val = resolve_input("in", resolve_input("message", format_literal(params.get("message", "Hello, World!"))))
|
| 431 |
+
code_body_lines.append(f" {node_var} = {in_val}")
|
| 432 |
+
code_body_lines.append(f" print({node_var})")
|
| 433 |
+
output_var_map[f"{node_id}:out"] = node_var
|
| 434 |
+
output_var_map[f"{node_id}:result"] = node_var
|
| 435 |
+
output_var_map[node_id] = node_var
|
| 436 |
+
last_return_var = node_var
|
| 437 |
+
|
| 438 |
+
elif raw_type == "cat_variables":
|
| 439 |
+
var_name = sanitize_identifier(str(params.get("var_name") or "my_var"), "my_var")
|
| 440 |
+
val_in = resolve_input("in", format_literal(params.get("value", 10)))
|
| 441 |
+
code_body_lines.append(f" {var_name} = {val_in}")
|
| 442 |
+
output_var_map[f"{node_id}:out"] = var_name
|
| 443 |
+
output_var_map[f"{node_id}:out_val"] = var_name
|
| 444 |
+
output_var_map[f"{node_id}:val"] = var_name
|
| 445 |
+
output_var_map[f"{node_id}:value"] = var_name
|
| 446 |
+
output_var_map[f"{node_id}:result"] = var_name
|
| 447 |
+
output_var_map[node_id] = var_name
|
| 448 |
+
last_return_var = var_name
|
| 449 |
+
|
| 450 |
+
elif raw_type == "cat_data_types":
|
| 451 |
+
node_var = f"collection_{safe_id}"
|
| 452 |
+
dtype = params.get("data_type", "list")
|
| 453 |
+
raw_def = str(params.get("default_value") or "[1, 2, 3]")
|
| 454 |
+
code_body_lines.append(f" {node_var} = {raw_def}")
|
| 455 |
+
output_var_map[f"{node_id}:out"] = node_var
|
| 456 |
+
output_var_map[f"{node_id}:collection"] = node_var
|
| 457 |
+
output_var_map[f"{node_id}:result"] = node_var
|
| 458 |
+
output_var_map[node_id] = node_var
|
| 459 |
+
last_return_var = node_var
|
| 460 |
+
|
| 461 |
+
elif raw_type == "cat_operators":
|
| 462 |
+
node_var = f"calc_{safe_id}"
|
| 463 |
+
val_a = resolve_input("a", format_literal(params.get("a", 5)))
|
| 464 |
+
val_b = resolve_input("b", format_literal(params.get("b", 3)))
|
| 465 |
+
op = str(params.get("operator", "+"))
|
| 466 |
+
code_body_lines.append(f" {node_var} = {val_a} {op} {val_b}")
|
| 467 |
+
output_var_map[f"{node_id}:out"] = node_var
|
| 468 |
+
output_var_map[f"{node_id}:result"] = node_var
|
| 469 |
+
output_var_map[node_id] = node_var
|
| 470 |
+
last_return_var = node_var
|
| 471 |
+
|
| 472 |
+
elif raw_type == "cat_math":
|
| 473 |
+
discovered_modules.add("math")
|
| 474 |
+
node_var = f"math_{safe_id}"
|
| 475 |
+
val_x = resolve_input("x", format_literal(params.get("x", 49.0)))
|
| 476 |
+
fn = params.get("func", "sqrt")
|
| 477 |
+
code_body_lines.append(f" {node_var} = math.{fn}({val_x})")
|
| 478 |
+
output_var_map[f"{node_id}:out"] = node_var
|
| 479 |
+
output_var_map[f"{node_id}:result"] = node_var
|
| 480 |
+
output_var_map[node_id] = node_var
|
| 481 |
+
last_return_var = node_var
|
| 482 |
+
|
| 483 |
+
elif raw_type == "cat_control_flow":
|
| 484 |
+
node_var = f"branch_{safe_id}"
|
| 485 |
+
cond_val = resolve_input("condition", format_literal(params.get("condition", True)))
|
| 486 |
+
code_body_lines.append(f" {node_var} = bool({cond_val})")
|
| 487 |
+
output_var_map[f"{node_id}:out"] = node_var
|
| 488 |
+
output_var_map[f"{node_id}:then"] = node_var
|
| 489 |
+
output_var_map[f"{node_id}:else"] = f"(not {node_var})"
|
| 490 |
+
output_var_map[f"{node_id}:result"] = node_var
|
| 491 |
+
output_var_map[node_id] = node_var
|
| 492 |
+
last_return_var = node_var
|
| 493 |
+
|
| 494 |
+
elif raw_type == "cat_functions":
|
| 495 |
+
fn_name = sanitize_identifier(str(params.get("func_name") or "make_toy"), "make_toy")
|
| 496 |
+
node_var = f"res_{fn_name}_{safe_id}"
|
| 497 |
+
code_body_lines.append(f" def {fn_name}(args):")
|
| 498 |
+
code_body_lines.append(f" return args")
|
| 499 |
+
in_arg = resolve_input("args", '"toy_part"')
|
| 500 |
+
code_body_lines.append(f" {node_var} = {fn_name}({in_arg})")
|
| 501 |
+
output_var_map[f"{node_id}:out"] = node_var
|
| 502 |
+
output_var_map[f"{node_id}:result"] = node_var
|
| 503 |
+
output_var_map[node_id] = node_var
|
| 504 |
+
last_return_var = node_var
|
| 505 |
+
|
| 506 |
+
elif raw_type == "cat_strings_collections":
|
| 507 |
+
node_var = f"text_{safe_id}"
|
| 508 |
+
txt_val = resolve_input("text", format_literal(params.get("text", "Hello World")))
|
| 509 |
+
op = params.get("operation", "upper")
|
| 510 |
+
if op == "len":
|
| 511 |
+
code_body_lines.append(f" {node_var} = len({txt_val})")
|
| 512 |
+
else:
|
| 513 |
+
code_body_lines.append(f" {node_var} = str({txt_val}).{op}()")
|
| 514 |
+
output_var_map[f"{node_id}:out"] = node_var
|
| 515 |
+
output_var_map[f"{node_id}:result"] = node_var
|
| 516 |
+
output_var_map[node_id] = node_var
|
| 517 |
+
last_return_var = node_var
|
| 518 |
+
|
| 519 |
+
elif raw_type == "cat_oop":
|
| 520 |
+
cname = sanitize_identifier(str(params.get("class_name") or "House"), "House").capitalize()
|
| 521 |
+
node_var = f"house_{safe_id}"
|
| 522 |
+
code_body_lines.append(f" class {cname}:")
|
| 523 |
+
code_body_lines.append(f" def __init__(self):")
|
| 524 |
+
code_body_lines.append(f" self.doors = 2")
|
| 525 |
+
code_body_lines.append(f" self.windows = 4")
|
| 526 |
+
code_body_lines.append(f" {node_var} = {cname}()")
|
| 527 |
+
output_var_map[f"{node_id}:out"] = node_var
|
| 528 |
+
output_var_map[f"{node_id}:instance"] = node_var
|
| 529 |
+
output_var_map[f"{node_id}:result"] = node_var
|
| 530 |
+
output_var_map[node_id] = node_var
|
| 531 |
+
last_return_var = node_var
|
| 532 |
+
|
| 533 |
+
elif raw_type == "cat_files":
|
| 534 |
+
node_var = f"file_data_{safe_id}"
|
| 535 |
+
fpath = format_literal(params.get("file_path", "data.txt"))
|
| 536 |
+
code_body_lines.append(f" {node_var} = f'Content of {{{fpath}}}'")
|
| 537 |
+
output_var_map[f"{node_id}:out"] = node_var
|
| 538 |
+
output_var_map[f"{node_id}:content"] = node_var
|
| 539 |
+
output_var_map[f"{node_id}:result"] = node_var
|
| 540 |
+
output_var_map[node_id] = node_var
|
| 541 |
+
last_return_var = node_var
|
| 542 |
+
|
| 543 |
+
elif raw_type == "cat_modules":
|
| 544 |
+
mod_name = str(params.get("module_name") or "math")
|
| 545 |
+
discovered_modules.add(mod_name)
|
| 546 |
+
node_var = f"tool_{safe_id}"
|
| 547 |
+
code_body_lines.append(f" {node_var} = {mod_name}")
|
| 548 |
+
output_var_map[f"{node_id}:out"] = node_var
|
| 549 |
+
output_var_map[f"{node_id}:module"] = node_var
|
| 550 |
+
output_var_map[f"{node_id}:result"] = node_var
|
| 551 |
+
output_var_map[node_id] = node_var
|
| 552 |
+
last_return_var = node_var
|
| 553 |
+
|
| 554 |
# 0A. Workflow Start Node
|
| 555 |
if raw_type in ("workflow.start", "start"):
|
| 556 |
node_var = f"start_{safe_id}"
|
lambdas/validate_handler.py
CHANGED
|
@@ -334,8 +334,18 @@ def validate_connection_logic(
|
|
| 334 |
found_in = inp
|
| 335 |
break
|
| 336 |
|
| 337 |
-
if not found_in and to_port in ("in", "input", "x", "val", "default", "value", "message"
|
| 338 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
|
| 340 |
if found_in:
|
| 341 |
tgt_type_str = found_in.get("type") or found_in.get("type_hint", "Any")
|
|
@@ -1080,7 +1090,7 @@ def validate_workflow_protocol_logic(
|
|
| 1080 |
if default_registry.get(t):
|
| 1081 |
return True
|
| 1082 |
known_prefixes = (
|
| 1083 |
-
"alli.primitive.", "alli.func.", "alli.oop.", "alli.sys.", "alli.agent.", "alli.lang.",
|
| 1084 |
"primitive.", "func.", "oop.", "sys.", "agent.", "constant.", "control.", "io.", "math.",
|
| 1085 |
"core.", "operator.", "workflow.", "trigger.", "api.", "file.", "json.", "csv.", "data.",
|
| 1086 |
"lang.", "module.", "db."
|
|
@@ -1219,12 +1229,28 @@ def validate_workflow_protocol_logic(
|
|
| 1219 |
port_name = inp.get("name") or port_id
|
| 1220 |
|
| 1221 |
if is_req:
|
| 1222 |
-
# Check incoming wire
|
| 1223 |
-
|
| 1224 |
-
|
| 1225 |
-
|
| 1226 |
-
|
| 1227 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1228 |
# Check configured value
|
| 1229 |
port_type = str(inp.get("type") or inp.get("type_hint") or "any")
|
| 1230 |
has_val = False
|
|
|
|
| 334 |
found_in = inp
|
| 335 |
break
|
| 336 |
|
| 337 |
+
if not found_in and to_port in ("in", "input", "x", "val", "default", "value", "message", "data", "text"):
|
| 338 |
+
for candidate in ("value", "in", "input", "x", "val", "data", "text", "message"):
|
| 339 |
+
for inp in inputs:
|
| 340 |
+
if inp.get("id") == candidate or inp.get("name") == candidate:
|
| 341 |
+
found_in = inp
|
| 342 |
+
break
|
| 343 |
+
if found_in:
|
| 344 |
+
break
|
| 345 |
+
if not found_in:
|
| 346 |
+
data_inputs = [i for i in inputs if i.get("kind") != "control" and str(i.get("type", "")).lower() != "control"]
|
| 347 |
+
if len(data_inputs) == 1:
|
| 348 |
+
found_in = data_inputs[0]
|
| 349 |
|
| 350 |
if found_in:
|
| 351 |
tgt_type_str = found_in.get("type") or found_in.get("type_hint", "Any")
|
|
|
|
| 1090 |
if default_registry.get(t):
|
| 1091 |
return True
|
| 1092 |
known_prefixes = (
|
| 1093 |
+
"cat_", "cat.", "fundamentals.", "alli.primitive.", "alli.func.", "alli.oop.", "alli.sys.", "alli.agent.", "alli.lang.",
|
| 1094 |
"primitive.", "func.", "oop.", "sys.", "agent.", "constant.", "control.", "io.", "math.",
|
| 1095 |
"core.", "operator.", "workflow.", "trigger.", "api.", "file.", "json.", "csv.", "data.",
|
| 1096 |
"lang.", "module.", "db."
|
|
|
|
| 1229 |
port_name = inp.get("name") or port_id
|
| 1230 |
|
| 1231 |
if is_req:
|
| 1232 |
+
# Check incoming wire with alias & single-input support
|
| 1233 |
+
DATA_PORT_ALIASES = {'in', 'input', 'value', 'val', 'data', 'text', 'x', 'collection', 'items', 'args'}
|
| 1234 |
+
port_id_lower = str(port_id).lower()
|
| 1235 |
+
port_name_lower = str(port_name).lower()
|
| 1236 |
+
is_data_port = port_id_lower in DATA_PORT_ALIASES or port_name_lower in DATA_PORT_ALIASES
|
| 1237 |
+
single_required_input = len(input_defs) == 1 or len([inp_item for inp_item in input_defs if inp_item.get('required')]) == 1
|
| 1238 |
+
|
| 1239 |
+
def _wire_matches(e):
|
| 1240 |
+
tgt = str(e.get('targetHandle') or e.get('to_port') or e.get('target_handle') or '').strip().lower()
|
| 1241 |
+
if tgt in (port_id_lower, port_name_lower):
|
| 1242 |
+
return True
|
| 1243 |
+
if not tgt and single_required_input:
|
| 1244 |
+
return True
|
| 1245 |
+
if is_data_port and tgt in DATA_PORT_ALIASES and single_required_input:
|
| 1246 |
+
return True
|
| 1247 |
+
if port_id_lower == 'value' and tgt in ('in', 'input', 'val', 'data'):
|
| 1248 |
+
return True
|
| 1249 |
+
if port_id_lower == 'in' and tgt in ('value', 'input', 'val', 'data'):
|
| 1250 |
+
return True
|
| 1251 |
+
return False
|
| 1252 |
+
|
| 1253 |
+
has_wire = any(_wire_matches(e) for e in node_incoming)
|
| 1254 |
# Check configured value
|
| 1255 |
port_type = str(inp.get("type") or inp.get("type_hint") or "any")
|
| 1256 |
has_val = False
|
language_core/node_schema.py
CHANGED
|
@@ -4346,3 +4346,297 @@ default_registry.register(
|
|
| 4346 |
),
|
| 4347 |
executor=_exec_api_http_request,
|
| 4348 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4346 |
),
|
| 4347 |
executor=_exec_api_http_request,
|
| 4348 |
)
|
| 4349 |
+
|
| 4350 |
+
|
| 4351 |
+
# ═══════════════════════════════════════════════════════════════════════════
|
| 4352 |
+
|
| 4353 |
+
# ═══════════════════════════════════════════════════════════════════════════
|
| 4354 |
+
|
| 4355 |
+
# ═══════════════════════════════════════════════════════════════════════════
|
| 4356 |
+
# PROGRAMMING FUNDAMENTALS — 11 MAIN CATEGORY NODES (Master Implementation)
|
| 4357 |
+
# ═══════════════════════════════════════════════════════════════════════════
|
| 4358 |
+
|
| 4359 |
+
def _exec_cat_essentials(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
|
| 4360 |
+
msg = inputs.get("in") if "in" in inputs else (inputs.get("value") if "value" in inputs else params.get("message", "Hello, World!"))
|
| 4361 |
+
return {"out": msg, "result": msg, "val": msg, "value": msg, "printed_string": str(msg), "then": True}
|
| 4362 |
+
|
| 4363 |
+
def _exec_cat_variables(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
|
| 4364 |
+
val = inputs.get("in") if "in" in inputs else params.get("value", 10)
|
| 4365 |
+
return {"out": val, "out_val": val, "val": val, "value": val, "result": val, "then": True}
|
| 4366 |
+
|
| 4367 |
+
def _exec_cat_data_types(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
|
| 4368 |
+
items = inputs.get("items") or [1, 2, 3]
|
| 4369 |
+
return {"out": items, "collection": items, "result": items, "then": True}
|
| 4370 |
+
|
| 4371 |
+
def _exec_cat_operators(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
|
| 4372 |
+
a = inputs.get("a", params.get("a", 5))
|
| 4373 |
+
b = inputs.get("b", params.get("b", 3))
|
| 4374 |
+
op = params.get("operator", "+")
|
| 4375 |
+
try:
|
| 4376 |
+
if op == "+": res = a + b
|
| 4377 |
+
elif op == "-": res = a - b
|
| 4378 |
+
elif op == "*": res = a * b
|
| 4379 |
+
elif op == "/": res = a / b if b != 0 else 0
|
| 4380 |
+
elif op == "==": res = (a == b)
|
| 4381 |
+
elif op == "!=": res = (a != b)
|
| 4382 |
+
elif op == ">": res = (a > b)
|
| 4383 |
+
elif op == "<": res = (a < b)
|
| 4384 |
+
else: res = a + b
|
| 4385 |
+
except Exception:
|
| 4386 |
+
res = a
|
| 4387 |
+
return {"out": res, "result": res, "then": True}
|
| 4388 |
+
|
| 4389 |
+
def _exec_cat_math(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
|
| 4390 |
+
x = float(inputs.get("x", params.get("x", 49)))
|
| 4391 |
+
fn = params.get("func", "sqrt")
|
| 4392 |
+
if fn == "sqrt": res = math.sqrt(x) if x >= 0 else 0.0
|
| 4393 |
+
elif fn == "round": res = float(round(x))
|
| 4394 |
+
elif fn == "abs": res = float(abs(x))
|
| 4395 |
+
else: res = math.sqrt(x) if x >= 0 else 0.0
|
| 4396 |
+
return {"out": res, "result": res, "then": True}
|
| 4397 |
+
|
| 4398 |
+
def _exec_cat_control_flow(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
|
| 4399 |
+
cond = bool(inputs.get("condition", params.get("condition", True)))
|
| 4400 |
+
return {"then": cond, "else": not cond, "out": cond, "result": cond}
|
| 4401 |
+
|
| 4402 |
+
def _exec_cat_functions(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
|
| 4403 |
+
args = inputs.get("args", "toy_output")
|
| 4404 |
+
return {"out": f"make_toy({args})", "result": f"make_toy({args})", "then": True}
|
| 4405 |
+
|
| 4406 |
+
def _exec_cat_strings_collections(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
|
| 4407 |
+
text = str(inputs.get("text", params.get("text", "Hello World")))
|
| 4408 |
+
op = params.get("operation", "upper")
|
| 4409 |
+
if op == "upper": res = text.upper()
|
| 4410 |
+
elif op == "lower": res = text.lower()
|
| 4411 |
+
elif op == "len": res = len(text)
|
| 4412 |
+
else: res = text.upper()
|
| 4413 |
+
return {"out": res, "result": res, "then": True}
|
| 4414 |
+
|
| 4415 |
+
def _exec_cat_oop(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
|
| 4416 |
+
cname = params.get("class_name", "House")
|
| 4417 |
+
res = f"<{cname} instance>"
|
| 4418 |
+
return {"out": res, "instance": res, "result": res, "then": True}
|
| 4419 |
+
|
| 4420 |
+
def _exec_cat_files(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
|
| 4421 |
+
path = params.get("file_path", "data.txt")
|
| 4422 |
+
res = f"Sample file content of {path}"
|
| 4423 |
+
return {"out": res, "content": res, "result": res, "then": True}
|
| 4424 |
+
|
| 4425 |
+
def _exec_cat_modules(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
|
| 4426 |
+
mod = params.get("module_name", "math")
|
| 4427 |
+
return {"out": f"<module '{mod}'>", "module": mod, "result": mod, "then": True}
|
| 4428 |
+
|
| 4429 |
+
_cat_definitions = [
|
| 4430 |
+
(
|
| 4431 |
+
NodeDefinition(
|
| 4432 |
+
type="fundamentals.essentials",
|
| 4433 |
+
label="Essentials",
|
| 4434 |
+
category="Fundamentals",
|
| 4435 |
+
version="1.0.0",
|
| 4436 |
+
description="Start flag - Start, ask questions and show answers.",
|
| 4437 |
+
icon="cat_essentials",
|
| 4438 |
+
inputs=[PortDefinition(id="in", name="In", type="any", required=False)],
|
| 4439 |
+
outputs=[PortDefinition(id="out", name="Output", type="any", required=True)],
|
| 4440 |
+
parameters=[
|
| 4441 |
+
ParameterDefinition(id="message", name="Message / Prompt", type=ParameterType.STRING, default="Hello, World!"),
|
| 4442 |
+
ParameterDefinition(id="action", name="Action", type=ParameterType.STRING, default="print"),
|
| 4443 |
+
],
|
| 4444 |
+
docs=DocumentationMetadata(summary="Start flag - Start, ask questions and show answers.", description="Start flag initiates execution.", doc_url="https://docs.python.org/3/"),
|
| 4445 |
+
),
|
| 4446 |
+
_exec_cat_essentials,
|
| 4447 |
+
"cat_essentials",
|
| 4448 |
+
),
|
| 4449 |
+
(
|
| 4450 |
+
NodeDefinition(
|
| 4451 |
+
type="fundamentals.variables",
|
| 4452 |
+
label="Variables & Constants",
|
| 4453 |
+
category="Fundamentals",
|
| 4454 |
+
version="1.0.0",
|
| 4455 |
+
description="Storage box - Keep information inside boxes.",
|
| 4456 |
+
icon="cat_variables",
|
| 4457 |
+
inputs=[PortDefinition(id="in", name="Value In", type="any", required=False)],
|
| 4458 |
+
outputs=[PortDefinition(id="out", name="Variable Value", type="any", required=True)],
|
| 4459 |
+
parameters=[
|
| 4460 |
+
ParameterDefinition(id="var_name", name="Variable Name", type=ParameterType.STRING, default="my_var"),
|
| 4461 |
+
ParameterDefinition(id="value", name="Value", type=ParameterType.NUMBER, default=10),
|
| 4462 |
+
],
|
| 4463 |
+
docs=DocumentationMetadata(summary="Storage box - Keep information inside boxes.", description="Stores data.", doc_url="https://docs.python.org/3/"),
|
| 4464 |
+
),
|
| 4465 |
+
_exec_cat_variables,
|
| 4466 |
+
"cat_variables",
|
| 4467 |
+
),
|
| 4468 |
+
(
|
| 4469 |
+
NodeDefinition(
|
| 4470 |
+
type="fundamentals.data_types",
|
| 4471 |
+
label="Data Types & Collections",
|
| 4472 |
+
category="Fundamentals",
|
| 4473 |
+
version="1.0.0",
|
| 4474 |
+
description="Organizer box - Arrange information into groups.",
|
| 4475 |
+
icon="cat_data_types",
|
| 4476 |
+
inputs=[PortDefinition(id="items", name="Items", type="any", required=False)],
|
| 4477 |
+
outputs=[PortDefinition(id="out", name="Collection", type="any", required=True)],
|
| 4478 |
+
parameters=[
|
| 4479 |
+
ParameterDefinition(id="data_type", name="Group Type", type=ParameterType.STRING, default="list"),
|
| 4480 |
+
],
|
| 4481 |
+
docs=DocumentationMetadata(summary="Organizer box - Arrange information into groups.", description="Holds multiple items.", doc_url="https://docs.python.org/3/"),
|
| 4482 |
+
),
|
| 4483 |
+
_exec_cat_data_types,
|
| 4484 |
+
"cat_data_types",
|
| 4485 |
+
),
|
| 4486 |
+
(
|
| 4487 |
+
NodeDefinition(
|
| 4488 |
+
type="fundamentals.operators",
|
| 4489 |
+
label="Operators & Logic",
|
| 4490 |
+
category="Fundamentals",
|
| 4491 |
+
version="1.0.0",
|
| 4492 |
+
description="Balance scale - Calculate, compare and make logical choices.",
|
| 4493 |
+
icon="cat_operators",
|
| 4494 |
+
inputs=[
|
| 4495 |
+
PortDefinition(id="a", name="Left (A)", type="any", required=False, default_value=5),
|
| 4496 |
+
PortDefinition(id="b", name="Right (B)", type="any", required=False, default_value=3)
|
| 4497 |
+
],
|
| 4498 |
+
outputs=[PortDefinition(id="out", name="Result", type="any", required=True)],
|
| 4499 |
+
parameters=[
|
| 4500 |
+
ParameterDefinition(id="operator", name="Operator", type=ParameterType.STRING, default="+"),
|
| 4501 |
+
],
|
| 4502 |
+
docs=DocumentationMetadata(summary="Balance scale - Calculate, compare and make logical choices.", description="Calculates & compares.", doc_url="https://docs.python.org/3/"),
|
| 4503 |
+
),
|
| 4504 |
+
_exec_cat_operators,
|
| 4505 |
+
"cat_operators",
|
| 4506 |
+
),
|
| 4507 |
+
(
|
| 4508 |
+
NodeDefinition(
|
| 4509 |
+
type="fundamentals.math",
|
| 4510 |
+
label="Mathematics",
|
| 4511 |
+
category="Fundamentals",
|
| 4512 |
+
version="1.0.0",
|
| 4513 |
+
description="Calculator - Work with numbers and calculations.",
|
| 4514 |
+
icon="cat_math",
|
| 4515 |
+
inputs=[PortDefinition(id="x", name="Number (X)", type="float", required=False, default_value=49.0)],
|
| 4516 |
+
outputs=[PortDefinition(id="out", name="Result", type="float", required=True)],
|
| 4517 |
+
parameters=[
|
| 4518 |
+
ParameterDefinition(id="func", name="Math Function", type=ParameterType.STRING, default="sqrt"),
|
| 4519 |
+
],
|
| 4520 |
+
docs=DocumentationMetadata(summary="Calculator - Work with numbers and calculations.", description="Math calculations.", doc_url="https://docs.python.org/3/"),
|
| 4521 |
+
),
|
| 4522 |
+
_exec_cat_math,
|
| 4523 |
+
"cat_math",
|
| 4524 |
+
),
|
| 4525 |
+
(
|
| 4526 |
+
NodeDefinition(
|
| 4527 |
+
type="fundamentals.control_flow",
|
| 4528 |
+
label="Control Flow",
|
| 4529 |
+
category="Fundamentals",
|
| 4530 |
+
version="1.0.0",
|
| 4531 |
+
description="Road junction - Choose a path and repeat actions.",
|
| 4532 |
+
icon="cat_control_flow",
|
| 4533 |
+
inputs=[PortDefinition(id="condition", name="Condition", type="bool", required=False, default_value=True)],
|
| 4534 |
+
outputs=[
|
| 4535 |
+
PortDefinition(id="then", name="If True", type="any", required=True),
|
| 4536 |
+
PortDefinition(id="else", name="If False", type="any", required=True),
|
| 4537 |
+
PortDefinition(id="out", name="Result", type="any", required=True)
|
| 4538 |
+
],
|
| 4539 |
+
parameters=[
|
| 4540 |
+
ParameterDefinition(id="mode", name="Flow Mode", type=ParameterType.STRING, default="branch"),
|
| 4541 |
+
],
|
| 4542 |
+
docs=DocumentationMetadata(summary="Road junction - Choose a path and repeat actions.", description="Branching decisions.", doc_url="https://docs.python.org/3/"),
|
| 4543 |
+
),
|
| 4544 |
+
_exec_cat_control_flow,
|
| 4545 |
+
"cat_control_flow",
|
| 4546 |
+
),
|
| 4547 |
+
(
|
| 4548 |
+
NodeDefinition(
|
| 4549 |
+
type="fundamentals.functions",
|
| 4550 |
+
label="Functions",
|
| 4551 |
+
category="Fundamentals",
|
| 4552 |
+
version="1.0.0",
|
| 4553 |
+
description="Toy machine - Create actions and use them again.",
|
| 4554 |
+
icon="cat_functions",
|
| 4555 |
+
inputs=[PortDefinition(id="args", name="Arguments", type="any", required=False)],
|
| 4556 |
+
outputs=[PortDefinition(id="out", name="Return Value", type="any", required=True)],
|
| 4557 |
+
parameters=[
|
| 4558 |
+
ParameterDefinition(id="func_name", name="Machine Name", type=ParameterType.STRING, default="make_toy"),
|
| 4559 |
+
],
|
| 4560 |
+
docs=DocumentationMetadata(summary="Toy machine - Create actions and use them again.", description="Reusable function.", doc_url="https://docs.python.org/3/"),
|
| 4561 |
+
),
|
| 4562 |
+
_exec_cat_functions,
|
| 4563 |
+
"cat_functions",
|
| 4564 |
+
),
|
| 4565 |
+
(
|
| 4566 |
+
NodeDefinition(
|
| 4567 |
+
type="fundamentals.strings_collections",
|
| 4568 |
+
label="Strings & Collection Operations",
|
| 4569 |
+
category="Fundamentals",
|
| 4570 |
+
version="1.0.0",
|
| 4571 |
+
description="Scissors and letters - Cut, join, change and select information.",
|
| 4572 |
+
icon="cat_strings_collections",
|
| 4573 |
+
inputs=[PortDefinition(id="text", name="Text / String", type="any", required=False, default_value="Hello World")],
|
| 4574 |
+
outputs=[PortDefinition(id="out", name="Result", type="any", required=True)],
|
| 4575 |
+
parameters=[
|
| 4576 |
+
ParameterDefinition(id="operation", name="Operation", type=ParameterType.STRING, default="upper"),
|
| 4577 |
+
],
|
| 4578 |
+
docs=DocumentationMetadata(summary="Scissors and letters - Cut, join, change and select information.", description="String transforms.", doc_url="https://docs.python.org/3/"),
|
| 4579 |
+
),
|
| 4580 |
+
_exec_cat_strings_collections,
|
| 4581 |
+
"cat_strings_collections",
|
| 4582 |
+
),
|
| 4583 |
+
(
|
| 4584 |
+
NodeDefinition(
|
| 4585 |
+
type="fundamentals.oop",
|
| 4586 |
+
label="Object-Oriented Programming (OOP)",
|
| 4587 |
+
category="Fundamentals",
|
| 4588 |
+
version="1.0.0",
|
| 4589 |
+
description="Blueprint and house - Design plans and build objects.",
|
| 4590 |
+
icon="cat_oop",
|
| 4591 |
+
inputs=[PortDefinition(id="params", name="Params", type="any", required=False)],
|
| 4592 |
+
outputs=[PortDefinition(id="out", name="Instance", type="any", required=True)],
|
| 4593 |
+
parameters=[
|
| 4594 |
+
ParameterDefinition(id="class_name", name="Blueprint Name", type=ParameterType.STRING, default="House"),
|
| 4595 |
+
],
|
| 4596 |
+
docs=DocumentationMetadata(summary="Blueprint and house - Design plans and build objects.", description="Classes & objects.", doc_url="https://docs.python.org/3/"),
|
| 4597 |
+
),
|
| 4598 |
+
_exec_cat_oop,
|
| 4599 |
+
"cat_oop",
|
| 4600 |
+
),
|
| 4601 |
+
(
|
| 4602 |
+
NodeDefinition(
|
| 4603 |
+
type="fundamentals.files",
|
| 4604 |
+
label="Files & Data Interchange",
|
| 4605 |
+
category="Fundamentals",
|
| 4606 |
+
version="1.0.0",
|
| 4607 |
+
description="Notebook and parcel - Open, save, pack and unpack information.",
|
| 4608 |
+
icon="cat_files",
|
| 4609 |
+
inputs=[PortDefinition(id="in", name="Data In", type="any", required=False)],
|
| 4610 |
+
outputs=[PortDefinition(id="out", name="Content", type="any", required=True)],
|
| 4611 |
+
parameters=[
|
| 4612 |
+
ParameterDefinition(id="file_path", name="Notebook File", type=ParameterType.STRING, default="data.txt"),
|
| 4613 |
+
],
|
| 4614 |
+
docs=DocumentationMetadata(summary="Notebook and parcel - Open, save, pack and unpack information.", description="File notes & data.", doc_url="https://docs.python.org/3/"),
|
| 4615 |
+
),
|
| 4616 |
+
_exec_cat_files,
|
| 4617 |
+
"cat_files",
|
| 4618 |
+
),
|
| 4619 |
+
(
|
| 4620 |
+
NodeDefinition(
|
| 4621 |
+
type="fundamentals.modules",
|
| 4622 |
+
label="Modules & Imports",
|
| 4623 |
+
category="Fundamentals",
|
| 4624 |
+
version="1.0.0",
|
| 4625 |
+
description="Toolbox - Bring in tools that help your program.",
|
| 4626 |
+
icon="cat_modules",
|
| 4627 |
+
inputs=[],
|
| 4628 |
+
outputs=[PortDefinition(id="out", name="Tool", type="any", required=True)],
|
| 4629 |
+
parameters=[
|
| 4630 |
+
ParameterDefinition(id="module_name", name="Tool Module", type=ParameterType.STRING, default="math"),
|
| 4631 |
+
],
|
| 4632 |
+
docs=DocumentationMetadata(summary="Toolbox - Bring in tools that help your program.", description="Toolbox modules.", doc_url="https://docs.python.org/3/"),
|
| 4633 |
+
),
|
| 4634 |
+
_exec_cat_modules,
|
| 4635 |
+
"cat_modules",
|
| 4636 |
+
),
|
| 4637 |
+
]
|
| 4638 |
+
|
| 4639 |
+
for node_def, exec_fn, alias_name in _cat_definitions:
|
| 4640 |
+
default_registry.register(node_def, executor=exec_fn)
|
| 4641 |
+
default_registry._schemas[alias_name] = node_def
|
| 4642 |
+
default_registry._executors[alias_name] = exec_fn
|
language_core/workflow_executor.py
CHANGED
|
@@ -798,7 +798,10 @@ def _execute_single_node(
|
|
| 798 |
node_type=ntype,
|
| 799 |
message=f"[EXEC_UNSUPPORTED] Node '{label}' ({node_id}) of type '{ntype}' is marked runtime_supported=False.",
|
| 800 |
)
|
| 801 |
-
|
|
|
|
|
|
|
|
|
|
| 802 |
elif global_staging_registry.has(ntype):
|
| 803 |
staged_node = global_staging_registry.get(ntype)
|
| 804 |
staged_rec = global_staging_registry.get_record(ntype)
|
|
|
|
| 798 |
node_type=ntype,
|
| 799 |
message=f"[EXEC_UNSUPPORTED] Node '{label}' ({node_id}) of type '{ntype}' is marked runtime_supported=False.",
|
| 800 |
)
|
| 801 |
+
res = default_registry.execute(ntype, node_inputs, params)
|
| 802 |
+
if isinstance(res, dict) and "printed_string" in res:
|
| 803 |
+
stdout_lines.append(str(res["printed_string"]))
|
| 804 |
+
return res
|
| 805 |
elif global_staging_registry.has(ntype):
|
| 806 |
staged_node = global_staging_registry.get(ntype)
|
| 807 |
staged_rec = global_staging_registry.get_record(ntype)
|