@beeos-ai/device-agent 0.4.0

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 (398) hide show
  1. package/.pi/extensions/android-tools.ts +139 -0
  2. package/.pi/skills/.gitkeep +0 -0
  3. package/.pi/skills/ground-mobile-fallback/SKILL.md +50 -0
  4. package/LICENSE +201 -0
  5. package/dist/action/handler.d.ts +9 -0
  6. package/dist/action/handler.js +124 -0
  7. package/dist/action/handler.js.map +1 -0
  8. package/dist/adapters/agent-gateway-client.d.ts +256 -0
  9. package/dist/adapters/agent-gateway-client.js +332 -0
  10. package/dist/adapters/agent-gateway-client.js.map +1 -0
  11. package/dist/adapters/agentcore-inner-loop.d.ts +29 -0
  12. package/dist/adapters/agentcore-inner-loop.js +72 -0
  13. package/dist/adapters/agentcore-inner-loop.js.map +1 -0
  14. package/dist/adapters/agentcore-pi.d.ts +215 -0
  15. package/dist/adapters/agentcore-pi.js +464 -0
  16. package/dist/adapters/agentcore-pi.js.map +1 -0
  17. package/dist/adapters/agentcore-runner.d.ts +70 -0
  18. package/dist/adapters/agentcore-runner.js +255 -0
  19. package/dist/adapters/agentcore-runner.js.map +1 -0
  20. package/dist/adapters/device-android-adb.d.ts +41 -0
  21. package/dist/adapters/device-android-adb.js +279 -0
  22. package/dist/adapters/device-android-adb.js.map +1 -0
  23. package/dist/adapters/device-desktop.d.ts +37 -0
  24. package/dist/adapters/device-desktop.js +101 -0
  25. package/dist/adapters/device-desktop.js.map +1 -0
  26. package/dist/adapters/identity-file.d.ts +30 -0
  27. package/dist/adapters/identity-file.js +50 -0
  28. package/dist/adapters/identity-file.js.map +1 -0
  29. package/dist/adapters/transport-bridge-ws.d.ts +39 -0
  30. package/dist/adapters/transport-bridge-ws.js +49 -0
  31. package/dist/adapters/transport-bridge-ws.js.map +1 -0
  32. package/dist/adapters/vlm-inner-loop.d.ts +88 -0
  33. package/dist/adapters/vlm-inner-loop.js +199 -0
  34. package/dist/adapters/vlm-inner-loop.js.map +1 -0
  35. package/dist/agent-runtime/adapters/base.d.ts +145 -0
  36. package/dist/agent-runtime/adapters/base.js +29 -0
  37. package/dist/agent-runtime/adapters/base.js.map +1 -0
  38. package/dist/agent-runtime/adapters/index.d.ts +17 -0
  39. package/dist/agent-runtime/adapters/index.js +17 -0
  40. package/dist/agent-runtime/adapters/index.js.map +1 -0
  41. package/dist/agent-runtime/adapters/mock.d.ts +44 -0
  42. package/dist/agent-runtime/adapters/mock.js +54 -0
  43. package/dist/agent-runtime/adapters/mock.js.map +1 -0
  44. package/dist/agent-runtime/adapters/openai.d.ts +63 -0
  45. package/dist/agent-runtime/adapters/openai.js +302 -0
  46. package/dist/agent-runtime/adapters/openai.js.map +1 -0
  47. package/dist/agent-runtime/adapters/registry.d.ts +49 -0
  48. package/dist/agent-runtime/adapters/registry.js +129 -0
  49. package/dist/agent-runtime/adapters/registry.js.map +1 -0
  50. package/dist/agent-runtime/adapters/ui-tars.d.ts +13 -0
  51. package/dist/agent-runtime/adapters/ui-tars.js +22 -0
  52. package/dist/agent-runtime/adapters/ui-tars.js.map +1 -0
  53. package/dist/agent-runtime/agent-runner.d.ts +149 -0
  54. package/dist/agent-runtime/agent-runner.js +356 -0
  55. package/dist/agent-runtime/agent-runner.js.map +1 -0
  56. package/dist/agent-runtime/core.d.ts +170 -0
  57. package/dist/agent-runtime/core.js +624 -0
  58. package/dist/agent-runtime/core.js.map +1 -0
  59. package/dist/agent-runtime/index.d.ts +16 -0
  60. package/dist/agent-runtime/index.js +17 -0
  61. package/dist/agent-runtime/index.js.map +1 -0
  62. package/dist/agent-runtime/plan-executor.d.ts +118 -0
  63. package/dist/agent-runtime/plan-executor.js +501 -0
  64. package/dist/agent-runtime/plan-executor.js.map +1 -0
  65. package/dist/agent-runtime/planner/base.d.ts +128 -0
  66. package/dist/agent-runtime/planner/base.js +157 -0
  67. package/dist/agent-runtime/planner/base.js.map +1 -0
  68. package/dist/agent-runtime/planner/llm-planner.d.ts +58 -0
  69. package/dist/agent-runtime/planner/llm-planner.js +112 -0
  70. package/dist/agent-runtime/planner/llm-planner.js.map +1 -0
  71. package/dist/agent-runtime/planner/noop-planner.d.ts +13 -0
  72. package/dist/agent-runtime/planner/noop-planner.js +30 -0
  73. package/dist/agent-runtime/planner/noop-planner.js.map +1 -0
  74. package/dist/agent-runtime/planner/prompts.d.ts +33 -0
  75. package/dist/agent-runtime/planner/prompts.js +165 -0
  76. package/dist/agent-runtime/planner/prompts.js.map +1 -0
  77. package/dist/agent-runtime/reflection.d.ts +81 -0
  78. package/dist/agent-runtime/reflection.js +189 -0
  79. package/dist/agent-runtime/reflection.js.map +1 -0
  80. package/dist/agent-runtime/reflectors/action-reflector.d.ts +97 -0
  81. package/dist/agent-runtime/reflectors/action-reflector.js +233 -0
  82. package/dist/agent-runtime/reflectors/action-reflector.js.map +1 -0
  83. package/dist/agent-runtime/reflectors/policy.d.ts +53 -0
  84. package/dist/agent-runtime/reflectors/policy.js +106 -0
  85. package/dist/agent-runtime/reflectors/policy.js.map +1 -0
  86. package/dist/agent-runtime/reflectors/trajectory-reflector.d.ts +94 -0
  87. package/dist/agent-runtime/reflectors/trajectory-reflector.js +223 -0
  88. package/dist/agent-runtime/reflectors/trajectory-reflector.js.map +1 -0
  89. package/dist/agent-runtime/skills/embedding.d.ts +53 -0
  90. package/dist/agent-runtime/skills/embedding.js +134 -0
  91. package/dist/agent-runtime/skills/embedding.js.map +1 -0
  92. package/dist/agent-runtime/skills/fs-store.d.ts +88 -0
  93. package/dist/agent-runtime/skills/fs-store.js +483 -0
  94. package/dist/agent-runtime/skills/fs-store.js.map +1 -0
  95. package/dist/agent-runtime/skills/index.d.ts +10 -0
  96. package/dist/agent-runtime/skills/index.js +10 -0
  97. package/dist/agent-runtime/skills/index.js.map +1 -0
  98. package/dist/agent-runtime/skills/matcher-evolver.d.ts +88 -0
  99. package/dist/agent-runtime/skills/matcher-evolver.js +110 -0
  100. package/dist/agent-runtime/skills/matcher-evolver.js.map +1 -0
  101. package/dist/agent-runtime/skills/memory-store.d.ts +23 -0
  102. package/dist/agent-runtime/skills/memory-store.js +94 -0
  103. package/dist/agent-runtime/skills/memory-store.js.map +1 -0
  104. package/dist/agent-runtime/skills/normalise.d.ts +40 -0
  105. package/dist/agent-runtime/skills/normalise.js +152 -0
  106. package/dist/agent-runtime/skills/normalise.js.map +1 -0
  107. package/dist/agent-runtime/skills/replay.d.ts +46 -0
  108. package/dist/agent-runtime/skills/replay.js +106 -0
  109. package/dist/agent-runtime/skills/replay.js.map +1 -0
  110. package/dist/agent-runtime/skills/sqlite-store.d.ts +60 -0
  111. package/dist/agent-runtime/skills/sqlite-store.js +234 -0
  112. package/dist/agent-runtime/skills/sqlite-store.js.map +1 -0
  113. package/dist/agent-runtime/skills/types.d.ts +99 -0
  114. package/dist/agent-runtime/skills/types.js +14 -0
  115. package/dist/agent-runtime/skills/types.js.map +1 -0
  116. package/dist/agent.d.ts +110 -0
  117. package/dist/agent.js +162 -0
  118. package/dist/agent.js.map +1 -0
  119. package/dist/api.d.ts +27 -0
  120. package/dist/api.js +48 -0
  121. package/dist/api.js.map +1 -0
  122. package/dist/app/agent-host.d.ts +59 -0
  123. package/dist/app/agent-host.js +263 -0
  124. package/dist/app/agent-host.js.map +1 -0
  125. package/dist/app/device-manager.d.ts +28 -0
  126. package/dist/app/device-manager.js +64 -0
  127. package/dist/app/device-manager.js.map +1 -0
  128. package/dist/app/message-store.d.ts +55 -0
  129. package/dist/app/message-store.js +99 -0
  130. package/dist/app/message-store.js.map +1 -0
  131. package/dist/app/session-manager.d.ts +132 -0
  132. package/dist/app/session-manager.js +350 -0
  133. package/dist/app/session-manager.js.map +1 -0
  134. package/dist/bootstrap.d.ts +94 -0
  135. package/dist/bootstrap.js +459 -0
  136. package/dist/bootstrap.js.map +1 -0
  137. package/dist/chat.d.ts +16 -0
  138. package/dist/chat.js +175 -0
  139. package/dist/chat.js.map +1 -0
  140. package/dist/config/loader.d.ts +77 -0
  141. package/dist/config/loader.js +292 -0
  142. package/dist/config/loader.js.map +1 -0
  143. package/dist/config/schema.d.ts +162 -0
  144. package/dist/config/schema.js +243 -0
  145. package/dist/config/schema.js.map +1 -0
  146. package/dist/core/actions.d.ts +60 -0
  147. package/dist/core/actions.js +120 -0
  148. package/dist/core/actions.js.map +1 -0
  149. package/dist/core/errors.d.ts +8 -0
  150. package/dist/core/errors.js +9 -0
  151. package/dist/core/errors.js.map +1 -0
  152. package/dist/core/screen.d.ts +7 -0
  153. package/dist/core/screen.js +8 -0
  154. package/dist/core/screen.js.map +1 -0
  155. package/dist/core/session.d.ts +42 -0
  156. package/dist/core/session.js +29 -0
  157. package/dist/core/session.js.map +1 -0
  158. package/dist/debug/dump-system-prompt.d.ts +1 -0
  159. package/dist/debug/dump-system-prompt.js +34 -0
  160. package/dist/debug/dump-system-prompt.js.map +1 -0
  161. package/dist/device/android.d.ts +25 -0
  162. package/dist/device/android.js +231 -0
  163. package/dist/device/android.js.map +1 -0
  164. package/dist/device/apps.d.ts +3 -0
  165. package/dist/device/apps.js +77 -0
  166. package/dist/device/apps.js.map +1 -0
  167. package/dist/device/base.d.ts +20 -0
  168. package/dist/device/base.js +2 -0
  169. package/dist/device/base.js.map +1 -0
  170. package/dist/device/ui-xml.d.ts +29 -0
  171. package/dist/device/ui-xml.js +194 -0
  172. package/dist/device/ui-xml.js.map +1 -0
  173. package/dist/fleet/adapters/process/node-process-manager.d.ts +157 -0
  174. package/dist/fleet/adapters/process/node-process-manager.js +664 -0
  175. package/dist/fleet/adapters/process/node-process-manager.js.map +1 -0
  176. package/dist/fleet/adapters/sources/local-adb.d.ts +105 -0
  177. package/dist/fleet/adapters/sources/local-adb.js +353 -0
  178. package/dist/fleet/adapters/sources/local-adb.js.map +1 -0
  179. package/dist/fleet/adapters/sources/remote-adb.d.ts +97 -0
  180. package/dist/fleet/adapters/sources/remote-adb.js +138 -0
  181. package/dist/fleet/adapters/sources/remote-adb.js.map +1 -0
  182. package/dist/fleet/adapters/state/beeos-cli-store.d.ts +72 -0
  183. package/dist/fleet/adapters/state/beeos-cli-store.js +250 -0
  184. package/dist/fleet/adapters/state/beeos-cli-store.js.map +1 -0
  185. package/dist/fleet/adapters/state/port-allocator.d.ts +43 -0
  186. package/dist/fleet/adapters/state/port-allocator.js +173 -0
  187. package/dist/fleet/adapters/state/port-allocator.js.map +1 -0
  188. package/dist/fleet/domain/device.d.ts +138 -0
  189. package/dist/fleet/domain/device.js +49 -0
  190. package/dist/fleet/domain/device.js.map +1 -0
  191. package/dist/fleet/domain/events.d.ts +102 -0
  192. package/dist/fleet/domain/events.js +15 -0
  193. package/dist/fleet/domain/events.js.map +1 -0
  194. package/dist/fleet/domain/fsm.d.ts +122 -0
  195. package/dist/fleet/domain/fsm.js +475 -0
  196. package/dist/fleet/domain/fsm.js.map +1 -0
  197. package/dist/fleet/http/status-client.d.ts +31 -0
  198. package/dist/fleet/http/status-client.js +115 -0
  199. package/dist/fleet/http/status-client.js.map +1 -0
  200. package/dist/fleet/http/status-server.d.ts +64 -0
  201. package/dist/fleet/http/status-server.js +200 -0
  202. package/dist/fleet/http/status-server.js.map +1 -0
  203. package/dist/fleet/index.d.ts +27 -0
  204. package/dist/fleet/index.js +17 -0
  205. package/dist/fleet/index.js.map +1 -0
  206. package/dist/fleet/installer/index.d.ts +12 -0
  207. package/dist/fleet/installer/index.js +13 -0
  208. package/dist/fleet/installer/index.js.map +1 -0
  209. package/dist/fleet/installer/launchd-mac.d.ts +73 -0
  210. package/dist/fleet/installer/launchd-mac.js +291 -0
  211. package/dist/fleet/installer/launchd-mac.js.map +1 -0
  212. package/dist/fleet/installer/service-spec.d.ts +70 -0
  213. package/dist/fleet/installer/service-spec.js +43 -0
  214. package/dist/fleet/installer/service-spec.js.map +1 -0
  215. package/dist/fleet/installer/spawn-env.d.ts +45 -0
  216. package/dist/fleet/installer/spawn-env.js +224 -0
  217. package/dist/fleet/installer/spawn-env.js.map +1 -0
  218. package/dist/fleet/ports/clock.d.ts +19 -0
  219. package/dist/fleet/ports/clock.js +26 -0
  220. package/dist/fleet/ports/clock.js.map +1 -0
  221. package/dist/fleet/ports/device-source.d.ts +28 -0
  222. package/dist/fleet/ports/device-source.js +18 -0
  223. package/dist/fleet/ports/device-source.js.map +1 -0
  224. package/dist/fleet/ports/process-manager.d.ts +110 -0
  225. package/dist/fleet/ports/process-manager.js +27 -0
  226. package/dist/fleet/ports/process-manager.js.map +1 -0
  227. package/dist/fleet/ports/state-registry.d.ts +49 -0
  228. package/dist/fleet/ports/state-registry.js +12 -0
  229. package/dist/fleet/ports/state-registry.js.map +1 -0
  230. package/dist/fleet/supervisor.d.ts +107 -0
  231. package/dist/fleet/supervisor.js +508 -0
  232. package/dist/fleet/supervisor.js.map +1 -0
  233. package/dist/grounding/grounder.d.ts +46 -0
  234. package/dist/grounding/grounder.js +82 -0
  235. package/dist/grounding/grounder.js.map +1 -0
  236. package/dist/inbound/acp/handlers/device.d.ts +43 -0
  237. package/dist/inbound/acp/handlers/device.js +153 -0
  238. package/dist/inbound/acp/handlers/device.js.map +1 -0
  239. package/dist/inbound/acp/handlers/initialize.d.ts +71 -0
  240. package/dist/inbound/acp/handlers/initialize.js +53 -0
  241. package/dist/inbound/acp/handlers/initialize.js.map +1 -0
  242. package/dist/inbound/acp/handlers/models.d.ts +16 -0
  243. package/dist/inbound/acp/handlers/models.js +23 -0
  244. package/dist/inbound/acp/handlers/models.js.map +1 -0
  245. package/dist/inbound/acp/handlers/session.d.ts +51 -0
  246. package/dist/inbound/acp/handlers/session.js +61 -0
  247. package/dist/inbound/acp/handlers/session.js.map +1 -0
  248. package/dist/inbound/acp/handlers/skills.d.ts +8 -0
  249. package/dist/inbound/acp/handlers/skills.js +9 -0
  250. package/dist/inbound/acp/handlers/skills.js.map +1 -0
  251. package/dist/inbound/acp/notifier.d.ts +35 -0
  252. package/dist/inbound/acp/notifier.js +45 -0
  253. package/dist/inbound/acp/notifier.js.map +1 -0
  254. package/dist/inbound/acp/router.d.ts +67 -0
  255. package/dist/inbound/acp/router.js +179 -0
  256. package/dist/inbound/acp/router.js.map +1 -0
  257. package/dist/inbound/cli/fleet-command.d.ts +34 -0
  258. package/dist/inbound/cli/fleet-command.js +792 -0
  259. package/dist/inbound/cli/fleet-command.js.map +1 -0
  260. package/dist/inbound/cli/main.d.ts +38 -0
  261. package/dist/inbound/cli/main.js +364 -0
  262. package/dist/inbound/cli/main.js.map +1 -0
  263. package/dist/inbound/cli/run-command.d.ts +101 -0
  264. package/dist/inbound/cli/run-command.js +405 -0
  265. package/dist/inbound/cli/run-command.js.map +1 -0
  266. package/dist/inbound/cli/skills-command.d.ts +39 -0
  267. package/dist/inbound/cli/skills-command.js +333 -0
  268. package/dist/inbound/cli/skills-command.js.map +1 -0
  269. package/dist/inbound/http/server.d.ts +7 -0
  270. package/dist/inbound/http/server.js +8 -0
  271. package/dist/inbound/http/server.js.map +1 -0
  272. package/dist/index.d.ts +66 -0
  273. package/dist/index.js +48 -0
  274. package/dist/index.js.map +1 -0
  275. package/dist/logger/index.d.ts +37 -0
  276. package/dist/logger/index.js +84 -0
  277. package/dist/logger/index.js.map +1 -0
  278. package/dist/mcp-client/autospawn.d.ts +67 -0
  279. package/dist/mcp-client/autospawn.js +173 -0
  280. package/dist/mcp-client/autospawn.js.map +1 -0
  281. package/dist/mcp-client/client.d.ts +78 -0
  282. package/dist/mcp-client/client.js +168 -0
  283. package/dist/mcp-client/client.js.map +1 -0
  284. package/dist/mcp-client/index.d.ts +7 -0
  285. package/dist/mcp-client/index.js +4 -0
  286. package/dist/mcp-client/index.js.map +1 -0
  287. package/dist/mcp-client/inproc.d.ts +47 -0
  288. package/dist/mcp-client/inproc.js +229 -0
  289. package/dist/mcp-client/inproc.js.map +1 -0
  290. package/dist/mcp-client/runtime.d.ts +34 -0
  291. package/dist/mcp-client/runtime.js +15 -0
  292. package/dist/mcp-client/runtime.js.map +1 -0
  293. package/dist/model/adapters/autoglm.d.ts +31 -0
  294. package/dist/model/adapters/autoglm.js +409 -0
  295. package/dist/model/adapters/autoglm.js.map +1 -0
  296. package/dist/model/adapters/base.d.ts +13 -0
  297. package/dist/model/adapters/base.js +27 -0
  298. package/dist/model/adapters/base.js.map +1 -0
  299. package/dist/model/adapters/guiowl.d.ts +1 -0
  300. package/dist/model/adapters/guiowl.js +253 -0
  301. package/dist/model/adapters/guiowl.js.map +1 -0
  302. package/dist/model/adapters/index.d.ts +6 -0
  303. package/dist/model/adapters/index.js +8 -0
  304. package/dist/model/adapters/index.js.map +1 -0
  305. package/dist/model/adapters/maiui.d.ts +1 -0
  306. package/dist/model/adapters/maiui.js +117 -0
  307. package/dist/model/adapters/maiui.js.map +1 -0
  308. package/dist/model/adapters/qwenvl.d.ts +1 -0
  309. package/dist/model/adapters/qwenvl.js +108 -0
  310. package/dist/model/adapters/qwenvl.js.map +1 -0
  311. package/dist/model/adapters/showui.d.ts +1 -0
  312. package/dist/model/adapters/showui.js +132 -0
  313. package/dist/model/adapters/showui.js.map +1 -0
  314. package/dist/model/adapters/tool-call.d.ts +6 -0
  315. package/dist/model/adapters/tool-call.js +102 -0
  316. package/dist/model/adapters/tool-call.js.map +1 -0
  317. package/dist/model/adapters/uitars.d.ts +1 -0
  318. package/dist/model/adapters/uitars.js +180 -0
  319. package/dist/model/adapters/uitars.js.map +1 -0
  320. package/dist/model/base.d.ts +32 -0
  321. package/dist/model/base.js +2 -0
  322. package/dist/model/base.js.map +1 -0
  323. package/dist/model/client.d.ts +26 -0
  324. package/dist/model/client.js +300 -0
  325. package/dist/model/client.js.map +1 -0
  326. package/dist/model/image/compress.d.ts +53 -0
  327. package/dist/model/image/compress.js +89 -0
  328. package/dist/model/image/compress.js.map +1 -0
  329. package/dist/model/image/transport.d.ts +134 -0
  330. package/dist/model/image/transport.js +154 -0
  331. package/dist/model/image/transport.js.map +1 -0
  332. package/dist/orchestrator-system-prompt.d.ts +6 -0
  333. package/dist/orchestrator-system-prompt.js +81 -0
  334. package/dist/orchestrator-system-prompt.js.map +1 -0
  335. package/dist/pi-context.d.ts +82 -0
  336. package/dist/pi-context.js +62 -0
  337. package/dist/pi-context.js.map +1 -0
  338. package/dist/pi-local-skills.d.ts +17 -0
  339. package/dist/pi-local-skills.js +24 -0
  340. package/dist/pi-local-skills.js.map +1 -0
  341. package/dist/plugins/acp/index.d.ts +46 -0
  342. package/dist/plugins/acp/index.js +111 -0
  343. package/dist/plugins/acp/index.js.map +1 -0
  344. package/dist/plugins/agent-sync/index.d.ts +40 -0
  345. package/dist/plugins/agent-sync/index.js +98 -0
  346. package/dist/plugins/agent-sync/index.js.map +1 -0
  347. package/dist/plugins/http-debug/index.d.ts +30 -0
  348. package/dist/plugins/http-debug/index.js +64 -0
  349. package/dist/plugins/http-debug/index.js.map +1 -0
  350. package/dist/plugins/http-debug/server.d.ts +92 -0
  351. package/dist/plugins/http-debug/server.js +464 -0
  352. package/dist/plugins/http-debug/server.js.map +1 -0
  353. package/dist/ports/agent-core.d.ts +158 -0
  354. package/dist/ports/agent-core.js +2 -0
  355. package/dist/ports/agent-core.js.map +1 -0
  356. package/dist/ports/agent-host.d.ts +125 -0
  357. package/dist/ports/agent-host.js +23 -0
  358. package/dist/ports/agent-host.js.map +1 -0
  359. package/dist/ports/device.d.ts +53 -0
  360. package/dist/ports/device.js +13 -0
  361. package/dist/ports/device.js.map +1 -0
  362. package/dist/ports/identity.d.ts +22 -0
  363. package/dist/ports/identity.js +9 -0
  364. package/dist/ports/identity.js.map +1 -0
  365. package/dist/ports/plugin.d.ts +62 -0
  366. package/dist/ports/plugin.js +35 -0
  367. package/dist/ports/plugin.js.map +1 -0
  368. package/dist/ports/transport.d.ts +32 -0
  369. package/dist/ports/transport.js +12 -0
  370. package/dist/ports/transport.js.map +1 -0
  371. package/dist/ports/vlm.d.ts +59 -0
  372. package/dist/ports/vlm.js +14 -0
  373. package/dist/ports/vlm.js.map +1 -0
  374. package/dist/test-lan-autoglm.d.ts +7 -0
  375. package/dist/test-lan-autoglm.js +46 -0
  376. package/dist/test-lan-autoglm.js.map +1 -0
  377. package/dist/test-mem-breakdown.d.ts +1 -0
  378. package/dist/test-mem-breakdown.js +103 -0
  379. package/dist/test-mem-breakdown.js.map +1 -0
  380. package/dist/test-mem.d.ts +1 -0
  381. package/dist/test-mem.js +60 -0
  382. package/dist/test-mem.js.map +1 -0
  383. package/dist/test-mobile-use.d.ts +1 -0
  384. package/dist/test-mobile-use.js +18 -0
  385. package/dist/test-mobile-use.js.map +1 -0
  386. package/dist/test-screenshot-loop.d.ts +1 -0
  387. package/dist/test-screenshot-loop.js +43 -0
  388. package/dist/test-screenshot-loop.js.map +1 -0
  389. package/dist/test-screenshot.d.ts +1 -0
  390. package/dist/test-screenshot.js +10 -0
  391. package/dist/test-screenshot.js.map +1 -0
  392. package/dist/test-ui-xml-dump.d.ts +15 -0
  393. package/dist/test-ui-xml-dump.js +49 -0
  394. package/dist/test-ui-xml-dump.js.map +1 -0
  395. package/dist/types.d.ts +69 -0
  396. package/dist/types.js +23 -0
  397. package/dist/types.js.map +1 -0
  398. package/package.json +94 -0
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Pi extension: registers three tools for the **outer** orchestrator.
3
+ *
4
+ * - `mobile_use` — **All-in-one**: one call runs the full inner loop (VLM screenshot→act until done).
5
+ * - `ground` — **Atomic**: NL → pixel coords; the outer agent must decide *when* to call it.
6
+ * - `ui_xml` — **Atomic**: dump/search UI hierarchy; the outer agent composes it with bash / ground / mobile_use.
7
+ *
8
+ * `ground` and `ui_xml` do **not** replace `mobile_use`; they rely on outer multi-turn scheduling.
9
+ *
10
+ * Extension lifecycle (since the dual-layer + MCP refactor):
11
+ *
12
+ * PiOrchestratorAgent.ensureSession()
13
+ * └─ setPiExtensionContext({ getMcpClient, getGrounder, runMobileUse, getUiXml })
14
+ * └─ pi.loader.reload() → loads this file → pi.registerTool(...)
15
+ * └─ pi.session.prompt(...) → tools execute → context.* invoked
16
+ *
17
+ * PiOrchestratorAgent.dispose()
18
+ * └─ setPiExtensionContext(null)
19
+ *
20
+ * The extension is the ONLY pi-coupling point. Bootstrap supplies the
21
+ * concrete dependencies (active `IMcpRuntime` — typically the sibling
22
+ * `device-mcp-server` HTTP client, grounder built from `config.grounder`,
23
+ * `mobile_use` runner backed by the shared `AgentLoop` over the MCP
24
+ * runtime) — this file stays free of process.env reads, ad-hoc
25
+ * `new AndroidDevice()` / `new HTTPGrounder()` calls, and direct MCP
26
+ * HTTP knowledge.
27
+ *
28
+ * Authoring custom extensions follows the same pattern: import
29
+ * `getPiExtensionContext()` and trust the bootstrap to populate it.
30
+ */
31
+
32
+ import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent";
33
+ import { Type } from "@sinclair/typebox";
34
+ import { getPiExtensionContext } from "../../src/pi-context.js";
35
+
36
+ export default function (pi: ExtensionAPI) {
37
+ // ── mobile_use ─────────────────────────────────────────────────────────────
38
+ pi.registerTool({
39
+ name: "mobile_use",
40
+ label: "Mobile Use",
41
+ description:
42
+ "Drive the connected Android phone with a natural-language task. " +
43
+ "A VLM runs its own screenshot→reason→act loop until it finishes or hits max-steps. " +
44
+ "Pass a full, concrete instruction with app-native UI text. " +
45
+ "For long text (especially Chinese), embed it verbatim and note '原样输入、不要翻译'. " +
46
+ "One call runs 10–30 steps autonomously; do NOT call repeatedly for the same task.",
47
+ promptSnippet: "mobile_use(task): drive Android phone via VLM screenshot→reason→act loop",
48
+ parameters: Type.Object({
49
+ task: Type.String({ description: "Full natural-language instruction in Chinese or English" }),
50
+ max_steps: Type.Integer({
51
+ description: "Maximum VLM steps for this call. Required. Typical range 10-30 depending on task complexity.",
52
+ minimum: 1,
53
+ maximum: 100,
54
+ }),
55
+ }),
56
+ async execute(_id, params, signal, onUpdate, _ctx: ExtensionContext) {
57
+ onUpdate?.({ content: [{ type: "text", text: `[mobile_use] ${params.task}\n` }], details: null });
58
+ if (signal?.aborted) throw new Error("aborted");
59
+
60
+ const ctx = getPiExtensionContext();
61
+ const result = await ctx.runMobileUse(params.task, params.max_steps, signal ?? undefined);
62
+ return { content: [{ type: "text", text: result }], details: null };
63
+ },
64
+ });
65
+
66
+ // ── ground ─────────────────────────────────────────────────────────────────
67
+ // Visual grounding tool: find where a described UI element is on screen.
68
+ // Takes a screenshot from the connected device (or uses a caller-supplied image),
69
+ // calls the configured grounder VLM, and returns pixel coordinates.
70
+ pi.registerTool({
71
+ name: "ground",
72
+ label: "Visual Ground",
73
+ description:
74
+ "Locate a UI element on the Android phone screen and return its pixel coordinates. " +
75
+ "Describe the element in natural language (e.g. '确认按钮', 'Settings icon', 'search box'). " +
76
+ "If image_b64 is omitted, a fresh screenshot is taken automatically. " +
77
+ "Returns JSON: { x, y, width, height, raw } where x/y are absolute pixels from the top-left. " +
78
+ "Use this when you need to know where to tap without running the full mobile_use loop.",
79
+ promptSnippet: "ground(query, image_b64?): locate UI element on screen → {x, y}",
80
+ parameters: Type.Object({
81
+ query: Type.String({ description: "Natural-language description of the element to locate" }),
82
+ image_b64: Type.Optional(
83
+ Type.String({ description: "Base64-encoded JPEG/PNG image. If omitted, a screenshot is taken." }),
84
+ ),
85
+ }),
86
+ async execute(_id, params, signal, onUpdate, _ctx: ExtensionContext) {
87
+ onUpdate?.({ content: [{ type: "text", text: `[ground] "${params.query}"\n` }], details: null });
88
+ if (signal?.aborted) throw new Error("aborted");
89
+
90
+ const ctx = getPiExtensionContext();
91
+ let imageB64 = params.image_b64 ?? null;
92
+
93
+ if (!imageB64) {
94
+ const ss = await ctx.getMcpClient().screenshot();
95
+ imageB64 = ss.b64;
96
+ }
97
+
98
+ const result = await ctx.getGrounder().ground(imageB64, params.query);
99
+
100
+ return {
101
+ content: [{ type: "text", text: result ?? "Element not found" }],
102
+ details: null,
103
+ };
104
+ },
105
+ });
106
+
107
+ // ── ui_xml ─────────────────────────────────────────────────────────────────
108
+ pi.registerTool({
109
+ name: "ui_xml",
110
+ label: "UI XML",
111
+ description:
112
+ "Dump the Android UI hierarchy from the connected device and return it as text. " +
113
+ "Without a query: returns the raw uiautomator XML (truncated at 8000 chars). " +
114
+ "With a query: searches nodes by text / resource-id / content-desc / class name " +
115
+ "(case-insensitive substring match) and returns matching nodes as JSON with: " +
116
+ "text, resourceId, contentDesc, className, bounds ([x1,y1][x2,y2]), center {x,y}, clickable. " +
117
+ "Use this to inspect the current screen structure, find resource IDs, or check element states.",
118
+ promptSnippet: "ui_xml(query?): dump or search UI hierarchy → raw XML or [{text, bounds, center, ...}]",
119
+ parameters: Type.Object({
120
+ query: Type.Optional(
121
+ Type.String({ description: "Substring to match against text/resource-id/content-desc/class. Omit for raw XML." }),
122
+ ),
123
+ }),
124
+ async execute(_id, params, signal, onUpdate, _ctx: ExtensionContext) {
125
+ onUpdate?.({ content: [{ type: "text", text: `[ui_xml] query=${params.query ?? "(raw)"}\n` }], details: null });
126
+ if (signal?.aborted) throw new Error("aborted");
127
+
128
+ const ctx = getPiExtensionContext();
129
+ const out = await ctx.getUiXml(params.query);
130
+ return { content: [{ type: "text", text: out }], details: null };
131
+ },
132
+ });
133
+
134
+ // ── mobile_use_brain_actor ─ (commented out, not exposed to orchestrator)
135
+ // pi.registerTool({ name: "mobile_use_brain_actor", ... execute: mobileUseBrainActor })
136
+
137
+ // ── mobile_use_grounding ─ (commented out, not exposed to orchestrator)
138
+ // pi.registerTool({ name: "mobile_use_grounding", ... execute: mobileUseGrounding })
139
+ }
File without changes
@@ -0,0 +1,50 @@
1
+ ---
2
+ name: ground-mobile-fallback
3
+ description: 当 mobile_use 失败或不可用时,指导外层编排 Agent 用 ground + adb(及可选 ui_xml)分步操作 Android:先理解界面、再视觉定位、再执行点击/滑动,作为一体化 VLM 回退路径。
4
+ ---
5
+
6
+ # mobile_use 不可用时的手机操作回退(ground + adb)
7
+
8
+ ## 何时启用
9
+
10
+ 在以下情况**不要**再盲目重试 `mobile_use`,改用本流程:
11
+
12
+ - `mobile_use` 报错(API、超时、鉴权、设备断开等)。
13
+ - 任务极短、只需 1~3 次精确点击,一体化循环性价比低或易跑偏。
14
+ - 你需要**可解释**的坐标(例如调试、或要向用户说明点在哪里)。
15
+
16
+ 若 `ground` 所依赖的 Grounder(`GROUNDER_*` / 与 `GUI_AGENT_*` 共用的 VLM)也不可用,本回退无效,应先恢复网络与密钥或改任务。
17
+
18
+ ## 工具分工(外层负责编排)
19
+
20
+ | 工具 | 作用 |
21
+ |------|------|
22
+ | `ui_xml` | 可选。看当前界面结构、文案、`bounds` / `center`,缩小「要点哪里」的描述范围。 |
23
+ | `ground` | 对**当前屏**截图(或你传入的 `image_b64`),根据自然语言描述返回目标大致像素位置(模型原始输出多为类似 `[x, y]` 的坐标;以工具返回文本为准并解析)。 |
24
+ | Bash + `adb` | 在解析出坐标后执行 `adb shell input tap x y`、`input swipe ...` 等(需已连接设备,必要时设置 `GUI_AGENT_DEVICE_ID`)。 |
25
+
26
+ ## 推荐流程
27
+
28
+ 1. **确认设备**:`adb devices`;多设备时指定 serial(与项目环境变量一致)。
29
+ 2. **(可选)** `ui_xml` 带 `query` 搜索按钮/列表项文案,确认目标在屏上且描述与界面语言一致。
30
+ 3. **`ground(query)`**:`query` 写具体、可区分(例如「设置列表里的 WLAN 项」而非「网络」)。避免一次描述多个无关目标。
31
+ 4. **解析坐标**:从返回文本中提取整数像素坐标;若有多个候选,优先与 `ui_xml` 的 `center` 接近的点。
32
+ 5. **`adb shell input tap x y`**。若未生效:等待动画后再 `ground` 一次(界面已变)或先 `ui_xml` 看是否被遮挡/未 clickable。
33
+ 6. **输入文字**:`adb shell input text '...'`(注意 shell 转义;复杂文本可改用系统剪贴板或拆分步骤)。
34
+ 7. **滑动**:需要时 `input swipe x1 y1 x2 y2 duration_ms`;长列表可多次滑动后再 `ground`。
35
+
36
+ ## 与 mobile_use 的配合
37
+
38
+ - 正常情况仍以 **`mobile_use` 为主**(一次调用内多步截图→推理→执行)。
39
+ - 仅当 `mobile_use` **明确失败**或**不适合**时,再切换到「`ui_xml` + `ground` + adb」的显式编排。
40
+ - 回退路径步数多、对描述敏感;每步后根据新截图或 `ui_xml` 校验是否到达预期界面。
41
+
42
+ ## 环境变量提示(便于排查)
43
+
44
+ - 设备:`GUI_AGENT_DEVICE_ID`
45
+ - 截图与 Grounder 常与内层共用:`GUI_AGENT_BASE_URL`、`GUI_AGENT_API_KEY`、`GUI_AGENT_MODEL`;若单独配置 Grounder:`GROUNDER_BASE_URL`、`GROUNDER_API_KEY`、`GROUNDER_MODEL`
46
+
47
+ ## 禁止事项
48
+
49
+ - 不要在未确认坐标的情况下连续乱点同一区域。
50
+ - 不要用模糊到无法在一屏内唯一定位的 `query` 调用 `ground`(先 `ui_xml` 或滚动到目标大致出现)。
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 BeeOS AI
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
200
+ implied. See the License for the specific language governing permissions
201
+ and limitations under the License.
@@ -0,0 +1,9 @@
1
+ import type { Device } from "../device/base.js";
2
+ import type { ParsedAction, ActionResult } from "../types.js";
3
+ export declare class ActionHandler {
4
+ private readonly device;
5
+ constructor(device: Device);
6
+ execute(action: ParsedAction, screenW: number, screenH: number): Promise<ActionResult>;
7
+ private dispatch;
8
+ private toAbsolute;
9
+ }
@@ -0,0 +1,124 @@
1
+ const IMAGE_FACTOR = 28;
2
+ const MIN_PIXELS = 100 * 28 * 28;
3
+ const MAX_PIXELS = 16384 * 28 * 28;
4
+ export class ActionHandler {
5
+ device;
6
+ constructor(device) {
7
+ this.device = device;
8
+ }
9
+ async execute(action, screenW, screenH) {
10
+ if (action.actionType === "finish") {
11
+ return { success: true, shouldFinish: true, message: action.finishMessage };
12
+ }
13
+ try {
14
+ return await this.dispatch(action, screenW, screenH);
15
+ }
16
+ catch (e) {
17
+ return { success: false, shouldFinish: false, message: `Action error: ${e}` };
18
+ }
19
+ }
20
+ async dispatch(action, w, h) {
21
+ const { actionType: t, params: p, coordSystem } = action;
22
+ const coords = (x, y) => this.toAbsolute(Number(x), Number(y), w, h, coordSystem);
23
+ if (t === "tap") {
24
+ const [x, y] = coords(p.x, p.y);
25
+ await this.device.tap(x, y);
26
+ return ok();
27
+ }
28
+ if (t === "double_tap") {
29
+ const [x, y] = coords(p.x, p.y);
30
+ await this.device.doubleTap(x, y);
31
+ return ok();
32
+ }
33
+ if (t === "long_press") {
34
+ const [x, y] = coords(p.x, p.y);
35
+ await this.device.longPress(x, y, Number(p.duration_ms ?? 3000));
36
+ return ok();
37
+ }
38
+ if (t === "swipe") {
39
+ const [sx, sy] = coords(p.start_x, p.start_y);
40
+ const [ex, ey] = coords(p.end_x, p.end_y);
41
+ await this.device.swipe(sx, sy, ex, ey, p.duration_ms != null ? Number(p.duration_ms) : undefined);
42
+ return ok();
43
+ }
44
+ if (t === "scroll") {
45
+ const [x, y] = coords(p.x, p.y);
46
+ const dir = String(p.direction ?? "down");
47
+ const dist = Math.floor(h * 0.35);
48
+ if (dir === "down")
49
+ await this.device.swipe(x, y, x, y - dist);
50
+ else if (dir === "up")
51
+ await this.device.swipe(x, y, x, y + dist);
52
+ else if (dir === "left")
53
+ await this.device.swipe(x, y, x + Math.floor(w * 0.3), y);
54
+ else
55
+ await this.device.swipe(x, y, x - Math.floor(w * 0.3), y);
56
+ return ok();
57
+ }
58
+ if (t === "type") {
59
+ await this.device.inputText(String(p.text ?? ""));
60
+ return ok();
61
+ }
62
+ if (t === "open_app") {
63
+ const launched = await this.device.launchApp(String(p.app_name ?? ""));
64
+ return { success: launched, shouldFinish: false, message: launched ? null : `App not found: ${p.app_name}` };
65
+ }
66
+ if (t === "press_back") {
67
+ await this.device.pressBack();
68
+ return ok();
69
+ }
70
+ if (t === "press_home") {
71
+ await this.device.pressHome();
72
+ return ok();
73
+ }
74
+ if (t === "press_key") {
75
+ await this.device.pressKey(String(p.key ?? ""));
76
+ return ok();
77
+ }
78
+ if (t === "wait") {
79
+ await new Promise((res) => setTimeout(res, (Number(p.duration_seconds ?? 2)) * 1000));
80
+ return ok();
81
+ }
82
+ if (t === "takeover") {
83
+ // In non-interactive mode just log and continue
84
+ console.log(`[takeover] ${p.message ?? "User intervention required"}`);
85
+ return ok();
86
+ }
87
+ return { success: false, shouldFinish: false, message: `Unknown action: ${t}` };
88
+ }
89
+ toAbsolute(x, y, w, h, coordSystem) {
90
+ if (coordSystem === "absolute")
91
+ return [clamp(Math.round(x), 0, w - 1), clamp(Math.round(y), 0, h - 1)];
92
+ if (coordSystem === "smart_resize")
93
+ return smartResizeToAbsolute(x, y, w, h);
94
+ // 0-1000 relative
95
+ return [clamp(Math.round(x / 1000 * w), 0, w - 1), clamp(Math.round(y / 1000 * h), 0, h - 1)];
96
+ }
97
+ }
98
+ // ── Smart-resize (UI-TARS) ────────────────────────────────────────────────────
99
+ function smartResize(height, width) {
100
+ const f = IMAGE_FACTOR;
101
+ const rnd = (n) => Math.round(n / f) * f;
102
+ const ceil = (n) => Math.ceil(n / f) * f;
103
+ const flr = (n) => Math.floor(n / f) * f;
104
+ let hBar = Math.max(f, rnd(height));
105
+ let wBar = Math.max(f, rnd(width));
106
+ if (hBar * wBar > MAX_PIXELS) {
107
+ const beta = Math.sqrt((height * width) / MAX_PIXELS);
108
+ hBar = flr(height / beta);
109
+ wBar = flr(width / beta);
110
+ }
111
+ else if (hBar * wBar < MIN_PIXELS) {
112
+ const beta = Math.sqrt(MIN_PIXELS / (height * width));
113
+ hBar = ceil(height * beta);
114
+ wBar = ceil(width * beta);
115
+ }
116
+ return [hBar, wBar];
117
+ }
118
+ function smartResizeToAbsolute(x, y, w, h) {
119
+ const [rh, rw] = smartResize(Math.max(1, h), Math.max(1, w));
120
+ return [clamp(Math.round(x / rw * w), 0, w - 1), clamp(Math.round(y / rh * h), 0, h - 1)];
121
+ }
122
+ function clamp(v, lo, hi) { return Math.max(lo, Math.min(hi, v)); }
123
+ function ok() { return { success: true, shouldFinish: false, message: null }; }
124
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/action/handler.ts"],"names":[],"mappings":"AAGA,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM,UAAU,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,CAA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