$ cat node-template.py

Text Merge

// Merges two text inputs into a single output. Supports configurable separators, templates, and formatting options.

Process
Data
template.py
1import os2import sys3import traceback4import json5from datetime import datetime67# Execution context8EXECUTION_CONTEXT = {9    "workspace_id": os.getenv("WORKSPACE_ID"),10    "node_id": os.getenv("NODE_ID"),11    "execution_id": os.getenv("EXECUTION_ID"),12}131415def merge_texts(16    text1: str,17    text2: str,18    separator: str = "\n\n",19    template: str = None,20    trim_whitespace: bool = True,21    skip_empty: bool = False,22) -> str:23    # Handle None values24    text1 = text1 or ""25    text2 = text2 or ""2627    # Trim whitespace if requested28    if trim_whitespace:29        text1 = text1.strip()30        text2 = text2.strip()3132    # Handle template mode33    if template:34        return template.format(text1=text1, text2=text2)3536    # Handle skip empty mode37    if skip_empty:38        parts = [t for t in [text1, text2] if t]39        return separator.join(parts)4041    # Standard concatenation42    return f"{text1}{separator}{text2}"434445def main():46    try:47        # Read execution input from stdin48        input_json = sys.stdin.read()49        execution_input = json.loads(input_json)5051        # Extract inputs (from connections)52        inputs = execution_input.get("inputs", {})53        text1 = inputs.get("text1", "")54        text2 = inputs.get("text2", "")5556        # Perform merge with default settings57        merged_text = merge_texts(58            text1=text1,59            text2=text2,60            separator="\n\n",61            template=None,62            trim_whitespace=True,63            skip_empty=False,64        )6566        # Log stats to stderr67        input_length = len(text1 or "") + len(text2 or "")68        output_length = len(merged_text)69        print(f"Input length: {input_length}, Output length: {output_length}", file=sys.stderr)7071        # Flat output — keys match OUTPUT_SCHEMA72        output = {73            "text": merged_text,74        }75        print(json.dumps(output, indent=2))7677    except Exception as e:78        # Write error to stderr79        error_output = {80            "error": str(e),81            "errorType": type(e).__name__,82            "traceback": traceback.format_exc(),83            "executionContext": EXECUTION_CONTEXT,84        }85        print(json.dumps(error_output), file=sys.stderr)86        sys.exit(1)878889if __name__ == "__main__":90    main()