human.py 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. from __future__ import annotations
  2. from typing import Any
  3. from ..context import WorkflowContext, WorkflowPaused
  4. from ..registry import control_ports, field_def, register_node
  5. def ask_user_node(node: dict[str, Any], inputs: dict[str, Any], context: WorkflowContext) -> dict[str, Any]:
  6. question = str(inputs.get("question", node.get("params", {}).get("question")) or "请确认下一步操作。")
  7. raise WorkflowPaused(
  8. question,
  9. {
  10. "node_id": node.get("id"),
  11. "question": question,
  12. "screenshot_path": context.runtime.get("current_screenshot_path"),
  13. },
  14. )
  15. register_node(
  16. {
  17. "type": "human.ask_user",
  18. "category": "human",
  19. "label": "询问用户",
  20. "params": {"question": field_def("textarea", "问题", "请确认下一步操作。")},
  21. "inputs": {"question": field_def("string", "问题")},
  22. "outputs": {"answer": {"type": "string", "label": "用户回答"}},
  23. "control_ports": control_ports(["answered", "failure"]),
  24. },
  25. ask_user_node,
  26. )