Files
johndoe6345789 7ce8b4ae8a refactor(workflow): convert all plugins to class/struct + factory pattern
- Python: class extending NodeExecutor + factory.py (80+ plugins)
- TypeScript: class implements NodeExecutor + factory.ts (7 groups, 116 classes)
- Go: struct with methods + factory.go (36 plugins)
- Rust: struct impl NodeExecutor trait + factory.rs (54 plugins)
- Mojo: struct + factory.mojo (11 plugins)

All package.json files now include:
- files array listing source files
- metadata.class/struct field
- metadata.entrypoint field

This enables a unified plugin loading system across all languages
with no import side effects (Spring-style DI pattern).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-22 14:53:04 +00:00

70 lines
2.1 KiB
Mojo

"""Workflow plugin: divide numbers.
Divides numbers sequentially from the first number.
Input: {"numbers": [100, 2, 5]}
Output: {"result": 10.0} (100 / 2 / 5 = 10)
"""
from collections import Dict
from python import PythonObject
struct MathDivide:
"""Plugin that divides numbers sequentially from the first number."""
var node_type: String
var category: String
var description: String
fn __init__(inout self):
"""Initialize the MathDivide plugin."""
self.node_type = "math.divide"
self.category = "math"
self.description = "Divide numbers sequentially from the first number"
fn execute(self, inputs: Dict[String, PythonObject], runtime: PythonObject = PythonObject(None)) -> Dict[String, PythonObject]:
"""Divide numbers sequentially from the first number.
Args:
inputs: Dictionary containing "numbers" key with a list of numbers.
The first number is the dividend, subsequent numbers are divisors.
runtime: Optional runtime context (unused).
Returns:
Dictionary with "result" key containing the quotient as Float64,
or "error" key if division by zero is attempted.
"""
var numbers = inputs.get("numbers", PythonObject([]))
var output = Dict[String, PythonObject]()
var length = len(numbers)
if length == 0:
output["result"] = PythonObject(0.0)
return output
var result: Float64 = Float64(numbers[0])
for i in range(1, length):
var divisor = Float64(numbers[i])
if divisor == 0.0:
output["error"] = PythonObject("Division by zero")
return output
result /= divisor
output["result"] = PythonObject(result)
return output
fn main():
"""Test the divide plugin."""
var plugin = MathDivide()
var inputs = Dict[String, PythonObject]()
inputs["numbers"] = PythonObject([100, 2, 5])
var result = plugin.execute(inputs)
if "error" in result:
print("Error:", result["error"])
else:
print("Quotient:", result["result"]) # Expected: 10.0