oagi-core 0.14.1__tar.gz → 0.15.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {oagi_core-0.14.1 → oagi_core-0.15.0}/PKG-INFO +1 -1
- {oagi_core-0.14.1 → oagi_core-0.15.0}/metapackage/pyproject.toml +2 -2
- {oagi_core-0.14.1 → oagi_core-0.15.0}/metapackage/uv.lock +5 -5
- {oagi_core-0.14.1 → oagi_core-0.15.0}/pyproject.toml +1 -1
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/__init__.py +10 -0
- oagi_core-0.15.0/src/oagi/converters/__init__.py +56 -0
- oagi_core-0.15.0/src/oagi/converters/base.py +292 -0
- oagi_core-0.15.0/src/oagi/converters/oagi.py +198 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/handler/pyautogui_action_handler.py +22 -41
- oagi_core-0.15.0/src/oagi/handler/utils.py +622 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/handler/ydotool_action_handler.py +22 -43
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/server/socketio_server.py +1 -1
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/types/models/action.py +1 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/utils/output_parser.py +2 -1
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/utils/prompt_builder.py +1 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/conftest.py +16 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_actor.py +21 -0
- oagi_core-0.15.0/tests/test_oagi_action_converter.py +189 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_pyautogui_action_handler.py +27 -8
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/utils/test_output_parser.py +25 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/uv.lock +1 -1
- oagi_core-0.14.1/src/oagi/handler/utils.py +0 -35
- {oagi_core-0.14.1 → oagi_core-0.15.0}/.github/ISSUE_TEMPLATE/bug-report.yml +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/.github/ISSUE_TEMPLATE/feature-request.yml +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/.github/ISSUE_TEMPLATE/question.yml +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/.github/workflows/ci.yml +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/.github/workflows/release.yml +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/.gitignore +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/.python-version +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/CONTRIBUTING.md +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/LICENSE +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/Makefile +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/README.md +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/examples/async_google_weather.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/examples/execute_task_auto.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/examples/execute_task_manual.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/examples/google_weather.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/examples/multi_screen_execution.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/examples/openai_agent_loop_example.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/examples/screenshot_with_config.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/examples/tasker_agent_example.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/actor/__init__.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/actor/async_.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/actor/async_short.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/actor/base.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/actor/short.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/actor/sync.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/__init__.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/default.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/factories.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/observer/__init__.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/observer/agent_observer.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/observer/events.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/observer/exporters.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/observer/protocol.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/observer/report_template.html +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/protocol.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/registry.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/tasker/__init__.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/tasker/memory.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/tasker/models.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/tasker/planner.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/tasker/taskee_agent.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/agent/tasker/tasker_agent.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/cli/__init__.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/cli/agent.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/cli/display.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/cli/main.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/cli/server.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/cli/tracking.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/cli/utils.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/client/__init__.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/client/async_.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/client/base.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/client/sync.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/constants.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/exceptions.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/handler/__init__.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/handler/_macos.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/handler/_windows.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/handler/_ydotool.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/handler/async_pyautogui_action_handler.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/handler/async_screenshot_maker.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/handler/async_ydotool_action_handler.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/handler/capslock_manager.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/handler/pil_image.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/handler/screen_manager.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/handler/screenshot_maker.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/handler/wayland_support.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/logging.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/platform_info.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/server/__init__.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/server/agent_wrappers.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/server/config.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/server/main.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/server/models.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/server/session_store.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/task/__init__.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/types/__init__.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/types/action_handler.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/types/async_action_handler.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/types/async_image_provider.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/types/image.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/types/image_provider.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/types/models/__init__.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/types/models/client.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/types/models/image_config.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/types/models/step.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/types/step_observer.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/types/url.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/src/oagi/utils/__init__.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/__init__.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_action_parsing.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_agent/test_agent_wrappers.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_agent/test_default_agent.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_agent_registry.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_async_actor.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_async_client.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_async_handlers.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_cli.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_logging.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_mac_double_click.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_observer.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_pil_image.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_planner.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_planner_memory.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_screenshot_maker.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_server/__init__.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_server/test_config.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_server/test_session_store.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_server/test_socketio_integration.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_sync_client.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_taskee_agent.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/test_tasker_agent.py +0 -0
- {oagi_core-0.14.1 → oagi_core-0.15.0}/tests/utils/__init__.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "oagi"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.15.0"
|
|
8
8
|
description = "Official API of OpenAGI Foundation (metapackage with all features)"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -16,7 +16,7 @@ authors = [
|
|
|
16
16
|
requires-python = ">= 3.10"
|
|
17
17
|
|
|
18
18
|
dependencies = [
|
|
19
|
-
"oagi-core[desktop,server]==0.
|
|
19
|
+
"oagi-core[desktop,server]==0.15.0",
|
|
20
20
|
]
|
|
21
21
|
|
|
22
22
|
[project.urls]
|
|
@@ -527,18 +527,18 @@ wheels = [
|
|
|
527
527
|
|
|
528
528
|
[[package]]
|
|
529
529
|
name = "oagi"
|
|
530
|
-
version = "0.
|
|
530
|
+
version = "0.15.0"
|
|
531
531
|
source = { editable = "." }
|
|
532
532
|
dependencies = [
|
|
533
533
|
{ name = "oagi-core", extra = ["desktop", "server"] },
|
|
534
534
|
]
|
|
535
535
|
|
|
536
536
|
[package.metadata]
|
|
537
|
-
requires-dist = [{ name = "oagi-core", extras = ["desktop", "server"], specifier = "==0.14.
|
|
537
|
+
requires-dist = [{ name = "oagi-core", extras = ["desktop", "server"], specifier = "==0.14.2" }]
|
|
538
538
|
|
|
539
539
|
[[package]]
|
|
540
540
|
name = "oagi-core"
|
|
541
|
-
version = "0.14.
|
|
541
|
+
version = "0.14.2"
|
|
542
542
|
source = { registry = "https://pypi.org/simple" }
|
|
543
543
|
dependencies = [
|
|
544
544
|
{ name = "httpx" },
|
|
@@ -546,9 +546,9 @@ dependencies = [
|
|
|
546
546
|
{ name = "pydantic" },
|
|
547
547
|
{ name = "rich" },
|
|
548
548
|
]
|
|
549
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
549
|
+
sdist = { url = "https://files.pythonhosted.org/packages/7f/6e/02d64ba32075a3977e1037228580d29de7122e8d5dce2a1267c71d8c3d69/oagi_core-0.14.2.tar.gz", hash = "sha256:2eda6ef21276dc0c7256b6014f8db7045eaedf98a6f091f0aedf3f44b20321e6", size = 319639, upload-time = "2026-02-03T07:42:15.596Z" }
|
|
550
550
|
wheels = [
|
|
551
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
551
|
+
{ url = "https://files.pythonhosted.org/packages/0b/90/62215c6e46961d29d6e9e715d89483d108a811f5c1c854a5bb7b053eacab/oagi_core-0.14.2-py3-none-any.whl", hash = "sha256:ceaeabbe20bafef7c031f3932d6870b42e7406173030790a5a55965b8ebe5f73", size = 124410, upload-time = "2026-02-03T07:42:14.23Z" },
|
|
552
552
|
]
|
|
553
553
|
|
|
554
554
|
[package.optional-dependencies]
|
|
@@ -38,6 +38,10 @@ from oagi.types.models import (
|
|
|
38
38
|
# Format: name -> (module_path, package_to_check, extra_name)
|
|
39
39
|
# package_to_check is None if no optional dependency is required
|
|
40
40
|
_LAZY_IMPORTS_DATA: dict[str, tuple[str, str | None, str | None]] = {
|
|
41
|
+
# Action converters (no optional dependencies)
|
|
42
|
+
"OagiActionConverter": ("oagi.converters.oagi", None, None),
|
|
43
|
+
"ConverterConfig": ("oagi.converters.base", None, None),
|
|
44
|
+
"BaseActionConverter": ("oagi.converters.base", None, None),
|
|
41
45
|
# Desktop handlers (require pyautogui/PIL)
|
|
42
46
|
"AsyncPyautoguiActionHandler": (
|
|
43
47
|
"oagi.handler.async_pyautogui_action_handler",
|
|
@@ -88,6 +92,8 @@ if TYPE_CHECKING:
|
|
|
88
92
|
from oagi.agent.default import AsyncDefaultAgent
|
|
89
93
|
from oagi.agent.observer.agent_observer import AsyncAgentObserver
|
|
90
94
|
from oagi.agent.tasker import TaskerAgent
|
|
95
|
+
from oagi.converters.base import BaseActionConverter, ConverterConfig
|
|
96
|
+
from oagi.converters.oagi import OagiActionConverter
|
|
91
97
|
from oagi.handler.async_pyautogui_action_handler import AsyncPyautoguiActionHandler
|
|
92
98
|
from oagi.handler.async_screenshot_maker import AsyncScreenshotMaker
|
|
93
99
|
from oagi.handler.async_ydotool_action_handler import AsyncYdotoolActionHandler
|
|
@@ -174,4 +180,8 @@ __all__ = [
|
|
|
174
180
|
"YdotoolConfig",
|
|
175
181
|
# Lazy imports - Screen manager
|
|
176
182
|
"ScreenManager",
|
|
183
|
+
# Lazy imports - Action converters
|
|
184
|
+
"OagiActionConverter",
|
|
185
|
+
"ConverterConfig",
|
|
186
|
+
"BaseActionConverter",
|
|
177
187
|
]
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# -----------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) OpenAGI Foundation
|
|
3
|
+
# All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# This file is part of the official API project.
|
|
6
|
+
# Licensed under the MIT License.
|
|
7
|
+
# -----------------------------------------------------------------------------
|
|
8
|
+
"""Action converters for VLM support.
|
|
9
|
+
|
|
10
|
+
This module provides the base class and OAGI implementation for action converters.
|
|
11
|
+
Third parties can inherit from BaseActionConverter to create custom converters.
|
|
12
|
+
|
|
13
|
+
Example usage:
|
|
14
|
+
from oagi.converters import OagiActionConverter, ConverterConfig
|
|
15
|
+
|
|
16
|
+
# Configure for 1920x1080 sandbox
|
|
17
|
+
config = ConverterConfig(sandbox_width=1920, sandbox_height=1080)
|
|
18
|
+
converter = OagiActionConverter(config=config)
|
|
19
|
+
|
|
20
|
+
# Convert OAGI actions to pyautogui strings
|
|
21
|
+
result = converter(actions) # list[str]
|
|
22
|
+
|
|
23
|
+
# Convert to runtime API steps
|
|
24
|
+
for cmd in result:
|
|
25
|
+
step = converter.action_string_to_step(cmd)
|
|
26
|
+
# Execute step via runtime API...
|
|
27
|
+
|
|
28
|
+
Creating custom converters:
|
|
29
|
+
from oagi.converters import BaseActionConverter, ConverterConfig
|
|
30
|
+
|
|
31
|
+
class MyActionConverter(BaseActionConverter[MyAction]):
|
|
32
|
+
@property
|
|
33
|
+
def coord_width(self) -> int:
|
|
34
|
+
return 1000 # Your model's coordinate width
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def coord_height(self) -> int:
|
|
38
|
+
return 1000 # Your model's coordinate height
|
|
39
|
+
|
|
40
|
+
def _convert_single_action(self, action: MyAction) -> list[str]:
|
|
41
|
+
# Convert action to pyautogui command strings
|
|
42
|
+
...
|
|
43
|
+
|
|
44
|
+
def serialize_actions(self, actions: list[MyAction]) -> list[dict]:
|
|
45
|
+
# Serialize actions for trajectory logging
|
|
46
|
+
...
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
from .base import BaseActionConverter, ConverterConfig
|
|
50
|
+
from .oagi import OagiActionConverter
|
|
51
|
+
|
|
52
|
+
__all__ = [
|
|
53
|
+
"BaseActionConverter",
|
|
54
|
+
"ConverterConfig",
|
|
55
|
+
"OagiActionConverter",
|
|
56
|
+
]
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
# -----------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) OpenAGI Foundation
|
|
3
|
+
# All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# This file is part of the official API project.
|
|
6
|
+
# Licensed under the MIT License.
|
|
7
|
+
# -----------------------------------------------------------------------------
|
|
8
|
+
"""Base class for action converters.
|
|
9
|
+
|
|
10
|
+
This module provides the abstract base class for converting model-specific
|
|
11
|
+
actions to pyautogui command strings for remote execution.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import re
|
|
15
|
+
from abc import ABC, abstractmethod
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from typing import Any, Generic, TypeVar
|
|
18
|
+
|
|
19
|
+
from ..handler.capslock_manager import CapsLockManager
|
|
20
|
+
from ..handler.utils import (
|
|
21
|
+
CoordinateScaler,
|
|
22
|
+
normalize_key,
|
|
23
|
+
parse_hotkey,
|
|
24
|
+
validate_keys,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
T = TypeVar("T")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class ConverterConfig:
|
|
32
|
+
"""Configuration for action converters.
|
|
33
|
+
|
|
34
|
+
Matches the configuration options in PyautoguiConfig for consistency.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
sandbox_width: int = 1920
|
|
38
|
+
sandbox_height: int = 1080
|
|
39
|
+
drag_duration: float = 0.5
|
|
40
|
+
scroll_amount: int = 2
|
|
41
|
+
wait_duration: float = 1.0
|
|
42
|
+
hotkey_interval: float = 0.1
|
|
43
|
+
capslock_mode: str = "session"
|
|
44
|
+
strict_coordinate_validation: bool = False
|
|
45
|
+
"""If True, raise ValueError when coordinates are outside valid range.
|
|
46
|
+
If False (default), clamp coordinates to valid range (original behavior)."""
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class BaseActionConverter(ABC, Generic[T]):
|
|
50
|
+
"""Abstract base class for action converters.
|
|
51
|
+
|
|
52
|
+
Subclasses must implement:
|
|
53
|
+
- coord_width/coord_height properties for input coordinate space
|
|
54
|
+
- _convert_single_action() for model-specific conversion logic
|
|
55
|
+
- serialize_actions() for trajectory logging
|
|
56
|
+
|
|
57
|
+
Provides common functionality:
|
|
58
|
+
- Coordinate scaling via CoordinateScaler
|
|
59
|
+
- Key normalization via shared utils
|
|
60
|
+
- __call__ interface returning list of action strings
|
|
61
|
+
- action_string_to_step() for runtime API format
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
def __init__(
|
|
65
|
+
self,
|
|
66
|
+
*,
|
|
67
|
+
config: ConverterConfig | None = None,
|
|
68
|
+
logger: Any | None = None,
|
|
69
|
+
):
|
|
70
|
+
"""Initialize the converter.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
config: Converter configuration. Uses defaults if not provided.
|
|
74
|
+
logger: Optional logger instance for debug/error logging.
|
|
75
|
+
"""
|
|
76
|
+
self.config = config or ConverterConfig()
|
|
77
|
+
self.logger = logger
|
|
78
|
+
|
|
79
|
+
# Initialize coordinate scaler
|
|
80
|
+
self._coord_scaler = CoordinateScaler(
|
|
81
|
+
source_width=self.coord_width,
|
|
82
|
+
source_height=self.coord_height,
|
|
83
|
+
target_width=self.config.sandbox_width,
|
|
84
|
+
target_height=self.config.sandbox_height,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# Initialize caps lock manager
|
|
88
|
+
self.caps_manager = CapsLockManager(mode=self.config.capslock_mode)
|
|
89
|
+
|
|
90
|
+
# Track last cursor position (for actions without explicit coordinates)
|
|
91
|
+
self._last_x: int | None = None
|
|
92
|
+
self._last_y: int | None = None
|
|
93
|
+
|
|
94
|
+
@property
|
|
95
|
+
@abstractmethod
|
|
96
|
+
def coord_width(self) -> int:
|
|
97
|
+
"""Input coordinate space width (e.g., 1024 for XGA, 1000 for OAGI)."""
|
|
98
|
+
...
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
@abstractmethod
|
|
102
|
+
def coord_height(self) -> int:
|
|
103
|
+
"""Input coordinate space height (e.g., 768 for XGA, 1000 for OAGI)."""
|
|
104
|
+
...
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def scale_x(self) -> float:
|
|
108
|
+
"""X scaling factor from input to sandbox coordinates."""
|
|
109
|
+
return self._coord_scaler.scale_x
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def scale_y(self) -> float:
|
|
113
|
+
"""Y scaling factor from input to sandbox coordinates."""
|
|
114
|
+
return self._coord_scaler.scale_y
|
|
115
|
+
|
|
116
|
+
def scale_coordinate(self, x: int | float, y: int | float) -> tuple[int, int]:
|
|
117
|
+
"""Scale coordinates from model space to sandbox space.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
x: X coordinate in model space
|
|
121
|
+
y: Y coordinate in model space
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
Tuple of (scaled_x, scaled_y) in sandbox space
|
|
125
|
+
"""
|
|
126
|
+
return self._coord_scaler.scale(x, y)
|
|
127
|
+
|
|
128
|
+
def normalize_key(self, key: str) -> str:
|
|
129
|
+
"""Normalize a key name to pyautogui format.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
key: Key name to normalize
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
Normalized key name
|
|
136
|
+
"""
|
|
137
|
+
return normalize_key(key)
|
|
138
|
+
|
|
139
|
+
def parse_hotkey(self, hotkey_str: str, *, validate: bool = True) -> list[str]:
|
|
140
|
+
"""Parse a hotkey string into a list of normalized key names.
|
|
141
|
+
|
|
142
|
+
Args:
|
|
143
|
+
hotkey_str: Hotkey string (e.g., "ctrl+c")
|
|
144
|
+
validate: If True, validate keys against PYAUTOGUI_VALID_KEYS
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
List of normalized key names
|
|
148
|
+
"""
|
|
149
|
+
return parse_hotkey(hotkey_str, validate=validate)
|
|
150
|
+
|
|
151
|
+
def validate_keys(self, keys: list[str]) -> None:
|
|
152
|
+
"""Validate that all keys are recognized by pyautogui.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
keys: List of key names to validate
|
|
156
|
+
|
|
157
|
+
Raises:
|
|
158
|
+
ValueError: If any key is invalid
|
|
159
|
+
"""
|
|
160
|
+
validate_keys(keys)
|
|
161
|
+
|
|
162
|
+
def _get_last_or_center(self) -> tuple[int, int]:
|
|
163
|
+
"""Get last cursor position or screen center as fallback.
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
Tuple of (x, y) coordinates
|
|
167
|
+
"""
|
|
168
|
+
if self._last_x is not None and self._last_y is not None:
|
|
169
|
+
return self._last_x, self._last_y
|
|
170
|
+
return self.config.sandbox_width // 2, self.config.sandbox_height // 2
|
|
171
|
+
|
|
172
|
+
def _log_error(self, message: str) -> None:
|
|
173
|
+
"""Log an error message if logger is available."""
|
|
174
|
+
if self.logger:
|
|
175
|
+
self.logger.error(message)
|
|
176
|
+
|
|
177
|
+
def _log_info(self, message: str) -> None:
|
|
178
|
+
"""Log an info message if logger is available."""
|
|
179
|
+
if self.logger:
|
|
180
|
+
self.logger.info(message)
|
|
181
|
+
|
|
182
|
+
def _log_debug(self, message: str) -> None:
|
|
183
|
+
"""Log a debug message if logger is available."""
|
|
184
|
+
if self.logger:
|
|
185
|
+
self.logger.debug(message)
|
|
186
|
+
|
|
187
|
+
def __call__(self, actions: list[T]) -> list[str]:
|
|
188
|
+
"""Convert actions to list of pyautogui command strings.
|
|
189
|
+
|
|
190
|
+
Args:
|
|
191
|
+
actions: List of model-specific action objects
|
|
192
|
+
|
|
193
|
+
Returns:
|
|
194
|
+
List of pyautogui command strings
|
|
195
|
+
|
|
196
|
+
Raises:
|
|
197
|
+
RuntimeError: If all action conversions failed
|
|
198
|
+
"""
|
|
199
|
+
converted: list[str] = []
|
|
200
|
+
failed: list[tuple[str, str]] = []
|
|
201
|
+
skipped: list[str] = []
|
|
202
|
+
|
|
203
|
+
if not actions:
|
|
204
|
+
return converted
|
|
205
|
+
|
|
206
|
+
for action in actions:
|
|
207
|
+
try:
|
|
208
|
+
action_strings = self._convert_single_action(action)
|
|
209
|
+
|
|
210
|
+
if not action_strings:
|
|
211
|
+
# No-op action (e.g., screenshot, cursor_position)
|
|
212
|
+
action_type = getattr(action, "action_type", repr(action))
|
|
213
|
+
skipped.append(str(action_type))
|
|
214
|
+
continue
|
|
215
|
+
|
|
216
|
+
converted.extend(action_strings)
|
|
217
|
+
|
|
218
|
+
except Exception as e:
|
|
219
|
+
action_repr = repr(action)
|
|
220
|
+
self._log_error(f"Failed to convert action: {action_repr}, error: {e}")
|
|
221
|
+
failed.append((action_repr, str(e)))
|
|
222
|
+
|
|
223
|
+
if skipped:
|
|
224
|
+
self._log_debug(f"Skipped no-op actions: {skipped}")
|
|
225
|
+
|
|
226
|
+
if not converted and actions and failed:
|
|
227
|
+
raise RuntimeError(
|
|
228
|
+
f"All action conversions failed ({len(failed)}/{len(actions)}): {failed}"
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
return converted
|
|
232
|
+
|
|
233
|
+
@abstractmethod
|
|
234
|
+
def _convert_single_action(self, action: T) -> list[str]:
|
|
235
|
+
"""Convert a single action to pyautogui command string(s).
|
|
236
|
+
|
|
237
|
+
Args:
|
|
238
|
+
action: Model-specific action object
|
|
239
|
+
|
|
240
|
+
Returns:
|
|
241
|
+
List of pyautogui command strings (may be empty for no-op actions)
|
|
242
|
+
|
|
243
|
+
Raises:
|
|
244
|
+
ValueError: If action format is invalid
|
|
245
|
+
"""
|
|
246
|
+
...
|
|
247
|
+
|
|
248
|
+
@abstractmethod
|
|
249
|
+
def serialize_actions(self, actions: list[T]) -> list[dict[str, Any]]:
|
|
250
|
+
"""Serialize actions for trajectory logging.
|
|
251
|
+
|
|
252
|
+
Args:
|
|
253
|
+
actions: List of model-specific action objects
|
|
254
|
+
|
|
255
|
+
Returns:
|
|
256
|
+
List of serialized action dictionaries
|
|
257
|
+
"""
|
|
258
|
+
...
|
|
259
|
+
|
|
260
|
+
def action_string_to_step(self, action: str) -> dict[str, Any]:
|
|
261
|
+
"""Convert an action string into a step for runtime/do API.
|
|
262
|
+
|
|
263
|
+
Args:
|
|
264
|
+
action: Action string (e.g., "pyautogui.click(x=100, y=200)")
|
|
265
|
+
|
|
266
|
+
Returns:
|
|
267
|
+
Step dict for runtime API
|
|
268
|
+
"""
|
|
269
|
+
action_str = str(action).strip()
|
|
270
|
+
|
|
271
|
+
# Special markers
|
|
272
|
+
upper = action_str.upper()
|
|
273
|
+
if upper in ["DONE", "FAIL"]:
|
|
274
|
+
return {"type": "sleep", "parameters": {"seconds": 0}}
|
|
275
|
+
|
|
276
|
+
# WAIT(seconds)
|
|
277
|
+
wait_match = re.match(
|
|
278
|
+
r"^WAIT\((?P<sec>[0-9]*\.?[0-9]+)\)$", action_str, re.IGNORECASE
|
|
279
|
+
)
|
|
280
|
+
if wait_match:
|
|
281
|
+
seconds = float(wait_match.group("sec"))
|
|
282
|
+
return {"type": "sleep", "parameters": {"seconds": seconds}}
|
|
283
|
+
|
|
284
|
+
# pyautogui code path
|
|
285
|
+
if "pyautogui" in action_str.lower():
|
|
286
|
+
return {
|
|
287
|
+
"type": "pyautogui",
|
|
288
|
+
"parameters": {"code": action_str},
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
# Default: shell command
|
|
292
|
+
return {"type": "execute", "parameters": {"command": action_str, "shell": True}}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# -----------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) OpenAGI Foundation
|
|
3
|
+
# All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# This file is part of the official API project.
|
|
6
|
+
# Licensed under the MIT License.
|
|
7
|
+
# -----------------------------------------------------------------------------
|
|
8
|
+
"""OAGI action converter.
|
|
9
|
+
|
|
10
|
+
This module provides the OagiActionConverter for converting OAGI actions
|
|
11
|
+
to pyautogui command strings for remote execution.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
from ..handler.utils import (
|
|
17
|
+
parse_click_coords,
|
|
18
|
+
parse_drag_coords,
|
|
19
|
+
parse_scroll_coords,
|
|
20
|
+
)
|
|
21
|
+
from ..types import Action, ActionType
|
|
22
|
+
from .base import BaseActionConverter
|
|
23
|
+
|
|
24
|
+
# OAGI uses normalized 0-1000 coordinate space
|
|
25
|
+
OAGI_COORD_SIZE = 1000
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class OagiActionConverter(BaseActionConverter[Action]):
|
|
29
|
+
"""Convert OAGI actions to pyautogui command strings.
|
|
30
|
+
|
|
31
|
+
This converter handles:
|
|
32
|
+
1. Coordinate scaling from 0-1000 space to sandbox dimensions (1920x1080)
|
|
33
|
+
2. Action format conversion from OAGI Action format to pyautogui strings
|
|
34
|
+
3. Key name normalization for hotkey combinations
|
|
35
|
+
|
|
36
|
+
The output can be converted to runtime API steps via action_string_to_step().
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def coord_width(self) -> int:
|
|
41
|
+
return OAGI_COORD_SIZE
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def coord_height(self) -> int:
|
|
45
|
+
return OAGI_COORD_SIZE
|
|
46
|
+
|
|
47
|
+
def __call__(self, actions: list[Action]) -> list[str]:
|
|
48
|
+
"""Convert OAGI actions to list of pyautogui command strings.
|
|
49
|
+
|
|
50
|
+
Extends base implementation to handle action count and finish detection.
|
|
51
|
+
"""
|
|
52
|
+
converted: list[str] = []
|
|
53
|
+
failed: list[tuple[str, str]] = []
|
|
54
|
+
has_terminal = False
|
|
55
|
+
|
|
56
|
+
if not actions:
|
|
57
|
+
return converted
|
|
58
|
+
|
|
59
|
+
for action in actions:
|
|
60
|
+
# Check for duplicate finish()/fail() during iteration
|
|
61
|
+
is_terminal = action.type in (ActionType.FINISH, ActionType.FAIL)
|
|
62
|
+
if is_terminal:
|
|
63
|
+
if has_terminal:
|
|
64
|
+
raise ValueError(
|
|
65
|
+
"Duplicate finish()/fail() detected. "
|
|
66
|
+
"Only one finish() or fail() is allowed per action sequence."
|
|
67
|
+
)
|
|
68
|
+
has_terminal = True
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
converted.extend(self._convert_action(action))
|
|
72
|
+
except Exception as e:
|
|
73
|
+
action_repr = f"{action.type.value}({action.argument})"
|
|
74
|
+
self._log_error(f"Failed to convert action: {action_repr}, error: {e}")
|
|
75
|
+
failed.append((action_repr, str(e)))
|
|
76
|
+
|
|
77
|
+
if not converted and actions and failed:
|
|
78
|
+
raise RuntimeError(
|
|
79
|
+
f"All action conversions failed ({len(failed)}/{len(actions)}): {failed}"
|
|
80
|
+
)
|
|
81
|
+
return converted
|
|
82
|
+
|
|
83
|
+
def _convert_action(self, action: Action) -> list[str]:
|
|
84
|
+
"""Convert action to list of pyautogui command strings.
|
|
85
|
+
|
|
86
|
+
Handles action.count for repeat support.
|
|
87
|
+
"""
|
|
88
|
+
count = action.count or 1
|
|
89
|
+
single_actions = self._convert_single_action(action)
|
|
90
|
+
|
|
91
|
+
# Repeat the actions count times
|
|
92
|
+
return single_actions * int(count)
|
|
93
|
+
|
|
94
|
+
def _convert_single_action(self, action: Action) -> list[str]:
|
|
95
|
+
"""Convert a single OAGI action to pyautogui command string(s)."""
|
|
96
|
+
action_type = action.type.value
|
|
97
|
+
argument = (action.argument or "").strip("()")
|
|
98
|
+
|
|
99
|
+
drag_duration = self.config.drag_duration
|
|
100
|
+
scroll_amount = self.config.scroll_amount
|
|
101
|
+
wait_duration = self.config.wait_duration
|
|
102
|
+
hotkey_interval = self.config.hotkey_interval
|
|
103
|
+
strict = self.config.strict_coordinate_validation
|
|
104
|
+
|
|
105
|
+
if action_type == ActionType.CLICK.value:
|
|
106
|
+
x, y = parse_click_coords(argument, self._coord_scaler, strict=strict)
|
|
107
|
+
return [f"pyautogui.click(x={x}, y={y})"]
|
|
108
|
+
|
|
109
|
+
if action_type == ActionType.LEFT_DOUBLE.value:
|
|
110
|
+
x, y = parse_click_coords(argument, self._coord_scaler, strict=strict)
|
|
111
|
+
return [f"pyautogui.doubleClick(x={x}, y={y})"]
|
|
112
|
+
|
|
113
|
+
if action_type == ActionType.LEFT_TRIPLE.value:
|
|
114
|
+
x, y = parse_click_coords(argument, self._coord_scaler, strict=strict)
|
|
115
|
+
return [f"pyautogui.tripleClick(x={x}, y={y})"]
|
|
116
|
+
|
|
117
|
+
if action_type == ActionType.RIGHT_SINGLE.value:
|
|
118
|
+
x, y = parse_click_coords(argument, self._coord_scaler, strict=strict)
|
|
119
|
+
return [f"pyautogui.rightClick(x={x}, y={y})"]
|
|
120
|
+
|
|
121
|
+
if action_type == ActionType.DRAG.value:
|
|
122
|
+
sx, sy, ex, ey = parse_drag_coords(
|
|
123
|
+
argument, self._coord_scaler, strict=strict
|
|
124
|
+
)
|
|
125
|
+
return [
|
|
126
|
+
f"pyautogui.moveTo({sx}, {sy})",
|
|
127
|
+
f"pyautogui.dragTo({ex}, {ey}, duration={drag_duration})",
|
|
128
|
+
]
|
|
129
|
+
|
|
130
|
+
if action_type == ActionType.HOTKEY.value:
|
|
131
|
+
keys = self.parse_hotkey(argument, validate=True)
|
|
132
|
+
valid_keys = [k for k in keys if k]
|
|
133
|
+
if not valid_keys:
|
|
134
|
+
raise ValueError(
|
|
135
|
+
f"Invalid hotkey format: '{argument}'. "
|
|
136
|
+
"Expected key names like 'ctrl+c', 'alt+tab'"
|
|
137
|
+
)
|
|
138
|
+
# Check if this is a caps lock key press
|
|
139
|
+
if len(valid_keys) == 1 and valid_keys[0] == "capslock":
|
|
140
|
+
if self.caps_manager.should_use_system_capslock():
|
|
141
|
+
return [f"pyautogui.hotkey('capslock', interval={hotkey_interval})"]
|
|
142
|
+
else:
|
|
143
|
+
self.caps_manager.toggle()
|
|
144
|
+
return [] # No pyautogui command for session mode
|
|
145
|
+
else:
|
|
146
|
+
keys_str = ", ".join(repr(k) for k in valid_keys)
|
|
147
|
+
return [f"pyautogui.hotkey({keys_str}, interval={hotkey_interval})"]
|
|
148
|
+
|
|
149
|
+
if action_type == ActionType.TYPE.value:
|
|
150
|
+
text = argument.strip("\"'")
|
|
151
|
+
text = self.caps_manager.transform_text(text)
|
|
152
|
+
return [f"pyautogui.typewrite({text!r})"]
|
|
153
|
+
|
|
154
|
+
if action_type == ActionType.SCROLL.value:
|
|
155
|
+
x, y, direction = parse_scroll_coords(
|
|
156
|
+
argument, self._coord_scaler, strict=strict
|
|
157
|
+
)
|
|
158
|
+
amount = scroll_amount if direction == "up" else -scroll_amount
|
|
159
|
+
return [f"pyautogui.moveTo({x}, {y})", f"pyautogui.scroll({amount})"]
|
|
160
|
+
|
|
161
|
+
if action_type == ActionType.WAIT.value:
|
|
162
|
+
try:
|
|
163
|
+
seconds = float(argument) if argument else wait_duration
|
|
164
|
+
except ValueError:
|
|
165
|
+
raise ValueError(
|
|
166
|
+
f"Invalid wait duration: '{argument}'. "
|
|
167
|
+
"Expected numeric value in seconds."
|
|
168
|
+
)
|
|
169
|
+
return [f"WAIT({seconds})"]
|
|
170
|
+
|
|
171
|
+
if action_type == ActionType.FINISH.value:
|
|
172
|
+
self._log_info("Task completion action -> DONE")
|
|
173
|
+
return ["DONE"]
|
|
174
|
+
|
|
175
|
+
if action_type == ActionType.FAIL.value:
|
|
176
|
+
self._log_info("Task infeasible action -> FAIL")
|
|
177
|
+
return ["FAIL"]
|
|
178
|
+
|
|
179
|
+
if action_type == ActionType.CALL_USER.value:
|
|
180
|
+
self._log_info("User intervention requested")
|
|
181
|
+
return []
|
|
182
|
+
|
|
183
|
+
raise ValueError(
|
|
184
|
+
f"Unknown action type: '{action_type}'. "
|
|
185
|
+
"Supported: click, left_double, left_triple, right_single, drag, "
|
|
186
|
+
"hotkey, type, scroll, wait, finish, fail, call_user"
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
def serialize_actions(self, actions: list[Action]) -> list[dict[str, Any]]:
|
|
190
|
+
"""Serialize OAGI actions for trajectory logging."""
|
|
191
|
+
return [
|
|
192
|
+
{
|
|
193
|
+
"type": action.type.value,
|
|
194
|
+
"argument": action.argument,
|
|
195
|
+
"count": action.count,
|
|
196
|
+
}
|
|
197
|
+
for action in (actions or [])
|
|
198
|
+
]
|