autoglm-gui 1.4.1__py3-none-any.whl → 1.5.1__py3-none-any.whl
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.
- AutoGLM_GUI/__init__.py +11 -0
- AutoGLM_GUI/__main__.py +26 -4
- AutoGLM_GUI/actions/__init__.py +6 -0
- phone_agent/actions/handler_ios.py → AutoGLM_GUI/actions/handler.py +30 -112
- AutoGLM_GUI/actions/types.py +15 -0
- {phone_agent → AutoGLM_GUI}/adb/__init__.py +25 -23
- {phone_agent → AutoGLM_GUI}/adb/connection.py +5 -40
- {phone_agent → AutoGLM_GUI}/adb/device.py +12 -94
- {phone_agent → AutoGLM_GUI}/adb/input.py +6 -47
- AutoGLM_GUI/adb/screenshot.py +11 -0
- {phone_agent/config → AutoGLM_GUI/adb}/timing.py +1 -1
- AutoGLM_GUI/adb_plus/keyboard_installer.py +4 -2
- AutoGLM_GUI/adb_plus/screenshot.py +22 -1
- AutoGLM_GUI/adb_plus/serial.py +38 -20
- AutoGLM_GUI/adb_plus/touch.py +4 -9
- AutoGLM_GUI/agents/__init__.py +43 -12
- AutoGLM_GUI/agents/events.py +19 -0
- AutoGLM_GUI/agents/factory.py +31 -38
- AutoGLM_GUI/agents/glm/__init__.py +7 -0
- AutoGLM_GUI/agents/glm/agent.py +297 -0
- AutoGLM_GUI/agents/glm/message_builder.py +81 -0
- AutoGLM_GUI/agents/glm/parser.py +110 -0
- {phone_agent/config → AutoGLM_GUI/agents/glm}/prompts_en.py +7 -9
- {phone_agent/config → AutoGLM_GUI/agents/glm}/prompts_zh.py +18 -25
- AutoGLM_GUI/agents/mai/__init__.py +28 -0
- AutoGLM_GUI/agents/mai/agent.py +408 -0
- AutoGLM_GUI/agents/mai/parser.py +254 -0
- AutoGLM_GUI/agents/mai/prompts.py +103 -0
- AutoGLM_GUI/agents/mai/traj_memory.py +91 -0
- AutoGLM_GUI/agents/protocols.py +12 -8
- AutoGLM_GUI/agents/stream_runner.py +193 -0
- AutoGLM_GUI/api/__init__.py +40 -21
- AutoGLM_GUI/api/agents.py +181 -239
- AutoGLM_GUI/api/control.py +9 -6
- AutoGLM_GUI/api/devices.py +102 -12
- AutoGLM_GUI/api/history.py +104 -0
- AutoGLM_GUI/api/layered_agent.py +67 -15
- AutoGLM_GUI/api/media.py +64 -1
- AutoGLM_GUI/api/scheduled_tasks.py +98 -0
- AutoGLM_GUI/config.py +81 -0
- AutoGLM_GUI/config_manager.py +68 -51
- AutoGLM_GUI/device_manager.py +248 -29
- AutoGLM_GUI/device_protocol.py +1 -1
- AutoGLM_GUI/devices/adb_device.py +5 -10
- AutoGLM_GUI/devices/mock_device.py +4 -2
- AutoGLM_GUI/devices/remote_device.py +8 -3
- AutoGLM_GUI/history_manager.py +164 -0
- AutoGLM_GUI/model/__init__.py +5 -0
- AutoGLM_GUI/model/message_builder.py +69 -0
- AutoGLM_GUI/model/types.py +24 -0
- AutoGLM_GUI/models/__init__.py +10 -0
- AutoGLM_GUI/models/history.py +140 -0
- AutoGLM_GUI/models/scheduled_task.py +71 -0
- AutoGLM_GUI/parsers/__init__.py +22 -0
- AutoGLM_GUI/parsers/base.py +50 -0
- AutoGLM_GUI/parsers/phone_parser.py +58 -0
- AutoGLM_GUI/phone_agent_manager.py +62 -396
- AutoGLM_GUI/platform_utils.py +26 -0
- AutoGLM_GUI/prompt_config.py +15 -0
- AutoGLM_GUI/prompts/__init__.py +32 -0
- AutoGLM_GUI/scheduler_manager.py +350 -0
- AutoGLM_GUI/schemas.py +246 -72
- AutoGLM_GUI/scrcpy_stream.py +142 -24
- AutoGLM_GUI/socketio_server.py +100 -27
- AutoGLM_GUI/static/assets/{about-_XNhzQZX.js → about-CfwX1Cmc.js} +1 -1
- AutoGLM_GUI/static/assets/alert-dialog-CtGlN2IJ.js +1 -0
- AutoGLM_GUI/static/assets/chat-BYa-foUI.js +129 -0
- AutoGLM_GUI/static/assets/circle-alert-t08bEMPO.js +1 -0
- AutoGLM_GUI/static/assets/dialog-FNwZJFwk.js +45 -0
- AutoGLM_GUI/static/assets/eye-D0UPWCWC.js +1 -0
- AutoGLM_GUI/static/assets/history-CRo95B7i.js +1 -0
- AutoGLM_GUI/static/assets/{index-Cy8TmmHV.js → index-BaLMSqd3.js} +1 -1
- AutoGLM_GUI/static/assets/index-CTHbFvKl.js +11 -0
- AutoGLM_GUI/static/assets/index-CV7jGxGm.css +1 -0
- AutoGLM_GUI/static/assets/label-DJFevVmr.js +1 -0
- AutoGLM_GUI/static/assets/logs-RW09DyYY.js +1 -0
- AutoGLM_GUI/static/assets/popover--JTJrE5v.js +1 -0
- AutoGLM_GUI/static/assets/scheduled-tasks-DTRKsQXF.js +1 -0
- AutoGLM_GUI/static/assets/square-pen-CPK_K680.js +1 -0
- AutoGLM_GUI/static/assets/textarea-PRmVnWq5.js +1 -0
- AutoGLM_GUI/static/assets/workflows-CdcsAoaT.js +1 -0
- AutoGLM_GUI/static/index.html +2 -2
- AutoGLM_GUI/types.py +17 -0
- {autoglm_gui-1.4.1.dist-info → autoglm_gui-1.5.1.dist-info}/METADATA +179 -130
- autoglm_gui-1.5.1.dist-info/RECORD +118 -0
- AutoGLM_GUI/agents/mai_adapter.py +0 -627
- AutoGLM_GUI/api/dual_model.py +0 -317
- AutoGLM_GUI/device_adapter.py +0 -263
- AutoGLM_GUI/dual_model/__init__.py +0 -53
- AutoGLM_GUI/dual_model/decision_model.py +0 -664
- AutoGLM_GUI/dual_model/dual_agent.py +0 -917
- AutoGLM_GUI/dual_model/protocols.py +0 -354
- AutoGLM_GUI/dual_model/vision_model.py +0 -442
- AutoGLM_GUI/mai_ui_adapter/agent_wrapper.py +0 -291
- AutoGLM_GUI/phone_agent_patches.py +0 -147
- AutoGLM_GUI/static/assets/chat-DwJpiAWf.js +0 -126
- AutoGLM_GUI/static/assets/dialog-B3uW4T8V.js +0 -45
- AutoGLM_GUI/static/assets/index-Cpv2gSF1.css +0 -1
- AutoGLM_GUI/static/assets/index-UYYauTly.js +0 -12
- AutoGLM_GUI/static/assets/workflows-Du_de-dt.js +0 -1
- autoglm_gui-1.4.1.dist-info/RECORD +0 -117
- mai_agent/base.py +0 -137
- mai_agent/mai_grounding_agent.py +0 -263
- mai_agent/mai_naivigation_agent.py +0 -526
- mai_agent/prompt.py +0 -148
- mai_agent/unified_memory.py +0 -67
- mai_agent/utils.py +0 -73
- phone_agent/__init__.py +0 -12
- phone_agent/actions/__init__.py +0 -5
- phone_agent/actions/handler.py +0 -400
- phone_agent/adb/screenshot.py +0 -108
- phone_agent/agent.py +0 -253
- phone_agent/agent_ios.py +0 -277
- phone_agent/config/__init__.py +0 -53
- phone_agent/config/apps_harmonyos.py +0 -256
- phone_agent/config/apps_ios.py +0 -339
- phone_agent/config/prompts.py +0 -80
- phone_agent/device_factory.py +0 -166
- phone_agent/hdc/__init__.py +0 -53
- phone_agent/hdc/connection.py +0 -384
- phone_agent/hdc/device.py +0 -269
- phone_agent/hdc/input.py +0 -145
- phone_agent/hdc/screenshot.py +0 -127
- phone_agent/model/__init__.py +0 -5
- phone_agent/model/client.py +0 -290
- phone_agent/xctest/__init__.py +0 -47
- phone_agent/xctest/connection.py +0 -379
- phone_agent/xctest/device.py +0 -472
- phone_agent/xctest/input.py +0 -311
- phone_agent/xctest/screenshot.py +0 -226
- {phone_agent/config → AutoGLM_GUI/adb}/apps.py +0 -0
- {phone_agent/config → AutoGLM_GUI}/i18n.py +0 -0
- {autoglm_gui-1.4.1.dist-info → autoglm_gui-1.5.1.dist-info}/WHEEL +0 -0
- {autoglm_gui-1.4.1.dist-info → autoglm_gui-1.5.1.dist-info}/entry_points.txt +0 -0
- {autoglm_gui-1.4.1.dist-info → autoglm_gui-1.5.1.dist-info}/licenses/LICENSE +0 -0
phone_agent/config/prompts.py
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"""System prompts for the AI agent."""
|
|
2
|
-
|
|
3
|
-
from datetime import datetime
|
|
4
|
-
|
|
5
|
-
today = datetime.today()
|
|
6
|
-
# NOTE: Do NOT use strftime with Chinese characters in format string!
|
|
7
|
-
# On some Windows systems with non-UTF-8 locale (e.g., GBK/CP936),
|
|
8
|
-
# strftime("%Y年%m月%d日") raises UnicodeEncodeError because the C library's
|
|
9
|
-
# strftime uses locale encoding, not Python's UTF-8 mode.
|
|
10
|
-
# Use f-string instead to avoid this issue completely.
|
|
11
|
-
formatted_date = f"{today.year}年{today.month:02d}月{today.day:02d}日"
|
|
12
|
-
|
|
13
|
-
SYSTEM_PROMPT = (
|
|
14
|
-
"今天的日期是: "
|
|
15
|
-
+ formatted_date
|
|
16
|
-
+ """
|
|
17
|
-
你是一个智能体分析专家,可以根据操作历史和当前状态图执行一系列操作来完成任务。
|
|
18
|
-
你必须严格按照要求输出以下格式:
|
|
19
|
-
<think>{think}</think>
|
|
20
|
-
<answer>{action}</answer>
|
|
21
|
-
|
|
22
|
-
其中:
|
|
23
|
-
- {think} 是对你为什么选择这个操作的简短推理说明。
|
|
24
|
-
- {action} 是本次执行的具体操作指令,必须严格遵循下方定义的指令格式。
|
|
25
|
-
|
|
26
|
-
操作指令及其作用如下:
|
|
27
|
-
- do(action="Launch", app="xxx")
|
|
28
|
-
Launch是启动目标app的操作,这比通过主屏幕导航更快。此操作完成后,您将自动收到结果状态的截图。
|
|
29
|
-
- do(action="Tap", element=[x,y])
|
|
30
|
-
Tap是点击操作,点击屏幕上的特定点。可用此操作点击按钮、选择项目、从主屏幕打开应用程序,或与任何可点击的用户界面元素进行交互。坐标系统从左上角 (0,0) 开始到右下角(999,999)结束。此操作完成后,您将自动收到结果状态的截图。
|
|
31
|
-
- do(action="Tap", element=[x,y], message="重要操作")
|
|
32
|
-
基本功能同Tap,点击涉及财产、支付、隐私等敏感按钮时触发。
|
|
33
|
-
- do(action="Type", text="xxx")
|
|
34
|
-
Type是输入操作,在当前聚焦的输入框中输入文本。使用此操作前,请确保输入框已被聚焦(先点击它)。输入的文本将像使用键盘输入一样输入。重要提示:手机可能正在使用 ADB 键盘,该键盘不会像普通键盘那样占用屏幕空间。要确认键盘已激活,请查看屏幕底部是否显示 'ADB Keyboard {ON}' 类似的文本,或者检查输入框是否处于激活/高亮状态。不要仅仅依赖视觉上的键盘显示。自动清除文本:当你使用输入操作时,输入框中现有的任何文本(包括占位符文本和实际输入)都会在输入新文本前自动清除。你无需在输入前手动清除文本——直接使用输入操作输入所需文本即可。操作完成后,你将自动收到结果状态的截图。
|
|
35
|
-
- do(action="Type_Name", text="xxx")
|
|
36
|
-
Type_Name是输入人名的操作,基本功能同Type。
|
|
37
|
-
- do(action="Interact")
|
|
38
|
-
Interact是当有多个满足条件的选项时而触发的交互操作,询问用户如何选择。
|
|
39
|
-
- do(action="Swipe", start=[x1,y1], end=[x2,y2])
|
|
40
|
-
Swipe是滑动操作,通过从起始坐标拖动到结束坐标来执行滑动手势。可用于滚动内容、在屏幕之间导航、下拉通知栏以及项目栏或进行基于手势的导航。坐标系统从左上角 (0,0) 开始到右下角(999,999)结束。滑动持续时间会自动调整以实现自然的移动。此操作完成后,您将自动收到结果状态的截图。
|
|
41
|
-
- do(action="Note", message="True")
|
|
42
|
-
记录当前页面内容以便后续总结。
|
|
43
|
-
- do(action="Call_API", instruction="xxx")
|
|
44
|
-
总结或评论当前页面或已记录的内容。
|
|
45
|
-
- do(action="Long Press", element=[x,y])
|
|
46
|
-
Long Pres是长按操作,在屏幕上的特定点长按指定时间。可用于触发上下文菜单、选择文本或激活长按交互。坐标系统从左上角 (0,0) 开始到右下角(999,999)结束。此操作完成后,您将自动收到结果状态的屏幕截图。
|
|
47
|
-
- do(action="Double Tap", element=[x,y])
|
|
48
|
-
Double Tap在屏幕上的特定点快速连续点按两次。使用此操作可以激活双击交互,如缩放、选择文本或打开项目。坐标系统从左上角 (0,0) 开始到右下角(999,999)结束。此操作完成后,您将自动收到结果状态的截图。
|
|
49
|
-
- do(action="Take_over", message="xxx")
|
|
50
|
-
Take_over是接管操作,表示在登录和验证阶段需要用户协助。
|
|
51
|
-
- do(action="Back")
|
|
52
|
-
导航返回到上一个屏幕或关闭当前对话框。相当于按下 Android 的返回按钮。使用此操作可以从更深的屏幕返回、关闭弹出窗口或退出当前上下文。此操作完成后,您将自动收到结果状态的截图。
|
|
53
|
-
- do(action="Home")
|
|
54
|
-
Home是回到系统桌面的操作,相当于按下 Android 主屏幕按钮。使用此操作可退出当前应用并返回启动器,或从已知状态启动新任务。此操作完成后,您将自动收到结果状态的截图。
|
|
55
|
-
- do(action="Wait", duration="x seconds")
|
|
56
|
-
等待页面加载,x为需要等待多少秒。
|
|
57
|
-
- finish(message="xxx")
|
|
58
|
-
finish是结束任务的操作,表示准确完整完成任务,message是终止信息。
|
|
59
|
-
|
|
60
|
-
必须遵循的规则:
|
|
61
|
-
1. 在执行任何操作前,先检查当前app是否是目标app,如果不是,先执行 Launch。
|
|
62
|
-
2. 如果进入到了无关页面,先执行 Back。如果执行Back后页面没有变化,请点击页面左上角的返回键进行返回,或者右上角的X号关闭。
|
|
63
|
-
3. 如果页面未加载出内容,最多连续 Wait 三次,否则执行 Back重新进入。
|
|
64
|
-
4. 如果页面显示网络问题,需要重新加载,请点击重新加载。
|
|
65
|
-
5. 如果当前页面找不到目标联系人、商品、店铺等信息,可以尝试 Swipe 滑动查找。
|
|
66
|
-
6. 遇到价格区间、时间区间等筛选条件,如果没有完全符合的,可以放宽要求。
|
|
67
|
-
7. 在做小红书总结类任务时一定要筛选图文笔记。
|
|
68
|
-
8. 购物车全选后再点击全选可以把状态设为全不选,在做购物车任务时,如果购物车里已经有商品被选中时,你需要点击全选后再点击取消全选,再去找需要购买或者删除的商品。
|
|
69
|
-
9. 在做外卖任务时,如果相应店铺购物车里已经有其他商品你需要先把购物车清空再去购买用户指定的外卖。
|
|
70
|
-
10. 在做点外卖任务时,如果用户需要点多个外卖,请尽量在同一店铺进行购买,如果无法找到可以下单,并说明某个商品未找到。
|
|
71
|
-
11. 请严格遵循用户意图执行任务,用户的特殊要求可以执行多次搜索,滑动查找。比如(i)用户要求点一杯咖啡,要咸的,你可以直接搜索咸咖啡,或者搜索咖啡后滑动查找咸的咖啡,比如海盐咖啡。(ii)用户要找到XX群,发一条消息,你可以先搜索XX群,找不到结果后,将"群"字去掉,搜索XX重试。(iii)用户要找到宠物友好的餐厅,你可以搜索餐厅,找到筛选,找到设施,选择可带宠物,或者直接搜索可带宠物,必要时可以使用AI搜索。
|
|
72
|
-
12. 在选择日期时,如果原滑动方向与预期日期越来越远,请向反方向滑动查找。
|
|
73
|
-
13. 执行任务过程中如果有多个可选择的项目栏,请逐个查找每个项目栏,直到完成任务,一定不要在同一项目栏多次查找,从而陷入死循环。
|
|
74
|
-
14. 在执行下一步操作前请一定要检查上一步的操作是否生效,如果点击没生效,可能因为app反应较慢,请先稍微等待一下,如果还是不生效请调整一下点击位置重试,如果仍然不生效请跳过这一步继续任务,并在finish message说明点击不生效。
|
|
75
|
-
15. 在执行任务中如果遇到滑动不生效的情况,请调整一下起始点位置,增大滑动距离重试,如果还是不生效,有可能是已经滑到底了,请继续向反方向滑动,直到顶部或底部,如果仍然没有符合要求的结果,请跳过这一步继续任务,并在finish message说明但没找到要求的项目。
|
|
76
|
-
16. 在做游戏任务时如果在战斗页面如果有自动战斗一定要开启自动战斗,如果多轮历史状态相似要检查自动战斗是否开启。
|
|
77
|
-
17. 如果没有合适的搜索结果,可能是因为搜索页面不对,请返回到搜索页面的上一级尝试重新搜索,如果尝试三次返回上一级搜索后仍然没有符合要求的结果,执行 finish(message="原因")。
|
|
78
|
-
18. 在结束任务前请一定要仔细检查任务是否完整准确的完成,如果出现错选、漏选、多选的情况,请返回之前的步骤进行纠正。
|
|
79
|
-
"""
|
|
80
|
-
)
|
phone_agent/device_factory.py
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
"""Device factory for selecting ADB or HDC based on device type."""
|
|
2
|
-
|
|
3
|
-
from enum import Enum
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class DeviceType(Enum):
|
|
7
|
-
"""Type of device connection tool."""
|
|
8
|
-
|
|
9
|
-
ADB = "adb"
|
|
10
|
-
HDC = "hdc"
|
|
11
|
-
IOS = "ios"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class DeviceFactory:
|
|
15
|
-
"""
|
|
16
|
-
Factory class for getting device-specific implementations.
|
|
17
|
-
|
|
18
|
-
This allows the system to work with both Android (ADB) and HarmonyOS (HDC) devices.
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
|
-
def __init__(self, device_type: DeviceType = DeviceType.ADB):
|
|
22
|
-
"""
|
|
23
|
-
Initialize the device factory.
|
|
24
|
-
|
|
25
|
-
Args:
|
|
26
|
-
device_type: The type of device to use (ADB or HDC).
|
|
27
|
-
"""
|
|
28
|
-
self.device_type = device_type
|
|
29
|
-
self._module = None
|
|
30
|
-
|
|
31
|
-
@property
|
|
32
|
-
def module(self):
|
|
33
|
-
"""Get the appropriate device module (adb or hdc)."""
|
|
34
|
-
if self._module is None:
|
|
35
|
-
if self.device_type == DeviceType.ADB:
|
|
36
|
-
from phone_agent import adb
|
|
37
|
-
|
|
38
|
-
self._module = adb
|
|
39
|
-
elif self.device_type == DeviceType.HDC:
|
|
40
|
-
from phone_agent import hdc
|
|
41
|
-
|
|
42
|
-
self._module = hdc
|
|
43
|
-
else:
|
|
44
|
-
raise ValueError(f"Unknown device type: {self.device_type}")
|
|
45
|
-
return self._module
|
|
46
|
-
|
|
47
|
-
def get_screenshot(self, device_id: str | None = None, timeout: int = 10):
|
|
48
|
-
"""Get screenshot from device."""
|
|
49
|
-
return self.module.get_screenshot(device_id, timeout)
|
|
50
|
-
|
|
51
|
-
def get_current_app(self, device_id: str | None = None) -> str:
|
|
52
|
-
"""Get current app name."""
|
|
53
|
-
return self.module.get_current_app(device_id)
|
|
54
|
-
|
|
55
|
-
def tap(
|
|
56
|
-
self, x: int, y: int, device_id: str | None = None, delay: float | None = None
|
|
57
|
-
):
|
|
58
|
-
"""Tap at coordinates."""
|
|
59
|
-
return self.module.tap(x, y, device_id, delay)
|
|
60
|
-
|
|
61
|
-
def double_tap(
|
|
62
|
-
self, x: int, y: int, device_id: str | None = None, delay: float | None = None
|
|
63
|
-
):
|
|
64
|
-
"""Double tap at coordinates."""
|
|
65
|
-
return self.module.double_tap(x, y, device_id, delay)
|
|
66
|
-
|
|
67
|
-
def long_press(
|
|
68
|
-
self,
|
|
69
|
-
x: int,
|
|
70
|
-
y: int,
|
|
71
|
-
duration_ms: int = 3000,
|
|
72
|
-
device_id: str | None = None,
|
|
73
|
-
delay: float | None = None,
|
|
74
|
-
):
|
|
75
|
-
"""Long press at coordinates."""
|
|
76
|
-
return self.module.long_press(x, y, duration_ms, device_id, delay)
|
|
77
|
-
|
|
78
|
-
def swipe(
|
|
79
|
-
self,
|
|
80
|
-
start_x: int,
|
|
81
|
-
start_y: int,
|
|
82
|
-
end_x: int,
|
|
83
|
-
end_y: int,
|
|
84
|
-
duration_ms: int | None = None,
|
|
85
|
-
device_id: str | None = None,
|
|
86
|
-
delay: float | None = None,
|
|
87
|
-
):
|
|
88
|
-
"""Swipe from start to end."""
|
|
89
|
-
return self.module.swipe(
|
|
90
|
-
start_x, start_y, end_x, end_y, duration_ms, device_id, delay
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
def back(self, device_id: str | None = None, delay: float | None = None):
|
|
94
|
-
"""Press back button."""
|
|
95
|
-
return self.module.back(device_id, delay)
|
|
96
|
-
|
|
97
|
-
def home(self, device_id: str | None = None, delay: float | None = None):
|
|
98
|
-
"""Press home button."""
|
|
99
|
-
return self.module.home(device_id, delay)
|
|
100
|
-
|
|
101
|
-
def launch_app(
|
|
102
|
-
self, app_name: str, device_id: str | None = None, delay: float | None = None
|
|
103
|
-
) -> bool:
|
|
104
|
-
"""Launch an app."""
|
|
105
|
-
return self.module.launch_app(app_name, device_id, delay)
|
|
106
|
-
|
|
107
|
-
def type_text(self, text: str, device_id: str | None = None):
|
|
108
|
-
"""Type text."""
|
|
109
|
-
return self.module.type_text(text, device_id)
|
|
110
|
-
|
|
111
|
-
def clear_text(self, device_id: str | None = None):
|
|
112
|
-
"""Clear text."""
|
|
113
|
-
return self.module.clear_text(device_id)
|
|
114
|
-
|
|
115
|
-
def detect_and_set_adb_keyboard(self, device_id: str | None = None) -> str:
|
|
116
|
-
"""Detect and set keyboard."""
|
|
117
|
-
return self.module.detect_and_set_adb_keyboard(device_id)
|
|
118
|
-
|
|
119
|
-
def restore_keyboard(self, ime: str, device_id: str | None = None):
|
|
120
|
-
"""Restore keyboard."""
|
|
121
|
-
return self.module.restore_keyboard(ime, device_id)
|
|
122
|
-
|
|
123
|
-
def list_devices(self):
|
|
124
|
-
"""List connected devices."""
|
|
125
|
-
return self.module.list_devices()
|
|
126
|
-
|
|
127
|
-
def get_connection_class(self):
|
|
128
|
-
"""Get the connection class (ADBConnection or HDCConnection)."""
|
|
129
|
-
if self.device_type == DeviceType.ADB:
|
|
130
|
-
from phone_agent.adb import ADBConnection
|
|
131
|
-
|
|
132
|
-
return ADBConnection
|
|
133
|
-
elif self.device_type == DeviceType.HDC:
|
|
134
|
-
from phone_agent.hdc import HDCConnection
|
|
135
|
-
|
|
136
|
-
return HDCConnection
|
|
137
|
-
else:
|
|
138
|
-
raise ValueError(f"Unknown device type: {self.device_type}")
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
# Global device factory instance
|
|
142
|
-
_device_factory: DeviceFactory | None = None
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
def set_device_type(device_type: DeviceType):
|
|
146
|
-
"""
|
|
147
|
-
Set the global device type.
|
|
148
|
-
|
|
149
|
-
Args:
|
|
150
|
-
device_type: The device type to use (ADB or HDC).
|
|
151
|
-
"""
|
|
152
|
-
global _device_factory
|
|
153
|
-
_device_factory = DeviceFactory(device_type)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
def get_device_factory() -> DeviceFactory:
|
|
157
|
-
"""
|
|
158
|
-
Get the global device factory instance.
|
|
159
|
-
|
|
160
|
-
Returns:
|
|
161
|
-
The device factory instance.
|
|
162
|
-
"""
|
|
163
|
-
global _device_factory
|
|
164
|
-
if _device_factory is None:
|
|
165
|
-
_device_factory = DeviceFactory(DeviceType.ADB) # Default to ADB
|
|
166
|
-
return _device_factory
|
phone_agent/hdc/__init__.py
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"""HDC utilities for HarmonyOS device interaction."""
|
|
2
|
-
|
|
3
|
-
from phone_agent.hdc.connection import (
|
|
4
|
-
HDCConnection,
|
|
5
|
-
ConnectionType,
|
|
6
|
-
DeviceInfo,
|
|
7
|
-
list_devices,
|
|
8
|
-
quick_connect,
|
|
9
|
-
set_hdc_verbose,
|
|
10
|
-
)
|
|
11
|
-
from phone_agent.hdc.device import (
|
|
12
|
-
back,
|
|
13
|
-
double_tap,
|
|
14
|
-
get_current_app,
|
|
15
|
-
home,
|
|
16
|
-
launch_app,
|
|
17
|
-
long_press,
|
|
18
|
-
swipe,
|
|
19
|
-
tap,
|
|
20
|
-
)
|
|
21
|
-
from phone_agent.hdc.input import (
|
|
22
|
-
clear_text,
|
|
23
|
-
detect_and_set_adb_keyboard,
|
|
24
|
-
restore_keyboard,
|
|
25
|
-
type_text,
|
|
26
|
-
)
|
|
27
|
-
from phone_agent.hdc.screenshot import get_screenshot
|
|
28
|
-
|
|
29
|
-
__all__ = [
|
|
30
|
-
# Screenshot
|
|
31
|
-
"get_screenshot",
|
|
32
|
-
# Input
|
|
33
|
-
"type_text",
|
|
34
|
-
"clear_text",
|
|
35
|
-
"detect_and_set_adb_keyboard",
|
|
36
|
-
"restore_keyboard",
|
|
37
|
-
# Device control
|
|
38
|
-
"get_current_app",
|
|
39
|
-
"tap",
|
|
40
|
-
"swipe",
|
|
41
|
-
"back",
|
|
42
|
-
"home",
|
|
43
|
-
"double_tap",
|
|
44
|
-
"long_press",
|
|
45
|
-
"launch_app",
|
|
46
|
-
# Connection management
|
|
47
|
-
"HDCConnection",
|
|
48
|
-
"DeviceInfo",
|
|
49
|
-
"ConnectionType",
|
|
50
|
-
"quick_connect",
|
|
51
|
-
"list_devices",
|
|
52
|
-
"set_hdc_verbose",
|
|
53
|
-
]
|
phone_agent/hdc/connection.py
DELETED
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
"""HDC connection management for HarmonyOS devices."""
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
import subprocess
|
|
5
|
-
import time
|
|
6
|
-
from dataclasses import dataclass
|
|
7
|
-
from enum import Enum
|
|
8
|
-
|
|
9
|
-
from phone_agent.config.timing import TIMING_CONFIG
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
# Global flag to control HDC command output
|
|
13
|
-
_HDC_VERBOSE = os.getenv("HDC_VERBOSE", "false").lower() in ("true", "1", "yes")
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def _run_hdc_command(cmd: list, **kwargs) -> subprocess.CompletedProcess:
|
|
17
|
-
"""
|
|
18
|
-
Run HDC command with optional verbose output.
|
|
19
|
-
|
|
20
|
-
Args:
|
|
21
|
-
cmd: Command list to execute.
|
|
22
|
-
**kwargs: Additional arguments for subprocess.run.
|
|
23
|
-
|
|
24
|
-
Returns:
|
|
25
|
-
CompletedProcess result.
|
|
26
|
-
"""
|
|
27
|
-
if _HDC_VERBOSE:
|
|
28
|
-
print(f"[HDC] Running command: {' '.join(cmd)}")
|
|
29
|
-
|
|
30
|
-
result = subprocess.run(cmd, **kwargs)
|
|
31
|
-
|
|
32
|
-
if _HDC_VERBOSE and result.returncode != 0:
|
|
33
|
-
print(f"[HDC] Command failed with return code {result.returncode}")
|
|
34
|
-
if hasattr(result, "stderr") and result.stderr:
|
|
35
|
-
print(f"[HDC] Error: {result.stderr}")
|
|
36
|
-
|
|
37
|
-
return result
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def set_hdc_verbose(verbose: bool):
|
|
41
|
-
"""Set HDC verbose mode globally."""
|
|
42
|
-
global _HDC_VERBOSE
|
|
43
|
-
_HDC_VERBOSE = verbose
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
class ConnectionType(Enum):
|
|
47
|
-
"""Type of HDC connection."""
|
|
48
|
-
|
|
49
|
-
USB = "usb"
|
|
50
|
-
WIFI = "wifi"
|
|
51
|
-
REMOTE = "remote"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
@dataclass
|
|
55
|
-
class DeviceInfo:
|
|
56
|
-
"""Information about a connected device."""
|
|
57
|
-
|
|
58
|
-
device_id: str
|
|
59
|
-
status: str
|
|
60
|
-
connection_type: ConnectionType
|
|
61
|
-
model: str | None = None
|
|
62
|
-
harmony_version: str | None = None
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class HDCConnection:
|
|
66
|
-
"""
|
|
67
|
-
Manages HDC connections to HarmonyOS devices.
|
|
68
|
-
|
|
69
|
-
Supports USB, WiFi, and remote TCP/IP connections.
|
|
70
|
-
|
|
71
|
-
Example:
|
|
72
|
-
>>> conn = HDCConnection()
|
|
73
|
-
>>> # Connect to remote device
|
|
74
|
-
>>> conn.connect("192.168.1.100:5555")
|
|
75
|
-
>>> # List devices
|
|
76
|
-
>>> devices = conn.list_devices()
|
|
77
|
-
>>> # Disconnect
|
|
78
|
-
>>> conn.disconnect("192.168.1.100:5555")
|
|
79
|
-
"""
|
|
80
|
-
|
|
81
|
-
def __init__(self, hdc_path: str = "hdc"):
|
|
82
|
-
"""
|
|
83
|
-
Initialize HDC connection manager.
|
|
84
|
-
|
|
85
|
-
Args:
|
|
86
|
-
hdc_path: Path to HDC executable.
|
|
87
|
-
"""
|
|
88
|
-
self.hdc_path = hdc_path
|
|
89
|
-
|
|
90
|
-
def connect(self, address: str, timeout: int = 10) -> tuple[bool, str]:
|
|
91
|
-
"""
|
|
92
|
-
Connect to a remote device via TCP/IP.
|
|
93
|
-
|
|
94
|
-
Args:
|
|
95
|
-
address: Device address in format "host:port" (e.g., "192.168.1.100:5555").
|
|
96
|
-
timeout: Connection timeout in seconds.
|
|
97
|
-
|
|
98
|
-
Returns:
|
|
99
|
-
Tuple of (success, message).
|
|
100
|
-
|
|
101
|
-
Note:
|
|
102
|
-
The remote device must have TCP/IP debugging enabled.
|
|
103
|
-
"""
|
|
104
|
-
# Validate address format
|
|
105
|
-
if ":" not in address:
|
|
106
|
-
address = f"{address}:5555" # Default HDC port
|
|
107
|
-
|
|
108
|
-
try:
|
|
109
|
-
result = _run_hdc_command(
|
|
110
|
-
[self.hdc_path, "tconn", address],
|
|
111
|
-
capture_output=True,
|
|
112
|
-
text=True,
|
|
113
|
-
timeout=timeout,
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
output = result.stdout + result.stderr
|
|
117
|
-
|
|
118
|
-
if "Connect OK" in output or "connected" in output.lower():
|
|
119
|
-
return True, f"Connected to {address}"
|
|
120
|
-
elif "already connected" in output.lower():
|
|
121
|
-
return True, f"Already connected to {address}"
|
|
122
|
-
else:
|
|
123
|
-
return False, output.strip()
|
|
124
|
-
|
|
125
|
-
except subprocess.TimeoutExpired:
|
|
126
|
-
return False, f"Connection timeout after {timeout}s"
|
|
127
|
-
except Exception as e:
|
|
128
|
-
return False, f"Connection error: {e}"
|
|
129
|
-
|
|
130
|
-
def disconnect(self, address: str | None = None) -> tuple[bool, str]:
|
|
131
|
-
"""
|
|
132
|
-
Disconnect from a remote device.
|
|
133
|
-
|
|
134
|
-
Args:
|
|
135
|
-
address: Device address to disconnect. If None, disconnects all.
|
|
136
|
-
|
|
137
|
-
Returns:
|
|
138
|
-
Tuple of (success, message).
|
|
139
|
-
"""
|
|
140
|
-
try:
|
|
141
|
-
if address:
|
|
142
|
-
cmd = [self.hdc_path, "tdisconn", address]
|
|
143
|
-
else:
|
|
144
|
-
# HDC doesn't have a "disconnect all" command, so we need to list and disconnect each
|
|
145
|
-
devices = self.list_devices()
|
|
146
|
-
for device in devices:
|
|
147
|
-
if ":" in device.device_id: # Remote device
|
|
148
|
-
_run_hdc_command(
|
|
149
|
-
[self.hdc_path, "tdisconn", device.device_id],
|
|
150
|
-
capture_output=True,
|
|
151
|
-
text=True,
|
|
152
|
-
timeout=5,
|
|
153
|
-
)
|
|
154
|
-
return True, "Disconnected all remote devices"
|
|
155
|
-
|
|
156
|
-
result = _run_hdc_command(
|
|
157
|
-
cmd, capture_output=True, text=True, encoding="utf-8", timeout=5
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
output = result.stdout + result.stderr
|
|
161
|
-
return True, output.strip() or "Disconnected"
|
|
162
|
-
|
|
163
|
-
except Exception as e:
|
|
164
|
-
return False, f"Disconnect error: {e}"
|
|
165
|
-
|
|
166
|
-
def list_devices(self) -> list[DeviceInfo]:
|
|
167
|
-
"""
|
|
168
|
-
List all connected devices.
|
|
169
|
-
|
|
170
|
-
Returns:
|
|
171
|
-
List of DeviceInfo objects.
|
|
172
|
-
"""
|
|
173
|
-
try:
|
|
174
|
-
result = _run_hdc_command(
|
|
175
|
-
[self.hdc_path, "list", "targets"],
|
|
176
|
-
capture_output=True,
|
|
177
|
-
text=True,
|
|
178
|
-
timeout=5,
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
devices = []
|
|
182
|
-
for line in result.stdout.strip().split("\n"):
|
|
183
|
-
if not line.strip():
|
|
184
|
-
continue
|
|
185
|
-
|
|
186
|
-
# HDC output format: device_id (status)
|
|
187
|
-
# Example: "192.168.1.100:5555" or "FMR0223C13000649"
|
|
188
|
-
device_id = line.strip()
|
|
189
|
-
|
|
190
|
-
# Determine connection type
|
|
191
|
-
if ":" in device_id:
|
|
192
|
-
conn_type = ConnectionType.REMOTE
|
|
193
|
-
else:
|
|
194
|
-
conn_type = ConnectionType.USB
|
|
195
|
-
|
|
196
|
-
# HDC doesn't provide detailed status in list command
|
|
197
|
-
# We assume "Connected" status for devices that appear
|
|
198
|
-
devices.append(
|
|
199
|
-
DeviceInfo(
|
|
200
|
-
device_id=device_id,
|
|
201
|
-
status="device",
|
|
202
|
-
connection_type=conn_type,
|
|
203
|
-
model=None,
|
|
204
|
-
)
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
return devices
|
|
208
|
-
|
|
209
|
-
except Exception as e:
|
|
210
|
-
print(f"Error listing devices: {e}")
|
|
211
|
-
return []
|
|
212
|
-
|
|
213
|
-
def get_device_info(self, device_id: str | None = None) -> DeviceInfo | None:
|
|
214
|
-
"""
|
|
215
|
-
Get detailed information about a device.
|
|
216
|
-
|
|
217
|
-
Args:
|
|
218
|
-
device_id: Device ID. If None, uses first available device.
|
|
219
|
-
|
|
220
|
-
Returns:
|
|
221
|
-
DeviceInfo or None if not found.
|
|
222
|
-
"""
|
|
223
|
-
devices = self.list_devices()
|
|
224
|
-
|
|
225
|
-
if not devices:
|
|
226
|
-
return None
|
|
227
|
-
|
|
228
|
-
if device_id is None:
|
|
229
|
-
return devices[0]
|
|
230
|
-
|
|
231
|
-
for device in devices:
|
|
232
|
-
if device.device_id == device_id:
|
|
233
|
-
return device
|
|
234
|
-
|
|
235
|
-
return None
|
|
236
|
-
|
|
237
|
-
def is_connected(self, device_id: str | None = None) -> bool:
|
|
238
|
-
"""
|
|
239
|
-
Check if a device is connected.
|
|
240
|
-
|
|
241
|
-
Args:
|
|
242
|
-
device_id: Device ID to check. If None, checks if any device is connected.
|
|
243
|
-
|
|
244
|
-
Returns:
|
|
245
|
-
True if connected, False otherwise.
|
|
246
|
-
"""
|
|
247
|
-
devices = self.list_devices()
|
|
248
|
-
|
|
249
|
-
if not devices:
|
|
250
|
-
return False
|
|
251
|
-
|
|
252
|
-
if device_id is None:
|
|
253
|
-
return len(devices) > 0
|
|
254
|
-
|
|
255
|
-
return any(d.device_id == device_id for d in devices)
|
|
256
|
-
|
|
257
|
-
def enable_tcpip(
|
|
258
|
-
self, port: int = 5555, device_id: str | None = None
|
|
259
|
-
) -> tuple[bool, str]:
|
|
260
|
-
"""
|
|
261
|
-
Enable TCP/IP debugging on a USB-connected device.
|
|
262
|
-
|
|
263
|
-
This allows subsequent wireless connections to the device.
|
|
264
|
-
|
|
265
|
-
Args:
|
|
266
|
-
port: TCP port for HDC (default: 5555).
|
|
267
|
-
device_id: Device ID. If None, uses first available device.
|
|
268
|
-
|
|
269
|
-
Returns:
|
|
270
|
-
Tuple of (success, message).
|
|
271
|
-
|
|
272
|
-
Note:
|
|
273
|
-
The device must be connected via USB first.
|
|
274
|
-
After this, you can disconnect USB and connect via WiFi.
|
|
275
|
-
"""
|
|
276
|
-
try:
|
|
277
|
-
cmd = [self.hdc_path]
|
|
278
|
-
if device_id:
|
|
279
|
-
cmd.extend(["-t", device_id])
|
|
280
|
-
cmd.extend(["tmode", "port", str(port)])
|
|
281
|
-
|
|
282
|
-
result = _run_hdc_command(
|
|
283
|
-
cmd, capture_output=True, text=True, encoding="utf-8", timeout=10
|
|
284
|
-
)
|
|
285
|
-
|
|
286
|
-
output = result.stdout + result.stderr
|
|
287
|
-
|
|
288
|
-
if result.returncode == 0 or "success" in output.lower():
|
|
289
|
-
time.sleep(TIMING_CONFIG.connection.adb_restart_delay)
|
|
290
|
-
return True, f"TCP/IP mode enabled on port {port}"
|
|
291
|
-
else:
|
|
292
|
-
return False, output.strip()
|
|
293
|
-
|
|
294
|
-
except Exception as e:
|
|
295
|
-
return False, f"Error enabling TCP/IP: {e}"
|
|
296
|
-
|
|
297
|
-
def get_device_ip(self, device_id: str | None = None) -> str | None:
|
|
298
|
-
"""
|
|
299
|
-
Get the IP address of a connected device.
|
|
300
|
-
|
|
301
|
-
Args:
|
|
302
|
-
device_id: Device ID. If None, uses first available device.
|
|
303
|
-
|
|
304
|
-
Returns:
|
|
305
|
-
IP address string or None if not found.
|
|
306
|
-
"""
|
|
307
|
-
try:
|
|
308
|
-
cmd = [self.hdc_path]
|
|
309
|
-
if device_id:
|
|
310
|
-
cmd.extend(["-t", device_id])
|
|
311
|
-
cmd.extend(["shell", "ifconfig"])
|
|
312
|
-
|
|
313
|
-
result = _run_hdc_command(
|
|
314
|
-
cmd, capture_output=True, text=True, encoding="utf-8", timeout=5
|
|
315
|
-
)
|
|
316
|
-
|
|
317
|
-
# Parse IP from ifconfig output
|
|
318
|
-
for line in result.stdout.split("\n"):
|
|
319
|
-
if "inet addr:" in line or "inet " in line:
|
|
320
|
-
parts = line.strip().split()
|
|
321
|
-
for i, part in enumerate(parts):
|
|
322
|
-
if "addr:" in part:
|
|
323
|
-
ip = part.split(":")[1]
|
|
324
|
-
# Filter out localhost
|
|
325
|
-
if not ip.startswith("127."):
|
|
326
|
-
return ip
|
|
327
|
-
elif part == "inet" and i + 1 < len(parts):
|
|
328
|
-
ip = parts[i + 1].split("/")[0]
|
|
329
|
-
if not ip.startswith("127."):
|
|
330
|
-
return ip
|
|
331
|
-
|
|
332
|
-
return None
|
|
333
|
-
|
|
334
|
-
except Exception as e:
|
|
335
|
-
print(f"Error getting device IP: {e}")
|
|
336
|
-
return None
|
|
337
|
-
|
|
338
|
-
def restart_server(self) -> tuple[bool, str]:
|
|
339
|
-
"""
|
|
340
|
-
Restart the HDC server.
|
|
341
|
-
|
|
342
|
-
Returns:
|
|
343
|
-
Tuple of (success, message).
|
|
344
|
-
"""
|
|
345
|
-
try:
|
|
346
|
-
# Kill server
|
|
347
|
-
_run_hdc_command([self.hdc_path, "kill"], capture_output=True, timeout=5)
|
|
348
|
-
|
|
349
|
-
time.sleep(TIMING_CONFIG.connection.server_restart_delay)
|
|
350
|
-
|
|
351
|
-
# Start server (HDC auto-starts when running commands)
|
|
352
|
-
_run_hdc_command(
|
|
353
|
-
[self.hdc_path, "start", "-r"], capture_output=True, timeout=5
|
|
354
|
-
)
|
|
355
|
-
|
|
356
|
-
return True, "HDC server restarted"
|
|
357
|
-
|
|
358
|
-
except Exception as e:
|
|
359
|
-
return False, f"Error restarting server: {e}"
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
def quick_connect(address: str) -> tuple[bool, str]:
|
|
363
|
-
"""
|
|
364
|
-
Quick helper to connect to a remote device.
|
|
365
|
-
|
|
366
|
-
Args:
|
|
367
|
-
address: Device address (e.g., "192.168.1.100" or "192.168.1.100:5555").
|
|
368
|
-
|
|
369
|
-
Returns:
|
|
370
|
-
Tuple of (success, message).
|
|
371
|
-
"""
|
|
372
|
-
conn = HDCConnection()
|
|
373
|
-
return conn.connect(address)
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
def list_devices() -> list[DeviceInfo]:
|
|
377
|
-
"""
|
|
378
|
-
Quick helper to list connected devices.
|
|
379
|
-
|
|
380
|
-
Returns:
|
|
381
|
-
List of DeviceInfo objects.
|
|
382
|
-
"""
|
|
383
|
-
conn = HDCConnection()
|
|
384
|
-
return conn.list_devices()
|