Skip to content

Commit e6bedb9

Browse files
committed
Add canonical computer-use action schema (Anthropic/OpenAI -> AC_*)
1 parent 6f06aa9 commit e6bedb9

15 files changed

Lines changed: 374 additions & 2 deletions

File tree

‎README/WHATS_NEW_zh-CN.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# 本次更新 — AutoControl
22

3+
## 本次更新 (2026-06-23) — 标准化 Computer-Use 动作结构
4+
5+
把 Anthropic / OpenAI agent 动作桥接到 AutoControl 命令。完整参考:[`docs/source/Zh/doc/new_features/v151_features_doc.rst`](../docs/source/Zh/doc/new_features/v151_features_doc.rst)。
6+
7+
- **`from_anthropic` / `from_openai_cua` / `to_ac_command` / `canonical_action`**(`AC_cua_command`):`tool_use_schema` 导出 AC_* 签章、`coordinate_space` 缩放——两者都不*正规化进来的动作载荷*。Anthropic 发出 `{action:"left_click", coordinate:[x,y]}`、OpenAI CUA 发出 `{type:"click", x, y, button}`;这些转接器把两者对应为标准动作再对应为可执行的 `[AC_*, params]`(含可选坐标空间 `scale`)。纯标准库、可无头测试;执行器命令对任一来源返回 `{canonical, command}`。
8+
39
## 本次更新 (2026-06-23) — 窗口客户区几何
410

511
不论标题栏 / 边框,点击窗口*内部*。完整参考:[`docs/source/Zh/doc/new_features/v150_features_doc.rst`](../docs/source/Zh/doc/new_features/v150_features_doc.rst)。

‎README/WHATS_NEW_zh-TW.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# 本次更新 — AutoControl
22

3+
## 本次更新 (2026-06-23) — 標準化 Computer-Use 動作結構
4+
5+
把 Anthropic / OpenAI agent 動作橋接到 AutoControl 命令。完整參考:[`docs/source/Zh/doc/new_features/v151_features_doc.rst`](../docs/source/Zh/doc/new_features/v151_features_doc.rst)。
6+
7+
- **`from_anthropic` / `from_openai_cua` / `to_ac_command` / `canonical_action`**(`AC_cua_command`):`tool_use_schema` 匯出 AC_* 簽章、`coordinate_space` 縮放——兩者都不*正規化進來的動作酬載*。Anthropic 發出 `{action:"left_click", coordinate:[x,y]}`、OpenAI CUA 發出 `{type:"click", x, y, button}`;這些轉接器把兩者對應為標準動作再對應為可執行的 `[AC_*, params]`(含選用座標空間 `scale`)。純標準函式庫、可無頭測試;執行器命令對任一來源回傳 `{canonical, command}`。
8+
39
## 本次更新 (2026-06-23) — 視窗客戶區幾何
410

511
不論標題列 / 邊框,點擊視窗*內部*。完整參考:[`docs/source/Zh/doc/new_features/v150_features_doc.rst`](../docs/source/Zh/doc/new_features/v150_features_doc.rst)。

‎WHATS_NEW.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# What's New — AutoControl
22

3+
## What's new (2026-06-23) — Canonical Computer-Use Action Schema
4+
5+
Bridge Anthropic / OpenAI agent actions to AutoControl commands. Full reference: [`docs/source/Eng/doc/new_features/v151_features_doc.rst`](docs/source/Eng/doc/new_features/v151_features_doc.rst).
6+
7+
- **`from_anthropic` / `from_openai_cua` / `to_ac_command` / `canonical_action`** (`AC_cua_command`): `tool_use_schema` exports AC_* signatures and `coordinate_space` rescales — neither *normalizes an inbound action payload*. Anthropic emits `{action:"left_click", coordinate:[x,y]}`, OpenAI CUA emits `{type:"click", x, y, button}`; these adapters map both to a canonical action and then to a runnable `[AC_*, params]` (with optional coordinate-space `scale`). Pure-stdlib, headless-testable; the executor command returns `{canonical, command}` for any source.
8+
39
## What's new (2026-06-23) — Window Client-Area Geometry
410

511
Click *inside* a window regardless of its title bar / borders. Full reference: [`docs/source/Eng/doc/new_features/v150_features_doc.rst`](docs/source/Eng/doc/new_features/v150_features_doc.rst).
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Canonical Computer-Use Action Schema
2+
====================================
3+
4+
``tool_use_schema`` exports the AC_* command *signatures* as tool definitions and
5+
``coordinate_space`` rescales a model grid — but neither *normalizes an inbound action
6+
payload*. Anthropic's computer-use tool emits ``{action:"left_click",
7+
coordinate:[x,y]}``, OpenAI's CUA emits ``{type:"click", x, y, button}`` — there was no
8+
adapter mapping these heterogeneous shapes onto a canonical action and then onto a
9+
runnable AC_* command, so integrators hand-wrote the glue.
10+
11+
Pure-stdlib dict mapping (an optional ``scale`` callable applies coordinate-space
12+
rescaling), fully headless-testable. Imports no ``PySide6``.
13+
14+
Headless API
15+
------------
16+
17+
.. code-block:: python
18+
19+
from je_auto_control import (from_anthropic, from_openai_cua, to_ac_command,
20+
canonical_action)
21+
22+
# Anthropic agent output -> canonical -> runnable AC action.
23+
canonical = from_anthropic({"action": "left_click", "coordinate": [120, 80]})
24+
command = to_ac_command(canonical)
25+
# -> ["AC_click_mouse", {"mouse_keycode": "mouse_left", "x": 120, "y": 80}]
26+
27+
# OpenAI CUA, with model->physical coordinate rescaling.
28+
cmd = to_ac_command(from_openai_cua({"type": "scroll", "x": 5, "y": 6,
29+
"scroll_y": 120}),
30+
scale=lambda x, y: (x * 2, y * 2))
31+
32+
``from_anthropic`` / ``from_openai_cua`` map each provider's payload to a canonical
33+
``{type, x, y, text, …}`` (clicks, double/right/middle click, move, type, key, scroll,
34+
screenshot). ``to_ac_command`` maps a canonical action to a ``[command_name, params]``
35+
AC action (``AC_click_mouse`` / ``AC_set_mouse_position`` / ``AC_write`` / ``AC_hotkey``
36+
/ ``AC_mouse_scroll`` / ``AC_screenshot``), applying ``scale`` to coordinates; an
37+
unmapped type raises ``AutoControlActionException``. ``canonical_action`` builds a
38+
canonical dict directly.
39+
40+
Executor command
41+
----------------
42+
43+
``AC_cua_command`` normalizes a ``payload`` from ``source`` (``anthropic`` / ``openai``
44+
/ ``canonical``) and returns ``{canonical, command}``. It is exposed as the MCP tool
45+
``ac_cua_command`` and as a Script Builder command under **Native UI**.

‎docs/source/Eng/eng_index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ Comprehensive guides for all AutoControl features.
173173
doc/new_features/v148_features_doc
174174
doc/new_features/v149_features_doc
175175
doc/new_features/v150_features_doc
176+
doc/new_features/v151_features_doc
176177
doc/ocr_backends/ocr_backends_doc
177178
doc/observability/observability_doc
178179
doc/operations_layer/operations_layer_doc
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
標準化 Computer-Use 動作結構
2+
============================
3+
4+
``tool_use_schema`` 把 AC_* 命令*簽章*匯出為工具定義,``coordinate_space`` 縮放模型網格——但兩者都不*正規化進來的
5+
動作酬載*。Anthropic 的 computer-use 工具發出 ``{action:"left_click", coordinate:[x,y]}``,OpenAI 的 CUA 發出
6+
``{type:"click", x, y, button}``——先前沒有把這些異質形狀對應到標準動作、再對應到可執行 AC_* 命令的轉接器,
7+
整合者只能手寫膠水程式。
8+
9+
純標準函式庫的字典對應(選用 ``scale`` callable 套用座標空間縮放),完全可無頭測試。不匯入 ``PySide6``。
10+
11+
無頭 API
12+
--------
13+
14+
.. code-block:: python
15+
16+
from je_auto_control import (from_anthropic, from_openai_cua, to_ac_command,
17+
canonical_action)
18+
19+
# Anthropic agent 輸出 -> 標準 -> 可執行 AC 動作。
20+
canonical = from_anthropic({"action": "left_click", "coordinate": [120, 80]})
21+
command = to_ac_command(canonical)
22+
# -> ["AC_click_mouse", {"mouse_keycode": "mouse_left", "x": 120, "y": 80}]
23+
24+
# OpenAI CUA,含 模型->實體 座標縮放。
25+
cmd = to_ac_command(from_openai_cua({"type": "scroll", "x": 5, "y": 6,
26+
"scroll_y": 120}),
27+
scale=lambda x, y: (x * 2, y * 2))
28+
29+
``from_anthropic`` / ``from_openai_cua`` 把各供應商酬載對應為標準 ``{type, x, y, text, …}``(click、double/right/
30+
middle click、move、type、key、scroll、screenshot)。``to_ac_command`` 把標準動作對應為 ``[command_name, params]``
31+
AC 動作(``AC_click_mouse`` / ``AC_set_mouse_position`` / ``AC_write`` / ``AC_hotkey`` / ``AC_mouse_scroll`` /
32+
``AC_screenshot``),並對座標套用 ``scale``;無法對應的類型會丟出 ``AutoControlActionException``。``canonical_action``
33+
直接建立標準字典。
34+
35+
執行器命令
36+
----------
37+
38+
``AC_cua_command`` 從 ``source``(``anthropic`` / ``openai`` / ``canonical``)正規化 ``payload`` 並回傳
39+
``{canonical, command}``。它以 MCP 工具 ``ac_cua_command`` 以及 Script Builder 中 **Native UI** 分類下的命令提供。

‎docs/source/Zh/zh_index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ AutoControl 所有功能的完整使用指南。
173173
doc/new_features/v148_features_doc
174174
doc/new_features/v149_features_doc
175175
doc/new_features/v150_features_doc
176+
doc/new_features/v151_features_doc
176177
doc/ocr_backends/ocr_backends_doc
177178
doc/observability/observability_doc
178179
doc/operations_layer/operations_layer_doc

‎je_auto_control/__init__.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@
361361
from je_auto_control.utils.window_geometry import (
362362
client_point, client_to_screen, frame_insets, get_client_rect,
363363
)
364+
# Canonical computer-use action schema (normalize Anthropic / OpenAI -> AC_*)
365+
from je_auto_control.utils.cua_action import (
366+
canonical_action, from_anthropic, from_openai_cua, to_ac_command,
367+
)
364368
# CI workflow annotations (GitHub Actions)
365369
from je_auto_control.utils.ci_annotations import (
366370
emit_annotations, format_annotation,
@@ -1235,6 +1239,10 @@ def start_autocontrol_gui(*args, **kwargs):
12351239
"client_to_screen",
12361240
"get_client_rect",
12371241
"client_point",
1242+
"canonical_action",
1243+
"from_anthropic",
1244+
"from_openai_cua",
1245+
"to_ac_command",
12381246
"emit_annotations", "format_annotation",
12391247
"ClipboardHistory", "default_clipboard_history",
12401248
"analyze_heal_log", "heal_stats", "scan_secrets",

‎je_auto_control/gui/script_builder/command_schema.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,6 +2910,16 @@ def _add_screen_state_specs(specs: List[CommandSpec]) -> None:
29102910

29112911

29122912
def _add_set_of_marks_specs(specs: List[CommandSpec]) -> None:
2913+
specs.append(CommandSpec(
2914+
"AC_cua_command", "Native UI", "Computer-Use: Map Action",
2915+
fields=(
2916+
FieldSpec("payload", FieldType.STRING,
2917+
placeholder='{"action":"left_click","coordinate":[x,y]}'),
2918+
FieldSpec("source", FieldType.ENUM, optional=True, default="canonical",
2919+
choices=("canonical", "anthropic", "openai")),
2920+
),
2921+
description="Map an Anthropic / OpenAI computer-use action to an AC command.",
2922+
))
29132923
specs.append(CommandSpec(
29142924
"AC_mark_screen", "Native UI", "Set-of-Marks: Number Elements",
29152925
fields=(
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""Canonical computer-use action schema (normalize Anthropic / OpenAI -> AC_*)."""
2+
from je_auto_control.utils.cua_action.cua_action import (
3+
canonical_action, from_anthropic, from_openai_cua, to_ac_command,
4+
)
5+
6+
__all__ = ["canonical_action", "from_anthropic", "from_openai_cua",
7+
"to_ac_command"]

0 commit comments

Comments
 (0)