diff --git a/api/core/workflow/nodes/base/node.py b/api/core/workflow/nodes/base/node.py index b7a5e3eeec..25751601b1 100644 --- a/api/core/workflow/nodes/base/node.py +++ b/api/core/workflow/nodes/base/node.py @@ -17,6 +17,15 @@ logger = logging.getLogger(__name__) class BaseNode: + """BaseNode serves as the foundational class for all node implementations. + + Nodes are allowed to maintain transient states (e.g., `LLMNode` uses the `_file_output` + attribute to track files generated by the LLM). However, these states are not persisted + when the workflow is suspended or resumed. If a node needs its state to be preserved + across workflow suspension and resumption, it should include the relevant state data + in its output. + """ + _node_type: ClassVar[NodeType] def __init__( diff --git a/api/libs/helper.py b/api/libs/helper.py index 00772d530a..c5178d2459 100644 --- a/api/libs/helper.py +++ b/api/libs/helper.py @@ -181,6 +181,26 @@ def timezone(timezone_string): def generate_string(n): + """ + Generates a cryptographically secure random string of the specified length. + + This function uses a cryptographically secure pseudorandom number generator (CSPRNG) + to create a string composed of ASCII letters (both uppercase and lowercase) and digits. + + Each character in the generated string provides approximately 5.95 bits of entropy + (log2(62)). To ensure a minimum of 128 bits of entropy for security purposes, the + length of the string (`n`) should be at least 22 characters. + + Args: + n (int): The length of the random string to generate. For secure usage, + `n` should be 22 or greater. + + Returns: + str: A random string of length `n` composed of ASCII letters and digits. + + Note: + This function is suitable for generating credentials or other secure tokens. + """ letters_digits = string.ascii_letters + string.digits result = "" for i in range(n):