text.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from __future__ import annotations
  2. from typing import Any
  3. from fastapi import HTTPException
  4. from ... import windows_automation
  5. from ..context import WorkflowContext
  6. from ..registry import control_ports, field_def, register_node
  7. def input_text_node(node: dict[str, Any], inputs: dict[str, Any], context: WorkflowContext) -> dict[str, Any]:
  8. text = str(inputs.get("text", node.get("params", {}).get("text")) or "")
  9. try:
  10. import pyperclip
  11. except ImportError as exc:
  12. raise HTTPException(status_code=500, detail="pyperclip is not installed") from exc
  13. pyperclip.copy(text)
  14. result = windows_automation.keyboard_action("hotkey", keys=["ctrl", "v"])
  15. return {"text": text, "length": len(text), "action": result.get("action")}
  16. register_node(
  17. {
  18. "type": "text.input",
  19. "category": "text",
  20. "label": "输入文本",
  21. "params": {"text": field_def("textarea", "文本", "")},
  22. "inputs": {"text": field_def("string", "文本")},
  23. "outputs": {
  24. "text": {"type": "string", "label": "输入文本"},
  25. "length": {"type": "number", "label": "文本长度"},
  26. "action": {"type": "string", "label": "动作名称"},
  27. },
  28. "control_ports": control_ports(),
  29. },
  30. input_text_node,
  31. )