auto / language_core /nodes /nodes_strings.py
rsnarsna
feat(alli-backend): Wave-1 standardization, standalone sys.env node & vault crypto, and DEC-014 security hardening
8628c98
Raw History Blame Contribute Delete
1.57 kB
"""
ALLI Domain Nodes: String Transformations & Operations.
Covers: string.transform, string.concat, string.split.
"""
from typing import Any, Dict
from language_core.nodes.loader import register_domain_nodes
def _exec_string_transform(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
raw_text = inputs.get("text_in") if inputs.get("text_in") is not None else inputs.get("text", "")
text = str(raw_text)
op = params.get("operation", "upper")
ops = {
"upper": text.upper,
"lower": text.lower,
"title": text.title,
"capitalize": text.capitalize,
"strip": text.strip,
}
res = ops[op]() if op in ops else text
return {"text_out": res, "result": res, "val": res, "out": res, "length": len(res)}
def _exec_string_concat(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
a = str(inputs.get("a", ""))
b = str(inputs.get("b", ""))
sep = str(params.get("separator", ""))
res = a + sep + b
return {"result": res, "length": len(res)}
def _exec_string_split(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
text = str(inputs.get("text", ""))
delim = str(params.get("delimiter", " "))
items = text.split(delim)
return {"items": items, "count": len(items)}
EXECUTORS = {
"string.transform": _exec_string_transform,
"string.concat": _exec_string_concat,
"string.split": _exec_string_split,
}
def register_strings_nodes(registry: Any) -> None:
register_domain_nodes(registry, "strings", EXECUTORS)