autoglm-gui 1.4.1__py3-none-any.whl → 1.5.0__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.
Files changed (104) hide show
  1. AutoGLM_GUI/__init__.py +11 -0
  2. AutoGLM_GUI/__main__.py +26 -4
  3. AutoGLM_GUI/actions/__init__.py +6 -0
  4. AutoGLM_GUI/actions/handler.py +196 -0
  5. AutoGLM_GUI/actions/types.py +15 -0
  6. AutoGLM_GUI/adb/__init__.py +53 -0
  7. AutoGLM_GUI/adb/apps.py +227 -0
  8. AutoGLM_GUI/adb/connection.py +323 -0
  9. AutoGLM_GUI/adb/device.py +171 -0
  10. AutoGLM_GUI/adb/input.py +67 -0
  11. AutoGLM_GUI/adb/screenshot.py +11 -0
  12. AutoGLM_GUI/adb/timing.py +167 -0
  13. AutoGLM_GUI/adb_plus/keyboard_installer.py +4 -2
  14. AutoGLM_GUI/adb_plus/screenshot.py +22 -1
  15. AutoGLM_GUI/adb_plus/serial.py +38 -20
  16. AutoGLM_GUI/adb_plus/touch.py +4 -9
  17. AutoGLM_GUI/agents/__init__.py +43 -12
  18. AutoGLM_GUI/agents/events.py +19 -0
  19. AutoGLM_GUI/agents/factory.py +31 -38
  20. AutoGLM_GUI/agents/glm/__init__.py +7 -0
  21. AutoGLM_GUI/agents/glm/agent.py +292 -0
  22. AutoGLM_GUI/agents/glm/message_builder.py +81 -0
  23. AutoGLM_GUI/agents/glm/parser.py +110 -0
  24. AutoGLM_GUI/agents/glm/prompts_en.py +77 -0
  25. AutoGLM_GUI/agents/glm/prompts_zh.py +75 -0
  26. AutoGLM_GUI/agents/mai/__init__.py +28 -0
  27. AutoGLM_GUI/agents/mai/agent.py +405 -0
  28. AutoGLM_GUI/agents/mai/parser.py +254 -0
  29. AutoGLM_GUI/agents/mai/prompts.py +103 -0
  30. AutoGLM_GUI/agents/mai/traj_memory.py +91 -0
  31. AutoGLM_GUI/agents/protocols.py +12 -8
  32. AutoGLM_GUI/agents/stream_runner.py +188 -0
  33. AutoGLM_GUI/api/__init__.py +40 -21
  34. AutoGLM_GUI/api/agents.py +157 -240
  35. AutoGLM_GUI/api/control.py +9 -6
  36. AutoGLM_GUI/api/devices.py +102 -12
  37. AutoGLM_GUI/api/history.py +78 -0
  38. AutoGLM_GUI/api/layered_agent.py +67 -15
  39. AutoGLM_GUI/api/media.py +64 -1
  40. AutoGLM_GUI/api/scheduled_tasks.py +98 -0
  41. AutoGLM_GUI/config.py +81 -0
  42. AutoGLM_GUI/config_manager.py +68 -51
  43. AutoGLM_GUI/device_manager.py +248 -29
  44. AutoGLM_GUI/device_protocol.py +1 -1
  45. AutoGLM_GUI/devices/adb_device.py +5 -10
  46. AutoGLM_GUI/devices/mock_device.py +4 -2
  47. AutoGLM_GUI/devices/remote_device.py +8 -3
  48. AutoGLM_GUI/history_manager.py +164 -0
  49. AutoGLM_GUI/i18n.py +81 -0
  50. AutoGLM_GUI/model/__init__.py +5 -0
  51. AutoGLM_GUI/model/message_builder.py +69 -0
  52. AutoGLM_GUI/model/types.py +24 -0
  53. AutoGLM_GUI/models/__init__.py +10 -0
  54. AutoGLM_GUI/models/history.py +96 -0
  55. AutoGLM_GUI/models/scheduled_task.py +71 -0
  56. AutoGLM_GUI/parsers/__init__.py +22 -0
  57. AutoGLM_GUI/parsers/base.py +50 -0
  58. AutoGLM_GUI/parsers/phone_parser.py +58 -0
  59. AutoGLM_GUI/phone_agent_manager.py +62 -396
  60. AutoGLM_GUI/platform_utils.py +26 -0
  61. AutoGLM_GUI/prompt_config.py +15 -0
  62. AutoGLM_GUI/prompts/__init__.py +32 -0
  63. AutoGLM_GUI/scheduler_manager.py +304 -0
  64. AutoGLM_GUI/schemas.py +234 -72
  65. AutoGLM_GUI/scrcpy_stream.py +142 -24
  66. AutoGLM_GUI/socketio_server.py +100 -27
  67. AutoGLM_GUI/static/assets/{about-_XNhzQZX.js → about-BQm96DAl.js} +1 -1
  68. AutoGLM_GUI/static/assets/alert-dialog-B42XxGPR.js +1 -0
  69. AutoGLM_GUI/static/assets/chat-C0L2gQYG.js +129 -0
  70. AutoGLM_GUI/static/assets/circle-alert-D4rSJh37.js +1 -0
  71. AutoGLM_GUI/static/assets/dialog-DZ78cEcj.js +45 -0
  72. AutoGLM_GUI/static/assets/history-DFBv7TGc.js +1 -0
  73. AutoGLM_GUI/static/assets/index-Bzyv2yQ2.css +1 -0
  74. AutoGLM_GUI/static/assets/{index-Cy8TmmHV.js → index-CmZSnDqc.js} +1 -1
  75. AutoGLM_GUI/static/assets/index-CssG-3TH.js +11 -0
  76. AutoGLM_GUI/static/assets/label-BCUzE_nm.js +1 -0
  77. AutoGLM_GUI/static/assets/logs-eoFxn5of.js +1 -0
  78. AutoGLM_GUI/static/assets/popover-DLsuV5Sx.js +1 -0
  79. AutoGLM_GUI/static/assets/scheduled-tasks-MyqGJvy_.js +1 -0
  80. AutoGLM_GUI/static/assets/square-pen-zGWYrdfj.js +1 -0
  81. AutoGLM_GUI/static/assets/textarea-BX6y7uM5.js +1 -0
  82. AutoGLM_GUI/static/assets/workflows-CYFs6ssC.js +1 -0
  83. AutoGLM_GUI/static/index.html +2 -2
  84. AutoGLM_GUI/types.py +17 -0
  85. {autoglm_gui-1.4.1.dist-info → autoglm_gui-1.5.0.dist-info}/METADATA +137 -130
  86. autoglm_gui-1.5.0.dist-info/RECORD +157 -0
  87. AutoGLM_GUI/agents/mai_adapter.py +0 -627
  88. AutoGLM_GUI/api/dual_model.py +0 -317
  89. AutoGLM_GUI/dual_model/__init__.py +0 -53
  90. AutoGLM_GUI/dual_model/decision_model.py +0 -664
  91. AutoGLM_GUI/dual_model/dual_agent.py +0 -917
  92. AutoGLM_GUI/dual_model/protocols.py +0 -354
  93. AutoGLM_GUI/dual_model/vision_model.py +0 -442
  94. AutoGLM_GUI/mai_ui_adapter/agent_wrapper.py +0 -291
  95. AutoGLM_GUI/phone_agent_patches.py +0 -147
  96. AutoGLM_GUI/static/assets/chat-DwJpiAWf.js +0 -126
  97. AutoGLM_GUI/static/assets/dialog-B3uW4T8V.js +0 -45
  98. AutoGLM_GUI/static/assets/index-Cpv2gSF1.css +0 -1
  99. AutoGLM_GUI/static/assets/index-UYYauTly.js +0 -12
  100. AutoGLM_GUI/static/assets/workflows-Du_de-dt.js +0 -1
  101. autoglm_gui-1.4.1.dist-info/RECORD +0 -117
  102. {autoglm_gui-1.4.1.dist-info → autoglm_gui-1.5.0.dist-info}/WHEEL +0 -0
  103. {autoglm_gui-1.4.1.dist-info → autoglm_gui-1.5.0.dist-info}/entry_points.txt +0 -0
  104. {autoglm_gui-1.4.1.dist-info → autoglm_gui-1.5.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,317 +0,0 @@
1
- """双模型协作API端点"""
2
-
3
- import threading
4
- from typing import Optional
5
-
6
- from fastapi import APIRouter, HTTPException
7
- from fastapi.responses import StreamingResponse
8
- from pydantic import BaseModel
9
-
10
- from AutoGLM_GUI.logger import logger
11
- from AutoGLM_GUI.dual_model import (
12
- DecisionModelConfig,
13
- DualModelAgent,
14
- DualModelEvent,
15
- DualModelEventType,
16
- )
17
- from AutoGLM_GUI.dual_model.protocols import ThinkingMode
18
- from phone_agent.model import ModelConfig
19
-
20
- router = APIRouter(prefix="/api/dual", tags=["dual-model"])
21
-
22
- # 活跃的双模型会话 (device_id -> (agent, stop_event))
23
- _active_dual_sessions: dict[str, tuple[DualModelAgent, threading.Event]] = {}
24
- _active_dual_sessions_lock = threading.Lock()
25
-
26
-
27
- class DualModelInitRequest(BaseModel):
28
- """双模型初始化请求"""
29
-
30
- device_id: str
31
-
32
- # 决策大模型配置
33
- decision_base_url: str
34
- decision_api_key: str
35
- decision_model_name: str
36
-
37
- # 视觉小模型配置(复用现有配置)
38
- vision_base_url: Optional[str] = None
39
- vision_api_key: Optional[str] = None
40
- vision_model_name: Optional[str] = None
41
-
42
- max_steps: int = 50
43
- thinking_mode: str = "deep" # fast, deep, turbo
44
-
45
-
46
- class DualModelChatRequest(BaseModel):
47
- """双模型聊天请求"""
48
-
49
- device_id: str
50
- message: str
51
-
52
-
53
- class DualModelAbortRequest(BaseModel):
54
- """中止请求"""
55
-
56
- device_id: str
57
-
58
-
59
- class DualModelStatusResponse(BaseModel):
60
- """状态响应"""
61
-
62
- active: bool
63
- device_id: Optional[str] = None
64
- state: Optional[dict] = None
65
-
66
-
67
- @router.post("/init")
68
- def init_dual_model(request: DualModelInitRequest) -> dict:
69
- """初始化双模型Agent"""
70
- from AutoGLM_GUI.config_manager import config_manager
71
- from AutoGLM_GUI.phone_agent_manager import PhoneAgentManager
72
-
73
- device_id = request.device_id
74
- thinking_mode_map = {
75
- "fast": ThinkingMode.FAST,
76
- "deep": ThinkingMode.DEEP,
77
- "turbo": ThinkingMode.TURBO,
78
- }
79
- thinking_mode = thinking_mode_map.get(request.thinking_mode, ThinkingMode.DEEP)
80
- logger.info(f"初始化双模型Agent: {device_id}, 模式: {thinking_mode.value}")
81
-
82
- # 检查设备是否已有单模型Agent初始化
83
- manager = PhoneAgentManager.get_instance()
84
- if not manager.is_initialized(device_id):
85
- raise HTTPException(
86
- status_code=400, detail="设备尚未初始化单模型Agent,请先调用 /api/init"
87
- )
88
-
89
- # 获取有效配置
90
- effective_config = config_manager.get_effective_config()
91
-
92
- # 获取配置的默认最大步数
93
- max_steps = effective_config.default_max_steps
94
-
95
- # 获取视觉模型配置(优先级:请求参数 > 有效配置)
96
- vision_base_url = request.vision_base_url or effective_config.base_url
97
- vision_api_key = request.vision_api_key or effective_config.api_key
98
- vision_model_name = request.vision_model_name or effective_config.model_name
99
-
100
- if not vision_base_url:
101
- raise HTTPException(status_code=400, detail="视觉模型base_url未配置")
102
-
103
- # 创建配置
104
- decision_config = DecisionModelConfig(
105
- base_url=request.decision_base_url,
106
- api_key=request.decision_api_key,
107
- model_name=request.decision_model_name,
108
- thinking_mode=thinking_mode,
109
- )
110
-
111
- vision_config = ModelConfig(
112
- base_url=vision_base_url,
113
- api_key=vision_api_key,
114
- model_name=vision_model_name,
115
- )
116
-
117
- # 创建双模型Agent
118
- try:
119
- agent = DualModelAgent(
120
- decision_config=decision_config,
121
- vision_config=vision_config,
122
- device_id=device_id,
123
- max_steps=max_steps,
124
- thinking_mode=thinking_mode,
125
- )
126
-
127
- # 存储到活跃会话
128
- with _active_dual_sessions_lock:
129
- # 清理旧会话
130
- if device_id in _active_dual_sessions:
131
- old_agent, old_event = _active_dual_sessions[device_id]
132
- old_event.set()
133
-
134
- _active_dual_sessions[device_id] = (agent, threading.Event())
135
-
136
- logger.info(f"双模型Agent初始化成功: {device_id}")
137
-
138
- return {
139
- "success": True,
140
- "device_id": device_id,
141
- "message": "双模型Agent初始化成功",
142
- "decision_model": request.decision_model_name,
143
- "vision_model": vision_model_name,
144
- "thinking_mode": thinking_mode.value,
145
- }
146
-
147
- except Exception as e:
148
- logger.error(f"双模型Agent初始化失败: {e}")
149
- raise HTTPException(status_code=500, detail=str(e))
150
-
151
-
152
- @router.post("/chat/stream")
153
- def dual_model_chat_stream(request: DualModelChatRequest):
154
- """双模型聊天(SSE流式)"""
155
- device_id = request.device_id
156
-
157
- with _active_dual_sessions_lock:
158
- if device_id not in _active_dual_sessions:
159
- raise HTTPException(
160
- status_code=400, detail="双模型Agent未初始化,请先调用 /api/dual/init"
161
- )
162
- agent, stop_event = _active_dual_sessions[device_id]
163
-
164
- # 重置停止事件
165
- stop_event.clear()
166
-
167
- def event_generator():
168
- """SSE事件生成器"""
169
- try:
170
- logger.info(f"开始双模型任务: {request.message[:50]}...")
171
-
172
- # 在后台线程运行Agent
173
- result_holder: list[dict | None] = [None]
174
- error_holder: list[Exception | None] = [None]
175
-
176
- def run_agent():
177
- try:
178
- result = agent.run(request.message)
179
- result_holder[0] = result
180
- except Exception as e:
181
- error_holder[0] = e
182
-
183
- thread = threading.Thread(target=run_agent, daemon=True)
184
- thread.start()
185
-
186
- # 持续发送事件
187
- while thread.is_alive() or not agent.event_queue.empty():
188
- if stop_event.is_set():
189
- agent.abort()
190
- yield "event: aborted\n"
191
- yield 'data: {"type": "aborted", "message": "任务被用户中断"}\n\n'
192
- break
193
-
194
- # 获取事件
195
- try:
196
- events = agent.get_events(timeout=0.1)
197
- for event in events:
198
- yield event.to_sse()
199
-
200
- # 如果是完成或错误事件,结束循环
201
- if event.type in [
202
- DualModelEventType.TASK_COMPLETE,
203
- DualModelEventType.ERROR,
204
- ]:
205
- return
206
- except Exception:
207
- continue
208
-
209
- # 等待线程完成
210
- thread.join(timeout=5)
211
-
212
- # 检查错误
213
- if error_holder[0]:
214
- error_event = DualModelEvent(
215
- type=DualModelEventType.ERROR,
216
- data={"message": str(error_holder[0])},
217
- )
218
- yield error_event.to_sse()
219
-
220
- # 如果没有发送完成事件,发送一个
221
- if result_holder[0] and not stop_event.is_set():
222
- result = result_holder[0]
223
- if isinstance(result, dict):
224
- done_event = DualModelEvent(
225
- type=DualModelEventType.TASK_COMPLETE,
226
- data={
227
- "success": result.get("success", False),
228
- "message": result.get("message", ""),
229
- "steps": result.get("steps", 0),
230
- },
231
- )
232
- yield done_event.to_sse()
233
-
234
- except Exception as e:
235
- logger.exception(f"双模型任务异常: {e}")
236
- error_event = DualModelEvent(
237
- type=DualModelEventType.ERROR,
238
- data={"message": str(e)},
239
- )
240
- yield error_event.to_sse()
241
-
242
- return StreamingResponse(
243
- event_generator(),
244
- media_type="text/event-stream",
245
- headers={
246
- "Cache-Control": "no-cache",
247
- "Connection": "keep-alive",
248
- "X-Accel-Buffering": "no",
249
- },
250
- )
251
-
252
-
253
- @router.post("/chat/abort")
254
- def abort_dual_model_chat(request: DualModelAbortRequest) -> dict:
255
- """中止双模型聊天"""
256
- device_id = request.device_id
257
-
258
- with _active_dual_sessions_lock:
259
- if device_id in _active_dual_sessions:
260
- agent, stop_event = _active_dual_sessions[device_id]
261
- stop_event.set()
262
- agent.abort()
263
- logger.info(f"双模型任务已中止: {device_id}")
264
- return {"success": True, "message": "已发送中止信号"}
265
- else:
266
- return {"success": False, "message": "未找到活跃的双模型会话"}
267
-
268
-
269
- @router.get("/status")
270
- def get_dual_model_status(device_id: Optional[str] = None) -> DualModelStatusResponse:
271
- """获取双模型状态"""
272
- with _active_dual_sessions_lock:
273
- if device_id:
274
- if device_id in _active_dual_sessions:
275
- agent, _ = _active_dual_sessions[device_id]
276
- return DualModelStatusResponse(
277
- active=True,
278
- device_id=device_id,
279
- state=agent.get_state(),
280
- )
281
- else:
282
- return DualModelStatusResponse(active=False, device_id=device_id)
283
- else:
284
- # 返回所有活跃会话
285
- return DualModelStatusResponse(
286
- active=len(_active_dual_sessions) > 0,
287
- state={"active_devices": list(_active_dual_sessions.keys())},
288
- )
289
-
290
-
291
- @router.post("/reset")
292
- def reset_dual_model(request: DualModelAbortRequest) -> dict:
293
- """重置双模型Agent"""
294
- device_id = request.device_id
295
-
296
- with _active_dual_sessions_lock:
297
- if device_id in _active_dual_sessions:
298
- agent, stop_event = _active_dual_sessions[device_id]
299
- stop_event.set()
300
- agent.reset()
301
- logger.info(f"双模型Agent已重置: {device_id}")
302
- return {"success": True, "message": "双模型Agent已重置"}
303
- else:
304
- return {"success": False, "message": "未找到双模型会话"}
305
-
306
-
307
- @router.delete("/session/{device_id}")
308
- def delete_dual_model_session(device_id: str) -> dict:
309
- """删除双模型会话"""
310
- with _active_dual_sessions_lock:
311
- if device_id in _active_dual_sessions:
312
- agent, stop_event = _active_dual_sessions.pop(device_id)
313
- stop_event.set()
314
- logger.info(f"双模型会话已删除: {device_id}")
315
- return {"success": True, "message": "双模型会话已删除"}
316
- else:
317
- return {"success": False, "message": "未找到双模型会话"}
@@ -1,53 +0,0 @@
1
- """
2
- 双模型协作模块
3
-
4
- 大模型(GLM-4.7): 负责任务分析、决策制定、内容生成
5
- 小模型(autoglm-phone): 负责屏幕识别、动作执行
6
- """
7
-
8
- from .decision_model import (
9
- DecisionModel,
10
- Decision,
11
- TaskPlan,
12
- ActionSequence,
13
- ActionStep,
14
- )
15
- from .vision_model import VisionModel, ScreenDescription, ExecutionResult
16
- from .dual_agent import DualModelAgent, DualModelCallbacks
17
- from .protocols import (
18
- DualModelConfig,
19
- DecisionModelConfig,
20
- DualModelState,
21
- DualModelEvent,
22
- DualModelEventType,
23
- ModelRole,
24
- ModelStage,
25
- ThinkingMode,
26
- DECISION_SYSTEM_PROMPT,
27
- DECISION_SYSTEM_PROMPT_TURBO,
28
- VISION_DESCRIBE_PROMPT,
29
- )
30
-
31
- __all__ = [
32
- "DecisionModel",
33
- "Decision",
34
- "TaskPlan",
35
- "ActionSequence",
36
- "ActionStep",
37
- "VisionModel",
38
- "ScreenDescription",
39
- "ExecutionResult",
40
- "DualModelAgent",
41
- "DualModelCallbacks",
42
- "DualModelConfig",
43
- "DecisionModelConfig",
44
- "DualModelState",
45
- "DualModelEvent",
46
- "DualModelEventType",
47
- "ModelRole",
48
- "ModelStage",
49
- "ThinkingMode",
50
- "DECISION_SYSTEM_PROMPT",
51
- "DECISION_SYSTEM_PROMPT_TURBO",
52
- "VISION_DESCRIBE_PROMPT",
53
- ]