| 1234567891011121314151617181920212223242526272829303132333435363738 |
- from __future__ import annotations
- from typing import Any
- from fastapi import HTTPException
- from ... import windows_automation
- from ..context import WorkflowContext
- from ..registry import control_ports, field_def, register_node
- def input_text_node(node: dict[str, Any], inputs: dict[str, Any], context: WorkflowContext) -> dict[str, Any]:
- text = str(inputs.get("text", node.get("params", {}).get("text")) or "")
- try:
- import pyperclip
- except ImportError as exc:
- raise HTTPException(status_code=500, detail="pyperclip is not installed") from exc
- pyperclip.copy(text)
- result = windows_automation.keyboard_action("hotkey", keys=["ctrl", "v"])
- return {"text": text, "length": len(text), "action": result.get("action")}
- register_node(
- {
- "type": "text.input",
- "category": "text",
- "label": "输入文本",
- "params": {"text": field_def("textarea", "文本", "")},
- "inputs": {"text": field_def("string", "文本")},
- "outputs": {
- "text": {"type": "string", "label": "输入文本"},
- "length": {"type": "number", "label": "文本长度"},
- "action": {"type": "string", "label": "动作名称"},
- },
- "control_ports": control_ports(),
- },
- input_text_node,
- )
|